📄 at32ap7000.c
字号:
.get_rate = pbb_clk_get_rate, .index = 2, .users = 1,};#define HMATRIX_BASE ((void __iomem *)0xfff00800)#define hmatrix_readl(reg) \ __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)#define hmatrix_writel(reg,value) \ __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)/* * Set bits in the HMATRIX Special Function Register (SFR) used by the * External Bus Interface (EBI). This can be used to enable special * features like CompactFlash support, NAND Flash support, etc. on * certain chipselects. */static inline void set_ebi_sfr_bits(u32 mask){ u32 sfr; clk_enable(&hmatrix_clk); sfr = hmatrix_readl(SFR4); sfr |= mask; hmatrix_writel(SFR4, sfr); clk_disable(&hmatrix_clk);}/* -------------------------------------------------------------------- * System Timer/Counter (TC) * -------------------------------------------------------------------- */static struct resource at32_systc0_resource[] = { PBMEM(0xfff00c00), IRQ(22),};struct platform_device at32_systc0_device = { .name = "systc", .id = 0, .resource = at32_systc0_resource, .num_resources = ARRAY_SIZE(at32_systc0_resource),};DEV_CLK(pclk, at32_systc0, pbb, 3);/* -------------------------------------------------------------------- * PIO * -------------------------------------------------------------------- */static struct resource pio0_resource[] = { PBMEM(0xffe02800), IRQ(13),};DEFINE_DEV(pio, 0);DEV_CLK(mck, pio0, pba, 10);static struct resource pio1_resource[] = { PBMEM(0xffe02c00), IRQ(14),};DEFINE_DEV(pio, 1);DEV_CLK(mck, pio1, pba, 11);static struct resource pio2_resource[] = { PBMEM(0xffe03000), IRQ(15),};DEFINE_DEV(pio, 2);DEV_CLK(mck, pio2, pba, 12);static struct resource pio3_resource[] = { PBMEM(0xffe03400), IRQ(16),};DEFINE_DEV(pio, 3);DEV_CLK(mck, pio3, pba, 13);static struct resource pio4_resource[] = { PBMEM(0xffe03800), IRQ(17),};DEFINE_DEV(pio, 4);DEV_CLK(mck, pio4, pba, 14);void __init at32_add_system_devices(void){ platform_device_register(&at32_pm0_device); platform_device_register(&at32_intc0_device); platform_device_register(&at32ap700x_rtc0_device); platform_device_register(&at32_wdt0_device); platform_device_register(&at32_eic0_device); platform_device_register(&smc0_device); platform_device_register(&pdc_device); platform_device_register(&dmaca0_device); platform_device_register(&at32_systc0_device); platform_device_register(&pio0_device); platform_device_register(&pio1_device); platform_device_register(&pio2_device); platform_device_register(&pio3_device); platform_device_register(&pio4_device);}/* -------------------------------------------------------------------- * USART * -------------------------------------------------------------------- */static struct atmel_uart_data atmel_usart0_data = { .use_dma_tx = 1, .use_dma_rx = 1,};static struct resource atmel_usart0_resource[] = { PBMEM(0xffe00c00), IRQ(6),};DEFINE_DEV_DATA(atmel_usart, 0);DEV_CLK(usart, atmel_usart0, pba, 3);static struct atmel_uart_data atmel_usart1_data = { .use_dma_tx = 1, .use_dma_rx = 1,};static struct resource atmel_usart1_resource[] = { PBMEM(0xffe01000), IRQ(7),};DEFINE_DEV_DATA(atmel_usart, 1);DEV_CLK(usart, atmel_usart1, pba, 4);static struct atmel_uart_data atmel_usart2_data = { .use_dma_tx = 1, .use_dma_rx = 1,};static struct resource atmel_usart2_resource[] = { PBMEM(0xffe01400), IRQ(8),};DEFINE_DEV_DATA(atmel_usart, 2);DEV_CLK(usart, atmel_usart2, pba, 5);static struct atmel_uart_data atmel_usart3_data = { .use_dma_tx = 1, .use_dma_rx = 1,};static struct resource atmel_usart3_resource[] = { PBMEM(0xffe01800), IRQ(9),};DEFINE_DEV_DATA(atmel_usart, 3);DEV_CLK(usart, atmel_usart3, pba, 6);static inline void configure_usart0_pins(void){ select_peripheral(PA(8), PERIPH_B, 0); /* RXD */ select_peripheral(PA(9), PERIPH_B, 0); /* TXD */}static inline void configure_usart1_pins(void){ select_peripheral(PA(17), PERIPH_A, 0); /* RXD */ select_peripheral(PA(18), PERIPH_A, 0); /* TXD */}static inline void configure_usart2_pins(void){ select_peripheral(PB(26), PERIPH_B, 0); /* RXD */ select_peripheral(PB(27), PERIPH_B, 0); /* TXD */}static inline void configure_usart3_pins(void){ select_peripheral(PB(18), PERIPH_B, 0); /* RXD */ select_peripheral(PB(17), PERIPH_B, 0); /* TXD */}static struct platform_device *__initdata at32_usarts[4];void __init at32_map_usart(unsigned int hw_id, unsigned int line){ struct platform_device *pdev; switch (hw_id) { case 0: pdev = &atmel_usart0_device; configure_usart0_pins(); break; case 1: pdev = &atmel_usart1_device; configure_usart1_pins(); break; case 2: pdev = &atmel_usart2_device; configure_usart2_pins(); break; case 3: pdev = &atmel_usart3_device; configure_usart3_pins(); break; default: return; } if (PXSEG(pdev->resource[0].start) == P4SEG) { /* Addresses in the P4 segment are permanently mapped 1:1 */ struct atmel_uart_data *data = pdev->dev.platform_data; data->regs = (void __iomem *)pdev->resource[0].start; } pdev->id = line; at32_usarts[line] = pdev;}struct platform_device *__init at32_add_device_usart(unsigned int id){ platform_device_register(at32_usarts[id]); return at32_usarts[id];}struct platform_device *atmel_default_console_device;void __init at32_setup_serial_console(unsigned int usart_id){ atmel_default_console_device = at32_usarts[usart_id];}/* -------------------------------------------------------------------- * Ethernet * -------------------------------------------------------------------- */static struct eth_platform_data macb0_data;static struct resource macb0_resource[] = { PBMEM(0xfff01800), IRQ(25),};DEFINE_DEV_DATA(macb, 0);DEV_CLK(hclk, macb0, hsb, 8);DEV_CLK(pclk, macb0, pbb, 6);static struct eth_platform_data macb1_data;static struct resource macb1_resource[] = { PBMEM(0xfff01c00), IRQ(26),};DEFINE_DEV_DATA(macb, 1);DEV_CLK(hclk, macb1, hsb, 9);DEV_CLK(pclk, macb1, pbb, 7);struct platform_device *__initat32_add_device_eth(unsigned int id, struct eth_platform_data *data){ struct platform_device *pdev; switch (id) { case 0: pdev = &macb0_device; select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */ select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */ select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */ select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */ select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */ select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */ select_peripheral(PC(13), PERIPH_A, 0); /* RXER */ select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */ select_peripheral(PC(16), PERIPH_A, 0); /* MDC */ select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */ if (!data->is_rmii) { select_peripheral(PC(0), PERIPH_A, 0); /* COL */ select_peripheral(PC(1), PERIPH_A, 0); /* CRS */ select_peripheral(PC(2), PERIPH_A, 0); /* TXER */ select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */ select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */ select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */ select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */ select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */ select_peripheral(PC(18), PERIPH_A, 0); /* SPD */ } break; case 1: pdev = &macb1_device; select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */ select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */ select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */ select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */ select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */ select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */ select_peripheral(PD(5), PERIPH_B, 0); /* RXER */ select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */ select_peripheral(PD(3), PERIPH_B, 0); /* MDC */ select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */ if (!data->is_rmii) { select_peripheral(PC(19), PERIPH_B, 0); /* COL */ select_peripheral(PC(23), PERIPH_B, 0); /* CRS */ select_peripheral(PC(26), PERIPH_B, 0); /* TXER */ select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */ select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */ select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */ select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */ select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */ select_peripheral(PD(15), PERIPH_B, 0); /* SPD */ } break; default: return NULL; } memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data)); platform_device_register(pdev); return pdev;}/* -------------------------------------------------------------------- * SPI * -------------------------------------------------------------------- */static struct resource atmel_spi0_resource[] = { PBMEM(0xffe00000), IRQ(3),};DEFINE_DEV(atmel_spi, 0);DEV_CLK(spi_clk, atmel_spi0, pba, 0);static struct resource atmel_spi1_resource[] = { PBMEM(0xffe00400), IRQ(4),};DEFINE_DEV(atmel_spi, 1);DEV_CLK(spi_clk, atmel_spi1, pba, 1);static void __initat32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n, const u8 *pins){ unsigned int pin, mode; for (; n; n--, b++) { b->bus_num = bus_num; if (b->chip_select >= 4) continue; pin = (unsigned)b->controller_data; if (!pin) { pin = pins[b->chip_select]; b->controller_data = (void *)pin; } mode = AT32_GPIOF_OUTPUT; if (!(b->mode & SPI_CS_HIGH)) mode |= AT32_GPIOF_HIGH; at32_select_gpio(pin, mode); }}struct platform_device *__initat32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n){ /* * Manage the chipselects as GPIOs, normally using the same pins * the SPI controller expects; but boards can use other pins. */ static u8 __initdata spi0_pins[] = { GPIO_PIN_PA(3), GPIO_PIN_PA(4), GPIO_PIN_PA(5), GPIO_PIN_PA(20), }; static u8 __initdata spi1_pins[] = { GPIO_PIN_PB(2), GPIO_PIN_PB(3), GPIO_PIN_PB(4), GPIO_PIN_PA(27), }; struct platform_device *pdev; switch (id) { case 0: pdev = &atmel_spi0_device; select_peripheral(PA(0), PERIPH_A, 0); /* MISO */ select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */ select_peripheral(PA(2), PERIPH_A, 0); /* SCK */ at32_spi_setup_slaves(0, b, n, spi0_pins); break; case 1: pdev = &atmel_spi1_device; select_peripheral(PB(0), PERIPH_B, 0); /* MISO */ select_peripheral(PB(1), PERIPH_B, 0); /* MOSI */ select_peripheral(PB(5), PERIPH_B, 0); /* SCK */ at32_spi_setup_slaves(1, b, n, spi1_pins); break; default: return NULL; } spi_register_board_info(b, n); platform_device_register(pdev); return pdev;}/* -------------------------------------------------------------------- * TWI * -------------------------------------------------------------------- */static struct resource atmel_twi0_resource[] __initdata = { PBMEM(0xffe00800), IRQ(5),};static struct clk atmel_twi0_pclk = { .name = "twi_pclk", .parent = &pba_clk, .mode = pba_clk_mode, .get_rate = pba_clk_get_rate, .index = 2,};struct platform_device *__init at32_add_device_twi(unsigned int id){ struct platform_device *pdev; if (id != 0) return NULL; pdev = platform_device_alloc("atmel_twi", id); if (!pdev) return NULL; if (platform_device_add_resources(pdev, atmel_twi0_resource, ARRAY_SIZE(atmel_twi0_resource))) goto err_add_resources; select_peripheral(PA(6), PERIPH_A, 0); /* SDA */ select_peripheral(PA(7), PERIPH_A, 0); /* SDL */ atmel_twi0_pclk.dev = &pdev->dev; platform_device_add(pdev); return pdev;err_add_resources: platform_device_put(pdev); return NULL;}/* -------------------------------------------------------------------- * MMC * -------------------------------------------------------------------- */static struct resource atmel_mci0_resource[] __initdata = { PBMEM(0xfff02400), IRQ(28),};static struct clk atmel_mci0_pclk = { .name = "mci_clk", .parent = &pbb_clk, .mode = pbb_clk_mode, .get_rate = pbb_clk_get_rate, .index = 9,};struct platform_device *__init at32_add_device_mci(unsigned int id){ struct platform_device *pdev; if (id != 0) return NULL; pdev = platform_device_alloc("atmel_mci", id); if (!pdev) return NULL; if (platform_device_add_resources(pdev, atmel_mci0_resource, ARRAY_SIZE(atmel_mci0_resource))) goto err_add_resources; select_peripheral(PA(10), PERIPH_A, 0); /* CLK */ select_peripheral(PA(11), PERIPH_A, 0); /* CMD */ select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */ select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */ select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */ select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */ atmel_mci0_pclk.dev = &pdev->dev; platform_device_add(pdev); return pdev;err_add_resources: platform_device_put(pdev); return NULL;}/* -------------------------------------------------------------------- * LCDC * -------------------------------------------------------------------- */static struct atmel_lcdfb_info atmel_lcdfb0_data;static struct resource atmel_lcdfb0_resource[] = { { .start = 0xff000000, .end = 0xff000fff, .flags = IORESOURCE_MEM, }, IRQ(1), { /* Placeholder for pre-allocated fb memory */ .start = 0x00000000, .end = 0x00000000, .flags = 0, },};DEFINE_DEV_DATA(atmel_lcdfb, 0);DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);static struct clk atmel_lcdfb0_pixclk = { .name = "lcdc_clk", .dev = &atmel_lcdfb0_device.dev, .mode = genclk_mode, .get_rate = genclk_get_rate, .set_rate = genclk_set_rate, .set_parent = genclk_set_parent, .index = 7,};struct platform_device *__initat32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data, unsigned long fbmem_start, unsigned long fbmem_len){ struct platform_device *pdev; struct atmel_lcdfb_info *info; struct fb_monspecs *monspecs; struct fb_videomode *modedb; unsigned int modedb_size; /* * Do a deep copy of the fb data, monspecs and modedb. Make * sure all allocations are done before setting up the * portmux. */ monspecs = kmemdup(data->default_monspecs, sizeof(struct fb_monspecs), GFP_KERNEL); if (!monspecs) return NULL; modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len; modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL); if (!modedb) goto err_dup_modedb; monspecs->modedb = modedb; switch (id) { case 0: pdev = &atmel_lcdfb0_device; select_peripheral(PC(19), PERIPH_A, 0); /* CC */ select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */ select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */ select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */ select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */ select_peripheral(PC(24), PERIPH_A, 0); /* MODE */ select_peripheral(PC(25), PERIPH_A, 0); /* PWR */ select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */ select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */ select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */ select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */ select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */ select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */ select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */ select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */ select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */ select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */ select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */ select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */ select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */ select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */ select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */ select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */ select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */ select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */ select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */ select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */ select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */ select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */ select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */ select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -