This patch adds driver support for the FIC GTA01 vibrator device. The driver 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 =================================================================== --- /dev/null +++ linux-2.6.21-moko/drivers/leds/leds-gta01.c @@ -0,0 +1,133 @@ +/* + * LED driver for the FIC GTA01 (Neo1973) GSM Phone Vibrator + * + * (C) 2006-2007 by OpenMoko, Inc. + * Author: Harald Welte + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * 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 + */ + +#include +#include +#include +#include +#include +#include +#include + +struct gta01_vib_priv +{ + struct led_classdev cdev; + unsigned int gpio; + unsigned int has_pwm; +}; + +static inline struct gta01_vib_priv *pdev_to_vpriv(struct platform_device *dev) +{ + return platform_get_drvdata(dev); +} + +static inline struct gta01_vib_priv *to_vpriv(struct led_classdev *led_cdev) +{ + return dev_get_drvdata(led_cdev->class_dev->dev); +} + +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); +} + +static struct led_classdev gta01_vib_led = { + .name = "gta01:vibrator", + .brightness_set = gta01vib_vib_set, +}; + +#ifdef CONFIG_PM +static int gta01vib_suspend(struct platform_device *dev, pm_message_t state) +{ + led_classdev_suspend(>a01_vib_led); + return 0; +} + +static int gta01vib_resume(struct platform_device *dev) +{ + led_classdev_resume(>a01_vib_led); + return 0; +} +#endif + +static int gta01vib_probe(struct platform_device *pdev) +{ + struct gta01_vib_priv *vp; + struct resource *r; + + if (!machine_is_neo1973_gta01()) + return -EIO; + + r = platform_get_resource(pdev, 0, 0); + if (!r || !r->start) + return -EIO; + + vp = kzalloc(sizeof(struct gta01_vib_priv), GFP_KERNEL); + if (!vp) + return -ENOMEM; + + platform_set_drvdata(pdev, vp); + + vp->gpio = r->start; + + if (vp->gpio == S3C2410_GPB3) + vp->has_pwm = 1; + + return led_classdev_register(&pdev->dev, >a01_vib_led); +} + +static int gta01vib_remove(struct platform_device *pdev) +{ + struct gta01_vib_priv *vp = pdev_to_vpriv(pdev); + + led_classdev_unregister(>a01_vib_led); + platform_set_drvdata(pdev, NULL); + kfree(vp); + + return 0; +} + +static struct platform_driver gta01vib_driver = { + .probe = gta01vib_probe, + .remove = gta01vib_remove, +#ifdef CONFIG_PM + .suspend = gta01vib_suspend, + .resume = gta01vib_resume, +#endif + .driver = { + .name = "gta01-led", + }, +}; + +static int __init gta01vib_init(void) +{ + return platform_driver_register(>a01vib_driver); +} + +static void __exit gta01vib_exit(void) +{ + platform_driver_unregister(>a01vib_driver); +} + +module_init(gta01vib_init); +module_exit(gta01vib_exit); + +MODULE_AUTHOR("Harald Welte "); +MODULE_DESCRIPTION("FIC GTA01 Vibrator driver"); +MODULE_LICENSE("GPL"); Index: linux-2.6.21-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 @@ help This option enables support for the front LED on Cobalt Server +config LEDS_GTA01 + tristate "Vibrator Support for the FIC Neo1973 (GTA01) Vibrator" + depends on LEDS_CLASS && MACH_NEO1973_GTA01 + help + This option enables support for the Vibrator on the FIC Neo1973. + comment "LED Triggers" config LEDS_TRIGGERS Index: linux-2.6.21-moko/drivers/leds/Makefile =================================================================== --- linux-2.6.21-moko.orig/drivers/leds/Makefile +++ linux-2.6.21-moko/drivers/leds/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o obj-$(CONFIG_LEDS_H1940) += leds-h1940.o obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o +obj-$(CONFIG_LEDS_GTA01) += leds-gta01.o # LED Triggers obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o