Skip to content

Commit 4246bc9

Browse files
ukleineknunojsa
authored andcommitted
pwm: Drop support for time units other than nanoseconds
Make pwm support nearly match upstream again. The support for time units other than nanoseconds adds no benefit as the input clock for all known PWM drivers is less than 1 GHz and so the mapping from pwm_state to hardware configuration is already surjective with nanoseconds. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
1 parent ddd999a commit 4246bc9

File tree

4 files changed

+10
-151
lines changed

4 files changed

+10
-151
lines changed

drivers/pwm/core.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
568568
state->polarity == pwm->state.polarity &&
569569
state->enabled == pwm->state.enabled &&
570570
state->usage_power == pwm->state.usage_power &&
571-
state->phase == pwm->state.phase &&
572-
state->time_unit == pwm->state.time_unit)
571+
state->phase == pwm->state.phase)
573572
return 0;
574573

575574
err = chip->ops->apply(chip, pwm, state);
@@ -645,7 +644,6 @@ int pwm_adjust_config(struct pwm_device *pwm)
645644
state.duty_cycle = 0;
646645
state.period = pargs.period;
647646
state.polarity = pargs.polarity;
648-
state.time_unit = pargs.time_unit;
649647

650648
return pwm_apply_state(pwm, &state);
651649
}
@@ -1107,15 +1105,6 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
11071105
EXPORT_SYMBOL_GPL(devm_fwnode_pwm_get);
11081106

11091107
#ifdef CONFIG_DEBUG_FS
1110-
1111-
const char *pwm_time_unit_strings[] = {
1112-
[PWM_UNIT_SEC] = "s",
1113-
[PWM_UNIT_MSEC] = "ms",
1114-
[PWM_UNIT_USEC] = "us",
1115-
[PWM_UNIT_NSEC] = "ns",
1116-
[PWM_UNIT_PSEC] = "ps",
1117-
};
1118-
11191108
static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
11201109
{
11211110
unsigned int i;
@@ -1125,8 +1114,6 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
11251114
struct pwm_state state;
11261115

11271116
pwm_get_state(pwm, &state);
1128-
if (!state.time_unit)
1129-
state.time_unit = PWM_UNIT_NSEC;
11301117

11311118
seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
11321119

@@ -1136,12 +1123,9 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
11361123
if (state.enabled)
11371124
seq_puts(s, " enabled");
11381125

1139-
seq_printf(s, " period: %llu %s", state.period,
1140-
pwm_time_unit_strings[state.time_unit]);
1141-
seq_printf(s, " duty: %llu %s", state.duty_cycle,
1142-
pwm_time_unit_strings[state.time_unit]);
1143-
seq_printf(s, " phase: %llu %s", state.phase,
1144-
pwm_time_unit_strings[state.time_unit]);
1126+
seq_printf(s, " period: %llu ns", state.period);
1127+
seq_printf(s, " duty: %llu ns", state.duty_cycle);
1128+
seq_printf(s, " phase: %llu ns", state.phase);
11451129
seq_printf(s, " polarity: %s",
11461130
state.polarity ? "inverse" : "normal");
11471131

drivers/pwm/pwm-axi-pwmgen.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@
4343

4444
#define AXI_PWMGEN_N_MAX_PWMS 16
4545

46-
static const unsigned long long axi_pwmgen_scales[] = {
47-
[PWM_UNIT_SEC] = 1000000000000ULL,
48-
[PWM_UNIT_MSEC] = 1000000000ULL,
49-
[PWM_UNIT_USEC] = 1000000ULL,
50-
[PWM_UNIT_NSEC] = 1000ULL,
51-
[PWM_UNIT_PSEC] = 1ULL,
52-
};
53-
5446
struct axi_pwmgen {
5547
struct pwm_chip chip;
5648
struct clk *clk;
@@ -114,21 +106,18 @@ static int axi_pwmgen_apply(struct pwm_chip *chip, struct pwm_device *pwm,
114106

115107
rate = clk_get_rate(pwmgen->clk);
116108

117-
cnt = mul_u64_u64_div_u64_roundclosest(state->period * axi_pwmgen_scales[state->time_unit],
118-
rate, PSEC_PER_SEC);
109+
cnt = mul_u64_u64_div_u64_roundclosest(state->period, rate, NSEC_PER_SEC);
119110
if (cnt > U32_MAX)
120111
cnt = U32_MAX;
121112
axi_pwmgen_write(pwmgen, AXI_PWMGEN_CHX_PERIOD(pwmgen, ch),
122113
state->enabled ? cnt : 0);
123114

124-
cnt = mul_u64_u64_div_u64_roundclosest(state->duty_cycle * axi_pwmgen_scales[state->time_unit],
125-
rate, PSEC_PER_SEC);
115+
cnt = mul_u64_u64_div_u64_roundclosest(state->duty_cycle, rate, NSEC_PER_SEC);
126116
if (cnt > U32_MAX)
127117
cnt = U32_MAX;
128118
axi_pwmgen_write(pwmgen, AXI_PWMGEN_CHX_DUTY(pwmgen, ch), cnt);
129119

130-
cnt = mul_u64_u64_div_u64_roundclosest(state->phase * axi_pwmgen_scales[state->time_unit],
131-
rate, PSEC_PER_SEC);
120+
cnt = mul_u64_u64_div_u64_roundclosest(state->phase, rate, NSEC_PER_SEC);
132121
if (cnt > U32_MAX)
133122
cnt = U32_MAX;
134123
axi_pwmgen_write(pwmgen, AXI_PWMGEN_CHX_PHASE(pwmgen, ch), cnt);
@@ -161,7 +150,6 @@ static void axi_pwmgen_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
161150
state->phase = DIV_ROUND_CLOSEST_ULL(cnt * NSEC_PER_SEC, rate);
162151

163152
state->enabled = state->period > 0;
164-
state->time_unit = PWM_UNIT_NSEC;
165153
}
166154

167155
static const struct pwm_ops axi_pwmgen_pwm_ops = {

drivers/pwm/sysfs.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -235,69 +235,6 @@ static ssize_t polarity_store(struct device *child,
235235
return ret ? : size;
236236
}
237237

238-
static ssize_t time_unit_show(struct device *child,
239-
struct device_attribute *attr,
240-
char *buf)
241-
{
242-
const struct pwm_device *pwm = child_to_pwm_device(child);
243-
const char *unit = "unknown";
244-
struct pwm_state state;
245-
246-
pwm_get_state(pwm, &state);
247-
248-
switch (state.time_unit) {
249-
case PWM_UNIT_SEC:
250-
unit = "second";
251-
break;
252-
case PWM_UNIT_MSEC:
253-
unit = "milisecond";
254-
break;
255-
case PWM_UNIT_USEC:
256-
unit = "microsecond";
257-
break;
258-
case PWM_UNIT_NSEC:
259-
unit = "nanosecond";
260-
break;
261-
case PWM_UNIT_PSEC:
262-
unit = "picosecond";
263-
break;
264-
}
265-
266-
return sprintf(buf, "%s\n", unit);
267-
}
268-
269-
static ssize_t time_unit_store(struct device *child,
270-
struct device_attribute *attr,
271-
const char *buf, size_t size)
272-
{
273-
struct pwm_export *export = child_to_pwm_export(child);
274-
struct pwm_device *pwm = export->pwm;
275-
enum pwm_time_unit unit;
276-
struct pwm_state state;
277-
int ret;
278-
279-
if (sysfs_streq(buf, "second"))
280-
unit = PWM_UNIT_SEC;
281-
else if (sysfs_streq(buf, "milisecond"))
282-
unit = PWM_UNIT_MSEC;
283-
else if (sysfs_streq(buf, "microsecond"))
284-
unit = PWM_UNIT_USEC;
285-
else if (sysfs_streq(buf, "nanosecond"))
286-
unit = PWM_UNIT_NSEC;
287-
else if (sysfs_streq(buf, "picosecond"))
288-
unit = PWM_UNIT_PSEC;
289-
else
290-
return -EINVAL;
291-
292-
mutex_lock(&export->lock);
293-
pwm_get_state(pwm, &state);
294-
state.time_unit = unit;
295-
ret = pwm_apply_state(pwm, &state);
296-
mutex_unlock(&export->lock);
297-
298-
return ret ? : size;
299-
}
300-
301238
static ssize_t capture_show(struct device *child,
302239
struct device_attribute *attr,
303240
char *buf)
@@ -319,7 +256,6 @@ static DEVICE_ATTR_RW(duty_cycle);
319256
static DEVICE_ATTR_RW(phase);
320257
static DEVICE_ATTR_RW(enable);
321258
static DEVICE_ATTR_RW(polarity);
322-
static DEVICE_ATTR_RW(time_unit);
323259
static DEVICE_ATTR_RO(capture);
324260

325261
static struct attribute *pwm_attrs[] = {
@@ -328,7 +264,6 @@ static struct attribute *pwm_attrs[] = {
328264
&dev_attr_phase.attr,
329265
&dev_attr_enable.attr,
330266
&dev_attr_polarity.attr,
331-
&dev_attr_time_unit.attr,
332267
&dev_attr_capture.attr,
333268
NULL
334269
};

include/linux/pwm.h

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88

99
struct pwm_chip;
1010

11-
/**
12-
* enum pwm_unit - the time unit in wich the pwm arguments are expressed.
13-
* @PWM_UNIT_SEC: the pwm_args members are specified in seconds
14-
* @PWM_UNIT_MSEC: the pwm_args members are specified in miliseconds
15-
* @PWM_UNIT_USEC: the pwm_args members are specified in microseconds
16-
* @PWM_UNIT_NSEC: the pwm_args members are specified in nanoseconds
17-
* @PWM_UNIT_PSEC: the pwm_args members are specified in picoseconds
18-
*/
19-
20-
enum pwm_time_unit {
21-
PWM_UNIT_SEC = 1,
22-
PWM_UNIT_MSEC,
23-
PWM_UNIT_USEC,
24-
PWM_UNIT_NSEC,
25-
PWM_UNIT_PSEC,
26-
};
27-
2811
/**
2912
* enum pwm_polarity - polarity of a PWM signal
3013
* @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
@@ -44,7 +27,6 @@ enum pwm_polarity {
4427
* @period: reference period
4528
* @polarity: reference polarity
4629
* @phase: reference phase
47-
* @time_unit: refference time unit
4830
*
4931
* This structure describes board-dependent arguments attached to a PWM
5032
* device. These arguments are usually retrieved from the PWM lookup table or
@@ -58,7 +40,6 @@ struct pwm_args {
5840
u64 period;
5941
u64 phase;
6042
enum pwm_polarity polarity;
61-
enum pwm_time_unit time_unit;
6243
};
6344

6445
enum {
@@ -68,11 +49,10 @@ enum {
6849

6950
/*
7051
* struct pwm_state - state of a PWM channel
71-
* @period: PWM period (with the time unit expressed in ->time_unit)
72-
* @duty_cycle: PWM duty cycle (with the time unit expressed in ->time_unit)
73-
* @phase: PWM phase (with the time unit expressed in ->time_unit)
52+
* @period: PWM period (in nanoseconds)
53+
* @duty_cycle: PWM duty cycle (in nanoseconds)
54+
* @phase: PWM phase (in nanoseconds)
7455
* @polarity: PWM polarity
75-
* @time_unit: PWM time unit
7656
* @enabled: PWM enabled status
7757
* @usage_power: If set, the PWM driver is only required to maintain the power
7858
* output but has more freedom regarding signal form.
@@ -84,7 +64,6 @@ struct pwm_state {
8464
u64 duty_cycle;
8565
u64 phase;
8666
enum pwm_polarity polarity;
87-
enum pwm_time_unit time_unit;
8867
bool enabled;
8968
bool usage_power;
9069
};
@@ -184,26 +163,6 @@ static inline u64 pwm_get_phase(const struct pwm_device *pwm)
184163
return state.phase;
185164
}
186165

187-
static inline int pwm_set_time_unit(struct pwm_device *pwm,
188-
enum pwm_time_unit time_unit)
189-
{
190-
if (!pwm || time_unit < PWM_UNIT_SEC || time_unit > PWM_UNIT_PSEC)
191-
return -EINVAL;
192-
193-
pwm->state.time_unit = time_unit;
194-
195-
return 0;
196-
}
197-
198-
static inline enum pwm_time_unit pwm_get_time_unit(const struct pwm_device *pwm)
199-
{
200-
struct pwm_state state;
201-
202-
pwm_get_state(pwm, &state);
203-
204-
return state.time_unit;
205-
}
206-
207166
static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
208167
{
209168
struct pwm_state state;
@@ -235,8 +194,6 @@ static inline void pwm_get_args(const struct pwm_device *pwm,
235194
* ->duty_cycle value exceed the pwm_args->period one, which would trigger
236195
* an error if the user calls pwm_apply_state() without adjusting ->duty_cycle
237196
* first.
238-
* ->time_unit is initially set to PWM_UNIT_NSEC to align all the previous
239-
* drivers that presume the pwm_state arguments time unit is nanoseconds.
240197
*/
241198
static inline void pwm_init_state(const struct pwm_device *pwm,
242199
struct pwm_state *state)
@@ -253,8 +210,6 @@ static inline void pwm_init_state(const struct pwm_device *pwm,
253210
state->polarity = args.polarity;
254211
state->duty_cycle = 0;
255212
state->phase = 0;
256-
/* Set the default time unit to nsec ensuring backward compatibility */
257-
state->time_unit = PWM_UNIT_NSEC;
258213
state->usage_power = false;
259214
}
260215

@@ -322,7 +277,6 @@ struct pwm_capture {
322277
u64 period;
323278
u64 duty_cycle;
324279
u64 phase;
325-
enum pwm_time_unit time_unit;
326280
};
327281

328282
/**
@@ -406,7 +360,6 @@ static inline int pwm_config(struct pwm_device *pwm, u64 duty_ns,
406360

407361
state.duty_cycle = duty_ns;
408362
state.period = period_ns;
409-
state.time_unit = PWM_UNIT_NSEC;
410363
return pwm_apply_state(pwm, &state);
411364
}
412365

@@ -611,7 +564,6 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
611564
state.polarity = pwm->args.polarity;
612565
state.period = pwm->args.period;
613566
state.phase = pwm->args.phase;
614-
state.time_unit = pwm->args.time_unit;
615567
state.usage_power = false;
616568

617569
pwm_apply_state(pwm, &state);

0 commit comments

Comments
 (0)