From: Peter Korsgaard <jacmet@sunsite.dk>
To: Andreas Larsson <andreas@gaisler.com>
Cc: Wolfram Sang <w.sang@pengutronix.de>,
Ben Dooks <ben-linux@fluff.org>,
linux-i2c@vger.kernel.org,
Grant Likely <grant.likely@secretlab.ca>,
devicetree-discuss@lists.ozlabs.org,
linux-kernel@vger.kernel.org, software@gaisler.com
Subject: Re: [PATCH v5 2/2] i2c: i2c-ocores: Add support for the GRLIB port of the controller and use function pointers for getreg and setreg functions
Date: Thu, 15 Nov 2012 15:56:44 +0100 [thread overview]
Message-ID: <87pq3e52z7.fsf@dell.be.48ers.dk> (raw)
In-Reply-To: <1352988548-10138-3-git-send-email-andreas@gaisler.com> (Andreas Larsson's message of "Thu, 15 Nov 2012 15:09:08 +0100")
>>>>> "Andreas" == Andreas Larsson <andreas@gaisler.com> writes:
Andreas> The registers in the GRLIB port of the controller are 32-bit
Andreas> and in big endian byte order. The PRELOW and PREHIGH registers
Andreas> are merged into one register. The subsequent registers have
Andreas> their offset decreased accordingly. Hence the register access
Andreas> needs to be handled in a non-standard manner using custom
Andreas> getreg and setreg functions.
Andreas> The single oc_getreg and one oc_setreg functions, that
Andreas> branches and call different ioread and iowrite functions, are
Andreas> replaced by specific functions that uses the appropriate
Andreas> ioread and iowrite functions and function pointers are
Andreas> initiated and used to call the approproate functions.
Andreas> A type is added as the data of the of match table entries. A
Andreas> new entry with a different compatible string is added to the
Andreas> table. The type of that entry triggers usage of the custom
Andreas> grlib functions by setting the new getreg and setreg function
Andreas> pointers to these functions.
Sorry to keep on requesting changes, but see below for a bit more:
Andreas> static void ocores_process(struct ocores_i2c *i2c)
Andreas> {
Andreas> struct i2c_msg *msg = i2c->msg;
Andreas> - u8 stat = oc_getreg(i2c, OCI2C_STATUS);
Andreas> + u8 stat = i2c->getreg(i2c, OCI2C_STATUS);
The patch would have been quite a bit smaller/easier to read if you had
kept oc_getreg / oc_setreg as wrappers.
Andreas> #ifdef CONFIG_OF
Andreas> static int ocores_i2c_of_probe(struct platform_device *pdev,
Andreas> struct ocores_i2c *i2c)
Andreas> {
Andreas> struct device_node *np = pdev->dev.of_node;
Andreas> + const struct of_device_id *match;
Andreas> u32 val;
Andreas> if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) {
Andreas> @@ -257,6 +324,14 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
Andreas> of_property_read_u32(pdev->dev.of_node, "reg-io-width",
Andreas> &i2c->reg_io_width);
Andreas> +
Andreas> + match = of_match_node(ocores_i2c_match, pdev->dev.of_node);
Andreas> + if (match && (int)match->data == TYPE_GRLIB) {
Andreas> + dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n");
Andreas> + i2c->setreg = oc_setreg_grlib;
Andreas> + i2c->getreg = oc_getreg_grlib;
Andreas> + }
Andreas> +
Andreas> return 0;
Andreas> }
Andreas> #else
Andreas> @@ -311,6 +386,23 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
Andreas> if (i2c->reg_io_width == 0)
i2c-> reg_io_width = 1; /* Set to default value */
Andreas> + if (!i2c->getreg) {
Andreas> + if (i2c->reg_io_width == 4)
Andreas> + i2c->getreg = oc_getreg_32;
Andreas> + else if (i2c->reg_io_width == 2)
Andreas> + i2c->getreg = oc_getreg_16;
Andreas> + else
Andreas> + i2c->getreg = oc_getreg_8;
Andreas> + }
Andreas> + if (!i2c->setreg) {
Andreas> + if (i2c->reg_io_width == 4)
Andreas> + i2c->setreg = oc_setreg_32;
Andreas> + else if (i2c->reg_io_width == 2)
Andreas> + i2c->setreg = oc_setreg_16;
Andreas> + else
Andreas> + i2c->setreg = oc_setreg_8;
Andreas> + }
Andreas> +
These are always set together (could even move to a single ops
structure), so it would be shorter to assign them at the same time:
if (!i2c->setreg || !i2c->getreg) {
switch (i2c->reg_io_width) {
case 1:
i2c->setreg = oc_setreg_8;
i2c->getreg = oc_getreg_8;
break;
case 2:
i2c->setreg = oc_setreg_16;
...
default:
dev_err(&pdev->dev "Unsupported I/O width (%d)\n", i2c->reg_io_width);
return -EINVAL;
}
}
--
Bye, Peter Korsgaard
prev parent reply other threads:[~2012-11-15 14:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-15 14:09 [PATCH v5 0/2] i2c: i2c-ocores: Add support for sparc, custom set and get functions, and the GRLIB port of the controller Andreas Larsson
2012-11-15 14:09 ` [PATCH v5 1/2] i2c: i2c-ocores: Add irq support for sparc Andreas Larsson
2012-11-15 14:09 ` [PATCH v5 2/2] i2c: i2c-ocores: Add support for the GRLIB port of the controller and use function pointers for getreg and setreg functions Andreas Larsson
2012-11-15 14:56 ` Peter Korsgaard [this message]
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=87pq3e52z7.fsf@dell.be.48ers.dk \
--to=jacmet@sunsite.dk \
--cc=andreas@gaisler.com \
--cc=ben-linux@fluff.org \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=software@gaisler.com \
--cc=w.sang@pengutronix.de \
/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
all inboxes | Powered by JetHome®