1 /* $OpenBSD: ofw_clock.h,v 1.5 2016/08/23 21:30:18 kettenis Exp $ */ 2 /* 3 * Copyright (c) 2016 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _DEV_OFW_CLOCK_H_ 19 #define _DEV_OFW_CLOCK_H_ 20 21 struct clock_device { 22 int cd_node; 23 void *cd_cookie; 24 uint32_t (*cd_get_frequency)(void *, uint32_t *); 25 int (*cd_set_frequency)(void *, uint32_t *, uint32_t); 26 void (*cd_enable)(void *, uint32_t *, int); 27 28 LIST_ENTRY(clock_device) cd_list; 29 uint32_t cd_phandle; 30 uint32_t cd_cells; 31 }; 32 33 void clock_register(struct clock_device *); 34 35 uint32_t clock_get_frequency(int, const char *); 36 uint32_t clock_get_frequency_idx(int, int); 37 int clock_set_frequency(int, const char *, uint32_t); 38 void clock_enable(int, const char *); 39 void clock_enable_idx(int, int); 40 void clock_disable(int, const char *); 41 void clock_disable_idx(int, int); 42 43 static inline void 44 clock_enable_all(int node) 45 { 46 clock_enable_idx(node, -1); 47 } 48 49 static inline void 50 clock_disable_all(int node) 51 { 52 clock_disable_idx(node, -1); 53 } 54 55 struct reset_device { 56 int rd_node; 57 void *rd_cookie; 58 void (*rd_reset)(void *, uint32_t *, int); 59 60 LIST_ENTRY(reset_device) rd_list; 61 uint32_t rd_phandle; 62 uint32_t rd_cells; 63 }; 64 65 void reset_register(struct reset_device *); 66 67 void reset_assert(int, const char *); 68 void reset_assert_idx(int, int); 69 void reset_deassert(int, const char *); 70 void reset_deassert_idx(int, int); 71 72 static inline void 73 reset_assert_all(int node) 74 { 75 reset_assert_idx(node, -1); 76 } 77 78 static inline void 79 reset_deassert_all(int node) 80 { 81 reset_deassert_idx(node, -1); 82 } 83 84 #endif /* _DEV_OFW_CLOCK_H_ */ 85