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" 15*db1015e9SEduardo Habkost #include "qom/object.h" 16282e74c8SJean-Christophe Dubois 17cb54d868SJean-Christophe Dubois #define CKIL_FREQ 32768 /* nominal 32khz clock */ 18282e74c8SJean-Christophe Dubois 19282e74c8SJean-Christophe Dubois /* PLL control registers */ 20282e74c8SJean-Christophe Dubois #define PD(v) (((v) >> 26) & 0xf) 21282e74c8SJean-Christophe Dubois #define MFD(v) (((v) >> 16) & 0x3ff) 22282e74c8SJean-Christophe Dubois #define MFI(v) (((v) >> 10) & 0xf); 23282e74c8SJean-Christophe Dubois #define MFN(v) ((v) & 0x3ff) 24282e74c8SJean-Christophe Dubois 25282e74c8SJean-Christophe Dubois #define PLL_PD(x) (((x) & 0xf) << 26) 26282e74c8SJean-Christophe Dubois #define PLL_MFD(x) (((x) & 0x3ff) << 16) 27282e74c8SJean-Christophe Dubois #define PLL_MFI(x) (((x) & 0xf) << 10) 28282e74c8SJean-Christophe Dubois #define PLL_MFN(x) (((x) & 0x3ff) << 0) 29282e74c8SJean-Christophe Dubois 30282e74c8SJean-Christophe Dubois #define TYPE_IMX_CCM "imx.ccm" 31*db1015e9SEduardo Habkost typedef struct IMXCCMClass IMXCCMClass; 32*db1015e9SEduardo Habkost typedef struct IMXCCMState IMXCCMState; 33cb54d868SJean-Christophe Dubois #define IMX_CCM(obj) \ 34cb54d868SJean-Christophe Dubois OBJECT_CHECK(IMXCCMState, (obj), TYPE_IMX_CCM) 35cb54d868SJean-Christophe Dubois #define IMX_CCM_CLASS(klass) \ 36cb54d868SJean-Christophe Dubois OBJECT_CLASS_CHECK(IMXCCMClass, (klass), TYPE_IMX_CCM) 37fed163c9SEduardo Habkost #define IMX_CCM_GET_CLASS(obj) \ 38cb54d868SJean-Christophe Dubois OBJECT_GET_CLASS(IMXCCMClass, (obj), TYPE_IMX_CCM) 39282e74c8SJean-Christophe Dubois 40*db1015e9SEduardo Habkost struct IMXCCMState { 41282e74c8SJean-Christophe Dubois /* <private> */ 42282e74c8SJean-Christophe Dubois SysBusDevice parent_obj; 43282e74c8SJean-Christophe Dubois 44282e74c8SJean-Christophe Dubois /* <public> */ 45282e74c8SJean-Christophe Dubois 46*db1015e9SEduardo Habkost }; 47282e74c8SJean-Christophe Dubois 48282e74c8SJean-Christophe Dubois typedef enum { 49c91a5883SJean-Christophe Dubois CLK_NONE, 50aaa9ec3bSJean-Christophe Dubois CLK_IPG, 51d552f675SJean-Christophe Dubois CLK_IPG_HIGH, 5266542f63SJean-Christophe Dubois CLK_32k, 5366542f63SJean-Christophe Dubois CLK_EXT, 5466542f63SJean-Christophe Dubois CLK_HIGH_DIV, 5566542f63SJean-Christophe Dubois CLK_HIGH, 56282e74c8SJean-Christophe Dubois } IMXClk; 57282e74c8SJean-Christophe Dubois 58*db1015e9SEduardo Habkost struct IMXCCMClass { 59cb54d868SJean-Christophe Dubois /* <private> */ 60cb54d868SJean-Christophe Dubois SysBusDeviceClass parent_class; 61cb54d868SJean-Christophe Dubois 62cb54d868SJean-Christophe Dubois /* <public> */ 63cb54d868SJean-Christophe Dubois uint32_t (*get_clock_frequency)(IMXCCMState *s, IMXClk clk); 64*db1015e9SEduardo Habkost }; 65cb54d868SJean-Christophe Dubois 66cb54d868SJean-Christophe Dubois uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq); 67cb54d868SJean-Christophe Dubois 68cb54d868SJean-Christophe Dubois uint32_t imx_ccm_get_clock_frequency(IMXCCMState *s, IMXClk clock); 69282e74c8SJean-Christophe Dubois 70282e74c8SJean-Christophe Dubois #endif /* IMX_CCM_H */ 71