diff options
author | Martin Sperl <kernel@martin.sperl.org> | 2015-04-06 13:16:31 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-04-10 14:50:52 -0400 |
commit | a30a555d7435a440fab06fe5960cf3448d8cedd3 (patch) | |
tree | 119afa8a1ede43f405397e2227e5ce4c69686f1b /drivers/spi/spi-bcm2835.c | |
parent | e3a2be3030e2fec27a2577d3c52203da090a4366 (diff) |
spi: bcm2835: transform native-cs to gpio-cs on first spi_setup
Transforms the bcm-2835 native SPI-chip select to their gpio-cs equivalent.
This allows for some support of some optimizations that are not
possible due to HW-gliches on the CS line - especially filling
the FIFO before enabling SPI interrupts (by writing to CS register)
while the transfer is already in progress (See commit: e3a2be3030e2)
This patch also works arround some issues in bcm2835-pinctrl which does not
set the value when setting the GPIO as output - it just sets up output and
(typically) leaves the GPIO as low. When a fix for this is merged then this
gpio_set_value can get removed from bcm2835_spi_setup.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-bcm2835.c')
-rw-r--r-- | drivers/spi/spi-bcm2835.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 08e5406c5029..90064494e828 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c | |||
@@ -291,8 +291,15 @@ static void bcm2835_spi_set_cs(struct spi_device *spi, bool gpio_level) | |||
291 | bcm2835_wr(bs, BCM2835_SPI_CS, cs); | 291 | bcm2835_wr(bs, BCM2835_SPI_CS, cs); |
292 | } | 292 | } |
293 | 293 | ||
294 | static int chip_match_name(struct gpio_chip *chip, void *data) | ||
295 | { | ||
296 | return !strcmp(chip->label, data); | ||
297 | } | ||
298 | |||
294 | static int bcm2835_spi_setup(struct spi_device *spi) | 299 | static int bcm2835_spi_setup(struct spi_device *spi) |
295 | { | 300 | { |
301 | int err; | ||
302 | struct gpio_chip *chip; | ||
296 | /* | 303 | /* |
297 | * sanity checking the native-chipselects | 304 | * sanity checking the native-chipselects |
298 | */ | 305 | */ |
@@ -300,13 +307,45 @@ static int bcm2835_spi_setup(struct spi_device *spi) | |||
300 | return 0; | 307 | return 0; |
301 | if (gpio_is_valid(spi->cs_gpio)) | 308 | if (gpio_is_valid(spi->cs_gpio)) |
302 | return 0; | 309 | return 0; |
303 | if (spi->chip_select < 3) | 310 | if (spi->chip_select > 1) { |
311 | /* error in the case of native CS requested with CS > 1 | ||
312 | * officially there is a CS2, but it is not documented | ||
313 | * which GPIO is connected with that... | ||
314 | */ | ||
315 | dev_err(&spi->dev, | ||
316 | "setup: only two native chip-selects are supported\n"); | ||
317 | return -EINVAL; | ||
318 | } | ||
319 | /* now translate native cs to GPIO */ | ||
320 | |||
321 | /* get the gpio chip for the base */ | ||
322 | chip = gpiochip_find("pinctrl-bcm2835", chip_match_name); | ||
323 | if (!chip) | ||
304 | return 0; | 324 | return 0; |
305 | 325 | ||
306 | /* error in the case of native CS requested with CS-id > 2 */ | 326 | /* and calculate the real CS */ |
307 | dev_err(&spi->dev, | 327 | spi->cs_gpio = chip->base + 8 - spi->chip_select; |
308 | "setup: only three native chip-selects are supported\n"); | 328 | |
309 | return -EINVAL; | 329 | /* and set up the "mode" and level */ |
330 | dev_info(&spi->dev, "setting up native-CS%i as GPIO %i\n", | ||
331 | spi->chip_select, spi->cs_gpio); | ||
332 | |||
333 | /* set up GPIO as output and pull to the correct level */ | ||
334 | err = gpio_direction_output(spi->cs_gpio, | ||
335 | (spi->mode & SPI_CS_HIGH) ? 0 : 1); | ||
336 | if (err) { | ||
337 | dev_err(&spi->dev, | ||
338 | "could not set CS%i gpio %i as output: %i", | ||
339 | spi->chip_select, spi->cs_gpio, err); | ||
340 | return err; | ||
341 | } | ||
342 | /* the implementation of pinctrl-bcm2835 currently does not | ||
343 | * set the GPIO value when using gpio_direction_output | ||
344 | * so we are setting it here explicitly | ||
345 | */ | ||
346 | gpio_set_value(spi->cs_gpio, (spi->mode & SPI_CS_HIGH) ? 0 : 1); | ||
347 | |||
348 | return 0; | ||
310 | } | 349 | } |
311 | 350 | ||
312 | static int bcm2835_spi_probe(struct platform_device *pdev) | 351 | static int bcm2835_spi_probe(struct platform_device *pdev) |