summaryrefslogtreecommitdiffstats
path: root/target/linux/xburst/files-2.6.32/arch/mips/jz4740/board-n516.c
blob: 0e146ac84d5076fc790eea84c434b9aed8a7b647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * linux/arch/mips/jz4740/board-516.c
 *
 * JZ4740 n516 board setup routines.
 *
 * Copyright (c) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/init.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/mm.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/mtd/mtd.h>
#include <linux/mmc/jz4740_mmc.h>
#include <linux/mtd/jz4740_nand.h>
#include <linux/leds.h>

#include <linux/power_supply.h>
#include <linux/power/gpio-charger.h>

#include <linux/i2c.h>
#include <linux/i2c-gpio.h>

#include <asm/mach-jz4740/board-n516.h>
#include <asm/mach-jz4740/platform.h>

#include "clock.h"

static long n516_panic_blink(long time)
{
	gpio_set_value(GPIO_LED_ENABLE, 1);
	mdelay(200);
	gpio_set_value(GPIO_LED_ENABLE, 0);
	mdelay(200);

	return 400;
}

static void __init board_gpio_setup(void)
{
/*	jz_gpio_enable_pullup(JZ_GPIO_PORTD(23));
	jz_gpio_enable_pullup(JZ_GPIO_PORTD(24));*/
}

static struct i2c_gpio_platform_data n516_i2c_pdata = {
	.sda_pin = JZ_GPIO_PORTD(23),
	.scl_pin = JZ_GPIO_PORTD(24),
	.udelay = 2,
	.timeout = 3 * HZ,
};

static struct platform_device n516_i2c_device = {
	.name = "i2c-gpio",
	.id = -1,
	.dev = {
		.platform_data = &n516_i2c_pdata,
	},
};

static const struct i2c_board_info n516_i2c_board_info[] = {
	{
		.type		= "LPC524",
		.addr		= 0x54,
	},
	{
		.type		= "lm75a",
		.addr		= 0x48,
	}
};

static struct jz4740_mmc_platform_data n516_mmc_pdata = {
	.gpio_card_detect	= GPIO_SD_CD_N,
	.card_detect_active_low = 1,
	.gpio_read_only		= -1,
	.gpio_power		= GPIO_SD_VCC_EN_N,
	.power_active_low = 1,
};

static struct gpio_led n516_leds[] = {
	{
		.name = "n516:blue:power",
		.gpio = GPIO_LED_ENABLE,
		.default_state = LEDS_GPIO_DEFSTATE_ON,
		.default_trigger = "nand-disk",
	}
};

static struct gpio_led_platform_data n516_leds_pdata = {
	.leds = n516_leds,
	.num_leds = ARRAY_SIZE(n516_leds),
};

static struct platform_device n516_leds_device = {
	.name = "leds-gpio",
	.id = -1,
	.dev = {
		.platform_data = &n516_leds_pdata,
	},
};

static struct mtd_partition n516_partitions[] = {
	{ .name = "NAND BOOT partition",
	  .offset = 0 * 0x100000,
	  .size = 4 * 0x100000,
 	},
	{ .name = "NAND KERNEL partition",
	  .offset = 4 * 0x100000,
	  .size = 4 * 0x100000,
 	},
	{ .name = "NAND ROOTFS partition",
	  .offset = 8 * 0x100000,
	  .size = 504 * 0x100000,
 	},
};

static struct nand_ecclayout n516_ecclayout = {
	.eccbytes = 36,
	.eccpos = {
		 6,  7,  8,  9, 10, 11, 12, 13, 14,
		15, 16, 17, 18, 19, 20, 21, 22, 23,
		24, 25, 26, 27, 28, 29, 30, 31, 32,
		33, 34, 35, 36, 37, 38, 39, 40, 41,
	},
	.oobfree = {
		{.offset = 2,
		 .length = 4},
		{.offset = 42,
		 .length = 22}}
};

static struct jz_nand_platform_data n516_nand_pdata = {
	.ecc_layout = &n516_ecclayout,
	.partitions = n516_partitions,
	.num_partitions = ARRAY_SIZE(n516_partitions),
	.busy_gpio = 94,
};

static char *n516_batteries[] = {
	"n516_battery",
};

static struct gpio_charger_platform_data n516_charger_pdata = {
	.name = "usb",
	.type = POWER_SUPPLY_TYPE_USB,
	.gpio = GPIO_USB_DETECT,
	.gpio_active_low = 1,
	.batteries = n516_batteries,
	.num_batteries = ARRAY_SIZE(n516_batteries),
};

static struct platform_device n516_charger_device = {
	.name = "gpio-charger",
	.dev = {
		.platform_data = &n516_charger_pdata,
	},
};

static struct platform_device *n516_devices[] __initdata = {
	&jz4740_nand_device,
	&n516_leds_device,
	&jz4740_mmc_device,
	&jz4740_i2s_device,
	&jz4740_codec_device,
	&jz4740_rtc_device,
	&jz4740_usb_gdt_device,
	&n516_i2c_device,
	&n516_charger_device,
};

struct jz4740_clock_board_data jz4740_clock_bdata = {
	.ext_rate = 12000000,
	.rtc_rate = 32768,
};

extern int jz_gpiolib_init(void);

static int n516_setup_platform(void)
{
	if (jz_gpiolib_init())
		panic("Failed to initalize jz gpio\n");

	jz4740_clock_init();
	board_gpio_setup();

	panic_blink = n516_panic_blink;
	i2c_register_board_info(0, n516_i2c_board_info, ARRAY_SIZE(n516_i2c_board_info));
	jz4740_mmc_device.dev.platform_data = &n516_mmc_pdata;
	jz4740_nand_device.dev.platform_data = &n516_nand_pdata;

	return platform_add_devices(n516_devices, ARRAY_SIZE(n516_devices));
}
arch_initcall(n516_setup_platform);