xref: /openbmc/linux/drivers/mfd/tc3589x.c (revision 593e9d70fb0f1ece1cf2a61c701dec35d8e41f8d)
1f4e8afdcSSundar Iyer /*
2f4e8afdcSSundar Iyer  * Copyright (C) ST-Ericsson SA 2010
3f4e8afdcSSundar Iyer  *
4f4e8afdcSSundar Iyer  * License Terms: GNU General Public License, version 2
5f4e8afdcSSundar Iyer  * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6f4e8afdcSSundar Iyer  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7f4e8afdcSSundar Iyer  */
8f4e8afdcSSundar Iyer 
9f4e8afdcSSundar Iyer #include <linux/module.h>
10f4e8afdcSSundar Iyer #include <linux/interrupt.h>
11f4e8afdcSSundar Iyer #include <linux/irq.h>
12f4e8afdcSSundar Iyer #include <linux/slab.h>
13f4e8afdcSSundar Iyer #include <linux/i2c.h>
14f4e8afdcSSundar Iyer #include <linux/mfd/core.h>
15f4e8afdcSSundar Iyer #include <linux/mfd/tc3589x.h>
16f4e8afdcSSundar Iyer 
17*593e9d70SSundar Iyer #define TC3589x_CLKMODE_MODCTL_SLEEP		0x0
18*593e9d70SSundar Iyer #define TC3589x_CLKMODE_MODCTL_OPERATION	(1 << 0)
19*593e9d70SSundar Iyer 
20f4e8afdcSSundar Iyer /**
2120406ebfSSundar Iyer  * tc3589x_reg_read() - read a single TC3589x register
2220406ebfSSundar Iyer  * @tc3589x:	Device to read from
23f4e8afdcSSundar Iyer  * @reg:	Register to read
24f4e8afdcSSundar Iyer  */
2520406ebfSSundar Iyer int tc3589x_reg_read(struct tc3589x *tc3589x, u8 reg)
26f4e8afdcSSundar Iyer {
27f4e8afdcSSundar Iyer 	int ret;
28f4e8afdcSSundar Iyer 
2920406ebfSSundar Iyer 	ret = i2c_smbus_read_byte_data(tc3589x->i2c, reg);
30f4e8afdcSSundar Iyer 	if (ret < 0)
3120406ebfSSundar Iyer 		dev_err(tc3589x->dev, "failed to read reg %#x: %d\n",
32f4e8afdcSSundar Iyer 			reg, ret);
33f4e8afdcSSundar Iyer 
34f4e8afdcSSundar Iyer 	return ret;
35f4e8afdcSSundar Iyer }
3620406ebfSSundar Iyer EXPORT_SYMBOL_GPL(tc3589x_reg_read);
37f4e8afdcSSundar Iyer 
38f4e8afdcSSundar Iyer /**
3920406ebfSSundar Iyer  * tc3589x_reg_read() - write a single TC3589x register
4020406ebfSSundar Iyer  * @tc3589x:	Device to write to
41f4e8afdcSSundar Iyer  * @reg:	Register to read
42f4e8afdcSSundar Iyer  * @data:	Value to write
43f4e8afdcSSundar Iyer  */
4420406ebfSSundar Iyer int tc3589x_reg_write(struct tc3589x *tc3589x, u8 reg, u8 data)
45f4e8afdcSSundar Iyer {
46f4e8afdcSSundar Iyer 	int ret;
47f4e8afdcSSundar Iyer 
4820406ebfSSundar Iyer 	ret = i2c_smbus_write_byte_data(tc3589x->i2c, reg, data);
49f4e8afdcSSundar Iyer 	if (ret < 0)
5020406ebfSSundar Iyer 		dev_err(tc3589x->dev, "failed to write reg %#x: %d\n",
51f4e8afdcSSundar Iyer 			reg, ret);
52f4e8afdcSSundar Iyer 
53f4e8afdcSSundar Iyer 	return ret;
54f4e8afdcSSundar Iyer }
5520406ebfSSundar Iyer EXPORT_SYMBOL_GPL(tc3589x_reg_write);
56f4e8afdcSSundar Iyer 
57f4e8afdcSSundar Iyer /**
5820406ebfSSundar Iyer  * tc3589x_block_read() - read multiple TC3589x registers
5920406ebfSSundar Iyer  * @tc3589x:	Device to read from
60f4e8afdcSSundar Iyer  * @reg:	First register
61f4e8afdcSSundar Iyer  * @length:	Number of registers
62f4e8afdcSSundar Iyer  * @values:	Buffer to write to
63f4e8afdcSSundar Iyer  */
6420406ebfSSundar Iyer int tc3589x_block_read(struct tc3589x *tc3589x, u8 reg, u8 length, u8 *values)
65f4e8afdcSSundar Iyer {
66f4e8afdcSSundar Iyer 	int ret;
67f4e8afdcSSundar Iyer 
6820406ebfSSundar Iyer 	ret = i2c_smbus_read_i2c_block_data(tc3589x->i2c, reg, length, values);
69f4e8afdcSSundar Iyer 	if (ret < 0)
7020406ebfSSundar Iyer 		dev_err(tc3589x->dev, "failed to read regs %#x: %d\n",
71f4e8afdcSSundar Iyer 			reg, ret);
72f4e8afdcSSundar Iyer 
73f4e8afdcSSundar Iyer 	return ret;
74f4e8afdcSSundar Iyer }
7520406ebfSSundar Iyer EXPORT_SYMBOL_GPL(tc3589x_block_read);
76f4e8afdcSSundar Iyer 
77f4e8afdcSSundar Iyer /**
7820406ebfSSundar Iyer  * tc3589x_block_write() - write multiple TC3589x registers
7920406ebfSSundar Iyer  * @tc3589x:	Device to write to
80f4e8afdcSSundar Iyer  * @reg:	First register
81f4e8afdcSSundar Iyer  * @length:	Number of registers
82f4e8afdcSSundar Iyer  * @values:	Values to write
83f4e8afdcSSundar Iyer  */
8420406ebfSSundar Iyer int tc3589x_block_write(struct tc3589x *tc3589x, u8 reg, u8 length,
85f4e8afdcSSundar Iyer 			const u8 *values)
86f4e8afdcSSundar Iyer {
87f4e8afdcSSundar Iyer 	int ret;
88f4e8afdcSSundar Iyer 
8920406ebfSSundar Iyer 	ret = i2c_smbus_write_i2c_block_data(tc3589x->i2c, reg, length,
90f4e8afdcSSundar Iyer 					     values);
91f4e8afdcSSundar Iyer 	if (ret < 0)
9220406ebfSSundar Iyer 		dev_err(tc3589x->dev, "failed to write regs %#x: %d\n",
93f4e8afdcSSundar Iyer 			reg, ret);
94f4e8afdcSSundar Iyer 
95f4e8afdcSSundar Iyer 	return ret;
96f4e8afdcSSundar Iyer }
9720406ebfSSundar Iyer EXPORT_SYMBOL_GPL(tc3589x_block_write);
98f4e8afdcSSundar Iyer 
99f4e8afdcSSundar Iyer /**
10020406ebfSSundar Iyer  * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register
10120406ebfSSundar Iyer  * @tc3589x:	Device to write to
102f4e8afdcSSundar Iyer  * @reg:	Register to write
103f4e8afdcSSundar Iyer  * @mask:	Mask of bits to set
104f4e8afdcSSundar Iyer  * @values:	Value to set
105f4e8afdcSSundar Iyer  */
10620406ebfSSundar Iyer int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val)
107f4e8afdcSSundar Iyer {
108f4e8afdcSSundar Iyer 	int ret;
109f4e8afdcSSundar Iyer 
11020406ebfSSundar Iyer 	mutex_lock(&tc3589x->lock);
111f4e8afdcSSundar Iyer 
11220406ebfSSundar Iyer 	ret = tc3589x_reg_read(tc3589x, reg);
113f4e8afdcSSundar Iyer 	if (ret < 0)
114f4e8afdcSSundar Iyer 		goto out;
115f4e8afdcSSundar Iyer 
116f4e8afdcSSundar Iyer 	ret &= ~mask;
117f4e8afdcSSundar Iyer 	ret |= val;
118f4e8afdcSSundar Iyer 
11920406ebfSSundar Iyer 	ret = tc3589x_reg_write(tc3589x, reg, ret);
120f4e8afdcSSundar Iyer 
121f4e8afdcSSundar Iyer out:
12220406ebfSSundar Iyer 	mutex_unlock(&tc3589x->lock);
123f4e8afdcSSundar Iyer 	return ret;
124f4e8afdcSSundar Iyer }
12520406ebfSSundar Iyer EXPORT_SYMBOL_GPL(tc3589x_set_bits);
126f4e8afdcSSundar Iyer 
127f4e8afdcSSundar Iyer static struct resource gpio_resources[] = {
128f4e8afdcSSundar Iyer 	{
12920406ebfSSundar Iyer 		.start	= TC3589x_INT_GPIIRQ,
13020406ebfSSundar Iyer 		.end	= TC3589x_INT_GPIIRQ,
131f4e8afdcSSundar Iyer 		.flags	= IORESOURCE_IRQ,
132f4e8afdcSSundar Iyer 	},
133f4e8afdcSSundar Iyer };
134f4e8afdcSSundar Iyer 
135611b7590SSundar Iyer static struct mfd_cell tc3589x_dev_gpio[] = {
136f4e8afdcSSundar Iyer 	{
13720406ebfSSundar Iyer 		.name		= "tc3589x-gpio",
138f4e8afdcSSundar Iyer 		.num_resources	= ARRAY_SIZE(gpio_resources),
139f4e8afdcSSundar Iyer 		.resources	= &gpio_resources[0],
140f4e8afdcSSundar Iyer 	},
141f4e8afdcSSundar Iyer };
142f4e8afdcSSundar Iyer 
14320406ebfSSundar Iyer static irqreturn_t tc3589x_irq(int irq, void *data)
144f4e8afdcSSundar Iyer {
14520406ebfSSundar Iyer 	struct tc3589x *tc3589x = data;
146f4e8afdcSSundar Iyer 	int status;
147f4e8afdcSSundar Iyer 
148bd77efd0SSundar Iyer again:
14920406ebfSSundar Iyer 	status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
150f4e8afdcSSundar Iyer 	if (status < 0)
151f4e8afdcSSundar Iyer 		return IRQ_NONE;
152f4e8afdcSSundar Iyer 
153f4e8afdcSSundar Iyer 	while (status) {
154f4e8afdcSSundar Iyer 		int bit = __ffs(status);
155f4e8afdcSSundar Iyer 
15620406ebfSSundar Iyer 		handle_nested_irq(tc3589x->irq_base + bit);
157f4e8afdcSSundar Iyer 		status &= ~(1 << bit);
158f4e8afdcSSundar Iyer 	}
159f4e8afdcSSundar Iyer 
160f4e8afdcSSundar Iyer 	/*
161f4e8afdcSSundar Iyer 	 * A dummy read or write (to any register) appears to be necessary to
162f4e8afdcSSundar Iyer 	 * have the last interrupt clear (for example, GPIO IC write) take
163bd77efd0SSundar Iyer 	 * effect. In such a case, recheck for any interrupt which is still
164bd77efd0SSundar Iyer 	 * pending.
165f4e8afdcSSundar Iyer 	 */
166bd77efd0SSundar Iyer 	status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
167bd77efd0SSundar Iyer 	if (status)
168bd77efd0SSundar Iyer 		goto again;
169f4e8afdcSSundar Iyer 
170f4e8afdcSSundar Iyer 	return IRQ_HANDLED;
171f4e8afdcSSundar Iyer }
172f4e8afdcSSundar Iyer 
17320406ebfSSundar Iyer static void tc3589x_irq_dummy(unsigned int irq)
174f4e8afdcSSundar Iyer {
175f4e8afdcSSundar Iyer 	/* No mask/unmask at this level */
176f4e8afdcSSundar Iyer }
177f4e8afdcSSundar Iyer 
17820406ebfSSundar Iyer static struct irq_chip tc3589x_irq_chip = {
17920406ebfSSundar Iyer 	.name	= "tc3589x",
18020406ebfSSundar Iyer 	.mask	= tc3589x_irq_dummy,
18120406ebfSSundar Iyer 	.unmask	= tc3589x_irq_dummy,
182f4e8afdcSSundar Iyer };
183f4e8afdcSSundar Iyer 
18420406ebfSSundar Iyer static int tc3589x_irq_init(struct tc3589x *tc3589x)
185f4e8afdcSSundar Iyer {
18620406ebfSSundar Iyer 	int base = tc3589x->irq_base;
187f4e8afdcSSundar Iyer 	int irq;
188f4e8afdcSSundar Iyer 
18920406ebfSSundar Iyer 	for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) {
19020406ebfSSundar Iyer 		set_irq_chip_data(irq, tc3589x);
19120406ebfSSundar Iyer 		set_irq_chip_and_handler(irq, &tc3589x_irq_chip,
192f4e8afdcSSundar Iyer 					 handle_edge_irq);
193f4e8afdcSSundar Iyer 		set_irq_nested_thread(irq, 1);
194f4e8afdcSSundar Iyer #ifdef CONFIG_ARM
195f4e8afdcSSundar Iyer 		set_irq_flags(irq, IRQF_VALID);
196f4e8afdcSSundar Iyer #else
197f4e8afdcSSundar Iyer 		set_irq_noprobe(irq);
198f4e8afdcSSundar Iyer #endif
199f4e8afdcSSundar Iyer 	}
200f4e8afdcSSundar Iyer 
201f4e8afdcSSundar Iyer 	return 0;
202f4e8afdcSSundar Iyer }
203f4e8afdcSSundar Iyer 
20420406ebfSSundar Iyer static void tc3589x_irq_remove(struct tc3589x *tc3589x)
205f4e8afdcSSundar Iyer {
20620406ebfSSundar Iyer 	int base = tc3589x->irq_base;
207f4e8afdcSSundar Iyer 	int irq;
208f4e8afdcSSundar Iyer 
20920406ebfSSundar Iyer 	for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) {
210f4e8afdcSSundar Iyer #ifdef CONFIG_ARM
211f4e8afdcSSundar Iyer 		set_irq_flags(irq, 0);
212f4e8afdcSSundar Iyer #endif
213f4e8afdcSSundar Iyer 		set_irq_chip_and_handler(irq, NULL, NULL);
214f4e8afdcSSundar Iyer 		set_irq_chip_data(irq, NULL);
215f4e8afdcSSundar Iyer 	}
216f4e8afdcSSundar Iyer }
217f4e8afdcSSundar Iyer 
21820406ebfSSundar Iyer static int tc3589x_chip_init(struct tc3589x *tc3589x)
219f4e8afdcSSundar Iyer {
220f4e8afdcSSundar Iyer 	int manf, ver, ret;
221f4e8afdcSSundar Iyer 
22220406ebfSSundar Iyer 	manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE);
223f4e8afdcSSundar Iyer 	if (manf < 0)
224f4e8afdcSSundar Iyer 		return manf;
225f4e8afdcSSundar Iyer 
22620406ebfSSundar Iyer 	ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION);
227f4e8afdcSSundar Iyer 	if (ver < 0)
228f4e8afdcSSundar Iyer 		return ver;
229f4e8afdcSSundar Iyer 
23020406ebfSSundar Iyer 	if (manf != TC3589x_MANFCODE_MAGIC) {
23120406ebfSSundar Iyer 		dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf);
232f4e8afdcSSundar Iyer 		return -EINVAL;
233f4e8afdcSSundar Iyer 	}
234f4e8afdcSSundar Iyer 
23520406ebfSSundar Iyer 	dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
236f4e8afdcSSundar Iyer 
237523bc382SSundar Iyer 	/*
238523bc382SSundar Iyer 	 * Put everything except the IRQ module into reset;
239523bc382SSundar Iyer 	 * also spare the GPIO module for any pin initialization
240523bc382SSundar Iyer 	 * done during pre-kernel boot
241523bc382SSundar Iyer 	 */
24220406ebfSSundar Iyer 	ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL,
24320406ebfSSundar Iyer 				TC3589x_RSTCTRL_TIMRST
24420406ebfSSundar Iyer 				| TC3589x_RSTCTRL_ROTRST
245523bc382SSundar Iyer 				| TC3589x_RSTCTRL_KBDRST);
246f4e8afdcSSundar Iyer 	if (ret < 0)
247f4e8afdcSSundar Iyer 		return ret;
248f4e8afdcSSundar Iyer 
249f4e8afdcSSundar Iyer 	/* Clear the reset interrupt. */
25020406ebfSSundar Iyer 	return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1);
251f4e8afdcSSundar Iyer }
252f4e8afdcSSundar Iyer 
253611b7590SSundar Iyer static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
254611b7590SSundar Iyer {
255611b7590SSundar Iyer 	int ret = 0;
256611b7590SSundar Iyer 	unsigned int blocks = tc3589x->pdata->block;
257611b7590SSundar Iyer 
258611b7590SSundar Iyer 	if (blocks & TC3589x_BLOCK_GPIO) {
259611b7590SSundar Iyer 		ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
260611b7590SSundar Iyer 				ARRAY_SIZE(tc3589x_dev_gpio), NULL,
261611b7590SSundar Iyer 				tc3589x->irq_base);
262611b7590SSundar Iyer 		if (ret) {
263611b7590SSundar Iyer 			dev_err(tc3589x->dev, "failed to add gpio child\n");
264611b7590SSundar Iyer 			return ret;
265611b7590SSundar Iyer 		}
266611b7590SSundar Iyer 		dev_info(tc3589x->dev, "added gpio block\n");
267611b7590SSundar Iyer 	}
268611b7590SSundar Iyer 
269611b7590SSundar Iyer 	return ret;
270611b7590SSundar Iyer 
271611b7590SSundar Iyer }
272611b7590SSundar Iyer 
27320406ebfSSundar Iyer static int __devinit tc3589x_probe(struct i2c_client *i2c,
274f4e8afdcSSundar Iyer 				   const struct i2c_device_id *id)
275f4e8afdcSSundar Iyer {
27620406ebfSSundar Iyer 	struct tc3589x_platform_data *pdata = i2c->dev.platform_data;
27720406ebfSSundar Iyer 	struct tc3589x *tc3589x;
278f4e8afdcSSundar Iyer 	int ret;
279f4e8afdcSSundar Iyer 
280f4e8afdcSSundar Iyer 	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
281f4e8afdcSSundar Iyer 				     | I2C_FUNC_SMBUS_I2C_BLOCK))
282f4e8afdcSSundar Iyer 		return -EIO;
283f4e8afdcSSundar Iyer 
28420406ebfSSundar Iyer 	tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL);
28520406ebfSSundar Iyer 	if (!tc3589x)
286f4e8afdcSSundar Iyer 		return -ENOMEM;
287f4e8afdcSSundar Iyer 
28820406ebfSSundar Iyer 	mutex_init(&tc3589x->lock);
289f4e8afdcSSundar Iyer 
29020406ebfSSundar Iyer 	tc3589x->dev = &i2c->dev;
29120406ebfSSundar Iyer 	tc3589x->i2c = i2c;
29220406ebfSSundar Iyer 	tc3589x->pdata = pdata;
29320406ebfSSundar Iyer 	tc3589x->irq_base = pdata->irq_base;
29420406ebfSSundar Iyer 	tc3589x->num_gpio = id->driver_data;
295f4e8afdcSSundar Iyer 
29620406ebfSSundar Iyer 	i2c_set_clientdata(i2c, tc3589x);
297f4e8afdcSSundar Iyer 
29820406ebfSSundar Iyer 	ret = tc3589x_chip_init(tc3589x);
299f4e8afdcSSundar Iyer 	if (ret)
300f4e8afdcSSundar Iyer 		goto out_free;
301f4e8afdcSSundar Iyer 
30220406ebfSSundar Iyer 	ret = tc3589x_irq_init(tc3589x);
303f4e8afdcSSundar Iyer 	if (ret)
304f4e8afdcSSundar Iyer 		goto out_free;
305f4e8afdcSSundar Iyer 
30620406ebfSSundar Iyer 	ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq,
307f4e8afdcSSundar Iyer 				   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
30820406ebfSSundar Iyer 				   "tc3589x", tc3589x);
309f4e8afdcSSundar Iyer 	if (ret) {
31020406ebfSSundar Iyer 		dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret);
311f4e8afdcSSundar Iyer 		goto out_removeirq;
312f4e8afdcSSundar Iyer 	}
313f4e8afdcSSundar Iyer 
314611b7590SSundar Iyer 	ret = tc3589x_device_init(tc3589x);
315f4e8afdcSSundar Iyer 	if (ret) {
316611b7590SSundar Iyer 		dev_err(tc3589x->dev, "failed to add child devices\n");
317f4e8afdcSSundar Iyer 		goto out_freeirq;
318f4e8afdcSSundar Iyer 	}
319f4e8afdcSSundar Iyer 
320f4e8afdcSSundar Iyer 	return 0;
321f4e8afdcSSundar Iyer 
322f4e8afdcSSundar Iyer out_freeirq:
32320406ebfSSundar Iyer 	free_irq(tc3589x->i2c->irq, tc3589x);
324f4e8afdcSSundar Iyer out_removeirq:
32520406ebfSSundar Iyer 	tc3589x_irq_remove(tc3589x);
326f4e8afdcSSundar Iyer out_free:
32720406ebfSSundar Iyer 	kfree(tc3589x);
328f4e8afdcSSundar Iyer 	return ret;
329f4e8afdcSSundar Iyer }
330f4e8afdcSSundar Iyer 
33120406ebfSSundar Iyer static int __devexit tc3589x_remove(struct i2c_client *client)
332f4e8afdcSSundar Iyer {
33320406ebfSSundar Iyer 	struct tc3589x *tc3589x = i2c_get_clientdata(client);
334f4e8afdcSSundar Iyer 
33520406ebfSSundar Iyer 	mfd_remove_devices(tc3589x->dev);
336f4e8afdcSSundar Iyer 
33720406ebfSSundar Iyer 	free_irq(tc3589x->i2c->irq, tc3589x);
33820406ebfSSundar Iyer 	tc3589x_irq_remove(tc3589x);
339f4e8afdcSSundar Iyer 
34020406ebfSSundar Iyer 	kfree(tc3589x);
341f4e8afdcSSundar Iyer 
342f4e8afdcSSundar Iyer 	return 0;
343f4e8afdcSSundar Iyer }
344f4e8afdcSSundar Iyer 
345*593e9d70SSundar Iyer static int tc3589x_suspend(struct device *dev)
346*593e9d70SSundar Iyer {
347*593e9d70SSundar Iyer 	struct tc3589x *tc3589x = dev_get_drvdata(dev);
348*593e9d70SSundar Iyer 	struct i2c_client *client = tc3589x->i2c;
349*593e9d70SSundar Iyer 	int ret = 0;
350*593e9d70SSundar Iyer 
351*593e9d70SSundar Iyer 	/* put the system to sleep mode */
352*593e9d70SSundar Iyer 	if (!device_may_wakeup(&client->dev))
353*593e9d70SSundar Iyer 		ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
354*593e9d70SSundar Iyer 				TC3589x_CLKMODE_MODCTL_SLEEP);
355*593e9d70SSundar Iyer 
356*593e9d70SSundar Iyer 	return ret;
357*593e9d70SSundar Iyer }
358*593e9d70SSundar Iyer 
359*593e9d70SSundar Iyer static int tc3589x_resume(struct device *dev)
360*593e9d70SSundar Iyer {
361*593e9d70SSundar Iyer 	struct tc3589x *tc3589x = dev_get_drvdata(dev);
362*593e9d70SSundar Iyer 	struct i2c_client *client = tc3589x->i2c;
363*593e9d70SSundar Iyer 	int ret = 0;
364*593e9d70SSundar Iyer 
365*593e9d70SSundar Iyer 	/* enable the system into operation */
366*593e9d70SSundar Iyer 	if (!device_may_wakeup(&client->dev))
367*593e9d70SSundar Iyer 		ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
368*593e9d70SSundar Iyer 				TC3589x_CLKMODE_MODCTL_OPERATION);
369*593e9d70SSundar Iyer 
370*593e9d70SSundar Iyer 	return ret;
371*593e9d70SSundar Iyer }
372*593e9d70SSundar Iyer 
373*593e9d70SSundar Iyer static const SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend,
374*593e9d70SSundar Iyer 						tc3589x_resume);
375*593e9d70SSundar Iyer 
37620406ebfSSundar Iyer static const struct i2c_device_id tc3589x_id[] = {
37720406ebfSSundar Iyer 	{ "tc3589x", 24 },
378f4e8afdcSSundar Iyer 	{ }
379f4e8afdcSSundar Iyer };
38020406ebfSSundar Iyer MODULE_DEVICE_TABLE(i2c, tc3589x_id);
381f4e8afdcSSundar Iyer 
38220406ebfSSundar Iyer static struct i2c_driver tc3589x_driver = {
38320406ebfSSundar Iyer 	.driver.name	= "tc3589x",
384f4e8afdcSSundar Iyer 	.driver.owner	= THIS_MODULE,
385*593e9d70SSundar Iyer #ifdef CONFIG_PM
386*593e9d70SSundar Iyer 	.driver.pm	= &tc3589x_dev_pm_ops,
387*593e9d70SSundar Iyer #endif
38820406ebfSSundar Iyer 	.probe		= tc3589x_probe,
38920406ebfSSundar Iyer 	.remove		= __devexit_p(tc3589x_remove),
39020406ebfSSundar Iyer 	.id_table	= tc3589x_id,
391f4e8afdcSSundar Iyer };
392f4e8afdcSSundar Iyer 
39320406ebfSSundar Iyer static int __init tc3589x_init(void)
394f4e8afdcSSundar Iyer {
39520406ebfSSundar Iyer 	return i2c_add_driver(&tc3589x_driver);
396f4e8afdcSSundar Iyer }
39720406ebfSSundar Iyer subsys_initcall(tc3589x_init);
398f4e8afdcSSundar Iyer 
39920406ebfSSundar Iyer static void __exit tc3589x_exit(void)
400f4e8afdcSSundar Iyer {
40120406ebfSSundar Iyer 	i2c_del_driver(&tc3589x_driver);
402f4e8afdcSSundar Iyer }
40320406ebfSSundar Iyer module_exit(tc3589x_exit);
404f4e8afdcSSundar Iyer 
405f4e8afdcSSundar Iyer MODULE_LICENSE("GPL v2");
40620406ebfSSundar Iyer MODULE_DESCRIPTION("TC3589x MFD core driver");
407f4e8afdcSSundar Iyer MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
408