Skip to content

Commit 655926c

Browse files
ukleineknunojsa
authored andcommitted
pwm: Drop phase support
There is a superior approach in mainline around pwm_waveform that is already backported into the ADI tree. There are no users left and also no PWM driver that honers the .phase setting. So drop the respective code from the core. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
1 parent 6530957 commit 655926c

File tree

3 files changed

+8
-74
lines changed

3 files changed

+8
-74
lines changed

Documentation/driver-api/pwm.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ After being requested, a PWM has to be configured using::
4343

4444
int pwm_apply_might_sleep(struct pwm_device *pwm, struct pwm_state *state);
4545

46-
This API controls both the PWM period, duty_cycle and phase config and the
46+
This API controls both the PWM period/duty_cycle config and the
4747
enable/disable state.
4848

4949
PWM devices can be used from atomic context, if the PWM does not sleep. You
@@ -122,10 +122,6 @@ channel that was exported. The following properties will then be available:
122122
The active time of the PWM signal (read/write).
123123
Value is in nanoseconds and must be less than the period.
124124

125-
phase
126-
The phase difference between the actual PWM signal and the reference one.
127-
The value is expressed in nanoseconds and must be lower than period.
128-
129125
polarity
130126
Changes the polarity of the PWM signal (read/write).
131127
Writes to this property only work if the PWM chip supports changing

drivers/pwm/core.c

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,20 @@ static bool pwm_wf_valid(const struct pwm_waveform *wf)
7676
static void pwm_wf2state(const struct pwm_waveform *wf, struct pwm_state *state)
7777
{
7878
if (wf->period_length_ns) {
79-
if (wf->duty_length_ns + wf->duty_offset_ns < wf->period_length_ns) {
79+
if (wf->duty_length_ns + wf->duty_offset_ns < wf->period_length_ns)
8080
*state = (struct pwm_state){
8181
.enabled = true,
8282
.polarity = PWM_POLARITY_NORMAL,
8383
.period = wf->period_length_ns,
8484
.duty_cycle = wf->duty_length_ns,
85-
.phase = wf->duty_offset_ns,
8685
};
87-
} else {
86+
else
8887
*state = (struct pwm_state){
8988
.enabled = true,
9089
.polarity = PWM_POLARITY_INVERSED,
9190
.period = wf->period_length_ns,
9291
.duty_cycle = wf->period_length_ns - wf->duty_length_ns,
93-
.phase = wf->duty_offset_ns + wf->duty_length_ns,
9492
};
95-
/*
96-
* Ideally we'd do
97-
* .phase = (wf->duty_offset_ns + wf->duty_length_ns) % wf->period_length_ns,
98-
* here, but that involves a 64bit division and so isn't
99-
* allowed.
100-
*/
101-
while (state->phase >= wf->period_length_ns)
102-
state->phase -= wf->period_length_ns;
103-
}
10493
} else {
10594
*state = (struct pwm_state){
10695
.enabled = false,
@@ -111,26 +100,18 @@ static void pwm_wf2state(const struct pwm_waveform *wf, struct pwm_state *state)
111100
static void pwm_state2wf(const struct pwm_state *state, struct pwm_waveform *wf)
112101
{
113102
if (state->enabled) {
114-
if (state->polarity == PWM_POLARITY_NORMAL) {
103+
if (state->polarity == PWM_POLARITY_NORMAL)
115104
*wf = (struct pwm_waveform){
116105
.period_length_ns = state->period,
117106
.duty_length_ns = state->duty_cycle,
118-
.duty_offset_ns = state->phase,
107+
.duty_offset_ns = 0,
119108
};
120-
} else {
109+
else
121110
*wf = (struct pwm_waveform){
122111
.period_length_ns = state->period,
123112
.duty_length_ns = state->period - state->duty_cycle,
124-
.duty_offset_ns = state->duty_cycle + state->phase,
113+
.duty_offset_ns = state->duty_cycle,
125114
};
126-
/*
127-
* Actually we want
128-
* .duty_offset_ns = (state->duty_cycle + state->phase) % wf->period_length_ns
129-
* but as this is a 64bit division do it manually.
130-
*/
131-
while (wf->duty_offset_ns >= wf->period_length_ns)
132-
wf->duty_offset_ns -= wf->period_length_ns;
133-
}
134115
} else {
135116
*wf = (struct pwm_waveform){
136117
.period_length_ns = 0,
@@ -608,8 +589,7 @@ static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state)
608589
state->duty_cycle == pwm->state.duty_cycle &&
609590
state->polarity == pwm->state.polarity &&
610591
state->enabled == pwm->state.enabled &&
611-
state->usage_power == pwm->state.usage_power &&
612-
state->phase == pwm->state.phase)
592+
state->usage_power == pwm->state.usage_power)
613593
return 0;
614594

615595
if (ops->write_waveform) {
@@ -1125,41 +1105,6 @@ static ssize_t duty_cycle_store(struct device *pwm_dev,
11251105
return ret ? : size;
11261106
}
11271107

1128-
static ssize_t phase_show(struct device *pwm_dev,
1129-
struct device_attribute *attr,
1130-
char *buf)
1131-
{
1132-
const struct pwm_device *pwm = pwm_from_dev(pwm_dev);
1133-
struct pwm_state state;
1134-
1135-
pwm_get_state(pwm, &state);
1136-
1137-
return sprintf(buf, "%llu\n", state.phase);
1138-
}
1139-
1140-
static ssize_t phase_store(struct device *pwm_dev,
1141-
struct device_attribute *attr,
1142-
const char *buf, size_t size)
1143-
{
1144-
struct pwm_export *export = pwmexport_from_dev(pwm_dev);
1145-
struct pwm_device *pwm = export->pwm;
1146-
struct pwm_state state;
1147-
u64 val;
1148-
int ret;
1149-
1150-
ret = kstrtou64(buf, 0, &val);
1151-
if (ret)
1152-
return ret;
1153-
1154-
mutex_lock(&export->lock);
1155-
pwm_get_state(pwm, &state);
1156-
state.phase = val;
1157-
ret = pwm_apply_state(pwm, &state);
1158-
mutex_unlock(&export->lock);
1159-
1160-
return ret ? : size;
1161-
}
1162-
11631108
static ssize_t enable_show(struct device *pwm_dev,
11641109
struct device_attribute *attr,
11651110
char *buf)
@@ -1271,15 +1216,13 @@ static ssize_t capture_show(struct device *pwm_dev,
12711216

12721217
static DEVICE_ATTR_RW(period);
12731218
static DEVICE_ATTR_RW(duty_cycle);
1274-
static DEVICE_ATTR_RW(phase);
12751219
static DEVICE_ATTR_RW(enable);
12761220
static DEVICE_ATTR_RW(polarity);
12771221
static DEVICE_ATTR_RO(capture);
12781222

12791223
static struct attribute *pwm_attrs[] = {
12801224
&dev_attr_period.attr,
12811225
&dev_attr_duty_cycle.attr,
1282-
&dev_attr_phase.attr,
12831226
&dev_attr_enable.attr,
12841227
&dev_attr_polarity.attr,
12851228
&dev_attr_capture.attr,
@@ -2267,7 +2210,6 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
22672210

22682211
seq_printf(s, " period: %llu ns", state.period);
22692212
seq_printf(s, " duty: %llu ns", state.duty_cycle);
2270-
seq_printf(s, " phase: %llu ns", state.phase);
22712213
seq_printf(s, " polarity: %s",
22722214
state.polarity ? "inverse" : "normal");
22732215

include/linux/pwm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ struct pwm_waveform {
7878
* struct pwm_state - state of a PWM channel
7979
* @period: PWM period (in nanoseconds)
8080
* @duty_cycle: PWM duty cycle (in nanoseconds)
81-
* @phase: PWM phase (in nanoseconds)
8281
* @polarity: PWM polarity
8382
* @enabled: PWM enabled status
8483
* @usage_power: If set, the PWM driver is only required to maintain the power
@@ -89,7 +88,6 @@ struct pwm_waveform {
8988
struct pwm_state {
9089
u64 period;
9190
u64 duty_cycle;
92-
u64 phase;
9391
enum pwm_polarity polarity;
9492
bool enabled;
9593
bool usage_power;
@@ -205,7 +203,6 @@ static inline void pwm_init_state(const struct pwm_device *pwm,
205203
state->period = args.period;
206204
state->polarity = args.polarity;
207205
state->duty_cycle = 0;
208-
state->phase = 0;
209206
state->usage_power = false;
210207
}
211208

@@ -615,7 +612,6 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
615612
state.enabled = false;
616613
state.polarity = pwm->args.polarity;
617614
state.period = pwm->args.period;
618-
state.phase = 0;
619615
state.usage_power = false;
620616

621617
pwm_apply_might_sleep(pwm, &state);

0 commit comments

Comments
 (0)