Skip to content

Commit 9cfed49

Browse files
committed
drivers: pwm_shim: correct api argument inconsistency
Correct the argument definition inconsistency for the set value API. To be consistent with other pwm sub drivers, the on and off arguments for the set value api are re-defined. On: how far (number of timer count) from the beginning of a PWM cycle the PWM pin will be asserted. Off:how far (number of timer count) from the beginning of a PWM cycle the PWM pin will be de-asserted. Jira: ZEP-642 Change-Id: I7b39f98f1935fc3499fb36dd813abed62b86c1e7 Signed-off-by: Baohong Liu <[email protected]>
1 parent 6f36d7d commit 9cfed49

File tree

2 files changed

+69
-24
lines changed

2 files changed

+69
-24
lines changed

drivers/pwm/pwm_qmsi.c

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,32 +158,35 @@ static int __set_one_port(struct device *dev, qm_pwm_t id, uint32_t pwm,
158158
}
159159

160160
/*
161-
* Set the duration for on/off timer of PWM.
161+
* Set the time to assert and de-assert the PWM pin.
162162
*
163-
* This sets the duration for the pin to low or high.
163+
* This sets the duration for the pin to stay low or high.
164164
*
165-
* Assumes a nominal system clock of 32MHz, each count of on/off represents
166-
* 31.25ns (e.g. on == 2 means the pin stays high for 62.5ns).
167-
* The duration of 1 count depends on system clock. Refer to the hardware
168-
* manual for more information.
165+
* For example, with a nominal system clock of 32MHz, each count of on/off
166+
* represents 31.25ns (e.g. off == 2 means the pin is to be de-asserted at
167+
* 62.5ns from the beginning of a PWM cycle). The duration of 1 count depends
168+
* on system clock. Refer to the hardware manual for more information.
169169
*
170170
* Parameters
171-
* dev: Device struct
171+
* dev: Pointer to PWM device structure
172172
* access_op: whether to set one pin or all
173-
* pwm: Which PWM port to set
174-
* on: Duration for pin to stay high (must be >= 2)
175-
* off: Duration for pin to stay low (must be >= 2)
173+
* pwm: PWM port number to set
174+
* on: How far (in timer count) from the beginning of a PWM cycle the PWM
175+
* pin should be asserted. Must be zero, since PWM from Quark MCU always
176+
* starts from high.
177+
* off: How far (in timer count) from the beginning of a PWM cycle the PWM
178+
* pin should be de-asserted.
176179
*
177-
* return 0, -ENOTSUP
180+
* return 0, or negative errno code
178181
*/
179182
static int pwm_qmsi_set_values(struct device *dev, int access_op,
180-
uint32_t pwm, uint32_t on, uint32_t off)
183+
uint32_t pwm, uint32_t on, uint32_t off)
181184
{
182-
int i;
185+
uint32_t *channel_period = dev->config->config_info;
186+
int i, high, low;
183187

184-
if (off == 0) {
185-
on--;
186-
off = 1;
188+
if (on) {
189+
return -EINVAL;
187190
}
188191

189192
switch (access_op) {
@@ -192,13 +195,40 @@ static int pwm_qmsi_set_values(struct device *dev, int access_op,
192195
if (pwm >= CONFIG_PWM_QMSI_NUM_PORTS) {
193196
return -EIO;
194197
}
195-
return __set_one_port(dev, QM_PWM_0, pwm, on, off);
198+
199+
high = off;
200+
low = channel_period[pwm] - off;
201+
202+
if (off >= channel_period[pwm]) {
203+
high = channel_period[pwm] - 1;
204+
low = 1;
205+
}
206+
207+
if (off == 0) {
208+
high = 1;
209+
low = channel_period[pwm] - 1;
210+
}
211+
212+
return __set_one_port(dev, QM_PWM_0, pwm, high, low);
196213

197214
case PWM_ACCESS_ALL:
198215
for (i = 0; i < CONFIG_PWM_QMSI_NUM_PORTS; i++) {
199-
__set_one_port(dev, QM_PWM_0, i, on, off);
216+
high = off;
217+
low = channel_period[i] - off;
218+
219+
if (off >= channel_period[i]) {
220+
high = channel_period[i] - 1;
221+
low = 1;
222+
}
223+
224+
if (off == 0) {
225+
high = 1;
226+
low = channel_period[i] - 1;
227+
}
228+
229+
return __set_one_port(dev, QM_PWM_0, i, high, low);
200230
}
201-
break;
231+
break;
202232
default:
203233
return -ENOTSUP;
204234
}
@@ -208,7 +238,7 @@ static int pwm_qmsi_set_values(struct device *dev, int access_op,
208238
}
209239

210240
static int pwm_qmsi_set_period(struct device *dev, int access_op,
211-
uint32_t pwm, uint32_t period)
241+
uint32_t pwm, uint32_t period)
212242
{
213243
uint32_t *channel_period = dev->config->config_info;
214244
int ret_val = 0;
@@ -295,12 +325,23 @@ static int pwm_qmsi_set_duty_cycle(struct device *dev, int access_op,
295325
return 0;
296326
}
297327

328+
static int pwm_qmsi_set_phase(struct device *dev, int access_op,
329+
uint32_t pwm, uint8_t phase)
330+
{
331+
ARG_UNUSED(dev);
332+
ARG_UNUSED(access_op);
333+
ARG_UNUSED(pwm);
334+
ARG_UNUSED(phase);
335+
336+
return -ENOTSUP;
337+
}
298338

299339
static struct pwm_driver_api pwm_qmsi_drv_api_funcs = {
300340
.config = pwm_qmsi_configure,
301341
.set_values = pwm_qmsi_set_values,
302342
.set_period = pwm_qmsi_set_period,
303343
.set_duty_cycle = pwm_qmsi_set_duty_cycle,
344+
.set_phase = pwm_qmsi_set_phase
304345
};
305346

306347
static int pwm_qmsi_init(struct device *dev)

include/pwm.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ static inline int pwm_pin_configure(struct device *dev, uint8_t pwm,
114114
*
115115
* @param dev Pointer to the device structure for the driver instance.
116116
* @param pwm PWM output.
117-
* @param on ON value set to the PWM.
118-
* @param off OFF value set to the PWM.
117+
* @param on ON value (number of timer count) set to the PWM. HW specific.
118+
* How far from the beginning of a PWM cycle the PWM pulse starts.
119+
* @param off OFF value (number of timer count) set to the PWM. HW specific.
120+
* How far from the beginning of a PWM cycle the PWM pulse stops.
119121
*
120122
* @retval 0 If successful.
121123
* @retval Negative errno code if failure.
@@ -220,8 +222,10 @@ static inline int pwm_all_configure(struct device *dev, int flags)
220222
* @brief Set the ON/OFF values for all PWM outputs.
221223
*
222224
* @param dev Pointer to the device structure for the driver instance.
223-
* @param on ON value set to the PWM.
224-
* @param off OFF value set to the PWM.
225+
* @param on ON value (number of timer count) set to the PWM. HW specific.
226+
* How far from the beginning of a PWM cycle the PWM pulse starts.
227+
* @param off OFF value (number of timer count) set to the PWM. HW specific.
228+
* How far from the beginning of a PWM cycle the PWM pulse stops.
225229
*
226230
* @retval 0 If successful.
227231
* @retval Negative errno code if failure.

0 commit comments

Comments
 (0)