diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/pwm/core.c | 5 | ||||
| -rw-r--r-- | drivers/pwm/sysfs.c | 48 |
2 files changed, 41 insertions, 12 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 729d457861fd..b0b87b3b52a6 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
| @@ -948,13 +948,16 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) | |||
| 948 | 948 | ||
| 949 | for (i = 0; i < chip->npwm; i++) { | 949 | for (i = 0; i < chip->npwm; i++) { |
| 950 | struct pwm_device *pwm = &chip->pwms[i]; | 950 | struct pwm_device *pwm = &chip->pwms[i]; |
| 951 | struct pwm_state state; | ||
| 952 | |||
| 953 | pwm_get_state(pwm, &state); | ||
| 951 | 954 | ||
| 952 | seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); | 955 | seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); |
| 953 | 956 | ||
| 954 | if (test_bit(PWMF_REQUESTED, &pwm->flags)) | 957 | if (test_bit(PWMF_REQUESTED, &pwm->flags)) |
| 955 | seq_puts(s, " requested"); | 958 | seq_puts(s, " requested"); |
| 956 | 959 | ||
| 957 | if (pwm_is_enabled(pwm)) | 960 | if (state.enabled) |
| 958 | seq_puts(s, " enabled"); | 961 | seq_puts(s, " enabled"); |
| 959 | 962 | ||
| 960 | seq_puts(s, "\n"); | 963 | seq_puts(s, "\n"); |
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 187ca0875cf6..d98599249a05 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c | |||
| @@ -46,8 +46,11 @@ static ssize_t period_show(struct device *child, | |||
| 46 | char *buf) | 46 | char *buf) |
| 47 | { | 47 | { |
| 48 | const struct pwm_device *pwm = child_to_pwm_device(child); | 48 | const struct pwm_device *pwm = child_to_pwm_device(child); |
| 49 | struct pwm_state state; | ||
| 49 | 50 | ||
| 50 | return sprintf(buf, "%u\n", pwm_get_period(pwm)); | 51 | pwm_get_state(pwm, &state); |
| 52 | |||
| 53 | return sprintf(buf, "%u\n", state.period); | ||
| 51 | } | 54 | } |
| 52 | 55 | ||
| 53 | static ssize_t period_store(struct device *child, | 56 | static ssize_t period_store(struct device *child, |
| @@ -56,6 +59,7 @@ static ssize_t period_store(struct device *child, | |||
| 56 | { | 59 | { |
| 57 | struct pwm_export *export = child_to_pwm_export(child); | 60 | struct pwm_export *export = child_to_pwm_export(child); |
| 58 | struct pwm_device *pwm = export->pwm; | 61 | struct pwm_device *pwm = export->pwm; |
| 62 | struct pwm_state state; | ||
| 59 | unsigned int val; | 63 | unsigned int val; |
| 60 | int ret; | 64 | int ret; |
| 61 | 65 | ||
| @@ -64,7 +68,9 @@ static ssize_t period_store(struct device *child, | |||
| 64 | return ret; | 68 | return ret; |
| 65 | 69 | ||
| 66 | mutex_lock(&export->lock); | 70 | mutex_lock(&export->lock); |
| 67 | ret = pwm_config(pwm, pwm_get_duty_cycle(pwm), val); | 71 | pwm_get_state(pwm, &state); |
| 72 | state.period = val; | ||
| 73 | ret = pwm_apply_state(pwm, &state); | ||
| 68 | mutex_unlock(&export->lock); | 74 | mutex_unlock(&export->lock); |
| 69 | 75 | ||
| 70 | return ret ? : size; | 76 | return ret ? : size; |
| @@ -75,8 +81,11 @@ static ssize_t duty_cycle_show(struct device *child, | |||
| 75 | char *buf) | 81 | char *buf) |
| 76 | { | 82 | { |
| 77 | const struct pwm_device *pwm = child_to_pwm_device(child); | 83 | const struct pwm_device *pwm = child_to_pwm_device(child); |
| 84 | struct pwm_state state; | ||
| 85 | |||
| 86 | pwm_get_state(pwm, &state); | ||
| 78 | 87 | ||
| 79 | return sprintf(buf, "%u\n", pwm_get_duty_cycle(pwm)); | 88 | return sprintf(buf, "%u\n", state.duty_cycle); |
| 80 | } | 89 | } |
| 81 | 90 | ||
| 82 | static ssize_t duty_cycle_store(struct device *child, | 91 | static ssize_t duty_cycle_store(struct device *child, |
| @@ -85,6 +94,7 @@ static ssize_t duty_cycle_store(struct device *child, | |||
| 85 | { | 94 | { |
| 86 | struct pwm_export *export = child_to_pwm_export(child); | 95 | struct pwm_export *export = child_to_pwm_export(child); |
| 87 | struct pwm_device *pwm = export->pwm; | 96 | struct pwm_device *pwm = export->pwm; |
| 97 | struct pwm_state state; | ||
| 88 | unsigned int val; | 98 | unsigned int val; |
| 89 | int ret; | 99 | int ret; |
| 90 | 100 | ||
| @@ -93,7 +103,9 @@ static ssize_t duty_cycle_store(struct device *child, | |||
| 93 | return ret; | 103 | return ret; |
| 94 | 104 | ||
| 95 | mutex_lock(&export->lock); | 105 | mutex_lock(&export->lock); |
| 96 | ret = pwm_config(pwm, val, pwm_get_period(pwm)); | 106 | pwm_get_state(pwm, &state); |
| 107 | state.duty_cycle = val; | ||
| 108 | ret = pwm_apply_state(pwm, &state); | ||
| 97 | mutex_unlock(&export->lock); | 109 | mutex_unlock(&export->lock); |
| 98 | 110 | ||
| 99 | return ret ? : size; | 111 | return ret ? : size; |
| @@ -104,8 +116,11 @@ static ssize_t enable_show(struct device *child, | |||
| 104 | char *buf) | 116 | char *buf) |
| 105 | { | 117 | { |
| 106 | const struct pwm_device *pwm = child_to_pwm_device(child); | 118 | const struct pwm_device *pwm = child_to_pwm_device(child); |
| 119 | struct pwm_state state; | ||
| 107 | 120 | ||
| 108 | return sprintf(buf, "%d\n", pwm_is_enabled(pwm)); | 121 | pwm_get_state(pwm, &state); |
| 122 | |||
| 123 | return sprintf(buf, "%d\n", state.enabled); | ||
| 109 | } | 124 | } |
| 110 | 125 | ||
| 111 | static ssize_t enable_store(struct device *child, | 126 | static ssize_t enable_store(struct device *child, |
| @@ -114,6 +129,7 @@ static ssize_t enable_store(struct device *child, | |||
| 114 | { | 129 | { |
| 115 | struct pwm_export *export = child_to_pwm_export(child); | 130 | struct pwm_export *export = child_to_pwm_export(child); |
| 116 | struct pwm_device *pwm = export->pwm; | 131 | struct pwm_device *pwm = export->pwm; |
| 132 | struct pwm_state state; | ||
| 117 | int val, ret; | 133 | int val, ret; |
| 118 | 134 | ||
| 119 | ret = kstrtoint(buf, 0, &val); | 135 | ret = kstrtoint(buf, 0, &val); |
| @@ -122,20 +138,24 @@ static ssize_t enable_store(struct device *child, | |||
| 122 | 138 | ||
| 123 | mutex_lock(&export->lock); | 139 | mutex_lock(&export->lock); |
| 124 | 140 | ||
| 141 | pwm_get_state(pwm, &state); | ||
| 142 | |||
| 125 | switch (val) { | 143 | switch (val) { |
| 126 | case 0: | 144 | case 0: |
| 127 | pwm_disable(pwm); | 145 | state.enabled = false; |
| 128 | break; | 146 | break; |
| 129 | case 1: | 147 | case 1: |
| 130 | ret = pwm_enable(pwm); | 148 | state.enabled = true; |
| 131 | break; | 149 | break; |
| 132 | default: | 150 | default: |
| 133 | ret = -EINVAL; | 151 | ret = -EINVAL; |
| 134 | break; | 152 | goto unlock; |
| 135 | } | 153 | } |
| 136 | 154 | ||
| 137 | mutex_unlock(&export->lock); | 155 | pwm_apply_state(pwm, &state); |
| 138 | 156 | ||
| 157 | unlock: | ||
| 158 | mutex_unlock(&export->lock); | ||
| 139 | return ret ? : size; | 159 | return ret ? : size; |
| 140 | } | 160 | } |
| 141 | 161 | ||
| @@ -145,8 +165,11 @@ static ssize_t polarity_show(struct device *child, | |||
| 145 | { | 165 | { |
| 146 | const struct pwm_device *pwm = child_to_pwm_device(child); | 166 | const struct pwm_device *pwm = child_to_pwm_device(child); |
| 147 | const char *polarity = "unknown"; | 167 | const char *polarity = "unknown"; |
| 168 | struct pwm_state state; | ||
| 169 | |||
| 170 | pwm_get_state(pwm, &state); | ||
| 148 | 171 | ||
| 149 | switch (pwm_get_polarity(pwm)) { | 172 | switch (state.polarity) { |
| 150 | case PWM_POLARITY_NORMAL: | 173 | case PWM_POLARITY_NORMAL: |
| 151 | polarity = "normal"; | 174 | polarity = "normal"; |
| 152 | break; | 175 | break; |
| @@ -166,6 +189,7 @@ static ssize_t polarity_store(struct device *child, | |||
| 166 | struct pwm_export *export = child_to_pwm_export(child); | 189 | struct pwm_export *export = child_to_pwm_export(child); |
| 167 | struct pwm_device *pwm = export->pwm; | 190 | struct pwm_device *pwm = export->pwm; |
| 168 | enum pwm_polarity polarity; | 191 | enum pwm_polarity polarity; |
| 192 | struct pwm_state state; | ||
| 169 | int ret; | 193 | int ret; |
| 170 | 194 | ||
| 171 | if (sysfs_streq(buf, "normal")) | 195 | if (sysfs_streq(buf, "normal")) |
| @@ -176,7 +200,9 @@ static ssize_t polarity_store(struct device *child, | |||
| 176 | return -EINVAL; | 200 | return -EINVAL; |
| 177 | 201 | ||
| 178 | mutex_lock(&export->lock); | 202 | mutex_lock(&export->lock); |
| 179 | ret = pwm_set_polarity(pwm, polarity); | 203 | pwm_get_state(pwm, &state); |
| 204 | state.polarity = polarity; | ||
| 205 | ret = pwm_apply_state(pwm, &state); | ||
| 180 | mutex_unlock(&export->lock); | 206 | mutex_unlock(&export->lock); |
| 181 | 207 | ||
| 182 | return ret ? : size; | 208 | return ret ? : size; |
