void dispatch_buttons(uint32_t buttons) { int i; uint8_t state; if ((buttons & (1 << btn_map[KEY_POWER]))) { /* hold button 500ms to shut down */ if ((lastbuttons & (1 << btn_map[KEY_POWER]))) { unsigned long elapsed = jiffies - power_hold; if (elapsed > 50) twl3025_power_off(); power_hold++; } else power_hold = jiffies; } if (buttons == lastbuttons) return; uint32_t diff = buttons ^ lastbuttons; for (i = 0; i < BUTTON_CNT; i++) { if (diff & (1 << btn_map[i])) { state = (buttons & (1 << btn_map[i])) ? PRESSED : RELEASED; emit_key(i, state); } } lastbuttons = buttons; }
void emit_key(uint8_t key, uint8_t state) { printf("key=%u %s\n", key, state == PRESSED ? "pressed" : "released"); if (state == RELEASED) if (key == KEY_POWER) twl3025_power_off(); if(key_handler) { key_handler(key, state); } }
static void twl3025_irq(enum irq_nr nr) { uint16_t src; printd("twl3025_irq: 0x%02x\n",nr); switch (nr) { case IRQ_EXTERNAL: // charger in/out, pwrbtn, adc done src = twl3025_reg_read(ITSTATREG); // printd("itstatreg 0x%02x\n", src); if (src & 0x08) handle_charger(); if (src & 0x20) handle_adc_done(); break; case IRQ_EXTERNAL_FIQ: // vcc <2.8V emergency power off puts("\nBROWNOUT!1!"); twl3025_power_off(); break; default: return; } }
static void device_poweroff(void) { flush_uart(); twl3025_power_off(); }
int main(void) { /* Simulate a compal loader saying "ACK" */ unsigned i = 0; for (i = 0; i < sizeof(phone_ack); i++) { putchar_asm(phone_ack[i]); } /* initialize board without interrupts */ board_init(0); sercomm_uart = sercomm_get_uart(); /* Say hi */ puts("\n\nOsmocomBB Loader (revision " GIT_REVISION ")\n"); puts(hr); fb_clear(); fb_setfg(FB_COLOR_BLACK); fb_setbg(FB_COLOR_WHITE); fb_setfont(FB_FONT_HELVB14); fb_gotoxy(2,20); fb_putstr("loader",framebuffer->width-4); fb_setfg(FB_COLOR_RED); fb_setbg(FB_COLOR_BLUE); fb_gotoxy(2,25); fb_boxto(framebuffer->width-3,38); fb_setfg(FB_COLOR_WHITE); fb_setfont(FB_FONT_HELVR08); fb_gotoxy(8,33); fb_putstr("osmocom-bb",framebuffer->width-4); fb_flush(); /* Identify environment */ printf("Running on %s in environment %s\n", manifest_board, manifest_environment); /* Initialize flash driver */ if (flash_init(&the_flash, 0)) { puts("Failed to initialize flash!\n"); } else { printf("Found flash of %zu bytes at 0x%p with %zu regions\n", the_flash.f_size, the_flash.f_base, the_flash.f_nregions); for (i = 0; i < the_flash.f_nregions; i++) { printf(" Region %d of %zu pages with %zu bytes each.\n", i, the_flash.f_regions[i].fr_bnum, the_flash.f_regions[i].fr_bsize); } } /* Set up a key handler for powering off */ keypad_set_handler(&key_handler); /* Set up loader communications */ sercomm_register_rx_cb(SC_DLCI_LOADER, &cmd_handler); /* Notify any running osmoload about our startup */ loader_send_init(SC_DLCI_LOADER); /* Wait for events */ while (1) { keypad_poll(); uart_poll(sercomm_uart); } /* NOT REACHED */ twl3025_power_off(); }
int main(void) { /* Simulate a compal loader saying "ACK" */ int i = 0; for (i = 0; i < sizeof(phone_ack); i++) { putchar_asm(phone_ack[i]); } /* Always disable wdt (some platforms enable it on boot) */ wdog_enable(0); /* Disable the bootrom mapping */ calypso_bootrom(0); /* Initialize TWL3025 for power control */ twl3025_init(); /* Backlight */ bl_mode_pwl(1); bl_level(50); /* Initialize UART without interrupts */ uart_init(SERCOMM_UART_NR, 0); uart_baudrate(SERCOMM_UART_NR, UART_115200); /* Initialize HDLC subsystem */ sercomm_init(); /* Say hi */ puts("\n\nOSMOCOM Loader (revision " GIT_REVISION ")\n"); puts(hr); /* Identify environment */ printf("Running on %s in environment %s\n", manifest_board, manifest_environment); /* Initialize flash driver */ if (flash_init(&the_flash, 0)) { puts("Failed to initialize flash!\n"); } else { printf("Found flash of %d bytes at 0x%x with %d regions\n", the_flash.f_size, the_flash.f_base, the_flash.f_nregions); int i; for (i = 0; i < the_flash.f_nregions; i++) { printf(" Region %d of %d pages with %d bytes each.\n", i, the_flash.f_regions[i].fr_bnum, the_flash.f_regions[i].fr_bsize); } } /* Set up a key handler for powering off */ keypad_set_handler(&key_handler); /* Set up loader communications */ sercomm_register_rx_cb(SC_DLCI_LOADER, &cmd_handler); /* Notify any running osmoload about our startup */ loader_send_init(SC_DLCI_LOADER); /* Wait for events */ while (1) { keypad_poll(); uart_poll(SERCOMM_UART_NR); } /* NOT REACHED */ twl3025_power_off(); }
int main(void) { uint8_t atr[20]; uint8_t atrLength = 0; board_init(1); puts("\n\nOsmocomBB Layer 1 (revision " GIT_REVISION ")\n"); puts(hr); /* Dump device identification */ dump_dev_id(); puts(hr); keypad_set_handler(&key_handler); /* Dump clock config after PLL set */ calypso_clk_dump(); puts(hr); fb_clear(); fb_setfg(FB_COLOR_BLACK); fb_setbg(FB_COLOR_WHITE); fb_setfont(FB_FONT_HELVB14); fb_gotoxy(2,20); fb_putstr("Layer 1",framebuffer->width-4); fb_setfg(FB_COLOR_RED); fb_setbg(FB_COLOR_BLUE); fb_gotoxy(2,25); fb_boxto(framebuffer->width-3,38); fb_setfg(FB_COLOR_WHITE); fb_setfont(FB_FONT_HELVR08); fb_gotoxy(8,33); fb_putstr("osmocom-bb",framebuffer->width-4); fb_flush(); /* initialize SIM */ calypso_sim_init(); puts("Power up simcard:\n"); memset(atr,0,sizeof(atr)); atrLength = calypso_sim_powerup(atr); layer1_init(); tpu_frame_irq_en(1, 1); while (1) { l1a_compl_execute(); osmo_timers_update(); sim_handler(); l1a_l23_handler(); } /* NOT REACHED */ twl3025_power_off(); }