OSDN Git Service

leds: qpnp-flash-v2: Update the flash_prepare API
authorDevesh Jhunjhunwala <deveshj@codeaurora.org>
Tue, 26 Jul 2016 23:37:28 +0000 (16:37 -0700)
committerDevesh Jhunjhunwala <deveshj@codeaurora.org>
Fri, 29 Jul 2016 18:21:23 +0000 (11:21 -0700)
Update the flash prepare API to accept a led_trigger device as an
argument. Also split the leds-qpnp-flash-v2 header file to keep the
flash_prepare API in a common header file for both legacy and v2
flash drivers.

CRs-Fixed: 1043718
Change-Id: Idb4ab086740b680e101d76d882bcfb618ac4b936
Signed-off-by: Devesh Jhunjhunwala <deveshj@codeaurora.org>
drivers/leds/leds-qpnp-flash-v2.c
drivers/leds/leds.h
include/linux/leds-qpnp-flash-v2.h
include/linux/leds-qpnp-flash.h [new file with mode: 0644]

index 0455ea6..3e5e10d 100644 (file)
@@ -23,7 +23,9 @@
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
 #include <linux/regulator/consumer.h>
+#include <linux/leds-qpnp-flash.h>
 #include <linux/leds-qpnp-flash-v2.h>
+#include "leds.h"
 
 #define        FLASH_LED_REG_INT_RT_STS(base)          (base + 0x10)
 #define        FLASH_LED_REG_SAFETY_TMR(base)          (base + 0x40)
@@ -485,13 +487,21 @@ static int qpnp_flash_led_switch_set(struct flash_switch_data *snode, bool on)
        return 0;
 }
 
-int qpnp_flash_led_prepare(struct led_classdev *led_cdev, int options)
+int qpnp_flash_led_prepare(struct led_trigger *trig, int options)
 {
-       struct flash_switch_data *snode =
-                       container_of(led_cdev, struct flash_switch_data, cdev);
-       struct qpnp_flash_led *led = dev_get_drvdata(&snode->pdev->dev);
+       struct led_classdev *led_cdev = trigger_to_lcdev(trig);
+       struct flash_switch_data *snode;
+       struct qpnp_flash_led *led;
        int rc, val = 0;
 
+       if (!led_cdev) {
+               pr_err("Invalid led_trigger provided\n");
+               return -EINVAL;
+       }
+
+       snode = container_of(led_cdev, struct flash_switch_data, cdev);
+       led = dev_get_drvdata(&snode->pdev->dev);
+
        if (!(options & (ENABLE_REGULATOR | QUERY_MAX_CURRENT))) {
                dev_err(&led->pdev->dev, "Invalid options %d\n", options);
                return -EINVAL;
index 4238fbc..61de87e 100644 (file)
@@ -44,6 +44,22 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)
        return led_cdev->brightness;
 }
 
+static inline struct led_classdev *trigger_to_lcdev(struct led_trigger *trig)
+{
+       struct led_classdev *led_cdev;
+
+       read_lock(&trig->leddev_list_lock);
+       list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) {
+               if (!strcmp(led_cdev->default_trigger, trig->name)) {
+                       read_unlock(&trig->leddev_list_lock);
+                       return led_cdev;
+               }
+       }
+
+       read_unlock(&trig->leddev_list_lock);
+       return NULL;
+}
+
 void led_init_core(struct led_classdev *led_cdev);
 void led_stop_software_blink(struct led_classdev *led_cdev);
 
index c8db3e0..1ae77e2 100644 (file)
 
 #include <linux/leds.h>
 #include <linux/notifier.h>
-#include "leds.h"
-
-#define ENABLE_REGULATOR       BIT(0)
-#define QUERY_MAX_CURRENT      BIT(1)
 
 enum flash_led_irq_type {
        LED_FAULT_IRQ = BIT(0),
@@ -32,8 +28,6 @@ enum flash_led_irq_type {
        INVALID_IRQ = BIT(8),
 };
 
-int qpnp_flash_led_prepare(struct led_classdev *led_cdev, int options);
-
 int qpnp_flash_led_register_irq_notifier(struct notifier_block *nb);
 int qpnp_flash_led_unregister_irq_notifier(struct notifier_block *nb);
 
diff --git a/include/linux/leds-qpnp-flash.h b/include/linux/leds-qpnp-flash.h
new file mode 100644 (file)
index 0000000..55867e7
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __LEDS_QPNP_FLASH_H
+#define __LEDS_QPNP_FLASH_H
+
+#include <linux/leds.h>
+
+#define ENABLE_REGULATOR       BIT(0)
+#define QUERY_MAX_CURRENT      BIT(1)
+
+int qpnp_flash_led_prepare(struct led_trigger *trig, int options);
+
+#endif