Lines Matching +full:adc +full:- +full:use +full:- +full:res

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Allwinner sun4i low res adc attached tablet keys driver
14 * there are no boards known to use channel 1.
63 /* struct lradc_variant - Describe sun4i-a10-lradc-keys hardware variant
114 ints = readl(lradc->base + LRADC_INTS); in sun4i_lradc_irq()
122 input_report_key(lradc->input, lradc->chan0_keycode, 0); in sun4i_lradc_irq()
123 lradc->chan0_keycode = 0; in sun4i_lradc_irq()
126 if ((ints & CHAN0_KEYDOWN_IRQ) && lradc->chan0_keycode == 0) { in sun4i_lradc_irq()
127 val = readl(lradc->base + LRADC_DATA0) & 0x3f; in sun4i_lradc_irq()
128 voltage = val * lradc->vref / 63; in sun4i_lradc_irq()
130 for (i = 0; i < lradc->chan0_map_count; i++) { in sun4i_lradc_irq()
131 diff = abs(lradc->chan0_map[i].voltage - voltage); in sun4i_lradc_irq()
134 keycode = lradc->chan0_map[i].keycode; in sun4i_lradc_irq()
138 lradc->chan0_keycode = keycode; in sun4i_lradc_irq()
139 input_report_key(lradc->input, lradc->chan0_keycode, 1); in sun4i_lradc_irq()
142 input_sync(lradc->input); in sun4i_lradc_irq()
144 writel(ints, lradc->base + LRADC_INTS); in sun4i_lradc_irq()
154 error = regulator_enable(lradc->vref_supply); in sun4i_lradc_open()
158 error = reset_control_deassert(lradc->reset); in sun4i_lradc_open()
162 error = clk_prepare_enable(lradc->clk); in sun4i_lradc_open()
166 lradc->vref = regulator_get_voltage(lradc->vref_supply) * in sun4i_lradc_open()
167 lradc->variant->divisor_numerator / in sun4i_lradc_open()
168 lradc->variant->divisor_denominator; in sun4i_lradc_open()
174 SAMPLE_RATE(0) | ENABLE(1), lradc->base + LRADC_CTRL); in sun4i_lradc_open()
176 writel(CHAN0_KEYUP_IRQ | CHAN0_KEYDOWN_IRQ, lradc->base + LRADC_INTC); in sun4i_lradc_open()
181 reset_control_assert(lradc->reset); in sun4i_lradc_open()
183 regulator_disable(lradc->vref_supply); in sun4i_lradc_open()
194 SAMPLE_RATE(2), lradc->base + LRADC_CTRL); in sun4i_lradc_close()
195 writel(0, lradc->base + LRADC_INTC); in sun4i_lradc_close()
197 clk_disable_unprepare(lradc->clk); in sun4i_lradc_close()
198 reset_control_assert(lradc->reset); in sun4i_lradc_close()
199 regulator_disable(lradc->vref_supply); in sun4i_lradc_close()
209 np = dev->of_node; in sun4i_lradc_load_dt_keymap()
211 return -EINVAL; in sun4i_lradc_load_dt_keymap()
213 lradc->chan0_map_count = of_get_child_count(np); in sun4i_lradc_load_dt_keymap()
214 if (lradc->chan0_map_count == 0) { in sun4i_lradc_load_dt_keymap()
216 return -EINVAL; in sun4i_lradc_load_dt_keymap()
219 lradc->chan0_map = devm_kmalloc_array(dev, lradc->chan0_map_count, in sun4i_lradc_load_dt_keymap()
222 if (!lradc->chan0_map) in sun4i_lradc_load_dt_keymap()
223 return -ENOMEM; in sun4i_lradc_load_dt_keymap()
227 struct sun4i_lradc_keymap *map = &lradc->chan0_map[i]; in sun4i_lradc_load_dt_keymap()
234 return -EINVAL; in sun4i_lradc_load_dt_keymap()
237 error = of_property_read_u32(pp, "voltage", &map->voltage); in sun4i_lradc_load_dt_keymap()
241 return -EINVAL; in sun4i_lradc_load_dt_keymap()
244 error = of_property_read_u32(pp, "linux,code", &map->keycode); in sun4i_lradc_load_dt_keymap()
248 return -EINVAL; in sun4i_lradc_load_dt_keymap()
260 struct device *dev = &pdev->dev; in sun4i_lradc_probe()
265 return -ENOMEM; in sun4i_lradc_probe()
271 lradc->variant = of_device_get_match_data(&pdev->dev); in sun4i_lradc_probe()
272 if (!lradc->variant) { in sun4i_lradc_probe()
273 dev_err(&pdev->dev, "Missing sun4i-a10-lradc-keys variant\n"); in sun4i_lradc_probe()
274 return -EINVAL; in sun4i_lradc_probe()
277 if (lradc->variant->has_clock_reset) { in sun4i_lradc_probe()
278 lradc->clk = devm_clk_get(dev, NULL); in sun4i_lradc_probe()
279 if (IS_ERR(lradc->clk)) in sun4i_lradc_probe()
280 return PTR_ERR(lradc->clk); in sun4i_lradc_probe()
282 lradc->reset = devm_reset_control_get_exclusive(dev, NULL); in sun4i_lradc_probe()
283 if (IS_ERR(lradc->reset)) in sun4i_lradc_probe()
284 return PTR_ERR(lradc->reset); in sun4i_lradc_probe()
287 lradc->vref_supply = devm_regulator_get(dev, "vref"); in sun4i_lradc_probe()
288 if (IS_ERR(lradc->vref_supply)) in sun4i_lradc_probe()
289 return PTR_ERR(lradc->vref_supply); in sun4i_lradc_probe()
291 lradc->dev = dev; in sun4i_lradc_probe()
292 lradc->input = devm_input_allocate_device(dev); in sun4i_lradc_probe()
293 if (!lradc->input) in sun4i_lradc_probe()
294 return -ENOMEM; in sun4i_lradc_probe()
296 lradc->input->name = pdev->name; in sun4i_lradc_probe()
297 lradc->input->phys = "sun4i_lradc/input0"; in sun4i_lradc_probe()
298 lradc->input->open = sun4i_lradc_open; in sun4i_lradc_probe()
299 lradc->input->close = sun4i_lradc_close; in sun4i_lradc_probe()
300 lradc->input->id.bustype = BUS_HOST; in sun4i_lradc_probe()
301 lradc->input->id.vendor = 0x0001; in sun4i_lradc_probe()
302 lradc->input->id.product = 0x0001; in sun4i_lradc_probe()
303 lradc->input->id.version = 0x0100; in sun4i_lradc_probe()
305 __set_bit(EV_KEY, lradc->input->evbit); in sun4i_lradc_probe()
306 for (i = 0; i < lradc->chan0_map_count; i++) in sun4i_lradc_probe()
307 __set_bit(lradc->chan0_map[i].keycode, lradc->input->keybit); in sun4i_lradc_probe()
309 input_set_drvdata(lradc->input, lradc); in sun4i_lradc_probe()
311 lradc->base = devm_platform_ioremap_resource(pdev, 0); in sun4i_lradc_probe()
312 if (IS_ERR(lradc->base)) in sun4i_lradc_probe()
313 return PTR_ERR(lradc->base); in sun4i_lradc_probe()
320 "sun4i-a10-lradc-keys", lradc); in sun4i_lradc_probe()
324 error = input_register_device(lradc->input); in sun4i_lradc_probe()
328 if (device_property_read_bool(dev, "wakeup-source")) { in sun4i_lradc_probe()
342 { .compatible = "allwinner,sun4i-a10-lradc-keys",
344 { .compatible = "allwinner,sun8i-a83t-r-lradc",
346 { .compatible = "allwinner,sun50i-r329-lradc",
354 .name = "sun4i-a10-lradc-keys",
362 MODULE_DESCRIPTION("Allwinner sun4i low res adc attached tablet keys driver");