aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/spi/spi_gpio.c21
-rw-r--r--include/linux/spi/spi_gpio.h6
2 files changed, 19 insertions, 8 deletions
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index d2866c293dee..26bd03e61855 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
diff --git a/include/linux/spi/spi_gpio.h b/include/linux/spi/spi_gpio.h
index 0f01a0f1f40c..ca6782ee4b9f 100644
--- a/include/linux/spi/spi_gpio.h
+++ b/include/linux/spi/spi_gpio.h
@@ -25,10 +25,16 @@
25 * ... 25 * ...
26 * }; 26 * };
27 * 27 *
28 * If chipselect is not used (there's only one device on the bus), assign
29 * SPI_GPIO_NO_CHIPSELECT to the controller_data:
30 * .controller_data = (void *) SPI_GPIO_NO_CHIPSELECT;
31 *
28 * If the bitbanged bus is later switched to a "native" controller, 32 * If the bitbanged bus is later switched to a "native" controller,
29 * that platform_device and controller_data should be removed. 33 * that platform_device and controller_data should be removed.
30 */ 34 */
31 35
36#define SPI_GPIO_NO_CHIPSELECT ((unsigned long)-1l)
37
32/** 38/**
33 * struct spi_gpio_platform_data - parameter for bitbanged SPI master 39 * struct spi_gpio_platform_data - parameter for bitbanged SPI master
34 * @sck: number of the GPIO used for clock output 40 * @sck: number of the GPIO used for clock output