Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 139638
b: refs/heads/master
c: bfb9bcd
h: refs/heads/master
v: v3
  • Loading branch information
Michael Buesch authored and Linus Torvalds committed Apr 3, 2009
1 parent 9482f84 commit 9ca143c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8a0cecffeb52363a57257bbbbd58f4c4537a75bb
refs/heads/master: bfb9bcdbda9a61bca469bf899a589918c60c4c18
21 changes: 13 additions & 8 deletions trunk/drivers/spi/spi_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
if (is_active)
setsck(spi, spi->mode & SPI_CPOL);

/* SPI is normally active-low */
gpio_set_value(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
if (cs != SPI_GPIO_NO_CHIPSELECT) {
/* SPI is normally active-low */
gpio_set_value(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
}
}

static int spi_gpio_setup(struct spi_device *spi)
Expand All @@ -191,15 +193,17 @@ static int spi_gpio_setup(struct spi_device *spi)
return -EINVAL;

if (!spi->controller_state) {
status = gpio_request(cs, dev_name(&spi->dev));
if (status)
return status;
status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH);
if (cs != SPI_GPIO_NO_CHIPSELECT) {
status = gpio_request(cs, dev_name(&spi->dev));
if (status)
return status;
status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH);
}
}
if (!status)
status = spi_bitbang_setup(spi);
if (status) {
if (!spi->controller_state)
if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
gpio_free(cs);
}
return status;
Expand All @@ -209,7 +213,8 @@ static void spi_gpio_cleanup(struct spi_device *spi)
{
unsigned long cs = (unsigned long) spi->controller_data;

gpio_free(cs);
if (cs != SPI_GPIO_NO_CHIPSELECT)
gpio_free(cs);
spi_bitbang_cleanup(spi);
}

Expand Down
6 changes: 6 additions & 0 deletions trunk/include/linux/spi/spi_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
* ...
* };
*
* If chipselect is not used (there's only one device on the bus), assign
* SPI_GPIO_NO_CHIPSELECT to the controller_data:
* .controller_data = (void *) SPI_GPIO_NO_CHIPSELECT;
*
* If the bitbanged bus is later switched to a "native" controller,
* that platform_device and controller_data should be removed.
*/

#define SPI_GPIO_NO_CHIPSELECT ((unsigned long)-1l)

/**
* struct spi_gpio_platform_data - parameter for bitbanged SPI master
* @sck: number of the GPIO used for clock output
Expand Down

0 comments on commit 9ca143c

Please sign in to comment.