Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2014 Google, Inc.
0004  */
0005 
0006 #ifndef __PISTACHIO_CLK_H
0007 #define __PISTACHIO_CLK_H
0008 
0009 #include <linux/clk-provider.h>
0010 
0011 struct pistachio_gate {
0012     unsigned int id;
0013     unsigned long reg;
0014     unsigned int shift;
0015     const char *name;
0016     const char *parent;
0017 };
0018 
0019 #define GATE(_id, _name, _pname, _reg, _shift)  \
0020     {                   \
0021         .id = _id,          \
0022         .reg    = _reg,         \
0023         .shift  = _shift,       \
0024         .name   = _name,        \
0025         .parent = _pname,       \
0026     }
0027 
0028 struct pistachio_mux {
0029     unsigned int id;
0030     unsigned long reg;
0031     unsigned int shift;
0032     unsigned int num_parents;
0033     const char *name;
0034     const char **parents;
0035 };
0036 
0037 #define PNAME(x) static const char *x[] __initconst
0038 
0039 #define MUX(_id, _name, _pnames, _reg, _shift)          \
0040     {                           \
0041         .id     = _id,              \
0042         .reg        = _reg,             \
0043         .shift      = _shift,           \
0044         .name       = _name,            \
0045         .parents    = _pnames,          \
0046         .num_parents    = ARRAY_SIZE(_pnames)       \
0047     }
0048 
0049 
0050 struct pistachio_div {
0051     unsigned int id;
0052     unsigned long reg;
0053     unsigned int width;
0054     unsigned int div_flags;
0055     const char *name;
0056     const char *parent;
0057 };
0058 
0059 #define DIV(_id, _name, _pname, _reg, _width)           \
0060     {                           \
0061         .id     = _id,              \
0062         .reg        = _reg,             \
0063         .width      = _width,           \
0064         .div_flags  = 0,                \
0065         .name       = _name,            \
0066         .parent     = _pname,           \
0067     }
0068 
0069 #define DIV_F(_id, _name, _pname, _reg, _width, _div_flags) \
0070     {                           \
0071         .id     = _id,              \
0072         .reg        = _reg,             \
0073         .width      = _width,           \
0074         .div_flags  = _div_flags,           \
0075         .name       = _name,            \
0076         .parent     = _pname,           \
0077     }
0078 
0079 struct pistachio_fixed_factor {
0080     unsigned int id;
0081     unsigned int div;
0082     const char *name;
0083     const char *parent;
0084 };
0085 
0086 #define FIXED_FACTOR(_id, _name, _pname, _div)          \
0087     {                           \
0088         .id     = _id,              \
0089         .div        = _div,             \
0090         .name       = _name,            \
0091         .parent     = _pname,           \
0092     }
0093 
0094 struct pistachio_pll_rate_table {
0095     unsigned long long fref;
0096     unsigned long long fout;
0097     unsigned long long refdiv;
0098     unsigned long long fbdiv;
0099     unsigned long long postdiv1;
0100     unsigned long long postdiv2;
0101     unsigned long long frac;
0102 };
0103 
0104 enum pistachio_pll_type {
0105     PLL_GF40LP_LAINT,
0106     PLL_GF40LP_FRAC,
0107 };
0108 
0109 struct pistachio_pll {
0110     unsigned int id;
0111     unsigned long reg_base;
0112     enum pistachio_pll_type type;
0113     struct pistachio_pll_rate_table *rates;
0114     unsigned int nr_rates;
0115     const char *name;
0116     const char *parent;
0117 };
0118 
0119 #define PLL(_id, _name, _pname, _type, _reg, _rates)        \
0120     {                           \
0121         .id     = _id,              \
0122         .reg_base   = _reg,             \
0123         .type       = _type,            \
0124         .rates      = _rates,           \
0125         .nr_rates   = ARRAY_SIZE(_rates),       \
0126         .name       = _name,            \
0127         .parent     = _pname,           \
0128     }
0129 
0130 #define PLL_FIXED(_id, _name, _pname, _type, _reg)      \
0131     {                           \
0132         .id     = _id,              \
0133         .reg_base   = _reg,             \
0134         .type       = _type,            \
0135         .rates      = NULL,             \
0136         .nr_rates   = 0,                \
0137         .name       = _name,            \
0138         .parent     = _pname,           \
0139     }
0140 
0141 struct pistachio_clk_provider {
0142     struct device_node *node;
0143     void __iomem *base;
0144     struct clk_onecell_data clk_data;
0145 };
0146 
0147 extern struct pistachio_clk_provider *
0148 pistachio_clk_alloc_provider(struct device_node *node, unsigned int num_clks);
0149 extern void pistachio_clk_register_provider(struct pistachio_clk_provider *p);
0150 
0151 extern void pistachio_clk_register_gate(struct pistachio_clk_provider *p,
0152                     struct pistachio_gate *gate,
0153                     unsigned int num);
0154 extern void pistachio_clk_register_mux(struct pistachio_clk_provider *p,
0155                        struct pistachio_mux *mux,
0156                        unsigned int num);
0157 extern void pistachio_clk_register_div(struct pistachio_clk_provider *p,
0158                        struct pistachio_div *div,
0159                        unsigned int num);
0160 extern void
0161 pistachio_clk_register_fixed_factor(struct pistachio_clk_provider *p,
0162                     struct pistachio_fixed_factor *ff,
0163                     unsigned int num);
0164 extern void pistachio_clk_register_pll(struct pistachio_clk_provider *p,
0165                        struct pistachio_pll *pll,
0166                        unsigned int num);
0167 
0168 extern void pistachio_clk_force_enable(struct pistachio_clk_provider *p,
0169                        unsigned int *clk_ids, unsigned int num);
0170 
0171 #endif