Path: blob/master/arch/arm/mach-at91/at91sam9260_devices.c
10817 views
/*1* arch/arm/mach-at91/at91sam9260_devices.c2*3* Copyright (C) 2006 Atmel4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10*/11#include <asm/mach/arch.h>12#include <asm/mach/map.h>1314#include <linux/dma-mapping.h>15#include <linux/platform_device.h>16#include <linux/i2c-gpio.h>1718#include <mach/board.h>19#include <mach/gpio.h>20#include <mach/cpu.h>21#include <mach/at91sam9260.h>22#include <mach/at91sam9260_matrix.h>23#include <mach/at91sam9_smc.h>2425#include "generic.h"262728/* --------------------------------------------------------------------29* USB Host30* -------------------------------------------------------------------- */3132#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)33static u64 ohci_dmamask = DMA_BIT_MASK(32);34static struct at91_usbh_data usbh_data;3536static struct resource usbh_resources[] = {37[0] = {38.start = AT91SAM9260_UHP_BASE,39.end = AT91SAM9260_UHP_BASE + SZ_1M - 1,40.flags = IORESOURCE_MEM,41},42[1] = {43.start = AT91SAM9260_ID_UHP,44.end = AT91SAM9260_ID_UHP,45.flags = IORESOURCE_IRQ,46},47};4849static struct platform_device at91_usbh_device = {50.name = "at91_ohci",51.id = -1,52.dev = {53.dma_mask = &ohci_dmamask,54.coherent_dma_mask = DMA_BIT_MASK(32),55.platform_data = &usbh_data,56},57.resource = usbh_resources,58.num_resources = ARRAY_SIZE(usbh_resources),59};6061void __init at91_add_device_usbh(struct at91_usbh_data *data)62{63if (!data)64return;6566usbh_data = *data;67platform_device_register(&at91_usbh_device);68}69#else70void __init at91_add_device_usbh(struct at91_usbh_data *data) {}71#endif727374/* --------------------------------------------------------------------75* USB Device (Gadget)76* -------------------------------------------------------------------- */7778#ifdef CONFIG_USB_GADGET_AT9179static struct at91_udc_data udc_data;8081static struct resource udc_resources[] = {82[0] = {83.start = AT91SAM9260_BASE_UDP,84.end = AT91SAM9260_BASE_UDP + SZ_16K - 1,85.flags = IORESOURCE_MEM,86},87[1] = {88.start = AT91SAM9260_ID_UDP,89.end = AT91SAM9260_ID_UDP,90.flags = IORESOURCE_IRQ,91},92};9394static struct platform_device at91_udc_device = {95.name = "at91_udc",96.id = -1,97.dev = {98.platform_data = &udc_data,99},100.resource = udc_resources,101.num_resources = ARRAY_SIZE(udc_resources),102};103104void __init at91_add_device_udc(struct at91_udc_data *data)105{106if (!data)107return;108109if (data->vbus_pin) {110at91_set_gpio_input(data->vbus_pin, 0);111at91_set_deglitch(data->vbus_pin, 1);112}113114/* Pullup pin is handled internally by USB device peripheral */115116udc_data = *data;117platform_device_register(&at91_udc_device);118}119#else120void __init at91_add_device_udc(struct at91_udc_data *data) {}121#endif122123124/* --------------------------------------------------------------------125* Ethernet126* -------------------------------------------------------------------- */127128#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)129static u64 eth_dmamask = DMA_BIT_MASK(32);130static struct at91_eth_data eth_data;131132static struct resource eth_resources[] = {133[0] = {134.start = AT91SAM9260_BASE_EMAC,135.end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,136.flags = IORESOURCE_MEM,137},138[1] = {139.start = AT91SAM9260_ID_EMAC,140.end = AT91SAM9260_ID_EMAC,141.flags = IORESOURCE_IRQ,142},143};144145static struct platform_device at91sam9260_eth_device = {146.name = "macb",147.id = -1,148.dev = {149.dma_mask = ð_dmamask,150.coherent_dma_mask = DMA_BIT_MASK(32),151.platform_data = ð_data,152},153.resource = eth_resources,154.num_resources = ARRAY_SIZE(eth_resources),155};156157void __init at91_add_device_eth(struct at91_eth_data *data)158{159if (!data)160return;161162if (data->phy_irq_pin) {163at91_set_gpio_input(data->phy_irq_pin, 0);164at91_set_deglitch(data->phy_irq_pin, 1);165}166167/* Pins used for MII and RMII */168at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */169at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */170at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */171at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */172at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */173at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */174at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */175at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */176at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */177at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */178179if (!data->is_rmii) {180at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */181at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */182at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */183at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */184at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */185at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */186at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */187at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */188}189190eth_data = *data;191platform_device_register(&at91sam9260_eth_device);192}193#else194void __init at91_add_device_eth(struct at91_eth_data *data) {}195#endif196197198/* --------------------------------------------------------------------199* MMC / SD200* -------------------------------------------------------------------- */201202#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)203static u64 mmc_dmamask = DMA_BIT_MASK(32);204static struct at91_mmc_data mmc_data;205206static struct resource mmc_resources[] = {207[0] = {208.start = AT91SAM9260_BASE_MCI,209.end = AT91SAM9260_BASE_MCI + SZ_16K - 1,210.flags = IORESOURCE_MEM,211},212[1] = {213.start = AT91SAM9260_ID_MCI,214.end = AT91SAM9260_ID_MCI,215.flags = IORESOURCE_IRQ,216},217};218219static struct platform_device at91sam9260_mmc_device = {220.name = "at91_mci",221.id = -1,222.dev = {223.dma_mask = &mmc_dmamask,224.coherent_dma_mask = DMA_BIT_MASK(32),225.platform_data = &mmc_data,226},227.resource = mmc_resources,228.num_resources = ARRAY_SIZE(mmc_resources),229};230231void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)232{233if (!data)234return;235236/* input/irq */237if (data->det_pin) {238at91_set_gpio_input(data->det_pin, 1);239at91_set_deglitch(data->det_pin, 1);240}241if (data->wp_pin)242at91_set_gpio_input(data->wp_pin, 1);243if (data->vcc_pin)244at91_set_gpio_output(data->vcc_pin, 0);245246/* CLK */247at91_set_A_periph(AT91_PIN_PA8, 0);248249if (data->slot_b) {250/* CMD */251at91_set_B_periph(AT91_PIN_PA1, 1);252253/* DAT0, maybe DAT1..DAT3 */254at91_set_B_periph(AT91_PIN_PA0, 1);255if (data->wire4) {256at91_set_B_periph(AT91_PIN_PA5, 1);257at91_set_B_periph(AT91_PIN_PA4, 1);258at91_set_B_periph(AT91_PIN_PA3, 1);259}260} else {261/* CMD */262at91_set_A_periph(AT91_PIN_PA7, 1);263264/* DAT0, maybe DAT1..DAT3 */265at91_set_A_periph(AT91_PIN_PA6, 1);266if (data->wire4) {267at91_set_A_periph(AT91_PIN_PA9, 1);268at91_set_A_periph(AT91_PIN_PA10, 1);269at91_set_A_periph(AT91_PIN_PA11, 1);270}271}272273mmc_data = *data;274platform_device_register(&at91sam9260_mmc_device);275}276#else277void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}278#endif279280/* --------------------------------------------------------------------281* MMC / SD Slot for Atmel MCI Driver282* -------------------------------------------------------------------- */283284#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)285static u64 mmc_dmamask = DMA_BIT_MASK(32);286static struct mci_platform_data mmc_data;287288static struct resource mmc_resources[] = {289[0] = {290.start = AT91SAM9260_BASE_MCI,291.end = AT91SAM9260_BASE_MCI + SZ_16K - 1,292.flags = IORESOURCE_MEM,293},294[1] = {295.start = AT91SAM9260_ID_MCI,296.end = AT91SAM9260_ID_MCI,297.flags = IORESOURCE_IRQ,298},299};300301static struct platform_device at91sam9260_mmc_device = {302.name = "atmel_mci",303.id = -1,304.dev = {305.dma_mask = &mmc_dmamask,306.coherent_dma_mask = DMA_BIT_MASK(32),307.platform_data = &mmc_data,308},309.resource = mmc_resources,310.num_resources = ARRAY_SIZE(mmc_resources),311};312313void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)314{315unsigned int i;316unsigned int slot_count = 0;317318if (!data)319return;320321for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {322if (data->slot[i].bus_width) {323/* input/irq */324if (data->slot[i].detect_pin) {325at91_set_gpio_input(data->slot[i].detect_pin, 1);326at91_set_deglitch(data->slot[i].detect_pin, 1);327}328if (data->slot[i].wp_pin)329at91_set_gpio_input(data->slot[i].wp_pin, 1);330331switch (i) {332case 0:333/* CMD */334at91_set_A_periph(AT91_PIN_PA7, 1);335/* DAT0, maybe DAT1..DAT3 */336at91_set_A_periph(AT91_PIN_PA6, 1);337if (data->slot[i].bus_width == 4) {338at91_set_A_periph(AT91_PIN_PA9, 1);339at91_set_A_periph(AT91_PIN_PA10, 1);340at91_set_A_periph(AT91_PIN_PA11, 1);341}342slot_count++;343break;344case 1:345/* CMD */346at91_set_B_periph(AT91_PIN_PA1, 1);347/* DAT0, maybe DAT1..DAT3 */348at91_set_B_periph(AT91_PIN_PA0, 1);349if (data->slot[i].bus_width == 4) {350at91_set_B_periph(AT91_PIN_PA5, 1);351at91_set_B_periph(AT91_PIN_PA4, 1);352at91_set_B_periph(AT91_PIN_PA3, 1);353}354slot_count++;355break;356default:357printk(KERN_ERR358"AT91: SD/MMC slot %d not available\n", i);359break;360}361}362}363364if (slot_count) {365/* CLK */366at91_set_A_periph(AT91_PIN_PA8, 0);367368mmc_data = *data;369platform_device_register(&at91sam9260_mmc_device);370}371}372#else373void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}374#endif375376377/* --------------------------------------------------------------------378* NAND / SmartMedia379* -------------------------------------------------------------------- */380381#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)382static struct atmel_nand_data nand_data;383384#define NAND_BASE AT91_CHIPSELECT_3385386static struct resource nand_resources[] = {387[0] = {388.start = NAND_BASE,389.end = NAND_BASE + SZ_256M - 1,390.flags = IORESOURCE_MEM,391},392[1] = {393.start = AT91_BASE_SYS + AT91_ECC,394.end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,395.flags = IORESOURCE_MEM,396}397};398399static struct platform_device at91sam9260_nand_device = {400.name = "atmel_nand",401.id = -1,402.dev = {403.platform_data = &nand_data,404},405.resource = nand_resources,406.num_resources = ARRAY_SIZE(nand_resources),407};408409void __init at91_add_device_nand(struct atmel_nand_data *data)410{411unsigned long csa;412413if (!data)414return;415416csa = at91_sys_read(AT91_MATRIX_EBICSA);417at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);418419/* enable pin */420if (data->enable_pin)421at91_set_gpio_output(data->enable_pin, 1);422423/* ready/busy pin */424if (data->rdy_pin)425at91_set_gpio_input(data->rdy_pin, 1);426427/* card detect pin */428if (data->det_pin)429at91_set_gpio_input(data->det_pin, 1);430431nand_data = *data;432platform_device_register(&at91sam9260_nand_device);433}434#else435void __init at91_add_device_nand(struct atmel_nand_data *data) {}436#endif437438439/* --------------------------------------------------------------------440* TWI (i2c)441* -------------------------------------------------------------------- */442443/*444* Prefer the GPIO code since the TWI controller isn't robust445* (gets overruns and underruns under load) and can only issue446* repeated STARTs in one scenario (the driver doesn't yet handle them).447*/448449#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)450451static struct i2c_gpio_platform_data pdata = {452.sda_pin = AT91_PIN_PA23,453.sda_is_open_drain = 1,454.scl_pin = AT91_PIN_PA24,455.scl_is_open_drain = 1,456.udelay = 2, /* ~100 kHz */457};458459static struct platform_device at91sam9260_twi_device = {460.name = "i2c-gpio",461.id = -1,462.dev.platform_data = &pdata,463};464465void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)466{467at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */468at91_set_multi_drive(AT91_PIN_PA23, 1);469470at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */471at91_set_multi_drive(AT91_PIN_PA24, 1);472473i2c_register_board_info(0, devices, nr_devices);474platform_device_register(&at91sam9260_twi_device);475}476477#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)478479static struct resource twi_resources[] = {480[0] = {481.start = AT91SAM9260_BASE_TWI,482.end = AT91SAM9260_BASE_TWI + SZ_16K - 1,483.flags = IORESOURCE_MEM,484},485[1] = {486.start = AT91SAM9260_ID_TWI,487.end = AT91SAM9260_ID_TWI,488.flags = IORESOURCE_IRQ,489},490};491492static struct platform_device at91sam9260_twi_device = {493.name = "at91_i2c",494.id = -1,495.resource = twi_resources,496.num_resources = ARRAY_SIZE(twi_resources),497};498499void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)500{501/* pins used for TWI interface */502at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */503at91_set_multi_drive(AT91_PIN_PA23, 1);504505at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */506at91_set_multi_drive(AT91_PIN_PA24, 1);507508i2c_register_board_info(0, devices, nr_devices);509platform_device_register(&at91sam9260_twi_device);510}511#else512void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}513#endif514515516/* --------------------------------------------------------------------517* SPI518* -------------------------------------------------------------------- */519520#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)521static u64 spi_dmamask = DMA_BIT_MASK(32);522523static struct resource spi0_resources[] = {524[0] = {525.start = AT91SAM9260_BASE_SPI0,526.end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,527.flags = IORESOURCE_MEM,528},529[1] = {530.start = AT91SAM9260_ID_SPI0,531.end = AT91SAM9260_ID_SPI0,532.flags = IORESOURCE_IRQ,533},534};535536static struct platform_device at91sam9260_spi0_device = {537.name = "atmel_spi",538.id = 0,539.dev = {540.dma_mask = &spi_dmamask,541.coherent_dma_mask = DMA_BIT_MASK(32),542},543.resource = spi0_resources,544.num_resources = ARRAY_SIZE(spi0_resources),545};546547static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };548549static struct resource spi1_resources[] = {550[0] = {551.start = AT91SAM9260_BASE_SPI1,552.end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,553.flags = IORESOURCE_MEM,554},555[1] = {556.start = AT91SAM9260_ID_SPI1,557.end = AT91SAM9260_ID_SPI1,558.flags = IORESOURCE_IRQ,559},560};561562static struct platform_device at91sam9260_spi1_device = {563.name = "atmel_spi",564.id = 1,565.dev = {566.dma_mask = &spi_dmamask,567.coherent_dma_mask = DMA_BIT_MASK(32),568},569.resource = spi1_resources,570.num_resources = ARRAY_SIZE(spi1_resources),571};572573static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };574575void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)576{577int i;578unsigned long cs_pin;579short enable_spi0 = 0;580short enable_spi1 = 0;581582/* Choose SPI chip-selects */583for (i = 0; i < nr_devices; i++) {584if (devices[i].controller_data)585cs_pin = (unsigned long) devices[i].controller_data;586else if (devices[i].bus_num == 0)587cs_pin = spi0_standard_cs[devices[i].chip_select];588else589cs_pin = spi1_standard_cs[devices[i].chip_select];590591if (devices[i].bus_num == 0)592enable_spi0 = 1;593else594enable_spi1 = 1;595596/* enable chip-select pin */597at91_set_gpio_output(cs_pin, 1);598599/* pass chip-select pin to driver */600devices[i].controller_data = (void *) cs_pin;601}602603spi_register_board_info(devices, nr_devices);604605/* Configure SPI bus(es) */606if (enable_spi0) {607at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */608at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */609at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */610611platform_device_register(&at91sam9260_spi0_device);612}613if (enable_spi1) {614at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */615at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */616at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */617618platform_device_register(&at91sam9260_spi1_device);619}620}621#else622void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}623#endif624625626/* --------------------------------------------------------------------627* Timer/Counter blocks628* -------------------------------------------------------------------- */629630#ifdef CONFIG_ATMEL_TCLIB631632static struct resource tcb0_resources[] = {633[0] = {634.start = AT91SAM9260_BASE_TCB0,635.end = AT91SAM9260_BASE_TCB0 + SZ_16K - 1,636.flags = IORESOURCE_MEM,637},638[1] = {639.start = AT91SAM9260_ID_TC0,640.end = AT91SAM9260_ID_TC0,641.flags = IORESOURCE_IRQ,642},643[2] = {644.start = AT91SAM9260_ID_TC1,645.end = AT91SAM9260_ID_TC1,646.flags = IORESOURCE_IRQ,647},648[3] = {649.start = AT91SAM9260_ID_TC2,650.end = AT91SAM9260_ID_TC2,651.flags = IORESOURCE_IRQ,652},653};654655static struct platform_device at91sam9260_tcb0_device = {656.name = "atmel_tcb",657.id = 0,658.resource = tcb0_resources,659.num_resources = ARRAY_SIZE(tcb0_resources),660};661662static struct resource tcb1_resources[] = {663[0] = {664.start = AT91SAM9260_BASE_TCB1,665.end = AT91SAM9260_BASE_TCB1 + SZ_16K - 1,666.flags = IORESOURCE_MEM,667},668[1] = {669.start = AT91SAM9260_ID_TC3,670.end = AT91SAM9260_ID_TC3,671.flags = IORESOURCE_IRQ,672},673[2] = {674.start = AT91SAM9260_ID_TC4,675.end = AT91SAM9260_ID_TC4,676.flags = IORESOURCE_IRQ,677},678[3] = {679.start = AT91SAM9260_ID_TC5,680.end = AT91SAM9260_ID_TC5,681.flags = IORESOURCE_IRQ,682},683};684685static struct platform_device at91sam9260_tcb1_device = {686.name = "atmel_tcb",687.id = 1,688.resource = tcb1_resources,689.num_resources = ARRAY_SIZE(tcb1_resources),690};691692static void __init at91_add_device_tc(void)693{694platform_device_register(&at91sam9260_tcb0_device);695platform_device_register(&at91sam9260_tcb1_device);696}697#else698static void __init at91_add_device_tc(void) { }699#endif700701702/* --------------------------------------------------------------------703* RTT704* -------------------------------------------------------------------- */705706static struct resource rtt_resources[] = {707{708.start = AT91_BASE_SYS + AT91_RTT,709.end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,710.flags = IORESOURCE_MEM,711}712};713714static struct platform_device at91sam9260_rtt_device = {715.name = "at91_rtt",716.id = 0,717.resource = rtt_resources,718.num_resources = ARRAY_SIZE(rtt_resources),719};720721static void __init at91_add_device_rtt(void)722{723platform_device_register(&at91sam9260_rtt_device);724}725726727/* --------------------------------------------------------------------728* Watchdog729* -------------------------------------------------------------------- */730731#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)732static struct platform_device at91sam9260_wdt_device = {733.name = "at91_wdt",734.id = -1,735.num_resources = 0,736};737738static void __init at91_add_device_watchdog(void)739{740platform_device_register(&at91sam9260_wdt_device);741}742#else743static void __init at91_add_device_watchdog(void) {}744#endif745746747/* --------------------------------------------------------------------748* SSC -- Synchronous Serial Controller749* -------------------------------------------------------------------- */750751#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)752static u64 ssc_dmamask = DMA_BIT_MASK(32);753754static struct resource ssc_resources[] = {755[0] = {756.start = AT91SAM9260_BASE_SSC,757.end = AT91SAM9260_BASE_SSC + SZ_16K - 1,758.flags = IORESOURCE_MEM,759},760[1] = {761.start = AT91SAM9260_ID_SSC,762.end = AT91SAM9260_ID_SSC,763.flags = IORESOURCE_IRQ,764},765};766767static struct platform_device at91sam9260_ssc_device = {768.name = "ssc",769.id = 0,770.dev = {771.dma_mask = &ssc_dmamask,772.coherent_dma_mask = DMA_BIT_MASK(32),773},774.resource = ssc_resources,775.num_resources = ARRAY_SIZE(ssc_resources),776};777778static inline void configure_ssc_pins(unsigned pins)779{780if (pins & ATMEL_SSC_TF)781at91_set_A_periph(AT91_PIN_PB17, 1);782if (pins & ATMEL_SSC_TK)783at91_set_A_periph(AT91_PIN_PB16, 1);784if (pins & ATMEL_SSC_TD)785at91_set_A_periph(AT91_PIN_PB18, 1);786if (pins & ATMEL_SSC_RD)787at91_set_A_periph(AT91_PIN_PB19, 1);788if (pins & ATMEL_SSC_RK)789at91_set_A_periph(AT91_PIN_PB20, 1);790if (pins & ATMEL_SSC_RF)791at91_set_A_periph(AT91_PIN_PB21, 1);792}793794/*795* SSC controllers are accessed through library code, instead of any796* kind of all-singing/all-dancing driver. For example one could be797* used by a particular I2S audio codec's driver, while another one798* on the same system might be used by a custom data capture driver.799*/800void __init at91_add_device_ssc(unsigned id, unsigned pins)801{802struct platform_device *pdev;803804/*805* NOTE: caller is responsible for passing information matching806* "pins" to whatever will be using each particular controller.807*/808switch (id) {809case AT91SAM9260_ID_SSC:810pdev = &at91sam9260_ssc_device;811configure_ssc_pins(pins);812break;813default:814return;815}816817platform_device_register(pdev);818}819820#else821void __init at91_add_device_ssc(unsigned id, unsigned pins) {}822#endif823824825/* --------------------------------------------------------------------826* UART827* -------------------------------------------------------------------- */828#if defined(CONFIG_SERIAL_ATMEL)829static struct resource dbgu_resources[] = {830[0] = {831.start = AT91_VA_BASE_SYS + AT91_DBGU,832.end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,833.flags = IORESOURCE_MEM,834},835[1] = {836.start = AT91_ID_SYS,837.end = AT91_ID_SYS,838.flags = IORESOURCE_IRQ,839},840};841842static struct atmel_uart_data dbgu_data = {843.use_dma_tx = 0,844.use_dma_rx = 0, /* DBGU not capable of receive DMA */845.regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),846};847848static u64 dbgu_dmamask = DMA_BIT_MASK(32);849850static struct platform_device at91sam9260_dbgu_device = {851.name = "atmel_usart",852.id = 0,853.dev = {854.dma_mask = &dbgu_dmamask,855.coherent_dma_mask = DMA_BIT_MASK(32),856.platform_data = &dbgu_data,857},858.resource = dbgu_resources,859.num_resources = ARRAY_SIZE(dbgu_resources),860};861862static inline void configure_dbgu_pins(void)863{864at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */865at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */866}867868static struct resource uart0_resources[] = {869[0] = {870.start = AT91SAM9260_BASE_US0,871.end = AT91SAM9260_BASE_US0 + SZ_16K - 1,872.flags = IORESOURCE_MEM,873},874[1] = {875.start = AT91SAM9260_ID_US0,876.end = AT91SAM9260_ID_US0,877.flags = IORESOURCE_IRQ,878},879};880881static struct atmel_uart_data uart0_data = {882.use_dma_tx = 1,883.use_dma_rx = 1,884};885886static u64 uart0_dmamask = DMA_BIT_MASK(32);887888static struct platform_device at91sam9260_uart0_device = {889.name = "atmel_usart",890.id = 1,891.dev = {892.dma_mask = &uart0_dmamask,893.coherent_dma_mask = DMA_BIT_MASK(32),894.platform_data = &uart0_data,895},896.resource = uart0_resources,897.num_resources = ARRAY_SIZE(uart0_resources),898};899900static inline void configure_usart0_pins(unsigned pins)901{902at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */903at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */904905if (pins & ATMEL_UART_RTS)906at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */907if (pins & ATMEL_UART_CTS)908at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */909if (pins & ATMEL_UART_DTR)910at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */911if (pins & ATMEL_UART_DSR)912at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */913if (pins & ATMEL_UART_DCD)914at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */915if (pins & ATMEL_UART_RI)916at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */917}918919static struct resource uart1_resources[] = {920[0] = {921.start = AT91SAM9260_BASE_US1,922.end = AT91SAM9260_BASE_US1 + SZ_16K - 1,923.flags = IORESOURCE_MEM,924},925[1] = {926.start = AT91SAM9260_ID_US1,927.end = AT91SAM9260_ID_US1,928.flags = IORESOURCE_IRQ,929},930};931932static struct atmel_uart_data uart1_data = {933.use_dma_tx = 1,934.use_dma_rx = 1,935};936937static u64 uart1_dmamask = DMA_BIT_MASK(32);938939static struct platform_device at91sam9260_uart1_device = {940.name = "atmel_usart",941.id = 2,942.dev = {943.dma_mask = &uart1_dmamask,944.coherent_dma_mask = DMA_BIT_MASK(32),945.platform_data = &uart1_data,946},947.resource = uart1_resources,948.num_resources = ARRAY_SIZE(uart1_resources),949};950951static inline void configure_usart1_pins(unsigned pins)952{953at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */954at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */955956if (pins & ATMEL_UART_RTS)957at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */958if (pins & ATMEL_UART_CTS)959at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */960}961962static struct resource uart2_resources[] = {963[0] = {964.start = AT91SAM9260_BASE_US2,965.end = AT91SAM9260_BASE_US2 + SZ_16K - 1,966.flags = IORESOURCE_MEM,967},968[1] = {969.start = AT91SAM9260_ID_US2,970.end = AT91SAM9260_ID_US2,971.flags = IORESOURCE_IRQ,972},973};974975static struct atmel_uart_data uart2_data = {976.use_dma_tx = 1,977.use_dma_rx = 1,978};979980static u64 uart2_dmamask = DMA_BIT_MASK(32);981982static struct platform_device at91sam9260_uart2_device = {983.name = "atmel_usart",984.id = 3,985.dev = {986.dma_mask = &uart2_dmamask,987.coherent_dma_mask = DMA_BIT_MASK(32),988.platform_data = &uart2_data,989},990.resource = uart2_resources,991.num_resources = ARRAY_SIZE(uart2_resources),992};993994static inline void configure_usart2_pins(unsigned pins)995{996at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */997at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */998999if (pins & ATMEL_UART_RTS)1000at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */1001if (pins & ATMEL_UART_CTS)1002at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */1003}10041005static struct resource uart3_resources[] = {1006[0] = {1007.start = AT91SAM9260_BASE_US3,1008.end = AT91SAM9260_BASE_US3 + SZ_16K - 1,1009.flags = IORESOURCE_MEM,1010},1011[1] = {1012.start = AT91SAM9260_ID_US3,1013.end = AT91SAM9260_ID_US3,1014.flags = IORESOURCE_IRQ,1015},1016};10171018static struct atmel_uart_data uart3_data = {1019.use_dma_tx = 1,1020.use_dma_rx = 1,1021};10221023static u64 uart3_dmamask = DMA_BIT_MASK(32);10241025static struct platform_device at91sam9260_uart3_device = {1026.name = "atmel_usart",1027.id = 4,1028.dev = {1029.dma_mask = &uart3_dmamask,1030.coherent_dma_mask = DMA_BIT_MASK(32),1031.platform_data = &uart3_data,1032},1033.resource = uart3_resources,1034.num_resources = ARRAY_SIZE(uart3_resources),1035};10361037static inline void configure_usart3_pins(unsigned pins)1038{1039at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */1040at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */10411042if (pins & ATMEL_UART_RTS)1043at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */1044if (pins & ATMEL_UART_CTS)1045at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */1046}10471048static struct resource uart4_resources[] = {1049[0] = {1050.start = AT91SAM9260_BASE_US4,1051.end = AT91SAM9260_BASE_US4 + SZ_16K - 1,1052.flags = IORESOURCE_MEM,1053},1054[1] = {1055.start = AT91SAM9260_ID_US4,1056.end = AT91SAM9260_ID_US4,1057.flags = IORESOURCE_IRQ,1058},1059};10601061static struct atmel_uart_data uart4_data = {1062.use_dma_tx = 1,1063.use_dma_rx = 1,1064};10651066static u64 uart4_dmamask = DMA_BIT_MASK(32);10671068static struct platform_device at91sam9260_uart4_device = {1069.name = "atmel_usart",1070.id = 5,1071.dev = {1072.dma_mask = &uart4_dmamask,1073.coherent_dma_mask = DMA_BIT_MASK(32),1074.platform_data = &uart4_data,1075},1076.resource = uart4_resources,1077.num_resources = ARRAY_SIZE(uart4_resources),1078};10791080static inline void configure_usart4_pins(void)1081{1082at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */1083at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */1084}10851086static struct resource uart5_resources[] = {1087[0] = {1088.start = AT91SAM9260_BASE_US5,1089.end = AT91SAM9260_BASE_US5 + SZ_16K - 1,1090.flags = IORESOURCE_MEM,1091},1092[1] = {1093.start = AT91SAM9260_ID_US5,1094.end = AT91SAM9260_ID_US5,1095.flags = IORESOURCE_IRQ,1096},1097};10981099static struct atmel_uart_data uart5_data = {1100.use_dma_tx = 1,1101.use_dma_rx = 1,1102};11031104static u64 uart5_dmamask = DMA_BIT_MASK(32);11051106static struct platform_device at91sam9260_uart5_device = {1107.name = "atmel_usart",1108.id = 6,1109.dev = {1110.dma_mask = &uart5_dmamask,1111.coherent_dma_mask = DMA_BIT_MASK(32),1112.platform_data = &uart5_data,1113},1114.resource = uart5_resources,1115.num_resources = ARRAY_SIZE(uart5_resources),1116};11171118static inline void configure_usart5_pins(void)1119{1120at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */1121at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */1122}11231124static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */1125struct platform_device *atmel_default_console_device; /* the serial console device */11261127void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)1128{1129struct platform_device *pdev;1130struct atmel_uart_data *pdata;11311132switch (id) {1133case 0: /* DBGU */1134pdev = &at91sam9260_dbgu_device;1135configure_dbgu_pins();1136break;1137case AT91SAM9260_ID_US0:1138pdev = &at91sam9260_uart0_device;1139configure_usart0_pins(pins);1140break;1141case AT91SAM9260_ID_US1:1142pdev = &at91sam9260_uart1_device;1143configure_usart1_pins(pins);1144break;1145case AT91SAM9260_ID_US2:1146pdev = &at91sam9260_uart2_device;1147configure_usart2_pins(pins);1148break;1149case AT91SAM9260_ID_US3:1150pdev = &at91sam9260_uart3_device;1151configure_usart3_pins(pins);1152break;1153case AT91SAM9260_ID_US4:1154pdev = &at91sam9260_uart4_device;1155configure_usart4_pins();1156break;1157case AT91SAM9260_ID_US5:1158pdev = &at91sam9260_uart5_device;1159configure_usart5_pins();1160break;1161default:1162return;1163}1164pdata = pdev->dev.platform_data;1165pdata->num = portnr; /* update to mapped ID */11661167if (portnr < ATMEL_MAX_UART)1168at91_uarts[portnr] = pdev;1169}11701171void __init at91_set_serial_console(unsigned portnr)1172{1173if (portnr < ATMEL_MAX_UART) {1174atmel_default_console_device = at91_uarts[portnr];1175at91sam9260_set_console_clock(at91_uarts[portnr]->id);1176}1177}11781179void __init at91_add_device_serial(void)1180{1181int i;11821183for (i = 0; i < ATMEL_MAX_UART; i++) {1184if (at91_uarts[i])1185platform_device_register(at91_uarts[i]);1186}11871188if (!atmel_default_console_device)1189printk(KERN_INFO "AT91: No default serial console defined.\n");1190}1191#else1192void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}1193void __init at91_set_serial_console(unsigned portnr) {}1194void __init at91_add_device_serial(void) {}1195#endif11961197/* --------------------------------------------------------------------1198* CF/IDE1199* -------------------------------------------------------------------- */12001201#if defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE) || \1202defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \1203defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)12041205static struct at91_cf_data cf0_data;12061207static struct resource cf0_resources[] = {1208[0] = {1209.start = AT91_CHIPSELECT_4,1210.end = AT91_CHIPSELECT_4 + SZ_256M - 1,1211.flags = IORESOURCE_MEM,1212}1213};12141215static struct platform_device cf0_device = {1216.id = 0,1217.dev = {1218.platform_data = &cf0_data,1219},1220.resource = cf0_resources,1221.num_resources = ARRAY_SIZE(cf0_resources),1222};12231224static struct at91_cf_data cf1_data;12251226static struct resource cf1_resources[] = {1227[0] = {1228.start = AT91_CHIPSELECT_5,1229.end = AT91_CHIPSELECT_5 + SZ_256M - 1,1230.flags = IORESOURCE_MEM,1231}1232};12331234static struct platform_device cf1_device = {1235.id = 1,1236.dev = {1237.platform_data = &cf1_data,1238},1239.resource = cf1_resources,1240.num_resources = ARRAY_SIZE(cf1_resources),1241};12421243void __init at91_add_device_cf(struct at91_cf_data *data)1244{1245struct platform_device *pdev;1246unsigned long csa;12471248if (!data)1249return;12501251csa = at91_sys_read(AT91_MATRIX_EBICSA);12521253switch (data->chipselect) {1254case 4:1255at91_set_multi_drive(AT91_PIN_PC8, 0);1256at91_set_A_periph(AT91_PIN_PC8, 0);1257csa |= AT91_MATRIX_CS4A_SMC_CF1;1258cf0_data = *data;1259pdev = &cf0_device;1260break;1261case 5:1262at91_set_multi_drive(AT91_PIN_PC9, 0);1263at91_set_A_periph(AT91_PIN_PC9, 0);1264csa |= AT91_MATRIX_CS5A_SMC_CF2;1265cf1_data = *data;1266pdev = &cf1_device;1267break;1268default:1269printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",1270data->chipselect);1271return;1272}12731274at91_sys_write(AT91_MATRIX_EBICSA, csa);12751276if (data->rst_pin) {1277at91_set_multi_drive(data->rst_pin, 0);1278at91_set_gpio_output(data->rst_pin, 1);1279}12801281if (data->irq_pin) {1282at91_set_gpio_input(data->irq_pin, 0);1283at91_set_deglitch(data->irq_pin, 1);1284}12851286if (data->det_pin) {1287at91_set_gpio_input(data->det_pin, 0);1288at91_set_deglitch(data->det_pin, 1);1289}12901291at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */1292at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */1293at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */1294at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */12951296if (data->flags & AT91_CF_TRUE_IDE)1297#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)1298pdev->name = "pata_at91";1299#elif defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE)1300pdev->name = "at91_ide";1301#else1302#warning "board requires AT91_CF_TRUE_IDE: enable either at91_ide or pata_at91"1303#endif1304else1305pdev->name = "at91_cf";13061307platform_device_register(pdev);1308}13091310#else1311void __init at91_add_device_cf(struct at91_cf_data * data) {}1312#endif13131314/* -------------------------------------------------------------------- */1315/*1316* These devices are always present and don't need any board-specific1317* setup.1318*/1319static int __init at91_add_standard_devices(void)1320{1321at91_add_device_rtt();1322at91_add_device_watchdog();1323at91_add_device_tc();1324return 0;1325}13261327arch_initcall(at91_add_standard_devices);132813291330