4 * \brief Generic clock management
\r
6 * Copyright (c) 2010-2011 Atmel Corporation. All rights reserved.
\r
10 * Redistribution and use in source and binary forms, with or without
\r
11 * modification, are permitted provided that the following conditions are met:
\r
13 * 1. Redistributions of source code must retain the above copyright notice,
\r
14 * this list of conditions and the following disclaimer.
\r
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
17 * this list of conditions and the following disclaimer in the documentation
\r
18 * and/or other materials provided with the distribution.
\r
20 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
21 * from this software without specific prior written permission.
\r
23 * 4. This software may only be redistributed and used in connection with an
\r
24 * Atmel microcontroller product.
\r
26 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
29 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
36 * POSSIBILITY OF SUCH DAMAGE.
\r
41 #ifndef CLK_GENCLK_H_INCLUDED
\r
42 #define CLK_GENCLK_H_INCLUDED
\r
47 # include "sam3s/genclk.h"
\r
49 # include "sam3u/genclk.h"
\r
51 # include "sam3n/genclk.h"
\r
53 # include "sam3x/genclk.h"
\r
55 # include "sam4s/genclk.h"
\r
56 #elif (UC3A0 || UC3A1)
\r
57 # include "uc3a0_a1/genclk.h"
\r
59 # include "uc3a3_a4/genclk.h"
\r
61 # include "uc3b0_b1/genclk.h"
\r
63 # include "uc3c/genclk.h"
\r
65 # include "uc3d/genclk.h"
\r
67 # include "uc3l/genclk.h"
\r
69 # error Unsupported chip type
\r
73 * \ingroup clk_group
\r
74 * \defgroup genclk_group Generic Clock Management
\r
76 * Generic clocks are configurable clocks which run outside the system
\r
77 * clock domain. They are often connected to peripherals which have an
\r
78 * asynchronous component running independently of the bus clock, e.g.
\r
79 * USB controllers, low-power timers and RTCs, etc.
\r
81 * Note that not all platforms have support for generic clocks; on such
\r
82 * platforms, this API will not be available.
\r
88 * \def GENCLK_DIV_MAX
\r
89 * \brief Maximum divider supported by the generic clock implementation
\r
92 * \enum genclk_source
\r
93 * \brief Generic clock source ID
\r
95 * Each generic clock may be generated from a different clock source.
\r
96 * These are the available alternatives provided by the chip.
\r
99 //! \name Generic clock configuration
\r
102 * \struct genclk_config
\r
103 * \brief Hardware representation of a set of generic clock parameters
\r
106 * \fn void genclk_config_defaults(struct genclk_config *cfg,
\r
108 * \brief Initialize \a cfg to the default configuration for the clock
\r
109 * identified by \a id.
\r
112 * \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id)
\r
113 * \brief Read the currently active configuration of the clock
\r
114 * identified by \a id into \a cfg.
\r
117 * \fn void genclk_config_write(const struct genclk_config *cfg,
\r
119 * \brief Activate the configuration \a cfg on the clock identified by
\r
123 * \fn void genclk_config_set_source(struct genclk_config *cfg,
\r
124 * enum genclk_source src)
\r
125 * \brief Select a new source clock \a src in configuration \a cfg.
\r
128 * \fn void genclk_config_set_divider(struct genclk_config *cfg,
\r
129 * unsigned int divider)
\r
130 * \brief Set a new \a divider in configuration \a cfg.
\r
133 * \fn void genclk_enable_source(enum genclk_source src)
\r
134 * \brief Enable the source clock \a src used by a generic clock.
\r
138 //! \name Enabling and disabling Generic Clocks
\r
141 * \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id)
\r
142 * \brief Activate the configuration \a cfg on the clock identified by
\r
143 * \a id and enable it.
\r
146 * \fn void genclk_disable(unsigned int id)
\r
147 * \brief Disable the generic clock identified by \a id.
\r
152 * \brief Enable the configuration defined by \a src and \a divider
\r
153 * for the generic clock identified by \a id.
\r
155 * \param id The ID of the generic clock.
\r
156 * \param src The source clock of the generic clock.
\r
157 * \param divider The divider used to generate the generic clock.
\r
159 static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider)
\r
161 struct genclk_config gcfg;
\r
163 genclk_config_defaults(&gcfg, id);
\r
164 genclk_enable_source(src);
\r
165 genclk_config_set_source(&gcfg, src);
\r
166 genclk_config_set_divider(&gcfg, divider);
\r
167 genclk_enable(&gcfg, id);
\r
172 #endif /* CLK_GENCLK_H_INCLUDED */
\r