Backlight driver using the new PWM API.
-Javi
diff -uprN -X dontdiff linux-2.6.22.5/drivers/video/backlight/gta01_bl.c linux-2.6.22.5.new/drivers/video/backlight/gta01_bl.c
--- linux-2.6.22.5/drivers/video/backlight/gta01_bl.c 2007-09-02 14:17:48.000000000 +0200
+++ linux-2.6.22.5.new/drivers/video/backlight/gta01_bl.c 2007-09-16 19:42:42.000000000 +0200
@@ -21,7 +21,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
- * TODO: implement PWM, instead of simple on/off switching
+ * Javi Roman <[EMAIL PROTECTED]>:
+ * implement PWM, instead of simple on/off switching
*
*/
@@ -38,6 +39,8 @@
#include <asm/arch/regs-timer.h>
#include <asm/arch/gta01.h>
+#include <asm/arch/s3c2410-pwm.h>
+
static struct backlight_properties gta01bl_prop;
static struct backlight_device *gta01_backlight_device;
static struct gta01bl_machinfo *bl_machinfo;
@@ -48,6 +51,7 @@ struct gta01bl_data {
int intensity;
struct mutex mutex;
struct clk *clk;
+ struct s3c2410_pwm_t *pwm;
};
static struct gta01bl_data gta01bl;
@@ -88,61 +92,28 @@ static int gta01bl_send_intensity(struct
s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
} else {
- __raw_writel(intensity & 0xffff, S3C2410_TCMPB(0));
+ s3c2410_pwm_duty_cycle(intensity & 0xffff, gta01bl.pwm);
s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPB0_TOUT0);
}
#endif
mutex_unlock(>a01bl.mutex);
gta01bl.intensity = intensity;
-
- return 0;
+return 0;
}
static void gta01bl_init_hw(void)
{
- unsigned long tcon, tcfg0, tcfg1, tcnt, pclk;
-
- pclk = clk_get_rate(gta01bl.clk);
-
- tcon = __raw_readl(S3C2410_TCON);
- tcfg1 = __raw_readl(S3C2410_TCFG1);
- tcfg0 = __raw_readl(S3C2410_TCFG0);
-
- tcfg1 &= ~S3C2410_TCFG1_MUX0_MASK;
- tcfg1 |= S3C2410_TCFG1_MUX0_DIV8;
-
- tcfg0 &= ~S3C2410_TCFG_PRESCALER0_MASK;
- tcfg0 |= (4 - 1);
+ gta01bl.pwm->timerid= PWM0;
+ gta01bl.pwm->prescaler = (4 - 1);
+ gta01bl.pwm->divider = S3C2410_TCFG1_MUX0_DIV8;
+ gta01bl.pwm->counter = (((gta01bl.pwm->pclk_rate) / 32) / GTA01BL_FREQ) -1;
+ gta01bl.pwm->comparer = gta01bl.pwm->counter;
- tcnt = (pclk / 32) / GTA01BL_FREQ;
- tcnt--;
+ s3c2410_pwm_enable(gta01bl.pwm);
+ s3c2410_pwm_start(gta01bl.pwm);
- __raw_writel(tcfg1, S3C2410_TCFG1);
- __raw_writel(tcfg0, S3C2410_TCFG0);
-
-#if 0
- __raw_writel(tcnt, S3C2410_TCNTB(0));
- __raw_writel(tcon, S3C2410_TCON);
- __raw_writel(tcnt, S3C2410_TCNTB(0));
-#endif
-
- /* ensure timer is stopped */
-
- tcon &= 0xffffff00;
- tcon |= S3C2410_TCON_T0RELOAD;
- tcon |= S3C2410_TCON_T0MANUALUPD;
-
- __raw_writel(tcnt, S3C2410_TCNTB(0));
- __raw_writel(tcnt, S3C2410_TCMPB(0));
- __raw_writel(tcon, S3C2410_TCON);
-
- /* start the timer */
- tcon |= S3C2410_TCON_T0START;
- tcon &= ~S3C2410_TCON_T0MANUALUPD;
- __raw_writel(tcon, S3C2410_TCON);
-
- gta01bl_prop.max_brightness = tcnt;
+ gta01bl_prop.max_brightness = gta01bl.pwm->counter;
}
#ifdef CONFIG_PM
@@ -208,11 +179,8 @@ static int __init gta01bl_probe(struct p
gta01bl_prop.max_brightness = 1;
#else
/* use s3c_device_timer0 for PWM */
- gta01bl.clk = clk_get(NULL, "timers");
- if (IS_ERR(gta01bl.clk))
- return PTR_ERR(gta01bl.clk);
-
- clk_enable(gta01bl.clk);
+ if (!(gta01bl.pwm = s3c2410_pwm_alloc()))
+ return -1;
gta01bl_init_hw();
#endif
@@ -240,15 +208,9 @@ static int __init gta01bl_probe(struct p
static int gta01bl_remove(struct platform_device *dev)
{
#ifndef GTA01_BACKLIGHT_ONOFF_ONLY
- unsigned long tcon;
- /* stop this timer */
- tcon = __raw_readl(S3C2410_TCON);
- tcon &= 0xffffff00;
- __raw_writel(tcon, S3C2410_TCON);
+ s3c2410_pwm_disable(gta01bl.pwm);
- clk_disable(gta01bl.clk);
- clk_put(gta01bl.clk);
#endif
backlight_device_unregister(gta01_backlight_device);
mutex_destroy(>a01bl.mutex);