pwm: meson: add relative_duty interface in pwm sysfs [1/1]

PD#SWPL-4225

Problem:
This interface is added to facilitate debugging the voltage-
table in pwm regulator, which can output different percentages
of waveforms in a fixed pwm cycle.
example:
echo 50 100 > sys/class/pwm/pwmchipx/pwmx/relative_duty
output 50% duty pwm

Solution:
add relative_duty interface in pwm sysfs

Verify:
test pass on tl1_X301_v1 tl1_skt_v1

Change-Id: Icd01e681694b81f3790f7cce8c326db02674a48c
Signed-off-by: Bichao Zheng <bichao.zheng@amlogic.com>
This commit is contained in:
Bichao Zheng
2019-01-16 14:21:43 +08:00
committed by Jianxin Pan
parent 105becb417
commit 900856a47f

View File

@@ -223,11 +223,52 @@ static ssize_t capture_show(struct device *child,
return sprintf(buf, "%u %u\n", result.period, result.duty_cycle);
}
#ifdef CONFIG_AMLOGIC_MODIFY
/*
* This interface is added to facilitate debugging the voltage-
* table in pwm regulator, which can output different percentages
* of waveforms in a fixed pwm cycle.
* example:
* echo 50 100 > sys/class/pwm/pwmchipx/pwmx/relative_duty
* output 50% duty pwm
*/
static ssize_t relative_duty_store(struct device *child,
struct device_attribute *attr,
const char *buf, size_t size)
{
struct pwm_export *export = child_to_pwm_export(child);
struct pwm_device *pwm = export->pwm;
struct pwm_state state = pwm->state;
int scale, dutycycle, ret;
ret = sscanf(buf, "%d %d", &dutycycle, &scale);
if (ret != 2) {
pr_err("Can't parse addr and scale,dutycycle:[dutycycle scale]\n");
return -EINVAL;
}
if (!scale || dutycycle > scale) {
pr_err("parameter error\n");
return -EINVAL;
}
mutex_lock(&export->lock);
pwm_set_relative_duty_cycle(&state, dutycycle, scale);
ret = pwm_apply_state(pwm, &state);
mutex_unlock(&export->lock);
return ret ? : size;
}
#endif
static DEVICE_ATTR_RW(period);
static DEVICE_ATTR_RW(duty_cycle);
static DEVICE_ATTR_RW(enable);
static DEVICE_ATTR_RW(polarity);
static DEVICE_ATTR_RO(capture);
#ifdef CONFIG_AMLOGIC_MODIFY
static DEVICE_ATTR_WO(relative_duty);
#endif
static struct attribute *pwm_attrs[] = {
&dev_attr_period.attr,
@@ -235,6 +276,9 @@ static struct attribute *pwm_attrs[] = {
&dev_attr_enable.attr,
&dev_attr_polarity.attr,
&dev_attr_capture.attr,
#ifdef CONFIG_AMLOGIC_MODIFY
&dev_attr_relative_duty.attr,
#endif
NULL
};
ATTRIBUTE_GROUPS(pwm);