47478cb868dfa49c5e913f26d73d8410c5872bba
1 /*
2 ** =============================================================================
3 ** Copyright (c) 2016 Texas Instruments Inc.
4 **
5 ** This program is free software; you can redistribute it and/or modify it under
6 ** the terms of the GNU General Public License as published by the Free Software
7 ** Foundation; version 2.
8 **
9 ** This program is distributed in the hope that it will be useful, but WITHOUT
10 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 ** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 **
13 ** File:
14 ** tas2557-regmap.c
15 **
16 ** Description:
17 ** I2C driver with regmap for Texas Instruments TAS2557 High Performance 4W Smart Amplifier
18 **
19 ** =============================================================================
20 */
22 #ifdef CONFIG_TAS2557_REGMAP
24 #define DEBUG
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/pm.h>
30 #include <linux/i2c.h>
31 #include <linux/gpio.h>
32 #include <linux/regulator/consumer.h>
33 #include <linux/firmware.h>
34 #include <linux/regmap.h>
35 #include <linux/of.h>
36 #include <linux/of_gpio.h>
37 #include <linux/slab.h>
38 #include <linux/syscalls.h>
39 #include <linux/fcntl.h>
40 #include <linux/uaccess.h>
41 #include "tas2557.h"
42 #include "tas2557-core.h"
44 #ifdef CONFIG_TAS2557_CODEC
45 #include "tas2557-codec.h"
46 #endif
48 #ifdef CONFIG_TAS2557_MISC
49 #include "tas2557-misc.h"
50 #endif
52 #define ENABLE_TILOAD
53 #ifdef ENABLE_TILOAD
54 #include "tiload.h"
55 #endif
57 #define LOW_TEMPERATURE_GAIN 6
59 static int tas2557_change_book_page(
60 struct tas2557_priv *pTAS2557,
61 unsigned char nBook,
62 unsigned char nPage)
63 {
64 int nResult = 0;
66 if ((pTAS2557->mnCurrentBook == nBook)
67 && pTAS2557->mnCurrentPage == nPage)
68 goto end;
70 if (pTAS2557->mnCurrentBook != nBook) {
71 nResult = regmap_write(pTAS2557->mpRegmap, TAS2557_BOOKCTL_PAGE, 0);
72 if (nResult < 0) {
73 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
74 __func__, __LINE__, nResult);
75 goto end;
76 }
77 pTAS2557->mnCurrentPage = 0;
78 nResult = regmap_write(pTAS2557->mpRegmap, TAS2557_BOOKCTL_REG, nBook);
79 if (nResult < 0) {
80 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
81 __func__, __LINE__, nResult);
82 goto end;
83 }
84 pTAS2557->mnCurrentBook = nBook;
85 if (nPage != 0) {
86 nResult = regmap_write(pTAS2557->mpRegmap, TAS2557_BOOKCTL_PAGE, nPage);
87 if (nResult < 0) {
88 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
89 __func__, __LINE__, nResult);
90 goto end;
91 }
92 pTAS2557->mnCurrentPage = nPage;
93 }
94 } else if (pTAS2557->mnCurrentPage != nPage) {
95 nResult = regmap_write(pTAS2557->mpRegmap, TAS2557_BOOKCTL_PAGE, nPage);
96 if (nResult < 0) {
97 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
98 __func__, __LINE__, nResult);
99 goto end;
100 }
101 pTAS2557->mnCurrentPage = nPage;
102 }
104 end:
106 return nResult;
107 }
109 static int tas2557_dev_read(
110 struct tas2557_priv *pTAS2557,
111 unsigned int nRegister,
112 unsigned int *pValue)
113 {
114 int nResult = 0;
115 unsigned int Value = 0;
117 mutex_lock(&pTAS2557->dev_lock);
119 if (pTAS2557->mbTILoadActive) {
120 if (!(nRegister & 0x80000000))
121 goto end; /* let only reads from TILoad pass. */
122 nRegister &= ~0x80000000;
124 dev_dbg(pTAS2557->dev, "TiLoad R REG B[%d]P[%d]R[%d]\n",
125 TAS2557_BOOK_ID(nRegister),
126 TAS2557_PAGE_ID(nRegister),
127 TAS2557_PAGE_REG(nRegister));
128 }
130 nResult = tas2557_change_book_page(pTAS2557,
131 TAS2557_BOOK_ID(nRegister),
132 TAS2557_PAGE_ID(nRegister));
133 if (nResult >= 0) {
134 nResult = regmap_read(pTAS2557->mpRegmap, TAS2557_PAGE_REG(nRegister), &Value);
135 if (nResult < 0) {
136 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
137 __func__, __LINE__, nResult);
138 goto end;
139 }
140 *pValue = Value;
141 }
143 end:
145 mutex_unlock(&pTAS2557->dev_lock);
146 return nResult;
147 }
149 static int tas2557_dev_write(
150 struct tas2557_priv *pTAS2557,
151 unsigned int nRegister,
152 unsigned int nValue)
153 {
154 int nResult = 0;
156 mutex_lock(&pTAS2557->dev_lock);
157 if ((nRegister == 0xAFFEAFFE) && (nValue == 0xBABEBABE)) {
158 pTAS2557->mbTILoadActive = true;
159 goto end;
160 }
162 if ((nRegister == 0xBABEBABE) && (nValue == 0xAFFEAFFE)) {
163 pTAS2557->mbTILoadActive = false;
164 goto end;
165 }
167 if (pTAS2557->mbTILoadActive) {
168 if (!(nRegister & 0x80000000))
169 goto end;/* let only writes from TILoad pass. */
170 nRegister &= ~0x80000000;
172 dev_dbg(pTAS2557->dev, "TiLoad W REG B[%d]P[%d]R[%d] =0x%x\n",
173 TAS2557_BOOK_ID(nRegister),
174 TAS2557_PAGE_ID(nRegister),
175 TAS2557_PAGE_REG(nRegister),
176 nValue);
177 }
179 nResult = tas2557_change_book_page(pTAS2557,
180 TAS2557_BOOK_ID(nRegister),
181 TAS2557_PAGE_ID(nRegister));
182 if (nResult >= 0) {
183 nResult = regmap_write(pTAS2557->mpRegmap, TAS2557_PAGE_REG(nRegister), nValue);
184 if (nResult < 0)
185 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
186 __func__, __LINE__, nResult);
187 }
189 end:
191 mutex_unlock(&pTAS2557->dev_lock);
193 return nResult;
194 }
196 static int tas2557_dev_bulk_read(
197 struct tas2557_priv *pTAS2557,
198 unsigned int nRegister,
199 u8 *pData,
200 unsigned int nLength)
201 {
202 int nResult = 0;
204 mutex_lock(&pTAS2557->dev_lock);
205 if (pTAS2557->mbTILoadActive) {
206 if (!(nRegister & 0x80000000))
207 goto end; /* let only writes from TILoad pass. */
209 nRegister &= ~0x80000000;
210 dev_dbg(pTAS2557->dev, "TiLoad BR REG B[%d]P[%d]R[%d], count=%d\n",
211 TAS2557_BOOK_ID(nRegister),
212 TAS2557_PAGE_ID(nRegister),
213 TAS2557_PAGE_REG(nRegister),
214 nLength);
215 }
217 nResult = tas2557_change_book_page(pTAS2557,
218 TAS2557_BOOK_ID(nRegister),
219 TAS2557_PAGE_ID(nRegister));
220 if (nResult >= 0) {
221 nResult = regmap_bulk_read(pTAS2557->mpRegmap, TAS2557_PAGE_REG(nRegister), pData, nLength);
222 if (nResult < 0)
223 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
224 __func__, __LINE__, nResult);
225 }
227 end:
229 mutex_unlock(&pTAS2557->dev_lock);
230 return nResult;
231 }
233 static int tas2557_dev_bulk_write(
234 struct tas2557_priv *pTAS2557,
235 unsigned int nRegister,
236 u8 *pData,
237 unsigned int nLength)
238 {
239 int nResult = 0;
241 mutex_lock(&pTAS2557->dev_lock);
242 if (pTAS2557->mbTILoadActive) {
243 if (!(nRegister & 0x80000000))
244 goto end; /* let only writes from TILoad pass. */
246 nRegister &= ~0x80000000;
248 dev_dbg(pTAS2557->dev, "TiLoad BW REG B[%d]P[%d]R[%d], count=%d\n",
249 TAS2557_BOOK_ID(nRegister),
250 TAS2557_PAGE_ID(nRegister),
251 TAS2557_PAGE_REG(nRegister),
252 nLength);
253 }
255 nResult = tas2557_change_book_page( pTAS2557,
256 TAS2557_BOOK_ID(nRegister),
257 TAS2557_PAGE_ID(nRegister));
258 if (nResult >= 0) {
259 nResult = regmap_bulk_write(pTAS2557->mpRegmap, TAS2557_PAGE_REG(nRegister), pData, nLength);
260 if (nResult < 0)
261 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
262 __func__, __LINE__, nResult);
263 }
265 end:
267 mutex_unlock(&pTAS2557->dev_lock);
268 return nResult;
269 }
271 static int tas2557_dev_update_bits(
272 struct tas2557_priv *pTAS2557,
273 unsigned int nRegister,
274 unsigned int nMask,
275 unsigned int nValue)
276 {
277 int nResult = 0;
279 mutex_lock(&pTAS2557->dev_lock);
281 if (pTAS2557->mbTILoadActive) {
282 if (!(nRegister & 0x80000000))
283 goto end; /* let only writes from TILoad pass. */
285 nRegister &= ~0x80000000;
286 dev_dbg(pTAS2557->dev, "TiLoad SB REG B[%d]P[%d]R[%d], mask=0x%x, value=0x%x\n",
287 TAS2557_BOOK_ID(nRegister),
288 TAS2557_PAGE_ID(nRegister),
289 TAS2557_PAGE_REG(nRegister),
290 nMask, nValue);
291 }
293 nResult = tas2557_change_book_page( pTAS2557,
294 TAS2557_BOOK_ID(nRegister),
295 TAS2557_PAGE_ID(nRegister));
296 if (nResult >= 0) {
297 nResult = regmap_update_bits(pTAS2557->mpRegmap, TAS2557_PAGE_REG(nRegister), nMask, nValue);
298 if (nResult < 0)
299 dev_err(pTAS2557->dev, "%s, %d, I2C error %d\n",
300 __func__, __LINE__, nResult);
301 }
303 end:
304 mutex_unlock(&pTAS2557->dev_lock);
305 return nResult;
306 }
308 int tas2557_enableIRQ(struct tas2557_priv *pTAS2557, bool enable, bool clear)
309 {
310 unsigned int nValue;
311 int nResult = 0;
313 if (enable) {
314 if (clear) {
315 nResult = pTAS2557->read(pTAS2557, TAS2557_FLAGS_1, &nValue);
316 if (nResult >= 0)
317 nResult = pTAS2557->read(pTAS2557, TAS2557_FLAGS_2, &nValue);
318 }
320 if (!pTAS2557->mbIRQEnable) {
321 if (pTAS2557->mnIRQ != 0)
322 enable_irq(pTAS2557->mnIRQ);
323 pTAS2557->mbIRQEnable = true;
324 }
325 } else {
326 if (pTAS2557->mbIRQEnable) {
327 if (pTAS2557->mnIRQ != 0)
328 disable_irq_nosync(pTAS2557->mnIRQ);
329 pTAS2557->mbIRQEnable = false;
330 }
332 if (clear) {
333 nResult = pTAS2557->read(pTAS2557, TAS2557_FLAGS_1, &nValue);
334 if (nResult >= 0)
335 nResult = pTAS2557->read(pTAS2557, TAS2557_FLAGS_2, &nValue);
336 }
337 }
339 return nResult;
340 }
342 static void tas2557_hw_reset(struct tas2557_priv *pTAS2557)
343 {
344 #ifdef ENABLE_GPIO_RESET
345 if (gpio_is_valid(pTAS2557->mnResetGPIO)) {
346 devm_gpio_request_one(pTAS2557->dev, pTAS2557->mnResetGPIO,
347 GPIOF_OUT_INIT_LOW, "TAS2557_RST");
348 msleep(10);
349 gpio_set_value_cansleep(pTAS2557->mnResetGPIO, 1);
350 udelay(1000);
351 }
352 #endif
353 pTAS2557->mnCurrentBook = -1;
354 pTAS2557->mnCurrentPage = -1;
355 }
357 static void irq_work_routine(struct work_struct *work)
358 {
359 int nResult = 0;
360 unsigned int nDevInt1Status = 0, nDevInt2Status = 0;
361 unsigned int nDevPowerUpFlag = 0, nDevPowerStatus = 0;
362 struct tas2557_priv *pTAS2557 =
363 container_of(work, struct tas2557_priv, irq_work.work);
365 if (!pTAS2557->mbPowerUp)
366 return;
368 nResult = tas2557_dev_read(pTAS2557, TAS2557_FLAGS_1, &nDevInt1Status);
369 if (nResult >= 0)
370 nResult = tas2557_dev_read(pTAS2557, TAS2557_FLAGS_2, &nDevInt2Status);
372 if (nResult < 0)
373 goto program;
375 if (((nDevInt1Status & 0xdc) != 0) || ((nDevInt2Status & 0x0c) != 0)) {
376 /* in case of INT_OC, INT_UV, INT_OT, INT_BO, INT_CL, INT_CLK1, INT_CLK2 */
377 dev_err(pTAS2557->dev, "critical error: 0x%x, 0x%x\n", nDevInt1Status, nDevInt2Status);
378 goto program;
379 } else {
380 nResult = tas2557_dev_read(pTAS2557, TAS2557_POWER_UP_FLAG_REG, &nDevPowerUpFlag);
381 if (nResult < 0)
382 goto program;
383 if ((nDevPowerUpFlag & 0x40) == 0) {
384 /* Class-D doesn't power on */
385 nResult = tas2557_dev_read(pTAS2557, TAS2557_POWER_CTRL2_REG, &nDevPowerStatus);
386 if (nResult < 0)
387 goto program;
388 if (nDevPowerStatus & 0x80)
389 goto program; /* failed to power on the Class-D */
390 }
392 dev_dbg(pTAS2557->dev, "%s: INT1=0x%x, INT2=0x%x; PowerUpFlag=0x%x, PwrStatus=0x%x\n",
393 __func__, nDevInt1Status, nDevInt2Status, nDevPowerUpFlag, nDevPowerStatus);
394 }
395 return;
397 program:
398 /* hardware reset and reload */
399 tas2557_hw_reset(pTAS2557);
400 tas2557_set_program(pTAS2557, pTAS2557->mnCurrentProgram, pTAS2557->mnCurrentConfiguration);
401 }
403 static irqreturn_t tas2557_irq_handler(int irq, void *dev_id)
404 {
405 struct tas2557_priv *pTAS2557 = (struct tas2557_priv *)dev_id;
407 tas2557_enableIRQ(pTAS2557, false, false);
408 /* get IRQ status after 100 ms */
409 schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(100));
410 return IRQ_HANDLED;
411 }
413 static enum hrtimer_restart temperature_timer_func(struct hrtimer *timer)
414 {
415 struct tas2557_priv *pTAS2557 = container_of(timer, struct tas2557_priv, mtimer);
417 if (pTAS2557->mbPowerUp)
418 schedule_work(&pTAS2557->mtimerwork);
419 return HRTIMER_NORESTART;
420 }
422 static void timer_work_routine(struct work_struct *work)
423 {
424 struct tas2557_priv *pTAS2557 = container_of(work, struct tas2557_priv, mtimerwork);
425 int nResult, nTemp;
427 if (!pTAS2557->mbPowerUp)
428 goto end;
430 nResult = tas2557_get_die_temperature(pTAS2557, &nTemp);
431 if (nResult >= 0) {
432 dev_dbg(pTAS2557->dev, "Die=0x%x, degree=%d\n", nTemp, (nTemp>>23));
433 if ((nTemp & 0x80000000) != 0) {
434 /* if Die temperature is below ZERO */
435 if (pTAS2557->mnDevCurrentGain != LOW_TEMPERATURE_GAIN) {
436 nResult = tas2557_set_DAC_gain(pTAS2557, LOW_TEMPERATURE_GAIN);
437 if (nResult < 0)
438 goto end;
439 pTAS2557->mnDevCurrentGain = LOW_TEMPERATURE_GAIN;
440 dev_dbg(pTAS2557->dev, "LOW Temp: set gain to %d\n", LOW_TEMPERATURE_GAIN);
441 }
442 } else {
443 /* if Die temperature is above ZERO */
444 if (pTAS2557->mnDevCurrentGain != pTAS2557->mnDevGain) {
445 nResult = tas2557_set_DAC_gain(pTAS2557, pTAS2557->mnDevGain);
446 if (nResult < 0)
447 goto end;
448 pTAS2557->mnDevCurrentGain = pTAS2557->mnDevGain;
449 dev_dbg(pTAS2557->dev, "LOW Temp: set gain to original\n");
450 }
451 }
453 if (pTAS2557->mbPowerUp)
454 hrtimer_start(&pTAS2557->mtimer,
455 ns_to_ktime((u64)LOW_TEMPERATURE_CHECK_PERIOD * NSEC_PER_MSEC), HRTIMER_MODE_REL);
456 }
458 end:
459 return;
460 }
462 int tas2557_suspend(struct i2c_client *pClient, pm_message_t mesg)
463 {
464 struct tas2557_priv *pTAS2557 = i2c_get_clientdata(pClient);
466 dev_dbg(pTAS2557->dev, "%s, power status = %d\n", __func__, mesg.event);
467 if (hrtimer_active(&pTAS2557->mtimer)) {
468 dev_dbg(pTAS2557->dev, "cancel die temp timer\n");
469 hrtimer_cancel(&pTAS2557->mtimer);
470 }
472 return 0;
473 }
475 int tas2557_resume(struct i2c_client *pClient)
476 {
477 struct tas2557_priv *pTAS2557 = i2c_get_clientdata(pClient);
478 struct TProgram *pProgram;
480 if (!pTAS2557->mpFirmware->mpPrograms) {
481 dev_dbg(pTAS2557->dev, "%s, firmware not loaded\n", __func__);
482 goto end;
483 }
485 if (pTAS2557->mnCurrentProgram >= pTAS2557->mpCalFirmware->mnPrograms) {
486 dev_err(pTAS2557->dev, "%s, firmware corrupted\n", __func__);
487 goto end;
488 }
490 pProgram = &(pTAS2557->mpFirmware->mpPrograms[pTAS2557->mnCurrentProgram]);
491 if (pTAS2557->mbPowerUp && (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE)) {
492 dev_dbg(pTAS2557->dev, "%s, start Die Temp check timer\n", __func__);
493 hrtimer_start(&pTAS2557->mtimer,
494 ns_to_ktime((u64)LOW_TEMPERATURE_CHECK_PERIOD * NSEC_PER_MSEC), HRTIMER_MODE_REL);
495 }
497 end:
499 return 0;
500 }
502 static bool tas2557_volatile(struct device *pDev, unsigned int nRegister)
503 {
504 return true;
505 }
507 static bool tas2557_writeable(struct device *pDev, unsigned int nRegister)
508 {
509 return true;
510 }
512 static const struct regmap_config tas2557_i2c_regmap = {
513 .reg_bits = 8,
514 .val_bits = 8,
515 .writeable_reg = tas2557_writeable,
516 .volatile_reg = tas2557_volatile,
517 .cache_type = REGCACHE_NONE,
518 .max_register = 128,
519 };
521 /* tas2557_i2c_probe :
522 * platform dependent
523 * should implement hardware reset functionality
524 */
525 static int tas2557_i2c_probe(struct i2c_client *pClient,
526 const struct i2c_device_id *pID)
527 {
528 struct tas2557_priv *pTAS2557;
529 int nResult = 0;
530 unsigned int nValue = 0;
531 const char *pFWName;
533 dev_info(&pClient->dev, "%s enter\n", __func__);
535 pTAS2557 = devm_kzalloc(&pClient->dev, sizeof(struct tas2557_priv), GFP_KERNEL);
536 if (!pTAS2557) {
537 nResult = -ENOMEM;
538 goto err;
539 }
541 pTAS2557->dev = &pClient->dev;
542 i2c_set_clientdata(pClient, pTAS2557);
543 dev_set_drvdata(&pClient->dev, pTAS2557);
545 pTAS2557->mpRegmap = devm_regmap_init_i2c(pClient, &tas2557_i2c_regmap);
546 if (IS_ERR(pTAS2557->mpRegmap)) {
547 nResult = PTR_ERR(pTAS2557->mpRegmap);
548 dev_err(&pClient->dev, "Failed to allocate register map: %d\n",
549 nResult);
550 goto err;
551 }
553 if (pClient->dev.of_node)
554 tas2557_parse_dt(&pClient->dev, pTAS2557);
556 tas2557_hw_reset(pTAS2557);
558 pTAS2557->read = tas2557_dev_read;
559 pTAS2557->write = tas2557_dev_write;
560 pTAS2557->bulk_read = tas2557_dev_bulk_read;
561 pTAS2557->bulk_write = tas2557_dev_bulk_write;
562 pTAS2557->update_bits = tas2557_dev_update_bits;
563 pTAS2557->enableIRQ = tas2557_enableIRQ;
564 pTAS2557->set_config = tas2557_set_config;
565 pTAS2557->set_calibration = tas2557_set_calibration;
566 pTAS2557->hw_reset = tas2557_hw_reset;
568 mutex_init(&pTAS2557->dev_lock);
570 /* Reset the chip */
571 nResult = tas2557_dev_write(pTAS2557, TAS2557_SW_RESET_REG, 0x01);
572 if (nResult < 0) {
573 dev_err(&pClient->dev, "I2c fail, %d\n", nResult);
574 goto err;
575 }
577 msleep(1);
578 tas2557_dev_read(pTAS2557, TAS2557_REV_PGID_REG, &nValue);
579 pTAS2557->mnPGID = nValue;
580 if (pTAS2557->mnPGID == TAS2557_PG_VERSION_2P1) {
581 dev_info(pTAS2557->dev, "PG2.1 Silicon found\n");
582 pFWName = TAS2557_FW_NAME;
583 } else if (pTAS2557->mnPGID == TAS2557_PG_VERSION_1P0) {
584 dev_info(pTAS2557->dev, "PG1.0 Silicon found\n");
585 pFWName = TAS2557_PG1P0_FW_NAME;
586 } else {
587 nResult = -ENOTSUPP;
588 dev_info(pTAS2557->dev, "unsupport Silicon 0x%x\n", pTAS2557->mnPGID);
589 goto err;
590 }
592 if (gpio_is_valid(pTAS2557->mnGpioINT)) {
593 nResult = gpio_request(pTAS2557->mnGpioINT, "TAS2557-IRQ");
594 if (nResult < 0) {
595 dev_err(pTAS2557->dev,
596 "%s: GPIO %d request INT error\n",
597 __func__, pTAS2557->mnGpioINT);
598 goto err;
599 }
601 gpio_direction_input(pTAS2557->mnGpioINT);
602 pTAS2557->mnIRQ = gpio_to_irq(pTAS2557->mnGpioINT);
603 dev_dbg(pTAS2557->dev, "irq = %d\n", pTAS2557->mnIRQ);
604 INIT_DELAYED_WORK(&pTAS2557->irq_work, irq_work_routine);
605 nResult = request_threaded_irq(pTAS2557->mnIRQ, tas2557_irq_handler,
606 NULL, IRQF_TRIGGER_RISING | IRQF_ONESHOT,
607 pClient->name, pTAS2557);
608 if (nResult < 0) {
609 dev_err(pTAS2557->dev,
610 "request_irq failed, %d\n", nResult);
611 goto err;
612 }
613 disable_irq_nosync(pTAS2557->mnIRQ);
614 }
616 pTAS2557->mpFirmware = devm_kzalloc(&pClient->dev, sizeof(struct TFirmware), GFP_KERNEL);
617 if (!pTAS2557->mpFirmware) {
618 nResult = -ENOMEM;
619 goto err;
620 }
622 pTAS2557->mpCalFirmware = devm_kzalloc(&pClient->dev, sizeof(struct TFirmware), GFP_KERNEL);
623 if (!pTAS2557->mpCalFirmware) {
624 nResult = -ENOMEM;
625 goto err;
626 }
628 #ifdef CONFIG_TAS2557_CODEC
629 tas2557_register_codec(pTAS2557);
630 #endif
632 #ifdef CONFIG_TAS2557_MISC
633 mutex_init(&pTAS2557->file_lock);
634 tas2557_register_misc(pTAS2557);
635 #endif
637 #ifdef ENABLE_TILOAD
638 tiload_driver_init(pTAS2557);
639 #endif
641 hrtimer_init(&pTAS2557->mtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
642 pTAS2557->mtimer.function = temperature_timer_func;
643 INIT_WORK(&pTAS2557->mtimerwork, timer_work_routine);
645 nResult = request_firmware_nowait(THIS_MODULE, 1, pFWName,
646 pTAS2557->dev, GFP_KERNEL, pTAS2557, tas2557_fw_ready);
648 err:
650 return nResult;
651 }
653 static int tas2557_i2c_remove(struct i2c_client *pClient)
654 {
655 struct tas2557_priv *pTAS2557 = i2c_get_clientdata(pClient);
657 dev_info(pTAS2557->dev, "%s\n", __func__);
659 #ifdef CONFIG_TAS2557_CODEC
660 tas2557_deregister_codec(pTAS2557);
661 #endif
663 #ifdef CONFIG_TAS2557_MISC
664 tas2557_deregister_misc(pTAS2557);
665 mutex_destroy(&pTAS2557->file_lock);
666 #endif
668 mutex_destroy(&pTAS2557->dev_lock);
669 return 0;
670 }
672 static const struct i2c_device_id tas2557_i2c_id[] = {
673 {"tas2557", 0},
674 {}
675 };
677 MODULE_DEVICE_TABLE(i2c, tas2557_i2c_id);
679 #if defined(CONFIG_OF)
680 static const struct of_device_id tas2557_of_match[] = {
681 {.compatible = "ti,tas2557"},
682 {},
683 };
685 MODULE_DEVICE_TABLE(of, tas2557_of_match);
686 #endif
688 static struct i2c_driver tas2557_i2c_driver = {
689 .driver = {
690 .name = "tas2557",
691 .owner = THIS_MODULE,
692 #if defined(CONFIG_OF)
693 .of_match_table = of_match_ptr(tas2557_of_match),
694 #endif
695 },
696 .probe = tas2557_i2c_probe,
697 .remove = tas2557_i2c_remove,
698 .id_table = tas2557_i2c_id,
699 .suspend = tas2557_suspend,
700 .resume = tas2557_resume,
701 };
703 module_i2c_driver(tas2557_i2c_driver);
705 MODULE_AUTHOR("Texas Instruments Inc.");
706 MODULE_DESCRIPTION("TAS2557 I2C Smart Amplifier driver");
707 MODULE_LICENSE("GPL v2");
708 #endif