From: Marcus Folkesson <marcus.folkesson@gmail.com>
To: Baolin Wang <baolin.wang@linaro.org>
Cc: linus.walleij@linaro.org, robh+dt@kernel.org,
mark.rutland@arm.com, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
broonie@kernel.org
Subject: Re: [PATCH 2/2] gpio: Add GPIO driver for Spreadtrum SC9860 platform
Date: Thu, 1 Feb 2018 13:17:53 +0100 [thread overview]
Message-ID: <20180201121753.GB690@gmail.com> (raw)
In-Reply-To: <cccc1addb9c0cc541b676dbad005ec341d12d165.1517313987.git.baolin.wang@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 3956 bytes --]
Hi Baolin,
On Tue, Jan 30, 2018 at 08:07:43PM +0800, Baolin Wang wrote:
> The Spreadtrum SC9860 platform GPIO controller contains 16 groups and
> each group contains 16 GPIOs. Each GPIO can set input/output and has
> the interrupt capability.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
> diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
> new file mode 100644
> index 0000000..af59b9f
> --- /dev/null
> +++ b/drivers/gpio/gpio-sprd.c
> @@ -0,0 +1,301 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2018 Spreadtrum Communications Inc.
> + * Copyright (c) 2018 Linaro Ltd.
> + */
> +
> +#include <linux/bitops.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/spinlock.h>
> +
> +/* GPIO registers definition */
> +#define SPRD_GPIO_DATA 0x0
> +#define SPRD_GPIO_DMSK 0x4
> +#define SPRD_GPIO_DIR 0x8
> +#define SPRD_GPIO_IS 0xc
> +#define SPRD_GPIO_IBE 0x10
> +#define SPRD_GPIO_IEV 0x14
> +#define SPRD_GPIO_IE 0x18
> +#define SPRD_GPIO_RIS 0x1c
> +#define SPRD_GPIO_MIS 0x20
> +#define SPRD_GPIO_IC 0x24
> +#define SPRD_GPIO_INEN 0x28
> +
> +/* We have 16 groups GPIOs and each group contain 16 GPIOs */
> +#define SPRD_GPIO_GROUP_NR 16
> +#define SPRD_GPIO_NR 256
> +#define SPRD_GPIO_GROUP_SIZE 0x80
> +#define SPRD_GPIO_GROUP_MASK GENMASK(15, 0)
> +#define SPRD_GPIO_BIT(x) ((x) & (SPRD_GPIO_GROUP_NR - 1))
> +
> +struct sprd_gpio {
> + struct gpio_chip chip;
> + void __iomem *base;
> + spinlock_t lock;
> + int irq;
> +};
> +
> +static inline void __iomem *sprd_gpio_group_base(struct sprd_gpio *sprd_gpio,
> + unsigned int group)
> +{
> + return sprd_gpio->base + SPRD_GPIO_GROUP_SIZE * group;
> +}
> +
> +static void sprd_gpio_update(struct gpio_chip *chip, unsigned int offset,
> + unsigned int reg, unsigned int val)
> +{
> + struct sprd_gpio *sprd_gpio = gpiochip_get_data(chip);
> + void __iomem *base = sprd_gpio_group_base(sprd_gpio,
> + offset / SPRD_GPIO_GROUP_NR);
> + u32 shift = SPRD_GPIO_BIT(offset);
> + unsigned long flags;
> + u32 orig, tmp;
> +
> + spin_lock_irqsave(&sprd_gpio->lock, flags);
> + orig = readl_relaxed(base + reg);
> +
> + tmp = (orig & ~BIT(shift)) | (val << shift);
> + writel_relaxed(tmp, base + reg);
> + spin_unlock_irqrestore(&sprd_gpio->lock, flags);
> +}
> +
> +static int sprd_gpio_read(struct gpio_chip *chip, unsigned int offset,
> + unsigned int reg)
> +{
> + struct sprd_gpio *sprd_gpio = gpiochip_get_data(chip);
> + void __iomem *base = sprd_gpio_group_base(sprd_gpio,
> + offset / SPRD_GPIO_GROUP_NR);
> + u32 value = readl_relaxed(base + reg) & SPRD_GPIO_GROUP_MASK;
> + u32 shift = SPRD_GPIO_BIT(offset);
> +
> + return !!(value & BIT(shift));
> +}
> +
> +static int sprd_gpio_request(struct gpio_chip *chip, unsigned int offset)
> +{
> + sprd_gpio_update(chip, offset, SPRD_GPIO_DMSK, 1);
> + return 0;
> +}
Better to change the function to void since the return value is not
valueable.
> +
> +static void sprd_gpio_free(struct gpio_chip *chip, unsigned int offset)
> +{
> + sprd_gpio_update(chip, offset, SPRD_GPIO_DMSK, 0);
> +}
> +
> +static int sprd_gpio_direction_input(struct gpio_chip *chip,
> + unsigned int offset)
> +{
> + sprd_gpio_update(chip, offset, SPRD_GPIO_DIR, 0);
> + sprd_gpio_update(chip, offset, SPRD_GPIO_INEN, 1);
> + return 0;
> +}
Same here
> +
> +static int sprd_gpio_direction_output(struct gpio_chip *chip,
> + unsigned int offset, int value)
> +{
> + sprd_gpio_update(chip, offset, SPRD_GPIO_DIR, 1);
> + sprd_gpio_update(chip, offset, SPRD_GPIO_INEN, 0);
> + sprd_gpio_update(chip, offset, SPRD_GPIO_DATA, value);
> + return 0;
> +}
and here.
Thanks,
Marcus Folkesson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-02-01 12:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 12:07 [PATCH 1/2] dt-bindings: gpio: Add Spreadtrum GPIO controller documentation Baolin Wang
[not found] ` <2834309f69a1ec37b84a33f153a3d0b90336bcc6.1517313987.git.baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-30 12:07 ` [PATCH 2/2] gpio: Add GPIO driver for Spreadtrum SC9860 platform Baolin Wang
[not found] ` <cccc1addb9c0cc541b676dbad005ec341d12d165.1517313987.git.baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-30 16:48 ` Andy Shevchenko
2018-01-31 2:01 ` Baolin Wang
[not found] ` <CAMz4kuL9r+97_rDihgKD_TyNaDQ3aCk7go6e4mB24QOpovFYJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-31 14:23 ` Andy Shevchenko
2018-02-01 3:08 ` Baolin Wang
2018-02-01 12:22 ` Marcus Folkesson
2018-02-01 12:26 ` Baolin Wang
[not found] ` <20180201122230.GC690-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-01 15:12 ` Andy Shevchenko
2018-02-01 12:17 ` Marcus Folkesson [this message]
2018-02-01 12:26 ` Baolin Wang
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=20180201121753.GB690@gmail.com \
--to=marcus.folkesson@gmail.com \
--cc=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.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).