Add support for sparc, custom set and get functions, and the GRLIB port of the controller
Subsystems (2)
cover Add support for sparc, custom set and get functions, and the GRLIB port of the controller
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(-)
A message that is not in the archive (sent off-list or not yet received): 1349964679-23244-1-git-send-email-andreas-FkzTOoA/[email protected]
PATCH 1/3 i2c-ocores: Add irq support for sparc
There are no platform resources of type IORESOURCE_IRQ on sparc, so irq number needs to be acquired in a different manner.
--- drivers/i2c/busses/i2c-ocores.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-ocores.c +12 -4
@@ -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;
Signature · 1 line
1.7.0.4
PATCH 2/3 i2c-ocores: Add support for custom getreg and setreg functions
In reply to a message not in the archive--- drivers/i2c/busses/i2c-ocores.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-ocores.c +9 -2
@@ -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));
Signature · 1 line
1.7.0.4
PATCH 3/3 i2c-ocores: Add support for the GRLIB port of the controller.
In reply to a message not in the archiveThe 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.
--- drivers/i2c/busses/i2c-ocores.c | 47 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-ocores.c +47 -0
@@ -4,6 +4,9 @@* * Peter Korsgaard <jacmet-OfajU3CKLf1/[email protected]> * +* Modified by Andreas Larsson <andreas-FkzTOoA/[email protected]> 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
Signature · 1 line
1.7.0.4