| /***************************************************************************** |
| * Copyright Statement: |
| * -------------------- |
| * This software is protected by Copyright and the information contained |
| * herein is confidential. The software may not be copied and the information |
| * contained herein may not be used or disclosed except with the written |
| * permission of MediaTek Inc. (C) 2017 |
| * |
| * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| * |
| * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| * |
| * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| * |
| *****************************************************************************/ |
| |
| /******************************************************************************* |
| * |
| * Filename: |
| * --------- |
| * tia_atcmd.c |
| * |
| * Project: |
| * -------- |
| * VMOLY |
| * |
| * Description: |
| * ------------ |
| * TIA (Thermal Information Acquisition) driver - atcmd |
| * |
| * Author: |
| * ------- |
| * ------- |
| * |
| *============================================================================ |
| * HISTORY |
| * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *------------------------------------------------------------------------------ |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| *------------------------------------------------------------------------------ |
| * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *============================================================================ |
| ****************************************************************************/ |
| |
| #include "kal_public_api.h" |
| #include "drv_comm.h" |
| #include "us_timer.h" |
| #include "tia_reg.h" |
| #include "tia.h" |
| |
| static kal_timerid atcmd_tmr_id; |
| |
| static kal_bool tia_atcmd_sensor_info(kal_uint32 len, kal_uint8 *dat) |
| { |
| // B0 B1 B2 B3 description |
| // .. all |
| // .. TID TID = 0~3, 4:all |
| tia_dbg_sns_infs((len < 2)? TIA_SENSOR_NUM: dat[1]); |
| return KAL_TRUE; |
| } |
| |
| static kal_bool tia_atcmd_sensor_state(kal_uint32 len, kal_uint8 *dat) |
| { |
| // B0 B1 B2 B3 description |
| // .. all |
| // .. TID TID = 0~3, 4:all |
| tia_dbg_thr_cfgs((len < 2)? TIA_SENSOR_NUM: dat[1]); |
| return KAL_TRUE; |
| } |
| |
| static kal_bool tia_atcmd_monitor_state(kal_uint32 len, kal_uint8 *dat) |
| { |
| // B0 B1 B2 B3 description |
| // .. all |
| // .. TID TID = 0~3, 4:all |
| tia_dbg_thr_mons((len < 2)? TIA_SENSOR_NUM: dat[1]); |
| return KAL_TRUE; |
| } |
| |
| static kal_bool tia_atcmd_auxadc_efuse(void) |
| { |
| tia_adc_dbg_efuse(NULL, NULL); |
| return KAL_TRUE; |
| } |
| |
| static kal_bool tia_atcmd_fake_tmp(kal_uint32 len, kal_uint8 *dat) |
| { |
| #ifdef __MTK_INTERNAL__ |
| // B0 B1 B2 B3 B4 description |
| // .. disable |
| // .. TID XX YY ZZ enable, TID={0~3, 4:all}, 0xXXYYZZ={ohm} |
| kal_bool ret = KAL_TRUE; |
| |
| if (len < 2) { |
| tia_dbg_fake_en(KAL_FALSE); |
| } else if (len >= 5) { |
| kal_uint32 tid, val; |
| tid = dat[1]; |
| val = (dat[2] << 16) | (dat[3] << 8) | (dat[4] << 0); |
| tia_dbg_fake_ohm(tid, val); |
| tia_dbg_fake_en(KAL_TRUE); |
| } else { |
| ret = KAL_FALSE; |
| } |
| |
| return ret; |
| #else |
| return KAL_FALSE; |
| #endif |
| } |
| |
| static kal_bool tia_atcmd_set_alarm(kal_uint32 len, kal_uint8 *dat) |
| { |
| #ifdef __MTK_INTERNAL__ |
| kal_uint32 idx, cid; |
| tfwk_thermal_cfg_t cfg[4]={}; |
| |
| // B1={enable,type}, B2={sid,aid}, B3=thres(signed'C), B4=hyst('C), B5=period(ms) => loop 1~4 |
| if ((len != 1+5*1) && (len != 1+5*2) && (len != 1+5*3) && (len != 1+5*4)) { |
| return KAL_FALSE; |
| } |
| for (idx = 1, cid = 0; idx + 5 <= len; idx += 5, cid++) { |
| cfg[cid].enable = dat[idx+0] >> 4; |
| cfg[cid].sensor_alarm_type = dat[idx+0] & 0xF; |
| cfg[cid].sensor_id = dat[idx+1] >> 4; |
| cfg[cid].alarm_id = dat[idx+1] & 0xF; |
| cfg[cid].threshold_value = ((signed char) dat[idx+2]) * 10; |
| cfg[cid].hysteresis_value = dat[idx+3] * 10; |
| cfg[cid].sampling_period = dat[idx+4]; |
| } |
| tia_set_alarm(cid, cfg); |
| |
| return KAL_TRUE; |
| #else |
| return KAL_FALSE; |
| #endif |
| } |
| |
| static kal_bool tia_atcmd_set_rc(kal_uint32 len, kal_uint8 *dat) |
| { |
| #ifdef __MTK_INTERNAL__ |
| // B0 B1 B2 description |
| // .. UID RC UID={0:MD,1:GPS,2:AP,3:all}, RC={0:100K,1:30K,2:400K} |
| kal_bool ret = KAL_FALSE; |
| kal_uint32 idx, msk, val; |
| kal_uint32 adr[] = {TIA_TIA2_MD_RC_CTRL, TIA_TIA2_GPS_RC_CTRL, TIA_TIA2_AP_RC_CTRL}; |
| |
| if ((len >= 3) /*&& (dat[1] <= 3)*/ && (dat[2] <= 2)) { |
| msk = (dat[1] < 3)? (1 << dat[1]): 0x7; |
| val = TIA_TIA2_GPS_RC_CTRL_TSX_RC_SEL_GPS(dat[2])| |
| TIA_TIA2_GPS_RC_CTRL_T0_RC_SEL_GPS(dat[2]) | |
| TIA_TIA2_GPS_RC_CTRL_T1_RC_SEL_GPS(dat[2]) | |
| TIA_TIA2_GPS_RC_CTRL_T2_RC_SEL_GPS(dat[2]) | |
| TIA_TIA2_GPS_RC_CTRL_T3_RC_SEL_GPS(dat[2]); |
| for (idx = 0; idx <= 2; idx++) { |
| if (msk & (1 << idx)) { |
| DRV_WriteReg32(adr[idx], val); |
| } |
| } |
| ret = KAL_TRUE; |
| } |
| |
| return ret; |
| #else |
| return KAL_FALSE; |
| #endif |
| } |
| |
| static kal_bool tia_atcmd_all_sensor_temp(void) |
| { |
| kal_uint32 idx, us; |
| kal_int32 tmp[TIA_LVTS_GET_ALL_NUM+TIA_SENSOR_NUM] = {}; |
| |
| us = ust_get_current_time(); UNUSED_PARAMETER(us); |
| TIA_LVTS_GET_ALL_TEMP(TIA_LVTS_GET_ALL_NUM, &tmp[0]); |
| for (idx = 0; idx < TIA_SENSOR_NUM; idx++) { |
| tia_get_temp(TIA_SENSOR_SID(idx), &tmp[TIA_LVTS_GET_ALL_NUM+idx]); |
| } |
| MD_TRC(TIA_MSG_THERMAL_TMP_ALL_8, tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], us); |
| |
| return KAL_TRUE; |
| } |
| |
| static void atcmd_tmr_handler(void *param_ptr) |
| { |
| tia_atcmd_all_sensor_temp(); |
| } |
| |
| static kal_bool atcmd_tmr_enable( |
| kal_uint32 en/*0:disable,1:enable,2:toggle*/, |
| kal_uint32 ms/*0:default(1000ms),others:XXms*/) |
| { |
| static kal_bool tmr_st = KAL_FALSE; |
| kal_uint32 cfg_en = (en == 2)? (!tmr_st): en; |
| kal_uint32 cfg_ms = (ms == 0)? 1000: ms; |
| kal_uint32 tick; |
| |
| switch (cfg_en) { |
| case 0: |
| kal_cancel_timer(atcmd_tmr_id); |
| tmr_st = KAL_FALSE; |
| break; |
| case 1: |
| tick = kal_milli_secs_to_ticks(cfg_ms); |
| kal_set_timer(atcmd_tmr_id, atcmd_tmr_handler, NULL, 1, tick); |
| tmr_st = KAL_TRUE; |
| break; |
| default: |
| return KAL_FALSE; |
| } |
| return KAL_TRUE; |
| } |
| |
| static kal_bool tia_atcmd_all_sensor_temp_periodic(kal_uint32 len, kal_uint8 *dat) |
| { |
| // B0 B1 B2 B3 description |
| // .. all temperature log periodic - toggle |
| // .. 00 disable |
| // .. 01 [XX YY] enable, default: 1000 ms, others: 0xXXYY ms |
| kal_bool ret = KAL_FALSE; |
| |
| if (len == 1) { |
| ret = atcmd_tmr_enable(2, 0); |
| } else if (dat[1] == 0x00) { |
| ret = atcmd_tmr_enable(0, 0); |
| } else if (dat[1] == 0x01) { |
| if (len == 2) { |
| ret = atcmd_tmr_enable(1, 0); |
| } else if (len >= 4) { |
| kal_uint32 ms = (dat[2] << 8) + dat[3]; |
| ret = atcmd_tmr_enable(1, ms); |
| } |
| } |
| |
| return ret; |
| } |
| |
| void tia_atcmd_init(void) |
| { |
| atcmd_tmr_id = kal_create_timer("TIA_ATCMD"); |
| } |
| |
| kal_bool tia_atcmd_public(kal_uint32 data_len, kal_uint8 *data_str) |
| { |
| kal_bool ret = KAL_FALSE; |
| |
| if (data_len < 1) { |
| goto T_EXIT; |
| } |
| |
| switch (data_str[0]) { |
| // 0x2x for tia only |
| case 0x20: |
| ret = tia_atcmd_sensor_info(data_len, data_str); |
| break; |
| case 0x21: |
| ret = tia_atcmd_sensor_state(data_len, data_str); |
| break; |
| case 0x22: |
| ret = tia_atcmd_monitor_state(data_len, data_str); |
| break; |
| case 0x24: |
| ret = tia_atcmd_auxadc_efuse(); |
| break; |
| case 0x29: |
| ret = tia_atcmd_fake_tmp(data_len, data_str); |
| break; |
| case 0x2A: |
| ret = tia_atcmd_set_alarm(data_len, data_str); |
| break; |
| case 0x2C: |
| ret = tia_atcmd_set_rc(data_len, data_str); |
| break; |
| |
| // 0x3x for thermal cross modules (lvts + tia + ...) |
| case 0x30: |
| ret = tia_atcmd_all_sensor_temp(); |
| break; |
| case 0x31: |
| ret = tia_atcmd_all_sensor_temp_periodic(data_len, data_str); |
| break; |
| default: |
| break; |
| } |
| |
| T_EXIT: |
| return ret; |
| } |