static void reset_ga(bus_t busnumber) { /* reset ga devices to values stored in data->i2c_values */ I2CDEV_DATA *data = (I2CDEV_DATA *) buses[busnumber].driverdata; int i, multiplexer_adr; int multiplex_buses; multiplex_buses = data->multiplex_buses; if (multiplex_buses > 0) { for (multiplexer_adr = 1; multiplexer_adr <= multiplex_buses; multiplexer_adr++) { select_bus(multiplexer_adr, busnumber); /* first PCF 8574 P */ for (i = 32; i <= 39; i++) { write_PCF8574(busnumber, i, data->i2c_values[i][multiplexer_adr - 1]); } /* now PCF 8574 AP */ for (i = 56; i <= 63; i++) { write_PCF8574(busnumber, i, data->i2c_values[i][multiplexer_adr - 1]); } } select_bus(0, busnumber); } }
void mlo_erase() { static unsigned MSG = 0xaabbccdd; int ret = 0; u8 val; /*Enable USB mux pin cfg enable USB clock */ enable_irqs(); if (usb_open(&usbdev)) return -1; ret = mmc_init(1); if (ret != 0){ printf("\n MMC init failed \n"); goto error; } ret = mmc_erase(1, (1024*128/MMC_BLOCK_SIZE), 1024*128); usb_write(&usbdev, &MSG, 4); /*power off PMIC */ printf("erase ret %d Powering off!\n", ret); select_bus(CFG_I2C_BUS, CFG_I2C_SPEED); val = SWITCH_OFF; i2c_write(TWL6030_PMC_ID, PHOENIX_DEV_ON, 1, &val, 1); /* we should never get here */ error: hang(); }
static inline int smb347_i2c_read_u8( u8 *val, u8 reg) { int mbid=0; mbid=get_mbid(); if(mbid>=4) select_bus(3,100); return i2c_read(g_smb_address, reg, 1, val, 1); }
void pwron_check_switch_off(void) { u32 t32k_t1, t32k_t2; u8 val; select_bus(CFG_I2C_BUS, CFG_I2C_SPEED); /* if start is on disabled start event, switch off the board */ i2c_read(TWL6030_PMC_ID, PHOENIX_START_CONDITION, 1, &val, 1); if (val & DISABLED_STRT_EVENTS) { printf("Start on disabled event.\n"); goto switch_off; } /* if start is not on PWRON, skip the power button check */ if (!(val & STRT_ON_PWRON)) { printf("Start not on PWRON, skiping power button check.\n"); goto clean_and_exit; } /* if USB or charger is detected, skip the check so the user * doesn't need to keep the button pressed for 5sec */ i2c_read(TWL6030_PMC_ID, STS_HW_CONDITIONS, 1, &val, 1); if (val & STS_PLUG_DET) { printf("Plug detected, skiping power button check.\n"); goto clean_and_exit; } printf("Checking power button state... "); t32k_t1 = t32k_t2 = *((volatile u32 *)OMAP4_32KSYNCNT_CR); do { if ((t32k_t2 - t32k_t1) % 328 == 0) { /* Check poweron button status every 10ms */ i2c_read(TWL6030_PMC_ID, STS_HW_CONDITIONS, 1, &val, 1); if (val & STS_PWRON) { printf("RELEASED. NOK.\n"); goto switch_off; } } t32k_t2 = *((volatile u32 *)OMAP4_32KSYNCNT_CR); } while (t32k_t2 - t32k_t1 < PWRON_CHECK_DURATION); printf("PRESSED. OK\n"); clean_and_exit: val = 0x00; i2c_write(TWL6030_PMC_ID, PHOENIX_START_CONDITION, 1, &val, 1); return; switch_off: printf("Powering off!\n"); val = SWITCH_OFF; i2c_write(TWL6030_PMC_ID, PHOENIX_DEV_ON, 1, &val, 1); /* we should never get here */ hang(); }
/* Functions to read and write from SMB347 */ static inline int smb347_i2c_write_u8( u8 val, u8 reg) { // printf("Charger: reg=0x%x value=0x%x \n",reg,val); int mbid=0; mbid=get_mbid(); if(mbid>=4) select_bus(3,100); return i2c_write(g_smb_address, reg, 1, &val, 1); }
void lp855x_restore_i2c(void) { int r; if ((r = select_bus(0, CFG_I2C_SPEED)) != 0) { printf("select_bus failed: %d\n", r); } i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE); }
void pmic_close_vpp(void) { u8 data = 0; select_bus(CFG_I2C_BUS, CFG_I2C_SPEED); data = 0x20; i2c_write(0x48, 0x9e, 1, &data, 1); // VPP_CFG_STATE return ; }
void lp855x_set_brightness(u8 brightness) { int r; if ((r = select_bus(2, 100)) != 0) { printf("select_bus failed: %d\n", r); } i2c_init(100, LP8556_I2C_ADDR); lp855x_i2c_write(BRIGHTNESS_CTRL, brightness); }
/********************************************** * Routine: dram_init * Description: sets uboots idea of sdram size **********************************************/ int dram_init(void) { DECLARE_GLOBAL_DATA_PTR; unsigned int size0 = 0, size1 = 0; u32 mtype, btype; #ifdef CONFIG_DRIVER_OMAP24XX_I2C u8 data; #endif #define NOT_EARLY 0 #ifdef CONFIG_DRIVER_OMAP24XX_I2C i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE); select_bus(1, CFG_I2C_SPEED); /* select bus with T2 on it */ #endif btype = get_board_type(); mtype = get_mem_type(); display_board_info(btype); #ifdef CONFIG_DRIVER_OMAP24XX_I2C if (btype == BOARD_SDP_2430_T2) { /* Enable VMODE following voltage switching */ data = 0x24; /* set the floor voltage to 1.05v */ i2c_write(I2C_TRITON2, 0xBB, 1, &data, 1); data = 0x38; /* set the roof voltage to 1.3V */ i2c_write(I2C_TRITON2, 0xBC, 1, &data, 1); data = 0x0; /* set jump mode for VDD voltage transition */ i2c_write(I2C_TRITON2, 0xBD, 1, &data, 1); data = 1; /* enable voltage scaling */ i2c_write(I2C_TRITON2, 0xBA, 1, &data, 1); } #endif if ((mtype == DDR_COMBO) || (mtype == DDR_STACKED)) { /* init other chip select and map CS1 right after CS0 */ do_sdrc_init(SDRC_CS1_OSET, NOT_EARLY); } size0 = get_sdr_cs_size(SDRC_CS0_OSET); size1 = get_sdr_cs_size(SDRC_CS1_OSET); gd->bd->bi_dram[0].start = PHYS_SDRAM_1; gd->bd->bi_dram[0].size = size0; gd->bd->bi_dram[1].start = PHYS_SDRAM_1+size0; gd->bd->bi_dram[1].size = size1; return 0; }
void lp855x_on(u8 cfg) { int r; if ((r = select_bus(2, 100)) != 0) { printf("select_bus failed: %d\n", r); goto out; } i2c_init(100, LP8556_I2C_ADDR); lp855x_i2c_write(BRIGHTNESS_CTRL, 0); lp855x_i2c_write(DEVICE_CTRL, 1 | (2 << 1)); lp855x_i2c_write(CFG5_REG, cfg); out: return r; }
void muic_for_download(int mode) { int ret; if(mode == 0) { select_bus(I2C3 , OMAP_I2C_STANDARD); usif1_switch_ctrl(USIF1_IPC); dp3t_switch_ctrl(2); ret = muic_i2c_write_byte(SW_CONTROL, DP_UART | DM_UART); } else dp3t_switch_ctrl(DP3T_S3_CP_USB); printf("CP_USB is set(910Kohm)\n"); }
void pmic_set_vpp(void) { u8 data = 0; select_bus(CFG_I2C_BUS, CFG_I2C_SPEED); data = 0x1; i2c_write(0x48, 0x9c, 1, &data, 1); // VPP_CFG_GRP data = 0x3; i2c_write(0x48, 0x9d, 1, &data, 1); // VPP_CFG_TRANS data = 0x21; i2c_write(0x48, 0x9e, 1, &data, 1); // VPP_CFG_STATE data = 0x8; i2c_write(0x48, 0x9f, 1, &data, 1); // VPP_CFG_VOLTAGE return ; }
void start_armboot (void) { init_fnc_t **init_fnc_ptr; uchar *buf; char boot_dev_name[8]; u32 si_type, omap4_rev; int len = 0; u8 val = SWITCH_OFF; image_type image; for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { if ((*init_fnc_ptr)() != 0) { hang (); } } image.image = 2; image.val =99; omap4_rev = omap_revision(); if (omap4_rev >= OMAP4460_ES1_0) { omap_temp_sensor_check(); if (omap4_rev == OMAP4470_ES1_0) { writel(((TSHUT_HIGH_ADC_CODE << 16) | TSHUT_COLD_ADC_CODE), CORE_TSHUT_THRESHOLD); MV1(WK(CONTROL_SPARE_RW) , (M1)); } si_type = omap4_silicon_type(); if (si_type == PROD_ID_1_SILICON_TYPE_HIGH_PERF) printf("OMAP4470: 1.5 GHz capable SOM\n"); else if (si_type == PROD_ID_1_SILICON_TYPE_STD_PERF) printf("OMAP4470: 1.3 GHz capable SOM\n"); } #ifdef CONFIG_USBBOOT_ERASER /* Erase mlo and poweroff */ mlo_erase(); #else #ifdef CONFIG_USBBOOT /*usb boot does not check power button */ printf("boot_device=0x%x boot_mode=0x%x\n", get_boot_device(), get_boot_mode()); printf("id_code=%08x\n", readl(CONTROL_ID_CODE)); #endif #ifdef CONFIG_USBOOT_MEMTEST /* the device will power off after the test */ mem_test(); /*power off PMIC */ printf("Memtest done, powering off!\n"); select_bus(CFG_I2C_BUS, CFG_I2C_SPEED); val = SWITCH_OFF; i2c_write(TWL6030_PMC_ID, PHOENIX_DEV_ON, 1, &val, 1); /* we should never get here */ hang(); #endif #ifdef START_LOADB_DOWNLOAD strcpy(boot_dev_name, "UART"); do_load_serial_bin (CFG_LOADADDR, 115200); #else buf = (uchar *) (CFG_LOADADDR - 0x120); image.data = (uchar *) (CFG_LOADADDR - 0x120); switch (get_boot_device()) { #ifdef CONFIG_USBBOOT case 0x45: printf("boot_dev=USB\n"); strcpy(boot_dev_name, "USB"); /* read data from usb and write to sdram */ if (usb_read_bootloader(&len) != 0) { hang(); } printf("usb read len=%d\n", len); break; #else case 0x03: strcpy(boot_dev_name, "ONENAND"); #if defined(CFG_ONENAND) for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++) { if (!onenand_read_block(buf, i)) buf += ONENAND_BLOCK_SIZE; else goto error; } #endif break; case 0x02: default: strcpy(boot_dev_name, "NAND"); #if defined(CFG_NAND) for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE) { if (!nand_read_block(buf, i)) buf += NAND_BLOCK_SIZE; /* advance buf ptr */ } #endif break; case 0x05: strcpy(boot_dev_name, "MMC/SD1"); #if defined(CONFIG_MMC) if (mmc_read_bootloader(0) != 0) goto error; #endif break; case 0x06: strcpy(boot_dev_name, "EMMC"); #if defined(CONFIG_MMC) if (mmc_read_bootloader(1) != 0) goto error; #endif break; #endif /* CONFIG_USBBOOT */ }; #endif SEC_ENTRY_Std_Ppa_Call ( PPA_SERV_HAL_BN_CHK , 1 , &image ); if ( image.val == 0 ) { /* go run U-Boot and never return */ printf("Starting OS Bootloader from %s ...\n", boot_dev_name); ((init_fnc_t *)CFG_LOADADDR)(); } /* should never come here */ #if defined(CFG_ONENAND) || defined(CONFIG_MMC) error: #endif printf("Could not read bootloader!\n"); hang(); #endif /* CONFIG_USBBOOT_ERASER */ }
void off_mode_charging( void ) { int bootup_reason = BOOTUP_UNKNOWN; #if CONFIG_MAX17043_GAUGE union power_supply_propval BatteryVol = {0,}; union power_supply_propval BatteryCap = {0,}; int model_count = 0; #elif CONFIG_TWL4030_MADC_VBAT int BatteryCap = 0, BatteryVol = 0; #endif #ifdef CONFIG_DISCHARGING_EXPERIMENTATION int quick_once = 1; #endif #if CONFIG_MAX17043_GAUGE select_bus(1, 100); off_mode_charging_info.write_model_false = max17043_write_custom_model(); mdelay(500); //#ifndef CONFIG_DISCHARGING_EXPERIMENTATION //if(!off_mode_charging_info.write_model_false) //{ //max17043_quick_start(); //mdelay(1000); //} //#endif #elif CONFIG_TWL4030_MADC_VBAT twl4030_vadc_onoff(1); twl4030_madc_init(); #endif bootup_reason = off_mode_charging_info.bootup_reason; while (1) { #if CONFIG_MAX17043_GAUGE // select I2C2 select_bus(1, 100); ds278x_battery_get_property(POWER_SUPPLY_PROP_VOLTAGE_NOW, &BatteryVol); ds278x_battery_get_property(POWER_SUPPLY_PROP_CAPACITY, &BatteryCap); if (off_mode_charging_info.write_model_false) { model_count++; if ((model_count%2) == 0) { off_mode_charging_info.write_model_false = off_mode_custom_model_retry(); } } #elif CONFIG_TWL4030_MADC_VBAT BatteryVol = twl4030_get_battery_voltage(); printf("**** Off Mode Charging(from MADC) *****\n"); printf("**** VOLTAGE: %d ********\n", BatteryVol); printf("**** End Of Off Mode Charging ****\n"); #endif //mdelay(1000); // select I2C1 select_bus(0, 100); off_mode_charging_info.cable_exist = dc_ok_detect(); #ifdef CONFIG_DISCHARGING_EXPERIMENTATION off_mode_charging_info.cable_exist = 0; #endif if ((twl4030_bootup_reason_get() & BOOTUP_POWER_KEY) || (bootup_reason & BOOTUP_POWER_KEY)) { //&*&*&*HC1_20110503, Adjust long press time (ref. bsp spec v0.6) //&*&*&*HC1_20110428, enable pwr key long press function #if CONFIG_PWRKEY_LONGPRESS if ((bootup_reason != BOOTUP_POWER_KEY) && (!pwrkey_press_check(PWRKEY_PRESS_TIME_CHARGING, bootup_reason))) { bootup_reason = BOOTUP_UNKNOWN; continue; } #endif // CONFIG_PWRKEY_LONGPRESS //&*&*&*HC2_20110428, enable pwr key long press function //&*&*&*HC2_20110503, Adjust long press time (ref. bsp spec v0.6) #if (defined(CONFIG_TWL4030_MADC_VBAT) || defined(CONFIG_MAX17043_GAUGE)) //&*&*&*AL1_20110528, different voltage between cable exist and not. #if CONFIG_MAX17043_GAUGE if((BatteryVol.intval < POWER_ON_VOLTAGE_NO_CABLE) && (off_mode_charging_info.cable_exist == 1)) { bootup_reason = BOOTUP_UNKNOWN; #if CONFIG_KEY_LIGHT_NOTIFICATION key_light_flash(3); #endif // CONFIG_KEY_LIGHT_NOTIFICATION printf("Battery voltage < 3.5V with no cable, can't boot up !!!\n"); } else if((off_mode_charging_info.CableInType == CABLE_AC) && (off_mode_charging_info.cable_exist == 0)) { if(BatteryVol.intval < POWER_ON_VOLTAGE_WITH_AC_CABLE) { bootup_reason = BOOTUP_UNKNOWN; #if CONFIG_KEY_LIGHT_NOTIFICATION key_light_flash(3); #endif // CONFIG_KEY_LIGHT_NOTIFICATION printf("Battery voltage < 3.3V with AC cable, can't boot up !!!\n"); } else break; } else if((off_mode_charging_info.CableInType == CABLE_USB) && (off_mode_charging_info.cable_exist == 0)) { if(BatteryVol.intval < POWER_ON_VOLTAGE_WITH_USB_CABLE) { bootup_reason = BOOTUP_UNKNOWN; #if CONFIG_KEY_LIGHT_NOTIFICATION key_light_flash(3); #endif // CONFIG_KEY_LIGHT_NOTIFICATION printf("Battery voltage < 3.5V with USB cable, can't boot up !!!\n"); } else break; } //&*&*&*AL2_20110528, different voltage between cable exist and not. #elif CONFIG_TWL4030_MADC_VBAT if(BatteryVol < POWER_ON_VOLTAGE) { bootup_reason = BOOTUP_UNKNOWN; printf("Battery voltage < 3.6V with no cable, can't boot up !!!\n"); } #endif else { #if CONFIG_KEY_LIGHT_NOTIFICATION // power on, keep key light on key_light_flash(0); #endif // CONFIG_KEY_LIGHT_NOTIFICATION break; } #else printf("No battery voltage checking implementation! !!\n"); break; #endif //&*&*&*HC2_20110103, enable the battery check //&*&*&*HC2_20101230, disable the battery check } if(off_mode_charging_info.cable_exist == 1) { printf("Not a vaild long press !!! Please press and hold pwr key more than 1 sec.\n"); twl4030_poweroff(); break; } else { if (off_mode_charging_info.CableInType == CABLE_UNKNOW) { off_mode_charging_info.CableInType = twl4030_get_cable_type(); if(off_mode_charging_info.CableInType == USB_EVENT_VBUS) { off_mode_charging_info.CableInType = CABLE_USB; printf("\n **** USB Cable: Start 500mA**** \n"); } else { off_mode_charging_info.CableInType = CABLE_AC; printf("\n **** AC Cable: Start 1500mA**** \n"); } #if CONFIG_CHARGING_REDUCE_SYS_LOAD pre_charging_configure(); change_cpu_freq(0); change_mem_freq(0); off_mode_charging_info.enter_reduce_frequencce = 1; #endif //CHARGING_REDUCE_SYS_LOAD } if(off_mode_charging_info.CableInType == CABLE_AC) charging_mode(CHARGING_START_1000MA); else charging_mode(CHARGING_START_500MA); } #ifdef CONFIG_MAX17043_DEBUG_MESSAGE_FORMAT select_bus(1, 100); max1704x_register_dump(); mdelay(5000); #endif mdelay(1000); // control charging LED off_mode_charging_info.is_charging_complete = chg_status_detect(); charging_led_notification(off_mode_charging_info.is_charging_complete, BatteryCap.intval); off_mode_charging_info.charging_fault = chg_fault_detect(); /* wait for redeuce frequence to get accurate capacity */ #ifdef CONFIG_DISCHARGING_EXPERIMENTATION if(!off_mode_charging_info.write_model_false && quick_once) { select_bus(1, 100); max17043_quick_start(); mdelay(1000); quick_once = 0; } //if(BatteryCap.intval == 2) //{ //select_bus(0, 100); //twl4030_poweroff(); //break; //} #endif if(off_mode_charging_info.charging_fault == 0) { printf("\n **** charging_fault:%d, charging time out, re-toggle CEN pin.***** \n", off_mode_charging_info.charging_fault); charging_mode(CHARGING_STOP); } printf("\n"); } }
/* * * The main worker-thread for the i2c-dev device * Enters an endless loop that waits for commands and * executes them. * * Currently we only support GA-devices * */ void *thr_sendrec_I2C_DEV(void *v) { char msg[1000]; ga_state_t gatmp; int last_cancel_state, last_cancel_type; bus_thread_t *btd = (bus_thread_t *) malloc(sizeof(bus_thread_t)); if (btd == NULL) pthread_exit((void *) 1); btd->bus = (bus_t) v; btd->fd = -1; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_cancel_state); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &last_cancel_type); /*register cleanup routine */ pthread_cleanup_push((void *) end_bus_thread, (void *) btd); syslog_bus(btd->bus, DBG_INFO, "i2c-dev bus started (device = %s).", buses[btd->bus].device.file.path); I2CDEV_DATA *data = buses[btd->bus].driverdata; int ga_reset_devices = data->ga_reset_devices; buses[btd->bus].watchdog = 1; /* command processing starts here */ while (true) { /* process POWER changes */ if (buses[btd->bus].power_changed == 1) { /* dummy select, power state is directly read by select_bus() */ select_bus(0, btd->bus); buses[btd->bus].power_changed = 0; infoPower(btd->bus, msg); enqueueInfoMessage(msg); if ((ga_reset_devices == 1) && (buses[btd->bus].power_state == 1)) { reset_ga(btd->bus); } } /* do nothing, if power is off */ if (buses[btd->bus].power_state == 0) { if (usleep(1000) == -1) { syslog_bus(btd->bus, DBG_ERROR, "usleep() failed: %s (errno = %d)\n", strerror(errno), errno); } continue; } buses[btd->bus].watchdog = 4; /* process GA commands */ if (!queue_GA_isempty(btd->bus)) { dequeueNextGA(btd->bus, &gatmp); handle_i2c_set_ga(btd->bus, &gatmp); setGA(btd->bus, gatmp.id, gatmp); select_bus(0, btd->bus); buses[btd->bus].watchdog = 6; } if (usleep(1000) == -1) { syslog_bus(btd->bus, DBG_ERROR, "usleep() failed: %s (errno = %d)\n", strerror(errno), errno); } } /*run the cleanup routine */ pthread_cleanup_pop(1); return NULL; }
/* Handle set command of GA */ static int handle_i2c_set_ga(bus_t bus, ga_state_t * gatmp) { I2C_ADDR i2c_addr; I2C_VALUE i2c_val; I2C_VALUE value; I2C_PORT port; I2C_MUX_BUS mult_busnum; I2CDEV_DATA *data = (I2CDEV_DATA *) buses[bus].driverdata; int addr; int reset_old_value; int ga_min_active_time = data->ga_min_active_time; int ga_hardware_inverters = data->ga_hardware_inverters; addr = gatmp->id; port = gatmp->port; value = gatmp->action; mult_busnum = (addr / 256) + 1; select_bus(mult_busnum, bus); i2c_addr = (addr % 256); /* gettimeofday(gatmp->tv[0], NULL); */ if (gatmp->activetime >= 0) { gatmp->activetime = (gatmp->activetime > ga_min_active_time) ? gatmp->activetime : ga_min_active_time; reset_old_value = 1; } else { gatmp->activetime = ga_min_active_time; /* always wait minimum time */ reset_old_value = 0; } syslog_bus(bus, DBG_DEBUG, "i2c_addr = %d on multiplexed bus #%d", i2c_addr, mult_busnum); /* port: 0 - direct write of value to device */ /* other - select port pins directly, value = {0,1} */ if (port == 0) { /* write directly to device */ if (ga_hardware_inverters == 1) { i2c_val = ~value; } else { i2c_val = value; } } else { /* set bit for selected port to 1 */ I2C_VALUE pin_bit = 1 << (port - 1); value = (value & 1); i2c_val = data->i2c_values[i2c_addr][mult_busnum - 1]; if (ga_hardware_inverters == 1) { value = (~value) & 1; } if (value != 0) { /* Set bit */ i2c_val |= pin_bit; } else { /* Reset bit */ i2c_val &= (~pin_bit); } } if (write_i2c_dev(bus, i2c_addr, i2c_val) < 0) { syslog_bus(bus, DBG_ERROR, "Device not found at address %d", addr); return (-1); } if (usleep((unsigned long) gatmp->activetime * 1000) == -1) { syslog_bus(bus, DBG_ERROR, "usleep() failed: %s (errno = %d)\n", strerror(errno), errno); } if (reset_old_value == 1) { if (write_i2c_dev (bus, i2c_addr, data->i2c_values[i2c_addr][mult_busnum - 1]) < 0) { syslog_bus(bus, DBG_ERROR, "Device not found at address %d", addr); return (-1); } if (usleep((unsigned long) gatmp->activetime * 1000) == -1) { syslog_bus(bus, DBG_ERROR, "usleep() failed: %s (errno = %d)\n", strerror(errno), errno); } } else { data->i2c_values[i2c_addr][mult_busnum - 1] = i2c_val; } return (0); }
int off_mode_start( void ) { printf(" +++ off_mode_start +++\n"); int bootup_reason; off_mode_charging_info.battery_info = g_BatteryID; printf(" #### Battery ID: %d ####\n", off_mode_charging_info.battery_info); off_mode_charging_info.bootup_reason = twl4030_bootup_reason_get(); bootup_reason = off_mode_charging_info.bootup_reason; if (bootup_reason == BOOTUP_8S_OFF) { printf("[pwr key 8s]: "); bootup_reason = BOOTUP_POWER_KEY; } else if (bootup_reason == BOOTUP_8S_OFF_CABLE) { printf("[pwr key 8s + cable]: "); bootup_reason = BOOTUP_CABLE_IN; } //&*&*&*HC1_20110727, Add rtc bootup check else if (bootup_reason == BOOTUP_8S_OFF_RTC) { printf("[pwr key 8s + rtc]: "); bootup_reason = BOOTUP_RTC; } //&*&*&*HC2_20110727, Add rtc bootup check // select I2C0 select_bus(0, 100); if (bootup_reason & BOOTUP_POWER_KEY) { printf("power key detect...\n"); //&*&*&*HC1_20110503, Adjust long press time (ref. bsp spec v0.6) //&*&*&*HC1_20110428, enable pwr key long press function #if CONFIG_PWRKEY_LONGPRESS if (pwrkey_press_check(PWRKEY_PRESS_TIME_STARTUP, bootup_reason)) bootup_reason = BOOTUP_POWER_KEY; else bootup_reason = BOOTUP_UNKNOWN; #endif // #if CONFIG_PWRKEY_LONGPRESS //&*&*&*HC2_20110428, enable pwr key long press function //&*&*&*HC2_20110503, Adjust long press time (ref. bsp spec v0.6) off_mode_charging_info.bootup_reason = bootup_reason; off_mode_charging(); } else if (bootup_reason & BOOTUP_CABLE_IN) { printf("cable detect...\n"); off_mode_charging_info.bootup_reason = bootup_reason; off_mode_charging(); } else if (bootup_reason & BOOTUP_BATTERY_DETECT) { printf("battery detect...\n"); #ifdef CONFIG_DISCHARGING_EXPERIMENTATION off_mode_charging(); #else twl4030_poweroff(); #endif } //&*&*&*HC1_20110727, Add rtc bootup check else if (bootup_reason & BOOTUP_RTC) { printf("rtc alarm...\n"); twl4030_alarm_it_enable(0); twl4030_poweroff(); } //&*&*&*HC2_20110727, Add rtc bootup check else { //&*&*&*HC1_20110221, let reboot pass the check printf("reboot ...\n"); //&*&*&*HC2_20110221, let reboot pass the check } #if CONFIG_CHARGING_REDUCE_SYS_LOAD //if (bootup_reason & BOOTUP_CABLE_IN) if(off_mode_charging_info.enter_reduce_frequencce) { change_mem_freq(1); change_cpu_freq(1); post_charging_configure(); } printf("end of uBoot boot_reason :%d...\n", bootup_reason); #endif //CHARGING_REDUCE_SYS_LOAD return 0; }
int muic_init(int isFactoryReset) { unsigned int retain_mode = NO_RETAIN; unsigned char i2c_ret; unsigned char reg_val; unsigned char muic_device; MUIC_MODE_TYPE muic_mode = MUIC_OPEN; char cmd_line[256]; strcpy(cmd_line, getenv("bootargs")); #if defined(CONFIG_COSMO_EVB_B) || defined(CONFIG_COSMO_EVB_C) printf("muic chip : I2C4\n"); select_bus(I2C4 , OMAP_I2C_STANDARD); #else printf("muic chip : I2C3\n"); select_bus(I2C3 , OMAP_I2C_STANDARD); #endif i2c_init(OMAP_I2C_STANDARD, MUIC_SLAVE_ADDR); i2c_ret = muic_i2c_read_byte(DEVICE_ID, ®_val); if ((reg_val & 0xf0) == 0x10) muic_device = TS5USBA33402; else if ((reg_val & 0xf0) == 0x20) muic_device = MAX14526; else if ((reg_val & 0xf0) == ANY_VANDOR_ID) muic_device = ANY_VANDOR; if (downloadkey()){ write_muic_retain_mode(NO_RETAIN); printf("[MUIC] No retain\n"); } retain_mode = read_muic_retain_mode(); printf("muic_init muic vendor : %d, reg_val:0x%x, retain_mode = %d\n", muic_device, reg_val, retain_mode); if (muic_device == TS5USBA33402) { printf("muic chip : TS5USBA33402\n"); if (retain_mode == RETAIN_AP_USB) { muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN); muic_i2c_write_byte(SW_CONTROL, USB); muic_mode = MUIC_USB; check_charging_mode(&muic_mode); printf("[MUIC] retain AP_USB\n"); printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n"); printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n"); strcat(cmd_line, " muic=2"); setenv("bootargs", cmd_line); } else if (retain_mode == RETAIN_CP_USB) { muic_i2c_write_byte(SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mode = MUIC_USB; check_charging_mode(&muic_mode); printf("[MUIC] retain CP_USB\n"); strcat(cmd_line, " muic=3"); setenv("bootargs", cmd_line); } else muic_mode = muic_device_ts5usba33402(isFactoryReset, cmd_line); } else if (muic_device == MAX14526) { printf("muic chip : MAX14526\n"); if (retain_mode == RETAIN_AP_USB) { muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN); muic_i2c_write_byte(SW_CONTROL, USB); muic_mode = MUIC_USB; check_charging_mode(&muic_mode); printf("[MUIC] retain AP_USB\n"); printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n"); printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n"); strcat(cmd_line, " muic=2"); setenv("bootargs", cmd_line); } else if (retain_mode == RETAIN_CP_USB) { muic_i2c_write_byte(SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mode = MUIC_USB; check_charging_mode(&muic_mode); printf("[MUIC] retain CP_USB\n"); strcat(cmd_line, " muic=3"); setenv("bootargs", cmd_line); } else muic_mode = muic_device_max14526(isFactoryReset, cmd_line); } else printf("[MUIC] ANY VENDOR, Not supported\n"); select_bus(I2C1, OMAP_I2C_STANDARD); return muic_mode; }