1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
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
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.
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/pinctrl/pinctrl.h>
21 #include <linux/acpi.h>
23 #include "pinctrl-msm.h"
25 /* A maximum of 256 allows us to use a u8 array to hold the GPIO numbers */
28 /* maximum size of each gpio name (enough room for "gpioXXX" + null) */
31 static int qdf2xxx_pinctrl_probe(struct platform_device
*pdev
)
33 struct msm_pinctrl_soc_data
*pinctrl
;
34 struct pinctrl_pin_desc
*pins
;
35 struct msm_pingroup
*groups
;
36 char (*names
)[NAME_SIZE
];
39 unsigned int avail_gpios
; /* The number of GPIOs we support */
40 u8 gpios
[MAX_GPIOS
]; /* An array of supported GPIOs */
43 /* Query the number of GPIOs from ACPI */
44 ret
= device_property_read_u32(&pdev
->dev
, "num-gpios", &num_gpios
);
46 dev_err(&pdev
->dev
, "missing 'num-gpios' property\n");
49 if (!num_gpios
|| num_gpios
> MAX_GPIOS
) {
50 dev_err(&pdev
->dev
, "invalid 'num-gpios' property\n");
54 /* The number of GPIOs in the approved list */
55 ret
= device_property_count_u8(&pdev
->dev
, "gpios");
57 dev_err(&pdev
->dev
, "missing 'gpios' property\n");
61 * The number of available GPIOs should be non-zero, and no
62 * more than the total number of GPIOS.
64 if (!ret
|| ret
> num_gpios
) {
65 dev_err(&pdev
->dev
, "invalid 'gpios' property\n");
70 ret
= device_property_read_u8_array(&pdev
->dev
, "gpios", gpios
,
73 dev_err(&pdev
->dev
, "could not read list of GPIOs\n");
77 pinctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pinctrl
), GFP_KERNEL
);
78 pins
= devm_kcalloc(&pdev
->dev
, num_gpios
,
79 sizeof(struct pinctrl_pin_desc
), GFP_KERNEL
);
80 groups
= devm_kcalloc(&pdev
->dev
, num_gpios
,
81 sizeof(struct msm_pingroup
), GFP_KERNEL
);
82 names
= devm_kcalloc(&pdev
->dev
, avail_gpios
, NAME_SIZE
, GFP_KERNEL
);
84 if (!pinctrl
|| !pins
|| !groups
|| !names
)
88 * Initialize the array. GPIOs not listed in the 'gpios' array
89 * still need a number, but nothing else.
91 for (i
= 0; i
< num_gpios
; i
++) {
93 groups
[i
].pins
= &pins
[i
].number
;
96 /* Populate the entries that are meant to be exposed as GPIOs. */
97 for (i
= 0; i
< avail_gpios
; i
++) {
98 unsigned int gpio
= gpios
[i
];
100 groups
[gpio
].npins
= 1;
101 snprintf(names
[i
], NAME_SIZE
, "gpio%u", gpio
);
102 pins
[gpio
].name
= names
[i
];
103 groups
[gpio
].name
= names
[i
];
105 groups
[gpio
].ctl_reg
= 0x10000 * gpio
;
106 groups
[gpio
].io_reg
= 0x04 + 0x10000 * gpio
;
107 groups
[gpio
].intr_cfg_reg
= 0x08 + 0x10000 * gpio
;
108 groups
[gpio
].intr_status_reg
= 0x0c + 0x10000 * gpio
;
109 groups
[gpio
].intr_target_reg
= 0x08 + 0x10000 * gpio
;
111 groups
[gpio
].mux_bit
= 2;
112 groups
[gpio
].pull_bit
= 0;
113 groups
[gpio
].drv_bit
= 6;
114 groups
[gpio
].oe_bit
= 9;
115 groups
[gpio
].in_bit
= 0;
116 groups
[gpio
].out_bit
= 1;
117 groups
[gpio
].intr_enable_bit
= 0;
118 groups
[gpio
].intr_status_bit
= 0;
119 groups
[gpio
].intr_target_bit
= 5;
120 groups
[gpio
].intr_target_kpss_val
= 1;
121 groups
[gpio
].intr_raw_status_bit
= 4;
122 groups
[gpio
].intr_polarity_bit
= 1;
123 groups
[gpio
].intr_detection_bit
= 2;
124 groups
[gpio
].intr_detection_width
= 2;
127 pinctrl
->pins
= pins
;
128 pinctrl
->groups
= groups
;
129 pinctrl
->npins
= num_gpios
;
130 pinctrl
->ngroups
= num_gpios
;
131 pinctrl
->ngpios
= num_gpios
;
133 return msm_pinctrl_probe(pdev
, pinctrl
);
136 static const struct acpi_device_id qdf2xxx_acpi_ids
[] = {
140 MODULE_DEVICE_TABLE(acpi
, qdf2xxx_acpi_ids
);
142 static struct platform_driver qdf2xxx_pinctrl_driver
= {
144 .name
= "qdf2xxx-pinctrl",
145 .acpi_match_table
= ACPI_PTR(qdf2xxx_acpi_ids
),
147 .probe
= qdf2xxx_pinctrl_probe
,
148 .remove
= msm_pinctrl_remove
,
151 static int __init
qdf2xxx_pinctrl_init(void)
153 return platform_driver_register(&qdf2xxx_pinctrl_driver
);
155 arch_initcall(qdf2xxx_pinctrl_init
);
157 static void __exit
qdf2xxx_pinctrl_exit(void)
159 platform_driver_unregister(&qdf2xxx_pinctrl_driver
);
161 module_exit(qdf2xxx_pinctrl_exit
);
163 MODULE_DESCRIPTION("Qualcomm Technologies QDF2xxx pin control driver");
164 MODULE_LICENSE("GPL v2");