Path: blob/master/arch/arm/mach-imx/mach-armadillo5x0.c
10819 views
/*1* armadillo5x0.c2*3* Copyright 2009 Alberto Panizzo <[email protected]>4* updates in http://alberdroid.blogspot.com/5*6* Based on Atmark Techno, Inc. armadillo 500 BSP 20087* Based on mx31ads.c and pcm037.c Great Work!8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,22* MA 02110-1301, USA.23*/2425#include <linux/types.h>26#include <linux/init.h>27#include <linux/clk.h>28#include <linux/platform_device.h>29#include <linux/gpio.h>30#include <linux/smsc911x.h>31#include <linux/interrupt.h>32#include <linux/irq.h>33#include <linux/mtd/physmap.h>34#include <linux/io.h>35#include <linux/input.h>36#include <linux/i2c.h>37#include <linux/usb/otg.h>38#include <linux/usb/ulpi.h>39#include <linux/delay.h>4041#include <mach/hardware.h>42#include <asm/mach-types.h>43#include <asm/mach/arch.h>44#include <asm/mach/time.h>45#include <asm/memory.h>46#include <asm/mach/map.h>4748#include <mach/common.h>49#include <mach/iomux-mx3.h>50#include <mach/ulpi.h>5152#include "devices-imx31.h"53#include "crmregs-imx31.h"5455static int armadillo5x0_pins[] = {56/* UART1 */57MX31_PIN_CTS1__CTS1,58MX31_PIN_RTS1__RTS1,59MX31_PIN_TXD1__TXD1,60MX31_PIN_RXD1__RXD1,61/* UART2 */62MX31_PIN_CTS2__CTS2,63MX31_PIN_RTS2__RTS2,64MX31_PIN_TXD2__TXD2,65MX31_PIN_RXD2__RXD2,66/* LAN9118_IRQ */67IOMUX_MODE(MX31_PIN_GPIO1_0, IOMUX_CONFIG_GPIO),68/* SDHC1 */69MX31_PIN_SD1_DATA3__SD1_DATA3,70MX31_PIN_SD1_DATA2__SD1_DATA2,71MX31_PIN_SD1_DATA1__SD1_DATA1,72MX31_PIN_SD1_DATA0__SD1_DATA0,73MX31_PIN_SD1_CLK__SD1_CLK,74MX31_PIN_SD1_CMD__SD1_CMD,75/* Framebuffer */76MX31_PIN_LD0__LD0,77MX31_PIN_LD1__LD1,78MX31_PIN_LD2__LD2,79MX31_PIN_LD3__LD3,80MX31_PIN_LD4__LD4,81MX31_PIN_LD5__LD5,82MX31_PIN_LD6__LD6,83MX31_PIN_LD7__LD7,84MX31_PIN_LD8__LD8,85MX31_PIN_LD9__LD9,86MX31_PIN_LD10__LD10,87MX31_PIN_LD11__LD11,88MX31_PIN_LD12__LD12,89MX31_PIN_LD13__LD13,90MX31_PIN_LD14__LD14,91MX31_PIN_LD15__LD15,92MX31_PIN_LD16__LD16,93MX31_PIN_LD17__LD17,94MX31_PIN_VSYNC3__VSYNC3,95MX31_PIN_HSYNC__HSYNC,96MX31_PIN_FPSHIFT__FPSHIFT,97MX31_PIN_DRDY0__DRDY0,98IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/99/* I2C2 */100MX31_PIN_CSPI2_MOSI__SCL,101MX31_PIN_CSPI2_MISO__SDA,102/* OTG */103MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,104MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,105MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,106MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,107MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,108MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,109MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,110MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,111MX31_PIN_USBOTG_CLK__USBOTG_CLK,112MX31_PIN_USBOTG_DIR__USBOTG_DIR,113MX31_PIN_USBOTG_NXT__USBOTG_NXT,114MX31_PIN_USBOTG_STP__USBOTG_STP,115/* USB host 2 */116IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),117IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),118IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),119IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),120IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),121IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),122IOMUX_MODE(MX31_PIN_STXD3, IOMUX_CONFIG_FUNC),123IOMUX_MODE(MX31_PIN_SRXD3, IOMUX_CONFIG_FUNC),124IOMUX_MODE(MX31_PIN_SCK3, IOMUX_CONFIG_FUNC),125IOMUX_MODE(MX31_PIN_SFS3, IOMUX_CONFIG_FUNC),126IOMUX_MODE(MX31_PIN_STXD6, IOMUX_CONFIG_FUNC),127IOMUX_MODE(MX31_PIN_SRXD6, IOMUX_CONFIG_FUNC),128};129130/* USB */131132#define OTG_RESET IOMUX_TO_GPIO(MX31_PIN_STXD4)133#define USBH2_RESET IOMUX_TO_GPIO(MX31_PIN_SCK6)134#define USBH2_CS IOMUX_TO_GPIO(MX31_PIN_GPIO1_3)135136#define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \137PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)138139static int usbotg_init(struct platform_device *pdev)140{141int err;142143mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);144mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);145mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);146mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);147mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);148mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);149mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);150mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);151mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);152mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);153mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);154mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);155156/* Chip already enabled by hardware */157/* OTG phy reset*/158err = gpio_request(OTG_RESET, "USB-OTG-RESET");159if (err) {160pr_err("Failed to request the usb otg reset gpio\n");161return err;162}163164err = gpio_direction_output(OTG_RESET, 1/*HIGH*/);165if (err) {166pr_err("Failed to reset the usb otg phy\n");167goto otg_free_reset;168}169170gpio_set_value(OTG_RESET, 0/*LOW*/);171mdelay(5);172gpio_set_value(OTG_RESET, 1/*HIGH*/);173mdelay(10);174175return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED |176MXC_EHCI_INTERFACE_DIFF_UNI);177178otg_free_reset:179gpio_free(OTG_RESET);180return err;181}182183static int usbh2_init(struct platform_device *pdev)184{185int err;186187mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);188mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);189mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);190mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);191mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);192mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);193mxc_iomux_set_pad(MX31_PIN_SRXD6, USB_PAD_CFG);194mxc_iomux_set_pad(MX31_PIN_STXD6, USB_PAD_CFG);195mxc_iomux_set_pad(MX31_PIN_SFS3, USB_PAD_CFG);196mxc_iomux_set_pad(MX31_PIN_SCK3, USB_PAD_CFG);197mxc_iomux_set_pad(MX31_PIN_SRXD3, USB_PAD_CFG);198mxc_iomux_set_pad(MX31_PIN_STXD3, USB_PAD_CFG);199200mxc_iomux_set_gpr(MUX_PGP_UH2, true);201202203/* Enable the chip */204err = gpio_request(USBH2_CS, "USB-H2-CS");205if (err) {206pr_err("Failed to request the usb host 2 CS gpio\n");207return err;208}209210err = gpio_direction_output(USBH2_CS, 0/*Enabled*/);211if (err) {212pr_err("Failed to drive the usb host 2 CS gpio\n");213goto h2_free_cs;214}215216/* H2 phy reset*/217err = gpio_request(USBH2_RESET, "USB-H2-RESET");218if (err) {219pr_err("Failed to request the usb host 2 reset gpio\n");220goto h2_free_cs;221}222223err = gpio_direction_output(USBH2_RESET, 1/*HIGH*/);224if (err) {225pr_err("Failed to reset the usb host 2 phy\n");226goto h2_free_reset;227}228229gpio_set_value(USBH2_RESET, 0/*LOW*/);230mdelay(5);231gpio_set_value(USBH2_RESET, 1/*HIGH*/);232mdelay(10);233234return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED |235MXC_EHCI_INTERFACE_DIFF_UNI);236237h2_free_reset:238gpio_free(USBH2_RESET);239h2_free_cs:240gpio_free(USBH2_CS);241return err;242}243244static struct mxc_usbh_platform_data usbotg_pdata __initdata = {245.init = usbotg_init,246.portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,247};248249static struct mxc_usbh_platform_data usbh2_pdata __initdata = {250.init = usbh2_init,251.portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,252};253254/* RTC over I2C*/255#define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)256257static struct i2c_board_info armadillo5x0_i2c_rtc = {258I2C_BOARD_INFO("s35390a", 0x30),259};260261/* GPIO BUTTONS */262static struct gpio_keys_button armadillo5x0_buttons[] = {263{264.code = KEY_ENTER, /*28*/265.gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),266.active_low = 1,267.desc = "menu",268.wakeup = 1,269}, {270.code = KEY_BACK, /*158*/271.gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),272.active_low = 1,273.desc = "back",274.wakeup = 1,275}276};277278static const struct gpio_keys_platform_data279armadillo5x0_button_data __initconst = {280.buttons = armadillo5x0_buttons,281.nbuttons = ARRAY_SIZE(armadillo5x0_buttons),282};283284/*285* NAND Flash286*/287static const struct mxc_nand_platform_data288armadillo5x0_nand_board_info __initconst = {289.width = 1,290.hw_ecc = 1,291};292293/*294* MTD NOR Flash295*/296static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {297{298.name = "nor.bootloader",299.offset = 0x00000000,300.size = 4*32*1024,301}, {302.name = "nor.kernel",303.offset = MTDPART_OFS_APPEND,304.size = 16*128*1024,305}, {306.name = "nor.userland",307.offset = MTDPART_OFS_APPEND,308.size = 110*128*1024,309}, {310.name = "nor.config",311.offset = MTDPART_OFS_APPEND,312.size = 1*128*1024,313},314};315316static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {317.width = 2,318.parts = armadillo5x0_nor_flash_partitions,319.nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),320};321322static struct resource armadillo5x0_nor_flash_resource = {323.flags = IORESOURCE_MEM,324.start = MX31_CS0_BASE_ADDR,325.end = MX31_CS0_BASE_ADDR + SZ_64M - 1,326};327328static struct platform_device armadillo5x0_nor_flash = {329.name = "physmap-flash",330.id = -1,331.num_resources = 1,332.resource = &armadillo5x0_nor_flash_resource,333};334335/*336* FB support337*/338static const struct fb_videomode fb_modedb[] = {339{ /* 640x480 @ 60 Hz */340.name = "CRT-VGA",341.refresh = 60,342.xres = 640,343.yres = 480,344.pixclock = 39721,345.left_margin = 35,346.right_margin = 115,347.upper_margin = 43,348.lower_margin = 1,349.hsync_len = 10,350.vsync_len = 1,351.sync = FB_SYNC_OE_ACT_HIGH,352.vmode = FB_VMODE_NONINTERLACED,353.flag = 0,354}, {/* 800x600 @ 56 Hz */355.name = "CRT-SVGA",356.refresh = 56,357.xres = 800,358.yres = 600,359.pixclock = 30000,360.left_margin = 30,361.right_margin = 108,362.upper_margin = 13,363.lower_margin = 10,364.hsync_len = 10,365.vsync_len = 1,366.sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |367FB_SYNC_VERT_HIGH_ACT,368.vmode = FB_VMODE_NONINTERLACED,369.flag = 0,370},371};372373static const struct ipu_platform_data mx3_ipu_data __initconst = {374.irq_base = MXC_IPU_IRQ_START,375};376377static struct mx3fb_platform_data mx3fb_pdata __initdata = {378.name = "CRT-VGA",379.mode = fb_modedb,380.num_modes = ARRAY_SIZE(fb_modedb),381};382383/*384* SDHC 1385* MMC support386*/387static int armadillo5x0_sdhc1_get_ro(struct device *dev)388{389return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));390}391392static int armadillo5x0_sdhc1_init(struct device *dev,393irq_handler_t detect_irq, void *data)394{395int ret;396int gpio_det, gpio_wp;397398gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);399gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);400401ret = gpio_request(gpio_det, "sdhc-card-detect");402if (ret)403return ret;404405gpio_direction_input(gpio_det);406407ret = gpio_request(gpio_wp, "sdhc-write-protect");408if (ret)409goto err_gpio_free;410411gpio_direction_input(gpio_wp);412413/* When supported the trigger type have to be BOTH */414ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,415IRQF_DISABLED | IRQF_TRIGGER_FALLING,416"sdhc-detect", data);417418if (ret)419goto err_gpio_free_2;420421return 0;422423err_gpio_free_2:424gpio_free(gpio_wp);425426err_gpio_free:427gpio_free(gpio_det);428429return ret;430431}432433static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)434{435free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);436gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));437gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));438}439440static const struct imxmmc_platform_data sdhc_pdata __initconst = {441.get_ro = armadillo5x0_sdhc1_get_ro,442.init = armadillo5x0_sdhc1_init,443.exit = armadillo5x0_sdhc1_exit,444};445446/*447* SMSC 9118448* Network support449*/450static struct resource armadillo5x0_smc911x_resources[] = {451{452.start = MX31_CS3_BASE_ADDR,453.end = MX31_CS3_BASE_ADDR + SZ_32M - 1,454.flags = IORESOURCE_MEM,455}, {456.start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),457.end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),458.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,459},460};461462static struct smsc911x_platform_config smsc911x_info = {463.flags = SMSC911X_USE_16BIT,464.irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,465.irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,466};467468static struct platform_device armadillo5x0_smc911x_device = {469.name = "smsc911x",470.id = -1,471.num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),472.resource = armadillo5x0_smc911x_resources,473.dev = {474.platform_data = &smsc911x_info,475},476};477478/* UART device data */479static const struct imxuart_platform_data uart_pdata __initconst = {480.flags = IMXUART_HAVE_RTSCTS,481};482483static struct platform_device *devices[] __initdata = {484&armadillo5x0_smc911x_device,485};486487/*488* Perform board specific initializations489*/490static void __init armadillo5x0_init(void)491{492mxc_iomux_setup_multiple_pins(armadillo5x0_pins,493ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");494495platform_add_devices(devices, ARRAY_SIZE(devices));496imx_add_gpio_keys(&armadillo5x0_button_data);497imx31_add_imx_i2c1(NULL);498499/* Register UART */500imx31_add_imx_uart0(&uart_pdata);501imx31_add_imx_uart1(&uart_pdata);502503/* SMSC9118 IRQ pin */504gpio_direction_input(MX31_PIN_GPIO1_0);505506/* Register SDHC */507imx31_add_mxc_mmc(0, &sdhc_pdata);508509/* Register FB */510imx31_add_ipu_core(&mx3_ipu_data);511imx31_add_mx3_sdc_fb(&mx3fb_pdata);512513/* Register NOR Flash */514mxc_register_device(&armadillo5x0_nor_flash,515&armadillo5x0_nor_flash_pdata);516517/* Register NAND Flash */518imx31_add_mxc_nand(&armadillo5x0_nand_board_info);519520/* set NAND page size to 2k if not configured via boot mode pins */521__raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);522523/* RTC */524/* Get RTC IRQ and register the chip */525if (gpio_request(ARMADILLO5X0_RTC_GPIO, "rtc") == 0) {526if (gpio_direction_input(ARMADILLO5X0_RTC_GPIO) == 0)527armadillo5x0_i2c_rtc.irq = gpio_to_irq(ARMADILLO5X0_RTC_GPIO);528else529gpio_free(ARMADILLO5X0_RTC_GPIO);530}531if (armadillo5x0_i2c_rtc.irq == 0)532pr_warning("armadillo5x0_init: failed to get RTC IRQ\n");533i2c_register_board_info(1, &armadillo5x0_i2c_rtc, 1);534535/* USB */536537usbotg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |538ULPI_OTG_DRVVBUS_EXT);539if (usbotg_pdata.otg)540imx31_add_mxc_ehci_otg(&usbotg_pdata);541usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |542ULPI_OTG_DRVVBUS_EXT);543if (usbh2_pdata.otg)544imx31_add_mxc_ehci_hs(2, &usbh2_pdata);545}546547static void __init armadillo5x0_timer_init(void)548{549mx31_clocks_init(26000000);550}551552static struct sys_timer armadillo5x0_timer = {553.init = armadillo5x0_timer_init,554};555556MACHINE_START(ARMADILLO5X0, "Armadillo-500")557/* Maintainer: Alberto Panizzo */558.boot_params = MX3x_PHYS_OFFSET + 0x100,559.map_io = mx31_map_io,560.init_early = imx31_init_early,561.init_irq = mx31_init_irq,562.timer = &armadillo5x0_timer,563.init_machine = armadillo5x0_init,564MACHINE_END565566567