@@ -89,80 +89,80 @@ struct tpu_device {
89
89
90
90
#define to_tpu_device (c ) container_of(c, struct tpu_device, chip)
91
91
92
- static void tpu_pwm_write (struct tpu_pwm_device * pwm , int reg_nr , u16 value )
92
+ static void tpu_pwm_write (struct tpu_pwm_device * tpd , int reg_nr , u16 value )
93
93
{
94
- void __iomem * base = pwm -> tpu -> base + TPU_CHANNEL_OFFSET
95
- + pwm -> channel * TPU_CHANNEL_SIZE ;
94
+ void __iomem * base = tpd -> tpu -> base + TPU_CHANNEL_OFFSET
95
+ + tpd -> channel * TPU_CHANNEL_SIZE ;
96
96
97
97
iowrite16 (value , base + reg_nr );
98
98
}
99
99
100
- static void tpu_pwm_set_pin (struct tpu_pwm_device * pwm ,
100
+ static void tpu_pwm_set_pin (struct tpu_pwm_device * tpd ,
101
101
enum tpu_pin_state state )
102
102
{
103
103
static const char * const states [] = { "inactive" , "PWM" , "active" };
104
104
105
- dev_dbg (& pwm -> tpu -> pdev -> dev , "%u: configuring pin as %s\n" ,
106
- pwm -> channel , states [state ]);
105
+ dev_dbg (& tpd -> tpu -> pdev -> dev , "%u: configuring pin as %s\n" ,
106
+ tpd -> channel , states [state ]);
107
107
108
108
switch (state ) {
109
109
case TPU_PIN_INACTIVE :
110
- tpu_pwm_write (pwm , TPU_TIORn ,
111
- pwm -> polarity == PWM_POLARITY_INVERSED ?
110
+ tpu_pwm_write (tpd , TPU_TIORn ,
111
+ tpd -> polarity == PWM_POLARITY_INVERSED ?
112
112
TPU_TIOR_IOA_1 : TPU_TIOR_IOA_0 );
113
113
break ;
114
114
case TPU_PIN_PWM :
115
- tpu_pwm_write (pwm , TPU_TIORn ,
116
- pwm -> polarity == PWM_POLARITY_INVERSED ?
115
+ tpu_pwm_write (tpd , TPU_TIORn ,
116
+ tpd -> polarity == PWM_POLARITY_INVERSED ?
117
117
TPU_TIOR_IOA_0_SET : TPU_TIOR_IOA_1_CLR );
118
118
break ;
119
119
case TPU_PIN_ACTIVE :
120
- tpu_pwm_write (pwm , TPU_TIORn ,
121
- pwm -> polarity == PWM_POLARITY_INVERSED ?
120
+ tpu_pwm_write (tpd , TPU_TIORn ,
121
+ tpd -> polarity == PWM_POLARITY_INVERSED ?
122
122
TPU_TIOR_IOA_0 : TPU_TIOR_IOA_1 );
123
123
break ;
124
124
}
125
125
}
126
126
127
- static void tpu_pwm_start_stop (struct tpu_pwm_device * pwm , int start )
127
+ static void tpu_pwm_start_stop (struct tpu_pwm_device * tpd , int start )
128
128
{
129
129
unsigned long flags ;
130
130
u16 value ;
131
131
132
- spin_lock_irqsave (& pwm -> tpu -> lock , flags );
133
- value = ioread16 (pwm -> tpu -> base + TPU_TSTR );
132
+ spin_lock_irqsave (& tpd -> tpu -> lock , flags );
133
+ value = ioread16 (tpd -> tpu -> base + TPU_TSTR );
134
134
135
135
if (start )
136
- value |= 1 << pwm -> channel ;
136
+ value |= 1 << tpd -> channel ;
137
137
else
138
- value &= ~(1 << pwm -> channel );
138
+ value &= ~(1 << tpd -> channel );
139
139
140
- iowrite16 (value , pwm -> tpu -> base + TPU_TSTR );
141
- spin_unlock_irqrestore (& pwm -> tpu -> lock , flags );
140
+ iowrite16 (value , tpd -> tpu -> base + TPU_TSTR );
141
+ spin_unlock_irqrestore (& tpd -> tpu -> lock , flags );
142
142
}
143
143
144
- static int tpu_pwm_timer_start (struct tpu_pwm_device * pwm )
144
+ static int tpu_pwm_timer_start (struct tpu_pwm_device * tpd )
145
145
{
146
146
int ret ;
147
147
148
- if (!pwm -> timer_on ) {
148
+ if (!tpd -> timer_on ) {
149
149
/* Wake up device and enable clock. */
150
- pm_runtime_get_sync (& pwm -> tpu -> pdev -> dev );
151
- ret = clk_prepare_enable (pwm -> tpu -> clk );
150
+ pm_runtime_get_sync (& tpd -> tpu -> pdev -> dev );
151
+ ret = clk_prepare_enable (tpd -> tpu -> clk );
152
152
if (ret ) {
153
- dev_err (& pwm -> tpu -> pdev -> dev , "cannot enable clock\n" );
153
+ dev_err (& tpd -> tpu -> pdev -> dev , "cannot enable clock\n" );
154
154
return ret ;
155
155
}
156
- pwm -> timer_on = true;
156
+ tpd -> timer_on = true;
157
157
}
158
158
159
159
/*
160
160
* Make sure the channel is stopped, as we need to reconfigure it
161
161
* completely. First drive the pin to the inactive state to avoid
162
162
* glitches.
163
163
*/
164
- tpu_pwm_set_pin (pwm , TPU_PIN_INACTIVE );
165
- tpu_pwm_start_stop (pwm , false);
164
+ tpu_pwm_set_pin (tpd , TPU_PIN_INACTIVE );
165
+ tpu_pwm_start_stop (tpd , false);
166
166
167
167
/*
168
168
* - Clear TCNT on TGRB match
@@ -172,80 +172,80 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *pwm)
172
172
* - Output 1 until TGRA, output 0 until TGRB (active high polarity
173
173
* - PWM mode
174
174
*/
175
- tpu_pwm_write (pwm , TPU_TCRn , TPU_TCR_CCLR_TGRB | TPU_TCR_CKEG_RISING |
176
- pwm -> prescaler );
177
- tpu_pwm_write (pwm , TPU_TMDRn , TPU_TMDR_MD_PWM );
178
- tpu_pwm_set_pin (pwm , TPU_PIN_PWM );
179
- tpu_pwm_write (pwm , TPU_TGRAn , pwm -> duty );
180
- tpu_pwm_write (pwm , TPU_TGRBn , pwm -> period );
175
+ tpu_pwm_write (tpd , TPU_TCRn , TPU_TCR_CCLR_TGRB | TPU_TCR_CKEG_RISING |
176
+ tpd -> prescaler );
177
+ tpu_pwm_write (tpd , TPU_TMDRn , TPU_TMDR_MD_PWM );
178
+ tpu_pwm_set_pin (tpd , TPU_PIN_PWM );
179
+ tpu_pwm_write (tpd , TPU_TGRAn , tpd -> duty );
180
+ tpu_pwm_write (tpd , TPU_TGRBn , tpd -> period );
181
181
182
- dev_dbg (& pwm -> tpu -> pdev -> dev , "%u: TGRA 0x%04x TGRB 0x%04x\n" ,
183
- pwm -> channel , pwm -> duty , pwm -> period );
182
+ dev_dbg (& tpd -> tpu -> pdev -> dev , "%u: TGRA 0x%04x TGRB 0x%04x\n" ,
183
+ tpd -> channel , tpd -> duty , tpd -> period );
184
184
185
185
/* Start the channel. */
186
- tpu_pwm_start_stop (pwm , true);
186
+ tpu_pwm_start_stop (tpd , true);
187
187
188
188
return 0 ;
189
189
}
190
190
191
- static void tpu_pwm_timer_stop (struct tpu_pwm_device * pwm )
191
+ static void tpu_pwm_timer_stop (struct tpu_pwm_device * tpd )
192
192
{
193
- if (!pwm -> timer_on )
193
+ if (!tpd -> timer_on )
194
194
return ;
195
195
196
196
/* Disable channel. */
197
- tpu_pwm_start_stop (pwm , false);
197
+ tpu_pwm_start_stop (tpd , false);
198
198
199
199
/* Stop clock and mark device as idle. */
200
- clk_disable_unprepare (pwm -> tpu -> clk );
201
- pm_runtime_put (& pwm -> tpu -> pdev -> dev );
200
+ clk_disable_unprepare (tpd -> tpu -> clk );
201
+ pm_runtime_put (& tpd -> tpu -> pdev -> dev );
202
202
203
- pwm -> timer_on = false;
203
+ tpd -> timer_on = false;
204
204
}
205
205
206
206
/* -----------------------------------------------------------------------------
207
207
* PWM API
208
208
*/
209
209
210
- static int tpu_pwm_request (struct pwm_chip * chip , struct pwm_device * _pwm )
210
+ static int tpu_pwm_request (struct pwm_chip * chip , struct pwm_device * pwm )
211
211
{
212
212
struct tpu_device * tpu = to_tpu_device (chip );
213
- struct tpu_pwm_device * pwm ;
213
+ struct tpu_pwm_device * tpd ;
214
214
215
- if (_pwm -> hwpwm >= TPU_CHANNEL_MAX )
215
+ if (pwm -> hwpwm >= TPU_CHANNEL_MAX )
216
216
return - EINVAL ;
217
217
218
- pwm = kzalloc (sizeof (* pwm ), GFP_KERNEL );
219
- if (pwm == NULL )
218
+ tpd = kzalloc (sizeof (* tpd ), GFP_KERNEL );
219
+ if (tpd == NULL )
220
220
return - ENOMEM ;
221
221
222
- pwm -> tpu = tpu ;
223
- pwm -> channel = _pwm -> hwpwm ;
224
- pwm -> polarity = PWM_POLARITY_NORMAL ;
225
- pwm -> prescaler = 0 ;
226
- pwm -> period = 0 ;
227
- pwm -> duty = 0 ;
222
+ tpd -> tpu = tpu ;
223
+ tpd -> channel = pwm -> hwpwm ;
224
+ tpd -> polarity = PWM_POLARITY_NORMAL ;
225
+ tpd -> prescaler = 0 ;
226
+ tpd -> period = 0 ;
227
+ tpd -> duty = 0 ;
228
228
229
- pwm -> timer_on = false;
229
+ tpd -> timer_on = false;
230
230
231
- pwm_set_chip_data (_pwm , pwm );
231
+ pwm_set_chip_data (pwm , tpd );
232
232
233
233
return 0 ;
234
234
}
235
235
236
- static void tpu_pwm_free (struct pwm_chip * chip , struct pwm_device * _pwm )
236
+ static void tpu_pwm_free (struct pwm_chip * chip , struct pwm_device * pwm )
237
237
{
238
- struct tpu_pwm_device * pwm = pwm_get_chip_data (_pwm );
238
+ struct tpu_pwm_device * tpd = pwm_get_chip_data (pwm );
239
239
240
- tpu_pwm_timer_stop (pwm );
241
- kfree (pwm );
240
+ tpu_pwm_timer_stop (tpd );
241
+ kfree (tpd );
242
242
}
243
243
244
- static int tpu_pwm_config (struct pwm_chip * chip , struct pwm_device * _pwm ,
244
+ static int tpu_pwm_config (struct pwm_chip * chip , struct pwm_device * pwm ,
245
245
int duty_ns , int period_ns , bool enabled )
246
246
{
247
247
static const unsigned int prescalers [] = { 1 , 4 , 16 , 64 };
248
- struct tpu_pwm_device * pwm = pwm_get_chip_data (_pwm );
248
+ struct tpu_pwm_device * tpd = pwm_get_chip_data (pwm );
249
249
struct tpu_device * tpu = to_tpu_device (chip );
250
250
unsigned int prescaler ;
251
251
bool duty_only = false;
@@ -285,29 +285,29 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
285
285
"rate %u, prescaler %u, period %u, duty %u\n" ,
286
286
clk_rate , prescalers [prescaler ], period , duty );
287
287
288
- if (pwm -> prescaler == prescaler && pwm -> period == period )
288
+ if (tpd -> prescaler == prescaler && tpd -> period == period )
289
289
duty_only = true;
290
290
291
- pwm -> prescaler = prescaler ;
292
- pwm -> period = period ;
293
- pwm -> duty = duty ;
291
+ tpd -> prescaler = prescaler ;
292
+ tpd -> period = period ;
293
+ tpd -> duty = duty ;
294
294
295
295
/* If the channel is disabled we're done. */
296
296
if (!enabled )
297
297
return 0 ;
298
298
299
- if (duty_only && pwm -> timer_on ) {
299
+ if (duty_only && tpd -> timer_on ) {
300
300
/*
301
301
* If only the duty cycle changed and the timer is already
302
302
* running, there's no need to reconfigure it completely, Just
303
303
* modify the duty cycle.
304
304
*/
305
- tpu_pwm_write (pwm , TPU_TGRAn , pwm -> duty );
306
- dev_dbg (& tpu -> pdev -> dev , "%u: TGRA 0x%04x\n" , pwm -> channel ,
307
- pwm -> duty );
305
+ tpu_pwm_write (tpd , TPU_TGRAn , tpd -> duty );
306
+ dev_dbg (& tpu -> pdev -> dev , "%u: TGRA 0x%04x\n" , tpd -> channel ,
307
+ tpd -> duty );
308
308
} else {
309
309
/* Otherwise perform a full reconfiguration. */
310
- ret = tpu_pwm_timer_start (pwm );
310
+ ret = tpu_pwm_timer_start (tpd );
311
311
if (ret < 0 )
312
312
return ret ;
313
313
}
@@ -317,53 +317,53 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
317
317
* To avoid running the timer when not strictly required, handle
318
318
* 0% and 100% duty cycles as fixed levels and stop the timer.
319
319
*/
320
- tpu_pwm_set_pin (pwm , duty ? TPU_PIN_ACTIVE : TPU_PIN_INACTIVE );
321
- tpu_pwm_timer_stop (pwm );
320
+ tpu_pwm_set_pin (tpd , duty ? TPU_PIN_ACTIVE : TPU_PIN_INACTIVE );
321
+ tpu_pwm_timer_stop (tpd );
322
322
}
323
323
324
324
return 0 ;
325
325
}
326
326
327
- static int tpu_pwm_set_polarity (struct pwm_chip * chip , struct pwm_device * _pwm ,
327
+ static int tpu_pwm_set_polarity (struct pwm_chip * chip , struct pwm_device * pwm ,
328
328
enum pwm_polarity polarity )
329
329
{
330
- struct tpu_pwm_device * pwm = pwm_get_chip_data (_pwm );
330
+ struct tpu_pwm_device * tpd = pwm_get_chip_data (pwm );
331
331
332
- pwm -> polarity = polarity ;
332
+ tpd -> polarity = polarity ;
333
333
334
334
return 0 ;
335
335
}
336
336
337
- static int tpu_pwm_enable (struct pwm_chip * chip , struct pwm_device * _pwm )
337
+ static int tpu_pwm_enable (struct pwm_chip * chip , struct pwm_device * pwm )
338
338
{
339
- struct tpu_pwm_device * pwm = pwm_get_chip_data (_pwm );
339
+ struct tpu_pwm_device * tpd = pwm_get_chip_data (pwm );
340
340
int ret ;
341
341
342
- ret = tpu_pwm_timer_start (pwm );
342
+ ret = tpu_pwm_timer_start (tpd );
343
343
if (ret < 0 )
344
344
return ret ;
345
345
346
346
/*
347
347
* To avoid running the timer when not strictly required, handle 0% and
348
348
* 100% duty cycles as fixed levels and stop the timer.
349
349
*/
350
- if (pwm -> duty == 0 || pwm -> duty == pwm -> period ) {
351
- tpu_pwm_set_pin (pwm , pwm -> duty ?
350
+ if (tpd -> duty == 0 || tpd -> duty == tpd -> period ) {
351
+ tpu_pwm_set_pin (tpd , tpd -> duty ?
352
352
TPU_PIN_ACTIVE : TPU_PIN_INACTIVE );
353
- tpu_pwm_timer_stop (pwm );
353
+ tpu_pwm_timer_stop (tpd );
354
354
}
355
355
356
356
return 0 ;
357
357
}
358
358
359
- static void tpu_pwm_disable (struct pwm_chip * chip , struct pwm_device * _pwm )
359
+ static void tpu_pwm_disable (struct pwm_chip * chip , struct pwm_device * pwm )
360
360
{
361
- struct tpu_pwm_device * pwm = pwm_get_chip_data (_pwm );
361
+ struct tpu_pwm_device * tpd = pwm_get_chip_data (pwm );
362
362
363
363
/* The timer must be running to modify the pin output configuration. */
364
- tpu_pwm_timer_start (pwm );
365
- tpu_pwm_set_pin (pwm , TPU_PIN_INACTIVE );
366
- tpu_pwm_timer_stop (pwm );
364
+ tpu_pwm_timer_start (tpd );
365
+ tpu_pwm_set_pin (tpd , TPU_PIN_INACTIVE );
366
+ tpu_pwm_timer_stop (tpd );
367
367
}
368
368
369
369
static int tpu_pwm_apply (struct pwm_chip * chip , struct pwm_device * pwm ,
0 commit comments