4 * \brief Generic clock management
\r
6 * Copyright (c) 2010-2012 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
43 #ifndef CLK_GENCLK_H_INCLUDED
\r
44 #define CLK_GENCLK_H_INCLUDED
\r
49 # include "sam3s/genclk.h"
\r
51 # include "sam3u/genclk.h"
\r
53 # include "sam3n/genclk.h"
\r
55 # include "sam3x/genclk.h"
\r
57 # include "sam4s/genclk.h"
\r
59 # include "sam4l/genclk.h"
\r
61 # include "sam4e/genclk.h"
\r
62 #elif (UC3A0 || UC3A1)
\r
63 # include "uc3a0_a1/genclk.h"
\r
65 # include "uc3a3_a4/genclk.h"
\r
67 # include "uc3b0_b1/genclk.h"
\r
69 # include "uc3c/genclk.h"
\r
71 # include "uc3d/genclk.h"
\r
73 # include "uc3l/genclk.h"
\r
75 # error Unsupported chip type
\r
79 * \ingroup clk_group
\r
80 * \defgroup genclk_group Generic Clock Management
\r
82 * Generic clocks are configurable clocks which run outside the system
\r
83 * clock domain. They are often connected to peripherals which have an
\r
84 * asynchronous component running independently of the bus clock, e.g.
\r
85 * USB controllers, low-power timers and RTCs, etc.
\r
87 * Note that not all platforms have support for generic clocks; on such
\r
88 * platforms, this API will not be available.
\r
94 * \def GENCLK_DIV_MAX
\r
95 * \brief Maximum divider supported by the generic clock implementation
\r
98 * \enum genclk_source
\r
99 * \brief Generic clock source ID
\r
101 * Each generic clock may be generated from a different clock source.
\r
102 * These are the available alternatives provided by the chip.
\r
105 //! \name Generic clock configuration
\r
108 * \struct genclk_config
\r
109 * \brief Hardware representation of a set of generic clock parameters
\r
112 * \fn void genclk_config_defaults(struct genclk_config *cfg,
\r
114 * \brief Initialize \a cfg to the default configuration for the clock
\r
115 * identified by \a id.
\r
118 * \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id)
\r
119 * \brief Read the currently active configuration of the clock
\r
120 * identified by \a id into \a cfg.
\r
123 * \fn void genclk_config_write(const struct genclk_config *cfg,
\r
125 * \brief Activate the configuration \a cfg on the clock identified by
\r
129 * \fn void genclk_config_set_source(struct genclk_config *cfg,
\r
130 * enum genclk_source src)
\r
131 * \brief Select a new source clock \a src in configuration \a cfg.
\r
134 * \fn void genclk_config_set_divider(struct genclk_config *cfg,
\r
135 * unsigned int divider)
\r
136 * \brief Set a new \a divider in configuration \a cfg.
\r
139 * \fn void genclk_enable_source(enum genclk_source src)
\r
140 * \brief Enable the source clock \a src used by a generic clock.
\r
144 //! \name Enabling and disabling Generic Clocks
\r
147 * \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id)
\r
148 * \brief Activate the configuration \a cfg on the clock identified by
\r
149 * \a id and enable it.
\r
152 * \fn void genclk_disable(unsigned int id)
\r
153 * \brief Disable the generic clock identified by \a id.
\r
158 * \brief Enable the configuration defined by \a src and \a divider
\r
159 * for the generic clock identified by \a id.
\r
161 * \param id The ID of the generic clock.
\r
162 * \param src The source clock of the generic clock.
\r
163 * \param divider The divider used to generate the generic clock.
\r
165 static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider)
\r
167 struct genclk_config gcfg;
\r
169 genclk_config_defaults(&gcfg, id);
\r
170 genclk_enable_source(src);
\r
171 genclk_config_set_source(&gcfg, src);
\r
172 genclk_config_set_divider(&gcfg, divider);
\r
173 genclk_enable(&gcfg, id);
\r
178 #endif /* CLK_GENCLK_H_INCLUDED */
\r