Date:2010-05-10 13:07:06 (10 years 4 months ago)
Author:Lars C.
Commit:f1df893177d8441142c0460041c84575da60445e
Message:pwm fixes.

Files: arch/mips/jz4740/pwm.c (4 diffs)
arch/mips/jz4740/timer.c (1 diff)
arch/mips/jz4740/timer.h (1 diff)

Change Details

arch/mips/jz4740/pwm.c
8383
8484    jz_gpio_set_function(pwm->gpio, JZ_GPIO_FUNC_PWM);
8585
86    jz4740_timer_start(id);
87
8688    return pwm;
8789}
8890
...... 
9496    jz_gpio_set_function(pwm->gpio, JZ_GPIO_FUNC_NONE);
9597    gpio_free(pwm->gpio);
9698
99    jz4740_timer_stop(pwm->id);
100
97101    pwm->used = false;
102
98103}
99104
100105int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
101106{
102
103107    unsigned long long tmp;
104108    unsigned long period, duty;
105109    unsigned int prescaler = 0;
106110    unsigned int id = pwm->id;
107111    uint16_t ctrl;
112    bool is_enabled;
108113
109    if (duty_ns > period_ns)
114    if (duty_ns < 0 || duty_ns > period_ns)
110115        return -EINVAL;
111116
112117    tmp = (unsigned long long)clk_get_rate(jz4740_pwm_clk) * period_ns;
...... 
128133    do_div(tmp, period_ns);
129134    duty = tmp;
130135
136    if (duty >= period)
137        duty = period - 1;
138
139    is_enabled = jz4740_timer_is_enabled(id);
140    jz4740_timer_disable(id);
141
142    jz4740_timer_set_count(id, 0);
131143    jz4740_timer_set_duty(id, duty);
132144    jz4740_timer_set_period(id, period);
133145
...... 
136148
137149    jz4740_timer_set_ctrl(id, ctrl);
138150
151    if (is_enabled)
152        jz4740_timer_enable(id);
153
139154    return 0;
140155}
141156
arch/mips/jz4740/timer.c
3939
4040    if (!jz4740_timer_base)
4141        panic("Failed to ioremap timer registers");
42
43    /* Disable all timers except those used as system timers */
44    writeb(0xfc, jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
4245}
arch/mips/jz4740/timer.h
6060extern void __iomem *jz4740_timer_base;
6161void __init jz4740_timer_init(void);
6262
63static inline void jz4740_timer_enable(unsigned int timer)
63static inline void jz4740_timer_stop(unsigned int timer)
64{
65    writel(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
66}
67
68static inline void jz4740_timer_start(unsigned int timer)
6469{
6570    writel(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_STOP_CLEAR);
71}
72
73static inline bool jz4740_timer_is_enabled(unsigned int timer)
74{
75    return readb(jz4740_timer_base + JZ_REG_TIMER_ENABLE) & BIT(timer);
76}
77
78static inline void jz4740_timer_enable(unsigned int timer)
79{
6680    writeb(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_ENABLE_SET);
6781}
6882
6983static inline void jz4740_timer_disable(unsigned int timer)
7084{
7185    writeb(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_ENABLE_CLEAR);
72    writel(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
7386}
7487
7588

Archive Download the corresponding diff file



interactive