static int ov2680_s_config(struct v4l2_subdev *sd, int irq, void *platform_data) { struct ov2680_device *dev = to_ov2680_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = 0; if (!platform_data) return -ENODEV; dev->platform_data = (struct camera_sensor_platform_data *)platform_data; mutex_lock(&dev->input_lock); /* power off the module, then power on it in future * as first power on by board may not fulfill the * power on sequqence needed by the module */ ret = power_down(sd); if (ret) { dev_err(&client->dev, "ov2680 power-off err.\n"); goto fail_power_off; } ret = power_up(sd); if (ret) { dev_err(&client->dev, "ov2680 power-up err.\n"); goto fail_power_on; } ret = dev->platform_data->csi_cfg(sd, 1); if (ret) goto fail_csi_cfg; /* config & detect sensor */ ret = ov2680_detect(client); if (ret) { dev_err(&client->dev, "ov2680_detect err s_config.\n"); goto fail_csi_cfg; } /* turn off sensor, after probed */ ret = power_down(sd); if (ret) { dev_err(&client->dev, "ov2680 power-off err.\n"); goto fail_csi_cfg; } mutex_unlock(&dev->input_lock); return 0; fail_csi_cfg: dev->platform_data->csi_cfg(sd, 0); fail_power_on: power_down(sd); dev_err(&client->dev, "sensor power-gating failed\n"); fail_power_off: mutex_unlock(&dev->input_lock); return ret; }
static int ov5693_s_config(struct v4l2_subdev *sd, int irq, void *platform_data) { struct ov5693_device *dev = to_ov5693_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = 0; if (platform_data == NULL) return -ENODEV; mutex_lock(&dev->input_lock); dev->platform_data = platform_data; ret = power_up(sd); if (ret) { dev_err(&client->dev, "ov5693 power-up err.\n"); goto fail_power_on; } ret = dev->platform_data->csi_cfg(sd, 1); if (ret) goto fail_csi_cfg; /* config & detect sensor */ ret = ov5693_detect(client); if (ret) { dev_err(&client->dev, "ov5693_detect err s_config.\n"); goto fail_csi_cfg; } /* turn off sensor, after probed */ ret = power_down(sd); if (ret) { dev_err(&client->dev, "ov5693 power-off err.\n"); goto fail_csi_cfg; } mutex_unlock(&dev->input_lock); return 0; fail_csi_cfg: dev->platform_data->csi_cfg(sd, 0); fail_power_on: power_down(sd); dev_err(&client->dev, "sensor power-gating failed\n"); mutex_unlock(&dev->input_lock); return ret; }
static int isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) { struct isp1301 *isp = container_of(otg, struct isp1301, otg); if (!otg || isp != the_transceiver) return -ENODEV; if (!gadget) { OTG_IRQ_EN_REG = 0; if (!isp->otg.default_a) enable_vbus_draw(isp, 0); usb_gadget_vbus_disconnect(isp->otg.gadget); isp->otg.gadget = 0; power_down(isp); return 0; } #ifdef CONFIG_USB_OTG isp->otg.gadget = gadget; dev_dbg(&isp->client.dev, "registered gadget\n"); /* gadget driver may be suspended until vbus_connect () */ if (isp->otg.host) return isp1301_otg_enable(isp); return 0; #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE) isp->otg.gadget = gadget; // FIXME update its refcount OTG_CTRL_REG = (OTG_CTRL_REG & OTG_CTRL_MASK & ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS)) | OTG_ID; power_up(isp); isp->otg.state = OTG_STATE_B_IDLE; if (machine_is_omap_h2()) isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, INTR_SESS_VLD); isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, INTR_VBUS_VLD); dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); dump_regs(isp, __func__); /* If this has a Mini-AB connector, this mode is highly * nonstandard ... but can be handy for testing, so long * as you don't plug a Mini-A cable into the jack. */ if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD) b_peripheral(isp); return 0; #else dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n"); return -EINVAL; #endif }
static int ov5693_s_power(struct v4l2_subdev *sd, int on) { struct ov5693_device *dev = to_ov5693_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = 0; mutex_lock(&dev->input_lock); if (on == 0) { if (dev->vcm_driver && dev->vcm_driver->power_down) ret = dev->vcm_driver->power_down(sd); if (ret) dev_err(&client->dev, "vcm power-down failed.\n"); ret = power_down(sd); } else { ret = power_up(sd); if (ret) goto done; ret = ov5693_init(sd); if (ret) goto done; if (dev->vcm_driver && dev->vcm_driver->power_up) ret = dev->vcm_driver->power_up(sd); if (ret) dev_err(&client->dev, "vcm power-up failed.\n"); } done: mutex_unlock(&dev->input_lock); return ret; }
int pm_suspend_disk(void) { int error; if ((error = prepare())) return error; pr_debug("PM: Attempting to suspend to disk.\n"); if (pm_disk_mode == PM_DISK_FIRMWARE) return pm_ops->enter(PM_SUSPEND_DISK); pr_debug("PM: snapshotting memory.\n"); in_suspend = 1; if ((error = swsusp_suspend())) goto Done; if (in_suspend) { pr_debug("PM: writing image.\n"); error = swsusp_write(); if (!error) power_down(pm_disk_mode); } else pr_debug("PM: Image restored successfully.\n"); swsusp_free(); Done: finish(); return error; }
int hibernate(void) { int error; mutex_lock(&pm_mutex); /* The snapshot device should not be opened while we're running */ if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { error = -EBUSY; goto Unlock; } error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); if (error) goto Exit; /* Allocate memory management structures */ error = create_basic_memory_bitmaps(); if (error) goto Exit; printk("Syncing filesystems ... "); sys_sync(); printk("done.\n"); error = prepare_processes(); if (error) goto Finish; if (hibernation_mode == HIBERNATION_TESTPROC) { printk("swsusp debug: Waiting for 5 seconds.\n"); mdelay(5000); goto Thaw; } error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); if (in_suspend && !error) { unsigned int flags = 0; if (hibernation_mode == HIBERNATION_PLATFORM) flags |= SF_PLATFORM_MODE; pr_debug("PM: writing image.\n"); error = swsusp_write(flags); swsusp_free(); if (!error) power_down(); } else { pr_debug("PM: Image restored successfully.\n"); swsusp_free(); } Thaw: unprepare_processes(); Finish: free_basic_memory_bitmaps(); Exit: pm_notifier_call_chain(PM_POST_HIBERNATION); atomic_inc(&snapshot_device_available); Unlock: mutex_unlock(&pm_mutex); return error; }
void quit(void) { if (buffer != NULL) free(buffer); power_down(); exit(1); }
/* * Called by SANE to read data. * * From the SANE spec: * This function is used to read image data from the device * represented by handle h. Argument buf is a pointer to a memory * area that is at least maxlen bytes long. The number of bytes * returned is stored in *len. A backend must set this to zero when * the call fails (i.e., when a status other than SANE_STATUS_GOOD is * returned). * * When the call succeeds, the number of bytes returned can be * anywhere in the range from 0 to maxlen bytes. */ SANE_Status sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len) { struct scanner *s = (struct scanner *) handle; SANE_Status ret=SANE_STATUS_GOOD; DBG (10, "sane_read: start\n"); *len = 0; /* cancelled? */ if(!s->started){ DBG (5, "sane_read: call sane_start first\n"); return SANE_STATUS_CANCELLED; } /* have sent all of current buffer */ if(s->bytes_tx == s->bytes_rx){ /* at end of data, stop */ if(s->paperless_lines >= MAX_PAPERLESS_LINES){ DBG (15, "sane_read: returning eof\n"); power_down(s); return SANE_STATUS_EOF; } /* more to get, reset and go */ s->bytes_tx = 0; s->bytes_rx = 0; if(s->mode == MODE_COLOR){ ret = read_from_scanner_color(s); } else{ ret = read_from_scanner_gray(s); } if(ret){ DBG(5,"sane_read: returning %d\n",ret); return ret; } } /* data in current buffer, send some of it */ *len = s->bytes_rx - s->bytes_tx; if(*len > max_len){ *len = max_len; } memcpy(buf,s->buffer+s->bytes_tx,*len); s->bytes_tx += *len; DBG (10, "sane_read: %d,%d,%d finish\n", *len,s->bytes_rx,s->bytes_tx); return ret; }
void read_chip(void) { int r; power_up(); r = chips[chipindex].read_func(buffersize, pagesize); file_save(); power_down(); }
/* add or disable the host device+driver */ static int isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) { struct isp1301 *isp = container_of(otg, struct isp1301, otg); if (!otg || isp != the_transceiver) return -ENODEV; if (!host) { omap_writew(0, OTG_IRQ_EN); power_down(isp); isp->otg.host = NULL; return 0; } #ifdef CONFIG_USB_OTG isp->otg.host = host; dev_dbg(&isp->client->dev, "registered host\n"); host_suspend(isp); if (isp->otg.gadget) return isp1301_otg_enable(isp); return 0; #elif !defined(CONFIG_USB_GADGET_OMAP) // FIXME update its refcount isp->otg.host = host; power_up(isp); if (machine_is_omap_h2()) isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); dev_info(&isp->client->dev, "A-Host sessions ok\n"); isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, INTR_ID_GND); isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, INTR_ID_GND); /* If this has a Mini-AB connector, this mode is highly * nonstandard ... but can be handy for testing, especially with * the Mini-A end of an OTG cable. (Or something nonstandard * like MiniB-to-StandardB, maybe built with a gender mender.) */ isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV); dump_regs(isp, __func__); return 0; #else dev_dbg(&isp->client->dev, "host sessions not allowed\n"); return -EINVAL; #endif }
int probe_chip (void) { int i; power_up (); for (i = 0; chips[i].name != NULL; i++) { chips[i].probe_func(); if ((chips[i].id1 == id1) && (chips[i].id2 == id2)) { chipindex = i; chip_selected (); power_down (); return 1; }; }; chipindex = i - 1; power_down (); return -1; }
int pm_suspend_disk(void) { int error; error = prepare_processes(); if (error) return error; if (pm_disk_mode == PM_DISK_TESTPROC) return 0; suspend_console(); error = device_suspend(PMSG_FREEZE); if (error) { resume_console(); printk("Some devices failed to suspend\n"); goto Thaw; } if (pm_disk_mode == PM_DISK_TEST) { printk("swsusp debug: Waiting for 5 seconds.\n"); mdelay(5000); goto Done; } pr_debug("PM: snapshotting memory.\n"); in_suspend = 1; if ((error = swsusp_suspend())) goto Done; if (in_suspend) { device_resume(); resume_console(); pr_debug("PM: writing image.\n"); error = swsusp_write(); if (!error) power_down(pm_disk_mode); else { swsusp_free(); goto Thaw; } } else { pr_debug("PM: Image restored successfully.\n"); } swsusp_free(); Done: device_resume(); resume_console(); Thaw: unprepare_processes(); return error; }
static int ov2680_s_power(struct v4l2_subdev *sd, int on) { int ret; if (on == 0){ ret = power_down(sd); } else { ret = power_up(sd); if (!ret) return ov2680_init(sd); } return ret; }
int main(uint32_t arg, uint32_t *result_id) { switch(boot_decision(get_context())) { case BOOT_ROCK: *result_id = arg; return BOOT_ROM_SECTION; case BOOT_OF: return BOOT_ROM_CONTINUE; case BOOT_STOP: default: power_down(); } }
void suspend_power_down(void) { #ifdef NO_SUSPEND_POWER_DOWN ; #elif defined(SUSPEND_MODE_NOPOWERSAVE) ; #elif defined(SUSPEND_MODE_STANDBY) standby(); #elif defined(SUSPEND_MODE_IDLE) idle(); #else power_down(WDTO_15MS); #endif }
void erase_chip(void) { int r, b; power_up(); r = chips[chipindex].erase_func(buffersize, pagesize); b = generic_blank_check(buffersize, pagesize); power_down(); if (r < 0 || b < 0) msg_error(); }
void program_chip(void) { int r, b, v; file_open(); power_up(); chips[chipindex].erase_func(buffersize, pagesize); b = generic_blank_check(buffersize, pagesize); r = chips[chipindex].burn_func(buffersize, pagesize); v = generic_verify(buffersize, pagesize); power_down(); if (r < 0 || b < 0 || v < 0) msg_error(); }
/** * power_down - Shut the machine down for hibernation. * * Use the platform driver, if configured, to put the system into the sleep * state corresponding to hibernation, or try to power it off or reboot, * depending on the value of hibernation_mode. */ static void power_down(void) { #ifdef CONFIG_SUSPEND int error; #endif switch (hibernation_mode) { case HIBERNATION_REBOOT: kernel_restart(NULL); break; case HIBERNATION_PLATFORM: hibernation_platform_enter(); case HIBERNATION_SHUTDOWN: if (pm_power_off) kernel_power_off(); break; #ifdef CONFIG_SUSPEND case HIBERNATION_SUSPEND: error = suspend_devices_and_enter(PM_SUSPEND_MEM); if (error) { if (hibernation_ops) hibernation_mode = HIBERNATION_PLATFORM; else hibernation_mode = HIBERNATION_SHUTDOWN; power_down(); } /* * Restore swap signature. */ error = swsusp_unmark(); if (error) printk(KERN_ERR "PM: Swap will be unusable! " "Try swapon -a.\n"); return; #endif } kernel_halt(); /* * Valid image is on the disk, if we continue we risk serious data * corruption after resume. */ printk(KERN_CRIT "PM: Please power down manually\n"); while (1) cpu_relax(); }
chrono::millis Low_Power::power_down_int(chrono::millis millis, ADC_t adc, BOD_t bod) { s_interrupt_fired = false; attachInterrupt(0, pinInterrupt, FALLING); if (s_interrupt_fired) { detachInterrupt(0); s_interrupt_fired = false; return millis; } chrono::millis remaining = power_down(millis, adc, bod); detachInterrupt(0); s_interrupt_fired = false; return remaining; }
static int hm5040_s_power(struct v4l2_subdev *sd, int on) { struct hm5040_device *dev = to_hm5040_sensor(sd); int ret; pr_info("%s: on %d\n", __func__, on); if (on == 0) { if (dev->vcm_driver && dev->vcm_driver->power_down) ret = dev->vcm_driver->power_down(sd); return power_down(sd); } else { if (dev->vcm_driver && dev->vcm_driver->power_up) ret = dev->vcm_driver->power_up(sd); ret = power_up(sd); if (!ret) return hm5040_init(sd); } return ret; }
int main(int argc, char *argv[]) { int which; int time; if ( argc <2 ) { printf("Usage: %s <KickerNumber> <Duration>\n",argv[0]); printf(" 0xF000 0xF000 -> Master OFF (default)\n"); printf(" 0xFFFF 0xFFFF -> Master ON\n"); return(3); } initKicker(); if (argc==3) { which = atoi(argv[1]); time = atoi(argv[2]); kick(which,time); } if (argc==2) { printf("Argv = %s \n",argv[1]); if (strcmp(argv[1],"on")==0) power_up(); if (strcmp(argv[1],"off")==0) power_down(); } deinitKicker(); return 0; }
int pm_suspend_disk(void) { int error; error = prepare_processes(); if (error) return error; error = device_suspend(PMSG_FREEZE); if (error) { printk("Some devices failed to suspend\n"); unprepare_processes(); return error; } pr_debug("PM: snapshotting memory.\n"); in_suspend = 1; if ((error = swsusp_suspend())) goto Done; if (in_suspend) { pr_debug("PM: writing image.\n"); error = swsusp_write(); if (!error) power_down(pm_disk_mode); else { /* swsusp_write can not fail in device_resume, no need to do second device_resume */ swsusp_free(); unprepare_processes(); return error; } } else pr_debug("PM: Image restored successfully.\n"); swsusp_free(); Done: device_resume(); unprepare_processes(); return error; }
int pm_suspend_disk(void) { int error; if ((error = prepare())) return error; pr_debug("PM: Attempting to suspend to disk.\n"); if (pm_disk_mode == PM_DISK_FIRMWARE) return pm_ops->enter(PM_SUSPEND_DISK); pr_debug("PM: snapshotting memory.\n"); in_suspend = 1; if ((error = pmdisk_save())) goto Done; if (in_suspend) { pr_debug("PM: writing image.\n"); /* * FIXME: Leftover from swsusp. Are they necessary? */ mb(); barrier(); error = pmdisk_write(); if (!error) { error = power_down(pm_disk_mode); pr_debug("PM: Power down failed.\n"); } } else pr_debug("PM: Image restored successfully.\n"); pmdisk_free(); Done: finish(); return error; }
nsapi_error_t PPPCellularInterface::connect() { nsapi_error_t retcode; bool success; bool did_init = false; const char *apn_config = NULL; if (dev_info.ppp_connection_up) { return NSAPI_ERROR_IS_CONNECTED; } do { retry_init: /* setup AT parser */ setup_at_parser(); if (!initialized) { /* If we have hangup (eg DCD) detection, we don't want it active * as long as we are using ATCmdParser. * As soon as we get into data mode, we will turn it back on. */ enable_hup(false); if (!power_up()) { return NSAPI_ERROR_DEVICE_ERROR; } retcode = initialize_sim_card(); if (retcode != NSAPI_ERROR_OK) { return retcode; } success = nwk_registration(PACKET_SWITCHED) //perform network registration && get_CCID(_at)//get integrated circuit ID of the SIM && get_IMSI(_at)//get international mobile subscriber information && get_IMEI(_at)//get international mobile equipment identifier && get_MEID(_at)//its same as IMEI && set_CMGF(_at)//set message format for SMS && set_CNMI(_at);//set new SMS indication if (!success) { return NSAPI_ERROR_NO_CONNECTION; } #if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP if (!apn_config) { apn_config = apnconfig(dev_info.imsi); } #endif /* Check if user want skip SIM pin checking on boot up */ if (set_sim_pin_check_request) { retcode = do_sim_pin_check(_at, _pin); if (retcode != NSAPI_ERROR_OK) { return retcode; } /* set this request to false, as it is unnecessary to repeat in case of retry */ set_sim_pin_check_request = false; } /* check if the user requested a sim pin change */ if (change_pin) { retcode = do_change_sim_pin(_at, _pin, _new_pin); if (retcode != NSAPI_ERROR_OK) { return retcode; } /* set this request to false, as it is unnecessary to repeat in case of retry */ change_pin = false; } #if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP if (apn_config) { _apn = _APN_GET(apn_config); _uname = _APN_GET(apn_config); _pwd = _APN_GET(apn_config); tr_info("Looked up APN %s.", _apn); } #endif //sets up APN and IP protocol for external PDP context retcode = setup_context_and_credentials(); if (retcode != NSAPI_ERROR_OK) { return retcode; } if (!success) { shutdown_at_parser(); return NSAPI_ERROR_NO_CONNECTION; } initialized = true; did_init = true; } else { /* If we were already initialized, we expect to receive NO_CARRIER response * from the modem as we were kicked out of Data mode */ _at->recv("NO CARRIER"); success = _at->send("AT") && _at->recv("OK"); } /* Attempt to enter data mode */ success = set_atd(_at); //enter into Data mode with the modem if (!success) { power_down(); initialized = false; /* if we were previously initialized , i.e., not in this particular attempt, * we want to re-initialize */ if (!did_init) { goto retry_init; } /* shutdown AT parser before notifying application of the failure */ shutdown_at_parser(); return NSAPI_ERROR_NO_CONNECTION; } /* This is the success case. * Save RAM, discard AT Parser as we have entered Data mode. */ shutdown_at_parser(); /* We now want hangup (e.g., DCD) detection if available */ enable_hup(true); /* Initialize PPP * mbed_ppp_init() is a blocking call, it will block until * connected, or timeout after 30 seconds*/ retcode = nsapi_ppp_connect(_fh, _connection_status_cb, _uname, _pwd, _stack); if (retcode == NSAPI_ERROR_OK) { dev_info.ppp_connection_up = true; } }while(!dev_info.ppp_connection_up && apn_config && *apn_config); return retcode; }
/** * hibernate - Carry out system hibernation, including saving the image. */ int hibernate(void) { int error, nr_calls = 0; bool snapshot_test = false; if (!hibernation_available()) { pr_debug("Hibernation not available.\n"); return -EPERM; } lock_system_sleep(); /* The snapshot device should not be opened while we're running */ if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { error = -EBUSY; goto Unlock; } pm_prepare_console(); error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls); if (error) { nr_calls--; goto Exit; } pr_info("Syncing filesystems ... \n"); sys_sync(); pr_info("done.\n"); error = freeze_processes(); if (error) goto Exit; lock_device_hotplug(); /* Allocate memory management structures */ error = create_basic_memory_bitmaps(); if (error) goto Thaw; error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); if (error || freezer_test_done) goto Free_bitmaps; if (in_suspend) { unsigned int flags = 0; if (hibernation_mode == HIBERNATION_PLATFORM) flags |= SF_PLATFORM_MODE; if (nocompress) flags |= SF_NOCOMPRESS_MODE; else flags |= SF_CRC32_MODE; pr_debug("Writing image.\n"); error = swsusp_write(flags); swsusp_free(); if (!error) { if (hibernation_mode == HIBERNATION_TEST_RESUME) snapshot_test = true; else power_down(); } in_suspend = 0; pm_restore_gfp_mask(); } else { pr_debug("Image restored successfully.\n"); } Free_bitmaps: free_basic_memory_bitmaps(); Thaw: unlock_device_hotplug(); if (snapshot_test) { pr_debug("Checking hibernation image\n"); error = swsusp_check(); if (!error) error = load_image_and_restore(); } thaw_processes(); /* Don't bother checking whether freezer_test_done is true */ freezer_test_done = false; Exit: __pm_notifier_call_chain(PM_POST_HIBERNATION, nr_calls, NULL); pm_restore_console(); atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); return error; }
int switch_boot_mode(void) { // unsigned long hold_time = 50000, polling_time = 10000, tmp; unsigned long upgrade_step; int ret=0; act8942_init(&act8942_pdata); //act8942_dump(); upgrade_step = simple_strtoul (getenv ("upgrade_step"), NULL, 16); printf("upgrade_step = %d\n", upgrade_step); saradc_enable(); #ifdef ENABLE_FONT_RESOURCE RegisterFont(DEFAULT_FONT); #endif ret=isVolAKeyPress(); if(ret==1) aml_autoscript(); powerkey_hold(0); #ifdef CONFIG_AML_TINY_USBTOOL usb_boot(1); #endif if(upgrade_step == 2) { switch(reboot_mode) { case AMLOGIC_NORMAL_BOOT: { ret=keypress_to_upgrade(); if(ret==0) return 0; printf("AMLOGIC_NORMAL_BOOT...\n"); power_up(); logo_display(); return 1; } case AMLOGIC_FACTORY_RESET_REBOOT: { printf("AMLOGIC_FACTORY_RESET_REBOOT...\n"); power_up(); logo_display(); run_command ("nand read ${recovery_name} ${loadaddr} 0 ${recovery_size}", 0); run_command ("bootm", 0); break; } case AMLOGIC_UPDATE_REBOOT: { printf("AMLOGIC_UPDATE_REBOOT...\n"); power_up(); logo_display(); run_command ("set upgrade_step 0", 0); run_command ("save", 0); upgrade_step = 0; break; } default: { printf("AMLOGIC_CHARGING_REBOOT...\n"); if(is_ac_connected) { power_up(); #ifdef CONFIG_BATTERY_CHARGING //battery_charging(); #endif logo_display(); } else { powerkey_hold(0); #ifdef CONFIG_BATTERY_CHARGING if(get_powerkey_hold_count()) { logo_display(); if(get_battery_percentage() < 10) { power_low_display(); sdelay(2); power_down(); printf("Low Power!!!\nPower Down!\n"); hang(); } #else if(powerkey_hold(1000)) { #endif logo_display(); power_up(); printf("Power Up!\n"); } else { power_down(); printf("Power Down!\n"); hang(); } } break; } } } else { power_up(); printf("Upgrade step %d...\n", upgrade_step); } if(upgrade_step == 0) { #ifdef CONFIG_AML_TINY_USBTOOL usb_boot(1); #endif display_messge("upgrade step 1! Don't Power Off!"); if(upgrade_bootloader()) { run_command ("set upgrade_step 1", 0); run_command ("save", 0); run_command ("reset", 0); hang(); } else { printf("### ERROR: u-boot write failed!!!\n"); return -1; } } else if(upgrade_step == 1) { display_messge("upgrade step 2! Don't Power Off!"); run_command ("defenv", 0); run_command ("set upgrade_step 2", 0); run_command ("save", 0); into_recovery(); } //added by Elvis for added fool idle /*get_key(); get_key(); while(hold_time > 0) { udelay(polling_time); tmp = get_key(); printf("get_key(): %d\n", tmp); if(!tmp) break; hold_time -= polling_time; } if(hold_time > 0) { printf("Normal Start...\n"); return 1; } else { display_messge("upgrading... please wait"); if(upgrade_bootloader()) { run_command ("set upgrade_step 1", 0); run_command ("save", 0); run_command ("reset", 0); hang(); } run_command ("set upgrade_step 2", 0); run_command ("save", 0); into_recovery(); } */ ret=keypress_to_upgrade(); return ret; //return 0; }
static int __init isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { int status; struct isp1301 *isp; if (the_transceiver) return 0; isp = kzalloc(sizeof *isp, GFP_KERNEL); if (!isp) return 0; INIT_WORK(&isp->work, isp1301_work); init_timer(&isp->timer); isp->timer.function = isp1301_timer; isp->timer.data = (unsigned long) isp; i2c_set_clientdata(i2c, isp); isp->client = i2c; /* verify the chip (shouldn't be necesary) */ status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); if (status != I2C_VENDOR_ID_PHILIPS) { dev_dbg(&i2c->dev, "not philips id: %d\n", status); goto fail; } status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); if (status != I2C_PRODUCT_ID_PHILIPS_1301) { dev_dbg(&i2c->dev, "not isp1301, %d\n", status); goto fail; } isp->i2c_release = i2c->dev.release; i2c->dev.release = isp1301_release; /* initial development used chiprev 2.00 */ status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE); dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n", status >> 8, status & 0xff); /* make like power-on reset */ isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK); isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI); isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI); isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN); isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0); isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); #ifdef CONFIG_USB_OTG status = otg_bind(isp); if (status < 0) { dev_dbg(&i2c->dev, "can't bind OTG\n"); goto fail; } #endif if (machine_is_omap_h2()) { /* full speed signaling by default */ isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SPEED); isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_SPD_SUSP_CTRL); /* IRQ wired at M14 */ omap_cfg_reg(M14_1510_GPIO2); if (gpio_request(2, "isp1301") == 0) gpio_direction_input(2); isp->irq_type = IRQF_TRIGGER_FALLING; } isp->irq_type |= IRQF_SAMPLE_RANDOM; status = request_irq(i2c->irq, isp1301_irq, isp->irq_type, DRIVER_NAME, isp); if (status < 0) { dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", i2c->irq, status); goto fail; } isp->otg.dev = &i2c->dev; isp->otg.label = DRIVER_NAME; isp->otg.set_host = isp1301_set_host, isp->otg.set_peripheral = isp1301_set_peripheral, isp->otg.set_power = isp1301_set_power, isp->otg.start_srp = isp1301_start_srp, isp->otg.start_hnp = isp1301_start_hnp, enable_vbus_draw(isp, 0); power_down(isp); the_transceiver = isp; #ifdef CONFIG_USB_OTG update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); #endif dump_regs(isp, __func__); #ifdef VERBOSE mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); #endif status = otg_set_transceiver(&isp->otg); if (status < 0) dev_err(&i2c->dev, "can't register transceiver, %d\n", status); return 0; fail: kfree(isp); return -ENODEV; }
int main(void) { uint8_t i; uint16_t wakeup_sec; bool send; // delay 1s to avoid further communication with uart or RFM12 when my programmer resets the MC after 500ms... _delay_ms(1000); util_init(); check_eeprom_compatibility(DEVICETYPE_SOILMOISTUREMETER); // configure power pin for 74HC14D as output sbi(TRIGGERPWR_DDR, TRIGGERPWR_PIN); // read packetcounter, increase by cycle and write back packetcounter = e2p_generic_get_packetcounter() + PACKET_COUNTER_WRITE_CYCLE; e2p_generic_set_packetcounter(packetcounter); // read device id device_id = e2p_generic_get_deviceid(); dry_thr = e2p_soilmoisturemeter_get_drythreshold(); if (dry_thr == 0) // set default value if never initialized { dry_thr = 40000; } counter_min = e2p_soilmoisturemeter_get_minval(); if (counter_min == 0) // set default value if never initialized { counter_min = 30000; } avgIntInit = e2p_soilmoisturemeter_get_averagingintervalinit(); avgInt = e2p_soilmoisturemeter_get_averaginginterval(); smoothing_percentage = e2p_soilmoisturemeter_get_smoothingpercentage(); osccal_init(); uart_init(); UART_PUTS ("\r\n"); UART_PUTF4("smarthomatic Soil Moisture Meter v%u.%u.%u (%08lx)\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_HASH); UART_PUTS("(c) 2014..2015 Uwe Freese, www.smarthomatic.org\r\n"); osccal_info(); UART_PUTF ("DeviceID: %u\r\n", device_id); UART_PUTF ("PacketCounter: %lu\r\n", packetcounter); UART_PUTF ("AveragingInterval for initialization: %u\r\n", avgIntInit); UART_PUTF ("AveragingInterval for normal operation: %u\r\n", avgInt); UART_PUTF ("Dry threshold: %u\r\n", dry_thr); UART_PUTF ("Min value: %u\r\n", counter_min); UART_PUTF ("Smoothing percentage: %u\r\n", smoothing_percentage); adc_init(); // init AES key e2p_generic_get_aeskey(aes_key); // set pull-up for BUTTON_DDR sbi(BUTTON_PORT, BUTTON_PIN); _delay_ms(10); // set DIDR for all ADC channels and AINs, switch off digital input buffers to reduce ADC noise and to save power DIDR0 = 63; DIDR1 = 3; // If button pressed at start up, go to sleep for idle power consumption test. // Don't communicate with RFM12, which may not have been connected yet. if (BUTTON) { led_blink(50, 50, 20); power_down(true); } led_blink(500, 500, 3); rfm12_init(); wakeup_sec = init_wakeup(); // init interrupt for button (falling edge) sbi(EICRA, ISC11); sbi(EIMSK, INT1); sei(); for (i = 0; i < SEND_STATUS_TIMES_AT_STARTUP; i++) { prepare_deviceinfo_status(); send_prepared_message(); _delay_ms(800); prepare_battery_status(); send_prepared_message(); _delay_ms(800); } while (42) { if (BUTTON) { led_blink(100, 0, 1); UART_PUTS("Button pressed!\r\n"); uint8_t cnt = 0; while (BUTTON && (cnt < 250)) { _delay_ms(10); cnt++; } if (cnt == 250) { UART_PUTS("Long press -> initiate measure mode!\r\n"); while (BUTTON) { led_blink(100, 100, 1); } init_mode = true; wupCnt = 0; counter_meas = 0; init_wakeup(); // to usually shorter value UART_PUTS("Button released!\r\n"); _delay_ms(10); } } else { send = true; //UART_PUTF("version_status_cycle = %u\r\n", version_status_cycle); if (!measure_humidity()) { if (battery_status_cycle > 0) battery_status_cycle--; if (version_status_cycle > 0) version_status_cycle--; if (version_status_cycle == 0) { version_status_cycle = SEND_VERSION_STATUS_CYCLE; prepare_deviceinfo_status(); } else if (battery_status_cycle == 0) { battery_status_cycle = SEND_BATTERY_STATUS_CYCLE; prepare_battery_status(); } else { send = false; } } if (send) { send_prepared_message(); } } power_down(true); } // never called // aes256_done(&aes_ctx); }
/** * hibernate - Carry out system hibernation, including saving the image. */ int hibernate(void) { int error; lock_system_sleep(); /* The snapshot device should not be opened while we're running */ if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { error = -EBUSY; goto Unlock; } pm_prepare_console(); error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); if (error) goto Exit; /* Allocate memory management structures */ error = create_basic_memory_bitmaps(); if (error) goto Exit; printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); error = freeze_processes(); if (error) goto Free_bitmaps; error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); if (error) goto Thaw; if (freezer_test_done) { freezer_test_done = false; goto Thaw; } if (in_suspend) { unsigned int flags = 0; if (hibernation_mode == HIBERNATION_PLATFORM) flags |= SF_PLATFORM_MODE; if (nocompress) flags |= SF_NOCOMPRESS_MODE; else flags |= SF_CRC32_MODE; pr_debug("PM: writing image.\n"); error = swsusp_write(flags); swsusp_free(); if (!error) power_down(); in_suspend = 0; pm_restore_gfp_mask(); } else { pr_debug("PM: Image restored successfully.\n"); } Thaw: thaw_processes(); Free_bitmaps: free_basic_memory_bitmaps(); Exit: pm_notifier_call_chain(PM_POST_HIBERNATION); pm_restore_console(); atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); return error; }
chrono::millis Low_Power::power_down(chrono::millis millis, ADC_t adc, BOD_t bod) { Serial.flush(); while (millis >= chrono::millis(15) && s_interrupt_fired == false) { Period_t period = SLEEP_15MS; chrono::millis sleep_duration; if (millis >= chrono::millis(8000)) { period = SLEEP_8S; sleep_duration = chrono::millis(8000); } else if (millis >= chrono::millis(4000)) { period = SLEEP_4S; sleep_duration = chrono::millis(4000); } else if (millis >= chrono::millis(2000)) { period = SLEEP_2S; sleep_duration = chrono::millis(2000); } else if (millis >= chrono::millis(1000)) { period = SLEEP_1S; sleep_duration = chrono::millis(1000); } else if (millis >= chrono::millis(500)) { period = SLEEP_500MS; sleep_duration = chrono::millis(500); } else if (millis >= chrono::millis(250)) { period = SLEEP_250MS; sleep_duration = chrono::millis(250); } else if (millis >= chrono::millis(120)) { period = SLEEP_120MS; sleep_duration = chrono::millis(120); } else if (millis >= chrono::millis(60)) { period = SLEEP_60MS; sleep_duration = chrono::millis(60); } else if (millis >= chrono::millis(30)) { period = SLEEP_30MS; sleep_duration = chrono::millis(30); } else if (millis >= chrono::millis(15)) { period = SLEEP_15MS; sleep_duration = chrono::millis(15); } millis -= sleep_duration; power_down(period, adc, bod); chrono::s_time_point += sleep_duration; } return millis; }