devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Olliver Schinagl <oliver@schinagl.nl>
To: Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	Richard Purdie <rpurdie@rpsys.net>,
	Jacek Anaszewski <j.anaszewski@samsung.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org, Olliver Schinagl <oliver@schinagl.nl>
Subject: [PATCH 2/6] leds: pca963x: Lock i2c r/w access
Date: Tue, 19 Apr 2016 09:40:46 +0200	[thread overview]
Message-ID: <1461051650-18824-3-git-send-email-oliver@schinagl.nl> (raw)
In-Reply-To: <1461051650-18824-1-git-send-email-oliver@schinagl.nl>

A pca963x device can have multiple leds with a single i2c channel to
access them. Some of the registers are shared between each other. To
ensure all i2c operations are atomic within an instance, we move some
mutex locks slightly around to guard these access.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
---
 drivers/leds/leds-pca963x.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 8dabf7a..1c30e92 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -99,7 +99,7 @@ struct pca963x_led;
 
 struct pca963x {
 	struct pca963x_chipdef *chipdef;
-	struct mutex mutex;
+	struct mutex mutex; /* protect i2c access to/from the pca963x chip */
 	struct i2c_client *client;
 	struct pca963x_led *leds;
 };
@@ -156,22 +156,22 @@ static void pca963x_blink(struct pca963x_led *pca963x)
 	u8 ledout_addr = pca963x->chip->chipdef->ledout_base +
 		(pca963x->led_num / 4);
 	u8 ledout;
-	u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client,
-							PCA963X_MODE2);
+	u8 mode2;
 	int shift = 2 * (pca963x->led_num % 4);
 	u8 mask = 0x3 << shift;
 
+	mutex_lock(&pca963x->chip->mutex);
 	i2c_smbus_write_byte_data(pca963x->chip->client,
 			pca963x->chip->chipdef->grppwm,	pca963x->gdc);
 
 	i2c_smbus_write_byte_data(pca963x->chip->client,
 			pca963x->chip->chipdef->grpfreq, pca963x->gfrq);
 
+	mode2 = i2c_smbus_read_byte_data(pca963x->chip->client, PCA963X_MODE2);
 	if (!(mode2 & PCA963X_MODE2_DMBLNK))
 		i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2,
 			mode2 | PCA963X_MODE2_DMBLNK);
 
-	mutex_lock(&pca963x->chip->mutex);
 	ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr);
 	if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift))
 		i2c_smbus_write_byte_data(pca963x->chip->client, ledout_addr,
-- 
2.8.0.rc3

  parent reply	other threads:[~2016-04-19  7:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19  7:40 [PATCHv1 0/6] leds: pca9653x: support inverted outputs and cleanups Olliver Schinagl
2016-04-19  7:40 ` [PATCH 1/6] leds: pca963x: Alphabetize headers Olliver Schinagl
2016-04-19  7:40 ` Olliver Schinagl [this message]
2016-04-19  7:40 ` [PATCH 3/6] leds: pca963x: Add defines and remove some magic values Olliver Schinagl
2016-04-19  8:16   ` kbuild test robot
2016-04-19  7:40 ` [PATCH 4/6] leds: pca963x: Reduce " Olliver Schinagl
2016-04-19  7:40 ` [PATCH 5/6] leds: pca963x: Inform the output that it is inverted Olliver Schinagl
2016-04-21 15:07   ` Rob Herring
2016-04-22 12:38     ` Olliver Schinagl
2016-04-22 13:09       ` Rob Herring
2016-04-22 15:44         ` Olliver Schinagl
2016-04-19  7:40 ` [PATCH 6/6] leds: pca963x: Remove whitespace and checkpatch problems Olliver Schinagl
2016-04-19  9:23 ` [PATCHv1 0/6] leds: pca9653x: support inverted outputs and cleanups Jacek Anaszewski
2016-04-19  9:39   ` Olliver Schinagl
     [not found]     ` <5715FCE8.7080106-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
2016-04-19 11:18       ` Ricardo Ribalda Delgado
2016-04-19 13:27         ` Olliver Schinagl
     [not found]           ` <57163252.5090000-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
2016-04-19 13:42             ` Ricardo Ribalda Delgado
2016-04-20  7:21               ` Olliver Schinagl
2016-04-20  8:01                 ` Ricardo Ribalda Delgado
2016-04-20  8:51                   ` Olliver Schinagl
     [not found]                     ` <5717430D.30702-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
2016-04-20  8:56                       ` Ricardo Ribalda Delgado
2016-04-20  9:06                         ` Olliver Schinagl
2016-04-20  9:17                           ` Ricardo Ribalda Delgado
2016-04-20 10:12                             ` Olliver Schinagl
2016-04-22  7:21                             ` Olliver Schinagl
2016-05-12  9:04                             ` Olliver Schinagl
2016-05-12  9:07                         ` Olliver Schinagl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461051650-18824-3-git-send-email-oliver@schinagl.nl \
    --to=oliver@schinagl.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=j.anaszewski@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=rpurdie@rpsys.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).