pinctrl-qdf2xxx.c 4.8 KB

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