Venkata Prahlad Valluru | 5c842b5 | 2018-01-03 16:10:26 +0530 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * FocalTech fts TouchScreen driver. |
| 4 | * |
| 5 | * Copyright (c) 2010-2017, Focaltech Ltd. All rights reserved. |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | /***************************************************************************** |
| 19 | * |
| 20 | * File Name: focaltech_upgrade_test.c |
| 21 | * |
| 22 | * Author: fupeipei |
| 23 | * |
| 24 | * Created: 2016-08-22 |
| 25 | * |
| 26 | * Abstract: |
| 27 | * |
| 28 | * Reference: |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | |
| 32 | /***************************************************************************** |
| 33 | * 1.Included header files |
| 34 | *****************************************************************************/ |
| 35 | #include "../focaltech_core.h" |
| 36 | #include "../focaltech_flash.h" |
Venkata Prahlad Valluru | 5c842b5 | 2018-01-03 16:10:26 +0530 | [diff] [blame] | 37 | #include <linux/timer.h> |
| 38 | |
| 39 | /***************************************************************************** |
| 40 | * Static variables |
| 41 | *****************************************************************************/ |
| 42 | #define FTS_GET_UPGRADE_TIME 0 |
| 43 | |
| 44 | /***************************************************************************** |
| 45 | * Global variable or extern global variabls/functions |
| 46 | *****************************************************************************/ |
| 47 | |
| 48 | #define FTS_DEBUG_UPGRADE(fmt, args...) do {\ |
| 49 | pr_err("[FTS][UPGRADE]:################\n");\ |
| 50 | pr_err("[FTS][UPGRADE]: "fmt"\n", ##args);\ |
| 51 | pr_err("[FTS][UPGRADE]:################\n");\ |
| 52 | } while (0)\ |
| 53 | |
| 54 | /***************************************************************************** |
| 55 | * Static function prototypes |
| 56 | *****************************************************************************/ |
| 57 | #if (FTS_UPGRADE_STRESS_TEST) |
| 58 | /************************************************************************ |
| 59 | * Name: fts_ctpm_auto_upgrade_pingpong |
| 60 | * Brief: 0 |
| 61 | * Input: 0 |
| 62 | * Output: 0 |
| 63 | * Return: 0 |
| 64 | ***********************************************************************/ |
| 65 | static int fts_ctpm_auto_upgrade_pingpong(struct i2c_client *client) |
| 66 | { |
| 67 | u8 uc_tp_fm_ver; |
| 68 | int i_ret = 0; |
| 69 | u8 uc_upgrade_times = 0; |
| 70 | |
| 71 | FTS_FUNC_ENTER(); |
| 72 | |
| 73 | /* pingpong test mode, need upgrade */ |
| 74 | FTS_INFO("[UPGRADE]: pingpong test mode, need upgrade!!"); |
| 75 | do { |
| 76 | uc_upgrade_times++; |
| 77 | |
| 78 | /* fw upgrade */ |
| 79 | i_ret = fts_ctpm_fw_upgrade(client); |
| 80 | |
| 81 | if (i_ret == 0) { |
| 82 | /* upgrade success */ |
| 83 | fts_i2c_read_reg(client, FTS_REG_FW_VER, &uc_tp_fm_ver); |
| 84 | FTS_DEBUG("[UPGRADE]: upgrade to new version 0x%x", |
| 85 | uc_tp_fm_ver); |
| 86 | } else { |
| 87 | /* upgrade fail */ |
| 88 | /* if upgrade fail, reset to run ROM. |
| 89 | * if app in flash is ok. TP will work success |
| 90 | */ |
| 91 | FTS_INFO("[UPGRADE]: upgrade fail, reset now!!"); |
| 92 | fts_ctpm_rom_or_pram_reset(client); |
| 93 | } |
| 94 | /* if upgrade fail, upgrade again. then return */ |
| 95 | } while ((i_ret != 0) && (uc_upgrade_times < 2)); |
| 96 | |
| 97 | FTS_FUNC_EXIT(); |
| 98 | return i_ret; |
| 99 | } |
| 100 | |
| 101 | /************************************************************************ |
| 102 | * Name: fts_ctpm_auto_upgrade |
| 103 | * Brief: 0 |
| 104 | * Input: 0 |
| 105 | * Output: 0 |
| 106 | * Return: 0 |
| 107 | ***********************************************************************/ |
| 108 | void fts_ctpm_display_upgrade_time(bool start_time) |
| 109 | { |
| 110 | #if FTS_GET_UPGRADE_TIME |
| 111 | static struct timeval tpend; |
| 112 | static struct timeval tpstart; |
| 113 | static int timeuse; |
| 114 | |
| 115 | if (start_time) { |
| 116 | do_gettimeofday(&tpstart); |
| 117 | } else { |
| 118 | do_gettimeofday(&tpend); |
| 119 | timeuse = 1000000 * (tpend.tv_sec-tpstart.tv_sec) |
| 120 | + tpend.tv_usec-tpstart.tv_usec; |
| 121 | timeuse /= 1000000; |
| 122 | FTS_DEBUG("[UPGRADE]: upgrade success : Use time: %d Seconds!!", |
| 123 | timeuse); |
| 124 | } |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | /************************************************************************ |
| 129 | * Name: fts_ctpm_auto_upgrade |
| 130 | * Brief: 0 |
| 131 | * Input: 0 |
| 132 | * Output: 0 |
| 133 | * Return: 0 |
| 134 | ***********************************************************************/ |
| 135 | int fts_ctpm_auto_upgrade(struct i2c_client *client) |
| 136 | { |
| 137 | int i_ret = 0; |
| 138 | static int uc_ErrorTimes; |
| 139 | static int uc_UpgradeTimes; |
| 140 | |
| 141 | |
| 142 | device_init_wakeup(&client->dev, 1); |
| 143 | pm_stay_awake(&client->dev); |
| 144 | |
| 145 | /* (FTS_GET_VENDOR_ID_NUM == 0) */ |
| 146 | g_fw_file = CTPM_FW; |
| 147 | g_fw_len = fts_getsize(FW_SIZE); |
| 148 | FTS_DEBUG("[UPGRADE]FW FILE:CTPM_FW, SIZE:%x", g_fw_len); |
| 149 | |
| 150 | do { |
| 151 | uc_UpgradeTimes++; |
| 152 | |
| 153 | FTS_DEBUG_UPGRADE("start to upgrade %d times !!", |
| 154 | uc_UpgradeTimes); |
| 155 | |
| 156 | fts_ctpm_display_upgrade_time(true); |
| 157 | |
| 158 | i_ret = fts_ctpm_auto_upgrade_pingpong(client); |
| 159 | if (i_ret == 0) |
| 160 | fts_ctpm_display_upgrade_time(false); |
| 161 | else |
| 162 | uc_ErrorTimes++; |
| 163 | |
| 164 | FTS_DEBUG_UPGRADE("upgrade %d times, error %d times!!", |
| 165 | uc_UpgradeTimes, uc_ErrorTimes); |
| 166 | } while (uc_UpgradeTimes < (FTS_UPGRADE_TEST_NUMBER)); |
| 167 | |
| 168 | pm_relax(&client->dev); |
| 169 | device_init_wakeup(&client->dev, 0); |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | #endif |
| 174 | |