From patchwork Tue May 31 16:04:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gagneraud X-Patchwork-Id: 832892 Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4VGAqb5014749 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 31 May 2011 16:11:18 GMT Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QRRSX-0005pv-3R; Tue, 31 May 2011 16:06:21 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QRRSA-0005oz-I5 for linux-arm-kernel@canuck.infradead.org; Tue, 31 May 2011 16:05:58 +0000 Received: from mailx.techworks.ie ([88.198.36.49]) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QRRRS-0001vi-Lv for linux-arm-kernel@lists.infradead.org; Tue, 31 May 2011 16:05:19 +0000 Received: from localhost (localhost [127.0.0.1]) by mailx.techworks.ie (Postfix) with ESMTP id 774FF580D3A; Tue, 31 May 2011 17:04:36 +0100 (IST) X-Virus-Scanned: amavisd-new at techworks.ie Received: from mailx.techworks.ie ([127.0.0.1]) by localhost (mailx.techworks.ie [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VH+rdLheU0I4; Tue, 31 May 2011 17:04:35 +0100 (IST) Received: from localhost.localdomain (unknown [86.43.120.173]) by mailx.techworks.ie (Postfix) with ESMTPSA id 6B9D2580DD5; Tue, 31 May 2011 17:04:35 +0100 (IST) From: Christian Gagneraud To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RFC 2/3] AT91: SPI: Split SPI controller device and SPI device Date: Tue, 31 May 2011 17:04:22 +0100 Message-Id: <1306857863-13424-3-git-send-email-chris@techworks.ie> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1306857863-13424-1-git-send-email-chris@techworks.ie> References: <1306857863-13424-1-git-send-email-chris@techworks.ie> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110531_170514_850431_17FA426A X-CRM114-Status: GOOD ( 17.61 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2-r929478 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Nicolas Ferre , Christian Gagneraud X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 31 May 2011 16:11:18 +0000 (UTC) Add a new atmel_spi_data structure to allow platform specific GPIO handling. Make at91_add_device_spi(), a function to add a SPI controller device. Plaform's SPI devices are now simply added by calling spi_register_board_info() from the board file. Signed-off-by: Christian Gagneraud --- arch/arm/mach-at91/at91sam9260_devices.c | 60 ++++++++++++++---------------- arch/arm/mach-at91/include/mach/board.h | 11 +++++- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c index 07eb7b0..e34225f 100644 --- a/arch/arm/mach-at91/at91sam9260_devices.c +++ b/arch/arm/mach-at91/at91sam9260_devices.c @@ -545,7 +545,12 @@ static struct platform_device at91sam9260_spi0_device = { .num_resources = ARRAY_SIZE(spi0_resources), }; -static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 }; +static struct gpio spi0_standard_cs_pins[] = { + { .gpio = AT91_PIN_PA3, }, + { .gpio = AT91_PIN_PC11, }, + { .gpio = AT91_PIN_PC16, }, + { .gpio = AT91_PIN_PC17, }, +}; static struct resource spi1_resources[] = { [0] = { @@ -571,53 +576,44 @@ static struct platform_device at91sam9260_spi1_device = { .num_resources = ARRAY_SIZE(spi1_resources), }; -static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 }; +static struct gpio spi1_standard_cs_pins[] = { + { .gpio = AT91_PIN_PB3, }, + { .gpio = AT91_PIN_PC5, }, + { .gpio = AT91_PIN_PC4, }, + { .gpio = AT91_PIN_PC3, }, +}; -void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) +void __init at91_add_device_spi(struct atmel_spi_data *data) { int i; - unsigned long cs_pin; - short enable_spi0 = 0; - short enable_spi1 = 0; - - /* Choose SPI chip-selects */ - for (i = 0; i < nr_devices; i++) { - if (devices[i].controller_data) - cs_pin = (unsigned long) devices[i].controller_data; - else if (devices[i].bus_num == 0) - cs_pin = spi0_standard_cs[devices[i].chip_select]; - else - cs_pin = spi1_standard_cs[devices[i].chip_select]; - - if (devices[i].bus_num == 0) - enable_spi0 = 1; - else - enable_spi1 = 1; - - /* enable chip-select pin */ - at91_set_gpio_output(cs_pin, 1); - - /* pass chip-select pin to driver */ - devices[i].controller_data = (void *) cs_pin; - } - spi_register_board_info(devices, nr_devices); + if (data->bus_num == 0) { + /* enable chip-select pins */ + if (!data->cs_pins) + data->cs_pins = spi0_standard_cs_pins; + for (i = 0; i < data->num_cs_pin; i++) + at91_set_gpio_output(data->cs_pins[i].gpio, 1); - /* Configure SPI bus(es) */ - if (enable_spi0) { at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */ at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */ at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */ at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk"); + platform_set_drvdata(&at91sam9260_spi0_device, data); platform_device_register(&at91sam9260_spi0_device); - } - if (enable_spi1) { + } else if (data->bus_num == 1) { + /* enable chip-select pins */ + if (!data->cs_pins) + data->cs_pins = spi1_standard_cs_pins; + for (i = 0; i < data->num_cs_pin; i++) + at91_set_gpio_output(data->cs_pins[i].gpio, 1); + at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */ at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */ at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */ at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk"); + platform_set_drvdata(&at91sam9260_spi1_device, data); platform_device_register(&at91sam9260_spi1_device); } } diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h index 2b499eb..d7cc95f 100644 --- a/arch/arm/mach-at91/include/mach/board.h +++ b/arch/arm/mach-at91/include/mach/board.h @@ -124,7 +124,16 @@ extern void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_de #endif /* SPI */ -extern void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices); +struct atmel_spi_data { + unsigned bus_num; + unsigned num_cs_pin; + struct gpio *cs_pins; + unsigned flags; +#define ATMEL_SPI_CS_DEC 0x01 /* The CS pins are decoded to + (2^num_cs_pin)-1 logical CS + lines */ +}; +extern void __init at91_add_device_spi(struct atmel_spi_data *data); /* Serial */ #define ATMEL_UART_CTS 0x01