Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/allwinner/clkng/aw_clk.h
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
(24MHz*N)/M | (24MHz*N)/M | ||||
(24MHz*N*K/2) | (24MHz*N*K/2) | ||||
(24MHz*N)/M | (24MHz*N)/M | ||||
Periph clocks: | Periph clocks: | ||||
Clock Source/Divider N/Divider M | Clock Source/Divider N/Divider M | ||||
Clock Source/Divider N/Divider M/2 | Clock Source/Divider N/Divider M/2 | ||||
Clock Source * N/Divider M + 1/Divider P + 1 | |||||
*/ | */ | ||||
struct aw_clk_init { | struct aw_clk_init { | ||||
const char *name; | const char *name; | ||||
const char *parent_name; | const char *parent_name; | ||||
uint64_t default_freq; | uint64_t default_freq; | ||||
bool enable; | bool enable; | ||||
}; | }; | ||||
#define AW_CLK_HAS_GATE 0x0001 | #define AW_CLK_HAS_GATE 0x0001 | ||||
#define AW_CLK_HAS_LOCK 0x0002 | #define AW_CLK_HAS_LOCK 0x0002 | ||||
#define AW_CLK_HAS_MUX 0x0004 | #define AW_CLK_HAS_MUX 0x0004 | ||||
#define AW_CLK_REPARENT 0x0008 | #define AW_CLK_REPARENT 0x0008 | ||||
#define AW_CLK_SCALE_CHANGE 0x0010 | #define AW_CLK_SCALE_CHANGE 0x0010 | ||||
#define AW_CLK_HAS_FRAC 0x0020 | #define AW_CLK_HAS_FRAC 0x0020 | ||||
#define AW_CLK_HAS_UPDATE 0x0040 | #define AW_CLK_HAS_UPDATE 0x0040 | ||||
#define AW_CLK_FACTOR_POWER_OF_TWO 0x0001 | #define AW_CLK_FACTOR_POWER_OF_TWO 0x0001 | ||||
#define AW_CLK_FACTOR_ZERO_BASED 0x0002 | #define AW_CLK_FACTOR_ZERO_BASED 0x0002 | ||||
#define AW_CLK_FACTOR_HAS_COND 0x0004 | #define AW_CLK_FACTOR_HAS_COND 0x0004 | ||||
#define AW_CLK_FACTOR_FIXED 0x0008 | #define AW_CLK_FACTOR_FIXED 0x0008 | ||||
#define AW_CLK_FACTOR_POWER_OF_FOUR 0x0010 | |||||
#define AW_CLK_FACTOR_HAS_BIT_COND 0x0020 | |||||
struct aw_clk_factor { | struct aw_clk_factor { | ||||
uint32_t shift; /* Shift bits for the factor */ | uint32_t shift; /* Shift bits for the factor */ | ||||
uint32_t mask; /* Mask to get the factor, will be override by the clk methods */ | uint32_t mask; /* Mask to get the factor, will be override by the clk methods */ | ||||
uint32_t width; /* Number of bits for the factor */ | uint32_t width; /* Number of bits for the factor */ | ||||
uint32_t value; /* Fixed value, depends on AW_CLK_FACTOR_FIXED */ | uint32_t value; /* Fixed value, depends on AW_CLK_FACTOR_FIXED */ | ||||
uint32_t cond_shift; | uint32_t cond_shift; | ||||
Show All 12 Lines | |||||
}; | }; | ||||
static inline uint32_t | static inline uint32_t | ||||
aw_clk_get_factor(uint32_t val, struct aw_clk_factor *factor) | aw_clk_get_factor(uint32_t val, struct aw_clk_factor *factor) | ||||
{ | { | ||||
uint32_t factor_val; | uint32_t factor_val; | ||||
uint32_t cond; | uint32_t cond; | ||||
if (factor->flags & AW_CLK_FACTOR_HAS_COND) { | if ((factor->flags & AW_CLK_FACTOR_HAS_COND) || | ||||
(factor->flags & AW_CLK_FACTOR_HAS_BIT_COND)) { | |||||
cond = (val & factor->cond_mask) >> factor->cond_shift; | cond = (val & factor->cond_mask) >> factor->cond_shift; | ||||
if (cond != factor->cond_value) | if (!(factor->flags & AW_CLK_FACTOR_HAS_BIT_COND) && | ||||
cond != factor->cond_value) | |||||
return (1); | return (1); | ||||
if ((factor->flags & AW_CLK_FACTOR_HAS_BIT_COND) && | |||||
(cond & factor->cond_value) == 0) | |||||
return (1); | |||||
} | } | ||||
if (factor->flags & AW_CLK_FACTOR_FIXED) | if (factor->flags & AW_CLK_FACTOR_FIXED) | ||||
return (factor->value); | return (factor->value); | ||||
factor_val = (val & factor->mask) >> factor->shift; | factor_val = (val & factor->mask) >> factor->shift; | ||||
if (!(factor->flags & AW_CLK_FACTOR_ZERO_BASED)) | if (!(factor->flags & AW_CLK_FACTOR_ZERO_BASED)) | ||||
factor_val += 1; | factor_val += 1; | ||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) | else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) | ||||
factor_val = 1 << factor_val; | factor_val = 1 << factor_val; | ||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_FOUR) | |||||
factor_val = 1 << (2 * factor_val); | |||||
return (factor_val); | return (factor_val); | ||||
} | } | ||||
static inline uint32_t | static inline uint32_t | ||||
aw_clk_factor_get_incremented(uint32_t val, struct aw_clk_factor *factor) | |||||
{ | |||||
if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) | |||||
return (val << 1); | |||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_FOUR) | |||||
return (val << 2); | |||||
else | |||||
return (val + 1); | |||||
} | |||||
static inline uint32_t | |||||
aw_clk_factor_get_max(struct aw_clk_factor *factor) | aw_clk_factor_get_max(struct aw_clk_factor *factor) | ||||
{ | { | ||||
uint32_t max; | uint32_t max; | ||||
if (factor->flags & AW_CLK_FACTOR_FIXED) | if (factor->flags & AW_CLK_FACTOR_FIXED) | ||||
max = factor->value; | max = factor->value; | ||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) | else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) | ||||
max = 1 << ((1 << factor->width) - 1); | max = 1 << ((1 << factor->width) - 1); | ||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_FOUR) | |||||
max = 1 << (2 * ((1 << factor->width) - 1)); | |||||
else { | else { | ||||
max = (1 << factor->width); | max = (1 << factor->width); | ||||
} | } | ||||
return (max); | return (max); | ||||
} | } | ||||
static inline uint32_t | static inline uint32_t | ||||
Show All 19 Lines | aw_clk_factor_get_value(struct aw_clk_factor *factor, uint32_t raw) | ||||
if (factor->flags & AW_CLK_FACTOR_FIXED) | if (factor->flags & AW_CLK_FACTOR_FIXED) | ||||
return (factor->value); | return (factor->value); | ||||
if (factor->flags & AW_CLK_FACTOR_ZERO_BASED) | if (factor->flags & AW_CLK_FACTOR_ZERO_BASED) | ||||
val = raw; | val = raw; | ||||
else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) { | else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) { | ||||
for (val = 0; raw != 1; val++) | for (val = 0; raw != 1; val++) | ||||
raw >>= 1; | raw >>= 1; | ||||
} else if (factor->flags & AW_CLK_FACTOR_POWER_OF_FOUR) { | |||||
for (val = 0; raw != 1; val++) | |||||
raw >>= 2; | |||||
} else | } else | ||||
val = raw - 1; | val = raw - 1; | ||||
return (val); | return (val); | ||||
} | } | ||||
#define CCU_RESET(idx, o, s) \ | #define CCU_RESET(idx, o, s) \ | ||||
[idx] = { \ | [idx] = { \ | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |