static int convert_to_int(const char *buf, int *val) { int ret = 0; if (!gbcl) return -EPERM; if (gbcl->bcl_mode != BCL_DEVICE_DISABLED) { pr_err("BCL is not disabled\n"); return -EINVAL; } ret = kstrtoint(buf, 10, val); if (ret || (*val < 0)) { pr_err("Invalid high threshold %s val:%d ret:%d\n", buf, *val, ret); return -EINVAL; } return ret; }
static ssize_t kcal_invert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int kcal_invert, r; struct kcal_lut_data *lut_data = dev_get_drvdata(dev); r = kstrtoint(buf, 10, &kcal_invert); if ((r) || (kcal_invert != 0 && kcal_invert != 1) || (lut_data->invert == kcal_invert)) return -EINVAL; lut_data->invert = kcal_invert; if (mdss_mdp_kcal_is_panel_on()) mdss_mdp_kcal_update_igc(lut_data); else lut_data->queue_changes = true; return count; }
static int param_set_delay_minmax(const char *val, const struct kernel_param *kp, long min, long max) { long d; int sec; int rc; rc = kstrtoint(val, 0, &sec); if (rc) return -EINVAL; d = cfs_time_seconds(sec) / 100; if (d < min || d > max) return -EINVAL; *((unsigned int *)kp->arg) = d; return 0; }
static ssize_t yas_sampling_frequency_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct yas_state *st = iio_priv(indio_dev); int ret, data; int delay; ret = kstrtoint(buf, 10, &data); if (ret) return ret; if (data <= 0) return -EINVAL; mutex_lock(&st->lock); st->sampling_frequency = data; delay = MSEC_PER_SEC / st->sampling_frequency; st->mag.set_delay(delay); mutex_unlock(&st->lock); return count; }
static ssize_t mma8x5x_position_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct mma8x5x_data *pdata = dev_get_drvdata(dev); int position; int ret; if (!pdata) { dev_err(dev, "Invalid driver private data!"); return -EINVAL; } ret = kstrtoint(buf, 10, &position); if (ret) return ret; mutex_lock(&pdata->data_lock); pdata->position = position; mutex_unlock(&pdata->data_lock); return count; }
static ssize_t fps_tm_count_write(struct file *filp, const char __user *buf, size_t len, loff_t *data) { char tmp[32] = {0}; len = (len < (sizeof(tmp) - 1)) ? len : (sizeof(tmp) - 1); /* write data to the buffer */ if (copy_from_user(tmp, buf, len)) return -EFAULT; if (kstrtoint(tmp, 10, &tm_input_fps) == 0) { mtk_cooler_fps_dprintk("[%s] = %d\n", __func__, tm_input_fps); return len; } mtk_cooler_fps_dprintk("[%s] invalid input\n", __func__); return -EINVAL; }
static ssize_t set_dsp_cabc(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct fb_info *fbi = dev_get_drvdata(dev); struct rk_lcdc_driver *dev_drv = (struct rk_lcdc_driver *)fbi->par; int ret,mode=0; ret = kstrtoint(buf, 0, &mode); if (ret) return ret; ret = dev_drv->ops->set_dsp_cabc(dev_drv, mode); if(ret < 0) return ret; return count; }
static ssize_t vbat_min_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int value = 0; int ret = 0; if (!gbcl) return -EPERM; ret = kstrtoint(buf, 10, &value); if (ret || (value < 0)) { pr_err("Incorrect vbatt min value\n"); return -EINVAL; } gbcl->bcl_vbat_min = value; return count; }
static ssize_t iavail_high_threshold_value_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int val = 0; int ret = 0; if (!gbcl) return -EPERM; ret = kstrtoint(buf, 10, &val); if (ret || (val < 0)) { pr_err("Incorrect available current threshold value\n"); return -EINVAL; } gbcl->bcl_threshold_value_ma[BCL_HIGH_THRESHOLD_TYPE] = val; return count; }
static ssize_t pwm_test_store_polarity(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int rc; struct pwm_test *pwm_test = dev_get_drvdata(dev); int val; enum pwm_polarity polarity; rc = kstrtoint(buf, 0, &val); if (rc) return rc; /* only zero and one allowed */ if (val != 0 && val != 1) return -EINVAL; polarity = val ? PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL; /* same? don't do anything */ if (polarity == pwm_test->polarity) return count; /* polarity can only change when we stop the pwm */ if (pwm_test->run) pwm_disable(pwm_test->pwm); rc = pwm_set_polarity(pwm_test->pwm, polarity); if (rc) { dev_err(dev, "pwm_set_polarity failed\n"); if (pwm_test->run) pwm_enable(pwm_test->pwm); return rc; } if (pwm_test->run) pwm_enable(pwm_test->pwm); pwm_test->polarity = polarity; return count; }
static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int value; int err = 0; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s, kstrtoint failed.", __func__); goto done; } printk(KERN_INFO "[GP2A] light_enable_store : value=%d\n", value); if (value != 0 && value != 1) goto done; mutex_lock(&data->light_mutex); if (data->light_enabled && !value) { data->light_enabled = value; cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); regulator_disable(prox_regulator); } if (!data->light_enabled && value) { data->light_enabled = value; regulator_enable(prox_regulator); msleep(5); lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(20)); } mutex_unlock(&data->light_mutex); done: return count; }
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { int error, value; struct i2c_client *client = to_i2c_client(dev); error = kstrtoint(buf, 10, &value); if (error) return error; if (value < FAN_MIN_DUTY_CYCLE) { value = FAN_MIN_DUTY_CYCLE; } if (value > FAN_MAX_DUTY_CYCLE) { value = FAN_MAX_DUTY_CYCLE; } as7116_54x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); return count; }
static ssize_t gisb_arb_set_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct platform_device *pdev = to_platform_device(dev); struct brcmstb_gisb_arb_device *gdev = platform_get_drvdata(pdev); int val, ret; ret = kstrtoint(buf, 10, &val); if (ret < 0) return ret; if (val == 0 || val >= 0xffffffff) return -EINVAL; mutex_lock(&gdev->lock); iowrite32(val, gdev->base + ARB_TIMER); mutex_unlock(&gdev->lock); return count; }
static ssize_t modem_state_store(struct device *pdev, struct device_attribute *attr, const char *buf, size_t count) { int modem_state; hwlog_info("set modem_state to %s\n", buf); if ( kstrtoint(buf, 10, &modem_state) ) { hwlog_err("%s:%d kstrtoint %s fail\n", __func__, __LINE__, buf); return -EINVAL; } if (modem_state == MODEM_STATE_READY) { via_modem_state = MODEM_STATE_READY; via_monitor_uevent_notify(MODEM_STATE_READY); }else { hwlog_err("Power PHY error state. %s\n", buf); } return count; }
static ssize_t tpo_td043_vmirror_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev); int val; int ret; ret = kstrtoint(buf, 0, &val); if (ret < 0) return ret; val = !!val; ret = tpo_td043_write_mirror(tpo_td043->spi, tpo_td043->hmirror, val); if (ret < 0) return ret; tpo_td043->vmirror = val; return count; }
/* "write" request on "impulse_volume" special file. */ static ssize_t pcm_set_impulse_volume(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_line6_pcm *line6pcm = dev2pcm(dev); int value; int ret; ret = kstrtoint(buf, 10, &value); if (ret < 0) return ret; line6pcm->impulse_volume = value; if (value > 0) line6_pcm_acquire(line6pcm, LINE6_BITS_PCM_IMPULSE); else line6_pcm_release(line6pcm, LINE6_BITS_PCM_IMPULSE); return count; }
static ssize_t kcal_min_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int kcal_min, r; struct kcal_lut_data *lut_data = dev_get_drvdata(dev); r = kstrtoint(buf, 10, &kcal_min); if ((r) || (kcal_min < 1 || kcal_min > 256)) return -EINVAL; lut_data->minimum = kcal_min; mdss_mdp_kcal_check_pcc(lut_data); if (mdss_mdp_kcal_is_panel_on()) mdss_mdp_kcal_update_pcc(lut_data); else lut_data->queue_changes = true; return count; }
static ssize_t display_mirror_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); int mirror, r; if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror) return -ENOENT; r = kstrtoint(buf, 0, &mirror); if (r) return r; mirror = !!mirror; r = dssdev->driver->set_mirror(dssdev, mirror); if (r) return r; return size; }
static ssize_t ina3221_shunt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); struct ina3221_data *ina = dev_get_drvdata(dev); unsigned int channel = sd_attr->index; struct ina3221_input *input = &ina->inputs[channel]; int val; int ret; ret = kstrtoint(buf, 0, &val); if (ret) return ret; val = clamp_val(val, 1, INT_MAX); input->shunt_resistor = val; return count; }
static ssize_t display_tear_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); int te, r; if (!dssdev->driver->enable_te || !dssdev->driver->get_te) return -ENOENT; r = kstrtoint(buf, 0, &te); if (r) return r; te = !!te; r = dssdev->driver->enable_te(dssdev, te); if (r) return r; return size; }
static ssize_t set_fps(struct device *dev,struct device_attribute *attr, const char *buf, size_t count) { struct fb_info *fbi = dev_get_drvdata(dev); struct rk_lcdc_device_driver * dev_drv = (struct rk_lcdc_device_driver * )fbi->par; int fps; int ret; ret = kstrtoint(buf, 0, &fps); if(ret) { return ret; } ret = dev_drv->fps_mgr(dev_drv,fps,1); if(ret < 0) { return ret; } return count; }
static ssize_t set_slot(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { int status, value; struct i2c_client *client = to_i2c_client(dev); status = kstrtoint(buf, 10, &value); if (status) return status; if (value < 0 || value > 7) return -EINVAL; /* Write the slot id to register 0x02 */ status = i2c_smbus_write_byte_data(client, 0x02, value); if (unlikely(status < 0)) { return status; } return count; }
static ssize_t tlbflush_write_file(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; ssize_t len; int ceiling; len = min(count, sizeof(buf) - 1); if (copy_from_user(buf, user_buf, len)) return -EFAULT; buf[len] = '\0'; if (kstrtoint(buf, 0, &ceiling)) return -EINVAL; if (ceiling < 0) return -EINVAL; tlb_single_page_flush_ceiling = ceiling; return count; }
/* Look for ibm,smt-enabled OF option */ void __init check_smt_enabled(void) { struct device_node *dn; const char *smt_option; /* Default to enabling all threads */ smt_enabled_at_boot = threads_per_core; /* Allow the command line to overrule the OF option */ if (smt_enabled_cmdline) { if (!strcmp(smt_enabled_cmdline, "on")) smt_enabled_at_boot = threads_per_core; else if (!strcmp(smt_enabled_cmdline, "off")) smt_enabled_at_boot = 0; else { int smt; int rc; rc = kstrtoint(smt_enabled_cmdline, 10, &smt); if (!rc) smt_enabled_at_boot = min(threads_per_core, smt); } } else { dn = of_find_node_by_path("/options"); if (dn) { smt_option = of_get_property(dn, "ibm,smt-enabled", NULL); if (smt_option) { if (!strcmp(smt_option, "on")) smt_enabled_at_boot = threads_per_core; else if (!strcmp(smt_option, "off")) smt_enabled_at_boot = 0; } of_node_put(dn); } } }
static ssize_t light_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int delay; int err = 0; err = kstrtoint(buf, 10, &delay); if (err) { pr_err("%s, kstrtoint failed.", __func__); goto done; } if (delay < 0) goto done; delay = delay / 1000000; /* ns to msec */ pr_info("%s, new_delay = %d, old_delay = %d", __func__, delay, data->light_delay); if (SENSOR_MAX_DELAY < delay) delay = SENSOR_MAX_DELAY; data->light_delay = delay; mutex_lock(&data->light_mutex); if (data->light_enabled) { cancel_delayed_work_sync(&data->light_work); schedule_delayed_work(&data->light_work, msecs_to_jiffies(delay)); } mutex_unlock(&data->light_mutex); done: return count; }
static ssize_t qpnp_vib_level_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct timed_output_dev *tdev = dev_get_drvdata(dev); struct qpnp_vib *vib = container_of(tdev, struct qpnp_vib, timed_dev); int val; int rc; u8 reg = 0; rc = kstrtoint(buf, 10, &val); if (rc) { pr_err("%s: error getting level\n", __func__); return -EINVAL; } if (val < QPNP_VIB_MIN_LEVEL) { pr_err("%s: level %d not in range (%d - %d), using min.", __func__, val, QPNP_VIB_MIN_LEVEL, QPNP_VIB_MAX_LEVEL); val = QPNP_VIB_MIN_LEVEL; } else if (val > QPNP_VIB_MAX_LEVEL) { pr_err("%s: level %d not in range (%d - %d), using max.", __func__, val, QPNP_VIB_MIN_LEVEL, QPNP_VIB_MAX_LEVEL); val = QPNP_VIB_MAX_LEVEL; } vib->vtg_level = val; /* Configure the VTG CTL regiser */ rc = qpnp_vib_read_u8(vib, ®, QPNP_VIB_VTG_CTL(vib->base)); if (rc < 0) { pr_info("qpnp: error while reading vibration control register\n"); } reg &= ~QPNP_VIB_VTG_SET_MASK; reg |= (vib->vtg_level & QPNP_VIB_VTG_SET_MASK); rc = qpnp_vib_write_u8(vib, ®, QPNP_VIB_VTG_CTL(vib->base)); if (rc) pr_info("qpnp: error while writing vibration control register\n"); return strnlen(buf, count); }
static ssize_t m4pas_setrate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int err = 0; struct platform_device *pdev = to_platform_device(dev); struct iio_dev *iio = platform_get_drvdata(pdev); struct m4pas_driver_data *dd = iio_priv(iio); int value = 0; mutex_lock(&(dd->mutex)); err = kstrtoint(buf, 10, &value); if (err < 0) { m4pas_err("%s: Failed to convert value.\n", __func__); goto m4pas_enable_store_exit; } if ((value < -1) || (value > 32767)) { m4pas_err("%s: Invalid samplerate %d passed.\n", __func__, value); err = -EINVAL; goto m4pas_enable_store_exit; } err = m4pas_set_samplerate(iio, value); if (err < 0) { m4pas_err("%s: Failed to set sample rate.\n", __func__); goto m4pas_enable_store_exit; } m4pas_enable_store_exit: if (err < 0) { m4pas_err("%s: Failed with error code %d.\n", __func__, err); size = err; } mutex_unlock(&(dd->mutex)); return size; }
static ssize_t reset_protection_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct toshiba_haps_dev *haps = dev_get_drvdata(dev); int reset; int ret; ret = kstrtoint(buf, 0, &reset); if (ret) return ret; /* The only accepted value is 1 */ if (reset != 1) return -EINVAL; /* Reset the protection interface */ ret = toshiba_haps_reset_protection(haps->acpi_dev->handle); if (ret != 0) return ret; return count; }
static ssize_t store_prox_infrared_suppression(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct isl29018_chip *chip = iio_priv(indio_dev); int val; if (kstrtoint(buf, 10, &val)) return -EINVAL; if (!(val == 0 || val == 1)) { dev_err(dev, "The mode is not supported\n"); return -EINVAL; } /* get the "proximity scheme" i.e. if the chip does on chip infrared suppression (1 means perform on chip suppression) */ mutex_lock(&chip->lock); chip->prox_scheme = val; mutex_unlock(&chip->lock); return count; }
static ssize_t bma254_calibartion_store(struct device *dev, struct device_attribute *attr,const char *buf, size_t count) { struct bma254_data *bma254 = dev_get_drvdata(dev); int value; int err; char tmp[64]; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s, kstrtoint failed.", __func__); return -EINVAL; } err = bma254_do_calibrate(bma254, value); if (err < 0) pr_err("%s, bma254_do_calibrate(%d)\n", __func__, err); else err = 0; count = sprintf(tmp, "%d\n", err); return count; }