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)  * Copyright (C) ST-Ericsson SA 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/irqdomain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/tc3589x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * enum tc3589x_version - indicates the TC3589x version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) enum tc3589x_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	TC3589X_TC35890,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	TC3589X_TC35892,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	TC3589X_TC35893,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	TC3589X_TC35894,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	TC3589X_TC35895,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	TC3589X_TC35896,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	TC3589X_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define TC3589x_CLKMODE_MODCTL_SLEEP		0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define TC3589x_CLKMODE_MODCTL_OPERATION	(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * tc3589x_reg_read() - read a single TC3589x register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * @tc3589x:	Device to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @reg:	Register to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) int tc3589x_reg_read(struct tc3589x *tc3589x, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ret = i2c_smbus_read_byte_data(tc3589x->i2c, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		dev_err(tc3589x->dev, "failed to read reg %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) EXPORT_SYMBOL_GPL(tc3589x_reg_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * tc3589x_reg_write() - write a single TC3589x register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @tc3589x:	Device to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * @reg:	Register to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @data:	Value to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) int tc3589x_reg_write(struct tc3589x *tc3589x, u8 reg, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ret = i2c_smbus_write_byte_data(tc3589x->i2c, reg, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		dev_err(tc3589x->dev, "failed to write reg %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) EXPORT_SYMBOL_GPL(tc3589x_reg_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * tc3589x_block_read() - read multiple TC3589x registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @tc3589x:	Device to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @reg:	First register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @length:	Number of registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @values:	Buffer to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) int tc3589x_block_read(struct tc3589x *tc3589x, u8 reg, u8 length, u8 *values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ret = i2c_smbus_read_i2c_block_data(tc3589x->i2c, reg, length, values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		dev_err(tc3589x->dev, "failed to read regs %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) EXPORT_SYMBOL_GPL(tc3589x_block_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * tc3589x_block_write() - write multiple TC3589x registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @tc3589x:	Device to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @reg:	First register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @length:	Number of registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @values:	Values to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int tc3589x_block_write(struct tc3589x *tc3589x, u8 reg, u8 length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			const u8 *values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ret = i2c_smbus_write_i2c_block_data(tc3589x->i2c, reg, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					     values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev_err(tc3589x->dev, "failed to write regs %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) EXPORT_SYMBOL_GPL(tc3589x_block_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @tc3589x:	Device to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @reg:	Register to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @mask:	Mask of bits to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @val:	Value to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	mutex_lock(&tc3589x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	ret = tc3589x_reg_read(tc3589x, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ret |= val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ret = tc3589x_reg_write(tc3589x, reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	mutex_unlock(&tc3589x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) EXPORT_SYMBOL_GPL(tc3589x_set_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static struct resource gpio_resources[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.start	= TC3589x_INT_GPIIRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		.end	= TC3589x_INT_GPIIRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		.flags	= IORESOURCE_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	},
^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) static struct resource keypad_resources[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		.start  = TC3589x_INT_KBDIRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		.end    = TC3589x_INT_KBDIRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		.flags  = IORESOURCE_IRQ,
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static const struct mfd_cell tc3589x_dev_gpio[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		.name		= "tc3589x-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		.num_resources	= ARRAY_SIZE(gpio_resources),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		.resources	= &gpio_resources[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.of_compatible	= "toshiba,tc3589x-gpio",
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static const struct mfd_cell tc3589x_dev_keypad[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		.name           = "tc3589x-keypad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.num_resources  = ARRAY_SIZE(keypad_resources),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		.resources      = &keypad_resources[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		.of_compatible	= "toshiba,tc3589x-keypad",
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static irqreturn_t tc3589x_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct tc3589x *tc3589x = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	while (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		int bit = __ffs(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		int virq = irq_find_mapping(tc3589x->domain, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		handle_nested_irq(virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		status &= ~(1 << bit);
^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) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * A dummy read or write (to any register) appears to be necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * have the last interrupt clear (for example, GPIO IC write) take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * effect. In such a case, recheck for any interrupt which is still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int tc3589x_irq_map(struct irq_domain *d, unsigned int virq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				irq_hw_number_t hwirq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct tc3589x *tc3589x = d->host_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	irq_set_chip_data(virq, tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	irq_set_chip_and_handler(virq, &dummy_irq_chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				handle_edge_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	irq_set_nested_thread(virq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	irq_set_noprobe(virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return 0;
^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) static void tc3589x_irq_unmap(struct irq_domain *d, unsigned int virq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	irq_set_chip_and_handler(virq, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	irq_set_chip_data(virq, NULL);
^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 const struct irq_domain_ops tc3589x_irq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.map    = tc3589x_irq_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.unmap  = tc3589x_irq_unmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	.xlate  = irq_domain_xlate_onecell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int tc3589x_irq_init(struct tc3589x *tc3589x, struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	tc3589x->domain = irq_domain_add_simple(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		np, TC3589x_NR_INTERNAL_IRQS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		&tc3589x_irq_ops, tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!tc3589x->domain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		dev_err(tc3589x->dev, "Failed to create irqdomain\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -ENOSYS;
^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) 	return 0;
^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) static int tc3589x_chip_init(struct tc3589x *tc3589x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	int manf, ver, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (manf < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return manf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (ver < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (manf != TC3589x_MANFCODE_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
^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) 	 * Put everything except the IRQ module into reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 * also spare the GPIO module for any pin initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 * done during pre-kernel boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				TC3589x_RSTCTRL_TIMRST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				| TC3589x_RSTCTRL_ROTRST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				| TC3589x_RSTCTRL_KBDRST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/* Clear the reset interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1);
^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 int tc3589x_device_init(struct tc3589x *tc3589x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	unsigned int blocks = tc3589x->pdata->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (blocks & TC3589x_BLOCK_GPIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				      ARRAY_SIZE(tc3589x_dev_gpio), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				      0, tc3589x->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			dev_err(tc3589x->dev, "failed to add gpio child\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		dev_info(tc3589x->dev, "added gpio block\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (blocks & TC3589x_BLOCK_KEYPAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				      ARRAY_SIZE(tc3589x_dev_keypad), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				      0, tc3589x->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			dev_err(tc3589x->dev, "failed to keypad child\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		dev_info(tc3589x->dev, "added keypad block\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static const struct of_device_id tc3589x_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* Legacy compatible string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	{ .compatible = "tc3589x", .data = (void *) TC3589X_UNKNOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	{ .compatible = "toshiba,tc35890", .data = (void *) TC3589X_TC35890 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	{ .compatible = "toshiba,tc35892", .data = (void *) TC3589X_TC35892 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	{ .compatible = "toshiba,tc35893", .data = (void *) TC3589X_TC35893 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	{ .compatible = "toshiba,tc35894", .data = (void *) TC3589X_TC35894 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	{ .compatible = "toshiba,tc35895", .data = (void *) TC3589X_TC35895 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	{ .compatible = "toshiba,tc35896", .data = (void *) TC3589X_TC35896 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	{ }
^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(of, tc3589x_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static struct tc3589x_platform_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) tc3589x_of_probe(struct device *dev, enum tc3589x_version *version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct tc3589x_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	const struct of_device_id *of_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	of_id = of_match_device(tc3589x_match, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (!of_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	*version = (enum tc3589x_version) of_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	for_each_child_of_node(np, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		if (of_device_is_compatible(child, "toshiba,tc3589x-gpio"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			pdata->block |= TC3589x_BLOCK_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (of_device_is_compatible(child, "toshiba,tc3589x-keypad"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			pdata->block |= TC3589x_BLOCK_KEYPAD;
^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) 	return pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int tc3589x_probe(struct i2c_client *i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				   const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct device_node *np = i2c->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct tc3589x_platform_data *pdata = dev_get_platdata(&i2c->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct tc3589x *tc3589x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	enum tc3589x_version version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		pdata = tc3589x_of_probe(&i2c->dev, &version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (IS_ERR(pdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			dev_err(&i2c->dev, "No platform data or DT found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			return PTR_ERR(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		/* When not probing from device tree we have this ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		version = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 				     | I2C_FUNC_SMBUS_I2C_BLOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	tc3589x = devm_kzalloc(&i2c->dev, sizeof(struct tc3589x),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (!tc3589x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	mutex_init(&tc3589x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	tc3589x->dev = &i2c->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	tc3589x->i2c = i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	tc3589x->pdata = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	case TC3589X_TC35893:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	case TC3589X_TC35895:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	case TC3589X_TC35896:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		tc3589x->num_gpio = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	case TC3589X_TC35890:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	case TC3589X_TC35892:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	case TC3589X_TC35894:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	case TC3589X_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		tc3589x->num_gpio = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	i2c_set_clientdata(i2c, tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	ret = tc3589x_chip_init(tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	ret = tc3589x_irq_init(tc3589x, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				   "tc3589x", tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	ret = tc3589x_device_init(tc3589x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		dev_err(tc3589x->dev, "failed to add child devices\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static int tc3589x_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	struct tc3589x *tc3589x = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	mfd_remove_devices(tc3589x->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int tc3589x_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	struct tc3589x *tc3589x = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct i2c_client *client = tc3589x->i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	/* put the system to sleep mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (!device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 				TC3589x_CLKMODE_MODCTL_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int tc3589x_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	struct tc3589x *tc3589x = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	struct i2c_client *client = tc3589x->i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/* enable the system into operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (!device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 				TC3589x_CLKMODE_MODCTL_OPERATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend, tc3589x_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static const struct i2c_device_id tc3589x_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	{ "tc35890", TC3589X_TC35890 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	{ "tc35892", TC3589X_TC35892 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	{ "tc35893", TC3589X_TC35893 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	{ "tc35894", TC3589X_TC35894 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	{ "tc35895", TC3589X_TC35895 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	{ "tc35896", TC3589X_TC35896 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	{ "tc3589x", TC3589X_UNKNOWN },
^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) MODULE_DEVICE_TABLE(i2c, tc3589x_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static struct i2c_driver tc3589x_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		.name	= "tc3589x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		.pm	= &tc3589x_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		.of_match_table = of_match_ptr(tc3589x_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	.probe		= tc3589x_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	.remove		= tc3589x_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	.id_table	= tc3589x_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static int __init tc3589x_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	return i2c_add_driver(&tc3589x_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) subsys_initcall(tc3589x_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static void __exit tc3589x_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	i2c_del_driver(&tc3589x_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) module_exit(tc3589x_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) MODULE_DESCRIPTION("TC3589x MFD core driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");