0028-gpio-pca953x-provide-GPIO-base-based-on-_UID.patch 2.8 KB

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