diff options
author | Tom Rini <trini@konsulko.com> | 2018-10-29 11:21:00 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-10-29 11:21:00 -0400 |
commit | 2f07a9a6d1abd1eeb283a21a8d718dc9628429a4 (patch) | |
tree | 1c7f7543d6da1822b40533560831c241ddcbe021 /drivers | |
parent | d735d3b6cb778012f05c2e3fca01df7f6ae6f035 (diff) | |
parent | 5776610e9ef022e2d8a15793d4b9955c3f8076ed (diff) | |
download | u-boot-2f07a9a6d1abd1eeb283a21a8d718dc9628429a4.zip u-boot-2f07a9a6d1abd1eeb283a21a8d718dc9628429a4.tar.gz u-boot-2f07a9a6d1abd1eeb283a21a8d718dc9628429a4.tar.bz2 |
Merge branch 'master' of git://git.denx.de/u-boot-sunxi
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/pwm/sunxi_pwm.c | 32 | ||||
-rw-r--r-- | drivers/video/sunxi/sunxi_display.c | 2 |
2 files changed, 20 insertions, 14 deletions
diff --git a/drivers/pwm/sunxi_pwm.c b/drivers/pwm/sunxi_pwm.c index 3c7dffd..8a55e4f 100644 --- a/drivers/pwm/sunxi_pwm.c +++ b/drivers/pwm/sunxi_pwm.c @@ -67,49 +67,55 @@ static int sunxi_pwm_set_config(struct udevice *dev, uint channel, { struct sunxi_pwm_priv *priv = dev_get_priv(dev); struct sunxi_pwm *regs = priv->regs; - int prescaler; - u32 v, period = 0, duty; - u64 scaled_freq = 0; + int best_prescaler = 0; + u32 v, best_period = 0, duty; + u64 best_scaled_freq = 0; const u32 nsecs_per_sec = 1000000000U; debug("%s: period_ns=%u, duty_ns=%u\n", __func__, period_ns, duty_ns); - for (prescaler = 0; prescaler < SUNXI_PWM_CTRL_PRESCALE0_MASK; + for (int prescaler = 0; prescaler <= SUNXI_PWM_CTRL_PRESCALE0_MASK; prescaler++) { + u32 period = 0; + u64 scaled_freq = 0; if (!prescaler_table[prescaler]) continue; scaled_freq = lldiv(OSC_24MHZ, prescaler_table[prescaler]); period = lldiv(scaled_freq * period_ns, nsecs_per_sec); - if (period - 1 <= SUNXI_PWM_CH0_PERIOD_MAX) - break; + if ((period - 1 <= SUNXI_PWM_CH0_PERIOD_MAX) && + best_period < period) { + best_period = period; + best_scaled_freq = scaled_freq; + best_prescaler = prescaler; + } } - if (period - 1 > SUNXI_PWM_CH0_PERIOD_MAX) { + if (best_period - 1 > SUNXI_PWM_CH0_PERIOD_MAX) { debug("%s: failed to find prescaler value\n", __func__); return -EINVAL; } - duty = lldiv(scaled_freq * duty_ns, nsecs_per_sec); + duty = lldiv(best_scaled_freq * duty_ns, nsecs_per_sec); - if (priv->prescaler != prescaler) { + if (priv->prescaler != best_prescaler) { /* Mask clock to update prescaler */ v = readl(®s->ctrl); v &= ~SUNXI_PWM_CTRL_CLK_GATE; writel(v, ®s->ctrl); v &= ~SUNXI_PWM_CTRL_PRESCALE0_MASK; - v |= (priv->prescaler & SUNXI_PWM_CTRL_PRESCALE0_MASK); + v |= (best_prescaler & SUNXI_PWM_CTRL_PRESCALE0_MASK); writel(v, ®s->ctrl); v |= SUNXI_PWM_CTRL_CLK_GATE; writel(v, ®s->ctrl); - priv->prescaler = prescaler; + priv->prescaler = best_prescaler; } - writel(SUNXI_PWM_CH0_PERIOD_PRD(period) | + writel(SUNXI_PWM_CH0_PERIOD_PRD(best_period) | SUNXI_PWM_CH0_PERIOD_DUTY(duty), ®s->ch0_period); debug("%s: prescaler: %d, period: %d, duty: %d\n", __func__, priv->prescaler, - period, duty); + best_period, duty); return 0; } diff --git a/drivers/video/sunxi/sunxi_display.c b/drivers/video/sunxi/sunxi_display.c index 5c8f88c..6dd9bec 100644 --- a/drivers/video/sunxi/sunxi_display.c +++ b/drivers/video/sunxi/sunxi_display.c @@ -460,7 +460,7 @@ static void sunxi_composer_init(void) setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_ENABLE); } -static u32 sunxi_rgb2yuv_coef[12] = { +static const u32 sunxi_rgb2yuv_coef[12] = { 0x00000107, 0x00000204, 0x00000064, 0x00000108, 0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808, 0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808 |