@@ -17,14 +17,12 @@ This subsystem deals with:
17
17
Top-level interface
18
18
===================
19
19
20
- Definition of PIN CONTROLLER :
20
+ Definitions :
21
21
22
- - A pin controller is a piece of hardware, usually a set of registers, that
22
+ - A PIN CONTROLLER is a piece of hardware, usually a set of registers, that
23
23
can control PINs. It may be able to multiplex, bias, set load capacitance,
24
24
set drive strength, etc. for individual pins or groups of pins.
25
25
26
- Definition of PIN:
27
-
28
26
- PINS are equal to pads, fingers, balls or whatever packaging input or
29
27
output line you want to control and these are denoted by unsigned integers
30
28
in the range 0..maxpin. This numberspace is local to each PIN CONTROLLER, so
@@ -96,20 +94,20 @@ this in our driver:
96
94
To enable the pinctrl subsystem and the subgroups for PINMUX and PINCONF and
97
95
selected drivers, you need to select them from your machine's Kconfig entry,
98
96
since these are so tightly integrated with the machines they are used on.
99
- See arch/arm/mach-ux500/Kconfig for an example.
97
+ See `` arch/arm/mach-ux500/Kconfig `` for an example.
100
98
101
99
Pins usually have fancier names than this. You can find these in the datasheet
102
100
for your chip. Notice that the core pinctrl.h file provides a fancy macro
103
- called PINCTRL_PIN() to create the struct entries. As you can see I enumerated
104
- the pins from 0 in the upper left corner to 63 in the lower right corner.
101
+ called `` PINCTRL_PIN() `` to create the struct entries. As you can see the pins are
102
+ enumerated from 0 in the upper left corner to 63 in the lower right corner.
105
103
This enumeration was arbitrarily chosen, in practice you need to think
106
104
through your numbering system so that it matches the layout of registers
107
105
and such things in your driver, or the code may become complicated. You must
108
106
also consider matching of offsets to the GPIO ranges that may be handled by
109
107
the pin controller.
110
108
111
- For a padring with 467 pads, as opposed to actual pins, I used an enumeration
112
- like this, walking around the edge of the chip, which seems to be industry
109
+ For a padding with 467 pads, as opposed to actual pins, the enumeration will
110
+ be like this, walking around the edge of the chip, which seems to be industry
113
111
standard too (all these pads had names, too)::
114
112
115
113
@@ -133,7 +131,7 @@ on { 0, 8, 16, 24 }, and a group of pins dealing with an I2C interface on pins
133
131
on { 24, 25 }.
134
132
135
133
These two groups are presented to the pin control subsystem by implementing
136
- some generic pinctrl_ops like this:
134
+ some generic `` pinctrl_ops `` like this:
137
135
138
136
.. code-block :: c
139
137
@@ -179,7 +177,7 @@ some generic pinctrl_ops like this:
179
177
.pctlops = &foo_pctrl_ops,
180
178
};
181
179
182
- The pin control subsystem will call the .get_groups_count() function to
180
+ The pin control subsystem will call the `` .get_groups_count() `` function to
183
181
determine the total number of legal selectors, then it will call the other functions
184
182
to retrieve the name and pins of the group. Maintaining the data structure of
185
183
the groups is up to the driver, this is just a simple example - in practice you
@@ -322,15 +320,15 @@ like this:
322
320
323
321
So this complex system has one pin controller handling two different
324
322
GPIO chips. "chip a" has 16 pins and "chip b" has 8 pins. The "chip a" and
325
- "chip b" have different . pin_base, which means a start pin number of the
323
+ "chip b" have different `` pin_base `` , which means a start pin number of the
326
324
GPIO range.
327
325
328
326
The GPIO range of "chip a" starts from the GPIO base of 32 and actual
329
327
pin range also starts from 32. However "chip b" has different starting
330
328
offset for the GPIO range and pin range. The GPIO range of "chip b" starts
331
329
from GPIO number 48, while the pin range of "chip b" starts from 64.
332
330
333
- We can convert a gpio number to actual pin number using this " pin_base" .
331
+ We can convert a gpio number to actual pin number using this `` pin_base `` .
334
332
They are mapped in the global GPIO pin space at:
335
333
336
334
chip a:
@@ -357,9 +355,9 @@ numbers can be encoded in the range like this:
357
355
.gc = &chip,
358
356
};
359
357
360
- In this case the pin_base property will be ignored. If the name of a pin
358
+ In this case the `` pin_base `` property will be ignored. If the name of a pin
361
359
group is known, the pins and npins elements of the above structure can be
362
- initialised using the function pinctrl_get_group_pins(), e.g. for pin
360
+ initialised using the function `` pinctrl_get_group_pins() `` , e.g. for pin
363
361
group "foo":
364
362
365
363
.. code-block :: c
@@ -380,8 +378,8 @@ will get a pin number into its handled number range. Further it is also passed
380
378
the range ID value, so that the pin controller knows which range it should
381
379
deal with.
382
380
383
- Calling pinctrl_add_gpio_range() from pinctrl driver is DEPRECATED. Please see
384
- section 2.1 of Documentation/devicetree/bindings/gpio/gpio.txt on how to bind
381
+ Calling `` pinctrl_add_gpio_range() `` from pinctrl driver is DEPRECATED. Please see
382
+ section 2.1 of `` Documentation/devicetree/bindings/gpio/gpio.txt `` on how to bind
385
383
pinctrl and gpio drivers.
386
384
387
385
@@ -468,10 +466,10 @@ in your machine configuration. It is inspired by the clk, GPIO and regulator
468
466
subsystems, so devices will request their mux setting, but it's also possible
469
467
to request a single pin for e.g. GPIO.
470
468
471
- Definitions :
469
+ The conventions are :
472
470
473
471
- FUNCTIONS can be switched in and out by a driver residing with the pin
474
- control subsystem in the drivers/pinctrl/* directory of the kernel. The
472
+ control subsystem in the `` drivers/pinctrl `` directory of the kernel. The
475
473
pin control driver knows the possible functions. In the example above you can
476
474
identify three pinmux functions, one for spi, one for i2c and one for mmc.
477
475
@@ -573,7 +571,7 @@ is possible to perform the requested mux setting, poke the hardware so that
573
571
this happens.
574
572
575
573
Pinmux drivers are required to supply a few callback functions, some are
576
- optional. Usually the .set_mux() function is implemented, writing values into
574
+ optional. Usually the `` .set_mux() `` function is implemented, writing values into
577
575
some certain registers to activate a certain mux setting for a certain pin.
578
576
579
577
A simple driver for the above example will work by setting bits 0, 1, 2, 3, 4, or 5
@@ -699,18 +697,18 @@ Pin control interaction with the GPIO subsystem
699
697
===============================================
700
698
701
699
Note that the following implies that the use case is to use a certain pin
702
- from the Linux kernel using the API in <linux/gpio/consumer.h> with gpiod_get()
700
+ from the Linux kernel using the API in `` <linux/gpio/consumer.h> `` with gpiod_get()
703
701
and similar functions. There are cases where you may be using something
704
702
that your datasheet calls "GPIO mode", but actually is just an electrical
705
703
configuration for a certain device. See the section below named
706
704
`GPIO mode pitfalls `_ for more details on this scenario.
707
705
708
- The public pinmux API contains two functions named pinctrl_gpio_request()
709
- and pinctrl_gpio_free(). These two functions shall *ONLY * be called from
710
- gpiolib-based drivers as part of their .request() and .free() semantics.
711
- Likewise the pinctrl_gpio_direction_input()/ pinctrl_gpio_direction_output()
712
- shall only be called from within respective .direction_input() /
713
- .direction_output() gpiolib implementation.
706
+ The public pinmux API contains two functions named `` pinctrl_gpio_request() ``
707
+ and `` pinctrl_gpio_free() `` . These two functions shall *ONLY * be called from
708
+ gpiolib-based drivers as part of their `` .request() `` and `` .free() `` semantics.
709
+ Likewise the `` pinctrl_gpio_direction_input() `` / `` pinctrl_gpio_direction_output() ``
710
+ shall only be called from within respective `` .direction_input() `` /
711
+ `` .direction_output() `` gpiolib implementation.
714
712
715
713
NOTE that platforms and individual drivers shall *NOT * request GPIO pins to be
716
714
controlled e.g. muxed in. Instead, implement a proper gpiolib driver and have
@@ -724,21 +722,21 @@ In this case, the function array would become 64 entries for each GPIO
724
722
setting and then the device functions.
725
723
726
724
For this reason there are two functions a pin control driver can implement
727
- to enable only GPIO on an individual pin: .gpio_request_enable() and
728
- .gpio_disable_free().
725
+ to enable only GPIO on an individual pin: `` .gpio_request_enable() `` and
726
+ `` .gpio_disable_free() `` .
729
727
730
728
This function will pass in the affected GPIO range identified by the pin
731
729
controller core, so you know which GPIO pins are being affected by the request
732
730
operation.
733
731
734
732
If your driver needs to have an indication from the framework of whether the
735
733
GPIO pin shall be used for input or output you can implement the
736
- .gpio_set_direction() function. As described this shall be called from the
734
+ `` .gpio_set_direction() `` function. As described this shall be called from the
737
735
gpiolib driver and the affected GPIO range, pin offset and desired direction
738
736
will be passed along to this function.
739
737
740
738
Alternatively to using these special functions, it is fully allowed to use
741
- named functions for each GPIO pin, the pinctrl_gpio_request() will attempt to
739
+ named functions for each GPIO pin, the `` pinctrl_gpio_request() `` will attempt to
742
740
obtain the function "gpioN" where "N" is the global GPIO pin number if no
743
741
special GPIO-handler is registered.
744
742
@@ -751,7 +749,7 @@ is taken to mean different things than what the kernel does, the developer
751
749
may be confused by a datasheet talking about a pin being possible to set
752
750
into "GPIO mode". It appears that what hardware engineers mean with
753
751
"GPIO mode" is not necessarily the use case that is implied in the kernel
754
- interface <linux/gpio/consumer.h>: a pin that you grab from kernel code and then
752
+ interface `` <linux/gpio/consumer.h> `` : a pin that you grab from kernel code and then
755
753
either listen for input or drive high/low to assert/deassert some
756
754
external line.
757
755
@@ -857,12 +855,12 @@ pin shall be used for UART TX and GPIO at the same time, that you will grab
857
855
a pin control handle and set it to a certain state to enable UART TX to be
858
856
muxed in, then twist it over to GPIO mode and use gpiod_direction_output()
859
857
to drive it low during sleep, then mux it over to UART TX again when you
860
- wake up and maybe even gpiod_get()/ gpiod_put() as part of this cycle. This
858
+ wake up and maybe even gpiod_get() / gpiod_put() as part of this cycle. This
861
859
all gets very complicated.
862
860
863
861
The solution is to not think that what the datasheet calls "GPIO mode"
864
- has to be handled by the <linux/gpio/consumer.h> interface. Instead view this as
865
- a certain pin config setting. Look in e.g. <linux/pinctrl/pinconf-generic.h>
862
+ has to be handled by the `` <linux/gpio/consumer.h> `` interface. Instead view this as
863
+ a certain pin config setting. Look in e.g. `` <linux/pinctrl/pinconf-generic.h> ``
866
864
and you find this in the documentation:
867
865
868
866
PIN_CONFIG_OUTPUT:
@@ -1040,7 +1038,7 @@ Finally, some devices expect the mapping table to contain certain specific
1040
1038
named states. When running on hardware that doesn't need any pin controller
1041
1039
configuration, the mapping table must still contain those named states, in
1042
1040
order to explicitly indicate that the states were provided and intended to
1043
- be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining
1041
+ be empty. Table entry macro `` PIN_MAP_DUMMY_STATE() `` serves the purpose of defining
1044
1042
a named state without causing any pin controller to be programmed:
1045
1043
1046
1044
.. code-block :: c
@@ -1165,7 +1163,7 @@ Pin control requests from drivers
1165
1163
=================================
1166
1164
1167
1165
When a device driver is about to probe the device core will automatically
1168
- attempt to issue pinctrl_get_select_default() on these devices.
1166
+ attempt to issue `` pinctrl_get_select_default() `` on these devices.
1169
1167
This way driver writers do not need to add any of the boilerplate code
1170
1168
of the type found below. However when doing fine-grained state selection
1171
1169
and not using the "default" state, you may have to do some device driver
@@ -1183,8 +1181,8 @@ some cases where a driver needs to e.g. switch between different mux mappings
1183
1181
at runtime this is not possible.
1184
1182
1185
1183
A typical case is if a driver needs to switch bias of pins from normal
1186
- operation and going to sleep, moving from the PINCTRL_STATE_DEFAULT to
1187
- PINCTRL_STATE_SLEEP at runtime, re-biasing or even re-muxing pins to save
1184
+ operation and going to sleep, moving from the `` PINCTRL_STATE_DEFAULT `` to
1185
+ `` PINCTRL_STATE_SLEEP `` at runtime, re-biasing or even re-muxing pins to save
1188
1186
current in sleep mode.
1189
1187
1190
1188
A driver may request a certain control state to be activated, usually just the
@@ -1230,49 +1228,49 @@ arrangement on your bus.
1230
1228
1231
1229
The semantics of the pinctrl APIs are:
1232
1230
1233
- - pinctrl_get() is called in process context to obtain a handle to all pinctrl
1231
+ - `` pinctrl_get() `` is called in process context to obtain a handle to all pinctrl
1234
1232
information for a given client device. It will allocate a struct from the
1235
1233
kernel memory to hold the pinmux state. All mapping table parsing or similar
1236
1234
slow operations take place within this API.
1237
1235
1238
- - devm_pinctrl_get() is a variant of pinctrl_get() that causes pinctrl_put()
1236
+ - `` devm_pinctrl_get() `` is a variant of pinctrl_get() that causes `` pinctrl_put() ``
1239
1237
to be called automatically on the retrieved pointer when the associated
1240
1238
device is removed. It is recommended to use this function over plain
1241
- pinctrl_get().
1239
+ `` pinctrl_get() `` .
1242
1240
1243
- - pinctrl_lookup_state() is called in process context to obtain a handle to a
1241
+ - `` pinctrl_lookup_state() `` is called in process context to obtain a handle to a
1244
1242
specific state for a client device. This operation may be slow, too.
1245
1243
1246
- - pinctrl_select_state() programs pin controller hardware according to the
1244
+ - `` pinctrl_select_state() `` programs pin controller hardware according to the
1247
1245
definition of the state as given by the mapping table. In theory, this is a
1248
1246
fast-path operation, since it only involved blasting some register settings
1249
1247
into hardware. However, note that some pin controllers may have their
1250
1248
registers on a slow/IRQ-based bus, so client devices should not assume they
1251
- can call pinctrl_select_state() from non-blocking contexts.
1249
+ can call `` pinctrl_select_state() `` from non-blocking contexts.
1252
1250
1253
- - pinctrl_put() frees all information associated with a pinctrl handle.
1251
+ - `` pinctrl_put() `` frees all information associated with a pinctrl handle.
1254
1252
1255
- - devm_pinctrl_put() is a variant of pinctrl_put() that may be used to
1256
- explicitly destroy a pinctrl object returned by devm_pinctrl_get().
1253
+ - `` devm_pinctrl_put() `` is a variant of `` pinctrl_put() `` that may be used to
1254
+ explicitly destroy a pinctrl object returned by `` devm_pinctrl_get() `` .
1257
1255
However, use of this function will be rare, due to the automatic cleanup
1258
1256
that will occur even without calling it.
1259
1257
1260
- pinctrl_get() must be paired with a plain pinctrl_put().
1261
- pinctrl_get() may not be paired with devm_pinctrl_put().
1262
- devm_pinctrl_get() can optionally be paired with devm_pinctrl_put().
1263
- devm_pinctrl_get() may not be paired with plain pinctrl_put().
1258
+ `` pinctrl_get() `` must be paired with a plain `` pinctrl_put() `` .
1259
+ `` pinctrl_get() `` may not be paired with `` devm_pinctrl_put() `` .
1260
+ `` devm_pinctrl_get() `` can optionally be paired with `` devm_pinctrl_put() `` .
1261
+ `` devm_pinctrl_get() `` may not be paired with plain `` pinctrl_put() `` .
1264
1262
1265
1263
Usually the pin control core handled the get/put pair and call out to the
1266
1264
device drivers bookkeeping operations, like checking available functions and
1267
- the associated pins, whereas pinctrl_select_state() pass on to the pin controller
1265
+ the associated pins, whereas `` pinctrl_select_state() `` pass on to the pin controller
1268
1266
driver which takes care of activating and/or deactivating the mux setting by
1269
1267
quickly poking some registers.
1270
1268
1271
- The pins are allocated for your device when you issue the devm_pinctrl_get()
1269
+ The pins are allocated for your device when you issue the `` devm_pinctrl_get() ``
1272
1270
call, after this you should be able to see this in the debugfs listing of all
1273
1271
pins.
1274
1272
1275
- NOTE: the pinctrl system will return -EPROBE_DEFER if it cannot find the
1273
+ NOTE: the pinctrl system will return `` -EPROBE_DEFER `` if it cannot find the
1276
1274
requested pinctrl handles, for example if the pinctrl driver has not yet
1277
1275
registered. Thus make sure that the error path in your driver gracefully
1278
1276
cleans up and is ready to retry the probing later in the startup process.
@@ -1329,12 +1327,12 @@ System pin control hogging
1329
1327
==========================
1330
1328
1331
1329
Pin control map entries can be hogged by the core when the pin controller
1332
- is registered. This means that the core will attempt to call pinctrl_get(),
1333
- pinctrl_lookup_state() and pinctrl_select_state() on it immediately after
1330
+ is registered. This means that the core will attempt to call `` pinctrl_get() `` ,
1331
+ `` pinctrl_lookup_state() `` and `` pinctrl_select_state() `` on it immediately after
1334
1332
the pin control device has been registered.
1335
1333
1336
1334
This occurs for mapping table entries where the client device name is equal
1337
- to the pin controller device name, and the state name is PINCTRL_STATE_DEFAULT:
1335
+ to the pin controller device name, and the state name is `` PINCTRL_STATE_DEFAULT `` :
1338
1336
1339
1337
.. code-block :: c
1340
1338
0 commit comments