blob: 753f17f9108ab5e48976b3ab672d19187f08b83d [file] [log] [blame]
wangyouqiangce12f2b2024-04-23 17:57:09 +08001#if 1
2#include <fcntl.h>
3#include <stdint.h>
4#include <libubox/blobmsg_json.h>
5#include <libubus.h>
liuyangcdf88992024-07-05 11:48:24 +08006#include <stdlib.h>
7#include <unistd.h>
8#include <errno.h>
9#include <sys/socket.h>
10#include <sys/un.h>
11#include <netinet/in.h>
12#include <pthread.h>
13#include <sys/epoll.h>
wangyouqiangce12f2b2024-04-23 17:57:09 +080014
15#include "mbtk_power.h"
16/****************************DEFINE***************************************/
17#define MBTK_POWER_RESULT_FAIL -1
18#define MBTK_POWER_RESULT_SUCCESS 0
19
20
21#define MBTK_POWER_CLOSE_FAIL -1
22#define MBTK_POWER_CLOSE_SUCCESS 0
23
liuyangcdf88992024-07-05 11:48:24 +080024#define GNSS_SOCK_PATH "/tmp/mbtk_gnss_sock"
25
26static int sock_listen_fd = -1;
27
28typedef enum {
29 GNSS_CMD_INIT = 0,
30 GNSS_CMD_DEINIT,
31 GNSS_CMD_SETTING,
32 GNSS_CMD_DL
33} gnss_cmd_enum;
34
35
wangyouqiangce12f2b2024-04-23 17:57:09 +080036/****************************DEFINE***************************************/
37
38/****************************VARIABLE***************************************/
39const struct blobmsg_policy mbtk_power_cb_policy1[] = {
40 [0] = {
41 .name = "event",
42 .type = BLOBMSG_TYPE_INT32,
43 },
44};
45/****************************VARIABLE***************************************/
46
47/****************************FUNC***************************************/
48static void mbtk_power_gnss_callback(struct ubus_request *req, int type, struct blob_attr *msg)
49{
50 UNUSED(type);
51
52 struct blob_attr *tb[1];
53 struct blob_attr *cur;
54 unsigned int event;
55 int *ubus_gnss_result = (int *)req->priv;
56 int rc;
57
58 /*parsing blob to be accessed easily with tb array - parse "1" argument*/
59 rc = blobmsg_parse(mbtk_power_cb_policy1, 1, tb, blob_data(msg), blob_len(msg));
60 if (rc < 0)
61 {
62 LOGE("[MBTK_POWER] blobmsg_parse fail.");
63 //printf("blobmsg_parse fail\n");
64 *ubus_gnss_result = MBTK_POWER_CLOSE_FAIL;
65 return;
66 }
67
68 /*parse first parameter*/
69 cur = tb[0];
70 if (!cur)
71 {
72 LOGE("[MBTK_POWER] missing parameter.");
73 //printf("missing parameter\n");
74 *ubus_gnss_result = MBTK_POWER_CLOSE_FAIL;
75 return;
76 }
77
78 event = blobmsg_get_u32(cur);
79 LOGE("[MBTK_POWER] get event = [%d].", event);
80 //printf("get event = [%d].\n", event);
81
r.xiaod888d2b2024-07-03 20:39:42 -070082#if 1
yq.wang0ff0ca22024-06-29 02:38:27 -070083 if(event != 0)
yq.wanga40216c2024-06-24 01:38:32 -070084#else
wangyouqiangce12f2b2024-04-23 17:57:09 +080085 if(event != 7)
yq.wanga40216c2024-06-24 01:38:32 -070086#endif
wangyouqiangce12f2b2024-04-23 17:57:09 +080087 {
88 *ubus_gnss_result = MBTK_POWER_CLOSE_FAIL;
89 }
90
91 return ;
92}
93
94static int mbtk_power_ubus_uloop_init(struct ubus_context **ctx)
95{
96 int ret = -1;
97 if(ctx == NULL)
98 {
99 LOGE("[MBTK_POWER] ctx is NULL");
100 return MBTK_POWER_RESULT_FAIL;
101 }
102
103 ret = uloop_init();
104 if(ret != 0)
105 {
106 LOGE("[MBTK_POWER] uloop_init fail.ret = [%d]", ret);
107 return MBTK_POWER_RESULT_FAIL;
108 }
109
110 if(*ctx != NULL)
111 {
112 LOGE("[MBTK_POWER] mbtk_gnss_ctx not NULL.");
113 return MBTK_POWER_RESULT_FAIL;
114 }
115
116 *ctx = ubus_connect(NULL);
117 if( !(*ctx) )
118 {
119 LOGE("[MBTK_POWER] ubus_connect fail.");
120 return MBTK_POWER_RESULT_FAIL;
121 }
122
123 ubus_add_uloop(*ctx);
124
125 return MBTK_POWER_RESULT_SUCCESS;
126}
127
128static int mbtk_power_ubus_uloop_deinit(struct ubus_context *ctx)
129{
130 if(ctx != NULL)
131 {
132 ubus_free(ctx);
133 ctx = NULL;
134 }
135
136 uloop_done();
137
138 return MBTK_POWER_RESULT_SUCCESS;
139}
140
141static int mbtk_power_invoke_reply_data_cb(const char *service, const char *method, struct blob_attr *msg,
142 ubus_data_handler_t cb, void *cb_param, int timeout, struct ubus_context *ctx)
143{
144 int rc = -1;
145 uint32_t id;
146 struct ubus_request req;
147
148 /* Look up the target object id by the object path */
149 rc = ubus_lookup_id(ctx, service, &id);
150 if(rc)
151 {
152 LOGE("[MBTK_POWER] ubus_lookup_id fail.rc = [%d]", rc);
153 return MBTK_POWER_RESULT_FAIL;
154 }
155
156 rc = ubus_invoke(ctx, id, method, msg, cb, cb_param, timeout);
157 if(rc)
158 {
159 LOGE("[MBTK_POWER] ubus_invoke fail.rc = [%d]", rc);
160 return MBTK_POWER_RESULT_FAIL;
161 }
162 return MBTK_POWER_RESULT_SUCCESS;
163}
164
r.xiao1258eba2024-08-16 22:47:25 -0700165 //mbtk wyq for AT+MGPSC add start
166
167#if 0//#ifndef MBTK_GNSS_FACTORY_TEST_MODE
168 if(strncasecmp((char const *)line, "AT+MGPSC=", strlen("AT+MGPSC=")) == 0)
169 {
170 int mode,ret = 0;
171 (void)sscanf((const char *)line, "%*[^0-9]%d", &mode);
172 if(mode == 1 || mode == 5)
173 {
174 if(modem_if.echo_mode == MODEM_ECHO_MODE)
175 {
176 writen(ppp_uart2_fd, line, 10);
177 }
178
179 ret = mbtk_GPS_process(GNSS_CMD_INIT, &mode);
180
181 if(-1 == ret)
182 {
183 const char RESP_BUFF[] = "\r\n+GPS: gps server timeout.\r\n\r\nERROR\r\n";
184 writen(ppp_uart2_fd, RESP_BUFF, sizeof(RESP_BUFF) - 1);
185 }
186 else
187 {
188 const char RESP_BUFF[] = "\r\n+GPS: gps init success\r\n";
189 writen(ppp_uart2_fd, RESP_BUFF, sizeof(RESP_BUFF) - 1);
190 }
191 continue;
192 }
193 }
194#endif
195 //mbtk wyq for AT+MGPSC add end
196
liuyangcdf88992024-07-05 11:48:24 +0800197 static int mbtk_GPS_process(gnss_cmd_enum cmd, void *arg)
198 {
199 if(sock_listen_fd < 0) {
200 sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
201 if(sock_listen_fd < 0)
202 {
r.xiao663d7ce2024-08-02 01:01:06 -0700203 LOGE("[MBTK_POWER]socket() fail[%d].", errno);
liuyangcdf88992024-07-05 11:48:24 +0800204 return -1;
205 }
206
207 struct sockaddr_un cli_addr;
208 memset(&cli_addr, 0, sizeof(cli_addr));
209 cli_addr.sun_family = AF_LOCAL;
210 strcpy(cli_addr.sun_path, GNSS_SOCK_PATH);
211 if(connect(sock_listen_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
212 {
r.xiao663d7ce2024-08-02 01:01:06 -0700213 LOGE("[MBTK_POWER]connect() fail[%d].", errno);
liuyangcdf88992024-07-05 11:48:24 +0800214 close(sock_listen_fd);
215 sock_listen_fd = -1;
216 return -1;
217 }
218 }
r.xiao1258eba2024-08-16 22:47:25 -0700219
liuyangcdf88992024-07-05 11:48:24 +0800220 char buff[100] = {0};
221 if(cmd == GNSS_CMD_INIT) {
222 if(arg) {
223 sprintf(buff, "gnss_init:%d", *(int*)arg);
224 } else {
225 return -1;
226 }
227 } else if(cmd == GNSS_CMD_DEINIT) {
228 sprintf(buff, "gnss_deinit");
229 } else if(cmd == GNSS_CMD_SETTING) {
230 sprintf(buff, "gnss_setting:%s", arg);
231 } else if(cmd == GNSS_CMD_DL) {
232 sprintf(buff, "gnss_dl:%s", arg);
233 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700234 LOGE("[MBTK_POWER]Unknown cmd.");
liuyangcdf88992024-07-05 11:48:24 +0800235 return -1;
236 }
237
238 write(sock_listen_fd, buff, strlen(buff));
239
240 int len = 0;
241 while(1) {
242 memset(buff, 0, sizeof(buff));
243 len = read(sock_listen_fd, buff, sizeof(buff));
244 if(len > 0) {
r.xiao663d7ce2024-08-02 01:01:06 -0700245 LOGE("[MBTK_POWER]RSP : %s", buff);
liuyangcdf88992024-07-05 11:48:24 +0800246 if(cmd == GNSS_CMD_INIT) {
r.xiao663d7ce2024-08-02 01:01:06 -0700247 if(strstr(buff, "gnss_init") != 0) {
248 return 0;
liuyangcdf88992024-07-05 11:48:24 +0800249 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700250 LOGE("[MBTK_POWER]gnss_init response error.");
liuyangcdf88992024-07-05 11:48:24 +0800251 return -1;
252 }
253 } else if(cmd == GNSS_CMD_DEINIT) {
r.xiao663d7ce2024-08-02 01:01:06 -0700254 if(strstr(buff, "gnss_deinit") != 0) {
255 return 0;
liuyangcdf88992024-07-05 11:48:24 +0800256 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700257 LOGE("[MBTK_POWER]gnss_deinit response error.");
liuyangcdf88992024-07-05 11:48:24 +0800258 return -1;
259 }
260 } else if(cmd == GNSS_CMD_SETTING) {
r.xiao663d7ce2024-08-02 01:01:06 -0700261 if(strstr(buff, "gnss_setting") != 0) {
262 return 0;
liuyangcdf88992024-07-05 11:48:24 +0800263 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700264 LOGE("[MBTK_POWER]gnss_setting response error.");
liuyangcdf88992024-07-05 11:48:24 +0800265 return -1;
266 }
267 } else if(cmd == GNSS_CMD_DL) {
r.xiao663d7ce2024-08-02 01:01:06 -0700268 if(strstr(buff, "gnss_dl") != 0) {
269 return 0;
liuyangcdf88992024-07-05 11:48:24 +0800270 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700271 LOGE("[MBTK_POWER]gnss_dl response error.");
liuyangcdf88992024-07-05 11:48:24 +0800272 return -1;
273 }
274 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700275 LOGE("[MBTK_POWER]Unknown response.\n");
liuyangcdf88992024-07-05 11:48:24 +0800276 return -1;
277 }
278 } else if(len == 0) {
r.xiao663d7ce2024-08-02 01:01:06 -0700279 LOGE("[MBTK_POWER]RSP is null.");
liuyangcdf88992024-07-05 11:48:24 +0800280 return -1;
281 } else {
r.xiao663d7ce2024-08-02 01:01:06 -0700282 LOGE("[MBTK_POWER]read = %d:errno = %d", len, errno);
liuyangcdf88992024-07-05 11:48:24 +0800283 }
284 }
285 }
286
287
r.xiao1258eba2024-08-16 22:47:25 -0700288 int mbtk_mgpsc_set(int arg)
289 {
290 int ret = 0;
291 int *p = 3;
292
293 if (arg == 1)
294 {
295 ret = mbtk_GPS_process(GNSS_CMD_INIT, &p);
296
297 if (-1 == ret)
298 {
299 LOGE("[MBTK_POWER] mbtk_mgpsc_set fail.");
300 return -1;
301 }
302 }
303 else
304 {
305 ret = mbtk_GPS_process(GNSS_CMD_DEINIT, NULL);
306
307 if (-1 == ret)
308 {
309 LOGE("[MBTK_POWER] mbtk_mgpsc_set fail.");
310 return -1;
311 }
312 }
313
314 return 0;
315 }
316
317
wangyouqiangce12f2b2024-04-23 17:57:09 +0800318
319static int mbtk_power_gnss_close(void)
320{
321 int ret = 0;
liuyangcdf88992024-07-05 11:48:24 +0800322
323 ret = mbtk_GPS_process(GNSS_CMD_DEINIT, NULL);
324
325 if (-1 == ret)
wangyouqiangce12f2b2024-04-23 17:57:09 +0800326 {
liuyangcdf88992024-07-05 11:48:24 +0800327 LOGE("[MBTK_POWER] mbtk_power_gnss_close fail.");
wangyouqiangce12f2b2024-04-23 17:57:09 +0800328 return MBTK_POWER_CLOSE_FAIL;
329 }
330
wangyouqiangce12f2b2024-04-23 17:57:09 +0800331 return MBTK_POWER_CLOSE_SUCCESS;
332}
333
334static int gpio_direct_set(char *value,int gpio)
335{
336 char buffer[50]= {0};
337 int file =-1;
338 int result =-1;
339
340 memset(buffer,0,50);
341 sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
342 file = open(buffer, O_WRONLY);
343 if(file == -1)
344 {
345 LOGE("[MBTK_POWER] Open gpio[%d] direct fail.", gpio);
346 return MBTK_POWER_RESULT_FAIL;
347 }
348
349 result = write(file,value,strlen(value));
350 if(result != strlen(value))
351 {
352 LOGE("[MBTK_POWER] Set gpio[%d] direct fail.", gpio);
353 close(file);
354 return MBTK_POWER_RESULT_FAIL;
355 }
356 close(file);
357
358 return MBTK_POWER_RESULT_SUCCESS;
359}
360
361static int gpio_value_set(int value, int gpio)
362{
363 char buffer[50]= {0};
364 int file =-1;
365 int result =-1;
366
367 memset(buffer,0,50);
368 sprintf(buffer,"/sys/class/gpio/gpio%d/value", gpio);
369 file = open(buffer,O_WRONLY);
370 if(file == -1)
371 {
372 LOGE("[MBTK_POWER] Open gpio[%d] value fail.", gpio);
373 return MBTK_POWER_RESULT_FAIL;
374 }
375 if(value == 0) {
376 result = write(file,"0",1);
377 } else {
378 result = write(file,"1",1);
379 }
380 if(result != 1)
381 {
382 LOGE("[MBTK_POWER] Set gpio[%d] value fail.", gpio);
383 close(file);
384 return MBTK_POWER_RESULT_FAIL;
385 }
386 close(file);
387
388 return MBTK_POWER_RESULT_SUCCESS;
389}
390
391//type:0 value 0
392//type:1 value 1
393//type:2 direction "out"
394//type:3 direction "in"
395
396static int one_gpio_export(int gpio, int type)
397{
398 int index=0;
399 int file=-1;
400 int file1=-1;
401 int result =-1;
402 char pin_index_buffer[5]= {0};
403 char buffer[50]= {0};
404 int ret =0;
405
406 file = open("/sys/class/gpio/export",O_WRONLY);
407 if(file == -1)
408 {
409 LOGE("[MBTK_POWER] Open gpio export file fail.");
410 return MBTK_POWER_RESULT_FAIL;
411 }
412
413 memset(buffer,0,50);
414 sprintf(buffer,"/sys/class/gpio/gpio%d", gpio);
415 file1 = open(buffer,O_RDONLY);
416 if(file1 != -1)
417 {
418 //file is created
419 close(file1);
420 }
421 else
422 { // create gpio
423 memset(pin_index_buffer,0,5);
424 sprintf(pin_index_buffer,"%d",gpio);
425 result = write(file,pin_index_buffer,strlen(pin_index_buffer));
426 if(result < 0)
427 {
428 LOGE("[MBTK_POWER] Gpio[%d] export fail.", gpio);
429 return MBTK_POWER_RESULT_FAIL;
430 }
431 }
432
433 close(file);
434
435
436 switch(type)
437 {
438 case 0 :
439 {
440 ret = gpio_value_set(0, gpio);
441 break;
442 }
443 case 1:
444 {
445 ret = gpio_value_set(1, gpio);
446 break;
447 }
448 case 2:
449 {
450 ret = gpio_direct_set("out", gpio);
451 break;
452 }
453 case 3:
454 {
455 ret = gpio_direct_set("in", gpio);
456 break;
457 }
458 default:
459 {
460 break;
461 }
462 }
463
464
465 return ret;
466}
467
468/****************************FUNC***************************************/
469
470/****************************API***************************************/
471#if defined(MBTK_PROJECT_T108)
472int mbtk_system_sleep(void)
473{
474 int ubus_ret = 0;
475
476 ubus_ret = mbtk_power_gnss_close();
477 if(ubus_ret < 0)
478 {
479 LOGE("[MBTK_POWER] mbtk_power_gnss_close() fail.");
480 return MBTK_POWER_RESULT_GNSS_CLOSE_FAIL;
481 }
482
483 // echo off > /sys/devices/mbtk-dev-op.10/gps_power && echo mem > /sys/power/autosleep
484 // echo 1 > /sys/devices/asr-rfkill.0/pwr_ctrl && sleep 2 && echo 0 > /sys/devices/asr-rfkill.0/pwr_ctrl
485
486 if(!access("/sys/power/autosleep", W_OK))
487 {
488 system("echo mem > /sys/power/autosleep");
489 }
490 else
491 {
492 LOGE("[MBTK_POWER] /sys/power/autosleep can not write.");
493 //printf("/sys/power/autosleep can not write.");
494 return MBTK_POWER_RESULT_NO_SLEEP_NODE;
495 }
496
497 return MBTK_POWER_RESULT_SUCCESS;
498}
499
500#elif defined(MBTK_PROJECT_L508_X6)
501int mbtk_system_sleep(void)
502{
503 int ubus_ret = 0;
504
505 ubus_ret = mbtk_power_gnss_close();
506 if(ubus_ret < 0)
507 {
508 LOGE("[MBTK_POWER] mbtk_power_gnss_close() fail.");
509 return MBTK_POWER_RESULT_GNSS_CLOSE_FAIL;
510 }
511
512 // echo off > /sys/devices/mbtk-dev-op.10/gps_power && echo mem > /sys/power/autosleep
513 // echo 1 > /sys/devices/asr-rfkill.0/pwr_ctrl && sleep 2 && echo 0 > /sys/devices/asr-rfkill.0/pwr_ctrl
514 //close Ldo6
515 system("i2cset -y -f 2 0x31 0x18 0x0f");
516 //GPS_WAKE_HOST to GPIO
517 system("hwacc w 0xd401e198 0x1040");
518 //HOST_WAKE_GPS to GPIO
519 //system("hwacc w 0xd401e0c0 0x1040");
520 //gpio34 to GPIO
521#if 1
522 system("hwacc w 0xd401e164 0x1040");
523 system("hwacc w 0xd401e166 0x1040");
524 system("hwacc w 0xd401e1b4 0x1040");
525
526 system("hwacc w 0xd401e2ec 0xa441");
527 system("hwacc w 0xd401e2f0 0xa441");
528 system("hwacc w 0xd401e2f4 0xa441");
529 system("hwacc w 0xd401e2f8 0xa441");
530 system("hwacc w 0xd401e2fc 0xa441");
531 system("hwacc w 0xd401e300 0xa441");
532#endif
533 one_gpio_export(117, 2);
534 one_gpio_export(117, 0);
535
536 one_gpio_export(119, 2);
537 one_gpio_export(119, 0);
538
539 one_gpio_export(127, 2);
540 one_gpio_export(127, 0);
541
542 one_gpio_export(33, 2);
543 one_gpio_export(33, 0);
544
545 one_gpio_export(34, 2);
546 one_gpio_export(34, 0);
547
548 one_gpio_export(54, 2);
549 one_gpio_export(54, 0);
550
551 one_gpio_export(21, 2);
552 one_gpio_export(21, 0);
553
554 one_gpio_export(118, 2);
555 one_gpio_export(118, 0);
556
557 if(!access("/sys/power/autosleep", W_OK))
558 {
559 system("echo mem > /sys/power/autosleep");
560 }
561 else
562 {
563 LOGE("[MBTK_POWER] /sys/power/autosleep can not write.");
564 //printf("/sys/power/autosleep can not write.");
565 return MBTK_POWER_RESULT_NO_SLEEP_NODE;
566 }
567
568 return MBTK_POWER_RESULT_SUCCESS;
569}
570
571#elif defined(MBTK_PROJECT_L509)
572int mbtk_system_sleep(void)
573{
574 int ubus_ret = 0;
575
576 ubus_ret = mbtk_power_gnss_close();
577 if(ubus_ret < 0)
578 {
579 LOGE("[MBTK_POWER] mbtk_power_gnss_close() fail.");
580 return MBTK_POWER_RESULT_GNSS_CLOSE_FAIL;
581 }
582
583 // echo off > /sys/devices/mbtk-dev-op.10/gps_power && echo mem > /sys/power/autosleep
584 // echo 1 > /sys/devices/asr-rfkill.0/pwr_ctrl && sleep 2 && echo 0 > /sys/devices/asr-rfkill.0/pwr_ctrl
585
586 one_gpio_export(120, 2);
587 one_gpio_export(120, 0);
588
589 one_gpio_export(21, 2);
590 one_gpio_export(21, 0);
591
592 one_gpio_export(118, 2);
593 one_gpio_export(118, 0);
594
595 if(!access("/sys/power/autosleep", W_OK))
596 {
597 system("echo mem > /sys/power/autosleep");
598 }
599 else
600 {
601 LOGE("[MBTK_POWER] /sys/power/autosleep can not write.");
602 //printf("/sys/power/autosleep can not write.");
603 return MBTK_POWER_RESULT_NO_SLEEP_NODE;
604 }
605
606 return MBTK_POWER_RESULT_SUCCESS;
607}
608
609#elif defined(MBTK_PROJECT_L508)
610int mbtk_system_sleep(void)
611{
612 int ubus_ret = 0;
613
614 ubus_ret = mbtk_power_gnss_close();
615 if(ubus_ret < 0)
616 {
617 LOGE("[MBTK_POWER] mbtk_power_gnss_close() fail.");
618 return MBTK_POWER_RESULT_GNSS_CLOSE_FAIL;
619 }
620
621 // echo off > /sys/devices/mbtk-dev-op.10/gps_power && echo mem > /sys/power/autosleep
622 // echo 1 > /sys/devices/asr-rfkill.0/pwr_ctrl && sleep 2 && echo 0 > /sys/devices/asr-rfkill.0/pwr_ctrl
623
624 one_gpio_export(119, 2);
625 one_gpio_export(119, 0);
626
627 one_gpio_export(21, 2);
628 one_gpio_export(21, 0);
629
630 one_gpio_export(118, 2);
631 one_gpio_export(118, 0);
632
633 if(!access("/sys/power/autosleep", W_OK))
634 {
635 system("echo mem > /sys/power/autosleep");
636 }
637 else
638 {
639 LOGE("[MBTK_POWER] /sys/power/autosleep can not write.");
640 //printf("/sys/power/autosleep can not write.");
641 return MBTK_POWER_RESULT_NO_SLEEP_NODE;
642 }
643
644 return MBTK_POWER_RESULT_SUCCESS;
645}
646
647#elif defined(MBTK_PROJECT_PN1803)
648int mbtk_system_sleep(void)
649{
650 int ubus_ret = 0;
651
652 ubus_ret = mbtk_power_gnss_close();
653 if(ubus_ret < 0)
654 {
655 LOGE("[MBTK_POWER] mbtk_power_gnss_close() fail.");
656 return MBTK_POWER_RESULT_GNSS_CLOSE_FAIL;
657 }
658
659 // echo off > /sys/devices/mbtk-dev-op.10/gps_power && echo mem > /sys/power/autosleep
660 // echo 1 > /sys/devices/asr-rfkill.0/pwr_ctrl && sleep 2 && echo 0 > /sys/devices/asr-rfkill.0/pwr_ctrl
661
662 one_gpio_export(119, 2);
663 one_gpio_export(119, 0);
664
665 one_gpio_export(21, 2);
666 one_gpio_export(21, 0);
667
668 one_gpio_export(118, 2);
669 one_gpio_export(118, 0);
670
671 if(!access("/sys/power/autosleep", W_OK))
672 {
673 system("echo mem > /sys/power/autosleep");
674 }
675 else
676 {
677 LOGE("[MBTK_POWER] /sys/power/autosleep can not write.");
678 //printf("/sys/power/autosleep can not write.");
679 return MBTK_POWER_RESULT_NO_SLEEP_NODE;
680 }
681
682 return MBTK_POWER_RESULT_SUCCESS;
683}
684
685#else
686int mbtk_system_sleep(void)
687{
688 return MBTK_POWER_RESULT_SUCCESS;
689}
690#endif
691/****************************API***************************************/
692#endif