aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2011-11-11 04:47:58 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-01-03 03:10:01 -0500
commit3c739ad0df5eb41cd7adad879eda6aa09879eb76 (patch)
tree4ab739e639373a18ca993b26b6c18ace7edee9e2
parent33d58949adee5086478e140751e4a7263bd7e207 (diff)
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>
-rw-r--r--Documentation/pinctrl.txt48
-rw-r--r--drivers/pinctrl/pinmux-sirf.c6
-rw-r--r--drivers/pinctrl/pinmux-u300.c1
-rw-r--r--drivers/pinctrl/pinmux.c4
-rw-r--r--include/linux/pinctrl/pinctrl.h2
-rw-r--r--include/linux/pinctrl/pinmux.h2
6 files changed, 34 insertions, 29 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index 0a8b2250062a..43ba411d1571 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -214,19 +214,20 @@ static struct pinctrl_gpio_range gpio_range_a = {
214 .name = "chip a", 214 .name = "chip a",
215 .id = 0, 215 .id = 0,
216 .base = 32, 216 .base = 32,
217 .pin_base = 32,
217 .npins = 16, 218 .npins = 16,
218 .gc = &chip_a; 219 .gc = &chip_a;
219}; 220};
220 221
221static struct pinctrl_gpio_range gpio_range_a = { 222static struct pinctrl_gpio_range gpio_range_b = {
222 .name = "chip b", 223 .name = "chip b",
223 .id = 0, 224 .id = 0,
224 .base = 48, 225 .base = 48,
226 .pin_base = 64,
225 .npins = 8, 227 .npins = 8,
226 .gc = &chip_b; 228 .gc = &chip_b;
227}; 229};
228 230
229
230{ 231{
231 struct pinctrl_dev *pctl; 232 struct pinctrl_dev *pctl;
232 ... 233 ...
@@ -235,11 +236,24 @@ static struct pinctrl_gpio_range gpio_range_a = {
235} 236}
236 237
237So this complex system has one pin controller handling two different 238So this complex system has one pin controller handling two different
238GPIO chips. Chip a has 16 pins and chip b has 8 pins. They are mapped in 239GPIO chips. "chip a" has 16 pins and "chip b" has 8 pins. The "chip a" and
239the global GPIO pin space at: 240"chip b" have different .pin_base, which means a start pin number of the
241GPIO range.
242
243The GPIO range of "chip a" starts from the GPIO base of 32 and actual
244pin range also starts from 32. However "chip b" has different starting
245offset for the GPIO range and pin range. The GPIO range of "chip b" starts
246from GPIO number 48, while the pin range of "chip b" starts from 64.
240 247
241chip a: [32 .. 47] 248We can convert a gpio number to actual pin number using this "pin_base".
242chip b: [48 .. 55] 249They are mapped in the global GPIO pin space at:
250
251chip a:
252 - GPIO range : [32 .. 47]
253 - pin range : [32 .. 47]
254chip b:
255 - GPIO range : [48 .. 55]
256 - pin range : [64 .. 71]
243 257
244When GPIO-specific functions in the pin control subsystem are called, these 258When GPIO-specific functions in the pin control subsystem are called, these
245ranges will be used to look up the appropriate pin controller by inspecting 259ranges will be used to look up the appropriate pin controller by inspecting
@@ -249,28 +263,12 @@ will be called on that specific pin controller.
249 263
250For all functionalities dealing with pin biasing, pin muxing etc, the pin 264For all functionalities dealing with pin biasing, pin muxing etc, the pin
251controller subsystem will subtract the range's .base offset from the passed 265controller subsystem will subtract the range's .base offset from the passed
252in gpio pin number, and pass that on to the pin control driver, so the driver 266in gpio number, and add the ranges's .pin_base offset to retrive a pin number.
253will get an offset into its handled number range. Further it is also passed 267After that, the subsystem passes it on to the pin control driver, so the driver
268will get an pin number into its handled number range. Further it is also passed
254the range ID value, so that the pin controller knows which range it should 269the range ID value, so that the pin controller knows which range it should
255deal with. 270deal with.
256 271
257For example: if a user issues pinctrl_gpio_set_foo(50), the pin control
258subsystem will find that the second range on this pin controller matches,
259subtract the base 48 and call the
260pinctrl_driver_gpio_set_foo(pinctrl, range, 2) where the latter function has
261this signature:
262
263int pinctrl_driver_gpio_set_foo(struct pinctrl_dev *pctldev,
264 struct pinctrl_gpio_range *rangeid,
265 unsigned offset);
266
267Now the driver knows that we want to do some GPIO-specific operation on the
268second 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
271pin space, this mapping will need to be augmented accordingly.)
272
273
274PINMUX interfaces 272PINMUX interfaces
275================= 273=================
276 274
diff --git a/drivers/pinctrl/pinmux-sirf.c b/drivers/pinctrl/pinmux-sirf.c
index d848d9764378..99e688e07ea0 100644
--- a/drivers/pinctrl/pinmux-sirf.c
+++ b/drivers/pinctrl/pinmux-sirf.c
@@ -1067,7 +1067,7 @@ static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev,
1067 spmx = pinctrl_dev_get_drvdata(pmxdev); 1067 spmx = pinctrl_dev_get_drvdata(pmxdev);
1068 1068
1069 muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group)); 1069 muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
1070 muxval = muxval | (1 << offset); 1070 muxval = muxval | (1 << (offset - range->pin_base));
1071 writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group)); 1071 writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
1072 1072
1073 return 0; 1073 return 0;
@@ -1100,21 +1100,25 @@ static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
1100 .name = "sirfsoc-gpio*", 1100 .name = "sirfsoc-gpio*",
1101 .id = 0, 1101 .id = 0,
1102 .base = 0, 1102 .base = 0,
1103 .pin_base = 0,
1103 .npins = 32, 1104 .npins = 32,
1104 }, { 1105 }, {
1105 .name = "sirfsoc-gpio*", 1106 .name = "sirfsoc-gpio*",
1106 .id = 1, 1107 .id = 1,
1107 .base = 32, 1108 .base = 32,
1109 .pin_base = 32,
1108 .npins = 32, 1110 .npins = 32,
1109 }, { 1111 }, {
1110 .name = "sirfsoc-gpio*", 1112 .name = "sirfsoc-gpio*",
1111 .id = 2, 1113 .id = 2,
1112 .base = 64, 1114 .base = 64,
1115 .pin_base = 64,
1113 .npins = 32, 1116 .npins = 32,
1114 }, { 1117 }, {
1115 .name = "sirfsoc-gpio*", 1118 .name = "sirfsoc-gpio*",
1116 .id = 3, 1119 .id = 3,
1117 .base = 96, 1120 .base = 96,
1121 .pin_base = 96,
1118 .npins = 19, 1122 .npins = 19,
1119 }, 1123 },
1120}; 1124};
diff --git a/drivers/pinctrl/pinmux-u300.c b/drivers/pinctrl/pinmux-u300.c
index 145a84dc16e6..bcf61bee7763 100644
--- a/drivers/pinctrl/pinmux-u300.c
+++ b/drivers/pinctrl/pinmux-u300.c
@@ -1026,6 +1026,7 @@ static struct pinctrl_gpio_range u300_gpio_range = {
1026 .name = "COH901*", 1026 .name = "COH901*",
1027 .id = 0, 1027 .id = 0,
1028 .base = 0, 1028 .base = 0,
1029 .pin_base = 0,
1029 .npins = 64, 1030 .npins = 64,
1030}; 1031};
1031 1032
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index ee3aba78c3dd..92aa13ee2208 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -229,7 +229,7 @@ int pinmux_request_gpio(unsigned gpio)
229 return -EINVAL; 229 return -EINVAL;
230 230
231 /* Convert to the pin controllers number space */ 231 /* Convert to the pin controllers number space */
232 pin = gpio - range->base; 232 pin = gpio - range->base + range->pin_base;
233 233
234 /* Conjure some name stating what chip and pin this is taken by */ 234 /* Conjure some name stating what chip and pin this is taken by */
235 snprintf(gpiostr, 15, "%s:%d", range->name, gpio); 235 snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
@@ -263,7 +263,7 @@ void pinmux_free_gpio(unsigned gpio)
263 return; 263 return;
264 264
265 /* Convert to the pin controllers number space */ 265 /* Convert to the pin controllers number space */
266 pin = gpio - range->base; 266 pin = gpio - range->base + range->pin_base;
267 267
268 func = pin_free(pctldev, pin, range); 268 func = pin_free(pctldev, pin, range);
269 kfree(func); 269 kfree(func);
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 04c011038f32..f17fac4b51f1 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -45,6 +45,7 @@ struct pinctrl_pin_desc {
45 * @name: a name for the chip in this range 45 * @name: a name for the chip in this range
46 * @id: an ID number for the chip in this range 46 * @id: an ID number for the chip in this range
47 * @base: base offset of the GPIO range 47 * @base: base offset of the GPIO range
48 * @pin_base: base pin number of the GPIO range
48 * @npins: number of pins in the GPIO range, including the base number 49 * @npins: number of pins in the GPIO range, including the base number
49 * @gc: an optional pointer to a gpio_chip 50 * @gc: an optional pointer to a gpio_chip
50 */ 51 */
@@ -53,6 +54,7 @@ struct pinctrl_gpio_range {
53 const char *name; 54 const char *name;
54 unsigned int id; 55 unsigned int id;
55 unsigned int base; 56 unsigned int base;
57 unsigned int pin_base;
56 unsigned int npins; 58 unsigned int npins;
57 struct gpio_chip *gc; 59 struct gpio_chip *gc;
58}; 60};
diff --git a/include/linux/pinctrl/pinmux.h b/include/linux/pinctrl/pinmux.h
index 350e32a98c6a..bb7a9792f1ea 100644
--- a/include/linux/pinctrl/pinmux.h
+++ b/include/linux/pinctrl/pinmux.h
@@ -52,7 +52,7 @@ struct pinctrl_dev;
52 * @disable: disable a certain muxing selector with a certain pin group 52 * @disable: disable a certain muxing selector with a certain pin group
53 * @gpio_request_enable: requests and enables GPIO on a certain pin. 53 * @gpio_request_enable: requests and enables GPIO on a certain pin.
54 * Implement this only if you can mux every pin individually as GPIO. The 54 * 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
56 * specific GPIO range - function selectors and pin groups are orthogonal 56 * specific GPIO range - function selectors and pin groups are orthogonal
57 * to this, the core will however make sure the pins do not collide 57 * to this, the core will however make sure the pins do not collide
58 */ 58 */