Lines Matching +full:coordinate +full:- +full:readouts
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/
33 spin_lock_irqsave(&tscadc->reg_lock, flags); in am335x_tsc_se_set_cache()
34 tscadc->reg_se_cache |= val; in am335x_tsc_se_set_cache()
35 if (tscadc->adc_waiting) in am335x_tsc_se_set_cache()
36 wake_up(&tscadc->reg_se_wait); in am335x_tsc_se_set_cache()
37 else if (!tscadc->adc_in_use) in am335x_tsc_se_set_cache()
38 regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); in am335x_tsc_se_set_cache()
40 spin_unlock_irqrestore(&tscadc->reg_lock, flags); in am335x_tsc_se_set_cache()
49 regmap_read(tscadc->regmap, REG_ADCFSM, ®); in am335x_tscadc_need_adc()
51 tscadc->adc_waiting = true; in am335x_tscadc_need_adc()
52 prepare_to_wait(&tscadc->reg_se_wait, &wait, in am335x_tscadc_need_adc()
54 spin_unlock_irq(&tscadc->reg_lock); in am335x_tscadc_need_adc()
58 spin_lock_irq(&tscadc->reg_lock); in am335x_tscadc_need_adc()
59 finish_wait(&tscadc->reg_se_wait, &wait); in am335x_tscadc_need_adc()
65 regmap_read(tscadc->regmap, REG_ADCFSM, ®); in am335x_tscadc_need_adc()
67 tscadc->adc_waiting = false; in am335x_tscadc_need_adc()
69 tscadc->adc_in_use = true; in am335x_tscadc_need_adc()
74 spin_lock_irq(&tscadc->reg_lock); in am335x_tsc_se_set_once()
77 regmap_write(tscadc->regmap, REG_SE, val); in am335x_tsc_se_set_once()
78 spin_unlock_irq(&tscadc->reg_lock); in am335x_tsc_se_set_once()
86 spin_lock_irqsave(&tscadc->reg_lock, flags); in am335x_tsc_se_adc_done()
87 tscadc->adc_in_use = false; in am335x_tsc_se_adc_done()
88 regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); in am335x_tsc_se_adc_done()
89 spin_unlock_irqrestore(&tscadc->reg_lock, flags); in am335x_tsc_se_adc_done()
97 spin_lock_irqsave(&tscadc->reg_lock, flags); in am335x_tsc_se_clr()
98 tscadc->reg_se_cache &= ~val; in am335x_tsc_se_clr()
99 regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); in am335x_tsc_se_clr()
100 spin_unlock_irqrestore(&tscadc->reg_lock, flags); in am335x_tsc_se_clr()
112 regmap_write(tscadc->regmap, REG_IDLECONFIG, idleconfig); in tscadc_idle_config()
128 int readouts = 0, mag_tracks = 0; in ti_tscadc_probe() local
131 tscadc = devm_kzalloc(&pdev->dev, sizeof(*tscadc), GFP_KERNEL); in ti_tscadc_probe()
133 return -ENOMEM; in ti_tscadc_probe()
135 tscadc->dev = &pdev->dev; in ti_tscadc_probe()
137 if (!pdev->dev.of_node) { in ti_tscadc_probe()
138 dev_err(&pdev->dev, "Could not find valid DT data.\n"); in ti_tscadc_probe()
139 return -EINVAL; in ti_tscadc_probe()
142 tscadc->data = of_device_get_match_data(&pdev->dev); in ti_tscadc_probe()
145 node = of_get_child_by_name(pdev->dev.of_node, "tsc"); in ti_tscadc_probe()
147 err = of_property_read_u32(node, "ti,coordinate-readouts", in ti_tscadc_probe()
148 &readouts); in ti_tscadc_probe()
150 of_property_read_u32(node, "ti,coordiante-readouts", in ti_tscadc_probe()
151 &readouts); in ti_tscadc_probe()
169 node = of_get_child_by_name(pdev->dev.of_node, "adc"); in ti_tscadc_probe()
170 of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) { in ti_tscadc_probe()
173 dev_err(&pdev->dev, " PIN numbers are 0..7 (not %d)\n", in ti_tscadc_probe()
176 return -EINVAL; in ti_tscadc_probe()
184 dev_err(&pdev->dev, "Number of i/p channels more than 8\n"); in ti_tscadc_probe()
185 return -EINVAL; in ti_tscadc_probe()
189 dev_err(&pdev->dev, "Need at least one channel.\n"); in ti_tscadc_probe()
190 return -EINVAL; in ti_tscadc_probe()
193 if (use_tsc && (readouts * 2 + 2 + adc_channels > 16)) { in ti_tscadc_probe()
194 dev_err(&pdev->dev, "Too many step configurations requested\n"); in ti_tscadc_probe()
195 return -EINVAL; in ti_tscadc_probe()
202 tscadc->irq = err; in ti_tscadc_probe()
204 tscadc->tscadc_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in ti_tscadc_probe()
205 if (IS_ERR(tscadc->tscadc_base)) in ti_tscadc_probe()
206 return PTR_ERR(tscadc->tscadc_base); in ti_tscadc_probe()
208 tscadc->tscadc_phys_base = res->start; in ti_tscadc_probe()
209 tscadc->regmap = devm_regmap_init_mmio(&pdev->dev, in ti_tscadc_probe()
210 tscadc->tscadc_base, in ti_tscadc_probe()
212 if (IS_ERR(tscadc->regmap)) { in ti_tscadc_probe()
213 dev_err(&pdev->dev, "regmap init failed\n"); in ti_tscadc_probe()
214 return PTR_ERR(tscadc->regmap); in ti_tscadc_probe()
217 spin_lock_init(&tscadc->reg_lock); in ti_tscadc_probe()
218 init_waitqueue_head(&tscadc->reg_se_wait); in ti_tscadc_probe()
220 pm_runtime_enable(&pdev->dev); in ti_tscadc_probe()
221 pm_runtime_get_sync(&pdev->dev); in ti_tscadc_probe()
225 * ADCs produce a 12-bit sample every 15 ADC_CLK cycles. in ti_tscadc_probe()
232 clk = devm_clk_get(&pdev->dev, NULL); in ti_tscadc_probe()
234 dev_err(&pdev->dev, "failed to get fck\n"); in ti_tscadc_probe()
239 tscadc->clk_div = (clk_get_rate(clk) / tscadc->data->target_clk_rate) - 1; in ti_tscadc_probe()
240 regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div); in ti_tscadc_probe()
243 * Set the control register bits. tscadc->ctrl stores the configuration in ti_tscadc_probe()
247 tscadc->ctrl = CNTRLREG_STEPID; in ti_tscadc_probe()
249 tscadc->ctrl |= CNTRLREG_TSC_STEPCONFIGWRT; in ti_tscadc_probe()
251 tscadc->ctrl |= CNTRLREG_TSC_ENB; in ti_tscadc_probe()
253 tscadc->ctrl |= CNTRLREG_TSC_5WIRE; in ti_tscadc_probe()
255 tscadc->ctrl |= CNTRLREG_TSC_4WIRE; in ti_tscadc_probe()
258 tscadc->ctrl |= CNTRLREG_MAG_PREAMP_PWRDOWN | in ti_tscadc_probe()
261 regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl); in ti_tscadc_probe()
266 regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl | CNTRLREG_SSENB); in ti_tscadc_probe()
270 cell = &tscadc->cells[cell_idx++]; in ti_tscadc_probe()
271 cell->name = tscadc->data->secondary_feature_name; in ti_tscadc_probe()
272 cell->of_compatible = tscadc->data->secondary_feature_compatible; in ti_tscadc_probe()
273 cell->platform_data = &tscadc; in ti_tscadc_probe()
274 cell->pdata_size = sizeof(tscadc); in ti_tscadc_probe()
279 cell = &tscadc->cells[cell_idx++]; in ti_tscadc_probe()
280 cell->name = tscadc->data->adc_feature_name; in ti_tscadc_probe()
281 cell->of_compatible = tscadc->data->adc_feature_compatible; in ti_tscadc_probe()
282 cell->platform_data = &tscadc; in ti_tscadc_probe()
283 cell->pdata_size = sizeof(tscadc); in ti_tscadc_probe()
286 err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, in ti_tscadc_probe()
287 tscadc->cells, cell_idx, NULL, 0, NULL); in ti_tscadc_probe()
295 pm_runtime_put_sync(&pdev->dev); in ti_tscadc_probe()
296 pm_runtime_disable(&pdev->dev); in ti_tscadc_probe()
305 regmap_write(tscadc->regmap, REG_SE, 0x00); in ti_tscadc_remove()
307 pm_runtime_put_sync(&pdev->dev); in ti_tscadc_remove()
308 pm_runtime_disable(&pdev->dev); in ti_tscadc_remove()
310 mfd_remove_devices(tscadc->dev); in ti_tscadc_remove()
324 regmap_write(tscadc->regmap, REG_SE, 0x00); in tscadc_suspend()
328 regmap_read(tscadc->regmap, REG_CTRL, &ctrl); in tscadc_suspend()
331 regmap_write(tscadc->regmap, REG_CTRL, ctrl); in tscadc_suspend()
344 regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div); in tscadc_resume()
345 regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl); in tscadc_resume()
347 regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl | CNTRLREG_SSENB); in tscadc_resume()
355 .adc_feature_name = "TI-am335x-adc",
356 .adc_feature_compatible = "ti,am3359-adc",
357 .secondary_feature_name = "TI-am335x-tsc",
358 .secondary_feature_compatible = "ti,am3359-tsc",
363 .adc_feature_name = "TI-am43xx-adc",
364 .adc_feature_compatible = "ti,am4372-adc",
365 .secondary_feature_name = "TI-am43xx-mag",
366 .secondary_feature_compatible = "ti,am4372-mag",
371 { .compatible = "ti,am3359-tscadc", .data = &tscdata },
372 { .compatible = "ti,am4372-magadc", .data = &magdata },
379 .name = "ti_am3359-tscadc",