Skip to content

Commit c85f776

Browse files
committed
dt-bindings: gpio: revise drive strength flags for generality
The documentation and design for drive strength was based on Nordic GPIO capabilities, and presumed that the default state was standard while the alternate state was high. The Semtech SX15088/SX1509B GPIO extender went the other way, with default being high and alternate being low. Rework the flags so that low and high are distinct from default. Update the two in-tree GPIO implementations that currently support drive strength to make use of these flags. Deprecate the ALT flag but define it to implement the documented selection (high drive) in case it's being used by out-of-tree systems. Signed-off-by: Peter A. Bigot <[email protected]>
1 parent c3d8936 commit c85f776

File tree

3 files changed

+89
-42
lines changed

3 files changed

+89
-42
lines changed

drivers/gpio/gpio_cc2650.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int gpio_cc2650_config_pin(int pin, int flags)
164164
if (flags & GPIO_DS_DISCONNECT_LOW) {
165165
disconnect(pin, &gpio_doe31_0_config, &iocfg_config);
166166
}
167-
if (flags & GPIO_DS_ALT_LOW) {
167+
if ((flags & GPIO_DS_LOW_MASK) == GPIO_DS_HI_LOW) {
168168
iocfg_config |= CC2650_IOC_MAX_DRIVE_STRENGTH;
169169
} else {
170170
iocfg_config |= CC2650_IOC_MIN_DRIVE_STRENGTH;

drivers/gpio/gpio_nrfx.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,31 +134,39 @@ static int gpio_nrfx_config(struct device *port, int access_op,
134134
u8_t from_pin;
135135
u8_t to_pin;
136136

137+
/* Map default selections to Nordic standard (low) */
138+
if ((flags & GPIO_DS_LOW_MASK) == GPIO_DS_DFLT_LOW) {
139+
flags |= GPIO_DS_LO_LOW;
140+
}
141+
if ((flags & GPIO_DS_HIGH_MASK) == GPIO_DS_DFLT_HIGH) {
142+
flags |= GPIO_DS_LO_HIGH;
143+
}
144+
137145
switch (flags & (GPIO_DS_LOW_MASK | GPIO_DS_HIGH_MASK)) {
138-
case GPIO_DS_DFLT_LOW | GPIO_DS_DFLT_HIGH:
146+
case GPIO_DS_LO_LOW | GPIO_DS_LO_HIGH:
139147
drive = NRF_GPIO_PIN_S0S1;
140148
break;
141-
case GPIO_DS_DFLT_LOW | GPIO_DS_ALT_HIGH:
149+
case GPIO_DS_LO_LOW | GPIO_DS_HI_HIGH:
142150
drive = NRF_GPIO_PIN_S0H1;
143151
break;
144-
case GPIO_DS_DFLT_LOW | GPIO_DS_DISCONNECT_HIGH:
152+
case GPIO_DS_LO_LOW | GPIO_DS_DISCONNECT_HIGH:
145153
drive = NRF_GPIO_PIN_S0D1;
146154
break;
147155

148-
case GPIO_DS_ALT_LOW | GPIO_DS_DFLT_HIGH:
156+
case GPIO_DS_HI_LOW | GPIO_DS_LO_HIGH:
149157
drive = NRF_GPIO_PIN_H0S1;
150158
break;
151-
case GPIO_DS_ALT_LOW | GPIO_DS_ALT_HIGH:
159+
case GPIO_DS_HI_LOW | GPIO_DS_HI_HIGH:
152160
drive = NRF_GPIO_PIN_H0H1;
153161
break;
154-
case GPIO_DS_ALT_LOW | GPIO_DS_DISCONNECT_HIGH:
162+
case GPIO_DS_HI_LOW | GPIO_DS_DISCONNECT_HIGH:
155163
drive = NRF_GPIO_PIN_H0D1;
156164
break;
157165

158-
case GPIO_DS_DISCONNECT_LOW | GPIO_DS_DFLT_HIGH:
166+
case GPIO_DS_DISCONNECT_LOW | GPIO_DS_LO_HIGH:
159167
drive = NRF_GPIO_PIN_D0S1;
160168
break;
161-
case GPIO_DS_DISCONNECT_LOW | GPIO_DS_ALT_HIGH:
169+
case GPIO_DS_DISCONNECT_LOW | GPIO_DS_HI_HIGH:
162170
drive = NRF_GPIO_PIN_D0H1;
163171
break;
164172

include/dt-bindings/gpio/gpio.h

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@
77
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_
88
#define ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_
99

10+
/*
11+
* Assigned Bit Positions
12+
*
13+
* @note: This table is intended as a convenience to summarize the bit
14+
* assignments used in the fields defined below. The GPIO_foo_SHIFT
15+
* macros are the canonical definition.
16+
*
17+
* Bit Prefix Variations
18+
* ===== ============== =======================================================
19+
* 0 GPIO_ACTIVE high or low
20+
* 1 GPIO_SIGNALING single-ended or push-pull
21+
* 2 GPIO_LINE source or drain
22+
* 3-4 GPIO_PUD pull normal/up/down
23+
* 5-8 GPIO_IO in, out, initialize, initial value
24+
* 9-13 GPIO_INT enable, level/edge, low, high, double-edge
25+
* 14 GPIO_POL polarity normal/invert
26+
* 15 GPIO_DEBOUNCE disable/enable
27+
* 16-17 GPIO_DS_LOW drive strength for output low: default/low/high/discon
28+
* 18-19 GPIO_DS_HIGH drive strength for output high: default/low/high/discon
29+
*/
30+
1031
/**
1132
* @name GPIO active level indicator.
1233
*
@@ -324,68 +345,72 @@
324345
* The drive strength of individual pins can be configured
325346
* independently for when the pin output is low and high.
326347
*
327-
* The `GPIO_DS_*_LOW` enumerations define the drive strength of a pin
348+
* The `GPIO_DS_*_LOW` bits define the drive strength of a pin
328349
* when output is low.
329-
330-
* The `GPIO_DS_*_HIGH` enumerations define the drive strength of a pin
350+
*
351+
* The `GPIO_DS_*_HIGH` bits define the drive strength of a pin
331352
* when output is high.
332353
*
333-
* The `DISCONNECT` drive strength indicates that the pin is placed in a
334-
* high impedance state and not driven, this option is used to
335-
* configure hardware that supports a open collector drive mode.
354+
* If the device does not distinguish drive strength by signal level,
355+
* the drive strength configuration from `GPIO_DS_*_LOW` shall be
356+
* used.
336357
*
337-
* The interface supports two different drive strengths:
338-
* `DFLT` - The lowest drive strength supported by the HW
339-
* `ALT` - The highest drive strength supported by the HW
358+
* The interface supports several drive strengths:
359+
* `LO` - The lowest drive strength supported by the HW
360+
* `HI` - The highest drive strength supported by the HW
361+
* `DISCONNECT` - The pin is placed in a high impedance state and not
362+
* driven (open drain mode)
340363
*
341-
* On hardware that supports only one standard drive strength, both
342-
* `DFLT` and `ALT` have the same behavior.
364+
* In addition `DFLT` represents the default drive strength for a
365+
* particular driver, and may be either `LO` or `HI`.
366+
*
367+
* On hardware that supports only one standard drive strength `LO` and
368+
* `HI` have the same behavior.
343369
*
344370
* On hardware that does not support a disconnect mode, `DISCONNECT`
345371
* will behave the same as `DFLT`.
346372
*
347373
* @{
348374
*/
349375
/** @cond INTERNAL_HIDDEN */
350-
#define GPIO_DS_LOW_POS 16
351-
#define GPIO_DS_LOW_MASK (3 << GPIO_DS_LOW_POS)
376+
#define GPIO_DS_LOW_SHIFT 16
377+
#define GPIO_DS_LOW_MASK (3 << GPIO_DS_LOW_SHIFT)
352378
/** @endcond */
353379

354-
/** Default drive strength standard when GPIO pin output is low.
355-
*/
356-
#define GPIO_DS_DFLT_LOW (0 << GPIO_DS_LOW_POS)
380+
/** Use default drive strength when GPIO pin output is low. */
381+
#define GPIO_DS_DFLT_LOW (0 << GPIO_DS_LOW_SHIFT)
357382

358-
/** Alternative drive strength when GPIO pin output is low.
359-
* For hardware that does not support configurable drive strength
360-
* use the default drive strength.
361-
*/
362-
#define GPIO_DS_ALT_LOW (1 << GPIO_DS_LOW_POS)
383+
/** Use low/reduced drive strength when GPIO pin output is low. */
384+
#define GPIO_DS_LO_LOW (1 << GPIO_DS_LOW_SHIFT)
385+
386+
/** Use high/increased drive strength when GPIO pin output is low. */
387+
#define GPIO_DS_HI_LOW (2 << GPIO_DS_LOW_SHIFT)
363388

364389
/** Disconnect pin when GPIO pin output is low.
365390
* For hardware that does not support disconnect use the default
366391
* drive strength.
367392
*/
368-
#define GPIO_DS_DISCONNECT_LOW (3 << GPIO_DS_LOW_POS)
393+
#define GPIO_DS_DISCONNECT_LOW (3 << GPIO_DS_LOW_SHIFT)
369394

370395
/** @cond INTERNAL_HIDDEN */
371-
#define GPIO_DS_HIGH_POS 18
372-
#define GPIO_DS_HIGH_MASK (3 << GPIO_DS_HIGH_POS)
396+
#define GPIO_DS_HIGH_SHIFT 18
397+
#define GPIO_DS_HIGH_MASK (3 << GPIO_DS_HIGH_SHIFT)
373398
/** @endcond */
374399

375-
/** Default drive strength when GPIO pin output is high. */
376-
#define GPIO_DS_DFLT_HIGH (0 << GPIO_DS_HIGH_POS)
400+
/** Use default drive strength when GPIO pin output is low. */
401+
#define GPIO_DS_DFLT_HIGH (0 << GPIO_DS_HIGH_SHIFT)
377402

378-
/** Alternative drive strength when GPIO pin output is high.
379-
* For hardware that does not support configurable drive strengths
380-
* use the default drive strength.
381-
*/
382-
#define GPIO_DS_ALT_HIGH (1 << GPIO_DS_HIGH_POS)
403+
/** Use low/reduced drive strength when GPIO pin output is low. */
404+
#define GPIO_DS_LO_HIGH (1 << GPIO_DS_HIGH_SHIFT)
405+
406+
/** Use high/increased drive strength when GPIO pin output is low. */
407+
#define GPIO_DS_HI_HIGH (2 << GPIO_DS_HIGH_SHIFT)
383408

384-
/** Disconnect pin when GPIO pin output is high.
409+
/** Disconnect pin when GPIO pin output is low.
385410
* For hardware that does not support disconnect use the default
386411
* drive strength.
387412
*/
388-
#define GPIO_DS_DISCONNECT_HIGH (3 << GPIO_DS_HIGH_POS)
413+
#define GPIO_DS_DISCONNECT_HIGH (3 << GPIO_DS_HIGH_SHIFT)
389414

390415
/** @} */
391416

@@ -443,6 +468,20 @@
443468
*/
444469
#define GPIO_INT GPIO_INT_ENABLE
445470

471+
/** Legacy alias identifying high drive strength when GPIO output is
472+
* low.
473+
*
474+
* @deprecated Replace with `GPIO_DS_HI_LOW`
475+
*/
476+
#define GPIO_DS_ALT_LOW GPIO_DS_HI_LOW
477+
478+
/** Legacy alias identifying high drive strength when GPIO output is
479+
* high.
480+
*
481+
* @deprecated Replace with `GPIO_DS_HI_HIGH`
482+
*/
483+
#define GPIO_DS_ALT_HIGH GPIO_DS_HI_HIGH
484+
446485
/** @} */
447486

448487
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_ */

0 commit comments

Comments
 (0)