1 //
2 // Copyright (c) 2010-2024 Antmicro
3 //
4 //  This file is licensed under the MIT License.
5 //  Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System;
8 using System.Collections.Generic;
9 using Antmicro.Renode.Core;
10 using Antmicro.Renode.Core.Structure.Registers;
11 using Antmicro.Renode.Peripherals.Bus;
12 
13 namespace Antmicro.Renode.Peripherals.Miscellaneous
14 {
15     public class NPCX_HFCG : BasicBytePeripheral, IKnownSize
16     {
NPCX_HFCG(IMachine machine)17         public NPCX_HFCG(IMachine machine) : base(machine)
18         {
19             DefineRegisters();
20             Reset();
21         }
22 
23         public long Size => 0x100;
24 
DefineRegisters()25         protected override void DefineRegisters()
26         {
27             Registers.Control.Define(this)
28                 .WithTag("LOAD (Load M and N Values)", 0, 1)
29                 .WithReservedBits(1, 1)
30                 .WithTag("LOCK (Disable Writing to all HFCG registers)", 2, 1)
31                 .WithReservedBits(3, 3)
32                 .WithTag("CLK_CHNG (Clock Changing)", 7, 1);
33 
34             Registers.MLowByteValue.Define(this)
35                 .WithTag("HFCGM7-0 (M Value Bits 7-0)", 0, 8);
36 
37             Registers.MHighByteValue.Define(this)
38                 .WithTag("HFCGM15-8 (M Value Bits 15-8)", 0, 8);
39 
40             Registers.NValue.Define(this)
41                 .WithTag("HFCGN5-0 (N Value Bits 5-0)", 0, 6)
42                 .WithReservedBits(6, 1)
43                 .WithTag("XF_RANGE (Extended Frequency Range)", 7, 1);
44 
45             Registers.Prescaler.Define(this)
46                 .WithTag("AHB6DIV (AHB6 Clock Divider)", 0, 2)
47                 .WithReservedBits(2, 2)
48                 .WithTag("FPRED (Core Clock Prescaler Divider Value)", 4, 4);
49 
50             Registers.BusClockDividers.Define(this)
51                 .WithReservedBits(0, 1)
52                 .WithTag("AHB6CLK_BLK (AHB6 Clock Block)", 1, 1)
53                 .WithReservedBits(2, 2)
54                 .WithTag("FIUDIV (FIU Clock Divider)", 4, 2)
55                 .WithReservedBits(6, 2);
56 
57             Registers.BusClockDividers1.Define(this)
58                 .WithTag("APB1DIV (APB1 Clock Divider)", 0, 4)
59                 .WithTag("APB2DIV (APB2 Clock Divider)", 4, 4);
60 
61             Registers.BusClockDividers2.Define(this)
62                 .WithTag("APB3DIV (APB3 Clock Divider)", 0, 4)
63                 .WithTag("APB4DIV (APB4 Clock Divider)", 4, 4);
64 
65             Registers.PrescalerInIdle.Define(this)
66                 .WithReservedBits(0, 3)
67                 .WithTag("FPRED_IDL_EN (Core Clock Prescaler Divider in Idle Value Enable)", 3, 1)
68                 .WithTag("FPRED_IDL (Core Clock Prescaler Divider in Idle Value)", 4, 4);
69         }
70 
71         private enum Registers
72         {
73             Control = 0x0,
74             MLowByteValue = 0x2,
75             MHighByteValue = 0x4,
76             NValue = 0x6,
77             Prescaler = 0x8,
78             BusClockDividers = 0x10,
79             BusClockDividers1 = 0x12,
80             BusClockDividers2 = 0x14,
81             PrescalerInIdle = 0x1C
82         }
83     }
84 }
85