blob: 2df44acaf90793868acd475d621d13cfe5ff3096 [file] [log] [blame]
Rabin Vincentb4ecd322010-05-10 23:39:47 +02001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
Lee Jones15e27b12012-09-07 12:14:56 +010012#include <linux/irqdomain.h>
Rabin Vincentb4ecd322010-05-10 23:39:47 +020013#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/mfd/core.h>
Sundar Iyerc6eda6c2010-12-13 09:33:12 +053016#include <linux/mfd/tc3589x.h>
Rabin Vincentb4ecd322010-05-10 23:39:47 +020017
Sundar Iyer593e9d72010-12-13 09:33:18 +053018#define TC3589x_CLKMODE_MODCTL_SLEEP 0x0
19#define TC3589x_CLKMODE_MODCTL_OPERATION (1 << 0)
20
Rabin Vincentb4ecd322010-05-10 23:39:47 +020021/**
Sundar Iyer20406eb2010-12-13 09:33:14 +053022 * tc3589x_reg_read() - read a single TC3589x register
23 * @tc3589x: Device to read from
Rabin Vincentb4ecd322010-05-10 23:39:47 +020024 * @reg: Register to read
25 */
Sundar Iyer20406eb2010-12-13 09:33:14 +053026int tc3589x_reg_read(struct tc3589x *tc3589x, u8 reg)
Rabin Vincentb4ecd322010-05-10 23:39:47 +020027{
28 int ret;
29
Sundar Iyer20406eb2010-12-13 09:33:14 +053030 ret = i2c_smbus_read_byte_data(tc3589x->i2c, reg);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020031 if (ret < 0)
Sundar Iyer20406eb2010-12-13 09:33:14 +053032 dev_err(tc3589x->dev, "failed to read reg %#x: %d\n",
Rabin Vincentb4ecd322010-05-10 23:39:47 +020033 reg, ret);
34
35 return ret;
36}
Sundar Iyer20406eb2010-12-13 09:33:14 +053037EXPORT_SYMBOL_GPL(tc3589x_reg_read);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020038
39/**
Sundar Iyer20406eb2010-12-13 09:33:14 +053040 * tc3589x_reg_read() - write a single TC3589x register
41 * @tc3589x: Device to write to
Rabin Vincentb4ecd322010-05-10 23:39:47 +020042 * @reg: Register to read
43 * @data: Value to write
44 */
Sundar Iyer20406eb2010-12-13 09:33:14 +053045int tc3589x_reg_write(struct tc3589x *tc3589x, u8 reg, u8 data)
Rabin Vincentb4ecd322010-05-10 23:39:47 +020046{
47 int ret;
48
Sundar Iyer20406eb2010-12-13 09:33:14 +053049 ret = i2c_smbus_write_byte_data(tc3589x->i2c, reg, data);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020050 if (ret < 0)
Sundar Iyer20406eb2010-12-13 09:33:14 +053051 dev_err(tc3589x->dev, "failed to write reg %#x: %d\n",
Rabin Vincentb4ecd322010-05-10 23:39:47 +020052 reg, ret);
53
54 return ret;
55}
Sundar Iyer20406eb2010-12-13 09:33:14 +053056EXPORT_SYMBOL_GPL(tc3589x_reg_write);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020057
58/**
Sundar Iyer20406eb2010-12-13 09:33:14 +053059 * tc3589x_block_read() - read multiple TC3589x registers
60 * @tc3589x: Device to read from
Rabin Vincentb4ecd322010-05-10 23:39:47 +020061 * @reg: First register
62 * @length: Number of registers
63 * @values: Buffer to write to
64 */
Sundar Iyer20406eb2010-12-13 09:33:14 +053065int tc3589x_block_read(struct tc3589x *tc3589x, u8 reg, u8 length, u8 *values)
Rabin Vincentb4ecd322010-05-10 23:39:47 +020066{
67 int ret;
68
Sundar Iyer20406eb2010-12-13 09:33:14 +053069 ret = i2c_smbus_read_i2c_block_data(tc3589x->i2c, reg, length, values);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020070 if (ret < 0)
Sundar Iyer20406eb2010-12-13 09:33:14 +053071 dev_err(tc3589x->dev, "failed to read regs %#x: %d\n",
Rabin Vincentb4ecd322010-05-10 23:39:47 +020072 reg, ret);
73
74 return ret;
75}
Sundar Iyer20406eb2010-12-13 09:33:14 +053076EXPORT_SYMBOL_GPL(tc3589x_block_read);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020077
78/**
Sundar Iyer20406eb2010-12-13 09:33:14 +053079 * tc3589x_block_write() - write multiple TC3589x registers
80 * @tc3589x: Device to write to
Rabin Vincentb4ecd322010-05-10 23:39:47 +020081 * @reg: First register
82 * @length: Number of registers
83 * @values: Values to write
84 */
Sundar Iyer20406eb2010-12-13 09:33:14 +053085int tc3589x_block_write(struct tc3589x *tc3589x, u8 reg, u8 length,
Rabin Vincentb4ecd322010-05-10 23:39:47 +020086 const u8 *values)
87{
88 int ret;
89
Sundar Iyer20406eb2010-12-13 09:33:14 +053090 ret = i2c_smbus_write_i2c_block_data(tc3589x->i2c, reg, length,
Rabin Vincentb4ecd322010-05-10 23:39:47 +020091 values);
92 if (ret < 0)
Sundar Iyer20406eb2010-12-13 09:33:14 +053093 dev_err(tc3589x->dev, "failed to write regs %#x: %d\n",
Rabin Vincentb4ecd322010-05-10 23:39:47 +020094 reg, ret);
95
96 return ret;
97}
Sundar Iyer20406eb2010-12-13 09:33:14 +053098EXPORT_SYMBOL_GPL(tc3589x_block_write);
Rabin Vincentb4ecd322010-05-10 23:39:47 +020099
100/**
Sundar Iyer20406eb2010-12-13 09:33:14 +0530101 * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register
102 * @tc3589x: Device to write to
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200103 * @reg: Register to write
104 * @mask: Mask of bits to set
105 * @values: Value to set
106 */
Sundar Iyer20406eb2010-12-13 09:33:14 +0530107int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200108{
109 int ret;
110
Sundar Iyer20406eb2010-12-13 09:33:14 +0530111 mutex_lock(&tc3589x->lock);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200112
Sundar Iyer20406eb2010-12-13 09:33:14 +0530113 ret = tc3589x_reg_read(tc3589x, reg);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200114 if (ret < 0)
115 goto out;
116
117 ret &= ~mask;
118 ret |= val;
119
Sundar Iyer20406eb2010-12-13 09:33:14 +0530120 ret = tc3589x_reg_write(tc3589x, reg, ret);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200121
122out:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530123 mutex_unlock(&tc3589x->lock);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200124 return ret;
125}
Sundar Iyer20406eb2010-12-13 09:33:14 +0530126EXPORT_SYMBOL_GPL(tc3589x_set_bits);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200127
128static struct resource gpio_resources[] = {
129 {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530130 .start = TC3589x_INT_GPIIRQ,
131 .end = TC3589x_INT_GPIIRQ,
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200132 .flags = IORESOURCE_IRQ,
133 },
134};
135
Sundar Iyer09c730a2010-12-21 15:53:31 +0530136static struct resource keypad_resources[] = {
137 {
138 .start = TC3589x_INT_KBDIRQ,
139 .end = TC3589x_INT_KBDIRQ,
140 .flags = IORESOURCE_IRQ,
141 },
142};
143
Sundar Iyer611b7592010-12-13 09:33:15 +0530144static struct mfd_cell tc3589x_dev_gpio[] = {
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200145 {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530146 .name = "tc3589x-gpio",
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200147 .num_resources = ARRAY_SIZE(gpio_resources),
148 .resources = &gpio_resources[0],
149 },
150};
151
Sundar Iyer09c730a2010-12-21 15:53:31 +0530152static struct mfd_cell tc3589x_dev_keypad[] = {
153 {
154 .name = "tc3589x-keypad",
155 .num_resources = ARRAY_SIZE(keypad_resources),
156 .resources = &keypad_resources[0],
157 },
158};
159
Sundar Iyer20406eb2010-12-13 09:33:14 +0530160static irqreturn_t tc3589x_irq(int irq, void *data)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200161{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530162 struct tc3589x *tc3589x = data;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200163 int status;
164
Sundar Iyerbd77efd2010-12-13 09:33:16 +0530165again:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530166 status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200167 if (status < 0)
168 return IRQ_NONE;
169
170 while (status) {
171 int bit = __ffs(status);
Lee Jones15e27b12012-09-07 12:14:56 +0100172 int virq = irq_create_mapping(tc3589x->domain, bit);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200173
Lee Jones15e27b12012-09-07 12:14:56 +0100174 handle_nested_irq(virq);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200175 status &= ~(1 << bit);
176 }
177
178 /*
179 * A dummy read or write (to any register) appears to be necessary to
180 * have the last interrupt clear (for example, GPIO IC write) take
Sundar Iyerbd77efd2010-12-13 09:33:16 +0530181 * effect. In such a case, recheck for any interrupt which is still
182 * pending.
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200183 */
Sundar Iyerbd77efd2010-12-13 09:33:16 +0530184 status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
185 if (status)
186 goto again;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200187
188 return IRQ_HANDLED;
189}
190
Lee Jones15e27b12012-09-07 12:14:56 +0100191static int tc3589x_irq_map(struct irq_domain *d, unsigned int virq,
192 irq_hw_number_t hwirq)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200193{
Lee Jones15e27b12012-09-07 12:14:56 +0100194 struct tc3589x *tc3589x = d->host_data;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200195
Lee Jones15e27b12012-09-07 12:14:56 +0100196 irq_set_chip_data(virq, tc3589x);
197 irq_set_chip_and_handler(virq, &dummy_irq_chip,
198 handle_edge_irq);
199 irq_set_nested_thread(virq, 1);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200200#ifdef CONFIG_ARM
Lee Jones15e27b12012-09-07 12:14:56 +0100201 set_irq_flags(virq, IRQF_VALID);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200202#else
Lee Jones15e27b12012-09-07 12:14:56 +0100203 irq_set_noprobe(virq);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200204#endif
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200205
206 return 0;
207}
208
Lee Jones15e27b12012-09-07 12:14:56 +0100209static void tc3589x_irq_unmap(struct irq_domain *d, unsigned int virq)
210{
211#ifdef CONFIG_ARM
212 set_irq_flags(virq, 0);
213#endif
214 irq_set_chip_and_handler(virq, NULL, NULL);
215 irq_set_chip_data(virq, NULL);
216}
217
218static struct irq_domain_ops tc3589x_irq_ops = {
219 .map = tc3589x_irq_map,
220 .unmap = tc3589x_irq_unmap,
221 .xlate = irq_domain_xlate_twocell,
222};
223
224static int tc3589x_irq_init(struct tc3589x *tc3589x)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200225{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530226 int base = tc3589x->irq_base;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200227
Lee Jones15e27b12012-09-07 12:14:56 +0100228 if (base) {
229 tc3589x->domain = irq_domain_add_legacy(
230 NULL, TC3589x_NR_INTERNAL_IRQS, base,
231 0, &tc3589x_irq_ops, tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200232 }
Lee Jones15e27b12012-09-07 12:14:56 +0100233 else {
234 tc3589x->domain = irq_domain_add_linear(
235 NULL, TC3589x_NR_INTERNAL_IRQS,
236 &tc3589x_irq_ops, tc3589x);
237 }
238
239 if (!tc3589x->domain) {
240 dev_err(tc3589x->dev, "Failed to create irqdomain\n");
241 return -ENOSYS;
242 }
243
244 return 0;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200245}
246
Sundar Iyer20406eb2010-12-13 09:33:14 +0530247static int tc3589x_chip_init(struct tc3589x *tc3589x)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200248{
249 int manf, ver, ret;
250
Sundar Iyer20406eb2010-12-13 09:33:14 +0530251 manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200252 if (manf < 0)
253 return manf;
254
Sundar Iyer20406eb2010-12-13 09:33:14 +0530255 ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200256 if (ver < 0)
257 return ver;
258
Sundar Iyer20406eb2010-12-13 09:33:14 +0530259 if (manf != TC3589x_MANFCODE_MAGIC) {
260 dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200261 return -EINVAL;
262 }
263
Sundar Iyer20406eb2010-12-13 09:33:14 +0530264 dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200265
Sundar Iyer523bc382010-12-13 09:33:17 +0530266 /*
267 * Put everything except the IRQ module into reset;
268 * also spare the GPIO module for any pin initialization
269 * done during pre-kernel boot
270 */
Sundar Iyer20406eb2010-12-13 09:33:14 +0530271 ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL,
272 TC3589x_RSTCTRL_TIMRST
273 | TC3589x_RSTCTRL_ROTRST
Sundar Iyer523bc382010-12-13 09:33:17 +0530274 | TC3589x_RSTCTRL_KBDRST);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200275 if (ret < 0)
276 return ret;
277
278 /* Clear the reset interrupt. */
Sundar Iyer20406eb2010-12-13 09:33:14 +0530279 return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200280}
281
Sundar Iyer611b7592010-12-13 09:33:15 +0530282static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
283{
284 int ret = 0;
285 unsigned int blocks = tc3589x->pdata->block;
286
287 if (blocks & TC3589x_BLOCK_GPIO) {
288 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
Mark Brown55692af2012-09-11 15:16:36 +0800289 ARRAY_SIZE(tc3589x_dev_gpio), NULL,
Lee Jones15e27b12012-09-07 12:14:56 +0100290 tc3589x->irq_base, tc3589x->domain);
Sundar Iyer611b7592010-12-13 09:33:15 +0530291 if (ret) {
292 dev_err(tc3589x->dev, "failed to add gpio child\n");
293 return ret;
294 }
295 dev_info(tc3589x->dev, "added gpio block\n");
296 }
297
Sundar Iyer09c730a2010-12-21 15:53:31 +0530298 if (blocks & TC3589x_BLOCK_KEYPAD) {
299 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad,
Mark Brown55692af2012-09-11 15:16:36 +0800300 ARRAY_SIZE(tc3589x_dev_keypad), NULL,
Lee Jones15e27b12012-09-07 12:14:56 +0100301 tc3589x->irq_base, tc3589x->domain);
Sundar Iyer09c730a2010-12-21 15:53:31 +0530302 if (ret) {
303 dev_err(tc3589x->dev, "failed to keypad child\n");
304 return ret;
305 }
306 dev_info(tc3589x->dev, "added keypad block\n");
307 }
Sundar Iyer611b7592010-12-13 09:33:15 +0530308
Sundar Iyer09c730a2010-12-21 15:53:31 +0530309 return ret;
Sundar Iyer611b7592010-12-13 09:33:15 +0530310}
311
Sundar Iyer20406eb2010-12-13 09:33:14 +0530312static int __devinit tc3589x_probe(struct i2c_client *i2c,
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200313 const struct i2c_device_id *id)
314{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530315 struct tc3589x_platform_data *pdata = i2c->dev.platform_data;
316 struct tc3589x *tc3589x;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200317 int ret;
318
319 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
320 | I2C_FUNC_SMBUS_I2C_BLOCK))
321 return -EIO;
322
Sundar Iyer20406eb2010-12-13 09:33:14 +0530323 tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL);
324 if (!tc3589x)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200325 return -ENOMEM;
326
Sundar Iyer20406eb2010-12-13 09:33:14 +0530327 mutex_init(&tc3589x->lock);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200328
Sundar Iyer20406eb2010-12-13 09:33:14 +0530329 tc3589x->dev = &i2c->dev;
330 tc3589x->i2c = i2c;
331 tc3589x->pdata = pdata;
332 tc3589x->irq_base = pdata->irq_base;
333 tc3589x->num_gpio = id->driver_data;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200334
Sundar Iyer20406eb2010-12-13 09:33:14 +0530335 i2c_set_clientdata(i2c, tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200336
Sundar Iyer20406eb2010-12-13 09:33:14 +0530337 ret = tc3589x_chip_init(tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200338 if (ret)
339 goto out_free;
340
Sundar Iyer20406eb2010-12-13 09:33:14 +0530341 ret = tc3589x_irq_init(tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200342 if (ret)
343 goto out_free;
344
Sundar Iyer20406eb2010-12-13 09:33:14 +0530345 ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq,
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200346 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Sundar Iyer20406eb2010-12-13 09:33:14 +0530347 "tc3589x", tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200348 if (ret) {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530349 dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret);
Lee Jones15e27b12012-09-07 12:14:56 +0100350 goto out_free;
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200351 }
352
Sundar Iyer611b7592010-12-13 09:33:15 +0530353 ret = tc3589x_device_init(tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200354 if (ret) {
Sundar Iyer611b7592010-12-13 09:33:15 +0530355 dev_err(tc3589x->dev, "failed to add child devices\n");
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200356 goto out_freeirq;
357 }
358
359 return 0;
360
361out_freeirq:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530362 free_irq(tc3589x->i2c->irq, tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200363out_free:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530364 kfree(tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200365 return ret;
366}
367
Sundar Iyer20406eb2010-12-13 09:33:14 +0530368static int __devexit tc3589x_remove(struct i2c_client *client)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200369{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530370 struct tc3589x *tc3589x = i2c_get_clientdata(client);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200371
Sundar Iyer20406eb2010-12-13 09:33:14 +0530372 mfd_remove_devices(tc3589x->dev);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200373
Sundar Iyer20406eb2010-12-13 09:33:14 +0530374 free_irq(tc3589x->i2c->irq, tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200375
Sundar Iyer20406eb2010-12-13 09:33:14 +0530376 kfree(tc3589x);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200377
378 return 0;
379}
380
Axel Lin930bf022012-07-02 17:19:52 +0800381#ifdef CONFIG_PM_SLEEP
Sundar Iyer593e9d72010-12-13 09:33:18 +0530382static int tc3589x_suspend(struct device *dev)
383{
384 struct tc3589x *tc3589x = dev_get_drvdata(dev);
385 struct i2c_client *client = tc3589x->i2c;
386 int ret = 0;
387
388 /* put the system to sleep mode */
389 if (!device_may_wakeup(&client->dev))
390 ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
391 TC3589x_CLKMODE_MODCTL_SLEEP);
392
393 return ret;
394}
395
396static int tc3589x_resume(struct device *dev)
397{
398 struct tc3589x *tc3589x = dev_get_drvdata(dev);
399 struct i2c_client *client = tc3589x->i2c;
400 int ret = 0;
401
402 /* enable the system into operation */
403 if (!device_may_wakeup(&client->dev))
404 ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
405 TC3589x_CLKMODE_MODCTL_OPERATION);
406
407 return ret;
408}
Linus Walleij54d8e2c2011-08-09 20:37:17 +0200409#endif
Sundar Iyer593e9d72010-12-13 09:33:18 +0530410
Axel Lin930bf022012-07-02 17:19:52 +0800411static SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend, tc3589x_resume);
412
Sundar Iyer20406eb2010-12-13 09:33:14 +0530413static const struct i2c_device_id tc3589x_id[] = {
414 { "tc3589x", 24 },
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200415 { }
416};
Sundar Iyer20406eb2010-12-13 09:33:14 +0530417MODULE_DEVICE_TABLE(i2c, tc3589x_id);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200418
Sundar Iyer20406eb2010-12-13 09:33:14 +0530419static struct i2c_driver tc3589x_driver = {
420 .driver.name = "tc3589x",
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200421 .driver.owner = THIS_MODULE,
Sundar Iyer593e9d72010-12-13 09:33:18 +0530422 .driver.pm = &tc3589x_dev_pm_ops,
Sundar Iyer20406eb2010-12-13 09:33:14 +0530423 .probe = tc3589x_probe,
424 .remove = __devexit_p(tc3589x_remove),
425 .id_table = tc3589x_id,
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200426};
427
Sundar Iyer20406eb2010-12-13 09:33:14 +0530428static int __init tc3589x_init(void)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200429{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530430 return i2c_add_driver(&tc3589x_driver);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200431}
Sundar Iyer20406eb2010-12-13 09:33:14 +0530432subsys_initcall(tc3589x_init);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200433
Sundar Iyer20406eb2010-12-13 09:33:14 +0530434static void __exit tc3589x_exit(void)
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200435{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530436 i2c_del_driver(&tc3589x_driver);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200437}
Sundar Iyer20406eb2010-12-13 09:33:14 +0530438module_exit(tc3589x_exit);
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200439
440MODULE_LICENSE("GPL v2");
Sundar Iyer20406eb2010-12-13 09:33:14 +0530441MODULE_DESCRIPTION("TC3589x MFD core driver");
Rabin Vincentb4ecd322010-05-10 23:39:47 +0200442MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");