1 /*
2  * linux/arch/arm/mach-omap2/board-am3517evm.c
3  *
4  * Copyright (C) 2009 Texas Instruments Incorporated
5  * Author: Ranjith Lohithakshan <ranjithl@ti.com>
6  *
7  * Based on mach-omap2/board-omap3evm.c
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as  published by the
11  * Free Software Foundation version 2.
12  *
13  * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
14  * whether express or implied; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  */
18 
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/clk.h>
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
24 #include <linux/i2c/pca953x.h>
25 #include <linux/can/platform/ti_hecc.h>
26 #include <linux/davinci_emac.h>
27 #include <linux/mmc/host.h>
28 
29 #include <mach/hardware.h>
30 #include <mach/am35xx.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 
35 #include <plat/board.h>
36 #include "common.h"
37 #include <plat/usb.h>
38 #include <video/omapdss.h>
39 #include <video/omap-panel-generic-dpi.h>
40 #include <video/omap-panel-dvi.h>
41 
42 #include "mux.h"
43 #include "control.h"
44 #include "hsmmc.h"
45 
46 #define AM35XX_EVM_MDIO_FREQUENCY	(1000000)
47 
48 static struct mdio_platform_data am3517_evm_mdio_pdata = {
49 	.bus_freq	= AM35XX_EVM_MDIO_FREQUENCY,
50 };
51 
52 static struct resource am3517_mdio_resources[] = {
53 	{
54 		.start  = AM35XX_IPSS_EMAC_BASE + AM35XX_EMAC_MDIO_OFFSET,
55 		.end    = AM35XX_IPSS_EMAC_BASE + AM35XX_EMAC_MDIO_OFFSET +
56 			  SZ_4K - 1,
57 		.flags  = IORESOURCE_MEM,
58 	},
59 };
60 
61 static struct platform_device am3517_mdio_device = {
62 	.name		= "davinci_mdio",
63 	.id		= 0,
64 	.num_resources	= ARRAY_SIZE(am3517_mdio_resources),
65 	.resource	= am3517_mdio_resources,
66 	.dev.platform_data = &am3517_evm_mdio_pdata,
67 };
68 
69 static struct emac_platform_data am3517_evm_emac_pdata = {
70 	.rmii_en	= 1,
71 };
72 
73 static struct resource am3517_emac_resources[] = {
74 	{
75 		.start  = AM35XX_IPSS_EMAC_BASE,
76 		.end    = AM35XX_IPSS_EMAC_BASE + 0x2FFFF,
77 		.flags  = IORESOURCE_MEM,
78 	},
79 	{
80 		.start  = INT_35XX_EMAC_C0_RXTHRESH_IRQ,
81 		.end    = INT_35XX_EMAC_C0_RXTHRESH_IRQ,
82 		.flags  = IORESOURCE_IRQ,
83 	},
84 	{
85 		.start  = INT_35XX_EMAC_C0_RX_PULSE_IRQ,
86 		.end    = INT_35XX_EMAC_C0_RX_PULSE_IRQ,
87 		.flags  = IORESOURCE_IRQ,
88 	},
89 	{
90 		.start  = INT_35XX_EMAC_C0_TX_PULSE_IRQ,
91 		.end    = INT_35XX_EMAC_C0_TX_PULSE_IRQ,
92 		.flags  = IORESOURCE_IRQ,
93 	},
94 	{
95 		.start  = INT_35XX_EMAC_C0_MISC_PULSE_IRQ,
96 		.end    = INT_35XX_EMAC_C0_MISC_PULSE_IRQ,
97 		.flags  = IORESOURCE_IRQ,
98 	},
99 };
100 
101 static struct platform_device am3517_emac_device = {
102 	.name		= "davinci_emac",
103 	.id		= -1,
104 	.num_resources	= ARRAY_SIZE(am3517_emac_resources),
105 	.resource	= am3517_emac_resources,
106 };
107 
am3517_enable_ethernet_int(void)108 static void am3517_enable_ethernet_int(void)
109 {
110 	u32 regval;
111 
112 	regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
113 	regval = (regval | AM35XX_CPGMAC_C0_RX_PULSE_CLR |
114 		AM35XX_CPGMAC_C0_TX_PULSE_CLR |
115 		AM35XX_CPGMAC_C0_MISC_PULSE_CLR |
116 		AM35XX_CPGMAC_C0_RX_THRESH_CLR);
117 	omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
118 	regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
119 }
120 
am3517_disable_ethernet_int(void)121 static void am3517_disable_ethernet_int(void)
122 {
123 	u32 regval;
124 
125 	regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
126 	regval = (regval | AM35XX_CPGMAC_C0_RX_PULSE_CLR |
127 		AM35XX_CPGMAC_C0_TX_PULSE_CLR);
128 	omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
129 	regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
130 }
131 
am3517_evm_ethernet_init(struct emac_platform_data * pdata)132 static void am3517_evm_ethernet_init(struct emac_platform_data *pdata)
133 {
134 	unsigned int regval;
135 
136 	pdata->ctrl_reg_offset		= AM35XX_EMAC_CNTRL_OFFSET;
137 	pdata->ctrl_mod_reg_offset	= AM35XX_EMAC_CNTRL_MOD_OFFSET;
138 	pdata->ctrl_ram_offset		= AM35XX_EMAC_CNTRL_RAM_OFFSET;
139 	pdata->ctrl_ram_size		= AM35XX_EMAC_CNTRL_RAM_SIZE;
140 	pdata->version			= EMAC_VERSION_2;
141 	pdata->hw_ram_addr		= AM35XX_EMAC_HW_RAM_ADDR;
142 	pdata->interrupt_enable		= am3517_enable_ethernet_int;
143 	pdata->interrupt_disable	= am3517_disable_ethernet_int;
144 	am3517_emac_device.dev.platform_data	= pdata;
145 	platform_device_register(&am3517_emac_device);
146 	platform_device_register(&am3517_mdio_device);
147 	clk_add_alias(NULL, dev_name(&am3517_mdio_device.dev),
148 		      NULL, &am3517_emac_device.dev);
149 
150 	regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
151 	regval = regval & (~(AM35XX_CPGMACSS_SW_RST));
152 	omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
153 	regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
154 
155 	return ;
156 }
157 
158 
159 
160 #define LCD_PANEL_PWR		176
161 #define LCD_PANEL_BKLIGHT_PWR	182
162 #define LCD_PANEL_PWM		181
163 
164 static struct i2c_board_info __initdata am3517evm_i2c1_boardinfo[] = {
165 	{
166 		I2C_BOARD_INFO("s35390a", 0x30),
167 	},
168 };
169 
170 /*
171  * RTC - S35390A
172  */
173 #define GPIO_RTCS35390A_IRQ	55
174 
am3517_evm_rtc_init(void)175 static void __init am3517_evm_rtc_init(void)
176 {
177 	int r;
178 
179 	omap_mux_init_gpio(GPIO_RTCS35390A_IRQ, OMAP_PIN_INPUT_PULLUP);
180 
181 	r = gpio_request_one(GPIO_RTCS35390A_IRQ, GPIOF_IN, "rtcs35390a-irq");
182 	if (r < 0) {
183 		printk(KERN_WARNING "failed to request GPIO#%d\n",
184 				GPIO_RTCS35390A_IRQ);
185 		return;
186 	}
187 
188 	am3517evm_i2c1_boardinfo[0].irq = gpio_to_irq(GPIO_RTCS35390A_IRQ);
189 }
190 
191 /*
192  * I2C GPIO Expander - TCA6416
193  */
194 
195 /* Mounted on Base-Board */
196 static struct pca953x_platform_data am3517evm_gpio_expander_info_0 = {
197 	.gpio_base	= OMAP_MAX_GPIO_LINES,
198 };
199 static struct i2c_board_info __initdata am3517evm_i2c2_boardinfo[] = {
200 	{
201 		I2C_BOARD_INFO("tlv320aic23", 0x1A),
202 	},
203 	{
204 		I2C_BOARD_INFO("tca6416", 0x21),
205 		.platform_data = &am3517evm_gpio_expander_info_0,
206 	},
207 };
208 
209 /* Mounted on UI Card */
210 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_1 = {
211 	.gpio_base	= OMAP_MAX_GPIO_LINES + 16,
212 };
213 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_2 = {
214 	.gpio_base	= OMAP_MAX_GPIO_LINES + 32,
215 };
216 static struct i2c_board_info __initdata am3517evm_i2c3_boardinfo[] = {
217 	{
218 		I2C_BOARD_INFO("tca6416", 0x20),
219 		.platform_data = &am3517evm_ui_gpio_expander_info_1,
220 	},
221 	{
222 		I2C_BOARD_INFO("tca6416", 0x21),
223 		.platform_data = &am3517evm_ui_gpio_expander_info_2,
224 	},
225 };
226 
am3517_evm_i2c_init(void)227 static int __init am3517_evm_i2c_init(void)
228 {
229 	omap_register_i2c_bus(1, 400, NULL, 0);
230 	omap_register_i2c_bus(2, 400, am3517evm_i2c2_boardinfo,
231 			ARRAY_SIZE(am3517evm_i2c2_boardinfo));
232 	omap_register_i2c_bus(3, 400, am3517evm_i2c3_boardinfo,
233 			ARRAY_SIZE(am3517evm_i2c3_boardinfo));
234 
235 	return 0;
236 }
237 
238 static int lcd_enabled;
239 static int dvi_enabled;
240 
241 #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \
242 		defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE)
243 static struct gpio am3517_evm_dss_gpios[] __initdata = {
244 	/* GPIO 182 = LCD Backlight Power */
245 	{ LCD_PANEL_BKLIGHT_PWR, GPIOF_OUT_INIT_HIGH, "lcd_backlight_pwr" },
246 	/* GPIO 181 = LCD Panel PWM */
247 	{ LCD_PANEL_PWM,	 GPIOF_OUT_INIT_HIGH, "lcd bl enable"	  },
248 	/* GPIO 176 = LCD Panel Power enable pin */
249 	{ LCD_PANEL_PWR,	 GPIOF_OUT_INIT_HIGH, "dvi enable"	  },
250 };
251 
am3517_evm_display_init(void)252 static void __init am3517_evm_display_init(void)
253 {
254 	int r;
255 
256 	omap_mux_init_gpio(LCD_PANEL_PWR, OMAP_PIN_INPUT_PULLUP);
257 	omap_mux_init_gpio(LCD_PANEL_BKLIGHT_PWR, OMAP_PIN_INPUT_PULLDOWN);
258 	omap_mux_init_gpio(LCD_PANEL_PWM, OMAP_PIN_INPUT_PULLDOWN);
259 
260 	r = gpio_request_array(am3517_evm_dss_gpios,
261 			       ARRAY_SIZE(am3517_evm_dss_gpios));
262 	if (r) {
263 		printk(KERN_ERR "failed to get DSS panel control GPIOs\n");
264 		return;
265 	}
266 
267 	printk(KERN_INFO "Display initialized successfully\n");
268 }
269 #else
am3517_evm_display_init(void)270 static void __init am3517_evm_display_init(void) {}
271 #endif
272 
am3517_evm_panel_enable_lcd(struct omap_dss_device * dssdev)273 static int am3517_evm_panel_enable_lcd(struct omap_dss_device *dssdev)
274 {
275 	if (dvi_enabled) {
276 		printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
277 		return -EINVAL;
278 	}
279 	gpio_set_value(LCD_PANEL_PWR, 1);
280 	lcd_enabled = 1;
281 
282 	return 0;
283 }
284 
am3517_evm_panel_disable_lcd(struct omap_dss_device * dssdev)285 static void am3517_evm_panel_disable_lcd(struct omap_dss_device *dssdev)
286 {
287 	gpio_set_value(LCD_PANEL_PWR, 0);
288 	lcd_enabled = 0;
289 }
290 
291 static struct panel_generic_dpi_data lcd_panel = {
292 	.name			= "sharp_lq",
293 	.platform_enable	= am3517_evm_panel_enable_lcd,
294 	.platform_disable	= am3517_evm_panel_disable_lcd,
295 };
296 
297 static struct omap_dss_device am3517_evm_lcd_device = {
298 	.type			= OMAP_DISPLAY_TYPE_DPI,
299 	.name			= "lcd",
300 	.driver_name		= "generic_dpi_panel",
301 	.data			= &lcd_panel,
302 	.phy.dpi.data_lines 	= 16,
303 };
304 
am3517_evm_panel_enable_tv(struct omap_dss_device * dssdev)305 static int am3517_evm_panel_enable_tv(struct omap_dss_device *dssdev)
306 {
307 	return 0;
308 }
309 
am3517_evm_panel_disable_tv(struct omap_dss_device * dssdev)310 static void am3517_evm_panel_disable_tv(struct omap_dss_device *dssdev)
311 {
312 }
313 
314 static struct omap_dss_device am3517_evm_tv_device = {
315 	.type 			= OMAP_DISPLAY_TYPE_VENC,
316 	.name 			= "tv",
317 	.driver_name		= "venc",
318 	.phy.venc.type		= OMAP_DSS_VENC_TYPE_SVIDEO,
319 	.platform_enable	= am3517_evm_panel_enable_tv,
320 	.platform_disable	= am3517_evm_panel_disable_tv,
321 };
322 
am3517_evm_panel_enable_dvi(struct omap_dss_device * dssdev)323 static int am3517_evm_panel_enable_dvi(struct omap_dss_device *dssdev)
324 {
325 	if (lcd_enabled) {
326 		printk(KERN_ERR "cannot enable DVI, LCD is enabled\n");
327 		return -EINVAL;
328 	}
329 	dvi_enabled = 1;
330 
331 	return 0;
332 }
333 
am3517_evm_panel_disable_dvi(struct omap_dss_device * dssdev)334 static void am3517_evm_panel_disable_dvi(struct omap_dss_device *dssdev)
335 {
336 	dvi_enabled = 0;
337 }
338 
339 static struct panel_dvi_platform_data dvi_panel = {
340 	.platform_enable	= am3517_evm_panel_enable_dvi,
341 	.platform_disable	= am3517_evm_panel_disable_dvi,
342 };
343 
344 static struct omap_dss_device am3517_evm_dvi_device = {
345 	.type			= OMAP_DISPLAY_TYPE_DPI,
346 	.name			= "dvi",
347 	.driver_name		= "dvi",
348 	.data			= &dvi_panel,
349 	.phy.dpi.data_lines	= 24,
350 };
351 
352 static struct omap_dss_device *am3517_evm_dss_devices[] = {
353 	&am3517_evm_lcd_device,
354 	&am3517_evm_tv_device,
355 	&am3517_evm_dvi_device,
356 };
357 
358 static struct omap_dss_board_info am3517_evm_dss_data = {
359 	.num_devices	= ARRAY_SIZE(am3517_evm_dss_devices),
360 	.devices	= am3517_evm_dss_devices,
361 	.default_device	= &am3517_evm_lcd_device,
362 };
363 
364 /*
365  * Board initialization
366  */
367 
368 static struct omap_musb_board_data musb_board_data = {
369 	.interface_type         = MUSB_INTERFACE_ULPI,
370 	.mode                   = MUSB_OTG,
371 	.power                  = 500,
372 	.set_phy_power		= am35x_musb_phy_power,
373 	.clear_irq		= am35x_musb_clear_irq,
374 	.set_mode		= am35x_set_mode,
375 	.reset			= am35x_musb_reset,
376 };
377 
am3517_evm_musb_init(void)378 static __init void am3517_evm_musb_init(void)
379 {
380 	u32 devconf2;
381 
382 	/*
383 	 * Set up USB clock/mode in the DEVCONF2 register.
384 	 */
385 	devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
386 
387 	/* USB2.0 PHY reference clock is 13 MHz */
388 	devconf2 &= ~(CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE);
389 	devconf2 |=  CONF2_REFFREQ_13MHZ | CONF2_SESENDEN | CONF2_VBDTCTEN
390 			| CONF2_DATPOL;
391 
392 	omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
393 
394 	usb_musb_init(&musb_board_data);
395 }
396 
397 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
398 	.port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
399 #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \
400 		defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE)
401 	.port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
402 #else
403 	.port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
404 #endif
405 	.port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
406 
407 	.phy_reset  = true,
408 	.reset_gpio_port[0]  = 57,
409 	.reset_gpio_port[1]  = -EINVAL,
410 	.reset_gpio_port[2]  = -EINVAL
411 };
412 
413 #ifdef CONFIG_OMAP_MUX
414 static struct omap_board_mux board_mux[] __initdata = {
415 	/* USB OTG DRVVBUS offset = 0x212 */
416 	OMAP3_MUX(SAD2D_MCAD23, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLDOWN),
417 	{ .reg_offset = OMAP_MUX_TERMINATOR },
418 };
419 #endif
420 
421 
422 static struct resource am3517_hecc_resources[] = {
423 	{
424 		.start	= AM35XX_IPSS_HECC_BASE,
425 		.end	= AM35XX_IPSS_HECC_BASE + 0x3FFF,
426 		.flags	= IORESOURCE_MEM,
427 	},
428 	{
429 		.start	= INT_35XX_HECC0_IRQ,
430 		.end	= INT_35XX_HECC0_IRQ,
431 		.flags	= IORESOURCE_IRQ,
432 	},
433 };
434 
435 static struct platform_device am3517_hecc_device = {
436 	.name		= "ti_hecc",
437 	.id		= -1,
438 	.num_resources	= ARRAY_SIZE(am3517_hecc_resources),
439 	.resource	= am3517_hecc_resources,
440 };
441 
442 static struct ti_hecc_platform_data am3517_evm_hecc_pdata = {
443 	.scc_hecc_offset	= AM35XX_HECC_SCC_HECC_OFFSET,
444 	.scc_ram_offset		= AM35XX_HECC_SCC_RAM_OFFSET,
445 	.hecc_ram_offset	= AM35XX_HECC_RAM_OFFSET,
446 	.mbx_offset		= AM35XX_HECC_MBOX_OFFSET,
447 	.int_line		= AM35XX_HECC_INT_LINE,
448 	.version		= AM35XX_HECC_VERSION,
449 };
450 
am3517_evm_hecc_init(struct ti_hecc_platform_data * pdata)451 static void am3517_evm_hecc_init(struct ti_hecc_platform_data *pdata)
452 {
453 	am3517_hecc_device.dev.platform_data = pdata;
454 	platform_device_register(&am3517_hecc_device);
455 }
456 
457 static struct omap_board_config_kernel am3517_evm_config[] __initdata = {
458 };
459 
460 static struct omap2_hsmmc_info mmc[] = {
461 	{
462 		.mmc		= 1,
463 		.caps		= MMC_CAP_4_BIT_DATA,
464 		.gpio_cd	= 127,
465 		.gpio_wp	= 126,
466 	},
467 	{
468 		.mmc		= 2,
469 		.caps		= MMC_CAP_4_BIT_DATA,
470 		.gpio_cd	= 128,
471 		.gpio_wp	= 129,
472 	},
473 	{}      /* Terminator */
474 };
475 
476 
am3517_evm_init(void)477 static void __init am3517_evm_init(void)
478 {
479 	omap_board_config = am3517_evm_config;
480 	omap_board_config_size = ARRAY_SIZE(am3517_evm_config);
481 	omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
482 
483 	am3517_evm_i2c_init();
484 	omap_display_init(&am3517_evm_dss_data);
485 	omap_serial_init();
486 	omap_sdrc_init(NULL, NULL);
487 
488 	/* Configure GPIO for EHCI port */
489 	omap_mux_init_gpio(57, OMAP_PIN_OUTPUT);
490 	usbhs_init(&usbhs_bdata);
491 	am3517_evm_hecc_init(&am3517_evm_hecc_pdata);
492 	/* DSS */
493 	am3517_evm_display_init();
494 
495 	/* RTC - S35390A */
496 	am3517_evm_rtc_init();
497 
498 	i2c_register_board_info(1, am3517evm_i2c1_boardinfo,
499 				ARRAY_SIZE(am3517evm_i2c1_boardinfo));
500 	/*Ethernet*/
501 	am3517_evm_ethernet_init(&am3517_evm_emac_pdata);
502 
503 	/* MUSB */
504 	am3517_evm_musb_init();
505 
506 	/* MMC init function */
507 	omap2_hsmmc_init(mmc);
508 }
509 
510 MACHINE_START(OMAP3517EVM, "OMAP3517/AM3517 EVM")
511 	.atag_offset	= 0x100,
512 	.reserve	= omap_reserve,
513 	.map_io		= omap3_map_io,
514 	.init_early	= am35xx_init_early,
515 	.init_irq	= omap3_init_irq,
516 	.handle_irq	= omap3_intc_handle_irq,
517 	.init_machine	= am3517_evm_init,
518 	.timer		= &omap3_timer,
519 	.restart	= omap_prcm_restart,
520 MACHINE_END
521