0016-iot2000-hack-gpio-pca953x-provide-GPIO-base-based-on.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 5c102aea3f4ffea811eec719edd638fc7888e9c3 Mon Sep 17 00:00:00 2001
  2. From: Yong Li <sdliyong@gmail.com>
  3. Date: Thu, 31 Mar 2016 15:33:08 +0800
  4. Subject: [PATCH 16/18] iot2000-hack: gpio: pca953x: provide GPIO base based on
  5. _UID
  6. Custom kernel for Intel Galileo Gen2 provides and moreover libmraa relies on
  7. the continuous GPIO space. To do such we have to configure GPIO base per each
  8. GPIO expander. The only value we can use is the ACPI _UID.
  9. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  10. Upstream-status: Inappropriate, custom code for legacy userspace
  11. Signed-off-by: Saul Wold <sgw@linux.intel.com>
  12. Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
  13. Signed-off-by: Yong Li <sdliyong@gmail.com>
  14. Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
  15. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  16. ---
  17. drivers/gpio/gpio-pca953x.c | 44 +++++++++++++++++++++++++++++++++++++-------
  18. 1 file changed, 37 insertions(+), 7 deletions(-)
  19. diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
  20. index b45ba6be69ef..8b467c0db1cb 100644
  21. --- a/drivers/gpio/gpio-pca953x.c
  22. +++ b/drivers/gpio/gpio-pca953x.c
  23. @@ -82,12 +82,6 @@ static const struct i2c_device_id pca953x_id[] = {
  24. };
  25. MODULE_DEVICE_TABLE(i2c, pca953x_id);
  26. -static const struct acpi_device_id pca953x_acpi_ids[] = {
  27. - { "INT3491", 16 | PCA953X_TYPE | PCA_INT | PCA_PCAL, },
  28. - { }
  29. -};
  30. -MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
  31. -
  32. #define MAX_BANK 5
  33. #define BANK_SZ 8
  34. @@ -119,6 +113,35 @@ static inline struct pca953x_chip *to_pca(struct gpio_chip *gc)
  35. return container_of(gc, struct pca953x_chip, gpio_chip);
  36. }
  37. +struct pca953x_info {
  38. + kernel_ulong_t driver_data;
  39. + void (*setup)(struct pca953x_chip *chip);
  40. +};
  41. +
  42. +static void pca953x_setup_int3491(struct pca953x_chip *chip)
  43. +{
  44. + struct acpi_device *adev = ACPI_COMPANION(&chip->client->dev);
  45. + unsigned int uid;
  46. +
  47. + if (kstrtouint(acpi_device_uid(adev), 0, &uid) || !uid--)
  48. + return;
  49. +
  50. + chip->gpio_start = 8 /* sch_gpio */ +
  51. + 8 /* gpio-dwapb */ +
  52. + 16 /* pca9535 */ * uid;
  53. +}
  54. +
  55. +static const struct pca953x_info pca953x_info_int3491 = {
  56. + .driver_data = 16 | PCA953X_TYPE | PCA_INT | PCA_PCAL,
  57. + .setup = pca953x_setup_int3491,
  58. +};
  59. +
  60. +static const struct acpi_device_id pca953x_acpi_ids[] = {
  61. + { "INT3491", (kernel_ulong_t)&pca953x_info_int3491 },
  62. + { }
  63. +};
  64. +MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
  65. +
  66. static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
  67. int off)
  68. {
  69. @@ -731,12 +754,19 @@ static int pca953x_probe(struct i2c_client *client,
  70. chip->driver_data = id->driver_data;
  71. } else {
  72. const struct acpi_device_id *id;
  73. + const struct pca953x_info *info;
  74. id = acpi_match_device(pca953x_acpi_ids, &client->dev);
  75. if (!id)
  76. return -ENODEV;
  77. - chip->driver_data = id->driver_data;
  78. + info = (struct pca953x_info *)id->driver_data;
  79. + if (!info)
  80. + return -ENODEV;
  81. +
  82. + chip->driver_data = info->driver_data;
  83. + if (info->setup)
  84. + info->setup(chip);
  85. }
  86. chip->chip_type = PCA_CHIP_TYPE(chip->driver_data);
  87. --
  88. 2.16.4