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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --- a/drivers/gpio/gpio-74x164.c
  2. +++ b/drivers/gpio/gpio-74x164.c
  3. @@ -13,6 +13,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. @@ -105,9 +106,16 @@ 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 = spi->dev.platform_data;
  16. + struct device_node *np = spi->dev.of_node;
  17. u32 nregs;
  18. int ret;
  19. + if (!np && !pdata) {
  20. + dev_err(&spi->dev, "No configuration data available.\n");
  21. + return -EINVAL;
  22. + }
  23. +
  24. /*
  25. * bits_per_word cannot be configured in platform data
  26. */
  27. @@ -117,12 +125,15 @@ static int gen_74x164_probe(struct spi_d
  28. if (ret < 0)
  29. return ret;
  30. - if (of_property_read_u32(spi->dev.of_node, "registers-number",
  31. - &nregs)) {
  32. - dev_err(&spi->dev,
  33. - "Missing registers-number property in the DT.\n");
  34. - return -EINVAL;
  35. - }
  36. + if (np) {
  37. + if (of_property_read_u32(np, "registers-number", &nregs)) {
  38. + dev_err(&spi->dev,
  39. + "Missing registers-number property in the DT.\n");
  40. + return -EINVAL;
  41. + }
  42. + } else if (pdata) {
  43. + nregs = pdata->num_registers;
  44. + }
  45. chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL);
  46. if (!chip)
  47. @@ -142,7 +153,11 @@ static int gen_74x164_probe(struct spi_d
  48. chip->gpio_chip.get = gen_74x164_get_value;
  49. chip->gpio_chip.set = gen_74x164_set_value;
  50. chip->gpio_chip.set_multiple = gen_74x164_set_multiple;
  51. - chip->gpio_chip.base = -1;
  52. + if (np)
  53. + chip->gpio_chip.base = -1;
  54. + else if (pdata)
  55. + chip->gpio_chip.base = pdata->base;
  56. +
  57. chip->registers = nregs;
  58. chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
  59. @@ -151,6 +166,9 @@ static int gen_74x164_probe(struct spi_d
  60. chip->gpio_chip.parent = &spi->dev;
  61. chip->gpio_chip.owner = THIS_MODULE;
  62. + if (pdata && pdata->init_data)
  63. + memcpy(chip->buffer, pdata->init_data, chip->registers);
  64. +
  65. mutex_init(&chip->lock);
  66. ret = __gen_74x164_write_config(chip);
  67. @@ -180,17 +198,19 @@ static int gen_74x164_remove(struct spi_
  68. return 0;
  69. }
  70. +#ifdef CONFIG_OF
  71. static const struct of_device_id gen_74x164_dt_ids[] = {
  72. { .compatible = "fairchild,74hc595" },
  73. { .compatible = "nxp,74lvc594" },
  74. {},
  75. };
  76. MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids);
  77. +#endif
  78. static struct spi_driver gen_74x164_driver = {
  79. .driver = {
  80. .name = "74x164",
  81. - .of_match_table = gen_74x164_dt_ids,
  82. + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
  83. },
  84. .probe = gen_74x164_probe,
  85. .remove = gen_74x164_remove,
  86. --- /dev/null
  87. +++ b/include/linux/spi/74x164.h
  88. @@ -0,0 +1,13 @@
  89. +#ifndef LINUX_SPI_74X164_H
  90. +#define LINUX_SPI_74X164_H
  91. +
  92. +struct gen_74x164_chip_platform_data {
  93. + /* number assigned to the first GPIO */
  94. + unsigned base;
  95. + /* number of chained registers */
  96. + unsigned num_registers;
  97. + /* address of a buffer containing initial data */
  98. + u8 *init_data;
  99. +};
  100. +
  101. +#endif
  102. --- a/drivers/gpio/Kconfig
  103. +++ b/drivers/gpio/Kconfig
  104. @@ -1252,7 +1252,6 @@ menu "SPI GPIO expanders"
  105. config GPIO_74X164
  106. tristate "74x164 serial-in/parallel-out 8-bits shift register"
  107. - depends on OF_GPIO
  108. help
  109. Driver for 74x164 compatible serial-in/parallel-out 8-outputs
  110. shift registers. This driver can be used to provide access