Source
118
118
u32 period, prescaler, pwm_clk, val;
119
119
u64 tmp;
120
120
int ret;
121
121
122
122
ret = pwm_imx27_clk_prepare_enable(chip);
123
123
if (ret < 0)
124
124
return;
125
125
126
126
val = readl(imx->mmio_base + MX3_PWMCR);
127
127
128
-
if (val & MX3_PWMCR_EN) {
128
+
if (val & MX3_PWMCR_EN)
129
129
state->enabled = true;
130
-
ret = pwm_imx27_clk_prepare_enable(chip);
131
-
if (ret)
132
-
return;
133
-
} else {
130
+
else
134
131
state->enabled = false;
135
-
}
136
132
137
133
switch (FIELD_GET(MX3_PWMCR_POUTC, val)) {
138
134
case MX3_PWMCR_POUTC_NORMAL:
139
135
state->polarity = PWM_POLARITY_NORMAL;
140
136
break;
141
137
case MX3_PWMCR_POUTC_INVERTED:
142
138
state->polarity = PWM_POLARITY_INVERSED;
143
139
break;
144
140
default:
145
141
dev_warn(chip->dev, "can't set polarity, output disconnected");
157
153
158
154
/* PWMSAR can be read only if PWM is enabled */
159
155
if (state->enabled) {
160
156
val = readl(imx->mmio_base + MX3_PWMSAR);
161
157
tmp = NSEC_PER_SEC * (u64)(val);
162
158
state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk);
163
159
} else {
164
160
state->duty_cycle = 0;
165
161
}
166
162
167
-
pwm_imx27_clk_disable_unprepare(chip);
163
+
if (!state->enabled)
164
+
pwm_imx27_clk_disable_unprepare(chip);
168
165
}
169
166
170
167
static void pwm_imx27_sw_reset(struct pwm_chip *chip)
171
168
{
172
169
struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
173
170
struct device *dev = chip->dev;
174
171
int wait_count = 0;
175
172
u32 cr;
176
173
177
174
writel(MX3_PWMCR_SWR, imx->mmio_base + MX3_PWMCR);