pinctrl-qdf2xxx.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. static struct msm_pinctrl_soc_data qdf2xxx_pinctrl;
  31. /* A reasonable limit to the number of GPIOS */
  32. #define MAX_GPIOS 256
  33. static int qdf2xxx_pinctrl_probe(struct platform_device *pdev)
  34. {
  35. struct pinctrl_pin_desc *pins;
  36. struct msm_pingroup *groups;
  37. unsigned int i;
  38. u32 num_gpios;
  39. int ret;
  40. /* Query the number of GPIOs from ACPI */
  41. ret = device_property_read_u32(&pdev->dev, "num-gpios", &num_gpios);
  42. if (ret < 0) {
  43. dev_warn(&pdev->dev, "missing num-gpios property\n");
  44. return ret;
  45. }
  46. if (!num_gpios || num_gpios > MAX_GPIOS) {
  47. dev_warn(&pdev->dev, "invalid num-gpios property\n");
  48. return -ENODEV;
  49. }
  50. pins = devm_kcalloc(&pdev->dev, num_gpios,
  51. sizeof(struct pinctrl_pin_desc), GFP_KERNEL);
  52. groups = devm_kcalloc(&pdev->dev, num_gpios,
  53. sizeof(struct msm_pingroup), GFP_KERNEL);
  54. if (!pins || !groups)
  55. return -ENOMEM;
  56. for (i = 0; i < num_gpios; i++) {
  57. pins[i].number = i;
  58. groups[i].npins = 1,
  59. groups[i].pins = &pins[i].number;
  60. groups[i].ctl_reg = 0x10000 * i;
  61. groups[i].io_reg = 0x04 + 0x10000 * i;
  62. groups[i].intr_cfg_reg = 0x08 + 0x10000 * i;
  63. groups[i].intr_status_reg = 0x0c + 0x10000 * i;
  64. groups[i].intr_target_reg = 0x08 + 0x10000 * i;
  65. groups[i].mux_bit = 2;
  66. groups[i].pull_bit = 0;
  67. groups[i].drv_bit = 6;
  68. groups[i].oe_bit = 9;
  69. groups[i].in_bit = 0;
  70. groups[i].out_bit = 1;
  71. groups[i].intr_enable_bit = 0;
  72. groups[i].intr_status_bit = 0;
  73. groups[i].intr_target_bit = 5;
  74. groups[i].intr_target_kpss_val = 1;
  75. groups[i].intr_raw_status_bit = 4;
  76. groups[i].intr_polarity_bit = 1;
  77. groups[i].intr_detection_bit = 2;
  78. groups[i].intr_detection_width = 2;
  79. }
  80. qdf2xxx_pinctrl.pins = pins;
  81. qdf2xxx_pinctrl.groups = groups;
  82. qdf2xxx_pinctrl.npins = num_gpios;
  83. qdf2xxx_pinctrl.ngroups = num_gpios;
  84. qdf2xxx_pinctrl.ngpios = num_gpios;
  85. return msm_pinctrl_probe(pdev, &qdf2xxx_pinctrl);
  86. }
  87. static const struct acpi_device_id qdf2xxx_acpi_ids[] = {
  88. {"QCOM8001"},
  89. {},
  90. };
  91. MODULE_DEVICE_TABLE(acpi, qdf2xxx_acpi_ids);
  92. static struct platform_driver qdf2xxx_pinctrl_driver = {
  93. .driver = {
  94. .name = "qdf2xxx-pinctrl",
  95. .acpi_match_table = ACPI_PTR(qdf2xxx_acpi_ids),
  96. },
  97. .probe = qdf2xxx_pinctrl_probe,
  98. .remove = msm_pinctrl_remove,
  99. };
  100. static int __init qdf2xxx_pinctrl_init(void)
  101. {
  102. return platform_driver_register(&qdf2xxx_pinctrl_driver);
  103. }
  104. arch_initcall(qdf2xxx_pinctrl_init);
  105. static void __exit qdf2xxx_pinctrl_exit(void)
  106. {
  107. platform_driver_unregister(&qdf2xxx_pinctrl_driver);
  108. }
  109. module_exit(qdf2xxx_pinctrl_exit);
  110. MODULE_DESCRIPTION("Qualcomm Technologies QDF2xxx pin control driver");
  111. MODULE_LICENSE("GPL v2");