1282e74c8SJean-Christophe Dubois /* 2cb54d868SJean-Christophe Dubois * IMX Clock Control Module base class 3282e74c8SJean-Christophe Dubois * 4282e74c8SJean-Christophe Dubois * Copyright (C) 2012 NICTA 5282e74c8SJean-Christophe Dubois * Updated by Jean-Christophe Dubois <jcd@tribudubois.net> 6282e74c8SJean-Christophe Dubois * 7282e74c8SJean-Christophe Dubois * This work is licensed under the terms of the GNU GPL, version 2 or later. 8282e74c8SJean-Christophe Dubois * See the COPYING file in the top-level directory. 9282e74c8SJean-Christophe Dubois */ 10282e74c8SJean-Christophe Dubois 11282e74c8SJean-Christophe Dubois #ifndef IMX_CCM_H 12282e74c8SJean-Christophe Dubois #define IMX_CCM_H 13282e74c8SJean-Christophe Dubois 14282e74c8SJean-Christophe Dubois #include "hw/sysbus.h" 15282e74c8SJean-Christophe Dubois 16cb54d868SJean-Christophe Dubois #define CKIL_FREQ 32768 /* nominal 32khz clock */ 17282e74c8SJean-Christophe Dubois 18282e74c8SJean-Christophe Dubois /* PLL control registers */ 19282e74c8SJean-Christophe Dubois #define PD(v) (((v) >> 26) & 0xf) 20282e74c8SJean-Christophe Dubois #define MFD(v) (((v) >> 16) & 0x3ff) 21282e74c8SJean-Christophe Dubois #define MFI(v) (((v) >> 10) & 0xf); 22282e74c8SJean-Christophe Dubois #define MFN(v) ((v) & 0x3ff) 23282e74c8SJean-Christophe Dubois 24282e74c8SJean-Christophe Dubois #define PLL_PD(x) (((x) & 0xf) << 26) 25282e74c8SJean-Christophe Dubois #define PLL_MFD(x) (((x) & 0x3ff) << 16) 26282e74c8SJean-Christophe Dubois #define PLL_MFI(x) (((x) & 0xf) << 10) 27282e74c8SJean-Christophe Dubois #define PLL_MFN(x) (((x) & 0x3ff) << 0) 28282e74c8SJean-Christophe Dubois 29282e74c8SJean-Christophe Dubois #define TYPE_IMX_CCM "imx.ccm" 30cb54d868SJean-Christophe Dubois #define IMX_CCM(obj) \ 31cb54d868SJean-Christophe Dubois OBJECT_CHECK(IMXCCMState, (obj), TYPE_IMX_CCM) 32cb54d868SJean-Christophe Dubois #define IMX_CCM_CLASS(klass) \ 33cb54d868SJean-Christophe Dubois OBJECT_CLASS_CHECK(IMXCCMClass, (klass), TYPE_IMX_CCM) 34*fed163c9SEduardo Habkost #define IMX_CCM_GET_CLASS(obj) \ 35cb54d868SJean-Christophe Dubois OBJECT_GET_CLASS(IMXCCMClass, (obj), TYPE_IMX_CCM) 36282e74c8SJean-Christophe Dubois 37282e74c8SJean-Christophe Dubois typedef struct IMXCCMState { 38282e74c8SJean-Christophe Dubois /* <private> */ 39282e74c8SJean-Christophe Dubois SysBusDevice parent_obj; 40282e74c8SJean-Christophe Dubois 41282e74c8SJean-Christophe Dubois /* <public> */ 42282e74c8SJean-Christophe Dubois 43282e74c8SJean-Christophe Dubois } IMXCCMState; 44282e74c8SJean-Christophe Dubois 45282e74c8SJean-Christophe Dubois typedef enum { 46c91a5883SJean-Christophe Dubois CLK_NONE, 47aaa9ec3bSJean-Christophe Dubois CLK_IPG, 48d552f675SJean-Christophe Dubois CLK_IPG_HIGH, 4966542f63SJean-Christophe Dubois CLK_32k, 5066542f63SJean-Christophe Dubois CLK_EXT, 5166542f63SJean-Christophe Dubois CLK_HIGH_DIV, 5266542f63SJean-Christophe Dubois CLK_HIGH, 53282e74c8SJean-Christophe Dubois } IMXClk; 54282e74c8SJean-Christophe Dubois 55cb54d868SJean-Christophe Dubois typedef struct IMXCCMClass { 56cb54d868SJean-Christophe Dubois /* <private> */ 57cb54d868SJean-Christophe Dubois SysBusDeviceClass parent_class; 58cb54d868SJean-Christophe Dubois 59cb54d868SJean-Christophe Dubois /* <public> */ 60cb54d868SJean-Christophe Dubois uint32_t (*get_clock_frequency)(IMXCCMState *s, IMXClk clk); 61cb54d868SJean-Christophe Dubois } IMXCCMClass; 62cb54d868SJean-Christophe Dubois 63cb54d868SJean-Christophe Dubois uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq); 64cb54d868SJean-Christophe Dubois 65cb54d868SJean-Christophe Dubois uint32_t imx_ccm_get_clock_frequency(IMXCCMState *s, IMXClk clock); 66282e74c8SJean-Christophe Dubois 67282e74c8SJean-Christophe Dubois #endif /* IMX_CCM_H */ 68