* [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges
@ 2011-10-26 4:22 Chanho Park
2011-10-26 6:21 ` Stephen Warren
0 siblings, 1 reply; 5+ messages in thread
From: Chanho Park @ 2011-10-26 4:22 UTC (permalink / raw)
To: linus.walleij, swarren, Baohua.Song, linux-kernel
Cc: Chanho Park, Kyungmin Park
This patch enables mapping a base offset of gpio ranges with
a pin offset even if does'nt matched. A base of pinctrl_gpio_range
means a base offset of gpio. However, we cannot convert gpio to pin
number for sparse gpio ranges just only using a gpio base offset.
We can convert a gpio to real pin number(even if not matched) using
a new pin_base which means a base pin offset of requested gpio range.
For example, let's assume below two gpio ranges in the system.
static struct pinctrl_gpio_range gpio_range_a = {
.name = "chip a",
.id = 0,
.base = 32,
.pin_base = 32,
.npins = 16,
.gc = &chip_a;
};
static struct pinctrl_gpio_range gpio_range_b = {
.name = "chip b",
.id = 0,
.base = 48,
.pin_base = 64,
.npins = 8,
.gc = &chip_b;
};
{
struct pinctrl_dev *pctl;
...
pinctrl_add_gpio_range(pctl, &gpio_range_a);
pinctrl_add_gpio_range(pctl, &gpio_range_b);
}
We can calucalate a exact pin ranges even if doesn't matched with gpio ranges.
chip a:
gpio-range : [32 .. 47]
pin-range : [32 .. 47]
chip b:
gpio-range : [48 .. 55]
pin-range : [64 .. 71]
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
Documentation/pinctrl.txt | 42 ++++++++------------------------------
drivers/pinctrl/pinmux-sirf.c | 4 +++
drivers/pinctrl/pinmux-u300.c | 1 +
drivers/pinctrl/pinmux.c | 4 +-
include/linux/pinctrl/pinctrl.h | 2 +
5 files changed, 18 insertions(+), 35 deletions(-)
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index 328adb7..41244e4 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -265,14 +265,16 @@ static struct pinctrl_gpio_range gpio_range_a = {
.name = "chip a",
.id = 0,
.base = 32,
+ .pin_base = 32,
.npins = 16,
.gc = &chip_a;
};
-static struct pinctrl_gpio_range gpio_range_a = {
+static struct pinctrl_gpio_range gpio_range_b = {
.name = "chip b",
.id = 0,
.base = 48,
+ .pin_base = 64,
.npins = 8,
.gc = &chip_b;
};
@@ -289,38 +291,12 @@ So this complex system has one pin controller handling two different
GPIO chips. Chip a has 16 pins and chip b has 8 pins. They are mapped in
the global GPIO pin space at:
-chip a: [32 .. 47]
-chip b: [48 .. 55]
-
-When GPIO-specific functions in the pin control subsystem are called, these
-ranges will be used to look up the apropriate pin controller by inspecting
-and matching the pin to the pin ranges across all controllers. When a
-pin controller handling the matching range is found, GPIO-specific functions
-will be called on that specific pin controller.
-
-For all functionalities dealing with pin biasing, pin muxing etc, the pin
-controller subsystem will subtract the range's .base offset from the passed
-in gpio pin number, and pass that on to the pin control driver, so the driver
-will get an offset into its handled number range. Further it is also passed
-the range ID value, so that the pin controller knows which range it should
-deal with.
-
-For example: if a user issues pinctrl_gpio_set_foo(50), the pin control
-subsystem will find that the second range on this pin controller matches,
-subtract the base 48 and call the
-pinctrl_driver_gpio_set_foo(pinctrl, range, 2) where the latter function has
-this signature:
-
-int pinctrl_driver_gpio_set_foo(struct pinctrl_dev *pctldev,
- struct pinctrl_gpio_range *rangeid,
- unsigned offset);
-
-Now the driver knows that we want to do some GPIO-specific operation on the
-second GPIO range handled by "chip b", at offset 2 in that specific range.
-
-(If the GPIO subsystem is ever refactored to use a local per-GPIO controller
-pin space, this mapping will need to be augmented accordingly.)
-
+chip a:
+ gpio-range : [32 .. 47]
+ pin-range : [32 .. 47]
+chip b:
+ gpio-range : [48 .. 55]
+ pin-range : [64 .. 71]
PINMUX interfaces
=================
diff --git a/drivers/pinctrl/pinmux-sirf.c b/drivers/pinctrl/pinmux-sirf.c
index ba73523..c9c277f 100644
--- a/drivers/pinctrl/pinmux-sirf.c
+++ b/drivers/pinctrl/pinmux-sirf.c
@@ -1100,21 +1100,25 @@ static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
.name = "sirfsoc-gpio*",
.id = 0,
.base = 0,
+ .pin_base = 0,
.npins = 32,
}, {
.name = "sirfsoc-gpio*",
.id = 1,
.base = 32,
+ .pin_base = 32,
.npins = 32,
}, {
.name = "sirfsoc-gpio*",
.id = 2,
.base = 64,
+ .pin_base = 64,
.npins = 32,
}, {
.name = "sirfsoc-gpio*",
.id = 3,
.base = 96,
+ .pin_base = 96,
.npins = 19,
},
};
diff --git a/drivers/pinctrl/pinmux-u300.c b/drivers/pinctrl/pinmux-u300.c
index 4858a64..dab0cfe 100644
--- a/drivers/pinctrl/pinmux-u300.c
+++ b/drivers/pinctrl/pinmux-u300.c
@@ -1023,6 +1023,7 @@ static struct pinctrl_gpio_range u300_gpio_range = {
.name = "COH901*",
.id = 0,
.base = 0,
+ .pin_base = 0,
.npins = 64,
};
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 5c4b782..d1384da 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -225,7 +225,7 @@ int pinmux_request_gpio(unsigned gpio)
return -EINVAL;
/* Convert to the pin controllers number space */
- pin = gpio - range->base;
+ pin = gpio - range->base + range->pin_base;
/* Conjure some name stating what chip and pin this is taken by */
snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
@@ -258,7 +258,7 @@ void pinmux_free_gpio(unsigned gpio)
return;
/* Convert to the pin controllers number space */
- pin = gpio - range->base;
+ pin = gpio - range->base + range->pin_base;
pin_free(pctldev, pin, true);
}
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 90dd28b..7768e44 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -127,6 +127,7 @@ struct pinctrl_pin_desc {
* @name: a name for the chip in this range
* @id: an ID number for the chip in this range
* @base: base offset of the GPIO range
+ * @pin_base: base pin offset of the GPIO range
* @npins: number of pins in the GPIO range, including the base number
* @gc: an optional pointer to a gpio_chip
*/
@@ -135,6 +136,7 @@ struct pinctrl_gpio_range {
const char *name;
unsigned int id;
unsigned int base;
+ unsigned int pin_base;
unsigned int npins;
struct gpio_chip *gc;
};
--
1.7.5.4
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges
2011-10-26 4:22 [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges Chanho Park
@ 2011-10-26 6:21 ` Stephen Warren
2011-10-26 9:39 ` Chanho Park
2011-10-28 19:57 ` Linus Walleij
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Warren @ 2011-10-26 6:21 UTC (permalink / raw)
To: Chanho Park, linus.walleij, Baohua.Song, linux-kernel; +Cc: Kyungmin Park
Chanho Park wrote at Tuesday, October 25, 2011 10:22 PM:
> This patch enables mapping a base offset of gpio ranges with
> a pin offset even if does'nt matched. A base of pinctrl_gpio_range
> means a base offset of gpio. However, we cannot convert gpio to pin
> number for sparse gpio ranges just only using a gpio base offset.
> We can convert a gpio to real pin number(even if not matched) using
> a new pin_base which means a base pin offset of requested gpio range.
...
> diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
...
> @@ -289,38 +291,12 @@ So this complex system has one pin controller handling two different
> GPIO chips. Chip a has 16 pins and chip b has 8 pins. They are mapped in
> the global GPIO pin space at:
>
> -chip a: [32 .. 47]
> -chip b: [48 .. 55]
> -
> -When GPIO-specific functions in the pin control subsystem are called, these
> -ranges will be used to look up the apropriate pin controller by inspecting
> -and matching the pin to the pin ranges across all controllers. When a
> -... [ quit a few lines of documentation removed]
> -(If the GPIO subsystem is ever refactored to use a local per-GPIO controller
> -pin space, this mapping will need to be augmented accordingly.)
> -
> +chip a:
> + gpio-range : [32 .. 47]
> + pin-range : [32 .. 47]
> +chip b:
> + gpio-range : [48 .. 55]
> + pin-range : [64 .. 71]
I'm all for replacing the example here with something more complete, but
removing all that text from the documentation doesn't seem right.
...
> diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
> index 90dd28b..7768e44 100644
> --- a/include/linux/pinctrl/pinctrl.h
> +++ b/include/linux/pinctrl/pinctrl.h
> @@ -127,6 +127,7 @@ struct pinctrl_pin_desc {
> * @name: a name for the chip in this range
> * @id: an ID number for the chip in this range
> * @base: base offset of the GPIO range
> + * @pin_base: base pin offset of the GPIO range
This may be bike-shedding, but I'd tend to call this "gpio_base", since
it's the first "gpio" number of this range, not the first "pin" number
("pins" are used in the pinctrl subsystem, but "gpios" by the GPIO
Subsystem)
--
nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges
2011-10-26 6:21 ` Stephen Warren
@ 2011-10-26 9:39 ` Chanho Park
2011-10-27 16:10 ` Stephen Warren
2011-10-28 19:57 ` Linus Walleij
1 sibling, 1 reply; 5+ messages in thread
From: Chanho Park @ 2011-10-26 9:39 UTC (permalink / raw)
To: 'Stephen Warren', linus.walleij, Baohua.Song, linux-kernel
Cc: 'Kyungmin Park'
> -----Original Message-----
> From: Stephen Warren [mailto:swarren@nvidia.com]
> Sent: Wednesday, October 26, 2011 3:21 PM
> To: Chanho Park; linus.walleij@linaro.org; Baohua.Song@csr.com; linux-
> kernel@vger.kernel.org
> Cc: Kyungmin Park
> Subject: RE: [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-
> ranges
>
> Chanho Park wrote at Tuesday, October 25, 2011 10:22 PM:
> > This patch enables mapping a base offset of gpio ranges with
> > a pin offset even if does'nt matched. A base of pinctrl_gpio_range
> > means a base offset of gpio. However, we cannot convert gpio to pin
> > number for sparse gpio ranges just only using a gpio base offset.
> > We can convert a gpio to real pin number(even if not matched) using
> > a new pin_base which means a base pin offset of requested gpio range.
> ...
> > diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
> ...
> > @@ -289,38 +291,12 @@ So this complex system has one pin controller
> handling two different
> > GPIO chips. Chip a has 16 pins and chip b has 8 pins. They are mapped
> in
> > the global GPIO pin space at:
> >
> > -chip a: [32 .. 47]
> > -chip b: [48 .. 55]
> > -
> > -When GPIO-specific functions in the pin control subsystem are called,
> these
> > -ranges will be used to look up the apropriate pin controller by
> inspecting
> > -and matching the pin to the pin ranges across all controllers. When a
> > -... [ quit a few lines of documentation removed]
> > -(If the GPIO subsystem is ever refactored to use a local per-GPIO
> controller
> > -pin space, this mapping will need to be augmented accordingly.)
> > -
> > +chip a:
> > + gpio-range : [32 .. 47]
> > + pin-range : [32 .. 47]
> > +chip b:
> > + gpio-range : [48 .. 55]
> > + pin-range : [64 .. 71]
>
> I'm all for replacing the example here with something more complete, but
> removing all that text from the documentation doesn't seem right.
OK. I'll modify this part of the documentation.
>
> ...
> > diff --git a/include/linux/pinctrl/pinctrl.h
> b/include/linux/pinctrl/pinctrl.h
> > index 90dd28b..7768e44 100644
> > --- a/include/linux/pinctrl/pinctrl.h
> > +++ b/include/linux/pinctrl/pinctrl.h
> > @@ -127,6 +127,7 @@ struct pinctrl_pin_desc {
> > * @name: a name for the chip in this range
> > * @id: an ID number for the chip in this range
> > * @base: base offset of the GPIO range
> > + * @pin_base: base pin offset of the GPIO range
>
> This may be bike-shedding, but I'd tend to call this "gpio_base", since
> it's the first "gpio" number of this range, not the first "pin" number
> ("pins" are used in the pinctrl subsystem, but "gpios" by the GPIO
> Subsystem)
A "base" means first "gpio" number of the range.
And a "pin_base" means first "pin" number.
Do you want to replace the "base" to the "gpio_base"?
>
> --
> nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges
2011-10-26 9:39 ` Chanho Park
@ 2011-10-27 16:10 ` Stephen Warren
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2011-10-27 16:10 UTC (permalink / raw)
To: Chanho Park, linus.walleij, Baohua.Song, linux-kernel
Cc: 'Kyungmin Park'
Chanho Park wrote at Wednesday, October 26, 2011 3:39 AM:
> Stephen Warren wrote at Wednesday, October 26, 2011 3:21 PM:
> > Chanho Park wrote at Tuesday, October 25, 2011 10:22 PM:
> > > This patch enables mapping a base offset of gpio ranges with
> > > a pin offset even if does'nt matched. A base of pinctrl_gpio_range
> > > means a base offset of gpio. However, we cannot convert gpio to pin
> > > number for sparse gpio ranges just only using a gpio base offset.
> > > We can convert a gpio to real pin number(even if not matched) using
> > > a new pin_base which means a base pin offset of requested gpio range.
> > ...
> > > diff --git a/include/linux/pinctrl/pinctrl.h
> > b/include/linux/pinctrl/pinctrl.h
> > > index 90dd28b..7768e44 100644
> > > --- a/include/linux/pinctrl/pinctrl.h
> > > +++ b/include/linux/pinctrl/pinctrl.h
> > > @@ -127,6 +127,7 @@ struct pinctrl_pin_desc {
> > > * @name: a name for the chip in this range
> > > * @id: an ID number for the chip in this range
> > > * @base: base offset of the GPIO range
> > > + * @pin_base: base pin offset of the GPIO range
> >
> > This may be bike-shedding, but I'd tend to call this "gpio_base", since
> > it's the first "gpio" number of this range, not the first "pin" number
> > ("pins" are used in the pinctrl subsystem, but "gpios" by the GPIO
> > Subsystem)
>
> A "base" means first "gpio" number of the range.
> And a "pin_base" means first "pin" number.
> Do you want to replace the "base" to the "gpio_base"?
Ah OK. I guess I misunderstood this slightly, since "base" was both a
pin and GPIO number before, or something like that.
Anyway, I certainly see value in s/base/gpio_base/ to make this all
explicit. Hopefully that doesn't cause the patch to grow too big and
churn the code too much.
--
nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges
2011-10-26 6:21 ` Stephen Warren
2011-10-26 9:39 ` Chanho Park
@ 2011-10-28 19:57 ` Linus Walleij
1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2011-10-28 19:57 UTC (permalink / raw)
To: Chanho Park, Stephen Warren; +Cc: Baohua.Song, linux-kernel, Kyungmin Park
On Wed, Oct 26, 2011 at 8:21 AM, Stephen Warren <swarren@nvidia.com> wrote:
> [Chanho]
>> -chip a: [32 .. 47]
>> -chip b: [48 .. 55]
>> -
>> -When GPIO-specific functions in the pin control subsystem are called, these
>> -ranges will be used to look up the apropriate pin controller by inspecting
>> -and matching the pin to the pin ranges across all controllers. When a
>> -... [ quit a few lines of documentation removed]
>> -(If the GPIO subsystem is ever refactored to use a local per-GPIO controller
>> -pin space, this mapping will need to be augmented accordingly.)
>
> I'm all for replacing the example here with something more complete, but
> removing all that text from the documentation doesn't seem right.
I agree. Make a real good example illustrating your setup or something
similar, so we all can understand from the documentation how to use
the different bases.
Apart from that the patch looks good.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-10-28 19:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-26 4:22 [PATCH] drivers: pinctrl: add a pin_base for sparse gpio-ranges Chanho Park
2011-10-26 6:21 ` Stephen Warren
2011-10-26 9:39 ` Chanho Park
2011-10-27 16:10 ` Stephen Warren
2011-10-28 19:57 ` Linus Walleij
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®