MIPS: Alchemy: devboard register abstraction
[linux-2.6.git] / arch / mips / alchemy / devboards / pb1200 / platform.c
1 /*
2  * Pb1200/DBAu1200 board platform device registration
3  *
4  * Copyright (C) 2008 MontaVista Software Inc. <source@mvista.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include <linux/dma-mapping.h>
22 #include <linux/init.h>
23 #include <linux/leds.h>
24 #include <linux/platform_device.h>
25 #include <linux/smc91x.h>
26
27 #include <asm/mach-au1x00/au1xxx.h>
28 #include <asm/mach-au1x00/au1100_mmc.h>
29 #include <asm/mach-db1x00/bcsr.h>
30
31 static int mmc_activity;
32
33 static void pb1200mmc0_set_power(void *mmc_host, int state)
34 {
35         if (state)
36                 bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD0PWR);
37         else
38                 bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD0PWR, 0);
39
40         msleep(1);
41 }
42
43 static int pb1200mmc0_card_readonly(void *mmc_host)
44 {
45         return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 1 : 0;
46 }
47
48 static int pb1200mmc0_card_inserted(void *mmc_host)
49 {
50         return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT) ? 1 : 0;
51 }
52
53 static void pb1200_mmcled_set(struct led_classdev *led,
54                         enum led_brightness brightness)
55 {
56         if (brightness != LED_OFF) {
57                 if (++mmc_activity == 1)
58                         bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
59         } else {
60                 if (--mmc_activity == 0)
61                         bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
62         }
63 }
64
65 static struct led_classdev pb1200mmc_led = {
66         .brightness_set = pb1200_mmcled_set,
67 };
68
69 #ifndef CONFIG_MIPS_DB1200
70 static void pb1200mmc1_set_power(void *mmc_host, int state)
71 {
72         if (state)
73                 bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD1PWR);
74         else
75                 bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD1PWR, 0);
76
77         msleep(1);
78 }
79
80 static int pb1200mmc1_card_readonly(void *mmc_host)
81 {
82         return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD1WP) ? 1 : 0;
83 }
84
85 static int pb1200mmc1_card_inserted(void *mmc_host)
86 {
87         return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT) ? 1 : 0;
88 }
89 #endif
90
91 const struct au1xmmc_platform_data au1xmmc_platdata[2] = {
92         [0] = {
93                 .set_power      = pb1200mmc0_set_power,
94                 .card_inserted  = pb1200mmc0_card_inserted,
95                 .card_readonly  = pb1200mmc0_card_readonly,
96                 .cd_setup       = NULL,         /* use poll-timer in driver */
97                 .led            = &pb1200mmc_led,
98         },
99 #ifndef CONFIG_MIPS_DB1200
100         [1] = {
101                 .set_power      = pb1200mmc1_set_power,
102                 .card_inserted  = pb1200mmc1_card_inserted,
103                 .card_readonly  = pb1200mmc1_card_readonly,
104                 .cd_setup       = NULL,         /* use poll-timer in driver */
105                 .led            = &pb1200mmc_led,
106         },
107 #endif
108 };
109
110 static struct resource ide_resources[] = {
111         [0] = {
112                 .start  = IDE_PHYS_ADDR,
113                 .end    = IDE_PHYS_ADDR + IDE_PHYS_LEN - 1,
114                 .flags  = IORESOURCE_MEM
115         },
116         [1] = {
117                 .start  = IDE_INT,
118                 .end    = IDE_INT,
119                 .flags  = IORESOURCE_IRQ
120         }
121 };
122
123 static u64 ide_dmamask = DMA_BIT_MASK(32);
124
125 static struct platform_device ide_device = {
126         .name           = "au1200-ide",
127         .id             = 0,
128         .dev = {
129                 .dma_mask               = &ide_dmamask,
130                 .coherent_dma_mask      = DMA_BIT_MASK(32),
131         },
132         .num_resources  = ARRAY_SIZE(ide_resources),
133         .resource       = ide_resources
134 };
135
136 static struct smc91x_platdata smc_data = {
137         .flags  = SMC91X_NOWAIT | SMC91X_USE_16BIT,
138         .leda   = RPC_LED_100_10,
139         .ledb   = RPC_LED_TX_RX,
140 };
141
142 static struct resource smc91c111_resources[] = {
143         [0] = {
144                 .name   = "smc91x-regs",
145                 .start  = SMC91C111_PHYS_ADDR,
146                 .end    = SMC91C111_PHYS_ADDR + 0xf,
147                 .flags  = IORESOURCE_MEM
148         },
149         [1] = {
150                 .start  = SMC91C111_INT,
151                 .end    = SMC91C111_INT,
152                 .flags  = IORESOURCE_IRQ
153         },
154 };
155
156 static struct platform_device smc91c111_device = {
157         .dev    = {
158                 .platform_data  = &smc_data,
159         },
160         .name           = "smc91x",
161         .id             = -1,
162         .num_resources  = ARRAY_SIZE(smc91c111_resources),
163         .resource       = smc91c111_resources
164 };
165
166 static struct platform_device *board_platform_devices[] __initdata = {
167         &ide_device,
168         &smc91c111_device
169 };
170
171 static int __init board_register_devices(void)
172 {
173         return platform_add_devices(board_platform_devices,
174                                     ARRAY_SIZE(board_platform_devices));
175 }
176
177 arch_initcall(board_register_devices);