pinctrl-qdf2xxx.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * GPIO and pin control functions on this SOC are handled by the "TLMM"
  14. * device. The driver which controls this device is pinctrl-msm.c. Each
  15. * SOC with a TLMM is expected to create a client driver that registers
  16. * with pinctrl-msm.c. This means that all TLMM drivers are pin control
  17. * drivers.
  18. *
  19. * This pin control driver is intended to be used only an ACPI-enabled
  20. * system. As such, UEFI will handle all pin control configuration, so
  21. * this driver does not provide pin control functions. It is effectively
  22. * a GPIO-only driver. The alternative is to duplicate the GPIO code of
  23. * pinctrl-msm.c into another driver.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/acpi.h>
  29. #include "pinctrl-msm.h"
  30. /* A maximum of 256 allows us to use a u8 array to hold the GPIO numbers */
  31. #define MAX_GPIOS 256
  32. /* maximum size of each gpio name (enough room for "gpioXXX" + null) */
  33. #define NAME_SIZE 8
  34. static int qdf2xxx_pinctrl_probe(struct platform_device *pdev)
  35. {
  36. struct msm_pinctrl_soc_data *pinctrl;
  37. struct pinctrl_pin_desc *pins;
  38. struct msm_pingroup *groups;
  39. char (*names)[NAME_SIZE];
  40. unsigned int i;
  41. u32 num_gpios;
  42. unsigned int avail_gpios; /* The number of GPIOs we support */
  43. u8 gpios[MAX_GPIOS]; /* An array of supported GPIOs */
  44. int ret;
  45. /* Query the number of GPIOs from ACPI */
  46. ret = device_property_read_u32(&pdev->dev, "num-gpios", &num_gpios);
  47. if (ret < 0) {
  48. dev_err(&pdev->dev, "missing 'num-gpios' property\n");
  49. return ret;
  50. }
  51. if (!num_gpios || num_gpios > MAX_GPIOS) {
  52. dev_err(&pdev->dev, "invalid 'num-gpios' property\n");
  53. return -ENODEV;
  54. }
  55. /* The number of GPIOs in the approved list */
  56. ret = device_property_read_u8_array(&pdev->dev, "gpios", NULL, 0);
  57. if (ret < 0) {
  58. dev_err(&pdev->dev, "missing 'gpios' property\n");
  59. return ret;
  60. }
  61. /*
  62. * The number of available GPIOs should be non-zero, and no
  63. * more than the total number of GPIOS.
  64. */
  65. if (!ret || ret > num_gpios) {
  66. dev_err(&pdev->dev, "invalid 'gpios' property\n");
  67. return -ENODEV;
  68. }
  69. avail_gpios = ret;
  70. ret = device_property_read_u8_array(&pdev->dev, "gpios", gpios,
  71. avail_gpios);
  72. if (ret < 0) {
  73. dev_err(&pdev->dev, "could not read list of GPIOs\n");
  74. return ret;
  75. }
  76. pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL);
  77. pins = devm_kcalloc(&pdev->dev, num_gpios,
  78. sizeof(struct pinctrl_pin_desc), GFP_KERNEL);
  79. groups = devm_kcalloc(&pdev->dev, num_gpios,
  80. sizeof(struct msm_pingroup), GFP_KERNEL);
  81. names = devm_kcalloc(&pdev->dev, avail_gpios, NAME_SIZE, GFP_KERNEL);
  82. if (!pinctrl || !pins || !groups || !names)
  83. return -ENOMEM;
  84. /*
  85. * Initialize the array. GPIOs not listed in the 'gpios' array
  86. * still need a number, but nothing else.
  87. */
  88. for (i = 0; i < num_gpios; i++) {
  89. pins[i].number = i;
  90. groups[i].pins = &pins[i].number;
  91. }
  92. /* Populate the entries that are meant to be exposed as GPIOs. */
  93. for (i = 0; i < avail_gpios; i++) {
  94. unsigned int gpio = gpios[i];
  95. groups[gpio].npins = 1;
  96. snprintf(names[i], NAME_SIZE, "gpio%u", gpio);
  97. pins[gpio].name = names[i];
  98. groups[gpio].name = names[i];
  99. groups[gpio].ctl_reg = 0x10000 * gpio;
  100. groups[gpio].io_reg = 0x04 + 0x10000 * gpio;
  101. groups[gpio].intr_cfg_reg = 0x08 + 0x10000 * gpio;
  102. groups[gpio].intr_status_reg = 0x0c + 0x10000 * gpio;
  103. groups[gpio].intr_target_reg = 0x08 + 0x10000 * gpio;
  104. groups[gpio].mux_bit = 2;
  105. groups[gpio].pull_bit = 0;
  106. groups[gpio].drv_bit = 6;
  107. groups[gpio].oe_bit = 9;
  108. groups[gpio].in_bit = 0;
  109. groups[gpio].out_bit = 1;
  110. groups[gpio].intr_enable_bit = 0;
  111. groups[gpio].intr_status_bit = 0;
  112. groups[gpio].intr_target_bit = 5;
  113. groups[gpio].intr_target_kpss_val = 1;
  114. groups[gpio].intr_raw_status_bit = 4;
  115. groups[gpio].intr_polarity_bit = 1;
  116. groups[gpio].intr_detection_bit = 2;
  117. groups[gpio].intr_detection_width = 2;
  118. }
  119. pinctrl->pins = pins;
  120. pinctrl->groups = groups;
  121. pinctrl->npins = num_gpios;
  122. pinctrl->ngroups = num_gpios;
  123. pinctrl->ngpios = num_gpios;
  124. return msm_pinctrl_probe(pdev, pinctrl);
  125. }
  126. static const struct acpi_device_id qdf2xxx_acpi_ids[] = {
  127. {"QCOM8002"},
  128. {},
  129. };
  130. MODULE_DEVICE_TABLE(acpi, qdf2xxx_acpi_ids);
  131. static struct platform_driver qdf2xxx_pinctrl_driver = {
  132. .driver = {
  133. .name = "qdf2xxx-pinctrl",
  134. .acpi_match_table = ACPI_PTR(qdf2xxx_acpi_ids),
  135. },
  136. .probe = qdf2xxx_pinctrl_probe,
  137. .remove = msm_pinctrl_remove,
  138. };
  139. static int __init qdf2xxx_pinctrl_init(void)
  140. {
  141. return platform_driver_register(&qdf2xxx_pinctrl_driver);
  142. }
  143. arch_initcall(qdf2xxx_pinctrl_init);
  144. static void __exit qdf2xxx_pinctrl_exit(void)
  145. {
  146. platform_driver_unregister(&qdf2xxx_pinctrl_driver);
  147. }
  148. module_exit(qdf2xxx_pinctrl_exit);
  149. MODULE_DESCRIPTION("Qualcomm Technologies QDF2xxx pin control driver");
  150. MODULE_LICENSE("GPL v2");