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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * DRV2665 haptics driver family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Dan Murphy <dmurphy@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright: (C) 2015 Texas Instruments, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* Contol registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define DRV2665_STATUS	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define DRV2665_CTRL_1	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DRV2665_CTRL_2	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DRV2665_FIFO	0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /* Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DRV2665_FIFO_FULL		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DRV2665_FIFO_EMPTY		BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* Control 1 Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DRV2665_25_VPP_GAIN		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DRV2665_50_VPP_GAIN		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define DRV2665_75_VPP_GAIN		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DRV2665_100_VPP_GAIN		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DRV2665_DIGITAL_IN		0xfc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define DRV2665_ANALOG_IN		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* Control 2 Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define DRV2665_BOOST_EN		BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define DRV2665_STANDBY			BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define DRV2665_DEV_RST			BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define DRV2665_5_MS_IDLE_TOUT		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define DRV2665_10_MS_IDLE_TOUT		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define DRV2665_15_MS_IDLE_TOUT		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define DRV2665_20_MS_IDLE_TOUT		0x0c
^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 drv2665_data -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @input_dev - Pointer to the input device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @client - Pointer to the I2C client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @regmap - Register map of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @work - Work item used to off load the enable/disable of the vibration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @regulator - Pointer to the regulator for the IC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct drv2665_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct regulator *regulator;
^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) /* 8kHz Sine wave to stream to the FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static const u8 drv2665_sine_wave_form[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	0x00, 0x10, 0x20, 0x2e, 0x3c, 0x48, 0x53, 0x5b, 0x61, 0x65, 0x66,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	0x65, 0x61, 0x5b, 0x53, 0x48, 0x3c, 0x2e, 0x20, 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	0x00, 0xf0, 0xe0, 0xd2, 0xc4, 0xb8, 0xad, 0xa5, 0x9f, 0x9b, 0x9a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	0x9b, 0x9f, 0xa5, 0xad, 0xb8, 0xc4, 0xd2, 0xe0, 0xf0, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static const struct reg_default drv2665_reg_defs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	{ DRV2665_STATUS, 0x02 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	{ DRV2665_CTRL_1, 0x28 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	{ DRV2665_CTRL_2, 0x40 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	{ DRV2665_FIFO, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static void drv2665_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct drv2665_data *haptics =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				container_of(work, struct drv2665_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned int read_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	error = regmap_read(haptics->regmap, DRV2665_STATUS, &read_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		dev_err(&haptics->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			"Failed to read status: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (read_buf & DRV2665_FIFO_EMPTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		error = regmap_bulk_write(haptics->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					  DRV2665_FIFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 					  drv2665_sine_wave_form,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					  ARRAY_SIZE(drv2665_sine_wave_form));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			dev_err(&haptics->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				"Failed to write FIFO: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int drv2665_haptics_play(struct input_dev *input, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct drv2665_data *haptics = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	schedule_work(&haptics->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void drv2665_close(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct drv2665_data *haptics = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	cancel_work_sync(&haptics->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	error = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				   DRV2665_STANDBY, DRV2665_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		dev_err(&haptics->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			"Failed to enter standby mode: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static const struct reg_sequence drv2665_init_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	{ DRV2665_CTRL_2, 0 | DRV2665_10_MS_IDLE_TOUT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	{ DRV2665_CTRL_1, DRV2665_25_VPP_GAIN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int drv2665_init(struct drv2665_data *haptics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	error = regmap_register_patch(haptics->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				      drv2665_init_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				      ARRAY_SIZE(drv2665_init_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		dev_err(&haptics->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			"Failed to write init registers: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return 0;
^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) static const struct regmap_config drv2665_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.max_register = DRV2665_FIFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.reg_defaults = drv2665_reg_defs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.num_reg_defaults = ARRAY_SIZE(drv2665_reg_defs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.cache_type = REGCACHE_NONE,
^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) static int drv2665_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			 const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct drv2665_data *haptics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!haptics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	haptics->regulator = devm_regulator_get(&client->dev, "vbat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (IS_ERR(haptics->regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		error = PTR_ERR(haptics->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			"unable to get regulator, error: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	haptics->input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (!haptics->input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dev_err(&client->dev, "Failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	haptics->input_dev->name = "drv2665:haptics";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	haptics->input_dev->dev.parent = client->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	haptics->input_dev->close = drv2665_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	input_set_drvdata(haptics->input_dev, haptics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	input_set_capability(haptics->input_dev, EV_FF, FF_RUMBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	error = input_ff_create_memless(haptics->input_dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					drv2665_haptics_play);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		dev_err(&client->dev, "input_ff_create() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return error;
^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) 	INIT_WORK(&haptics->work, drv2665_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	haptics->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	i2c_set_clientdata(client, haptics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	haptics->regmap = devm_regmap_init_i2c(client, &drv2665_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (IS_ERR(haptics->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		error = PTR_ERR(haptics->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		dev_err(&client->dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	error = drv2665_init(haptics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		dev_err(&client->dev, "Device init failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	error = input_register_device(haptics->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		dev_err(&client->dev, "couldn't register input device: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int __maybe_unused drv2665_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct drv2665_data *haptics = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	mutex_lock(&haptics->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (haptics->input_dev->users) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 					 DRV2665_STANDBY, DRV2665_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			dev_err(dev, "Failed to set standby mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			regulator_disable(haptics->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			goto out;
^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) 		ret = regulator_disable(haptics->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			dev_err(dev, "Failed to disable regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			regmap_update_bits(haptics->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 					   DRV2665_CTRL_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					   DRV2665_STANDBY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	mutex_unlock(&haptics->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int __maybe_unused drv2665_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct drv2665_data *haptics = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	mutex_lock(&haptics->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (haptics->input_dev->users) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		ret = regulator_enable(haptics->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			dev_err(dev, "Failed to enable regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			goto out;
^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) 		ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 					 DRV2665_STANDBY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			dev_err(dev, "Failed to unset standby mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			regulator_disable(haptics->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	mutex_unlock(&haptics->input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static SIMPLE_DEV_PM_OPS(drv2665_pm_ops, drv2665_suspend, drv2665_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static const struct i2c_device_id drv2665_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	{ "drv2665", 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) MODULE_DEVICE_TABLE(i2c, drv2665_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static const struct of_device_id drv2665_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	{ .compatible = "ti,drv2665", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) MODULE_DEVICE_TABLE(of, drv2665_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static struct i2c_driver drv2665_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.probe		= drv2665_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		.name	= "drv2665-haptics",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		.of_match_table = of_match_ptr(drv2665_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		.pm	= &drv2665_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.id_table = drv2665_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) module_i2c_driver(drv2665_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_DESCRIPTION("TI DRV2665 haptics driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>");