736d647ebe0c0264116bea639417c3b06299fefd
[platform/adaptation/renesas_rcar/renesas_kernel.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 #include "../platform.h"
32
33 static int mmc_activity;
34
35 static void pb1200mmc0_set_power(void *mmc_host, int state)
36 {
37         if (state)
38                 bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD0PWR);
39         else
40                 bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD0PWR, 0);
41
42         msleep(1);
43 }
44
45 static int pb1200mmc0_card_readonly(void *mmc_host)
46 {
47         return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 1 : 0;
48 }
49
50 static int pb1200mmc0_card_inserted(void *mmc_host)
51 {
52         return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT) ? 1 : 0;
53 }
54
55 static void pb1200_mmcled_set(struct led_classdev *led,
56                         enum led_brightness brightness)
57 {
58         if (brightness != LED_OFF) {
59                 if (++mmc_activity == 1)
60                         bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
61         } else {
62                 if (--mmc_activity == 0)
63                         bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
64         }
65 }
66
67 static struct led_classdev pb1200mmc_led = {
68         .brightness_set = pb1200_mmcled_set,
69 };
70
71 #ifndef CONFIG_MIPS_DB1200
72 static void pb1200mmc1_set_power(void *mmc_host, int state)
73 {
74         if (state)
75                 bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD1PWR);
76         else
77                 bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD1PWR, 0);
78
79         msleep(1);
80 }
81
82 static int pb1200mmc1_card_readonly(void *mmc_host)
83 {
84         return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD1WP) ? 1 : 0;
85 }
86
87 static int pb1200mmc1_card_inserted(void *mmc_host)
88 {
89         return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT) ? 1 : 0;
90 }
91 #endif
92
93 const struct au1xmmc_platform_data au1xmmc_platdata[2] = {
94         [0] = {
95                 .set_power      = pb1200mmc0_set_power,
96                 .card_inserted  = pb1200mmc0_card_inserted,
97                 .card_readonly  = pb1200mmc0_card_readonly,
98                 .cd_setup       = NULL,         /* use poll-timer in driver */
99                 .led            = &pb1200mmc_led,
100         },
101 #ifndef CONFIG_MIPS_DB1200
102         [1] = {
103                 .set_power      = pb1200mmc1_set_power,
104                 .card_inserted  = pb1200mmc1_card_inserted,
105                 .card_readonly  = pb1200mmc1_card_readonly,
106                 .cd_setup       = NULL,         /* use poll-timer in driver */
107                 .led            = &pb1200mmc_led,
108         },
109 #endif
110 };
111
112 static struct resource ide_resources[] = {
113         [0] = {
114                 .start  = IDE_PHYS_ADDR,
115                 .end    = IDE_PHYS_ADDR + IDE_PHYS_LEN - 1,
116                 .flags  = IORESOURCE_MEM
117         },
118         [1] = {
119                 .start  = IDE_INT,
120                 .end    = IDE_INT,
121                 .flags  = IORESOURCE_IRQ
122         }
123 };
124
125 static u64 ide_dmamask = DMA_BIT_MASK(32);
126
127 static struct platform_device ide_device = {
128         .name           = "au1200-ide",
129         .id             = 0,
130         .dev = {
131                 .dma_mask               = &ide_dmamask,
132                 .coherent_dma_mask      = DMA_BIT_MASK(32),
133         },
134         .num_resources  = ARRAY_SIZE(ide_resources),
135         .resource       = ide_resources
136 };
137
138 static struct smc91x_platdata smc_data = {
139         .flags  = SMC91X_NOWAIT | SMC91X_USE_16BIT,
140         .leda   = RPC_LED_100_10,
141         .ledb   = RPC_LED_TX_RX,
142 };
143
144 static struct resource smc91c111_resources[] = {
145         [0] = {
146                 .name   = "smc91x-regs",
147                 .start  = SMC91C111_PHYS_ADDR,
148                 .end    = SMC91C111_PHYS_ADDR + 0xf,
149                 .flags  = IORESOURCE_MEM
150         },
151         [1] = {
152                 .start  = SMC91C111_INT,
153                 .end    = SMC91C111_INT,
154                 .flags  = IORESOURCE_IRQ
155         },
156 };
157
158 static struct platform_device smc91c111_device = {
159         .dev    = {
160                 .platform_data  = &smc_data,
161         },
162         .name           = "smc91x",
163         .id             = -1,
164         .num_resources  = ARRAY_SIZE(smc91c111_resources),
165         .resource       = smc91c111_resources
166 };
167
168 static struct platform_device *board_platform_devices[] __initdata = {
169         &ide_device,
170         &smc91c111_device
171 };
172
173 static int __init board_register_devices(void)
174 {
175         int swapped;
176
177 #ifdef CONFIG_MIPS_PB1200
178         db1x_register_pcmcia_socket(PCMCIA_ATTR_PSEUDO_PHYS,
179                                     PCMCIA_ATTR_PSEUDO_PHYS + 0x00040000 - 1,
180                                     PCMCIA_MEM_PSEUDO_PHYS,
181                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00040000 - 1,
182                                     PCMCIA_IO_PSEUDO_PHYS,
183                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00001000 - 1,
184                                     PB1200_PC0_INT,
185                                     PB1200_PC0_INSERT_INT,
186                                     /*PB1200_PC0_STSCHG_INT*/0,
187                                     PB1200_PC0_EJECT_INT,
188                                     0);
189
190         db1x_register_pcmcia_socket(PCMCIA_ATTR_PSEUDO_PHYS + 0x00800000,
191                                     PCMCIA_ATTR_PSEUDO_PHYS + 0x00840000 - 1,
192                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00800000,
193                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00840000 - 1,
194                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00800000,
195                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00801000 - 1,
196                                     PB1200_PC1_INT,
197                                     PB1200_PC1_INSERT_INT,
198                                     /*PB1200_PC1_STSCHG_INT*/0,
199                                     PB1200_PC1_EJECT_INT,
200                                     1);
201 #else
202         db1x_register_pcmcia_socket(PCMCIA_ATTR_PSEUDO_PHYS,
203                                     PCMCIA_ATTR_PSEUDO_PHYS + 0x00040000 - 1,
204                                     PCMCIA_MEM_PSEUDO_PHYS,
205                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00040000 - 1,
206                                     PCMCIA_IO_PSEUDO_PHYS,
207                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00001000 - 1,
208                                     DB1200_PC0_INT,
209                                     DB1200_PC0_INSERT_INT,
210                                     /*DB1200_PC0_STSCHG_INT*/0,
211                                     DB1200_PC0_EJECT_INT,
212                                     0);
213
214         db1x_register_pcmcia_socket(PCMCIA_ATTR_PSEUDO_PHYS + 0x00400000,
215                                     PCMCIA_ATTR_PSEUDO_PHYS + 0x00440000 - 1,
216                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00400000,
217                                     PCMCIA_MEM_PSEUDO_PHYS  + 0x00440000 - 1,
218                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00400000,
219                                     PCMCIA_IO_PSEUDO_PHYS   + 0x00401000 - 1,
220                                     DB1200_PC1_INT,
221                                     DB1200_PC1_INSERT_INT,
222                                     /*DB1200_PC1_STSCHG_INT*/0,
223                                     DB1200_PC1_EJECT_INT,
224                                     1);
225 #endif
226
227         swapped = bcsr_read(BCSR_STATUS) &  BCSR_STATUS_DB1200_SWAPBOOT;
228 #ifdef CONFIG_MIPS_PB1200
229         db1x_register_norflash(128 * 1024 * 1024, 2, swapped);
230 #else
231         db1x_register_norflash(64 * 1024 * 1024, 2, swapped);
232 #endif
233
234         return platform_add_devices(board_platform_devices,
235                                     ARRAY_SIZE(board_platform_devices));
236 }
237 device_initcall(board_register_devices);