r3137 - trunk/src/target/kernel/patches

laforge at sita.openmoko.org laforge at sita.openmoko.org
Tue Oct 9 19:30:22 CEST 2007


Author: laforge
Date: 2007-10-09 19:30:14 +0200 (Tue, 09 Oct 2007)
New Revision: 3137

Modified:
   trunk/src/target/kernel/patches/gta01-backlight.patch
   trunk/src/target/kernel/patches/gta01-vibrator.patch
Log:
Modify GTA01 vibrator and backlight driver to work on top of new s3c2410 generic pwm code
WARNING: this is untested and mainly just committed so shoragan can resolve
conflicts with his 2.6.23 work.  

If you're bumping OE's srcrev for the kernel beyond this commit, please make sure that
the vibrator and backlight control has been tested on GTA01Bv4!


Modified: trunk/src/target/kernel/patches/gta01-backlight.patch
===================================================================
--- trunk/src/target/kernel/patches/gta01-backlight.patch	2007-10-09 17:26:37 UTC (rev 3136)
+++ trunk/src/target/kernel/patches/gta01-backlight.patch	2007-10-09 17:30:14 UTC (rev 3137)
@@ -1,9 +1,9 @@
 This is a backlight driver for FIC's Neo1973 Phone (codename GTA01)
 
-Index: linux-2.6.21.3-moko/drivers/video/backlight/Kconfig
+Index: linux-2.6.22.5-moko/drivers/video/backlight/Kconfig
 ===================================================================
---- linux-2.6.21.3-moko.orig/drivers/video/backlight/Kconfig
-+++ linux-2.6.21.3-moko/drivers/video/backlight/Kconfig
+--- linux-2.6.22.5-moko.orig/drivers/video/backlight/Kconfig
++++ linux-2.6.22.5-moko/drivers/video/backlight/Kconfig
 @@ -48,6 +48,14 @@
  	  If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to
  	  enable the LCD/backlight driver.
@@ -19,10 +19,10 @@
  config BACKLIGHT_HP680
  	tristate "HP Jornada 680 Backlight Driver"
  	depends on BACKLIGHT_CLASS_DEVICE && SH_HP6XX
-Index: linux-2.6.21.3-moko/drivers/video/backlight/Makefile
+Index: linux-2.6.22.5-moko/drivers/video/backlight/Makefile
 ===================================================================
---- linux-2.6.21.3-moko.orig/drivers/video/backlight/Makefile
-+++ linux-2.6.21.3-moko/drivers/video/backlight/Makefile
+--- linux-2.6.22.5-moko.orig/drivers/video/backlight/Makefile
++++ linux-2.6.22.5-moko/drivers/video/backlight/Makefile
 @@ -3,6 +3,7 @@
  obj-$(CONFIG_LCD_CLASS_DEVICE)     += lcd.o
  obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
@@ -31,11 +31,11 @@
  obj-$(CONFIG_BACKLIGHT_HP680)	+= hp680_bl.o
  obj-$(CONFIG_BACKLIGHT_LOCOMO)	+= locomolcd.o
  obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
-Index: linux-2.6.21.3-moko/drivers/video/backlight/gta01_bl.c
+Index: linux-2.6.22.5-moko/drivers/video/backlight/gta01_bl.c
 ===================================================================
 --- /dev/null
-+++ linux-2.6.21.3-moko/drivers/video/backlight/gta01_bl.c
-@@ -0,0 +1,288 @@
++++ linux-2.6.22.5-moko/drivers/video/backlight/gta01_bl.c
+@@ -0,0 +1,249 @@
 +/*
 + *  Backlight Driver for FIC GTA01 (Neo1973) GSM Phone
 + *
@@ -59,7 +59,8 @@
 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 + * MA 02111-1307 USA
 + *
-+ * TODO: implement PWM, instead of simple on/off switching
++ * Javi Roman <javiroman at kernel-labs.org>:
++ * 	implement PWM, instead of simple on/off switching
 + *
 + */
 +
@@ -75,6 +76,7 @@
 +#include <asm/arch/hardware.h>
 +#include <asm/arch/regs-timer.h>
 +#include <asm/arch/gta01.h>
++#include <asm/arch/pwm.h>
 +
 +static struct backlight_properties gta01bl_prop;
 +static struct backlight_device *gta01_backlight_device;
@@ -86,6 +88,7 @@
 +	int intensity;
 +	struct mutex mutex;
 +	struct clk *clk;
++	struct s3c2410_pwm_t *pwm;
 +};
 +
 +static struct gta01bl_data gta01bl;
@@ -126,61 +129,28 @@
 +		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(&gta01bl.mutex);
 +
 +	gta01bl.intensity = intensity;
-+
 +	return 0;
 +}
 +
 +static void gta01bl_init_hw(void)
 +{
-+	unsigned long tcon, tcfg0, tcfg1, tcnt, pclk;
++	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;
 +
-+	pclk = clk_get_rate(gta01bl.clk);
++	s3c2410_pwm_enable(gta01bl.pwm);
++	s3c2410_pwm_start(gta01bl.pwm);
 +
-+	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);
-+
-+	tcnt = (pclk / 32) / GTA01BL_FREQ;
-+	tcnt--;
-+
-+	__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
@@ -246,12 +216,9 @@
 +	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);
++	if (!(gta01bl.pwm = s3c2410_pwm_alloc()))
++		return -ENOMEM;
 +
-+	clk_enable(gta01bl.clk);
-+
 +	gta01bl_init_hw();
 +#endif
 +	mutex_init(&gta01bl.mutex);
@@ -278,15 +245,9 @@
 +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(&gta01bl.mutex);

Modified: trunk/src/target/kernel/patches/gta01-vibrator.patch
===================================================================
--- trunk/src/target/kernel/patches/gta01-vibrator.patch	2007-10-09 17:26:37 UTC (rev 3136)
+++ trunk/src/target/kernel/patches/gta01-vibrator.patch	2007-10-09 17:30:14 UTC (rev 3137)
@@ -2,11 +2,11 @@
 uses the existing LED class driver framework, since there's a lot of
 similarity between the LED and the vibrator function.
 
-Index: linux-2.6.21-moko/drivers/leds/leds-gta01.c
+Index: linux-2.6.22.5-moko/drivers/leds/leds-gta01.c
 ===================================================================
 --- /dev/null
-+++ linux-2.6.21-moko/drivers/leds/leds-gta01.c
-@@ -0,0 +1,133 @@
++++ linux-2.6.22.5-moko/drivers/leds/leds-gta01.c
+@@ -0,0 +1,187 @@
 +/*
 + * LED driver for the FIC GTA01 (Neo1973) GSM Phone Vibrator
 + *
@@ -18,7 +18,8 @@
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + *
-+ * TODO: Implement PWM support for GTA01Bv4 and later
++ * Javi Roman <javiroman at kernel-labs.org>:
++ * 	Implement PWM support for GTA01Bv4 and later
 + */
 +
 +#include <linux/kernel.h>
@@ -27,13 +28,18 @@
 +#include <linux/leds.h>
 +#include <asm/hardware.h>
 +#include <asm/mach-types.h>
++#include <asm/arch/pwm.h>
 +#include <asm/arch/gta01.h>
 +
++#define COUNTER 256
++
 +struct gta01_vib_priv
 +{
-+	struct led_classdev	cdev;
++	struct led_classdev cdev;
 +	unsigned int gpio;
++	struct mutex mutex;
 +	unsigned int has_pwm;
++	struct s3c2410_pwm_t *pwm;
 +};
 +
 +static inline struct gta01_vib_priv *pdev_to_vpriv(struct platform_device *dev)
@@ -46,14 +52,28 @@
 +	return dev_get_drvdata(led_cdev->class_dev->dev);
 +}
 +
-+static void gta01vib_vib_set(struct led_classdev *led_cdev, enum led_brightness value)
++static void gta01vib_vib_set(struct led_classdev *led_cdev,
++		enum led_brightness value)
 +{
 +	struct gta01_vib_priv *vp = to_vpriv(led_cdev);
 +
-+	if (value)
-+		s3c2410_gpio_setpin(vp->gpio, 1);
-+	else
-+		s3c2410_gpio_setpin(vp->gpio, 0);
++	/*
++ 	 * value == 255 -> 99% duty cycle (full power)
++ 	 * value == 128 -> 50% duty cycle (medium power)
++ 	 * value == 0 -> 0% duty cycle (zero power)
++ 	 */
++ 	mutex_lock(&vp->mutex);
++	if (vp->has_pwm) {
++			s3c2410_pwm_duty_cycle(value, vp->pwm);
++			s3c2410_gpio_cfgpin(vp->gpio, S3C2410_GPB3_TOUT3);
++	} else {
++		if (value)
++			s3c2410_gpio_setpin(vp->gpio, 1);
++		else
++			s3c2410_gpio_setpin(vp->gpio, 0);
++	}
++
++	mutex_unlock(&vp->mutex);
 +}
 +
 +static struct led_classdev gta01_vib_led = {
@@ -75,8 +95,24 @@
 +}
 +#endif
 +
-+static int gta01vib_probe(struct platform_device *pdev)
++static void gta01vib_init_hw(struct platform_device *pdev)
 +{
++	struct gta01_vib_priv *vp = pdev_to_vpriv(pdev);
++
++	vp->pwm->timerid= PWM3;
++	vp->pwm->prescaler = 0x0000;
++	vp->pwm->divider = S3C2410_TCFG1_MUX3_DIV8;
++	vp->pwm->counter = COUNTER;
++	vp->pwm->comparer = COUNTER;
++
++	s3c2410_pwm_enable(vp->pwm);
++	s3c2410_pwm_start(vp->pwm);
++
++	return;
++}
++
++static int __init gta01vib_probe(struct platform_device *pdev)
++{
 +	struct gta01_vib_priv *vp;
 +	struct resource *r;
 +
@@ -95,9 +131,22 @@
 +
 +	vp->gpio = r->start;
 +
-+	if (vp->gpio == S3C2410_GPB3)
++	/* TOUT3 */
++	if (vp->gpio == S3C2410_GPB3) {
 +		vp->has_pwm = 1;
 +
++		vp->pwm = s3c2410_pwm_alloc();
++		if (!vp->pwm) {
++			dev_err(&pdev->dev, "PWM allocation failed\n");
++			kfree(vp);
++			return -ENOMEM;
++		}
++
++		gta01vib_init_hw(pdev);
++	}
++
++	mutex_init(&vp->mutex);
++
 +	return led_classdev_register(&pdev->dev, &gta01_vib_led);
 +}
 +
@@ -105,10 +154,15 @@
 +{
 +	struct gta01_vib_priv *vp = pdev_to_vpriv(pdev);
 +
++	if (vp->has_pwm)
++		s3c2410_pwm_disable(vp->pwm);
++
 +	led_classdev_unregister(&gta01_vib_led);
 +	platform_set_drvdata(pdev, NULL);
 +	kfree(vp);
 +
++	mutex_destroy(&vp->mutex);
++
 +	return 0;
 +}
 +
@@ -140,12 +194,21 @@
 +MODULE_AUTHOR("Harald Welte <laforge at openmoko.org>");
 +MODULE_DESCRIPTION("FIC GTA01 Vibrator driver");
 +MODULE_LICENSE("GPL");
-Index: linux-2.6.21-moko/drivers/leds/Kconfig
+Index: linux-2.6.22.5-moko/drivers/leds/Kconfig
 ===================================================================
---- linux-2.6.21-moko.orig/drivers/leds/Kconfig
-+++ linux-2.6.21-moko/drivers/leds/Kconfig
-@@ -94,6 +94,12 @@
+--- linux-2.6.22.5-moko.orig/drivers/leds/Kconfig
++++ linux-2.6.22.5-moko/drivers/leds/Kconfig
+@@ -59,7 +59,7 @@
+ 
+ config LEDS_S3C24XX
+ 	tristate "LED Support for Samsung S3C24XX GPIO LEDs"
+-	depends on LEDS_CLASS && ARCH_S3C2410
++	depends on LEDS_CLASS && ARCH_S3C2410 && S3C2410_PWM
  	help
+ 	  This option enables support for LEDs connected to GPIO lines
+ 	  on Samsung S3C24XX series CPUs, such as the S3C2410 and S3C2440.
+@@ -95,6 +95,12 @@
+ 	help
  	  This option enables support for the front LED on Cobalt Server
  
 +config LEDS_GTA01
@@ -157,10 +220,10 @@
  comment "LED Triggers"
  
  config LEDS_TRIGGERS
-Index: linux-2.6.21-moko/drivers/leds/Makefile
+Index: linux-2.6.22.5-moko/drivers/leds/Makefile
 ===================================================================
---- linux-2.6.21-moko.orig/drivers/leds/Makefile
-+++ linux-2.6.21-moko/drivers/leds/Makefile
+--- linux-2.6.22.5-moko.orig/drivers/leds/Makefile
++++ linux-2.6.22.5-moko/drivers/leds/Makefile
 @@ -16,6 +16,7 @@
  obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
  obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o





More information about the commitlog mailing list