aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Ma <pma@mediamatech.com>2009-08-27 03:31:47 -0400
committerHaavard Skinnemoen <haavard.skinnemoen@atmel.com>2009-08-27 04:20:58 -0400
commit0708420370db7350b75cbf64b1eb80ad1b2a89df (patch)
tree7dcfc21d595bba183468199fb9565a8afbc3c13d
parent3fe6ad6c39834350d74145de855fbffdde02ace4 (diff)
avr32: function for independently setting up SPI slaves
at32ap_spi_setup_slaves() is exposed to allow the addition of SPI slaves to a SPI bus that has already been registered. This is especially useful for add-on cards, which have their own board setup function. at32ap_spi_add_device() has been slightly re-organized, but should be transparent to existing users. So to add a SPI slave, after a SPI bus has already been registered: /* Configure the list of slaves on SPI controller "id" */ at32_spi_setup_slaves(id,spi_board_info,ARRAY_SIZE(spi_board_info)); /* Register the list of slaves */ spi_register_board_info(spi_board_info,ARRAY_SIZE(spi_board_info)); Signed-off-by: Peter Ma <pma@mediamatech.com> [haavard.skinnemoen@atmel.com: trivial whitespace fix] Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
-rw-r--r--arch/avr32/mach-at32ap/at32ap700x.c35
-rw-r--r--arch/avr32/mach-at32ap/include/mach/board.h1
2 files changed, 20 insertions, 16 deletions
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c
index eb9d4dc2e86..a47592e2fc3 100644
--- a/arch/avr32/mach-at32ap/at32ap700x.c
+++ b/arch/avr32/mach-at32ap/at32ap700x.c
@@ -1181,19 +1181,32 @@ static struct resource atmel_spi1_resource[] = {
1181DEFINE_DEV(atmel_spi, 1); 1181DEFINE_DEV(atmel_spi, 1);
1182DEV_CLK(spi_clk, atmel_spi1, pba, 1); 1182DEV_CLK(spi_clk, atmel_spi1, pba, 1);
1183 1183
1184static void __init 1184void __init
1185at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, 1185at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n)
1186 unsigned int n, const u8 *pins)
1187{ 1186{
1187 /*
1188 * Manage the chipselects as GPIOs, normally using the same pins
1189 * the SPI controller expects; but boards can use other pins.
1190 */
1191 static u8 __initdata spi_pins[][4] = {
1192 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1193 GPIO_PIN_PA(5), GPIO_PIN_PA(20) },
1194 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1195 GPIO_PIN_PB(4), GPIO_PIN_PA(27) },
1196 };
1188 unsigned int pin, mode; 1197 unsigned int pin, mode;
1189 1198
1199 /* There are only 2 SPI controllers */
1200 if (bus_num > 1)
1201 return;
1202
1190 for (; n; n--, b++) { 1203 for (; n; n--, b++) {
1191 b->bus_num = bus_num; 1204 b->bus_num = bus_num;
1192 if (b->chip_select >= 4) 1205 if (b->chip_select >= 4)
1193 continue; 1206 continue;
1194 pin = (unsigned)b->controller_data; 1207 pin = (unsigned)b->controller_data;
1195 if (!pin) { 1208 if (!pin) {
1196 pin = pins[b->chip_select]; 1209 pin = spi_pins[bus_num][b->chip_select];
1197 b->controller_data = (void *)pin; 1210 b->controller_data = (void *)pin;
1198 } 1211 }
1199 mode = AT32_GPIOF_OUTPUT; 1212 mode = AT32_GPIOF_OUTPUT;
@@ -1206,16 +1219,6 @@ at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
1206struct platform_device *__init 1219struct platform_device *__init
1207at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) 1220at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1208{ 1221{
1209 /*
1210 * Manage the chipselects as GPIOs, normally using the same pins
1211 * the SPI controller expects; but boards can use other pins.
1212 */
1213 static u8 __initdata spi0_pins[] =
1214 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1215 GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
1216 static u8 __initdata spi1_pins[] =
1217 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1218 GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
1219 struct platform_device *pdev; 1222 struct platform_device *pdev;
1220 u32 pin_mask; 1223 u32 pin_mask;
1221 1224
@@ -1228,7 +1231,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1228 select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP); 1231 select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP);
1229 select_peripheral(PIOA, pin_mask, PERIPH_A, 0); 1232 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1230 1233
1231 at32_spi_setup_slaves(0, b, n, spi0_pins); 1234 at32_spi_setup_slaves(0, b, n);
1232 break; 1235 break;
1233 1236
1234 case 1: 1237 case 1:
@@ -1239,7 +1242,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1239 select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP); 1242 select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP);
1240 select_peripheral(PIOB, pin_mask, PERIPH_B, 0); 1243 select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
1241 1244
1242 at32_spi_setup_slaves(1, b, n, spi1_pins); 1245 at32_spi_setup_slaves(1, b, n);
1243 break; 1246 break;
1244 1247
1245 default: 1248 default:
diff --git a/arch/avr32/mach-at32ap/include/mach/board.h b/arch/avr32/mach-at32ap/include/mach/board.h
index ddedb471f33..c7f25bb1d06 100644
--- a/arch/avr32/mach-at32ap/include/mach/board.h
+++ b/arch/avr32/mach-at32ap/include/mach/board.h
@@ -49,6 +49,7 @@ at32_add_device_eth(unsigned int id, struct eth_platform_data *data);
49struct spi_board_info; 49struct spi_board_info;
50struct platform_device * 50struct platform_device *
51at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n); 51at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
52void at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n);
52 53
53struct atmel_lcdfb_info; 54struct atmel_lcdfb_info;
54struct platform_device * 55struct platform_device *