yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2014, ZTE Corporation. |
| 3 | * |
| 4 | * File Name: hal_led.c |
| 5 | * File Mark: |
| 6 | * Description: This file contains the hal layer routines for i2c driver. |
| 7 | * Others: |
| 8 | * Version: V1.0 |
| 9 | * Author: yx |
| 10 | * Date: 2014-07-03 |
| 11 | * History 1: |
| 12 | * Date: |
| 13 | * Version: |
| 14 | * Author: |
| 15 | * Modification: |
| 16 | * History 2: |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /**************************************************************************** |
| 20 | * Include files |
| 21 | ****************************************************************************/ |
| 22 | #include <common.h> |
| 23 | //#include "drvs_general.h" |
| 24 | //#include "drvs_i2c.h" |
| 25 | #include <linux/types.h> |
| 26 | #include <power.h> |
| 27 | #include <zx234290.h> |
| 28 | #include <led.h> |
| 29 | #include <lcd.h> |
| 30 | //#include <lcd_blg.h> |
| 31 | #include <charge.h> |
| 32 | #include <zx234502.h> |
| 33 | #include <partition_table.h> |
| 34 | #include <linux/mtd/compat.h> |
| 35 | /**************************************************************************** |
| 36 | * Local Macros |
| 37 | ****************************************************************************/ |
| 38 | #define CHARGER_EN_GPIO GPIO124 |
| 39 | #define CHARGER_EN_GPIO_FUN GPIO124_GPIO124 |
| 40 | |
| 41 | /**************************************************************************** |
| 42 | * Local Types |
| 43 | ****************************************************************************/ |
| 44 | |
| 45 | /**************************************************************************** |
| 46 | * Local Constants |
| 47 | ****************************************************************************/ |
| 48 | static void ms_delay(unsigned long ms) |
| 49 | { |
| 50 | volatile int i = 0; |
| 51 | while (i < (50000 * ms)) {i++;} |
| 52 | } |
| 53 | |
| 54 | /**************************************************************************** |
| 55 | * Function: peripheral_init |
| 56 | * Description: init the peripheral include pmu\charger\led\lcd etc. |
| 57 | * Parameters: |
| 58 | * Input: |
| 59 | * |
| 60 | * Output: |
| 61 | * |
| 62 | * Returns: |
| 63 | * int |
| 64 | * |
| 65 | * |
| 66 | * Others: |
| 67 | ***************************************************************************/ |
| 68 | int peripheral_init(void) |
| 69 | { |
| 70 | int ret = 0; |
| 71 | ret = power_init(); |
| 72 | |
| 73 | /*reset for the TF card LD08 */ |
| 74 | zx234290_ldo8_enable(0); |
| 75 | |
| 76 | udelay(100000/20); /*50ms*/ |
| 77 | //zx234290_SetVldo8(VLDOD_2_800); |
| 78 | zx234290_ldo8_enable(1); |
| 79 | |
| 80 | /*led*/ |
| 81 | // ret |= zDrvLcdBlg_Initiate(); |
| 82 | /*lcd*/ |
| 83 | //ret |= zDrvLcd_Initiate(); |
| 84 | #if 0 |
| 85 | usb_charger_init(); |
| 86 | #endif |
| 87 | //zx234502_charger_enable(); |
| 88 | zDrvGpio_SetFunc(CHARGER_EN_GPIO,CHARGER_EN_GPIO_FUN); |
| 89 | zDrvGpio_SetDirection(CHARGER_EN_GPIO,GPIO_OUT); |
| 90 | zDrvGpio_SetOutputValue(CHARGER_EN_GPIO,GPIO_LOW); |
| 91 | |
| 92 | /* 0.2 for jtagµ÷ÊÔ */ |
| 93 | #if !CONFIG_MUTUAL_DEBUG |
| 94 | // jtag_init(); |
| 95 | #endif |
| 96 | |
| 97 | return ret ; |
| 98 | } |
| 99 | |
| 100 | /**************************************************************************** |
| 101 | * Function: Show_UpdateWait |
| 102 | * Description: show the logo when the local updataing through lcd/led etc. |
| 103 | * Parameters: |
| 104 | * Input: |
| 105 | * |
| 106 | * Output: |
| 107 | * |
| 108 | * |
| 109 | * Returns: |
| 110 | * int |
| 111 | * |
| 112 | * |
| 113 | * Others: |
| 114 | ***************************************************************************/ |
| 115 | int Show_UpdateWait(void) |
| 116 | { |
| 117 | int ret = 0; |
| 118 | /*led*/ |
| 119 | |
| 120 | /*lcd*/ |
| 121 | ; |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | /**************************************************************************** |
| 126 | * Function: Show_UpdateSucc |
| 127 | * Description: show the logo when the local updataing through lcd/led etc. |
| 128 | * Parameters: |
| 129 | * Input: |
| 130 | * |
| 131 | * Output: |
| 132 | * |
| 133 | * |
| 134 | * Returns: |
| 135 | * int |
| 136 | * |
| 137 | * |
| 138 | * Others: |
| 139 | ***************************************************************************/ |
| 140 | int Show_UpdateSucc(void) |
| 141 | { |
| 142 | int ret = 0; |
| 143 | /*led*/ |
| 144 | |
| 145 | /*lcd*/ |
| 146 | ; |
| 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | /**************************************************************************** |
| 151 | * Function: Show_UpdateFail |
| 152 | * Description: show the logo when the local updataing through lcd/led etc. |
| 153 | * Parameters: |
| 154 | * Input: |
| 155 | * |
| 156 | * Output: |
| 157 | * |
| 158 | * |
| 159 | * Returns: |
| 160 | * int |
| 161 | * |
| 162 | * |
| 163 | * Others: |
| 164 | ***************************************************************************/ |
| 165 | int Show_UpdateFail(void) |
| 166 | { |
| 167 | int ret = 0; |
| 168 | /*led*/ |
| 169 | |
| 170 | /*lcd*/ |
| 171 | ; |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | /**************************************************************************** |
| 176 | * Function: Show_LowPower |
| 177 | * Description: show the logo when the local updataing through lcd/led etc. |
| 178 | * Parameters: |
| 179 | * Input: |
| 180 | * |
| 181 | * Output: |
| 182 | * |
| 183 | * |
| 184 | * Returns: |
| 185 | * int |
| 186 | * |
| 187 | * |
| 188 | * Others: |
| 189 | ***************************************************************************/ |
| 190 | int Show_LowPower(void) |
| 191 | { |
| 192 | int ret = 0; |
| 193 | /*led*/ |
| 194 | |
| 195 | /*lcd*/ |
| 196 | zDrvLcd_ShowLowBattery(); |
| 197 | ms_delay(100); |
| 198 | zDrvLcd_TurnBacklightOnOff(1); |
| 199 | // ret = zDrvLcdBlg_SetBlg(128); |
| 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | /**************************************************************************** |
| 204 | * Function: Show_No_Battery |
| 205 | * Description: show the logo when the local updataing through lcd/led etc. |
| 206 | * Parameters: |
| 207 | * Input: |
| 208 | * |
| 209 | * Output: |
| 210 | * |
| 211 | * |
| 212 | * Returns: |
| 213 | * int |
| 214 | * |
| 215 | * |
| 216 | * Others: |
| 217 | ***************************************************************************/ |
| 218 | int Show_No_Battery(void) |
| 219 | { |
| 220 | int ret = 0; |
| 221 | /*led*/ |
| 222 | |
| 223 | /*lcd*/ |
| 224 | zDrvLcd_ShowNoBattery(); |
| 225 | ms_delay(100); |
| 226 | zDrvLcd_TurnBacklightOnOff(1); |
| 227 | // ret = zDrvLcdBlg_SetBlg(128); |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | /**************************************************************************** |
| 232 | * Function: Show_PowerOn_Normal |
| 233 | * Description: show the logo when the local updataing through lcd/led etc. |
| 234 | * Parameters: |
| 235 | * Input: |
| 236 | * |
| 237 | * Output: |
| 238 | * |
| 239 | * |
| 240 | * Returns: |
| 241 | * int |
| 242 | * |
| 243 | * |
| 244 | * Others: |
| 245 | ***************************************************************************/ |
| 246 | int Show_PowerOn_Normal(void) |
| 247 | { |
| 248 | int ret = 0; |
| 249 | /*led*/ |
| 250 | |
| 251 | /*lcd*/ |
| 252 | zDrvLcd_PowerOnLogo(); |
| 253 | ms_delay(100); |
| 254 | zDrvLcd_TurnBacklightOnOff(1); |
| 255 | // ret = zDrvLcdBlg_SetBlg(128); |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | /**************************************************************************** |
| 260 | * Function: Show_PowerOn_Fota |
| 261 | * Description: show the logo when the local updataing through lcd/led etc. |
| 262 | * Parameters: |
| 263 | * Input: |
| 264 | * |
| 265 | * Output: |
| 266 | * |
| 267 | * |
| 268 | * Returns: |
| 269 | * int |
| 270 | * |
| 271 | * |
| 272 | * Others: |
| 273 | ***************************************************************************/ |
| 274 | |
| 275 | int Show_PowerOn_Fota(void) |
| 276 | { |
| 277 | int ret = 0; |
| 278 | /*led*/ |
| 279 | |
| 280 | /*lcd*/ |
| 281 | zDrvLcd_ShowUpdateWait(); |
| 282 | ms_delay(100); |
| 283 | zDrvLcd_TurnBacklightOnOff(1); |
| 284 | // ret = zDrvLcdBlg_SetBlg(128); |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /**************************************************************************** |
| 290 | * Function: Show_Charging |
| 291 | * Description: show the logo when the local updataing through lcd/led etc. |
| 292 | * Parameters: |
| 293 | * Input: |
| 294 | * |
| 295 | * Output: |
| 296 | * |
| 297 | * |
| 298 | * Returns: |
| 299 | * int |
| 300 | * |
| 301 | * |
| 302 | * Others: |
| 303 | ***************************************************************************/ |
| 304 | int Show_Charging(void) |
| 305 | { |
| 306 | int ret = 0; |
| 307 | /*led*/ |
| 308 | |
| 309 | /*lcd*/ |
| 310 | zDrvLcd_PowerOnLogo(); |
| 311 | ms_delay(100); |
| 312 | zDrvLcd_TurnBacklightOnOff(1); |
| 313 | // ret = zDrvLcdBlg_SetBlg(128); |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | /**************************************************************************** |
| 318 | * Function: Show_PowerOn_Rtc |
| 319 | * Description: show the logo when the local updataing through lcd/led etc. |
| 320 | * Parameters: |
| 321 | * Input: |
| 322 | * |
| 323 | * Output: |
| 324 | * |
| 325 | * |
| 326 | * Returns: |
| 327 | * int |
| 328 | * |
| 329 | * |
| 330 | * Others: |
| 331 | ***************************************************************************/ |
| 332 | |
| 333 | int Show_PowerOn_Rtc(void) |
| 334 | { |
| 335 | int ret = 0; |
| 336 | /*led*/ |
| 337 | |
| 338 | /*lcd*/ |
| 339 | zDrvLcd_PowerOnLogo(); |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | /**************************************************************************** |
| 344 | * Function: zx_get_vbat_voltage |
| 345 | * Description: . |
| 346 | * Parameters: |
| 347 | * Input: |
| 348 | * |
| 349 | * Output: |
| 350 | * |
| 351 | * |
| 352 | * Returns: |
| 353 | * int |
| 354 | * |
| 355 | * |
| 356 | * Others: |
| 357 | ***************************************************************************/ |
| 358 | int zx_get_vbat_voltage(void) |
| 359 | { |
| 360 | // int ret = 0; |
| 361 | |
| 362 | return zx234290_get_adc1_voltage(); |
| 363 | } |
| 364 | |
| 365 | /**************************************************************************** |
| 366 | * Function: zx_get_battery_Status |
| 367 | * Description: |
| 368 | * Parameters: |
| 369 | * Input: |
| 370 | * |
| 371 | * Output: |
| 372 | * |
| 373 | * |
| 374 | * Returns: |
| 375 | * int |
| 376 | * |
| 377 | * |
| 378 | * Others: |
| 379 | ***************************************************************************/ |
| 380 | unsigned int zx_get_battery_Status(void) |
| 381 | { |
| 382 | #if 0 |
| 383 | int ret = 0; |
| 384 | int boost_flag = 1; |
| 385 | |
| 386 | zx234502_battery_status(&boost_flag); |
| 387 | if(boost_flag){ |
| 388 | return 0;/*battery uninstall*/ |
| 389 | } |
| 390 | else |
| 391 | return 1;/*battery install*/ |
| 392 | #else |
| 393 | int ret = 0; |
| 394 | int battery_status = 0; |
| 395 | |
| 396 | ret = zx234290_get_adc2_voltage(); |
| 397 | if (ret < 0) |
| 398 | { |
| 399 | printf("\t[zx234290_get_adc2_voltage] return [%d] in [%s]\n", ret, __FUNCTION__); |
| 400 | return ret; |
| 401 | } |
| 402 | |
| 403 | battery_status = (ret < 1700); |
| 404 | |
| 405 | #if 0 |
| 406 | if (battery_status) |
| 407 | printf("\t[%s] get %d and return battery connected\n", __FUNCTION__, ret); |
| 408 | else |
| 409 | printf("\t[%s] get %d and return battery disconnected\n", __FUNCTION__, ret); |
| 410 | #endif |
| 411 | |
| 412 | return battery_status; |
| 413 | #endif |
| 414 | } |