Path: blob/master/arch/arm/mach-at91/at91sam9260.c
10817 views
/*1* arch/arm/mach-at91/at91sam9260.c2*3* Copyright (C) 2006 SAN People4*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*/1112#include <linux/module.h>13#include <linux/pm.h>1415#include <asm/irq.h>16#include <asm/mach/arch.h>17#include <asm/mach/map.h>18#include <mach/cpu.h>19#include <mach/at91sam9260.h>20#include <mach/at91_pmc.h>21#include <mach/at91_rstc.h>22#include <mach/at91_shdwc.h>2324#include "generic.h"25#include "clock.h"2627static struct map_desc at91sam9260_io_desc[] __initdata = {28{29.virtual = AT91_VA_BASE_SYS,30.pfn = __phys_to_pfn(AT91_BASE_SYS),31.length = SZ_16K,32.type = MT_DEVICE,33}34};3536static struct map_desc at91sam9260_sram_desc[] __initdata = {37{38.virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE,39.pfn = __phys_to_pfn(AT91SAM9260_SRAM0_BASE),40.length = AT91SAM9260_SRAM0_SIZE,41.type = MT_DEVICE,42}, {43.virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE - AT91SAM9260_SRAM1_SIZE,44.pfn = __phys_to_pfn(AT91SAM9260_SRAM1_BASE),45.length = AT91SAM9260_SRAM1_SIZE,46.type = MT_DEVICE,47}48};4950static struct map_desc at91sam9g20_sram_desc[] __initdata = {51{52.virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE,53.pfn = __phys_to_pfn(AT91SAM9G20_SRAM0_BASE),54.length = AT91SAM9G20_SRAM0_SIZE,55.type = MT_DEVICE,56}, {57.virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE - AT91SAM9G20_SRAM1_SIZE,58.pfn = __phys_to_pfn(AT91SAM9G20_SRAM1_BASE),59.length = AT91SAM9G20_SRAM1_SIZE,60.type = MT_DEVICE,61}62};6364static struct map_desc at91sam9xe_sram_desc[] __initdata = {65{66.pfn = __phys_to_pfn(AT91SAM9XE_SRAM_BASE),67.type = MT_DEVICE,68}69};7071/* --------------------------------------------------------------------72* Clocks73* -------------------------------------------------------------------- */7475/*76* The peripheral clocks.77*/78static struct clk pioA_clk = {79.name = "pioA_clk",80.pmc_mask = 1 << AT91SAM9260_ID_PIOA,81.type = CLK_TYPE_PERIPHERAL,82};83static struct clk pioB_clk = {84.name = "pioB_clk",85.pmc_mask = 1 << AT91SAM9260_ID_PIOB,86.type = CLK_TYPE_PERIPHERAL,87};88static struct clk pioC_clk = {89.name = "pioC_clk",90.pmc_mask = 1 << AT91SAM9260_ID_PIOC,91.type = CLK_TYPE_PERIPHERAL,92};93static struct clk adc_clk = {94.name = "adc_clk",95.pmc_mask = 1 << AT91SAM9260_ID_ADC,96.type = CLK_TYPE_PERIPHERAL,97};98static struct clk usart0_clk = {99.name = "usart0_clk",100.pmc_mask = 1 << AT91SAM9260_ID_US0,101.type = CLK_TYPE_PERIPHERAL,102};103static struct clk usart1_clk = {104.name = "usart1_clk",105.pmc_mask = 1 << AT91SAM9260_ID_US1,106.type = CLK_TYPE_PERIPHERAL,107};108static struct clk usart2_clk = {109.name = "usart2_clk",110.pmc_mask = 1 << AT91SAM9260_ID_US2,111.type = CLK_TYPE_PERIPHERAL,112};113static struct clk mmc_clk = {114.name = "mci_clk",115.pmc_mask = 1 << AT91SAM9260_ID_MCI,116.type = CLK_TYPE_PERIPHERAL,117};118static struct clk udc_clk = {119.name = "udc_clk",120.pmc_mask = 1 << AT91SAM9260_ID_UDP,121.type = CLK_TYPE_PERIPHERAL,122};123static struct clk twi_clk = {124.name = "twi_clk",125.pmc_mask = 1 << AT91SAM9260_ID_TWI,126.type = CLK_TYPE_PERIPHERAL,127};128static struct clk spi0_clk = {129.name = "spi0_clk",130.pmc_mask = 1 << AT91SAM9260_ID_SPI0,131.type = CLK_TYPE_PERIPHERAL,132};133static struct clk spi1_clk = {134.name = "spi1_clk",135.pmc_mask = 1 << AT91SAM9260_ID_SPI1,136.type = CLK_TYPE_PERIPHERAL,137};138static struct clk ssc_clk = {139.name = "ssc_clk",140.pmc_mask = 1 << AT91SAM9260_ID_SSC,141.type = CLK_TYPE_PERIPHERAL,142};143static struct clk tc0_clk = {144.name = "tc0_clk",145.pmc_mask = 1 << AT91SAM9260_ID_TC0,146.type = CLK_TYPE_PERIPHERAL,147};148static struct clk tc1_clk = {149.name = "tc1_clk",150.pmc_mask = 1 << AT91SAM9260_ID_TC1,151.type = CLK_TYPE_PERIPHERAL,152};153static struct clk tc2_clk = {154.name = "tc2_clk",155.pmc_mask = 1 << AT91SAM9260_ID_TC2,156.type = CLK_TYPE_PERIPHERAL,157};158static struct clk ohci_clk = {159.name = "ohci_clk",160.pmc_mask = 1 << AT91SAM9260_ID_UHP,161.type = CLK_TYPE_PERIPHERAL,162};163static struct clk macb_clk = {164.name = "macb_clk",165.pmc_mask = 1 << AT91SAM9260_ID_EMAC,166.type = CLK_TYPE_PERIPHERAL,167};168static struct clk isi_clk = {169.name = "isi_clk",170.pmc_mask = 1 << AT91SAM9260_ID_ISI,171.type = CLK_TYPE_PERIPHERAL,172};173static struct clk usart3_clk = {174.name = "usart3_clk",175.pmc_mask = 1 << AT91SAM9260_ID_US3,176.type = CLK_TYPE_PERIPHERAL,177};178static struct clk usart4_clk = {179.name = "usart4_clk",180.pmc_mask = 1 << AT91SAM9260_ID_US4,181.type = CLK_TYPE_PERIPHERAL,182};183static struct clk usart5_clk = {184.name = "usart5_clk",185.pmc_mask = 1 << AT91SAM9260_ID_US5,186.type = CLK_TYPE_PERIPHERAL,187};188static struct clk tc3_clk = {189.name = "tc3_clk",190.pmc_mask = 1 << AT91SAM9260_ID_TC3,191.type = CLK_TYPE_PERIPHERAL,192};193static struct clk tc4_clk = {194.name = "tc4_clk",195.pmc_mask = 1 << AT91SAM9260_ID_TC4,196.type = CLK_TYPE_PERIPHERAL,197};198static struct clk tc5_clk = {199.name = "tc5_clk",200.pmc_mask = 1 << AT91SAM9260_ID_TC5,201.type = CLK_TYPE_PERIPHERAL,202};203204static struct clk *periph_clocks[] __initdata = {205&pioA_clk,206&pioB_clk,207&pioC_clk,208&adc_clk,209&usart0_clk,210&usart1_clk,211&usart2_clk,212&mmc_clk,213&udc_clk,214&twi_clk,215&spi0_clk,216&spi1_clk,217&ssc_clk,218&tc0_clk,219&tc1_clk,220&tc2_clk,221&ohci_clk,222&macb_clk,223&isi_clk,224&usart3_clk,225&usart4_clk,226&usart5_clk,227&tc3_clk,228&tc4_clk,229&tc5_clk,230// irq0 .. irq2231};232233static struct clk_lookup periph_clocks_lookups[] = {234CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),235CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),236CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),237CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),238CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),239CLKDEV_CON_DEV_ID("t3_clk", "atmel_tcb.1", &tc3_clk),240CLKDEV_CON_DEV_ID("t4_clk", "atmel_tcb.1", &tc4_clk),241CLKDEV_CON_DEV_ID("t5_clk", "atmel_tcb.1", &tc5_clk),242CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc_clk),243};244245static struct clk_lookup usart_clocks_lookups[] = {246CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),247CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),248CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),249CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),250CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),251CLKDEV_CON_DEV_ID("usart", "atmel_usart.5", &usart4_clk),252CLKDEV_CON_DEV_ID("usart", "atmel_usart.6", &usart5_clk),253};254255/*256* The two programmable clocks.257* You must configure pin multiplexing to bring these signals out.258*/259static struct clk pck0 = {260.name = "pck0",261.pmc_mask = AT91_PMC_PCK0,262.type = CLK_TYPE_PROGRAMMABLE,263.id = 0,264};265static struct clk pck1 = {266.name = "pck1",267.pmc_mask = AT91_PMC_PCK1,268.type = CLK_TYPE_PROGRAMMABLE,269.id = 1,270};271272static void __init at91sam9260_register_clocks(void)273{274int i;275276for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)277clk_register(periph_clocks[i]);278279clkdev_add_table(periph_clocks_lookups,280ARRAY_SIZE(periph_clocks_lookups));281clkdev_add_table(usart_clocks_lookups,282ARRAY_SIZE(usart_clocks_lookups));283284clk_register(&pck0);285clk_register(&pck1);286}287288static struct clk_lookup console_clock_lookup;289290void __init at91sam9260_set_console_clock(int id)291{292if (id >= ARRAY_SIZE(usart_clocks_lookups))293return;294295console_clock_lookup.con_id = "usart";296console_clock_lookup.clk = usart_clocks_lookups[id].clk;297clkdev_add(&console_clock_lookup);298}299300/* --------------------------------------------------------------------301* GPIO302* -------------------------------------------------------------------- */303304static struct at91_gpio_bank at91sam9260_gpio[] = {305{306.id = AT91SAM9260_ID_PIOA,307.offset = AT91_PIOA,308.clock = &pioA_clk,309}, {310.id = AT91SAM9260_ID_PIOB,311.offset = AT91_PIOB,312.clock = &pioB_clk,313}, {314.id = AT91SAM9260_ID_PIOC,315.offset = AT91_PIOC,316.clock = &pioC_clk,317}318};319320static void at91sam9260_poweroff(void)321{322at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);323}324325326/* --------------------------------------------------------------------327* AT91SAM9260 processor initialization328* -------------------------------------------------------------------- */329330static void __init at91sam9xe_map_io(void)331{332unsigned long cidr, sram_size;333334cidr = at91_sys_read(AT91_DBGU_CIDR);335336switch (cidr & AT91_CIDR_SRAMSIZ) {337case AT91_CIDR_SRAMSIZ_32K:338sram_size = 2 * SZ_16K;339break;340case AT91_CIDR_SRAMSIZ_16K:341default:342sram_size = SZ_16K;343}344345at91sam9xe_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;346at91sam9xe_sram_desc->length = sram_size;347348iotable_init(at91sam9xe_sram_desc, ARRAY_SIZE(at91sam9xe_sram_desc));349}350351void __init at91sam9260_map_io(void)352{353/* Map peripherals */354iotable_init(at91sam9260_io_desc, ARRAY_SIZE(at91sam9260_io_desc));355356if (cpu_is_at91sam9xe())357at91sam9xe_map_io();358else if (cpu_is_at91sam9g20())359iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));360else361iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));362}363364void __init at91sam9260_initialize(unsigned long main_clock)365{366at91_arch_reset = at91sam9_alt_reset;367pm_power_off = at91sam9260_poweroff;368at91_extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)369| (1 << AT91SAM9260_ID_IRQ2);370371/* Init clock subsystem */372at91_clock_init(main_clock);373374/* Register the processor-specific clocks */375at91sam9260_register_clocks();376377/* Register GPIO subsystem */378at91_gpio_init(at91sam9260_gpio, 3);379}380381/* --------------------------------------------------------------------382* Interrupt initialization383* -------------------------------------------------------------------- */384385/*386* The default interrupt priority levels (0 = lowest, 7 = highest).387*/388static unsigned int at91sam9260_default_irq_priority[NR_AIC_IRQS] __initdata = {3897, /* Advanced Interrupt Controller */3907, /* System Peripherals */3911, /* Parallel IO Controller A */3921, /* Parallel IO Controller B */3931, /* Parallel IO Controller C */3940, /* Analog-to-Digital Converter */3955, /* USART 0 */3965, /* USART 1 */3975, /* USART 2 */3980, /* Multimedia Card Interface */3992, /* USB Device Port */4006, /* Two-Wire Interface */4015, /* Serial Peripheral Interface 0 */4025, /* Serial Peripheral Interface 1 */4035, /* Serial Synchronous Controller */4040,4050,4060, /* Timer Counter 0 */4070, /* Timer Counter 1 */4080, /* Timer Counter 2 */4092, /* USB Host port */4103, /* Ethernet */4110, /* Image Sensor Interface */4125, /* USART 3 */4135, /* USART 4 */4145, /* USART 5 */4150, /* Timer Counter 3 */4160, /* Timer Counter 4 */4170, /* Timer Counter 5 */4180, /* Advanced Interrupt Controller */4190, /* Advanced Interrupt Controller */4200, /* Advanced Interrupt Controller */421};422423void __init at91sam9260_init_interrupts(unsigned int priority[NR_AIC_IRQS])424{425if (!priority)426priority = at91sam9260_default_irq_priority;427428/* Initialize the AIC interrupt controller */429at91_aic_init(priority);430431/* Enable GPIO interrupts */432at91_gpio_irq_setup();433}434435436