2019-06-04 11:11:33 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2013-03-09 12:02:44 +04:00
/*
* Copyright ( c ) 2013 Samsung Electronics Co . , Ltd .
* Copyright ( c ) 2013 Linaro Ltd .
* Author : Thomas Abraham < thomas . ab @ samsung . com >
*
* Common Clock Framework support for all Samsung platforms
*/
# ifndef __SAMSUNG_CLK_H
# define __SAMSUNG_CLK_H
# include <linux/clk-provider.h>
2013-06-11 13:31:07 +04:00
# include "clk-pll.h"
2013-03-09 12:02:44 +04:00
2014-03-12 18:56:44 +04:00
/**
* struct samsung_clk_provider : information about clock provider
* @ reg_base : virtual address for the register base .
2014-09-29 11:47:46 +04:00
* @ lock : maintains exclusion between callbacks for a given clock - provider .
2017-04-24 09:42:20 +03:00
* @ clk_data : holds clock related data like clk_hw * and number of clocks .
2014-03-12 18:56:44 +04:00
*/
struct samsung_clk_provider {
void __iomem * reg_base ;
2017-08-21 11:05:00 +03:00
struct device * dev ;
2014-03-12 18:56:44 +04:00
spinlock_t lock ;
2019-01-05 00:48:26 +03:00
/* clk_data must be the last entry due to variable length 'hws' array */
2017-04-24 09:42:20 +03:00
struct clk_hw_onecell_data clk_data ;
2014-03-12 18:56:44 +04:00
} ;
2013-03-18 08:43:56 +04:00
/**
* struct samsung_clock_alias : information about mux clock
* @ id : platform specific id of the clock .
* @ dev_name : name of the device to which this clock belongs .
* @ alias : optional clock alias name to be assigned to this clock .
*/
struct samsung_clock_alias {
unsigned int id ;
const char * dev_name ;
const char * alias ;
} ;
# define ALIAS(_id, dname, a) \
{ \
. id = _id , \
. dev_name = dname , \
. alias = a , \
}
2013-06-11 13:31:16 +04:00
# define MHZ (1000 * 1000)
2013-03-09 12:02:44 +04:00
/**
* struct samsung_fixed_rate_clock : information about fixed - rate clock
* @ id : platform specific id of the clock .
* @ name : name of this fixed - rate clock .
* @ parent_name : optional parent clock name .
* @ flags : optional fixed - rate clock flags .
* @ fixed - rate : fixed clock rate of this clock .
*/
struct samsung_fixed_rate_clock {
unsigned int id ;
char * name ;
const char * parent_name ;
unsigned long flags ;
unsigned long fixed_rate ;
} ;
# define FRATE(_id, cname, pname, f, frate) \
{ \
. id = _id , \
. name = cname , \
. parent_name = pname , \
. flags = f , \
. fixed_rate = frate , \
}
/*
* struct samsung_fixed_factor_clock : information about fixed - factor clock
* @ id : platform specific id of the clock .
* @ name : name of this fixed - factor clock .
* @ parent_name : parent clock name .
* @ mult : fixed multiplication factor .
* @ div : fixed division factor .
* @ flags : optional fixed - factor clock flags .
*/
struct samsung_fixed_factor_clock {
unsigned int id ;
char * name ;
const char * parent_name ;
unsigned long mult ;
unsigned long div ;
unsigned long flags ;
} ;
# define FFACTOR(_id, cname, pname, m, d, f) \
{ \
. id = _id , \
. name = cname , \
. parent_name = pname , \
. mult = m , \
. div = d , \
. flags = f , \
}
/**
* struct samsung_mux_clock : information about mux clock
* @ id : platform specific id of the clock .
* @ name : name of this mux clock .
* @ parent_names : array of pointer to parent clock names .
* @ num_parents : number of parents listed in @ parent_names .
* @ flags : optional flags for basic clock .
* @ offset : offset of the register for configuring the mux .
* @ shift : starting bit location of the mux control bit - field in @ reg .
* @ width : width of the mux control bit - field in @ reg .
* @ mux_flags : flags for mux - type clock .
*/
struct samsung_mux_clock {
unsigned int id ;
const char * name ;
2015-05-28 11:45:51 +03:00
const char * const * parent_names ;
2013-03-09 12:02:44 +04:00
u8 num_parents ;
unsigned long flags ;
unsigned long offset ;
u8 shift ;
u8 width ;
u8 mux_flags ;
} ;
2017-10-03 13:00:16 +03:00
# define __MUX(_id, cname, pnames, o, s, w, f, mf) \
2013-03-09 12:02:44 +04:00
{ \
. id = _id , \
. name = cname , \
. parent_names = pnames , \
. num_parents = ARRAY_SIZE ( pnames ) , \
2013-07-29 15:25:01 +04:00
. flags = ( f ) | CLK_SET_RATE_NO_REPARENT , \
2013-03-09 12:02:44 +04:00
. offset = o , \
. shift = s , \
. width = w , \
. mux_flags = mf , \
}
# define MUX(_id, cname, pnames, o, s, w) \
2017-10-03 13:00:16 +03:00
__MUX ( _id , cname , pnames , o , s , w , 0 , 0 )
2013-03-09 12:02:44 +04:00
# define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
2017-10-03 13:00:16 +03:00
__MUX ( _id , cname , pnames , o , s , w , f , mf )
2013-06-20 14:47:17 +04:00
2013-03-09 12:02:44 +04:00
/**
* @ id : platform specific id of the clock .
* struct samsung_div_clock : information about div clock
* @ name : name of this div clock .
* @ parent_name : name of the parent clock .
* @ flags : optional flags for basic clock .
* @ offset : offset of the register for configuring the div .
* @ shift : starting bit location of the div control bit - field in @ reg .
* @ div_flags : flags for div - type clock .
*/
struct samsung_div_clock {
unsigned int id ;
const char * name ;
const char * parent_name ;
unsigned long flags ;
unsigned long offset ;
u8 shift ;
u8 width ;
u8 div_flags ;
2013-03-18 08:43:52 +04:00
struct clk_div_table * table ;
2013-03-09 12:02:44 +04:00
} ;
2017-10-03 13:00:16 +03:00
# define __DIV(_id, cname, pname, o, s, w, f, df, t) \
2013-03-09 12:02:44 +04:00
{ \
. id = _id , \
. name = cname , \
. parent_name = pname , \
. flags = f , \
. offset = o , \
. shift = s , \
. width = w , \
. div_flags = df , \
2013-03-18 08:43:52 +04:00
. table = t , \
2013-03-09 12:02:44 +04:00
}
# define DIV(_id, cname, pname, o, s, w) \
2017-10-03 13:00:16 +03:00
__DIV ( _id , cname , pname , o , s , w , 0 , 0 , NULL )
2013-03-09 12:02:44 +04:00
# define DIV_F(_id, cname, pname, o, s, w, f, df) \
2017-10-03 13:00:16 +03:00
__DIV ( _id , cname , pname , o , s , w , f , df , NULL )
2013-03-18 08:43:52 +04:00
# define DIV_T(_id, cname, pname, o, s, w, t) \
2017-10-03 13:00:16 +03:00
__DIV ( _id , cname , pname , o , s , w , 0 , 0 , t )
2013-03-09 12:02:44 +04:00
/**
* struct samsung_gate_clock : information about gate clock
* @ id : platform specific id of the clock .
* @ name : name of this gate clock .
* @ parent_name : name of the parent clock .
* @ flags : optional flags for basic clock .
* @ offset : offset of the register for configuring the gate .
* @ bit_idx : bit index of the gate control bit - field in @ reg .
* @ gate_flags : flags for gate - type clock .
*/
struct samsung_gate_clock {
unsigned int id ;
const char * name ;
const char * parent_name ;
unsigned long flags ;
unsigned long offset ;
u8 bit_idx ;
u8 gate_flags ;
} ;
2017-10-03 13:00:16 +03:00
# define __GATE(_id, cname, pname, o, b, f, gf) \
2013-03-09 12:02:44 +04:00
{ \
. id = _id , \
. name = cname , \
. parent_name = pname , \
. flags = f , \
. offset = o , \
. bit_idx = b , \
. gate_flags = gf , \
}
# define GATE(_id, cname, pname, o, b, f, gf) \
2017-10-03 13:00:16 +03:00
__GATE ( _id , cname , pname , o , b , f , gf )
2013-03-09 12:02:44 +04:00
2016-05-11 15:02:14 +03:00
# define PNAME(x) static const char * const x[] __initconst
2013-03-09 12:02:44 +04:00
/**
* struct samsung_clk_reg_dump : register dump of clock controller registers .
* @ offset : clock register offset from the controller base address .
* @ value : the value to be register at offset .
*/
struct samsung_clk_reg_dump {
u32 offset ;
u32 value ;
} ;
2013-06-11 13:31:07 +04:00
/**
* struct samsung_pll_clock : information about pll clock
* @ id : platform specific id of the clock .
* @ name : name of this pll clock .
* @ parent_name : name of the parent clock .
* @ flags : optional flags for basic clock .
* @ con_offset : offset of the register for configuring the PLL .
* @ lock_offset : offset of the register for locking the PLL .
* @ type : Type of PLL to be registered .
*/
struct samsung_pll_clock {
unsigned int id ;
const char * name ;
const char * parent_name ;
unsigned long flags ;
int con_offset ;
int lock_offset ;
enum samsung_pll_type type ;
2013-06-11 13:31:12 +04:00
const struct samsung_pll_rate_table * rate_table ;
2013-06-11 13:31:07 +04:00
} ;
2017-10-03 13:00:16 +03:00
# define __PLL(_typ, _id, _name, _pname, _flags, _lock, _con, _rtable) \
2013-06-11 13:31:07 +04:00
{ \
. id = _id , \
. type = _typ , \
. name = _name , \
. parent_name = _pname , \
2017-09-14 17:38:17 +03:00
. flags = _flags , \
2013-06-11 13:31:07 +04:00
. con_offset = _con , \
. lock_offset = _lock , \
2013-06-11 13:31:12 +04:00
. rate_table = _rtable , \
2013-06-11 13:31:07 +04:00
}
2013-06-11 13:31:12 +04:00
# define PLL(_typ, _id, _name, _pname, _lock, _con, _rtable) \
2017-10-03 13:00:16 +03:00
__PLL ( _typ , _id , _name , _pname , CLK_GET_RATE_NOCACHE , _lock , \
_con , _rtable )
2013-06-11 13:31:07 +04:00
2021-10-14 22:53:45 +03:00
struct samsung_cpu_clock {
unsigned int id ;
const char * name ;
unsigned int parent_id ;
unsigned int alt_parent_id ;
unsigned long flags ;
int offset ;
const struct exynos_cpuclk_cfg_data * cfg ;
} ;
# define CPU_CLK(_id, _name, _pid, _apid, _flags, _offset, _cfg) \
{ \
. id = _id , \
. name = _name , \
. parent_id = _pid , \
. alt_parent_id = _apid , \
. flags = _flags , \
. offset = _offset , \
. cfg = _cfg , \
}
2014-09-22 08:47:02 +04:00
struct samsung_clock_reg_cache {
struct list_head node ;
void __iomem * reg_base ;
struct samsung_clk_reg_dump * rdump ;
unsigned int rd_num ;
2018-09-06 18:55:30 +03:00
const struct samsung_clk_reg_dump * rsuspend ;
unsigned int rsuspend_num ;
2014-09-22 08:47:02 +04:00
} ;
struct samsung_cmu_info {
/* list of pll clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_pll_clock * pll_clks ;
2014-09-22 08:47:02 +04:00
unsigned int nr_pll_clks ;
/* list of mux clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_mux_clock * mux_clks ;
2014-09-22 08:47:02 +04:00
unsigned int nr_mux_clks ;
/* list of div clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_div_clock * div_clks ;
2014-09-22 08:47:02 +04:00
unsigned int nr_div_clks ;
/* list of gate clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_gate_clock * gate_clks ;
2014-09-22 08:47:02 +04:00
unsigned int nr_gate_clks ;
/* list of fixed clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_fixed_rate_clock * fixed_clks ;
2014-09-22 08:47:02 +04:00
unsigned int nr_fixed_clks ;
2014-09-22 08:47:03 +04:00
/* list of fixed factor clocks and respective count */
2016-05-11 15:01:57 +03:00
const struct samsung_fixed_factor_clock * fixed_factor_clks ;
2014-09-22 08:47:03 +04:00
unsigned int nr_fixed_factor_clks ;
2014-09-22 08:47:02 +04:00
/* total number of clocks with IDs assigned*/
unsigned int nr_clk_ids ;
2021-10-14 22:53:45 +03:00
/* list of cpu clocks and respective count */
const struct samsung_cpu_clock * cpu_clks ;
unsigned int nr_cpu_clks ;
2014-09-22 08:47:02 +04:00
/* list and number of clocks registers */
2016-05-11 15:01:57 +03:00
const unsigned long * clk_regs ;
2014-09-22 08:47:02 +04:00
unsigned int nr_clk_regs ;
2017-08-21 11:05:01 +03:00
/* list and number of clocks registers to set before suspend */
const struct samsung_clk_reg_dump * suspend_regs ;
unsigned int nr_suspend_regs ;
/* name of the parent clock needed for CMU register access */
const char * clk_name ;
2014-09-22 08:47:02 +04:00
} ;
2021-10-15 18:14:25 +03:00
struct samsung_clk_provider * samsung_clk_init (
2014-03-12 18:56:44 +04:00
struct device_node * np , void __iomem * base ,
unsigned long nr_clks ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_of_add_provider ( struct device_node * np ,
2014-06-18 19:46:52 +04:00
struct samsung_clk_provider * ctx ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_of_register_fixed_ext (
2014-03-12 18:56:44 +04:00
struct samsung_clk_provider * ctx ,
struct samsung_fixed_rate_clock * fixed_rate_clk ,
unsigned int nr_fixed_rate_clk ,
2014-06-26 16:00:06 +04:00
const struct of_device_id * clk_matches ) ;
2013-03-09 12:02:44 +04:00
2021-10-15 18:14:25 +03:00
void samsung_clk_add_lookup ( struct samsung_clk_provider * ctx ,
2017-04-24 09:42:20 +03:00
struct clk_hw * clk_hw , unsigned int id ) ;
2013-03-09 12:02:44 +04:00
2021-10-15 18:14:25 +03:00
void samsung_clk_register_alias ( struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_clock_alias * list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_fixed_rate (
2014-03-12 18:56:44 +04:00
struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_fixed_rate_clock * clk_list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_fixed_factor (
2014-03-12 18:56:44 +04:00
struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_fixed_factor_clock * list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_mux ( struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_mux_clock * clk_list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_div ( struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_div_clock * clk_list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_gate ( struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_gate_clock * clk_list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_pll ( struct samsung_clk_provider * ctx ,
2015-05-28 11:45:51 +03:00
const struct samsung_pll_clock * pll_list ,
2014-03-12 18:56:44 +04:00
unsigned int nr_clk , void __iomem * base ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_register_cpu ( struct samsung_clk_provider * ctx ,
2021-10-14 22:53:45 +03:00
const struct samsung_cpu_clock * list , unsigned int nr_clk ) ;
2013-03-09 12:02:44 +04:00
2021-10-15 18:14:25 +03:00
struct samsung_clk_provider * samsung_cmu_register_one (
2014-12-23 10:40:21 +03:00
struct device_node * ,
2016-05-11 15:01:57 +03:00
const struct samsung_cmu_info * ) ;
2014-09-22 08:47:02 +04:00
2018-09-06 18:55:30 +03:00
# ifdef CONFIG_PM_SLEEP
2021-10-15 18:14:25 +03:00
void samsung_clk_extended_sleep_init ( void __iomem * reg_base ,
2016-05-24 16:19:15 +03:00
const unsigned long * rdump ,
2018-09-06 18:55:30 +03:00
unsigned long nr_rdump ,
const struct samsung_clk_reg_dump * rsuspend ,
unsigned long nr_rsuspend ) ;
# else
static inline void samsung_clk_extended_sleep_init ( void __iomem * reg_base ,
const unsigned long * rdump ,
unsigned long nr_rdump ,
const struct samsung_clk_reg_dump * rsuspend ,
unsigned long nr_rsuspend ) { }
# endif
# define samsung_clk_sleep_init(reg_base, rdump, nr_rdump) \
samsung_clk_extended_sleep_init ( reg_base , rdump , nr_rdump , NULL , 0 )
2016-05-24 16:19:15 +03:00
2021-10-15 18:14:25 +03:00
void samsung_clk_save ( void __iomem * base ,
2014-03-12 18:56:44 +04:00
struct samsung_clk_reg_dump * rd ,
unsigned int num_regs ) ;
2021-10-15 18:14:25 +03:00
void samsung_clk_restore ( void __iomem * base ,
2014-03-12 18:56:44 +04:00
const struct samsung_clk_reg_dump * rd ,
unsigned int num_regs ) ;
2021-10-15 18:14:25 +03:00
struct samsung_clk_reg_dump * samsung_clk_alloc_reg_dump (
2014-03-12 18:56:44 +04:00
const unsigned long * rdump ,
unsigned long nr_rdump ) ;
2014-02-14 03:16:00 +04:00
2013-03-09 12:02:44 +04:00
# endif /* __SAMSUNG_CLK_H */