update end-system tuning
authora0220410 <peter-li@ti.com>
Mon, 26 Dec 2016 01:02:23 +0000 (09:02 +0800)
committera0220410 <peter-li@ti.com>
Mon, 26 Dec 2016 01:02:23 +0000 (09:02 +0800)
tas2555-i2c.c
tas2555.h
tiload.c
tiload.h

index a2e172e150cf4a05cfc4ec69846e732e3fa7b2e2..6ddcfabb3deae3991170055b6d8fe04ad2a125c4 100755 (executable)
@@ -186,8 +186,8 @@ static int tas2555_i2c_update_bits(
 static int tas2555_change_book_page(
        struct tas2555_priv *pTAS2555, 
        enum channel chn,
-       int nBook,
-       int nPage)
+       unsigned char nBook,
+       unsigned char nPage)
 {
        int nResult = 0;
        
@@ -663,8 +663,7 @@ static int tas2555_i2c_probe(struct i2c_client *pClient,
 #endif
 
 #ifdef ENABLE_TILOAD
-               tiload_driver_init(pTAS2555, channel_left);
-               tiload_driver_init(pTAS2555, channel_right);
+               tiload_driver_init(pTAS2555);
 #endif
 
        }
index 3902b81cbd2e28c6e7ccc0e89fcb1d25b885b65f..0890a5ad377cc0783ef8690cd79f55ead7910c6a 100755 (executable)
--- a/tas2555.h
+++ b/tas2555.h
 #define TAS2555_BOOKCTL_PAGE                   0
 #define TAS2555_BOOKCTL_REG                    127
 
-#define TAS2555_REG(book, page, reg)           (((book * 256 * 128) + \
-                                                (page * 128)) + reg)
+#define TAS2555_REG(book, page, reg)           ((((unsigned int)book * 256 * 128) + \
+                                                ((unsigned int)page * 128)) + reg)
 
-#define TAS2555_BOOK_ID(reg)                   (reg / (256 * 128))
-#define TAS2555_PAGE_ID(reg)                   ((reg % (256 * 128)) / 128)
-#define TAS2555_BOOK_REG(reg)                  (reg % (256 * 128))
-#define TAS2555_PAGE_REG(reg)                  ((reg % (256 * 128)) % 128)
+#define TAS2555_BOOK_ID(reg)                   ((unsigned char)(reg / (256 * 128)))
+#define TAS2555_PAGE_ID(reg)                   ((unsigned char)((reg % (256 * 128)) / 128))
+#define TAS2555_BOOK_REG(reg)                  ((unsigned char)(reg % (256 * 128)))
+#define TAS2555_PAGE_REG(reg)                  ((unsigned char)((reg % (256 * 128)) % 128))
 
 /* Book0, Page0 registers */
 #define TAS2555_SW_RESET_REG                   TAS2555_REG(0, 0, 1)
@@ -361,10 +361,10 @@ struct tas2555_priv {
        enum channel mnCurrentChannel;
        unsigned char mnLAddr;
        unsigned char mnRAddr;
-       int mnLCurrentBook;
-       int mnLCurrentPage;
-       int mnRCurrentBook;
-       int mnRCurrentPage;     
+       unsigned char mnLCurrentBook;
+       unsigned char mnLCurrentPage;
+       unsigned char mnRCurrentBook;
+       unsigned char mnRCurrentPage;   
        bool mbTILoadActive;
        int reset_gpio;
        bool mbPowerUp;
@@ -405,9 +405,6 @@ struct tas2555_priv {
        struct mutex file_lock;
 #endif 
 
-       //used for in-system tuning
-       void *chl_private_data;
-       void *chr_private_data;
 };
 
 #endif /* _TAS2555_H */
index b7cca1f5e852d66807874f57a92530ae85d6334c..e87084baab79dc19dc49fcefdbe938f5624c1f75 100755 (executable)
--- a/tiload.c
+++ b/tiload.c
@@ -22,8 +22,7 @@
 **
 ** =============================================================================
 */
-/* enable debug prints in the driver */
-#define DEBUG
+
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <asm/uaccess.h>
 
 #include "tiload.h"
-/* Function prototypes */
 
-/* externs */
-//static struct cdev *tiload_cdev;
-//static int tiload_major = 0; /* Dynamic allocation of Mjr No. */
-//static int tiload_opened = 0;        /* Dynamic allocation of Mjr No. */
+/* enable debug prints in the driver */
+#define DEBUG
+
+static struct cdev *tiload_cdev;
+static int tiload_major = 0;   /* Dynamic allocation of Mjr No. */
+static int tiload_opened = 0;  /* Dynamic allocation of Mjr No. */
 static struct tas2555_priv *g_TAS2555;
-//struct class *tiload_class;
-//static unsigned int magic_num = 0x00;
+struct class *tiload_class;
+static unsigned int magic_num = 0x00;
 
-//static char gPage = 0;
-//static char gBook = 0;
+static char gPage = 0;
+static char gBook = 0;
 /******************************** Debug section *****************************/
 
 /*
@@ -66,34 +66,15 @@ static struct tas2555_priv *g_TAS2555;
 static int tiload_open(struct inode *in, struct file *filp)
 {
        struct tas2555_priv *pTAS2555 = g_TAS2555;
-       const unsigned char *pFileName;
-       struct tiload_data *pTiLoad;
        
        dev_info(pTAS2555->dev, "%s\n", __FUNCTION__);
        
-       pFileName = filp->f_path.dentry->d_name.name;
-       if(strcmp(pFileName, CHL_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chl_private_data;
-       else if(strcmp(pFileName, CHR_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chr_private_data;
-       else{
-               dev_err(pTAS2555->dev, "channel err,dev (%s)\n", pFileName);
-               return -1;              
-       }
-       
-       if(pTiLoad == NULL)
-               return -1;
-       else{
-               if(pTiLoad->mnTiload_Opened!=0){
+       if (tiload_opened) {
                        dev_info(pTAS2555->dev, "%s device is already opened\n", "tiload");
-                       dev_info(pTAS2555->dev, "%s: only one instance of driver is allowed\n", "tiload");
-                       return -1;
-               }
+               return -1;
        }
-       
        filp->private_data = (void*)pTAS2555;
-       pTiLoad->mnTiload_Opened++;
-       
+       tiload_opened++;
        return 0;
 }
 
@@ -107,28 +88,14 @@ static int tiload_open(struct inode *in, struct file *filp)
 static int tiload_release(struct inode *in, struct file *filp)
 {
        struct tas2555_priv *pTAS2555 = (struct tas2555_priv *)filp->private_data;
-       const unsigned char *pFileName;
-       struct tiload_data *pTiLoad;
        
        dev_info(pTAS2555->dev, "%s\n", __FUNCTION__);
-       
-       pFileName = filp->f_path.dentry->d_name.name;
-       if(strcmp(pFileName, CHL_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chl_private_data;
-       else if(strcmp(pFileName, CHR_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chr_private_data;
-       else{
-               dev_err(pTAS2555->dev, "channel err,dev (%s)\n", pFileName);
-               return 0;               
-       }
-       
-       if(pTiLoad == NULL)
-               return 0;
-       
-       pTiLoad->mnTiload_Opened--;
+       filp->private_data = NULL;
+       tiload_opened--;
        return 0;
 }
 
+#define MAX_LENGTH 128
 /*
  *----------------------------------------------------------------------------
  * Function : tiload_read
@@ -140,39 +107,18 @@ static ssize_t tiload_read(struct file *filp, char __user * buf,
        size_t count, loff_t * offset)
 {
        struct tas2555_priv *pTAS2555 = (struct tas2555_priv *)filp->private_data;      
-       const unsigned char *pFileName;
-       unsigned char channel;
-       struct tiload_data *pTiLoad;
-       unsigned int nCompositeRegister = 0, Value;
+       static char rd_data[MAX_LENGTH + 1];
+       unsigned int nCompositeRegister = 0, Value = 0;
        //unsigned int n;
        char reg_addr;
        size_t size;
        int ret = 0;
-       unsigned char nBook, nPage;
 #ifdef DEBUG
-       int i;
+       //int i;
 #endif
+//    struct i2c_client *i2c = g_codec->control_data;
 
        dev_dbg(pTAS2555->dev, "%s\n", __FUNCTION__);
-       
-       pFileName = filp->f_path.dentry->d_name.name;
-       if(strcmp(pFileName, CHL_DEVICE_NAME) == 0){
-               pTiLoad = pTAS2555->chl_private_data;
-               channel = channel_left;
-       }else if(strcmp(pFileName, CHR_DEVICE_NAME) == 0){
-               pTiLoad = pTAS2555->chr_private_data;
-               channel = channel_right;
-       }else{
-               dev_err(pTAS2555->dev, "channel err,dev (%s)\n", pFileName);
-               return -1;              
-       }
-       
-       if(pTiLoad == NULL)
-               return -1;
-       
-       nBook = pTiLoad->mnBook;
-       nPage = pTiLoad->mnPage;
-       
        if (count > MAX_LENGTH) {
                dev_err(pTAS2555->dev, "Max %d bytes can be read\n", MAX_LENGTH);
                return -1;
@@ -187,17 +133,16 @@ static ssize_t tiload_read(struct file *filp, char __user * buf,
 
        size = count;
 
-       nCompositeRegister = BPR_REG(nBook, nPage, reg_addr);
+       nCompositeRegister = BPR_REG(gBook, gPage, reg_addr);
        if (count == 1) {
                ret = pTAS2555->read(pTAS2555, 
-                                       channel, 
+                                       pTAS2555->mnCurrentChannel, 
                                        0x80000000 | nCompositeRegister, &Value);
-               if (ret >= 0)
-                       pTiLoad->mpRd_data[0] = (char) Value;
+               if (ret >= 0) rd_data[0] = (char) Value;
        } else if (count > 1) {
                ret = pTAS2555->bulk_read(pTAS2555, 
-                                       channel, 
-                                       0x80000000 | nCompositeRegister, pTiLoad->mpRd_data, size);
+                                       pTAS2555->mnCurrentChannel, 
+                                       0x80000000 | nCompositeRegister, rd_data, size);
        }
        if (ret < 0)
                dev_err(pTAS2555->dev, 
@@ -208,18 +153,16 @@ static ssize_t tiload_read(struct file *filp, char __user * buf,
        dev_dbg(pTAS2555->dev, 
                "read size = %d, reg_addr= 0x%x , count = %d\n",
                (int) size, reg_addr, (int) count);
-       for (i = 0; i < (int) size; i++) {
-               dev_dbg(pTAS2555->dev, 
-                       "chl[%d] rd_data[%d]=0x%x\n", 
-                       channel,i, pTiLoad->mpRd_data[i]);
-       }
+//     for (i = 0; i < (int) size; i++) {
+//             dev_dbg(pTAS2557->dev, "rd_data[%d]=%x\n", i, rd_data[i]);
+//     }
 #endif
        if (size != count) {
                dev_err(pTAS2555->dev, 
                        "read %d registers from the codec\n", (int) size);
        }
 
-       if (copy_to_user(buf, pTiLoad->mpRd_data, size) != 0) {
+       if (copy_to_user(buf, rd_data, size) != 0) {
                dev_err(pTAS2555->dev, "copy_to_user failed\n");
                return -1;
        }
@@ -238,46 +181,27 @@ static ssize_t tiload_write(struct file *filp, const char __user * buf,
        size_t count, loff_t * offset)
 {
        struct tas2555_priv *pTAS2555 = (struct tas2555_priv *)filp->private_data;              
-       const unsigned char *pFileName;
-       unsigned char channel;
-       struct tiload_data *pTiLoad;
-       char *pData;// = wr_data;
+       static char wr_data[MAX_LENGTH + 1];
+       char *pData = wr_data;
        size_t size;
        unsigned int nCompositeRegister = 0;
+//    u8 pg_no;
+//    unsigned int n;   
        unsigned int nRegister;
        int ret = 0;
 #ifdef DEBUG
-       int i;
+       //int i;
 #endif
 
        dev_info(pTAS2555->dev, "%s\n", __FUNCTION__);
 
-       pFileName = filp->f_path.dentry->d_name.name;
-       if(strcmp(pFileName, CHL_DEVICE_NAME) == 0){
-               channel = channel_left;
-               pTiLoad = pTAS2555->chl_private_data;
-       }else if(strcmp(pFileName, CHR_DEVICE_NAME) == 0){
-               channel = channel_right;
-               pTiLoad = pTAS2555->chr_private_data;
-       }else{
-               dev_err(pTAS2555->dev, "channel err,dev (%s)\n", pFileName);
-               return -1;              
-       }
-       
-       dev_dbg(pTAS2555->dev, "file:%s, channel=%d\n", pFileName, channel);
-       
-       if(pTiLoad == NULL)
-               return -1;
-       
        if (count > MAX_LENGTH) {
                dev_err(pTAS2555->dev,"Max %d bytes can be read\n", MAX_LENGTH);
                return -1;
        }
        
-       pData = pTiLoad->mpWr_data;
-
        /* copy buffer from user space  */
-       size = copy_from_user(pTiLoad->mpWr_data, buf, count);
+       size = copy_from_user(wr_data, buf, count);
        if (size != 0) {
                dev_err(pTAS2555->dev,
                        "copy_from_user failure %d\n", (int) size);
@@ -285,33 +209,31 @@ static ssize_t tiload_write(struct file *filp, const char __user * buf,
        }
 #ifdef DEBUG
        dev_dbg(pTAS2555->dev, "write size = %zu\n", count);
-       for (i = 0; i < (int) count; i++) {
-
-               dev_dbg(pTAS2555->dev,"wr_data[%d]=%x\n", i, pTiLoad->mpWr_data[i]);
-       }
+       //for (i = 0; i < (int) count; i++) {
+       //      dev_info(pTAS2557->dev, "wr_data[%d]=%x\n", i, wr_data[i]);
+       //}
 #endif
-       nRegister = pTiLoad->mpWr_data[0];
+       nRegister = wr_data[0];
        size = count;
-       if ((nRegister == 127) && (pTiLoad->mnPage == 0)) {
-               pTiLoad->mnBook = pTiLoad->mpWr_data[1];
+       if ((nRegister == 127) && (gPage == 0)) {
+               gBook = wr_data[1];
                return size;
        }
 
        if (nRegister == 0) {
-               pTiLoad->mnPage = pTiLoad->mpWr_data[1];
-               if(count == 2) return size;
+               gPage = wr_data[1];
                pData++;
                count--;
        }
 #if 1
-       nCompositeRegister = BPR_REG(pTiLoad->mnBook, pTiLoad->mnPage, nRegister);
+       nCompositeRegister = BPR_REG(gBook, gPage, nRegister);
        if (count == 2) {
                ret = pTAS2555->write(pTAS2555, 
-                               channel, 
+                               pTAS2555->mnCurrentChannel, 
                                0x80000000 | nCompositeRegister, pData[1]);
        } else if (count > 2) {
                ret = pTAS2555->bulk_write(pTAS2555, 
-                               channel, 
+                               pTAS2555->mnCurrentChannel, 
                                0x80000000 | nCompositeRegister, &pData[1], count - 1);
        }
        if (ret < 0)
@@ -334,11 +256,11 @@ static void tiload_route_IO(struct tas2555_priv *pTAS2555,
 {
        if (bLock) {
                pTAS2555->write(pTAS2555, 
-                       channel_both
+                       pTAS2555->mnCurrentChannel
                        0xAFFEAFFE, 0xBABEBABE);
        } else {
                pTAS2555->write(pTAS2555, 
-                       channel_both
+                       pTAS2555->mnCurrentChannel
                        0xBABEBABE, 0xAFFEAFFE);
        }
 }
@@ -347,10 +269,8 @@ static long tiload_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        long num = 0;
        struct tas2555_priv *pTAS2555 = (struct tas2555_priv *)filp->private_data;      
-       const unsigned char *pFileName; 
-       struct tiload_data *pTiLoad;
-       int magic_num;
        void __user *argp = (void __user *) arg;
+       unsigned char addr = 0;
        int val;
        BPR bpr;
 
@@ -358,27 +278,14 @@ static long tiload_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 //    if (_IOC_TYPE(cmd) != TILOAD_IOC_MAGIC)
 //        return -ENOTTY;
 
-       pFileName = filp->f_path.dentry->d_name.name;
-       if(strcmp(pFileName, CHL_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chl_private_data;
-       else if(strcmp(pFileName, CHR_DEVICE_NAME) == 0)
-               pTiLoad = pTAS2555->chr_private_data;
-       else{
-               dev_err(pTAS2555->dev, "channel err,dev (%s)\n", pFileName);
-               return 0;               
-       }
-       
        switch (cmd) {
        case TILOAD_IOMAGICNUM_GET:
-               magic_num = pTiLoad->mnMagicNum;
                num = copy_to_user(argp, &magic_num, sizeof(int));
                break;
        case TILOAD_IOMAGICNUM_SET:
                num = copy_from_user(&magic_num, argp, sizeof(int));
-               if(num==0) {
-                       pTiLoad->mnMagicNum = magic_num;
+               dev_info(pTAS2555->dev, "TILOAD_IOMAGICNUM_SET\n");
                        tiload_route_IO(pTAS2555, magic_num);
-               }
                break;
        case TILOAD_BPR_READ:
                break;
@@ -388,6 +295,20 @@ static long tiload_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                        "TILOAD_BPR_WRITE: 0x%02X, 0x%02X, 0x%02X\n\r", bpr.nBook,
                        bpr.nPage, bpr.nRegister);
                break;
+       case TILOAD_IOCTL_SET_CHL:
+               num = copy_from_user(&val, argp, sizeof(int));
+               addr = (unsigned char)(val>>1);
+               if(addr == pTAS2555->mnLAddr){
+                       dev_info(pTAS2555->dev, "TILOAD_IOCTL_SET_CHL left\n");
+                       pTAS2555->mnCurrentChannel = channel_left;
+               }else if(addr == pTAS2555->mnRAddr){
+                       dev_info(pTAS2555->dev, "TILOAD_IOCTL_SET_CHL right\n");
+                       pTAS2555->mnCurrentChannel = channel_right;
+               }else{
+                       dev_err(pTAS2555->dev, "TILOAD_IOCTL_SET_CHL error L(0x%x) R(0x%x) 0x%x,\n", 
+                               pTAS2555->mnLAddr, pTAS2555->mnRAddr, addr);
+               }
+               break;          
        case TILOAD_IOCTL_SET_CONFIG:
                num = copy_from_user(&val, argp, sizeof(val));
                pTAS2555->set_config(pTAS2555, val);
@@ -419,49 +340,22 @@ static struct file_operations tiload_fops = {
  * Purpose  : Register a char driver for dynamic tiload programming
  *----------------------------------------------------------------------------
  */
-int tiload_driver_init(struct tas2555_priv *pTAS2555, unsigned char channel)
+int tiload_driver_init(struct tas2555_priv *pTAS2555)
 {
        int result;
-       int tiload_major = 0;
-       struct cdev *tiload_cdev;
-       struct class *tiload_class;
-       dev_t dev;
-       const char *pDeviceName;
-       struct tiload_data *private_data;
+
+       dev_t dev = MKDEV(tiload_major, 0);
 
        dev_info(pTAS2555->dev, "%s\n", __FUNCTION__);
-       
-       private_data = kzalloc(sizeof(struct tiload_data), GFP_KERNEL);
-       if(private_data == NULL){
-               dev_err(pTAS2555->dev, "no mem\n");
-               return -ENOMEM;
-       }
-               
-       if(channel == channel_left){
-               pDeviceName = CHL_DEVICE_NAME;
-               if(pTAS2555->chl_private_data != NULL)
-                       kfree(pTAS2555->chl_private_data);
-               pTAS2555->chl_private_data = private_data;
-       }else if(channel == channel_right){             
-               pDeviceName = CHR_DEVICE_NAME;
-               if(pTAS2555->chr_private_data != NULL)
-                       kfree(pTAS2555->chr_private_data);              
-               pTAS2555->chr_private_data = private_data;
-       }else{
-               result = -EINVAL;
-               goto err;
-       }
-       
-       dev = MKDEV(tiload_major, 0);
        g_TAS2555 = pTAS2555;
 
-       result = alloc_chrdev_region(&dev, 0, 1, pDeviceName);
+       result = alloc_chrdev_region(&dev, 0, 1, DEVICE_NAME);
        if (result < 0) {
                dev_err(pTAS2555->dev,
                        "cannot allocate major number %d\n", tiload_major);
-               goto err;
+               return result;
        }
-       tiload_class = class_create(THIS_MODULE, pDeviceName);
+       tiload_class = class_create(THIS_MODULE, DEVICE_NAME);
        tiload_major = MAJOR(dev);
        dev_info(pTAS2555->dev,
                "allocated Major Number: %d\n", tiload_major);
@@ -471,29 +365,22 @@ int tiload_driver_init(struct tas2555_priv *pTAS2555, unsigned char channel)
        tiload_cdev->owner = THIS_MODULE;
        tiload_cdev->ops = &tiload_fops;
 
-       if (device_create(tiload_class, NULL, dev, NULL, pDeviceName) == NULL){
+       if (device_create(tiload_class, NULL, dev, NULL, "tiload_node") == NULL)
                dev_err(pTAS2555->dev,
                        "Device creation failed\n");
-       }
 
        if (cdev_add(tiload_cdev, dev, 1) < 0) {
                dev_err(pTAS2555->dev,
                                "tiload_driver: cdev_add failed \n");
                unregister_chrdev_region(dev, 1);
                tiload_cdev = NULL;
-               goto err;
+               return 1;
        }
        
        dev_info(pTAS2555->dev,
                "Registered TiLoad driver, Major number: %d \n", tiload_major);
                
        return 0;
-       
-err:
-       if(private_data!=NULL)
-               kfree(private_data);
-       
-       return result;
 }
 
 MODULE_AUTHOR("Texas Instruments Inc.");
index ca628ccfe15cdfd47a458fe5de02c87fa396be98..fe03fb5bed339e32d650c7862880c4c24602b178 100755 (executable)
--- a/tiload.h
+++ b/tiload.h
@@ -28,7 +28,6 @@
 
 #include "tas2555.h"
 
-#define MAX_LENGTH 128
 
 #define BPR_REG(book, page, reg)               (((book * 256 * 128) + \
                                                 (page * 128)) + reg)
@@ -42,28 +41,18 @@ typedef struct {
        unsigned char nRegister;
 } BPR;
 
-struct tiload_data {
-       unsigned char mnBook;
-       unsigned char mnPage;
-       unsigned char mnMagicNum;
-       int mnTiload_Opened;
-       char mpRd_data[MAX_LENGTH + 1];
-       char mpWr_data[MAX_LENGTH + 1];
-} ;
-
 /* defines */
-#define CHL_DEVICE_NAME     "tiload_chl_node"
-#define CHR_DEVICE_NAME     "tiload_chr_node"
+#define DEVICE_NAME     "tiload_node"
 
 #define TILOAD_IOC_MAGIC   0xE0
 #define TILOAD_IOMAGICNUM_GET                          _IOR(TILOAD_IOC_MAGIC, 1, int)
 #define TILOAD_IOMAGICNUM_SET                          _IOW(TILOAD_IOC_MAGIC, 2, int)
 #define TILOAD_BPR_READ                                _IOR(TILOAD_IOC_MAGIC, 3, BPR)
 #define TILOAD_BPR_WRITE                               _IOW(TILOAD_IOC_MAGIC, 4, BPR)
-#define TILOAD_IOCHLNUM_SET                    _IOW(TILOAD_IOC_MAGIC, 5, int)
+#define TILOAD_IOCTL_SET_CHL                   _IOW(TILOAD_IOC_MAGIC, 5, int)
 #define TILOAD_IOCTL_SET_CONFIG                _IOW(TILOAD_IOC_MAGIC, 6, int)
 #define TILOAD_IOCTL_SET_CALIBRATION   _IOW(TILOAD_IOC_MAGIC, 7, int)
 
-int tiload_driver_init(struct tas2555_priv *pTAS2555, unsigned char channel);
+int tiload_driver_init(struct tas2555_priv *pTAS2555);
 
 #endif