|
沙发
楼主 |
发表于 2015-9-11 11:43:58
|
只看该作者
解决办法(个人参考),
修改arch\arm\mach-s5p4418\soc\pwm.c如下:
- unsigned long nxp_soc_pwm_set_frequency(int ch, unsigned int request, unsigned int duty)
- {
- struct pwm_device *pwm = &devs_pwm[ch];
- volatile unsigned long rate, freq, clock = 0;
- volatile unsigned long hz = 0, pwmhz = 0;
- volatile unsigned int tcnt;
- int i, n, end = 0;
- RET_ASSERT_VAL(PWN_CHANNELS > ch, -EINVAL);
- RET_ASSERT_VAL(ch >= 0, -EINVAL);
- RET_ASSERT_VAL(100 >= duty && duty >= 0, -EINVAL);
- if (request > (clk_in_max/DUTY_MIN_VAL)) {
- pr_err("Invalid request=%u hz over max pwm out %ld hz\n",
- request, (clk_in_max/DUTY_MIN_VAL));
- return -EINVAL;
- }
- if (0 == duty) {
- pwm->compare = 0;
- pwm->duty=0;
- pwm->request = request;
- pwm_set_device(pwm);
- return request;
- }
- /*duwu20150911
- //for suspend -> resume
- if (pwm->request == request) {
- clock = pwm->rate;
- pwmhz = pwm->pwm_hz;
- }
- //change only dutycycle
- if (pwm->request == request && pwm->duty != duty) {
- clock = pwm->rate;
- pwmhz = pwm->pwm_hz;
- //set new pwm out
- } else {
- for (n = 1; !end; n *= 10) {
- for (i = (n == 1 ? DUTY_MIN_VAL : 1); 10 > i; i++) {
- freq = request * i * n;
- if (freq > clk_in_max) {
- end = 1;
- break;
- }
- rate = clk_round_rate(pwm->clk, freq);
- tcnt = rate/request;
- hz = rate/tcnt;
- if (0 == rate%request) {
- clock = rate, pwmhz = hz, end = 1;
- break;
- }
- if (hz && (abs(hz-request) >= abs(pwmhz-request)))
- continue;
- clock = rate, pwmhz = hz;
- }
- }
- }
- */
- if (pwm->request == request) {
- clock = pwm->rate;
- pwmhz = pwm->pwm_hz;
- }
- if(pwm->request != request || pwm->rate ==0){
- for (n = 1; !end; n *= 10) {
- for (i = (n == 1 ? DUTY_MIN_VAL : 1); 10 > i; i++) {
- freq = request * i * n;
- if (freq > clk_in_max) {
- end = 1;
- break;
- }
- rate = clk_round_rate(pwm->clk, freq);
- tcnt = rate/request;
- hz = rate/tcnt;
- if (0 == rate%request) {
- clock = rate, pwmhz = hz, end = 1;
- break;
- }
- if (hz && (abs(hz-request) >= abs(pwmhz-request)))
- continue;
- clock = rate, pwmhz = hz;
- }
- }
- }
- if (clock) {
- pwm->request = request;
- pwm->rate = clock;
- pwm->duty = duty;
- pwm->pwm_hz = pwmhz;
- pwm->counter = clock/request;
- pwm->compare = PWM_COMPARE(pwm->counter, duty) ? : 1;
- pwm_set_device(pwm);
- } else {
- printk("%s: can't find clock!!!\n", __func__);
- }
- return clock ? pwm->pwm_hz : 0;
- }
复制代码 |
|