hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/keyboard/sun4i-lradc-keys.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Allwinner sun4i low res adc attached tablet keys driver
34 *
45 * Copyright (C) 2014 Hans de Goede <hdegoede@redhat.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167
178 /*
....@@ -46,6 +37,7 @@
4637 #define CONTINUE_TIME_SEL(x) ((x) << 16) /* 4 bits */
4738 #define KEY_MODE_SEL(x) ((x) << 12) /* 2 bits */
4839 #define LEVELA_B_CNT(x) ((x) << 8) /* 4 bits */
40
+#define HOLD_KEY_EN(x) ((x) << 7)
4941 #define HOLD_EN(x) ((x) << 6)
5042 #define LEVELB_VOL(x) ((x) << 4) /* 2 bits */
5143 #define SAMPLE_RATE(x) ((x) << 2) /* 2 bits */
....@@ -63,6 +55,25 @@
6355 #define CHAN0_KEYDOWN_IRQ BIT(1)
6456 #define CHAN0_DATA_IRQ BIT(0)
6557
58
+/* struct lradc_variant - Describe sun4i-a10-lradc-keys hardware variant
59
+ * @divisor_numerator: The numerator of lradc Vref internally divisor
60
+ * @divisor_denominator: The denominator of lradc Vref internally divisor
61
+ */
62
+struct lradc_variant {
63
+ u8 divisor_numerator;
64
+ u8 divisor_denominator;
65
+};
66
+
67
+static const struct lradc_variant lradc_variant_a10 = {
68
+ .divisor_numerator = 2,
69
+ .divisor_denominator = 3
70
+};
71
+
72
+static const struct lradc_variant r_lradc_variant_a83t = {
73
+ .divisor_numerator = 3,
74
+ .divisor_denominator = 4
75
+};
76
+
6677 struct sun4i_lradc_keymap {
6778 u32 voltage;
6879 u32 keycode;
....@@ -74,6 +85,7 @@
7485 void __iomem *base;
7586 struct regulator *vref_supply;
7687 struct sun4i_lradc_keymap *chan0_map;
88
+ const struct lradc_variant *variant;
7789 u32 chan0_map_count;
7890 u32 chan0_keycode;
7991 u32 vref;
....@@ -128,9 +140,9 @@
128140 if (error)
129141 return error;
130142
131
- /* lradc Vref internally is divided by 2/3 */
132
- lradc->vref = regulator_get_voltage(lradc->vref_supply) * 2 / 3;
133
-
143
+ lradc->vref = regulator_get_voltage(lradc->vref_supply) *
144
+ lradc->variant->divisor_numerator /
145
+ lradc->variant->divisor_denominator;
134146 /*
135147 * Set sample time to 4 ms / 250 Hz. Wait 2 * 4 ms for key to
136148 * stabilize on press, wait (1 + 1) * 4 ms for key release
....@@ -185,19 +197,22 @@
185197
186198 error = of_property_read_u32(pp, "channel", &channel);
187199 if (error || channel != 0) {
188
- dev_err(dev, "%s: Inval channel prop\n", pp->name);
200
+ dev_err(dev, "%pOFn: Inval channel prop\n", pp);
201
+ of_node_put(pp);
189202 return -EINVAL;
190203 }
191204
192205 error = of_property_read_u32(pp, "voltage", &map->voltage);
193206 if (error) {
194
- dev_err(dev, "%s: Inval voltage prop\n", pp->name);
207
+ dev_err(dev, "%pOFn: Inval voltage prop\n", pp);
208
+ of_node_put(pp);
195209 return -EINVAL;
196210 }
197211
198212 error = of_property_read_u32(pp, "linux,code", &map->keycode);
199213 if (error) {
200
- dev_err(dev, "%s: Inval linux,code prop\n", pp->name);
214
+ dev_err(dev, "%pOFn: Inval linux,code prop\n", pp);
215
+ of_node_put(pp);
201216 return -EINVAL;
202217 }
203218
....@@ -221,6 +236,12 @@
221236 error = sun4i_lradc_load_dt_keymap(dev, lradc);
222237 if (error)
223238 return error;
239
+
240
+ lradc->variant = of_device_get_match_data(&pdev->dev);
241
+ if (!lradc->variant) {
242
+ dev_err(&pdev->dev, "Missing sun4i-a10-lradc-keys variant\n");
243
+ return -EINVAL;
244
+ }
224245
225246 lradc->vref_supply = devm_regulator_get(dev, "vref");
226247 if (IS_ERR(lradc->vref_supply))
....@@ -265,7 +286,10 @@
265286 }
266287
267288 static const struct of_device_id sun4i_lradc_of_match[] = {
268
- { .compatible = "allwinner,sun4i-a10-lradc-keys", },
289
+ { .compatible = "allwinner,sun4i-a10-lradc-keys",
290
+ .data = &lradc_variant_a10 },
291
+ { .compatible = "allwinner,sun8i-a83t-r-lradc",
292
+ .data = &r_lradc_variant_a83t },
269293 { /* sentinel */ }
270294 };
271295 MODULE_DEVICE_TABLE(of, sun4i_lradc_of_match);