rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | |
| 2 | #include "loader.h" |
| 3 | #include "loader_pwr.h" |
| 4 | //#include <syslog.h> |
| 5 | #include <private/android_filesystem_config.h> |
| 6 | #include <utils/Log.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | #ifdef LOG_TAG |
| 10 | #undef LOG_TAG |
| 11 | #endif |
| 12 | #define LOG_TAG "wmt_loader" |
| 13 | |
| 14 | #define WCN_COMBO_LOADER_CHIP_ID_PROP "persist.mtk.wcn.combo.chipid" |
| 15 | #define WCN_DRIVER_READY_PROP "service.wcn.driver.ready" |
| 16 | #define WCN_COMBO_LOADER_DEV "/dev/wmtdetect" |
| 17 | #define WCN_COMBO_DEF_CHIPID "0x6582" |
| 18 | #define WMT_MODULES_PRE "/system/lib/modules/" |
| 19 | #define WMT_MODULES_SUFF ".ko" |
| 20 | #define WMT_IOC_MAGIC 'w' |
| 21 | #define COMBO_IOCTL_GET_CHIP_ID _IOR(WMT_IOC_MAGIC, 0, int) |
| 22 | #define COMBO_IOCTL_SET_CHIP_ID _IOW(WMT_IOC_MAGIC, 1, int) |
| 23 | #define COMBO_IOCTL_EXT_CHIP_DETECT _IOR(WMT_IOC_MAGIC, 2, int) |
| 24 | #define COMBO_IOCTL_GET_SOC_CHIP_ID _IOR(WMT_IOC_MAGIC, 3, int) |
| 25 | #define COMBO_IOCTL_DO_MODULE_INIT _IOR(WMT_IOC_MAGIC, 4, int) |
| 26 | #define COMBO_IOCTL_MODULE_CLEANUP _IOR(WMT_IOC_MAGIC, 5, int) |
| 27 | #define COMBO_IOCTL_EXT_CHIP_PWR_ON _IOR(WMT_IOC_MAGIC, 6, int) |
| 28 | #define COMBO_IOCTL_EXT_CHIP_PWR_OFF _IOR(WMT_IOC_MAGIC, 7, int) |
| 29 | #define COMBO_IOCTL_DO_SDIO_AUDOK _IOR(WMT_IOC_MAGIC, 8, int) |
| 30 | |
| 31 | |
| 32 | |
| 33 | #define STP_WMT_MODULE_PRE_FIX "mtk_stp_wmt" |
| 34 | #define STP_BT_MODULE_PRE_FIX "mtk_stp_bt" |
| 35 | #define STP_GPS_MODULE_PRE_FIX "mtk_stp_gps" |
| 36 | #define HIF_SDIO_MODULE_PRE_FIX "mtk_hif_sdio" |
| 37 | #define STP_SDIO_MODULE_PRE_FIX "mtk_stp_sdio" |
| 38 | #define STP_UART_MODULE_PRE_FIX "mtk_stp_uart" |
| 39 | |
| 40 | |
| 41 | |
| 42 | static int gLoaderFd = -1; |
| 43 | |
| 44 | static char DRIVER_MODULE_PATH[64] = {0}; |
| 45 | static char DRIVER_MODULE_ARG[8] = ""; |
| 46 | static int chipid_array[] = { |
| 47 | 0x6620, |
| 48 | 0x6628, |
| 49 | 0x6630, |
| 50 | 0x6572, |
| 51 | 0x6582, |
| 52 | 0x6592, |
| 53 | 0x8127, |
| 54 | 0x6571, |
| 55 | 0x6752, |
| 56 | 0x6735, |
| 57 | 0x0321, |
| 58 | 0x0335, |
| 59 | 0x0337, |
| 60 | 0x8163, |
| 61 | 0x6580, |
| 62 | 0x6755, |
| 63 | 0x0326, |
| 64 | 0x6797, |
| 65 | 0x0279 |
| 66 | }; |
| 67 | static char chip_version[PROPERTY_VALUE_MAX] = {0}; |
| 68 | |
| 69 | static int g_remove_ko_flag = 1; |
| 70 | |
| 71 | |
| 72 | extern int init_module(void *, unsigned long, const char *); |
| 73 | extern int delete_module(const char *, unsigned int); |
| 74 | extern int load_fm_module(int chip_id); |
| 75 | extern int load_wifi_module(int chip_id); |
| 76 | extern int load_ant_module(int chip_id); |
| 77 | //insmod |
| 78 | static int insmod(const char *filename, const char *args) |
| 79 | { |
| 80 | void *module; |
| 81 | unsigned int size; |
| 82 | int ret = -1; |
| 83 | int retry = 10; |
| 84 | |
| 85 | ALOGI("filename(%s)\n",filename); |
| 86 | |
| 87 | module = load_file(filename, &size); |
| 88 | if (!module) |
| 89 | { |
| 90 | ALOGI("load file fail\n"); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | while(retry-- > 0){ |
| 95 | ret = init_module(module, size, args); |
| 96 | |
| 97 | if(ret < 0) |
| 98 | { |
| 99 | ALOGI("insmod module fail(%d)\n",ret); |
| 100 | usleep(30000); |
| 101 | } |
| 102 | else |
| 103 | break; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | free(module); |
| 108 | |
| 109 | return ret; |
| 110 | } |
| 111 | static int is_chipId_vaild(int chipid) |
| 112 | { |
| 113 | int iret; |
| 114 | unsigned char i; |
| 115 | iret = -1; |
| 116 | |
| 117 | for(i = 0;i < sizeof(chipid_array)/sizeof(0x6630); i++){ |
| 118 | if(chipid == chipid_array[i]){ |
| 119 | ALOGI("is_chipId_vaild: %d :0x%x!\n",i,chipid); |
| 120 | iret = 0; |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | return iret; |
| 125 | } |
| 126 | static int rmmod(const char *modname) |
| 127 | { |
| 128 | int ret = -1; |
| 129 | int maxtry = 10; |
| 130 | |
| 131 | while (maxtry-- > 0) { |
| 132 | ret = delete_module(modname, O_EXCL);//O_NONBLOCK | O_EXCL); |
| 133 | if (ret < 0 && errno == EAGAIN) |
| 134 | usleep(500000); |
| 135 | else |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | if (ret != 0) |
| 140 | ALOGI("Unable to unload driver module \"%s\": %s,ret(%d)\n", |
| 141 | modname, strerror(errno),ret); |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static int insmod_by_path (char *nameBuf, char * modulePath, char *preFix, char *postFix ) |
| 146 | { |
| 147 | int iRet = -1; |
| 148 | int len = 0; |
| 149 | int path_len = 0; |
| 150 | |
| 151 | /*no need to check, upper layer API will makesure this condition fullfill*/ |
| 152 | strcat (nameBuf, modulePath); |
| 153 | strcat (nameBuf, preFix); |
| 154 | strcat (nameBuf, postFix); |
| 155 | strcat (nameBuf, WMT_MODULES_SUFF); |
| 156 | |
| 157 | insmod_retry: |
| 158 | iRet = insmod(nameBuf, DRIVER_MODULE_ARG); |
| 159 | if(iRet) |
| 160 | { |
| 161 | ALOGI("insert <%s> failed, len(%d), iret(%d), retrying\n", nameBuf, sizeof(nameBuf), iRet); |
| 162 | /*break;*/ |
| 163 | usleep(800000); |
| 164 | goto insmod_retry; |
| 165 | }else |
| 166 | { |
| 167 | ALOGI("insert <%s> succeed,len(%d)\n", nameBuf, len); |
| 168 | iRet = 0; |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | static int insert_wmt_module_for_soc(int chipid, char *modulePath, char *nameBuf, int nameBufLen) |
| 175 | { |
| 176 | int iRet = -1; |
| 177 | int len = 0; |
| 178 | int path_len = 0; |
| 179 | int i = 0; |
| 180 | char postFixStr[10] = {0}; |
| 181 | int totalLen = 0; |
| 182 | char *soc_modulse[] = { |
| 183 | STP_WMT_MODULE_PRE_FIX, |
| 184 | STP_BT_MODULE_PRE_FIX, |
| 185 | STP_GPS_MODULE_PRE_FIX, |
| 186 | }; |
| 187 | |
| 188 | #if 0 |
| 189 | path_len = strlen(modulePath); |
| 190 | strncpy(nameBuf, modulePath,path_len); |
| 191 | ALOGI("module subpath1(%s),sublen1(%d)\n",nameBuf,path_len); |
| 192 | len = path_len; |
| 193 | #endif |
| 194 | |
| 195 | sprintf(postFixStr, "_%s", "soc"); |
| 196 | |
| 197 | #if 0 |
| 198 | switch (chipid) |
| 199 | { |
| 200 | case 0x6572: |
| 201 | case 0x6582: |
| 202 | strcpy(postFixStr, "_6582"); |
| 203 | break; |
| 204 | case 0x6571: |
| 205 | strcpy(postFixStr, "_6592"); |
| 206 | case 0x6592: |
| 207 | strcpy(postFixStr, "_6592"); |
| 208 | break; |
| 209 | default: |
| 210 | |
| 211 | break; |
| 212 | } |
| 213 | #endif |
| 214 | |
| 215 | if (NULL == modulePath || NULL == nameBuf || 0 >= nameBufLen) |
| 216 | { |
| 217 | ALOGI("invalid parameter:modulePath(%p), nameBuf(%p), nameBufLen(%d)\n", modulePath, nameBuf, nameBufLen); |
| 218 | return iRet; |
| 219 | } |
| 220 | |
| 221 | for(i = 0;i < sizeof(soc_modulse)/sizeof(soc_modulse[0]);i++) |
| 222 | { |
| 223 | totalLen = sizeof (modulePath) + sizeof (soc_modulse[i]) + sizeof(postFixStr) + sizeof(WMT_MODULES_SUFF); |
| 224 | if (nameBufLen > totalLen) |
| 225 | { |
| 226 | |
| 227 | memset (nameBuf, 0, nameBufLen); |
| 228 | insmod_by_path(nameBuf, modulePath, soc_modulse[i], postFixStr); |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | ALOGI("nameBuf length(%d) too short, (%d) needed\n", nameBufLen, totalLen); |
| 233 | } |
| 234 | #if 0 |
| 235 | len = path_len; |
| 236 | len += sprintf(nameBuf + len,"%s",soc_modulse[i]); |
| 237 | ALOGI("module subpath2(%s),sublen2(%d)\n",nameBuf,len); |
| 238 | |
| 239 | len += sprintf(nameBuf + len,"%s", postFixStr); |
| 240 | ALOGI("module subpath3(%s),sublen3(%d)\n",nameBuf,len); |
| 241 | |
| 242 | len += sprintf(nameBuf + len,"%s",WMT_MODULES_SUFF); |
| 243 | ALOGI("module subpath4(%s),sublen4(%d)\n",nameBuf,len); |
| 244 | |
| 245 | nameBuf[len] = '\0'; |
| 246 | ALOGI("module subpath5(%s),sublen5(%d)\n",nameBuf,len); |
| 247 | |
| 248 | soc_retry: |
| 249 | iRet = insmod(nameBuf, DRIVER_MODULE_ARG); |
| 250 | if(iRet) |
| 251 | { |
| 252 | ALOGI("(%d):current modules(%s) insert fail,len(%d),iret(%d), retrying\n", i, nameBuf, len, iRet); |
| 253 | /*break;*/ |
| 254 | usleep(300000); |
| 255 | goto soc_retry; |
| 256 | }else |
| 257 | { |
| 258 | ALOGI("(%d):current modules(%s) insert ok,len(%d)\n", i, nameBuf, len); |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | } |
| 263 | |
| 264 | |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int insert_wmt_module_for_combo(int chipid, char *modulePath, char *nameBuf, int nameBufLen) |
| 270 | { |
| 271 | int iRet = -1; |
| 272 | int len = 0; |
| 273 | int path_len = 0; |
| 274 | int i = 0; |
| 275 | char postFixStr[10] = {0}; |
| 276 | int totalLen = 0; |
| 277 | |
| 278 | char *combo_modulse[] = { |
| 279 | HIF_SDIO_MODULE_PRE_FIX, |
| 280 | STP_WMT_MODULE_PRE_FIX, |
| 281 | STP_UART_MODULE_PRE_FIX, |
| 282 | STP_SDIO_MODULE_PRE_FIX, |
| 283 | STP_BT_MODULE_PRE_FIX, |
| 284 | STP_GPS_MODULE_PRE_FIX |
| 285 | }; |
| 286 | |
| 287 | if (NULL == modulePath || NULL == nameBuf || 0 >= nameBufLen) |
| 288 | { |
| 289 | ALOGI("invalid parameter:modulePath(%p), nameBuf(%p), nameBufLen(%d)\n", modulePath, nameBuf, nameBufLen); |
| 290 | return iRet; |
| 291 | } |
| 292 | |
| 293 | #if 0 |
| 294 | path_len = strlen(modulePath); |
| 295 | strncpy(nameBuf, modulePath,path_len); |
| 296 | ALOGI("module subpath1(%s),sublen1(%d)\n",nameBuf,path_len); |
| 297 | |
| 298 | len = path_len; |
| 299 | #endif |
| 300 | |
| 301 | switch (chipid) |
| 302 | { |
| 303 | case 0x6620: |
| 304 | case 0x6628: |
| 305 | /*strcpy(postFixStr, "_6620_28");*/ |
| 306 | strcpy(postFixStr, ""); |
| 307 | break; |
| 308 | case 0x6630: |
| 309 | //strcpy(postFixStr, "_6630"); |
| 310 | strcpy(postFixStr, ""); |
| 311 | break; |
| 312 | default: |
| 313 | |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | for(i = 0;i < sizeof(combo_modulse)/sizeof(combo_modulse[0]);i++) |
| 318 | { |
| 319 | totalLen = sizeof (modulePath) + sizeof (combo_modulse[i]) + sizeof(postFixStr) + sizeof(WMT_MODULES_SUFF); |
| 320 | if (nameBufLen > totalLen) |
| 321 | { |
| 322 | memset (nameBuf, 0, nameBufLen); |
| 323 | insmod_by_path(nameBuf, modulePath, combo_modulse[i], postFixStr); |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | ALOGI("nameBuf length(%d) too short, (%d) needed\n", nameBufLen, totalLen); |
| 328 | } |
| 329 | #if 0 |
| 330 | len = path_len; |
| 331 | len += sprintf(nameBuf + len,"%s",combo_modulse[i]); |
| 332 | ALOGI("module subpath2(%s),sublen2(%d)\n",nameBuf,len); |
| 333 | |
| 334 | len += sprintf(nameBuf + len,"%s",postFixStr); |
| 335 | ALOGI("module subpath3(%s),sublen3(%d)\n",nameBuf,len); |
| 336 | |
| 337 | len += sprintf(nameBuf + len,"%s",WMT_MODULES_SUFF); |
| 338 | ALOGI("module subpath4(%s),sublen4(%d)\n",nameBuf,len); |
| 339 | |
| 340 | nameBuf[len] = '\0'; |
| 341 | ALOGI("module subpath5(%s),sublen5(%d)\n",nameBuf,len); |
| 342 | |
| 343 | combo_retry: |
| 344 | iRet = insmod(nameBuf, DRIVER_MODULE_ARG); |
| 345 | if(iRet) |
| 346 | { |
| 347 | ALOGI("(%d):current modules(%s) insert fail,len(%d),iret(%d), retrying\n", i, nameBuf, len, iRet); |
| 348 | /*break;*/ |
| 349 | usleep(300000); |
| 350 | goto combo_retry; |
| 351 | }else |
| 352 | { |
| 353 | ALOGI("(%d):current modules(%s) insert ok,len(%d)\n",i, nameBuf, len); |
| 354 | } |
| 355 | #endif |
| 356 | } |
| 357 | |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | |
| 364 | /****************************************************** |
| 365 | arg1: |
| 366 | = 0:there is already a valid chipid in peroperty or there is no external combo chip |
| 367 | chipid is just MT6582 |
| 368 | > 0:there is no valid chipid in peroperty, boot system firstly |
| 369 | |
| 370 | arg2: // handle combo chip (there is an external combo chip) |
| 371 | = 0:insert mtk_hif_sdio.ko for detech combo chipid |
| 372 | > 0:insert combo modules except mtk_hif_sdio.ko |
| 373 | ******************************************************/ |
| 374 | |
| 375 | static int insert_wmt_modules(int chipid,int arg1,int arg2) |
| 376 | { |
| 377 | int iRet = -1; |
| 378 | |
| 379 | switch (chipid) |
| 380 | { |
| 381 | case 0x6582: |
| 382 | case 0x6572: |
| 383 | case 0x6571: |
| 384 | case 0x6592: |
| 385 | case 0x8127: |
| 386 | case 0x6752: |
| 387 | case 0x6735: |
| 388 | case 0x8163: |
| 389 | case 0x6580: |
| 390 | case 0x6755: |
| 391 | case 0x6797: |
| 392 | iRet = insert_wmt_module_for_soc(chipid, WMT_MODULES_PRE, DRIVER_MODULE_PATH, sizeof (DRIVER_MODULE_PATH)); |
| 393 | break; |
| 394 | case 0x6620: |
| 395 | case 0x6628: |
| 396 | case 0x6630: |
| 397 | iRet = insert_wmt_module_for_combo(chipid, WMT_MODULES_PRE, DRIVER_MODULE_PATH, sizeof (DRIVER_MODULE_PATH)); |
| 398 | break; |
| 399 | default: |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | return iRet; |
| 404 | } |
| 405 | |
| 406 | int do_kernel_module_init(int gLoaderFd, int chipId) |
| 407 | { |
| 408 | int iRet = 0; |
| 409 | if (gLoaderFd < 0) |
| 410 | { |
| 411 | ALOGI("invalid gLoaderFd: %d\n", gLoaderFd); |
| 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | iRet = ioctl (gLoaderFd, COMBO_IOCTL_MODULE_CLEANUP, chipId); |
| 416 | if (iRet) |
| 417 | { |
| 418 | ALOGI("do WMT-DETECT module cleanup failed: %d\n", iRet); |
| 419 | return -2; |
| 420 | } |
| 421 | iRet = ioctl (gLoaderFd, COMBO_IOCTL_DO_MODULE_INIT, chipId); |
| 422 | if (iRet) |
| 423 | { |
| 424 | ALOGI("do kernel module init failed: %d\n", iRet); |
| 425 | return -3; |
| 426 | } |
| 427 | ALOGI("do kernel module init succeed: %d\n", iRet); |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | int main(int argc, char *argv[]) |
| 433 | { |
| 434 | int iRet = -1; |
| 435 | int noextChip = -1; |
| 436 | int chipId = -1; |
| 437 | int count = 0; |
| 438 | char chipidStr[PROPERTY_VALUE_MAX] = {0}; |
| 439 | char readyStr[PROPERTY_VALUE_MAX] = {0}; |
| 440 | int loadFmResult = -1; |
| 441 | int loadAntResult = -1; |
| 442 | int loadWlanResult = -1; |
| 443 | int retryCounter = 1; |
| 444 | int autokRet = 0; |
| 445 | do{ |
| 446 | gLoaderFd = open(WCN_COMBO_LOADER_DEV, O_RDWR | O_NOCTTY); |
| 447 | if(gLoaderFd < 0) |
| 448 | { |
| 449 | count ++; |
| 450 | ALOGI("Can't open device node(%s) count(%d)\n", WCN_COMBO_LOADER_DEV,count); |
| 451 | usleep(300000); |
| 452 | } |
| 453 | else |
| 454 | break; |
| 455 | }while(1); |
| 456 | |
| 457 | //read from system property |
| 458 | iRet = property_get(WCN_COMBO_LOADER_CHIP_ID_PROP, chipidStr, NULL); |
| 459 | chipId = strtoul(chipidStr, NULL, 16); |
| 460 | |
| 461 | if ((0 != iRet) && (-1 != is_chipId_vaild(chipId))) |
| 462 | { |
| 463 | /*valid chipid detected*/ |
| 464 | ALOGI("key:(%s)-value:(%s),chipId:0x%04x,iRet(%d)\n", WCN_COMBO_LOADER_CHIP_ID_PROP, chipidStr, chipId,iRet); |
| 465 | if (0x6630 == chipId) |
| 466 | { |
| 467 | retryCounter = 10; |
| 468 | /*trigger autok process, incase last autok process is interrupted by abnormal power off or battery down*/ |
| 469 | do { |
| 470 | /*power on combo chip*/ |
| 471 | iRet = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_PWR_ON); |
| 472 | if (0 != iRet) |
| 473 | { |
| 474 | ALOGI("external combo chip power on failed\n"); |
| 475 | noextChip = 1; |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | /*detect is there is an external combo chip*/ |
| 480 | noextChip = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_DETECT,NULL); |
| 481 | } |
| 482 | |
| 483 | if(noextChip) |
| 484 | { |
| 485 | // do nothing |
| 486 | ALOGI("no external combo chip detected\n"); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | ALOGI("external combo chip detected\n"); |
| 491 | |
| 492 | chipId = ioctl(gLoaderFd, COMBO_IOCTL_GET_CHIP_ID, NULL); |
| 493 | ALOGI("chipid (0x%x) detected\n", chipId); |
| 494 | } |
| 495 | |
| 496 | |
| 497 | if(0 == noextChip) |
| 498 | { |
| 499 | autokRet = ioctl(gLoaderFd,COMBO_IOCTL_DO_SDIO_AUDOK,chipId); |
| 500 | if (0 != autokRet) |
| 501 | { |
| 502 | ALOGI("do SDIO3.0 autok failed\n"); |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | ALOGI("do SDIO3.0 autok succeed\n"); |
| 507 | } |
| 508 | } |
| 509 | iRet = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_PWR_OFF); |
| 510 | if (0 != iRet) |
| 511 | { |
| 512 | ALOGI("external combo chip power off failed\n"); |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | ALOGI("external combo chip power off succeed\n"); |
| 517 | } |
| 518 | if ((0 == noextChip) && (-1 == chipId)) |
| 519 | { |
| 520 | /*extenral chip detected, but no valid chipId detected, retry*/ |
| 521 | retryCounter--; |
| 522 | ALOGI("chipId detect failed, retrying, left retryCounter:%d\n", retryCounter); |
| 523 | usleep(500000); |
| 524 | } |
| 525 | else |
| 526 | break; |
| 527 | }while (0 < retryCounter); |
| 528 | chipId = 0x6630; |
| 529 | } |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | /*trigger external combo chip detect and chip identification process*/ |
| 534 | do { |
| 535 | /*power on combo chip*/ |
| 536 | iRet = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_PWR_ON); |
| 537 | if (0 != iRet) |
| 538 | { |
| 539 | ALOGI("external combo chip power on failed\n"); |
| 540 | noextChip = 1; |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | /*detect is there is an external combo chip*/ |
| 545 | noextChip = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_DETECT,NULL); |
| 546 | } |
| 547 | |
| 548 | if(noextChip)// use soc itself |
| 549 | { |
| 550 | ALOGI("no external combo chip detected, get current soc chipid\n"); |
| 551 | chipId = ioctl(gLoaderFd, COMBO_IOCTL_GET_SOC_CHIP_ID, NULL); |
| 552 | ALOGI("soc chipid (0x%x) detected\n", chipId); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | ALOGI("external combo chip detected\n"); |
| 557 | |
| 558 | chipId = ioctl(gLoaderFd, COMBO_IOCTL_GET_CHIP_ID, NULL); |
| 559 | ALOGI("chipid (0x%x) detected\n", chipId); |
| 560 | } |
| 561 | |
| 562 | sprintf (chipidStr, "0x%04x", chipId); |
| 563 | iRet = property_set(WCN_COMBO_LOADER_CHIP_ID_PROP,chipidStr); |
| 564 | if (0 != iRet) |
| 565 | { |
| 566 | ALOGI("set property(%s) to %s failed,iRet:%d, errno:%d\n", WCN_COMBO_LOADER_CHIP_ID_PROP, chipidStr, iRet, errno); |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | ALOGI("set property(%s) to %s succeed.\n", WCN_COMBO_LOADER_CHIP_ID_PROP, chipidStr); |
| 571 | } |
| 572 | if(0 == noextChip) |
| 573 | { |
| 574 | autokRet = ioctl(gLoaderFd,COMBO_IOCTL_DO_SDIO_AUDOK,chipId); |
| 575 | if (0 != autokRet) |
| 576 | { |
| 577 | ALOGI("do SDIO3.0 autok failed\n"); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | ALOGI("do SDIO3.0 autok succeed\n"); |
| 582 | } |
| 583 | } |
| 584 | iRet = ioctl(gLoaderFd,COMBO_IOCTL_EXT_CHIP_PWR_OFF); |
| 585 | if (0 != iRet) |
| 586 | { |
| 587 | ALOGI("external combo chip power off failed\n"); |
| 588 | } |
| 589 | else |
| 590 | { |
| 591 | ALOGI("external combo chip power off succeed\n"); |
| 592 | } |
| 593 | if ((0 == noextChip) && (-1 == chipId)) |
| 594 | { |
| 595 | /*extenral chip detected, but no valid chipId detected, retry*/ |
| 596 | retryCounter--; |
| 597 | usleep(500000); |
| 598 | ALOGI("chipId detect failed, retrying, left retryCounter:%d\n", retryCounter); |
| 599 | } |
| 600 | else |
| 601 | break; |
| 602 | }while (0 < retryCounter); |
| 603 | } |
| 604 | |
| 605 | /*set chipid to kernel*/ |
| 606 | ioctl(gLoaderFd,COMBO_IOCTL_SET_CHIP_ID,chipId); |
| 607 | |
| 608 | if (g_remove_ko_flag) |
| 609 | { |
| 610 | if((0x0321 == chipId) || (0x0335 == chipId) || (0x0337 == chipId)) |
| 611 | { |
| 612 | chipId = 0x6735; |
| 613 | } |
| 614 | if (0x0326 == chipId) { |
| 615 | chipId = 0x6755; |
| 616 | } |
| 617 | if (0x0279 == chipId) { |
| 618 | chipId = 0x6797; |
| 619 | } |
| 620 | do_kernel_module_init(gLoaderFd, chipId); |
| 621 | if(gLoaderFd >= 0) |
| 622 | { |
| 623 | close(gLoaderFd); |
| 624 | gLoaderFd = -1; |
| 625 | } |
| 626 | |
| 627 | } |
| 628 | else |
| 629 | { |
| 630 | if(gLoaderFd >= 0) |
| 631 | { |
| 632 | close(gLoaderFd); |
| 633 | gLoaderFd = -1; |
| 634 | } |
| 635 | ALOGI("rmmod mtk_wmt_detect\n"); |
| 636 | rmmod("mtk_wmt_detect"); |
| 637 | |
| 638 | /*INSERT TARGET MODULE TO KERNEL*/ |
| 639 | |
| 640 | iRet = insert_wmt_modules(chipId, 0, -1); |
| 641 | /*this process should never fail*/ |
| 642 | if(iRet) |
| 643 | { |
| 644 | ALOGI("insert wmt modules fail(%d):(%d)\n",iRet,__LINE__); |
| 645 | /*goto done;*/ |
| 646 | } |
| 647 | |
| 648 | |
| 649 | loadFmResult = load_fm_module(chipId); |
| 650 | if(loadFmResult) |
| 651 | { |
| 652 | ALOGI("load FM modules fail(%d):(%d)\n",iRet,__LINE__); |
| 653 | /*continue, we cannot let this process interrupted by subsystem module load fail*/ |
| 654 | /*goto done;*/ |
| 655 | } |
| 656 | |
| 657 | loadAntResult = load_ant_module(chipId); |
| 658 | if(loadAntResult) |
| 659 | { |
| 660 | ALOGI("load ANT modules fail(%d):(%d)\n",iRet,__LINE__); |
| 661 | /*continue, we cannot let this process interrupted by subsystem module load fail*/ |
| 662 | /*goto done;*/ |
| 663 | } |
| 664 | |
| 665 | loadWlanResult = load_wifi_module(chipId); |
| 666 | if(loadWlanResult) |
| 667 | { |
| 668 | ALOGI("load WIFI modules fail(%d):(%d)\n",iRet,__LINE__); |
| 669 | /*continue, we cannot let this process interrupted by subsystem module load fail*/ |
| 670 | /*goto done;*/ |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | |
| 675 | |
| 676 | if((chown("/proc/driver/wmt_dbg",AID_SHELL,AID_SYSTEM) == -1) || (chown("/proc/driver/wmt_aee",AID_SHELL,AID_SYSTEM) == -1)) |
| 677 | { |
| 678 | ALOGI("chown wmt_dbg or wmt_aee fail:%s\n",strerror(errno)); |
| 679 | } |
| 680 | |
| 681 | if(chown("/proc/wmt_tm/wmt_tm",0,1000) == -1) |
| 682 | { |
| 683 | ALOGI("chown wmt_tm fail:%s\n",strerror(errno)); |
| 684 | } |
| 685 | if (0/*0x6630 == chipId*/) |
| 686 | { |
| 687 | retryCounter = 0; |
| 688 | int i_ret = -1; |
| 689 | do { |
| 690 | i_ret = loader_wmt_pwr_ctrl(1); |
| 691 | if (0 == i_ret) |
| 692 | break; |
| 693 | else |
| 694 | { |
| 695 | loader_wmt_pwr_ctrl(0); |
| 696 | ALOGI("power on %x failed, retrying, retry counter:%d\n", chipId, retryCounter); |
| 697 | usleep(1000000); |
| 698 | } |
| 699 | retryCounter++; |
| 700 | } while (retryCounter < 20); |
| 701 | } |
| 702 | iRet = property_get(WCN_DRIVER_READY_PROP, readyStr, NULL); |
| 703 | if ((0 >= iRet) || (0 == strcmp(readyStr, "yes"))) { |
| 704 | ALOGI("get property(%s) failed iRet:%d or property is %s\n", WCN_DRIVER_READY_PROP, iRet, readyStr); |
| 705 | } |
| 706 | /*set it to yes anyway*/ |
| 707 | sprintf(readyStr, "%s", "yes"); |
| 708 | iRet = property_set(WCN_DRIVER_READY_PROP, readyStr); |
| 709 | if (0 != iRet) { |
| 710 | ALOGI("set property(%s) to %s failed iRet:%d\n", WCN_DRIVER_READY_PROP, readyStr, iRet); |
| 711 | } else { |
| 712 | ALOGI("set property(%s) to %s succeed\n", WCN_DRIVER_READY_PROP, readyStr); |
| 713 | } |
| 714 | #if 0 |
| 715 | while (loadWlanResult || loadFmResult) |
| 716 | { |
| 717 | if(loadFmResult) |
| 718 | { |
| 719 | static int retryCounter = 0; |
| 720 | retryCounter++; |
| 721 | ALOGI("retry loading fm module, retryCounter:%d\n", retryCounter); |
| 722 | loadFmResult = load_fm_module(chipId); |
| 723 | } |
| 724 | |
| 725 | if(loadWlanResult) |
| 726 | { |
| 727 | static int retryCounter = 0; |
| 728 | retryCounter++; |
| 729 | ALOGI("retry loading wlan module, retryCounter:%d\n", retryCounter); |
| 730 | loadWlanResult = load_wifi_module(chipId); |
| 731 | } |
| 732 | usleep(1000000); |
| 733 | } |
| 734 | #endif |
| 735 | |
| 736 | return iRet; |
| 737 | } |
| 738 | |
| 739 | |
| 740 | |