From: Johannes Poehlmann <johannes.poehlmann@izt-labs.de>
To: linux-kernel@vger.kernel.org
Cc: Johannes Poehlmann <johannes.poehlmann@izt-labs.de>,
Evgeniy Polyakov <zbr@ioremap.net>,
Greg Kroah-Hartman <greg@kroah.com>
Subject: [PATCH v3 1/4] w1: ds1wm: fix and simplify register access
Date: Tue, 18 Jul 2017 13:26:50 +0200 [thread overview]
Message-ID: <1500377213-1117-2-git-send-email-johannes.poehlmann@izt-labs.de> (raw)
In-Reply-To: <1500377213-1117-1-git-send-email-johannes.poehlmann@izt-labs.de>
In-Reply-To: <6a03463f-7e93-8ee7-d56f-aaed1e2befba@izt-labs.de>
o Replace incorrect register offsett calculation by
direct configuration of bus_shift in mfd-cell.
Indirect definition of address-shift by resource size
was unobvious and should have used a binary log.
o Make endian clean, make HW-endianness configurable.
o Use ioread*, iowrite* instead of __raw_readb,__raw_writeb
to also use memory-barriers when accessing HW-registers.
We do not want reordering to happen here.
Signed-off-by: Johannes Poehlmann <johannes.poehlmann@izt-labs.de>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/masters/ds1wm.c | 84 ++++++++++++++++++++++++++++++++++++++++++----
include/linux/mfd/ds1wm.h | 9 +++++
2 files changed, 87 insertions(+), 6 deletions(-)
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index fd2e9da..6bba2fe 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -95,7 +95,8 @@ static struct {
struct ds1wm_data {
void __iomem *map;
- int bus_shift; /* # of shifts to calc register offsets */
+ unsigned int bus_shift; /* # of shifts to calc register offsets */
+ int is_hw_big_endian;
struct platform_device *pdev;
const struct mfd_cell *cell;
int irq;
@@ -115,12 +116,66 @@ struct ds1wm_data {
static inline void ds1wm_write_register(struct ds1wm_data *ds1wm_data, u32 reg,
u8 val)
{
- __raw_writeb(val, ds1wm_data->map + (reg << ds1wm_data->bus_shift));
+ if (ds1wm_data->is_hw_big_endian) {
+ switch (ds1wm_data->bus_shift) {
+ case 0:
+ iowrite8(val, ds1wm_data->map + (reg << 0));
+ break;
+ case 1:
+ iowrite16be((u16)val, ds1wm_data->map+(reg<<1));
+ break;
+ case 2:
+ iowrite32be((u32)val, ds1wm_data->map+(reg<<2));
+ break;
+ }
+ } else {
+ switch (ds1wm_data->bus_shift) {
+ case 0:
+ iowrite8(val, ds1wm_data->map + (reg << 0));
+ break;
+ case 1:
+ iowrite16((u16) val, ds1wm_data->map+(reg << 1));
+ break;
+ case 2:
+ iowrite32((u32) val, ds1wm_data->map+(reg << 2));
+ break;
+ }
+ }
}
static inline u8 ds1wm_read_register(struct ds1wm_data *ds1wm_data, u32 reg)
{
- return __raw_readb(ds1wm_data->map + (reg << ds1wm_data->bus_shift));
+
+ u32 val = 0;
+
+ if (ds1wm_data->is_hw_big_endian) {
+ switch (ds1wm_data->bus_shift) {
+ case 0:
+ val = ioread8(ds1wm_data->map + (reg << 0));
+ break;
+ case 1:
+ val = ioread16be(ds1wm_data->map + (reg << 1));
+ break;
+ case 2:
+ val = ioread32be(ds1wm_data->map + (reg << 2));
+ break;
+ }
+ } else {
+ switch (ds1wm_data->bus_shift) {
+ case 0:
+ val = ioread8(ds1wm_data->map + (reg << 0));
+ break;
+ case 1:
+ val = ioread16(ds1wm_data->map + (reg << 1));
+ break;
+ case 2:
+ val = ioread32(ds1wm_data->map + (reg << 2));
+ break;
+ }
+ }
+ dev_dbg(&ds1wm_data->pdev->dev,
+ "ds1wm_read_register reg: %d, 32 bit val:%x\n", reg, val);
+ return (u8) val;
}
@@ -473,9 +528,6 @@ static int ds1wm_probe(struct platform_device *pdev)
if (!ds1wm_data->map)
return -ENOMEM;
- /* calculate bus shift from mem resource */
- ds1wm_data->bus_shift = resource_size(res) >> 3;
-
ds1wm_data->pdev = pdev;
ds1wm_data->cell = mfd_get_cell(pdev);
if (!ds1wm_data->cell)
@@ -484,6 +536,26 @@ static int ds1wm_probe(struct platform_device *pdev)
if (!plat)
return -ENODEV;
+ /* how many bits to shift register number to get register offset */
+ if (plat->bus_shift > 2) {
+ dev_err(&ds1wm_data->pdev->dev,
+ "illegal bus shift %d, not written",
+ ds1wm_data->bus_shift);
+ return -EINVAL;
+ }
+
+ ds1wm_data->bus_shift = plat->bus_shift;
+ /* make sure resource has space for 8 registers */
+ if ((8 << ds1wm_data->bus_shift) > resource_size(res)) {
+ dev_err(&ds1wm_data->pdev->dev,
+ "memory resource size %d to small, should be %d\n",
+ (int) resource_size(res),
+ 8 << ds1wm_data->bus_shift);
+ return -EINVAL;
+ }
+
+ ds1wm_data->is_hw_big_endian = plat->is_hw_big_endian;
+
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res)
return -ENXIO;
diff --git a/include/linux/mfd/ds1wm.h b/include/linux/mfd/ds1wm.h
index 38a372a..4efd626 100644
--- a/include/linux/mfd/ds1wm.h
+++ b/include/linux/mfd/ds1wm.h
@@ -3,6 +3,7 @@
struct ds1wm_driver_data {
int active_high;
int clock_rate;
+
/* in milliseconds, the amount of time to */
/* sleep following a reset pulse. Zero */
/* should work if your bus devices recover*/
@@ -10,4 +11,12 @@ struct ds1wm_driver_data {
/* ds1wm implements the precise timings of*/
/* a reset pulse/presence detect sequence.*/
unsigned int reset_recover_delay;
+
+ /* Say 1 here for big endian Hardware */
+ /* (only relevant with bus-shift > 0 */
+ int is_hw_big_endian;
+
+ /* left shift of register number to get register address offsett */
+ /* only 0,1,2 allowed for 8,16 or 32 bit bus width respectively */
+ unsigned int bus_shift;
};
--
2.1.4
next prev parent reply other threads:[~2017-07-18 11:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-19 11:38 [PATCH V1] one wire ds1wm patch Johannes Pöhlmann
2017-06-19 14:55 ` Evgeniy Polyalkov
2017-06-19 15:24 ` Greg Kroah-Hartman
2017-06-19 17:38 ` kbuild test robot
[not found] ` <1498214835-11186-1-git-send-email-johannes.poehlmann@izt-labs.de>
2017-06-29 13:32 ` [PATCH v2 0/4] w1: ds1wm: register access patch Evgeniy Polyakov
[not found] ` <1498214835-11186-4-git-send-email-johannes.poehlmann@izt-labs.de>
2017-07-17 14:55 ` [PATCH v2 3/4] w1: ds1wm: silence interrupts on HW before claiming the interrupt Greg Kroah-Hartman
[not found] ` <1498214835-11186-5-git-send-email-johannes.poehlmann@izt-labs.de>
2017-07-17 14:55 ` [PATCH v2 4/4] w1: ds1wm: add messages to make incorporation in mfd-drivers easier Greg Kroah-Hartman
[not found] ` <1498214835-11186-2-git-send-email-johannes.poehlmann@izt-labs.de>
2017-07-17 14:55 ` [PATCH v2 1/4] w1: ds1wm: fix and simplify register access Greg Kroah-Hartman
2017-07-18 11:26 ` [PATCH v3 0/4] w1: ds1wm: register access patch Johannes Poehlmann
2017-07-18 11:26 ` Johannes Poehlmann [this message]
2017-07-18 14:15 ` [PATCH v3 1/4] w1: ds1wm: fix and simplify register access Greg Kroah-Hartman
2017-07-25 11:27 ` [PATCH v4 0/5] w1: ds1wm: register access patch Johannes Poehlmann
2017-08-27 7:19 ` Evgeniy Polyakov
2017-07-25 11:27 ` [PATCH v4 1/5] w1: ds1wm: fix register offset (bus shift) calculation Johannes Poehlmann
2017-07-25 11:27 ` [PATCH v4 2/5] w1: ds1wm: make endian clean and use standard io memory accessors Johannes Poehlmann
2017-07-25 11:27 ` [PATCH v4 3/5] w1: ds1wm: add level interrupt modes Johannes Poehlmann
2017-07-25 11:27 ` [PATCH v4 4/5] w1: ds1wm: silence interrupts on HW before claiming the interrupt Johannes Poehlmann
2017-07-25 11:27 ` [PATCH v4 5/5] w1: ds1wm: add messages to make incorporation in mfd-drivers easier Johannes Poehlmann
2017-07-18 11:26 ` [PATCH v3 2/4] w1: ds1wm: add level interrupt modes Johannes Poehlmann
2017-07-18 14:15 ` Greg Kroah-Hartman
2017-07-18 11:26 ` [PATCH v3 3/4] w1: ds1wm: silence interrupts on HW before claiming the interrupt Johannes Poehlmann
2017-07-18 14:15 ` Greg Kroah-Hartman
2017-07-18 11:26 ` [PATCH v3 4/4] w1: ds1wm: add messages to make incorporation in mfd-drivers easier Johannes Poehlmann
2017-07-18 14:16 ` Greg Kroah-Hartman
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=1500377213-1117-2-git-send-email-johannes.poehlmann@izt-labs.de \
--to=johannes.poehlmann@izt-labs.de \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=zbr@ioremap.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).