From: guiming zhuo <gmzhuo@gbsoft.localdomain>
Subject: [PATCH] ezx/funlight

add funlight led driver for ezx

Signed-off-by: guiming zhuo <gmzhuo@gbsoft.localdomain>

---
 drivers/leds/Kconfig          |    7 +++
 drivers/leds/Makefile         |    1 +
 drivers/leds/leds-funlight.c  |  102 +++++++++++++++++++++++++++++++++++++++++
 include/linux/leds-funlight.h |    9 ++++
 4 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 65ab1e1..2fb964c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -177,6 +177,13 @@ config LEDS_PCAP
 	help
 	  This option enables support for the led controller on PCAP2.
 
+config LEDS_FUNLIGHT
+	tristate "LED Support for funlight"
+	depends on LEDS_CLASS && I2C
+	help
+	  This option enables support for the led controller on funlight.
+
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index d172739..39a860e 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_LEDS_DA903X)		+= leds-da903x.o
 obj-$(CONFIG_LEDS_HP_DISK)		+= leds-hp-disk.o
 obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
 obj-$(CONFIG_LEDS_PCAP)			+= leds-pcap.o
+obj-$(CONFIG_LEDS_FUNLIGHT)		+= leds-funlight.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
diff --git a/drivers/leds/leds-funlight.c b/drivers/leds/leds-funlight.c
new file mode 100644
index 0000000..9825c05
--- /dev/null
+++ b/drivers/leds/leds-funlight.c
@@ -0,0 +1,102 @@
+/*
+ * funlight driver for EZX Phones
+ *
+ * Copyright (C) 2009 GuiMing zhuo <gmzhuo@gmail.com>
+ *
+ * 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/i2c.h>
+#include <linux/platform_device.h>
+
+static struct i2c_client *funlight_i2c_client = 0;
+static const struct i2c_device_id funlight_id[] = {
+	{ "funlight-eoc", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, funlight_id);
+
+int funlight_reg_read(char reg, unsigned int *val)
+{
+	char value[EOC_REG_DATA_SIZE];
+
+	struct i2c_msg msgs[2] = {
+		{ funlight_i2c_client->addr, 0, EOC_REG_ADDR_SIZE, &reg },
+		{ funlight_i2c_client->addr, I2C_M_RD, EOC_REG_DATA_SIZE, value },
+	};
+	if (funlight_transfer(funlight_i2c_client->adapter, msgs, 2) != 2)
+		return -EIO;
+	*val = (value[2]);
+	*val |= (value[1] << 8);
+	*val |= (value[0] << 16);
+
+	printk(KERN_INFO "FUNLIGHT: read %d: %08x\n", reg, *val);
+	return 0;
+}
+
+int funlight_reg_write(char reg, unsigned int val)
+{
+	char value[EOC_REG_ADDR_SIZE + EOC_REG_DATA_SIZE];
+
+	value[0] = reg;
+	value[1] = (char)(val >> 16);
+	value[2] = (char)(val >> 8);
+	value[3] = (char)val;
+	printk(KERN_INFO "FUNLIGHT: write %d: %08x\n", reg, val);
+	if(i2c_master_send(funlight_i2c_client, value, EOC_REG_ADDR_SIZE +
+		EOC_REG_DATA_SIZE) != (EOC_REG_ADDR_SIZE + EOC_REG_DATA_SIZE))
+		return -EIO;
+	return 0;
+}
+
+static int __devinit funlight_probe(struct i2c_client *client,
+				const struct i2c_device_id *id)
+{
+	int ret = 0;
+	struct funlight_platform_data *fdata = client->dev.platform_data;
+	if (!fdata)
+		return -ENODEV;
+	
+	if (fdata->init)
+		fdata->init();
+	funlight_i2c_client = client;
+	
+	return ret;
+}
+
+static int __devexit funlight_remove(struct i2c_client *client)
+{
+	funlight_i2c_client = 0;
+	return 0;
+}
+
+static struct i2c_driver eoc_driver = {
+	.driver = {
+		.name = "ezx-funlight",
+		.owner = THIS_MODULE,
+	},
+	.probe = funlight_probe,
+	.remove = __devexit_p(funlight_remove),
+	.id_table = funlight_id,
+};
+
+static int __init funlight_init(void)
+{
+	return i2c_add_driver(&funlight_driver);
+}
+
+static void __exit eoc_exit(void)
+{
+	i2c_del_driver(&funlight_driver);
+}
+
+MODULE_AUTHOR("GuiMing zhuo <gmzhuo@gmail.com>");
+MODULE_DESCRIPTION("ezx funlight driver");
+MODULE_LICENSE("GPL");
+
+module_init(funlight_init);
+module_exit(funlight_exit);
diff --git a/include/linux/leds-funlight.h b/include/linux/leds-funlight.h
new file mode 100644
index 0000000..1954fa4
--- /dev/null
+++ b/include/linux/leds-funlight.h
@@ -0,0 +1,9 @@
+#ifndef _LEDS_FUNLIGHT_H
+#define _LEDS_FUNLIGHT_H
+int funlight_reg_read(char reg, unsigned int *val);
+int funlight_reg_write(char reg, unsigned int val);
+struct funlight_platform_data {
+	void (*init) (void);	/* board specific init */
+};
+
+#endif
\ No newline at end of file
-- 
tg: (75208ae..) ezx/funlight (depends on: ezx/pcap_leds)

