Skip to contentSkip to conversation

Add HTC PLD driver

PATCH In review Cory Maccarrone 3 participants 4 messages Dec 6, 2009 – Dec 12, 2009 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add HTC PLD driver

This change introduces a driver for the HTC PLD chip found on some smartphones, such as the HTC Wizard and HTC Herald. It works through the I2C bus and provides two main features:

* 32 general-purpose I/O pins
* Input device support for directional keypad buttons

The above phones have LCD and keyboard backlight brightness and LED controls attached to this chip, as well as some power management functions.

This driver was originally written by
Angelo Arrifano <[email protected]> of the Linwizard project.

---
 drivers/misc/Kconfig   |   11 +++
 drivers/misc/Makefile  |    1 +
 drivers/misc/htcpld.c  |  204 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/htcpld.h |   14 ++++
 4 files changed, 230 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/htcpld.c
 create mode 100644 include/linux/htcpld.h
drivers/misc/Kconfig +11 -0
index df1f86b..be6109e 100644
@@ -246,6 +246,17 @@ config EP93XX_PWM
 	  To compile this driver as a module, choose M here: the module will
 	  be called ep93xx_pwm.
 
+config HTCPLD
+	tristate "HTC Wizard/Herald CPLD"
+	depends on I2C=y
+	help
+	  If you say yes here you get support for the supposed CPLD
+	  found on omap850 HTC devices like the HTC Wizard and HTC Herald.
+	  This device controls backlight, leds, rumble and also the dpad.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called htcpld.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index f982d2e..1679bc9 100644
@@ -21,5 +21,6 @@ obj-$(CONFIG_HP_ILO)		+= hpilo.o
 obj-$(CONFIG_ISL29003)		+= isl29003.o
 obj-$(CONFIG_EP93XX_PWM)	+= ep93xx_pwm.o
 obj-$(CONFIG_C2PORT)		+= c2port/
+obj-$(CONFIG_HTCPLD)		+= htcpld.o
 obj-y				+= eeprom/
 obj-y				+= cb710/
drivers/misc/htcpld.c new file +204 -0

204 lines not on this page · raw message

include/linux/htcpld.h new file +14 -0
new file mode 100644
index 0000000..4d06336
@@ -0,0 +1,14 @@
+#ifndef __LINUX_HTCPLD_H
+#define __LINUX_HTCPLD_H
+
+struct htcpld_chip_platform_data {
+	u8 reset;
+};
+
+u8 htcpld_chip_get(u8 chip_addr);
+void htcpld_chip_set(u8 chip_addr, u8 val);
+void htcpld_chip_reset(u8 chip_addr);
+u8 htcpld_chip_cache_read(const int addr);
+
+#endif /* __LINUX_HTCPLD_H */
+
Signature · 1 line
1.6.3.3

A message that is not in the archive (sent off-list or not yet received): 1260083683-13095-1-git-send-email-darkstar6262-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 14 lines · Cory Maccarrone

This change introduces a driver for the HTC PLD chip found on some smartphones, such as the HTC Wizard and HTC Herald. It works through the I2C bus and provides two main features:

* 32 general-purpose I/O pins
* Input device support for directional keypad buttons

The above phones have LCD and keyboard backlight brightness and LED controls attached to this chip, as well as some power management functions.

This driver was originally written by
Angelo Arrifano <[email protected]> of the Linwizard project.

Quoted 6 lines
 drivers/misc/Kconfig   |   11 +++
 drivers/misc/Makefile  |    1 +
 drivers/misc/htcpld.c  |  204 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/htcpld.h |   14 ++++

A core in drivers/mfd plus drivers/gpio and drivers/input drivers for the indidivudal functions would be a more natural implementation for this.

Quoted 8 lines
drivers/misc/htcpld.c new file +8 -0
+void htcpld_chip_set(u8 chip_addr, u8 val)
+{
+	struct htcpld_chip_data *chip_data;
+
+	if (chip_addr > HTCPLD_ADDR_MAX)
+		return;
+
+	if (!htcpld_chip[chip_addr])

drivers/misc/htcpld.c line 64

Quoted 10 lines
drivers/misc/htcpld.c new file +10 -0
+		return;
+
+	chip_data = i2c_get_clientdata(htcpld_chip[chip_addr]);
+	if (!chip_data)
+		return;
+
+	i2c_smbus_read_byte_data(htcpld_chip[chip_addr],
+				(chip_data->cache = val));
+}
+EXPORT_SYMBOL_GPL(htcpld_chip_set);

I'd certainly suggest taking a look at how MFD core drivers are usually structured. Much of this code looks like it's supposed to be doing the same job as a MFD driver normally would but without the device model.

#3 lore raw
In reply to a message not in the archive

drivers/misc/Kconfig config EP93XX_PWM · line 251

Quoted 11 lines · Cory Maccarrone
drivers/misc/Kconfig +3 -0
index df1f86b..be6109e 100644
@@ -246,6 +246,17 @@ config EP93XX_PWM
 	  To compile this driver as a module, choose M here: the module will
 	  be called ep93xx_pwm.
 
+config HTCPLD
+	tristate "HTC Wizard/Herald CPLD"
+	depends on I2C=y

I'm curious why your driver wouldn't work when I2C support is modular.

Quoted 15 lines
drivers/misc/Kconfig +7 -0
+	help
+	  If you say yes here you get support for the supposed CPLD
+	  found on omap850 HTC devices like the HTC Wizard and HTC Herald.
+	  This device controls backlight, leds, rumble and also the dpad.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called htcpld.
 
(...)
drivers/misc/htcpld.c new file +0 -0
new file mode 100644
index 0000000..97a0260

drivers/misc/htcpld.c line 33

Quoted 9 lines
drivers/misc/htcpld.c new file +8 -0
@@ -0,0 +1,204 @@
(...)
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/timer.h>
+#include <linux/platform_device.h>

I fail to see why you need to include that one.

drivers/misc/htcpld.c line 38

Quoted 5 lines
drivers/misc/htcpld.c new file +5 -0
+#include <linux/i2c.h>
+
+#include <linux/htcpld.h>
+
+#define HTCPLD_ADDR_MAX 16

This define is the sure sign that your driver is badly designed. You shouldn't have to set any such arbitrary limit...

Quoted 2 lines

(...)
+static struct i2c_client *htcpld_chip[HTCPLD_ADDR_MAX];

... because you shouldn't have to rely on a global like that in the first place.

Signature · 1 line
Jean Delvare

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 11 lines · Jean Delvare

I'm curious why your driver wouldn't work when I2C support is modular.

I fail to see why you need to include that one.

This define is the sure sign that your driver is badly designed. You shouldn't have to set any such arbitrary limit...

... because you shouldn't have to rely on a global like that in the first place.

Thanks for the feedback. I've taken it back and rewrote the driver into something which I hope will be much more acceptable. I'll be posting it shortly.

- Cory