From 3b4d23e9cc0d7cd45d2db9ff00631dbeec88e0a6 Mon Sep 17 00:00:00 2001 From: Valeri Atamaniouk Date: Fri, 25 Oct 2013 06:47:17 +0300 Subject: [PATCH] apq8084: qca1530 configuration handling is added. Provide function for qca1530 detection. Rename 'get_target' to 'loc_get_target'. Fix loc_get_target state detection to avoid double detection. Fix few minor code defects. Change-Id: I3daaff99598771742572aab407475474fad41e93 --- core/ContextBase.cpp | 2 +- loc_api/libloc_api_50001/loc.cpp | 38 +++++++----- loc_api/libloc_api_50001/loc_eng.cpp | 17 ++++-- utils/loc_log.cpp | 8 +-- utils/loc_target.cpp | 88 +++++++++++++++++++++++++--- utils/loc_target.h | 7 ++- 6 files changed, 124 insertions(+), 36 deletions(-) diff --git a/core/ContextBase.cpp b/core/ContextBase.cpp index 7879015f..756983bf 100644 --- a/core/ContextBase.cpp +++ b/core/ContextBase.cpp @@ -64,7 +64,7 @@ LocApiBase* ContextBase::createLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask) LocApiBase* locApi = NULL; // first if can not be MPQ - if (TARGET_MPQ != get_target()) { + if (TARGET_MPQ != loc_get_target()) { if (NULL == (locApi = mLBSProxy->getLocApi(mMsgTask, exMask))) { // only RPC is the option now void* handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW); diff --git a/loc_api/libloc_api_50001/loc.cpp b/loc_api/libloc_api_50001/loc.cpp index 6cca8544..9ead486b 100644 --- a/loc_api/libloc_api_50001/loc.cpp +++ b/loc_api/libloc_api_50001/loc.cpp @@ -140,7 +140,7 @@ static const AGpsRilInterface sLocEngAGpsRilInterface = }; static loc_eng_data_s_type loc_afw_data; -static int gss_fd = 0; +static int gss_fd = -1; /*=========================================================================== FUNCTION gps_get_hardware_interface @@ -190,10 +190,14 @@ extern "C" const GpsInterface* get_gps_interface() unsigned int target = TARGET_DEFAULT; loc_eng_read_config(); - target = get_target(); + target = loc_get_target(); LOC_LOGD("Target name check returned %s", loc_get_target_name(target)); + + int gnssType = getTargetGnssType(target); + switch (gnssType) + { + case GNSS_GSS: //APQ8064 - if( getTargetGnssType(target) == GNSS_GSS ) { gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); gss_fd = open("/dev/gss", O_RDONLY); if (gss_fd < 0) { @@ -203,11 +207,16 @@ extern "C" const GpsInterface* get_gps_interface() LOC_LOGD("GSS open success! CAPABILITIES %0lx\n", gps_conf.CAPABILITIES); } - } - //MPQ8064 - else if( getTargetGnssType(target) == GNSS_NONE) { - LOC_LOGE("No GPS HW on this target (MPQ8064). Not returning interface"); + break; + case GNSS_NONE: + //MPQ8064 + LOC_LOGE("No GPS HW on this target. Not returning interface."); return NULL; + case GNSS_QCA1530: + // qca1530 chip is present + gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); + LOC_LOGD("qca1530 present: CAPABILITIES %0lx\n", gps_conf.CAPABILITIES); + break; } return &sLocEngInterface; } @@ -297,13 +306,14 @@ static void loc_cleanup() gps_loc_cb = NULL; gps_sv_cb = NULL; - /* - * if (get_target() == TARGET_NAME_APQ8064_STANDALONE) - * { - * close(gss_fd); - * LOC_LOGD("GSS shutdown.\n"); - * } - */ +/* + if (gss_fd >= 0) + { + close(gss_fd); + gss_fd = -1; + LOC_LOGD("GSS shutdown.\n"); + } +*/ EXIT_LOG(%s, VOID_RET); } diff --git a/loc_api/libloc_api_50001/loc_eng.cpp b/loc_api/libloc_api_50001/loc_eng.cpp index 098d403b..53e3a1f7 100644 --- a/loc_api/libloc_api_50001/loc_eng.cpp +++ b/loc_api/libloc_api_50001/loc_eng.cpp @@ -1771,11 +1771,14 @@ int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data, ENTRY_LOG_CALLFLOW(); INIT_CHECK(loc_eng_data.adapter, return -1); - // The position mode for APQ target can only be standalone - bool isAPQ = (getTargetGnssType(get_target()) == GNSS_GSS); - if (isAPQ && params.mode != LOC_POSITION_MODE_STANDALONE) { + int gnssType = getTargetGnssType(loc_get_target()); + + // The position mode for GSS/QCA1530 can only be standalone + bool is1530 = gnssType == GNSS_QCA1530; + bool isAPQ = gnssType == GNSS_GSS; + if ((isAPQ || is1530) && params.mode != LOC_POSITION_MODE_STANDALONE) { params.mode = LOC_POSITION_MODE_STANDALONE; - LOC_LOGD("Position mode changed to standalone for APQ target."); + LOC_LOGD("Position mode changed to standalone for target with GSS/qca1530."); } if(! loc_eng_data.adapter->getUlpProxy()->sendFixMode(params)) @@ -2019,8 +2022,10 @@ void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* call AGPS_TYPE_WIFI, true); - bool isAPQ = (getTargetGnssType(get_target()) == GNSS_GSS); - if (!isAPQ) { + int gnssType = getTargetGnssType(loc_get_target()); + bool isAPQ = (gnssType == GNSS_GSS); + bool is1530 = (gnssType == GNSS_QCA1530); + if (!isAPQ && !is1530) { loc_eng_data.agnss_nif = new AgpsStateMachine(servicerTypeAgps, (void *)loc_eng_data.agps_status_cb, AGPS_TYPE_SUPL, diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp index f755d70d..597b5b62 100644 --- a/utils/loc_log.cpp +++ b/utils/loc_log.cpp @@ -112,7 +112,7 @@ loc_name_val_s_type target_name[] = NAME_VAL(GNSS_MSM), NAME_VAL(GNSS_GSS), NAME_VAL(GNSS_MDM), - NAME_VAL(GNSS_GRIFFON), + NAME_VAL(GNSS_QCA1530), NAME_VAL(GNSS_UNKNOWN) }; @@ -134,18 +134,18 @@ RETURN VALUE const char *loc_get_target_name(unsigned int target) { int index = 0; - char ret[BUFFER_SIZE]; + static char ret[BUFFER_SIZE]; index = getTargetGnssType(target); if( index >= target_name_num || index < 0) index = target_name_num - 1; if( (target & HAS_SSC) == HAS_SSC ) { - sprintf(ret, " %s with SSC", + snprintf(ret, sizeof(ret), " %s with SSC", loc_get_name_from_val(target_name, target_name_num, (long)index) ); } else { - sprintf(ret, " %s without SSC", + snprintf(ret, sizeof(ret), " %s without SSC", loc_get_name_from_val(target_name, target_name_num, (long)index) ); } return ret; diff --git a/utils/loc_target.cpp b/utils/loc_target.cpp index cd781c05..a3ef6b3c 100644 --- a/utils/loc_target.cpp +++ b/utils/loc_target.cpp @@ -56,9 +56,11 @@ #define LENGTH(s) (sizeof(s) - 1) #define GPS_CHECK_NO_ERROR 0 #define GPS_CHECK_NO_GPS_HW 1 +#define QCA1530_DETECT_TIMEOUT 30 +#define QCA1530_DETECT_PRESENT "yes" +#define QCA1530_DETECT_PROGRESS "detect" -static int gss_fd = 0; -static unsigned int gTarget = TARGET_UNKNOWN; +static unsigned int gTarget = (unsigned int)-1; static int read_a_line(const char * file_path, char * line, int line_size) { @@ -82,22 +84,85 @@ static int read_a_line(const char * file_path, char * line, int line_size) return result; } -unsigned int get_target(void) +/*! + * \brief Checks if QCA1530 is avalable. + * + * Function verifies if qca1530 SoC is configured on the device. The test is + * based on property value. For 1530 scenario, the value shall be one of the + * following: "yes", "no", "detect". All other values are treated equally to + * "no". When the value is "detect" the system waits for SoC detection to + * finish before returning result. + * + * \retval true - QCA1530 is available. + * \retval false - QCA1530 is not available. + */ +static bool is_qca1530(void) { - if (gTarget != TARGET_UNKNOWN) + static const char qca1530_property_name[] = "persist.qca1530"; + bool res = false; + int ret, i; + char buf[PROPERTY_VALUE_MAX]; + + memset(buf, 0, sizeof(buf)); + + for (i = 0; i < QCA1530_DETECT_TIMEOUT; ++i) + { + ret = property_get(qca1530_property_name, buf, NULL); + if (ret < 0) + { + LOC_LOGV( "qca1530: property %s is not accessible, ret=%d", + qca1530_property_name, + ret); + + break; + } + + LOC_LOGV( "qca1530: property %s is set to %s", + qca1530_property_name, + buf); + + if (!memcmp(buf, QCA1530_DETECT_PRESENT, + sizeof(QCA1530_DETECT_PRESENT))) + { + res = true; + break; + } + if (!memcmp(buf, QCA1530_DETECT_PROGRESS, + sizeof(QCA1530_DETECT_PROGRESS))) + { + LOC_LOGV("qca1530: SoC detection is in progress."); + sleep(1); + continue; + } + break; + } + + LOC_LOGD("qca1530: detected=%s", res ? "true" : "false"); + return res; +} + +unsigned int loc_get_target(void) +{ + if (gTarget != (unsigned int)-1) return gTarget; - char hw_platform[] = "/sys/devices/soc0/hw_platform"; - char id[] = "/sys/devices/soc0/soc_id"; - char hw_platform_dep[] = "/sys/devices/system/soc/soc0/hw_platform"; - char id_dep[] = "/sys/devices/system/soc/soc0/id"; - char mdm[] = "/dev/mdm"; // No such file or directory + static const char hw_platform[] = "/sys/devices/soc0/hw_platform"; + static const char id[] = "/sys/devices/soc0/soc_id"; + static const char hw_platform_dep[] = + "/sys/devices/system/soc/soc0/hw_platform"; + static const char id_dep[] = "/sys/devices/system/soc/soc0/id"; + static const char mdm[] = "/dev/mdm"; // No such file or directory char rd_hw_platform[LINE_LEN]; char rd_id[LINE_LEN]; char rd_mdm[LINE_LEN]; char baseband[LINE_LEN]; + if (is_qca1530()) { + gTarget = TARGET_QCA1530; + goto detected; + } + property_get("ro.baseband", baseband, ""); if (!access(hw_platform, F_OK)) { read_a_line(hw_platform, rd_hw_platform, LINE_LEN); @@ -133,6 +198,11 @@ unsigned int get_target(void) (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) gTarget = TARGET_MSM_NO_SSC; + else + gTarget = TARGET_UNKNOWN; } + +detected: + LOC_LOGD("HAL: %s returned %d", __FUNCTION__, gTarget); return gTarget; } diff --git a/utils/loc_target.h b/utils/loc_target.h index be68f928..4aebb851 100644 --- a/utils/loc_target.h +++ b/utils/loc_target.h @@ -34,6 +34,7 @@ #define TARGET_APQ_SA TARGET_SET(GNSS_GSS, NO_SSC) #define TARGET_MPQ TARGET_SET(GNSS_NONE,NO_SSC) #define TARGET_MSM_NO_SSC TARGET_SET(GNSS_MSM, NO_SSC) +#define TARGET_QCA1530 TARGET_SET(GNSS_QCA1530, NO_SSC) #define TARGET_UNKNOWN TARGET_SET(GNSS_UNKNOWN, NO_SSC) #define getTargetGnssType(target) (target>>1) @@ -42,14 +43,16 @@ extern "C" { #endif -unsigned int get_target(void); +unsigned int loc_get_target(void); +/* Please remember to update 'target_name' in loc_log.cpp, + if do any changes to this enum. */ typedef enum { GNSS_NONE = 0, GNSS_MSM, GNSS_GSS, GNSS_MDM, - GNSS_GRIFFON, + GNSS_QCA1530, GNSS_UNKNOWN }GNSS_TARGET;