Path: blob/master/arch/arm/mach-at91/at91sam9261_devices.c
10817 views
/*1* arch/arm/mach-at91/at91sam9261_devices.c2*3* Copyright (C) 2005 Thibaut VARENE <[email protected]>4* Copyright (C) 2005 David Brownell5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11*/12#include <asm/mach/arch.h>13#include <asm/mach/map.h>1415#include <linux/dma-mapping.h>16#include <linux/platform_device.h>17#include <linux/i2c-gpio.h>1819#include <linux/fb.h>20#include <video/atmel_lcdc.h>2122#include <mach/board.h>23#include <mach/gpio.h>24#include <mach/at91sam9261.h>25#include <mach/at91sam9261_matrix.h>26#include <mach/at91sam9_smc.h>2728#include "generic.h"293031/* --------------------------------------------------------------------32* USB Host33* -------------------------------------------------------------------- */3435#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)36static u64 ohci_dmamask = DMA_BIT_MASK(32);37static struct at91_usbh_data usbh_data;3839static struct resource usbh_resources[] = {40[0] = {41.start = AT91SAM9261_UHP_BASE,42.end = AT91SAM9261_UHP_BASE + SZ_1M - 1,43.flags = IORESOURCE_MEM,44},45[1] = {46.start = AT91SAM9261_ID_UHP,47.end = AT91SAM9261_ID_UHP,48.flags = IORESOURCE_IRQ,49},50};5152static struct platform_device at91sam9261_usbh_device = {53.name = "at91_ohci",54.id = -1,55.dev = {56.dma_mask = &ohci_dmamask,57.coherent_dma_mask = DMA_BIT_MASK(32),58.platform_data = &usbh_data,59},60.resource = usbh_resources,61.num_resources = ARRAY_SIZE(usbh_resources),62};6364void __init at91_add_device_usbh(struct at91_usbh_data *data)65{66if (!data)67return;6869usbh_data = *data;70platform_device_register(&at91sam9261_usbh_device);71}72#else73void __init at91_add_device_usbh(struct at91_usbh_data *data) {}74#endif757677/* --------------------------------------------------------------------78* USB Device (Gadget)79* -------------------------------------------------------------------- */8081#ifdef CONFIG_USB_GADGET_AT9182static struct at91_udc_data udc_data;8384static struct resource udc_resources[] = {85[0] = {86.start = AT91SAM9261_BASE_UDP,87.end = AT91SAM9261_BASE_UDP + SZ_16K - 1,88.flags = IORESOURCE_MEM,89},90[1] = {91.start = AT91SAM9261_ID_UDP,92.end = AT91SAM9261_ID_UDP,93.flags = IORESOURCE_IRQ,94},95};9697static struct platform_device at91sam9261_udc_device = {98.name = "at91_udc",99.id = -1,100.dev = {101.platform_data = &udc_data,102},103.resource = udc_resources,104.num_resources = ARRAY_SIZE(udc_resources),105};106107void __init at91_add_device_udc(struct at91_udc_data *data)108{109if (!data)110return;111112if (data->vbus_pin) {113at91_set_gpio_input(data->vbus_pin, 0);114at91_set_deglitch(data->vbus_pin, 1);115}116117/* Pullup pin is handled internally by USB device peripheral */118119udc_data = *data;120platform_device_register(&at91sam9261_udc_device);121}122#else123void __init at91_add_device_udc(struct at91_udc_data *data) {}124#endif125126/* --------------------------------------------------------------------127* MMC / SD128* -------------------------------------------------------------------- */129130#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)131static u64 mmc_dmamask = DMA_BIT_MASK(32);132static struct at91_mmc_data mmc_data;133134static struct resource mmc_resources[] = {135[0] = {136.start = AT91SAM9261_BASE_MCI,137.end = AT91SAM9261_BASE_MCI + SZ_16K - 1,138.flags = IORESOURCE_MEM,139},140[1] = {141.start = AT91SAM9261_ID_MCI,142.end = AT91SAM9261_ID_MCI,143.flags = IORESOURCE_IRQ,144},145};146147static struct platform_device at91sam9261_mmc_device = {148.name = "at91_mci",149.id = -1,150.dev = {151.dma_mask = &mmc_dmamask,152.coherent_dma_mask = DMA_BIT_MASK(32),153.platform_data = &mmc_data,154},155.resource = mmc_resources,156.num_resources = ARRAY_SIZE(mmc_resources),157};158159void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)160{161if (!data)162return;163164/* input/irq */165if (data->det_pin) {166at91_set_gpio_input(data->det_pin, 1);167at91_set_deglitch(data->det_pin, 1);168}169if (data->wp_pin)170at91_set_gpio_input(data->wp_pin, 1);171if (data->vcc_pin)172at91_set_gpio_output(data->vcc_pin, 0);173174/* CLK */175at91_set_B_periph(AT91_PIN_PA2, 0);176177/* CMD */178at91_set_B_periph(AT91_PIN_PA1, 1);179180/* DAT0, maybe DAT1..DAT3 */181at91_set_B_periph(AT91_PIN_PA0, 1);182if (data->wire4) {183at91_set_B_periph(AT91_PIN_PA4, 1);184at91_set_B_periph(AT91_PIN_PA5, 1);185at91_set_B_periph(AT91_PIN_PA6, 1);186}187188mmc_data = *data;189platform_device_register(&at91sam9261_mmc_device);190}191#else192void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}193#endif194195196/* --------------------------------------------------------------------197* NAND / SmartMedia198* -------------------------------------------------------------------- */199200#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)201static struct atmel_nand_data nand_data;202203#define NAND_BASE AT91_CHIPSELECT_3204205static struct resource nand_resources[] = {206{207.start = NAND_BASE,208.end = NAND_BASE + SZ_256M - 1,209.flags = IORESOURCE_MEM,210}211};212213static struct platform_device atmel_nand_device = {214.name = "atmel_nand",215.id = -1,216.dev = {217.platform_data = &nand_data,218},219.resource = nand_resources,220.num_resources = ARRAY_SIZE(nand_resources),221};222223void __init at91_add_device_nand(struct atmel_nand_data *data)224{225unsigned long csa;226227if (!data)228return;229230csa = at91_sys_read(AT91_MATRIX_EBICSA);231at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);232233/* enable pin */234if (data->enable_pin)235at91_set_gpio_output(data->enable_pin, 1);236237/* ready/busy pin */238if (data->rdy_pin)239at91_set_gpio_input(data->rdy_pin, 1);240241/* card detect pin */242if (data->det_pin)243at91_set_gpio_input(data->det_pin, 1);244245at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */246at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */247248nand_data = *data;249platform_device_register(&atmel_nand_device);250}251252#else253void __init at91_add_device_nand(struct atmel_nand_data *data) {}254#endif255256257/* --------------------------------------------------------------------258* TWI (i2c)259* -------------------------------------------------------------------- */260261/*262* Prefer the GPIO code since the TWI controller isn't robust263* (gets overruns and underruns under load) and can only issue264* repeated STARTs in one scenario (the driver doesn't yet handle them).265*/266#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)267268static struct i2c_gpio_platform_data pdata = {269.sda_pin = AT91_PIN_PA7,270.sda_is_open_drain = 1,271.scl_pin = AT91_PIN_PA8,272.scl_is_open_drain = 1,273.udelay = 2, /* ~100 kHz */274};275276static struct platform_device at91sam9261_twi_device = {277.name = "i2c-gpio",278.id = -1,279.dev.platform_data = &pdata,280};281282void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)283{284at91_set_GPIO_periph(AT91_PIN_PA7, 1); /* TWD (SDA) */285at91_set_multi_drive(AT91_PIN_PA7, 1);286287at91_set_GPIO_periph(AT91_PIN_PA8, 1); /* TWCK (SCL) */288at91_set_multi_drive(AT91_PIN_PA8, 1);289290i2c_register_board_info(0, devices, nr_devices);291platform_device_register(&at91sam9261_twi_device);292}293294#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)295296static struct resource twi_resources[] = {297[0] = {298.start = AT91SAM9261_BASE_TWI,299.end = AT91SAM9261_BASE_TWI + SZ_16K - 1,300.flags = IORESOURCE_MEM,301},302[1] = {303.start = AT91SAM9261_ID_TWI,304.end = AT91SAM9261_ID_TWI,305.flags = IORESOURCE_IRQ,306},307};308309static struct platform_device at91sam9261_twi_device = {310.name = "at91_i2c",311.id = -1,312.resource = twi_resources,313.num_resources = ARRAY_SIZE(twi_resources),314};315316void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)317{318/* pins used for TWI interface */319at91_set_A_periph(AT91_PIN_PA7, 0); /* TWD */320at91_set_multi_drive(AT91_PIN_PA7, 1);321322at91_set_A_periph(AT91_PIN_PA8, 0); /* TWCK */323at91_set_multi_drive(AT91_PIN_PA8, 1);324325i2c_register_board_info(0, devices, nr_devices);326platform_device_register(&at91sam9261_twi_device);327}328#else329void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}330#endif331332333/* --------------------------------------------------------------------334* SPI335* -------------------------------------------------------------------- */336337#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)338static u64 spi_dmamask = DMA_BIT_MASK(32);339340static struct resource spi0_resources[] = {341[0] = {342.start = AT91SAM9261_BASE_SPI0,343.end = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,344.flags = IORESOURCE_MEM,345},346[1] = {347.start = AT91SAM9261_ID_SPI0,348.end = AT91SAM9261_ID_SPI0,349.flags = IORESOURCE_IRQ,350},351};352353static struct platform_device at91sam9261_spi0_device = {354.name = "atmel_spi",355.id = 0,356.dev = {357.dma_mask = &spi_dmamask,358.coherent_dma_mask = DMA_BIT_MASK(32),359},360.resource = spi0_resources,361.num_resources = ARRAY_SIZE(spi0_resources),362};363364static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };365366static struct resource spi1_resources[] = {367[0] = {368.start = AT91SAM9261_BASE_SPI1,369.end = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,370.flags = IORESOURCE_MEM,371},372[1] = {373.start = AT91SAM9261_ID_SPI1,374.end = AT91SAM9261_ID_SPI1,375.flags = IORESOURCE_IRQ,376},377};378379static struct platform_device at91sam9261_spi1_device = {380.name = "atmel_spi",381.id = 1,382.dev = {383.dma_mask = &spi_dmamask,384.coherent_dma_mask = DMA_BIT_MASK(32),385},386.resource = spi1_resources,387.num_resources = ARRAY_SIZE(spi1_resources),388};389390static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };391392void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)393{394int i;395unsigned long cs_pin;396short enable_spi0 = 0;397short enable_spi1 = 0;398399/* Choose SPI chip-selects */400for (i = 0; i < nr_devices; i++) {401if (devices[i].controller_data)402cs_pin = (unsigned long) devices[i].controller_data;403else if (devices[i].bus_num == 0)404cs_pin = spi0_standard_cs[devices[i].chip_select];405else406cs_pin = spi1_standard_cs[devices[i].chip_select];407408if (devices[i].bus_num == 0)409enable_spi0 = 1;410else411enable_spi1 = 1;412413/* enable chip-select pin */414at91_set_gpio_output(cs_pin, 1);415416/* pass chip-select pin to driver */417devices[i].controller_data = (void *) cs_pin;418}419420spi_register_board_info(devices, nr_devices);421422/* Configure SPI bus(es) */423if (enable_spi0) {424at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */425at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */426at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */427428platform_device_register(&at91sam9261_spi0_device);429}430if (enable_spi1) {431at91_set_A_periph(AT91_PIN_PB30, 0); /* SPI1_MISO */432at91_set_A_periph(AT91_PIN_PB31, 0); /* SPI1_MOSI */433at91_set_A_periph(AT91_PIN_PB29, 0); /* SPI1_SPCK */434435platform_device_register(&at91sam9261_spi1_device);436}437}438#else439void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}440#endif441442443/* --------------------------------------------------------------------444* LCD Controller445* -------------------------------------------------------------------- */446447#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)448static u64 lcdc_dmamask = DMA_BIT_MASK(32);449static struct atmel_lcdfb_info lcdc_data;450451static struct resource lcdc_resources[] = {452[0] = {453.start = AT91SAM9261_LCDC_BASE,454.end = AT91SAM9261_LCDC_BASE + SZ_4K - 1,455.flags = IORESOURCE_MEM,456},457[1] = {458.start = AT91SAM9261_ID_LCDC,459.end = AT91SAM9261_ID_LCDC,460.flags = IORESOURCE_IRQ,461},462#if defined(CONFIG_FB_INTSRAM)463[2] = {464.start = AT91SAM9261_SRAM_BASE,465.end = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,466.flags = IORESOURCE_MEM,467},468#endif469};470471static struct platform_device at91_lcdc_device = {472.name = "atmel_lcdfb",473.id = 0,474.dev = {475.dma_mask = &lcdc_dmamask,476.coherent_dma_mask = DMA_BIT_MASK(32),477.platform_data = &lcdc_data,478},479.resource = lcdc_resources,480.num_resources = ARRAY_SIZE(lcdc_resources),481};482483void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)484{485if (!data) {486return;487}488489#if defined(CONFIG_FB_ATMEL_STN)490at91_set_A_periph(AT91_PIN_PB0, 0); /* LCDVSYNC */491at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */492at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */493at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */494at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */495at91_set_A_periph(AT91_PIN_PB5, 0); /* LCDD0 */496at91_set_A_periph(AT91_PIN_PB6, 0); /* LCDD1 */497at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */498at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */499#else500at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */501at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */502at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */503at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */504at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */505at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */506at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */507at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */508at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */509at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */510at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */511at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */512at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */513at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */514at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */515at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */516at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */517at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */518at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */519at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */520at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */521at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */522#endif523524if (ARRAY_SIZE(lcdc_resources) > 2) {525void __iomem *fb;526struct resource *fb_res = &lcdc_resources[2];527size_t fb_len = fb_res->end - fb_res->start + 1;528529fb = ioremap(fb_res->start, fb_len);530if (fb) {531memset(fb, 0, fb_len);532iounmap(fb);533}534}535lcdc_data = *data;536platform_device_register(&at91_lcdc_device);537}538#else539void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}540#endif541542543/* --------------------------------------------------------------------544* Timer/Counter block545* -------------------------------------------------------------------- */546547#ifdef CONFIG_ATMEL_TCLIB548549static struct resource tcb_resources[] = {550[0] = {551.start = AT91SAM9261_BASE_TCB0,552.end = AT91SAM9261_BASE_TCB0 + SZ_16K - 1,553.flags = IORESOURCE_MEM,554},555[1] = {556.start = AT91SAM9261_ID_TC0,557.end = AT91SAM9261_ID_TC0,558.flags = IORESOURCE_IRQ,559},560[2] = {561.start = AT91SAM9261_ID_TC1,562.end = AT91SAM9261_ID_TC1,563.flags = IORESOURCE_IRQ,564},565[3] = {566.start = AT91SAM9261_ID_TC2,567.end = AT91SAM9261_ID_TC2,568.flags = IORESOURCE_IRQ,569},570};571572static struct platform_device at91sam9261_tcb_device = {573.name = "atmel_tcb",574.id = 0,575.resource = tcb_resources,576.num_resources = ARRAY_SIZE(tcb_resources),577};578579static void __init at91_add_device_tc(void)580{581platform_device_register(&at91sam9261_tcb_device);582}583#else584static void __init at91_add_device_tc(void) { }585#endif586587588/* --------------------------------------------------------------------589* RTT590* -------------------------------------------------------------------- */591592static struct resource rtt_resources[] = {593{594.start = AT91_BASE_SYS + AT91_RTT,595.end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,596.flags = IORESOURCE_MEM,597}598};599600static struct platform_device at91sam9261_rtt_device = {601.name = "at91_rtt",602.id = 0,603.resource = rtt_resources,604.num_resources = ARRAY_SIZE(rtt_resources),605};606607static void __init at91_add_device_rtt(void)608{609platform_device_register(&at91sam9261_rtt_device);610}611612613/* --------------------------------------------------------------------614* Watchdog615* -------------------------------------------------------------------- */616617#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)618static struct platform_device at91sam9261_wdt_device = {619.name = "at91_wdt",620.id = -1,621.num_resources = 0,622};623624static void __init at91_add_device_watchdog(void)625{626platform_device_register(&at91sam9261_wdt_device);627}628#else629static void __init at91_add_device_watchdog(void) {}630#endif631632633/* --------------------------------------------------------------------634* SSC -- Synchronous Serial Controller635* -------------------------------------------------------------------- */636637#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)638static u64 ssc0_dmamask = DMA_BIT_MASK(32);639640static struct resource ssc0_resources[] = {641[0] = {642.start = AT91SAM9261_BASE_SSC0,643.end = AT91SAM9261_BASE_SSC0 + SZ_16K - 1,644.flags = IORESOURCE_MEM,645},646[1] = {647.start = AT91SAM9261_ID_SSC0,648.end = AT91SAM9261_ID_SSC0,649.flags = IORESOURCE_IRQ,650},651};652653static struct platform_device at91sam9261_ssc0_device = {654.name = "ssc",655.id = 0,656.dev = {657.dma_mask = &ssc0_dmamask,658.coherent_dma_mask = DMA_BIT_MASK(32),659},660.resource = ssc0_resources,661.num_resources = ARRAY_SIZE(ssc0_resources),662};663664static inline void configure_ssc0_pins(unsigned pins)665{666if (pins & ATMEL_SSC_TF)667at91_set_A_periph(AT91_PIN_PB21, 1);668if (pins & ATMEL_SSC_TK)669at91_set_A_periph(AT91_PIN_PB22, 1);670if (pins & ATMEL_SSC_TD)671at91_set_A_periph(AT91_PIN_PB23, 1);672if (pins & ATMEL_SSC_RD)673at91_set_A_periph(AT91_PIN_PB24, 1);674if (pins & ATMEL_SSC_RK)675at91_set_A_periph(AT91_PIN_PB25, 1);676if (pins & ATMEL_SSC_RF)677at91_set_A_periph(AT91_PIN_PB26, 1);678}679680static u64 ssc1_dmamask = DMA_BIT_MASK(32);681682static struct resource ssc1_resources[] = {683[0] = {684.start = AT91SAM9261_BASE_SSC1,685.end = AT91SAM9261_BASE_SSC1 + SZ_16K - 1,686.flags = IORESOURCE_MEM,687},688[1] = {689.start = AT91SAM9261_ID_SSC1,690.end = AT91SAM9261_ID_SSC1,691.flags = IORESOURCE_IRQ,692},693};694695static struct platform_device at91sam9261_ssc1_device = {696.name = "ssc",697.id = 1,698.dev = {699.dma_mask = &ssc1_dmamask,700.coherent_dma_mask = DMA_BIT_MASK(32),701},702.resource = ssc1_resources,703.num_resources = ARRAY_SIZE(ssc1_resources),704};705706static inline void configure_ssc1_pins(unsigned pins)707{708if (pins & ATMEL_SSC_TF)709at91_set_B_periph(AT91_PIN_PA17, 1);710if (pins & ATMEL_SSC_TK)711at91_set_B_periph(AT91_PIN_PA18, 1);712if (pins & ATMEL_SSC_TD)713at91_set_B_periph(AT91_PIN_PA19, 1);714if (pins & ATMEL_SSC_RD)715at91_set_B_periph(AT91_PIN_PA20, 1);716if (pins & ATMEL_SSC_RK)717at91_set_B_periph(AT91_PIN_PA21, 1);718if (pins & ATMEL_SSC_RF)719at91_set_B_periph(AT91_PIN_PA22, 1);720}721722static u64 ssc2_dmamask = DMA_BIT_MASK(32);723724static struct resource ssc2_resources[] = {725[0] = {726.start = AT91SAM9261_BASE_SSC2,727.end = AT91SAM9261_BASE_SSC2 + SZ_16K - 1,728.flags = IORESOURCE_MEM,729},730[1] = {731.start = AT91SAM9261_ID_SSC2,732.end = AT91SAM9261_ID_SSC2,733.flags = IORESOURCE_IRQ,734},735};736737static struct platform_device at91sam9261_ssc2_device = {738.name = "ssc",739.id = 2,740.dev = {741.dma_mask = &ssc2_dmamask,742.coherent_dma_mask = DMA_BIT_MASK(32),743},744.resource = ssc2_resources,745.num_resources = ARRAY_SIZE(ssc2_resources),746};747748static inline void configure_ssc2_pins(unsigned pins)749{750if (pins & ATMEL_SSC_TF)751at91_set_B_periph(AT91_PIN_PC25, 1);752if (pins & ATMEL_SSC_TK)753at91_set_B_periph(AT91_PIN_PC26, 1);754if (pins & ATMEL_SSC_TD)755at91_set_B_periph(AT91_PIN_PC27, 1);756if (pins & ATMEL_SSC_RD)757at91_set_B_periph(AT91_PIN_PC28, 1);758if (pins & ATMEL_SSC_RK)759at91_set_B_periph(AT91_PIN_PC29, 1);760if (pins & ATMEL_SSC_RF)761at91_set_B_periph(AT91_PIN_PC30, 1);762}763764/*765* SSC controllers are accessed through library code, instead of any766* kind of all-singing/all-dancing driver. For example one could be767* used by a particular I2S audio codec's driver, while another one768* on the same system might be used by a custom data capture driver.769*/770void __init at91_add_device_ssc(unsigned id, unsigned pins)771{772struct platform_device *pdev;773774/*775* NOTE: caller is responsible for passing information matching776* "pins" to whatever will be using each particular controller.777*/778switch (id) {779case AT91SAM9261_ID_SSC0:780pdev = &at91sam9261_ssc0_device;781configure_ssc0_pins(pins);782break;783case AT91SAM9261_ID_SSC1:784pdev = &at91sam9261_ssc1_device;785configure_ssc1_pins(pins);786break;787case AT91SAM9261_ID_SSC2:788pdev = &at91sam9261_ssc2_device;789configure_ssc2_pins(pins);790break;791default:792return;793}794795platform_device_register(pdev);796}797798#else799void __init at91_add_device_ssc(unsigned id, unsigned pins) {}800#endif801802803/* --------------------------------------------------------------------804* UART805* -------------------------------------------------------------------- */806807#if defined(CONFIG_SERIAL_ATMEL)808static struct resource dbgu_resources[] = {809[0] = {810.start = AT91_VA_BASE_SYS + AT91_DBGU,811.end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,812.flags = IORESOURCE_MEM,813},814[1] = {815.start = AT91_ID_SYS,816.end = AT91_ID_SYS,817.flags = IORESOURCE_IRQ,818},819};820821static struct atmel_uart_data dbgu_data = {822.use_dma_tx = 0,823.use_dma_rx = 0, /* DBGU not capable of receive DMA */824.regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),825};826827static u64 dbgu_dmamask = DMA_BIT_MASK(32);828829static struct platform_device at91sam9261_dbgu_device = {830.name = "atmel_usart",831.id = 0,832.dev = {833.dma_mask = &dbgu_dmamask,834.coherent_dma_mask = DMA_BIT_MASK(32),835.platform_data = &dbgu_data,836},837.resource = dbgu_resources,838.num_resources = ARRAY_SIZE(dbgu_resources),839};840841static inline void configure_dbgu_pins(void)842{843at91_set_A_periph(AT91_PIN_PA9, 0); /* DRXD */844at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */845}846847static struct resource uart0_resources[] = {848[0] = {849.start = AT91SAM9261_BASE_US0,850.end = AT91SAM9261_BASE_US0 + SZ_16K - 1,851.flags = IORESOURCE_MEM,852},853[1] = {854.start = AT91SAM9261_ID_US0,855.end = AT91SAM9261_ID_US0,856.flags = IORESOURCE_IRQ,857},858};859860static struct atmel_uart_data uart0_data = {861.use_dma_tx = 1,862.use_dma_rx = 1,863};864865static u64 uart0_dmamask = DMA_BIT_MASK(32);866867static struct platform_device at91sam9261_uart0_device = {868.name = "atmel_usart",869.id = 1,870.dev = {871.dma_mask = &uart0_dmamask,872.coherent_dma_mask = DMA_BIT_MASK(32),873.platform_data = &uart0_data,874},875.resource = uart0_resources,876.num_resources = ARRAY_SIZE(uart0_resources),877};878879static inline void configure_usart0_pins(unsigned pins)880{881at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */882at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */883884if (pins & ATMEL_UART_RTS)885at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */886if (pins & ATMEL_UART_CTS)887at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */888}889890static struct resource uart1_resources[] = {891[0] = {892.start = AT91SAM9261_BASE_US1,893.end = AT91SAM9261_BASE_US1 + SZ_16K - 1,894.flags = IORESOURCE_MEM,895},896[1] = {897.start = AT91SAM9261_ID_US1,898.end = AT91SAM9261_ID_US1,899.flags = IORESOURCE_IRQ,900},901};902903static struct atmel_uart_data uart1_data = {904.use_dma_tx = 1,905.use_dma_rx = 1,906};907908static u64 uart1_dmamask = DMA_BIT_MASK(32);909910static struct platform_device at91sam9261_uart1_device = {911.name = "atmel_usart",912.id = 2,913.dev = {914.dma_mask = &uart1_dmamask,915.coherent_dma_mask = DMA_BIT_MASK(32),916.platform_data = &uart1_data,917},918.resource = uart1_resources,919.num_resources = ARRAY_SIZE(uart1_resources),920};921922static inline void configure_usart1_pins(unsigned pins)923{924at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */925at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */926927if (pins & ATMEL_UART_RTS)928at91_set_B_periph(AT91_PIN_PA12, 0); /* RTS1 */929if (pins & ATMEL_UART_CTS)930at91_set_B_periph(AT91_PIN_PA13, 0); /* CTS1 */931}932933static struct resource uart2_resources[] = {934[0] = {935.start = AT91SAM9261_BASE_US2,936.end = AT91SAM9261_BASE_US2 + SZ_16K - 1,937.flags = IORESOURCE_MEM,938},939[1] = {940.start = AT91SAM9261_ID_US2,941.end = AT91SAM9261_ID_US2,942.flags = IORESOURCE_IRQ,943},944};945946static struct atmel_uart_data uart2_data = {947.use_dma_tx = 1,948.use_dma_rx = 1,949};950951static u64 uart2_dmamask = DMA_BIT_MASK(32);952953static struct platform_device at91sam9261_uart2_device = {954.name = "atmel_usart",955.id = 3,956.dev = {957.dma_mask = &uart2_dmamask,958.coherent_dma_mask = DMA_BIT_MASK(32),959.platform_data = &uart2_data,960},961.resource = uart2_resources,962.num_resources = ARRAY_SIZE(uart2_resources),963};964965static inline void configure_usart2_pins(unsigned pins)966{967at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */968at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */969970if (pins & ATMEL_UART_RTS)971at91_set_B_periph(AT91_PIN_PA15, 0); /* RTS2*/972if (pins & ATMEL_UART_CTS)973at91_set_B_periph(AT91_PIN_PA16, 0); /* CTS2 */974}975976static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */977struct platform_device *atmel_default_console_device; /* the serial console device */978979void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)980{981struct platform_device *pdev;982struct atmel_uart_data *pdata;983984switch (id) {985case 0: /* DBGU */986pdev = &at91sam9261_dbgu_device;987configure_dbgu_pins();988break;989case AT91SAM9261_ID_US0:990pdev = &at91sam9261_uart0_device;991configure_usart0_pins(pins);992break;993case AT91SAM9261_ID_US1:994pdev = &at91sam9261_uart1_device;995configure_usart1_pins(pins);996break;997case AT91SAM9261_ID_US2:998pdev = &at91sam9261_uart2_device;999configure_usart2_pins(pins);1000break;1001default:1002return;1003}1004pdata = pdev->dev.platform_data;1005pdata->num = portnr; /* update to mapped ID */10061007if (portnr < ATMEL_MAX_UART)1008at91_uarts[portnr] = pdev;1009}10101011void __init at91_set_serial_console(unsigned portnr)1012{1013if (portnr < ATMEL_MAX_UART) {1014atmel_default_console_device = at91_uarts[portnr];1015at91sam9261_set_console_clock(at91_uarts[portnr]->id);1016}1017}10181019void __init at91_add_device_serial(void)1020{1021int i;10221023for (i = 0; i < ATMEL_MAX_UART; i++) {1024if (at91_uarts[i])1025platform_device_register(at91_uarts[i]);1026}10271028if (!atmel_default_console_device)1029printk(KERN_INFO "AT91: No default serial console defined.\n");1030}1031#else1032void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}1033void __init at91_set_serial_console(unsigned portnr) {}1034void __init at91_add_device_serial(void) {}1035#endif103610371038/* -------------------------------------------------------------------- */10391040/*1041* These devices are always present and don't need any board-specific1042* setup.1043*/1044static int __init at91_add_standard_devices(void)1045{1046at91_add_device_rtt();1047at91_add_device_watchdog();1048at91_add_device_tc();1049return 0;1050}10511052arch_initcall(at91_add_standard_devices);105310541055