Commit 1e202de6 authored by Peter Ma's avatar Peter Ma Committed by Haavard Skinnemoen

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: default avatarPeter Ma <pma@mediamatech.com>
[haavard.skinnemoen@atmel.com: trivial whitespace fix]
Signed-off-by: default avatarHaavard Skinnemoen <haavard.skinnemoen@atmel.com>
parent 26a5e1e2
...@@ -1181,19 +1181,32 @@ static struct resource atmel_spi1_resource[] = { ...@@ -1181,19 +1181,32 @@ static struct resource atmel_spi1_resource[] = {
DEFINE_DEV(atmel_spi, 1); DEFINE_DEV(atmel_spi, 1);
DEV_CLK(spi_clk, atmel_spi1, pba, 1); DEV_CLK(spi_clk, atmel_spi1, pba, 1);
static void __init void __init
at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n)
unsigned int n, const u8 *pins)
{ {
/*
* Manage the chipselects as GPIOs, normally using the same pins
* the SPI controller expects; but boards can use other pins.
*/
static u8 __initdata spi_pins[][4] = {
{ GPIO_PIN_PA(3), GPIO_PIN_PA(4),
GPIO_PIN_PA(5), GPIO_PIN_PA(20) },
{ GPIO_PIN_PB(2), GPIO_PIN_PB(3),
GPIO_PIN_PB(4), GPIO_PIN_PA(27) },
};
unsigned int pin, mode; unsigned int pin, mode;
/* There are only 2 SPI controllers */
if (bus_num > 1)
return;
for (; n; n--, b++) { for (; n; n--, b++) {
b->bus_num = bus_num; b->bus_num = bus_num;
if (b->chip_select >= 4) if (b->chip_select >= 4)
continue; continue;
pin = (unsigned)b->controller_data; pin = (unsigned)b->controller_data;
if (!pin) { if (!pin) {
pin = pins[b->chip_select]; pin = spi_pins[bus_num][b->chip_select];
b->controller_data = (void *)pin; b->controller_data = (void *)pin;
} }
mode = AT32_GPIOF_OUTPUT; mode = AT32_GPIOF_OUTPUT;
...@@ -1206,16 +1219,6 @@ at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, ...@@ -1206,16 +1219,6 @@ at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
struct platform_device *__init struct platform_device *__init
at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) at32_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; struct platform_device *pdev;
u32 pin_mask; u32 pin_mask;
...@@ -1228,7 +1231,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) ...@@ -1228,7 +1231,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP); select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP);
select_peripheral(PIOA, pin_mask, PERIPH_A, 0); select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
at32_spi_setup_slaves(0, b, n, spi0_pins); at32_spi_setup_slaves(0, b, n);
break; break;
case 1: case 1:
...@@ -1239,7 +1242,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) ...@@ -1239,7 +1242,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP); select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP);
select_peripheral(PIOB, pin_mask, PERIPH_B, 0); select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
at32_spi_setup_slaves(1, b, n, spi1_pins); at32_spi_setup_slaves(1, b, n);
break; break;
default: default:
......
...@@ -49,6 +49,7 @@ at32_add_device_eth(unsigned int id, struct eth_platform_data *data); ...@@ -49,6 +49,7 @@ at32_add_device_eth(unsigned int id, struct eth_platform_data *data);
struct spi_board_info; struct spi_board_info;
struct platform_device * struct platform_device *
at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n); at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
void at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n);
struct atmel_lcdfb_info; struct atmel_lcdfb_info;
struct platform_device * struct platform_device *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment