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

Commit 187ece99 authored by ansharma's avatar ansharma
Browse files

drivers: leds-qpnp-wled: Synchronize brightness_set and worker thread



Synchronize between the brightness_set and worker thread by using
led_access mutex lock from LED class device. This makes sure that
the brightness level does not get changed when the register write
is in progress and the last set brightness level always
gets applied.

CRs-Fixed: 1044717
Change-Id: Ia0d213e36814f867ec7b2a14b432f33a62f1e6e1
Signed-off-by: default avataransharma <ansharma@codeaurora.org>
parent ee20f199
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -249,7 +249,6 @@ static int qpnp_wled_avdd_trim_adjustments[NUM_SUPPORTED_AVDD_VOLTAGES] = {
 *  @ cdev - led class device
 *  @ spmi - spmi device
 *  @ work - worker for led operation
 *  @ lock - mutex lock for exclusive access
 *  @ fdbk_op - output feedback mode
 *  @ dim_mode - dimming mode
 *  @ ovp_irq - over voltage protection irq
@@ -290,7 +289,6 @@ struct qpnp_wled {
	struct led_classdev	cdev;
	struct spmi_device *spmi;
	struct work_struct work;
	struct mutex lock;
	enum qpnp_wled_fdbk_op fdbk_op;
	enum qpnp_wled_dim_mode dim_mode;
	int ovp_irq;
@@ -490,7 +488,7 @@ static ssize_t qpnp_wled_ramp_store(struct device *dev,
	struct qpnp_wled *wled = dev_get_drvdata(dev);
	int i, rc;

	mutex_lock(&wled->lock);
	mutex_lock(&wled->cdev.led_access);

	if (!wled->cdev.brightness) {
		rc = qpnp_wled_module_en(wled, wled->ctrl_base, true);
@@ -555,7 +553,7 @@ restore_brightness:
			dev_err(&wled->spmi->dev, "wled enable failed\n");
	}
unlock_mutex:
	mutex_unlock(&wled->lock);
	mutex_unlock(&wled->cdev.led_access);

	return count;
}
@@ -801,11 +799,10 @@ static void qpnp_wled_work(struct work_struct *work)
	int level, rc;

	wled = container_of(work, struct qpnp_wled, work);
	mutex_lock(&wled->cdev.led_access);

	level = wled->cdev.brightness;

	mutex_lock(&wled->lock);

	if (level) {
		rc = qpnp_wled_set_level(wled, level);
		if (rc) {
@@ -826,7 +823,7 @@ static void qpnp_wled_work(struct work_struct *work)

	wled->prev_state = !!level;
unlock_mutex:
	mutex_unlock(&wled->lock);
	mutex_unlock(&wled->cdev.led_access);
}

/* get api registered with led classdev for wled brightness */
@@ -1743,7 +1740,6 @@ static int qpnp_wled_probe(struct spmi_device *spmi)
		return rc;
	}

	mutex_init(&wled->lock);
	INIT_WORK(&wled->work, qpnp_wled_work);
	wled->ramp_ms = QPNP_WLED_RAMP_DLY_MS;
	wled->ramp_step = 1;
@@ -1777,7 +1773,6 @@ sysfs_fail:
	led_classdev_unregister(&wled->cdev);
wled_register_fail:
	cancel_work_sync(&wled->work);
	mutex_destroy(&wled->lock);
	return rc;
}

@@ -1792,7 +1787,6 @@ static int qpnp_wled_remove(struct spmi_device *spmi)

	led_classdev_unregister(&wled->cdev);
	cancel_work_sync(&wled->work);
	mutex_destroy(&wled->lock);

	return 0;
}