yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /********************************************************************* |
| 2 | Copyright 2014 by ZTE Corporation. |
| 3 | * |
| 4 | * FileName:: |
| 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 | /******************************************************************************* |
| 21 | * Include files |
| 22 | *******************************************************************************/ |
| 23 | #include <common.h> |
| 24 | #include <errno.h> |
| 25 | #include <command.h> |
| 26 | #include <malloc.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <boot_mode.h> |
| 29 | #include <i2c.h> |
| 30 | #include <drvs_gpio.h> |
| 31 | #include "drvs_aw9523b.h" |
| 32 | #include <lcd_blg.h> |
| 33 | |
| 34 | |
| 35 | /******************************************************************************* |
| 36 | * Macro |
| 37 | *******************************************************************************/ |
| 38 | #define AW9523B_AD1AD0 (0x3) /* AD1, AD0 pin connection */ |
| 39 | #define AW9523B_ROW_POS (1) /* start position of adjacent row pins */ |
| 40 | #define AW9523B_ROW_NUM (7) /* count of adjacent row pins */ |
| 41 | #define AW9523B_COL_POS (4) /* start position of adjacent column pins */ |
| 42 | #define AW9523B_COL_NUM (3) /* count of adjacent column pins */ |
| 43 | |
| 44 | #define ROW_BITS_MASK (((1<<AW9523B_ROW_NUM) - 1)<<AW9523B_ROW_POS) |
| 45 | #define COL_BITS_MASK (((1<<AW9523B_COL_NUM) - 1)<<AW9523B_COL_POS) |
| 46 | |
| 47 | #define AW9523B_I2C_SLAVE_ADDR (I2C_ADDR_AW9523B_WITHOUT_AD | AW9523B_AD1AD0) |
| 48 | |
| 49 | /******************************************************************************* |
| 50 | * Types |
| 51 | *******************************************************************************/ |
| 52 | typedef struct |
| 53 | { |
| 54 | UINT8 addr; |
| 55 | UINT8 value; |
| 56 | } T_ZDrvKpd_ChipConfig; |
| 57 | |
| 58 | /******************************************************************************* |
| 59 | * Function Prototypes |
| 60 | *******************************************************************************/ |
| 61 | |
| 62 | |
| 63 | /******************************************************************************* |
| 64 | * Global Variable |
| 65 | *******************************************************************************/ |
| 66 | static const UINT32 s_kpdGpioReset = 75; /* keypad chip reset pin */ |
| 67 | /* other chips which use the same i2c bus */ |
| 68 | static const UINT32 s_codecGpioReset = 71; /* codec chip reset pin */ |
| 69 | static const UINT32 s_cameraGpioReset = 44; /* camera chip reset pin */ |
| 70 | |
| 71 | /******************************************************************************* |
| 72 | * Function Defines |
| 73 | *******************************************************************************/ |
| 74 | |
| 75 | /******************************************************************************* |
| 76 | * Function: zx234290_i2c_read_reg |
| 77 | * Description: |
| 78 | * Parameters: |
| 79 | * Input: |
| 80 | * |
| 81 | * Output: |
| 82 | * |
| 83 | * Returns: |
| 84 | * |
| 85 | * |
| 86 | * Others: |
| 87 | ********************************************************************************/ |
| 88 | int aw9523b_i2c_read_reg(ushort reg, uchar *val) |
| 89 | { |
| 90 | return i2c_read(1, AW9523B_I2C_SLAVE_ADDR, reg, 8, val, 1); |
| 91 | } |
| 92 | |
| 93 | /******************************************************************************* |
| 94 | * Function: zx234290_i2c_write_reg |
| 95 | * Description: |
| 96 | * Parameters: |
| 97 | * Input: |
| 98 | * |
| 99 | * Output: |
| 100 | * |
| 101 | * Returns: |
| 102 | * |
| 103 | * |
| 104 | * Others: |
| 105 | ********************************************************************************/ |
| 106 | int aw9523b_i2c_write_reg(ushort reg, uchar *val) |
| 107 | { |
| 108 | return i2c_write(1, AW9523B_I2C_SLAVE_ADDR, reg, 8, val, 1); |
| 109 | } |
| 110 | |
| 111 | /******************************************************************************* |
| 112 | * Function: kpd_ChipReset |
| 113 | * Description: reset the keypad and backlight chip. |
| 114 | * Parameters: |
| 115 | * Input: |
| 116 | * None |
| 117 | * Output: |
| 118 | * None |
| 119 | * Returns: |
| 120 | * DRV_SUCCESS or error code. |
| 121 | * Others: |
| 122 | *******************************************************************************/ |
| 123 | static SINT32 kpd_ChipReset(VOID) |
| 124 | { |
| 125 | SINT32 ret = SUCCESS; |
| 126 | |
| 127 | #if 1 |
| 128 | /* reset camera */ |
| 129 | zDrvGpio_PullUpDown(s_cameraGpioReset, 0); |
| 130 | zDrvGpio_SetFunc(s_cameraGpioReset, GPIO44_GPIO44); |
| 131 | zDrvGpio_SetDirection(s_cameraGpioReset, GPIO_OUT); |
| 132 | zDrvGpio_SetOutputValue(s_cameraGpioReset, GPIO_LOW); |
| 133 | |
| 134 | /* reset codec */ |
| 135 | zDrvGpio_PullUpDown(s_codecGpioReset, 0); |
| 136 | zDrvGpio_SetFunc(s_codecGpioReset, GPIO71_GPIO71); |
| 137 | zDrvGpio_SetDirection(s_codecGpioReset, GPIO_OUT); |
| 138 | zDrvGpio_SetOutputValue(s_codecGpioReset, GPIO_LOW); |
| 139 | #endif |
| 140 | |
| 141 | ret = zDrvGpio_PullUpDown(s_kpdGpioReset, 0); |
| 142 | if( ret != SUCCESS ) |
| 143 | { |
| 144 | return -EIO; |
| 145 | } |
| 146 | |
| 147 | ret = zDrvGpio_SetFunc(s_kpdGpioReset, GPIO75_GPIO75); |
| 148 | if( ret != SUCCESS ) |
| 149 | { |
| 150 | return -EIO; |
| 151 | } |
| 152 | |
| 153 | zDrvGpio_SetDirection(s_kpdGpioReset, GPIO_OUT); |
| 154 | zDrvGpio_SetOutputValue(s_kpdGpioReset, GPIO_LOW); |
| 155 | |
| 156 | udelay(100000/30/200); /*Actual 0.1s/200, i.e. 50us */ |
| 157 | |
| 158 | zDrvGpio_SetOutputValue(s_kpdGpioReset, GPIO_HIGH); |
| 159 | |
| 160 | udelay(100000/30/200); /*Actual 0.1s/200, i.e. 50us */ |
| 161 | |
| 162 | return SUCCESS; |
| 163 | } |
| 164 | |
| 165 | /******************************************************************************* |
| 166 | * Function: zDrvLcdBlg_Initiate |
| 167 | * Description: Initiate the keypad and backlight chip |
| 168 | * Parameters: |
| 169 | * Input: |
| 170 | * None |
| 171 | * Output: |
| 172 | * None |
| 173 | * Returns: |
| 174 | * DRV_SUCCESS or error code |
| 175 | * Others: |
| 176 | *******************************************************************************/ |
| 177 | SINT32 zDrvLcdBlg_Initiate(VOID) |
| 178 | { |
| 179 | const T_ZDrvKpd_ChipConfig aw9523b_configs[] = { |
| 180 | {REG_MODE_P0, COL_BITS_MASK}, |
| 181 | {REG_MODE_P1, ROW_BITS_MASK}, |
| 182 | }; |
| 183 | SINT32 ret = SUCCESS; |
| 184 | SINT32 i = 0; |
| 185 | UINT8 tmp_reg = 0; |
| 186 | |
| 187 | ret = kpd_ChipReset(); |
| 188 | if(ret != SUCCESS) |
| 189 | { |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | /* check I2C communication and chip status */ |
| 194 | ret = aw9523b_i2c_read_reg(REG_ID, &tmp_reg); |
| 195 | if (ret != SUCCESS) |
| 196 | { |
| 197 | return -EIO; |
| 198 | } |
| 199 | if(tmp_reg != AW9523B_REG_ID_VALUE) |
| 200 | { |
| 201 | return -EIO; |
| 202 | } |
| 203 | |
| 204 | /* set chip registers */ |
| 205 | for (i = 0; i < (sizeof(aw9523b_configs) / sizeof(aw9523b_configs[0])); i++) |
| 206 | { |
| 207 | ret = aw9523b_i2c_write_reg(aw9523b_configs[i].addr, &aw9523b_configs[i].value); |
| 208 | if (ret != SUCCESS) |
| 209 | { |
| 210 | return -EIO; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | return SUCCESS; |
| 215 | } |
| 216 | |
| 217 | /******************************************************************************* |
| 218 | * Function: zDrvLcdBlg_SetBlg |
| 219 | * Description: Set lcd backlight. |
| 220 | * Parameters: |
| 221 | * Input: |
| 222 | * brightness: |
| 223 | * Output: |
| 224 | * None |
| 225 | * Returns: |
| 226 | * DRV_SUCCESS or error code |
| 227 | * Others: |
| 228 | *******************************************************************************/ |
| 229 | SINT32 zDrvLcdBlg_SetBlg(UINT8 brightness) |
| 230 | { |
| 231 | SINT32 ret = SUCCESS; |
| 232 | uchar val = brightness; |
| 233 | |
| 234 | ret |= aw9523b_i2c_write_reg(REG_DIM0, &val); |
| 235 | ret |= aw9523b_i2c_write_reg(REG_DIM4, &val); |
| 236 | ret |= aw9523b_i2c_write_reg(REG_DIM5, &val); |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |