@@ -76,31 +76,20 @@ static bool pwm_wf_valid(const struct pwm_waveform *wf)
76
76
static void pwm_wf2state (const struct pwm_waveform * wf , struct pwm_state * state )
77
77
{
78
78
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 )
80
80
* state = (struct pwm_state ){
81
81
.enabled = true,
82
82
.polarity = PWM_POLARITY_NORMAL ,
83
83
.period = wf -> period_length_ns ,
84
84
.duty_cycle = wf -> duty_length_ns ,
85
- .phase = wf -> duty_offset_ns ,
86
85
};
87
- } else {
86
+ else
88
87
* state = (struct pwm_state ){
89
88
.enabled = true,
90
89
.polarity = PWM_POLARITY_INVERSED ,
91
90
.period = wf -> period_length_ns ,
92
91
.duty_cycle = wf -> period_length_ns - wf -> duty_length_ns ,
93
- .phase = wf -> duty_offset_ns + wf -> duty_length_ns ,
94
92
};
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
- }
104
93
} else {
105
94
* state = (struct pwm_state ){
106
95
.enabled = false,
@@ -111,26 +100,18 @@ static void pwm_wf2state(const struct pwm_waveform *wf, struct pwm_state *state)
111
100
static void pwm_state2wf (const struct pwm_state * state , struct pwm_waveform * wf )
112
101
{
113
102
if (state -> enabled ) {
114
- if (state -> polarity == PWM_POLARITY_NORMAL ) {
103
+ if (state -> polarity == PWM_POLARITY_NORMAL )
115
104
* wf = (struct pwm_waveform ){
116
105
.period_length_ns = state -> period ,
117
106
.duty_length_ns = state -> duty_cycle ,
118
- .duty_offset_ns = state -> phase ,
107
+ .duty_offset_ns = 0 ,
119
108
};
120
- } else {
109
+ else
121
110
* wf = (struct pwm_waveform ){
122
111
.period_length_ns = state -> period ,
123
112
.duty_length_ns = state -> period - state -> duty_cycle ,
124
- .duty_offset_ns = state -> duty_cycle + state -> phase ,
113
+ .duty_offset_ns = state -> duty_cycle ,
125
114
};
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
- }
134
115
} else {
135
116
* wf = (struct pwm_waveform ){
136
117
.period_length_ns = 0 ,
@@ -608,8 +589,7 @@ static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state)
608
589
state -> duty_cycle == pwm -> state .duty_cycle &&
609
590
state -> polarity == pwm -> state .polarity &&
610
591
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 )
613
593
return 0 ;
614
594
615
595
if (ops -> write_waveform ) {
@@ -1125,41 +1105,6 @@ static ssize_t duty_cycle_store(struct device *pwm_dev,
1125
1105
return ret ? : size ;
1126
1106
}
1127
1107
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
-
1163
1108
static ssize_t enable_show (struct device * pwm_dev ,
1164
1109
struct device_attribute * attr ,
1165
1110
char * buf )
@@ -1271,15 +1216,13 @@ static ssize_t capture_show(struct device *pwm_dev,
1271
1216
1272
1217
static DEVICE_ATTR_RW (period );
1273
1218
static DEVICE_ATTR_RW (duty_cycle );
1274
- static DEVICE_ATTR_RW (phase );
1275
1219
static DEVICE_ATTR_RW (enable );
1276
1220
static DEVICE_ATTR_RW (polarity );
1277
1221
static DEVICE_ATTR_RO (capture );
1278
1222
1279
1223
static struct attribute * pwm_attrs [] = {
1280
1224
& dev_attr_period .attr ,
1281
1225
& dev_attr_duty_cycle .attr ,
1282
- & dev_attr_phase .attr ,
1283
1226
& dev_attr_enable .attr ,
1284
1227
& dev_attr_polarity .attr ,
1285
1228
& dev_attr_capture .attr ,
@@ -2267,7 +2210,6 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
2267
2210
2268
2211
seq_printf (s , " period: %llu ns" , state .period );
2269
2212
seq_printf (s , " duty: %llu ns" , state .duty_cycle );
2270
- seq_printf (s , " phase: %llu ns" , state .phase );
2271
2213
seq_printf (s , " polarity: %s" ,
2272
2214
state .polarity ? "inverse" : "normal" );
2273
2215
0 commit comments