Skip to content

Commit 67faaa5

Browse files
zelenskiCS107E BOT
authored andcommitted
add to prefix ccu typedefs
commit 0ad919e9ebf529c9f221363567b17e51010906b2 Author: Julie Zelenski <[email protected]> Date: Fri Nov 22 09:47:48 2024 -0800 add to prefix ccu typedefs
1 parent efaa32e commit 67faaa5

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

cs107e/include/ccu.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include <stdint.h>
1111

1212
/*
13-
* Type: `module_clk_id_t`, `bgr_id_t`, `pll_id_t`
13+
* Type: `ccu_module_id_t`, `ccu_bgr_id_t`, `ccu_pll_id_t`
1414
*
15-
* Type used to identify a ccu register by id (offset).
15+
* Type used to identify a ccu clock register by id (offset).
1616
* We list only the ids of those ccu registers that we are using.
1717
*/
1818

@@ -24,27 +24,29 @@ typedef enum { // ids for Module Clock registers
2424
CCU_DRAM_CLK_REG = 0x0800,
2525
CCU_HDMI_24M_CLK_REG = 0x0B04,
2626
CCU_TCONTV_CLK_REG = 0x0B80,
27+
CCU_SPI0_CLK_REG = 0x0940,
28+
CCU_SPI1_CLK_REG = 0x0944,
2729
CCU_I2S0_CLK_REG = 0x0A10,
2830
CCU_I2S1_CLK_REG = 0x0A14,
2931
CCU_I2S2_CLK_REG = 0x0A18,
30-
CCU_SPI0_CLK_REG = 0x0940,
31-
CCU_SPI1_CLK_REG = 0x0944,
32-
} module_clk_id_t;
32+
CCU_LEDC_CLK_REG = 0x0BF0,
33+
} ccu_module_id_t;
3334

3435
typedef enum { // ids for Bus Gating Reset registers
3536
CCU_DE_BGR_REG = 0x060C, // Display engine
36-
CCU_DPSS_TOP_BGR_REG = 0x0ABC, // TCON TOP
37-
CCU_HDMI_BGR_REG = 0x0B1C,
38-
CCU_TCONTV_BGR_REG = 0x0B9C,
3937
CCU_DMA_BGR_REG = 0x070C,
4038
CCU_HSTIMER_BGR_REG = 0x073C,
4139
CCU_PWM_BGR_REG = 0x07AC,
4240
CCU_DRAM_BGR_REG = 0x080C,
4341
CCU_UART_BGR_REG = 0x090C,
44-
CCU_I2S_BGR_REG = 0x0A20,
4542
CCU_TWI_BGR_REG = 0x091C, // TWI == I2C
4643
CCU_SPI_BGR_REG = 0x096C,
47-
} bgr_id_t;
44+
CCU_I2S_BGR_REG = 0x0A20,
45+
CCU_DPSS_TOP_BGR_REG = 0x0ABC, // TCON TOP
46+
CCU_HDMI_BGR_REG = 0x0B1C,
47+
CCU_TCONTV_BGR_REG = 0x0B9C,
48+
CCU_LEDC_BGR_REG = 0x0BFC,
49+
} ccu_bgr_id_t;
4850

4951
typedef enum { // ids for PLL registers
5052
CCU_PLL_CPU_CTRL_REG = 0x0000,
@@ -55,10 +57,10 @@ typedef enum { // ids for PLL registers
5557
CCU_PLL_VE_CTRL_REG = 0x0058,
5658
CCU_PLL_AUDIO0_CTRL_REG = 0x0078,
5759
CCU_PLL_AUDIO1_CTRL_REG = 0x0080,
58-
} pll_id_t;
60+
} ccu_pll_id_t;
5961

6062
/*
61-
* Type: `parent_id_t`
63+
* Type: `ccu_parent_id_t`
6264
*
6365
* Enum type used to identify a clock's parent clock.
6466
*/
@@ -80,7 +82,7 @@ typedef enum {
8082
PARENT_APB0,
8183
PARENT_APB1,
8284
PARENT_PSI,
83-
} parent_id_t;
85+
} ccu_parent_id_t;
8486

8587
/*
8688
* `ccu_config_pll_rate`: Update settings and enable pll
@@ -93,7 +95,7 @@ typedef enum {
9395
* @param rate desired rate in hz
9496
* @return pll rate of new configuration
9597
*/
96-
long ccu_config_pll_rate(pll_id_t id, long rate);
98+
long ccu_config_pll_rate(ccu_pll_id_t id, long rate);
9799

98100
/*
99101
* `ccu_config_module_clock_rate`: Update settings and enable module clock
@@ -105,7 +107,7 @@ long ccu_config_pll_rate(pll_id_t id, long rate);
105107
* @param rate desired rate in hz
106108
* @return rate of module clock
107109
*/
108-
long ccu_config_module_clock_rate(module_clk_id_t id, parent_id_t parent, long rate);
110+
long ccu_config_module_clock_rate(ccu_module_id_t id, ccu_parent_id_t parent, long rate);
109111

110112
/*
111113
* `ccu_ungate_bus_clock`: Ungate bus clock
@@ -116,8 +118,8 @@ long ccu_config_module_clock_rate(module_clk_id_t id, parent_id_t parent, long r
116118
* @param id id of bgr from bgr enum above
117119
* @return rate of bus clock
118120
*/
119-
long ccu_ungate_bus_clock(bgr_id_t reg_id);
120-
long ccu_ungate_bus_clock_bits(bgr_id_t reg_id, uint32_t gating_bits, uint32_t reset_bits);
121+
long ccu_ungate_bus_clock(ccu_bgr_id_t reg_id);
122+
long ccu_ungate_bus_clock_bits(ccu_bgr_id_t reg_id, uint32_t gating_bits, uint32_t reset_bits);
121123

122124
// for debugging purposes
123125
void ccu_debug_show_clocks(const char *label);

cs107e/lib/libmango.a

816 Bytes
Binary file not shown.

cs107e/src/ccu.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ struct debug_info {
2121
long (*fn)(uint32_t);
2222
uint32_t reg_id;
2323
const char *name;
24-
parent_id_t parents[4];
24+
ccu_parent_id_t parents[4];
2525
uint32_t ncount, mcount;
2626
};
2727
static struct debug_info *info_for_id(uint32_t id);
28-
static long debug_rate_pll(pll_id_t id);
29-
static long debug_rate_clk(module_clk_id_t id);
30-
static long debug_rate_bgr(bgr_id_t id);
31-
static long debug_rate_parent(parent_id_t id);
32-
static int get_parent_src_index(module_clk_id_t id, parent_id_t parent);
33-
static void validate_pll(pll_id_t id);
34-
static void validate_module_clk(module_clk_id_t id);
35-
static void validate_bgr(bgr_id_t id);
28+
static long debug_rate_pll(ccu_pll_id_t id);
29+
static long debug_rate_clk(ccu_module_id_t id);
30+
static long debug_rate_bgr(ccu_bgr_id_t id);
31+
static long debug_rate_parent(ccu_parent_id_t id);
32+
static int get_parent_src_index(ccu_module_id_t id, ccu_parent_id_t parent);
33+
static void validate_pll(ccu_pll_id_t id);
34+
static void validate_module_clk(ccu_module_id_t id);
35+
static void validate_bgr(ccu_bgr_id_t id);
3636

3737
typedef union {
3838
struct {
@@ -88,7 +88,7 @@ static volatile uint32_t *reg_for_id(uint32_t raw_offset) {
8888
// commonly used PLL rates and list in this table for easy access.
8989
// if you need an additional rate config, simply add to this table
9090
static const struct pll_config_t {
91-
pll_id_t pll_id;
91+
ccu_pll_id_t pll_id;
9292
uint32_t rate;
9393
struct { uint8_t P; uint8_t N; uint8_t M1; uint8_t M0; };
9494
} pll_table[] = {
@@ -99,7 +99,7 @@ static const struct pll_config_t {
9999
{0}
100100
};
101101

102-
static const struct pll_config_t *get_pll_config_for_rate(pll_id_t id, long rate) {
102+
static const struct pll_config_t *get_pll_config_for_rate(ccu_pll_id_t id, long rate) {
103103
for (const struct pll_config_t *cfg = pll_table; cfg->rate != 0; cfg++) {
104104
if (cfg->pll_id == id && cfg->rate == rate) return cfg;
105105
}
@@ -110,7 +110,7 @@ static const struct pll_config_t *get_pll_config_for_rate(pll_id_t id, long rate
110110
#define BITS_N_M1(n, m1) ((pll_reg_t){ .factor_n=n, .factor_m1=m1 }).bits
111111
#define BITS_P_N_M1_M0(p, n, m1, m0) ((pll_reg_t){ .factor_p=p, .factor_n=n, .factor_m1=m1, .factor_m0=m0 }).bits;
112112

113-
static void get_pll_bits(pll_id_t id, long rate, uint32_t *factor_mask, uint32_t *new_factors) {
113+
static void get_pll_bits(ccu_pll_id_t id, long rate, uint32_t *factor_mask, uint32_t *new_factors) {
114114
uint32_t out_mhz;
115115
const struct pll_config_t *cfg = get_pll_config_for_rate(id, rate);
116116
if (!cfg) error("No matching pll config found in rate table.");
@@ -170,7 +170,7 @@ static void update_pll_bits(volatile uint32_t *reg, uint32_t factor_mask, uint32
170170
*reg |= OUT_ENA; // re-enable output
171171
}
172172

173-
long ccu_config_pll_rate(pll_id_t id, long rate) {
173+
long ccu_config_pll_rate(ccu_pll_id_t id, long rate) {
174174
validate_pll(id);
175175
uint32_t factor_mask, new_factors;
176176
get_pll_bits(id, rate, &factor_mask, &new_factors);
@@ -180,7 +180,7 @@ long ccu_config_pll_rate(pll_id_t id, long rate) {
180180
return set_rate;
181181
}
182182

183-
static uint32_t get_module_clk_bits(module_clk_id_t id, parent_id_t parent, long rate) {
183+
static uint32_t get_module_clk_bits(ccu_module_id_t id, ccu_parent_id_t parent, long rate) {
184184
int src = get_parent_src_index(id, parent);
185185
if (src == -1) error("Parent id is not valid for module clock")
186186
long parent_rate = debug_rate_parent(parent);
@@ -220,7 +220,7 @@ static void update_clock_bits(volatile uint32_t *reg, uint32_t bits) {
220220
*reg |= ENA; // re-enable
221221
}
222222

223-
long ccu_config_module_clock_rate(module_clk_id_t id, parent_id_t parent, long rate) {
223+
long ccu_config_module_clock_rate(ccu_module_id_t id, ccu_parent_id_t parent, long rate) {
224224
validate_module_clk(id);
225225
uint32_t new_bits = get_module_clk_bits(id, parent, rate);
226226
update_clock_bits(reg_for_id(id), new_bits);
@@ -235,7 +235,7 @@ long ccu_config_module_clock_rate(module_clk_id_t id, parent_id_t parent, long r
235235
* and then the clock gating bit is enabled to avoid potential problems
236236
* caused by the asynchronous release of the reset signal.
237237
*/
238-
long ccu_ungate_bus_clock_bits(bgr_id_t id, uint32_t gating_bits, uint32_t reset_bits) {
238+
long ccu_ungate_bus_clock_bits(ccu_bgr_id_t id, uint32_t gating_bits, uint32_t reset_bits) {
239239
validate_bgr(id);
240240
volatile uint32_t *reg = reg_for_id(id);
241241
*reg |= reset_bits; // de-assert reset
@@ -245,7 +245,7 @@ long ccu_ungate_bus_clock_bits(bgr_id_t id, uint32_t gating_bits, uint32_t reset
245245

246246
// most bus clocks use standard bits for reset/gate
247247
// general function above allow other use cases
248-
long ccu_ungate_bus_clock(bgr_id_t id) {
248+
long ccu_ungate_bus_clock(ccu_bgr_id_t id) {
249249
const uint32_t standard_gating_bits = 1 << 0;
250250
const uint32_t standard_reset_bits = 1 << 16;
251251
return ccu_ungate_bus_clock_bits(id, standard_gating_bits, standard_reset_bits);
@@ -283,6 +283,7 @@ static struct debug_info info_table[] = {
283283
{ INFO_CLK(CCU_SPI0_CLK_REG), {PARENT_HOSC, PARENT_PERI, PARENT_PERI_2X}, .ncount=2,.mcount=4 },
284284
{ INFO_CLK(CCU_SPI1_CLK_REG), {PARENT_HOSC, PARENT_PERI, PARENT_PERI_2X}, .ncount=2,.mcount=4 },
285285
{ INFO_CLK(CCU_I2S2_CLK_REG), {PARENT_AUDIO0, NOT_IN_MODEL, NOT_IN_MODEL, PARENT_AUDIO1_DIV5}, .ncount=0,.mcount=5},
286+
{ INFO_CLK(CCU_LEDC_CLK_REG), {PARENT_HOSC, PARENT_PERI, NOT_IN_MODEL, NOT_IN_MODEL}, .ncount=2,.mcount=4},
286287
{ .name= "Bus Clock" },
287288
{ INFO_BGR(CCU_DE_BGR_REG), {PARENT_AHB0} },
288289
{ INFO_BGR(CCU_DPSS_TOP_BGR_REG), {PARENT_AHB0} },
@@ -295,10 +296,11 @@ static struct debug_info info_table[] = {
295296
{ INFO_BGR(CCU_I2S_BGR_REG), {PARENT_APB0} },
296297
{ INFO_BGR(CCU_TWI_BGR_REG), {PARENT_APB1} },
297298
{ INFO_BGR(CCU_SPI_BGR_REG), {PARENT_APB1} },
299+
{ INFO_BGR(CCU_LEDC_BGR_REG), {PARENT_APB1} },
298300
{0},
299301
};
300302

301-
static int get_parent_src_index(module_clk_id_t id, parent_id_t parent) {
303+
static int get_parent_src_index(ccu_module_id_t id, ccu_parent_id_t parent) {
302304
for (struct debug_info *info = info_table; info->name; info++) {
303305
if (info->reg_id == id) {
304306
for (int i = 0; i < sizeof(info->parents)/sizeof(*info->parents); i++) {
@@ -330,7 +332,7 @@ void ccu_debug_show_clocks(const char *label) {
330332
}
331333
}
332334

333-
static long debug_rate_parent(parent_id_t id) {
335+
static long debug_rate_parent(ccu_parent_id_t id) {
334336
int mult = 1, div = 1;
335337
switch (id) {
336338
case NOT_IN_MODEL: return -1;
@@ -354,7 +356,7 @@ static long debug_rate_parent(parent_id_t id) {
354356
return -1;
355357
}
356358

357-
static long debug_rate_pll(pll_id_t id) {
359+
static long debug_rate_pll(ccu_pll_id_t id) {
358360
pll_reg_t pll;
359361
pll.bits = *reg_for_id(id);
360362
if (!pll.ena || !pll.output_ena) return 0;
@@ -373,34 +375,34 @@ static long debug_rate_pll(pll_id_t id) {
373375
}
374376
}
375377

376-
static long debug_rate_clk(module_clk_id_t id) {
378+
static long debug_rate_clk(ccu_module_id_t id) {
377379
module_clk_reg_t clk;
378380
clk.bits = *reg_for_id(id);
379381
if (id > CCU_APB1_CLK_REG && !clk.ena) return 0; // cheezy (ena bits not applicable for psi/apb?)
380382
int n = 1 << clk.factor_n;
381383
int m = clk.factor_m + 1;
382384
struct debug_info *i = info_for_id(id);
383-
parent_id_t parent = i->parents[clk.src];
385+
ccu_parent_id_t parent = i->parents[clk.src];
384386
return debug_rate_parent(parent)/n/m;
385387
}
386388

387-
static long debug_rate_bgr(bgr_id_t id) {
389+
static long debug_rate_bgr(ccu_bgr_id_t id) {
388390
uint32_t val = *reg_for_id(id);
389391
struct debug_info *i = info_for_id(id);
390392
return (val & 0xff) ? debug_rate_parent(i->parents[0]) : 0;
391393
}
392394

393-
static void validate_pll(pll_id_t id) {
395+
static void validate_pll(ccu_pll_id_t id) {
394396
struct debug_info *info = info_for_id(id);
395397
if (!info || info->fn != debug_rate_pll) error("PLL id is not valid");
396398
}
397399

398-
static void validate_module_clk(module_clk_id_t id) {
400+
static void validate_module_clk(ccu_module_id_t id) {
399401
struct debug_info *info = info_for_id(id);
400402
if (!info || info->fn != debug_rate_clk) error("Module clock id is not valid");
401403
}
402404

403-
static void validate_bgr(bgr_id_t id) {
405+
static void validate_bgr(ccu_bgr_id_t id) {
404406
struct debug_info *info = info_for_id(id);
405407
if (!info || info->fn != debug_rate_bgr) error("Bus clock id is not valid");
406408
}

cs107e/src/hdmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ struct display_timing {
7777
} horiz, vert;
7878
struct {
7979
long rate;
80-
pll_id_t id;
80+
ccu_pll_id_t id;
8181
} pll;
8282
struct {
8383
long rate;
84-
parent_id_t parent;
84+
ccu_parent_id_t parent;
8585
} tcon_clk, de_clk; // TCONTV and DE clocks
8686
};
8787

0 commit comments

Comments
 (0)