[xburst] Export clock states through debugfs
[openwrt.git] / target / linux / xburst / files-2.6.32 / arch / mips / jz4740 / board-n526.c
1 /*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * N526 eBook reader support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/gpio.h>
19
20 #include <asm/mach-jz4740/platform.h>
21
22 #include <linux/mtd/jz4740_nand.h>
23 #include <linux/jz4740_fb.h>
24 #include <linux/power_supply.h>
25 #include <linux/power/jz4740-battery.h>
26 #include <linux/mmc/jz4740_mmc.h>
27
28 #include <video/broadsheetfb.h>
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
31
32 #include <linux/input.h>
33 #include <linux/gpio_keys.h>
34
35 #include <linux/i2c.h>
36 #include <linux/i2c-gpio.h>
37
38 /* NAND */
39 static struct nand_ecclayout n526_ecclayout = {
40 .eccbytes = 36,
41 .eccpos = {
42 6, 7, 8, 9, 10, 11, 12, 13,
43 14, 15, 16, 17, 18, 19, 20, 21,
44 22, 23, 24, 25, 26, 27, 28, 29,
45 30, 31, 32, 33, 34, 35, 36, 37,
46 38, 39, 40, 41},
47 .oobfree = {
48 {.offset = 2,
49 .length = 4},
50 {.offset = 42,
51 .length = 22}}
52 };
53
54 static struct mtd_partition n526_partitions[] = {
55 { .name = "NAND BOOT partition",
56 .offset = 0 * 0x100000,
57 .size = 4 * 0x100000,
58 },
59 { .name = "NAND KERNEL partition",
60 .offset = 4 * 0x100000,
61 .size = 4 * 0x100000,
62 },
63 { .name = "NAND ROOTFS partition",
64 .offset = 16 * 0x100000,
65 .size = 498 * 0x100000,
66 },
67 };
68
69 static struct jz_nand_platform_data n526_nand_pdata = {
70 .ecc_layout = &n526_ecclayout,
71 .partitions = n526_partitions,
72 .num_partitions = ARRAY_SIZE(n526_partitions),
73 .busy_gpio = 94,
74 };
75
76
77 /* Battery */
78 /*static struct jz_batt_info n526_battery_pdata = {
79 .dc_dect_gpio = GPIO_DC_DETE_N,
80 .usb_dect_gpio = GPIO_USB_DETE,
81 .charg_stat_gpio = GPIO_CHARG_STAT_N,
82
83 .min_voltag = 3600000,
84 .max_voltag = 4200000,
85 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
86 };*/
87
88
89 static struct jz4740_mmc_platform_data n526_mmc_pdata = {
90 .gpio_card_detect = JZ_GPIO_PORTD(7),
91 .card_detect_active_low = 1,
92 .gpio_read_only = -1,
93 .gpio_power = JZ_GPIO_PORTD(17),
94 .power_active_low = 1,
95 };
96
97 static struct gpio_led n526_leds[] = {
98 {
99 .name = "n526:blue:power",
100 .gpio = JZ_GPIO_PORTD(28),
101 .default_state = LEDS_GPIO_DEFSTATE_ON,
102 }
103 };
104
105 static struct gpio_led_platform_data n526_leds_pdata = {
106 .leds = n526_leds,
107 .num_leds = ARRAY_SIZE(n526_leds),
108 };
109
110 static struct platform_device n526_leds_device = {
111 .name = "leds-gpio",
112 .id = -1,
113 .dev = {
114 .platform_data = &n526_leds_pdata,
115 },
116 };
117
118 static void __init board_gpio_setup(void)
119 {
120 /* We only need to enable/disable pullup here for pins used in generic
121 * drivers. Everything else is done by the drivers themselfs. */
122 jz_gpio_disable_pullup(JZ_GPIO_PORTD(17));
123 jz_gpio_enable_pullup(JZ_GPIO_PORTD(7));
124 jz_gpio_disable_pullup(JZ_GPIO_PORTC(19));
125 jz_gpio_disable_pullup(JZ_GPIO_PORTC(20));
126 jz_gpio_disable_pullup(JZ_GPIO_PORTC(21));
127 jz_gpio_disable_pullup(JZ_GPIO_PORTC(23));
128 }
129
130
131 static const int n526_eink_ctrl_gpios[] = {
132 0,
133 JZ_GPIO_PORTC(23),
134 JZ_GPIO_PORTC(19),
135 JZ_GPIO_PORTC(20),
136 };
137
138 static void n526_eink_set_ctl(struct broadsheetfb_par * par, unsigned char ctrl, u8
139 value)
140 {
141 gpio_set_value(n526_eink_ctrl_gpios[ctrl], value);
142 }
143
144
145 static int n526_eink_wait(struct broadsheetfb_par *par)
146 {
147 int i = 0;
148 wait_event(par->waitq, gpio_get_value(JZ_GPIO_PORTB(17)));
149
150 return 0;
151 }
152
153 static u16 n526_eink_get_hdb(struct broadsheetfb_par *par)
154 {
155 u16 value = 0;
156 jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
157 gpio_set_value(JZ_GPIO_PORTC(21), 0);
158 mdelay(100);
159
160 value = jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
161
162 gpio_set_value(JZ_GPIO_PORTC(21), 1);
163 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
164 return value;
165 }
166
167 static void n526_eink_set_hdb(struct broadsheetfb_par *par, u16 value)
168 {
169 jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value, 0xffff);
170 }
171
172 static int n526_eink_init(struct broadsheetfb_par *par)
173 {
174 int i = 0;
175
176 gpio_request(JZ_GPIO_PORTD(1), "display reset?");
177 gpio_direction_output(JZ_GPIO_PORTD(1), 1);
178 mdelay(10);
179 gpio_set_value(JZ_GPIO_PORTD(1), 0);
180
181 gpio_request(JZ_GPIO_PORTB(18), "foobar");
182 gpio_direction_output(JZ_GPIO_PORTB(18), 0);
183
184 gpio_request(JZ_GPIO_PORTB(29), "foobar");
185 gpio_direction_output(JZ_GPIO_PORTB(29), 1);
186
187
188 for(i = 1; i < ARRAY_SIZE(n526_eink_ctrl_gpios); ++i) {
189 gpio_request(n526_eink_ctrl_gpios[i], "foobar");
190 gpio_direction_output(n526_eink_ctrl_gpios[i], 0);
191 }
192
193 gpio_request(JZ_GPIO_PORTC(22), "foobar");
194 gpio_direction_input(JZ_GPIO_PORTC(22));
195 gpio_request(JZ_GPIO_PORTC(21), "foobar");
196 gpio_direction_output(JZ_GPIO_PORTC(21), 1);
197
198 for(i = 0; i < 16; ++i) {
199 gpio_request(JZ_GPIO_PORTC(i), "display data");
200 }
201 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
202
203 gpio_direction_output(JZ_GPIO_PORTB(18), 1);
204
205 return 0;
206 }
207
208 static irqreturn_t n526_eink_busy_irq(int irq, void *devid)
209 {
210 struct broadsheetfb_par *par = devid;
211 wake_up(&par->waitq);
212
213 return IRQ_HANDLED;
214 }
215
216 static int n526_eink_setup_irq(struct fb_info *info)
217 {
218 int ret;
219 struct broadsheetfb_par *par = info->par;
220
221 gpio_request(JZ_GPIO_PORTB(17), "foobar");
222 gpio_direction_input(JZ_GPIO_PORTB(17));
223
224 ret = request_irq(gpio_to_irq(JZ_GPIO_PORTB(17)), n526_eink_busy_irq,
225 IRQF_DISABLED | IRQF_TRIGGER_RISING,
226 "eInk busyline", par);
227 if (ret)
228 printk("n526 display: Failed to request busyline irq: %d\n", ret);
229 return 0;
230 }
231
232 static void n526_eink_cleanup(struct broadsheetfb_par *par)
233 {
234 }
235
236 static struct broadsheet_board broadsheet_pdata = {
237 .owner = THIS_MODULE,
238 .init = n526_eink_init,
239 .wait_for_rdy = n526_eink_wait,
240 .set_ctl = n526_eink_set_ctl,
241 .set_hdb = n526_eink_set_hdb,
242 .get_hdb = n526_eink_get_hdb,
243 .cleanup = n526_eink_cleanup,
244 .setup_irq = n526_eink_setup_irq,
245 };
246
247 static struct platform_device n526_broadsheet_device = {
248 .name = "broadsheetfb",
249 .id = -1,
250 .dev = {
251 .platform_data = &broadsheet_pdata,
252 },
253 };
254
255 static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
256 [0] = {
257 .code = KEY_ENTER,
258 .gpio = 0,
259 .active_low = 1,
260 .desc = "Power",
261 },
262 };
263
264 static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
265 .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
266 .buttons = qi_lb60_gpio_keys_buttons,
267 };
268
269 static struct platform_device qi_lb60_gpio_keys = {
270 .name = "gpio-keys",
271 .id = -1,
272 .dev = {
273 .platform_data = &qi_lb60_gpio_keys_data,
274 }
275 };
276
277 static struct i2c_gpio_platform_data n526_i2c_pdata = {
278 .sda_pin = JZ_GPIO_PORTD(23),
279 .scl_pin = JZ_GPIO_PORTD(24),
280 .udelay = 2,
281 .timeout = 3 * HZ,
282 };
283
284 static struct platform_device n526_i2c_device = {
285 .name = "i2c-gpio",
286 .id = -1,
287 .dev = {
288 .platform_data = &n526_i2c_pdata,
289 },
290 };
291
292 static struct i2c_board_info n526_i2c_board_info = {
293 .type = "n526-lpc",
294 .addr = 0x54,
295 };
296
297
298 static struct platform_device *jz_platform_devices[] __initdata = {
299 &jz4740_usb_ohci_device,
300 &jz4740_usb_gdt_device,
301 &jz4740_mmc_device,
302 &jz4740_nand_device,
303 &jz4740_i2s_device,
304 &jz4740_codec_device,
305 &jz4740_rtc_device,
306 &n526_leds_device,
307 &n526_broadsheet_device,
308 &qi_lb60_gpio_keys,
309 &n526_i2c_device,
310 };
311
312
313 static int __init n526_init_platform_devices(void)
314 {
315
316 jz4740_nand_device.dev.platform_data = &n526_nand_pdata;
317 /* jz4740_battery_device.dev.platform_data = &n526_battery_pdata;*/
318 jz4740_mmc_device.dev.platform_data = &n526_mmc_pdata;
319
320 n526_i2c_board_info.irq = gpio_to_irq(JZ_GPIO_PORTD(14)),
321 i2c_register_board_info(0, &n526_i2c_board_info, 1);
322
323 return platform_add_devices(jz_platform_devices,
324 ARRAY_SIZE(jz_platform_devices));
325
326 }
327
328
329 extern int jz_gpiolib_init(void);
330 extern int jz_init_clocks(unsigned long extal);
331
332 static int __init n526_board_setup(void)
333 {
334 if (jz_gpiolib_init())
335 panic("Failed to initalize jz gpio\n");
336 jz_init_clocks(12000000);
337
338 board_gpio_setup();
339
340 if (n526_init_platform_devices())
341 panic("Failed to initalize platform devices\n");
342
343 return 0;
344 }
345
346 arch_initcall(n526_board_setup);
This page took 0.05698 seconds and 5 git commands to generate.