0e146ac84d5076fc790eea84c434b9aed8a7b647
[openwrt/openwrt.git] / target / linux / xburst / files-2.6.32 / arch / mips / jz4740 / board-n516.c
1 /*
2 * linux/arch/mips/jz4740/board-516.c
3 *
4 * JZ4740 n516 board setup routines.
5 *
6 * Copyright (c) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/ioport.h>
17 #include <linux/mm.h>
18 #include <linux/console.h>
19 #include <linux/delay.h>
20 #include <linux/i2c.h>
21 #include <linux/platform_device.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mmc/jz4740_mmc.h>
24 #include <linux/mtd/jz4740_nand.h>
25 #include <linux/leds.h>
26
27 #include <linux/power_supply.h>
28 #include <linux/power/gpio-charger.h>
29
30 #include <linux/i2c.h>
31 #include <linux/i2c-gpio.h>
32
33 #include <asm/mach-jz4740/board-n516.h>
34 #include <asm/mach-jz4740/platform.h>
35
36 #include "clock.h"
37
38 static long n516_panic_blink(long time)
39 {
40 gpio_set_value(GPIO_LED_ENABLE, 1);
41 mdelay(200);
42 gpio_set_value(GPIO_LED_ENABLE, 0);
43 mdelay(200);
44
45 return 400;
46 }
47
48 static void __init board_gpio_setup(void)
49 {
50 /* jz_gpio_enable_pullup(JZ_GPIO_PORTD(23));
51 jz_gpio_enable_pullup(JZ_GPIO_PORTD(24));*/
52 }
53
54 static struct i2c_gpio_platform_data n516_i2c_pdata = {
55 .sda_pin = JZ_GPIO_PORTD(23),
56 .scl_pin = JZ_GPIO_PORTD(24),
57 .udelay = 2,
58 .timeout = 3 * HZ,
59 };
60
61 static struct platform_device n516_i2c_device = {
62 .name = "i2c-gpio",
63 .id = -1,
64 .dev = {
65 .platform_data = &n516_i2c_pdata,
66 },
67 };
68
69 static const struct i2c_board_info n516_i2c_board_info[] = {
70 {
71 .type = "LPC524",
72 .addr = 0x54,
73 },
74 {
75 .type = "lm75a",
76 .addr = 0x48,
77 }
78 };
79
80 static struct jz4740_mmc_platform_data n516_mmc_pdata = {
81 .gpio_card_detect = GPIO_SD_CD_N,
82 .card_detect_active_low = 1,
83 .gpio_read_only = -1,
84 .gpio_power = GPIO_SD_VCC_EN_N,
85 .power_active_low = 1,
86 };
87
88 static struct gpio_led n516_leds[] = {
89 {
90 .name = "n516:blue:power",
91 .gpio = GPIO_LED_ENABLE,
92 .default_state = LEDS_GPIO_DEFSTATE_ON,
93 .default_trigger = "nand-disk",
94 }
95 };
96
97 static struct gpio_led_platform_data n516_leds_pdata = {
98 .leds = n516_leds,
99 .num_leds = ARRAY_SIZE(n516_leds),
100 };
101
102 static struct platform_device n516_leds_device = {
103 .name = "leds-gpio",
104 .id = -1,
105 .dev = {
106 .platform_data = &n516_leds_pdata,
107 },
108 };
109
110 static struct mtd_partition n516_partitions[] = {
111 { .name = "NAND BOOT partition",
112 .offset = 0 * 0x100000,
113 .size = 4 * 0x100000,
114 },
115 { .name = "NAND KERNEL partition",
116 .offset = 4 * 0x100000,
117 .size = 4 * 0x100000,
118 },
119 { .name = "NAND ROOTFS partition",
120 .offset = 8 * 0x100000,
121 .size = 504 * 0x100000,
122 },
123 };
124
125 static struct nand_ecclayout n516_ecclayout = {
126 .eccbytes = 36,
127 .eccpos = {
128 6, 7, 8, 9, 10, 11, 12, 13, 14,
129 15, 16, 17, 18, 19, 20, 21, 22, 23,
130 24, 25, 26, 27, 28, 29, 30, 31, 32,
131 33, 34, 35, 36, 37, 38, 39, 40, 41,
132 },
133 .oobfree = {
134 {.offset = 2,
135 .length = 4},
136 {.offset = 42,
137 .length = 22}}
138 };
139
140 static struct jz_nand_platform_data n516_nand_pdata = {
141 .ecc_layout = &n516_ecclayout,
142 .partitions = n516_partitions,
143 .num_partitions = ARRAY_SIZE(n516_partitions),
144 .busy_gpio = 94,
145 };
146
147 static char *n516_batteries[] = {
148 "n516_battery",
149 };
150
151 static struct gpio_charger_platform_data n516_charger_pdata = {
152 .name = "usb",
153 .type = POWER_SUPPLY_TYPE_USB,
154 .gpio = GPIO_USB_DETECT,
155 .gpio_active_low = 1,
156 .batteries = n516_batteries,
157 .num_batteries = ARRAY_SIZE(n516_batteries),
158 };
159
160 static struct platform_device n516_charger_device = {
161 .name = "gpio-charger",
162 .dev = {
163 .platform_data = &n516_charger_pdata,
164 },
165 };
166
167 static struct platform_device *n516_devices[] __initdata = {
168 &jz4740_nand_device,
169 &n516_leds_device,
170 &jz4740_mmc_device,
171 &jz4740_i2s_device,
172 &jz4740_codec_device,
173 &jz4740_rtc_device,
174 &jz4740_usb_gdt_device,
175 &n516_i2c_device,
176 &n516_charger_device,
177 };
178
179 struct jz4740_clock_board_data jz4740_clock_bdata = {
180 .ext_rate = 12000000,
181 .rtc_rate = 32768,
182 };
183
184 extern int jz_gpiolib_init(void);
185
186 static int n516_setup_platform(void)
187 {
188 if (jz_gpiolib_init())
189 panic("Failed to initalize jz gpio\n");
190
191 jz4740_clock_init();
192 board_gpio_setup();
193
194 panic_blink = n516_panic_blink;
195 i2c_register_board_info(0, n516_i2c_board_info, ARRAY_SIZE(n516_i2c_board_info));
196 jz4740_mmc_device.dev.platform_data = &n516_mmc_pdata;
197 jz4740_nand_device.dev.platform_data = &n516_nand_pdata;
198
199 return platform_add_devices(n516_devices, ARRAY_SIZE(n516_devices));
200 }
201 arch_initcall(n516_setup_platform);