From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/4] S5P: GPIO: Add GPIO pin numbering to driver
Date: Wed, 05 Dec 2012 20:21:24 +0900 [thread overview]
Message-ID: <50BF2E34.1030503@samsung.com> (raw)
In-Reply-To: <00f501cdd2d5$c5336840$4f9a38c0$%kang@samsung.com>
Dear Rajeshwari,
On 05/12/12 19:46, Minkyu Kang wrote:
> API's for GPIO pin numbering support are added to the generic S5P
> gpio driver
>
> Signed-off-by: Leela Krishna Amudala <l.krishna@samsung.com>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Rajeshawari Shinde <rajeshwari.s@samsung.com>
> ---
> drivers/gpio/s5p_gpio.c | 158
> +++++++++++++++++++++++++++++++++++++++++++++--
> 1 files changed, 152 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c
> index 47f3213..5c051d4 100644
> --- a/drivers/gpio/s5p_gpio.c
> +++ b/drivers/gpio/s5p_gpio.c
> @@ -142,20 +142,165 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank,
> int gpio, int mode)
> writel(value, &bank->drv);
> }
>
> -struct s5p_gpio_bank *s5p_gpio_get_bank(unsigned gpio)
> +
> +int s5p_gpio_get_pin(unsigned gpio)
> {
> - int bank = gpio / GPIO_PER_BANK;
> - bank *= sizeof(struct s5p_gpio_bank);
> + return gpio % GPIO_PER_BANK;
> +}
>
> - return (struct s5p_gpio_bank *) (s5p_gpio_base(gpio) + bank);
> +#ifdef HAVE_GENERIC_GPIO
Is it generic naming?
Also.. why we support two types of GPIO functions?
If you want to support generic GPIO, you should be replaced new gpio functions completely.
> +static struct s5p_gpio_bank *gpio_get_bank(unsigned int gpio)
> +{
> + int bank_offset;
> +
> + if (gpio < GPIO_MAX_PORT_PART_1) {
> + bank_offset = gpio / GPIO_PER_BANK;
> + return (struct s5p_gpio_bank *) (EXYNOS5_GPIO_PART1_BASE +
Is it exynos5 specific?
> (bank_offset *
> + sizeof(struct
> s5p_gpio_bank)));
> + } else if (gpio < GPIO_MAX_PORT_PART_2) {
> + bank_offset = (gpio - GPIO_MAX_PORT_PART_1) / GPIO_PER_BANK;
> + return (struct s5p_gpio_bank *) (EXYNOS5_GPIO_PART2_BASE +
> (bank_offset *
> + sizeof(struct
> s5p_gpio_bank)));
> + } else if (gpio < GPIO_MAX_PORT_PART_3) {
> + bank_offset = (gpio - GPIO_MAX_PORT_PART_2) / GPIO_PER_BANK;
> + return (struct s5p_gpio_bank *) (EXYNOS5_GPIO_PART3_BASE +
> (bank_offset *
> + sizeof(struct
> s5p_gpio_bank)));
> + }
> + else
should be moved to upper line.
And need the brace at this else state.
> + return (struct s5p_gpio_bank *) EXYNOS5_GPIO_PART4_BASE;
> +
> + return NULL;
> }
>
> -int s5p_gpio_get_pin(unsigned gpio)
> +void gpio_cfg_pin(int gpio, int cfg)
> {
> - return gpio % GPIO_PER_BANK;
> + unsigned int value;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + value = readl(&bank->con);
> + value &= ~CON_MASK(GPIO_BIT(gpio));
> + value |= CON_SFR(GPIO_BIT(gpio), cfg);
> + writel(value, &bank->con);
> +}
> +
> +void gpio_set_pull(int gpio, int mode)
> +{
> + unsigned int value;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + value = readl(&bank->pull);
> + value &= ~PULL_MASK(GPIO_BIT(gpio));
> +
> + switch (mode) {
> + case GPIO_PULL_DOWN:
> + case GPIO_PULL_UP:
> + value |= PULL_MODE(GPIO_BIT(gpio), mode);
> + break;
> + default:
> + break;
> + }
> +
> + writel(value, &bank->pull);
> +}
> +
> +void gpio_set_drv(int gpio, int mode)
> +{
> + unsigned int value;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + value = readl(&bank->drv);
> + value &= ~DRV_MASK(GPIO_BIT(gpio));
> +
> + switch (mode) {
> + case GPIO_DRV_1X:
> + case GPIO_DRV_2X:
> + case GPIO_DRV_3X:
> + case GPIO_DRV_4X:
> + value |= DRV_SET(GPIO_BIT(gpio), mode);
> + break;
> + default:
> + return;
> + }
> +
> + writel(value, &bank->drv);
> }
>
> +void gpio_set_rate(int gpio, int mode)
> +{
> + unsigned int value;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + value = readl(&bank->drv);
> + value &= ~RATE_MASK(GPIO_BIT(gpio));
> +
> + switch (mode) {
> + case GPIO_DRV_FAST:
> + case GPIO_DRV_SLOW:
> + value |= RATE_SET(GPIO_BIT(gpio));
> + break;
> + default:
> + return;
> + }
> +
> + writel(value, &bank->drv);
> +}
> +
> +int gpio_direction_input(unsigned gpio)
> +{
> + gpio_cfg_pin(gpio, GPIO_INPUT);
> +
> + return 0;
> +}
> +
> +int gpio_direction_output(unsigned gpio, int value)
> +{
> + unsigned int val;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + gpio_cfg_pin(gpio, GPIO_OUTPUT);
> +
> + val = readl(&bank->dat);
> + val &= ~DAT_MASK(GPIO_BIT(gpio));
> + if (value)
> + val |= DAT_SET(GPIO_BIT(gpio));
> + writel(val, &bank->dat);
> +
> + return 0;
> +}
> +
> +int gpio_get_value(unsigned gpio)
> +{
> + unsigned int value;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + value = readl(&bank->dat);
> + return !!(value & DAT_MASK(GPIO_BIT(gpio)));
> +}
> +
> +
> +int gpio_set_value(unsigned gpio, int value)
> +{
> + unsigned int val;
> + struct s5p_gpio_bank *bank = gpio_get_bank(gpio);
> +
> + val = readl(&bank->dat);
> + val &= ~DAT_MASK(GPIO_BIT(gpio));
> + if (value)
> + val |= DAT_SET(GPIO_BIT(gpio));
> + writel(val, &bank->dat);
> +
> + return 0;
> +}
> +
> +#else
> /* Common GPIO API */
> +struct s5p_gpio_bank *s5p_gpio_get_bank(unsigned gpio)
> +{
> + int bank = gpio / GPIO_PER_BANK;
> + bank *= sizeof(struct s5p_gpio_bank);
> +
> + return (struct s5p_gpio_bank *) (s5p_gpio_base(gpio) + bank);
> +}
>
> int gpio_request(unsigned gpio, const char *label)
> {
> @@ -194,3 +339,4 @@ int gpio_set_value(unsigned gpio, int value)
>
> return 0;
> }
> +#endif /* HAVE_GENERIC_GPIO */
>
Thanks.
Minkyu Kang.
next parent reply other threads:[~2012-12-05 11:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <00f501cdd2d5$c5336840$4f9a38c0$%kang@samsung.com>
2012-12-05 11:21 ` Minkyu Kang [this message]
2012-12-11 12:17 ` [U-Boot] [PATCH 2/4] S5P: GPIO: Add GPIO pin numbering to driver Rajeshwari Birje
2012-08-06 13:05 [U-Boot] [PATCH 0/4] EXYNOS5: Add GPIO numbering feature Rajeshwari Shinde
2012-08-06 13:05 ` [U-Boot] [PATCH 2/4] S5P: GPIO: Add GPIO pin numbering to driver Rajeshwari Shinde
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=50BF2E34.1030503@samsung.com \
--to=mk7.kang@samsung.com \
--cc=u-boot@lists.denx.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