* [PATCH 0/3] Add support for sparc, custom set and get functions, and the GRLIB port of the controller
@ 2012-10-11 14:11 Andreas Larsson
[not found] ` <1349964679-23244-1-git-send-email-andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Larsson @ 2012-10-11 14:11 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: jacmet-OfajU3CKLf1/SzgSGea1oA, software-FkzTOoA/JUlBDgjK7y7TUQ
Hi!
This patchset adds support for sparc, for custom setreg and getreg functions,
and for the GRLIB port of the controller.
On sparc, irq is not present as an IORESOURCE in the struct platform_device
representation. Therefore, irq_of_parse_and_map() is used instead, which for
sparc simply returns an irq number.
The GRLIB port of the controller needs custom getreg and setreg functions to
allow for big endian register access and to deal with the fact that the PRELOW
and PREHIGH registers have been merged into one register.
Cheers,
Andreas
Andreas Larsson (3):
i2c-ocores: Add irq support for sparc
i2c-ocores: Add support for custom getreg and setreg functions
i2c-ocores: Add support for the GRLIB port of the controller.
drivers/i2c/busses/i2c-ocores.c | 74 +++++++++++++++++++++++++++++++++++---
1 files changed, 68 insertions(+), 6 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] i2c-ocores: Add irq support for sparc
[not found] ` <1349964679-23244-1-git-send-email-andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
@ 2012-10-11 14:11 ` Andreas Larsson
2012-10-11 14:11 ` [PATCH 2/3] i2c-ocores: Add support for custom getreg and setreg functions Andreas Larsson
2012-10-11 14:11 ` [PATCH 3/3] i2c-ocores: Add support for the GRLIB port of the controller Andreas Larsson
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Larsson @ 2012-10-11 14:11 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: jacmet-OfajU3CKLf1/SzgSGea1oA, software-FkzTOoA/JUlBDgjK7y7TUQ
There are no platform resources of type IORESOURCE_IRQ on sparc, so irq number
needs to be acquired in a different manner.
Signed-off-by: Andreas Larsson <andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
---
drivers/i2c/busses/i2c-ocores.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index bffd550..d62cb3f 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/of_i2c.h>
+#include <linux/of_irq.h>
#include <linux/log2.h>
struct ocores_i2c {
@@ -270,14 +271,22 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
struct resource *res, *res2;
int ret;
int i;
+ int irq = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (!res2)
- return -ENODEV;
+ if (res2) {
+ irq = res2->start;
+ } else {
+#ifdef CONFIG_SPARC
+ irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+#endif
+ if (!irq)
+ return -ENODEV;
+ }
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
if (!i2c)
@@ -313,8 +322,7 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
ocores_init(i2c);
init_waitqueue_head(&i2c->wait);
- ret = devm_request_irq(&pdev->dev, res2->start, ocores_isr, 0,
- pdev->name, i2c);
+ ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0, pdev->name, i2c);
if (ret) {
dev_err(&pdev->dev, "Cannot claim IRQ\n");
return ret;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] i2c-ocores: Add support for custom getreg and setreg functions
[not found] ` <1349964679-23244-1-git-send-email-andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
2012-10-11 14:11 ` [PATCH 1/3] i2c-ocores: Add irq support for sparc Andreas Larsson
@ 2012-10-11 14:11 ` Andreas Larsson
2012-10-11 14:11 ` [PATCH 3/3] i2c-ocores: Add support for the GRLIB port of the controller Andreas Larsson
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Larsson @ 2012-10-11 14:11 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: jacmet-OfajU3CKLf1/SzgSGea1oA, software-FkzTOoA/JUlBDgjK7y7TUQ
Signed-off-by: Andreas Larsson <andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
---
drivers/i2c/busses/i2c-ocores.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index d62cb3f..de93b2d 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -39,6 +39,8 @@ struct ocores_i2c {
int nmsgs;
int state; /* see STATE_ */
int clock_khz;
+ void (*setreg)(struct ocores_i2c *i2c, int reg, u8 value);
+ u8 (*getreg)(struct ocores_i2c *i2c, int reg);
};
/* registers */
@@ -72,9 +74,12 @@ struct ocores_i2c {
#define STATE_READ 3
#define STATE_ERROR 4
+
static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value)
{
- if (i2c->reg_io_width == 4)
+ if (i2c->setreg)
+ i2c->setreg(i2c, reg, value);
+ else if (i2c->reg_io_width == 4)
iowrite32(value, i2c->base + (reg << i2c->reg_shift));
else if (i2c->reg_io_width == 2)
iowrite16(value, i2c->base + (reg << i2c->reg_shift));
@@ -84,7 +89,9 @@ static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value)
static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg)
{
- if (i2c->reg_io_width == 4)
+ if (i2c->getreg)
+ return i2c->getreg(i2c, reg);
+ else if (i2c->reg_io_width == 4)
return ioread32(i2c->base + (reg << i2c->reg_shift));
else if (i2c->reg_io_width == 2)
return ioread16(i2c->base + (reg << i2c->reg_shift));
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] i2c-ocores: Add support for the GRLIB port of the controller.
[not found] ` <1349964679-23244-1-git-send-email-andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
2012-10-11 14:11 ` [PATCH 1/3] i2c-ocores: Add irq support for sparc Andreas Larsson
2012-10-11 14:11 ` [PATCH 2/3] i2c-ocores: Add support for custom getreg and setreg functions Andreas Larsson
@ 2012-10-11 14:11 ` Andreas Larsson
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Larsson @ 2012-10-11 14:11 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: jacmet-OfajU3CKLf1/SzgSGea1oA, software-FkzTOoA/JUlBDgjK7y7TUQ
The registers are 32-bit and in big endian byte order. The PRELOW and PREHIGH
registers are merged into one register. The subsequent registers have their
offset decreased accordingly.
Signed-off-by: Andreas Larsson <andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
---
drivers/i2c/busses/i2c-ocores.c | 47 +++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index de93b2d..1895e8c 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -4,6 +4,9 @@
*
* Peter Korsgaard <jacmet-OfajU3CKLf1/SzgSGea1oA@public.gmane.org>
*
+ * Modified by Andreas Larsson <andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org> to support the GRLIB port
+ * of the controller.
+ *
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of any
* kind, whether express or implied.
@@ -99,6 +102,40 @@ static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg)
return ioread8(i2c->base + (reg << i2c->reg_shift));
}
+/* Read and write functions for the GRLIB port of the controller. Registers are
+ * 32-bit big endian and the PRELOW and PREHIGH registers are merged into one
+ * register. The subsequent registers has their offset decreased accordingly. */
+static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg)
+{
+ u32 rd;
+ int rreg = reg;
+ if (reg != OCI2C_PRELOW)
+ rreg--;
+ rd = ioread32be(i2c->base + (rreg << i2c->reg_shift));
+ if (reg == OCI2C_PREHIGH)
+ return (u8)rd >> 8;
+ else
+ return (u8)rd;
+}
+
+static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value)
+{
+ u32 curr, wr;
+ int rreg = reg;
+ if (reg != OCI2C_PRELOW)
+ rreg--;
+ if (reg == OCI2C_PRELOW || reg == OCI2C_PREHIGH) {
+ curr = ioread32be(i2c->base + (rreg << i2c->reg_shift));
+ if (reg == OCI2C_PRELOW)
+ wr = (curr & 0xff00) | value;
+ else
+ wr = (((u32)value) << 8) | (curr & 0xff);
+ } else {
+ wr = value;
+ }
+ iowrite32be(wr, i2c->base + (rreg << i2c->reg_shift));
+}
+
static void ocores_process(struct ocores_i2c *i2c)
{
struct i2c_msg *msg = i2c->msg;
@@ -241,6 +278,7 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
{
struct device_node *np = pdev->dev.of_node;
u32 val;
+ const char *name;
if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) {
/* no 'reg-shift', check for deprecated 'regstep' */
@@ -265,6 +303,15 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
of_property_read_u32(pdev->dev.of_node, "reg-io-width",
&i2c->reg_io_width);
+
+ name = of_get_property(pdev->dev.of_node, "name", NULL);
+ if (name && (!strcmp(name, "GAISLER_I2CMST") ||
+ !strcmp(name, "01_028"))) {
+ dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n");
+ i2c->setreg = oc_setreg_grlib;
+ i2c->getreg = oc_getreg_grlib;
+ }
+
return 0;
}
#else
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-11 14:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-11 14:11 [PATCH 0/3] Add support for sparc, custom set and get functions, and the GRLIB port of the controller Andreas Larsson
[not found] ` <1349964679-23244-1-git-send-email-andreas-FkzTOoA/JUlBDgjK7y7TUQ@public.gmane.org>
2012-10-11 14:11 ` [PATCH 1/3] i2c-ocores: Add irq support for sparc Andreas Larsson
2012-10-11 14:11 ` [PATCH 2/3] i2c-ocores: Add support for custom getreg and setreg functions Andreas Larsson
2012-10-11 14:11 ` [PATCH 3/3] i2c-ocores: Add support for the GRLIB port of the controller Andreas Larsson
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).