Skip to content

Commit 3c739ad

Browse files
cometzeroLinus Walleij
authored andcommitted
pinctrl: add a pin_base for sparse gpio-ranges
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. Now, the pin control subsystem passes the pin base offset to the pinmux driver. 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; }; 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> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 33d5894 commit 3c739ad

6 files changed

Lines changed: 34 additions & 29 deletions

File tree

‎Documentation/pinctrl.txt‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,20 @@ static struct pinctrl_gpio_range gpio_range_a = {
214214
.name = "chip a",
215215
.id = 0,
216216
.base = 32,
217+
.pin_base = 32,
217218
.npins = 16,
218219
.gc = &chip_a;
219220
};
220221

221-
static struct pinctrl_gpio_range gpio_range_a = {
222+
static struct pinctrl_gpio_range gpio_range_b = {
222223
.name = "chip b",
223224
.id = 0,
224225
.base = 48,
226+
.pin_base = 64,
225227
.npins = 8,
226228
.gc = &chip_b;
227229
};
228230

229-
230231
{
231232
struct pinctrl_dev *pctl;
232233
...
@@ -235,11 +236,24 @@ static struct pinctrl_gpio_range gpio_range_a = {
235236
}
236237

237238
So this complex system has one pin controller handling two different
238-
GPIO chips. Chip a has 16 pins and chip b has 8 pins. They are mapped in
239-
the global GPIO pin space at:
239+
GPIO chips. "chip a" has 16 pins and "chip b" has 8 pins. The "chip a" and
240+
"chip b" have different .pin_base, which means a start pin number of the
241+
GPIO range.
242+
243+
The GPIO range of "chip a" starts from the GPIO base of 32 and actual
244+
pin range also starts from 32. However "chip b" has different starting
245+
offset for the GPIO range and pin range. The GPIO range of "chip b" starts
246+
from GPIO number 48, while the pin range of "chip b" starts from 64.
240247

241-
chip a: [32 .. 47]
242-
chip b: [48 .. 55]
248+
We can convert a gpio number to actual pin number using this "pin_base".
249+
They are mapped in the global GPIO pin space at:
250+
251+
chip a:
252+
- GPIO range : [32 .. 47]
253+
- pin range : [32 .. 47]
254+
chip b:
255+
- GPIO range : [48 .. 55]
256+
- pin range : [64 .. 71]
243257

244258
When GPIO-specific functions in the pin control subsystem are called, these
245259
ranges will be used to look up the appropriate pin controller by inspecting
@@ -249,28 +263,12 @@ will be called on that specific pin controller.
249263

250264
For all functionalities dealing with pin biasing, pin muxing etc, the pin
251265
controller subsystem will subtract the range's .base offset from the passed
252-
in gpio pin number, and pass that on to the pin control driver, so the driver
253-
will get an offset into its handled number range. Further it is also passed
266+
in gpio number, and add the ranges's .pin_base offset to retrive a pin number.
267+
After that, the subsystem passes it on to the pin control driver, so the driver
268+
will get an pin number into its handled number range. Further it is also passed
254269
the range ID value, so that the pin controller knows which range it should
255270
deal with.
256271

257-
For example: if a user issues pinctrl_gpio_set_foo(50), the pin control
258-
subsystem will find that the second range on this pin controller matches,
259-
subtract the base 48 and call the
260-
pinctrl_driver_gpio_set_foo(pinctrl, range, 2) where the latter function has
261-
this signature:
262-
263-
int pinctrl_driver_gpio_set_foo(struct pinctrl_dev *pctldev,
264-
struct pinctrl_gpio_range *rangeid,
265-
unsigned offset);
266-
267-
Now the driver knows that we want to do some GPIO-specific operation on the
268-
second GPIO range handled by "chip b", at offset 2 in that specific range.
269-
270-
(If the GPIO subsystem is ever refactored to use a local per-GPIO controller
271-
pin space, this mapping will need to be augmented accordingly.)
272-
273-
274272
PINMUX interfaces
275273
=================
276274

‎drivers/pinctrl/pinmux-sirf.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev,
10671067
spmx = pinctrl_dev_get_drvdata(pmxdev);
10681068

10691069
muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
1070-
muxval = muxval | (1 << offset);
1070+
muxval = muxval | (1 << (offset - range->pin_base));
10711071
writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
10721072

10731073
return 0;
@@ -1100,21 +1100,25 @@ static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
11001100
.name = "sirfsoc-gpio*",
11011101
.id = 0,
11021102
.base = 0,
1103+
.pin_base = 0,
11031104
.npins = 32,
11041105
}, {
11051106
.name = "sirfsoc-gpio*",
11061107
.id = 1,
11071108
.base = 32,
1109+
.pin_base = 32,
11081110
.npins = 32,
11091111
}, {
11101112
.name = "sirfsoc-gpio*",
11111113
.id = 2,
11121114
.base = 64,
1115+
.pin_base = 64,
11131116
.npins = 32,
11141117
}, {
11151118
.name = "sirfsoc-gpio*",
11161119
.id = 3,
11171120
.base = 96,
1121+
.pin_base = 96,
11181122
.npins = 19,
11191123
},
11201124
};

‎drivers/pinctrl/pinmux-u300.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ static struct pinctrl_gpio_range u300_gpio_range = {
10261026
.name = "COH901*",
10271027
.id = 0,
10281028
.base = 0,
1029+
.pin_base = 0,
10291030
.npins = 64,
10301031
};
10311032

‎drivers/pinctrl/pinmux.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int pinmux_request_gpio(unsigned gpio)
229229
return -EINVAL;
230230

231231
/* Convert to the pin controllers number space */
232-
pin = gpio - range->base;
232+
pin = gpio - range->base + range->pin_base;
233233

234234
/* Conjure some name stating what chip and pin this is taken by */
235235
snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
@@ -263,7 +263,7 @@ void pinmux_free_gpio(unsigned gpio)
263263
return;
264264

265265
/* Convert to the pin controllers number space */
266-
pin = gpio - range->base;
266+
pin = gpio - range->base + range->pin_base;
267267

268268
func = pin_free(pctldev, pin, range);
269269
kfree(func);

‎include/linux/pinctrl/pinctrl.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct pinctrl_pin_desc {
4545
* @name: a name for the chip in this range
4646
* @id: an ID number for the chip in this range
4747
* @base: base offset of the GPIO range
48+
* @pin_base: base pin number of the GPIO range
4849
* @npins: number of pins in the GPIO range, including the base number
4950
* @gc: an optional pointer to a gpio_chip
5051
*/
@@ -53,6 +54,7 @@ struct pinctrl_gpio_range {
5354
const char *name;
5455
unsigned int id;
5556
unsigned int base;
57+
unsigned int pin_base;
5658
unsigned int npins;
5759
struct gpio_chip *gc;
5860
};

‎include/linux/pinctrl/pinmux.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct pinctrl_dev;
5252
* @disable: disable a certain muxing selector with a certain pin group
5353
* @gpio_request_enable: requests and enables GPIO on a certain pin.
5454
* Implement this only if you can mux every pin individually as GPIO. The
55-
* affected GPIO range is passed along with an offset into that
55+
* affected GPIO range is passed along with an offset(pin number) into that
5656
* specific GPIO range - function selectors and pin groups are orthogonal
5757
* to this, the core will however make sure the pins do not collide
5858
*/

0 commit comments

Comments
 (0)