2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
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.
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.
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
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.
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/pinctrl/pinctrl.h>
29 #include <linux/acpi.h>
31 #include "pinctrl-msm.h"
33 /* A maximum of 256 allows us to use a u8 array to hold the GPIO numbers */
36 /* maximum size of each gpio name (enough room for "gpioXXX" + null) */
39 static int qdf2xxx_pinctrl_probe(struct platform_device
*pdev
)
41 struct msm_pinctrl_soc_data
*pinctrl
;
42 struct pinctrl_pin_desc
*pins
;
43 struct msm_pingroup
*groups
;
44 char (*names
)[NAME_SIZE
];
47 unsigned int avail_gpios
; /* The number of GPIOs we support */
48 u8 gpios
[MAX_GPIOS
]; /* An array of supported GPIOs */
51 /* Query the number of GPIOs from ACPI */
52 ret
= device_property_read_u32(&pdev
->dev
, "num-gpios", &num_gpios
);
54 dev_err(&pdev
->dev
, "missing 'num-gpios' property\n");
57 if (!num_gpios
|| num_gpios
> MAX_GPIOS
) {
58 dev_err(&pdev
->dev
, "invalid 'num-gpios' property\n");
62 /* The number of GPIOs in the approved list */
63 ret
= device_property_read_u8_array(&pdev
->dev
, "gpios", NULL
, 0);
65 dev_err(&pdev
->dev
, "missing 'gpios' property\n");
69 * The number of available GPIOs should be non-zero, and no
70 * more than the total number of GPIOS.
72 if (!ret
|| ret
> num_gpios
) {
73 dev_err(&pdev
->dev
, "invalid 'gpios' property\n");
78 ret
= device_property_read_u8_array(&pdev
->dev
, "gpios", gpios
,
81 dev_err(&pdev
->dev
, "could not read list of GPIOs\n");
85 pinctrl
= devm_kzalloc(&pdev
->dev
, sizeof(*pinctrl
), GFP_KERNEL
);
86 pins
= devm_kcalloc(&pdev
->dev
, num_gpios
,
87 sizeof(struct pinctrl_pin_desc
), GFP_KERNEL
);
88 groups
= devm_kcalloc(&pdev
->dev
, num_gpios
,
89 sizeof(struct msm_pingroup
), GFP_KERNEL
);
90 names
= devm_kcalloc(&pdev
->dev
, avail_gpios
, NAME_SIZE
, GFP_KERNEL
);
92 if (!pinctrl
|| !pins
|| !groups
|| !names
)
96 * Initialize the array. GPIOs not listed in the 'gpios' array
97 * still need a number, but nothing else.
99 for (i
= 0; i
< num_gpios
; i
++) {
101 groups
[i
].pins
= &pins
[i
].number
;
104 /* Populate the entries that are meant to be exposed as GPIOs. */
105 for (i
= 0; i
< avail_gpios
; i
++) {
106 unsigned int gpio
= gpios
[i
];
108 groups
[gpio
].npins
= 1;
109 snprintf(names
[i
], NAME_SIZE
, "gpio%u", gpio
);
110 pins
[gpio
].name
= names
[i
];
111 groups
[gpio
].name
= names
[i
];
113 groups
[gpio
].ctl_reg
= 0x10000 * gpio
;
114 groups
[gpio
].io_reg
= 0x04 + 0x10000 * gpio
;
115 groups
[gpio
].intr_cfg_reg
= 0x08 + 0x10000 * gpio
;
116 groups
[gpio
].intr_status_reg
= 0x0c + 0x10000 * gpio
;
117 groups
[gpio
].intr_target_reg
= 0x08 + 0x10000 * gpio
;
119 groups
[gpio
].mux_bit
= 2;
120 groups
[gpio
].pull_bit
= 0;
121 groups
[gpio
].drv_bit
= 6;
122 groups
[gpio
].oe_bit
= 9;
123 groups
[gpio
].in_bit
= 0;
124 groups
[gpio
].out_bit
= 1;
125 groups
[gpio
].intr_enable_bit
= 0;
126 groups
[gpio
].intr_status_bit
= 0;
127 groups
[gpio
].intr_target_bit
= 5;
128 groups
[gpio
].intr_target_kpss_val
= 1;
129 groups
[gpio
].intr_raw_status_bit
= 4;
130 groups
[gpio
].intr_polarity_bit
= 1;
131 groups
[gpio
].intr_detection_bit
= 2;
132 groups
[gpio
].intr_detection_width
= 2;
135 pinctrl
->pins
= pins
;
136 pinctrl
->groups
= groups
;
137 pinctrl
->npins
= num_gpios
;
138 pinctrl
->ngroups
= num_gpios
;
139 pinctrl
->ngpios
= num_gpios
;
141 return msm_pinctrl_probe(pdev
, pinctrl
);
144 static const struct acpi_device_id qdf2xxx_acpi_ids
[] = {
148 MODULE_DEVICE_TABLE(acpi
, qdf2xxx_acpi_ids
);
150 static struct platform_driver qdf2xxx_pinctrl_driver
= {
152 .name
= "qdf2xxx-pinctrl",
153 .acpi_match_table
= ACPI_PTR(qdf2xxx_acpi_ids
),
155 .probe
= qdf2xxx_pinctrl_probe
,
156 .remove
= msm_pinctrl_remove
,
159 static int __init
qdf2xxx_pinctrl_init(void)
161 return platform_driver_register(&qdf2xxx_pinctrl_driver
);
163 arch_initcall(qdf2xxx_pinctrl_init
);
165 static void __exit
qdf2xxx_pinctrl_exit(void)
167 platform_driver_unregister(&qdf2xxx_pinctrl_driver
);
169 module_exit(qdf2xxx_pinctrl_exit
);
171 MODULE_DESCRIPTION("Qualcomm Technologies QDF2xxx pin control driver");
172 MODULE_LICENSE("GPL v2");