^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Atmel Atmegaxx Capacitive Touch Button Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2016 Google, inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * It's irrelevant that the HW used to develop captouch driver is based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * on Atmega88PA part and uses QtouchADC parts for sensing touch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Calling this driver "captouch" is an arbitrary way to distinguish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * the protocol this driver supported by other atmel/qtouch drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Captouch driver supports a newer/different version of the I2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * registers/commands than the qt1070.c driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Don't let the similarity of the general driver structure fool you.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * For raw i2c access from userspace, use i2cset/i2cget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * to poke at /dev/i2c-N devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Maximum number of buttons supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define MAX_NUM_OF_BUTTONS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define REG_KEY1_THRESHOLD 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define REG_KEY2_THRESHOLD 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define REG_KEY3_THRESHOLD 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define REG_KEY4_THRESHOLD 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define REG_KEY1_REF_H 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define REG_KEY1_REF_L 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define REG_KEY2_REF_H 0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define REG_KEY2_REF_L 0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define REG_KEY3_REF_H 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define REG_KEY3_REF_L 0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define REG_KEY4_REF_H 0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define REG_KEY4_REF_L 0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define REG_KEY1_DLT_H 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define REG_KEY1_DLT_L 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define REG_KEY2_DLT_H 0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define REG_KEY2_DLT_L 0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define REG_KEY3_DLT_H 0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define REG_KEY3_DLT_L 0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define REG_KEY4_DLT_H 0x36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define REG_KEY4_DLT_L 0x37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define REG_KEY_STATE 0x3C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @i2c_client: I2C slave device client pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @input: Input device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @num_btn: Number of buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @keycodes: map of button# to KeyCode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @prev_btn: Previous key state to detect button "press" or "release"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @xfer_buf: I2C transfer buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct atmel_captouch_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u32 num_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u32 keycodes[MAX_NUM_OF_BUTTONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u8 prev_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 xfer_buf[8] ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Read from I2C slave device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * The protocol is that the client has to provide both the register address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * and the length, and while reading back the device would prepend the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * with address and length for verification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static int atmel_read(struct atmel_captouch_device *capdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u8 reg, u8 *data, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct i2c_client *client = capdev->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct i2c_msg msg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (len > sizeof(capdev->xfer_buf) - 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) capdev->xfer_buf[0] = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) capdev->xfer_buf[1] = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) msg[0].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) msg[0].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) msg[0].buf = capdev->xfer_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) msg[0].len = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) msg[1].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) msg[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) msg[1].buf = capdev->xfer_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) msg[1].len = len + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) err = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (err != ARRAY_SIZE(msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return err < 0 ? err : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (capdev->xfer_buf[0] != reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) "I2C read error: register address does not match (%#02x vs %02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) capdev->xfer_buf[0], reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return -ECOMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) memcpy(data, &capdev->xfer_buf[2], len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Handle interrupt and report the key changes to the input system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Multi-touch can be supported; however, it really depends on whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * the device can multi-touch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static irqreturn_t atmel_captouch_isr(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct atmel_captouch_device *capdev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct device *dev = &capdev->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u8 new_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u8 changed_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) error = atmel_read(capdev, REG_KEY_STATE, &new_btn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) dev_err(dev, "failed to read button state: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) dev_dbg(dev, "%s: button state %#02x\n", __func__, new_btn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) changed_btn = new_btn ^ capdev->prev_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) capdev->prev_btn = new_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) for (i = 0; i < capdev->num_btn; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (changed_btn & BIT(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) input_report_key(capdev->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) capdev->keycodes[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) new_btn & BIT(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) input_sync(capdev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return IRQ_HANDLED;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Probe function to setup the device, input system and interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int atmel_captouch_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct atmel_captouch_device *capdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) I2C_FUNC_SMBUS_BYTE_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) I2C_FUNC_SMBUS_WORD_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) I2C_FUNC_SMBUS_I2C_BLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_err(dev, "needed i2c functionality is not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return -EINVAL;
^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) capdev = devm_kzalloc(dev, sizeof(*capdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!capdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) capdev->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) err = atmel_read(capdev, REG_KEY_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) &capdev->prev_btn, sizeof(capdev->prev_btn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) dev_err(dev, "failed to read initial button state: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) capdev->input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (!capdev->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dev_err(dev, "failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -ENOMEM;
^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) capdev->input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) capdev->input->id.product = 0x880A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) capdev->input->id.version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) capdev->input->name = "ATMegaXX Capacitive Button Controller";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) __set_bit(EV_KEY, capdev->input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) dev_err(dev, "failed to find matching node in device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (of_property_read_bool(node, "autorepeat"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) __set_bit(EV_REP, capdev->input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) capdev->num_btn = of_property_count_u32_elems(node, "linux,keymap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (capdev->num_btn > MAX_NUM_OF_BUTTONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) capdev->num_btn = MAX_NUM_OF_BUTTONS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) err = of_property_read_u32_array(node, "linux,keycodes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) capdev->keycodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) capdev->num_btn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) "failed to read linux,keycode property: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) for (i = 0; i < capdev->num_btn; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) __set_bit(capdev->keycodes[i], capdev->input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) capdev->input->keycode = capdev->keycodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) capdev->input->keycodesize = sizeof(capdev->keycodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) capdev->input->keycodemax = capdev->num_btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) err = input_register_device(capdev->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) err = devm_request_threaded_irq(dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) NULL, atmel_captouch_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) "atmel_captouch", capdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) dev_err(dev, "failed to request irq %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) client->irq, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static const struct of_device_id atmel_captouch_of_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .compatible = "atmel,captouch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) MODULE_DEVICE_TABLE(of, atmel_captouch_of_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static const struct i2c_device_id atmel_captouch_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) { "atmel_captouch", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_DEVICE_TABLE(i2c, atmel_captouch_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static struct i2c_driver atmel_captouch_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .probe = atmel_captouch_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .id_table = atmel_captouch_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .name = "atmel_captouch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .of_match_table = of_match_ptr(atmel_captouch_of_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) module_i2c_driver(atmel_captouch_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_AUTHOR("Hung-yu Wu <hywu@google.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_DESCRIPTION("Atmel ATmegaXX Capacitance Touch Sensor I2C Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_LICENSE("GPL v2");