@@ -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 */
179182static 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
210240static 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
299339static 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
306347static int pwm_qmsi_init (struct device * dev )
0 commit comments