Example #1
0
static ssize_t transient_activate_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	struct transient_trig_data *transient_data = led_cdev->trigger_data;
	unsigned long state;
	ssize_t ret;

	ret = kstrtoul(buf, 10, &state);
	if (ret)
		return ret;

	if (state != 1 && state != 0)
		return -EINVAL;

	/* cancel the running timer */
	if (state == 0 && transient_data->activate == 1) {
		del_timer(&transient_data->timer);
		transient_data->activate = state;
		__led_set_brightness(led_cdev, transient_data->restore_state);
		return size;
	}

	/* start timer if there is no active timer */
	if (state == 1 && transient_data->activate == 0 &&
	    transient_data->duration != 0) {
		transient_data->activate = state;
		__led_set_brightness(led_cdev, transient_data->state);
		transient_data->restore_state =
		    (transient_data->state == LED_FULL) ? LED_OFF : LED_FULL;
		mod_timer(&transient_data->timer,
			  jiffies + transient_data->duration);
	}

	/* state == 0 && transient_data->activate == 0
		timer is not active - just return */
	/* state == 1 && transient_data->activate == 1
		timer is already active - just return */

	return size;
}
/*!
 * @brief enable/disable sensor function via sysfs node
 *
 * @param dev the pointer of device
 * @param attr the pointer of device attribute file
 * @param buf the pointer of enable/disable buffer
 * @param count buffer size
 *
 * @return zero success, non-zero failed
 * @retval zero success
 * @retval non-zero failed
*/
static ssize_t store_enable(struct device *dev,
			struct device_attribute *attr,
			const char *buf, size_t count)
{
	struct bme_client_data *data = dev_get_drvdata(dev);
	unsigned long enable;
	int status = kstrtoul(buf, 10, &enable);
	if (status == 0) {
		enable = enable ? 1 : 0;
		mutex_lock(&data->lock);
		if (data->enable != enable) {
			if (enable) {
				if (regulator_enable(data->data_bus.avdd)) {
					dev_err(dev, "bosch sensor avdd power supply enable failed\n");
					goto out;
				}
				#ifdef CONFIG_PM
				bme_enable(dev);
				#endif
				bme_set_op_mode(data, \
					BME_VAL_NAME(NORMAL_MODE));
				schedule_delayed_work(&data->work,
					msecs_to_jiffies(data->delay));
			} else{
				cancel_delayed_work_sync(&data->work);
				bme_set_op_mode(data, \
					BME_VAL_NAME(SLEEP_MODE));
				#ifdef CONFIG_PM
				bme_disable(dev);
				#endif
				regulator_disable(data->data_bus.avdd);
			}
			data->enable = enable;
		}
		mutex_unlock(&data->lock);
		return count;
	}
	return status;
out:
	return 0;
}
static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct iio_trigger *trig = to_iio_trigger(dev);
	struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
	unsigned long val;
	bool enabled;
	int ret;

	ret = kstrtoul(buf, 10, &val);
	if (ret)
		goto error_ret;

	if (val > 100000) {
		ret = -EINVAL;
		goto error_ret;
	}

	enabled = get_enabled_gptimers() & st->t->bit;

	if (enabled)
		disable_gptimers(st->t->bit);

	if (!val)
		goto error_ret;

	val = get_sclk() / val;
	if (val <= 4 || val <= st->duty) {
		ret = -EINVAL;
		goto error_ret;
	}

	set_gptimer_period(st->t->id, val);
	set_gptimer_pwidth(st->t->id, val - st->duty);

	if (enabled)
		enable_gptimers(st->t->bit);

error_ret:
	return ret ? ret : count;
}
Example #4
0
static ssize_t
store_pwm_enable(struct device *dev, struct device_attribute *attr,
		 const char *buf, size_t count)
{
	struct imanager_hwmon_data *data = imanager_hwmon_update_device(dev);
	int nr = to_sensor_dev_attr(attr)->index - 1;
	struct hwm_smartfan *fan = &data->hwm.fan[nr];
	unsigned long mode = 0;
	int err;

	err = kstrtoul(buf, 10, &mode);
	if (err < 0)
		return err;

	if (mode > MODE_AUTO)
		return -EINVAL;

	mutex_lock(&data->ec->lock);

	switch (mode) {
	case 0:
		if (mode != 0)
			hwm_core_fan_set_ctrl(nr, MODE_FULL, CTRL_PWM, 100,
					      fan->pulse, NULL, NULL);
		break;
	case 1:
		if (mode != 1)
			hwm_core_fan_set_ctrl(nr, MODE_MANUAL, CTRL_PWM, 0,
					      fan->pulse, NULL, NULL);
		break;
	case 2:
		if (mode != 2)
			hwm_core_fan_set_ctrl(nr, MODE_AUTO, fan->type, 0,
					      fan->pulse, &fan->limit, NULL);
		break;
	}

	mutex_unlock(&data->ec->lock);

	return count;
}
static ssize_t qpnp_vib_attrs_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t count)
{
	int tmp_vtg_level;
	unsigned long value;
	int ret = -EINVAL;
	struct qpnp_vib *vib = container_of(dev, struct qpnp_vib, sysfs_dev);

	if (kstrtoul(buf, 0, &value)) {
		dev_err(dev, "%s: Invalid value\n", __func__);
		goto err_out;
	}

	value /= QPNP_VIB_UV_PER_MV;

	if (value) {
		if (value < QPNP_VIB_MIN_LEVEL ||
				value > QPNP_VIB_MAX_LEVEL) {
			dev_err(dev, "Invalid voltage level\n");
			goto err_out;
		}
	} else {
		dev_err(dev, "Voltage level not specified\n");
		goto err_out;
	}
	tmp_vtg_level = vib->vtg_level;
	vib->vtg_level = value;

	ret = qpnp_vib_set(vib, vib->state);
	if (ret) {
		dev_err(dev, "%s: qpnp_vib_set failed %d\n", __func__, ret);
		vib->vtg_level = tmp_vtg_level;
		goto err_out;
	}

	return count;

err_out:
	return ret;
}
Example #6
0
static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
		struct device_attribute *attr, char const *buf, size_t size)
{
	struct kovaplus_device *kovaplus;
	struct usb_device *usb_dev;
	unsigned long profile;
	int retval;
	struct kovaplus_roccat_report roccat_report;

	dev = dev->parent->parent;
	kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
	usb_dev = interface_to_usbdev(to_usb_interface(dev));

	retval = kstrtoul(buf, 10, &profile);
	if (retval)
		return retval;

	if (profile >= 5)
		return -EINVAL;

	mutex_lock(&kovaplus->kovaplus_lock);
	retval = kovaplus_set_actual_profile(usb_dev, profile);
	if (retval) {
		mutex_unlock(&kovaplus->kovaplus_lock);
		return retval;
	}

	kovaplus_profile_activated(kovaplus, profile);

	roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
	roccat_report.profile = profile + 1;
	roccat_report.button = 0;
	roccat_report.data1 = profile + 1;
	roccat_report.data2 = 0;
	roccat_report_event(kovaplus->chrdev_minor,
			(uint8_t const *)&roccat_report);

	mutex_unlock(&kovaplus->kovaplus_lock);

	return size;
}
Example #7
0
static ssize_t mode_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int value = 0;
	int ret;
#if !defined(CONFIG_FB_MDNIE_PWM)
	int result[5] = {0,};
#endif

	ret = kstrtoul(buf, 0, (unsigned long *)&value);
	if (ret < 0)
		return ret;

	dev_info(dev, "%s: value=%d\n", __func__, value);

	if (value >= MODE_MAX) {
		value = STANDARD;
		return -EINVAL;
	}

	mutex_lock(&mdnie->lock);
	mdnie->mode = value;
	mutex_unlock(&mdnie->lock);

#if !defined(CONFIG_FB_MDNIE_PWM)
	if (!mdnie->color_correction) {
		ret = get_panel_coordinate(mdnie, result);
		if (ret > 0)
			update_color_position(mdnie, ret - 1);
	}
#endif

	mdnie_update(mdnie);
#if defined(CONFIG_FB_MDNIE_PWM)
	if ((mdnie->enable) && (mdnie->bd_enable))
		update_brightness(mdnie);
#endif

	return count;
}
Example #8
0
static ssize_t buffer_size_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t size)
{
	int ret;
	unsigned long val;
	struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);

	/* Only permitted for TMC-ETRs */
	if (drvdata->config_type != TMC_CONFIG_TYPE_ETR)
		return -EPERM;

	ret = kstrtoul(buf, 0, &val);
	if (ret)
		return ret;
	/* The buffer size should be page aligned */
	if (val & (PAGE_SIZE - 1))
		return -EINVAL;
	drvdata->size = val;
	return size;
}
Example #9
0
static int __init sec_subsys_log_setup(char *str)
{
	unsigned size = memparse(str, &str);
	unsigned long base = 0;

	/* If we encounter any problem parsing str ... */
	if (!size || size != roundup_pow_of_two(size) || *str != '@'
		|| kstrtoul(str + 1, 0, &base))
			goto out;

	if (reserve_bootmem(base - 8, size + 8, BOOTMEM_EXCLUSIVE)) {
			pr_err("%s: failed reserving size %d " \
						"at base 0x%lx\n", __func__, size, base);
			goto out;
	}

	sec_debug_subsys_info_set_log_buffer(phys_to_virt(base),size);

out:
	return 0;
}
static ssize_t pmic8xxx_debounce_store(struct device *dev,
			struct device_attribute *attr,
			const char *buf, size_t size)
{
	struct pmic8xxx_pwrkey *pwrkey = dev_get_drvdata(dev);
	int err;
	unsigned long val;

	if (size > 8)
		return -EINVAL;

	err = kstrtoul(buf, 10, &val);
	if (err < 0)
		return err;

	err = pmic8xxx_set_pon1(dev, val, pwrkey->pdata->pull_up);
	if (err < 0)
		return err;

	return size;
}
Example #11
0
/**
 * dtbocfg_overlay_item_status_store() - Set Status Attibute
 * @item:  Pointer to Configuration Item
 * @page:  Pointer to Value Buffer
 * @count: Size of Value Buffer Size
 * return  Stored Size or Error Status.
 */
static ssize_t dtbocfg_overlay_item_status_store(struct config_item *item, const char *buf, size_t count)
{
    struct dtbocfg_overlay_item *overlay = container_of_dtbocfg_overlay_item(item);
    ssize_t       status;
    unsigned long value;
    if (0 != (status = kstrtoul(buf, 10, &value))) {
        goto failed;
    }
    if (value == 0) {
        if (overlay->id >= 0) {
            dtbocfg_overlay_item_release(overlay);
        }
    } else {
        if (overlay->id  < 0) {
            dtbocfg_overlay_item_create(overlay);
        }
    }
    return count;
  failed:
    return -EPERM;
}
static ssize_t led_blink_store(struct device *dev,
			struct device_attribute *attr,
			const char *buf, size_t len)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	struct ktd2026_led *led = cdev_to_led(led_cdev);
	unsigned long blink_set;

	if (kstrtoul(buf, 0, &blink_set))
		return -EINVAL;

	if (!blink_set) {
		led->delay_on_time_ms = LED_OFF;
		ktd2026_set_brightness(led_cdev, LED_OFF);
	}

	led_blink_set(led_cdev,
		&led->delay_on_time_ms, &led->delay_off_time_ms);

	return len;
}
Example #13
0
static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
		       const char *buf, size_t count)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct lm63_data *data = i2c_get_clientdata(client);
	unsigned long val;
	int err;

	err = kstrtoul(buf, 10, &val);
	if (err)
		return err;

	mutex_lock(&data->update_lock);
	data->fan[1] = FAN_TO_REG(val);
	i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
				  data->fan[1] & 0xFF);
	i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
				  data->fan[1] >> 8);
	mutex_unlock(&data->update_lock);
	return count;
}
Example #14
0
static ssize_t write_file_dfs(struct file *file, const char __user *user_buf,
                              size_t count, loff_t *ppos)
{
    struct ath_softc *sc = file->private_data;
    unsigned long val;
    char buf[32];
    ssize_t len;

    len = min(count, sizeof(buf) - 1);
    if (copy_from_user(buf, user_buf, len))
        return -EFAULT;

    buf[len] = '\0';
    if (kstrtoul(buf, 0, &val))
        return -EINVAL;

    if (val == DFS_STATS_RESET_MAGIC)
        memset(&sc->debug.stats.dfs_stats, 0,
               sizeof(sc->debug.stats.dfs_stats));
    return count;
}
static ssize_t pm8941_set_fine_current_common(struct device *ldev, u16 offset,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct pm8941_flash_data *data = dev_get_drvdata(ldev);
	unsigned long fine_current;
	int rc = 0;

	if (kstrtoul(buf, 10, &fine_current))
		return -EINVAL;

	mutex_lock(&data->lock);
	if (fine_current > FLASH_MAX_FINE_LEVEL)
		fine_current = FLASH_MAX_FINE_LEVEL;

	rc = pm_reg_write(data, offset, (u8)fine_current);
	if (rc)
		pm8941_dev_err(data, "Fine current reg write failed(%d)\n", rc);
	mutex_unlock(&data->lock);

	return rc ? rc : size;
}
static ssize_t pm8941_set_startup_delay(struct device *ldev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct pm8941_flash_data *data = dev_get_drvdata(ldev);
	unsigned long delay;
	int rc = 0;

	if (kstrtoul(buf, 10, &delay))
		return -EINVAL;

	mutex_lock(&data->lock);
	if (delay > DELAY_128us)
		delay = DELAY_128us;

	rc = pm_reg_write(data, STARTUP_DELAY, delay);
	if (rc)
		pm8941_dev_err(data, "Startup delay write failed(%d)\n", rc);
	mutex_unlock(&data->lock);

	return rc ? rc : size;
}
static ssize_t pm8941_set_strobe(struct device *ldev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct pm8941_flash_data *data = dev_get_drvdata(ldev);
	unsigned long strobe;
	int rc = kstrtoul(buf, 10, &strobe);

	if (rc && strobe > 1)
		return -EINVAL;

	mutex_lock(&data->lock);

	rc = pm_reg_masked_write(data, STROBE_CONTROL, STROBE_SELECT_HW,
		strobe ? STROBE_SELECT_HW : STROBE_SELECT_SW);
	if (rc)
		pm8941_dev_err(data, "reg write failed(%d)\n", rc);

	mutex_unlock(&data->lock);

	return rc ? rc : size;
}
static ssize_t set_dvfs_enable(struct device *dev,
			       struct device_attribute *attr, const char *buf,
			       size_t count)
{
	struct kbase_device *kbdev = dev_get_drvdata(dev);
	unsigned long enable;
	ssize_t ret;

	ret = kstrtoul(buf, 0, &enable);
	if (ret)
		return ret;

	if (enable == 1)
		kbase_rk_dvfs_enable(kbdev);
	else if (enable == 0)
		kbase_rk_dvfs_disable(kbdev);
	else
		return -EINVAL;

	return count;
}
static ssize_t led_invert_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	struct oneshot_trig_data *oneshot_data = led_cdev->trigger_data;
	unsigned long state;
	int ret;

	ret = kstrtoul(buf, 0, &state);
	if (ret)
		return ret;

	oneshot_data->invert = !!state;

	if (oneshot_data->invert)
		__led_set_brightness(led_cdev, LED_FULL);
	else
		__led_set_brightness(led_cdev, LED_OFF);

	return size;
}
static ssize_t conservative_boost_enabled_store(struct kgsl_device *device, struct kgsl_pwrscale
						   *pwrscale, const char *buf,
						   size_t count)
{
	unsigned long tmp;
	int err;

	err = kstrtoul(buf, 0, &tmp);
	if (err) {
		pr_err("%s: failed enabling/disabling boost!\n", KGSL_NAME);
		return err;
	}

	enable_boost = tmp;

	if (g_show_stats == 1)
		pr_info("%s: boost %s\n", KGSL_NAME,
			enable_boost ? "enabled" : "disabled");

	return count;
}
Example #21
0
static ssize_t led_duty_cycle_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	struct rt_timer *rt = container_of(led_cdev->trigger, struct rt_timer, led_trigger);
	unsigned long state;
	ssize_t ret = -EINVAL;

	ret = kstrtoul(buf, 10, &state);
	if (ret)
		return ret;

	if (state <= 100)
		rt->duty_cycle = state;
	else
		rt->duty_cycle = 100;

	rt->fade = 0;

	return size;
}
Example #22
0
static int duration_set(const char *arg, const struct kernel_param *kp)
{
	int ret = 0;
	unsigned long new_duration;

	ret = kstrtoul(arg, 10, &new_duration);
	if (ret)
		goto exit;
	if (new_duration > 25 || new_duration < 6) {
		pr_err("Out of recommended range %lu, between 6-25ms\n",
			new_duration);
		ret = -EINVAL;
	}

	duration = clamp(new_duration, 6ul, 25ul);
	smp_mb();

exit:

	return ret;
}
static ssize_t set_out0_output(struct device *dev,
                               struct device_attribute *attr,
                               const char *buf, size_t count)
{
    unsigned long val;
    struct i2c_client *client = to_i2c_client(dev);
    struct pcf8591_data *data = i2c_get_clientdata(client);
    int err;

    err = kstrtoul(buf, 10, &val);
    if (err)
        return err;

    val /= 10;
    if (val > 255)
        return -EINVAL;

    data->aout = val;
    i2c_smbus_write_byte_data(client, data->control, data->aout);
    return count;
}
Example #24
0
static ssize_t ak89xx_rate_store(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	unsigned long data;
	int error;
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct inv_ak89xx_state_s *st = iio_priv(indio_dev);

	error = kstrtoul(buf, 10, &data);
	if (error)
		return error;
	/* transform rate to delay in ms */
	data = 1000 / data;
	if (data > AK89XX_MAX_DELAY)
		data = AK89XX_MAX_DELAY;
	if (data < AK89XX_MIN_DELAY)
		data = AK89XX_MIN_DELAY;
	st->delay = (unsigned int) data;
	return count;
}
Example #25
0
static int window_size_set(const char *arg, const struct kernel_param *kp)
{
	int ret = 0;
	unsigned long new_window_size;

	ret = kstrtoul(arg, 10, &new_window_size);
	if (ret)
		goto exit_win;
	if (new_window_size > 10 || new_window_size < 2) {
		pr_err("Out of recommended window size %lu, between 2-10\n",
			new_window_size);
		ret = -EINVAL;
	}

	window_size = clamp(new_window_size, 2ul, 10ul);
	smp_mb();

exit_win:

	return ret;
}
Example #26
0
static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_store(
		struct config_item *item, const char *page, size_t count)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
						   tl_se_tpg);
	unsigned long val;
	int ret = kstrtoul(page, 0, &val);

	if (ret) {
		pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret);
		return ret;
	}
	if (val != 0 && val != 1 && val != 3) {
		pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val);
		return -EINVAL;
	}
	tl_tpg->tl_fabric_prot_type = val;

	return count;
}
Example #27
0
static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
			struct f2fs_sb_info *sbi,
			const char *buf, size_t count)
{
	unsigned char *ptr;
	unsigned long t;
	unsigned int *ui;
	ssize_t ret;

	ptr = __struct_ptr(sbi, a->struct_type);
	if (!ptr)
		return -EINVAL;

	ui = (unsigned int *)(ptr + a->offset);

	ret = kstrtoul(skip_spaces(buf), 0, &t);
	if (ret < 0)
		return ret;
	*ui = t;
	return count;
}
Example #28
0
static ssize_t hmtColorTemp_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int value;
	int ret;

	ret = kstrtoul(buf, 0, (unsigned long *)&value);
	if (ret < 0)
		return ret;


	if (value != mdnie->hmt_mode && value < HMT_MDNIE_MAX) {
		mutex_lock(&mdnie->lock);
		mdnie->hmt_mode = value;
		mutex_unlock(&mdnie->lock);
		mdnie_update(mdnie);
	}

	return count;
}
static ssize_t ctxid_pid_store(struct device *dev,
			       struct device_attribute *attr,
			       const char *buf, size_t size)
{
	int ret;
	unsigned long vpid, pid;
	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);

	ret = kstrtoul(buf, 16, &vpid);
	if (ret)
		return ret;

	pid = coresight_vpid_to_pid(vpid);

	spin_lock(&drvdata->spinlock);
	drvdata->ctxid_pid[drvdata->ctxid_idx] = pid;
	drvdata->ctxid_vpid[drvdata->ctxid_idx] = vpid;
	spin_unlock(&drvdata->spinlock);

	return size;
}
Example #30
0
static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
	int nr = sensor_attr->index;
	struct smsc47m192_data *data = dev_get_drvdata(dev);
	struct i2c_client *client = data->client;
	unsigned long val;
	int err;

	err = kstrtoul(buf, 10, &val);
	if (err)
		return err;

	mutex_lock(&data->update_lock);
	data->in_max[nr] = IN_TO_REG(val, nr);
	i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr),
							data->in_max[nr]);
	mutex_unlock(&data->update_lock);
	return count;
}