From d4a93460004c0b0f226974f3d7824f65a70165b6 Mon Sep 17 00:00:00 2001
From: z3deverp <z3@vmsv-debian.(none)>
Date: Sat, 14 Nov 2009 01:28:40 +0900
Subject: [PATCH] sha_pon led support

---
 drivers/leds/Kconfig        |    6 +
 drivers/leds/Makefile       |    1 +
 drivers/leds/leds-sha_pon.c |  235 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 242 insertions(+), 0 deletions(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 7c8e712..586be77 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -229,6 +229,12 @@ config LEDS_BD2802
 	  This option enables support for BD2802GU RGB LED driver chips
 	  accessed via the I2C bus.
 
+config LEDS_SHA_PON
+	tristate "LED Support for Sharp WS0xxSH smartphone"
+	depends on LEDS_CLASS && PXA_SHA_PON
+	help
+	  This option enables support for Sharp WS0xxSH smartphone LEDs.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index e8cdcf7..ef5df80 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_LEDS_PCA955X)		+= leds-pca955x.o
 obj-$(CONFIG_LEDS_DA903X)		+= leds-da903x.o
 obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
 obj-$(CONFIG_LEDS_PWM)			+= leds-pwm.o
+obj-$(CONFIG_LEDS_SHA_PON)		+= leds-sha_pon.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
diff --git a/drivers/leds/leds-sha_pon.c b/drivers/leds/leds-sha_pon.c
new file mode 100644
index 0000000..de56ed2
--- /dev/null
+++ b/drivers/leds/leds-sha_pon.c
@@ -0,0 +1,235 @@
+/*
+ * LED Triggers Core
+ *
+ * Based on leds-spitz.c
+ *
+ * Author: zaki
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+
+#include <asm/mach-types.h>
+/*
+#include <mach/hardware.h>
+#include <mach/pxa-regs.h>
+*/
+#include <mach/sha_pon.h>
+
+static void sha_pon_led_anntena_red_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_ANNTENA_RED, value);
+}
+
+
+static void sha_pon_led_anntena_green_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_ANNTENA_GREEN, value);
+}
+
+
+static void sha_pon_led_anntena_mode_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_ANNTENA_MODE, value);
+}
+
+
+static void sha_pon_led_10key_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_10KEY1, value & 0x01);
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_10KEY2, value & 0x02);
+	sha_pon_gpio_bit_set(SHA_PON_O_LED_10KEY3, value & 0x04);
+}
+
+
+static void sha_pon_led_fullkey_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	if (machine_is_sha_pon007())
+		sha_pon_gpio_bit_set(SHA_PON007_O_LED_FULLKEY, value);
+}
+
+
+/*for test :-)*/
+static void sha_pon_viblator_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_VIBLATOR, value);
+}
+
+
+/*for test :-)*/
+static void sha_pon_wsim_power_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	sha_pon_gpio_bit_set(SHA_PON_O_WSIM_POWER, value);
+}
+
+
+
+static struct led_classdev sha_pon_anntena_red_led = {
+	.name			= "sha_pon:red:anntena",
+	.brightness_set		= sha_pon_led_anntena_red_set,
+};
+
+static struct led_classdev sha_pon_anntena_green_led = {
+	.name			= "sha_pon:green:anntena",
+	.brightness_set		= sha_pon_led_anntena_green_set,
+};
+
+static struct led_classdev sha_pon_anntena_mode_led = {
+	.name			= "sha_pon:mode:anntena",
+	.brightness_set		= sha_pon_led_anntena_mode_set,
+};
+
+static struct led_classdev sha_pon_10key_led = {
+	.name			= "sha_pon:orange:10keys",
+	.brightness_set		= sha_pon_led_10key_set,
+};
+
+static struct led_classdev sha_pon_fullkey_led = {
+	.name			= "sha_pon:orange:fullkeys",
+	.brightness_set		= sha_pon_led_fullkey_set,
+};
+
+static struct led_classdev sha_pon_viblator = {
+	.name			= "sha_pon:test:viblator",
+	.brightness_set		= sha_pon_viblator_set,
+};
+
+static struct led_classdev sha_pon_wsim_power = {
+	.name			= "sha_pon:test:wsim-power",
+	.brightness_set		= sha_pon_wsim_power_set,
+};
+
+
+
+#ifdef CONFIG_PM
+static int sha_pon_led_suspend(struct platform_device *dev, pm_message_t state)
+{
+	led_classdev_suspend(&sha_pon_anntena_red_led);
+	led_classdev_suspend(&sha_pon_anntena_green_led);
+	led_classdev_suspend(&sha_pon_anntena_mode_led);
+	led_classdev_suspend(&sha_pon_10key_led);
+	led_classdev_suspend(&sha_pon_fullkey_led);
+	led_classdev_suspend(&sha_pon_viblator);
+	led_classdev_suspend(&sha_pon_wsim_power);
+	return 0;
+}
+
+static int sha_pon_led_resume(struct platform_device *dev)
+{
+	led_classdev_resume(&sha_pon_anntena_red_led);
+	led_classdev_resume(&sha_pon_anntena_green_led);
+	led_classdev_resume(&sha_pon_anntena_mode_led);
+	led_classdev_resume(&sha_pon_10key_led);
+	led_classdev_resume(&sha_pon_fullkey_led);
+	led_classdev_resume(&sha_pon_viblator);
+	led_classdev_resume(&sha_pon_wsim_power);
+	return 0;
+}
+#endif
+
+static int sha_pon_led_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_anntena_red_led);
+	if (ret < 0)
+		goto done1;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_anntena_green_led);
+	if (ret < 0)
+		goto done2;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_anntena_mode_led);
+	if (ret < 0)
+		goto done3;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_10key_led);
+	if (ret < 0)
+		goto done4;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_fullkey_led);
+	if (ret < 0)
+		goto done5;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_viblator);
+	if (ret < 0)
+		goto done6;
+
+	ret = led_classdev_register(&pdev->dev, &sha_pon_wsim_power);
+	if (ret < 0)
+		goto done7;
+
+	return ret;
+
+done7:
+	led_classdev_unregister(&sha_pon_viblator);
+done6:
+	led_classdev_unregister(&sha_pon_fullkey_led);
+done5:
+	led_classdev_unregister(&sha_pon_10key_led);
+done4:
+	led_classdev_unregister(&sha_pon_anntena_mode_led);
+done3:
+	led_classdev_unregister(&sha_pon_anntena_green_led);
+done2:
+	led_classdev_unregister(&sha_pon_anntena_red_led);
+done1:
+	return ret;
+}
+
+static int sha_pon_led_remove(struct platform_device *pdev)
+{
+	led_classdev_unregister(&sha_pon_anntena_red_led);
+	led_classdev_unregister(&sha_pon_anntena_green_led);
+	led_classdev_unregister(&sha_pon_anntena_mode_led);
+	led_classdev_unregister(&sha_pon_10key_led);
+	led_classdev_unregister(&sha_pon_fullkey_led);
+	led_classdev_unregister(&sha_pon_viblator);
+	led_classdev_unregister(&sha_pon_wsim_power);
+	return 0;
+}
+
+static struct platform_driver sha_pon_led_driver = {
+	.probe		= sha_pon_led_probe,
+	.remove		= sha_pon_led_remove,
+#ifdef CONFIG_PM
+	.suspend	= sha_pon_led_suspend,
+	.resume		= sha_pon_led_resume,
+#endif
+	.driver		= {
+		.name		= "sha_pon-led",
+		.owner		= THIS_MODULE,
+	},
+};
+
+static int __init sha_pon_led_init(void)
+{
+	return platform_driver_register(&sha_pon_led_driver);
+}
+
+static void __exit sha_pon_led_exit(void)
+{
+	platform_driver_unregister(&sha_pon_led_driver);
+}
+
+module_init(sha_pon_led_init);
+module_exit(sha_pon_led_exit);
+
+MODULE_AUTHOR("zaki");
+MODULE_DESCRIPTION("sha_pon LED driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:sha_pon-led");
-- 
1.4.4.4

