Merge git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6
[sfrench/cifs-2.6.git] / arch / mips / alchemy / 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
26 #include <asm/mach-au1x00/au1xxx.h>
27 #include <asm/mach-au1x00/au1100_mmc.h>
28
29 static int mmc_activity;
30
31 static void pb1200mmc0_set_power(void *mmc_host, int state)
32 {
33         if (state)
34                 bcsr->board |= BCSR_BOARD_SD0PWR;
35         else
36                 bcsr->board &= ~BCSR_BOARD_SD0PWR;
37
38         au_sync_delay(1);
39 }
40
41 static int pb1200mmc0_card_readonly(void *mmc_host)
42 {
43         return (bcsr->status & BCSR_STATUS_SD0WP) ? 1 : 0;
44 }
45
46 static int pb1200mmc0_card_inserted(void *mmc_host)
47 {
48         return (bcsr->sig_status & BCSR_INT_SD0INSERT) ? 1 : 0;
49 }
50
51 static void pb1200_mmcled_set(struct led_classdev *led,
52                         enum led_brightness brightness)
53 {
54         if (brightness != LED_OFF) {
55                 if (++mmc_activity == 1)
56                         bcsr->disk_leds &= ~(1 << 8);
57         } else {
58                 if (--mmc_activity == 0)
59                         bcsr->disk_leds |= (1 << 8);
60         }
61 }
62
63 static struct led_classdev pb1200mmc_led = {
64         .brightness_set = pb1200_mmcled_set,
65 };
66
67 #ifndef CONFIG_MIPS_DB1200
68 static void pb1200mmc1_set_power(void *mmc_host, int state)
69 {
70         if (state)
71                 bcsr->board |= BCSR_BOARD_SD1PWR;
72         else
73                 bcsr->board &= ~BCSR_BOARD_SD1PWR;
74
75         au_sync_delay(1);
76 }
77
78 static int pb1200mmc1_card_readonly(void *mmc_host)
79 {
80         return (bcsr->status & BCSR_STATUS_SD1WP) ? 1 : 0;
81 }
82
83 static int pb1200mmc1_card_inserted(void *mmc_host)
84 {
85         return (bcsr->sig_status & BCSR_INT_SD1INSERT) ? 1 : 0;
86 }
87 #endif
88
89 const struct au1xmmc_platform_data au1xmmc_platdata[2] = {
90         [0] = {
91                 .set_power      = pb1200mmc0_set_power,
92                 .card_inserted  = pb1200mmc0_card_inserted,
93                 .card_readonly  = pb1200mmc0_card_readonly,
94                 .cd_setup       = NULL,         /* use poll-timer in driver */
95                 .led            = &pb1200mmc_led,
96         },
97 #ifndef CONFIG_MIPS_DB1200
98         [1] = {
99                 .set_power      = pb1200mmc1_set_power,
100                 .card_inserted  = pb1200mmc1_card_inserted,
101                 .card_readonly  = pb1200mmc1_card_readonly,
102                 .cd_setup       = NULL,         /* use poll-timer in driver */
103                 .led            = &pb1200mmc_led,
104         },
105 #endif
106 };
107
108 static struct resource ide_resources[] = {
109         [0] = {
110                 .start  = IDE_PHYS_ADDR,
111                 .end    = IDE_PHYS_ADDR + IDE_PHYS_LEN - 1,
112                 .flags  = IORESOURCE_MEM
113         },
114         [1] = {
115                 .start  = IDE_INT,
116                 .end    = IDE_INT,
117                 .flags  = IORESOURCE_IRQ
118         }
119 };
120
121 static u64 ide_dmamask = DMA_32BIT_MASK;
122
123 static struct platform_device ide_device = {
124         .name           = "au1200-ide",
125         .id             = 0,
126         .dev = {
127                 .dma_mask               = &ide_dmamask,
128                 .coherent_dma_mask      = DMA_32BIT_MASK,
129         },
130         .num_resources  = ARRAY_SIZE(ide_resources),
131         .resource       = ide_resources
132 };
133
134 static struct resource smc91c111_resources[] = {
135         [0] = {
136                 .name   = "smc91x-regs",
137                 .start  = SMC91C111_PHYS_ADDR,
138                 .end    = SMC91C111_PHYS_ADDR + 0xf,
139                 .flags  = IORESOURCE_MEM
140         },
141         [1] = {
142                 .start  = SMC91C111_INT,
143                 .end    = SMC91C111_INT,
144                 .flags  = IORESOURCE_IRQ
145         },
146 };
147
148 static struct platform_device smc91c111_device = {
149         .name           = "smc91x",
150         .id             = -1,
151         .num_resources  = ARRAY_SIZE(smc91c111_resources),
152         .resource       = smc91c111_resources
153 };
154
155 static struct platform_device *board_platform_devices[] __initdata = {
156         &ide_device,
157         &smc91c111_device
158 };
159
160 static int __init board_register_devices(void)
161 {
162         return platform_add_devices(board_platform_devices,
163                                     ARRAY_SIZE(board_platform_devices));
164 }
165
166 arch_initcall(board_register_devices);