| 1 | /******************************************************************** |
|---|
| 2 | DHL_SYS_Impl.c |
|---|
| 3 | |
|---|
| 4 | PHOENIX Driver HAL library |
|---|
| 5 | System init/gpio/pinconfig implementation |
|---|
| 6 | |
|---|
| 7 | Copyright 2006 Digital STREAM Technology, Inc. |
|---|
| 8 | All Rights Reserved |
|---|
| 9 | |
|---|
| 10 | $Id: DHL_SYS.c v1.00 2006/04 cafrii Exp $ |
|---|
| 11 | |
|---|
| 12 | ********************************************************************/ |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "DHL_SYS_Impl.h" |
|---|
| 16 | //#include "DHL_IR_Impl.h" |
|---|
| 17 | #include "DHL_DBG.h" |
|---|
| 18 | #include "DHL_Timer.h" |
|---|
| 19 | //#include "DHL_Timer_Impl.h" |
|---|
| 20 | |
|---|
| 21 | #include "DHL_SYS.h" // for GPIO number |
|---|
| 22 | |
|---|
| 23 | //#include "DHL_OSAL.h" |
|---|
| 24 | //#include "DHL_SYS.h" |
|---|
| 25 | //#include "DHL_Debug.h" |
|---|
| 26 | //#include "DHL_FE.h" // FE version |
|---|
| 27 | //#include "DHL_Version.h" |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | //#include "projinc.h" |
|---|
| 31 | //#include "ministd.h" |
|---|
| 32 | #include "bsettop.h" |
|---|
| 33 | #include "bsettop_gpio.h" |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | #include "gist.h" |
|---|
| 37 | #include "bstd.h" |
|---|
| 38 | #include "bint.h" |
|---|
| 39 | #include "bgio.h" |
|---|
| 40 | #include "bcm_mips_defs.h" |
|---|
| 41 | #include "bchp_kbd1.h" |
|---|
| 42 | |
|---|
| 43 | #include "bchp_gio.h" |
|---|
| 44 | #include "bchp_irq0.h" |
|---|
| 45 | #include "bchp_sun_l2.h" |
|---|
| 46 | #include "bchp_hif_cpu_intr1.h" |
|---|
| 47 | #include "bchp_aio_misc.h" |
|---|
| 48 | #include "bchp_timer.h" |
|---|
| 49 | #include "bchp_misc.h" // for vdac control |
|---|
| 50 | #include "bchp_sun_top_ctrl.h" |
|---|
| 51 | #include "bchp_memc_misc_0.h" |
|---|
| 52 | #include "birw.h" //standby |
|---|
| 53 | #include "bchp_aon_ctrl.h" |
|---|
| 54 | #include "bchp_aon_pm_l2.h" |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | #if COMMENT |
|---|
| 58 | ____Config____(){} |
|---|
| 59 | #endif |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | //--------------------------------------------------------------- |
|---|
| 63 | // CONFIG MACRO |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | #define SCRATCH_CMD_BASE BCHP_MEMC_MISC_0_SCRATCH_0 |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | //--------------------------------------------------------------- |
|---|
| 72 | // GLOBAL |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | #define GPIO_IRQ_MASK(n) (((n) >= 0 && (n) <= 31) ? (1 << (n)) : 0) |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | #if COMMENT |
|---|
| 79 | ____Var____(){} |
|---|
| 80 | #endif |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | typedef enum |
|---|
| 84 | { |
|---|
| 85 | eDHL_IN_INVALID, |
|---|
| 86 | |
|---|
| 87 | eDHL_IN_POWER, |
|---|
| 88 | eDHL_IN_CHDN, |
|---|
| 89 | eDHL_IN_CHUP, |
|---|
| 90 | eDHL_IN_RFM, |
|---|
| 91 | |
|---|
| 92 | eDHL_IN_WAKEUP, |
|---|
| 93 | // generic wakeup message. |
|---|
| 94 | eDHL_IN_WAKEUP_POWER, |
|---|
| 95 | // special wakeup message about power button. |
|---|
| 96 | // power button is special case. we cannot read its state at any time. |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | } DHL_GIO_MSGTYPE; |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | typedef struct |
|---|
| 103 | { |
|---|
| 104 | DHL_GIO_MSGTYPE type; |
|---|
| 105 | //UINT32 mstick; |
|---|
| 106 | UINT32 cputick; // cafrii 081006, mstick may not be correct for checking time gap. |
|---|
| 107 | |
|---|
| 108 | } DHL_GIO_MSG; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | DHL_OS_MSGQ_ID g_gpio_qid; |
|---|
| 112 | DHL_OS_TASK_ID g_gpio_tid; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | // user callback |
|---|
| 117 | // |
|---|
| 118 | void (*g_dhl_sys_cb_func)(int type, UINT32 userparam, UINT32 state); |
|---|
| 119 | UINT32 g_dhl_sys_cb_param; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | int g_Trace_bDHLGpio; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | #if COMMENT |
|---|
| 127 | ____ISR____(){} |
|---|
| 128 | #endif |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | #if 0 |
|---|
| 132 | static void dhl_isr_gpio(void *data) |
|---|
| 133 | { |
|---|
| 134 | /* |
|---|
| 135 | in normal state, button gpio is pulled down (0V). |
|---|
| 136 | if button (ch+,ch-) is pressed, it will be pulled up. (3V). |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | pressed released |
|---|
| 140 | +------+ |
|---|
| 141 | | | |
|---|
| 142 | ----+ +---------- |
|---|
| 143 | |
|---|
| 144 | gpio isr is programmed as falling-edge triggerred. |
|---|
| 145 | |
|---|
| 146 | */ |
|---|
| 147 | |
|---|
| 148 | // read gpio interrupt status. (not data) |
|---|
| 149 | unsigned int status = ReadReg32(BCHP_GIO_STAT_LO); |
|---|
| 150 | |
|---|
| 151 | UINT32 mask = GPIO_IRQ_MASK(GPIO_CH_DN) | GPIO_IRQ_MASK(GPIO_CH_UP) | GPIO_IRQ_MASK(GPIO_CH34_SW_IN); |
|---|
| 152 | DHL_GIO_MSG msg; |
|---|
| 153 | int err; |
|---|
| 154 | |
|---|
| 155 | //printf("isr: gpio stat %08x\n", status); |
|---|
| 156 | |
|---|
| 157 | if (status & mask) |
|---|
| 158 | { |
|---|
| 159 | //msg.mstick = dhl_sys_get_ms_tick(); |
|---|
| 160 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 161 | msg.type = eDHL_IN_INVALID; |
|---|
| 162 | |
|---|
| 163 | if (status & (1 << GPIO_CH_DN)) { |
|---|
| 164 | //printf("isr: ch dn %d\n", dhl_sys_gpio_rw(GPIO_CH_DN, 0, 0)); |
|---|
| 165 | msg.type = eDHL_IN_CHDN; |
|---|
| 166 | } |
|---|
| 167 | else if (status & (1 << GPIO_CH_UP)) { |
|---|
| 168 | //printf("isr: ch up\n", dhl_sys_gpio_rw(GPIO_CH_UP, 0, 0)); |
|---|
| 169 | msg.type = eDHL_IN_CHUP; |
|---|
| 170 | } |
|---|
| 171 | else if (status & (1 << GPIO_CH34_SW_IN)) { |
|---|
| 172 | //printf("isr: ch %d\n", dhl_sys_gpio_rw(GPIO_CH34_SW_IN, 0, 0) ? 4 : 3); |
|---|
| 173 | msg.type = eDHL_IN_RFM; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | if (msg.type != eDHL_IN_INVALID) { |
|---|
| 177 | err = DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 178 | if (err) |
|---|
| 179 | printf("!! send msg err %d\n", err); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | WriteReg32(BCHP_GIO_STAT_LO, status); /* Reset status */ |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | #endif |
|---|
| 186 | #if 0 |
|---|
| 187 | static void dhl_isr_power_button(void *data) |
|---|
| 188 | { |
|---|
| 189 | /* |
|---|
| 190 | in normal state, power button is pulled down (0V). |
|---|
| 191 | if button is pressed, it will be pulled up. (3V). |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | pressed released |
|---|
| 195 | +------+ |
|---|
| 196 | | | |
|---|
| 197 | ----+ +---------- |
|---|
| 198 | |
|---|
| 199 | power button cannot be accessed using gpio. |
|---|
| 200 | power button isr is programmed as rising-edge triggerred and it is fixed!! |
|---|
| 201 | |
|---|
| 202 | */ |
|---|
| 203 | unsigned int status = ReadReg32(BCHP_SUN_L2_CPU_STATUS); |
|---|
| 204 | DHL_GIO_MSG msg; |
|---|
| 205 | |
|---|
| 206 | if (status & BCHP_SUN_L2_CPU_STATUS_AUX_INTR_MASK) |
|---|
| 207 | { |
|---|
| 208 | //printf("isr: power_btn\n"); |
|---|
| 209 | //msg.mstick = dhl_sys_get_ms_tick(); |
|---|
| 210 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 211 | msg.type = eDHL_IN_POWER; |
|---|
| 212 | DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 213 | } |
|---|
| 214 | WriteReg32(BCHP_SUN_L2_CPU_CLEAR,status); /* Reset status */ |
|---|
| 215 | } |
|---|
| 216 | #endif |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | #if COMMENT |
|---|
| 220 | ____GpioDpc____(){} |
|---|
| 221 | #endif |
|---|
| 222 | |
|---|
| 223 | void dhl_gpio_wakeup_proc(UINT32 nIDTimer, UINT32 param) |
|---|
| 224 | { |
|---|
| 225 | if (nIDTimer == eDHL_TIMER_GPIO_DPC) |
|---|
| 226 | { |
|---|
| 227 | DHL_GIO_MSG msg; |
|---|
| 228 | msg.type = param == eDHL_IN_POWER ? eDHL_IN_WAKEUP_POWER : eDHL_IN_WAKEUP; |
|---|
| 229 | //msg.mstick = dhl_sys_get_ms_tick(); |
|---|
| 230 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 231 | |
|---|
| 232 | //printf("gpio wakeup %d\n", param); |
|---|
| 233 | DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | void dhl_gpio_dpc(DHL_OS_MSGQ_ID qid) |
|---|
| 239 | { |
|---|
| 240 | int r; |
|---|
| 241 | DHL_GIO_MSG msg; |
|---|
| 242 | // int msgLen; |
|---|
| 243 | |
|---|
| 244 | // static int prev_button_state = eDHL_IN_INVALID; |
|---|
| 245 | // static BOOL prev_switch_state; |
|---|
| 246 | |
|---|
| 247 | // int state; |
|---|
| 248 | |
|---|
| 249 | if (g_Trace_bDHLGpio) |
|---|
| 250 | printf("gpio dpc task start. qid %x\n", qid); |
|---|
| 251 | |
|---|
| 252 | while (1) |
|---|
| 253 | { |
|---|
| 254 | // qid == g_gpio_qid |
|---|
| 255 | |
|---|
| 256 | r = DHL_OS_ReceiveMessage(qid, &msg, DHL_TIMEOUT_FOREVER); |
|---|
| 257 | |
|---|
| 258 | if (r != 0) { |
|---|
| 259 | printf("!! gpio_dpc: msg get err %d\n", r); |
|---|
| 260 | DHL_OS_Delay(DHL_OS_GetTicksPerSecond()); |
|---|
| 261 | continue; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | //printf("gpio_dpc: msg %x\n", msg); |
|---|
| 265 | |
|---|
| 266 | // to avoid false input by glitch noise, |
|---|
| 267 | // we program 2nd dpc using timer. |
|---|
| 268 | // 10 ms is enough. |
|---|
| 269 | |
|---|
| 270 | if (0); |
|---|
| 271 | else if (msg.type == eDHL_IN_CHDN) |
|---|
| 272 | { |
|---|
| 273 | //printf("gpio_dpc: chdn %d, tick %d\n", dhl_sys_gpio_rw(GPIO_CH_DN, 0, 0), msg.mstick); |
|---|
| 274 | DHL_SYS_StartTimer(eDHL_TIMER_GPIO_DPC, 10, dhl_gpio_wakeup_proc, eDHL_IN_CHDN, TRUE); |
|---|
| 275 | } |
|---|
| 276 | else if (msg.type == eDHL_IN_CHUP) |
|---|
| 277 | { |
|---|
| 278 | //printf("gpio_dpc: chup %d, tick %d\n", dhl_sys_gpio_rw(GPIO_CH_UP, 0, 0), msg.mstick); |
|---|
| 279 | DHL_SYS_StartTimer(eDHL_TIMER_GPIO_DPC, 10, dhl_gpio_wakeup_proc, eDHL_IN_CHUP, TRUE); |
|---|
| 280 | } |
|---|
| 281 | else if (msg.type == eDHL_IN_RFM) |
|---|
| 282 | { |
|---|
| 283 | //printf("gpio_dpc: rfm %d, tick %d\n", dhl_sys_gpio_rw(GPIO_CH34_SW_IN, 0, 0), msg.mstick); |
|---|
| 284 | DHL_SYS_StartTimer(eDHL_TIMER_GPIO_DPC, 10, dhl_gpio_wakeup_proc, eDHL_IN_RFM, TRUE); |
|---|
| 285 | } |
|---|
| 286 | else if (msg.type == eDHL_IN_POWER) |
|---|
| 287 | { |
|---|
| 288 | //printf("gpio_dpc: power, tick %d\n", msg.mstick); |
|---|
| 289 | DHL_SYS_StartTimer(eDHL_TIMER_GPIO_DPC, 10, dhl_gpio_wakeup_proc, eDHL_IN_POWER, TRUE); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | else if (msg.type == eDHL_IN_WAKEUP || msg.type == eDHL_IN_WAKEUP_POWER) |
|---|
| 293 | { |
|---|
| 294 | if (msg.type == eDHL_IN_WAKEUP_POWER) |
|---|
| 295 | { |
|---|
| 296 | dhl_sys_notify_callback(eDHL_SYS_CB_POWER, 0); |
|---|
| 297 | } |
|---|
| 298 | #if 0//BKCHECK - °¢°¢ÀÇ callback¿¡¼ Á÷Á¢ ³Ñ±âµµ·Ï ÇÔ. |
|---|
| 299 | // this is order of button priority. |
|---|
| 300 | // |
|---|
| 301 | if (dhl_sys_gpio_rw(GPIO_CH_UP, 0, 0)) { |
|---|
| 302 | state = GPIO_CH_UP; |
|---|
| 303 | } |
|---|
| 304 | else if (dhl_sys_gpio_rw(GPIO_CH_DN, 0, 0)) { |
|---|
| 305 | state = GPIO_CH_DN; |
|---|
| 306 | } |
|---|
| 307 | else { |
|---|
| 308 | state = 0; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | if (state != prev_button_state) // if state is changed, |
|---|
| 312 | { |
|---|
| 313 | // |
|---|
| 314 | printf("=== button state changed, %d\n", state); |
|---|
| 315 | prev_button_state = state; |
|---|
| 316 | |
|---|
| 317 | // send message.. |
|---|
| 318 | // at first, send ir task for repeat processing. |
|---|
| 319 | dhl_ir_send_button_message(state); |
|---|
| 320 | } |
|---|
| 321 | #endif |
|---|
| 322 | #if 0//BKTODO: |
|---|
| 323 | state = dhl_sys_gpio_rw(GPIO_CH34_SW_IN, 0, 0); |
|---|
| 324 | |
|---|
| 325 | if (state != prev_switch_state) |
|---|
| 326 | { |
|---|
| 327 | printf("**** switch state changed, %d\n", state); |
|---|
| 328 | prev_switch_state = state; |
|---|
| 329 | |
|---|
| 330 | // gpio value 0: ch 3 |
|---|
| 331 | // gpio value 1: ch 4 |
|---|
| 332 | // |
|---|
| 333 | dhl_sys_notify_callback(eDHL_SYS_CB_RFM, state ? 4 : 3); |
|---|
| 334 | } |
|---|
| 335 | #endif |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | void dhl_init_gpio_dpc() |
|---|
| 343 | { |
|---|
| 344 | g_gpio_qid = DHL_OS_CreateMessageQueue("gpio", 0, 20, sizeof(DHL_GIO_MSG)); |
|---|
| 345 | if (g_gpio_qid == 0) { |
|---|
| 346 | printf("!! ir queue create err\n"); |
|---|
| 347 | return; |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | g_gpio_tid = DHL_OS_CreateTask((OS_TASKFUNCTION)dhl_gpio_dpc, "gpio", TASK_PRI_DRV_GPIO, 4096, |
|---|
| 351 | (SINT32)g_gpio_qid); |
|---|
| 352 | if (g_gpio_tid == 0) { |
|---|
| 353 | printf("!! ir task create err\n"); |
|---|
| 354 | return; |
|---|
| 355 | } |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | #if COMMENT |
|---|
| 360 | ____GPIO____(){} |
|---|
| 361 | #endif |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | //--------------------------------------------------------------- |
|---|
| 367 | // GPIO Table |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | #if 0 |
|---|
| 371 | |
|---|
| 372 | #define GPIO_PIN_DEF(p) #p, p |
|---|
| 373 | |
|---|
| 374 | DHL_GPIO_DESC s_dhl_config_table[] = |
|---|
| 375 | { |
|---|
| 376 | //name/gpio#/pad#, reset_LH, PinMode, PinParam |
|---|
| 377 | // |
|---|
| 378 | { GPIO_PIN_DEF(GPIO_LED_GREEN), NON_RESET_PIN, GPIO_DIR_OUTPUT, PIN_OUTPUT_LOW, 0, 0 }, |
|---|
| 379 | { GPIO_PIN_DEF(GPIO_CH_DN), NON_RESET_PIN, GPIO_DIR_INPUT, PIN_OUTPUT_NONE, 0, 0 }, |
|---|
| 380 | { GPIO_PIN_DEF(GPIO_CH_UP), NON_RESET_PIN, GPIO_DIR_INPUT, PIN_OUTPUT_NONE, 0, 0 }, |
|---|
| 381 | { GPIO_PIN_DEF(GPIO_CH34_SW_IN), NON_RESET_PIN, GPIO_DIR_INPUT, PIN_OUTPUT_NONE, 0, 0 }, |
|---|
| 382 | { GPIO_PIN_DEF(GPIO_PATH_CONTROL), NON_RESET_PIN, GPIO_DIR_OUTPUT, PIN_OUTPUT_LOW, 0, 0 }, |
|---|
| 383 | //{ GPIO_PIN_DEF(GPIO_FLASH_WP), NON_RESET_PIN, GPIO_DIR_INPUT, PIN_OUTPUT_NONE, 0, 0 }, |
|---|
| 384 | |
|---|
| 385 | }; |
|---|
| 386 | |
|---|
| 387 | int s_dhl_max_num_gpio = sizeof(s_dhl_config_table)/sizeof(DHL_GPIO_DESC); |
|---|
| 388 | |
|---|
| 389 | #endif |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | /* |
|---|
| 393 | configure initial gpio setting. |
|---|
| 394 | |
|---|
| 395 | refer buser_input_open() in bsettop_user_io.c. |
|---|
| 396 | |
|---|
| 397 | */ |
|---|
| 398 | |
|---|
| 399 | BGIO_Pin_Handle hPinMute; |
|---|
| 400 | BGIO_Pin_Handle hPinChU; |
|---|
| 401 | BGIO_Pin_Handle hPinChD; |
|---|
| 402 | BGIO_Pin_Handle hPinChP; |
|---|
| 403 | |
|---|
| 404 | static bgpio_t gpioHandle_P; |
|---|
| 405 | static bgpio_t gpioHandle_CHU; |
|---|
| 406 | static bgpio_t gpioHandle_CHD; |
|---|
| 407 | static BGIO_Pin_Handle pinLED_R = NULL; |
|---|
| 408 | static BGIO_Pin_Handle pinLED_G = NULL; |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | #define BUTTON_KEY_UP 0 |
|---|
| 412 | #define BUTTON_KEY_DOWN 1 |
|---|
| 413 | #define BUTTON_KEY_POWER 2 |
|---|
| 414 | #define BUTTON_KEY_EXIT 3/*janzy@20121115,OSD TimeOut*/ |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | static void dhl_isr_power_button(void *context) |
|---|
| 419 | { |
|---|
| 420 | BGIO_PinValue PinValue; |
|---|
| 421 | BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context; |
|---|
| 422 | DHL_GIO_MSG msg; |
|---|
| 423 | |
|---|
| 424 | if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0) |
|---|
| 425 | { |
|---|
| 426 | if(PinValue == BGIO_PinValue_e0) |
|---|
| 427 | { |
|---|
| 428 | //printf("isr: power_btn\n"); |
|---|
| 429 | //msg.mstick = dhl_sys_get_ms_tick(); |
|---|
| 430 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 431 | msg.type = eDHL_IN_POWER; |
|---|
| 432 | DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | static void aov_ChannelUpButton_callback(void *context) |
|---|
| 438 | { |
|---|
| 439 | BGIO_PinValue PinValue; |
|---|
| 440 | BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context; |
|---|
| 441 | // DHL_GIO_MSG msg; |
|---|
| 442 | int state; |
|---|
| 443 | |
|---|
| 444 | if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0) |
|---|
| 445 | { |
|---|
| 446 | if(PinValue == BGIO_PinValue_e0) |
|---|
| 447 | { |
|---|
| 448 | #if 0// |
|---|
| 449 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 450 | msg.type = eDHL_IN_CHUP; |
|---|
| 451 | DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 452 | #else |
|---|
| 453 | state = GPIO_CH_UP; |
|---|
| 454 | //BKTODO: dhl_ir_send_button_message(state); |
|---|
| 455 | #endif |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | } |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | static void aov_ChannelDownButton_callback(void *context) |
|---|
| 463 | { |
|---|
| 464 | BGIO_PinValue PinValue; |
|---|
| 465 | BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context; |
|---|
| 466 | // DHL_GIO_MSG msg; |
|---|
| 467 | int state; |
|---|
| 468 | |
|---|
| 469 | if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0) |
|---|
| 470 | { |
|---|
| 471 | if(PinValue == BGIO_PinValue_e0) |
|---|
| 472 | { |
|---|
| 473 | #if 0 |
|---|
| 474 | msg.cputick = dhl_sys_get_cpu_tick(); |
|---|
| 475 | msg.type = eDHL_IN_CHDN; |
|---|
| 476 | DHL_OS_SendMessage(g_gpio_qid, &msg, sizeof(msg)); |
|---|
| 477 | #else |
|---|
| 478 | state = GPIO_CH_DN; |
|---|
| 479 | //BKTODO: dhl_ir_send_button_message(state); |
|---|
| 480 | |
|---|
| 481 | #endif |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | } |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | #ifndef WriteReg32 |
|---|
| 488 | #define WriteReg32(reg,val) BREG_Write32(GetREG(),reg,val) |
|---|
| 489 | #endif |
|---|
| 490 | #ifndef ReadReg32 |
|---|
| 491 | #define ReadReg32(reg) BREG_Read32(GetREG(),reg) |
|---|
| 492 | #endif |
|---|
| 493 | |
|---|
| 494 | static DHL_RESULT dhl_sys_gpio_init(void) |
|---|
| 495 | { |
|---|
| 496 | |
|---|
| 497 | bgpio_settings gpio_settings; |
|---|
| 498 | BERR_Code err; |
|---|
| 499 | uint32_t value; |
|---|
| 500 | |
|---|
| 501 | if (g_Trace_bDHLGpio) |
|---|
| 502 | printf("%s: start \n", __FUNCTION__); |
|---|
| 503 | |
|---|
| 504 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eGpio118,&hPinMute); |
|---|
| 505 | if (err != BERR_SUCCESS) |
|---|
| 506 | { |
|---|
| 507 | hPinMute = NULL; |
|---|
| 508 | printf("BGIO_PinId_eGpio118 Fail\n"); |
|---|
| 509 | return DHL_FAIL; |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | BGIO_Pin_SetType(hPinMute,BGIO_PinType_ePushPull); |
|---|
| 513 | BGIO_Pin_PushPull_SetValue(hPinMute,BGIO_PinValue_e1); |
|---|
| 514 | |
|---|
| 515 | value = ReadReg32(BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8); |
|---|
| 516 | value &= ~BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_MASK; |
|---|
| 517 | value |= (BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_PULL_UP << BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_SHIFT); |
|---|
| 518 | WriteReg32(BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8, value); |
|---|
| 519 | |
|---|
| 520 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio06,&hPinChU); |
|---|
| 521 | if (err != BERR_SUCCESS) |
|---|
| 522 | { |
|---|
| 523 | hPinChU = NULL; |
|---|
| 524 | printf("BGIO_PinId_eAgpio05 Fail\n"); |
|---|
| 525 | return DHL_FAIL; |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio05,&hPinChD); |
|---|
| 529 | if (err != BERR_SUCCESS) |
|---|
| 530 | { |
|---|
| 531 | hPinChD = NULL; |
|---|
| 532 | printf("BGIO_PinId_eAgpio06 Fail\n"); |
|---|
| 533 | return DHL_FAIL; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio07,&hPinChP); |
|---|
| 537 | if (err != BERR_SUCCESS) |
|---|
| 538 | { |
|---|
| 539 | hPinChP = NULL; |
|---|
| 540 | printf("BGIO_PinId_eAgpio07 Fail\n"); |
|---|
| 541 | return DHL_FAIL; |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | gpio_settings.type = eGPIO_AStandard; |
|---|
| 546 | gpio_settings.mode = eGPIO_Input; |
|---|
| 547 | gpio_settings.intMode = eGPIO_Edge; |
|---|
| 548 | gpio_settings.user_callback = dhl_isr_power_button; |
|---|
| 549 | gpio_settings.user_callback_context = hPinChP; |
|---|
| 550 | gpioHandle_P = bgpio_open(BGIO_PinId_eAgpio07, &gpio_settings); |
|---|
| 551 | |
|---|
| 552 | gpio_settings.user_callback = aov_ChannelUpButton_callback; |
|---|
| 553 | gpio_settings.user_callback_context = hPinChU; |
|---|
| 554 | gpioHandle_CHU = bgpio_open(BGIO_PinId_eAgpio06, &gpio_settings); |
|---|
| 555 | |
|---|
| 556 | gpio_settings.user_callback = aov_ChannelDownButton_callback; |
|---|
| 557 | gpio_settings.user_callback_context = hPinChD; |
|---|
| 558 | gpioHandle_CHD = bgpio_open(BGIO_PinId_eAgpio05, &gpio_settings); |
|---|
| 559 | |
|---|
| 560 | //LED AON GPIO |
|---|
| 561 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio04,&pinLED_R); |
|---|
| 562 | if (err != BERR_SUCCESS) |
|---|
| 563 | { |
|---|
| 564 | printf("BGIO_PinId_eAgpio04 Fail\n"); |
|---|
| 565 | return DHL_FAIL; |
|---|
| 566 | } |
|---|
| 567 | err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio09,&pinLED_G); |
|---|
| 568 | if (err != BERR_SUCCESS) |
|---|
| 569 | { |
|---|
| 570 | printf("BGIO_PinId_eAgpio09 Fail\n"); |
|---|
| 571 | return DHL_FAIL; |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | BGIO_Pin_SetType(pinLED_R,BGIO_PinType_ePushPull); |
|---|
| 575 | BGIO_Pin_SetType(pinLED_G,BGIO_PinType_ePushPull); |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | // dhl_sys_gpio_rw(GPIO_LED_GREEN, TRUE, TRUE); |
|---|
| 579 | // dhl_sys_gpio_rw(GPIO_AUDIO_UNMUTE, TRUE, TRUE); |
|---|
| 580 | |
|---|
| 581 | // dhl_sys_gpio_config(GPIO_LED_GREEN, DHL_GPIO_OUTPUT, 1); // turn on green led. |
|---|
| 582 | // dhl_sys_gpio_config(GPIO_AUDIO_UNMUTE, DHL_GPIO_OUTPUT, 1); // unmute audio. |
|---|
| 583 | |
|---|
| 584 | return DHL_OK; |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | /* |
|---|
| 590 | read/write internal api. |
|---|
| 591 | |
|---|
| 592 | read: |
|---|
| 593 | data = dhl_sys_gpio_rw(num, 0, 0); |
|---|
| 594 | write: |
|---|
| 595 | dhl_sys_gpio_rw(num, value, 1); |
|---|
| 596 | */ |
|---|
| 597 | int dhl_sys_gpio_rw(UINT32 num, int bData, BOOL bWrite) |
|---|
| 598 | { |
|---|
| 599 | #if 1// |
|---|
| 600 | if(bWrite) |
|---|
| 601 | { |
|---|
| 602 | if(num == GPIO_LED_GREEN) |
|---|
| 603 | { |
|---|
| 604 | if(bData) |
|---|
| 605 | BGIO_Pin_PushPull_SetValue(pinLED_G,BGIO_PinValue_e1); |
|---|
| 606 | else |
|---|
| 607 | BGIO_Pin_PushPull_SetValue(pinLED_G,BGIO_PinValue_e0); |
|---|
| 608 | }else if(num == GPIO_LED_RED) |
|---|
| 609 | { |
|---|
| 610 | if(bData) |
|---|
| 611 | BGIO_Pin_PushPull_SetValue(pinLED_R,BGIO_PinValue_e1); |
|---|
| 612 | else |
|---|
| 613 | BGIO_Pin_PushPull_SetValue(pinLED_R,BGIO_PinValue_e0); |
|---|
| 614 | }else if(num == GPIO_AUDIO_MUTE) |
|---|
| 615 | { |
|---|
| 616 | if(bData) |
|---|
| 617 | BGIO_Pin_PushPull_SetValue(hPinMute,BGIO_PinValue_e1); |
|---|
| 618 | else |
|---|
| 619 | BGIO_Pin_PushPull_SetValue(hPinMute,BGIO_PinValue_e0); |
|---|
| 620 | }else |
|---|
| 621 | { |
|---|
| 622 | printf("!! check gpio %d is not available to write\n", num); |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | }else |
|---|
| 626 | { |
|---|
| 627 | { |
|---|
| 628 | printf("!! check gpio %d is not available to read\n", num); |
|---|
| 629 | } |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | return 0; |
|---|
| 633 | |
|---|
| 634 | #else//org |
|---|
| 635 | UINT32 flag; |
|---|
| 636 | UINT32 reg, mask; |
|---|
| 637 | UINT32 value; |
|---|
| 638 | |
|---|
| 639 | if (g_Trace_bDHLGpio) |
|---|
| 640 | printf("%s: %d %d %d\n", __FUNCTION__, num, bData, bWrite); |
|---|
| 641 | |
|---|
| 642 | if (num <= 31) { // GPIO LO |
|---|
| 643 | reg = BCHP_GIO_DATA_LO; |
|---|
| 644 | mask = (1 << num); |
|---|
| 645 | } |
|---|
| 646 | else if (num <= 46) { // GPIO HI |
|---|
| 647 | reg = BCHP_GIO_DATA_HI; |
|---|
| 648 | mask = (1 << (num - 32)); |
|---|
| 649 | } |
|---|
| 650 | else { |
|---|
| 651 | printf("!! %s: gpio num %d invalid\n", __FUNCTION__, num); |
|---|
| 652 | return -1; // gpio num is invalid. |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | flag = bos_enter_critical(); // replace this with OSAL api.. |
|---|
| 656 | value = ReadReg32(reg); |
|---|
| 657 | |
|---|
| 658 | if (bWrite) { |
|---|
| 659 | if (bData) { |
|---|
| 660 | WriteReg32(reg, (value | mask)); |
|---|
| 661 | } |
|---|
| 662 | else { |
|---|
| 663 | WriteReg32(reg, (value & ~mask)); |
|---|
| 664 | } |
|---|
| 665 | } |
|---|
| 666 | bos_exit_critical(flag); // replace this with OSAL api.. |
|---|
| 667 | |
|---|
| 668 | if (g_Trace_bDHLGpio) |
|---|
| 669 | printf("old value: 0x%x\n", value); |
|---|
| 670 | |
|---|
| 671 | return ((value & mask) ? 1 : 0); |
|---|
| 672 | #endif |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | #if 0 |
|---|
| 676 | /* |
|---|
| 677 | RED led is not under control by GPIO. |
|---|
| 678 | so, provide special routines. |
|---|
| 679 | */ |
|---|
| 680 | void dhl_sys_set_red_led(int bOn) |
|---|
| 681 | { |
|---|
| 682 | // for green led, use gpio api. |
|---|
| 683 | // ex: dhl_sys_gpio_rw(GPIO_LED_GREEN, 1, TRUE); |
|---|
| 684 | |
|---|
| 685 | // red color is controlled by wake-up module, not GPIO. |
|---|
| 686 | |
|---|
| 687 | if (bOn) { |
|---|
| 688 | // turn on red led. |
|---|
| 689 | WriteReg32(BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1, ReadReg32( BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1) | |
|---|
| 690 | BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1_irw_top_sw_led_cntrl_MASK); |
|---|
| 691 | } |
|---|
| 692 | else { |
|---|
| 693 | // turn off red led. |
|---|
| 694 | WriteReg32(BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1, ReadReg32( BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1) & |
|---|
| 695 | ~BCHP_SUN_TOP_CTRL_GENERAL_CTRL_1_irw_top_sw_led_cntrl_MASK); |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | #endif |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | #if COMMENT |
|---|
| 703 | ____SysControl____(){} |
|---|
| 704 | #endif |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | /* |
|---|
| 708 | reboot system. |
|---|
| 709 | |
|---|
| 710 | boot_cmd: |
|---|
| 711 | #define DHL_BOOTCMD_DOWNLOAD 0x1 |
|---|
| 712 | #define DHL_BOOTCMD_FUPDATE 0x2 |
|---|
| 713 | */ |
|---|
| 714 | void dhl_sys_reset(int boot_cmd) |
|---|
| 715 | { |
|---|
| 716 | //BKTODO: test needed |
|---|
| 717 | //BKNOTE: bcm_main()ÁÖ¼Ò·Î ÇØ¾ß ¿ÇÀºµ¥, À̹ÌÁö ¾÷µ¥ÀÌÆ® µÇ´Â °æ¿ì flash¿¡¼ ´Ù½Ã ÀоîµéÀÏ Çʿ䰡 ÀÖÀ½.. |
|---|
| 718 | #define START_S2_ADDR 0x80001000//__start_s2 (bootloader7574/bls2.S) |
|---|
| 719 | uint32_t val; |
|---|
| 720 | |
|---|
| 721 | void (*system_boot)(); |
|---|
| 722 | |
|---|
| 723 | system_boot = (void (*)())START_S2_ADDR; |
|---|
| 724 | |
|---|
| 725 | bos_sleep(100); |
|---|
| 726 | bos_enter_critical(); // disable interrupt.. |
|---|
| 727 | |
|---|
| 728 | /* clear KBD1 interrupt */ |
|---|
| 729 | val = BREG_Read32(GetREG(), BCHP_KBD1_STATUS); |
|---|
| 730 | val &= ~BCHP_KBD1_STATUS_irq_MASK; |
|---|
| 731 | BREG_Write32(GetREG(), BCHP_KBD1_STATUS, val); |
|---|
| 732 | |
|---|
| 733 | /* clear reset history */ |
|---|
| 734 | BREG_Write32(GetREG(), BCHP_AON_CTRL_RESET_CTRL, BCHP_AON_CTRL_RESET_CTRL_clear_reset_history_MASK); |
|---|
| 735 | |
|---|
| 736 | /* reset wake up device */ |
|---|
| 737 | BREG_Write32(GetREG(), BCHP_AON_PM_L2_CPU_MASK_SET, 0xFFFFFFFF); |
|---|
| 738 | BREG_Write32(GetREG(), BCHP_AON_PM_L2_CPU_CLEAR, 0xFFFFFFF); |
|---|
| 739 | |
|---|
| 740 | system_boot(); |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | /* |
|---|
| 744 | test code.. |
|---|
| 745 | jump to specific address. |
|---|
| 746 | |
|---|
| 747 | Shell> dhl_sys_jump 1234 |
|---|
| 748 | --> exception vector occurrs repeatedly |
|---|
| 749 | |
|---|
| 750 | */ |
|---|
| 751 | void dhl_sys_jump(UINT32 addr) |
|---|
| 752 | { |
|---|
| 753 | bos_enter_critical(); |
|---|
| 754 | ((void (*)())addr)(); |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | /* |
|---|
| 758 | go into standby mode. |
|---|
| 759 | |
|---|
| 760 | */ |
|---|
| 761 | void dhl_sys_standby(void) |
|---|
| 762 | { |
|---|
| 763 | b_s3_standby(USERIO_ID); |
|---|
| 764 | /* don't switch task, experimental till figure out the issue */ |
|---|
| 765 | while (1); |
|---|
| 766 | |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | UINT32 dhl_sys_get_clock_freq(int type) |
|---|
| 771 | { |
|---|
| 772 | extern unsigned int calc_mips_freq(void); // in bos.c |
|---|
| 773 | // actually, this is NOT mips freq. this is mips clock counter freq. |
|---|
| 774 | // clock counter freq is half of mips freq. |
|---|
| 775 | |
|---|
| 776 | if (type == 0) // cpu clock |
|---|
| 777 | return (calc_mips_freq() * 2); |
|---|
| 778 | #if 0//BKTODO: |
|---|
| 779 | if (type == 1) // ddr clock |
|---|
| 780 | { |
|---|
| 781 | UINT32 val; |
|---|
| 782 | UINT32 ddr_speed[4] = { 166000000, 200000000, 125000000, 142000000, }; |
|---|
| 783 | |
|---|
| 784 | val = ReadReg32(BCHP_SUN_TOP_CTRL_STRAP_VALUE_0); |
|---|
| 785 | val = BCHP_GET_FIELD_DATA(val, SUN_TOP_CTRL_STRAP_VALUE_0, strap_ddr_speed); |
|---|
| 786 | |
|---|
| 787 | return ddr_speed[val & 3]; |
|---|
| 788 | } |
|---|
| 789 | #else |
|---|
| 790 | printf("BKTODO: not yet dhl_sys_get_clock_freq() DDR\n"); |
|---|
| 791 | #endif |
|---|
| 792 | return 0; // invalid.. |
|---|
| 793 | |
|---|
| 794 | } |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | UINT32 dhl_sys_get_cpu_tick(void) |
|---|
| 798 | { |
|---|
| 799 | return bcm_read_cp0($9,0); |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | UINT32 dhl_sys_cpu_ticks_per_ms(void) |
|---|
| 803 | { |
|---|
| 804 | static UINT32 divider; |
|---|
| 805 | |
|---|
| 806 | if (divider == 0) |
|---|
| 807 | divider = dhl_sys_get_clock_freq(0)/2/1000; |
|---|
| 808 | |
|---|
| 809 | return divider; |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | /* |
|---|
| 814 | note!! |
|---|
| 815 | allowed range for ms tick is : |
|---|
| 816 | 0xffffffff/108000 = 39768 ms. |
|---|
| 817 | |
|---|
| 818 | and 32bit integer is not multiple of 108000. |
|---|
| 819 | so, when wrap around occurs, timing is not correct. |
|---|
| 820 | do not use this api.. |
|---|
| 821 | |
|---|
| 822 | 39767 -> 39768 -> 0 -> 1 -> .. |
|---|
| 823 | ^ ^ ^ ^ |
|---|
| 824 | |<------>|<----->|<------>| |
|---|
| 825 | =1 ms <1ms =1ms |
|---|
| 826 | |
|---|
| 827 | */ |
|---|
| 828 | #if 0 |
|---|
| 829 | static UINT32 g_dhl_tick_high, g_dhl_tick_low; |
|---|
| 830 | #endif |
|---|
| 831 | |
|---|
| 832 | UINT32 dhl_sys_get_ms_tick(void) |
|---|
| 833 | { |
|---|
| 834 | // do not use this function for checking timing gap!! |
|---|
| 835 | // use dhl_sys_get_cpu_tick() directly. |
|---|
| 836 | #if 1 |
|---|
| 837 | return dhl_sys_get_cpu_tick()/dhl_sys_cpu_ticks_per_ms(); |
|---|
| 838 | |
|---|
| 839 | #else |
|---|
| 840 | static UINT32 prev_ms_tick; |
|---|
| 841 | static BOOL first_call = 1; |
|---|
| 842 | UINT32 tick; |
|---|
| 843 | UINT32 flag; |
|---|
| 844 | |
|---|
| 845 | flag = DHL_OS_LockTask(); |
|---|
| 846 | |
|---|
| 847 | tick = bcm_read_cp0($9,0); |
|---|
| 848 | |
|---|
| 849 | if (first_call) { |
|---|
| 850 | prev_ms_tick = tick; |
|---|
| 851 | first_call = 0; |
|---|
| 852 | return tick; |
|---|
| 853 | } |
|---|
| 854 | else { |
|---|
| 855 | if (tick < g_dhl_tick_low) { // overflow |
|---|
| 856 | g_dhl_tick_high++; |
|---|
| 857 | } |
|---|
| 858 | g_dhl_tick_low = tick; |
|---|
| 859 | } |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | DHL_OS_UnlockTask(flag); |
|---|
| 863 | |
|---|
| 864 | // if high part is same, calculate |
|---|
| 865 | |
|---|
| 866 | #endif |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | void dhl_sys_config_vdac(BOOL bEnable) |
|---|
| 871 | { |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | void dhl_sys_register_callback(void (*cb)(int type, UINT32 param, UINT32 state), UINT32 param) |
|---|
| 876 | { |
|---|
| 877 | UINT32 flag; |
|---|
| 878 | flag = bos_enter_critical(); |
|---|
| 879 | g_dhl_sys_cb_func = cb; |
|---|
| 880 | g_dhl_sys_cb_param = param; |
|---|
| 881 | bos_exit_critical(flag); |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | /* |
|---|
| 886 | 'state' has different meanings per 'type'. |
|---|
| 887 | refer comments in 'type' |
|---|
| 888 | */ |
|---|
| 889 | void dhl_sys_notify_callback(int type, UINT32 state) |
|---|
| 890 | { |
|---|
| 891 | void (*cb)(int, UINT32, UINT32); |
|---|
| 892 | UINT32 param; |
|---|
| 893 | UINT32 flag; |
|---|
| 894 | |
|---|
| 895 | flag = bos_enter_critical(); |
|---|
| 896 | cb = g_dhl_sys_cb_func; |
|---|
| 897 | param = g_dhl_sys_cb_param; |
|---|
| 898 | bos_exit_critical(flag); |
|---|
| 899 | |
|---|
| 900 | if (cb) |
|---|
| 901 | (*cb)(type, param, state); |
|---|
| 902 | } |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | #if COMMENT |
|---|
| 908 | ____Watchdog____(){} |
|---|
| 909 | #endif |
|---|
| 910 | |
|---|
| 911 | /* |
|---|
| 912 | comment: |
|---|
| 913 | |
|---|
| 914 | there is no way to know whether currently watchdog is running or not. |
|---|
| 915 | |
|---|
| 916 | normal timer provides to query current count value. (downcounter) |
|---|
| 917 | but bcm3543 does not privode a way to know current watchdog count value. |
|---|
| 918 | |
|---|
| 919 | however, usually watchdog is used together with watchdog timeout interrupt. |
|---|
| 920 | in watchdog timeout interrupt occurs, we re-program (restart) watchdog countdown. |
|---|
| 921 | |
|---|
| 922 | so, if watchdog timeout interrupt is enabled, we treat that watchdog is running. |
|---|
| 923 | |
|---|
| 924 | note that watchdog timeout interrupt can be disabled for test. |
|---|
| 925 | in this case, above assumption becomes wrong. |
|---|
| 926 | */ |
|---|
| 927 | |
|---|
| 928 | // this is only for test, to know watchdog is really working or not. |
|---|
| 929 | // if we disable watchdog interrupt, system will reboot after a few second. |
|---|
| 930 | // same result will occur when we disable system-wide interrupt (like OS_DisableInterrupts()). |
|---|
| 931 | // |
|---|
| 932 | void dhl_disable_watchdog_isr() |
|---|
| 933 | { |
|---|
| 934 | // just disable watchdog isr. then system will reboot after some time. |
|---|
| 935 | WriteReg32(BCHP_TIMER_TIMER_IE0, |
|---|
| 936 | ReadReg32(BCHP_TIMER_TIMER_IE0) & ~BCHP_TIMER_TIMER_IE0_WDINTMASK_MASK); |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | void dhl_sys_enable_watchdog(BOOL bEnable, UINT32 period) |
|---|
| 941 | { |
|---|
| 942 | /* |
|---|
| 943 | period is watchdog timer timout value. (27MHz clock) |
|---|
| 944 | |
|---|
| 945 | maximum value for 3543 is unknown, but refsw used 0x1FFFFFFF. |
|---|
| 946 | this is equivalent to 19.88 second in 27MHz clock source. |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | |
|---|
| 950 | if 0 is specified, maximum value will be used. |
|---|
| 951 | */ |
|---|
| 952 | |
|---|
| 953 | #define MAX_WDTIMER_VALUE 0x1FFFFFFF |
|---|
| 954 | |
|---|
| 955 | UINT32 flag; |
|---|
| 956 | |
|---|
| 957 | flag = DHL_OS_DisableInterrupts(); |
|---|
| 958 | |
|---|
| 959 | if (period == 0 || period > MAX_WDTIMER_VALUE) |
|---|
| 960 | period = MAX_WDTIMER_VALUE; |
|---|
| 961 | |
|---|
| 962 | // stop watchdog counter first. |
|---|
| 963 | // |
|---|
| 964 | WriteReg32(BCHP_TIMER_TIMER_IE0, |
|---|
| 965 | ReadReg32(BCHP_TIMER_TIMER_IE0) & ~BCHP_TIMER_TIMER_IE0_WDINTMASK_MASK); |
|---|
| 966 | |
|---|
| 967 | WriteReg32(BCHP_TIMER_WDCMD,0xEE00); |
|---|
| 968 | WriteReg32(BCHP_TIMER_WDCMD,0x00EE); |
|---|
| 969 | |
|---|
| 970 | if (bEnable) |
|---|
| 971 | { |
|---|
| 972 | // read watchdog chip reset status. check if watchdog is already occurred. |
|---|
| 973 | if (ReadReg32(BCHP_TIMER_WDCRS) == BCHP_TIMER_WDCRS_WDCR_MASK) { |
|---|
| 974 | // Clear the reset status register |
|---|
| 975 | WriteReg32(BCHP_TIMER_WDCRS,BCHP_TIMER_WDCRS_WDCR_MASK); |
|---|
| 976 | } |
|---|
| 977 | |
|---|
| 978 | // this interrupt is already registerred in bsettop_init() and never disabled. |
|---|
| 979 | // |
|---|
| 980 | //bint_set_handler(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_TMR_CPU_INTR_SHIFT,bsettop_wd_isr,NULL); |
|---|
| 981 | //bint_enable(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_TMR_CPU_INTR_SHIFT,1); |
|---|
| 982 | |
|---|
| 983 | // timeout value 1FFFFFFF is about 19.88 second. |
|---|
| 984 | // after 19.88/2 = 9.9 seconds, watchdog interrupt occurred. |
|---|
| 985 | // |
|---|
| 986 | WriteReg32(BCHP_TIMER_WDTIMEOUT, period); // <- 1FFFFFFF |
|---|
| 987 | WriteReg32(BCHP_TIMER_TIMER_IE0, BCHP_TIMER_TIMER_IE0_WDINTMASK_MASK); |
|---|
| 988 | |
|---|
| 989 | WriteReg32(BCHP_TIMER_WDCHIPRST_CNT, 0x800000); // 300 ms |
|---|
| 990 | |
|---|
| 991 | // Write start sequence |
|---|
| 992 | WriteReg32(BCHP_TIMER_WDCMD,0xFF00); |
|---|
| 993 | WriteReg32(BCHP_TIMER_WDCMD,0x00FF); |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | DHL_OS_RestoreInterrupts(flag); |
|---|
| 997 | |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | #if COMMENT |
|---|
| 1003 | ____Test____(){} |
|---|
| 1004 | #endif |
|---|
| 1005 | |
|---|
| 1006 | |
|---|
| 1007 | /* |
|---|
| 1008 | register read/write test. |
|---|
| 1009 | |
|---|
| 1010 | read: Shell> dhl_sys_reg 0x404000 |
|---|
| 1011 | write: Shell> dhl_sys_reg 0xxxxxxx value 1 |
|---|
| 1012 | |
|---|
| 1013 | */ |
|---|
| 1014 | void dhl_sys_reg(UINT32 regaddr, UINT32 val, BOOL bwrite) |
|---|
| 1015 | { |
|---|
| 1016 | UINT32 new_val; |
|---|
| 1017 | |
|---|
| 1018 | if (regaddr > 0x80000000) { |
|---|
| 1019 | // it seems that regaddr is system address. |
|---|
| 1020 | regaddr = (regaddr & 0x0FFFFFFF); |
|---|
| 1021 | } |
|---|
| 1022 | if (regaddr == 0) { |
|---|
| 1023 | printf("usage: %s regaddr [value] [1:write]\n", __FUNCTION__); |
|---|
| 1024 | return; |
|---|
| 1025 | } |
|---|
| 1026 | |
|---|
| 1027 | if (bwrite) { |
|---|
| 1028 | printf("***** Reg[0x%08x] <== 0x%08x (%d) \n", regaddr, val, val); |
|---|
| 1029 | WriteReg32(regaddr, val); |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | new_val = ReadReg32(regaddr); |
|---|
| 1033 | printf("***** Reg[0x%08x] = 0x%08x (%d) \n", regaddr, new_val, new_val); |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | void dhl_sys_test_cb(DHL_SYS_CB_TYPE type, UINT32 param, UINT32 state) |
|---|
| 1038 | { |
|---|
| 1039 | if (type == eDHL_SYS_CB_POWER) { |
|---|
| 1040 | printf("$$$ power\n"); |
|---|
| 1041 | } |
|---|
| 1042 | else if (type == eDHL_SYS_CB_CHUP) { |
|---|
| 1043 | printf("$$$ ch_up %d\n", state); |
|---|
| 1044 | } |
|---|
| 1045 | else if (type == eDHL_SYS_CB_CHDN) { |
|---|
| 1046 | printf("$$$ ch_dn %d\n", state); |
|---|
| 1047 | } |
|---|
| 1048 | else if (type == eDHL_SYS_CB_RFM) { |
|---|
| 1049 | printf("$$$ rfm %d\n", state); |
|---|
| 1050 | } |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | |
|---|
| 1054 | #if COMMENT |
|---|
| 1055 | ____Init____(){} |
|---|
| 1056 | #endif |
|---|
| 1057 | |
|---|
| 1058 | /* |
|---|
| 1059 | only for 3543!! |
|---|
| 1060 | |
|---|
| 1061 | */ |
|---|
| 1062 | |
|---|
| 1063 | |
|---|
| 1064 | static DHL_SymbolTable s_dhl_sys_symbols[] = |
|---|
| 1065 | { |
|---|
| 1066 | // it will be defined in OSAL. |
|---|
| 1067 | //{ "i", osi_show_taskinfo, DHL_SYM_FN, }, |
|---|
| 1068 | |
|---|
| 1069 | DHL_FNC_SYM_ENTRY(dhl_sys_reset), |
|---|
| 1070 | DHL_FNC_SYM_ENTRY(dhl_sys_standby), |
|---|
| 1071 | |
|---|
| 1072 | // DHL_FNC_SYM_ENTRY(dhl_sys_set_red_led), |
|---|
| 1073 | |
|---|
| 1074 | // { "reset", dhl_sys_standby, DHL_SYM_FN, }, |
|---|
| 1075 | //{ "reboot", dhl_sys_reset, DHL_SYM_FN, }, |
|---|
| 1076 | |
|---|
| 1077 | //{ "watchdog", dhl_sys_enable_watchdog, DHL_SYM_FN, }, |
|---|
| 1078 | |
|---|
| 1079 | //----- |
|---|
| 1080 | //DHL_VAR_SYM_ENTRY(dmc_bRequestVideoWidthReduction), |
|---|
| 1081 | |
|---|
| 1082 | }; |
|---|
| 1083 | |
|---|
| 1084 | void dhl_sys_init(void) |
|---|
| 1085 | { |
|---|
| 1086 | DHL_ASSERT(bsettop_init(BSETTOP_VERSION) == b_ok, ""); |
|---|
| 1087 | |
|---|
| 1088 | // gpio |
|---|
| 1089 | dhl_init_gpio_dpc(); |
|---|
| 1090 | dhl_sys_gpio_init(); |
|---|
| 1091 | //dhl_sys_gpio_rw(GPIO_LED_GREEN, 1, TRUE); // Green LED on. |
|---|
| 1092 | |
|---|
| 1093 | DHL_DBG_RegisterSymbols(s_dhl_sys_symbols, DHL_NUMSYMBOLS(s_dhl_sys_symbols)); |
|---|
| 1094 | |
|---|
| 1095 | // BOOTPRINT(("%s end\n", __FUNCTION__)); |
|---|
| 1096 | |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | |
|---|