^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Atmel AT42QT1070 QTouch Sensor Controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Atmel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors: Bo Shen <voice.shen@atmel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Base on AT42QT2160 driver by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Raphael Derosso Pereira <raphaelpereira@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Address for each register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CHIP_ID 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define QT1070_CHIP_ID 0x2E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define FW_VERSION 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define QT1070_FW_VERSION 0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DET_STATUS 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define KEY_STATUS 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Calibrate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define CALIBRATE_CMD 0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define QT1070_CAL_TIME 200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define RESET 0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define QT1070_RESET_TIME 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* AT42QT1070 support up to 7 keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const unsigned short qt1070_key2code[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) KEY_0, KEY_1, KEY_2, KEY_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) KEY_4, KEY_5, KEY_6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct qt1070_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned short keycodes[ARRAY_SIZE(qt1070_key2code)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u8 last_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int qt1070_read(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ret = i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) "can not read register, returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int qt1070_write(struct i2c_client *client, u8 reg, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ret = i2c_smbus_write_byte_data(client, reg, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) "can not write register, returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static bool qt1070_identify(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int id, ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Read Chip ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) id = qt1070_read(client, CHIP_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (id != QT1070_CHIP_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) dev_err(&client->dev, "ID %d not supported\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Read firmware version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ver = qt1070_read(client, FW_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ver < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dev_err(&client->dev, "could not read the firmware version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) dev_info(&client->dev, "AT42QT1070 firmware version %x\n", ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static irqreturn_t qt1070_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct qt1070_data *data = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct input_dev *input = data->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 new_keys, keyval, mask = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Read the detected status register, thus clearing interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) qt1070_read(client, DET_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Read which key changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) new_keys = qt1070_read(client, KEY_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) keyval = new_keys & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if ((data->last_keys & mask) != keyval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) input_report_key(input, data->keycodes[i], keyval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) mask <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) data->last_keys = new_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int qt1070_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct qt1070_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) dev_err(&client->dev, "%s adapter not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) dev_driver_string(&client->adapter->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) dev_err(&client->dev, "please assign the irq to this device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* Identify the qt1070 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!qt1070_identify(client))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!data || !input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dev_err(&client->dev, "insufficient memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) data->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) data->irq = client->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) input->name = "AT42QT1070 QTouch Sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) input->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Add the keycode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) input->keycode = data->keycodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) input->keycodesize = sizeof(data->keycodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) input->keycodemax = ARRAY_SIZE(qt1070_key2code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) __set_bit(EV_KEY, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) data->keycodes[i] = qt1070_key2code[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) __set_bit(qt1070_key2code[i], input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Calibrate device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) qt1070_write(client, CALIBRATE_CMD, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) msleep(QT1070_CAL_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Soft reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) qt1070_write(client, RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) msleep(QT1070_RESET_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) IRQF_TRIGGER_NONE | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) client->dev.driver->name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) dev_err(&client->dev, "fail to request irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Register the input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) err = input_register_device(data->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) dev_err(&client->dev, "Failed to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Read to clear the chang line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) qt1070_read(client, DET_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) free_irq(client->irq, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int qt1070_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct qt1070_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Release IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) free_irq(client->irq, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) input_unregister_device(data->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 0;
^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) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int qt1070_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct qt1070_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) enable_irq_wake(data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int qt1070_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct qt1070_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) disable_irq_wake(data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static SIMPLE_DEV_PM_OPS(qt1070_pm_ops, qt1070_suspend, qt1070_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static const struct i2c_device_id qt1070_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) { "qt1070", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MODULE_DEVICE_TABLE(i2c, qt1070_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static const struct of_device_id qt1070_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) { .compatible = "qt1070", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_DEVICE_TABLE(of, qt1070_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static struct i2c_driver qt1070_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .name = "qt1070",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .of_match_table = of_match_ptr(qt1070_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .pm = &qt1070_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .id_table = qt1070_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .probe = qt1070_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .remove = qt1070_remove,
^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) module_i2c_driver(qt1070_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("Driver for AT42QT1070 QTouch sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_LICENSE("GPL");