451-gpio-74x164-improve-platform-device-support.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. --- a/drivers/gpio/gpio-74x164.c
  2. +++ b/drivers/gpio/gpio-74x164.c
  3. @@ -12,6 +12,7 @@
  4. #include <linux/init.h>
  5. #include <linux/mutex.h>
  6. #include <linux/spi/spi.h>
  7. +#include <linux/spi/74x164.h>
  8. #include <linux/gpio.h>
  9. #include <linux/of_gpio.h>
  10. #include <linux/slab.h>
  11. @@ -107,8 +108,18 @@ static int gen_74x164_direction_output(s
  12. static int gen_74x164_probe(struct spi_device *spi)
  13. {
  14. struct gen_74x164_chip *chip;
  15. + struct gen_74x164_chip_platform_data *pdata;
  16. + struct device_node *np;
  17. int ret;
  18. + pdata = spi->dev.platform_data;
  19. + np = spi->dev.of_node;
  20. +
  21. + if (!np && !pdata) {
  22. + dev_err(&spi->dev, "No configuration data available.\n");
  23. + return -EINVAL;
  24. + }
  25. +
  26. /*
  27. * bits_per_word cannot be configured in platform data
  28. */
  29. @@ -130,18 +141,28 @@ static int gen_74x164_probe(struct spi_d
  30. chip->gpio_chip.set = gen_74x164_set_value;
  31. chip->gpio_chip.base = -1;
  32. - if (of_property_read_u32(spi->dev.of_node, "registers-number",
  33. - &chip->registers)) {
  34. - dev_err(&spi->dev,
  35. - "Missing registers-number property in the DT.\n");
  36. - return -EINVAL;
  37. + if (np) {
  38. + if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) {
  39. + dev_err(&spi->dev, "Missing registers-number property in the DT.\n");
  40. + ret = -EINVAL;
  41. + goto exit_destroy;
  42. + }
  43. + } else if (pdata) {
  44. + chip->gpio_chip.base = pdata->base;
  45. + chip->registers = pdata->num_registers;
  46. }
  47. + if (!chip->registers)
  48. + chip->registers = 1;
  49. +
  50. chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
  51. chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL);
  52. if (!chip->buffer)
  53. return -ENOMEM;
  54. + if (pdata && pdata->init_data)
  55. + memcpy(chip->buffer, pdata->init_data, chip->registers);
  56. +
  57. chip->gpio_chip.can_sleep = true;
  58. chip->gpio_chip.dev = &spi->dev;
  59. chip->gpio_chip.owner = THIS_MODULE;
  60. @@ -174,17 +195,19 @@ static int gen_74x164_remove(struct spi_
  61. return 0;
  62. }
  63. +#ifdef CONFIG_OF
  64. static const struct of_device_id gen_74x164_dt_ids[] = {
  65. { .compatible = "fairchild,74hc595" },
  66. {},
  67. };
  68. MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
  69. +#endif /* CONFIG_OF */
  70. static struct spi_driver gen_74x164_driver = {
  71. .driver = {
  72. .name = "74x164",
  73. .owner = THIS_MODULE,
  74. - .of_match_table = gen_74x164_dt_ids,
  75. + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
  76. },
  77. .probe = gen_74x164_probe,
  78. .remove = gen_74x164_remove,
  79. --- /dev/null
  80. +++ b/include/linux/spi/74x164.h
  81. @@ -0,0 +1,13 @@
  82. +#ifndef LINUX_SPI_74X164_H
  83. +#define LINUX_SPI_74X164_H
  84. +
  85. +struct gen_74x164_chip_platform_data {
  86. + /* number assigned to the first GPIO */
  87. + unsigned base;
  88. + /* number of chained registers */
  89. + unsigned num_registers;
  90. + /* address of a buffer containing initial data */
  91. + u8 *init_data;
  92. +};
  93. +
  94. +#endif
  95. --- a/drivers/gpio/Kconfig
  96. +++ b/drivers/gpio/Kconfig
  97. @@ -821,7 +821,7 @@ config GPIO_MC33880
  98. config GPIO_74X164
  99. tristate "74x164 serial-in/parallel-out 8-bits shift register"
  100. - depends on SPI_MASTER && OF
  101. + depends on SPI_MASTER
  102. help
  103. Driver for 74x164 compatible serial-in/parallel-out 8-outputs
  104. shift registers. This driver can be used to provide access