lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /********************************************************************* |
| 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 <zx234502.h> |
| 28 | |
| 29 | |
| 30 | |
| 31 | /******************************************************************************* |
| 32 | * Function: zx234290_i2c_read_reg |
| 33 | * Description: |
| 34 | * Parameters: |
| 35 | * Input: |
| 36 | * |
| 37 | * Output: |
| 38 | * |
| 39 | * Returns: |
| 40 | * |
| 41 | * |
| 42 | * Others: |
| 43 | ********************************************************************************/ |
| 44 | int zx234502_i2c_read_reg(ushort reg, uchar *val) |
| 45 | { |
| 46 | return i2c_read(1, ZX234502_I2C_SLAVE_ADDR, reg, 8, val, 1); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | /******************************************************************************* |
| 52 | * Function: zx234290_i2c_write_reg |
| 53 | * Description: |
| 54 | * Parameters: |
| 55 | * Input: |
| 56 | * |
| 57 | * Output: |
| 58 | * |
| 59 | * Returns: |
| 60 | * |
| 61 | * |
| 62 | * Others: |
| 63 | ********************************************************************************/ |
| 64 | int zx234502_i2c_write_reg(ushort reg, uchar *val) |
| 65 | { |
| 66 | return i2c_write(1, ZX234502_I2C_SLAVE_ADDR, reg, 8, val, 1); |
| 67 | } |
| 68 | |
| 69 | /******************************************************************************* |
| 70 | * Function: zx234502_boost_flag |
| 71 | * Description: |
| 72 | * Parameters: |
| 73 | * Input: |
| 74 | * |
| 75 | * Output: |
| 76 | * |
| 77 | * Returns: |
| 78 | * |
| 79 | * |
| 80 | * Others: |
| 81 | ********************************************************************************/ |
| 82 | int zx234502_boost_flag(int *boost_flag) |
| 83 | { |
| 84 | int ret = 0; |
| 85 | uchar reg = 0; |
| 86 | |
| 87 | |
| 88 | ret = zx234502_i2c_read_reg(ZX234502_REG_PIS, ®); |
| 89 | if( ret != 0 ){ |
| 90 | printf( "[zx234502_boost_flag]ERROR!!\n"); |
| 91 | return 1; |
| 92 | } |
| 93 | printf( " [zx234502_boost_flag][ZX234502_REG_PIS = 0x%x] ...\n", reg); |
| 94 | |
| 95 | *boost_flag = reg & ZX234502_REG_PIS_POWERON_IT_MASK; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | * Function: zx234502_battery_status |
| 102 | * Description: |
| 103 | * Parameters: |
| 104 | * Input: |
| 105 | * |
| 106 | * Output: |
| 107 | * |
| 108 | * Returns: |
| 109 | * |
| 110 | * |
| 111 | * Others: |
| 112 | ********************************************************************************/ |
| 113 | int zx234502_battery_status(int *bat_state) |
| 114 | { |
| 115 | int ret = 0; |
| 116 | uchar reg = 0; |
| 117 | |
| 118 | ret = zx234502_i2c_read_reg(ZX234502_REG_CBIS, ®); |
| 119 | if( ret != 0 ){ |
| 120 | printf( "[zx234502_battery_status]ERROR!!\n"); |
| 121 | return 1; |
| 122 | } |
| 123 | printf( " [zx234502_boost_flag][zx234502_battery_status = 0x%x] ...\n", reg); |
| 124 | |
| 125 | *bat_state = reg & ZX234502_REG_CBIS_NOBAT_MASK; |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | int zx234502_charger_enable() |
| 131 | { |
| 132 | unsigned char reg = 0; |
| 133 | reg &= ~0xF; |
| 134 | zx234502_i2c_write_reg(0, ®); |
| 135 | |
| 136 | return 0; |
| 137 | } |