4 * \brief Generic clock management
\r
6 * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved.
\r
12 * Redistribution and use in source and binary forms, with or without
\r
13 * modification, are permitted provided that the following conditions are met:
\r
15 * 1. Redistributions of source code must retain the above copyright notice,
\r
16 * this list of conditions and the following disclaimer.
\r
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
19 * this list of conditions and the following disclaimer in the documentation
\r
20 * and/or other materials provided with the distribution.
\r
22 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
23 * from this software without specific prior written permission.
\r
25 * 4. This software may only be redistributed and used in connection with an
\r
26 * Atmel microcontroller product.
\r
28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
38 * POSSIBILITY OF SUCH DAMAGE.
\r
44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
\r
46 #ifndef CLK_GENCLK_H_INCLUDED
\r
47 #define CLK_GENCLK_H_INCLUDED
\r
52 # include "sam3s/genclk.h"
\r
54 # include "sam3u/genclk.h"
\r
56 # include "sam3n/genclk.h"
\r
58 # include "sam3x/genclk.h"
\r
60 # include "sam4s/genclk.h"
\r
62 # include "sam4l/genclk.h"
\r
64 # include "sam4e/genclk.h"
\r
66 # include "sam4n/genclk.h"
\r
68 # include "sam4c/genclk.h"
\r
70 # include "sam4cm/genclk.h"
\r
72 # include "sam4cp/genclk.h"
\r
74 # include "samg/genclk.h"
\r
76 # include "samv71/genclk.h"
\r
78 # include "samv70/genclk.h"
\r
80 # include "same70/genclk.h"
\r
82 # include "sams70/genclk.h"
\r
83 #elif (UC3A0 || UC3A1)
\r
84 # include "uc3a0_a1/genclk.h"
\r
86 # include "uc3a3_a4/genclk.h"
\r
88 # include "uc3b0_b1/genclk.h"
\r
90 # include "uc3c/genclk.h"
\r
92 # include "uc3d/genclk.h"
\r
94 # include "uc3l/genclk.h"
\r
96 # error Unsupported chip type
\r
100 * \ingroup clk_group
\r
101 * \defgroup genclk_group Generic Clock Management
\r
103 * Generic clocks are configurable clocks which run outside the system
\r
104 * clock domain. They are often connected to peripherals which have an
\r
105 * asynchronous component running independently of the bus clock, e.g.
\r
106 * USB controllers, low-power timers and RTCs, etc.
\r
108 * Note that not all platforms have support for generic clocks; on such
\r
109 * platforms, this API will not be available.
\r
115 * \def GENCLK_DIV_MAX
\r
116 * \brief Maximum divider supported by the generic clock implementation
\r
119 * \enum genclk_source
\r
120 * \brief Generic clock source ID
\r
122 * Each generic clock may be generated from a different clock source.
\r
123 * These are the available alternatives provided by the chip.
\r
126 //! \name Generic clock configuration
\r
129 * \struct genclk_config
\r
130 * \brief Hardware representation of a set of generic clock parameters
\r
133 * \fn void genclk_config_defaults(struct genclk_config *cfg,
\r
135 * \brief Initialize \a cfg to the default configuration for the clock
\r
136 * identified by \a id.
\r
139 * \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id)
\r
140 * \brief Read the currently active configuration of the clock
\r
141 * identified by \a id into \a cfg.
\r
144 * \fn void genclk_config_write(const struct genclk_config *cfg,
\r
146 * \brief Activate the configuration \a cfg on the clock identified by
\r
150 * \fn void genclk_config_set_source(struct genclk_config *cfg,
\r
151 * enum genclk_source src)
\r
152 * \brief Select a new source clock \a src in configuration \a cfg.
\r
155 * \fn void genclk_config_set_divider(struct genclk_config *cfg,
\r
156 * unsigned int divider)
\r
157 * \brief Set a new \a divider in configuration \a cfg.
\r
160 * \fn void genclk_enable_source(enum genclk_source src)
\r
161 * \brief Enable the source clock \a src used by a generic clock.
\r
165 //! \name Enabling and disabling Generic Clocks
\r
168 * \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id)
\r
169 * \brief Activate the configuration \a cfg on the clock identified by
\r
170 * \a id and enable it.
\r
173 * \fn void genclk_disable(unsigned int id)
\r
174 * \brief Disable the generic clock identified by \a id.
\r
179 * \brief Enable the configuration defined by \a src and \a divider
\r
180 * for the generic clock identified by \a id.
\r
182 * \param id The ID of the generic clock.
\r
183 * \param src The source clock of the generic clock.
\r
184 * \param divider The divider used to generate the generic clock.
\r
186 static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider)
\r
188 struct genclk_config gcfg;
\r
190 genclk_config_defaults(&gcfg, id);
\r
191 genclk_enable_source(src);
\r
192 genclk_config_set_source(&gcfg, src);
\r
193 genclk_config_set_divider(&gcfg, divider);
\r
194 genclk_enable(&gcfg, id);
\r
199 #endif /* CLK_GENCLK_H_INCLUDED */
\r