Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca4866d7 authored by Kiran Gunda's avatar Kiran Gunda Committed by Gerrit - the friendly Code Review server
Browse files

leds: qpnp-flash: Introduce a "qpnp_flash_register_led_prepare"



Currently legacy "qpnp-flash-v2" and "qti-flash" drivers exposes an API
which needs to be called by the client drivers. The name of the APIs
are different in both flash drivers and both the drivers need to be
enabled in a single defconfig. To keep the client interface un-changed
introduce a function to which the individual flash drivers can register
their exposed APIs. Using this mechanism clients can use a common API
irrespective of the flash driver in use for that specific hardware.

Change-Id: I1ded3d4d9013c6f7f56e0a8952f4b45d20b07326
Signed-off-by: default avatarKiran Gunda <kgunda@codeaurora.org>
parent c49400a9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ obj-$(CONFIG_LEDS_LM3642) += leds-lm3642.o
obj-$(CONFIG_LEDS_MIKROTIK_RB532)	+= leds-rb532.o
obj-$(CONFIG_LEDS_S3C24XX)		+= leds-s3c24xx.o
obj-$(CONFIG_LEDS_NET48XX)		+= leds-net48xx.o
obj-$(CONFIG_LEDS_QTI_FLASH)		+= leds-qti-flash.o
obj-$(CONFIG_LEDS_QTI_FLASH)		+= leds-qti-flash.o leds-qpnp-flash-common.o
obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
obj-$(CONFIG_LEDS_COBALT_QUBE)		+= leds-cobalt-qube.o
obj-$(CONFIG_LEDS_COBALT_RAQ)		+= leds-cobalt-raq.o
@@ -80,7 +80,7 @@ obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o
obj-$(CONFIG_LEDS_SC27XX_BLTC)		+= leds-sc27xx-bltc.o
obj-$(CONFIG_LEDS_LM3601X)		+= leds-lm3601x.o
obj-$(CONFIG_LEDS_QTI_TRI_LED)		+= leds-qti-tri-led.o
obj-$(CONFIG_LEDS_QPNP_FLASH_V2)        += leds-qpnp-flash-v2.o
obj-$(CONFIG_LEDS_QPNP_FLASH_V2)        += leds-qpnp-flash-v2.o leds-qpnp-flash-common.o
obj-$(CONFIG_LEDS_QPNP_VIBRATOR_LDO)	+= leds-qpnp-vibrator-ldo.o

# LED SPI Drivers
+48 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
 */

#include "leds.h"

struct flash_data {
	struct list_head link;
	struct device *dev;
	int (*func)(struct led_trigger *trig, int options,
					int *max_current);
};

static LIST_HEAD(flash_common_data);

int qpnp_flash_register_led_prepare(struct device *dev, void *data)
{
	struct flash_data *flash_data;

	flash_data = devm_kzalloc(dev, sizeof(struct flash_data),
						GFP_KERNEL);
	if (!flash_data)
		return -ENOMEM;

	flash_data->dev = dev;
	flash_data->func = data;

	list_add(&flash_data->link, &flash_common_data);

	return 0;
}

int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
					int *max_current)
{
	struct flash_data *flash_data;
	struct led_classdev *led_cdev;
	int rc = -ENODEV;

	led_cdev = trigger_to_lcdev(trig);
	list_for_each_entry(flash_data, &flash_common_data, link) {
		if (led_cdev->dev->parent == flash_data->dev)
			rc = flash_data->func(trig, options, max_current);
	}

	return rc;
}
+9 −2
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt)	"flashv2: %s: " fmt, __func__
@@ -1762,7 +1762,7 @@ static int qpnp_flash_led_regulator_control(struct led_classdev *led_cdev,
	return 0;
}

int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
static int qpnp_flash_leds_prepare(struct led_trigger *trig, int options,
					int *max_current)
{
	struct led_classdev *led_cdev;
@@ -3116,6 +3116,13 @@ static int qpnp_flash_led_probe(struct platform_device *pdev)
		}
	}

	rc = qpnp_flash_register_led_prepare(&pdev->dev,
					     qpnp_flash_leds_prepare);
	if (rc < 0) {
		pr_err("Failed to register flash_led_prepare, rc=%d\n", rc);
		goto sysfs_fail;
	}

	dev_set_drvdata(&pdev->dev, led);

	return 0;
+6 −0
Original line number Diff line number Diff line
@@ -1205,6 +1205,12 @@ static int qti_flash_led_probe(struct platform_device *pdev)
		return rc;
	}

	rc = qpnp_flash_register_led_prepare(&pdev->dev, qti_flash_led_prepare);
	if (rc < 0) {
		pr_err("Failed to register flash_led_prepare, rc=%d\n", rc);
		return rc;
	}

	dev_set_drvdata(&pdev->dev, led);

	return 0;
+5 −3
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
 */

#ifndef __LEDS_QPNP_FLASH_H
@@ -15,14 +15,16 @@

#define FLASH_LED_PREPARE_OPTIONS_MASK	GENMASK(3, 0)

#ifdef CONFIG_LEDS_QPNP_FLASH_V2
int qpnp_flash_register_led_prepare(struct device *dev, void *data);

#if (defined CONFIG_LEDS_QTI_FLASH || defined CONFIG_LEDS_QPNP_FLASH_V2)
int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
					int *max_current);
#else
static inline int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
					int *max_current)
{
	return -EINVAL;
	return -ENODEV;
}
#endif

Loading