1. update driver to support "Driver Firmware Version" in firmware (tas2555s_uCDSP...
authora0220410 <peter-li@ti.com>
Wed, 10 Aug 2016 16:00:45 +0000 (00:00 +0800)
committera0220410 <peter-li@ti.com>
Wed, 10 Aug 2016 16:00:45 +0000 (00:00 +0800)
2. use regmap API to replace i2c API

tas2555-core.c
tas2555-i2c.c
tas2555.h

index b1045eac4f48918d0e5541697cbaa173a5286c9d..32dec54ee3ddb76b681f8b24aa4201a823654944 100755 (executable)
@@ -44,6 +44,7 @@
 #include "tas2555.h"
 #include "tas2555-core.h"
 
+#define PPC_WITH_DRIVER_VERSION                0x010b8100
 #define TAS2555_CAL_NAME    "/data/tas2555_cal.bin"
 
 //set default PLL CLKIN to GPI2 (MCLK) = 0x00
@@ -352,14 +353,15 @@ int tas2555_set_sampling_rate(struct tas2555_priv *pTAS2555, unsigned int nSampl
 
 static void fw_print_header(struct tas2555_priv *pTAS2555, TFirmware * pFirmware)
 {
-       dev_info(pTAS2555->dev, "  FW Size       = %d", pFirmware->mnFWSize);
-       dev_info(pTAS2555->dev, "  Checksum      = 0x%04X", pFirmware->mnChecksum);
-       dev_info(pTAS2555->dev, "  PPC Version   = 0x%04X", pFirmware->mnPPCVersion);
-       dev_info(pTAS2555->dev, "  DSPFWVersion  = 0x%04X", pFirmware->mnDSPFWVersion);
-       dev_info(pTAS2555->dev, "  DRVFWVersion  = 0x%04X", pFirmware->mnDrvFWVersion);
-       dev_info(pTAS2555->dev, "  Timestamp     = %d", pFirmware->mnTimeStamp);
-       dev_info(pTAS2555->dev, "  DDC Name      = %s", pFirmware->mpDDCName);
-       dev_info(pTAS2555->dev, "  Description   = %s", pFirmware->mpDescription);
+       dev_info(pTAS2555->dev, "FW Size       = %d", pFirmware->mnFWSize);
+       dev_info(pTAS2555->dev, "Checksum      = 0x%04X", pFirmware->mnChecksum);
+       dev_info(pTAS2555->dev, "PPC Version   = 0x%04X", pFirmware->mnPPCVersion);
+       dev_info(pTAS2555->dev, "DSPFWVersion  = 0x%04X", pFirmware->mnFWVersion);      
+       if(pFirmware->mnPPCVersion >= PPC_WITH_DRIVER_VERSION)
+       dev_info(pTAS2555->dev, "Driver Version= 0x%04X", pFirmware->mnDriverVersion);
+       dev_info(pTAS2555->dev, "Timestamp     = %d", pFirmware->mnTimeStamp);
+       dev_info(pTAS2555->dev, "DDC Name      = %s", pFirmware->mpDDCName);
+       dev_info(pTAS2555->dev, "Description   = %s", pFirmware->mpDescription);
 }
 
 inline unsigned int fw_convert_number(unsigned char *pData)
@@ -395,12 +397,14 @@ static int fw_parse_header(struct tas2555_priv *pTAS2555,
        pFirmware->mnPPCVersion = fw_convert_number(pData);
        pData += 4;
 
-//     pFirmware->mnDSPFWVersion = fw_convert_number(pData);
-//     pData += 4;
-       
-       pFirmware->mnDrvFWVersion = fw_convert_number(pData);
+       pFirmware->mnFWVersion = fw_convert_number(pData);
        pData += 4;
 
+       if(pFirmware->mnPPCVersion >= PPC_WITH_DRIVER_VERSION){
+               pFirmware->mnDriverVersion = fw_convert_number(pData);
+               pData += 4;             
+       }       
+
        pFirmware->mnTimeStamp = fw_convert_number(pData);
        pData += 4;
 
index 976119656f2a96d02c452ec42cbb34c16fad17c2..732a562d4fde3f6acbf377111c078fcbedd56757 100755 (executable)
@@ -68,31 +68,18 @@ static int tas2555_i2c_write_device(
        unsigned char reg, 
        unsigned char value)
 {
-       int ret;
-       u8 data[2];
-       struct i2c_msg *msg = &pTAS2555->xfer_msg[0];
-
-       msg->addr = addr;
-       msg->len = 2;
-       msg->flags = 0;
-       data[0] = reg;
-       data[1] = value;
-       msg->buf = data;
-       ret = i2c_transfer(
-               pTAS2555->client->adapter, 
-               pTAS2555->xfer_msg, 1);
-       /* Try again if the write fails */
-       if (ret != 1) {
-               ret = i2c_transfer(
-                       pTAS2555->client->adapter, 
-                       pTAS2555->xfer_msg, 1);
-               if (ret != 1) {
-                       dev_err(pTAS2555->dev, "failed to write the device, %d\n", ret);
-                       return ret;
-               }
+       int ret = 0;
+       
+       pTAS2555->client->addr = addr;
+       ret = regmap_write(pTAS2555->mpRegmap, reg, value);
+       if(ret < 0){
+               dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
+                       __FUNCTION__, addr, ret);
+       }else{
+               ret = 1;
        }
        
-       return 0;
+       return ret;
 }
 
 /*
@@ -106,32 +93,17 @@ static int tas2555_i2c_bulkwrite_device(
        unsigned char *pBuf,
        unsigned int len)
 {
-       int ret;
-       u8 data[ 1 + len];
-       struct i2c_msg *msg = &pTAS2555->xfer_msg[0];
-
-       msg->addr = addr;
-       msg->len = 2;
-       msg->flags = 0;
-       data[0] = reg;
-       memcpy(&data[1], pBuf, len);    
-       msg->buf = data;
-       ret = i2c_transfer(
-               pTAS2555->client->adapter, 
-               pTAS2555->xfer_msg, 1);
-       /* Try again if the write fails */
-       if (ret != 1) {
-               ret = i2c_transfer(
-                       pTAS2555->client->adapter, 
-                       pTAS2555->xfer_msg, 1);
-               if (ret != 1) {
-                       dev_err(pTAS2555->dev, 
-                               "failed to multiple write the device, %d\n", ret);
-                       return ret;
-               }
-       }
+       int ret = 0;
        
-       return 0;
+       pTAS2555->client->addr = addr;
+       ret = regmap_bulk_write(pTAS2555->mpRegmap, reg, pBuf, len);
+       if(ret < 0){
+               dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
+                       __FUNCTION__, addr, ret);
+       }else{
+               ret = len;
+       }
+       return ret;
 }
 
 /*
@@ -144,33 +116,20 @@ static int tas2555_i2c_read_device(
        unsigned char reg, 
        unsigned char *p_value)
 {
-       struct i2c_msg *msg;
        int ret = 0;
-
-       msg = &pTAS2555->xfer_msg[0];
-       msg->addr = addr;
-       msg->len = 1;
-       msg->flags = 0;
-       msg->buf = &reg;
-       msg = &pTAS2555->xfer_msg[1];
-       msg->addr = addr;
-       msg->len = 1;
-       msg->flags = I2C_M_RD;
-       msg->buf = p_value;
-       ret = i2c_transfer(pTAS2555->client->adapter,
-                       pTAS2555->xfer_msg, 2);
-
-       /* Try again if read fails first time */
-       if (ret != 2) {
-               ret = i2c_transfer(pTAS2555->client->adapter,
-                                  pTAS2555->xfer_msg, 2);
-               if (ret != 2) {
-                       dev_err(pTAS2555->dev, "failed to read the device, %d\n", ret);
-                       return ret;
-               }
+       unsigned int val = 0;
+       
+       pTAS2555->client->addr = addr;
+       ret = regmap_read(pTAS2555->mpRegmap, reg, &val);
+       if(ret < 0){
+               dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
+                       __FUNCTION__, addr, ret);
+       }else{
+               *p_value = (unsigned char)val;
+               ret = 1;
        }
        
-       return 0;
+       return ret;
 }
 
 /*
@@ -184,34 +143,40 @@ static int tas2555_i2c_bulkread_device(
        unsigned char *p_value,
        unsigned int len)
 {
-       struct i2c_msg *msg;
        int ret = 0;
+       pTAS2555->client->addr = addr;
+       ret = regmap_bulk_read(pTAS2555->mpRegmap, reg, p_value, len);
+       
+       if(ret < 0){
+               dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
+                       __FUNCTION__, addr, ret);
+       }else{
+               ret = len;
+       }
+       
+       return ret;
+}
 
-       msg = &pTAS2555->xfer_msg[0];
-       msg->addr = addr;
-       msg->len = 1;
-       msg->flags = 0;
-       msg->buf = &reg;
-       msg = &pTAS2555->xfer_msg[1];
-       msg->addr = addr;
-       msg->len = len;
-       msg->flags = I2C_M_RD;
-       msg->buf = p_value;
-       ret = i2c_transfer(pTAS2555->client->adapter,
-                       pTAS2555->xfer_msg, 2);
-
-       /* Try again if read fails first time */
-       if (ret != 2) {
-               ret = i2c_transfer(pTAS2555->client->adapter,
-                                  pTAS2555->xfer_msg, 2);
-               if (ret != 2) {
-                       dev_err(pTAS2555->dev, 
-                               "failed to bulk read the device, %d\n", ret);
-                       return ret;
-               }
+static int tas2555_i2c_update_bits(    
+       struct tas2555_priv *pTAS2555,
+       unsigned char addr, 
+       unsigned char reg, 
+       unsigned char mask,
+       unsigned char value)
+{
+       int ret = 0;
+       
+       pTAS2555->client->addr = addr;
+       ret = regmap_update_bits(pTAS2555->mpRegmap, reg, mask, value);
+       
+       if(ret < 0){
+               dev_err(pTAS2555->dev, "%s[0x%x] Error %d\n",
+                       __FUNCTION__, addr, ret);
+       }else{
+               ret = 1;
        }
        
-       return 0;
+       return ret;
 }
 
 /* 
@@ -516,7 +481,6 @@ static int tas2555_dev_update_bits(
        unsigned int nValue)
 {
        int nResult = 0;
-       unsigned char temp = 0;
        
        mutex_lock(&pTAS2555->dev_lock);
        
@@ -544,21 +508,11 @@ static int tas2555_dev_update_bits(
        
        if(nResult>=0){
                if(chn&channel_left){
-                       tas2555_i2c_read_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), &temp);
-                       if((temp&nMask)!=(nValue&nMask)){
-                               temp &= ~nMask;
-                               temp |= (nValue&nMask);
-                               tas2555_i2c_write_device(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), temp);
-                       }
+                       tas2555_i2c_update_bits(pTAS2555, pTAS2555->mnLAddr, TAS2555_PAGE_REG(nRegister), nMask, nValue);
                }
                
                if(chn&channel_right){
-                       tas2555_i2c_read_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), &temp);
-                       if((temp&nMask)!=(nValue&nMask)){
-                               temp &= ~nMask;
-                               temp |= (nValue&nMask);
-                               tas2555_i2c_write_device(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), temp);
-                       }
+                       tas2555_i2c_update_bits(pTAS2555, pTAS2555->mnRAddr, TAS2555_PAGE_REG(nRegister), nMask, nValue);
                }       
        }
                
@@ -566,6 +520,24 @@ static int tas2555_dev_update_bits(
        return nResult;
 }
 
+static bool tas2555_volatile(struct device *pDev, unsigned int nRegister)
+{
+       return true;
+}
+
+static bool tas2555_writeable(struct device *pDev, unsigned int nRegister)
+{
+       return true;
+}
+
+static const struct regmap_config tas2555_i2c_regmap = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .writeable_reg = tas2555_writeable,
+       .volatile_reg = tas2555_volatile,
+       .cache_type = REGCACHE_NONE,
+       .max_register = 128,
+};
 /* 
 * tas2555_i2c_probe :
 * platform dependent
@@ -598,10 +570,25 @@ static int tas2555_i2c_probe(struct i2c_client *pClient,
                return -EINVAL;
        }
 
+       pTAS2555->mpRegmap = devm_regmap_init_i2c(pClient, &tas2555_i2c_regmap);
+       if (IS_ERR(pTAS2555->mpRegmap)) {
+               nResult = PTR_ERR(pTAS2555->mpRegmap);
+               dev_err(&pClient->dev, "Failed to allocate register map: %d\n",
+                       nResult);
+               return nResult;
+       }
+       
 #ifdef HARD_RESET      
        //TODO implement hardware reset here to both TAS2555 devices
        //platform dependent
-       udelay(1000);
+       dev_info(&pClient->dev, "reset gpio is %d\n", pTAS2555->mnResetGPIO);
+       if (gpio_is_valid(pTAS2555->mnResetGPIO)) {
+               devm_gpio_request_one(&pClient->dev, pTAS2555->mnResetGPIO,
+                       GPIOF_OUT_INIT_LOW, "TAS2555_RST");
+               mdelay(2);
+               gpio_set_value_cansleep(pTAS2555->mnResetGPIO, 1);
+               udelay(1000);
+       }
 #else  
        pTAS2555->mnLCurrentBook = -1;
        pTAS2555->mnLCurrentPage = -1;
index 04b12b332423d95394bafbcc480e7afae5eafced..1b0b97efcf87b2727b17caaa7da88dd48889a719 100755 (executable)
--- a/tas2555.h
+++ b/tas2555.h
@@ -26,6 +26,8 @@
 #ifndef _TAS2555_H
 #define _TAS2555_H
 
+#include <linux/regmap.h>
+
 /* Page Control Register */
 #define TAS2555_PAGECTL_REG                    0
 
@@ -311,8 +313,8 @@ typedef struct {
        unsigned int mnFWSize;
        unsigned int mnChecksum;
        unsigned int mnPPCVersion;
-       unsigned int mnDSPFWVersion;
-       unsigned int mnDrvFWVersion;
+       unsigned int mnFWVersion;
+       unsigned int mnDriverVersion;
        unsigned int mnTimeStamp;
        char mpDDCName[64];
        char *mpDescription;
@@ -342,10 +344,8 @@ enum channel{
 
 struct tas2555_priv {
        struct device *dev;
-#ifdef CONFIG_TAS2555_I2C_STEREO       
-       struct i2c_msg xfer_msg[2];
+       struct regmap *mpRegmap;
        struct i2c_client *client;      
-#endif 
        int mnResetGPIO;
        struct mutex dev_lock;  
        TFirmware *mpFirmware;