From 2f7c68cb55ecb7331f2381deb497c27155f32faf Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Wed, 03 Jan 2024 09:43:39 +0000 Subject: [PATCH] update kernel to 5.10.198 --- kernel/drivers/pwm/sysfs.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 91 insertions(+), 0 deletions(-) diff --git a/kernel/drivers/pwm/sysfs.c b/kernel/drivers/pwm/sysfs.c index ca47570..b1b2a61 100644 --- a/kernel/drivers/pwm/sysfs.c +++ b/kernel/drivers/pwm/sysfs.c @@ -138,6 +138,76 @@ return ret ? : size; } + +static ssize_t oneshot_repeat_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + const struct pwm_device *pwm = child_to_pwm_device(child); + struct pwm_state state; + + pwm_get_state(pwm, &state); + + return sprintf(buf, "%u\n", state.oneshot_repeat); +} + +static ssize_t oneshot_repeat_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; + unsigned int val; + int ret; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&export->lock); + pwm_get_state(pwm, &state); + state.oneshot_repeat = val; + ret = pwm_apply_state(pwm, &state); + mutex_unlock(&export->lock); + + return ret ? : size; +} + +static ssize_t duty_offset_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + const struct pwm_device *pwm = child_to_pwm_device(child); + struct pwm_state state; + + pwm_get_state(pwm, &state); + + return sprintf(buf, "%llu\n", state.duty_offset); +} + +static ssize_t duty_offset_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; + u64 val; + int ret; + + ret = kstrtou64(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&export->lock); + pwm_get_state(pwm, &state); + state.duty_offset = val; + ret = pwm_apply_state(pwm, &state); + mutex_unlock(&export->lock); + + return ret ? : size; +} #endif static ssize_t enable_show(struct device *child, @@ -279,6 +349,8 @@ static DEVICE_ATTR_RW(duty_cycle); #ifdef CONFIG_PWM_ROCKCHIP_ONESHOT static DEVICE_ATTR_RW(oneshot_count); +static DEVICE_ATTR_RW(oneshot_repeat); +static DEVICE_ATTR_RW(duty_offset); #endif static DEVICE_ATTR_RW(enable); static DEVICE_ATTR_RW(polarity); @@ -290,6 +362,8 @@ &dev_attr_duty_cycle.attr, #ifdef CONFIG_PWM_ROCKCHIP_ONESHOT &dev_attr_oneshot_count.attr, + &dev_attr_oneshot_repeat.attr, + &dev_attr_duty_offset.attr, #endif &dev_attr_enable.attr, &dev_attr_polarity.attr, @@ -492,6 +566,13 @@ if (!export) continue; + /* If pwmchip was not enabled before suspend, do nothing. */ + if (!export->suspend.enabled) { + /* release lock taken in pwm_class_get_state */ + mutex_unlock(&export->lock); + continue; + } + state.enabled = export->suspend.enabled; ret = pwm_class_apply_state(export, pwm, &state); if (ret < 0) @@ -516,7 +597,17 @@ if (!export) continue; + /* + * If pwmchip was not enabled before suspend, save + * state for resume time and do nothing else. + */ export->suspend = state; + if (!state.enabled) { + /* release lock taken in pwm_class_get_state */ + mutex_unlock(&export->lock); + continue; + } + state.enabled = false; ret = pwm_class_apply_state(export, pwm, &state); if (ret < 0) { -- Gitblit v1.6.2