From 876cd45bcb8d9efb58545779477d040b6f08e27f Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 18 Dec 2017 09:13:47 +0000 Subject: [PATCH] Add support for enabling registered regulators. Make sure that we leave regulators with a "regulator-always-on" property alone. ok patrick@ --- sys/dev/ofw/ofw_regulator.c | 40 +++++++++++++++++++++++++++---------- sys/dev/ofw/ofw_regulator.h | 3 ++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/sys/dev/ofw/ofw_regulator.c b/sys/dev/ofw/ofw_regulator.c index efd720a6979..d941887a23f 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.3 2017/12/16 21:12:03 kettenis Exp $ */ +/* $OpenBSD: ofw_regulator.c,v 1.4 2017/12/18 09:13:47 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -50,21 +50,13 @@ regulator_register(struct regulator_device *rd) } int -regulator_set(uint32_t phandle, int enable) +regulator_fixed_set(int node, int enable) { uint32_t *gpio; uint32_t startup_delay; int active; - int node; int len; - node = OF_getnodebyphandle(phandle); - if (node == 0) - return -1; - - if (!OF_is_compatible(node, "regulator-fixed")) - return -1; - pinctrl_byname(node, "default"); if (OF_getproplen(node, "enable-active-high") == 0) @@ -93,6 +85,34 @@ regulator_set(uint32_t phandle, int enable) return 0; } +int +regulator_set(uint32_t phandle, int enable) +{ + struct regulator_device *rd; + int node; + + node = OF_getnodebyphandle(phandle); + if (node == 0) + return ENODEV; + + /* Don't mess around with regulators that are always on. */ + if (OF_getproplen(node, "regulator-always-on") == 0) + return 0; + + LIST_FOREACH(rd, ®ulator_devices, rd_list) { + if (rd->rd_phandle == phandle) + break; + } + + if (rd && rd->rd_enable) + return rd->rd_enable(rd->rd_cookie, enable); + + if (OF_is_compatible(node, "regulator-fixed")) + return regulator_fixed_set(node, enable); + + return ENODEV; +} + int regulator_enable(uint32_t phandle) { diff --git a/sys/dev/ofw/ofw_regulator.h b/sys/dev/ofw/ofw_regulator.h index 006ecfa0dc4..80bb0a45df4 100644 --- a/sys/dev/ofw/ofw_regulator.h +++ b/sys/dev/ofw/ofw_regulator.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_regulator.h,v 1.4 2017/12/16 21:12:03 kettenis Exp $ */ +/* $OpenBSD: ofw_regulator.h,v 1.5 2017/12/18 09:13:47 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -23,6 +23,7 @@ struct regulator_device { void *rd_cookie; uint32_t (*rd_get_voltage)(void *); int (*rd_set_voltage)(void *, uint32_t); + int (*rd_enable)(void *, int); uint32_t rd_min, rd_max; -- 2.20.1