From 2c8982197d6eb56281c369b4426739cb1d8e2cb3 Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 22 Aug 2016 11:23:54 +0000 Subject: [PATCH] Implement interfaces to disable clocks and add interfaces that enable or disable all clocks for a device. The latter interfaces are useful for devices that have multiple clocks that don't have specific names/purposes such as sxiahci(4). --- sys/dev/ofw/ofw_clock.c | 42 ++++++++++++++++++++++++++++++++--------- sys/dev/ofw/ofw_clock.h | 16 +++++++++++++++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/sys/dev/ofw/ofw_clock.c b/sys/dev/ofw/ofw_clock.c index 0159d48a84c..a0ec43a2406 100644 --- a/sys/dev/ofw/ofw_clock.c +++ b/sys/dev/ofw/ofw_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_clock.c,v 1.1 2016/08/21 21:38:05 kettenis Exp $ */ +/* $OpenBSD: ofw_clock.c,v 1.2 2016/08/22 11:23:54 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -71,7 +71,7 @@ clock_get_frequency_cells(uint32_t *cells) } void -clock_enable_cells(uint32_t *cells) +clock_enable_cells(uint32_t *cells, int on) { struct clock_device *cd; uint32_t phandle = cells[0]; @@ -82,7 +82,7 @@ clock_enable_cells(uint32_t *cells) } if (cd && cd->cd_enable) - cd->cd_enable(cd->cd_cookie, &cells[1], 1); + cd->cd_enable(cd->cd_cookie, &cells[1], on); } uint32_t * @@ -173,7 +173,7 @@ clock_get_frequency(int node, const char *name) } void -clock_enable_idx(int node, int idx) +clock_do_enable_idx(int node, int idx, int on) { uint32_t *clocks; uint32_t *clock; @@ -188,10 +188,10 @@ clock_enable_idx(int node, int idx) clock = clocks; while (clock && clock < clocks + (len / sizeof(uint32_t))) { - if (idx == 0) { - clock_enable_cells(clock); + if (idx <= 0) + clock_enable_cells(clock, on); + if (idx == 0) break; - } clock = clock_next_clock(clock); idx--; } @@ -200,7 +200,7 @@ clock_enable_idx(int node, int idx) } void -clock_enable(int node, const char *name) +clock_do_enable(int node, const char *name, int on) { int idx; @@ -208,5 +208,29 @@ clock_enable(int node, const char *name) if (idx == -1) return; - clock_enable_idx(node, idx); + clock_do_enable_idx(node, idx, on); +} + +void +clock_enable_idx(int node, int idx) +{ + clock_do_enable_idx(node, idx, 1); +} + +void +clock_enable(int node, const char *name) +{ + clock_do_enable(node, name, 1); +} + +void +clock_disable_idx(int node, int idx) +{ + clock_do_enable_idx(node, idx, 0); +} + +void +clock_disable(int node, const char *name) +{ + clock_do_enable(node, name, 0); } diff --git a/sys/dev/ofw/ofw_clock.h b/sys/dev/ofw/ofw_clock.h index eaa4143453c..d67f959ba41 100644 --- a/sys/dev/ofw/ofw_clock.h +++ b/sys/dev/ofw/ofw_clock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_clock.h,v 1.1 2016/08/21 21:38:05 kettenis Exp $ */ +/* $OpenBSD: ofw_clock.h,v 1.2 2016/08/22 11:23:54 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -35,5 +35,19 @@ uint32_t clock_get_frequency(int, const char *); uint32_t clock_get_frequency_idx(int, int); void clock_enable(int, const char *); void clock_enable_idx(int, int); +void clock_disable(int, const char *); +void clock_disable_idx(int, int); + +static inline void +clock_enable_all(int node) +{ + clock_enable_idx(node, -1); +} + +static inline void +clock_disable_all(int node) +{ + clock_disable_idx(node, -1); +} #endif /* _DEV_OFW_CLOCK_H_ */ -- 2.20.1