blob: ca20c3dd27c1c5de8a66c3049c6d042e2b05d433 [file] [log] [blame]
Simon Glassf26c8a82015-06-23 15:39:15 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
Michal Simek08d0d6f2013-11-21 13:39:02 -08008#ifndef _CLK_H_
9#define _CLK_H_
10
Simon Glasse70cc432016-01-20 19:43:02 -070011#include <errno.h>
Masahiro Yamadaad1cf782016-01-13 13:16:09 +090012#include <linux/types.h>
13
14struct udevice;
15
Michal Simek08d0d6f2013-11-21 13:39:02 -080016int soc_clk_dump(void);
17
Simon Glassf26c8a82015-06-23 15:39:15 -060018struct 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
36 /**
Masahiro Yamadaf0e07512016-01-13 13:16:12 +090037 * 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
45 /**
Masahiro Yamada8bdf9cf2016-01-13 13:16:08 +090046 * 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 */
Simon Glassf26c8a82015-06-23 15:39:15 -060052 ulong (*get_periph_rate)(struct udevice *dev, int periph);
53
54 /**
Masahiro Yamada8bdf9cf2016-01-13 13:16:08 +090055 * set_periph_rate() - Set current clock rate for a peripheral
Simon Glassf26c8a82015-06-23 15:39:15 -060056 *
57 * @dev: Device to update (UCLASS_CLK)
Masahiro Yamada8bdf9cf2016-01-13 13:16:08 +090058 * @periph: Peripheral ID to update
Simon Glassf26c8a82015-06-23 15:39:15 -060059 * @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/**
Masahiro Yamada8bdf9cf2016-01-13 13:16:08 +090075 * clk_set_rate() - Set current clock rate
Simon Glassf26c8a82015-06-23 15:39:15 -060076 *
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
83/**
Masahiro Yamadaf0e07512016-01-13 13:16:12 +090084 * 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
92/**
Simon Glassf26c8a82015-06-23 15:39:15 -060093 * 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)
Masahiro Yamada8bdf9cf2016-01-13 13:16:08 +0900104 * @periph: Peripheral ID to update
Simon Glassf26c8a82015-06-23 15:39:15 -0600105 * @return new clock rate in Hz, or -ve error code
106 */
107ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
108
Simon Glasse70cc432016-01-20 19:43:02 -0700109#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
Michal Simek08d0d6f2013-11-21 13:39:02 -0800132#endif /* _CLK_H_ */