diff options
Diffstat (limited to 'drivers/spi/spi-gpio.c')
-rw-r--r-- | drivers/spi/spi-gpio.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 9f595535cf27..4b600d4f8548 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -48,7 +48,7 @@ struct spi_gpio { | |||
48 | struct spi_bitbang bitbang; | 48 | struct spi_bitbang bitbang; |
49 | struct spi_gpio_platform_data pdata; | 49 | struct spi_gpio_platform_data pdata; |
50 | struct platform_device *pdev; | 50 | struct platform_device *pdev; |
51 | int cs_gpios[0]; | 51 | unsigned long cs_gpios[0]; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | /*----------------------------------------------------------------------*/ | 54 | /*----------------------------------------------------------------------*/ |
@@ -220,7 +220,7 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, | |||
220 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) | 220 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) |
221 | { | 221 | { |
222 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 222 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
223 | unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; | 223 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; |
224 | 224 | ||
225 | /* set initial clock polarity */ | 225 | /* set initial clock polarity */ |
226 | if (is_active) | 226 | if (is_active) |
@@ -234,7 +234,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active) | |||
234 | 234 | ||
235 | static int spi_gpio_setup(struct spi_device *spi) | 235 | static int spi_gpio_setup(struct spi_device *spi) |
236 | { | 236 | { |
237 | unsigned int cs; | 237 | unsigned long cs; |
238 | int status = 0; | 238 | int status = 0; |
239 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 239 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
240 | struct device_node *np = spi->master->dev.of_node; | 240 | struct device_node *np = spi->master->dev.of_node; |
@@ -249,7 +249,7 @@ static int spi_gpio_setup(struct spi_device *spi) | |||
249 | /* | 249 | /* |
250 | * ... otherwise, take it from spi->controller_data | 250 | * ... otherwise, take it from spi->controller_data |
251 | */ | 251 | */ |
252 | cs = (unsigned int)(uintptr_t) spi->controller_data; | 252 | cs = (uintptr_t) spi->controller_data; |
253 | } | 253 | } |
254 | 254 | ||
255 | if (!spi->controller_state) { | 255 | if (!spi->controller_state) { |
@@ -277,7 +277,7 @@ static int spi_gpio_setup(struct spi_device *spi) | |||
277 | static void spi_gpio_cleanup(struct spi_device *spi) | 277 | static void spi_gpio_cleanup(struct spi_device *spi) |
278 | { | 278 | { |
279 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 279 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
280 | unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; | 280 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; |
281 | 281 | ||
282 | if (cs != SPI_GPIO_NO_CHIPSELECT) | 282 | if (cs != SPI_GPIO_NO_CHIPSELECT) |
283 | gpio_free(cs); | 283 | gpio_free(cs); |
@@ -413,6 +413,7 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
413 | struct spi_gpio_platform_data *pdata; | 413 | struct spi_gpio_platform_data *pdata; |
414 | u16 master_flags = 0; | 414 | u16 master_flags = 0; |
415 | bool use_of = 0; | 415 | bool use_of = 0; |
416 | int num_devices; | ||
416 | 417 | ||
417 | status = spi_gpio_probe_dt(pdev); | 418 | status = spi_gpio_probe_dt(pdev); |
418 | if (status < 0) | 419 | if (status < 0) |
@@ -422,16 +423,21 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
422 | 423 | ||
423 | pdata = dev_get_platdata(&pdev->dev); | 424 | pdata = dev_get_platdata(&pdev->dev); |
424 | #ifdef GENERIC_BITBANG | 425 | #ifdef GENERIC_BITBANG |
425 | if (!pdata || !pdata->num_chipselect) | 426 | if (!pdata || (!use_of && !pdata->num_chipselect)) |
426 | return -ENODEV; | 427 | return -ENODEV; |
427 | #endif | 428 | #endif |
428 | 429 | ||
430 | if (use_of && !SPI_N_CHIPSEL) | ||
431 | num_devices = 1; | ||
432 | else | ||
433 | num_devices = SPI_N_CHIPSEL; | ||
434 | |||
429 | status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags); | 435 | status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags); |
430 | if (status < 0) | 436 | if (status < 0) |
431 | return status; | 437 | return status; |
432 | 438 | ||
433 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + | 439 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + |
434 | (sizeof(int) * SPI_N_CHIPSEL)); | 440 | (sizeof(unsigned long) * num_devices)); |
435 | if (!master) { | 441 | if (!master) { |
436 | status = -ENOMEM; | 442 | status = -ENOMEM; |
437 | goto gpio_free; | 443 | goto gpio_free; |
@@ -446,7 +452,7 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
446 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); | 452 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); |
447 | master->flags = master_flags; | 453 | master->flags = master_flags; |
448 | master->bus_num = pdev->id; | 454 | master->bus_num = pdev->id; |
449 | master->num_chipselect = SPI_N_CHIPSEL; | 455 | master->num_chipselect = num_devices; |
450 | master->setup = spi_gpio_setup; | 456 | master->setup = spi_gpio_setup; |
451 | master->cleanup = spi_gpio_cleanup; | 457 | master->cleanup = spi_gpio_cleanup; |
452 | #ifdef CONFIG_OF | 458 | #ifdef CONFIG_OF |
@@ -461,9 +467,18 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
461 | * property of the node. | 467 | * property of the node. |
462 | */ | 468 | */ |
463 | 469 | ||
464 | for (i = 0; i < SPI_N_CHIPSEL; i++) | 470 | if (!SPI_N_CHIPSEL) |
465 | spi_gpio->cs_gpios[i] = | 471 | spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; |
466 | of_get_named_gpio(np, "cs-gpios", i); | 472 | else |
473 | for (i = 0; i < SPI_N_CHIPSEL; i++) { | ||
474 | status = of_get_named_gpio(np, "cs-gpios", i); | ||
475 | if (status < 0) { | ||
476 | dev_err(&pdev->dev, | ||
477 | "invalid cs-gpios property\n"); | ||
478 | goto gpio_free; | ||
479 | } | ||
480 | spi_gpio->cs_gpios[i] = status; | ||
481 | } | ||
467 | } | 482 | } |
468 | #endif | 483 | #endif |
469 | 484 | ||