1 /*
2 * ALSA SoC Texas Instruments TAS2562 High Performance 4W Smart Amplifier
3 *
4 * Copyright (C) 2016 Texas Instruments, Inc.
5 *
6 * Author: saiprasad
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 */
17 #ifdef CONFIG_TAS2562_REGMAP
19 #define DEBUG 5
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/pm.h>
26 #include <linux/i2c.h>
27 #include <linux/gpio.h>
28 #include <linux/regulator/consumer.h>
29 #include <linux/firmware.h>
30 #include <linux/regmap.h>
31 #include <linux/of.h>
32 #include <linux/of_gpio.h>
33 #include <linux/slab.h>
34 #include <sound/soc.h>
35 #include <linux/interrupt.h>
36 #include <linux/irq.h>
38 #include "tas2562.h"
39 #include "tas2562-codec.h"
40 #include "tas2562-misc.h"
42 static int tas2562_change_book_page(struct tas2562_priv *pTAS2562,
43 int book, int page)
44 {
45 int nResult = 0;
47 if ((pTAS2562->mnCurrentBook == book)
48 && (pTAS2562->mnCurrentPage == page))
49 goto end;
51 if (pTAS2562->mnCurrentBook != book) {
52 nResult = regmap_write(pTAS2562->regmap, TAS2562_BOOKCTL_PAGE, 0);
53 if (nResult < 0) {
54 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
55 __func__, __LINE__, nResult);
56 goto end;
57 }
58 pTAS2562->mnCurrentPage = 0;
59 nResult = regmap_write(pTAS2562->regmap, TAS2562_BOOKCTL_REG, book);
60 if (nResult < 0) {
61 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
62 __func__, __LINE__, nResult);
63 goto end;
64 }
65 pTAS2562->mnCurrentBook = book;
66 }
68 if (pTAS2562->mnCurrentPage != page) {
69 nResult = regmap_write(pTAS2562->regmap, TAS2562_BOOKCTL_PAGE, page);
70 if (nResult < 0) {
71 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
72 __func__, __LINE__, nResult);
73 goto end;
74 }
75 pTAS2562->mnCurrentPage = page;
76 }
78 end:
79 return nResult;
80 }
82 static int tas2562_dev_read(struct tas2562_priv *pTAS2562,
83 unsigned int reg, unsigned int *pValue)
84 {
85 int nResult = 0;
87 mutex_lock(&pTAS2562->dev_lock);
89 nResult = tas2562_change_book_page(pTAS2562,
90 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg));
91 if (nResult < 0)
92 goto end;
94 nResult = regmap_read(pTAS2562->regmap, TAS2562_PAGE_REG(reg), pValue);
95 if (nResult < 0)
96 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
97 __func__, __LINE__, nResult);
98 else
99 dev_dbg(pTAS2562->dev, "%s: BOOK:PAGE:REG %u:%u:%u\n", __func__,
100 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg),
101 TAS2562_PAGE_REG(reg));
103 end:
104 mutex_unlock(&pTAS2562->dev_lock);
105 return nResult;
106 }
108 static int tas2562_dev_write(struct tas2562_priv *pTAS2562,
109 unsigned int reg, unsigned int value)
110 {
111 int nResult = 0;
113 mutex_lock(&pTAS2562->dev_lock);
115 nResult = tas2562_change_book_page(pTAS2562,
116 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg));
117 if (nResult < 0)
118 goto end;
120 nResult = regmap_write(pTAS2562->regmap, TAS2562_PAGE_REG(reg),
121 value);
122 if (nResult < 0)
123 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
124 __func__, __LINE__, nResult);
125 else
126 dev_dbg(pTAS2562->dev, "%s: BOOK:PAGE:REG %u:%u:%u, VAL: 0x%02x\n",
127 __func__, TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg),
128 TAS2562_PAGE_REG(reg), value);
130 end:
131 mutex_unlock(&pTAS2562->dev_lock);
132 return nResult;
133 }
135 static int tas2562_dev_bulk_write(struct tas2562_priv *pTAS2562,
136 unsigned int reg, unsigned char *pData, unsigned int nLength)
137 {
138 int nResult = 0;
140 mutex_lock(&pTAS2562->dev_lock);
142 nResult = tas2562_change_book_page(pTAS2562,
143 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg));
144 if (nResult < 0)
145 goto end;
147 nResult = regmap_bulk_write(pTAS2562->regmap,
148 TAS2562_PAGE_REG(reg), pData, nLength);
149 if (nResult < 0)
150 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
151 __func__, __LINE__, nResult);
152 else
153 dev_dbg(pTAS2562->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n",
154 __func__, TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg),
155 TAS2562_PAGE_REG(reg), nLength);
157 end:
158 mutex_unlock(&pTAS2562->dev_lock);
159 return nResult;
160 }
162 static int tas2562_dev_bulk_read(struct tas2562_priv *pTAS2562,
163 unsigned int reg, unsigned char *pData, unsigned int nLength)
164 {
165 int nResult = 0;
167 mutex_lock(&pTAS2562->dev_lock);
169 nResult = tas2562_change_book_page(pTAS2562,
170 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg));
171 if (nResult < 0)
172 goto end;
174 nResult = regmap_bulk_read(pTAS2562->regmap,
175 TAS2562_PAGE_REG(reg), pData, nLength);
176 if (nResult < 0)
177 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
178 __func__, __LINE__, nResult);
179 else
180 dev_dbg(pTAS2562->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n",
181 __func__, TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg),
182 TAS2562_PAGE_REG(reg), nLength);
183 end:
184 mutex_unlock(&pTAS2562->dev_lock);
185 return nResult;
186 }
188 static int tas2562_dev_update_bits(struct tas2562_priv *pTAS2562,
189 unsigned int reg, unsigned int mask, unsigned int value)
190 {
191 int nResult = 0;
193 mutex_lock(&pTAS2562->dev_lock);
194 nResult = tas2562_change_book_page(pTAS2562,
195 TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg));
196 if (nResult < 0)
197 goto end;
199 nResult = regmap_update_bits(pTAS2562->regmap,
200 TAS2562_PAGE_REG(reg), mask, value);
201 if (nResult < 0)
202 dev_err(pTAS2562->dev, "%s, ERROR, L=%d, E=%d\n",
203 __func__, __LINE__, nResult);
204 else
205 dev_dbg(pTAS2562->dev, "%s: BOOK:PAGE:REG %u:%u:%u, mask: 0x%x, val=0x%x\n",
206 __func__, TAS2562_BOOK_ID(reg), TAS2562_PAGE_ID(reg),
207 TAS2562_PAGE_REG(reg), mask, value);
208 end:
209 mutex_unlock(&pTAS2562->dev_lock);
210 return nResult;
211 }
213 static bool tas2562_volatile(struct device *dev, unsigned int reg)
214 {
215 return true;
216 }
218 static bool tas2562_writeable(struct device *dev, unsigned int reg)
219 {
220 return true;
221 }
222 static const struct regmap_config tas2562_i2c_regmap = {
223 .reg_bits = 8,
224 .val_bits = 8,
225 .writeable_reg = tas2562_writeable,
226 .volatile_reg = tas2562_volatile,
227 .cache_type = REGCACHE_NONE,
228 .max_register = 1 * 128,
229 };
232 static void tas2562_hw_reset(struct tas2562_priv *pTAS2562)
233 {
234 if (gpio_is_valid(pTAS2562->mnResetGPIO)) {
235 gpio_direction_output(pTAS2562->mnResetGPIO, 0);
236 msleep(5);
237 gpio_direction_output(pTAS2562->mnResetGPIO, 1);
238 msleep(2);
239 }
240 dev_err(pTAS2562->dev, "gpio up !!\n");
242 pTAS2562->mnCurrentBook = -1;
243 pTAS2562->mnCurrentPage = -1;
244 }
246 void tas2562_enableIRQ(struct tas2562_priv *pTAS2562, bool enable)
247 {
248 if (enable) {
249 if (pTAS2562->mbIRQEnable)
250 return;
252 if (gpio_is_valid(pTAS2562->mnIRQGPIO))
253 enable_irq(pTAS2562->mnIRQ);
255 schedule_delayed_work(&pTAS2562->irq_work, msecs_to_jiffies(10));
257 pTAS2562->mbIRQEnable = true;
258 } else {
259 if (gpio_is_valid(pTAS2562->mnIRQGPIO))
260 disable_irq_nosync(pTAS2562->mnIRQ);
261 pTAS2562->mbIRQEnable = false;
262 }
263 }
265 static void irq_work_routine(struct work_struct *work)
266 {
267 struct tas2562_priv *pTAS2562 =
268 container_of(work, struct tas2562_priv, irq_work.work);
269 unsigned int nDevInt1Status = 0, nDevInt2Status = 0;
270 int nCounter = 2;
271 int nResult = 0;
273 dev_info(pTAS2562->dev, "%s\n", __func__);
274 #ifdef CONFIG_TAS2562_CODEC
275 mutex_lock(&pTAS2562->codec_lock);
276 #endif
278 if (pTAS2562->mbRuntimeSuspend) {
279 dev_info(pTAS2562->dev, "%s, Runtime Suspended\n", __func__);
280 goto end;
281 }
283 if (pTAS2562->mnPowerState == TAS2562_POWER_SHUTDOWN) {
284 dev_info(pTAS2562->dev, "%s, device not powered\n", __func__);
285 goto end;
286 }
288 nResult = tas2562_dev_read(pTAS2562, TAS2562_LatchedInterruptReg0, &nDevInt1Status);
289 if (nResult >= 0)
290 nResult = tas2562_dev_read(pTAS2562, TAS2562_LatchedInterruptReg1, &nDevInt2Status);
291 else
292 goto reload;
294 dev_dbg(pTAS2562->dev, "IRQ status : 0x%x, 0x%x\n",
295 nDevInt1Status, nDevInt2Status);
297 if (((nDevInt1Status & 0x3) != 0) || ((nDevInt2Status & 0x0f) != 0)) {
298 /* in case of INT_OC, INT_OT, INT_OVLT, INT_UVLT, INT_BO */
300 if (nDevInt1Status & TAS2562_LatchedInterruptReg0_OCEFlagSticky_Interrupt) {
301 pTAS2562->mnErrCode |= ERROR_OVER_CURRENT;
302 dev_err(pTAS2562->dev, "SPK over current!\n");
303 } else
304 pTAS2562->mnErrCode &= ~ERROR_OVER_CURRENT;
306 if (nDevInt1Status & TAS2562_LatchedInterruptReg0_OTEFlagSticky_Interrupt) {
307 pTAS2562->mnErrCode |= ERROR_DIE_OVERTEMP;
308 dev_err(pTAS2562->dev, "die over temperature!\n");
309 } else
310 pTAS2562->mnErrCode &= ~ERROR_DIE_OVERTEMP;
312 if (nDevInt2Status & TAS2562_LatchedInterruptReg1_VBATOVLOSticky_Interrupt) {
313 pTAS2562->mnErrCode |= ERROR_OVER_VOLTAGE;
314 dev_err(pTAS2562->dev, "SPK over voltage!\n");
315 } else
316 pTAS2562->mnErrCode &= ~ERROR_UNDER_VOLTAGE;
318 if (nDevInt2Status & TAS2562_LatchedInterruptReg1_VBATUVLOSticky_Interrupt) {
319 pTAS2562->mnErrCode |= ERROR_UNDER_VOLTAGE;
320 dev_err(pTAS2562->dev, "SPK under voltage!\n");
321 } else
322 pTAS2562->mnErrCode &= ~ERROR_UNDER_VOLTAGE;
324 if (nDevInt2Status & TAS2562_LatchedInterruptReg1_BrownOutFlagSticky_Interrupt) {
325 pTAS2562->mnErrCode |= ERROR_BROWNOUT;
326 dev_err(pTAS2562->dev, "brownout!\n");
327 } else
328 pTAS2562->mnErrCode &= ~ERROR_BROWNOUT;
330 dev_err(pTAS2562->dev, "before goto reload\n");
331 goto reload;
332 } else {
333 nCounter = 2;
335 while (nCounter > 0) {
336 nResult = tas2562_dev_read(pTAS2562, TAS2562_PowerControl, &nDevInt1Status);
337 if (nResult < 0)
338 goto reload;
340 if ((nDevInt1Status & TAS2562_PowerControl_OperationalMode10_Mask)
341 != TAS2562_PowerControl_OperationalMode10_Shutdown)
342 break;
344 nCounter--;
345 if (nCounter > 0) {
346 /* in case check pow status just after power on TAS2562 */
347 dev_dbg(pTAS2562->dev, "PowSts B: 0x%x, check again after 10ms\n",
348 nDevInt1Status);
349 msleep(10);
350 }
351 }
353 if ((nDevInt1Status & TAS2562_PowerControl_OperationalMode10_Mask)
354 == TAS2562_PowerControl_OperationalMode10_Shutdown) {
355 dev_err(pTAS2562->dev, "%s, Critical ERROR REG[0x%x] = 0x%x\n",
356 __func__,
357 TAS2562_PowerControl,
358 nDevInt1Status);
359 pTAS2562->mnErrCode |= ERROR_CLASSD_PWR;
360 goto reload;
361 }
362 pTAS2562->mnErrCode &= ~ERROR_CLASSD_PWR;
363 }
365 goto end;
367 reload:
368 /* hardware reset and reload */
369 nResult = -1;
370 tas2562_LoadConfig(pTAS2562);
372 end:
373 if (nResult >= 0) {
374 tas2562_enableIRQ(pTAS2562, true);
375 dev_info(pTAS2562->dev, "enable IRQ\n");
376 }
378 nResult = gpio_get_value(pTAS2562->mnIRQGPIO);
379 dev_info(pTAS2562->dev, "%s, irq GPIO state: %d\n", __func__, nResult);
381 if (!hrtimer_active(&pTAS2562->mtimer)) {
382 dev_dbg(pTAS2562->dev, "%s, start timer\n", __func__);
383 hrtimer_start(&pTAS2562->mtimer,
384 ns_to_ktime((u64)CHECK_PERIOD * NSEC_PER_MSEC), HRTIMER_MODE_REL);
385 } else
386 dev_info(pTAS2562->dev, "timer not active\n");
388 #ifdef CONFIG_TAS2562_CODEC
389 mutex_unlock(&pTAS2562->codec_lock);
390 #endif
391 }
393 static enum hrtimer_restart timer_func(struct hrtimer *timer)
394 {
395 struct tas2562_priv *pTAS2562 = container_of(timer,
396 struct tas2562_priv, mtimer);
398 if (pTAS2562->mbPowerUp) {
399 if (!delayed_work_pending(&pTAS2562->irq_work))
400 schedule_delayed_work(&pTAS2562->irq_work,
401 msecs_to_jiffies(20));
402 }
404 return HRTIMER_NORESTART;
405 }
407 static irqreturn_t tas2562_irq_handler(int irq, void *dev_id)
408 {
409 struct tas2562_priv *pTAS2562 = (struct tas2562_priv *)dev_id;
411 tas2562_enableIRQ(pTAS2562, false);
412 /* get IRQ status after 100 ms */
413 schedule_delayed_work(&pTAS2562->irq_work, msecs_to_jiffies(100));
414 return IRQ_HANDLED;
415 }
417 static int tas2562_runtime_suspend(struct tas2562_priv *pTAS2562)
418 {
419 dev_dbg(pTAS2562->dev, "%s\n", __func__);
421 pTAS2562->mbRuntimeSuspend = true;
423 if (hrtimer_active(&pTAS2562->mtimer)) {
424 dev_dbg(pTAS2562->dev, "cancel timer\n");
425 hrtimer_cancel(&pTAS2562->mtimer);
426 }
428 if (delayed_work_pending(&pTAS2562->irq_work)) {
429 dev_dbg(pTAS2562->dev, "cancel IRQ work\n");
430 cancel_delayed_work_sync(&pTAS2562->irq_work);
431 }
433 return 0;
434 }
436 static int tas2562_runtime_resume(struct tas2562_priv *pTAS2562)
437 {
438 dev_dbg(pTAS2562->dev, "%s\n", __func__);
440 if (pTAS2562->mbPowerUp) {
441 if (!hrtimer_active(&pTAS2562->mtimer)) {
442 dev_dbg(pTAS2562->dev, "%s, start check timer\n", __func__);
443 hrtimer_start(&pTAS2562->mtimer,
444 ns_to_ktime((u64)CHECK_PERIOD * NSEC_PER_MSEC),
445 HRTIMER_MODE_REL);
446 }
447 }
449 pTAS2562->mbRuntimeSuspend = false;
451 return 0;
452 }
454 static int tas2562_parse_dt(struct device *dev, struct tas2562_priv *pTAS2562)
455 {
456 struct device_node *np = dev->of_node;
457 int rc = 0, ret = 0;
459 // u32 debounceInfo[2] = { 0, 0 };
460 rc = of_property_read_u32(np, "ti,asi-format", &pTAS2562->mnASIFormat);
461 if (rc) {
462 dev_err(pTAS2562->dev, "Looking up %s property in node %s failed %d\n",
463 "ti,asi-format", np->full_name, rc);
464 } else {
465 dev_dbg(pTAS2562->dev, "ti,asi-format=%d",
466 pTAS2562->mnASIFormat);
467 }
469 pTAS2562->mnResetGPIO = of_get_named_gpio(np, "ti,reset-gpio", 0);
470 if (!gpio_is_valid(pTAS2562->mnResetGPIO)) {
471 dev_err(pTAS2562->dev, "Looking up %s property in node %s failed %d\n",
472 "ti,reset-gpio", np->full_name, pTAS2562->mnResetGPIO);
473 } else {
474 dev_dbg(pTAS2562->dev, "ti,reset-gpio=%d",
475 pTAS2562->mnResetGPIO);
476 }
478 pTAS2562->mnIRQGPIO = of_get_named_gpio(np, "ti,irq-gpio", 0);
479 if (!gpio_is_valid(pTAS2562->mnIRQGPIO)) {
480 dev_err(pTAS2562->dev, "Looking up %s property in node %s failed %d\n",
481 "ti,irq-gpio", np->full_name, pTAS2562->mnIRQGPIO);
482 } else {
483 dev_dbg(pTAS2562->dev, "ti,irq-gpio=%d", pTAS2562->mnIRQGPIO);
484 }
486 return ret;
487 }
489 static int tas2562_i2c_probe(struct i2c_client *pClient,
490 const struct i2c_device_id *id)
491 {
492 struct tas2562_priv *pTAS2562;
493 int nResult;
495 dev_info(&pClient->dev, "%s enter\n", __func__);
497 pTAS2562 = devm_kzalloc(&pClient->dev,
498 sizeof(struct tas2562_priv), GFP_KERNEL);
499 if (pTAS2562 == NULL) {
500 dev_err(&pClient->dev, "failed to get i2c device\n");
501 nResult = -ENOMEM;
502 goto err;
503 }
505 pTAS2562->dev = &pClient->dev;
506 i2c_set_clientdata(pClient, pTAS2562);
507 dev_set_drvdata(&pClient->dev, pTAS2562);
509 pTAS2562->regmap = devm_regmap_init_i2c(pClient, &tas2562_i2c_regmap);
510 if (IS_ERR(pTAS2562->regmap)) {
511 nResult = PTR_ERR(pTAS2562->regmap);
512 dev_err(&pClient->dev, "Failed to allocate register map: %d\n",
513 nResult);
514 goto err;
515 }
517 if (pClient->dev.of_node)
518 tas2562_parse_dt(&pClient->dev, pTAS2562);
520 if (gpio_is_valid(pTAS2562->mnResetGPIO)) {
521 nResult = gpio_request(pTAS2562->mnResetGPIO, "TAS2562_RESET");
522 if (nResult) {
523 dev_err(pTAS2562->dev, "%s: Failed to request gpio %d\n",
524 __func__, pTAS2562->mnResetGPIO);
525 nResult = -EINVAL;
526 goto err;
527 }
528 tas2562_hw_reset(pTAS2562);
529 }
531 pTAS2562->read = tas2562_dev_read;
532 pTAS2562->write = tas2562_dev_write;
533 pTAS2562->bulk_read = tas2562_dev_bulk_read;
534 pTAS2562->bulk_write = tas2562_dev_bulk_write;
535 pTAS2562->update_bits = tas2562_dev_update_bits;
536 pTAS2562->hw_reset = tas2562_hw_reset;
537 pTAS2562->enableIRQ = tas2562_enableIRQ;
538 //pTAS2562->clearIRQ = tas2562_clearIRQ;
539 pTAS2562->runtime_suspend = tas2562_runtime_suspend;
540 pTAS2562->runtime_resume = tas2562_runtime_resume;
541 pTAS2562->mnPowerState = TAS2562_POWER_SHUTDOWN;
543 mutex_init(&pTAS2562->dev_lock);
545 /* Reset the chip */
546 nResult = tas2562_dev_write(pTAS2562, TAS2562_SoftwareReset, 0x01);
547 if (nResult < 0) {
548 dev_err(&pClient->dev, "I2c fail, %d\n", nResult);
549 goto err;
550 }
552 if (gpio_is_valid(pTAS2562->mnIRQGPIO)) {
553 nResult = gpio_request(pTAS2562->mnIRQGPIO, "TAS2562-IRQ");
554 if (nResult < 0) {
555 dev_err(pTAS2562->dev, "%s: GPIO %d request error\n",
556 __func__, pTAS2562->mnIRQGPIO);
557 goto err;
558 }
559 gpio_direction_input(pTAS2562->mnIRQGPIO);
560 nResult = gpio_get_value(pTAS2562->mnIRQGPIO);
561 dev_info(pTAS2562->dev, "irq GPIO state: %d\n", nResult);
563 pTAS2562->mnIRQ = gpio_to_irq(pTAS2562->mnIRQGPIO);
564 dev_dbg(pTAS2562->dev, "irq = %d\n", pTAS2562->mnIRQ);
565 INIT_DELAYED_WORK(&pTAS2562->irq_work, irq_work_routine);
566 nResult = request_threaded_irq(pTAS2562->mnIRQ, tas2562_irq_handler,
567 NULL, IRQF_TRIGGER_LOW|IRQF_ONESHOT,
568 pClient->name, pTAS2562);
569 if (nResult < 0) {
570 dev_err(pTAS2562->dev,
571 "request_irq failed, %d\n", nResult);
572 goto err;
573 }
574 disable_irq_nosync(pTAS2562->mnIRQ);
575 }
577 #ifdef CONFIG_TAS2562_CODEC
578 mutex_init(&pTAS2562->codec_lock);
579 nResult = tas2562_register_codec(pTAS2562);
580 if (nResult < 0) {
581 dev_err(pTAS2562->dev,
582 "register codec failed, %d\n", nResult);
583 goto err;
584 }
585 #endif
587 #ifdef CONFIG_TAS2562_MISC
588 mutex_init(&pTAS2562->file_lock);
589 nResult = tas2562_register_misc(pTAS2562);
590 if (nResult < 0) {
591 dev_err(pTAS2562->dev,
592 "register codec failed, %d\n", nResult);
593 goto err;
594 }
595 #endif
597 hrtimer_init(&pTAS2562->mtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
598 pTAS2562->mtimer.function = timer_func;
600 err:
601 return nResult;
602 }
604 static int tas2562_i2c_remove(struct i2c_client *pClient)
605 {
606 struct tas2562_priv *pTAS2562 = i2c_get_clientdata(pClient);
608 dev_info(pTAS2562->dev, "%s\n", __func__);
610 #ifdef CONFIG_TAS2562_CODEC
611 tas2562_deregister_codec(pTAS2562);
612 mutex_destroy(&pTAS2562->codec_lock);
613 #endif
615 #ifdef CONFIG_TAS2562_MISC
616 tas2562_deregister_misc(pTAS2562);
617 mutex_destroy(&pTAS2562->file_lock);
618 #endif
620 if (gpio_is_valid(pTAS2562->mnResetGPIO))
621 gpio_free(pTAS2562->mnResetGPIO);
622 if (gpio_is_valid(pTAS2562->mnIRQGPIO))
623 gpio_free(pTAS2562->mnIRQGPIO);
625 return 0;
626 }
629 static const struct i2c_device_id tas2562_i2c_id[] = {
630 { "tas2562", 0},
631 { }
632 };
633 MODULE_DEVICE_TABLE(i2c, tas2562_i2c_id);
635 #if defined(CONFIG_OF)
636 static const struct of_device_id tas2562_of_match[] = {
637 { .compatible = "ti,tas2562" },
638 {},
639 };
640 MODULE_DEVICE_TABLE(of, tas2562_of_match);
641 #endif
644 static struct i2c_driver tas2562_i2c_driver = {
645 .driver = {
646 .name = "tas2562",
647 .owner = THIS_MODULE,
648 #if defined(CONFIG_OF)
649 .of_match_table = of_match_ptr(tas2562_of_match),
650 #endif
651 },
652 .probe = tas2562_i2c_probe,
653 .remove = tas2562_i2c_remove,
654 .id_table = tas2562_i2c_id,
655 };
657 module_i2c_driver(tas2562_i2c_driver);
659 MODULE_AUTHOR("Texas Instruments Inc.");
660 MODULE_DESCRIPTION("TAS2562 I2C Smart Amplifier driver");
661 MODULE_LICENSE("GPL v2");
662 #endif