blob: 1f2f485941ab2e0dcdb8a8a5735528f6037436b8 [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>
31
32
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);
184
185 /* ¶Á²¢ÇåZX234290_REG_USER */
186 ret = zx234290_i2c_read_reg(ZX234290_REG_USER, &reg_user);
187 if(reg_user != ZX234290_USER_RST_UNDEFINE)
188 {
189 reg_write = ZX234290_USER_RST_UNDEFINE; /* write back the reset value */
190
191 ret |= zx234290_i2c_write_reg(ZX234290_REG_USER, &reg_write);
192 }
193 if ( ret != 0 )
194 {
195 return -EIO;
196 }
197 printf( " [%s][USER_RESERVED = 0x%X] ...\n", __FUNCTION__, reg_user);
198
199 /* 1. Õý³£¿ª»ú¼ì²â */
200 if( reg_start & PWR_ON_START_UP )
201 /* ÏµÍ³ÖØÆô,Èç¹ûZX234290_REG_USER²»Îª³õÖµ£¬ÔòÎªÖØÆô */
202 {
203 s_boot_reason = RB_POWER_KEY;
204 return 0;
205 }
206 else if( reg_start & PS_HOLD_START_UP )
207 {
208 s_boot_reason = RB_USB_INSERT;
209
210 /* ZX234290_REG_USERΪÉϵ縴λֵ»ò·Ç·¨Öµ */
211 return 0;
212 }
213 else if( reg_start & RTC_ALARM_START_UP )
214 /* 2. Õý³£¿ª»ú¼ì²â */
215 {
216 uchar rtc_ctrl2 = 0xF0;
217
218 ret = zx234290_i2c_read_reg(ZX234290_REG_RTC_CONTROL2, &rtc_ctrl2);
219 printf( " [%s][RTC_CONTROL2 = 0x%X]\n", __FUNCTION__, rtc_ctrl2);
220
221 if (rtc_ctrl2 & RTC_CONTROL2_AF) {
222 s_boot_reason = RB_RTC;
223 } else if (rtc_ctrl2 & RTC_CONTROL2_TF) {
224 s_boot_reason = RB_RESET_NOMAL;
225 }
226
227 return ret;
228 }
229 else if( reg_start & LLP_RESTART_UP )
230 {
231 s_boot_reason = RB_POWER_KEY_LONG;
232 return 0;
233 }
234 /* reg_startΪ0£¬¼´reg_start¶ÁÇåÖ®ºóδµôµç£¬¼´ÏµÍ³ÖØÆô */
235
236 /* 2. ÖØÆô¼ì²â */
237
238 /* ÏµÍ³ÖØÆô,Èç¹ûZX234290_REG_USER²»Îª³õÖµ£¬ÔòÎªÖØÆô */
239 switch (reg_user)
240 {
241 case ZX234290_USER_RST_TO_NORMAL:
242 {
243 s_boot_reason = RB_RESET_NOMAL;
244 return 0;
245 }
246
247 case ZX234290_USER_RST_TO_CHARGER:
248 {
249 s_boot_reason = RB_RESET_USB_OFF;
250 return 0;
251 }
252
253 case ZX234290_USER_RST_TO_ALARM:
254 {
255 s_boot_reason = RB_RESET_ALARM;
256 return 0;
257 }
258
259 /* ZX234290_REG_USERΪÉϵ縴λֵ»ò·Ç·¨Öµ */
260 default:
261 {
262 if ((reg_user & 0xF0) == ZX234290_WDT_RST_FLAG) {
263 s_boot_reason = reg_user;
264 return 0;
265 }
266 break;
267 }
268 }
269
270 s_boot_reason = RB_USB_INSERT;
271
272 return 0;
273}
274
275/*******************************************************************************
276 * Function: zx234290_ps_hold_pull_on
277 * Description:
278 * Parameters:
279 * Input:
280 *
281 * Output:
282 *
283 * Returns:
284 *
285 *
286 * Others:
287 ********************************************************************************/
288int zx234290_ps_hold_pull_on(void)
289{
290 zDrvGpio_PullUpDown(PIN_PSHOLD_NUM, 0);
291 //gpio_set_reuse(PS_HOLD_PIN, 0);
292 zDrvGpio_SetFunc(PIN_PSHOLD_NUM,GPIO_PSHOLD_FUNC_SEL);
293 zDrvGpio_SetDirection(PIN_PSHOLD_NUM,GPIO_IN); //set output;v3 gpio24(pshold) direction is reverse
294 zDrvGpio_SetOutputValue(PIN_PSHOLD_NUM,GPIO_HIGH);
295 return 0;
296}
297
298/*******************************************************************************
299 * Function: zx234290_ps_hold_pull_off
300 * Description:
301 * Parameters:
302 * Input:
303 *
304 * Output:
305 *
306 * Returns:
307 *
308 *
309 * Others:
310 ********************************************************************************/
311int zx234290_ps_hold_pull_off(void)
312{
313 zDrvGpio_PullUpDown(PIN_PSHOLD_NUM, 0);
314 //gpio_set_reuse(PS_HOLD_PIN, 0);
315 //gpio_direction_output(PS_HOLD_PIN, GPIO_LOW);
316 zDrvGpio_SetFunc(PIN_PSHOLD_NUM,GPIO_PSHOLD_FUNC_SEL);
317 zDrvGpio_SetDirection(PIN_PSHOLD_NUM,GPIO_IN); //set output;v3 gpio24(pshold) direction is reverse
318 zDrvGpio_SetOutputValue(PIN_PSHOLD_NUM,GPIO_LOW);
319 return 0;
320}
321
322/*******************************************************************************
323 * Function: zx234290_power_off
324 * Description:
325 * Parameters:
326 * Input:
327 *
328 * Output:
329 *
330 * Returns:
331 *
332 *
333 * Others:
334 ********************************************************************************/
335int zx234290_power_off(void)
336{
337 return zx234290_ps_hold_pull_off();
338}
339
340/*******************************************************************************
341 * Function:
342 * Description:
343 * Parameters:
344 * Input:
345 *
346 * Output:
347 *
348 * Returns:
349 *
350 *
351 * Others:
352 ********************************************************************************/
353int pmu_init(void)
354{
355 int ret = 0;
356 struct pmu_opt pmu = {NULL};
357
358 /* GPIO init */
359 //gpio_set_reuse(PS_HOLD_PIN, 0x0);
360 //gpio_direction_output(PS_HOLD_PIN,GPIO_LOW);
361
362 // gpio_set_reuse(POWER_KEY_PIN,0x0);
363 // gpio_direction_input(POWER_KEY_PIN);
364
365 // gpio_noaction(POWER_KEY_PIN);
366
367 /* register pmu opt */
368 pmu.read_reg = zx234290_i2c_read_reg;
369 pmu.write_reg = zx234290_i2c_write_reg;
370 pmu.get_boot_reason = zx234290_get_boot_reason;
371 pmu.ps_hold_pull_on = pmu_pull_on_ps_hold;
372 pmu.ps_hold_pull_off = pmu_pull_off_ps_hold;
373 pmu.power_off = zx234290_power_off;
374 ret = register_pmu_opt(&pmu);
375 /*
376 if( ret != 0 )
377 {
378 return -EIO;
379 }
380 */
381 ret = zx234290_get_boot_reason_prev();
382
383 return ret;
384}
385
386/* ================================================================================
387 * pmu_init:
388 */
389int pmu_pull_off_ps_hold(void)
390{
391 return zx234290_ps_hold_pull_off();
392}
393
394/* ================================================================================
395 * pmu_init:
396 */
397int pmu_pull_on_ps_hold(void)
398{
399 return zx234290_ps_hold_pull_on();
400}
401
402/* ================================================================================
403 * system_power_off:
404 */
405void system_power_off(void)
406{
407 zx234290_power_off();
408}
409
410int zx234290_get_adc2_voltage(void)
411{
412 int nTempAdc = 0, ret = -1;
413 int adcReadInt = -1;
414 int msb=0, lsb=0;
415 int num;
416 uchar status_a=0;
417 uchar adcEnable = 0x28;
418 uchar sys_ctrl;
419
420 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
421 if (ret != SUCCESS)
422 {
423 return -EIO;
424 }
425 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
426
427 /*enable adc*/
428#if 0
429 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
430 if (ret != SUCCESS)
431 {
432 return -EIO;
433 }
434#else
435 for(num=1; num <= 50; num++)
436 {
437 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
438 if (ret != SUCCESS)
439 {
440 return -EIO;
441 }
442 udelay((100000/3000)*5); /* delay 5ms */
443 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
444 if (ret != SUCCESS)
445 {
446 return -EIO;
447 }
448
449 if(status_a & 0x04)
450 {
451 printf( "adc2 get adc,break num =%d ...\n", num);
452 break;
453 }
454 }
455#endif
456 udelay((100000/3000)*20); /* delay 20ms */
457
458 /*read adc*/
459 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC2MSB, &msb);
460 if (ret != SUCCESS)
461 {
462 return -EIO;
463 }
464 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC2LSB, &lsb);
465 if (ret != SUCCESS)
466 {
467 return -EIO;
468 }
469
470 /*clear int*/
471 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
472 if (ret != SUCCESS)
473 {
474 return -EIO;
475 }
476 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
477 if (ret != SUCCESS)
478 {
479 return -EIO;
480 }
481
482 nTempAdc = ((msb<<4)|(lsb>>4));
483
484 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
485
486 return nTempAdc;
487}
488
489int zx234290_get_adc1_voltage(void) /*read adc1*/
490{
491 int nTempAdc = 0,adcEnable = 0,ret = -1;
492 int adcReadInt = -1;
493 int msb=0, lsb=0;
494 int num;
495 uchar status_a=0;
496 adcEnable = 0x30; /*read adc1*/
497 uchar sys_ctrl;
498
499 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
500 if (ret != SUCCESS)
501 {
502 return -EIO;
503 }
504 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
505
506 /*enable adc*/
507#if 0
508 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
509 if (ret != SUCCESS)
510 {
511 return -EIO;
512 }
513#else
514 for(num=1; num <= 50; num++)
515 {
516 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
517 if (ret != SUCCESS)
518 {
519 return -EIO;
520 }
521 udelay((100000/3000)*5); /* delay 5ms */
522 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
523 if (ret != SUCCESS)
524 {
525 return -EIO;
526 }
527 if(status_a & 0x04)
528 {
529 printf( "adc1 get adc,break num =%d ...\n", num);
530 break;
531 }
532 }
533#endif
534
535 udelay((100000/3000)*20); /* delay 20ms */
536
537 /*read adc*/
538 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1MSB, &msb);
539 if (ret != SUCCESS)
540 {
541 return -EIO;
542 }
543 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1LSB, &lsb);
544 if (ret != SUCCESS)
545 {
546 return -EIO;
547 }
548
549 /*clear int*/
550 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
551 if (ret != SUCCESS)
552 {
553 return -EIO;
554 }
555 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
556 if (ret != SUCCESS)
557 {
558 return -EIO;
559 }
560
561 nTempAdc = ((msb<<4)|(lsb>>4));
562
563 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
564
565 return nTempAdc;
566}
567
568int zx234290_get_vbat_voltage(void)
569{
570 int nTempAdc = 0,adcEnable = 0,ret = -1;
571 int adcReadInt = -1;
572 int msb=0, lsb=0;
573 int num;
574 uchar status_a=0;
575 //adcEnable = 0x30;
576 adcEnable = 0x20;
577 uchar sys_ctrl;
578
579 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
580 if (ret != SUCCESS)
581 {
582 return -EIO;
583 }
584 sys_ctrl = (sys_ctrl & (1 << 7)) | adcEnable;
585
586#if 0
587 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL,&sys_ctrl);
588 if (ret != SUCCESS)
589 {
590 return -EIO;
591 }
592#else
593 for(num=1; num <= 50; num++)
594 {
595 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &sys_ctrl);
596 if (ret != SUCCESS)
597 {
598 return -EIO;
599 }
600 udelay((100000/3000)*5); /* delay 5ms */
601 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_STSA, &status_a);
602 if (ret != SUCCESS)
603 {
604 return -EIO;
605 }
606 if(status_a & 0x04)
607 {
608 printf( "vbat get adc,break num =%d ...\n", num);
609 break;
610 }
611 }
612#endif
613 //ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1MSB, &msb);
614 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_VBATMSB, &msb);
615 if (ret != SUCCESS)
616 {
617 return -EIO;
618 }
619 //ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_ADC1LSB, &lsb);
620 ret = zx234290_i2c_read_reg(ZX234290_REG_ADC_VBATLSB, &lsb);
621 if (ret != SUCCESS)
622 {
623 return -EIO;
624 }
625 ret = zx234290_i2c_read_reg(ZX234290_REG_INTA, &adcReadInt);
626 if (ret != SUCCESS)
627 {
628 return -EIO;
629 }
630 ret =zx234290_i2c_read_reg(ZX234290_REG_INTB, &adcReadInt);
631 if (ret != SUCCESS)
632 {
633 return -EIO;
634 }
635 nTempAdc = ((msb<<4)|(lsb>>4));
636 nTempAdc = (int)((double)(5000-0)*(nTempAdc)/4096);
637 return nTempAdc;
638}
639
640int zx234290_set_llp_enable(void)
641{
642 int ret = -1;
643 ushort reg=ZX234290_REG_ADDR_PWRON;
644 uchar val=0x05;
645
646 ret = zx234290_i2c_write_reg(reg, &val);
647 if (ret != SUCCESS)
648 {
649 return -EIO;
650 }
651 return ret;
652}
653
654/*get the poweron key state 0x1<<5: poweron press 0:poweron up*/
655int zx234290_get_poweron_state(void)
656{
657 int val = 0,ret = -1;
658 uchar reg = 0;
659
660 ret = zx234290_i2c_read_reg(STATUS_A,&reg);
661 if (ret != SUCCESS)
662 {
663 return -EIO;
664 }
665 val = reg&STATUS_PWR_ON;
666 return val;
667}
668
669/* get the rtc_alarm status: bit0 in reg 0x05 */
670int zx234290_get_rtc_state(void)
671{
672 int val = 0,ret = -1;
673 uchar reg = 0;
674
675 ret = zx234290_i2c_read_reg(STATUS_B, &reg);
676 if (ret != SUCCESS)
677 {
678 return -EIO;
679 }
680 val = reg & STATUS_RTC_ALARM;
681 return val;
682}
683
684/* Set or clear SoftOn bit in ZX234290_REG_SYS_CTRL */
685int zx234290_set_softon(int on)
686{
687 uchar reg = 0;
688 int ret;
689
690 ret = zx234290_i2c_read_reg(ZX234290_REG_SYS_CTRL, &reg);
691 if (ret != SUCCESS)
692 {
693 return -EIO;
694 }
695
696 if ((reg >> 7) != on) {
697 reg ^= (0x01<<7);
698 ret = zx234290_i2c_write_reg(ZX234290_REG_SYS_CTRL, &reg);
699 if (ret != SUCCESS)
700 {
701 return -EIO;
702 }
703 }
704 return 0;
705}
706
707/*set ldo8 SD VOL*/
708int zx234290_set_ldo8_voltage(T_ZDrvZx234290_VldoD vol)
709{
710 int ret = 0;
711 unsigned char reg_addr=0, reg_val=0;
712
713 if(vol > VLDOD_MAX)
714 {
715 return -EINVAL;
716 }
717 reg_addr = ZX234290_REG_ADDR_LDO78_VOL;
718 ret = zx234290_i2c_read_reg(reg_addr,&reg_val);
719 if (ret != SUCCESS)
720 {
721 return -EIO;
722 }
723 reg_val &= ~(0xf<<ZX234290_LDO8_VSEL_LSH);
724 reg_val |= (vol<<ZX234290_LDO8_VSEL_LSH);
725
726 ret = zx234290_i2c_write_reg(reg_addr, &reg_val);
727 if (ret != SUCCESS)
728 {
729 return -EIO;
730 }
731
732 return 0;
733}
734
735int zx234290_set_ldo8_sleep_voltage(T_ZDrvZx234290_VldoD vol)
736{
737 int ret = 0;
738 unsigned char reg_addr=0, reg_val=0;
739
740 if(vol > VLDOD_MAX)
741 {
742 return -EINVAL;
743 }
744 reg_addr = ZX234290_REG_ADDR_LDO78_VOL;
745 ret = zx234290_i2c_read_reg(reg_addr,&reg_val);
746 if (ret != SUCCESS)
747 {
748 return -EIO;
749 }
750 reg_val &= ~(0xf<<ZX234290_LDO8_SLP_VSEL_LSH);
751 reg_val |= (vol<<ZX234290_LDO8_SLP_VSEL_LSH);
752
753 ret = zx234290_i2c_write_reg(reg_addr, &reg_val);
754 if (ret != SUCCESS)
755 {
756 return -EIO;
757 }
758
759 return 0;
760}
761
762
763/* clear SoftOn bit in ZX234290_REG_SYS_CTRL bit7 */
764int zx234290_ldo8_enable(int enable)
765{
766 int ret = -1;
767 uchar reg = 0;
768
769 ret = zx234290_i2c_read_reg(ZX234290_REG_LDO_EN1, &reg);
770 if (ret != SUCCESS)
771 {
772 return -EIO;
773 }
774 reg &= ~(0x01<<7);
775 reg |= (enable<<7);
776 ret = zx234290_i2c_write_reg(ZX234290_REG_LDO_EN1, &reg);
777 if (ret != SUCCESS)
778 {
779 return -EIO;
780 }
781 return 0;
782}
783int zx234290_set_sink(T_ZX234290_SINK sink_num, int is_on, T_ZX234297_SINK_CURRENT sink_current)
784{
785 int ret = 0;
786 unsigned char lsh_on, lsh_current;
787 uchar reg = 0;
788
789 ret = zx234290_i2c_read_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
790 if (ret != SUCCESS)
791 {
792 return -EIO;
793 }
794 if(0xff==reg){
795 printf("pmu zx234296 no sink\n");
796 return SUCCESS;
797 }
798 if (sink_num == SINK_1) {
799 lsh_on = ZX234297_SINK1_ON_LSH;
800 lsh_current = ZX234297_SINK1_CURRENT_LSH;
801 } else if (sink_num == SINK_2) {
802 lsh_on = ZX234297_SINK2_ON_LSH;
803 lsh_current = ZX234297_SINK2_CURRENT_LSH;
804 } else
805 return -EINVAL;
806
807 if (is_on) {
808 if (sink_current >= SINK_CURRENT_MAX)
809 sink_current = SINK_CURRENT_120MA;
810
811 ret = zx234290_i2c_read_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
812 if (ret != SUCCESS)
813 {
814 return -EIO;
815 }
816 reg &= ~(0xf<<lsh_current);
817 reg |= (sink_current<<lsh_current);
818 ret = zx234290_i2c_write_reg(ZX234297_REG_ADDR_SINK_CONTROL, &reg);
819 if (ret != SUCCESS)
820 {
821 return -EIO;
822 }
823 }
824
825 is_on = !!is_on;
826 ret = zx234290_i2c_read_reg(ZX234290_REG_ADDR_LDO_EN2, &reg);
827 if (ret != SUCCESS)
828 {
829 return -EIO;
830 }
831 reg &= ~(0x1<<lsh_on);
832 reg |= (is_on<<lsh_on);
833 ret = zx234290_i2c_write_reg(ZX234290_REG_ADDR_LDO_EN2, &reg);
834 if (ret != SUCCESS)
835 {
836 return -EIO;
837 }
838
839 return 0;
840}
841
842#if 0
843int zx234290_SetVldo8(Zx234290_VldoD vol)
844{
845 int reg = 0,val = 0,ret = -1;
846 ret = zx234290_i2c_read_reg(ZX234290_REG_LD78_VOL, &reg);
847 if (ret != SUCCESS)
848 {
849 return -EIO;
850 }
851 BOOT_PRINTF(UBOOT_ERR, "********First REG0x15=0x%x!!!\n",reg);
852 reg &= 0xf;/*00001111*/
853 reg |= (vol<<4);
854 ret = zx234290_i2c_write_reg(ZX234290_REG_LD78_VOL, &reg);
855 if (ret != SUCCESS)
856 {
857 return -EIO;
858 }
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, "********Last REG0x15=0x%x!!!\n",reg);
865 return 0;
866}
867
868#endif
869
870