^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Touchscreen driver for the tps6507x chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2009 RidgeRun (todd.fischer@ridgerun.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Credits:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Using code from tsc2007, MtekVision Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * For licencing details see kernel-base/COPYING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * TPS65070, TPS65073, TPS650731, and TPS650732 support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 10 bit touch screen interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mfd/tps6507x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/input/tps6507x-ts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define TSC_DEFAULT_POLL_PERIOD 30 /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TPS_DEFAULT_MIN_PRESSURE 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define MAX_10BIT ((1 << 10) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define TPS6507X_ADCONFIG_CONVERT_TS (TPS6507X_ADCONFIG_AD_ENABLE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) TPS6507X_ADCONFIG_START_CONVERSION | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) TPS6507X_ADCONFIG_INPUT_REAL_TSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define TPS6507X_ADCONFIG_POWER_DOWN_TS (TPS6507X_ADCONFIG_INPUT_REAL_TSC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct ts_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u16 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u16 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u16 pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct tps6507x_ts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct tps6507x_dev *mfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ts_event tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u16 min_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) bool pendown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int tps6507x_read_u8(struct tps6507x_ts *tsc, u8 reg, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return tsc->mfd->read_dev(tsc->mfd, reg, 1, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static int tps6507x_write_u8(struct tps6507x_ts *tsc, u8 reg, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return tsc->mfd->write_dev(tsc->mfd, reg, 1, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static s32 tps6507x_adc_conversion(struct tps6507x_ts *tsc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u8 tsc_mode, u16 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) s32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u8 adc_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u8 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Route input signal to A/D converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ret = tps6507x_write_u8(tsc, TPS6507X_REG_TSCMODE, tsc_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dev_err(tsc->dev, "TSC mode read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* Start A/D conversion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ret = tps6507x_write_u8(tsc, TPS6507X_REG_ADCONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) TPS6507X_ADCONFIG_CONVERT_TS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dev_err(tsc->dev, "ADC config write failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ret = tps6507x_read_u8(tsc, TPS6507X_REG_ADCONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) &adc_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev_err(tsc->dev, "ADC config read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } while (adc_status & TPS6507X_ADCONFIG_START_CONVERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ret = tps6507x_read_u8(tsc, TPS6507X_REG_ADRESULT_2, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) dev_err(tsc->dev, "ADC result 2 read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *value = (result & TPS6507X_REG_ADRESULT_2_MASK) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ret = tps6507x_read_u8(tsc, TPS6507X_REG_ADRESULT_1, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev_err(tsc->dev, "ADC result 1 read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *value |= result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev_dbg(tsc->dev, "TSC channel %d = 0x%X\n", tsc_mode, *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Need to call tps6507x_adc_standby() after using A/D converter for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * touch screen interrupt to work properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static s32 tps6507x_adc_standby(struct tps6507x_ts *tsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) s32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) s32 loops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ret = tps6507x_write_u8(tsc, TPS6507X_REG_ADCONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) TPS6507X_ADCONFIG_INPUT_TSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ret = tps6507x_write_u8(tsc, TPS6507X_REG_TSCMODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) TPS6507X_TSCMODE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = tps6507x_read_u8(tsc, TPS6507X_REG_INT, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) while (val & TPS6507X_REG_TSC_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mdelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ret = tps6507x_read_u8(tsc, TPS6507X_REG_INT, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) loops++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void tps6507x_ts_poll(struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct tps6507x_ts *tsc = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) bool pendown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) s32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) &tsc->tc.pressure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pendown = tsc->tc.pressure > tsc->min_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (unlikely(!pendown && tsc->pendown)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) dev_dbg(tsc->dev, "UP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) input_report_key(input_dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) input_report_abs(input_dev, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) tsc->pendown = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (pendown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!tsc->pendown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) dev_dbg(tsc->dev, "DOWN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) input_report_key(input_dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_dbg(tsc->dev, "still down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_X_POSITION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) &tsc->tc.x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_Y_POSITION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) &tsc->tc.y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) input_report_abs(input_dev, ABS_X, tsc->tc.x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) input_report_abs(input_dev, ABS_Y, tsc->tc.y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) input_report_abs(input_dev, ABS_PRESSURE, tsc->tc.pressure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) tsc->pendown = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) tps6507x_adc_standby(tsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int tps6507x_ts_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) const struct tps6507x_board *tps_board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) const struct touchscreen_init_data *init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct tps6507x_ts *tsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * tps_board points to pmic related constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * coming from the board-evm file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) tps_board = dev_get_platdata(tps6507x_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!tps_board) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) dev_err(tps6507x_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) "Could not find tps6507x platform data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * init_data points to array of regulator_init structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * coming from the board-evm file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) init_data = tps_board->tps6507x_ts_init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!tsc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dev_err(tps6507x_dev->dev, "failed to allocate driver data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) tsc->mfd = tps6507x_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) tsc->dev = tps6507x_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) tsc->min_pressure = init_data ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) init_data->min_pressure : TPS_DEFAULT_MIN_PRESSURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) snprintf(tsc->phys, sizeof(tsc->phys),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) "%s/input0", dev_name(tsc->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) input_dev = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) dev_err(tsc->dev, "Failed to allocate polled input device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) tsc->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) input_set_drvdata(input_dev, tsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) input_set_abs_params(input_dev, ABS_X, 0, MAX_10BIT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) input_set_abs_params(input_dev, ABS_Y, 0, MAX_10BIT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_10BIT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) input_dev->name = "TPS6507x Touchscreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) input_dev->phys = tsc->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) input_dev->dev.parent = tsc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (init_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) input_dev->id.vendor = init_data->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) input_dev->id.product = init_data->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) input_dev->id.version = init_data->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) error = tps6507x_adc_standby(tsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) error = input_setup_polling(input_dev, tps6507x_ts_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) input_set_poll_interval(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) init_data ? init_data->poll_period :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) TSC_DEFAULT_POLL_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static struct platform_driver tps6507x_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .name = "tps6507x-ts",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .probe = tps6507x_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) module_platform_driver(tps6507x_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) MODULE_AUTHOR("Todd Fischer <todd.fischer@ridgerun.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MODULE_DESCRIPTION("TPS6507x - TouchScreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) MODULE_ALIAS("platform:tps6507x-ts");