blob: 021dcf1d4d7739ca9734196d482365f8e4d88a0e [file] [log] [blame]
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/mfd/core.h>
17#include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h>
18#include <linux/mfd/wcd9xxx/core.h>
19#include <linux/mfd/wcd9xxx/pdata.h>
20#include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
21
22#include <linux/delay.h>
23#include <linux/gpio.h>
24#include <linux/debugfs.h>
25#include <linux/regulator/consumer.h>
26#include <linux/i2c.h>
27#include <sound/soc.h>
28
29#define WCD9XXX_SLIM_GLA_MAX_RETRIES 5
30#define WCD9XXX_REGISTER_START_OFFSET 0x800
31#define WCD9XXX_SLIM_RW_MAX_TRIES 3
32
33#define MAX_WCD9XXX_DEVICE 4
Asish Bhattacharya2b709d42011-11-15 10:39:23 +053034#define TABLA_I2C_MODE 0x03
35#define SITAR_I2C_MODE 0x01
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053036
37struct wcd9xxx_i2c {
38 struct i2c_client *client;
39 struct i2c_msg xfer_msg[2];
40 struct mutex xfer_lock;
41 int mod_id;
42};
43
44struct wcd9xxx_i2c wcd9xxx_modules[MAX_WCD9XXX_DEVICE];
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -070045static int wcd9xxx_intf = -1;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053046
47static int wcd9xxx_read(struct wcd9xxx *wcd9xxx, unsigned short reg,
48 int bytes, void *dest, bool interface_reg)
49{
50 int ret;
51 u8 *buf = dest;
52
53 if (bytes <= 0) {
54 dev_err(wcd9xxx->dev, "Invalid byte read length %d\n", bytes);
55 return -EINVAL;
56 }
57
58 ret = wcd9xxx->read_dev(wcd9xxx, reg, bytes, dest, interface_reg);
59 if (ret < 0) {
60 dev_err(wcd9xxx->dev, "Codec read failed\n");
61 return ret;
62 } else
Kiran Kandi1e6371d2012-03-29 11:48:57 -070063 dev_dbg(wcd9xxx->dev, "Read 0x%02x from 0x%x\n",
64 *buf, reg);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053065
66 return 0;
67}
68int wcd9xxx_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg)
69{
70 u8 val;
71 int ret;
72
73 mutex_lock(&wcd9xxx->io_lock);
74 ret = wcd9xxx_read(wcd9xxx, reg, 1, &val, false);
75 mutex_unlock(&wcd9xxx->io_lock);
76
77 if (ret < 0)
78 return ret;
79 else
80 return val;
81}
82EXPORT_SYMBOL_GPL(wcd9xxx_reg_read);
83
84static int wcd9xxx_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
85 int bytes, void *src, bool interface_reg)
86{
87 u8 *buf = src;
88
89 if (bytes <= 0) {
90 pr_err("%s: Error, invalid write length\n", __func__);
91 return -EINVAL;
92 }
93
Kiran Kandi1e6371d2012-03-29 11:48:57 -070094 dev_dbg(wcd9xxx->dev, "Write %02x to 0x%x\n",
95 *buf, reg);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053096
97 return wcd9xxx->write_dev(wcd9xxx, reg, bytes, src, interface_reg);
98}
99
100int wcd9xxx_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
101 u8 val)
102{
103 int ret;
104
105 mutex_lock(&wcd9xxx->io_lock);
106 ret = wcd9xxx_write(wcd9xxx, reg, 1, &val, false);
107 mutex_unlock(&wcd9xxx->io_lock);
108
109 return ret;
110}
111EXPORT_SYMBOL_GPL(wcd9xxx_reg_write);
112
113static u8 wcd9xxx_pgd_la;
114static u8 wcd9xxx_inf_la;
115
116int wcd9xxx_interface_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg)
117{
118 u8 val;
119 int ret;
120
121 mutex_lock(&wcd9xxx->io_lock);
122 ret = wcd9xxx_read(wcd9xxx, reg, 1, &val, true);
123 mutex_unlock(&wcd9xxx->io_lock);
124
125 if (ret < 0)
126 return ret;
127 else
128 return val;
129}
130EXPORT_SYMBOL_GPL(wcd9xxx_interface_reg_read);
131
132int wcd9xxx_interface_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
133 u8 val)
134{
135 int ret;
136
137 mutex_lock(&wcd9xxx->io_lock);
138 ret = wcd9xxx_write(wcd9xxx, reg, 1, &val, true);
139 mutex_unlock(&wcd9xxx->io_lock);
140
141 return ret;
142}
143EXPORT_SYMBOL_GPL(wcd9xxx_interface_reg_write);
144
145int wcd9xxx_bulk_read(struct wcd9xxx *wcd9xxx, unsigned short reg,
146 int count, u8 *buf)
147{
148 int ret;
149
150 mutex_lock(&wcd9xxx->io_lock);
151
152 ret = wcd9xxx_read(wcd9xxx, reg, count, buf, false);
153
154 mutex_unlock(&wcd9xxx->io_lock);
155
156 return ret;
157}
158EXPORT_SYMBOL_GPL(wcd9xxx_bulk_read);
159
160int wcd9xxx_bulk_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
161 int count, u8 *buf)
162{
163 int ret;
164
165 mutex_lock(&wcd9xxx->io_lock);
166
167 ret = wcd9xxx_write(wcd9xxx, reg, count, buf, false);
168
169 mutex_unlock(&wcd9xxx->io_lock);
170
171 return ret;
172}
173EXPORT_SYMBOL_GPL(wcd9xxx_bulk_write);
174
175static int wcd9xxx_slim_read_device(struct wcd9xxx *wcd9xxx, unsigned short reg,
176 int bytes, void *dest, bool interface)
177{
178 int ret;
179 struct slim_ele_access msg;
180 int slim_read_tries = WCD9XXX_SLIM_RW_MAX_TRIES;
181 msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg;
182 msg.num_bytes = bytes;
183 msg.comp = NULL;
184
185 while (1) {
186 mutex_lock(&wcd9xxx->xfer_lock);
187 ret = slim_request_val_element(interface ?
188 wcd9xxx->slim_slave : wcd9xxx->slim,
189 &msg, dest, bytes);
190 mutex_unlock(&wcd9xxx->xfer_lock);
191 if (likely(ret == 0) || (--slim_read_tries == 0))
192 break;
193 usleep_range(5000, 5000);
194 }
195
196 if (ret)
197 pr_err("%s: Error, Codec read failed (%d)\n", __func__, ret);
198
199 return ret;
200}
201/* Interface specifies whether the write is to the interface or general
202 * registers.
203 */
204static int wcd9xxx_slim_write_device(struct wcd9xxx *wcd9xxx,
205 unsigned short reg, int bytes, void *src, bool interface)
206{
207 int ret;
208 struct slim_ele_access msg;
209 int slim_write_tries = WCD9XXX_SLIM_RW_MAX_TRIES;
210 msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg;
211 msg.num_bytes = bytes;
212 msg.comp = NULL;
213
214 while (1) {
215 mutex_lock(&wcd9xxx->xfer_lock);
216 ret = slim_change_val_element(interface ?
217 wcd9xxx->slim_slave : wcd9xxx->slim,
218 &msg, src, bytes);
219 mutex_unlock(&wcd9xxx->xfer_lock);
220 if (likely(ret == 0) || (--slim_write_tries == 0))
221 break;
222 usleep_range(5000, 5000);
223 }
224
225 if (ret)
226 pr_err("%s: Error, Codec write failed (%d)\n", __func__, ret);
227
228 return ret;
229}
230
231static struct mfd_cell tabla1x_devs[] = {
232 {
233 .name = "tabla1x_codec",
234 },
235};
236
237static struct mfd_cell tabla_devs[] = {
238 {
239 .name = "tabla_codec",
240 },
241};
242
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530243static struct mfd_cell sitar_devs[] = {
244 {
245 .name = "sitar_codec",
246 },
247};
248
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530249static void wcd9xxx_bring_up(struct wcd9xxx *wcd9xxx)
250{
251 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x4);
252 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_CDC_CTL, 0);
253 usleep_range(5000, 5000);
254 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_CDC_CTL, 3);
255 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 3);
256}
257
258static void wcd9xxx_bring_down(struct wcd9xxx *wcd9xxx)
259{
260 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x7);
261 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x6);
262 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0xe);
263 wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x8);
264}
265
266static int wcd9xxx_reset(struct wcd9xxx *wcd9xxx)
267{
268 int ret;
269
270 if (wcd9xxx->reset_gpio) {
271 ret = gpio_request(wcd9xxx->reset_gpio, "CDC_RESET");
272 if (ret) {
273 pr_err("%s: Failed to request gpio %d\n", __func__,
274 wcd9xxx->reset_gpio);
275 wcd9xxx->reset_gpio = 0;
276 return ret;
277 }
278
279 gpio_direction_output(wcd9xxx->reset_gpio, 1);
280 msleep(20);
281 gpio_direction_output(wcd9xxx->reset_gpio, 0);
282 msleep(20);
283 gpio_direction_output(wcd9xxx->reset_gpio, 1);
284 msleep(20);
285 }
286 return 0;
287}
288
289static void wcd9xxx_free_reset(struct wcd9xxx *wcd9xxx)
290{
291 if (wcd9xxx->reset_gpio) {
292 gpio_free(wcd9xxx->reset_gpio);
293 wcd9xxx->reset_gpio = 0;
294 }
295}
296
297static int wcd9xxx_device_init(struct wcd9xxx *wcd9xxx, int irq)
298{
299 int ret;
300 u8 idbyte_0, idbyte_1, idbyte_2, idbyte_3;
301 struct mfd_cell *wcd9xxx_dev = NULL;
302 int wcd9xxx_dev_size = 0;
303
304 mutex_init(&wcd9xxx->io_lock);
305 mutex_init(&wcd9xxx->xfer_lock);
306
307 mutex_init(&wcd9xxx->pm_lock);
308 wcd9xxx->wlock_holders = 0;
309 wcd9xxx->pm_state = WCD9XXX_PM_SLEEPABLE;
310 init_waitqueue_head(&wcd9xxx->pm_wq);
Stephen Boyd2fcabf92012-05-30 10:41:11 -0700311 pm_qos_add_request(&wcd9xxx->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
312 PM_QOS_DEFAULT_VALUE);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530313
314 dev_set_drvdata(wcd9xxx->dev, wcd9xxx);
315
316 wcd9xxx_bring_up(wcd9xxx);
317
318 ret = wcd9xxx_irq_init(wcd9xxx);
319 if (ret) {
320 pr_err("IRQ initialization failed\n");
321 goto err;
322 }
323
324 idbyte_0 = wcd9xxx_reg_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_0);
325 idbyte_1 = wcd9xxx_reg_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_1);
326 idbyte_2 = wcd9xxx_reg_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_2);
327 idbyte_3 = wcd9xxx_reg_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_3);
328
329 wcd9xxx->version = wcd9xxx_reg_read(wcd9xxx,
330 WCD9XXX_A_CHIP_VERSION) & 0x1F;
331 pr_info("%s : Codec version %u initialized\n",
332 __func__, wcd9xxx->version);
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530333 pr_info("idbyte_0[%08x] idbyte_1[%08x] idbyte_2[%08x] idbyte_3[%08x]\n",
334 idbyte_0, idbyte_1, idbyte_2, idbyte_3);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530335
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700336 if (wcd9xxx->slim != NULL) {
337 if (!strncmp(wcd9xxx->slim->name, "tabla", 5)) {
338 if (TABLA_IS_1_X(wcd9xxx->version)) {
339 wcd9xxx_dev = tabla1x_devs;
340 wcd9xxx_dev_size = ARRAY_SIZE(tabla1x_devs);
341 } else {
342 wcd9xxx_dev = tabla_devs;
343 wcd9xxx_dev_size = ARRAY_SIZE(tabla_devs);
344 }
345 } else {
346 wcd9xxx_dev = sitar_devs;
347 wcd9xxx_dev_size = ARRAY_SIZE(sitar_devs);
348 }
349 } else {
350 /* Need to add here check for Tabla.
351 * For now the read of version takes
352 * care of now only tabla.
353 */
354 pr_debug("%s : Read codec version using I2C\n", __func__);
Asish Bhattacharya2b709d42011-11-15 10:39:23 +0530355 if (!strncmp(wcd9xxx_modules[0].client->name, "sitar", 5)) {
356 wcd9xxx_dev = sitar_devs;
357 wcd9xxx_dev_size = ARRAY_SIZE(sitar_devs);
358 } else if (TABLA_IS_1_X(wcd9xxx->version)) {
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530359 wcd9xxx_dev = tabla1x_devs;
360 wcd9xxx_dev_size = ARRAY_SIZE(tabla1x_devs);
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700361 } else if (TABLA_IS_2_0(wcd9xxx->version)) {
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530362 wcd9xxx_dev = tabla_devs;
363 wcd9xxx_dev_size = ARRAY_SIZE(tabla_devs);
364 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530365 }
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530366
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530367 ret = mfd_add_devices(wcd9xxx->dev, -1,
368 wcd9xxx_dev, wcd9xxx_dev_size,
369 NULL, 0);
370 if (ret != 0) {
371 dev_err(wcd9xxx->dev, "Failed to add children: %d\n", ret);
372 goto err_irq;
373 }
374 return ret;
375err_irq:
376 wcd9xxx_irq_exit(wcd9xxx);
377err:
378 wcd9xxx_bring_down(wcd9xxx);
Stephen Boyd2fcabf92012-05-30 10:41:11 -0700379 pm_qos_remove_request(&wcd9xxx->pm_qos_req);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530380 mutex_destroy(&wcd9xxx->pm_lock);
381 mutex_destroy(&wcd9xxx->io_lock);
382 mutex_destroy(&wcd9xxx->xfer_lock);
383 return ret;
384}
385
386static void wcd9xxx_device_exit(struct wcd9xxx *wcd9xxx)
387{
388 wcd9xxx_irq_exit(wcd9xxx);
389 wcd9xxx_bring_down(wcd9xxx);
390 wcd9xxx_free_reset(wcd9xxx);
391 mutex_destroy(&wcd9xxx->pm_lock);
Stephen Boyd2fcabf92012-05-30 10:41:11 -0700392 pm_qos_remove_request(&wcd9xxx->pm_qos_req);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530393 mutex_destroy(&wcd9xxx->io_lock);
394 mutex_destroy(&wcd9xxx->xfer_lock);
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700395 if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
396 slim_remove_device(wcd9xxx->slim_slave);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530397 kfree(wcd9xxx);
398}
399
400
401#ifdef CONFIG_DEBUG_FS
402struct wcd9xxx *debugCodec;
403
404static struct dentry *debugfs_wcd9xxx_dent;
405static struct dentry *debugfs_peek;
406static struct dentry *debugfs_poke;
407
408static unsigned char read_data;
409
410static int codec_debug_open(struct inode *inode, struct file *file)
411{
412 file->private_data = inode->i_private;
413 return 0;
414}
415
416static int get_parameters(char *buf, long int *param1, int num_of_par)
417{
418 char *token;
419 int base, cnt;
420
421 token = strsep(&buf, " ");
422
423 for (cnt = 0; cnt < num_of_par; cnt++) {
424 if (token != NULL) {
425 if ((token[1] == 'x') || (token[1] == 'X'))
426 base = 16;
427 else
428 base = 10;
429
430 if (strict_strtoul(token, base, &param1[cnt]) != 0)
431 return -EINVAL;
432
433 token = strsep(&buf, " ");
434 } else
435 return -EINVAL;
436 }
437 return 0;
438}
439
440static ssize_t codec_debug_read(struct file *file, char __user *ubuf,
441 size_t count, loff_t *ppos)
442{
443 char lbuf[8];
444
445 snprintf(lbuf, sizeof(lbuf), "0x%x\n", read_data);
446 return simple_read_from_buffer(ubuf, count, ppos, lbuf,
447 strnlen(lbuf, 7));
448}
449
450
451static ssize_t codec_debug_write(struct file *filp,
452 const char __user *ubuf, size_t cnt, loff_t *ppos)
453{
454 char *access_str = filp->private_data;
455 char lbuf[32];
456 int rc;
457 long int param[5];
458
459 if (cnt > sizeof(lbuf) - 1)
460 return -EINVAL;
461
462 rc = copy_from_user(lbuf, ubuf, cnt);
463 if (rc)
464 return -EFAULT;
465
466 lbuf[cnt] = '\0';
467
468 if (!strncmp(access_str, "poke", 6)) {
469 /* write */
470 rc = get_parameters(lbuf, param, 2);
471 if ((param[0] <= 0x3FF) && (param[1] <= 0xFF) &&
472 (rc == 0))
473 wcd9xxx_interface_reg_write(debugCodec, param[0],
474 param[1]);
475 else
476 rc = -EINVAL;
477 } else if (!strncmp(access_str, "peek", 6)) {
478 /* read */
479 rc = get_parameters(lbuf, param, 1);
480 if ((param[0] <= 0x3FF) && (rc == 0))
481 read_data = wcd9xxx_interface_reg_read(debugCodec,
482 param[0]);
483 else
484 rc = -EINVAL;
485 }
486
487 if (rc == 0)
488 rc = cnt;
489 else
490 pr_err("%s: rc = %d\n", __func__, rc);
491
492 return rc;
493}
494
495static const struct file_operations codec_debug_ops = {
496 .open = codec_debug_open,
497 .write = codec_debug_write,
498 .read = codec_debug_read
499};
500#endif
501
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700502static int wcd9xxx_enable_supplies(struct wcd9xxx *wcd9xxx,
503 struct wcd9xxx_pdata *pdata)
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530504{
505 int ret;
506 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530507 wcd9xxx->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
508 ARRAY_SIZE(pdata->regulator),
509 GFP_KERNEL);
510 if (!wcd9xxx->supplies) {
511 ret = -ENOMEM;
512 goto err;
513 }
514
515 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++)
516 wcd9xxx->supplies[i].supply = pdata->regulator[i].name;
517
518 ret = regulator_bulk_get(wcd9xxx->dev, ARRAY_SIZE(pdata->regulator),
519 wcd9xxx->supplies);
520 if (ret != 0) {
521 dev_err(wcd9xxx->dev, "Failed to get supplies: err = %d\n",
522 ret);
523 goto err_supplies;
524 }
525
526 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
527 ret = regulator_set_voltage(wcd9xxx->supplies[i].consumer,
528 pdata->regulator[i].min_uV, pdata->regulator[i].max_uV);
529 if (ret) {
530 pr_err("%s: Setting regulator voltage failed for "
531 "regulator %s err = %d\n", __func__,
532 wcd9xxx->supplies[i].supply, ret);
533 goto err_get;
534 }
535
536 ret = regulator_set_optimum_mode(wcd9xxx->supplies[i].consumer,
537 pdata->regulator[i].optimum_uA);
538 if (ret < 0) {
539 pr_err("%s: Setting regulator optimum mode failed for "
540 "regulator %s err = %d\n", __func__,
541 wcd9xxx->supplies[i].supply, ret);
542 goto err_get;
543 }
544 }
545
546 ret = regulator_bulk_enable(ARRAY_SIZE(pdata->regulator),
547 wcd9xxx->supplies);
548 if (ret != 0) {
549 dev_err(wcd9xxx->dev, "Failed to enable supplies: err = %d\n",
550 ret);
551 goto err_configure;
552 }
553 return ret;
554
555err_configure:
556 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
557 regulator_set_voltage(wcd9xxx->supplies[i].consumer, 0,
558 pdata->regulator[i].max_uV);
559 regulator_set_optimum_mode(wcd9xxx->supplies[i].consumer, 0);
560 }
561err_get:
562 regulator_bulk_free(ARRAY_SIZE(pdata->regulator), wcd9xxx->supplies);
563err_supplies:
564 kfree(wcd9xxx->supplies);
565err:
566 return ret;
567}
568
Venkat Sudhir49203862012-05-21 14:29:13 -0700569static void wcd9xxx_disable_supplies(struct wcd9xxx *wcd9xxx,
570 struct wcd9xxx_pdata *pdata)
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530571{
572 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530573
574 regulator_bulk_disable(ARRAY_SIZE(pdata->regulator),
575 wcd9xxx->supplies);
576 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
577 regulator_set_voltage(wcd9xxx->supplies[i].consumer, 0,
578 pdata->regulator[i].max_uV);
579 regulator_set_optimum_mode(wcd9xxx->supplies[i].consumer, 0);
580 }
581 regulator_bulk_free(ARRAY_SIZE(pdata->regulator), wcd9xxx->supplies);
582 kfree(wcd9xxx->supplies);
583}
584
585int wcd9xxx_get_intf_type(void)
586{
587 return wcd9xxx_intf;
588}
589EXPORT_SYMBOL_GPL(wcd9xxx_get_intf_type);
590
591struct wcd9xxx_i2c *get_i2c_wcd9xxx_device_info(u16 reg)
592{
593 u16 mask = 0x0f00;
594 int value = 0;
595 struct wcd9xxx_i2c *wcd9xxx = NULL;
596 value = ((reg & mask) >> 8) & 0x000f;
597 switch (value) {
598 case 0:
599 wcd9xxx = &wcd9xxx_modules[0];
600 break;
601 case 1:
602 wcd9xxx = &wcd9xxx_modules[1];
603 break;
604 case 2:
605 wcd9xxx = &wcd9xxx_modules[2];
606 break;
607 case 3:
608 wcd9xxx = &wcd9xxx_modules[3];
609 break;
610 default:
611 break;
612 }
613 return wcd9xxx;
614}
615
616int wcd9xxx_i2c_write_device(u16 reg, u8 *value,
617 u32 bytes)
618{
619
620 struct i2c_msg *msg;
621 int ret = 0;
622 u8 reg_addr = 0;
623 u8 data[bytes + 1];
624 struct wcd9xxx_i2c *wcd9xxx;
625
626 wcd9xxx = get_i2c_wcd9xxx_device_info(reg);
627 if (wcd9xxx == NULL || wcd9xxx->client == NULL) {
628 pr_err("failed to get device info\n");
629 return -ENODEV;
630 }
631 reg_addr = (u8)reg;
632 msg = &wcd9xxx->xfer_msg[0];
633 msg->addr = wcd9xxx->client->addr;
634 msg->len = bytes + 1;
635 msg->flags = 0;
636 data[0] = reg;
637 data[1] = *value;
638 msg->buf = data;
639 ret = i2c_transfer(wcd9xxx->client->adapter, wcd9xxx->xfer_msg, 1);
640 /* Try again if the write fails */
641 if (ret != 1) {
642 ret = i2c_transfer(wcd9xxx->client->adapter,
643 wcd9xxx->xfer_msg, 1);
644 if (ret != 1) {
645 pr_err("failed to write the device\n");
646 return ret;
647 }
648 }
649 pr_debug("write sucess register = %x val = %x\n", reg, data[1]);
650 return 0;
651}
652
653
654int wcd9xxx_i2c_read_device(unsigned short reg,
655 int bytes, unsigned char *dest)
656{
657 struct i2c_msg *msg;
658 int ret = 0;
659 u8 reg_addr = 0;
660 struct wcd9xxx_i2c *wcd9xxx;
661 u8 i = 0;
662
663 wcd9xxx = get_i2c_wcd9xxx_device_info(reg);
664 if (wcd9xxx == NULL || wcd9xxx->client == NULL) {
665 pr_err("failed to get device info\n");
666 return -ENODEV;
667 }
668 for (i = 0; i < bytes; i++) {
669 reg_addr = (u8)reg++;
670 msg = &wcd9xxx->xfer_msg[0];
671 msg->addr = wcd9xxx->client->addr;
672 msg->len = 1;
673 msg->flags = 0;
674 msg->buf = &reg_addr;
675
676 msg = &wcd9xxx->xfer_msg[1];
677 msg->addr = wcd9xxx->client->addr;
678 msg->len = 1;
679 msg->flags = I2C_M_RD;
680 msg->buf = dest++;
681 ret = i2c_transfer(wcd9xxx->client->adapter,
682 wcd9xxx->xfer_msg, 2);
683
684 /* Try again if read fails first time */
685 if (ret != 2) {
686 ret = i2c_transfer(wcd9xxx->client->adapter,
687 wcd9xxx->xfer_msg, 2);
688 if (ret != 2) {
689 pr_err("failed to read wcd9xxx register\n");
690 return ret;
691 }
692 }
693 }
694 return 0;
695}
696
697int wcd9xxx_i2c_read(struct wcd9xxx *wcd9xxx, unsigned short reg,
698 int bytes, void *dest, bool interface_reg)
699{
700 return wcd9xxx_i2c_read_device(reg, bytes, dest);
701}
702
703int wcd9xxx_i2c_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
704 int bytes, void *src, bool interface_reg)
705{
706 return wcd9xxx_i2c_write_device(reg, src, bytes);
707}
708
709static int __devinit wcd9xxx_i2c_probe(struct i2c_client *client,
710 const struct i2c_device_id *id)
711{
712 struct wcd9xxx *wcd9xxx;
713 struct wcd9xxx_pdata *pdata = client->dev.platform_data;
714 int val = 0;
715 int ret = 0;
Asish Bhattacharya2b709d42011-11-15 10:39:23 +0530716 int i2c_mode = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530717 static int device_id;
718
Asish Bhattacharya2b709d42011-11-15 10:39:23 +0530719 pr_info("%s\n", __func__);
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700720 if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
721 pr_info("tabla card is already detected in slimbus mode\n");
722 return -ENODEV;
723 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530724 if (device_id > 0) {
725 wcd9xxx_modules[device_id++].client = client;
726 pr_info("probe for other slaves devices of tabla\n");
727 return ret;
728 }
729
730 wcd9xxx = kzalloc(sizeof(struct wcd9xxx), GFP_KERNEL);
731 if (wcd9xxx == NULL) {
732 pr_err("%s: error, allocation failed\n", __func__);
733 ret = -ENOMEM;
734 goto fail;
735 }
736
737 if (!pdata) {
738 dev_dbg(&client->dev, "no platform data?\n");
739 ret = -EINVAL;
740 goto fail;
741 }
742 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
743 dev_dbg(&client->dev, "can't talk I2C?\n");
744 ret = -EIO;
745 goto fail;
746 }
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530747 dev_set_drvdata(&client->dev, wcd9xxx);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530748 wcd9xxx->dev = &client->dev;
749 wcd9xxx->reset_gpio = pdata->reset_gpio;
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700750 ret = wcd9xxx_enable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530751 if (ret) {
752 pr_err("%s: Fail to enable Codec supplies\n", __func__);
753 goto err_codec;
754 }
755
756 usleep_range(5, 5);
757 ret = wcd9xxx_reset(wcd9xxx);
758 if (ret) {
759 pr_err("%s: Resetting Codec failed\n", __func__);
760 goto err_supplies;
761 }
762 wcd9xxx_modules[device_id++].client = client;
763
764 wcd9xxx->read_dev = wcd9xxx_i2c_read;
765 wcd9xxx->write_dev = wcd9xxx_i2c_write;
766 wcd9xxx->irq = pdata->irq;
767 wcd9xxx->irq_base = pdata->irq_base;
768
769 /*read the tabla status before initializing the device type*/
770 ret = wcd9xxx_read(wcd9xxx, WCD9XXX_A_CHIP_STATUS, 1, &val, 0);
Asish Bhattacharya2b709d42011-11-15 10:39:23 +0530771 if (!strncmp(wcd9xxx_modules[0].client->name, "sitar", 5))
772 i2c_mode = SITAR_I2C_MODE;
773 else if (!strncmp(wcd9xxx_modules[0].client->name, "tabla", 5))
774 i2c_mode = TABLA_I2C_MODE;
775
776 if ((ret < 0) || (val != i2c_mode))
777 pr_err("failed to read the wcd9xxx status ret = %d\n", ret);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530778
779 ret = wcd9xxx_device_init(wcd9xxx, wcd9xxx->irq);
780 if (ret) {
781 pr_err("%s: error, initializing device failed\n", __func__);
782 goto err_device_init;
783 }
784 wcd9xxx_intf = WCD9XXX_INTERFACE_TYPE_I2C;
785
786 return ret;
787err_device_init:
788 wcd9xxx_free_reset(wcd9xxx);
789err_supplies:
Venkat Sudhir49203862012-05-21 14:29:13 -0700790 wcd9xxx_disable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530791err_codec:
792 kfree(wcd9xxx);
793fail:
794 return ret;
795}
796
797static int __devexit wcd9xxx_i2c_remove(struct i2c_client *client)
798{
799 struct wcd9xxx *wcd9xxx;
Venkat Sudhir49203862012-05-21 14:29:13 -0700800 struct wcd9xxx_pdata *pdata = client->dev.platform_data;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530801 pr_debug("exit\n");
802 wcd9xxx = dev_get_drvdata(&client->dev);
Venkat Sudhir49203862012-05-21 14:29:13 -0700803 wcd9xxx_disable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530804 wcd9xxx_device_exit(wcd9xxx);
805 return 0;
806}
807
808static int wcd9xxx_slim_probe(struct slim_device *slim)
809{
810 struct wcd9xxx *wcd9xxx;
811 struct wcd9xxx_pdata *pdata;
812 int ret = 0;
813 int sgla_retry_cnt;
814
815 dev_info(&slim->dev, "Initialized slim device %s\n", slim->name);
816 pdata = slim->dev.platform_data;
817
818 if (!pdata) {
819 dev_err(&slim->dev, "Error, no platform data\n");
820 ret = -EINVAL;
821 goto err;
822 }
823
824 wcd9xxx = kzalloc(sizeof(struct wcd9xxx), GFP_KERNEL);
825 if (wcd9xxx == NULL) {
826 pr_err("%s: error, allocation failed\n", __func__);
827 ret = -ENOMEM;
828 goto err;
829 }
830 if (!slim->ctrl) {
831 pr_err("Error, no SLIMBUS control data\n");
832 ret = -EINVAL;
833 goto err_codec;
834 }
835 wcd9xxx->slim = slim;
836 slim_set_clientdata(slim, wcd9xxx);
837 wcd9xxx->reset_gpio = pdata->reset_gpio;
838 wcd9xxx->dev = &slim->dev;
839
Venkat Sudhirdb7aa2b2012-05-15 15:06:14 -0700840 ret = wcd9xxx_enable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530841 if (ret)
842 goto err_codec;
843 usleep_range(5, 5);
844
845 ret = wcd9xxx_reset(wcd9xxx);
846 if (ret) {
847 pr_err("%s: Resetting Codec failed\n", __func__);
848 goto err_supplies;
849 }
850
851 ret = slim_get_logical_addr(wcd9xxx->slim, wcd9xxx->slim->e_addr,
852 ARRAY_SIZE(wcd9xxx->slim->e_addr), &wcd9xxx->slim->laddr);
853 if (ret) {
854 pr_err("fail to get slimbus logical address %d\n", ret);
855 goto err_reset;
856 }
857 wcd9xxx->read_dev = wcd9xxx_slim_read_device;
858 wcd9xxx->write_dev = wcd9xxx_slim_write_device;
859 wcd9xxx->irq = pdata->irq;
860 wcd9xxx->irq_base = pdata->irq_base;
861 wcd9xxx_pgd_la = wcd9xxx->slim->laddr;
862
863 if (pdata->num_irqs < TABLA_NUM_IRQS) {
864 pr_err("%s: Error, not enough interrupt lines allocated\n",
865 __func__);
866 goto err_reset;
867 }
868
869 wcd9xxx->slim_slave = &pdata->slimbus_slave_device;
870
871 ret = slim_add_device(slim->ctrl, wcd9xxx->slim_slave);
872 if (ret) {
873 pr_err("%s: error, adding SLIMBUS device failed\n", __func__);
874 goto err_reset;
875 }
876
877 sgla_retry_cnt = 0;
878
879 while (1) {
880 ret = slim_get_logical_addr(wcd9xxx->slim_slave,
881 wcd9xxx->slim_slave->e_addr,
882 ARRAY_SIZE(wcd9xxx->slim_slave->e_addr),
883 &wcd9xxx->slim_slave->laddr);
884 if (ret) {
885 if (sgla_retry_cnt++ < WCD9XXX_SLIM_GLA_MAX_RETRIES) {
886 /* Give SLIMBUS slave time to report present
887 and be ready.
888 */
889 usleep_range(1000, 1000);
890 pr_debug("%s: retry slim_get_logical_addr()\n",
891 __func__);
892 continue;
893 }
894 pr_err("fail to get slimbus slave logical address"
895 " %d\n", ret);
896 goto err_slim_add;
897 }
898 break;
899 }
900 wcd9xxx_inf_la = wcd9xxx->slim_slave->laddr;
901 wcd9xxx_intf = WCD9XXX_INTERFACE_TYPE_SLIMBUS;
902
903 ret = wcd9xxx_device_init(wcd9xxx, wcd9xxx->irq);
904 if (ret) {
905 pr_err("%s: error, initializing device failed\n", __func__);
906 goto err_slim_add;
907 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530908 wcd9xxx_init_slimslave(wcd9xxx, wcd9xxx_pgd_la);
909#ifdef CONFIG_DEBUG_FS
910 debugCodec = wcd9xxx;
911
912 debugfs_wcd9xxx_dent = debugfs_create_dir
913 ("wcd9310_slimbus_interface_device", 0);
914 if (!IS_ERR(debugfs_wcd9xxx_dent)) {
915 debugfs_peek = debugfs_create_file("peek",
916 S_IFREG | S_IRUGO, debugfs_wcd9xxx_dent,
917 (void *) "peek", &codec_debug_ops);
918
919 debugfs_poke = debugfs_create_file("poke",
920 S_IFREG | S_IRUGO, debugfs_wcd9xxx_dent,
921 (void *) "poke", &codec_debug_ops);
922 }
923#endif
924
925 return ret;
926
927err_slim_add:
928 slim_remove_device(wcd9xxx->slim_slave);
929err_reset:
930 wcd9xxx_free_reset(wcd9xxx);
931err_supplies:
Venkat Sudhir49203862012-05-21 14:29:13 -0700932 wcd9xxx_disable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530933err_codec:
934 kfree(wcd9xxx);
935err:
936 return ret;
937}
938static int wcd9xxx_slim_remove(struct slim_device *pdev)
939{
940 struct wcd9xxx *wcd9xxx;
Venkat Sudhir49203862012-05-21 14:29:13 -0700941 struct wcd9xxx_pdata *pdata = pdev->dev.platform_data;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530942
943#ifdef CONFIG_DEBUG_FS
944 debugfs_remove(debugfs_peek);
945 debugfs_remove(debugfs_poke);
946 debugfs_remove(debugfs_wcd9xxx_dent);
947#endif
948 wcd9xxx = slim_get_devicedata(pdev);
949 wcd9xxx_deinit_slimslave(wcd9xxx);
950 slim_remove_device(wcd9xxx->slim_slave);
Venkat Sudhir49203862012-05-21 14:29:13 -0700951 wcd9xxx_disable_supplies(wcd9xxx, pdata);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530952 wcd9xxx_device_exit(wcd9xxx);
953 return 0;
954}
955
956static int wcd9xxx_resume(struct wcd9xxx *wcd9xxx)
957{
958 int ret = 0;
959
960 pr_debug("%s: enter\n", __func__);
961 mutex_lock(&wcd9xxx->pm_lock);
962 if (wcd9xxx->pm_state == WCD9XXX_PM_ASLEEP) {
963 pr_debug("%s: resuming system, state %d, wlock %d\n", __func__,
964 wcd9xxx->pm_state, wcd9xxx->wlock_holders);
965 wcd9xxx->pm_state = WCD9XXX_PM_SLEEPABLE;
966 } else {
967 pr_warn("%s: system is already awake, state %d wlock %d\n",
968 __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders);
969 }
970 mutex_unlock(&wcd9xxx->pm_lock);
971 wake_up_all(&wcd9xxx->pm_wq);
972
973 return ret;
974}
975
976static int wcd9xxx_slim_resume(struct slim_device *sldev)
977{
978 struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
979 return wcd9xxx_resume(wcd9xxx);
980}
981
982static int wcd9xxx_i2c_resume(struct i2c_client *i2cdev)
983{
984 struct wcd9xxx *wcd9xxx = dev_get_drvdata(&i2cdev->dev);
Asish Bhattacharyab86c3472012-02-15 08:31:52 +0530985 if (wcd9xxx)
986 return wcd9xxx_resume(wcd9xxx);
987 else
988 return 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530989}
990
991static int wcd9xxx_suspend(struct wcd9xxx *wcd9xxx, pm_message_t pmesg)
992{
993 int ret = 0;
994
995 pr_debug("%s: enter\n", __func__);
Stephen Boyd2fcabf92012-05-30 10:41:11 -0700996 /*
997 * pm_qos_update_request() can be called after this suspend chain call
998 * started. thus suspend can be called while lock is being held
999 */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301000 mutex_lock(&wcd9xxx->pm_lock);
1001 if (wcd9xxx->pm_state == WCD9XXX_PM_SLEEPABLE) {
1002 pr_debug("%s: suspending system, state %d, wlock %d\n",
1003 __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders);
1004 wcd9xxx->pm_state = WCD9XXX_PM_ASLEEP;
1005 } else if (wcd9xxx->pm_state == WCD9XXX_PM_AWAKE) {
1006 /* unlock to wait for pm_state == WCD9XXX_PM_SLEEPABLE
1007 * then set to WCD9XXX_PM_ASLEEP */
1008 pr_debug("%s: waiting to suspend system, state %d, wlock %d\n",
1009 __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders);
1010 mutex_unlock(&wcd9xxx->pm_lock);
1011 if (!(wait_event_timeout(wcd9xxx->pm_wq,
1012 wcd9xxx_pm_cmpxchg(wcd9xxx,
1013 WCD9XXX_PM_SLEEPABLE,
1014 WCD9XXX_PM_ASLEEP) ==
1015 WCD9XXX_PM_SLEEPABLE,
1016 HZ))) {
1017 pr_debug("%s: suspend failed state %d, wlock %d\n",
1018 __func__, wcd9xxx->pm_state,
1019 wcd9xxx->wlock_holders);
1020 ret = -EBUSY;
1021 } else {
1022 pr_debug("%s: done, state %d, wlock %d\n", __func__,
1023 wcd9xxx->pm_state, wcd9xxx->wlock_holders);
1024 }
1025 mutex_lock(&wcd9xxx->pm_lock);
1026 } else if (wcd9xxx->pm_state == WCD9XXX_PM_ASLEEP) {
1027 pr_warn("%s: system is already suspended, state %d, wlock %dn",
1028 __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders);
1029 }
1030 mutex_unlock(&wcd9xxx->pm_lock);
1031
1032 return ret;
1033}
1034
1035static int wcd9xxx_slim_suspend(struct slim_device *sldev, pm_message_t pmesg)
1036{
1037 struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
1038 return wcd9xxx_suspend(wcd9xxx, pmesg);
1039}
1040
1041static int wcd9xxx_i2c_suspend(struct i2c_client *i2cdev, pm_message_t pmesg)
1042{
1043 struct wcd9xxx *wcd9xxx = dev_get_drvdata(&i2cdev->dev);
Asish Bhattacharyab86c3472012-02-15 08:31:52 +05301044 if (wcd9xxx)
1045 return wcd9xxx_suspend(wcd9xxx, pmesg);
1046 else
1047 return 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301048}
1049
Asish Bhattacharyab86c3472012-02-15 08:31:52 +05301050static const struct slim_device_id sitar_slimtest_id[] = {
1051 {"sitar-slim", 0},
1052 {}
1053};
1054static struct slim_driver sitar_slim_driver = {
1055 .driver = {
1056 .name = "sitar-slim",
1057 .owner = THIS_MODULE,
1058 },
1059 .probe = wcd9xxx_slim_probe,
1060 .remove = wcd9xxx_slim_remove,
1061 .id_table = sitar_slimtest_id,
1062 .resume = wcd9xxx_slim_resume,
1063 .suspend = wcd9xxx_slim_suspend,
1064};
1065
Bhalchandra Gajare83c81f62012-05-18 16:09:05 -07001066static const struct slim_device_id sitar1p1_slimtest_id[] = {
1067 {"sitar1p1-slim", 0},
1068 {}
1069};
1070static struct slim_driver sitar1p1_slim_driver = {
1071 .driver = {
1072 .name = "sitar1p1-slim",
1073 .owner = THIS_MODULE,
1074 },
1075 .probe = wcd9xxx_slim_probe,
1076 .remove = wcd9xxx_slim_remove,
1077 .id_table = sitar1p1_slimtest_id,
1078 .resume = wcd9xxx_slim_resume,
1079 .suspend = wcd9xxx_slim_suspend,
1080};
1081
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301082static const struct slim_device_id slimtest_id[] = {
1083 {"tabla-slim", 0},
1084 {}
1085};
1086
1087static struct slim_driver tabla_slim_driver = {
1088 .driver = {
1089 .name = "tabla-slim",
1090 .owner = THIS_MODULE,
1091 },
1092 .probe = wcd9xxx_slim_probe,
1093 .remove = wcd9xxx_slim_remove,
1094 .id_table = slimtest_id,
1095 .resume = wcd9xxx_slim_resume,
1096 .suspend = wcd9xxx_slim_suspend,
1097};
1098
1099static const struct slim_device_id slimtest2x_id[] = {
1100 {"tabla2x-slim", 0},
1101 {}
1102};
1103
1104static struct slim_driver tabla2x_slim_driver = {
1105 .driver = {
1106 .name = "tabla2x-slim",
1107 .owner = THIS_MODULE,
1108 },
1109 .probe = wcd9xxx_slim_probe,
1110 .remove = wcd9xxx_slim_remove,
1111 .id_table = slimtest2x_id,
1112 .resume = wcd9xxx_slim_resume,
1113 .suspend = wcd9xxx_slim_suspend,
1114};
1115
Asish Bhattacharya2b709d42011-11-15 10:39:23 +05301116#define WCD9XXX_I2C_TOP_LEVEL 0
1117#define WCD9XXX_I2C_ANALOG 1
1118#define WCD9XXX_I2C_DIGITAL_1 2
1119#define WCD9XXX_I2C_DIGITAL_2 3
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301120
1121static struct i2c_device_id tabla_id_table[] = {
Asish Bhattacharya2b709d42011-11-15 10:39:23 +05301122 {"tabla top level", WCD9XXX_I2C_TOP_LEVEL},
1123 {"tabla analog", WCD9XXX_I2C_ANALOG},
1124 {"tabla digital1", WCD9XXX_I2C_DIGITAL_1},
1125 {"tabla digital2", WCD9XXX_I2C_DIGITAL_2},
1126 {}
1127};
1128MODULE_DEVICE_TABLE(i2c, tabla_id_table);
1129
1130static struct i2c_device_id sitar_id_table[] = {
1131 {"sitar top level", WCD9XXX_I2C_TOP_LEVEL},
1132 {"sitar analog", WCD9XXX_I2C_ANALOG},
1133 {"sitar digital1", WCD9XXX_I2C_DIGITAL_1},
1134 {"sitar digital2", WCD9XXX_I2C_DIGITAL_2},
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301135 {}
1136};
1137MODULE_DEVICE_TABLE(i2c, tabla_id_table);
1138
1139static struct i2c_driver tabla_i2c_driver = {
1140 .driver = {
1141 .owner = THIS_MODULE,
1142 .name = "tabla-i2c-core",
1143 },
1144 .id_table = tabla_id_table,
1145 .probe = wcd9xxx_i2c_probe,
1146 .remove = __devexit_p(wcd9xxx_i2c_remove),
1147 .resume = wcd9xxx_i2c_resume,
1148 .suspend = wcd9xxx_i2c_suspend,
1149};
1150
Asish Bhattacharya2b709d42011-11-15 10:39:23 +05301151static struct i2c_driver sitar_i2c_driver = {
1152 .driver = {
1153 .owner = THIS_MODULE,
1154 .name = "sitar-i2c-core",
1155 },
1156 .id_table = sitar_id_table,
1157 .probe = wcd9xxx_i2c_probe,
1158 .remove = __devexit_p(wcd9xxx_i2c_remove),
1159 .resume = wcd9xxx_i2c_resume,
1160 .suspend = wcd9xxx_i2c_suspend,
1161};
1162
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301163static int __init wcd9xxx_init(void)
1164{
Asish Bhattacharya2b709d42011-11-15 10:39:23 +05301165 int ret1, ret2, ret3, ret4, ret5, ret6;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301166
1167 ret1 = slim_driver_register(&tabla_slim_driver);
1168 if (ret1 != 0)
1169 pr_err("Failed to register tabla SB driver: %d\n", ret1);
1170
1171 ret2 = slim_driver_register(&tabla2x_slim_driver);
1172 if (ret2 != 0)
1173 pr_err("Failed to register tabla2x SB driver: %d\n", ret2);
1174
1175 ret3 = i2c_add_driver(&tabla_i2c_driver);
1176 if (ret3 != 0)
1177 pr_err("failed to add the I2C driver\n");
1178
Asish Bhattacharyab86c3472012-02-15 08:31:52 +05301179 ret4 = slim_driver_register(&sitar_slim_driver);
Bhalchandra Gajare83c81f62012-05-18 16:09:05 -07001180 if (ret4 != 0)
Asish Bhattacharyab86c3472012-02-15 08:31:52 +05301181 pr_err("Failed to register sitar SB driver: %d\n", ret4);
1182
Bhalchandra Gajare83c81f62012-05-18 16:09:05 -07001183 ret5 = slim_driver_register(&sitar1p1_slim_driver);
1184 if (ret5 != 0)
1185 pr_err("Failed to register sitar SB driver: %d\n", ret5);
1186
Asish Bhattacharya2b709d42011-11-15 10:39:23 +05301187 ret6 = i2c_add_driver(&sitar_i2c_driver);
1188 if (ret6 != 0)
1189 pr_err("failed to add the I2C driver\n");
1190
1191 return (ret1 && ret2 && ret3 && ret4 && ret5 && ret6) ? -1 : 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05301192}
1193module_init(wcd9xxx_init);
1194
1195static void __exit wcd9xxx_exit(void)
1196{
1197}
1198module_exit(wcd9xxx_exit);
1199
1200MODULE_DESCRIPTION("Codec core driver");
1201MODULE_VERSION("1.0");
1202MODULE_LICENSE("GPL v2");