Skip to contentSkip to conversation

leds: leds-mc13783: Add MC34708 LED support

PATCH New Alexander Shiyan 1 participant 4 messages Feb 1, 2014

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

PATCH v3 1/5 leds: leds-mc13783: Add MC34708 LED support

This patch adds support for two LEDs on MC34708 PMIC.

---
 drivers/leds/Kconfig        |  2 +-
 drivers/leds/leds-mc13783.c | 98 ++++++++++++++++++++++-----------------------
 include/linux/mfd/mc13xxx.h |  6 +++
 3 files changed, 55 insertions(+), 51 deletions(-)
drivers/leds/Kconfig +1 -1
index 6e3ca59..9c719fd 100644
@@ -413,7 +413,7 @@ config LEDS_MC13783
 	depends on MFD_MC13XXX
 	help
 	  This option enable support for on-chip LED drivers found
-	  on Freescale Semiconductor MC13783/MC13892 PMIC.
+	  on Freescale Semiconductor MC13783/MC13892/MC34708 PMIC.
 
 config LEDS_NS2
 	tristate "LED support for Network Space v2 GPIO LEDs"
drivers/leds/leds-mc13783.c +48 -50

242 lines not on this page · raw message

include/linux/mfd/mc13xxx.h +6 -0
index ac39d91..a326c85 100644
@@ -104,6 +104,9 @@ enum {
 	MC13892_LED_R,
 	MC13892_LED_G,
 	MC13892_LED_B,
+	/* MC34708 LED IDs */
+	MC34708_LED_R,
+	MC34708_LED_G,
 };
 
 struct mc13xxx_led_platform_data {
@@ -163,6 +166,9 @@ struct mc13xxx_leds_platform_data {
 #define MC13892_LED_C2_CURRENT_G(x)	(((x) & 0x7) << 21)
 /* MC13892 LED Control 3 */
 #define MC13892_LED_C3_CURRENT_B(x)	(((x) & 0x7) << 9)
+/* MC34708 LED Control 0 */
+#define MC34708_LED_C0_CURRENT_R(x)	(((x) & 0x3) << 9)
+#define MC34708_LED_C0_CURRENT_G(x)	(((x) & 0x3) << 21)
 	u32 led_control[MAX_LED_CONTROL_REGS];
 };
 
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH v3 2/5 leds: leds-mc13783: Use LED core PM functions

---
 drivers/leds/leds-mc13783.c | 1 +
 1 file changed, 1 insertion(+)
drivers/leds/leds-mc13783.c +1 -0
index 5534002..c8bd8a8 100644
@@ -183,6 +183,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)
 		leds->led[i].leds = leds;
 		leds->led[i].cdev.name = name;
 		leds->led[i].cdev.default_trigger = trig;
+		leds->led[i].cdev.flags = LED_CORE_SUSPENDRESUME;
 		leds->led[i].cdev.brightness_set = mc13xxx_led_set;
 		leds->led[i].cdev.brightness = LED_OFF;
 
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH v3 3/5 leds: leds-mc13783: Use proper "max_brightness" value fo LEDs

In reply to Alexander Shiyan

Instead of using maximum value of 255 and shift it to appropriate LED duty cycle, this patch introduce a helper to use proper maximum value for each LED.

---
 drivers/leds/leds-mc13783.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/leds/leds-mc13783.c +14 -13
index c8bd8a8..2360eca 100644
@@ -44,11 +44,21 @@ struct mc13xxx_leds {
 	struct mc13xxx_led		led[0];
 };
 
+static unsigned int mc13xxx_max_brightness(int id)
+{
+	if (id >= MC13783_LED_MD && id <= MC13783_LED_KP)
+		return 0x0f;
+	else if (id >= MC13783_LED_R1 && id <= MC13783_LED_B3)
+		return 0x1f;
+
+	return 0x3f;
+}
+
 static void mc13xxx_led_work(struct work_struct *work)
 {
 	struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work);
 	struct mc13xxx_leds *leds = led->leds;
-	unsigned int reg, mask, value, bank, off, shift;
+	unsigned int reg, bank, off, shift;
 
 	switch (led->id) {
 	case MC13783_LED_MD:
@@ -56,8 +66,6 @@ static void mc13xxx_led_work(struct work_struct *work)
 	case MC13783_LED_KP:
 		reg = 2;
 		shift = 9 + (led->id - MC13783_LED_MD) * 4;
-		mask = 0x0f;
-		value = led->new_brightness >> 4;
 		break;
 	case MC13783_LED_R1:
 	case MC13783_LED_G1:
@@ -72,16 +80,12 @@ static void mc13xxx_led_work(struct work_struct *work)
 		bank = off / 3;
 		reg = 3 + bank;
 		shift = (off - bank * 3) * 5 + 6;
-		value = led->new_brightness >> 3;
-		mask = 0x1f;
 		break;
 	case MC13892_LED_MD:
 	case MC13892_LED_AD:
 	case MC13892_LED_KP:
 		reg = (led->id - MC13892_LED_MD) / 2;
 		shift = 3 + (led->id - MC13892_LED_MD) * 12;
-		mask = 0x3f;
-		value = led->new_brightness >> 2;
 		break;
 	case MC13892_LED_R:
 	case MC13892_LED_G:
@@ -90,22 +94,19 @@ static void mc13xxx_led_work(struct work_struct *work)
 		bank = off / 2;
 		reg = 2 + bank;
 		shift = (off - bank * 2) * 12 + 3;
-		value = led->new_brightness >> 2;
-		mask = 0x3f;
 		break;
 	case MC34708_LED_R:
 	case MC34708_LED_G:
 		reg = 0;
 		shift = 3 + (led->id - MC34708_LED_R) * 12;
-		value = led->new_brightness >> 2;
-		mask = 0x3f;
 		break;
 	default:
 		BUG();
 	}
 
 	mc13xxx_reg_rmw(leds->master, leds->devtype->ledctrl_base + reg,
-			mask << shift, value << shift);
+			mc13xxx_max_brightness(led->id) << shift,
+			led->new_brightness << shift);
 }
 
 static void mc13xxx_led_set(struct led_classdev *led_cdev,
@@ -185,7 +186,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)
 		leds->led[i].cdev.default_trigger = trig;
 		leds->led[i].cdev.flags = LED_CORE_SUSPENDRESUME;
 		leds->led[i].cdev.brightness_set = mc13xxx_led_set;
-		leds->led[i].cdev.brightness = LED_OFF;
+		leds->led[i].cdev.max_brightness = mc13xxx_max_brightness(id);
 
 		INIT_WORK(&leds->led[i].work, mc13xxx_led_work);
 
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH v3 4/5 leds: leds-mc13783: Remove unnecessary cleaning of registers on exit

In reply to Alexander Shiyan

LED core switches each LED to OFF-state on exit, so there is no need for resetting registers.

---
 drivers/leds/leds-mc13783.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/leds/leds-mc13783.c +0 -4
index 2360eca..4cfcfde 100644
@@ -209,7 +209,6 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)
 static int mc13xxx_led_remove(struct platform_device *pdev)
 {
 	struct mc13xxx_leds *leds = platform_get_drvdata(pdev);
-	struct mc13xxx *mcdev = leds->master;
 	int i;
 
 	for (i = 0; i < leds->num_leds; i++) {
@@ -217,9 +216,6 @@ static int mc13xxx_led_remove(struct platform_device *pdev)
 		cancel_work_sync(&leds->led[i].work);
 	}
 
-	for (i = 0; i < leds->devtype->num_regs; i++)
-		mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, 0);
-
 	return 0;
 }
 
Signature · 1 line
1.8.3.2