Skip to content

Commit 2d35c7c

Browse files
committed
soc: microchip: sam: optimize array size for sama7g5 registered clocks
Replace the array size for sama7g5 registered clocks with macros and put the macros to soc.h with descriptions. Signed-off-by: Tony Han <tony.han@microchip.com>
1 parent 79e4461 commit 2d35c7c

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

soc/microchip/sam/common/clk-generated.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct clk_generated {
2929

3030
#define to_clk_generated(ptr) CONTAINER_OF(ptr, struct clk_generated, clk)
3131

32-
static struct clk_generated clocks_gck[ID_PERIPH_MAX];
32+
static struct clk_generated clocks_gck[SOC_NUM_CLOCK_GENERATED];
3333
static uint32_t clocks_gck_idx;
3434

3535
static int clk_generated_on(const struct device *dev, clock_control_subsys_t sys)

soc/microchip/sam/common/clk-master.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(clk_mck, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
1919

2020
#define PMC_MCR_CSS_SHIFT 16
2121

22-
#define MASTER_MAX_ID 4
22+
#define MASTER_MAX_ID (SOC_NUM_CLOCK_MASTER - 1)
2323

2424
#define to_clk_master(ptr) CONTAINER_OF(ptr, struct clk_master, clk)
2525

@@ -38,7 +38,7 @@ struct clk_master {
3838
uint8_t div;
3939
};
4040

41-
static struct clk_master clocks_master[5];
41+
static struct clk_master clocks_master[SOC_NUM_CLOCK_MASTER];
4242
static uint32_t clocks_master_idx;
4343

4444
static inline bool clk_master_ready(struct clk_master *master)

soc/microchip/sam/common/clk-peripheral.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct clk_peripheral {
2525
const struct clk_pcr_layout *layout;
2626
};
2727

28-
static struct clk_peripheral clocks_periph[72];
28+
static struct clk_peripheral clocks_periph[SOC_NUM_CLOCK_PERIPHERAL];
2929
static uint32_t clocks_periph_idx;
3030

3131
#define to_clk_peripheral(ptr) CONTAINER_OF(ptr, struct clk_peripheral, clk)

soc/microchip/sam/common/clk-sam9x60-pll.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ LOG_MODULE_REGISTER(clk_pll, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
4646
q * n_ + r * n_ / d_; \
4747
})
4848

49-
#define PLL_MAX_ID 7
49+
#define PLL_MAX_ID SOC_NUM_CLOCK_PLL_FRAC
5050

5151
struct sam9x60_pll_core {
5252
pmc_registers_t *pmc;
@@ -73,10 +73,10 @@ struct sam9x60_div {
7373
#define to_sam9x60_frac(ptr) CONTAINER_OF(ptr, struct sam9x60_frac, core)
7474
#define to_sam9x60_div(ptr) CONTAINER_OF(ptr, struct sam9x60_div, core)
7575

76-
static struct sam9x60_frac clocks_frac[7];
76+
static struct sam9x60_frac clocks_frac[SOC_NUM_CLOCK_PLL_FRAC];
7777
static uint32_t clocks_frac_idx;
7878

79-
static struct sam9x60_div clocks_div[8];
79+
static struct sam9x60_div clocks_div[SOC_NUM_CLOCK_PLL_DIV];
8080
static uint32_t clocks_div_idx;
8181

8282
static inline bool sam9x60_pll_ready(pmc_registers_t *pmc, int id)

soc/microchip/sam/common/clk-system.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct clk_system {
2525
uint8_t id;
2626
};
2727

28-
static struct clk_system clocks_sys[8];
28+
static struct clk_system clocks_sys[SOC_NUM_CLOCK_SYSTEM];
2929
static uint32_t clocks_sys_idx;
3030

3131
static inline int is_pck(int id)

soc/microchip/sam/sama7g5/soc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@
1313

1414
#include "sam.h"
1515

16+
/* number of clocks registered */
17+
#define SOC_NUM_CLOCK_PLL_FRAC 7
18+
#define SOC_NUM_CLOCK_PLL_DIV (SOC_NUM_CLOCK_PLL_FRAC + 1) /* AUDIO PLL: DIVPMC, DIVIO */
19+
#define SOC_NUM_CLOCK_MASTER 5 /* MCK 0 ~ 4 */
20+
#define SOC_NUM_CLOCK_PROGRAMMABLE 8 /* MCK 0 ~ 7 */
21+
#define SOC_NUM_CLOCK_SYSTEM 8 /* PCK 0 ~ 7 */
22+
#define SOC_NUM_CLOCK_PERIPHERAL 72
23+
#define SOC_NUM_CLOCK_GENERATED 46
24+
1625
#endif /* __SAMA7G5_SOC__H_ */

0 commit comments

Comments
 (0)