Lines Matching +full:y +full:- +full:plate
1 // SPDX-License-Identifier: GPL-2.0-only
9 * - ads7846.c
12 * - corgi_ts.c
13 * Copyright (C) 2004-2005 Richard Purdie
14 * - omap_ts.[hc], ads7846.h, ts_osk.c
36 data = i2c_smbus_read_word_data(tsc->client, cmd); in tsc2007_xfer()
38 dev_err(&tsc->client->dev, "i2c io error: %d\n", data); in tsc2007_xfer()
44 * Where DataLow has [D11-D4], DataHigh has [D3-D0 << 4 | Dummy 4bit]. in tsc2007_xfer()
48 dev_dbg(&tsc->client->dev, "data: 0x%x, val: 0x%x\n", data, val); in tsc2007_xfer()
55 /* y- still on; turn on only y+ (and ADC) */ in tsc2007_read_values()
56 tc->y = tsc2007_xfer(tsc, READ_Y); in tsc2007_read_values()
58 /* turn y- off, x+ on, then leave in lowpower */ in tsc2007_read_values()
59 tc->x = tsc2007_xfer(tsc, READ_X); in tsc2007_read_values()
61 /* turn y+ off, x- on; we'll use formula #1 */ in tsc2007_read_values()
62 tc->z1 = tsc2007_xfer(tsc, READ_Z1); in tsc2007_read_values()
63 tc->z2 = tsc2007_xfer(tsc, READ_Z2); in tsc2007_read_values()
65 /* Prepare for next touch reading - power down ADC, enable PENIRQ */ in tsc2007_read_values()
74 if (tc->x == MAX_12BIT) in tsc2007_calculate_resistance()
75 tc->x = 0; in tsc2007_calculate_resistance()
77 if (likely(tc->x && tc->z1)) { in tsc2007_calculate_resistance()
79 rt = tc->z2 - tc->z1; in tsc2007_calculate_resistance()
80 rt *= tc->x; in tsc2007_calculate_resistance()
81 rt *= tsc->x_plate_ohms; in tsc2007_calculate_resistance()
82 rt /= tc->z1; in tsc2007_calculate_resistance()
105 if (!ts->get_pendown_state) in tsc2007_is_pen_down()
108 return ts->get_pendown_state(&ts->client->dev); in tsc2007_is_pen_down()
114 struct input_dev *input = ts->input; in tsc2007_soft_irq()
118 while (!ts->stopped && tsc2007_is_pen_down(ts)) { in tsc2007_soft_irq()
122 mutex_lock(&ts->mlock); in tsc2007_soft_irq()
124 mutex_unlock(&ts->mlock); in tsc2007_soft_irq()
128 if (!rt && !ts->get_pendown_state) { in tsc2007_soft_irq()
137 if (rt <= ts->max_rt) { in tsc2007_soft_irq()
138 dev_dbg(&ts->client->dev, in tsc2007_soft_irq()
140 tc.x, tc.y, rt); in tsc2007_soft_irq()
142 rt = ts->max_rt - rt; in tsc2007_soft_irq()
146 input_report_abs(input, ABS_Y, tc.y); in tsc2007_soft_irq()
157 dev_dbg(&ts->client->dev, "ignored pressure %d\n", rt); in tsc2007_soft_irq()
160 wait_event_timeout(ts->wait, ts->stopped, ts->poll_period); in tsc2007_soft_irq()
163 dev_dbg(&ts->client->dev, "UP\n"); in tsc2007_soft_irq()
169 if (ts->clear_penirq) in tsc2007_soft_irq()
170 ts->clear_penirq(); in tsc2007_soft_irq()
177 ts->stopped = true; in tsc2007_stop()
179 wake_up(&ts->wait); in tsc2007_stop()
181 disable_irq(ts->irq); in tsc2007_stop()
189 ts->stopped = false; in tsc2007_open()
192 enable_irq(ts->irq); in tsc2007_open()
194 /* Prepare for touch readings - power down ADC and enable PENIRQ */ in tsc2007_open()
216 return gpiod_get_value_cansleep(ts->gpiod); in tsc2007_get_pendown_state_gpio()
224 if (!device_property_read_u32(dev, "ti,max-rt", &val32)) in tsc2007_probe_properties()
225 ts->max_rt = val32; in tsc2007_probe_properties()
227 ts->max_rt = MAX_12BIT; in tsc2007_probe_properties()
230 ts->fuzzx = val32; in tsc2007_probe_properties()
233 ts->fuzzy = val32; in tsc2007_probe_properties()
236 ts->fuzzz = val32; in tsc2007_probe_properties()
238 if (!device_property_read_u64(dev, "ti,poll-period", &val64)) in tsc2007_probe_properties()
239 ts->poll_period = msecs_to_jiffies(val64); in tsc2007_probe_properties()
241 ts->poll_period = msecs_to_jiffies(1); in tsc2007_probe_properties()
243 if (!device_property_read_u32(dev, "ti,x-plate-ohms", &val32)) { in tsc2007_probe_properties()
244 ts->x_plate_ohms = val32; in tsc2007_probe_properties()
246 dev_err(dev, "Missing ti,x-plate-ohms device property\n"); in tsc2007_probe_properties()
247 return -EINVAL; in tsc2007_probe_properties()
250 ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN); in tsc2007_probe_properties()
251 if (IS_ERR(ts->gpiod)) in tsc2007_probe_properties()
252 return PTR_ERR(ts->gpiod); in tsc2007_probe_properties()
254 if (ts->gpiod) in tsc2007_probe_properties()
255 ts->get_pendown_state = tsc2007_get_pendown_state_gpio; in tsc2007_probe_properties()
266 ts->model = pdata->model; in tsc2007_probe_pdev()
267 ts->x_plate_ohms = pdata->x_plate_ohms; in tsc2007_probe_pdev()
268 ts->max_rt = pdata->max_rt ? : MAX_12BIT; in tsc2007_probe_pdev()
269 ts->poll_period = msecs_to_jiffies(pdata->poll_period ? : 1); in tsc2007_probe_pdev()
270 ts->get_pendown_state = pdata->get_pendown_state; in tsc2007_probe_pdev()
271 ts->clear_penirq = pdata->clear_penirq; in tsc2007_probe_pdev()
272 ts->fuzzx = pdata->fuzzx; in tsc2007_probe_pdev()
273 ts->fuzzy = pdata->fuzzy; in tsc2007_probe_pdev()
274 ts->fuzzz = pdata->fuzzz; in tsc2007_probe_pdev()
276 if (pdata->x_plate_ohms == 0) { in tsc2007_probe_pdev()
278 return -EINVAL; in tsc2007_probe_pdev()
289 pdata->exit_platform_hw(); in tsc2007_call_exit_platform_hw()
296 dev_get_platdata(&client->dev); in tsc2007_probe()
301 if (!i2c_check_functionality(client->adapter, in tsc2007_probe()
303 return -EIO; in tsc2007_probe()
305 ts = devm_kzalloc(&client->dev, sizeof(struct tsc2007), GFP_KERNEL); in tsc2007_probe()
307 return -ENOMEM; in tsc2007_probe()
310 err = tsc2007_probe_pdev(&client->dev, ts, pdata, id); in tsc2007_probe()
312 err = tsc2007_probe_properties(&client->dev, ts); in tsc2007_probe()
316 input_dev = devm_input_allocate_device(&client->dev); in tsc2007_probe()
318 return -ENOMEM; in tsc2007_probe()
322 ts->client = client; in tsc2007_probe()
323 ts->irq = client->irq; in tsc2007_probe()
324 ts->input = input_dev; in tsc2007_probe()
326 init_waitqueue_head(&ts->wait); in tsc2007_probe()
327 mutex_init(&ts->mlock); in tsc2007_probe()
329 snprintf(ts->phys, sizeof(ts->phys), in tsc2007_probe()
330 "%s/input0", dev_name(&client->dev)); in tsc2007_probe()
332 input_dev->name = "TSC2007 Touchscreen"; in tsc2007_probe()
333 input_dev->phys = ts->phys; in tsc2007_probe()
334 input_dev->id.bustype = BUS_I2C; in tsc2007_probe()
336 input_dev->open = tsc2007_open; in tsc2007_probe()
337 input_dev->close = tsc2007_close; in tsc2007_probe()
343 input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, ts->fuzzx, 0); in tsc2007_probe()
344 input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, ts->fuzzy, 0); in tsc2007_probe()
346 ts->fuzzz, 0); in tsc2007_probe()
349 if (pdata->exit_platform_hw) { in tsc2007_probe()
350 err = devm_add_action(&client->dev, in tsc2007_probe()
352 &client->dev); in tsc2007_probe()
354 dev_err(&client->dev, in tsc2007_probe()
361 if (pdata->init_platform_hw) in tsc2007_probe()
362 pdata->init_platform_hw(); in tsc2007_probe()
365 err = devm_request_threaded_irq(&client->dev, ts->irq, in tsc2007_probe()
368 client->dev.driver->name, ts); in tsc2007_probe()
370 dev_err(&client->dev, "Failed to request irq %d: %d\n", in tsc2007_probe()
371 ts->irq, err); in tsc2007_probe()
380 dev_err(&client->dev, in tsc2007_probe()
387 dev_err(&client->dev, in tsc2007_probe()
394 dev_err(&client->dev, in tsc2007_probe()