@@ -64,6 +64,11 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
64
64
int ret ;
65
65
struct ep93xx_pwm * ep93xx_pwm = to_ep93xx_pwm (chip );
66
66
bool enabled = state -> enabled ;
67
+ void __iomem * base = ep93xx_pwm -> base ;
68
+ unsigned long long c ;
69
+ unsigned long period_cycles ;
70
+ unsigned long duty_cycles ;
71
+ unsigned long term ;
67
72
68
73
if (state -> polarity != pwm -> state .polarity ) {
69
74
if (enabled ) {
@@ -97,57 +102,47 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
97
102
return 0 ;
98
103
}
99
104
100
- if (state -> period != pwm -> state .period ||
101
- state -> duty_cycle != pwm -> state .duty_cycle ) {
102
- struct ep93xx_pwm * ep93xx_pwm = to_ep93xx_pwm (chip );
103
- void __iomem * base = ep93xx_pwm -> base ;
104
- unsigned long long c ;
105
- unsigned long period_cycles ;
106
- unsigned long duty_cycles ;
107
- unsigned long term ;
105
+ /*
106
+ * The clock needs to be enabled to access the PWM registers.
107
+ * Configuration can be changed at any time.
108
+ */
109
+ if (!pwm_is_enabled (pwm )) {
110
+ ret = clk_prepare_enable (ep93xx_pwm -> clk );
111
+ if (ret )
112
+ return ret ;
113
+ }
108
114
109
- /*
110
- * The clock needs to be enabled to access the PWM registers.
111
- * Configuration can be changed at any time.
112
- */
113
- if (! pwm_is_enabled ( pwm )) {
114
- ret = clk_prepare_enable ( ep93xx_pwm -> clk ) ;
115
- if ( ret )
116
- return ret ;
117
- }
115
+ c = clk_get_rate ( ep93xx_pwm -> clk );
116
+ c *= state -> period ;
117
+ do_div ( c , 1000000000 );
118
+ period_cycles = c ;
119
+
120
+ c = period_cycles ;
121
+ c *= state -> duty_cycle ;
122
+ do_div ( c , state -> period ) ;
123
+ duty_cycles = c ;
118
124
119
- c = clk_get_rate (ep93xx_pwm -> clk );
120
- c *= state -> period ;
121
- do_div (c , 1000000000 );
122
- period_cycles = c ;
123
-
124
- c = period_cycles ;
125
- c *= state -> duty_cycle ;
126
- do_div (c , state -> period );
127
- duty_cycles = c ;
128
-
129
- if (period_cycles < 0x10000 && duty_cycles < 0x10000 ) {
130
- term = readw (base + EP93XX_PWMx_TERM_COUNT );
131
-
132
- /* Order is important if PWM is running */
133
- if (period_cycles > term ) {
134
- writew (period_cycles , base + EP93XX_PWMx_TERM_COUNT );
135
- writew (duty_cycles , base + EP93XX_PWMx_DUTY_CYCLE );
136
- } else {
137
- writew (duty_cycles , base + EP93XX_PWMx_DUTY_CYCLE );
138
- writew (period_cycles , base + EP93XX_PWMx_TERM_COUNT );
139
- }
140
- ret = 0 ;
125
+ if (period_cycles < 0x10000 && duty_cycles < 0x10000 ) {
126
+ term = readw (base + EP93XX_PWMx_TERM_COUNT );
127
+
128
+ /* Order is important if PWM is running */
129
+ if (period_cycles > term ) {
130
+ writew (period_cycles , base + EP93XX_PWMx_TERM_COUNT );
131
+ writew (duty_cycles , base + EP93XX_PWMx_DUTY_CYCLE );
141
132
} else {
142
- ret = - EINVAL ;
133
+ writew (duty_cycles , base + EP93XX_PWMx_DUTY_CYCLE );
134
+ writew (period_cycles , base + EP93XX_PWMx_TERM_COUNT );
143
135
}
136
+ ret = 0 ;
137
+ } else {
138
+ ret = - EINVAL ;
139
+ }
144
140
145
- if (!pwm_is_enabled (pwm ))
146
- clk_disable_unprepare (ep93xx_pwm -> clk );
141
+ if (!pwm_is_enabled (pwm ))
142
+ clk_disable_unprepare (ep93xx_pwm -> clk );
147
143
148
- if (ret )
149
- return ret ;
150
- }
144
+ if (ret )
145
+ return ret ;
151
146
152
147
if (!enabled ) {
153
148
ret = clk_prepare_enable (ep93xx_pwm -> clk );
0 commit comments