.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Allwinner sun4i low res adc attached tablet keys driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
15 | 6 | */ |
---|
16 | 7 | |
---|
17 | 8 | /* |
---|
.. | .. |
---|
46 | 37 | #define CONTINUE_TIME_SEL(x) ((x) << 16) /* 4 bits */ |
---|
47 | 38 | #define KEY_MODE_SEL(x) ((x) << 12) /* 2 bits */ |
---|
48 | 39 | #define LEVELA_B_CNT(x) ((x) << 8) /* 4 bits */ |
---|
| 40 | +#define HOLD_KEY_EN(x) ((x) << 7) |
---|
49 | 41 | #define HOLD_EN(x) ((x) << 6) |
---|
50 | 42 | #define LEVELB_VOL(x) ((x) << 4) /* 2 bits */ |
---|
51 | 43 | #define SAMPLE_RATE(x) ((x) << 2) /* 2 bits */ |
---|
.. | .. |
---|
63 | 55 | #define CHAN0_KEYDOWN_IRQ BIT(1) |
---|
64 | 56 | #define CHAN0_DATA_IRQ BIT(0) |
---|
65 | 57 | |
---|
| 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 | + |
---|
66 | 77 | struct sun4i_lradc_keymap { |
---|
67 | 78 | u32 voltage; |
---|
68 | 79 | u32 keycode; |
---|
.. | .. |
---|
74 | 85 | void __iomem *base; |
---|
75 | 86 | struct regulator *vref_supply; |
---|
76 | 87 | struct sun4i_lradc_keymap *chan0_map; |
---|
| 88 | + const struct lradc_variant *variant; |
---|
77 | 89 | u32 chan0_map_count; |
---|
78 | 90 | u32 chan0_keycode; |
---|
79 | 91 | u32 vref; |
---|
.. | .. |
---|
128 | 140 | if (error) |
---|
129 | 141 | return error; |
---|
130 | 142 | |
---|
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; |
---|
134 | 146 | /* |
---|
135 | 147 | * Set sample time to 4 ms / 250 Hz. Wait 2 * 4 ms for key to |
---|
136 | 148 | * stabilize on press, wait (1 + 1) * 4 ms for key release |
---|
.. | .. |
---|
185 | 197 | |
---|
186 | 198 | error = of_property_read_u32(pp, "channel", &channel); |
---|
187 | 199 | 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); |
---|
189 | 202 | return -EINVAL; |
---|
190 | 203 | } |
---|
191 | 204 | |
---|
192 | 205 | error = of_property_read_u32(pp, "voltage", &map->voltage); |
---|
193 | 206 | 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); |
---|
195 | 209 | return -EINVAL; |
---|
196 | 210 | } |
---|
197 | 211 | |
---|
198 | 212 | error = of_property_read_u32(pp, "linux,code", &map->keycode); |
---|
199 | 213 | 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); |
---|
201 | 216 | return -EINVAL; |
---|
202 | 217 | } |
---|
203 | 218 | |
---|
.. | .. |
---|
221 | 236 | error = sun4i_lradc_load_dt_keymap(dev, lradc); |
---|
222 | 237 | if (error) |
---|
223 | 238 | 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 | + } |
---|
224 | 245 | |
---|
225 | 246 | lradc->vref_supply = devm_regulator_get(dev, "vref"); |
---|
226 | 247 | if (IS_ERR(lradc->vref_supply)) |
---|
.. | .. |
---|
265 | 286 | } |
---|
266 | 287 | |
---|
267 | 288 | 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 }, |
---|
269 | 293 | { /* sentinel */ } |
---|
270 | 294 | }; |
---|
271 | 295 | MODULE_DEVICE_TABLE(of, sun4i_lradc_of_match); |
---|