Skip to content

Commit 6a13680

Browse files
tlebbebarino
authored andcommitted
clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag
Add CLK_DIVIDER_EVEN_INTEGERS flag to support divisor of 2, 4, 6, etc. The same divisor can be done using a table, which would be big and wasteful for a clock dividor of width 8 (256 entries). Require increasing flags size from u8 to u16 because CLK_DIVIDER_EVEN_INTEGERS is the eighth flag. u16 is used inside struct clk_divider; `unsigned long` is used for function arguments. Signed-off-by: Théo Lebrun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent bae7aff commit 6a13680

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

drivers/clk/clk-divider.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width,
7272
return clk_div_mask(width);
7373
if (flags & CLK_DIVIDER_POWER_OF_TWO)
7474
return 1 << clk_div_mask(width);
75+
if (flags & CLK_DIVIDER_EVEN_INTEGERS)
76+
return 2 * (clk_div_mask(width) + 1);
7577
if (table)
7678
return _get_table_maxdiv(table, width);
7779
return clk_div_mask(width) + 1;
@@ -97,6 +99,8 @@ static unsigned int _get_div(const struct clk_div_table *table,
9799
return 1 << val;
98100
if (flags & CLK_DIVIDER_MAX_AT_ZERO)
99101
return val ? val : clk_div_mask(width) + 1;
102+
if (flags & CLK_DIVIDER_EVEN_INTEGERS)
103+
return 2 * (val + 1);
100104
if (table)
101105
return _get_table_div(table, val);
102106
return val + 1;
@@ -122,6 +126,8 @@ static unsigned int _get_val(const struct clk_div_table *table,
122126
return __ffs(div);
123127
if (flags & CLK_DIVIDER_MAX_AT_ZERO)
124128
return (div == clk_div_mask(width) + 1) ? 0 : div;
129+
if (flags & CLK_DIVIDER_EVEN_INTEGERS)
130+
return (div >> 1) - 1;
125131
if (table)
126132
return _get_table_val(table, div);
127133
return div - 1;
@@ -538,7 +544,8 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev,
538544
struct device_node *np, const char *name,
539545
const char *parent_name, const struct clk_hw *parent_hw,
540546
const struct clk_parent_data *parent_data, unsigned long flags,
541-
void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
547+
void __iomem *reg, u8 shift, u8 width,
548+
unsigned long clk_divider_flags,
542549
const struct clk_div_table *table, spinlock_t *lock)
543550
{
544551
struct clk_divider *div;
@@ -610,8 +617,8 @@ EXPORT_SYMBOL_GPL(__clk_hw_register_divider);
610617
struct clk *clk_register_divider_table(struct device *dev, const char *name,
611618
const char *parent_name, unsigned long flags,
612619
void __iomem *reg, u8 shift, u8 width,
613-
u8 clk_divider_flags, const struct clk_div_table *table,
614-
spinlock_t *lock)
620+
unsigned long clk_divider_flags,
621+
const struct clk_div_table *table, spinlock_t *lock)
615622
{
616623
struct clk_hw *hw;
617624

@@ -664,7 +671,8 @@ struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
664671
struct device_node *np, const char *name,
665672
const char *parent_name, const struct clk_hw *parent_hw,
666673
const struct clk_parent_data *parent_data, unsigned long flags,
667-
void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
674+
void __iomem *reg, u8 shift, u8 width,
675+
unsigned long clk_divider_flags,
668676
const struct clk_div_table *table, spinlock_t *lock)
669677
{
670678
struct clk_hw **ptr, *hw;

include/linux/clk-provider.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,15 @@ struct clk_div_table {
689689
* CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used
690690
* for the divider register. Setting this flag makes the register accesses
691691
* big endian.
692+
* CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc.
693+
* Formula is 2 * (value read from hardware + 1).
692694
*/
693695
struct clk_divider {
694696
struct clk_hw hw;
695697
void __iomem *reg;
696698
u8 shift;
697699
u8 width;
698-
u8 flags;
700+
u16 flags;
699701
const struct clk_div_table *table;
700702
spinlock_t *lock;
701703
};
@@ -711,6 +713,7 @@ struct clk_divider {
711713
#define CLK_DIVIDER_READ_ONLY BIT(5)
712714
#define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
713715
#define CLK_DIVIDER_BIG_ENDIAN BIT(7)
716+
#define CLK_DIVIDER_EVEN_INTEGERS BIT(8)
714717

715718
extern const struct clk_ops clk_divider_ops;
716719
extern const struct clk_ops clk_divider_ro_ops;
@@ -740,19 +743,21 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev,
740743
struct device_node *np, const char *name,
741744
const char *parent_name, const struct clk_hw *parent_hw,
742745
const struct clk_parent_data *parent_data, unsigned long flags,
743-
void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
746+
void __iomem *reg, u8 shift, u8 width,
747+
unsigned long clk_divider_flags,
744748
const struct clk_div_table *table, spinlock_t *lock);
745749
struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
746750
struct device_node *np, const char *name,
747751
const char *parent_name, const struct clk_hw *parent_hw,
748752
const struct clk_parent_data *parent_data, unsigned long flags,
749-
void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
753+
void __iomem *reg, u8 shift, u8 width,
754+
unsigned long clk_divider_flags,
750755
const struct clk_div_table *table, spinlock_t *lock);
751756
struct clk *clk_register_divider_table(struct device *dev, const char *name,
752757
const char *parent_name, unsigned long flags,
753758
void __iomem *reg, u8 shift, u8 width,
754-
u8 clk_divider_flags, const struct clk_div_table *table,
755-
spinlock_t *lock);
759+
unsigned long clk_divider_flags,
760+
const struct clk_div_table *table, spinlock_t *lock);
756761
/**
757762
* clk_register_divider - register a divider clock with the clock framework
758763
* @dev: device registering this clock

0 commit comments

Comments
 (0)