]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tas2555sw-android/tas2555-android-device-driver-stereo.git/blob - tas2555-i2c.c
a2e172e150cf4a05cfc4ec69846e732e3fa7b2e2
[tas2555sw-android/tas2555-android-device-driver-stereo.git] / tas2555-i2c.c
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 ** You should have received a copy of the GNU General Public License along with
14 ** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 ** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 **
17 ** File:
18 **     tas2555-regmap.c
19 **
20 ** Description:
21 **     I2C driver with regmap for Texas Instruments TAS2555 High Performance 4W Smart Amplifier
22 **
23 ** =============================================================================
24 */
26 #ifdef CONFIG_TAS2555_I2C_STEREO
28 #define DEBUG
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/pm.h>
34 #include <linux/i2c.h>
35 #include <linux/gpio.h>
36 #include <linux/regulator/consumer.h>
37 #include <linux/firmware.h>
38 #include <linux/regmap.h>
39 #include <linux/of.h>
40 #include <linux/of_gpio.h>
41 #include <linux/slab.h>
42 #include <linux/syscalls.h>
43 #include <linux/fcntl.h>
44 #include <asm/uaccess.h>
45 #include "tas2555.h"
46 #include "tas2555-core.h"
48 #ifdef CONFIG_TAS2555_CODEC_STEREO
49 #include "tas2555-codec.h"
50 #endif
52 #ifdef CONFIG_TAS2555_MISC_STEREO
53 #include "tas2555-misc.h"
54 #endif
56 #define ENABLE_TILOAD                   //only enable this for in-system tuning or debug, not for production systems
57 #ifdef ENABLE_TILOAD
58 #include "tiload.h"
59 #endif
61 /*
62 * tas2555_i2c_write_device : write single byte to device
63 * platform dependent, need platform specific support
64 */
65 static int tas2555_i2c_write_device(
66         struct tas2555_priv *pTAS2555,
67         unsigned char addr, 
68         unsigned char reg, 
69         unsigned char value)
70 {
71         int ret = 0;
72         
73         pTAS2555->client->addr = addr;
74         ret = regmap_write(pTAS2555->mpRegmap, reg, value);
75         if(ret < 0){
76                 dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
77                         __FUNCTION__, addr, ret);
78         }else{
79                 ret = 1;
80         }
81         
82         return ret;
83 }
85 /*
86 * tas2555_i2c_bulkwrite_device : write multiple bytes to device
87 * platform dependent, need platform specific support
88 */
89 static int tas2555_i2c_bulkwrite_device(
90         struct tas2555_priv *pTAS2555,
91         unsigned char addr, 
92         unsigned char reg, 
93         unsigned char *pBuf,
94         unsigned int len)
95 {
96         int ret = 0;
97         
98         pTAS2555->client->addr = addr;
99         ret = regmap_bulk_write(pTAS2555->mpRegmap, reg, pBuf, len);
100         if(ret < 0){
101                 dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
102                         __FUNCTION__, addr, ret);
103         }else{
104                 ret = len;
105         }
106         return ret;
109 /*
110 * tas2555_i2c_read_device : read single byte from device
111 * platform dependent, need platform specific support
112 */
113 static int tas2555_i2c_read_device(     
114         struct tas2555_priv *pTAS2555,
115         unsigned char addr, 
116         unsigned char reg, 
117         unsigned char *p_value)
119         int ret = 0;
120         unsigned int val = 0;
121         
122         pTAS2555->client->addr = addr;
123         ret = regmap_read(pTAS2555->mpRegmap, reg, &val);
124         if(ret < 0){
125                 dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
126                         __FUNCTION__, addr, ret);
127         }else{
128                 *p_value = (unsigned char)val;
129                 ret = 1;
130         }
131         
132         return ret;
135 /*
136 * tas2555_i2c_bulkread_device : read multiple bytes from device
137 * platform dependent, need platform specific support
138 */
139 static int tas2555_i2c_bulkread_device( 
140         struct tas2555_priv *pTAS2555,
141         unsigned char addr, 
142         unsigned char reg, 
143         unsigned char *p_value,
144         unsigned int len)
146         int ret = 0;
147         pTAS2555->client->addr = addr;
148         ret = regmap_bulk_read(pTAS2555->mpRegmap, reg, p_value, len);
149         
150         if(ret < 0){
151                 dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
152                         __FUNCTION__, addr, ret);
153         }else{
154                 ret = len;
155         }
156         
157         return ret;
160 static int tas2555_i2c_update_bits(     
161         struct tas2555_priv *pTAS2555,
162         unsigned char addr, 
163         unsigned char reg, 
164         unsigned char mask,
165         unsigned char value)
167         int ret = 0;
168         
169         pTAS2555->client->addr = addr;
170         ret = regmap_update_bits(pTAS2555->mpRegmap, reg, mask, value);
171         
172         if(ret < 0){
173                 dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
174                         __FUNCTION__, addr, ret);
175         }else{
176                 ret = 1;
177         }
178         
179         return ret;
182 /* 
183 * tas2555_change_book_page : switch to certain book and page
184 * platform independent, don't change unless necessary
185 */
186 static int tas2555_change_book_page(
187         struct tas2555_priv *pTAS2555, 
188         enum channel chn,
189         int nBook,
190         int nPage)
192         int nResult = 0;
193         
194         if(chn&channel_left){
195                 if(pTAS2555->mnLCurrentBook == nBook){
196                         if(pTAS2555->mnLCurrentPage != nPage){
197                                 nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_BOOKCTL_PAGE, nPage);
198                                 if(nResult >=0 )
199                                         pTAS2555->mnLCurrentPage = nPage;
200                         }
201                 }else{
202                         nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_BOOKCTL_PAGE, 0);
203                         if(nResult >=0){
204                                 pTAS2555->mnLCurrentPage = 0;
205                                 nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_BOOKCTL_REG, nBook);
206                                 pTAS2555->mnLCurrentBook = nBook;
207                                 if(nPage != 0){
208                                         tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_BOOKCTL_PAGE, nPage);
209                                         pTAS2555->mnLCurrentPage = nPage;
210                                 }
211                         }
212                 }
213         }
215         if(chn&channel_right){
216                 if(pTAS2555->mnRCurrentBook == nBook){
217                         if(pTAS2555->mnRCurrentPage != nPage){
218                                 nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_BOOKCTL_PAGE, nPage);
219                                 if(nResult >=0 )
220                                         pTAS2555->mnRCurrentPage = nPage;
221                         }
222                 }else{
223                         nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_BOOKCTL_PAGE, 0);
224                         if(nResult >=0){
225                                 pTAS2555->mnRCurrentPage = 0;
226                                 nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_BOOKCTL_REG, nBook);
227                                 pTAS2555->mnRCurrentBook = nBook;
228                                 if(nPage != 0){
229                                         tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_BOOKCTL_PAGE, nPage);
230                                         pTAS2555->mnRCurrentPage = nPage;
231                                 }
232                         }
233                 }
234         }       
235         
236         if(chn == channel_broadcast){
237                 nResult = tas2555_i2c_write_device(pTAS2555, TAS2555_BROADCAST_ADDR, TAS2555_BOOKCTL_PAGE, 0);
238                 if(nResult >= 0){
239                         tas2555_i2c_write_device(pTAS2555, TAS2555_BROADCAST_ADDR, TAS2555_BOOKCTL_REG, nBook);
240                         tas2555_i2c_write_device(pTAS2555, TAS2555_BROADCAST_ADDR, TAS2555_BOOKCTL_PAGE, nPage);
241                         pTAS2555->mnLCurrentPage = nPage;
242                         pTAS2555->mnRCurrentPage = nPage;
243                         pTAS2555->mnLCurrentBook = nBook;
244                         pTAS2555->mnRCurrentBook = nBook;               
245                 }
246         }
247         
248         return nResult;
251 /* 
252 * tas2555_dev_read :
253 * platform independent, don't change unless necessary
254 */
255 static int tas2555_dev_read(
256         struct tas2555_priv *pTAS2555,
257         enum channel chn,
258         unsigned int nRegister, 
259         unsigned int *pValue)
261         int nResult = 0;
262         unsigned char Value = 0;
264         mutex_lock(&pTAS2555->dev_lock);        
265         
266         if (pTAS2555->mbTILoadActive) {
267                 if (!(nRegister & 0x80000000)){
268                         mutex_unlock(&pTAS2555->dev_lock);
269                         return 0;                       // let only reads from TILoad pass.
270                 }
271                 nRegister &= ~0x80000000;
272                 
273                 dev_dbg(pTAS2555->dev, "TiLoad R CH[%d] REG B[%d]P[%d]R[%d]\n", 
274                                 chn,
275                                 TAS2555_BOOK_ID(nRegister),
276                                 TAS2555_PAGE_ID(nRegister),
277                                 TAS2555_PAGE_REG(nRegister));
278         }
280         nResult = tas2555_change_book_page(pTAS2555, 
281                                                         chn, 
282                                                         TAS2555_BOOK_ID(nRegister),
283                                                         TAS2555_PAGE_ID(nRegister));
284         if(nResult >=0){
285                 if(chn == channel_left){
286                         nResult = tas2555_i2c_read_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), &Value);
287                 }else if(chn == channel_right){
288                         nResult = tas2555_i2c_read_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), &Value);
289                 }else{
290                         dev_err(pTAS2555->dev, "read chn ERROR %d\n", chn);
291                         nResult = -1;
292                 }
293                 
294                 if(nResult>=0) *pValue = Value;
295         }
296         mutex_unlock(&pTAS2555->dev_lock);
297         return nResult;
300 /* 
301 * tas2555_dev_write :
302 * platform independent, don't change unless necessary
303 */
304 static int tas2555_dev_write(
305         struct tas2555_priv *pTAS2555,
306         enum channel chn,
307         unsigned int nRegister, 
308         unsigned int nValue)
310         int nResult = 0;
311         
312         mutex_lock(&pTAS2555->dev_lock);
313         if ((nRegister == 0xAFFEAFFE) && (nValue == 0xBABEBABE)) {
314                 pTAS2555->mbTILoadActive = true;
315                 mutex_unlock(&pTAS2555->dev_lock);
316                 
317                 dev_dbg(pTAS2555->dev, "TiLoad Active\n");
318                 return 0;
319         }
321         if ((nRegister == 0xBABEBABE) && (nValue == 0xAFFEAFFE)) {
322                 pTAS2555->mbTILoadActive = false;
323                 mutex_unlock(&pTAS2555->dev_lock);
324                 
325                 dev_dbg(pTAS2555->dev, "TiLoad DeActive\n");
326                 return 0;
327         }
329         if (pTAS2555->mbTILoadActive) {
330                 if (!(nRegister & 0x80000000)){
331                         mutex_unlock(&pTAS2555->dev_lock);
332                         return 0;                       // let only writes from TILoad pass.
333                 }
334                 nRegister &= ~0x80000000;
335                 
336                 dev_dbg(pTAS2555->dev, "TiLoad W CH[%d] REG B[%d]P[%d]R[%d] =0x%x\n", 
337                                                 chn,
338                                                 TAS2555_BOOK_ID(nRegister),
339                                                 TAS2555_PAGE_ID(nRegister),
340                                                 TAS2555_PAGE_REG(nRegister),
341                                                 nValue);
342         }
344         nResult = tas2555_change_book_page(pTAS2555, 
345                                                         chn, 
346                                                         TAS2555_BOOK_ID(nRegister),
347                                                         TAS2555_PAGE_ID(nRegister));
349         if(nResult >= 0){
350                 if(chn & channel_left){
351                         nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), nValue);
352                 }
353                 
354                 if(chn & channel_right){
355                         nResult = tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), nValue);
356                 }       
357                 
358                 if(chn == channel_broadcast){
359                         nResult = tas2555_i2c_write_device(pTAS2555, TAS2555_BROADCAST_ADDR, TAS2555_PAGE_REG(nRegister), nValue);
360                 }
361         }
362         
363         mutex_unlock(&pTAS2555->dev_lock);              
364         
365         return nResult;
368 /* 
369 * tas2555_dev_bulk_read :
370 * platform independent, don't change unless necessary
371 */
372 static int tas2555_dev_bulk_read(
373         struct tas2555_priv *pTAS2555,
374         enum channel chn,
375         unsigned int nRegister, 
376         u8 * pData, 
377         unsigned int nLength)
379         int nResult = 0;
380         unsigned char reg = 0;
381         unsigned char Addr = 0;
382         
383         mutex_lock(&pTAS2555->dev_lock);
384         if (pTAS2555->mbTILoadActive) {
385                 if (!(nRegister & 0x80000000)){
386                         mutex_unlock(&pTAS2555->dev_lock);
387                         return 0;                       // let only writes from TILoad pass.
388                 }
389                                                                 
390                 nRegister &= ~0x80000000;
391                 dev_dbg(pTAS2555->dev, "TiLoad BR CH[%d] REG B[%d]P[%d]R[%d], count=%d\n", 
392                                 chn,
393                                 TAS2555_BOOK_ID(nRegister),
394                                 TAS2555_PAGE_ID(nRegister),
395                                 TAS2555_PAGE_REG(nRegister),
396                                 nLength);               
397         }
399         nResult = tas2555_change_book_page(pTAS2555, 
400                                                                         chn,
401                                                                         TAS2555_BOOK_ID(nRegister),
402                                                                         TAS2555_PAGE_ID(nRegister));
403         if(nResult >= 0){
404                 reg = TAS2555_PAGE_REG(nRegister);              
405                 if(chn == channel_left){                        
406                         Addr = pTAS2555->mnLAddr;
407                 }else if(chn == channel_right){
408                         Addr = pTAS2555->mnRAddr;
409                 }else{
410                         dev_err(pTAS2555->dev, "bulk read chn ERROR %d\n", chn);
411                         nResult = -1;
412                 }
413                 
414                 if(nResult >= 0){
415                         nResult = tas2555_i2c_bulkread_device(
416                                 pTAS2555, Addr, reg, pData, nLength);
417                 }
418         }
419                                                                         
420         mutex_unlock(&pTAS2555->dev_lock);      
422         return nResult;
425 /* 
426 * tas2555_dev_bulk_write :
427 * platform independent, don't change unless necessary
428 */
429 static int tas2555_dev_bulk_write(
430         struct tas2555_priv *pTAS2555,
431         enum channel chn,
432         unsigned int nRegister, 
433         u8 * pData, 
434         unsigned int nLength)
436         int nResult = 0;
437         unsigned char reg = 0;
438         
439         mutex_lock(&pTAS2555->dev_lock);
440         if (pTAS2555->mbTILoadActive) {
441                 if (!(nRegister & 0x80000000)){
442                         mutex_unlock(&pTAS2555->dev_lock);
443                         return 0;                       // let only writes from TILoad pass.
444                 }
445                                                         
446                 nRegister &= ~0x80000000;
447                 
448                 dev_dbg(pTAS2555->dev, "TiLoad BW CH[%d] REG B[%d]P[%d]R[%d], count=%d\n", 
449                                 chn,
450                                 TAS2555_BOOK_ID(nRegister),
451                                 TAS2555_PAGE_ID(nRegister),
452                                 TAS2555_PAGE_REG(nRegister),
453                                 nLength);               
454         }
456         nResult = tas2555_change_book_page(
457                 pTAS2555, 
458                 chn,
459                 TAS2555_BOOK_ID(nRegister),
460                 TAS2555_PAGE_ID(nRegister));
461                 
462         if(nResult >=0){
463                 reg = TAS2555_PAGE_REG(nRegister);      
464                 if(chn & channel_left){
465                         nResult = tas2555_i2c_bulkwrite_device(
466                                 pTAS2555,
467                                 pTAS2555->mnLAddr,
468                                 reg, pData, nLength);
469                         if(nResult < 0){
470                                 dev_err(pTAS2555->dev, "bulk write error %d\n", nResult);
471                         }
472                 }
473                 
474                 if(chn & channel_right){
475                         nResult = tas2555_i2c_bulkwrite_device(
476                                 pTAS2555,
477                                 pTAS2555->mnRAddr,
478                                 reg, pData, nLength);
479                         if(nResult < 0){
480                                 dev_err(pTAS2555->dev, "bulk write error %d\n", nResult);
481                         }
482                 }
483                 
484                 if(chn == channel_broadcast){
485                         nResult = tas2555_i2c_bulkwrite_device(pTAS2555, TAS2555_BROADCAST_ADDR, reg, pData, nLength);
486                 }
487         }
488         mutex_unlock(&pTAS2555->dev_lock);              
489         
490         return nResult;
493 /* 
494 * tas2555_dev_update_bits :
495 * platform independent, don't change unless necessary
496 */
497 static int tas2555_dev_update_bits(
498         struct tas2555_priv *pTAS2555,
499         enum channel chn,
500         unsigned int nRegister, 
501         unsigned int nMask, 
502         unsigned int nValue)
504         int nResult = 0;
505         
506         mutex_lock(&pTAS2555->dev_lock);
507         
508         if (pTAS2555->mbTILoadActive) {
509                 if (!(nRegister & 0x80000000)){
510                         mutex_unlock(&pTAS2555->dev_lock);
511                         return 0;                       // let only writes from TILoad pass.
512                 }
513                                                                 
514                 nRegister &= ~0x80000000;
515                 
516                 dev_dbg(pTAS2555->dev, "TiLoad SB CH[%d] REG B[%d]P[%d]R[%d], mask=0x%x, value=0x%x\n", 
517                                 chn,
518                                 TAS2555_BOOK_ID(nRegister),
519                                 TAS2555_PAGE_ID(nRegister),
520                                 TAS2555_PAGE_REG(nRegister),
521                                 nMask, nValue);         
522         }
523         
524         nResult = tas2555_change_book_page(
525                 pTAS2555,
526                 chn,
527                 TAS2555_BOOK_ID(nRegister),
528                 TAS2555_PAGE_ID(nRegister));
529         
530         if(nResult>=0){
531                 if(chn&channel_left){
532                         tas2555_i2c_update_bits(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), nMask, nValue);
533                 }
534                 
535                 if(chn&channel_right){
536                         tas2555_i2c_update_bits(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), nMask, nValue);
537                 }       
538         }
539                 
540         mutex_unlock(&pTAS2555->dev_lock);              
541         return nResult;
544 static bool tas2555_volatile(struct device *pDev, unsigned int nRegister)
546         return true;
549 static bool tas2555_writeable(struct device *pDev, unsigned int nRegister)
551         return true;
554 static const struct regmap_config tas2555_i2c_regmap = {
555         .reg_bits = 8,
556         .val_bits = 8,
557         .writeable_reg = tas2555_writeable,
558         .volatile_reg = tas2555_volatile,
559         .cache_type = REGCACHE_NONE,
560         .max_register = 128,
561 };
562 /* 
563 * tas2555_i2c_probe :
564 * platform dependent
565 * should implement hardware reset functionality
566 */
567 static int tas2555_i2c_probe(struct i2c_client *pClient,
568         const struct i2c_device_id *pID)
570         struct tas2555_priv *pTAS2555;
571         int nResult;
572         unsigned int nValue = 0;
574         dev_info(&pClient->dev, "%s enter\n", __FUNCTION__);
575                 
576         pTAS2555 = devm_kzalloc(&pClient->dev, sizeof(struct tas2555_priv), GFP_KERNEL);
577         if (!pTAS2555){
578                 dev_err(&pClient->dev, " -ENOMEM\n");
579                 return -ENOMEM;
580         }
581         
582         pTAS2555->client = pClient;
583         pTAS2555->dev = &pClient->dev;
584         i2c_set_clientdata(pClient, pTAS2555);
585         dev_set_drvdata(&pClient->dev, pTAS2555);       
586         mutex_init(&pTAS2555->dev_lock);
587         
588         nResult = tas2555_parse_dt(&pClient->dev, pTAS2555);
589         if(nResult < 0){
590                 dev_err(&pClient->dev, " dt error\n");
591                 return -EINVAL;
592         }
594         pTAS2555->mpRegmap = devm_regmap_init_i2c(pClient, &tas2555_i2c_regmap);
595         if (IS_ERR(pTAS2555->mpRegmap)) {
596                 nResult = PTR_ERR(pTAS2555->mpRegmap);
597                 dev_err(&pClient->dev, "Failed to allocate register map: %d\n",
598                         nResult);
599                 return nResult;
600         }
601         
602 #ifdef HARD_RESET       
603         //TODO implement hardware reset here to both TAS2555 devices
604         //platform dependent
605         dev_info(&pClient->dev, "reset gpio is %d\n", pTAS2555->mnResetGPIO);
606         if (gpio_is_valid(pTAS2555->mnResetGPIO)) {
607                 devm_gpio_request_one(&pClient->dev, pTAS2555->mnResetGPIO,
608                         GPIOF_OUT_INIT_LOW, "TAS2555_RST");
609                 mdelay(2);
610                 gpio_set_value_cansleep(pTAS2555->mnResetGPIO, 1);
611                 udelay(1000);
612         }
613 #else   
614         pTAS2555->mnLCurrentBook = -1;
615         pTAS2555->mnLCurrentPage = -1;
616         pTAS2555->mnRCurrentBook = -1;
617         pTAS2555->mnRCurrentPage = -1;
618 #endif  
619         /* Reset the chip */
620         nResult = tas2555_dev_write(pTAS2555, channel_both, TAS2555_SW_RESET_REG, 1);
621         if(nResult < 0){
622                 dev_err(&pClient->dev, "I2c fail, %d\n", nResult);      
623                 mutex_destroy(&pTAS2555->dev_lock);
624         }else{
625                 udelay(1000);
626                 tas2555_dev_read(pTAS2555, channel_left, TAS2555_REV_PGID_REG, &nValue);
627                 dev_info(&pClient->dev, "Left Chn, PGID=0x%x\n", nValue);
628                 tas2555_dev_read(pTAS2555, channel_right, TAS2555_REV_PGID_REG, &nValue);
629                 dev_info(&pClient->dev, "Right Chn, PGID=0x%x\n", nValue);      
630                 
631                 pTAS2555->mpFirmware = devm_kzalloc(&pClient->dev, sizeof(TFirmware), GFP_KERNEL);
632                 if (!pTAS2555->mpFirmware){
633                         dev_err(&pClient->dev, "mpFirmware ENOMEM\n");  
634                         mutex_destroy(&pTAS2555->dev_lock);
635                         return -ENOMEM;
636                 }
638                 pTAS2555->mpCalFirmware = devm_kzalloc(&pClient->dev, sizeof(TFirmware), GFP_KERNEL);
639                 if (!pTAS2555->mpCalFirmware){
640                         dev_err(&pClient->dev, "mpCalFirmware ENOMEM\n");
641                         mutex_destroy(&pTAS2555->dev_lock);                     
642                         return -ENOMEM;
643                 }
644                 
645                 pTAS2555->read = tas2555_dev_read;
646                 pTAS2555->write = tas2555_dev_write;
647                 pTAS2555->bulk_read = tas2555_dev_bulk_read;
648                 pTAS2555->bulk_write = tas2555_dev_bulk_write;
649                 pTAS2555->update_bits = tas2555_dev_update_bits;
650                 pTAS2555->set_config = tas2555_set_config;
651                 pTAS2555->set_calibration = tas2555_set_calibration;
652                 
653                 nResult = request_firmware_nowait(THIS_MODULE, 1, TAS2555_FW_NAME,
654                         pTAS2555->dev, GFP_KERNEL, pTAS2555, tas2555_fw_ready);
656 #ifdef CONFIG_TAS2555_CODEC_STEREO      
657                 tas2555_register_codec(pTAS2555);
658 #endif
660 #ifdef CONFIG_TAS2555_MISC_STEREO       
661                 mutex_init(&pTAS2555->file_lock);
662                 tas2555_register_misc(pTAS2555);
663 #endif
665 #ifdef ENABLE_TILOAD
666                 tiload_driver_init(pTAS2555, channel_left);
667                 tiload_driver_init(pTAS2555, channel_right);
668 #endif
670         }
671         
672         return nResult;
675 static int tas2555_i2c_remove(struct i2c_client *pClient)
677         struct tas2555_priv *pTAS2555 = i2c_get_clientdata(pClient);
678         
679         dev_info(pTAS2555->dev, "%s\n", __FUNCTION__);
680         
681 #ifdef CONFIG_TAS2555_CODEC_STEREO              
682         tas2555_deregister_codec(pTAS2555);
683 #endif
685 #ifdef CONFIG_TAS2555_MISC_STEREO               
686         tas2555_deregister_misc(pTAS2555);
687         mutex_destroy(&pTAS2555->file_lock);
688 #endif
689         
690         return 0;
693 static const struct i2c_device_id tas2555_i2c_id[] = {
694         {"tas2555s", 0},
695         {}
696 };
698 MODULE_DEVICE_TABLE(i2c, tas2555_i2c_id);
700 #if defined(CONFIG_OF)
701 static const struct of_device_id tas2555_of_match[] = {
702         {.compatible = "ti,tas2555s"},
703         {},
704 };
706 MODULE_DEVICE_TABLE(of, tas2555_of_match);
707 #endif
709 static struct i2c_driver tas2555_i2c_driver = {
710         .driver = {
711                         .name = "tas2555s",
712                         .owner = THIS_MODULE,
713 #if defined(CONFIG_OF)
714                         .of_match_table = of_match_ptr(tas2555_of_match),
715 #endif
716                 },
717         .probe = tas2555_i2c_probe,
718         .remove = tas2555_i2c_remove,
719         .id_table = tas2555_i2c_id,
720 };
722 module_i2c_driver(tas2555_i2c_driver);
724 MODULE_AUTHOR("Texas Instruments Inc.");
725 MODULE_DESCRIPTION("TAS2555 Stereo I2C Smart Amplifier driver");
726 MODULE_LICENSE("GPLv2");
727 #endif