static void hfa_detect(bool __maybe_unused hotplug) { /* Set up the CRC tables only once. */ if (!hfa_crc8_set) hfa_init_crc8(); usb_detect(&hashfast_drv, hfa_detect_one); }
static void hfa_detect(bool hotplug) { /* Set up the CRC tables only once. */ if (!hotplug) hfa_init_crc8(); usb_detect(&hashfast_drv, hfa_detect_one); }
/* Caller isn't expected to filter for changes in status. * current_status: * USB_DETECT_BY_DRV: USB_POWERED, USB_UNPOWERED, USB_INSERTED (driver) * else: USB_INSERTED, USB_EXTRACTED */ if(usb_monitor_enabled) { int oldstatus = disable_irq_save(); /* Dual-use function */ if(last_usb_status != current_status) { last_usb_status = current_status; queue_post(&usb_queue, current_status, 0); } restore_irq(oldstatus); } } void usb_start_monitoring(void) { int oldstatus = disable_irq_save(); /* Sync to event */ int status = usb_detect(); usb_monitor_enabled = true; #ifdef USB_DETECT_BY_DRV status = (status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED; #endif usb_status_event(status); #ifdef USB_FIREWIRE_HANDLING if (firewire_detect()) usb_firewire_connect_event(); #endif restore_irq(oldstatus); } #ifdef USB_FIREWIRE_HANDLING void usb_firewire_connect_event(void) { queue_post(&usb_queue, USB_REQUEST_REBOOT, 0); } #endif /* USB_FIREWIRE_HANDLING */ #else /* !USB_STATUS_BY_EVENT */ static void usb_tick(void) { int current_status; if(usb_monitor_enabled) { #ifdef USB_FIREWIRE_HANDLING int current_firewire_status = firewire_detect(); if(current_firewire_status != last_firewire_status) { last_firewire_status = current_firewire_status; firewire_countdown = NUM_POLL_READINGS; } else { /* Count down until it gets negative */ if(firewire_countdown >= 0) firewire_countdown--; /* Report to the thread if we have had 3 identical status readings in a row */ if(firewire_countdown == 0) { queue_post(&usb_queue, USB_REQUEST_REBOOT, 0); } } #endif /* USB_FIREWIRE_HANDLING */ current_status = usb_detect(); /* Only report when the status has changed */ if(current_status != last_usb_status) { last_usb_status = current_status; countdown = NUM_POLL_READINGS; } else { /* Count down until it gets negative */ if(countdown >= 0) countdown--; /* Report to the thread if we have had 3 identical status readings in a row */ if(countdown == 0) { queue_post(&usb_queue, current_status, 0); } } } #if (CONFIG_STORAGE & STORAGE_MMC) if(usb_mmc_countdown > 0) { usb_mmc_countdown--; if (usb_mmc_countdown == 0) queue_post(&usb_queue, USB_REENABLE, 0); } #endif }
void fatal_error(void) { extern int line; bool holdstatus=false; /* System font is 6 pixels wide */ #if defined(IPOD_1G2G) || defined(IPOD_3G) printf("Insert Firewire cable, or"); printf("hold MENU+PLAY to reboot"); printf("then REW+FF for disk mode"); #elif LCD_WIDTH >= (30*6) printf("Insert USB cable, or"); printf("hold MENU+SELECT to reboot"); printf("then SELECT+PLAY for disk mode"); #else printf("Insert USB cable, or"); printf("hold MENU+SELECT to"); printf("reboot then SELECT+PLAY"); printf("for disk mode"); #endif lcd_update(); usb_init(); while (1) { if (button_hold() != holdstatus) { if (button_hold()) { holdstatus=true; lcd_puts(0, line, "Hold switch on!"); } else { holdstatus=false; lcd_puts(0, line, " "); } lcd_update(); } if (usb_detect() == USB_INSERTED) { ata_sleepnow(); /* Immediately spindown the disk. */ sleep(HZ*2); #if CONFIG_CPU == PP5020 memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); #elif CONFIG_CPU == PP5022 memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); #elif CONFIG_CPU == PP5002 memcpy((void *)0x40017f00, "diskmodehotstuff\1", 17); #endif /* CONFIG_CPU */ system_reboot(); /* Reboot */ } udelay(100000); /* 100ms */ } }
static void charging_screen(void) { unsigned int button; const char* msg; ide_power_enable(false); /* power down the disk, else would be spinning */ lcd_clear_display(); do { #ifdef ARCHOS_RECORDER if (charge_state == CHARGING) msg = "charging"; else if (charge_state == TOPOFF) msg = "topoff charge"; else if (charge_state == TRICKLE) msg = "trickle charge"; else msg = "not charging"; #else msg = "charging"; #endif lcd_puts(0, 0, msg); { char buf[32]; int battv = battery_voltage(); snprintf(buf, sizeof(buf), "%d.%02dV %d%%", battv / 1000, (battv % 1000) / 10, battery_level()); lcd_puts(0, 1, buf); } lcd_update(); button = button_get_w_tmo(HZ/2); #ifdef BUTTON_ON if (button == (BUTTON_ON | BUTTON_REL)) #else if (button == (BUTTON_RIGHT | BUTTON_REL)) #endif break; /* start */ else { if (usb_detect() == USB_INSERTED) break; else if (!charger_inserted()) power_off(); /* charger removed: power down */ } } while (1); }
static void usb_mode(int connect_timeout) { int button; usb_init(); usb_start_monitoring(); /* Wait for threads to connect or cable is pulled */ printf("USB: Connecting"); long end_tick = current_tick + connect_timeout; while(1) { button = button_get_w_tmo(HZ/10); if(button == SYS_USB_CONNECTED) break; /* Hit */ if(TIME_AFTER(current_tick, end_tick)) { /* Timed out waiting for the connect - will happen when connected * to a charger through the USB port */ printf("USB: Timed out"); break; } if(usb_detect() == USB_EXTRACTED) break; /* Cable pulled */ } if(button == SYS_USB_CONNECTED) { /* Got the message - wait for disconnect */ printf("Bootloader USB mode"); usb_acknowledge(SYS_USB_CONNECTED_ACK); while(1) { button = button_get_w_tmo(HZ/2); if(button == SYS_USB_DISCONNECTED) break; } } /* Put drivers initialized for USB connection into a known state */ usb_close(); }
unsigned int power_input_status(void) { unsigned int status = POWER_INPUT_NONE; /* Is the battery switch ON? */ if ((GPGDAT & (1 << 9)) == 0) status |= POWER_INPUT_BATTERY; /* Main or cradle power available? */ if ((GPFDAT & (1 << 4)) == 0) status |= POWER_INPUT_MAIN_CHARGER; /* Is the USB cable inserted? */ if (usb_detect() == USB_INSERTED) status |= POWER_INPUT_USB_CHARGER; return status; }
void usb_start_monitoring(void) { int oldstatus = disable_irq_save(); /* Sync to event */ int status = usb_detect(); usb_monitor_enabled = true; #ifdef USB_DETECT_BY_DRV status = (status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED; #endif usb_status_event(status); #ifdef USB_FIREWIRE_HANDLING if (firewire_detect()) usb_firewire_connect_event(); #endif restore_irq(oldstatus); }
/* Return USB_INSERTED if cable present */ static int handle_usb(int connect_timeout) { int usb_retry = 0; int usb = USB_EXTRACTED; usb_init(); while (usb_drv_powered() && usb_retry < 5 && usb != USB_INSERTED) { usb_retry++; sleep(HZ/4); usb = usb_detect(); } if (usb != USB_INSERTED) usb = USB_EXTRACTED; return usb; (void)connect_timeout; }
/* Called from kernel thread */ static void do_detect(struct uh_data *uh) { D("Called.\n"); if (!test_and_clear_bit(BIT_DO_DETECT, &uh->flags)) return; D("Do detect.\n"); if(__gpio_get_pin(uh->gpio_pin)) { cable_detect(uh); usb_detect(uh); set_cable_state(uh, uh->cable_detect_state); }else{ set_cable_state(uh, UH_CABLE_STATE_OFFLINE); } return; }
void main(void) { unsigned char* loadbuffer; int buffer_size; int rc; int(*kernel_entry)(void); /* Make sure interrupts are disabled */ set_irq_level(IRQ_DISABLED); set_fiq_status(FIQ_DISABLED); system_init(); kernel_init(); /* Now enable interrupts */ set_irq_level(IRQ_ENABLED); set_fiq_status(FIQ_ENABLED); lcd_init(); backlight_init(); font_init(); button_init(); usb_init(); power_init(); // enable_irq(); // enable_fiq(); adc_init(); lcd_setfont(FONT_SYSFIXED); /* Show debug messages if button is pressed */ // if(button_read_device()) verbose = true; printf("Rockbox boot loader"); printf("Version %s", rbversion); /* Enter USB mode without USB thread */ if(usb_detect() == USB_INSERTED) { const char msg[] = "Bootloader USB mode"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); ide_power_enable(true); storage_enable(false); sleep(HZ/20); usb_enable(true); while (usb_detect() == USB_INSERTED) { storage_spin(); /* Prevent the drive from spinning down */ sleep(HZ); } usb_enable(false); reset_screen(); lcd_update(); } sleep(50); printf("ATA"); rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } printf("filesystem"); filesystem_init(); printf("mount"); rc = disk_mount_all(); if (rc<=0) { error(EDISK,rc, true); } printf("Loading firmware"); loadbuffer = (unsigned char*) 0x00900000; buffer_size = (unsigned char*)0x01900000 - loadbuffer; rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); if(rc <= EFILE_EMPTY) error(EBOOTFILE, rc, true); kernel_entry = (void*) loadbuffer; rc = kernel_entry(); /* Should not get here! */ return rc; }
void main(void) { unsigned char* loadbuffer; int buffer_size; int rc; int(*kernel_entry)(void); system_init(); kernel_init(); /* Need the kernel to sleep */ enable_interrupt(IRQ_FIQ_STATUS); lcd_init(); backlight_init(); button_init(); font_init(); adc_init(); lcd_setfont(FONT_SYSFIXED); /* These checks should only run if the bootloader is flashed */ if(GSTATUS3&0x02) { GSTATUS3&=0xFFFFFFFD; if(!(GPGDAT&BUTTON_POWER) && charger_inserted()) { while(!(GPGDAT&BUTTON_POWER) && charger_inserted()) { char msg[20]; if(charging_state()) { snprintf(msg,sizeof(msg),"Charging"); } else { snprintf(msg,sizeof(msg),"Charge Complete"); } reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); #if defined(HAVE_RTC_ALARM) /* Check if the alarm went off while charging */ if(rtc_check_alarm_flag()) { GSTATUS3=1; /* Normally this is set in crt0.s */ break; } #endif } if(!(GPGDAT&BUTTON_POWER) #if defined(HAVE_RTC_ALARM) && !GSTATUS3 #endif ) { shutdown(); } } if(button_hold()) { const char msg[] = "HOLD is enabled"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); sleep(2*HZ); shutdown(); } } power_init(); usb_init(); /* Enter USB mode without USB thread */ if(usb_detect() == USB_INSERTED) { const char msg[] = "Bootloader USB mode"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); storage_enable(false); sleep(HZ/20); usb_enable(true); while (usb_detect() == USB_INSERTED) sleep(HZ); usb_enable(false); reset_screen(); lcd_update(); } reset_screen(); /* Show debug messages if button is pressed */ if(button_read_device()&BUTTON_A) verbose = true; printf("Rockbox boot loader"); printf("Version %s", rbversion); sleep(50); /* ATA seems to error without this pause */ rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } filesystem_init(); rc = disk_mount_all(); if (rc<=0) { error(EDISK, rc, true); } printf("Loading firmware"); /* Flush out anything pending first */ commit_discard_idcache(); loadbuffer = (unsigned char*) 0x31000000; buffer_size = (unsigned char*)0x31400000 - loadbuffer; rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); if(rc <= EFILE_EMPTY) error(EBOOTFILE, rc, true); storage_close(); system_prepare_fw_start(); commit_discard_idcache(); kernel_entry = (void*) loadbuffer; rc = kernel_entry(); #if 0 /* Halt */ while (1) core_idle(); #else /* Return and restart */ #endif }
bool charging_state(void) { return (usb_detect() == USB_INSERTED); }
static void gridseed_detect(bool __maybe_unused hotplug) { usb_detect(&gridseed_drv, gridseed_detect_one); }
void main(void) { int rc; power_init(); system_init(); kernel_init(); lcd_init(); show_logo(); enable_irq(); adc_init(); usb_init(); button_init(); powermgmt_init(); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) if (charger_inserted() #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { charging_screen(); /* display a "charging" screen */ show_logo(); /* again, to provide better visual feedback */ } #endif rc = storage_init(); if(rc) { #ifdef HAVE_LCD_BITMAP char str[32]; lcd_clear_display(); snprintf(str, 31, "ATA error: %d", rc); lcd_puts(0, 1, str); lcd_update(); while(!(button_get(true) & BUTTON_REL)); #endif panicf("storage: %d", rc); } usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) { usb_screen(); } } rc = disk_mount_all(); if (rc<=0) { prompt_usb("No partition", "found."); } { // rolo the firmware static const char filename[] = "/" BOOTFILE; rolo_load((char*)filename); /* won't return if started */ prompt_usb("No firmware", filename); } }
void charging_algorithm_step(void) { #if IMX233_SUBTARGET >= 3780 bool is_5v_present = usb_detect() == USB_INSERTED; /* initial state & 5v -> battery transition */ if(!is_5v_present && charge_state != DISCHARGING) { logf("pwrmgmt: * -> discharging"); logf("pwrmgmt: disable charger and 4p2"); /* 5V has been lost: disable 4p2 power rail */ BF_SET(POWER_CHARGE, PWD_BATTCHRG); BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0); BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0); BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); charge_state = DISCHARGING; } /* battery -> 5v transition */ else if(is_5v_present && charge_state == DISCHARGING) { logf("pwrmgmt: discharging -> trickle"); logf("pwrmgmt: begin charging 4p2"); /* 5V has been detected: prepare 4.2V power rail for activation */ BF_WR(POWER_DCDC4P2, ENABLE_4P2, 1); BF_SET(POWER_CHARGE, ENABLE_LOAD); BF_WR(POWER_5VCTRL, CHARGE_4P2_ILIMIT, 1); BF_CLR(POWER_5VCTRL, PWD_CHARGE_4P2);// FIXME: manual error ? BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 1); timeout_4p2_ilimit_increase = current_tick + HZ / 100; charge_state = TRICKLE; } else if(charge_state == TRICKLE && TIME_AFTER(current_tick, timeout_4p2_ilimit_increase)) { /* if 4.2V current limit has not reached 780mA, increase it slowly to * charge the 4.2V capacitance */ if(BF_RD(POWER_5VCTRL, CHARGE_4P2_ILIMIT) != 0x3f) { //logf("pwrmgmt: incr 4.2 ilimit"); HW_POWER_5VCTRL += BF_POWER_5VCTRL_CHARGE_4P2_ILIMIT(1); timeout_4p2_ilimit_increase = current_tick + HZ / 100; } /* we've reached the maximum, take action */ else { logf("pwrmgmt: enable dcdc and charger"); logf("pwrmgmt: trickle -> charging"); BF_CLR(POWER_5VCTRL, DCDC_XFER); BF_SET(POWER_5VCTRL, ENABLE_DCDC); /* enable battery charging */ BF_CLR(POWER_CHARGE, PWD_BATTCHRG); charge_state = CHARGING; timeout_charging = current_tick + IMX233_CHARGING_TIMEOUT; } } else if(charge_state == CHARGING && TIME_AFTER(current_tick, timeout_charging)) { /* we have charged for a too long time, declare charger broken */ logf("pwrmgmt: charging timeout exceeded!"); logf("pwrmgmt: charging -> error"); /* stop charging */ BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); /* goto error state */ charge_state = CHARGE_STATE_ERROR; } else if(charge_state == CHARGING && !BF_RD(POWER_STS, CHRGSTS)) { logf("pwrmgmt: topping off"); logf("pwrmgmt: charging -> topoff"); charge_state = TOPOFF; timeout_topping_off = current_tick + IMX233_TOPOFF_TIMEOUT; } else if(charge_state == TOPOFF && TIME_AFTER(current_tick, timeout_topping_off)) { logf("pwrmgmt: charging finished"); logf("pwrmgmt: topoff -> disabled"); /* stop charging */ BF_SET(POWER_CHARGE, PWD_BATTCHRG); charge_state = CHARGE_STATE_DISABLED; } #endif }
void platform_init(void) { #if defined(TARGET_M805_892X_EVM) int ac_charger_detect_flag, usb_detect_flag; volatile int i; i = 0; #endif #if defined(TCC_I2C_USE) i2c_init(); #endif clock_init(); #if defined(TCC_PCA953X_USE) pca953x_init(); #endif uart_init(); adc_init(); #if defined(DISPLAY_SPLASH_SCREEN) || defined(DISPLAY_SPLASH_SCREEN_DIRECT) #ifndef DEFAULT_DISPLAY_OUTPUT_DUAL display_init(); dprintf(INFO, "Display initialized\n"); //disp_init = 1; #endif #endif #if defined(TARGET_M805_892X_EVM) ac_charger_detect_flag = ac_charger_detect(); usb_detect_flag = usb_detect(); dprintf(INFO, "USB DETECT(%d) AC CHARGER DETECT(%d)\n", usb_detect_flag, ac_charger_detect_flag); if( check_fwdn_mode() ) return; if(! (ac_charger_detect_flag || usb_detect_flag) ) { if( check_low_battery()) { while(1) { dprintf(CRITICAL, "Low Battery!!!! Power Off\n"); display_lowbattery_logo(); for ( i = 0 ; i < 1000000 ; i ++ ); for ( i = 0 ; i < 1000000 ; i ++ ); while(1) powercon_disable(); } } } else { if( check_low_battery()) { display_lowbattery_logo(); while( check_low_battery()) { ac_charger_detect_flag = ac_charger_detect(); usb_detect_flag = usb_detect(); for ( i = 0 ; i < 1000000 ; i ++ ); if(! (ac_charger_detect_flag || usb_detect_flag) ) { dprintf(CRITICAL, "Low Battery!!!! Power Off\n"); while(1) powercon_disable(); } } } } #endif display_booting_logo(); dprintf(INFO, "platform_init()\n"); }
unsigned int power_input_status(void) { return (usb_detect() == USB_INSERTED) ? POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; }
static void gridseed_detect(bool __maybe_unused hotplug) { if (opt_noasic) return; usb_detect(&gridseed_drv, gridseed_detect_one); }
static void init(void) { int rc; bool mounted = false; #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* if nobody initialized ATA before, I consider this a cold start */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ #endif system_init(); kernel_init(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ set_cpu_frequency(CPUFREQ_NORMAL); #ifdef CPU_COLDFIRE coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); #endif cpu_boost(true); #endif buffer_init(); settings_reset(); i2c_init(); power_init(); enable_irq(); #ifdef CPU_ARM enable_fiq(); #endif /* current_tick should be ticking by now */ CHART("ticking"); lcd_init(); #ifdef HAVE_REMOTE_LCD lcd_remote_init(); #endif font_init(); CHART(">show_logo"); show_logo(); CHART("<show_logo"); lang_init(core_language_builtin, language_strings, LANG_LAST_INDEX_IN_ARRAY); #ifdef DEBUG debug_init(); #else #ifdef HAVE_SERIAL serial_setup(); #endif #endif #if CONFIG_RTC rtc_init(); #endif #ifdef HAVE_RTC_RAM CHART(">settings_load(RTC)"); settings_load(SETTINGS_RTC); /* early load parts of global_settings */ CHART("<settings_load(RTC)"); #endif adc_init(); usb_init(); #if CONFIG_USBOTG == USBOTG_ISP1362 isp1362_init(); #elif CONFIG_USBOTG == USBOTG_M5636 m5636_init(); #endif backlight_init(); button_init(); powermgmt_init(); #if CONFIG_TUNER radio_init(); #endif /* Keep the order of this 3 (viewportmanager handles statusbars) * Must be done before any code uses the multi-screen API */ CHART(">gui_syncstatusbar_init"); gui_syncstatusbar_init(&statusbars); CHART("<gui_syncstatusbar_init"); CHART(">sb_skin_init"); sb_skin_init(); CHART("<sb_skin_init"); CHART(">gui_sync_wps_init"); gui_sync_wps_init(); CHART("<gui_sync_wps_init"); CHART(">viewportmanager_init"); viewportmanager_init(); CHART("<viewportmanager_init"); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* charger_inserted() can't be used here because power_thread() hasn't checked power_input_status() yet */ if (coldstart && (power_input_status() & POWER_INPUT_MAIN_CHARGER) && !global_settings.car_adapter_mode #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { rc = charging_screen(); /* display a "charging" screen */ if (rc == 1) /* charger removed */ power_off(); /* "On" pressed or USB connected: proceed */ show_logo(); /* again, to provide better visual feedback */ } #endif CHART(">storage_init"); rc = storage_init(); CHART("<storage_init"); if(rc) { #ifdef HAVE_LCD_BITMAP lcd_clear_display(); lcd_putsf(0, 1, "ATA error: %d", rc); lcd_puts(0, 3, "Press ON to debug"); lcd_update(); while(!(button_get(true) & BUTTON_REL)); /*DO NOT CHANGE TO ACTION SYSTEM */ dbg_ports(); #endif panicf("ata: %d", rc); } #ifdef HAVE_EEPROM_SETTINGS CHART(">eeprom_settings_init"); eeprom_settings_init(); CHART("<eeprom_settings_init"); #endif #ifndef HAVE_USBSTACK usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { #ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) #if (CONFIG_STORAGE & STORAGE_MMC) if (!mmc_touched() || (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED)) #endif { gui_usb_screen_run(); mounted = true; /* mounting done @ end of USB mode */ } #ifdef HAVE_USB_POWER if (usb_powered()) /* avoid deadlock */ break; #endif } #endif if (!mounted) { CHART(">disk_mount_all"); rc = disk_mount_all(); CHART("<disk_mount_all"); if (rc<=0) { lcd_clear_display(); lcd_puts(0, 0, "No partition"); lcd_puts(0, 1, "found."); #ifdef HAVE_LCD_BITMAP lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 3, "and fix it."); #endif lcd_update(); while(button_get(true) != SYS_USB_CONNECTED) {}; gui_usb_screen_run(); system_reboot(); } } #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IRIVER_H10_PAD) #ifdef SETTINGS_RESET /* Reset settings if holding the reset button. (Rec on Archos, A on Gigabeat) */ if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET) #else /* Reset settings if the hold button is turned on */ if (button_hold()) #endif { splash(HZ*2, str(LANG_RESET_DONE_CLEAR)); settings_reset(); } else #endif { CHART(">settings_load(ALL)"); settings_load(SETTINGS_ALL); CHART("<settings_load(ALL)"); } CHART(">init_dircache(true)"); rc = init_dircache(true); CHART("<init_dircache(true)"); if (rc < 0) { #ifdef HAVE_TAGCACHE remove(TAGCACHE_STATEFILE); #endif } CHART(">settings_apply(true)"); settings_apply(true); CHART("<settings_apply(true)"); CHART(">init_dircache(false)"); init_dircache(false); CHART("<init_dircache(false)"); #ifdef HAVE_TAGCACHE CHART(">init_tagcache"); init_tagcache(); CHART("<init_tagcache"); #endif #ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { /* In case we crash. */ firmware_settings.disk_clean = false; CHART(">eeprom_settings_store"); eeprom_settings_store(); CHART("<eeprom_settings_store"); } #endif playlist_init(); tree_mem_init(); filetype_init(); scrobbler_init(); #if CONFIG_CODEC == SWCODEC tdspeed_init(); #endif /* CONFIG_CODEC == SWCODEC */ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to audio_init() since the mpeg thread takes the rest of the buffer space */ mp3_init( global_settings.volume, global_settings.bass, global_settings.treble, global_settings.balance, global_settings.loudness, global_settings.avc, global_settings.channel_config, global_settings.stereo_width, global_settings.mdb_strength, global_settings.mdb_harmonics, global_settings.mdb_center, global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ CHART(">audio_init"); audio_init(); CHART("<audio_init"); #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR) pcm_rec_init(); #endif /* runtime database has to be initialized after audio_init() */ cpu_boost(false); #if CONFIG_CHARGING car_adapter_mode_init(); #endif #ifdef IPOD_ACCESSORY_PROTOCOL iap_setup(global_settings.serial_bitrate); #endif #ifdef HAVE_ACCESSORY_SUPPLY accessory_supply_set(global_settings.accessory_supply); #endif #ifdef HAVE_LINEOUT_POWEROFF lineout_set(global_settings.lineout_active); #endif #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN CHART("<check_bootfile(false)"); check_bootfile(false); /* remember write time and filesize */ CHART(">check_bootfile(false)"); #endif CHART("<settings_apply_skins"); settings_apply_skins(); CHART(">settings_apply_skins"); }
static inline void hashratio_detect(bool __maybe_unused hotplug) { usb_detect(&hashratio_drv, hashratio_detect_one); }
static void bitforce_detect(bool __maybe_unused hotplug) { usb_detect(&bitforce_drv, bitforce_detect_one); }
static void klondike_detect(void) { usb_detect(&klondike_drv, klondike_detect_one); }
void main(uint32_t arg, uint32_t addr) { unsigned char* loadbuffer; int buffer_size; void(*kernel_entry)(void); int ret; system_init(); kernel_init(); power_init(); enable_irq(); lcd_init(); lcd_clear_display(); lcd_update(); backlight_init(); button_init(); //button_debug_screen(); printf("Boot version: %s", RBVERSION); printf("arg=%x addr=%x", arg, addr); #ifdef SANSA_FUZEPLUS extern void imx233_mmc_disable_window(void); if(arg == 0xfee1dead) { printf("Disable MMC window."); imx233_mmc_disable_window(); } #endif ret = storage_init(); if(ret < 0) error(EATA, ret, true); /* NOTE: allow disk_init and disk_mount_all to fail since we can do USB after. * We need this order to determine the correct logical sector size */ while(!disk_init(IF_MV(0))) printf("disk_init failed!"); if((ret = disk_mount_all()) <= 0) error(EDISK, ret, false); if(usb_detect() == USB_INSERTED) usb_mode(HZ); printf("Loading firmware"); loadbuffer = (unsigned char*)loadaddress; buffer_size = (int)(loadaddressend - loadaddress); while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0) { error(EBOOTFILE, ret, true); } kernel_entry = (void*) loadbuffer; printf("Executing"); disable_interrupt(IRQ_FIQ_STATUS); commit_discard_idcache(); kernel_entry(); printf("ERR: Failed to boot"); /* never returns */ while(1) ; }
static void bitforce_detect(void) { usb_detect(&bitforce_drv, bitforce_detect_one); }
static bool gridseed_check_new_task(struct cgpu_info *gridseed, GRIDSEED_INFO *info) { cgtimer_t ts_now, ts_res; bool ret = false; cgtimer_time(&ts_now); mutex_lock(&info->qlock); cgtimer_sub(&ts_now, &info->query_ts, &ts_res); #ifndef WIN32 if (ts_res.tv_sec > 0 || ts_res.tv_nsec > 350000000) { #else if (ts_res.QuadPart > 3500000) { #endif info->query_qlen = false; info->dev_queue_len = 1; info->needworks = 1; cgtimer_time(&info->query_ts); } mutex_unlock(&info->qlock); } /* * Thread to read response from Miner device */ static void *gridseed_get_results(void *userdata) { struct cgpu_info *gridseed = (struct cgpu_info *)userdata; GRIDSEED_INFO *info = gridseed->device_data; struct thr_info *thr = info->thr; char threadname[24]; unsigned char readbuf[GRIDSEED_READBUF_SIZE]; int offset = 0, ret; snprintf(threadname, sizeof(threadname), "GridSeed_Recv/%d", gridseed->device_id); RenameThread(threadname); applog(LOG_NOTICE, "GridSeed: recv thread running, %s", threadname); while(likely(!gridseed->shutdown)) { unsigned char buf[GRIDSEED_READ_SIZE]; if (offset >= GRIDSEED_READ_SIZE) gridseed_parse_results(gridseed, info, thr, readbuf, &offset); if (unlikely(offset + GRIDSEED_READ_SIZE >= GRIDSEED_READBUF_SIZE)) { applog(LOG_ERR, "Read buffer overflow, resetting %d", gridseed->device_id); offset = 0; } ret = gc3355_get_data(gridseed, buf, sizeof(buf)); if (ret == LIBUSB_ERROR_NO_DEVICE) gridseed->shutdown = true; if (unlikely(ret != 0)) continue; if (opt_debug) { applog(LOG_DEBUG, "GridSeed: get %d bytes", GRIDSEED_READ_SIZE); hexdump((uint8_t *)buf, GRIDSEED_READ_SIZE); } memcpy(readbuf + offset, buf, GRIDSEED_READ_SIZE); offset += GRIDSEED_READ_SIZE; } return NULL; } /* * Thread to send task and queue length query command to device */ static void *gridseed_send_command(void *userdata) { struct cgpu_info *gridseed = (struct cgpu_info *)userdata; GRIDSEED_INFO *info = gridseed->device_data; char threadname[24]; int i; snprintf(threadname, sizeof(threadname), "GridSeed_Send/%d", gridseed->device_id); RenameThread(threadname); applog(LOG_NOTICE, "GridSeed: send thread running, %s", threadname); while(likely(!gridseed->shutdown)) { cgsleep_ms(10); if (info->usefifo == 0) { /* mark the first work in queue as complete after several ms */ if (gridseed_check_new_task(gridseed, info)) continue; } else { /* send query command to device */ if (gridseed_send_query_cmd(gridseed, info)) continue; } /* send task to device */ mutex_lock(&info->qlock); for(i=0; i<info->soft_queue_len; i++) { if (info->workqueue[i] && info->workqueue[i]->devflag == false) { if (gridseed_send_task(gridseed, info, info->workqueue[i])) { info->workqueue[i]->devflag = true; break; } } } mutex_unlock(&info->qlock); /* recv LTC task and send to device */ gridseed_recv_ltc(gridseed, info); } return NULL; } /*========== functions for struct device_drv ===========*/ static void gridseed_detect(bool __maybe_unused hotplug) { usb_detect(&gridseed_drv, gridseed_detect_one); }
void charging_algorithm_step(void) { bool is_5v_present = usb_detect() == USB_INSERTED; /* initial state & 5v -> battery transition */ if(!is_5v_present && charge_state != DISCHARGING) { logf("pwrmgmt: * -> discharging"); logf("pwrmgmt: disable charger and 4p2"); /* 5V has been lost: disable 4p2 power rail */ __REG_SET(HW_POWER_CHARGE) = HW_POWER_CHARGE__PWD_BATTCHRG; __REG_CLR(HW_POWER_DCDC4P2) = HW_POWER_DCDC4P2__ENABLE_DCDC | HW_POWER_DCDC4P2__ENABLE_4P2; __REG_SET(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__PWD_CHARGE_4P2; charge_state = DISCHARGING; } /* battery -> 5v transition */ else if(is_5v_present && charge_state == DISCHARGING) { logf("pwrmgmt: discharging -> trickle"); logf("pwrmgmt: begin charging 4p2"); /* 5V has been detected: prepare 4.2V power rail for activation */ __REG_SET(HW_POWER_DCDC4P2) = HW_POWER_DCDC4P2__ENABLE_4P2; __REG_SET(HW_POWER_CHARGE) = HW_POWER_CHARGE__ENABLE_LOAD; __FIELD_SET(HW_POWER_5VCTRL, CHARGE_4P2_ILIMIT, 1); __REG_CLR(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__PWD_CHARGE_4P2;// FIXME: manual error ? __REG_SET(HW_POWER_DCDC4P2) = HW_POWER_DCDC4P2__ENABLE_DCDC; timeout_4p2_ilimit_increase = current_tick + HZ / 100; charge_state = TRICKLE; } else if(charge_state == TRICKLE && TIME_AFTER(current_tick, timeout_4p2_ilimit_increase)) { /* if 4.2V current limit has not reached 780mA, increase it slowly to * charge the 4.2V capacitance */ if(__XTRACT(HW_POWER_5VCTRL, CHARGE_4P2_ILIMIT) != 0x3f) { //logf("pwrmgmt: incr 4.2 ilimit"); HW_POWER_5VCTRL += 1 << HW_POWER_5VCTRL__CHARGE_4P2_ILIMIT_BP; timeout_4p2_ilimit_increase = current_tick + HZ / 100; } /* we've reached the maximum, take action */ else { logf("pwrmgmt: enable dcdc and charger"); logf("pwrmgmt: trickle -> charging"); /* adjust arbitration between 4.2 and battery */ __FIELD_SET(HW_POWER_DCDC4P2, CMPTRIP, 0); /* 85% */ __FIELD_SET(HW_POWER_DCDC4P2, DROPOUT_CTRL, 0xe); /* select greater, 200 mV drop */ __REG_CLR(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__DCDC_XFER; __REG_SET(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__ENABLE_DCDC; /* enable battery charging */ __REG_CLR(HW_POWER_CHARGE) = HW_POWER_CHARGE__PWD_BATTCHRG; charge_state = CHARGING; timeout_charging = current_tick + IMX233_CHARGING_TIMEOUT; } } else if(charge_state == CHARGING && TIME_AFTER(current_tick, timeout_charging)) { /* we have charged for a too long time, declare charger broken */ logf("pwrmgmt: charging timeout exceeded!"); logf("pwrmgmt: charging -> error"); /* stop charging */ __REG_SET(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__PWD_CHARGE_4P2; /* goto error state */ charge_state = CHARGE_STATE_ERROR; } else if(charge_state == CHARGING && !(HW_POWER_STS & HW_POWER_STS__CHRGSTS)) { logf("pwrmgmt: topping off"); logf("pwrmgmt: charging -> topoff"); charge_state = TOPOFF; timeout_topping_off = current_tick + IMX233_TOPOFF_TIMEOUT; } else if(charge_state == TOPOFF && TIME_AFTER(current_tick, timeout_topping_off)) { logf("pwrmgmt: charging finished"); logf("pwrmgmt: topoff -> disabled"); /* stop charging */ __REG_SET(HW_POWER_5VCTRL) = HW_POWER_5VCTRL__PWD_CHARGE_4P2; charge_state = CHARGE_STATE_DISABLED; } }
void charging_algorithm_step(void) { #if IMX233_SUBTARGET >= 3700 bool is_5v_present = usb_detect() == USB_INSERTED; /* initial state & 5v -> battery transition */ if(!is_5v_present && charge_state != DISCHARGING) { logf("pwrmgmt: * -> discharging"); logf("pwrmgmt: disable charger and 4p2"); charge_state = DISCHARGING; /* 5V has been lost: disable 4p2 power rail */ BF_SET(POWER_CHARGE, PWD_BATTCHRG); #if IMX233_SUBTARGET >= 3780 BF_WR(POWER_DCDC4P2, ENABLE_DCDC(0)); BF_WR(POWER_DCDC4P2, ENABLE_4P2(0)); BF_WR(POWER_5VCTRL, CHARGE_4P2_ILIMIT(0)); BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); #endif } /* battery -> 5v transition */ else if(is_5v_present && charge_state == DISCHARGING) { logf("pwrmgmt: discharging -> trickle"); logf("pwrmgmt: begin charging 4p2"); #if IMX233_SUBTARGET >= 3780 /* 5V has been detected: prepare 4.2V power rail for activation * WARNING we can reach this situation when starting after Freescale bootloader * or after RoLo in a state where the DCDC is running. In this case, * we must *NOT* disable it or this will shutdown the device. This procedure * is safe: it will never disable the DCDC and will not reduce the charge * limit on the 4P2 rail. */ BF_WR(POWER_DCDC4P2, ENABLE_4P2(1)); BF_SET(POWER_CHARGE, ENABLE_LOAD); BF_WR(POWER_5VCTRL, CHARGE_4P2_ILIMIT(0)); /* start by drawing 0mA */ BF_CLR(POWER_5VCTRL, PWD_CHARGE_4P2);// FIXME: manual error ? BF_WR(POWER_DCDC4P2, ENABLE_DCDC(1)); /* the tick task will take care of slowly ramping up the current in the rail * every 10ms (since it runs at HZ and HZ=100) */ #endif charge_state = TRICKLE; } /* trickle -> charging transition */ else if(charge_state == TRICKLE) { #if IMX233_SUBTARGET >= 3780 /* If 4.2V current limit has not reached 780mA, don't do anything, the * DPC is still running */ /* If we've reached the maximum, take action */ if(BF_RD(POWER_5VCTRL, CHARGE_4P2_ILIMIT) == MAX_4P2_ILIMIT) #endif { logf("pwrmgmt: enable dcdc and charger"); logf("pwrmgmt: trickle -> charging"); #if IMX233_SUBTARGET >= 3780 /* adjust arbitration between 4.2 and battery */ BF_WR(POWER_DCDC4P2, CMPTRIP(0)); /* 85% */ BF_WR(POWER_DCDC4P2, DROPOUT_CTRL(0xe)); /* select greater, 200 mV drop */ #endif /* switch to DCDC */ BF_CLR(POWER_5VCTRL, DCDC_XFER); BF_SET(POWER_5VCTRL, ENABLE_DCDC); /* enable battery charging */ BF_CLR(POWER_CHARGE, PWD_BATTCHRG); charge_state = CHARGING; timeout_charging = current_tick + IMX233_CHARGING_TIMEOUT; } } /* charging -> error transition */ else if(charge_state == CHARGING && TIME_AFTER(current_tick, timeout_charging)) { /* we have charged for a too long time, declare charger broken */ logf("pwrmgmt: charging timeout exceeded!"); logf("pwrmgmt: charging -> error"); /* stop charging, note that we leave the 4.2 rail active so that the DCDC * keep drawing current from the 4.2 only and leave the battery untouched */ BF_SET(POWER_CHARGE, PWD_BATTCHRG); /* goto error state */ charge_state = CHARGE_STATE_ERROR; } /* charging -> topoff transition */ else if(charge_state == CHARGING && !BF_RD(POWER_STS, CHRGSTS)) { logf("pwrmgmt: topping off"); logf("pwrmgmt: charging -> topoff"); charge_state = TOPOFF; timeout_topping_off = current_tick + IMX233_TOPOFF_TIMEOUT; } /* topoff -> disabled transition */ else if(charge_state == TOPOFF && TIME_AFTER(current_tick, timeout_topping_off)) { logf("pwrmgmt: charging finished"); logf("pwrmgmt: topoff -> disabled"); /* stop charging, note that we leave the 4.2 rail active so that the DCDC * keep drawing current from the 4.2 only and leave the battery untouched */ BF_SET(POWER_CHARGE, PWD_BATTCHRG); charge_state = CHARGE_STATE_DISABLED; } #endif }