Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi/spi-fsl-spi: Add support for gpio chipselects for GRLIB type cores

This relies upon of_spi_register_master to find out which gpios to use.

Acked-by: Anton Vorontsov <anton@enomsg.org>
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Andreas Larsson and committed by
Grant Likely
76a7498f 447b0c7b

+46 -5
+1
drivers/spi/spi-fsl-lib.h
··· 71 71 72 72 #ifdef CONFIG_SPI_FSL_SPI 73 73 int type; 74 + int native_chipselects; 74 75 u8 max_bits_per_word; 75 76 76 77 void (*set_shifts)(u32 *rx_shift, u32 *tx_shift,
+45 -5
drivers/spi/spi-fsl-spi.c
··· 456 456 return retval; 457 457 } 458 458 459 + if (mpc8xxx_spi->type == TYPE_GRLIB) { 460 + if (gpio_is_valid(spi->cs_gpio)) { 461 + int desel; 462 + 463 + retval = gpio_request(spi->cs_gpio, 464 + dev_name(&spi->dev)); 465 + if (retval) 466 + return retval; 467 + 468 + desel = !(spi->mode & SPI_CS_HIGH); 469 + retval = gpio_direction_output(spi->cs_gpio, desel); 470 + if (retval) { 471 + gpio_free(spi->cs_gpio); 472 + return retval; 473 + } 474 + } else if (spi->cs_gpio != -ENOENT) { 475 + if (spi->cs_gpio < 0) 476 + return spi->cs_gpio; 477 + return -EINVAL; 478 + } 479 + /* When spi->cs_gpio == -ENOENT, a hole in the phandle list 480 + * indicates to use native chipselect if present, or allow for 481 + * an always selected chip 482 + */ 483 + } 484 + 459 485 /* Initialize chipselect - might be active for SPI_CS_HIGH mode */ 460 486 fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE); 461 487 462 488 return 0; 489 + } 490 + 491 + static void fsl_spi_cleanup(struct spi_device *spi) 492 + { 493 + struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 494 + 495 + if (mpc8xxx_spi->type == TYPE_GRLIB && gpio_is_valid(spi->cs_gpio)) 496 + gpio_free(spi->cs_gpio); 463 497 } 464 498 465 499 static void fsl_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) ··· 563 529 u32 slvsel; 564 530 u16 cs = spi->chip_select; 565 531 566 - slvsel = mpc8xxx_spi_read_reg(&reg_base->slvsel); 567 - slvsel = on ? (slvsel | (1 << cs)) : (slvsel & ~(1 << cs)); 568 - mpc8xxx_spi_write_reg(&reg_base->slvsel, slvsel); 532 + if (gpio_is_valid(spi->cs_gpio)) { 533 + gpio_set_value(spi->cs_gpio, on); 534 + } else if (cs < mpc8xxx_spi->native_chipselects) { 535 + slvsel = mpc8xxx_spi_read_reg(&reg_base->slvsel); 536 + slvsel = on ? (slvsel | (1 << cs)) : (slvsel & ~(1 << cs)); 537 + mpc8xxx_spi_write_reg(&reg_base->slvsel, slvsel); 538 + } 569 539 } 570 540 571 541 static void fsl_spi_grlib_probe(struct device *dev) ··· 588 550 if (mbits) 589 551 mpc8xxx_spi->max_bits_per_word = mbits + 1; 590 552 591 - master->num_chipselect = 1; /* Allow for an always selected chip */ 553 + mpc8xxx_spi->native_chipselects = 0; 592 554 if (SPCAP_SSEN(capabilities)) { 593 - master->num_chipselect = SPCAP_SSSZ(capabilities); 555 + mpc8xxx_spi->native_chipselects = SPCAP_SSSZ(capabilities); 594 556 mpc8xxx_spi_write_reg(&reg_base->slvsel, 0xffffffff); 595 557 } 558 + master->num_chipselect = mpc8xxx_spi->native_chipselects; 596 559 pdata->cs_control = fsl_spi_grlib_cs_control; 597 560 } 598 561 ··· 620 581 goto err_probe; 621 582 622 583 master->setup = fsl_spi_setup; 584 + master->cleanup = fsl_spi_cleanup; 623 585 624 586 mpc8xxx_spi = spi_master_get_devdata(master); 625 587 mpc8xxx_spi->spi_do_one_msg = fsl_spi_do_one_msg;