]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/clk.h
arc/cache: really do invalidate_dcache_all() even if IOC exists
[people/ms/u-boot.git] / include / clk.h
CommitLineData
f26c8a8e
SG
1/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
08d0d6f3
MS
8#ifndef _CLK_H_
9#define _CLK_H_
10
e70cc438 11#include <errno.h>
ad1cf785
MY
12#include <linux/types.h>
13
14struct udevice;
15
08d0d6f3
MS
16int soc_clk_dump(void);
17
f26c8a8e
SG
18struct clk_ops {
19 /**
20 * get_rate() - Get current clock rate
21 *
22 * @dev: Device to check (UCLASS_CLK)
23 * @return clock rate in Hz, or -ve error code
24 */
25 ulong (*get_rate)(struct udevice *dev);
26
27 /**
28 * set_rate() - Set current clock rate
29 *
30 * @dev: Device to adjust
31 * @rate: New clock rate in Hz
32 * @return new rate, or -ve error code
33 */
34 ulong (*set_rate)(struct udevice *dev, ulong rate);
35
f0e07516
MY
36 /**
37 * enable() - Enable the clock for a peripheral
38 *
39 * @dev: clock provider
40 * @periph: Peripheral ID to enable
41 * @return zero on success, or -ve error code
42 */
43 int (*enable)(struct udevice *dev, int periph);
44
f26c8a8e 45 /**
8bdf9cfd
MY
46 * get_periph_rate() - Get clock rate for a peripheral
47 *
48 * @dev: Device to check (UCLASS_CLK)
49 * @periph: Peripheral ID to check
50 * @return clock rate in Hz, or -ve error code
51 */
f26c8a8e
SG
52 ulong (*get_periph_rate)(struct udevice *dev, int periph);
53
54 /**
8bdf9cfd 55 * set_periph_rate() - Set current clock rate for a peripheral
f26c8a8e
SG
56 *
57 * @dev: Device to update (UCLASS_CLK)
8bdf9cfd 58 * @periph: Peripheral ID to update
f26c8a8e
SG
59 * @return new clock rate in Hz, or -ve error code
60 */
61 ulong (*set_periph_rate)(struct udevice *dev, int periph, ulong rate);
62};
63
64#define clk_get_ops(dev) ((struct clk_ops *)(dev)->driver->ops)
65
66/**
67 * clk_get_rate() - Get current clock rate
68 *
69 * @dev: Device to check (UCLASS_CLK)
70 * @return clock rate in Hz, or -ve error code
71 */
72ulong clk_get_rate(struct udevice *dev);
73
74/**
8bdf9cfd 75 * clk_set_rate() - Set current clock rate
f26c8a8e
SG
76 *
77 * @dev: Device to adjust
78 * @rate: New clock rate in Hz
79 * @return new rate, or -ve error code
80 */
81ulong clk_set_rate(struct udevice *dev, ulong rate);
82
f0e07516
MY
83/**
84 * clk_enable() - Enable the clock for a peripheral
85 *
86 * @dev: clock provider
87 * @periph: Peripheral ID to enable
88 * @return zero on success, or -ve error code
89 */
90int clk_enable(struct udevice *dev, int periph);
91
f26c8a8e
SG
92/**
93 * clk_get_periph_rate() - Get current clock rate for a peripheral
94 *
95 * @dev: Device to check (UCLASS_CLK)
96 * @return clock rate in Hz, -ve error code
97 */
98ulong clk_get_periph_rate(struct udevice *dev, int periph);
99
100/**
101 * clk_set_periph_rate() - Set current clock rate for a peripheral
102 *
103 * @dev: Device to update (UCLASS_CLK)
8bdf9cfd 104 * @periph: Peripheral ID to update
f26c8a8e
SG
105 * @return new clock rate in Hz, or -ve error code
106 */
107ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
108
e70cc438
SG
109#if CONFIG_IS_ENABLED(OF_CONTROL)
110/**
111 * clk_get_by_index() - look up a clock referenced by a device
112 *
113 * Parse a device's 'clocks' list, returning information on the indexed clock,
114 * ensuring that it is activated.
115 *
116 * @dev: Device containing the clock reference
117 * @index: Clock index to return (0 = first)
118 * @clk_devp: Returns clock device
119 * @return: Peripheral ID for the device to control. This is the first
120 * argument after the clock node phandle. If there is no arguemnt,
121 * returns 0. Return -ve error code on any error
122 */
123int clk_get_by_index(struct udevice *dev, int index, struct udevice **clk_devp);
124#else
125static inline int clk_get_by_index(struct udevice *dev, int index,
126 struct udevice **clk_devp)
127{
128 return -ENOSYS;
129}
130#endif
131
08d0d6f3 132#endif /* _CLK_H_ */