| 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 <asm/setup.h> | 
 | 23 |  | 
| Haavard Skinnemoen | 3663b73 | 2008-08-05 13:57:38 +0200 | [diff] [blame] | 24 | #include <mach/at32ap700x.h> | 
 | 25 | #include <mach/board.h> | 
 | 26 | #include <mach/init.h> | 
 | 27 | #include <mach/portmux.h> | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 28 |  | 
 | 29 | #include "atstk1000.h" | 
 | 30 |  | 
| Alex | 60ed795 | 2008-03-17 14:55:06 +0100 | [diff] [blame] | 31 | /* Oscillator frequencies. These are board specific */ | 
 | 32 | unsigned long at32_board_osc_rates[3] = { | 
 | 33 | 	[0] = 32768,	/* 32.768 kHz on RTC osc */ | 
 | 34 | 	[1] = 20000000,	/* 20 MHz on osc0 */ | 
 | 35 | 	[2] = 12000000,	/* 12 MHz on osc1 */ | 
 | 36 | }; | 
 | 37 |  | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 38 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC | 
 | 39 | static struct at73c213_board_info at73c213_data = { | 
 | 40 | 	.ssc_id		= 0, | 
 | 41 | 	.shortname	= "AVR32 STK1000 external DAC", | 
 | 42 | }; | 
 | 43 | #endif | 
 | 44 |  | 
 | 45 | #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM | 
 | 46 | static struct spi_board_info spi0_board_info[] __initdata = { | 
 | 47 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC | 
 | 48 | 	{ | 
 | 49 | 		/* AT73C213 */ | 
 | 50 | 		.modalias	= "at73c213", | 
 | 51 | 		.max_speed_hz	= 200000, | 
 | 52 | 		.chip_select	= 0, | 
 | 53 | 		.mode		= SPI_MODE_1, | 
 | 54 | 		.platform_data	= &at73c213_data, | 
 | 55 | 	}, | 
 | 56 | #endif | 
 | 57 | 	/* | 
 | 58 | 	 * We can control the LTV350QV LCD panel, but it isn't much | 
 | 59 | 	 * point since we don't have an LCD controller... | 
 | 60 | 	 */ | 
 | 61 | }; | 
 | 62 | #endif | 
 | 63 |  | 
 | 64 | #ifdef CONFIG_BOARD_ATSTK100X_SPI1 | 
 | 65 | static struct spi_board_info spi1_board_info[] __initdata = { { | 
 | 66 | 	/* patch in custom entries here */ | 
 | 67 | } }; | 
 | 68 | #endif | 
 | 69 |  | 
| Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 70 | #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM | 
 | 71 | static struct mci_platform_data __initdata mci0_data = { | 
 | 72 | 	.slot[0] = { | 
 | 73 | 		.bus_width	= 4, | 
 | 74 | 		.detect_pin	= -ENODEV, | 
 | 75 | 		.wp_pin		= -ENODEV, | 
 | 76 | 	}, | 
 | 77 | }; | 
 | 78 | #endif | 
 | 79 |  | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC | 
 | 81 | static void __init atstk1003_setup_extdac(void) | 
 | 82 | { | 
 | 83 | 	struct clk *gclk; | 
 | 84 | 	struct clk *pll; | 
 | 85 |  | 
 | 86 | 	gclk = clk_get(NULL, "gclk0"); | 
 | 87 | 	if (IS_ERR(gclk)) | 
 | 88 | 		goto err_gclk; | 
 | 89 | 	pll = clk_get(NULL, "pll0"); | 
 | 90 | 	if (IS_ERR(pll)) | 
 | 91 | 		goto err_pll; | 
 | 92 |  | 
 | 93 | 	if (clk_set_parent(gclk, pll)) { | 
 | 94 | 		pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n"); | 
 | 95 | 		goto err_set_clk; | 
 | 96 | 	} | 
 | 97 |  | 
| Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 98 | 	at32_select_periph(GPIO_PIOA_BASE, (1 << 30), GPIO_PERIPH_A, 0); | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 99 | 	at73c213_data.dac_clk = gclk; | 
 | 100 |  | 
 | 101 | err_set_clk: | 
 | 102 | 	clk_put(pll); | 
 | 103 | err_pll: | 
 | 104 | 	clk_put(gclk); | 
 | 105 | err_gclk: | 
 | 106 | 	return; | 
 | 107 | } | 
 | 108 | #else | 
 | 109 | static void __init atstk1003_setup_extdac(void) | 
 | 110 | { | 
 | 111 |  | 
 | 112 | } | 
 | 113 | #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */ | 
 | 114 |  | 
 | 115 | void __init setup_board(void) | 
 | 116 | { | 
 | 117 | #ifdef	CONFIG_BOARD_ATSTK100X_SW2_CUSTOM | 
 | 118 | 	at32_map_usart(0, 1);	/* USART 0/B: /dev/ttyS1, IRDA */ | 
 | 119 | #else | 
 | 120 | 	at32_map_usart(1, 0);	/* USART 1/A: /dev/ttyS0, DB9 */ | 
 | 121 | #endif | 
 | 122 | 	/* USART 2/unused: expansion connector */ | 
 | 123 | 	at32_map_usart(3, 2);	/* USART 3/C: /dev/ttyS2, DB9 */ | 
 | 124 |  | 
 | 125 | 	at32_setup_serial_console(0); | 
 | 126 | } | 
 | 127 |  | 
 | 128 | static int __init atstk1003_init(void) | 
 | 129 | { | 
 | 130 | 	/* | 
 | 131 | 	 * ATSTK1000 uses 32-bit SDRAM interface. Reserve the | 
 | 132 | 	 * SDRAM-specific pins so that nobody messes with them. | 
 | 133 | 	 */ | 
| Alex Raimondi | adde42b | 2008-11-04 23:37:10 +0100 | [diff] [blame] | 134 | 	at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL); | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 135 |  | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 136 | #ifdef	CONFIG_BOARD_ATSTK100X_SW2_CUSTOM | 
 | 137 | 	at32_add_device_usart(1); | 
 | 138 | #else | 
 | 139 | 	at32_add_device_usart(0); | 
 | 140 | #endif | 
 | 141 | 	at32_add_device_usart(2); | 
 | 142 |  | 
 | 143 | #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM | 
 | 144 | 	at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info)); | 
 | 145 | #endif | 
 | 146 | #ifdef CONFIG_BOARD_ATSTK100X_SPI1 | 
 | 147 | 	at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info)); | 
 | 148 | #endif | 
 | 149 | #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM | 
| Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 150 | 	at32_add_device_mci(0, &mci0_data); | 
| Haavard Skinnemoen | 78693e4 | 2007-10-29 17:03:26 +0100 | [diff] [blame] | 151 | #endif | 
 | 152 | 	at32_add_device_usba(0, NULL); | 
 | 153 | #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM | 
 | 154 | 	at32_add_device_ssc(0, ATMEL_SSC_TX); | 
 | 155 | #endif | 
 | 156 |  | 
 | 157 | 	atstk1000_setup_j2_leds(); | 
 | 158 | 	atstk1003_setup_extdac(); | 
 | 159 |  | 
 | 160 | 	return 0; | 
 | 161 | } | 
 | 162 | postcore_initcall(atstk1003_init); |