summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-02-22 10:39:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-02-22 10:39:39 +0100
commite59a93e1d5689ae174051f4179f3a8a283492f46 (patch)
treed9938ce3c87eab8b88e27e1c72f3b790bc18eb97 /drivers
parent9eff9ce48c2e2398a52f0d9d572c0a15f1a50de9 (diff)
parent87d6abb654b993948a9eea2169ffe7d5fc631154 (diff)
downloadbarebox-e59a93e1d5689ae174051f4179f3a8a283492f46.tar.gz
barebox-e59a93e1d5689ae174051f4179f3a8a283492f46.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/overlay.c11
-rw-r--r--drivers/usb/otg/otgdev.c63
-rw-r--r--drivers/watchdog/wd_core.c29
3 files changed, 80 insertions, 23 deletions
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 8bf632c1e7..8f4ee3f0a2 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -109,7 +109,7 @@ static char *of_overlay_fix_path(struct device_node *root,
}
static void of_overlay_apply_symbols(struct device_node *root,
- struct device_node *overlay)
+ struct device_node *overlay)
{
const char *old_path;
char *new_path;
@@ -120,8 +120,13 @@ static void of_overlay_apply_symbols(struct device_node *root,
root_symbols = of_get_child_by_name(root, "__symbols__");
overlay_symbols = of_get_child_by_name(overlay, "__symbols__");
- if (!overlay_symbols || !root_symbols) {
- pr_info("overlay/root doesn't have a __symbols__ node\n");
+ if (!overlay_symbols) {
+ pr_debug("overlay doesn't have a __symbols__ node\n");
+ return;
+ }
+
+ if (!root_symbols) {
+ pr_info("root doesn't have a __symbols__ node\n");
return;
}
diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index 52f43b75d2..c233315d91 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -4,28 +4,33 @@
#include <driver.h>
#include <usb/usb.h>
-static int (*set_mode_callback)(void *ctx, enum usb_dr_mode mode);
-static unsigned int otg_mode;
+struct otg_mode {
+ struct device_d dev;
+ unsigned int var_mode;
+ unsigned int cur_mode;
+ int (*set_mode_callback)(void *ctx, enum usb_dr_mode mode);
+ void *ctx;
+};
static int otg_set_mode(struct param_d *param, void *ctx)
{
- static int cur_mode = USB_DR_MODE_OTG;
+ struct otg_mode *otg = ctx;
int ret;
- if (otg_mode == USB_DR_MODE_UNKNOWN)
+ if (otg->var_mode == USB_DR_MODE_UNKNOWN)
return -EINVAL;
- if (otg_mode == cur_mode)
+ if (otg->var_mode == otg->cur_mode)
return 0;
- if (cur_mode != USB_DR_MODE_OTG)
+ if (otg->cur_mode != USB_DR_MODE_OTG)
return -EBUSY;
- ret = set_mode_callback(ctx, otg_mode);
+ ret = otg->set_mode_callback(otg->ctx, otg->var_mode);
if (ret)
return ret;
- cur_mode = otg_mode;
+ otg->cur_mode = otg->var_mode;
return 0;
}
@@ -47,20 +52,38 @@ int usb_register_otg_device(struct device_d *parent,
{
int ret;
struct param_d *param_mode;
-
- if (otg_device.parent)
- return -EBUSY;
-
- otg_device.parent = parent;
- set_mode_callback = set_mode;
- otg_mode = USB_DR_MODE_OTG;
-
- ret = register_device(&otg_device);
+ struct otg_mode *otg;
+
+ otg = xzalloc(sizeof(*otg));
+ otg->dev.priv = otg;
+ otg->dev.parent = parent;
+ otg->dev.id = DEVICE_ID_DYNAMIC;
+ dev_set_name(&otg->dev, "otg");
+
+ otg->var_mode = USB_DR_MODE_OTG;
+ otg->cur_mode = USB_DR_MODE_OTG;
+ otg->set_mode_callback = set_mode;
+ otg->ctx = ctx;
+
+ /* register otg.mode as an alias of otg0.mode */
+ if (otg_device.parent == NULL) {
+ otg_device.parent = parent;
+ ret = register_device(&otg_device);
+ if (ret)
+ return ret;
+
+ param_mode = dev_add_param_enum(&otg_device, "mode",
+ otg_set_mode, NULL, &otg->var_mode,
+ otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
+ }
+
+ ret = register_device(&otg->dev);
if (ret)
return ret;
- param_mode = dev_add_param_enum(&otg_device, "mode",
- otg_set_mode, NULL, &otg_mode,
- otg_mode_names, ARRAY_SIZE(otg_mode_names), ctx);
+ param_mode = dev_add_param_enum(&otg->dev, "mode",
+ otg_set_mode, NULL, &otg->var_mode,
+ otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
+
return PTR_ERR_OR_ZERO(param_mode);
}
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 643c53268f..4b0ee31d5b 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -54,6 +54,9 @@ int watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
if (ret)
return ret;
+ wd->last_ping = get_time_ns();
+ wd->timeout_cur = timeout;
+
wd->running = timeout ? WDOG_HW_RUNNING : WDOG_HW_NOT_RUNNING;
return 0;
@@ -155,6 +158,25 @@ static unsigned int dev_get_watchdog_priority(struct device_d *dev)
return priority;
}
+static int seconds_to_expire_get(struct param_d *p, void *priv)
+{
+ struct watchdog *wd = priv;
+ uint64_t diff;
+
+ if (!wd->timeout_cur) {
+ wd->seconds_to_expire = -1;
+ return 0;
+ }
+
+ diff = get_time_ns() - wd->last_ping;
+
+ do_div(diff, 1000000000);
+
+ wd->seconds_to_expire = wd->timeout_cur - diff;
+
+ return 0;
+}
+
int watchdog_register(struct watchdog *wd)
{
struct param_d *p;
@@ -218,6 +240,13 @@ int watchdog_register(struct watchdog *wd)
goto error_unregister;
}
+ p = dev_add_param_uint32(&wd->dev, "seconds_to_expire", param_set_readonly,
+ seconds_to_expire_get, &wd->seconds_to_expire, "%d", wd);
+ if (IS_ERR(p)) {
+ ret = PTR_ERR(p);
+ goto error_unregister;
+ }
+
list_add_tail(&wd->list, &watchdog_list);
pr_debug("registering watchdog %s with priority %d\n", watchdog_name(wd),