spi/imx: Use dev_name() for request_irq() to distinguish SPIs
[cascardo/linux.git] / arch / mips / alchemy / board-gpr.c
1 /*
2  * GPR board platform device registration (Au1550)
3  *
4  * Copyright (C) 2010 Wolfgang Grandegger <wg@denx.de>
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/delay.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/kernel.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/physmap.h>
29 #include <linux/leds.h>
30 #include <linux/gpio.h>
31 #include <linux/i2c.h>
32 #include <linux/i2c-gpio.h>
33 #include <asm/bootinfo.h>
34 #include <asm/idle.h>
35 #include <asm/reboot.h>
36 #include <asm/mach-au1x00/au1000.h>
37 #include <prom.h>
38
39 const char *get_system_type(void)
40 {
41         return "GPR";
42 }
43
44 void __init prom_init(void)
45 {
46         unsigned char *memsize_str;
47         unsigned long memsize;
48
49         prom_argc = fw_arg0;
50         prom_argv = (char **)fw_arg1;
51         prom_envp = (char **)fw_arg2;
52
53         prom_init_cmdline();
54
55         memsize_str = prom_getenv("memsize");
56         if (!memsize_str)
57                 memsize = 0x04000000;
58         else
59                 strict_strtoul(memsize_str, 0, &memsize);
60         add_memory_region(0, memsize, BOOT_MEM_RAM);
61 }
62
63 void prom_putchar(unsigned char c)
64 {
65         alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
66 }
67
68 static void gpr_reset(char *c)
69 {
70         /* switch System-LED to orange (red# and green# on) */
71         alchemy_gpio_direction_output(4, 0);
72         alchemy_gpio_direction_output(5, 0);
73
74         /* trigger watchdog to reset board in 200ms */
75         printk(KERN_EMERG "Triggering watchdog soft reset...\n");
76         raw_local_irq_disable();
77         alchemy_gpio_direction_output(1, 0);
78         udelay(1);
79         alchemy_gpio_set_value(1, 1);
80         while (1)
81                 cpu_wait();
82 }
83
84 static void gpr_power_off(void)
85 {
86         while (1)
87                 cpu_wait();
88 }
89
90 void __init board_setup(void)
91 {
92         printk(KERN_INFO "Trapeze ITS GPR board\n");
93
94         pm_power_off = gpr_power_off;
95         _machine_halt = gpr_power_off;
96         _machine_restart = gpr_reset;
97
98         /* Enable UART1/3 */
99         alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);
100         alchemy_uart_enable(AU1000_UART1_PHYS_ADDR);
101
102         /* Take away Reset of UMTS-card */
103         alchemy_gpio_direction_output(215, 1);
104 }
105
106 /*
107  * Watchdog
108  */
109 static struct resource gpr_wdt_resource[] = {
110         [0] = {
111                 .start  = 1,
112                 .end    = 1,
113                 .name   = "gpr-adm6320-wdt",
114                 .flags  = IORESOURCE_IRQ,
115         }
116 };
117
118 static struct platform_device gpr_wdt_device = {
119         .name = "adm6320-wdt",
120         .id = 0,
121         .num_resources = ARRAY_SIZE(gpr_wdt_resource),
122         .resource = gpr_wdt_resource,
123 };
124
125 /*
126  * FLASH
127  *
128  * 0x00000000-0x00200000 : "kernel"
129  * 0x00200000-0x00a00000 : "rootfs"
130  * 0x01d00000-0x01f00000 : "config"
131  * 0x01c00000-0x01d00000 : "yamon"
132  * 0x01d00000-0x01d40000 : "yamon env vars"
133  * 0x00000000-0x00a00000 : "kernel+rootfs"
134  */
135 static struct mtd_partition gpr_mtd_partitions[] = {
136         {
137                 .name   = "kernel",
138                 .size   = 0x00200000,
139                 .offset = 0,
140         },
141         {
142                 .name   = "rootfs",
143                 .size   = 0x00800000,
144                 .offset = MTDPART_OFS_APPEND,
145                 .mask_flags = MTD_WRITEABLE,
146         },
147         {
148                 .name   = "config",
149                 .size   = 0x00200000,
150                 .offset = 0x01d00000,
151         },
152         {
153                 .name   = "yamon",
154                 .size   = 0x00100000,
155                 .offset = 0x01c00000,
156         },
157         {
158                 .name   = "yamon env vars",
159                 .size   = 0x00040000,
160                 .offset = MTDPART_OFS_APPEND,
161         },
162         {
163                 .name   = "kernel+rootfs",
164                 .size   = 0x00a00000,
165                 .offset = 0,
166         },
167 };
168
169 static struct physmap_flash_data gpr_flash_data = {
170         .width          = 4,
171         .nr_parts       = ARRAY_SIZE(gpr_mtd_partitions),
172         .parts          = gpr_mtd_partitions,
173 };
174
175 static struct resource gpr_mtd_resource = {
176         .start  = 0x1e000000,
177         .end    = 0x1fffffff,
178         .flags  = IORESOURCE_MEM,
179 };
180
181 static struct platform_device gpr_mtd_device = {
182         .name           = "physmap-flash",
183         .dev            = {
184                 .platform_data  = &gpr_flash_data,
185         },
186         .num_resources  = 1,
187         .resource       = &gpr_mtd_resource,
188 };
189
190 /*
191  * LEDs
192  */
193 static struct gpio_led gpr_gpio_leds[] = {
194         {       /* green */
195                 .name                   = "gpr:green",
196                 .gpio                   = 4,
197                 .active_low             = 1,
198         },
199         {       /* red */
200                 .name                   = "gpr:red",
201                 .gpio                   = 5,
202                 .active_low             = 1,
203         }
204 };
205
206 static struct gpio_led_platform_data gpr_led_data = {
207         .num_leds = ARRAY_SIZE(gpr_gpio_leds),
208         .leds = gpr_gpio_leds,
209 };
210
211 static struct platform_device gpr_led_devices = {
212         .name = "leds-gpio",
213         .id = -1,
214         .dev = {
215                 .platform_data = &gpr_led_data,
216         }
217 };
218
219 /*
220  * I2C
221  */
222 static struct i2c_gpio_platform_data gpr_i2c_data = {
223         .sda_pin                = 209,
224         .sda_is_open_drain      = 1,
225         .scl_pin                = 210,
226         .scl_is_open_drain      = 1,
227         .udelay                 = 2,            /* ~100 kHz */
228         .timeout                = HZ,
229 };
230
231 static struct platform_device gpr_i2c_device = {
232         .name                   = "i2c-gpio",
233         .id                     = -1,
234         .dev.platform_data      = &gpr_i2c_data,
235 };
236
237 static struct i2c_board_info gpr_i2c_info[] __initdata = {
238         {
239                 I2C_BOARD_INFO("lm83", 0x18),
240                 .type = "lm83"
241         }
242 };
243
244
245
246 static struct resource alchemy_pci_host_res[] = {
247         [0] = {
248                 .start  = AU1500_PCI_PHYS_ADDR,
249                 .end    = AU1500_PCI_PHYS_ADDR + 0xfff,
250                 .flags  = IORESOURCE_MEM,
251         },
252 };
253
254 static int gpr_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
255 {
256         if ((slot == 0) && (pin == 1))
257                 return AU1550_PCI_INTA;
258         else if ((slot == 0) && (pin == 2))
259                 return AU1550_PCI_INTB;
260
261         return 0xff;
262 }
263
264 static struct alchemy_pci_platdata gpr_pci_pd = {
265         .board_map_irq  = gpr_map_pci_irq,
266         .pci_cfg_set    = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
267                           PCI_CONFIG_CH |
268 #if defined(__MIPSEB__)
269                           PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
270 #else
271                           0,
272 #endif
273 };
274
275 static struct platform_device gpr_pci_host_dev = {
276         .dev.platform_data = &gpr_pci_pd,
277         .name           = "alchemy-pci",
278         .id             = 0,
279         .num_resources  = ARRAY_SIZE(alchemy_pci_host_res),
280         .resource       = alchemy_pci_host_res,
281 };
282
283 static struct platform_device *gpr_devices[] __initdata = {
284         &gpr_wdt_device,
285         &gpr_mtd_device,
286         &gpr_i2c_device,
287         &gpr_led_devices,
288 };
289
290 static int __init gpr_pci_init(void)
291 {
292         return platform_device_register(&gpr_pci_host_dev);
293 }
294 /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */
295 arch_initcall(gpr_pci_init);
296
297
298 static int __init gpr_dev_init(void)
299 {
300         i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
301
302         return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
303 }
304 device_initcall(gpr_dev_init);