1e331f79eSHavard Skinnemoen /* 2e331f79eSHavard Skinnemoen * Nuvoton NPCM7xx Clock Control Registers. 3e331f79eSHavard Skinnemoen * 4e331f79eSHavard Skinnemoen * Copyright 2020 Google LLC 5e331f79eSHavard Skinnemoen * 6e331f79eSHavard Skinnemoen * This program is free software; you can redistribute it and/or modify it 7e331f79eSHavard Skinnemoen * under the terms of the GNU General Public License as published by the 8e331f79eSHavard Skinnemoen * Free Software Foundation; either version 2 of the License, or 9e331f79eSHavard Skinnemoen * (at your option) any later version. 10e331f79eSHavard Skinnemoen * 11e331f79eSHavard Skinnemoen * This program is distributed in the hope that it will be useful, but WITHOUT 12e331f79eSHavard Skinnemoen * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13e331f79eSHavard Skinnemoen * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14e331f79eSHavard Skinnemoen * for more details. 15e331f79eSHavard Skinnemoen */ 16c8283b0fSHao Wu #ifndef NPCM_CLK_H 17c8283b0fSHao Wu #define NPCM_CLK_H 18e331f79eSHavard Skinnemoen 19e331f79eSHavard Skinnemoen #include "exec/memory.h" 20bcda710fSHao Wu #include "hw/clock.h" 21e331f79eSHavard Skinnemoen #include "hw/sysbus.h" 22e331f79eSHavard Skinnemoen 23e331f79eSHavard Skinnemoen #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) 24*ca6d6a94SHao Wu /* 25*ca6d6a94SHao Wu * Number of maximum registers in NPCM device state structure. Don't change 26*ca6d6a94SHao Wu * this without incrementing the version_id in the vmstate. 27*ca6d6a94SHao Wu */ 28*ca6d6a94SHao Wu #define NPCM_CLK_MAX_NR_REGS NPCM7XX_CLK_NR_REGS 29e331f79eSHavard Skinnemoen 307d378ed6SHao Wu #define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" 317d378ed6SHao Wu 32bcda710fSHao Wu /* Maximum amount of clock inputs in a SEL module. */ 33bcda710fSHao Wu #define NPCM7XX_CLK_SEL_MAX_INPUT 5 34bcda710fSHao Wu 35bcda710fSHao Wu /* PLLs in CLK module. */ 36bcda710fSHao Wu typedef enum NPCM7xxClockPLL { 37bcda710fSHao Wu NPCM7XX_CLOCK_PLL0, 38bcda710fSHao Wu NPCM7XX_CLOCK_PLL1, 39bcda710fSHao Wu NPCM7XX_CLOCK_PLL2, 40bcda710fSHao Wu NPCM7XX_CLOCK_PLLG, 41bcda710fSHao Wu NPCM7XX_CLOCK_NR_PLLS, 42bcda710fSHao Wu } NPCM7xxClockPLL; 43bcda710fSHao Wu 44bcda710fSHao Wu /* SEL/MUX in CLK module. */ 45bcda710fSHao Wu typedef enum NPCM7xxClockSEL { 46bcda710fSHao Wu NPCM7XX_CLOCK_PIXCKSEL, 47bcda710fSHao Wu NPCM7XX_CLOCK_MCCKSEL, 48bcda710fSHao Wu NPCM7XX_CLOCK_CPUCKSEL, 49bcda710fSHao Wu NPCM7XX_CLOCK_CLKOUTSEL, 50bcda710fSHao Wu NPCM7XX_CLOCK_UARTCKSEL, 51bcda710fSHao Wu NPCM7XX_CLOCK_TIMCKSEL, 52bcda710fSHao Wu NPCM7XX_CLOCK_SDCKSEL, 53bcda710fSHao Wu NPCM7XX_CLOCK_GFXMSEL, 54bcda710fSHao Wu NPCM7XX_CLOCK_SUCKSEL, 55bcda710fSHao Wu NPCM7XX_CLOCK_NR_SELS, 56bcda710fSHao Wu } NPCM7xxClockSEL; 57bcda710fSHao Wu 58bcda710fSHao Wu /* Dividers in CLK module. */ 59bcda710fSHao Wu typedef enum NPCM7xxClockDivider { 60bcda710fSHao Wu NPCM7XX_CLOCK_PLL1D2, /* PLL1/2 */ 61bcda710fSHao Wu NPCM7XX_CLOCK_PLL2D2, /* PLL2/2 */ 62bcda710fSHao Wu NPCM7XX_CLOCK_MC_DIVIDER, 63bcda710fSHao Wu NPCM7XX_CLOCK_AXI_DIVIDER, 64bcda710fSHao Wu NPCM7XX_CLOCK_AHB_DIVIDER, 65bcda710fSHao Wu NPCM7XX_CLOCK_AHB3_DIVIDER, 66bcda710fSHao Wu NPCM7XX_CLOCK_SPI0_DIVIDER, 67bcda710fSHao Wu NPCM7XX_CLOCK_SPIX_DIVIDER, 68bcda710fSHao Wu NPCM7XX_CLOCK_APB1_DIVIDER, 69bcda710fSHao Wu NPCM7XX_CLOCK_APB2_DIVIDER, 70bcda710fSHao Wu NPCM7XX_CLOCK_APB3_DIVIDER, 71bcda710fSHao Wu NPCM7XX_CLOCK_APB4_DIVIDER, 72bcda710fSHao Wu NPCM7XX_CLOCK_APB5_DIVIDER, 73bcda710fSHao Wu NPCM7XX_CLOCK_CLKOUT_DIVIDER, 74bcda710fSHao Wu NPCM7XX_CLOCK_UART_DIVIDER, 75bcda710fSHao Wu NPCM7XX_CLOCK_TIMER_DIVIDER, 76bcda710fSHao Wu NPCM7XX_CLOCK_ADC_DIVIDER, 77bcda710fSHao Wu NPCM7XX_CLOCK_MMC_DIVIDER, 78bcda710fSHao Wu NPCM7XX_CLOCK_SDHC_DIVIDER, 79bcda710fSHao Wu NPCM7XX_CLOCK_GFXM_DIVIDER, /* divide by 3 */ 80bcda710fSHao Wu NPCM7XX_CLOCK_UTMI_DIVIDER, 81bcda710fSHao Wu NPCM7XX_CLOCK_NR_DIVIDERS, 82bcda710fSHao Wu } NPCM7xxClockConverter; 83bcda710fSHao Wu 84*ca6d6a94SHao Wu typedef struct NPCMCLKState NPCMCLKState; 85bcda710fSHao Wu 86bcda710fSHao Wu /** 87bcda710fSHao Wu * struct NPCM7xxClockPLLState - A PLL module in CLK module. 88bcda710fSHao Wu * @name: The name of the module. 89bcda710fSHao Wu * @clk: The CLK module that owns this module. 90bcda710fSHao Wu * @clock_in: The input clock of this module. 91bcda710fSHao Wu * @clock_out: The output clock of this module. 92bcda710fSHao Wu * @reg: The control registers for this PLL module. 93bcda710fSHao Wu */ 94bcda710fSHao Wu typedef struct NPCM7xxClockPLLState { 95bcda710fSHao Wu DeviceState parent; 96bcda710fSHao Wu 97bcda710fSHao Wu const char *name; 98*ca6d6a94SHao Wu NPCMCLKState *clk; 99bcda710fSHao Wu Clock *clock_in; 100bcda710fSHao Wu Clock *clock_out; 101bcda710fSHao Wu 102bcda710fSHao Wu int reg; 103bcda710fSHao Wu } NPCM7xxClockPLLState; 104bcda710fSHao Wu 105bcda710fSHao Wu /** 106bcda710fSHao Wu * struct NPCM7xxClockSELState - A SEL module in CLK module. 107bcda710fSHao Wu * @name: The name of the module. 108bcda710fSHao Wu * @clk: The CLK module that owns this module. 109bcda710fSHao Wu * @input_size: The size of inputs of this module. 110bcda710fSHao Wu * @clock_in: The input clocks of this module. 111bcda710fSHao Wu * @clock_out: The output clocks of this module. 112bcda710fSHao Wu * @offset: The offset of this module in the control register. 113bcda710fSHao Wu * @len: The length of this module in the control register. 114bcda710fSHao Wu */ 115bcda710fSHao Wu typedef struct NPCM7xxClockSELState { 116bcda710fSHao Wu DeviceState parent; 117bcda710fSHao Wu 118bcda710fSHao Wu const char *name; 119*ca6d6a94SHao Wu NPCMCLKState *clk; 120bcda710fSHao Wu uint8_t input_size; 121bcda710fSHao Wu Clock *clock_in[NPCM7XX_CLK_SEL_MAX_INPUT]; 122bcda710fSHao Wu Clock *clock_out; 123bcda710fSHao Wu 124bcda710fSHao Wu int offset; 125bcda710fSHao Wu int len; 126bcda710fSHao Wu } NPCM7xxClockSELState; 127bcda710fSHao Wu 128bcda710fSHao Wu /** 129bcda710fSHao Wu * struct NPCM7xxClockDividerState - A Divider module in CLK module. 130bcda710fSHao Wu * @name: The name of the module. 131bcda710fSHao Wu * @clk: The CLK module that owns this module. 132bcda710fSHao Wu * @clock_in: The input clock of this module. 133bcda710fSHao Wu * @clock_out: The output clock of this module. 134bcda710fSHao Wu * @divide: The function the divider uses to divide the input. 135bcda710fSHao Wu * @reg: The index of the control register that contains the divisor. 136bcda710fSHao Wu * @offset: The offset of the divisor in the control register. 137bcda710fSHao Wu * @len: The length of the divisor in the control register. 138bcda710fSHao Wu * @divisor: The divisor for a constant divisor 139bcda710fSHao Wu */ 140bcda710fSHao Wu typedef struct NPCM7xxClockDividerState { 141bcda710fSHao Wu DeviceState parent; 142bcda710fSHao Wu 143bcda710fSHao Wu const char *name; 144*ca6d6a94SHao Wu NPCMCLKState *clk; 145bcda710fSHao Wu Clock *clock_in; 146bcda710fSHao Wu Clock *clock_out; 147bcda710fSHao Wu 148bcda710fSHao Wu uint32_t (*divide)(struct NPCM7xxClockDividerState *s); 149bcda710fSHao Wu union { 150bcda710fSHao Wu struct { 151bcda710fSHao Wu int reg; 152bcda710fSHao Wu int offset; 153bcda710fSHao Wu int len; 154bcda710fSHao Wu }; 155bcda710fSHao Wu int divisor; 156bcda710fSHao Wu }; 157bcda710fSHao Wu } NPCM7xxClockDividerState; 158bcda710fSHao Wu 159*ca6d6a94SHao Wu struct NPCMCLKState { 160e331f79eSHavard Skinnemoen SysBusDevice parent; 161e331f79eSHavard Skinnemoen 162e331f79eSHavard Skinnemoen MemoryRegion iomem; 163e331f79eSHavard Skinnemoen 164bcda710fSHao Wu /* Clock converters */ 165bcda710fSHao Wu NPCM7xxClockPLLState plls[NPCM7XX_CLOCK_NR_PLLS]; 166bcda710fSHao Wu NPCM7xxClockSELState sels[NPCM7XX_CLOCK_NR_SELS]; 167bcda710fSHao Wu NPCM7xxClockDividerState dividers[NPCM7XX_CLOCK_NR_DIVIDERS]; 168bcda710fSHao Wu 169*ca6d6a94SHao Wu uint32_t regs[NPCM_CLK_MAX_NR_REGS]; 170e331f79eSHavard Skinnemoen 171e331f79eSHavard Skinnemoen /* Time reference for SECCNT and CNTR25M, initialized by power on reset */ 172e331f79eSHavard Skinnemoen int64_t ref_ns; 173bcda710fSHao Wu 174bcda710fSHao Wu /* The incoming reference clock. */ 175bcda710fSHao Wu Clock *clkref; 176bcda710fSHao Wu }; 177e331f79eSHavard Skinnemoen 178*ca6d6a94SHao Wu #define TYPE_NPCM_CLK "npcm-clk" 179*ca6d6a94SHao Wu OBJECT_DECLARE_SIMPLE_TYPE(NPCMCLKState, NPCM_CLK) 180e331f79eSHavard Skinnemoen #define TYPE_NPCM7XX_CLK "npcm7xx-clk" 181e331f79eSHavard Skinnemoen 182c8283b0fSHao Wu #endif /* NPCM_CLK_H */ 183