Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Melfas MMS114/MMS152 touchscreen device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (c) 2012 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Author: Joonyoung Shim <jy0922.shim@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* Write only registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define MMS114_MODE_CONTROL		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define MMS114_OPERATION_MODE_MASK	0xE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define MMS114_ACTIVE			BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MMS114_XY_RESOLUTION_H		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define MMS114_X_RESOLUTION		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define MMS114_Y_RESOLUTION		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MMS114_CONTACT_THRESHOLD	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define MMS114_MOVING_THRESHOLD		0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /* Read only registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define MMS114_PACKET_SIZE		0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define MMS114_INFORMATION		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define MMS114_TSP_REV			0xF0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define MMS152_FW_REV			0xE1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MMS152_COMPAT_GROUP		0xF2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* Minimum delay time is 50us between stop and start signal of i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define MMS114_I2C_DELAY		50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* 200ms needs after power on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define MMS114_POWERON_DELAY		200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Touchscreen absolute values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define MMS114_MAX_AREA			0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define MMS114_MAX_TOUCH		10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define MMS114_PACKET_NUM		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /* Touch type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define MMS114_TYPE_NONE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define MMS114_TYPE_TOUCHSCREEN		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define MMS114_TYPE_TOUCHKEY		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) enum mms_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	TYPE_MMS114	= 114,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	TYPE_MMS152	= 152,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	TYPE_MMS345L	= 345,
^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) struct mms114_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct i2c_client	*client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct input_dev	*input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct regulator	*core_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct regulator	*io_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct touchscreen_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	enum mms_type		type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int		contact_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int		moving_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* Use cache data for mode control register(write only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u8			cache_mode_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) struct mms114_touch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u8 id:4, reserved_bit4:1, type:2, pressed:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u8 x_hi:4, y_hi:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	u8 x_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u8 y_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u8 width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u8 strength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u8 reserved[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static int __mms114_read_reg(struct mms114_data *data, unsigned int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			     unsigned int len, u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct i2c_msg xfer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	u8 buf = reg & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (reg <= MMS114_MODE_CONTROL && reg + len > MMS114_MODE_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Write register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	xfer[0].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	xfer[0].flags = client->flags & I2C_M_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	xfer[0].len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	xfer[0].buf = &buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* Read data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	xfer[1].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	xfer[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	xfer[1].len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	xfer[1].buf = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	error = i2c_transfer(client->adapter, xfer, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (error != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			"%s: i2c transfer failed (%d)\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return error < 0 ? error : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	udelay(MMS114_I2C_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^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) static int mms114_read_reg(struct mms114_data *data, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (reg == MMS114_MODE_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return data->cache_mode_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	error = __mms114_read_reg(data, reg, 1, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return error < 0 ? error : val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int mms114_write_reg(struct mms114_data *data, unsigned int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			    unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u8 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	buf[0] = reg & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	buf[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	error = i2c_master_send(client, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (error != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			"%s: i2c send failed (%d)\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return error < 0 ? error : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	udelay(MMS114_I2C_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (reg == MMS114_MODE_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		data->cache_mode_control = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct input_dev *input_dev = data->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	unsigned int y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (touch->id > MMS114_MAX_TOUCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		dev_err(&client->dev, "Wrong touch id (%d)\n", touch->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (touch->type != MMS114_TYPE_TOUCHSCREEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		dev_err(&client->dev, "Wrong touch type (%d)\n", touch->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	id = touch->id - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	x = touch->x_lo | touch->x_hi << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	y = touch->y_lo | touch->y_hi << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		"id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		id, touch->type, touch->pressed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		x, y, touch->width, touch->strength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	input_mt_slot(input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (touch->pressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		touchscreen_report_pos(input_dev, &data->props, x, y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static irqreturn_t mms114_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct mms114_data *data = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct input_dev *input_dev = data->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct mms114_touch touch[MMS114_MAX_TOUCH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	int packet_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int touch_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	mutex_lock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!input_dev->users) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	packet_size = mms114_read_reg(data, MMS114_PACKET_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (packet_size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	touch_size = packet_size / MMS114_PACKET_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	error = __mms114_read_reg(data, MMS114_INFORMATION, packet_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			(u8 *)touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	for (index = 0; index < touch_size; index++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		mms114_process_mt(data, touch + index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	input_mt_report_pointer_emulation(data->input_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	input_sync(data->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int mms114_set_active(struct mms114_data *data, bool active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	val = mms114_read_reg(data, MMS114_MODE_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	val &= ~MMS114_OPERATION_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	/* If active is false, sleep mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		val |= MMS114_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return mms114_write_reg(data, MMS114_MODE_CONTROL, val);
^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) static int mms114_get_version(struct mms114_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct device *dev = &data->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	u8 buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	switch (data->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	case TYPE_MMS345L:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			 buf[0], buf[1], buf[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	case TYPE_MMS152:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf);
^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) 		group = i2c_smbus_read_byte_data(data->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 						  MMS152_COMPAT_GROUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		if (group < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			 buf[0], buf[1], buf[2], group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	case TYPE_MMS114:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			 buf[0], buf[1], buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		break;
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int mms114_setup_regs(struct mms114_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	const struct touchscreen_properties *props = &data->props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	error = mms114_get_version(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* Only MMS114 has configuration and power on registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (data->type != TYPE_MMS114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	error = mms114_set_active(data, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	val = (props->max_x >> 8) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	val |= ((props->max_y >> 8) & 0xf) << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	error = mms114_write_reg(data, MMS114_XY_RESOLUTION_H, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	val = props->max_x & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	error = mms114_write_reg(data, MMS114_X_RESOLUTION, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	val = props->max_x & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	error = mms114_write_reg(data, MMS114_Y_RESOLUTION, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (data->contact_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		error = mms114_write_reg(data, MMS114_CONTACT_THRESHOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				data->contact_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (data->moving_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		error = mms114_write_reg(data, MMS114_MOVING_THRESHOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				data->moving_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int mms114_start(struct mms114_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	error = regulator_enable(data->core_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		dev_err(&client->dev, "Failed to enable avdd: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	error = regulator_enable(data->io_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		dev_err(&client->dev, "Failed to enable vdd: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		regulator_disable(data->core_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	msleep(MMS114_POWERON_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	error = mms114_setup_regs(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		regulator_disable(data->io_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		regulator_disable(data->core_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static void mms114_stop(struct mms114_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	error = regulator_disable(data->io_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		dev_warn(&client->dev, "Failed to disable vdd: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	error = regulator_disable(data->core_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		dev_warn(&client->dev, "Failed to disable avdd: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static int mms114_input_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	struct mms114_data *data = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return mms114_start(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static void mms114_input_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct mms114_data *data = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	mms114_stop(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int mms114_parse_legacy_bindings(struct mms114_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct device *dev = &data->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct touchscreen_properties *props = &data->props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (device_property_read_u32(dev, "x-size", &props->max_x)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		dev_dbg(dev, "failed to get legacy x-size property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (device_property_read_u32(dev, "y-size", &props->max_y)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		dev_dbg(dev, "failed to get legacy y-size property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	device_property_read_u32(dev, "contact-threshold",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 				&data->contact_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	device_property_read_u32(dev, "moving-threshold",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 				&data->moving_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (device_property_read_bool(dev, "x-invert"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		props->invert_x = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (device_property_read_bool(dev, "y-invert"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		props->invert_y = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	props->swap_x_y = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static int mms114_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 				  const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct mms114_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	const void *match_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		dev_err(&client->dev, "Not supported I2C adapter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	data = devm_kzalloc(&client->dev, sizeof(struct mms114_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (!data || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		dev_err(&client->dev, "Failed to allocate memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	data->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	match_data = device_get_match_data(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (!match_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	data->type = (enum mms_type)match_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			     0, MMS114_MAX_AREA, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	touchscreen_parse_properties(input_dev, true, &data->props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (!data->props.max_x || !data->props.max_y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			"missing X/Y size properties, trying legacy bindings\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		error = mms114_parse_legacy_bindings(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		input_set_abs_params(input_dev, ABS_MT_POSITION_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 				     0, data->props.max_x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 				     0, data->props.max_y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (data->type == TYPE_MMS114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		 * The firmware handles movement and pressure fuzz, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		 * don't duplicate that in software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		data->moving_threshold = input_abs_get_fuzz(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 							    ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		data->contact_threshold = input_abs_get_fuzz(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 							     ABS_MT_PRESSURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	input_dev->name = devm_kasprintf(&client->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 					 "MELFAS MMS%d Touchscreen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 					 data->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (!input_dev->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	input_dev->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	input_dev->open = mms114_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	input_dev->close = mms114_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	error = input_mt_init_slots(input_dev, MMS114_MAX_TOUCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				    INPUT_MT_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	input_set_drvdata(input_dev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	data->core_reg = devm_regulator_get(&client->dev, "avdd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (IS_ERR(data->core_reg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		error = PTR_ERR(data->core_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			"Unable to get the Core regulator (%d)\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	data->io_reg = devm_regulator_get(&client->dev, "vdd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (IS_ERR(data->io_reg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		error = PTR_ERR(data->io_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			"Unable to get the IO regulator (%d)\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	error = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 					  NULL, mms114_interrupt, IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 					  dev_name(&client->dev), data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		dev_err(&client->dev, "Failed to register interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	error = input_register_device(data->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		dev_err(&client->dev, "Failed to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static int __maybe_unused mms114_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	struct mms114_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	struct input_dev *input_dev = data->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	/* Release all touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	for (id = 0; id < MMS114_MAX_TOUCH; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		input_mt_slot(input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		input_mt_report_slot_inactive(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	input_mt_report_pointer_emulation(input_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	mutex_lock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if (input_dev->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		mms114_stop(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static int __maybe_unused mms114_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	struct mms114_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	struct input_dev *input_dev = data->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	mutex_lock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	if (input_dev->users) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		error = mms114_start(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static SIMPLE_DEV_PM_OPS(mms114_pm_ops, mms114_suspend, mms114_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static const struct i2c_device_id mms114_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	{ "mms114", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) MODULE_DEVICE_TABLE(i2c, mms114_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static const struct of_device_id mms114_dt_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		.compatible = "melfas,mms114",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		.data = (void *)TYPE_MMS114,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		.compatible = "melfas,mms152",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		.data = (void *)TYPE_MMS152,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		.compatible = "melfas,mms345l",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		.data = (void *)TYPE_MMS345L,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) MODULE_DEVICE_TABLE(of, mms114_dt_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static struct i2c_driver mms114_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		.name	= "mms114",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		.pm	= &mms114_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		.of_match_table = of_match_ptr(mms114_dt_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	.probe		= mms114_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	.id_table	= mms114_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) module_i2c_driver(mms114_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) MODULE_LICENSE("GPL v2");