2 * Hawkboard.org based on TI's OMAP-L138 Platform
4 * Initial code: Syed Mohammed Khasim
6 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of
10 * any kind, whether express or implied.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/console.h>
15 #include <linux/interrupt.h>
16 #include <linux/gpio.h>
17 #include <linux/gpio/machine.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/mtd/rawnand.h>
20 #include <linux/platform_data/gpio-davinci.h>
21 #include <linux/platform_data/mtd-davinci.h>
22 #include <linux/platform_data/mtd-davinci-aemif.h>
23 #include <linux/platform_data/ti-aemif.h>
24 #include <linux/regulator/machine.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
29 #include <mach/common.h>
31 #include <mach/da8xx.h>
34 #define HAWKBOARD_PHY_ID "davinci_mdio-0:07"
36 #define DA850_USB1_VBUS_PIN GPIO_TO_PIN(2, 4)
37 #define DA850_USB1_OC_PIN GPIO_TO_PIN(6, 13)
39 static short omapl138_hawk_mii_pins[] __initdata = {
40 DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
41 DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
42 DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
43 DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
48 static __init void omapl138_hawk_config_emac(void)
50 void __iomem *cfgchip3 = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
53 struct davinci_soc_info *soc_info = &davinci_soc_info;
55 val = __raw_readl(cfgchip3);
57 ret = davinci_cfg_reg_list(omapl138_hawk_mii_pins);
59 pr_warn("%s: CPGMAC/MII mux setup failed: %d\n", __func__, ret);
63 /* configure the CFGCHIP3 register for MII */
64 __raw_writel(val, cfgchip3);
65 pr_info("EMAC: MII PHY configured\n");
67 soc_info->emac_pdata->phy_id = HAWKBOARD_PHY_ID;
69 ret = da8xx_register_emac();
71 pr_warn("%s: EMAC registration failed: %d\n", __func__, ret);
75 * The following EDMA channels/slots are not being used by drivers (for
76 * example: Timer, GPIO, UART events etc) on da850/omap-l138 EVM/Hawkboard,
77 * hence they are being reserved for codecs on the DSP side.
79 static const s16 da850_dma0_rsv_chans[][2] = {
80 /* (offset, number) */
87 static const s16 da850_dma0_rsv_slots[][2] = {
88 /* (offset, number) */
95 static const s16 da850_dma1_rsv_chans[][2] = {
96 /* (offset, number) */
102 static const s16 da850_dma1_rsv_slots[][2] = {
103 /* (offset, number) */
109 static struct edma_rsv_info da850_edma_cc0_rsv = {
110 .rsv_chans = da850_dma0_rsv_chans,
111 .rsv_slots = da850_dma0_rsv_slots,
114 static struct edma_rsv_info da850_edma_cc1_rsv = {
115 .rsv_chans = da850_dma1_rsv_chans,
116 .rsv_slots = da850_dma1_rsv_slots,
119 static struct edma_rsv_info *da850_edma_rsv[2] = {
124 static const short hawk_mmcsd0_pins[] = {
125 DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
126 DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
127 DA850_GPIO3_12, DA850_GPIO3_13,
131 #define DA850_HAWK_MMCSD_CD_PIN GPIO_TO_PIN(3, 12)
132 #define DA850_HAWK_MMCSD_WP_PIN GPIO_TO_PIN(3, 13)
134 static struct gpiod_lookup_table mmc_gpios_table = {
135 .dev_id = "da830-mmc.0",
137 GPIO_LOOKUP("davinci_gpio.0", DA850_HAWK_MMCSD_CD_PIN, "cd",
139 GPIO_LOOKUP("davinci_gpio.0", DA850_HAWK_MMCSD_WP_PIN, "wp",
144 static struct davinci_mmc_config da850_mmc_config = {
146 .max_freq = 50000000,
147 .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
150 static __init void omapl138_hawk_mmc_init(void)
154 ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
156 pr_warn("%s: MMC/SD0 mux setup failed: %d\n", __func__, ret);
160 gpiod_add_lookup_table(&mmc_gpios_table);
162 ret = da8xx_register_mmcsd0(&da850_mmc_config);
164 pr_warn("%s: MMC/SD0 registration failed: %d\n", __func__, ret);
165 goto mmc_setup_mmcsd_fail;
170 mmc_setup_mmcsd_fail:
171 gpiod_remove_lookup_table(&mmc_gpios_table);
174 static struct mtd_partition omapl138_hawk_nandflash_partition[] = {
176 .name = "u-boot env",
179 .mask_flags = MTD_WRITEABLE,
183 .offset = MTDPART_OFS_APPEND,
185 .mask_flags = MTD_WRITEABLE,
188 .name = "free space",
189 .offset = MTDPART_OFS_APPEND,
190 .size = MTDPART_SIZ_FULL,
195 static struct davinci_aemif_timing omapl138_hawk_nandflash_timing = {
205 static struct davinci_nand_pdata omapl138_hawk_nandflash_data = {
207 .parts = omapl138_hawk_nandflash_partition,
208 .nr_parts = ARRAY_SIZE(omapl138_hawk_nandflash_partition),
209 .ecc_mode = NAND_ECC_HW,
211 .bbt_options = NAND_BBT_USE_FLASH,
212 .options = NAND_BUSWIDTH_16,
213 .timing = &omapl138_hawk_nandflash_timing,
219 static struct resource omapl138_hawk_nandflash_resource[] = {
221 .start = DA8XX_AEMIF_CS3_BASE,
222 .end = DA8XX_AEMIF_CS3_BASE + SZ_32M,
223 .flags = IORESOURCE_MEM,
226 .start = DA8XX_AEMIF_CTL_BASE,
227 .end = DA8XX_AEMIF_CTL_BASE + SZ_32K,
228 .flags = IORESOURCE_MEM,
232 static struct resource omapl138_hawk_aemif_resource[] = {
234 .start = DA8XX_AEMIF_CTL_BASE,
235 .end = DA8XX_AEMIF_CTL_BASE + SZ_32K,
236 .flags = IORESOURCE_MEM,
240 static struct aemif_abus_data omapl138_hawk_aemif_abus_data[] = {
246 static struct platform_device omapl138_hawk_aemif_devices[] = {
248 .name = "davinci_nand",
251 .platform_data = &omapl138_hawk_nandflash_data,
253 .resource = omapl138_hawk_nandflash_resource,
254 .num_resources = ARRAY_SIZE(omapl138_hawk_nandflash_resource),
258 static struct aemif_platform_data omapl138_hawk_aemif_pdata = {
260 .abus_data = omapl138_hawk_aemif_abus_data,
261 .num_abus_data = ARRAY_SIZE(omapl138_hawk_aemif_abus_data),
262 .sub_devices = omapl138_hawk_aemif_devices,
263 .num_sub_devices = ARRAY_SIZE(omapl138_hawk_aemif_devices),
266 static struct platform_device omapl138_hawk_aemif_device = {
270 .platform_data = &omapl138_hawk_aemif_pdata,
272 .resource = omapl138_hawk_aemif_resource,
273 .num_resources = ARRAY_SIZE(omapl138_hawk_aemif_resource),
276 static const short omapl138_hawk_nand_pins[] = {
277 DA850_EMA_WAIT_1, DA850_NEMA_OE, DA850_NEMA_WE, DA850_NEMA_CS_3,
278 DA850_EMA_D_0, DA850_EMA_D_1, DA850_EMA_D_2, DA850_EMA_D_3,
279 DA850_EMA_D_4, DA850_EMA_D_5, DA850_EMA_D_6, DA850_EMA_D_7,
280 DA850_EMA_D_8, DA850_EMA_D_9, DA850_EMA_D_10, DA850_EMA_D_11,
281 DA850_EMA_D_12, DA850_EMA_D_13, DA850_EMA_D_14, DA850_EMA_D_15,
282 DA850_EMA_A_1, DA850_EMA_A_2,
286 static int omapl138_hawk_register_aemif(void)
290 ret = davinci_cfg_reg_list(omapl138_hawk_nand_pins);
292 pr_warn("%s: NAND mux setup failed: %d\n", __func__, ret);
294 return platform_device_register(&omapl138_hawk_aemif_device);
297 static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
298 static da8xx_ocic_handler_t hawk_usb_ocic_handler;
300 static const short da850_hawk_usb11_pins[] = {
301 DA850_GPIO2_4, DA850_GPIO6_13,
305 static int hawk_usb_set_power(unsigned port, int on)
307 gpio_set_value(DA850_USB1_VBUS_PIN, on);
311 static int hawk_usb_get_power(unsigned port)
313 return gpio_get_value(DA850_USB1_VBUS_PIN);
316 static int hawk_usb_get_oci(unsigned port)
318 return !gpio_get_value(DA850_USB1_OC_PIN);
321 static int hawk_usb_ocic_notify(da8xx_ocic_handler_t handler)
323 int irq = gpio_to_irq(DA850_USB1_OC_PIN);
326 if (handler != NULL) {
327 hawk_usb_ocic_handler = handler;
329 error = request_irq(irq, omapl138_hawk_usb_ocic_irq,
330 IRQF_TRIGGER_RISING |
331 IRQF_TRIGGER_FALLING,
332 "OHCI over-current indicator", NULL);
334 pr_err("%s: could not request IRQ to watch "
335 "over-current indicator changes\n", __func__);
342 static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
343 .set_power = hawk_usb_set_power,
344 .get_power = hawk_usb_get_power,
345 .get_oci = hawk_usb_get_oci,
346 .ocic_notify = hawk_usb_ocic_notify,
347 /* TPS2087 switch @ 5V */
348 .potpgt = (3 + 1) / 2, /* 3 ms max */
351 static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
353 hawk_usb_ocic_handler(&omapl138_hawk_usb11_pdata, 1);
357 static __init void omapl138_hawk_usb_init(void)
361 ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
363 pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
367 ret = da8xx_register_usb_phy_clocks();
369 pr_warn("%s: USB PHY CLK registration failed: %d\n",
372 ret = da8xx_register_usb_phy();
374 pr_warn("%s: USB PHY registration failed: %d\n",
377 ret = gpio_request_one(DA850_USB1_VBUS_PIN,
378 GPIOF_DIR_OUT, "USB1 VBUS");
380 pr_err("%s: failed to request GPIO for USB 1.1 port "
381 "power control: %d\n", __func__, ret);
385 ret = gpio_request_one(DA850_USB1_OC_PIN,
386 GPIOF_DIR_IN, "USB1 OC");
388 pr_err("%s: failed to request GPIO for USB 1.1 port "
389 "over-current indicator: %d\n", __func__, ret);
390 goto usb11_setup_oc_fail;
393 ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
395 pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
396 goto usb11_setup_fail;
402 gpio_free(DA850_USB1_OC_PIN);
404 gpio_free(DA850_USB1_VBUS_PIN);
407 static __init void omapl138_hawk_init(void)
411 da850_register_clocks();
413 ret = da850_register_gpio();
415 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
417 davinci_serial_init(da8xx_serial_device);
419 omapl138_hawk_config_emac();
421 ret = da850_register_edma(da850_edma_rsv);
423 pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
425 omapl138_hawk_mmc_init();
427 omapl138_hawk_usb_init();
429 ret = omapl138_hawk_register_aemif();
431 pr_warn("%s: aemif registration failed: %d\n", __func__, ret);
433 ret = da8xx_register_watchdog();
435 pr_warn("%s: watchdog registration failed: %d\n",
438 ret = da8xx_register_rproc();
440 pr_warn("%s: dsp/rproc registration failed: %d\n",
443 regulator_has_full_constraints();
446 #ifdef CONFIG_SERIAL_8250_CONSOLE
447 static int __init omapl138_hawk_console_init(void)
449 if (!machine_is_omapl138_hawkboard())
452 return add_preferred_console("ttyS", 2, "115200");
454 console_initcall(omapl138_hawk_console_init);
457 static void __init omapl138_hawk_map_io(void)
462 MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
463 .atag_offset = 0x100,
464 .map_io = omapl138_hawk_map_io,
465 .init_irq = cp_intc_init,
466 .init_time = da850_init_time,
467 .init_machine = omapl138_hawk_init,
468 .init_late = davinci_init_late,
469 .dma_zone_size = SZ_128M,
470 .reserve = da8xx_rproc_reserve_cma,