xref: /linux/drivers/mfd/mt6370.c (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1b2adf788SChiYuan Huang // SPDX-License-Identifier: GPL-2.0-only
2b2adf788SChiYuan Huang /*
3b2adf788SChiYuan Huang  * Copyright (C) 2022 Richtek Technology Corp.
4b2adf788SChiYuan Huang  *
5b2adf788SChiYuan Huang  * Author: ChiYuan Huang <cy_huang@richtek.com>
6b2adf788SChiYuan Huang  */
7b2adf788SChiYuan Huang 
8b2adf788SChiYuan Huang #include <linux/bits.h>
9b2adf788SChiYuan Huang #include <linux/bitfield.h>
10b2adf788SChiYuan Huang #include <linux/i2c.h>
11b2adf788SChiYuan Huang #include <linux/interrupt.h>
12b2adf788SChiYuan Huang #include <linux/kernel.h>
13b2adf788SChiYuan Huang #include <linux/mfd/core.h>
14b2adf788SChiYuan Huang #include <linux/module.h>
15b2adf788SChiYuan Huang #include <linux/regmap.h>
16b2adf788SChiYuan Huang 
17b2adf788SChiYuan Huang #include "mt6370.h"
18b2adf788SChiYuan Huang 
19b2adf788SChiYuan Huang #define MT6370_REG_DEV_INFO	0x100
20b2adf788SChiYuan Huang #define MT6370_REG_CHG_IRQ1	0x1C0
21b2adf788SChiYuan Huang #define MT6370_REG_CHG_MASK1	0x1E0
22b2adf788SChiYuan Huang #define MT6370_REG_MAXADDR	0x1FF
23b2adf788SChiYuan Huang 
24b2adf788SChiYuan Huang #define MT6370_VENID_MASK	GENMASK(7, 4)
25b2adf788SChiYuan Huang 
26b2adf788SChiYuan Huang #define MT6370_NUM_IRQREGS	16
27b2adf788SChiYuan Huang #define MT6370_USBC_I2CADDR	0x4E
28b2adf788SChiYuan Huang #define MT6370_MAX_ADDRLEN	2
29b2adf788SChiYuan Huang 
30b2adf788SChiYuan Huang #define MT6370_VENID_RT5081	0x8
31b2adf788SChiYuan Huang #define MT6370_VENID_RT5081A	0xA
32b2adf788SChiYuan Huang #define MT6370_VENID_MT6370	0xE
33b2adf788SChiYuan Huang #define MT6370_VENID_MT6371	0xF
34b2adf788SChiYuan Huang #define MT6370_VENID_MT6372P	0x9
35b2adf788SChiYuan Huang #define MT6370_VENID_MT6372CP	0xB
36b2adf788SChiYuan Huang 
37b2adf788SChiYuan Huang static const struct regmap_irq mt6370_irqs[] = {
38b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHGON, 8),
39b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_TREG, 8),
40b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_AICR, 8),
41b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_MIVR, 8),
42b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_PWR_RDY, 8),
43b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FL_CHG_VINOVP, 8),
44b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_VSYSUV, 8),
45b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_VSYSOV, 8),
46b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_VBATOV, 8),
47b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_VINOVPCHG, 8),
48b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TS_BAT_COLD, 8),
49b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TS_BAT_COOL, 8),
50b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TS_BAT_WARM, 8),
51b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TS_BAT_HOT, 8),
52b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TS_STATC, 8),
53b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_FAULT, 8),
54b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_STATC, 8),
55b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_TMR, 8),
56b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_BATABS, 8),
57b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_ADPBAD, 8),
58b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_RVP, 8),
59b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_TSHUTDOWN, 8),
60b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_IINMEAS, 8),
61b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_ICCMEAS, 8),
62b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHGDET_DONE, 8),
63b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_WDTMR, 8),
64b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_SSFINISH, 8),
65b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_RECHG, 8),
66b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_TERM, 8),
67b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHG_IEOC, 8),
68b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_ADC_DONE, 8),
69b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_PUMPX_DONE, 8),
70b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_BST_BATUV, 8),
71b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_BST_MIDOV, 8),
72b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_BST_OLP, 8),
73b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_ATTACH, 8),
74b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DETACH, 8),
75b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_HVDCP_STPDONE, 8),
76b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_HVDCP_VBUSDET_DONE, 8),
77b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_HVDCP_DET, 8),
78b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_CHGDET, 8),
79b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DCDT, 8),
80b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHG_VGOK, 8),
81b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHG_WDTMR, 8),
82b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHG_UC, 8),
83b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHG_OC, 8),
84b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DIRCHG_OV, 8),
85b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OVPCTRL_SWON, 8),
86b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OVPCTRL_UVP_D, 8),
87b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OVPCTRL_UVP, 8),
88b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OVPCTRL_OVP_D, 8),
89b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OVPCTRL_OVP, 8),
90b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED_STRBPIN, 8),
91b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED_TORPIN, 8),
92b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED_TX, 8),
93b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED_LVF, 8),
94b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED2_SHORT, 8),
95b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED1_SHORT, 8),
96b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED2_STRB, 8),
97b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED1_STRB, 8),
98b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(mT6370_IRQ_FLED2_STRB_TO, 8),
99b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED1_STRB_TO, 8),
100b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED2_TOR, 8),
101b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_FLED1_TOR, 8),
102b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_OTP, 8),
103b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_VDDA_OVP, 8),
104b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_VDDA_UV, 8),
105b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_LDO_OC, 8),
106b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_BLED_OCP, 8),
107b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_BLED_OVP, 8),
108b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DSV_VNEG_OCP, 8),
109b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DSV_VPOS_OCP, 8),
110b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DSV_BST_OCP, 8),
111b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DSV_VNEG_SCP, 8),
112b2adf788SChiYuan Huang 	REGMAP_IRQ_REG_LINE(MT6370_IRQ_DSV_VPOS_SCP, 8),
113b2adf788SChiYuan Huang };
114b2adf788SChiYuan Huang 
115b2adf788SChiYuan Huang static const struct regmap_irq_chip mt6370_irq_chip = {
116b2adf788SChiYuan Huang 	.name		= "mt6370-irqs",
117b2adf788SChiYuan Huang 	.status_base	= MT6370_REG_CHG_IRQ1,
118b2adf788SChiYuan Huang 	.mask_base	= MT6370_REG_CHG_MASK1,
119b2adf788SChiYuan Huang 	.num_regs	= MT6370_NUM_IRQREGS,
120b2adf788SChiYuan Huang 	.irqs		= mt6370_irqs,
121b2adf788SChiYuan Huang 	.num_irqs	= ARRAY_SIZE(mt6370_irqs),
122b2adf788SChiYuan Huang };
123b2adf788SChiYuan Huang 
124b2adf788SChiYuan Huang static const struct resource mt6370_regulator_irqs[] = {
125b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_DSV_VPOS_SCP, "db_vpos_scp"),
126b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_DSV_VNEG_SCP, "db_vneg_scp"),
127b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_DSV_BST_OCP, "db_vbst_ocp"),
128b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_DSV_VPOS_OCP, "db_vpos_ocp"),
129b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_DSV_VNEG_OCP, "db_vneg_ocp"),
130b2adf788SChiYuan Huang 	DEFINE_RES_IRQ_NAMED(MT6370_IRQ_LDO_OC, "ldo_oc"),
131b2adf788SChiYuan Huang };
132b2adf788SChiYuan Huang 
133b2adf788SChiYuan Huang static const struct mfd_cell mt6370_devices[] = {
134b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-adc",
135b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-adc"),
136b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-charger",
137b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-charger"),
138b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-flashlight",
139b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-flashlight"),
140b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-indicator",
141b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-indicator"),
142b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-tcpc",
143b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-tcpc"),
144b2adf788SChiYuan Huang 	MFD_CELL_RES("mt6370-regulator", mt6370_regulator_irqs),
145b2adf788SChiYuan Huang };
146b2adf788SChiYuan Huang 
147b2adf788SChiYuan Huang static const struct mfd_cell mt6370_exclusive_devices[] = {
148b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-backlight",
149b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6370-backlight"),
150b2adf788SChiYuan Huang };
151b2adf788SChiYuan Huang 
152b2adf788SChiYuan Huang static const struct mfd_cell mt6372_exclusive_devices[] = {
153b2adf788SChiYuan Huang 	MFD_CELL_OF("mt6370-backlight",
154b2adf788SChiYuan Huang 		    NULL, NULL, 0, 0, "mediatek,mt6372-backlight"),
155b2adf788SChiYuan Huang };
156b2adf788SChiYuan Huang 
mt6370_check_vendor_info(struct device * dev,struct regmap * rmap,int * vid)157b2adf788SChiYuan Huang static int mt6370_check_vendor_info(struct device *dev, struct regmap *rmap,
158b2adf788SChiYuan Huang 				    int *vid)
159b2adf788SChiYuan Huang {
160b2adf788SChiYuan Huang 	unsigned int devinfo;
161b2adf788SChiYuan Huang 	int ret;
162b2adf788SChiYuan Huang 
163b2adf788SChiYuan Huang 	ret = regmap_read(rmap, MT6370_REG_DEV_INFO, &devinfo);
164b2adf788SChiYuan Huang 	if (ret)
165b2adf788SChiYuan Huang 		return ret;
166b2adf788SChiYuan Huang 
167b2adf788SChiYuan Huang 	*vid = FIELD_GET(MT6370_VENID_MASK, devinfo);
168b2adf788SChiYuan Huang 	switch (*vid) {
169b2adf788SChiYuan Huang 	case MT6370_VENID_RT5081:
170b2adf788SChiYuan Huang 	case MT6370_VENID_RT5081A:
171b2adf788SChiYuan Huang 	case MT6370_VENID_MT6370:
172b2adf788SChiYuan Huang 	case MT6370_VENID_MT6371:
173b2adf788SChiYuan Huang 	case MT6370_VENID_MT6372P:
174b2adf788SChiYuan Huang 	case MT6370_VENID_MT6372CP:
175b2adf788SChiYuan Huang 		return 0;
176b2adf788SChiYuan Huang 	default:
177b2adf788SChiYuan Huang 		dev_err(dev, "Unknown Vendor ID 0x%02x\n", devinfo);
178b2adf788SChiYuan Huang 		return -ENODEV;
179b2adf788SChiYuan Huang 	}
180b2adf788SChiYuan Huang }
181b2adf788SChiYuan Huang 
mt6370_regmap_read(void * context,const void * reg_buf,size_t reg_size,void * val_buf,size_t val_size)182b2adf788SChiYuan Huang static int mt6370_regmap_read(void *context, const void *reg_buf,
183b2adf788SChiYuan Huang 			      size_t reg_size, void *val_buf, size_t val_size)
184b2adf788SChiYuan Huang {
185b2adf788SChiYuan Huang 	struct mt6370_info *info = context;
186b2adf788SChiYuan Huang 	const u8 *u8_buf = reg_buf;
187b2adf788SChiYuan Huang 	u8 bank_idx, bank_addr;
188b2adf788SChiYuan Huang 	int ret;
189b2adf788SChiYuan Huang 
190b2adf788SChiYuan Huang 	bank_idx = u8_buf[0];
191b2adf788SChiYuan Huang 	bank_addr = u8_buf[1];
192b2adf788SChiYuan Huang 
193b2adf788SChiYuan Huang 	ret = i2c_smbus_read_i2c_block_data(info->i2c[bank_idx], bank_addr,
194b2adf788SChiYuan Huang 					    val_size, val_buf);
195b2adf788SChiYuan Huang 	if (ret < 0)
196b2adf788SChiYuan Huang 		return ret;
197b2adf788SChiYuan Huang 
198b2adf788SChiYuan Huang 	if (ret != val_size)
199b2adf788SChiYuan Huang 		return -EIO;
200b2adf788SChiYuan Huang 
201b2adf788SChiYuan Huang 	return 0;
202b2adf788SChiYuan Huang }
203b2adf788SChiYuan Huang 
mt6370_regmap_write(void * context,const void * data,size_t count)204b2adf788SChiYuan Huang static int mt6370_regmap_write(void *context, const void *data, size_t count)
205b2adf788SChiYuan Huang {
206b2adf788SChiYuan Huang 	struct mt6370_info *info = context;
207b2adf788SChiYuan Huang 	const u8 *u8_buf = data;
208b2adf788SChiYuan Huang 	u8 bank_idx, bank_addr;
209b2adf788SChiYuan Huang 	int len = count - MT6370_MAX_ADDRLEN;
210b2adf788SChiYuan Huang 
211b2adf788SChiYuan Huang 	bank_idx = u8_buf[0];
212b2adf788SChiYuan Huang 	bank_addr = u8_buf[1];
213b2adf788SChiYuan Huang 
214b2adf788SChiYuan Huang 	return i2c_smbus_write_i2c_block_data(info->i2c[bank_idx], bank_addr,
215b2adf788SChiYuan Huang 					      len, data + MT6370_MAX_ADDRLEN);
216b2adf788SChiYuan Huang }
217b2adf788SChiYuan Huang 
218b2adf788SChiYuan Huang static const struct regmap_bus mt6370_regmap_bus = {
219b2adf788SChiYuan Huang 	.read		= mt6370_regmap_read,
220b2adf788SChiYuan Huang 	.write		= mt6370_regmap_write,
221b2adf788SChiYuan Huang };
222b2adf788SChiYuan Huang 
223b2adf788SChiYuan Huang static const struct regmap_config mt6370_regmap_config = {
224b2adf788SChiYuan Huang 	.reg_bits		= 16,
225b2adf788SChiYuan Huang 	.val_bits		= 8,
226b2adf788SChiYuan Huang 	.reg_format_endian	= REGMAP_ENDIAN_BIG,
227b2adf788SChiYuan Huang 	.max_register		= MT6370_REG_MAXADDR,
228b2adf788SChiYuan Huang };
229b2adf788SChiYuan Huang 
mt6370_probe(struct i2c_client * i2c)230b2adf788SChiYuan Huang static int mt6370_probe(struct i2c_client *i2c)
231b2adf788SChiYuan Huang {
232b2adf788SChiYuan Huang 	struct mt6370_info *info;
233b2adf788SChiYuan Huang 	struct i2c_client *usbc_i2c;
234b2adf788SChiYuan Huang 	struct regmap *regmap;
235b2adf788SChiYuan Huang 	struct device *dev = &i2c->dev;
236b2adf788SChiYuan Huang 	int ret, vid;
237b2adf788SChiYuan Huang 
238b2adf788SChiYuan Huang 	info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
239b2adf788SChiYuan Huang 	if (!info)
240b2adf788SChiYuan Huang 		return -ENOMEM;
241b2adf788SChiYuan Huang 
242b2adf788SChiYuan Huang 	usbc_i2c = devm_i2c_new_dummy_device(dev, i2c->adapter,
243b2adf788SChiYuan Huang 					     MT6370_USBC_I2CADDR);
244b2adf788SChiYuan Huang 	if (IS_ERR(usbc_i2c))
245b2adf788SChiYuan Huang 		return dev_err_probe(dev, PTR_ERR(usbc_i2c),
246b2adf788SChiYuan Huang 				     "Failed to register USBC I2C client\n");
247b2adf788SChiYuan Huang 
248b2adf788SChiYuan Huang 	/* Assign I2C client for PMU and TypeC */
249b2adf788SChiYuan Huang 	info->i2c[MT6370_PMU_I2C] = i2c;
250b2adf788SChiYuan Huang 	info->i2c[MT6370_USBC_I2C] = usbc_i2c;
251b2adf788SChiYuan Huang 
252b2adf788SChiYuan Huang 	regmap = devm_regmap_init(dev, &mt6370_regmap_bus,
253b2adf788SChiYuan Huang 				  info, &mt6370_regmap_config);
254b2adf788SChiYuan Huang 	if (IS_ERR(regmap))
255b2adf788SChiYuan Huang 		return dev_err_probe(dev, PTR_ERR(regmap),
256b2adf788SChiYuan Huang 				     "Failed to init regmap\n");
257b2adf788SChiYuan Huang 
258b2adf788SChiYuan Huang 	ret = mt6370_check_vendor_info(dev, regmap, &vid);
259b2adf788SChiYuan Huang 	if (ret)
260b2adf788SChiYuan Huang 		return dev_err_probe(dev, ret, "Failed to check vendor info\n");
261b2adf788SChiYuan Huang 
262b2adf788SChiYuan Huang 	ret = devm_regmap_add_irq_chip(dev, regmap, i2c->irq,
263b2adf788SChiYuan Huang 				       IRQF_ONESHOT, -1, &mt6370_irq_chip,
264b2adf788SChiYuan Huang 				       &info->irq_data);
265b2adf788SChiYuan Huang 	if (ret)
266b2adf788SChiYuan Huang 		return dev_err_probe(dev, ret, "Failed to add irq chip\n");
267b2adf788SChiYuan Huang 
268b2adf788SChiYuan Huang 	switch (vid) {
269b2adf788SChiYuan Huang 	case MT6370_VENID_MT6372P:
270b2adf788SChiYuan Huang 	case MT6370_VENID_MT6372CP:
271b2adf788SChiYuan Huang 		ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,
272b2adf788SChiYuan Huang 					   mt6372_exclusive_devices,
273b2adf788SChiYuan Huang 					   ARRAY_SIZE(mt6372_exclusive_devices),
274b2adf788SChiYuan Huang 					   NULL, 0,
275b2adf788SChiYuan Huang 					   regmap_irq_get_domain(info->irq_data));
276b2adf788SChiYuan Huang 		break;
277b2adf788SChiYuan Huang 	default:
278b2adf788SChiYuan Huang 		ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,
279b2adf788SChiYuan Huang 					   mt6370_exclusive_devices,
280b2adf788SChiYuan Huang 					   ARRAY_SIZE(mt6370_exclusive_devices),
281b2adf788SChiYuan Huang 					   NULL, 0,
282b2adf788SChiYuan Huang 					   regmap_irq_get_domain(info->irq_data));
283b2adf788SChiYuan Huang 		break;
284b2adf788SChiYuan Huang 	}
285b2adf788SChiYuan Huang 
286b2adf788SChiYuan Huang 	if (ret)
287b2adf788SChiYuan Huang 		return dev_err_probe(dev, ret, "Failed to add the exclusive devices\n");
288b2adf788SChiYuan Huang 
289b2adf788SChiYuan Huang 	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,
290b2adf788SChiYuan Huang 				    mt6370_devices, ARRAY_SIZE(mt6370_devices),
291b2adf788SChiYuan Huang 				    NULL, 0,
292b2adf788SChiYuan Huang 				    regmap_irq_get_domain(info->irq_data));
293b2adf788SChiYuan Huang }
294b2adf788SChiYuan Huang 
295b2adf788SChiYuan Huang static const struct of_device_id mt6370_match_table[] = {
296b2adf788SChiYuan Huang 	{ .compatible = "mediatek,mt6370" },
297b2adf788SChiYuan Huang 	{}
298b2adf788SChiYuan Huang };
299b2adf788SChiYuan Huang MODULE_DEVICE_TABLE(of, mt6370_match_table);
300b2adf788SChiYuan Huang 
301b2adf788SChiYuan Huang static struct i2c_driver mt6370_driver = {
302b2adf788SChiYuan Huang 	.driver = {
303b2adf788SChiYuan Huang 		.name = "mt6370",
304b2adf788SChiYuan Huang 		.of_match_table = mt6370_match_table,
305b2adf788SChiYuan Huang 	},
306*9816d859SUwe Kleine-König 	.probe = mt6370_probe,
307b2adf788SChiYuan Huang };
308b2adf788SChiYuan Huang module_i2c_driver(mt6370_driver);
309b2adf788SChiYuan Huang 
310b2adf788SChiYuan Huang MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
311b2adf788SChiYuan Huang MODULE_DESCRIPTION("MediaTek MT6370 SubPMIC Driver");
312b2adf788SChiYuan Huang MODULE_LICENSE("GPL v2");
313