Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ATSTK1003 daughterboard-specific init code |
| 3 | * |
| 4 | * Copyright (C) 2007 Atmel Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/types.h> |
| 17 | |
| 18 | #include <linux/spi/at73c213.h> |
| 19 | #include <linux/spi/spi.h> |
Nicolas Ferre | c42aa77 | 2008-11-20 15:59:12 +0100 | [diff] [blame] | 20 | #include <linux/atmel-mci.h> |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 21 | |
| 22 | #include <video/atmel_lcdc.h> |
| 23 | |
| 24 | #include <asm/setup.h> |
| 25 | |
Haavard Skinnemoen | 3663b73 | 2008-08-05 13:57:38 +0200 | [diff] [blame] | 26 | #include <mach/at32ap700x.h> |
| 27 | #include <mach/board.h> |
| 28 | #include <mach/init.h> |
| 29 | #include <mach/portmux.h> |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 30 | |
| 31 | #include "atstk1000.h" |
| 32 | |
Alex | 60ed795 | 2008-03-17 14:55:06 +0100 | [diff] [blame] | 33 | /* Oscillator frequencies. These are board specific */ |
| 34 | unsigned long at32_board_osc_rates[3] = { |
| 35 | [0] = 32768, /* 32.768 kHz on RTC osc */ |
| 36 | [1] = 20000000, /* 20 MHz on osc0 */ |
| 37 | [2] = 12000000, /* 12 MHz on osc1 */ |
| 38 | }; |
| 39 | |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 40 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC |
| 41 | static struct at73c213_board_info at73c213_data = { |
| 42 | .ssc_id = 0, |
| 43 | .shortname = "AVR32 STK1000 external DAC", |
| 44 | }; |
| 45 | #endif |
| 46 | |
| 47 | #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM |
| 48 | static struct spi_board_info spi0_board_info[] __initdata = { |
| 49 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC |
| 50 | { |
| 51 | /* AT73C213 */ |
| 52 | .modalias = "at73c213", |
| 53 | .max_speed_hz = 200000, |
| 54 | .chip_select = 0, |
| 55 | .mode = SPI_MODE_1, |
| 56 | .platform_data = &at73c213_data, |
| 57 | }, |
| 58 | #endif |
| 59 | { |
| 60 | /* QVGA display */ |
| 61 | .modalias = "ltv350qv", |
| 62 | .max_speed_hz = 16000000, |
| 63 | .chip_select = 1, |
| 64 | .mode = SPI_MODE_3, |
| 65 | }, |
| 66 | }; |
| 67 | #endif |
| 68 | |
| 69 | #ifdef CONFIG_BOARD_ATSTK100X_SPI1 |
| 70 | static struct spi_board_info spi1_board_info[] __initdata = { { |
| 71 | /* patch in custom entries here */ |
| 72 | } }; |
| 73 | #endif |
| 74 | |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 75 | #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM |
| 76 | static struct mci_platform_data __initdata mci0_data = { |
| 77 | .slot[0] = { |
| 78 | .bus_width = 4, |
| 79 | .detect_pin = -ENODEV, |
| 80 | .wp_pin = -ENODEV, |
| 81 | }, |
| 82 | }; |
| 83 | #endif |
| 84 | |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 85 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC |
| 86 | static void __init atstk1004_setup_extdac(void) |
| 87 | { |
| 88 | struct clk *gclk; |
| 89 | struct clk *pll; |
| 90 | |
| 91 | gclk = clk_get(NULL, "gclk0"); |
| 92 | if (IS_ERR(gclk)) |
| 93 | goto err_gclk; |
| 94 | pll = clk_get(NULL, "pll0"); |
| 95 | if (IS_ERR(pll)) |
| 96 | goto err_pll; |
| 97 | |
| 98 | if (clk_set_parent(gclk, pll)) { |
| 99 | pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n"); |
| 100 | goto err_set_clk; |
| 101 | } |
| 102 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 103 | at32_select_periph(GPIO_PIOA_BASE, (1 << 30), GPIO_PERIPH_A, 0); |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 104 | at73c213_data.dac_clk = gclk; |
| 105 | |
| 106 | err_set_clk: |
| 107 | clk_put(pll); |
| 108 | err_pll: |
| 109 | clk_put(gclk); |
| 110 | err_gclk: |
| 111 | return; |
| 112 | } |
| 113 | #else |
| 114 | static void __init atstk1004_setup_extdac(void) |
| 115 | { |
| 116 | |
| 117 | } |
| 118 | #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */ |
| 119 | |
| 120 | void __init setup_board(void) |
| 121 | { |
| 122 | #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM |
Peter Ma | bf4861c | 2009-03-31 10:31:02 -0700 | [diff] [blame] | 123 | at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */ |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 124 | #else |
Peter Ma | bf4861c | 2009-03-31 10:31:02 -0700 | [diff] [blame] | 125 | at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */ |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 126 | #endif |
| 127 | /* USART 2/unused: expansion connector */ |
Peter Ma | bf4861c | 2009-03-31 10:31:02 -0700 | [diff] [blame] | 128 | at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */ |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 129 | |
| 130 | at32_setup_serial_console(0); |
| 131 | } |
| 132 | |
| 133 | static int __init atstk1004_init(void) |
| 134 | { |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 135 | #ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM |
| 136 | at32_add_device_usart(1); |
| 137 | #else |
| 138 | at32_add_device_usart(0); |
| 139 | #endif |
| 140 | at32_add_device_usart(2); |
| 141 | |
| 142 | #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM |
| 143 | at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info)); |
| 144 | #endif |
| 145 | #ifdef CONFIG_BOARD_ATSTK100X_SPI1 |
| 146 | at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info)); |
| 147 | #endif |
Haavard Skinnemoen | f059267 | 2008-02-13 14:29:30 +0100 | [diff] [blame] | 148 | #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 149 | at32_add_device_mci(0, &mci0_data); |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 150 | #endif |
| 151 | at32_add_device_lcdc(0, &atstk1000_lcdc_data, |
Julien May | 7066412 | 2008-08-04 14:27:38 +0200 | [diff] [blame] | 152 | fbmem_start, fbmem_size, |
| 153 | ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL); |
Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 154 | at32_add_device_usba(0, NULL); |
| 155 | #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM |
| 156 | at32_add_device_ssc(0, ATMEL_SSC_TX); |
| 157 | #endif |
| 158 | |
| 159 | atstk1000_setup_j2_leds(); |
| 160 | atstk1004_setup_extdac(); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | postcore_initcall(atstk1004_init); |