Lines Matching refs:lradc
96 struct sun4i_lradc_data *lradc = dev_id; in sun4i_lradc_irq() local
99 ints = readl(lradc->base + LRADC_INTS); in sun4i_lradc_irq()
107 input_report_key(lradc->input, lradc->chan0_keycode, 0); in sun4i_lradc_irq()
108 lradc->chan0_keycode = 0; in sun4i_lradc_irq()
111 if ((ints & CHAN0_KEYDOWN_IRQ) && lradc->chan0_keycode == 0) { in sun4i_lradc_irq()
112 val = readl(lradc->base + LRADC_DATA0) & 0x3f; in sun4i_lradc_irq()
113 voltage = val * lradc->vref / 63; in sun4i_lradc_irq()
115 for (i = 0; i < lradc->chan0_map_count; i++) { in sun4i_lradc_irq()
116 diff = abs(lradc->chan0_map[i].voltage - voltage); in sun4i_lradc_irq()
119 keycode = lradc->chan0_map[i].keycode; in sun4i_lradc_irq()
123 lradc->chan0_keycode = keycode; in sun4i_lradc_irq()
124 input_report_key(lradc->input, lradc->chan0_keycode, 1); in sun4i_lradc_irq()
127 input_sync(lradc->input); in sun4i_lradc_irq()
129 writel(ints, lradc->base + LRADC_INTS); in sun4i_lradc_irq()
136 struct sun4i_lradc_data *lradc = input_get_drvdata(dev); in sun4i_lradc_open() local
139 error = regulator_enable(lradc->vref_supply); in sun4i_lradc_open()
143 lradc->vref = regulator_get_voltage(lradc->vref_supply) * in sun4i_lradc_open()
144 lradc->variant->divisor_numerator / in sun4i_lradc_open()
145 lradc->variant->divisor_denominator; in sun4i_lradc_open()
151 SAMPLE_RATE(0) | ENABLE(1), lradc->base + LRADC_CTRL); in sun4i_lradc_open()
153 writel(CHAN0_KEYUP_IRQ | CHAN0_KEYDOWN_IRQ, lradc->base + LRADC_INTC); in sun4i_lradc_open()
160 struct sun4i_lradc_data *lradc = input_get_drvdata(dev); in sun4i_lradc_close() local
164 SAMPLE_RATE(2), lradc->base + LRADC_CTRL); in sun4i_lradc_close()
165 writel(0, lradc->base + LRADC_INTC); in sun4i_lradc_close()
167 regulator_disable(lradc->vref_supply); in sun4i_lradc_close()
171 struct sun4i_lradc_data *lradc) in sun4i_lradc_load_dt_keymap() argument
181 lradc->chan0_map_count = of_get_child_count(np); in sun4i_lradc_load_dt_keymap()
182 if (lradc->chan0_map_count == 0) { in sun4i_lradc_load_dt_keymap()
187 lradc->chan0_map = devm_kmalloc_array(dev, lradc->chan0_map_count, in sun4i_lradc_load_dt_keymap()
190 if (!lradc->chan0_map) in sun4i_lradc_load_dt_keymap()
195 struct sun4i_lradc_keymap *map = &lradc->chan0_map[i]; in sun4i_lradc_load_dt_keymap()
227 struct sun4i_lradc_data *lradc; in sun4i_lradc_probe() local
232 lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL); in sun4i_lradc_probe()
233 if (!lradc) in sun4i_lradc_probe()
236 error = sun4i_lradc_load_dt_keymap(dev, lradc); in sun4i_lradc_probe()
240 lradc->variant = of_device_get_match_data(&pdev->dev); in sun4i_lradc_probe()
241 if (!lradc->variant) { in sun4i_lradc_probe()
246 lradc->vref_supply = devm_regulator_get(dev, "vref"); in sun4i_lradc_probe()
247 if (IS_ERR(lradc->vref_supply)) in sun4i_lradc_probe()
248 return PTR_ERR(lradc->vref_supply); in sun4i_lradc_probe()
250 lradc->dev = dev; in sun4i_lradc_probe()
251 lradc->input = devm_input_allocate_device(dev); in sun4i_lradc_probe()
252 if (!lradc->input) in sun4i_lradc_probe()
255 lradc->input->name = pdev->name; in sun4i_lradc_probe()
256 lradc->input->phys = "sun4i_lradc/input0"; in sun4i_lradc_probe()
257 lradc->input->open = sun4i_lradc_open; in sun4i_lradc_probe()
258 lradc->input->close = sun4i_lradc_close; in sun4i_lradc_probe()
259 lradc->input->id.bustype = BUS_HOST; in sun4i_lradc_probe()
260 lradc->input->id.vendor = 0x0001; in sun4i_lradc_probe()
261 lradc->input->id.product = 0x0001; in sun4i_lradc_probe()
262 lradc->input->id.version = 0x0100; in sun4i_lradc_probe()
264 __set_bit(EV_KEY, lradc->input->evbit); in sun4i_lradc_probe()
265 for (i = 0; i < lradc->chan0_map_count; i++) in sun4i_lradc_probe()
266 __set_bit(lradc->chan0_map[i].keycode, lradc->input->keybit); in sun4i_lradc_probe()
268 input_set_drvdata(lradc->input, lradc); in sun4i_lradc_probe()
270 lradc->base = devm_ioremap_resource(dev, in sun4i_lradc_probe()
272 if (IS_ERR(lradc->base)) in sun4i_lradc_probe()
273 return PTR_ERR(lradc->base); in sun4i_lradc_probe()
277 "sun4i-a10-lradc-keys", lradc); in sun4i_lradc_probe()
281 error = input_register_device(lradc->input); in sun4i_lradc_probe()