From: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Mika Westerberg <mika.westerberg@intel.com>,
Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>,
GPIO Subsystem Mailing List <linux-gpio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Denis Turischev <denis.turischev@compulab.co.il>
Subject: [PATCHv3 1/3] gpio: sch: Consolidate similar algorithms
Date: Thu, 16 Oct 2014 11:51:13 +0800 [thread overview]
Message-ID: <1413431475-12799-2-git-send-email-rebecca.swee.fun.chang@intel.com> (raw)
In-Reply-To: <1413431475-12799-1-git-send-email-rebecca.swee.fun.chang@intel.com>
Consolidating similar algorithms into common functions to make
GPIO SCH simpler and manageable.
Signed-off-by: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>
---
drivers/gpio/gpio-sch.c | 95 ++++++++++++++++++++++++++---------------------
1 file changed, 53 insertions(+), 42 deletions(-)
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index 99720c8..6e89be9 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -63,94 +63,105 @@ static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
return gpio % 8;
}
-static void sch_gpio_enable(struct sch_gpio *sch, unsigned gpio)
+static void sch_gpio_register_set(struct sch_gpio *sch, unsigned gpio,
+ unsigned reg)
{
unsigned short offset, bit;
u8 enable;
spin_lock(&sch->lock);
- offset = sch_gpio_offset(sch, gpio, GEN);
+ offset = sch_gpio_offset(sch, gpio, reg);
bit = sch_gpio_bit(sch, gpio);
enable = inb(sch->iobase + offset);
- if (!(enable & (1 << bit)))
- outb(enable | (1 << bit), sch->iobase + offset);
+ if (!(enable & BIT(bit)))
+ outb(enable | BIT(bit), sch->iobase + offset);
spin_unlock(&sch->lock);
}
-static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
+static void sch_gpio_register_clear(struct sch_gpio *sch, unsigned gpio,
+ unsigned reg)
{
- struct sch_gpio *sch = to_sch_gpio(gc);
- u8 curr_dirs;
unsigned short offset, bit;
+ u8 disable;
spin_lock(&sch->lock);
- offset = sch_gpio_offset(sch, gpio_num, GIO);
- bit = sch_gpio_bit(sch, gpio_num);
-
- curr_dirs = inb(sch->iobase + offset);
+ offset = sch_gpio_offset(sch, gpio, reg);
+ bit = sch_gpio_bit(sch, gpio);
- if (!(curr_dirs & (1 << bit)))
- outb(curr_dirs | (1 << bit), sch->iobase + offset);
+ disable = inb(sch->iobase + offset);
+ if (disable & BIT(bit))
+ outb(disable & ~BIT(bit), sch->iobase + offset);
spin_unlock(&sch->lock);
- return 0;
}
-static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
+static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg)
{
struct sch_gpio *sch = to_sch_gpio(gc);
- int res;
unsigned short offset, bit;
+ u8 curr_dirs;
- offset = sch_gpio_offset(sch, gpio_num, GLV);
- bit = sch_gpio_bit(sch, gpio_num);
+ offset = sch_gpio_offset(sch, gpio, reg);
+ bit = sch_gpio_bit(sch, gpio);
- res = !!(inb(sch->iobase + offset) & (1 << bit));
+ curr_dirs = !!(inb(sch->iobase + offset) & BIT(bit));
- return res;
+ return curr_dirs;
}
-static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
+static void sch_gpio_reg_set(struct gpio_chip *gc, unsigned gpio, unsigned reg,
+ int val)
{
struct sch_gpio *sch = to_sch_gpio(gc);
- u8 curr_vals;
unsigned short offset, bit;
+ u8 curr_dirs;
- spin_lock(&sch->lock);
-
- offset = sch_gpio_offset(sch, gpio_num, GLV);
- bit = sch_gpio_bit(sch, gpio_num);
+ offset = sch_gpio_offset(sch, gpio, reg);
+ bit = sch_gpio_bit(sch, gpio);
- curr_vals = inb(sch->iobase + offset);
+ curr_dirs = inb(sch->iobase + offset);
if (val)
- outb(curr_vals | (1 << bit), sch->iobase + offset);
+ outb(curr_dirs | BIT(bit), sch->iobase + offset);
else
- outb((curr_vals & ~(1 << bit)), sch->iobase + offset);
+ outb((curr_dirs & ~BIT(bit)), sch->iobase + offset);
+}
+static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
+{
+ struct sch_gpio *sch = to_sch_gpio(gc);
+
+ spin_lock(&sch->lock);
+ sch_gpio_register_set(sch, gpio_num, GIO);
spin_unlock(&sch->lock);
+ return 0;
}
-static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
- int val)
+static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
+{
+ return sch_gpio_reg_get(gc, gpio_num, GLV);
+}
+
+static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
{
struct sch_gpio *sch = to_sch_gpio(gc);
- u8 curr_dirs;
- unsigned short offset, bit;
spin_lock(&sch->lock);
+ sch_gpio_reg_set(gc, gpio_num, GLV, val);
+ spin_unlock(&sch->lock);
+}
- offset = sch_gpio_offset(sch, gpio_num, GIO);
- bit = sch_gpio_bit(sch, gpio_num);
-
- curr_dirs = inb(sch->iobase + offset);
- if (curr_dirs & (1 << bit))
- outb(curr_dirs & ~(1 << bit), sch->iobase + offset);
+static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
+ int val)
+{
+ struct sch_gpio *sch = to_sch_gpio(gc);
+ spin_lock(&sch->lock);
+ sch_gpio_register_clear(sch, gpio_num, GIO);
spin_unlock(&sch->lock);
/*
@@ -209,13 +220,13 @@ static int sch_gpio_probe(struct platform_device *pdev)
* GPIO7 is configured by the CMC as SLPIOVR
* Enable GPIO[9:8] core powered gpios explicitly
*/
- sch_gpio_enable(sch, 8);
- sch_gpio_enable(sch, 9);
+ sch_gpio_register_set(sch, 8, GEN);
+ sch_gpio_register_set(sch, 9, GEN);
/*
* SUS_GPIO[2:0] enabled by default
* Enable SUS_GPIO3 resume powered gpio explicitly
*/
- sch_gpio_enable(sch, 13);
+ sch_gpio_register_set(sch, 13, GEN);
break;
case PCI_DEVICE_ID_INTEL_ITC_LPC:
--
1.7.9.5
next prev parent reply other threads:[~2014-10-16 3:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-16 3:51 [PATCHv3 0/3] Enable Quark X1000 support in gpio-sch Chang Rebecca Swee Fun
2014-10-16 3:51 ` Chang Rebecca Swee Fun [this message]
2014-10-16 10:06 ` [PATCHv3 1/3] gpio: sch: Consolidate similar algorithms Mika Westerberg
2014-10-17 8:43 ` Alexandre Courbot
2014-10-23 7:23 ` Chang, Rebecca Swee Fun
2014-10-16 3:51 ` [PATCHv3 2/3] gpio: sch: Add support for Intel Quark X1000 SoC Chang Rebecca Swee Fun
2014-10-16 10:06 ` Mika Westerberg
2014-10-17 8:47 ` Alexandre Courbot
2014-10-16 3:51 ` [PATCHv3 3/3] gpio: sch: Enable IRQ support for Quark X1000 Chang Rebecca Swee Fun
2014-10-16 4:01 ` Varka Bhadram
2014-10-16 10:19 ` Mika Westerberg
2014-11-05 9:33 ` Chang, Rebecca Swee Fun
2014-11-05 10:15 ` Westerberg, Mika
2014-10-17 8:54 ` Alexandre Courbot
2014-10-23 7:29 ` Chang, Rebecca Swee Fun
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=1413431475-12799-2-git-send-email-rebecca.swee.fun.chang@intel.com \
--to=rebecca.swee.fun.chang@intel.com \
--cc=denis.turischev@compulab.co.il \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@intel.com \
/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®