Path: blob/master/arch/arm/mach-davinci/board-da830-evm.c
10699 views
/*1* TI DA830/OMAP L137 EVM board2*3* Author: Mark A. Greer <[email protected]>4* Derived from: arch/arm/mach-davinci/board-dm644x-evm.c5*6* 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under7* the terms of the GNU General Public License version 2. This program8* is licensed "as is" without any warranty of any kind, whether express9* or implied.10*/11#include <linux/kernel.h>12#include <linux/init.h>13#include <linux/console.h>14#include <linux/interrupt.h>15#include <linux/gpio.h>16#include <linux/platform_device.h>17#include <linux/i2c.h>18#include <linux/i2c/pcf857x.h>19#include <linux/i2c/at24.h>20#include <linux/mtd/mtd.h>21#include <linux/mtd/partitions.h>22#include <linux/spi/spi.h>23#include <linux/spi/flash.h>2425#include <asm/mach-types.h>26#include <asm/mach/arch.h>2728#include <mach/cp_intc.h>29#include <mach/mux.h>30#include <mach/nand.h>31#include <mach/da8xx.h>32#include <mach/usb.h>33#include <mach/aemif.h>34#include <mach/spi.h>3536#define DA830_EVM_PHY_ID ""37/*38* USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4].39*/40#define ON_BD_USB_DRV GPIO_TO_PIN(1, 15)41#define ON_BD_USB_OVC GPIO_TO_PIN(2, 4)4243static const short da830_evm_usb11_pins[] = {44DA830_GPIO1_15, DA830_GPIO2_4,45-146};4748static da8xx_ocic_handler_t da830_evm_usb_ocic_handler;4950static int da830_evm_usb_set_power(unsigned port, int on)51{52gpio_set_value(ON_BD_USB_DRV, on);53return 0;54}5556static int da830_evm_usb_get_power(unsigned port)57{58return gpio_get_value(ON_BD_USB_DRV);59}6061static int da830_evm_usb_get_oci(unsigned port)62{63return !gpio_get_value(ON_BD_USB_OVC);64}6566static irqreturn_t da830_evm_usb_ocic_irq(int, void *);6768static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler)69{70int irq = gpio_to_irq(ON_BD_USB_OVC);71int error = 0;7273if (handler != NULL) {74da830_evm_usb_ocic_handler = handler;7576error = request_irq(irq, da830_evm_usb_ocic_irq, IRQF_DISABLED |77IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,78"OHCI over-current indicator", NULL);79if (error)80printk(KERN_ERR "%s: could not request IRQ to watch "81"over-current indicator changes\n", __func__);82} else83free_irq(irq, NULL);8485return error;86}8788static struct da8xx_ohci_root_hub da830_evm_usb11_pdata = {89.set_power = da830_evm_usb_set_power,90.get_power = da830_evm_usb_get_power,91.get_oci = da830_evm_usb_get_oci,92.ocic_notify = da830_evm_usb_ocic_notify,9394/* TPS2065 switch @ 5V */95.potpgt = (3 + 1) / 2, /* 3 ms max */96};9798static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id)99{100da830_evm_usb_ocic_handler(&da830_evm_usb11_pdata, 1);101return IRQ_HANDLED;102}103104static __init void da830_evm_usb_init(void)105{106u32 cfgchip2;107int ret;108109/*110* Set up USB clock/mode in the CFGCHIP2 register.111* FYI: CFGCHIP2 is 0x0000ef00 initially.112*/113cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));114115/* USB2.0 PHY reference clock is 24 MHz */116cfgchip2 &= ~CFGCHIP2_REFFREQ;117cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ;118119/*120* Select internal reference clock for USB 2.0 PHY121* and use it as a clock source for USB 1.1 PHY122* (this is the default setting anyway).123*/124cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;125cfgchip2 |= CFGCHIP2_USB2PHYCLKMUX;126127/*128* We have to override VBUS/ID signals when MUSB is configured into the129* host-only mode -- ID pin will float if no cable is connected, so the130* controller won't be able to drive VBUS thinking that it's a B-device.131* Otherwise, we want to use the OTG mode and enable VBUS comparators.132*/133cfgchip2 &= ~CFGCHIP2_OTGMODE;134#ifdef CONFIG_USB_MUSB_HOST135cfgchip2 |= CFGCHIP2_FORCE_HOST;136#else137cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;138#endif139140__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));141142/* USB_REFCLKIN is not used. */143ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);144if (ret)145pr_warning("%s: USB 2.0 PinMux setup failed: %d\n",146__func__, ret);147else {148/*149* TPS2065 switch @ 5V supplies 1 A (sustains 1.5 A),150* with the power on to power good time of 3 ms.151*/152ret = da8xx_register_usb20(1000, 3);153if (ret)154pr_warning("%s: USB 2.0 registration failed: %d\n",155__func__, ret);156}157158ret = davinci_cfg_reg_list(da830_evm_usb11_pins);159if (ret) {160pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",161__func__, ret);162return;163}164165ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV");166if (ret) {167printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "168"power control: %d\n", __func__, ret);169return;170}171gpio_direction_output(ON_BD_USB_DRV, 0);172173ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC");174if (ret) {175printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "176"over-current indicator: %d\n", __func__, ret);177return;178}179gpio_direction_input(ON_BD_USB_OVC);180181ret = da8xx_register_usb11(&da830_evm_usb11_pdata);182if (ret)183pr_warning("%s: USB 1.1 registration failed: %d\n",184__func__, ret);185}186187static struct davinci_uart_config da830_evm_uart_config __initdata = {188.enabled_uarts = 0x7,189};190191static const short da830_evm_mcasp1_pins[] = {192DA830_AHCLKX1, DA830_ACLKX1, DA830_AFSX1, DA830_AHCLKR1, DA830_AFSR1,193DA830_AMUTE1, DA830_AXR1_0, DA830_AXR1_1, DA830_AXR1_2, DA830_AXR1_5,194DA830_ACLKR1, DA830_AXR1_6, DA830_AXR1_7, DA830_AXR1_8, DA830_AXR1_10,195DA830_AXR1_11,196-1197};198199static u8 da830_iis_serializer_direction[] = {200RX_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,201INACTIVE_MODE, TX_MODE, INACTIVE_MODE, INACTIVE_MODE,202INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,203};204205static struct snd_platform_data da830_evm_snd_data = {206.tx_dma_offset = 0x2000,207.rx_dma_offset = 0x2000,208.op_mode = DAVINCI_MCASP_IIS_MODE,209.num_serializer = ARRAY_SIZE(da830_iis_serializer_direction),210.tdm_slots = 2,211.serial_dir = da830_iis_serializer_direction,212.asp_chan_q = EVENTQ_0,213.version = MCASP_VERSION_2,214.txnumevt = 1,215.rxnumevt = 1,216};217218/*219* GPIO2[1] is used as MMC_SD_WP and GPIO2[2] as MMC_SD_INS.220*/221static const short da830_evm_mmc_sd_pins[] = {222DA830_MMCSD_DAT_0, DA830_MMCSD_DAT_1, DA830_MMCSD_DAT_2,223DA830_MMCSD_DAT_3, DA830_MMCSD_DAT_4, DA830_MMCSD_DAT_5,224DA830_MMCSD_DAT_6, DA830_MMCSD_DAT_7, DA830_MMCSD_CLK,225DA830_MMCSD_CMD, DA830_GPIO2_1, DA830_GPIO2_2,226-1227};228229#define DA830_MMCSD_WP_PIN GPIO_TO_PIN(2, 1)230#define DA830_MMCSD_CD_PIN GPIO_TO_PIN(2, 2)231232static int da830_evm_mmc_get_ro(int index)233{234return gpio_get_value(DA830_MMCSD_WP_PIN);235}236237static int da830_evm_mmc_get_cd(int index)238{239return !gpio_get_value(DA830_MMCSD_CD_PIN);240}241242static struct davinci_mmc_config da830_evm_mmc_config = {243.get_ro = da830_evm_mmc_get_ro,244.get_cd = da830_evm_mmc_get_cd,245.wires = 8,246.max_freq = 50000000,247.caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,248.version = MMC_CTLR_VERSION_2,249};250251static inline void da830_evm_init_mmc(void)252{253int ret;254255ret = davinci_cfg_reg_list(da830_evm_mmc_sd_pins);256if (ret) {257pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n",258ret);259return;260}261262ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP");263if (ret) {264pr_warning("da830_evm_init: can not open GPIO %d\n",265DA830_MMCSD_WP_PIN);266return;267}268gpio_direction_input(DA830_MMCSD_WP_PIN);269270ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n");271if (ret) {272pr_warning("da830_evm_init: can not open GPIO %d\n",273DA830_MMCSD_CD_PIN);274return;275}276gpio_direction_input(DA830_MMCSD_CD_PIN);277278ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);279if (ret) {280pr_warning("da830_evm_init: mmc/sd registration failed: %d\n",281ret);282gpio_free(DA830_MMCSD_WP_PIN);283}284}285286/*287* UI board NAND/NOR flashes only use 8-bit data bus.288*/289static const short da830_evm_emif25_pins[] = {290DA830_EMA_D_0, DA830_EMA_D_1, DA830_EMA_D_2, DA830_EMA_D_3,291DA830_EMA_D_4, DA830_EMA_D_5, DA830_EMA_D_6, DA830_EMA_D_7,292DA830_EMA_A_0, DA830_EMA_A_1, DA830_EMA_A_2, DA830_EMA_A_3,293DA830_EMA_A_4, DA830_EMA_A_5, DA830_EMA_A_6, DA830_EMA_A_7,294DA830_EMA_A_8, DA830_EMA_A_9, DA830_EMA_A_10, DA830_EMA_A_11,295DA830_EMA_A_12, DA830_EMA_BA_0, DA830_EMA_BA_1, DA830_NEMA_WE,296DA830_NEMA_CS_2, DA830_NEMA_CS_3, DA830_NEMA_OE, DA830_EMA_WAIT_0,297-1298};299300#if defined(CONFIG_MMC_DAVINCI) || defined(CONFIG_MMC_DAVINCI_MODULE)301#define HAS_MMC 1302#else303#define HAS_MMC 0304#endif305306#ifdef CONFIG_DA830_UI_NAND307static struct mtd_partition da830_evm_nand_partitions[] = {308/* bootloader (U-Boot, etc) in first sector */309[0] = {310.name = "bootloader",311.offset = 0,312.size = SZ_128K,313.mask_flags = MTD_WRITEABLE, /* force read-only */314},315/* bootloader params in the next sector */316[1] = {317.name = "params",318.offset = MTDPART_OFS_APPEND,319.size = SZ_128K,320.mask_flags = MTD_WRITEABLE, /* force read-only */321},322/* kernel */323[2] = {324.name = "kernel",325.offset = MTDPART_OFS_APPEND,326.size = SZ_2M,327.mask_flags = 0,328},329/* file system */330[3] = {331.name = "filesystem",332.offset = MTDPART_OFS_APPEND,333.size = MTDPART_SIZ_FULL,334.mask_flags = 0,335}336};337338/* flash bbt decriptors */339static uint8_t da830_evm_nand_bbt_pattern[] = { 'B', 'b', 't', '0' };340static uint8_t da830_evm_nand_mirror_pattern[] = { '1', 't', 'b', 'B' };341342static struct nand_bbt_descr da830_evm_nand_bbt_main_descr = {343.options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE |344NAND_BBT_WRITE | NAND_BBT_2BIT |345NAND_BBT_VERSION | NAND_BBT_PERCHIP,346.offs = 2,347.len = 4,348.veroffs = 16,349.maxblocks = 4,350.pattern = da830_evm_nand_bbt_pattern351};352353static struct nand_bbt_descr da830_evm_nand_bbt_mirror_descr = {354.options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE |355NAND_BBT_WRITE | NAND_BBT_2BIT |356NAND_BBT_VERSION | NAND_BBT_PERCHIP,357.offs = 2,358.len = 4,359.veroffs = 16,360.maxblocks = 4,361.pattern = da830_evm_nand_mirror_pattern362};363364static struct davinci_aemif_timing da830_evm_nandflash_timing = {365.wsetup = 24,366.wstrobe = 21,367.whold = 14,368.rsetup = 19,369.rstrobe = 50,370.rhold = 0,371.ta = 20,372};373374static struct davinci_nand_pdata da830_evm_nand_pdata = {375.parts = da830_evm_nand_partitions,376.nr_parts = ARRAY_SIZE(da830_evm_nand_partitions),377.ecc_mode = NAND_ECC_HW,378.ecc_bits = 4,379.options = NAND_USE_FLASH_BBT,380.bbt_td = &da830_evm_nand_bbt_main_descr,381.bbt_md = &da830_evm_nand_bbt_mirror_descr,382.timing = &da830_evm_nandflash_timing,383};384385static struct resource da830_evm_nand_resources[] = {386[0] = { /* First memory resource is NAND I/O window */387.start = DA8XX_AEMIF_CS3_BASE,388.end = DA8XX_AEMIF_CS3_BASE + PAGE_SIZE - 1,389.flags = IORESOURCE_MEM,390},391[1] = { /* Second memory resource is AEMIF control registers */392.start = DA8XX_AEMIF_CTL_BASE,393.end = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,394.flags = IORESOURCE_MEM,395},396};397398static struct platform_device da830_evm_nand_device = {399.name = "davinci_nand",400.id = 1,401.dev = {402.platform_data = &da830_evm_nand_pdata,403},404.num_resources = ARRAY_SIZE(da830_evm_nand_resources),405.resource = da830_evm_nand_resources,406};407408static inline void da830_evm_init_nand(int mux_mode)409{410int ret;411412if (HAS_MMC) {413pr_warning("WARNING: both MMC/SD and NAND are "414"enabled, but they share AEMIF pins.\n"415"\tDisable MMC/SD for NAND support.\n");416return;417}418419ret = davinci_cfg_reg_list(da830_evm_emif25_pins);420if (ret)421pr_warning("da830_evm_init: emif25 mux setup failed: %d\n",422ret);423424ret = platform_device_register(&da830_evm_nand_device);425if (ret)426pr_warning("da830_evm_init: NAND device not registered.\n");427428gpio_direction_output(mux_mode, 1);429}430#else431static inline void da830_evm_init_nand(int mux_mode) { }432#endif433434#ifdef CONFIG_DA830_UI_LCD435static inline void da830_evm_init_lcdc(int mux_mode)436{437int ret;438439ret = davinci_cfg_reg_list(da830_lcdcntl_pins);440if (ret)441pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n",442ret);443444ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata);445if (ret)446pr_warning("da830_evm_init: lcd setup failed: %d\n", ret);447448gpio_direction_output(mux_mode, 0);449}450#else451static inline void da830_evm_init_lcdc(int mux_mode) { }452#endif453454static struct at24_platform_data da830_evm_i2c_eeprom_info = {455.byte_len = SZ_256K / 8,456.page_size = 64,457.flags = AT24_FLAG_ADDR16,458.setup = davinci_get_mac_addr,459.context = (void *)0x7f00,460};461462static int __init da830_evm_ui_expander_setup(struct i2c_client *client,463int gpio, unsigned ngpio, void *context)464{465gpio_request(gpio + 6, "UI MUX_MODE");466467/* Drive mux mode low to match the default without UI card */468gpio_direction_output(gpio + 6, 0);469470da830_evm_init_lcdc(gpio + 6);471472da830_evm_init_nand(gpio + 6);473474return 0;475}476477static int da830_evm_ui_expander_teardown(struct i2c_client *client, int gpio,478unsigned ngpio, void *context)479{480gpio_free(gpio + 6);481return 0;482}483484static struct pcf857x_platform_data __initdata da830_evm_ui_expander_info = {485.gpio_base = DAVINCI_N_GPIO,486.setup = da830_evm_ui_expander_setup,487.teardown = da830_evm_ui_expander_teardown,488};489490static struct i2c_board_info __initdata da830_evm_i2c_devices[] = {491{492I2C_BOARD_INFO("24c256", 0x50),493.platform_data = &da830_evm_i2c_eeprom_info,494},495{496I2C_BOARD_INFO("tlv320aic3x", 0x18),497},498{499I2C_BOARD_INFO("pcf8574", 0x3f),500.platform_data = &da830_evm_ui_expander_info,501},502};503504static struct davinci_i2c_platform_data da830_evm_i2c_0_pdata = {505.bus_freq = 100, /* kHz */506.bus_delay = 0, /* usec */507};508509/*510* The following EDMA channels/slots are not being used by drivers (for511* example: Timer, GPIO, UART events etc) on da830/omap-l137 EVM, hence512* they are being reserved for codecs on the DSP side.513*/514static const s16 da830_dma_rsv_chans[][2] = {515/* (offset, number) */516{ 8, 2},517{12, 2},518{24, 4},519{30, 2},520{-1, -1}521};522523static const s16 da830_dma_rsv_slots[][2] = {524/* (offset, number) */525{ 8, 2},526{12, 2},527{24, 4},528{30, 26},529{-1, -1}530};531532static struct edma_rsv_info da830_edma_rsv[] = {533{534.rsv_chans = da830_dma_rsv_chans,535.rsv_slots = da830_dma_rsv_slots,536},537};538539static struct mtd_partition da830evm_spiflash_part[] = {540[0] = {541.name = "DSP-UBL",542.offset = 0,543.size = SZ_8K,544.mask_flags = MTD_WRITEABLE,545},546[1] = {547.name = "ARM-UBL",548.offset = MTDPART_OFS_APPEND,549.size = SZ_16K + SZ_8K,550.mask_flags = MTD_WRITEABLE,551},552[2] = {553.name = "U-Boot",554.offset = MTDPART_OFS_APPEND,555.size = SZ_256K - SZ_32K,556.mask_flags = MTD_WRITEABLE,557},558[3] = {559.name = "U-Boot-Environment",560.offset = MTDPART_OFS_APPEND,561.size = SZ_16K,562.mask_flags = 0,563},564[4] = {565.name = "Kernel",566.offset = MTDPART_OFS_APPEND,567.size = MTDPART_SIZ_FULL,568.mask_flags = 0,569},570};571572static struct flash_platform_data da830evm_spiflash_data = {573.name = "m25p80",574.parts = da830evm_spiflash_part,575.nr_parts = ARRAY_SIZE(da830evm_spiflash_part),576.type = "w25x32",577};578579static struct davinci_spi_config da830evm_spiflash_cfg = {580.io_type = SPI_IO_TYPE_DMA,581.c2tdelay = 8,582.t2cdelay = 8,583};584585static struct spi_board_info da830evm_spi_info[] = {586{587.modalias = "m25p80",588.platform_data = &da830evm_spiflash_data,589.controller_data = &da830evm_spiflash_cfg,590.mode = SPI_MODE_0,591.max_speed_hz = 30000000,592.bus_num = 0,593.chip_select = 0,594},595};596597static __init void da830_evm_init(void)598{599struct davinci_soc_info *soc_info = &davinci_soc_info;600int ret;601602ret = da830_register_edma(da830_edma_rsv);603if (ret)604pr_warning("da830_evm_init: edma registration failed: %d\n",605ret);606607ret = davinci_cfg_reg_list(da830_i2c0_pins);608if (ret)609pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n",610ret);611612ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata);613if (ret)614pr_warning("da830_evm_init: i2c0 registration failed: %d\n",615ret);616617da830_evm_usb_init();618619soc_info->emac_pdata->rmii_en = 1;620soc_info->emac_pdata->phy_id = DA830_EVM_PHY_ID;621622ret = davinci_cfg_reg_list(da830_cpgmac_pins);623if (ret)624pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n",625ret);626627ret = da8xx_register_emac();628if (ret)629pr_warning("da830_evm_init: emac registration failed: %d\n",630ret);631632ret = da8xx_register_watchdog();633if (ret)634pr_warning("da830_evm_init: watchdog registration failed: %d\n",635ret);636637davinci_serial_init(&da830_evm_uart_config);638i2c_register_board_info(1, da830_evm_i2c_devices,639ARRAY_SIZE(da830_evm_i2c_devices));640641ret = davinci_cfg_reg_list(da830_evm_mcasp1_pins);642if (ret)643pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n",644ret);645646da8xx_register_mcasp(1, &da830_evm_snd_data);647648da830_evm_init_mmc();649650ret = da8xx_register_rtc();651if (ret)652pr_warning("da830_evm_init: rtc setup failed: %d\n", ret);653654ret = da8xx_register_spi(0, da830evm_spi_info,655ARRAY_SIZE(da830evm_spi_info));656if (ret)657pr_warning("da830_evm_init: spi 0 registration failed: %d\n",658ret);659}660661#ifdef CONFIG_SERIAL_8250_CONSOLE662static int __init da830_evm_console_init(void)663{664if (!machine_is_davinci_da830_evm())665return 0;666667return add_preferred_console("ttyS", 2, "115200");668}669console_initcall(da830_evm_console_init);670#endif671672static void __init da830_evm_map_io(void)673{674da830_init();675}676677MACHINE_START(DAVINCI_DA830_EVM, "DaVinci DA830/OMAP-L137/AM17x EVM")678.boot_params = (DA8XX_DDR_BASE + 0x100),679.map_io = da830_evm_map_io,680.init_irq = cp_intc_init,681.timer = &davinci_timer,682.init_machine = da830_evm_init,683MACHINE_END684685686