aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi_gpio.c
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-04-02 19:57:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-02 22:04:51 -0400
commitbfb9bcdbda9a61bca469bf899a589918c60c4c18 (patch)
tree40b28178c9d969c94e2039b27ac213cab5de0e79 /drivers/spi/spi_gpio.c
parent8a0cecffeb52363a57257bbbbd58f4c4537a75bb (diff)
spi-gpio: allow operation without CS signal
Change spi-gpio so that it is possible to drive SPI communications over GPIO without the need for a chipselect signal. This is useful in very small setups where there's only one slave device on the bus. This patch does not affect existing setups. I use this for a tiny communication channel between an embedded device and a microcontroller. There are not enough GPIOs available for chipselect and it's not needed anyway in this case. Signed-off-by: Michael Buesch <mb@bu3sch.de> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/spi/spi_gpio.c')
-rw-r--r--drivers/spi/spi_gpio.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index d2866c293de..26bd03e6185 100644
--- a/drivers/spi/spi_gpio.c
+++ b/drivers/spi/spi_gpio.c
@@ -178,8 +178,10 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
178 if (is_active) 178 if (is_active)
179 setsck(spi, spi->mode & SPI_CPOL); 179 setsck(spi, spi->mode & SPI_CPOL);
180 180
181 /* SPI is normally active-low */ 181 if (cs != SPI_GPIO_NO_CHIPSELECT) {
182 gpio_set_value(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); 182 /* SPI is normally active-low */
183 gpio_set_value(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
184 }
183} 185}
184 186
185static int spi_gpio_setup(struct spi_device *spi) 187static int spi_gpio_setup(struct spi_device *spi)
@@ -191,15 +193,17 @@ static int spi_gpio_setup(struct spi_device *spi)
191 return -EINVAL; 193 return -EINVAL;
192 194
193 if (!spi->controller_state) { 195 if (!spi->controller_state) {
194 status = gpio_request(cs, dev_name(&spi->dev)); 196 if (cs != SPI_GPIO_NO_CHIPSELECT) {
195 if (status) 197 status = gpio_request(cs, dev_name(&spi->dev));
196 return status; 198 if (status)
197 status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH); 199 return status;
200 status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH);
201 }
198 } 202 }
199 if (!status) 203 if (!status)
200 status = spi_bitbang_setup(spi); 204 status = spi_bitbang_setup(spi);
201 if (status) { 205 if (status) {
202 if (!spi->controller_state) 206 if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
203 gpio_free(cs); 207 gpio_free(cs);
204 } 208 }
205 return status; 209 return status;
@@ -209,7 +213,8 @@ static void spi_gpio_cleanup(struct spi_device *spi)
209{ 213{
210 unsigned long cs = (unsigned long) spi->controller_data; 214 unsigned long cs = (unsigned long) spi->controller_data;
211 215
212 gpio_free(cs); 216 if (cs != SPI_GPIO_NO_CHIPSELECT)
217 gpio_free(cs);
213 spi_bitbang_cleanup(spi); 218 spi_bitbang_cleanup(spi);
214} 219}
215 220