From: Linus Walleij <linus.walleij@linaro.org>
To: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linuxppc-dev@lists.ozlabs.org list"
<linuxppc-dev@lists.ozlabs.org>,
linux-gpio@vger.kernel.org,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@vger.kernel.org>,
Albert Herranz <albert_herranz@yahoo.es>,
Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH 3/6] gpio: Add GPIO driver for Nintendo Wii
Date: Tue, 16 Jan 2018 10:42:54 +0100 [thread overview]
Message-ID: <CACRpkdb11jn4HFdoKLuNVmXeTBntpTAjkVctvH1=R-p6989eTg@mail.gmail.com> (raw)
In-Reply-To: <20180115031401.19577-4-j.neuschaefer@gmx.net>
On Mon, Jan 15, 2018 at 4:13 AM, Jonathan Neuschäfer
<j.neuschaefer@gmx.net> wrote:
> This patch is based on code developed by Albert Herranz and the GameCube
> Linux Team, file arch/powerpc/platforms/embedded6xx/hlwd-gpio.c,
> available at https://github.com/DeltaResero/GC-Wii-Linux-Kernels, but
> has grown quite dissimilar.
I'm impressed by this effort. As with all reverse engineering.
> This driver currently uses __raw_readl and __raw_writel to access the
> GPIO controller's MMIO registers. I wonder if readl/writel plus explicit
> byte-swapping would be more correct, because it could be independent of
> the CPU's endianness. That said, this hardware only exists in two
> big-endian machines (Wii and Wii U).
I don't know about PPC but I think you're supposed to use
ioread32be() and iowrite32be() to do explicit BE access.
But when I look at it, I think you can just use the gpio-mmio library
for this driver and cut down code cosiderably.
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Can't you just save a pointer to struct device *dev in the
state container and use dev_info(state->dev, ...) etc instead
of this?
> +#include <linux/of_gpio.h>
This include should not be needed.
> +/*
> + * Update the bit with the given bit offset in the given register to a given
> + * value
> + */
> +static void hlwd_gpio_update_bit(struct gpio_chip *gc, unsigned int reg,
> + int offset, int value)
> +{
> + struct hlwd_gpio *hlwd = gpiochip_get_data(gc);
> + unsigned long flags;
> + u32 bit = 1UL << offset;
#include <linux/bitops.h>
u32 bit = BIT(offset);
> + u32 tmp;
> +
> + spin_lock_irqsave(&hlwd->lock, flags);
> + tmp = __raw_readl(hlwd->regs + reg);
> + if (value)
> + __raw_writel(tmp | bit, hlwd->regs + reg);
> + else
> + __raw_writel(tmp & ~bit, hlwd->regs + reg);
> + spin_unlock_irqrestore(&hlwd->lock, flags);
> +}
This looks very much like it is reimplementing the stuff we already
have in drivers/gpio/gpio-mmio.h.
There is even a big endian access flag for the library.
And you get so much for free with gpio-mmio.
select GPIO_GENERIC
in Kconfig
the helpers come in from <linux/gpio/driver.h>
Look at other drivers for inspiration:
git grep bgpio_init
If you need IRQ support you should probably have your own file
for this driver, but it will be just a few lines of wrapper using
bgpio_init() and BGPIOF_BIG_ENDIAN and/or possibly
BGPIOF_BIG_ENDIAN_BYTE_ORDER.
See the other drivers.
Yours,
Linus Walleij
next prev parent reply other threads:[~2018-01-16 9:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-15 3:13 [PATCH 0/6] Nintendo Wii GPIO driver Jonathan Neuschäfer
2018-01-15 3:13 ` [PATCH 1/6] resource: Extend the PPC32 reserved memory hack Jonathan Neuschäfer
2018-01-15 3:13 ` [PATCH 2/6] powerpc: wii: Explicitly configure GPIO owner for poweroff pin Jonathan Neuschäfer
2018-01-15 3:13 ` [PATCH 3/6] gpio: Add GPIO driver for Nintendo Wii Jonathan Neuschäfer
2018-01-16 9:42 ` Linus Walleij [this message]
2018-01-16 21:58 ` Jonathan Neuschäfer
2018-01-15 3:13 ` [PATCH 4/6] dt-bindings: gpio: Add binding for Wii GPIO controller Jonathan Neuschäfer
2018-01-16 9:28 ` Linus Walleij
2018-01-19 23:05 ` Rob Herring
2018-01-20 1:47 ` Jonathan Neuschäfer
2018-01-15 3:14 ` [PATCH 5/6] powerpc: wii.dts: Add ngpios property Jonathan Neuschäfer
2018-01-15 3:14 ` [PATCH 6/6] powerpc: wii.dts: Add GPIO line names Jonathan Neuschäfer
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='CACRpkdb11jn4HFdoKLuNVmXeTBntpTAjkVctvH1=R-p6989eTg@mail.gmail.com' \
--to=linus.walleij@linaro.org \
--cc=albert_herranz@yahoo.es \
--cc=devicetree@vger.kernel.org \
--cc=j.neuschaefer@gmx.net \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=segher@kernel.crashing.org \
/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).