blob: d84924993bad4056e2c6fc0d09c7977f263e88fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/badge4.c
3 *
4 * BadgePAD 4 specific initialization
5 *
6 * Tim Connors <connors@hpl.hp.com>
7 * Christopher Hoover <ch@hpl.hp.com>
8 *
9 * Copyright (C) 2002 Hewlett-Packard Company
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 */
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010019#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h>
21#include <linux/tty.h>
22#include <linux/mtd/mtd.h>
23#include <linux/mtd/partitions.h>
24#include <linux/errno.h>
25
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/mach-types.h>
28#include <asm/setup.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <asm/mach/arch.h>
32#include <asm/mach/flash.h>
33#include <asm/mach/map.h>
34#include <asm/hardware/sa1111.h>
35#include <asm/mach/serial_sa1100.h>
36
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/badge4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include "generic.h"
40
41static struct resource sa1111_resources[] = {
42 [0] = {
43 .start = BADGE4_SA1111_BASE,
44 .end = BADGE4_SA1111_BASE + 0x00001fff,
45 .flags = IORESOURCE_MEM,
46 },
47 [1] = {
48 .start = BADGE4_IRQ_GPIO_SA1111,
49 .end = BADGE4_IRQ_GPIO_SA1111,
50 .flags = IORESOURCE_IRQ,
51 },
52};
53
Russell King32597012012-01-26 13:28:35 +000054static int badge4_sa1111_enable(void *data, unsigned devid)
55{
56 if (devid == SA1111_DEVID_USB)
57 badge4_set_5V(BADGE4_5V_USB, 1);
58 return 0;
59}
60
61static void badge4_sa1111_disable(void *data, unsigned devid)
62{
63 if (devid == SA1111_DEVID_USB)
64 badge4_set_5V(BADGE4_5V_USB, 0);
65}
66
Eric Miao19851c52009-12-26 16:23:02 +080067static struct sa1111_platform_data sa1111_info = {
68 .irq_base = IRQ_BOARD_END,
Russell King32597012012-01-26 13:28:35 +000069 .enable = badge4_sa1111_enable,
70 .disable = badge4_sa1111_disable,
Eric Miao19851c52009-12-26 16:23:02 +080071};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static u64 sa1111_dmamask = 0xffffffffUL;
74
75static struct platform_device sa1111_device = {
76 .name = "sa1111",
77 .id = 0,
78 .dev = {
79 .dma_mask = &sa1111_dmamask,
80 .coherent_dma_mask = 0xffffffff,
Eric Miao19851c52009-12-26 16:23:02 +080081 .platform_data = &sa1111_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 },
83 .num_resources = ARRAY_SIZE(sa1111_resources),
84 .resource = sa1111_resources,
85};
86
87static struct platform_device *devices[] __initdata = {
88 &sa1111_device,
89};
90
91static int __init badge4_sa1111_init(void)
92{
93 /*
94 * Ensure that the memory bus request/grant signals are setup,
95 * and the grant is held in its inactive state
96 */
97 sa1110_mb_disable();
98
99 /*
100 * Probe for SA1111.
101 */
102 return platform_add_devices(devices, ARRAY_SIZE(devices));
103}
104
105
106/*
107 * 1 x Intel 28F320C3 Advanced+ Boot Block Flash (32 Mi bit)
108 * Eight 4 KiW Parameter Bottom Blocks (64 KiB)
109 * Sixty-three 32 KiW Main Blocks (4032 Ki b)
110 *
111 * <or>
112 *
113 * 1 x Intel 28F640C3 Advanced+ Boot Block Flash (64 Mi bit)
114 * Eight 4 KiW Parameter Bottom Blocks (64 KiB)
115 * One-hundred-twenty-seven 32 KiW Main Blocks (8128 Ki b)
116 */
117static struct mtd_partition badge4_partitions[] = {
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100118 {
119 .name = "BLOB boot loader",
120 .offset = 0,
121 .size = 0x0000A000
122 }, {
123 .name = "params",
124 .offset = MTDPART_OFS_APPEND,
125 .size = 0x00006000
126 }, {
127 .name = "root",
128 .offset = MTDPART_OFS_APPEND,
129 .size = MTDPART_SIZ_FULL
130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
133static struct flash_platform_data badge4_flash_data = {
134 .map_name = "cfi_probe",
135 .parts = badge4_partitions,
136 .nr_parts = ARRAY_SIZE(badge4_partitions),
137};
138
139static struct resource badge4_flash_resource = {
140 .start = SA1100_CS0_PHYS,
141 .end = SA1100_CS0_PHYS + SZ_64M - 1,
142 .flags = IORESOURCE_MEM,
143};
144
145static int five_v_on __initdata = 0;
146
147static int __init five_v_on_setup(char *ignore)
148{
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100149 five_v_on = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return 1;
151}
152__setup("five_v_on", five_v_on_setup);
153
154
155static int __init badge4_init(void)
156{
157 int ret;
158
159 if (!machine_is_badge4())
160 return -ENODEV;
161
162 /* LCD */
163 GPCR = (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
164 BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
165 BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
166 BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
167 BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
168 BADGE4_GPIO_GPC_VID);
169 GPDR &= ~BADGE4_GPIO_INT_VID;
170 GPDR |= (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
171 BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
172 BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
173 BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
174 BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
175 BADGE4_GPIO_GPC_VID);
176
177 /* SDRAM SPD i2c */
178 GPCR = (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
179 GPDR |= (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
180
181 /* uart */
182 GPCR = (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
183 GPDR |= (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
184
185 /* CPLD muxsel0 input for mux/adc chip select */
186 GPCR = BADGE4_GPIO_MUXSEL0;
187 GPDR |= BADGE4_GPIO_MUXSEL0;
188
189 /* test points: J5, J6 as inputs, J7 outputs */
190 GPDR &= ~(BADGE4_GPIO_TESTPT_J5 | BADGE4_GPIO_TESTPT_J6);
191 GPCR = BADGE4_GPIO_TESTPT_J7;
192 GPDR |= BADGE4_GPIO_TESTPT_J7;
193
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100194 /* 5V supply rail. */
195 GPCR = BADGE4_GPIO_PCMEN5V; /* initially off */
196 GPDR |= BADGE4_GPIO_PCMEN5V;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /* CPLD sdram type inputs; set up by blob */
199 //GPDR |= (BADGE4_GPIO_SDTYP1 | BADGE4_GPIO_SDTYP0);
200 printk(KERN_DEBUG __FILE__ ": SDRAM CPLD typ1=%d typ0=%d\n",
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100201 !!(GPLR & BADGE4_GPIO_SDTYP1),
202 !!(GPLR & BADGE4_GPIO_SDTYP0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 /* SA1111 reset pin; set up by blob */
205 //GPSR = BADGE4_GPIO_SA1111_NRST;
206 //GPDR |= BADGE4_GPIO_SA1111_NRST;
207
208
209 /* power management cruft */
210 PGSR = 0;
211 PWER = 0;
212 PCFR = 0;
213 PSDR = 0;
214
215 PWER |= PWER_GPIO26; /* wake up on an edge from TESTPT_J5 */
216 PWER |= PWER_RTC; /* wake up if rtc fires */
217
218 /* drive sa1111_nrst during sleep */
219 PGSR |= BADGE4_GPIO_SA1111_NRST;
220 /* drive CPLD as is during sleep */
221 PGSR |= (GPLR & (BADGE4_GPIO_SDTYP0|BADGE4_GPIO_SDTYP1));
222
223
224 /* Now bring up the SA-1111. */
225 ret = badge4_sa1111_init();
226 if (ret < 0)
227 printk(KERN_ERR
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100228 "%s: SA-1111 initialization failed (%d)\n",
229 __func__, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231
232 /* maybe turn on 5v0 from the start */
233 badge4_set_5V(BADGE4_5V_INITIALLY, five_v_on);
234
Russell King7a5b4e12009-10-06 14:55:53 +0100235 sa11x0_register_mtd(&badge4_flash_data, &badge4_flash_resource, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 return 0;
238}
239
240arch_initcall(badge4_init);
241
242
243static unsigned badge4_5V_bitmap = 0;
244
245void badge4_set_5V(unsigned subsystem, int on)
246{
247 unsigned long flags;
248 unsigned old_5V_bitmap;
249
250 local_irq_save(flags);
251
252 old_5V_bitmap = badge4_5V_bitmap;
253
254 if (on) {
255 badge4_5V_bitmap |= subsystem;
256 } else {
257 badge4_5V_bitmap &= ~subsystem;
258 }
259
260 /* detect on->off and off->on transitions */
261 if ((!old_5V_bitmap) && (badge4_5V_bitmap)) {
262 /* was off, now on */
Harvey Harrison8e86f422008-03-04 15:08:02 -0800263 printk(KERN_INFO "%s: enabling 5V supply rail\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 GPSR = BADGE4_GPIO_PCMEN5V;
265 } else if ((old_5V_bitmap) && (!badge4_5V_bitmap)) {
266 /* was on, now off */
Harvey Harrison8e86f422008-03-04 15:08:02 -0800267 printk(KERN_INFO "%s: disabling 5V supply rail\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 GPCR = BADGE4_GPIO_PCMEN5V;
269 }
270
271 local_irq_restore(flags);
272}
273EXPORT_SYMBOL(badge4_set_5V);
274
275
276static struct map_desc badge4_io_desc[] __initdata = {
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100277 { /* SRAM bank 1 */
Deepak Saxena92519d82005-10-28 15:19:04 +0100278 .virtual = 0xf1000000,
279 .pfn = __phys_to_pfn(0x08000000),
280 .length = 0x00100000,
281 .type = MT_DEVICE
282 }, { /* SRAM bank 2 */
283 .virtual = 0xf2000000,
284 .pfn = __phys_to_pfn(0x10000000),
285 .length = 0x00100000,
286 .type = MT_DEVICE
287 }, { /* SA-1111 */
288 .virtual = 0xf4000000,
289 .pfn = __phys_to_pfn(0x48000000),
290 .length = 0x00100000,
291 .type = MT_DEVICE
292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293};
294
295static void
296badge4_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
297{
298 if (!state) {
299 Ser1SDCR0 |= SDCR0_UART;
300 }
301}
302
303static struct sa1100_port_fns badge4_port_fns __initdata = {
304 //.get_mctrl = badge4_get_mctrl,
305 //.set_mctrl = badge4_set_mctrl,
306 .pm = badge4_uart_pm,
307};
308
309static void __init badge4_map_io(void)
310{
311 sa1100_map_io();
312 iotable_init(badge4_io_desc, ARRAY_SIZE(badge4_io_desc));
313
314 sa1100_register_uart_fns(&badge4_port_fns);
315 sa1100_register_uart(0, 3);
316 sa1100_register_uart(1, 1);
317}
318
319MACHINE_START(BADGE4, "Hewlett-Packard Laboratories BadgePAD 4")
Nicolas Pitre17f44252011-07-05 22:38:17 -0400320 .atag_offset = 0x100,
Russell Kinge9dea0c2005-07-03 17:38:58 +0100321 .map_io = badge4_map_io,
322 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 .timer = &sa1100_timer,
Nicolas Pitree9107ab2011-07-05 22:28:09 -0400324#ifdef CONFIG_SA1111
325 .dma_zone_size = SZ_1M,
326#endif
Russell Kingd9ca5832011-11-05 10:28:50 +0000327 .restart = sa11x0_restart,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328MACHINE_END