blob: 90a52e272c71a4d8441eda5507f7895aff1e48ad [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*********************************************************************
2 Copyright 2016 by ZIXC Corporation.
3*
4* FileName:: zx234290.c
5* File Mark:
6* Description:
7* Others:
8* Version:
9* Author:
10* Date:
11
12* History 1:
13* Date:
14* Version:
15* Author:
16* Modification:
17* History 2:
18**********************************************************************/
19
20#include <common.h>
21#include <errno.h>
22#include <command.h>
23#include <malloc.h>
24#include <asm/io.h>
25#include <boot_mode.h>
26#include <i2c.h>
27#include <drvs_gpio.h>
28#include <power.h>
29#include <zx234290.h>
30#include <zx234502.h>
xf.libdd93d52023-05-12 07:10:14 -070031#include <watchdog.h>
lh9ed821d2023-04-07 01:36:19 -070032
33int zx234290_write_flag(UINT8 val);
34
35#define PIN_PSHOLD_NUM GPIO24
36#define GPIO_PSHOLD_FUNC_SEL GPIO24_GPIO24
37
38static boot_reason_t s_boot_reason = UNKNOWN_BOOT_REASON;
39
40/*******************************************************************************
41 * Function: zx234290_i2c_read_reg
42 * Description:
43 * Parameters:
44 * Input:
45 *
46 * Output:
47 *
48 * Returns:
49 *
50 *
51 * Others:
52 ********************************************************************************/
53int zx234290_i2c_read_reg(ushort reg, uchar *val)
54{
55 return i2c_read(0, ZX234290_I2C_SLAVE_ADDR, reg, 8, val, 1);
56}
57
58/*******************************************************************************
59 * Function: zx234290_i2c_write_reg
60 * Description:
61 * Parameters:
62 * Input:
63 *
64 * Output:
65 *
66 * Returns:
67 *
68 *
69 * Others:
70 ********************************************************************************/
71int zx234290_i2c_write_reg(ushort reg, uchar *val)
72{
73 return i2c_write(0, ZX234290_I2C_SLAVE_ADDR, reg, 8, val, 1);
74}
75
76int zx234290_reset_flag(void)
77{
78#if 0
79 int ret = 0;
80 int val = 0;
81
82 /*
83 int val = 0xff;
84 ret = zx234290_i2c_write_reg(0x0f,&val);
85 */
86 ret = zx234290_i2c_read_reg(BUCK_MODE_CONTROL0, &val);
87 val &= (~0x30);
88 ret += zx234290_i2c_write_reg(BUCK_MODE_CONTROL0, &val);
89
90 return ret;
91#else
92 return zx234290_write_flag(ZX234290_USER_RST_UNDEFINE);
93#endif
94}
95
96int zx234290_write_flag(UINT8 val)
97{
98#if 0
99 int ret = 0;
100 int tmp = 0;
101
102 if(val > 3)
103 {
104 return -1;
105 }
106 ret = zx234290_i2c_read_reg(BUCK_MODE_CONTROL0, &tmp);
107 tmp &= (~0x30);
108 tmp |= (val<<4);
109 ret += zx234290_i2c_write_reg(BUCK_MODE_CONTROL0, &tmp);
110
111 return ret;
112#else
113 int ret = 0;
114 uchar tmp = 0;
115
116 /*
117 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_USER_RESERVED, &tmp);
118 tmp &= ~(0x03<<2);
119 tmp |= (val<<2);
120 */
121 tmp = val;
122 ret |= zx234290_i2c_write_reg(ZX234290_REG_USER, &tmp);
123
124 return ret;
125#endif
126}
127
128/*******************************************************************************
129 * Function: zx234290_get_boot_reason
130 * Description:
131 * Parameters:
132 * Input:
133 *
134 * Output:
135 *
136 * Returns:
137 *
138 *
139 * Others:
140 ********************************************************************************/
141int zx234290_get_boot_reason(boot_reason_t *boot_reason)
142{
143 if (boot_reason == NULL)
144 {
145 return -1;
146 }
147
148 if(s_boot_reason == UNKNOWN_BOOT_REASON)
149 {
150 return -EIO;
151 }
152 *boot_reason = s_boot_reason;
153
154 return 0;
155}
156
157/*******************************************************************************
158 * Function: zx234290_get_boot_reason
159 * Description:
160 * Parameters:
161 * Input:
162 *
163 * Output:
164 *
165 * Returns:
166 *
167 *
168 * Others:
169 ********************************************************************************/
170static int zx234290_get_boot_reason_prev(void)
171{
172 int ret = 0;
173 uchar reg_user = ZX234290_USER_RST_UNDEFINE;
174 uchar reg_start = 0;
175 uchar reg_write = 0;
176
177 /* ¶Á²¢ÇåSTART_UP_STATUS */
178 ret = zx234290_i2c_read_reg(START_UP_STATUS, &reg_start);
179 if( ret != 0 )
180 {
181 return -EIO;
182 }
183 printf( " [%s][START_UP_STATUS = 0x%X] ...\n", __FUNCTION__, reg_start);
xf.libdd93d52023-05-12 07:10:14 -0700184 (*(volatile unsigned long *)(START_UP_STATUS_BASE))=reg_start;
lh9ed821d2023-04-07 01:36:19 -0700185
186 /* ¶Á²¢ÇåZX234290_REG_USER */
187 ret = zx234290_i2c_read_reg(ZX234290_REG_USER, &reg_user);
188 if(reg_user != ZX234290_USER_RST_UNDEFINE)
189 {
190 reg_write = ZX234290_USER_RST_UNDEFINE; /* write back the reset value */
191
192 ret |= zx234290_i2c_write_reg(ZX234290_REG_USER, &reg_write);
193 }
194 if ( ret != 0 )
195 {
196 return -EIO;
197 }
198 printf( " [%s][USER_RESERVED = 0x%X] ...\n", __FUNCTION__, reg_user);
xf.libdd93d52023-05-12 07:10:14 -0700199 (*(volatile unsigned long *)(USER_RESERVED_BASE)) =reg_user;
lh9ed821d2023-04-07 01:36:19 -0700200
201 /* 1. Õý³£¿ª»ú¼ì²â */
202 if( reg_start & PWR_ON_START_UP )
203 /* ÏµÍ³ÖØÆô,Èç¹ûZX234290_REG_USER²»Îª³õÖµ£¬ÔòÎªÖØÆô */
204 {
205 s_boot_reason = RB_POWER_KEY;
206 return 0;
207 }
208 else if( reg_start & PS_HOLD_START_UP )
209 {
210 s_boot_reason = RB_USB_INSERT;
211
212 /* ZX234290_REG_USERΪÉϵ縴λֵ»ò·Ç·¨Öµ */
213 return 0;
214 }
215 else if( reg_start & RTC_ALARM_START_UP )
216 /* 2. Õý³£¿ª»ú¼ì²â */
217 {
218 uchar rtc_ctrl2 = 0xF0;
219
220 ret = zx234290_i2c_read_reg(ZX234290_REG_RTC_CONTROL2, &rtc_ctrl2);
221 printf( " [%s][RTC_CONTROL2 = 0x%X]\n", __FUNCTION__, rtc_ctrl2);
222
223 if (rtc_ctrl2 & RTC_CONTROL2_AF) {
224 s_boot_reason = RB_RTC;
225 } else if (rtc_ctrl2 & RTC_CONTROL2_TF) {
226 s_boot_reason = RB_RESET_NOMAL;
227 }
228
229 return ret;
230 }
231 else if( reg_start & LLP_RESTART_UP )
232 {
233 s_boot_reason = RB_POWER_KEY_LONG;
234 return 0;
235 }
236 /* reg_startΪ0£¬¼´reg_start¶ÁÇåÖ®ºóδµôµç£¬¼´ÏµÍ³ÖØÆô */
237
238 /* 2. ÖØÆô¼ì²â */
239
240 /* ÏµÍ³ÖØÆô,Èç¹ûZX234290_REG_USER²»Îª³õÖµ£¬ÔòÎªÖØÆô */
241 switch (reg_user)
242 {
243 case ZX234290_USER_RST_TO_NORMAL:
244 {
245 s_boot_reason = RB_RESET_NOMAL;
246 return 0;
247 }
248
249 case ZX234290_USER_RST_TO_CHARGER:
250 {
251 s_boot_reason = RB_RESET_USB_OFF;
252 return 0;
253 }
254
255 case ZX234290_USER_RST_TO_ALARM:
256 {
257 s_boot_reason = RB_RESET_ALARM;
258 return 0;
259 }
260
261 /* ZX234290_REG_USERΪÉϵ縴λֵ»ò·Ç·¨Öµ */
262 default:
263 {
264 if ((reg_user & 0xF0) == ZX234290_WDT_RST_FLAG) {
265 s_boot_reason = reg_user;
266 return 0;
267 }
268 break;
269 }
270 }
271
272 s_boot_reason = RB_USB_INSERT;
273
274 return 0;
275}
276
277/*******************************************************************************
278 * Function: zx234290_ps_hold_pull_on
279 * Description:
280 * Parameters:
281 * Input:
282 *
283 * Output:
284 *
285 * Returns:
286 *
287 *
288 * Others:
289 ********************************************************************************/
290int zx234290_ps_hold_pull_on(void)
291{
292 zDrvGpio_PullUpDown(PIN_PSHOLD_NUM, 0);
293 //gpio_set_reuse(PS_HOLD_PIN, 0);
294 zDrvGpio_SetFunc(PIN_PSHOLD_NUM,GPIO_PSHOLD_FUNC_SEL);
295 zDrvGpio_SetDirection(PIN_PSHOLD_NUM,GPIO_IN); //set output;v3 gpio24(pshold) direction is reverse
296 zDrvGpio_SetOutputValue(PIN_PSHOLD_NUM,GPIO_HIGH);
297 return 0;
298}
299
300/*******************************************************************************
301 * Function: zx234290_ps_hold_pull_off
302 * Description:
303 * Parameters:
304 * Input:
305 *
306 * Output:
307 *
308 * Returns:
309 *
310 *
311 * Others:
312 ********************************************************************************/
313int zx234290_ps_hold_pull_off(void)
314{
315 zDrvGpio_PullUpDown(PIN_PSHOLD_NUM, 0);
316 //gpio_set_reuse(PS_HOLD_PIN, 0);
317 //gpio_direction_output(PS_HOLD_PIN, GPIO_LOW);
318 zDrvGpio_SetFunc(PIN_PSHOLD_NUM,GPIO_PSHOLD_FUNC_SEL);
319 zDrvGpio_SetDirection(PIN_PSHOLD_NUM,GPIO_IN); //set output;v3 gpio24(pshold) direction is reverse
320 zDrvGpio_SetOutputValue(PIN_PSHOLD_NUM,GPIO_LOW);
321 return 0;
322}
323
324/*******************************************************************************
325 * Function: zx234290_power_off
326 * Description:
327 * Parameters:
328 * Input:
329 *
330 * Output:
331 *
332 * Returns:
333 *
334 *
335 * Others:
336 ********************************************************************************/
337int zx234290_power_off(void)
338{
339 return zx234290_ps_hold_pull_off();
340}
341
342/*******************************************************************************
343 * Function:
344 * Description:
345 * Parameters:
346 * Input:
347 *
348 * Output:
349 *
350 * Returns:
351 *
352 *
353 * Others:
354 ********************************************************************************/
355int pmu_init(void)
356{
357 int ret = 0;
xf.lie31de8b2023-12-26 23:38:58 -0800358 uchar reg_val = 0;
lh9ed821d2023-04-07 01:36:19 -0700359 struct pmu_opt pmu = {NULL};
360
361 /* GPIO init */
362 //gpio_set_reuse(PS_HOLD_PIN, 0x0);
363 //gpio_direction_output(PS_HOLD_PIN,GPIO_LOW);
364
365 // gpio_set_reuse(POWER_KEY_PIN,0x0);
366 // gpio_direction_input(POWER_KEY_PIN);
367
368 // gpio_noaction(POWER_KEY_PIN);
369
370 /* register pmu opt */
371 pmu.read_reg = zx234290_i2c_read_reg;
372 pmu.write_reg = zx234290_i2c_write_reg;
373 pmu.get_boot_reason = zx234290_get_boot_reason;
374 pmu.ps_hold_pull_on = pmu_pull_on_ps_hold;
375 pmu.ps_hold_pull_off = pmu_pull_off_ps_hold;
376 pmu.power_off = zx234290_power_off;
377 ret = register_pmu_opt(&pmu);
378 /*
379 if( ret != 0 )
380 {
381 return -EIO;
382 }
383 */
384 ret = zx234290_get_boot_reason_prev();
xf.lie31de8b2023-12-26 23:38:58 -0800385 ret +=zx234290_i2c_read_reg(ZX234297_REG_ADDR_SINK_CONTROL,&reg_val);
386 if(reg_val==0x7f){//means 296G C
387 reg_val = 0xff;//define to 296
388 ret+=zx234290_i2c_write_reg(ZX234297_REG_ADDR_SINK_CONTROL,&reg_val);
389 }
390
391 if (ret != SUCCESS)
392 {
393 printf( "[%s]set 0x29 error ret=0x%x!\n", __FUNCTION__,ret);
394 }
395
lh9ed821d2023-04-07 01:36:19 -0700396 return ret;
397}
398
399/* ================================================================================
400 * pmu_init:
401 */
402int pmu_pull_off_ps_hold(void)
403{
404 return zx234290_ps_hold_pull_off();
405}
406
407/* ================================================================================
408 * pmu_init:
409 */
410int pmu_pull_on_ps_hold(void)
411{
412 return zx234290_ps_hold_pull_on();
413}
414
415/* ================================================================================
416 * system_power_off:
417 */
418void system_power_off(void)
419{
420 zx234290_power_off();
421}
422
423int zx234290_get_adc2_voltage(void)
424{
425 int nTempAdc = 0, ret = -1;
426 int adcReadInt = -1;
427 int msb=0, lsb=0;
428 int num;
429 uchar status_a=0;
430 uchar adcEnable = 0x28;
431 uchar sys_ctrl;
432
433 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
434 if (ret != SUCCESS)
435 {
436 return -EIO;
437 }
438 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
439
440 /*enable adc*/
441#if 0
442 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
443 if (ret != SUCCESS)
444 {
445 return -EIO;
446 }
447#else
448 for(num=1; num <= 50; num++)
449 {
450 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
451 if (ret != SUCCESS)
452 {
453 return -EIO;
454 }
455 udelay((100000/3000)*5); /* delay 5ms */
456 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
457 if (ret != SUCCESS)
458 {
459 return -EIO;
460 }
461
462 if(status_a & 0x04)
463 {
464 printf( "adc2 get adc,break num =%d ...\n", num);
465 break;
466 }
467 }
468#endif
469 udelay((100000/3000)*20); /* delay 20ms */
470
471 /*read adc*/
472 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC2MSB, &msb);
473 if (ret != SUCCESS)
474 {
475 return -EIO;
476 }
477 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC2LSB, &lsb);
478 if (ret != SUCCESS)
479 {
480 return -EIO;
481 }
482
483 /*clear int*/
484 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
485 if (ret != SUCCESS)
486 {
487 return -EIO;
488 }
489 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
490 if (ret != SUCCESS)
491 {
492 return -EIO;
493 }
494
495 nTempAdc = ((msb<<4)|(lsb>>4));
496
497 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
498
499 return nTempAdc;
500}
501
502int zx234290_get_adc1_voltage(void) /*read adc1*/
503{
504 int nTempAdc = 0,adcEnable = 0,ret = -1;
505 int adcReadInt = -1;
506 int msb=0, lsb=0;
507 int num;
508 uchar status_a=0;
509 adcEnable = 0x30; /*read adc1*/
510 uchar sys_ctrl;
511
512 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
513 if (ret != SUCCESS)
514 {
515 return -EIO;
516 }
517 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
518
519 /*enable adc*/
520#if 0
521 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
522 if (ret != SUCCESS)
523 {
524 return -EIO;
525 }
526#else
527 for(num=1; num <= 50; num++)
528 {
529 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
530 if (ret != SUCCESS)
531 {
532 return -EIO;
533 }
534 udelay((100000/3000)*5); /* delay 5ms */
535 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
536 if (ret != SUCCESS)
537 {
538 return -EIO;
539 }
540 if(status_a & 0x04)
541 {
542 printf( "adc1 get adc,break num =%d ...\n", num);
543 break;
544 }
545 }
546#endif
547
548 udelay((100000/3000)*20); /* delay 20ms */
549
550 /*read adc*/
551 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1MSB, &msb);
552 if (ret != SUCCESS)
553 {
554 return -EIO;
555 }
556 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1LSB, &lsb);
557 if (ret != SUCCESS)
558 {
559 return -EIO;
560 }
561
562 /*clear int*/
563 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
564 if (ret != SUCCESS)
565 {
566 return -EIO;
567 }
568 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
569 if (ret != SUCCESS)
570 {
571 return -EIO;
572 }
573
574 nTempAdc = ((msb<<4)|(lsb>>4));
575
576 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
577
578 return nTempAdc;
579}
580
581int zx234290_get_vbat_voltage(void)
582{
583 int nTempAdc = 0,adcEnable = 0,ret = -1;
584 int adcReadInt = -1;
585 int msb=0, lsb=0;
586 int num;
587 uchar status_a=0;
588 //adcEnable = 0x30;
589 adcEnable = 0x20;
590 uchar sys_ctrl;
591
592 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
593 if (ret != SUCCESS)
594 {
595 return -EIO;
596 }
597 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
598
599#if 0
600 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
601 if (ret != SUCCESS)
602 {
603 return -EIO;
604 }
605#else
606 for(num=1; num <= 50; num++)
607 {
608 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
609 if (ret != SUCCESS)
610 {
611 return -EIO;
612 }
613 udelay((100000/3000)*5); /* delay 5ms */
614 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
615 if (ret != SUCCESS)
616 {
617 return -EIO;
618 }
619 if(status_a & 0x04)
620 {
621 printf( "vbat get adc,break num =%d ...\n", num);
622 break;
623 }
624 }
625#endif
626 //ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1MSB, &msb);
627 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_VBATMSB, &msb);
628 if (ret != SUCCESS)
629 {
630 return -EIO;
631 }
632 //ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1LSB, &lsb);
633 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_VBATLSB, &lsb);
634 if (ret != SUCCESS)
635 {
636 return -EIO;
637 }
638 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
639 if (ret != SUCCESS)
640 {
641 return -EIO;
642 }
643 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
644 if (ret != SUCCESS)
645 {
646 return -EIO;
647 }
648 nTempAdc = ((msb<<4)|(lsb>>4));
649 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
650 return nTempAdc;
651}
652
653int zx234290_set_llp_enable(void)
654{
655 int ret = -1;
656 ushort reg=ZX234290_REG_ADDR_PWRON;
657 uchar val=0x05;
658
659 ret = zx234290_i2c_write_reg(reg, &val);
660 if (ret != SUCCESS)
661 {
662 return -EIO;
663 }
664 return ret;
665}
666
667/*get the poweron key state 0x1<<5: poweron press 0:poweron up*/
668int zx234290_get_poweron_state(void)
669{
670 int val = 0,ret = -1;
671 uchar reg = 0;
672
673 ret = zx234290_i2c_read_reg(STATUS_A,&reg);
674 if (ret != SUCCESS)
675 {
676 return -EIO;
677 }
678 val = reg&STATUS_PWR_ON;
679 return val;
680}
681
682/* get the rtc_alarm status: bit0 in reg 0x05 */
683int zx234290_get_rtc_state(void)
684{
685 int val = 0,ret = -1;
686 uchar reg = 0;
687
688 ret = zx234290_i2c_read_reg(STATUS_B, &reg);
689 if (ret != SUCCESS)
690 {
691 return -EIO;
692 }
693 val = reg & STATUS_RTC_ALARM;
694 return val;
695}
696
697/* Set or clear SoftOn bit in ZX234290_REG_SYS_CTRL */
698int zx234290_set_softon(int on)
699{
700 uchar reg = 0;
701 int ret;
702
703 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &reg);
704 if (ret != SUCCESS)
705 {
706 return -EIO;
707 }
708
709 if ((reg >> 7) != on) {
710 reg ^= (0x01<<7);
711 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &reg);
712 if (ret != SUCCESS)
713 {
714 return -EIO;
715 }
716 }
717 return 0;
718}
719
720/*set ldo8 SD VOL*/
721int zx234290_set_ldo8_voltage(T_ZDrvZx234290_VldoD vol)
722{
723 int ret = 0;
724 unsigned char reg_addr=0, reg_val=0;
725
726 if(vol > VLDOD_MAX)
727 {
728 return -EINVAL;
729 }
730 reg_addr = ZX234290_REG_ADDR_LDO78_VOL;
731 ret = zx234290_i2c_read_reg(reg_addr,&reg_val);
732 if (ret != SUCCESS)
733 {
734 return -EIO;
735 }
736 reg_val &= ~(0xf<<ZX234290_LDO8_VSEL_LSH);
737 reg_val |= (vol<<ZX234290_LDO8_VSEL_LSH);
738
739 ret = zx234290_i2c_write_reg(reg_addr, &reg_val);
740 if (ret != SUCCESS)
741 {
742 return -EIO;
743 }
744
745 return 0;
746}
747
748int zx234290_set_ldo8_sleep_voltage(T_ZDrvZx234290_VldoD vol)
749{
750 int ret = 0;
751 unsigned char reg_addr=0, reg_val=0;
752
753 if(vol > VLDOD_MAX)
754 {
755 return -EINVAL;
756 }
757 reg_addr = ZX234290_REG_ADDR_LDO78_VOL;
758 ret = zx234290_i2c_read_reg(reg_addr,&reg_val);
759 if (ret != SUCCESS)
760 {
761 return -EIO;
762 }
763 reg_val &= ~(0xf<<ZX234290_LDO8_SLP_VSEL_LSH);
764 reg_val |= (vol<<ZX234290_LDO8_SLP_VSEL_LSH);
765
766 ret = zx234290_i2c_write_reg(reg_addr, &reg_val);
767 if (ret != SUCCESS)
768 {
769 return -EIO;
770 }
771
772 return 0;
773}
774
775
776/* clear SoftOn bit in ZX234290_REG_SYS_CTRL bit7 */
777int zx234290_ldo8_enable(int enable)
778{
779 int ret = -1;
780 uchar reg = 0;
781
782 ret = zx234290_i2c_read_reg(ZX234290_REG_LDO_EN1, &reg);
783 if (ret != SUCCESS)
784 {
785 return -EIO;
786 }
787 reg &= ~(0x01<<7);
788 reg |= (enable<<7);
789 ret = zx234290_i2c_write_reg(ZX234290_REG_LDO_EN1, &reg);
790 if (ret != SUCCESS)
791 {
792 return -EIO;
793 }
794 return 0;
795}
796int zx234290_set_sink(T_ZX234290_SINK sink_num, int is_on, T_ZX234297_SINK_CURRENT sink_current)
797{
798 int ret = 0;
799 unsigned char lsh_on, lsh_current;
800 uchar reg = 0;
801
802 ret = zx234290_i2c_read_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
803 if (ret != SUCCESS)
804 {
805 return -EIO;
806 }
807 if(0xff==reg){
808 printf("pmu zx234296 no sink\n");
809 return SUCCESS;
810 }
811 if (sink_num == SINK_1) {
812 lsh_on = ZX234297_SINK1_ON_LSH;
813 lsh_current = ZX234297_SINK1_CURRENT_LSH;
814 } else if (sink_num == SINK_2) {
815 lsh_on = ZX234297_SINK2_ON_LSH;
816 lsh_current = ZX234297_SINK2_CURRENT_LSH;
817 } else
818 return -EINVAL;
819
820 if (is_on) {
821 if (sink_current >= SINK_CURRENT_MAX)
822 sink_current = SINK_CURRENT_120MA;
823
824 ret = zx234290_i2c_read_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
825 if (ret != SUCCESS)
826 {
827 return -EIO;
828 }
829 reg &= ~(0xf<<lsh_current);
830 reg |= (sink_current<<lsh_current);
831 ret = zx234290_i2c_write_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
832 if (ret != SUCCESS)
833 {
834 return -EIO;
835 }
836 }
837
838 is_on = !!is_on;
839 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_LDO_EN2, &reg);
840 if (ret != SUCCESS)
841 {
842 return -EIO;
843 }
844 reg &= ~(0x1<<lsh_on);
845 reg |= (is_on<<lsh_on);
846 ret = zx234290_i2c_write_reg(ZX234290_REG_ADDR_LDO_EN2, &reg);
847 if (ret != SUCCESS)
848 {
849 return -EIO;
850 }
851
852 return 0;
853}
854
855#if 0
856int zx234290_SetVldo8(Zx234290_VldoD vol)
857{
858 int reg = 0,val = 0,ret = -1;
859 ret = zx234290_i2c_read_reg(ZX234290_REG_LD78_VOL, &reg);
860 if (ret != SUCCESS)
861 {
862 return -EIO;
863 }
864 BOOT_PRINTF(UBOOT_ERR, "********First REG0x15=0x%x!!!\n",reg);
865 reg &= 0xf;/*00001111*/
866 reg |= (vol<<4);
867 ret = zx234290_i2c_write_reg(ZX234290_REG_LD78_VOL, &reg);
868 if (ret != SUCCESS)
869 {
870 return -EIO;
871 }
872 ret = zx234290_i2c_read_reg(ZX234290_REG_LD78_VOL, &reg);
873 if (ret != SUCCESS)
874 {
875 return -EIO;
876 }
877 BOOT_PRINTF(UBOOT_ERR, "********Last REG0x15=0x%x!!!\n",reg);
878 return 0;
879}
880
881#endif
882
883