2006-11-19 17:06:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Atmel Corporation
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2006-11-19 17:06:53 +00:00
|
|
|
*/
|
|
|
|
#ifndef __ASM_AVR32_ARCH_CLK_H__
|
|
|
|
#define __ASM_AVR32_ARCH_CLK_H__
|
|
|
|
|
2007-10-29 12:23:33 +00:00
|
|
|
#include <asm/arch/chip-features.h>
|
2008-08-31 16:05:32 +00:00
|
|
|
#include <asm/arch/portmux.h>
|
2007-10-29 12:23:33 +00:00
|
|
|
|
2006-11-19 17:06:53 +00:00
|
|
|
#ifdef CONFIG_PLL
|
2008-12-17 15:53:07 +00:00
|
|
|
#define PLL0_RATE ((CONFIG_SYS_OSC0_HZ / CONFIG_SYS_PLL0_DIV) \
|
|
|
|
* CONFIG_SYS_PLL0_MUL)
|
2008-08-31 16:05:32 +00:00
|
|
|
#define MAIN_CLK_RATE PLL0_RATE
|
2006-11-19 17:06:53 +00:00
|
|
|
#else
|
2008-12-17 15:53:07 +00:00
|
|
|
#define MAIN_CLK_RATE (CONFIG_SYS_OSC0_HZ)
|
2006-11-19 17:06:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline unsigned long get_cpu_clk_rate(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
return MAIN_CLK_RATE >> CONFIG_SYS_CLKDIV_CPU;
|
2006-11-19 17:06:53 +00:00
|
|
|
}
|
|
|
|
static inline unsigned long get_hsb_clk_rate(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
return MAIN_CLK_RATE >> CONFIG_SYS_CLKDIV_HSB;
|
2006-11-19 17:06:53 +00:00
|
|
|
}
|
|
|
|
static inline unsigned long get_pba_clk_rate(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
return MAIN_CLK_RATE >> CONFIG_SYS_CLKDIV_PBA;
|
2006-11-19 17:06:53 +00:00
|
|
|
}
|
|
|
|
static inline unsigned long get_pbb_clk_rate(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
return MAIN_CLK_RATE >> CONFIG_SYS_CLKDIV_PBB;
|
2006-11-19 17:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Accessors for specific devices. More will be added as needed. */
|
|
|
|
static inline unsigned long get_sdram_clk_rate(void)
|
|
|
|
{
|
|
|
|
return get_hsb_clk_rate();
|
|
|
|
}
|
2007-10-29 12:23:33 +00:00
|
|
|
#ifdef AT32AP700x_CHIP_HAS_USART
|
2006-11-19 17:06:53 +00:00
|
|
|
static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
|
|
|
|
{
|
|
|
|
return get_pba_clk_rate();
|
|
|
|
}
|
2007-10-29 12:23:33 +00:00
|
|
|
#endif
|
2008-04-30 11:09:56 +00:00
|
|
|
#ifdef AT32AP700x_CHIP_HAS_MACB
|
2006-12-17 15:56:14 +00:00
|
|
|
static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
|
|
|
|
{
|
|
|
|
return get_pbb_clk_rate();
|
|
|
|
}
|
|
|
|
static inline unsigned long get_macb_hclk_rate(unsigned int dev_id)
|
|
|
|
{
|
|
|
|
return get_hsb_clk_rate();
|
|
|
|
}
|
2007-10-29 12:23:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT32AP700x_CHIP_HAS_MMCI
|
2006-12-17 17:55:37 +00:00
|
|
|
static inline unsigned long get_mci_clk_rate(void)
|
|
|
|
{
|
|
|
|
return get_pbb_clk_rate();
|
|
|
|
}
|
2007-10-29 12:23:33 +00:00
|
|
|
#endif
|
2008-05-16 09:10:32 +00:00
|
|
|
#ifdef AT32AP700x_CHIP_HAS_SPI
|
|
|
|
static inline unsigned long get_spi_clk_rate(unsigned int dev_id)
|
|
|
|
{
|
|
|
|
return get_pba_clk_rate();
|
|
|
|
}
|
|
|
|
#endif
|
2009-07-21 10:11:37 +00:00
|
|
|
#ifdef AT32AP700x_CHIP_HAS_LCDC
|
|
|
|
static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
|
|
|
|
{
|
|
|
|
return get_hsb_clk_rate();
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-19 17:06:53 +00:00
|
|
|
|
2008-05-02 13:21:40 +00:00
|
|
|
extern void clk_init(void);
|
|
|
|
|
2008-01-23 16:20:14 +00:00
|
|
|
/* Board code may need the SDRAM base clock as a compile-time constant */
|
2008-10-16 13:01:15 +00:00
|
|
|
#define SDRAMC_BUS_HZ (MAIN_CLK_RATE >> CONFIG_SYS_CLKDIV_HSB)
|
2008-01-23 16:20:14 +00:00
|
|
|
|
2008-08-31 16:05:32 +00:00
|
|
|
/* Generic clock control */
|
|
|
|
enum gclk_parent {
|
|
|
|
GCLK_PARENT_OSC0 = 0,
|
|
|
|
GCLK_PARENT_OSC1 = 1,
|
|
|
|
GCLK_PARENT_PLL0 = 2,
|
|
|
|
GCLK_PARENT_PLL1 = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Some generic clocks have specific roles */
|
|
|
|
#define GCLK_DAC_SAMPLE_CLK 6
|
|
|
|
#define GCLK_LCDC_PIXCLK 7
|
|
|
|
|
|
|
|
extern unsigned long __gclk_set_rate(unsigned int id, enum gclk_parent parent,
|
|
|
|
unsigned long rate, unsigned long parent_rate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gclk_set_rate - configure and enable a generic clock
|
|
|
|
* @id: Which GCLK[id] to enable
|
|
|
|
* @parent: Parent clock feeding the GCLK
|
|
|
|
* @rate: Target rate of the GCLK in Hz
|
|
|
|
*
|
|
|
|
* Returns the actual GCLK rate in Hz, after rounding to the nearest
|
|
|
|
* supported rate.
|
|
|
|
*
|
|
|
|
* All three parameters are usually constant, hence the inline.
|
|
|
|
*/
|
|
|
|
static inline unsigned long gclk_set_rate(unsigned int id,
|
|
|
|
enum gclk_parent parent, unsigned long rate)
|
|
|
|
{
|
|
|
|
unsigned long parent_rate;
|
|
|
|
|
|
|
|
if (id > 7)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (parent) {
|
|
|
|
case GCLK_PARENT_OSC0:
|
2008-12-17 15:53:07 +00:00
|
|
|
parent_rate = CONFIG_SYS_OSC0_HZ;
|
2008-08-31 16:05:32 +00:00
|
|
|
break;
|
2008-12-17 15:53:07 +00:00
|
|
|
#ifdef CONFIG_SYS_OSC1_HZ
|
2008-08-31 16:05:32 +00:00
|
|
|
case GCLK_PARENT_OSC1:
|
2008-12-17 15:53:07 +00:00
|
|
|
parent_rate = CONFIG_SYS_OSC1_HZ;
|
2008-08-31 16:05:32 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef PLL0_RATE
|
|
|
|
case GCLK_PARENT_PLL0:
|
|
|
|
parent_rate = PLL0_RATE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef PLL1_RATE
|
|
|
|
case GCLK_PARENT_PLL1:
|
|
|
|
parent_rate = PLL1_RATE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
parent_rate = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return __gclk_set_rate(id, parent, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gclk_enable_output - enable output on a GCLK pin
|
|
|
|
* @id: Which GCLK[id] pin to enable
|
|
|
|
* @drive_strength: Drive strength of external GCLK pin, if applicable
|
|
|
|
*/
|
|
|
|
static inline void gclk_enable_output(unsigned int id,
|
|
|
|
unsigned long drive_strength)
|
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
case 0:
|
|
|
|
portmux_select_peripheral(PORTMUX_PORT_A, 1 << 30,
|
|
|
|
PORTMUX_FUNC_A, drive_strength);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
portmux_select_peripheral(PORTMUX_PORT_A, 1 << 31,
|
|
|
|
PORTMUX_FUNC_A, drive_strength);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
portmux_select_peripheral(PORTMUX_PORT_B, 1 << 19,
|
|
|
|
PORTMUX_FUNC_A, drive_strength);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
portmux_select_peripheral(PORTMUX_PORT_B, 1 << 29,
|
|
|
|
PORTMUX_FUNC_A, drive_strength);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
portmux_select_peripheral(PORTMUX_PORT_B, 1 << 30,
|
|
|
|
PORTMUX_FUNC_A, drive_strength);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-19 17:06:53 +00:00
|
|
|
#endif /* __ASM_AVR32_ARCH_CLK_H__ */
|