Path: blob/master/arch/arm/mach-at91/board-sam9261ek.c
10817 views
/*1* linux/arch/arm/mach-at91/board-sam9261ek.c2*3* Copyright (C) 2005 SAN People4* Copyright (C) 2006 Atmel5*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* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*/2021#include <linux/types.h>22#include <linux/init.h>23#include <linux/mm.h>24#include <linux/module.h>25#include <linux/platform_device.h>26#include <linux/spi/spi.h>27#include <linux/spi/ads7846.h>28#include <linux/spi/at73c213.h>29#include <linux/clk.h>30#include <linux/dm9000.h>31#include <linux/fb.h>32#include <linux/gpio_keys.h>33#include <linux/input.h>3435#include <video/atmel_lcdc.h>3637#include <asm/setup.h>38#include <asm/mach-types.h>39#include <asm/irq.h>4041#include <asm/mach/arch.h>42#include <asm/mach/map.h>43#include <asm/mach/irq.h>4445#include <mach/hardware.h>46#include <mach/board.h>47#include <mach/gpio.h>48#include <mach/at91sam9_smc.h>49#include <mach/at91_shdwc.h>50#include <mach/system_rev.h>5152#include "sam9_smc.h"53#include "generic.h"545556static void __init ek_init_early(void)57{58/* Initialize processor: 18.432 MHz crystal */59at91sam9261_initialize(18432000);6061/* Setup the LEDs */62at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14);6364/* DBGU on ttyS0. (Rx & Tx only) */65at91_register_uart(0, 0, 0);6667/* set serial console to ttyS0 (ie, DBGU) */68at91_set_serial_console(0);69}7071static void __init ek_init_irq(void)72{73at91sam9261_init_interrupts(NULL);74}757677/*78* DM9000 ethernet device79*/80#if defined(CONFIG_DM9000)81static struct resource dm9000_resource[] = {82[0] = {83.start = AT91_CHIPSELECT_2,84.end = AT91_CHIPSELECT_2 + 3,85.flags = IORESOURCE_MEM86},87[1] = {88.start = AT91_CHIPSELECT_2 + 0x44,89.end = AT91_CHIPSELECT_2 + 0xFF,90.flags = IORESOURCE_MEM91},92[2] = {93.start = AT91_PIN_PC11,94.end = AT91_PIN_PC11,95.flags = IORESOURCE_IRQ96| IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE,97}98};99100static struct dm9000_plat_data dm9000_platdata = {101.flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,102};103104static struct platform_device dm9000_device = {105.name = "dm9000",106.id = 0,107.num_resources = ARRAY_SIZE(dm9000_resource),108.resource = dm9000_resource,109.dev = {110.platform_data = &dm9000_platdata,111}112};113114/*115* SMC timings for the DM9000.116* Note: These timings were calculated for MASTER_CLOCK = 100000000 according to the DM9000 timings.117*/118static struct sam9_smc_config __initdata dm9000_smc_config = {119.ncs_read_setup = 0,120.nrd_setup = 2,121.ncs_write_setup = 0,122.nwe_setup = 2,123124.ncs_read_pulse = 8,125.nrd_pulse = 4,126.ncs_write_pulse = 8,127.nwe_pulse = 4,128129.read_cycle = 16,130.write_cycle = 16,131132.mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16,133.tdf_cycles = 1,134};135136static void __init ek_add_device_dm9000(void)137{138/* Configure chip-select 2 (DM9000) */139sam9_smc_configure(2, &dm9000_smc_config);140141/* Configure Reset signal as output */142at91_set_gpio_output(AT91_PIN_PC10, 0);143144/* Configure Interrupt pin as input, no pull-up */145at91_set_gpio_input(AT91_PIN_PC11, 0);146147platform_device_register(&dm9000_device);148}149#else150static void __init ek_add_device_dm9000(void) {}151#endif /* CONFIG_DM9000 */152153154/*155* USB Host Port156*/157static struct at91_usbh_data __initdata ek_usbh_data = {158.ports = 2,159};160161162/*163* USB Device Port164*/165static struct at91_udc_data __initdata ek_udc_data = {166.vbus_pin = AT91_PIN_PB29,167.pullup_pin = 0, /* pull-up driven by UDC */168};169170171/*172* NAND flash173*/174static struct mtd_partition __initdata ek_nand_partition[] = {175{176.name = "Partition 1",177.offset = 0,178.size = SZ_256K,179},180{181.name = "Partition 2",182.offset = MTDPART_OFS_NXTBLK,183.size = MTDPART_SIZ_FULL,184},185};186187static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)188{189*num_partitions = ARRAY_SIZE(ek_nand_partition);190return ek_nand_partition;191}192193static struct atmel_nand_data __initdata ek_nand_data = {194.ale = 22,195.cle = 21,196// .det_pin = ... not connected197.rdy_pin = AT91_PIN_PC15,198.enable_pin = AT91_PIN_PC14,199.partition_info = nand_partitions,200};201202static struct sam9_smc_config __initdata ek_nand_smc_config = {203.ncs_read_setup = 0,204.nrd_setup = 1,205.ncs_write_setup = 0,206.nwe_setup = 1,207208.ncs_read_pulse = 3,209.nrd_pulse = 3,210.ncs_write_pulse = 3,211.nwe_pulse = 3,212213.read_cycle = 5,214.write_cycle = 5,215216.mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,217.tdf_cycles = 2,218};219220static void __init ek_add_device_nand(void)221{222ek_nand_data.bus_width_16 = board_have_nand_16bit();223/* setup bus-width (8 or 16) */224if (ek_nand_data.bus_width_16)225ek_nand_smc_config.mode |= AT91_SMC_DBW_16;226else227ek_nand_smc_config.mode |= AT91_SMC_DBW_8;228229/* configure chip-select 3 (NAND) */230sam9_smc_configure(3, &ek_nand_smc_config);231232at91_add_device_nand(&ek_nand_data);233}234235/*236* SPI related devices237*/238#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)239240/*241* ADS7846 Touchscreen242*/243#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)244245static int ads7843_pendown_state(void)246{247return !at91_get_gpio_value(AT91_PIN_PC2); /* Touchscreen PENIRQ */248}249250static struct ads7846_platform_data ads_info = {251.model = 7843,252.x_min = 150,253.x_max = 3830,254.y_min = 190,255.y_max = 3830,256.vref_delay_usecs = 100,257.x_plate_ohms = 450,258.y_plate_ohms = 250,259.pressure_max = 15000,260.debounce_max = 1,261.debounce_rep = 0,262.debounce_tol = (~0),263.get_pendown_state = ads7843_pendown_state,264};265266static void __init ek_add_device_ts(void)267{268at91_set_B_periph(AT91_PIN_PC2, 1); /* External IRQ0, with pullup */269at91_set_gpio_input(AT91_PIN_PA11, 1); /* Touchscreen BUSY signal */270}271#else272static void __init ek_add_device_ts(void) {}273#endif274275/*276* Audio277*/278static struct at73c213_board_info at73c213_data = {279.ssc_id = 1,280#if defined(CONFIG_MACH_AT91SAM9261EK)281.shortname = "AT91SAM9261-EK external DAC",282#else283.shortname = "AT91SAM9G10-EK external DAC",284#endif285};286287#if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)288static void __init at73c213_set_clk(struct at73c213_board_info *info)289{290struct clk *pck2;291struct clk *plla;292293pck2 = clk_get(NULL, "pck2");294plla = clk_get(NULL, "plla");295296/* AT73C213 MCK Clock */297at91_set_B_periph(AT91_PIN_PB31, 0); /* PCK2 */298299clk_set_parent(pck2, plla);300clk_put(plla);301302info->dac_clk = pck2;303}304#else305static void __init at73c213_set_clk(struct at73c213_board_info *info) {}306#endif307308/*309* SPI devices310*/311static struct spi_board_info ek_spi_devices[] = {312{ /* DataFlash chip */313.modalias = "mtd_dataflash",314.chip_select = 0,315.max_speed_hz = 15 * 1000 * 1000,316.bus_num = 0,317},318#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)319{320.modalias = "ads7846",321.chip_select = 2,322.max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */323.bus_num = 0,324.platform_data = &ads_info,325.irq = AT91SAM9261_ID_IRQ0,326.controller_data = (void *) AT91_PIN_PA28, /* CS pin */327},328#endif329#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)330{ /* DataFlash card - jumper (J12) configurable to CS3 or CS0 */331.modalias = "mtd_dataflash",332.chip_select = 3,333.max_speed_hz = 15 * 1000 * 1000,334.bus_num = 0,335},336#elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)337{ /* AT73C213 DAC */338.modalias = "at73c213",339.chip_select = 3,340.max_speed_hz = 10 * 1000 * 1000,341.bus_num = 0,342.mode = SPI_MODE_1,343.platform_data = &at73c213_data,344.controller_data = (void*) AT91_PIN_PA29, /* default for CS3 is PA6, but it must be PA29 */345},346#endif347};348349#else /* CONFIG_SPI_ATMEL_* */350/* spi0 and mmc/sd share the same PIO pins: cannot be used at the same time */351352/*353* MCI (SD/MMC)354* det_pin, wp_pin and vcc_pin are not connected355*/356static struct at91_mmc_data __initdata ek_mmc_data = {357.wire4 = 1,358};359360#endif /* CONFIG_SPI_ATMEL_* */361362363/*364* LCD Controller365*/366#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)367368#if defined(CONFIG_FB_ATMEL_STN)369370/* STN */371static struct fb_videomode at91_stn_modes[] = {372{373.name = "SP06Q002 @ 75",374.refresh = 75,375.xres = 320, .yres = 240,376.pixclock = KHZ2PICOS(1440),377378.left_margin = 1, .right_margin = 1,379.upper_margin = 0, .lower_margin = 0,380.hsync_len = 1, .vsync_len = 1,381382.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,383.vmode = FB_VMODE_NONINTERLACED,384},385};386387static struct fb_monspecs at91fb_default_stn_monspecs = {388.manufacturer = "HIT",389.monitor = "SP06Q002",390391.modedb = at91_stn_modes,392.modedb_len = ARRAY_SIZE(at91_stn_modes),393.hfmin = 15000,394.hfmax = 64000,395.vfmin = 50,396.vfmax = 150,397};398399#define AT91SAM9261_DEFAULT_STN_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \400| ATMEL_LCDC_DISTYPE_STNMONO \401| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \402| ATMEL_LCDC_IFWIDTH_4 \403| ATMEL_LCDC_SCANMOD_SINGLE)404405static void at91_lcdc_stn_power_control(int on)406{407/* backlight */408if (on) { /* power up */409at91_set_gpio_value(AT91_PIN_PC14, 0);410at91_set_gpio_value(AT91_PIN_PC15, 0);411} else { /* power down */412at91_set_gpio_value(AT91_PIN_PC14, 1);413at91_set_gpio_value(AT91_PIN_PC15, 1);414}415}416417static struct atmel_lcdfb_info __initdata ek_lcdc_data = {418.default_bpp = 1,419.default_dmacon = ATMEL_LCDC_DMAEN,420.default_lcdcon2 = AT91SAM9261_DEFAULT_STN_LCDCON2,421.default_monspecs = &at91fb_default_stn_monspecs,422.atmel_lcdfb_power_control = at91_lcdc_stn_power_control,423.guard_time = 1,424#if defined(CONFIG_MACH_AT91SAM9G10EK)425.lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,426#endif427};428429#else430431/* TFT */432static struct fb_videomode at91_tft_vga_modes[] = {433{434.name = "TX09D50VM1CCA @ 60",435.refresh = 60,436.xres = 240, .yres = 320,437.pixclock = KHZ2PICOS(4965),438439.left_margin = 1, .right_margin = 33,440.upper_margin = 1, .lower_margin = 0,441.hsync_len = 5, .vsync_len = 1,442443.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,444.vmode = FB_VMODE_NONINTERLACED,445},446};447448static struct fb_monspecs at91fb_default_tft_monspecs = {449.manufacturer = "HIT",450.monitor = "TX09D50VM1CCA",451452.modedb = at91_tft_vga_modes,453.modedb_len = ARRAY_SIZE(at91_tft_vga_modes),454.hfmin = 15000,455.hfmax = 64000,456.vfmin = 50,457.vfmax = 150,458};459460#define AT91SAM9261_DEFAULT_TFT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \461| ATMEL_LCDC_DISTYPE_TFT \462| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)463464static void at91_lcdc_tft_power_control(int on)465{466if (on)467at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */468else469at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */470}471472static struct atmel_lcdfb_info __initdata ek_lcdc_data = {473.lcdcon_is_backlight = true,474.default_bpp = 16,475.default_dmacon = ATMEL_LCDC_DMAEN,476.default_lcdcon2 = AT91SAM9261_DEFAULT_TFT_LCDCON2,477.default_monspecs = &at91fb_default_tft_monspecs,478.atmel_lcdfb_power_control = at91_lcdc_tft_power_control,479.guard_time = 1,480#if defined(CONFIG_MACH_AT91SAM9G10EK)481.lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,482#endif483};484#endif485486#else487static struct atmel_lcdfb_info __initdata ek_lcdc_data;488#endif489490491/*492* GPIO Buttons493*/494#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)495static struct gpio_keys_button ek_buttons[] = {496{497.gpio = AT91_PIN_PA27,498.code = BTN_0,499.desc = "Button 0",500.active_low = 1,501.wakeup = 1,502},503{504.gpio = AT91_PIN_PA26,505.code = BTN_1,506.desc = "Button 1",507.active_low = 1,508.wakeup = 1,509},510{511.gpio = AT91_PIN_PA25,512.code = BTN_2,513.desc = "Button 2",514.active_low = 1,515.wakeup = 1,516},517{518.gpio = AT91_PIN_PA24,519.code = BTN_3,520.desc = "Button 3",521.active_low = 1,522.wakeup = 1,523}524};525526static struct gpio_keys_platform_data ek_button_data = {527.buttons = ek_buttons,528.nbuttons = ARRAY_SIZE(ek_buttons),529};530531static struct platform_device ek_button_device = {532.name = "gpio-keys",533.id = -1,534.num_resources = 0,535.dev = {536.platform_data = &ek_button_data,537}538};539540static void __init ek_add_device_buttons(void)541{542at91_set_gpio_input(AT91_PIN_PA27, 1); /* btn0 */543at91_set_deglitch(AT91_PIN_PA27, 1);544at91_set_gpio_input(AT91_PIN_PA26, 1); /* btn1 */545at91_set_deglitch(AT91_PIN_PA26, 1);546at91_set_gpio_input(AT91_PIN_PA25, 1); /* btn2 */547at91_set_deglitch(AT91_PIN_PA25, 1);548at91_set_gpio_input(AT91_PIN_PA24, 1); /* btn3 */549at91_set_deglitch(AT91_PIN_PA24, 1);550551platform_device_register(&ek_button_device);552}553#else554static void __init ek_add_device_buttons(void) {}555#endif556557/*558* LEDs559*/560static struct gpio_led ek_leds[] = {561{ /* "bottom" led, green, userled1 to be defined */562.name = "ds7",563.gpio = AT91_PIN_PA14,564.active_low = 1,565.default_trigger = "none",566},567{ /* "top" led, green, userled2 to be defined */568.name = "ds8",569.gpio = AT91_PIN_PA13,570.active_low = 1,571.default_trigger = "none",572},573{ /* "power" led, yellow */574.name = "ds1",575.gpio = AT91_PIN_PA23,576.default_trigger = "heartbeat",577}578};579580static void __init ek_board_init(void)581{582/* Serial */583at91_add_device_serial();584/* USB Host */585at91_add_device_usbh(&ek_usbh_data);586/* USB Device */587at91_add_device_udc(&ek_udc_data);588/* I2C */589at91_add_device_i2c(NULL, 0);590/* NAND */591ek_add_device_nand();592/* DM9000 ethernet */593ek_add_device_dm9000();594595/* spi0 and mmc/sd share the same PIO pins */596#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)597/* SPI */598at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));599/* Touchscreen */600ek_add_device_ts();601/* SSC (to AT73C213) */602at73c213_set_clk(&at73c213_data);603at91_add_device_ssc(AT91SAM9261_ID_SSC1, ATMEL_SSC_TX);604#else605/* MMC */606at91_add_device_mmc(0, &ek_mmc_data);607#endif608/* LCD Controller */609at91_add_device_lcdc(&ek_lcdc_data);610/* Push Buttons */611ek_add_device_buttons();612/* LEDs */613at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));614}615616#if defined(CONFIG_MACH_AT91SAM9261EK)617MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")618#else619MACHINE_START(AT91SAM9G10EK, "Atmel AT91SAM9G10-EK")620#endif621/* Maintainer: Atmel */622.timer = &at91sam926x_timer,623.map_io = at91sam9261_map_io,624.init_early = ek_init_early,625.init_irq = ek_init_irq,626.init_machine = ek_board_init,627MACHINE_END628629630