Skip to contentSkip to conversation

max77693-led driver

RFC PATCH Superseded Andrzej Hajda 1 participant 3 messages Feb 19, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover max77693-led driver

Those two patches adds max77693-led driver with device tree support. Driver is exposed to user space as a V4L2 flash subdevice. This subdevice should be registered by V4L2 driver of the camera device.

Regards
Andrzej

#1 lore raw

PATCH 1/2 max77693: added device tree support

---
 drivers/mfd/max77693.c |   40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)
drivers/mfd/max77693.c +33 -7
index cc5155e..46223da 100644
@@ -106,11 +106,30 @@ static const struct regmap_config max77693_regmap_config = {
 	.max_register = MAX77693_PMIC_REG_END,
 };
 
+static int max77693_get_platform_data(struct max77693_dev *max77693,
+				      struct device *dev)
+{
+	struct device_node *node = dev->of_node;
+	struct max77693_platform_data *pdata = dev->platform_data;
+
+	if (node) {
+		max77693->wakeup = of_property_read_bool(node, "wakeup-source");
+		return 0;
+	}
+
+	if (pdata) {
+		max77693->wakeup = pdata->wakeup;
+		return 0;
+	}
+
+	dev_err(dev, "No platform data found.\n");
+	return -EINVAL;
+}
+
 static int max77693_i2c_probe(struct i2c_client *i2c,
 			      const struct i2c_device_id *id)
 {
 	struct max77693_dev *max77693;
-	struct max77693_platform_data *pdata = i2c->dev.platform_data;
 	u8 reg_data;
 	int ret = 0;
 
@@ -119,6 +138,10 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
 	if (max77693 == NULL)
 		return -ENOMEM;
 
+	ret = max77693_get_platform_data(max77693, &i2c->dev);
+	if (ret < 0)
+		return ret;
+
 	max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config);
 	if (IS_ERR(max77693->regmap)) {
 		ret = PTR_ERR(max77693->regmap);
@@ -133,11 +156,6 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
 	max77693->irq = i2c->irq;
 	max77693->type = id->driver_data;
 
-	if (!pdata)
-		goto err_regmap;
-
-	max77693->wakeup = pdata->wakeup;
-
 	if (max77693_read_reg(max77693->regmap,
 				MAX77693_PMIC_REG_PMIC_ID2, &reg_data) < 0) {
 		dev_err(max77693->dev, "device not found on this channel\n");
@@ -177,7 +195,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
 	if (ret < 0)
 		goto err_mfd;
 
-	device_init_wakeup(max77693->dev, pdata->wakeup);
+	device_init_wakeup(max77693->dev, max77693->wakeup);
 
 	return ret;
 
@@ -233,11 +251,19 @@ static const struct dev_pm_ops max77693_pm = {
 	.resume = max77693_resume,
 };
 
+#ifdef CONFIG_OF
+static struct of_device_id max77693_dt_match[] = {
+	{.compatible = "maxim,max77693"},
+	{},
+};
+#endif
+
 static struct i2c_driver max77693_i2c_driver = {
 	.driver = {
 		   .name = "max77693",
 		   .owner = THIS_MODULE,
 		   .pm = &max77693_pm,
+		   .of_match_table = of_match_ptr(max77693_dt_match),
 	},
 	.probe = max77693_i2c_probe,
 	.remove = max77693_i2c_remove,
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/2 media: added max77693-led driver

In reply to Andrzej Hajda

The patch adds led-flash support to Maxim max77693 chipset. Device is exposed to user space as a V4L2 subdevice. It can be controlled via V4L2 controls interface. Device supports up to two leds which can work in flash and torch mode. Leds can be triggered externally or by software.

---
 Documentation/devicetree/bindings/mfd/max77693.txt |   77 +++
 drivers/media/i2c/Kconfig                          |    8 +
 drivers/media/i2c/Makefile                         |    1 +
 drivers/media/i2c/max77693-led.c                   |  651 ++++++++++++++++++++
 drivers/mfd/max77693.c                             |   55 +-
 include/linux/mfd/max77693.h                       |   33 +-
 6 files changed, 805 insertions(+), 20 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/max77693.txt
 create mode 100644 drivers/media/i2c/max77693-led.c
Documentation/devicetree/bindings/mfd/max77693.txt new file +77 -0
new file mode 100644
index 0000000..a80397c
@@ -0,0 +1,77 @@
+Maxim MAX77693 multi-function device
+
+MAX77686 is a Mulitifunction device with the following submodules:
+- PMIC,
+- Charger,
+- LED,
+- MUIC,
+- HAPTIC.
+
+It is interfaced to host controller using i2c.
+This document describes the bindings for the mfd device and the LED submodule.
+
+Required properties:
+- compatible : Must be "maxim,max77693".
+- reg : Specifies the i2c slave address of PMIC block.
+- interrupts : This i2c device has an IRQ line connected to the main SoC.
+- interrupt-parent : The parent interrupt controller.
+
+Optional properties:
+- wakeup-source : Indicates if the device can wakeup the system from the sleep
+	state.
+
+Optional node:
+- led-flash : The LED submodule device node.
+
+Required properties of "led-flash" node:
+- compatible : Must be "maxim,max77693-led"
+
+Optional properties of "led-flash" node:
+- maxim,iout : Array of four intensities in microamps of the current
+	in order: flash1, flash2, torch1, torch2.
+	Range:
+		flash - 15625 - 1000000,
+		torch - 15625 - 250000.
+- maxim,trigger : Array of flags indicating which trigger can activate given led
+	in order: flash1, flash2, torch1, torch2.
+	Possible flag values (can be combined):
+		1 - flash pin of the chip,
+		2 - torch pin of the chip,
+		4 - software via I2C command.
+- maxim,trigger-type : Array of trigger types in order: flash, torch.
+	Possible trigger types:
+		0 - Rising edge of the signal triggers the flash/torch,
+		1 - Signal level controls duration of the flash/torch.
+- maxim,timeout : Array of timeouts in microseconds after which leds are
+	turned off in order: flash, torch.
+	Range:
+		flash: 62500 - 1000000,
+		torch: 0 (no timeout) - 15728000.
+- maxim,boost-mode : Array of the flash boost modes in order: flash1, flash2.
+	Possible values:
+		0 - no boost,
+		1 - adaptive mode,
+		2 - fixed mode.
+- maxim,boost-vout : Output voltage of the boost module in milivolts.
+- maxim,low-vsys : Low input voltage level in milivolts. Flash is not fired
+	if chip estimates that system voltage could drop below this level due
+	to flash power consumption.
+
+Example:
+max77693@66 {
+	compatible = "maxim,max77693";
+	reg = <0x66>;
+	interrupt-parent = <&gpx1>;
+	interrupts = <5 0>;
+	wakeup-source;
+	led_flash: led-flash {
+		compatible = "maxim,max77693-led";
+		maxim,iout = <500000 500000 250000 250000>;
+		maxim,trigger = <5 5 6 0>;
+		maxim,trigger-type = <0 1>;
+		maxim,timeout = <500000 0>;
+		maxim,boost-mode = <1 1>;
+		maxim,boost-vout = <5000>;
+		maxim,low-vsys = <2400>;
+	};
+};
drivers/media/i2c/Kconfig +8 -0
index 7b771ba..b72d4a1 100644
@@ -522,6 +522,14 @@ config VIDEO_AS3645A
 	  This is a driver for the AS3645A and LM3555 flash controllers. It has
 	  build in control for flash, torch and indicator LEDs.
 
+config VIDEO_MAX77693_LED
+	tristate "MAX77693 led-flash driver support"
+	depends on MFD_MAX77693 && VIDEO_V4L2 && MEDIA_CONTROLLER
+	depends on MEDIA_CAMERA_SUPPORT
+	---help---
+	  This is a driver for the flash part of the MAX77693 multifunction
+	  device. It has build in control for two leds in flash and torch mode.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
drivers/media/i2c/Makefile +1 -0
index cfefd30..bfbfae6 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_VIDEO_S5K4ECGX)	+= s5k4ecgx.o
 obj-$(CONFIG_VIDEO_S5C73M3)	+= s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)	+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)	+= as3645a.o
+obj-$(CONFIG_VIDEO_MAX77693_LED) += max77693-led.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL)	+= smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X)		+= ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
drivers/media/i2c/max77693-led.c new file +651 -0

651 lines not on this page · raw message

drivers/mfd/max77693.c +36 -19

93 lines not on this page · raw message

include/linux/mfd/max77693.h +32 -1
index fe03b2d..d29d9ee 100644
@@ -40,10 +40,41 @@ struct max77693_muic_platform_data {
 	int num_init_data;
 };
 
+/* MAX77693 led flash */
+
+/* triggers */
+#define MAX77693_LED_TRIG_OFF		0
+#define MAX77693_LED_TRIG_FLASH		1
+#define MAX77693_LED_TRIG_TORCH		2
+#define MAX77693_LED_TRIG_EXT		(MAX77693_LED_TRIG_FLASH |\
+					 MAX77693_LED_TRIG_TORCH)
+#define MAX77693_LED_TRIG_SOFT		4
+
+/* trigger types */
+#define MAX77693_LED_TRIG_TYPE_EDGE	0
+#define MAX77693_LED_TRIG_TYPE_LEVEL	1
+
+/* boost modes */
+#define MAX77693_LED_BOOST_NONE		0
+#define MAX77693_LED_BOOST_ADAPTIVE	1
+#define MAX77693_LED_BOOST_FIXED	2
+
+struct max77693_led_platform_data {
+	u32 iout[4];
+	u32 trigger[4];
+	u32 trigger_type[2];
+	u32 timeout[2];
+	u32 boost_mode[2];
+	u32 boost_vout;
+	u32 low_vsys;
+};
+
+/* MAX77693 */
+
 struct max77693_platform_data {
 	int wakeup;
 
-	/* muic data */
 	struct max77693_muic_platform_data *muic_data;
+	struct max77693_led_platform_data *led_data;
 };
 #endif	/* __LINUX_MFD_MAX77693_H */
Signature · 1 line
1.7.10.4