Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Driver for AUO in-cell touchscreens
0004  *
0005  * Copyright (c) 2011 Heiko Stuebner <heiko@sntech.de>
0006  *
0007  * loosely based on auo_touch.c from Dell Streak vendor-kernel
0008  *
0009  * Copyright (c) 2008 QUALCOMM Incorporated.
0010  * Copyright (c) 2008 QUALCOMM USA, INC.
0011  */
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/slab.h>
0017 #include <linux/input.h>
0018 #include <linux/jiffies.h>
0019 #include <linux/i2c.h>
0020 #include <linux/mutex.h>
0021 #include <linux/delay.h>
0022 #include <linux/gpio.h>
0023 #include <linux/input/auo-pixcir-ts.h>
0024 #include <linux/of.h>
0025 #include <linux/of_gpio.h>
0026 
0027 /*
0028  * Coordinate calculation:
0029  * X1 = X1_LSB + X1_MSB*256
0030  * Y1 = Y1_LSB + Y1_MSB*256
0031  * X2 = X2_LSB + X2_MSB*256
0032  * Y2 = Y2_LSB + Y2_MSB*256
0033  */
0034 #define AUO_PIXCIR_REG_X1_LSB       0x00
0035 #define AUO_PIXCIR_REG_X1_MSB       0x01
0036 #define AUO_PIXCIR_REG_Y1_LSB       0x02
0037 #define AUO_PIXCIR_REG_Y1_MSB       0x03
0038 #define AUO_PIXCIR_REG_X2_LSB       0x04
0039 #define AUO_PIXCIR_REG_X2_MSB       0x05
0040 #define AUO_PIXCIR_REG_Y2_LSB       0x06
0041 #define AUO_PIXCIR_REG_Y2_MSB       0x07
0042 
0043 #define AUO_PIXCIR_REG_STRENGTH     0x0d
0044 #define AUO_PIXCIR_REG_STRENGTH_X1_LSB  0x0e
0045 #define AUO_PIXCIR_REG_STRENGTH_X1_MSB  0x0f
0046 
0047 #define AUO_PIXCIR_REG_RAW_DATA_X   0x2b
0048 #define AUO_PIXCIR_REG_RAW_DATA_Y   0x4f
0049 
0050 #define AUO_PIXCIR_REG_X_SENSITIVITY    0x6f
0051 #define AUO_PIXCIR_REG_Y_SENSITIVITY    0x70
0052 #define AUO_PIXCIR_REG_INT_SETTING  0x71
0053 #define AUO_PIXCIR_REG_INT_WIDTH    0x72
0054 #define AUO_PIXCIR_REG_POWER_MODE   0x73
0055 
0056 #define AUO_PIXCIR_REG_VERSION      0x77
0057 #define AUO_PIXCIR_REG_CALIBRATE    0x78
0058 
0059 #define AUO_PIXCIR_REG_TOUCHAREA_X1 0x1e
0060 #define AUO_PIXCIR_REG_TOUCHAREA_Y1 0x1f
0061 #define AUO_PIXCIR_REG_TOUCHAREA_X2 0x20
0062 #define AUO_PIXCIR_REG_TOUCHAREA_Y2 0x21
0063 
0064 #define AUO_PIXCIR_REG_EEPROM_CALIB_X   0x42
0065 #define AUO_PIXCIR_REG_EEPROM_CALIB_Y   0xad
0066 
0067 #define AUO_PIXCIR_INT_TPNUM_MASK   0xe0
0068 #define AUO_PIXCIR_INT_TPNUM_SHIFT  5
0069 #define AUO_PIXCIR_INT_RELEASE      (1 << 4)
0070 #define AUO_PIXCIR_INT_ENABLE       (1 << 3)
0071 #define AUO_PIXCIR_INT_POL_HIGH     (1 << 2)
0072 #define AUO_PIXCIR_INT_MODE_MASK    0x03
0073 
0074 /*
0075  * Power modes:
0076  * active:  scan speed 60Hz
0077  * sleep:   scan speed 10Hz can be auto-activated, wakeup on 1st touch
0078  * deep sleep:  scan speed 1Hz can only be entered or left manually.
0079  */
0080 #define AUO_PIXCIR_POWER_ACTIVE     0x00
0081 #define AUO_PIXCIR_POWER_SLEEP      0x01
0082 #define AUO_PIXCIR_POWER_DEEP_SLEEP 0x02
0083 #define AUO_PIXCIR_POWER_MASK       0x03
0084 
0085 #define AUO_PIXCIR_POWER_ALLOW_SLEEP    (1 << 2)
0086 #define AUO_PIXCIR_POWER_IDLE_TIME(ms)  ((ms & 0xf) << 4)
0087 
0088 #define AUO_PIXCIR_CALIBRATE        0x03
0089 
0090 #define AUO_PIXCIR_EEPROM_CALIB_X_LEN   62
0091 #define AUO_PIXCIR_EEPROM_CALIB_Y_LEN   36
0092 
0093 #define AUO_PIXCIR_RAW_DATA_X_LEN   18
0094 #define AUO_PIXCIR_RAW_DATA_Y_LEN   11
0095 
0096 #define AUO_PIXCIR_STRENGTH_ENABLE  (1 << 0)
0097 
0098 /* Touchscreen absolute values */
0099 #define AUO_PIXCIR_REPORT_POINTS    2
0100 #define AUO_PIXCIR_MAX_AREA     0xff
0101 #define AUO_PIXCIR_PENUP_TIMEOUT_MS 10
0102 
0103 struct auo_pixcir_ts {
0104     struct i2c_client   *client;
0105     struct input_dev    *input;
0106     const struct auo_pixcir_ts_platdata *pdata;
0107     char            phys[32];
0108 
0109     /* special handling for touch_indicate interupt mode */
0110     bool            touch_ind_mode;
0111 
0112     wait_queue_head_t   wait;
0113     bool            stopped;
0114 };
0115 
0116 struct auo_point_t {
0117     int coord_x;
0118     int coord_y;
0119     int area_major;
0120     int area_minor;
0121     int orientation;
0122 };
0123 
0124 static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
0125                    struct auo_point_t *point)
0126 {
0127     struct i2c_client *client = ts->client;
0128     const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
0129     uint8_t raw_coord[8];
0130     uint8_t raw_area[4];
0131     int i, ret;
0132 
0133     /* touch coordinates */
0134     ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_X1_LSB,
0135                         8, raw_coord);
0136     if (ret < 0) {
0137         dev_err(&client->dev, "failed to read coordinate, %d\n", ret);
0138         return ret;
0139     }
0140 
0141     /* touch area */
0142     ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_TOUCHAREA_X1,
0143                         4, raw_area);
0144     if (ret < 0) {
0145         dev_err(&client->dev, "could not read touch area, %d\n", ret);
0146         return ret;
0147     }
0148 
0149     for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
0150         point[i].coord_x =
0151             raw_coord[4 * i + 1] << 8 | raw_coord[4 * i];
0152         point[i].coord_y =
0153             raw_coord[4 * i + 3] << 8 | raw_coord[4 * i + 2];
0154 
0155         if (point[i].coord_x > pdata->x_max ||
0156             point[i].coord_y > pdata->y_max) {
0157             dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
0158                 point[i].coord_x, point[i].coord_y);
0159             point[i].coord_x = point[i].coord_y = 0;
0160         }
0161 
0162         /* determine touch major, minor and orientation */
0163         point[i].area_major = max(raw_area[2 * i], raw_area[2 * i + 1]);
0164         point[i].area_minor = min(raw_area[2 * i], raw_area[2 * i + 1]);
0165         point[i].orientation = raw_area[2 * i] > raw_area[2 * i + 1];
0166     }
0167 
0168     return 0;
0169 }
0170 
0171 static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id)
0172 {
0173     struct auo_pixcir_ts *ts = dev_id;
0174     const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
0175     struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
0176     int i;
0177     int ret;
0178     int fingers = 0;
0179     int abs = -1;
0180 
0181     while (!ts->stopped) {
0182 
0183         /* check for up event in touch touch_ind_mode */
0184         if (ts->touch_ind_mode) {
0185             if (gpio_get_value(pdata->gpio_int) == 0) {
0186                 input_mt_sync(ts->input);
0187                 input_report_key(ts->input, BTN_TOUCH, 0);
0188                 input_sync(ts->input);
0189                 break;
0190             }
0191         }
0192 
0193         ret = auo_pixcir_collect_data(ts, point);
0194         if (ret < 0) {
0195             /* we want to loop only in touch_ind_mode */
0196             if (!ts->touch_ind_mode)
0197                 break;
0198 
0199             wait_event_timeout(ts->wait, ts->stopped,
0200                 msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
0201             continue;
0202         }
0203 
0204         for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
0205             if (point[i].coord_x > 0 || point[i].coord_y > 0) {
0206                 input_report_abs(ts->input, ABS_MT_POSITION_X,
0207                          point[i].coord_x);
0208                 input_report_abs(ts->input, ABS_MT_POSITION_Y,
0209                          point[i].coord_y);
0210                 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
0211                          point[i].area_major);
0212                 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
0213                          point[i].area_minor);
0214                 input_report_abs(ts->input, ABS_MT_ORIENTATION,
0215                          point[i].orientation);
0216                 input_mt_sync(ts->input);
0217 
0218                 /* use first finger as source for singletouch */
0219                 if (fingers == 0)
0220                     abs = i;
0221 
0222                 /* number of touch points could also be queried
0223                  * via i2c but would require an additional call
0224                  */
0225                 fingers++;
0226             }
0227         }
0228 
0229         input_report_key(ts->input, BTN_TOUCH, fingers > 0);
0230 
0231         if (abs > -1) {
0232             input_report_abs(ts->input, ABS_X, point[abs].coord_x);
0233             input_report_abs(ts->input, ABS_Y, point[abs].coord_y);
0234         }
0235 
0236         input_sync(ts->input);
0237 
0238         /* we want to loop only in touch_ind_mode */
0239         if (!ts->touch_ind_mode)
0240             break;
0241 
0242         wait_event_timeout(ts->wait, ts->stopped,
0243                  msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
0244     }
0245 
0246     return IRQ_HANDLED;
0247 }
0248 
0249 /*
0250  * Set the power mode of the device.
0251  * Valid modes are
0252  * - AUO_PIXCIR_POWER_ACTIVE
0253  * - AUO_PIXCIR_POWER_SLEEP - automatically left on first touch
0254  * - AUO_PIXCIR_POWER_DEEP_SLEEP
0255  */
0256 static int auo_pixcir_power_mode(struct auo_pixcir_ts *ts, int mode)
0257 {
0258     struct i2c_client *client = ts->client;
0259     int ret;
0260 
0261     ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_POWER_MODE);
0262     if (ret < 0) {
0263         dev_err(&client->dev, "unable to read reg %Xh, %d\n",
0264             AUO_PIXCIR_REG_POWER_MODE, ret);
0265         return ret;
0266     }
0267 
0268     ret &= ~AUO_PIXCIR_POWER_MASK;
0269     ret |= mode;
0270 
0271     ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_POWER_MODE, ret);
0272     if (ret) {
0273         dev_err(&client->dev, "unable to write reg %Xh, %d\n",
0274             AUO_PIXCIR_REG_POWER_MODE, ret);
0275         return ret;
0276     }
0277 
0278     return 0;
0279 }
0280 
0281 static int auo_pixcir_int_config(struct auo_pixcir_ts *ts,
0282                        int int_setting)
0283 {
0284     struct i2c_client *client = ts->client;
0285     const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
0286     int ret;
0287 
0288     ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
0289     if (ret < 0) {
0290         dev_err(&client->dev, "unable to read reg %Xh, %d\n",
0291             AUO_PIXCIR_REG_INT_SETTING, ret);
0292         return ret;
0293     }
0294 
0295     ret &= ~AUO_PIXCIR_INT_MODE_MASK;
0296     ret |= int_setting;
0297     ret |= AUO_PIXCIR_INT_POL_HIGH; /* always use high for interrupts */
0298 
0299     ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
0300                     ret);
0301     if (ret < 0) {
0302         dev_err(&client->dev, "unable to write reg %Xh, %d\n",
0303             AUO_PIXCIR_REG_INT_SETTING, ret);
0304         return ret;
0305     }
0306 
0307     ts->touch_ind_mode = pdata->int_setting == AUO_PIXCIR_INT_TOUCH_IND;
0308 
0309     return 0;
0310 }
0311 
0312 /* control the generation of interrupts on the device side */
0313 static int auo_pixcir_int_toggle(struct auo_pixcir_ts *ts, bool enable)
0314 {
0315     struct i2c_client *client = ts->client;
0316     int ret;
0317 
0318     ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
0319     if (ret < 0) {
0320         dev_err(&client->dev, "unable to read reg %Xh, %d\n",
0321             AUO_PIXCIR_REG_INT_SETTING, ret);
0322         return ret;
0323     }
0324 
0325     if (enable)
0326         ret |= AUO_PIXCIR_INT_ENABLE;
0327     else
0328         ret &= ~AUO_PIXCIR_INT_ENABLE;
0329 
0330     ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
0331                     ret);
0332     if (ret < 0) {
0333         dev_err(&client->dev, "unable to write reg %Xh, %d\n",
0334             AUO_PIXCIR_REG_INT_SETTING, ret);
0335         return ret;
0336     }
0337 
0338     return 0;
0339 }
0340 
0341 static int auo_pixcir_start(struct auo_pixcir_ts *ts)
0342 {
0343     struct i2c_client *client = ts->client;
0344     int ret;
0345 
0346     ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_ACTIVE);
0347     if (ret < 0) {
0348         dev_err(&client->dev, "could not set power mode, %d\n",
0349             ret);
0350         return ret;
0351     }
0352 
0353     ts->stopped = false;
0354     mb();
0355     enable_irq(client->irq);
0356 
0357     ret = auo_pixcir_int_toggle(ts, 1);
0358     if (ret < 0) {
0359         dev_err(&client->dev, "could not enable interrupt, %d\n",
0360             ret);
0361         disable_irq(client->irq);
0362         return ret;
0363     }
0364 
0365     return 0;
0366 }
0367 
0368 static int auo_pixcir_stop(struct auo_pixcir_ts *ts)
0369 {
0370     struct i2c_client *client = ts->client;
0371     int ret;
0372 
0373     ret = auo_pixcir_int_toggle(ts, 0);
0374     if (ret < 0) {
0375         dev_err(&client->dev, "could not disable interrupt, %d\n",
0376             ret);
0377         return ret;
0378     }
0379 
0380     /* disable receiving of interrupts */
0381     disable_irq(client->irq);
0382     ts->stopped = true;
0383     mb();
0384     wake_up(&ts->wait);
0385 
0386     return auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_DEEP_SLEEP);
0387 }
0388 
0389 static int auo_pixcir_input_open(struct input_dev *dev)
0390 {
0391     struct auo_pixcir_ts *ts = input_get_drvdata(dev);
0392 
0393     return auo_pixcir_start(ts);
0394 }
0395 
0396 static void auo_pixcir_input_close(struct input_dev *dev)
0397 {
0398     struct auo_pixcir_ts *ts = input_get_drvdata(dev);
0399 
0400     auo_pixcir_stop(ts);
0401 }
0402 
0403 static int __maybe_unused auo_pixcir_suspend(struct device *dev)
0404 {
0405     struct i2c_client *client = to_i2c_client(dev);
0406     struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
0407     struct input_dev *input = ts->input;
0408     int ret = 0;
0409 
0410     mutex_lock(&input->mutex);
0411 
0412     /* when configured as wakeup source, device should always wake system
0413      * therefore start device if necessary
0414      */
0415     if (device_may_wakeup(&client->dev)) {
0416         /* need to start device if not open, to be wakeup source */
0417         if (!input_device_enabled(input)) {
0418             ret = auo_pixcir_start(ts);
0419             if (ret)
0420                 goto unlock;
0421         }
0422 
0423         enable_irq_wake(client->irq);
0424         ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP);
0425     } else if (input_device_enabled(input)) {
0426         ret = auo_pixcir_stop(ts);
0427     }
0428 
0429 unlock:
0430     mutex_unlock(&input->mutex);
0431 
0432     return ret;
0433 }
0434 
0435 static int __maybe_unused auo_pixcir_resume(struct device *dev)
0436 {
0437     struct i2c_client *client = to_i2c_client(dev);
0438     struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
0439     struct input_dev *input = ts->input;
0440     int ret = 0;
0441 
0442     mutex_lock(&input->mutex);
0443 
0444     if (device_may_wakeup(&client->dev)) {
0445         disable_irq_wake(client->irq);
0446 
0447         /* need to stop device if it was not open on suspend */
0448         if (!input_device_enabled(input)) {
0449             ret = auo_pixcir_stop(ts);
0450             if (ret)
0451                 goto unlock;
0452         }
0453 
0454         /* device wakes automatically from SLEEP */
0455     } else if (input_device_enabled(input)) {
0456         ret = auo_pixcir_start(ts);
0457     }
0458 
0459 unlock:
0460     mutex_unlock(&input->mutex);
0461 
0462     return ret;
0463 }
0464 
0465 static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
0466              auo_pixcir_suspend, auo_pixcir_resume);
0467 
0468 #ifdef CONFIG_OF
0469 static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
0470 {
0471     struct auo_pixcir_ts_platdata *pdata;
0472     struct device_node *np = dev->of_node;
0473 
0474     if (!np)
0475         return ERR_PTR(-ENOENT);
0476 
0477     pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
0478     if (!pdata)
0479         return ERR_PTR(-ENOMEM);
0480 
0481     pdata->gpio_int = of_get_gpio(np, 0);
0482     if (!gpio_is_valid(pdata->gpio_int)) {
0483         dev_err(dev, "failed to get interrupt gpio\n");
0484         return ERR_PTR(-EINVAL);
0485     }
0486 
0487     pdata->gpio_rst = of_get_gpio(np, 1);
0488     if (!gpio_is_valid(pdata->gpio_rst)) {
0489         dev_err(dev, "failed to get reset gpio\n");
0490         return ERR_PTR(-EINVAL);
0491     }
0492 
0493     if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
0494         dev_err(dev, "failed to get x-size property\n");
0495         return ERR_PTR(-EINVAL);
0496     }
0497 
0498     if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
0499         dev_err(dev, "failed to get y-size property\n");
0500         return ERR_PTR(-EINVAL);
0501     }
0502 
0503     /* default to asserting the interrupt when the screen is touched */
0504     pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
0505 
0506     return pdata;
0507 }
0508 #else
0509 static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
0510 {
0511     return ERR_PTR(-EINVAL);
0512 }
0513 #endif
0514 
0515 static void auo_pixcir_reset(void *data)
0516 {
0517     struct auo_pixcir_ts *ts = data;
0518 
0519     gpio_set_value(ts->pdata->gpio_rst, 0);
0520 }
0521 
0522 static int auo_pixcir_probe(struct i2c_client *client,
0523                 const struct i2c_device_id *id)
0524 {
0525     const struct auo_pixcir_ts_platdata *pdata;
0526     struct auo_pixcir_ts *ts;
0527     struct input_dev *input_dev;
0528     int version;
0529     int error;
0530 
0531     pdata = dev_get_platdata(&client->dev);
0532     if (!pdata) {
0533         pdata = auo_pixcir_parse_dt(&client->dev);
0534         if (IS_ERR(pdata))
0535             return PTR_ERR(pdata);
0536     }
0537 
0538     ts = devm_kzalloc(&client->dev,
0539               sizeof(struct auo_pixcir_ts), GFP_KERNEL);
0540     if (!ts)
0541         return -ENOMEM;
0542 
0543     input_dev = devm_input_allocate_device(&client->dev);
0544     if (!input_dev) {
0545         dev_err(&client->dev, "could not allocate input device\n");
0546         return -ENOMEM;
0547     }
0548 
0549     ts->pdata = pdata;
0550     ts->client = client;
0551     ts->input = input_dev;
0552     ts->touch_ind_mode = 0;
0553     ts->stopped = true;
0554     init_waitqueue_head(&ts->wait);
0555 
0556     snprintf(ts->phys, sizeof(ts->phys),
0557          "%s/input0", dev_name(&client->dev));
0558 
0559     input_dev->name = "AUO-Pixcir touchscreen";
0560     input_dev->phys = ts->phys;
0561     input_dev->id.bustype = BUS_I2C;
0562 
0563     input_dev->open = auo_pixcir_input_open;
0564     input_dev->close = auo_pixcir_input_close;
0565 
0566     __set_bit(EV_ABS, input_dev->evbit);
0567     __set_bit(EV_KEY, input_dev->evbit);
0568 
0569     __set_bit(BTN_TOUCH, input_dev->keybit);
0570 
0571     /* For single touch */
0572     input_set_abs_params(input_dev, ABS_X, 0, pdata->x_max, 0, 0);
0573     input_set_abs_params(input_dev, ABS_Y, 0, pdata->y_max, 0, 0);
0574 
0575     /* For multi touch */
0576     input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
0577                  pdata->x_max, 0, 0);
0578     input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
0579                  pdata->y_max, 0, 0);
0580     input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
0581                  AUO_PIXCIR_MAX_AREA, 0, 0);
0582     input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
0583                  AUO_PIXCIR_MAX_AREA, 0, 0);
0584     input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
0585 
0586     input_set_drvdata(ts->input, ts);
0587 
0588     error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
0589                       GPIOF_DIR_IN, "auo_pixcir_ts_int");
0590     if (error) {
0591         dev_err(&client->dev, "request of gpio %d failed, %d\n",
0592             pdata->gpio_int, error);
0593         return error;
0594     }
0595 
0596     error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
0597                       GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
0598                       "auo_pixcir_ts_rst");
0599     if (error) {
0600         dev_err(&client->dev, "request of gpio %d failed, %d\n",
0601             pdata->gpio_rst, error);
0602         return error;
0603     }
0604 
0605     error = devm_add_action_or_reset(&client->dev, auo_pixcir_reset, ts);
0606     if (error) {
0607         dev_err(&client->dev, "failed to register reset action, %d\n",
0608             error);
0609         return error;
0610     }
0611 
0612     msleep(200);
0613 
0614     version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
0615     if (version < 0) {
0616         error = version;
0617         return error;
0618     }
0619 
0620     dev_info(&client->dev, "firmware version 0x%X\n", version);
0621 
0622     error = auo_pixcir_int_config(ts, pdata->int_setting);
0623     if (error)
0624         return error;
0625 
0626     error = devm_request_threaded_irq(&client->dev, client->irq,
0627                       NULL, auo_pixcir_interrupt,
0628                       IRQF_TRIGGER_RISING | IRQF_ONESHOT,
0629                       input_dev->name, ts);
0630     if (error) {
0631         dev_err(&client->dev, "irq %d requested failed, %d\n",
0632             client->irq, error);
0633         return error;
0634     }
0635 
0636     /* stop device and put it into deep sleep until it is opened */
0637     error = auo_pixcir_stop(ts);
0638     if (error)
0639         return error;
0640 
0641     error = input_register_device(input_dev);
0642     if (error) {
0643         dev_err(&client->dev, "could not register input device, %d\n",
0644             error);
0645         return error;
0646     }
0647 
0648     i2c_set_clientdata(client, ts);
0649 
0650     return 0;
0651 }
0652 
0653 static const struct i2c_device_id auo_pixcir_idtable[] = {
0654     { "auo_pixcir_ts", 0 },
0655     { }
0656 };
0657 MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
0658 
0659 #ifdef CONFIG_OF
0660 static const struct of_device_id auo_pixcir_ts_dt_idtable[] = {
0661     { .compatible = "auo,auo_pixcir_ts" },
0662     {},
0663 };
0664 MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
0665 #endif
0666 
0667 static struct i2c_driver auo_pixcir_driver = {
0668     .driver = {
0669         .name   = "auo_pixcir_ts",
0670         .pm = &auo_pixcir_pm_ops,
0671         .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
0672     },
0673     .probe      = auo_pixcir_probe,
0674     .id_table   = auo_pixcir_idtable,
0675 };
0676 
0677 module_i2c_driver(auo_pixcir_driver);
0678 
0679 MODULE_DESCRIPTION("AUO-PIXCIR touchscreen driver");
0680 MODULE_LICENSE("GPL v2");
0681 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");