1/*
2 * DM355 leopard board support
3 *
4 * Based on board-dm355-evm.c
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/err.h>
13#include <linux/platform_device.h>
14#include <linux/mtd/mtd.h>
15#include <linux/mtd/partitions.h>
16#include <linux/mtd/rawnand.h>
17#include <linux/i2c.h>
18#include <linux/gpio.h>
19#include <linux/clk.h>
20#include <linux/spi/spi.h>
21#include <linux/spi/eeprom.h>
22#include <linux/platform_data/i2c-davinci.h>
23#include <linux/platform_data/mmc-davinci.h>
24#include <linux/platform_data/mtd-davinci.h>
25#include <linux/platform_data/usb-davinci.h>
26
27#include <asm/mach-types.h>
28#include <asm/mach/arch.h>
29
30#include <mach/common.h>
31#include <mach/serial.h>
32
33#include "davinci.h"
34
35/* NOTE:  this is geared for the standard config, with a socketed
36 * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors.  If you
37 * swap chips, maybe with a different block size, partitioning may
38 * need to be changed.
39 */
40#define NAND_BLOCK_SIZE		SZ_128K
41
42static struct mtd_partition davinci_nand_partitions[] = {
43	{
44		/* UBL (a few copies) plus U-Boot */
45		.name		= "bootloader",
46		.offset		= 0,
47		.size		= 15 * NAND_BLOCK_SIZE,
48		.mask_flags	= MTD_WRITEABLE, /* force read-only */
49	}, {
50		/* U-Boot environment */
51		.name		= "params",
52		.offset		= MTDPART_OFS_APPEND,
53		.size		= 1 * NAND_BLOCK_SIZE,
54		.mask_flags	= 0,
55	}, {
56		.name		= "kernel",
57		.offset		= MTDPART_OFS_APPEND,
58		.size		= SZ_4M,
59		.mask_flags	= 0,
60	}, {
61		.name		= "filesystem1",
62		.offset		= MTDPART_OFS_APPEND,
63		.size		= SZ_512M,
64		.mask_flags	= 0,
65	}, {
66		.name		= "filesystem2",
67		.offset		= MTDPART_OFS_APPEND,
68		.size		= MTDPART_SIZ_FULL,
69		.mask_flags	= 0,
70	}
71	/* two blocks with bad block table (and mirror) at the end */
72};
73
74static struct davinci_nand_pdata davinci_nand_data = {
75	.core_chipsel		= 0,
76	.mask_chipsel		= BIT(14),
77	.parts			= davinci_nand_partitions,
78	.nr_parts		= ARRAY_SIZE(davinci_nand_partitions),
79	.engine_type		= NAND_ECC_ENGINE_TYPE_ON_HOST,
80	.ecc_placement		= NAND_ECC_PLACEMENT_INTERLEAVED,
81	.ecc_bits		= 4,
82	.bbt_options		= NAND_BBT_USE_FLASH,
83};
84
85static struct resource davinci_nand_resources[] = {
86	{
87		.start		= DM355_ASYNC_EMIF_DATA_CE0_BASE,
88		.end		= DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
89		.flags		= IORESOURCE_MEM,
90	}, {
91		.start		= DM355_ASYNC_EMIF_CONTROL_BASE,
92		.end		= DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
93		.flags		= IORESOURCE_MEM,
94	},
95};
96
97static struct platform_device davinci_nand_device = {
98	.name			= "davinci_nand",
99	.id			= 0,
100
101	.num_resources		= ARRAY_SIZE(davinci_nand_resources),
102	.resource		= davinci_nand_resources,
103
104	.dev			= {
105		.platform_data	= &davinci_nand_data,
106	},
107};
108
109static struct davinci_i2c_platform_data i2c_pdata = {
110	.bus_freq	= 400	/* kHz */,
111	.bus_delay	= 0	/* usec */,
112};
113
114static int leopard_mmc_gpio = -EINVAL;
115
116static void dm355leopard_mmcsd_gpios(unsigned gpio)
117{
118	gpio_request(gpio + 0, "mmc0_ro");
119	gpio_request(gpio + 1, "mmc0_cd");
120	gpio_request(gpio + 2, "mmc1_ro");
121	gpio_request(gpio + 3, "mmc1_cd");
122
123	/* we "know" these are input-only so we don't
124	 * need to call gpio_direction_input()
125	 */
126
127	leopard_mmc_gpio = gpio;
128}
129
130static struct i2c_board_info dm355leopard_i2c_info[] = {
131	{ I2C_BOARD_INFO("dm355leopard_msp", 0x25),
132		.platform_data = dm355leopard_mmcsd_gpios,
133		/* plus irq */ },
134	/* { I2C_BOARD_INFO("tlv320aic3x", 0x1b), }, */
135	/* { I2C_BOARD_INFO("tvp5146", 0x5d), }, */
136};
137
138static void __init leopard_init_i2c(void)
139{
140	davinci_init_i2c(&i2c_pdata);
141
142	gpio_request(5, "dm355leopard_msp");
143	gpio_direction_input(5);
144	dm355leopard_i2c_info[0].irq = gpio_to_irq(5);
145
146	i2c_register_board_info(1, dm355leopard_i2c_info,
147			ARRAY_SIZE(dm355leopard_i2c_info));
148}
149
150static struct resource dm355leopard_dm9000_rsrc[] = {
151	{
152		/* addr */
153		.start	= 0x04000000,
154		.end	= 0x04000001,
155		.flags	= IORESOURCE_MEM,
156	}, {
157		/* data */
158		.start	= 0x04000016,
159		.end	= 0x04000017,
160		.flags	= IORESOURCE_MEM,
161	}, {
162		.flags	= IORESOURCE_IRQ
163			| IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
164	},
165};
166
167static struct platform_device dm355leopard_dm9000 = {
168	.name		= "dm9000",
169	.id		= -1,
170	.resource	= dm355leopard_dm9000_rsrc,
171	.num_resources	= ARRAY_SIZE(dm355leopard_dm9000_rsrc),
172};
173
174static struct platform_device *davinci_leopard_devices[] __initdata = {
175	&dm355leopard_dm9000,
176	&davinci_nand_device,
177};
178
179static void __init dm355_leopard_map_io(void)
180{
181	dm355_init();
182}
183
184static int dm355leopard_mmc_get_cd(int module)
185{
186	if (!gpio_is_valid(leopard_mmc_gpio))
187		return -ENXIO;
188	/* low == card present */
189	return !gpio_get_value_cansleep(leopard_mmc_gpio + 2 * module + 1);
190}
191
192static int dm355leopard_mmc_get_ro(int module)
193{
194	if (!gpio_is_valid(leopard_mmc_gpio))
195		return -ENXIO;
196	/* high == card's write protect switch active */
197	return gpio_get_value_cansleep(leopard_mmc_gpio + 2 * module + 0);
198}
199
200static struct davinci_mmc_config dm355leopard_mmc_config = {
201	.get_cd		= dm355leopard_mmc_get_cd,
202	.get_ro		= dm355leopard_mmc_get_ro,
203	.wires		= 4,
204	.max_freq       = 50000000,
205	.caps           = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
206};
207
208/* Don't connect anything to J10 unless you're only using USB host
209 * mode *and* have to do so with some kind of gender-bender.  If
210 * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
211 * the ID pin won't need any help.
212 */
213#define USB_ID_VALUE	1	/* ID pulled low */
214
215static struct spi_eeprom at25640a = {
216	.byte_len	= SZ_64K / 8,
217	.name		= "at25640a",
218	.page_size	= 32,
219	.flags		= EE_ADDR2,
220};
221
222static const struct spi_board_info dm355_leopard_spi_info[] __initconst = {
223	{
224		.modalias	= "at25",
225		.platform_data	= &at25640a,
226		.max_speed_hz	= 10 * 1000 * 1000,	/* at 3v3 */
227		.bus_num	= 0,
228		.chip_select	= 0,
229		.mode		= SPI_MODE_0,
230	},
231};
232
233static __init void dm355_leopard_init(void)
234{
235	struct clk *aemif;
236	int ret;
237
238	dm355_register_clocks();
239
240	ret = dm355_gpio_register();
241	if (ret)
242		pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
243
244	gpio_request(9, "dm9000");
245	gpio_direction_input(9);
246	dm355leopard_dm9000_rsrc[2].start = gpio_to_irq(9);
247
248	aemif = clk_get(&dm355leopard_dm9000.dev, "aemif");
249	if (!WARN(IS_ERR(aemif), "unable to get AEMIF clock\n"))
250		clk_prepare_enable(aemif);
251
252	platform_add_devices(davinci_leopard_devices,
253			     ARRAY_SIZE(davinci_leopard_devices));
254	leopard_init_i2c();
255	davinci_serial_init(dm355_serial_device);
256
257	/* NOTE:  NAND flash timings set by the UBL are slower than
258	 * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
259	 * but could be 0x0400008c for about 25% faster page reads.
260	 */
261
262	gpio_request(2, "usb_id_toggle");
263	gpio_direction_output(2, USB_ID_VALUE);
264	/* irlml6401 switches over 1A in under 8 msec */
265	davinci_setup_usb(1000, 8);
266
267	davinci_setup_mmc(0, &dm355leopard_mmc_config);
268	davinci_setup_mmc(1, &dm355leopard_mmc_config);
269
270	dm355_init_spi0(BIT(0), dm355_leopard_spi_info,
271			ARRAY_SIZE(dm355_leopard_spi_info));
272}
273
274MACHINE_START(DM355_LEOPARD, "DaVinci DM355 leopard")
275	.atag_offset  = 0x100,
276	.map_io	      = dm355_leopard_map_io,
277	.init_irq     = dm355_init_irq,
278	.init_time	= dm355_init_time,
279	.init_machine = dm355_leopard_init,
280	.init_late	= davinci_init_late,
281	.dma_zone_size	= SZ_128M,
282MACHINE_END
283