1
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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,16 +195,18 @@ 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
  70. static struct spi_driver gen_74x164_driver = {
  71. .driver = {
  72. .name = "74x164",
  73. - .of_match_table = gen_74x164_dt_ids,
  74. + .of_match_table = of_match_ptr(gen_74x164_dt_ids),
  75. },
  76. .probe = gen_74x164_probe,
  77. .remove = gen_74x164_remove,
  78. --- /dev/null
  79. +++ b/include/linux/spi/74x164.h
  80. @@ -0,0 +1,13 @@
  81. +#ifndef LINUX_SPI_74X164_H
  82. +#define LINUX_SPI_74X164_H
  83. +
  84. +struct gen_74x164_chip_platform_data {
  85. + /* number assigned to the first GPIO */
  86. + unsigned base;
  87. + /* number of chained registers */
  88. + unsigned num_registers;
  89. + /* address of a buffer containing initial data */
  90. + u8 *init_data;
  91. +};
  92. +
  93. +#endif
  94. --- a/drivers/gpio/Kconfig
  95. +++ b/drivers/gpio/Kconfig
  96. @@ -991,7 +991,6 @@ menu "SPI GPIO expanders"
  97. config GPIO_74X164
  98. tristate "74x164 serial-in/parallel-out 8-bits shift register"
  99. - depends on OF
  100. help
  101. Driver for 74x164 compatible serial-in/parallel-out 8-outputs
  102. shift registers. This driver can be used to provide access