summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-12-23 11:58:37 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-12-23 11:58:37 +0000
commitef1573e3026a767195ac143e386d05e71651f533 (patch)
treec67ab375776296578d2e2a44cd30d768af006629
parent12bbb7ecf6de74a23725b41d4420a4dc8762df5f (diff)
Fix regulators that use "active-low" polarity. Our implementation now
ignores the presence "enable-active-high" property and relies on the encode polarity of the GPIO in the flags in the device tree instead. This might not be the case for older device trees; such device trees should be fixed. ok patrick@
-rw-r--r--sys/dev/ofw/ofw_regulator.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/dev/ofw/ofw_regulator.c b/sys/dev/ofw/ofw_regulator.c
index 645c3d0136e..bb0d6399451 100644
--- a/sys/dev/ofw/ofw_regulator.c
+++ b/sys/dev/ofw/ofw_regulator.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_regulator.c,v 1.14 2020/06/06 16:59:43 patrick Exp $ */
+/* $OpenBSD: ofw_regulator.c,v 1.15 2020/12/23 11:58:36 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -92,28 +92,35 @@ regulator_fixed_set(int node, int enable)
{
uint32_t *gpio;
uint32_t startup_delay;
- int active;
int len;
pinctrl_byname(node, "default");
- if (OF_getproplen(node, "enable-active-high") == 0)
- active = 1;
- else
- active = 0;
-
/* The "gpio" property is optional. */
len = OF_getproplen(node, "gpio");
if (len < 0)
return 0;
+ /*
+ * We deliberately ignore the "enable-active-high" property
+ * here. Its presence (or absence) is used to override the
+ * polarity encoded by the GPIO flags in the device tree. But
+ * supporting this behaviour is awkward since it would require
+ * interpreting the GPIO flags here which would be a layer
+ * violation since those flags may be driver-specific. In
+ * practice the presence of "enable-active-high" is always
+ * aligned with the polarity encoded by the GPIO flags and any
+ * discrepancy is considered to be a bug by the Linux device
+ * tree maintainers.
+ */
+
gpio = malloc(len, M_TEMP, M_WAITOK);
OF_getpropintarray(node, "gpio", gpio, len);
gpio_controller_config_pin(gpio, GPIO_CONFIG_OUTPUT);
if (enable)
- gpio_controller_set_pin(gpio, active);
+ gpio_controller_set_pin(gpio, 1);
else
- gpio_controller_set_pin(gpio, !active);
+ gpio_controller_set_pin(gpio, 0);
free(gpio, M_TEMP, len);
startup_delay = OF_getpropint(node, "startup-delay-us", 0);