(CR):[Kane]:[factory] tp:fix selftest result save to csv file process.
authorhq_qiaoquanbin_tmp <qiaoquanbin@huaqin.com>
Fri, 7 Dec 2018 10:28:06 +0000 (18:28 +0800)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:30:04 +0000 (17:30 +0800)
Change-Id: I62739af66e2f515c7d22656fa782e546c48639fc
Signed-off-by: hq_qiaoquanbin_tmp <qiaoquanbin@huaqin.com>
drivers/input/touchscreen/nt36xxx/nt36xxx_mp_ctrlram.c

index 3ec90f732798d7efb8c3609a0352ba2d1b87dcf1..481e643ffd552b24b3b06574f7d5f834fa2afde8 100755 (executable)
@@ -314,30 +314,92 @@ static int32_t nvt_save_rawdata_to_csv(int32_t *rawdata, uint8_t x_ch, uint8_t y
        int32_t x = 0;
        int32_t y = 0;
        int32_t iArrayIndex = 0;
+       struct file *fp = NULL;
+       char *fbufp = NULL;
+       mm_segment_t org_fs;
+       int32_t write_ret = 0;
+       uint32_t output_len = 0;
+       loff_t pos = 0;
 #if TOUCH_KEY_NUM > 0
        int32_t k = 0;
+       int32_t keydata_output_offset = 0;
 #endif /* #if TOUCH_KEY_NUM > 0 */
 
-       printk("%s:++%s\n", __func__, file_path);
+       printk("%s:++\n", __func__);
+       fbufp = (char *)kzalloc(8192, GFP_KERNEL);
+       if (!fbufp) {
+               NVT_ERR("kzalloc for fbufp failed!\n");
+               return -ENOMEM;
+       }
 
        for (y = 0; y < y_ch; y++) {
                for (x = 0; x < x_ch; x++) {
                        iArrayIndex = y * x_ch + x;
                        printk("%5d, ", rawdata[iArrayIndex]);
+                       sprintf(fbufp + iArrayIndex * 7 + y * 2, "%5d, ", rawdata[iArrayIndex]);
                }
                printk("\n");
+               sprintf(fbufp + (iArrayIndex + 1) * 7 + y * 2,"\r\n");
        }
 #if TOUCH_KEY_NUM > 0
+       keydata_output_offset = y_ch * x_ch * 7 + y_ch * 2;
        for (k = 0; k < Key_Channel; k++) {
                iArrayIndex = y_ch * x_ch + k;
                printk("%5d, ", rawdata[iArrayIndex]);
+               sprintf(fbufp + keydata_output_offset + k * 7, "%5d, ", rawdata[iArrayIndex]);
        }
        printk("\n");
+       sprintf(fbufp + y_ch * x_ch * 7 + y_ch * 2 + Key_Channel * 7, "\r\n");
+#endif /* #if TOUCH_KEY_NUM > 0 */
+
+       org_fs = get_fs();
+       set_fs(KERNEL_DS);
+       fp = filp_open(file_path, O_RDWR | O_CREAT, 0644);
+       if (fp == NULL || IS_ERR(fp)) {
+               NVT_ERR("open %s failed\n", file_path);
+               set_fs(org_fs);
+               if (fbufp) {
+                       kfree(fbufp);
+                       fbufp = NULL;
+               }
+               return -1;
+       }
+
+#if TOUCH_KEY_NUM > 0
+       output_len = y_ch * x_ch * 7 + y_ch * 2 + Key_Channel * 7 + 2;
+#else
+       output_len = y_ch * x_ch * 7 + y_ch * 2;
 #endif /* #if TOUCH_KEY_NUM > 0 */
+       pos = offset;
+       write_ret = vfs_write(fp, (char __user *)fbufp, output_len, &pos);
+       if (write_ret <= 0) {
+               NVT_ERR("write %s failed\n", file_path);
+               set_fs(org_fs);
+               if (fp) {
+                       filp_close(fp, NULL);
+                       fp = NULL;
+               }
+               if (fbufp) {
+                       kfree(fbufp);
+                       fbufp = NULL;
+               }
+               return -1;
+       }
+
+       set_fs(org_fs);
+       if (fp) {
+               filp_close(fp, NULL);
+               fp = NULL;
+       }
+       if (fbufp) {
+               kfree(fbufp);
+               fbufp = NULL;
+       }
 
        printk("%s:--\n", __func__);
 
        return 0;
+
 }
 
 static int32_t nvt_polling_hand_shake_status(void)