^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) * TM2 touchkey device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2005 Phil Blundell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2016 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author: Beomho Seo <beomho.seo@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Author: Jaechul Lee <jcsing.lee@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/device.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/interrupt.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/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define ARIES_TOUCHKEY_CMD_LED_ON 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define ARIES_TOUCHKEY_CMD_LED_OFF 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define TM2_TOUCHKEY_CMD_LED_ON 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define TM2_TOUCHKEY_CMD_LED_OFF 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define TM2_TOUCHKEY_BIT_KEYCODE GENMASK(2, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct touchkey_variant {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u8 keycode_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u8 base_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u8 cmd_led_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 cmd_led_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) bool no_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) bool fixed_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct tm2_touchkey_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct led_classdev led_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct regulator *vdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct regulator_bulk_data regulators[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) const struct touchkey_variant *variant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 keycodes[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int num_keycodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const struct touchkey_variant tm2_touchkey_variant = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .keycode_reg = 0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .base_reg = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static const struct touchkey_variant midas_touchkey_variant = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .keycode_reg = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .base_reg = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static struct touchkey_variant aries_touchkey_variant = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .no_reg = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .fixed_regulator = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .cmd_led_on = ARIES_TOUCHKEY_CMD_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .cmd_led_off = ARIES_TOUCHKEY_CMD_LED_OFF,
^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) static const struct touchkey_variant tc360_touchkey_variant = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .keycode_reg = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .base_reg = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .fixed_regulator = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct tm2_touchkey_data *touchkey =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) container_of(led_dev, struct tm2_touchkey_data, led_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u32 volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) u8 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (brightness == LED_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) volt = TM2_TOUCHKEY_LED_VOLTAGE_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) data = touchkey->variant->cmd_led_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) volt = TM2_TOUCHKEY_LED_VOLTAGE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) data = touchkey->variant->cmd_led_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!touchkey->variant->fixed_regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) regulator_set_voltage(touchkey->vdd, volt, volt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return touchkey->variant->no_reg ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) i2c_smbus_write_byte(touchkey->client, data) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) i2c_smbus_write_byte_data(touchkey->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) touchkey->variant->base_reg, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) touchkey->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* waiting for device initialization, at least 150ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) msleep(150);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void tm2_touchkey_power_disable(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct tm2_touchkey_data *touchkey = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) touchkey->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct tm2_touchkey_data *touchkey = devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (touchkey->variant->no_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) data = i2c_smbus_read_byte(touchkey->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) data = i2c_smbus_read_byte_data(touchkey->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) touchkey->variant->keycode_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (data < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dev_err(&touchkey->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "failed to read i2c data: %d\n", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) index = (data & TM2_TOUCHKEY_BIT_KEYCODE) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (index < 0 || index >= touchkey->num_keycodes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_warn(&touchkey->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) "invalid keycode index %d\n", index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (data & TM2_TOUCHKEY_BIT_PRESS_EV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) for (i = 0; i < touchkey->num_keycodes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) input_report_key(touchkey->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) touchkey->keycodes[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) input_report_key(touchkey->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) touchkey->keycodes[index], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) input_sync(touchkey->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (touchkey->variant->fixed_regulator &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) data & TM2_TOUCHKEY_BIT_PRESS_EV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* touch turns backlight on, so make sure we're in sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (touchkey->led_dev.brightness == LED_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) tm2_touchkey_led_brightness_set(&touchkey->led_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int tm2_touchkey_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct device_node *np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct tm2_touchkey_data *touchkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_err(&client->dev, "incompatible I2C adapter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -EIO;
^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) touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!touchkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) touchkey->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) i2c_set_clientdata(client, touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) touchkey->variant = of_device_get_match_data(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) touchkey->regulators[0].supply = "vcc";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) touchkey->regulators[1].supply = "vdd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) error = devm_regulator_bulk_get(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ARRAY_SIZE(touchkey->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) touchkey->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dev_err(&client->dev, "failed to get regulators: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* Save VDD for easy access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) touchkey->vdd = touchkey->regulators[1].consumer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) touchkey->num_keycodes = of_property_read_variable_u32_array(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) "linux,keycodes", touchkey->keycodes, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ARRAY_SIZE(touchkey->keycodes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (touchkey->num_keycodes <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* default keycodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) touchkey->keycodes[0] = KEY_PHONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) touchkey->keycodes[1] = KEY_BACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) touchkey->num_keycodes = 2;
^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) error = tm2_touchkey_power_enable(touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) dev_err(&client->dev, "failed to power up device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) error = devm_add_action_or_reset(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) tm2_touchkey_power_disable, touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) "failed to install poweroff handler: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) touchkey->input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!touchkey->input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) dev_err(&client->dev, "failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return -ENOMEM;
^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) touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) touchkey->input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) for (i = 0; i < touchkey->num_keycodes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) input_set_capability(touchkey->input_dev, EV_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) touchkey->keycodes[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) error = input_register_device(touchkey->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) "failed to register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) error = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) NULL, tm2_touchkey_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) TM2_TOUCHKEY_DEV_NAME, touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) "failed to request threaded irq: %d\n", 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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* led device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) touchkey->led_dev.name = TM2_TOUCHKEY_DEV_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) touchkey->led_dev.brightness = LED_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) touchkey->led_dev.max_brightness = LED_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) touchkey->led_dev.brightness_set_blocking =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) tm2_touchkey_led_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) error = devm_led_classdev_register(&client->dev, &touchkey->led_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) "failed to register touchkey led: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (touchkey->variant->fixed_regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) tm2_touchkey_led_brightness_set(&touchkey->led_dev, LED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static int __maybe_unused tm2_touchkey_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) tm2_touchkey_power_disable(touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int __maybe_unused tm2_touchkey_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ret = tm2_touchkey_power_enable(touchkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) dev_err(dev, "failed to enable power: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) tm2_touchkey_suspend, tm2_touchkey_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static const struct i2c_device_id tm2_touchkey_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) { TM2_TOUCHKEY_DEV_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static const struct of_device_id tm2_touchkey_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .compatible = "cypress,tm2-touchkey",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .data = &tm2_touchkey_variant,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .compatible = "cypress,midas-touchkey",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .data = &midas_touchkey_variant,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .compatible = "cypress,aries-touchkey",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .data = &aries_touchkey_variant,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .compatible = "coreriver,tc360-touchkey",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .data = &tc360_touchkey_variant,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static struct i2c_driver tm2_touchkey_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .name = TM2_TOUCHKEY_DEV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .pm = &tm2_touchkey_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .of_match_table = of_match_ptr(tm2_touchkey_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .probe = tm2_touchkey_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .id_table = tm2_touchkey_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) module_i2c_driver(tm2_touchkey_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) MODULE_AUTHOR("Jaechul Lee <jcsing.lee@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) MODULE_DESCRIPTION("Samsung touchkey driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) MODULE_LICENSE("GPL v2");