xref: /openbmc/linux/drivers/clk/qcom/gdsc.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
197fb5e8dSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
245dd0e55SStephen Boyd /*
34e7c4d36STaniya Das  * Copyright (c) 2015, 2017-2018, 2022, The Linux Foundation. All rights reserved.
445dd0e55SStephen Boyd  */
545dd0e55SStephen Boyd 
645dd0e55SStephen Boyd #ifndef __QCOM_GDSC_H__
745dd0e55SStephen Boyd #define __QCOM_GDSC_H__
845dd0e55SStephen Boyd 
945dd0e55SStephen Boyd #include <linux/err.h>
1045dd0e55SStephen Boyd #include <linux/pm_domain.h>
1145dd0e55SStephen Boyd 
1245dd0e55SStephen Boyd struct regmap;
1337416e55SBjorn Andersson struct regulator;
143c53f5e2SRajendra Nayak struct reset_controller_dev;
1545dd0e55SStephen Boyd 
1645dd0e55SStephen Boyd /**
1745dd0e55SStephen Boyd  * struct gdsc - Globally Distributed Switch Controller
1845dd0e55SStephen Boyd  * @pd: generic power domain
1945dd0e55SStephen Boyd  * @regmap: regmap for MMIO accesses
2045dd0e55SStephen Boyd  * @gdscr: gsdc control register
2177ea2bd7SJohan Hovold  * @collapse_ctrl: APCS collapse-vote register
2277ea2bd7SJohan Hovold  * @collapse_mask: APCS collapse-vote mask
2377b1067aSRajendra Nayak  * @gds_hw_ctrl: gds_hw_ctrl register
24014e193cSRajendra Nayak  * @cxcs: offsets of branch registers to toggle mem/periph bits in
25014e193cSRajendra Nayak  * @cxc_count: number of @cxcs
26014e193cSRajendra Nayak  * @pwrsts: Possible powerdomain power states
274e7c4d36STaniya Das  * @en_rest_wait_val: transition delay value for receiving enr ack signal
284e7c4d36STaniya Das  * @en_few_wait_val: transition delay value for receiving enf ack signal
294e7c4d36STaniya Das  * @clk_dis_wait_val: transition delay value for halting clock
303c53f5e2SRajendra Nayak  * @resets: ids of resets associated with this gdsc
313c53f5e2SRajendra Nayak  * @reset_count: number of @resets
323c53f5e2SRajendra Nayak  * @rcdev: reset controller
3345dd0e55SStephen Boyd  */
3445dd0e55SStephen Boyd struct gdsc {
3545dd0e55SStephen Boyd 	struct generic_pm_domain	pd;
36c2c7f0a4SRajendra Nayak 	struct generic_pm_domain	*parent;
3745dd0e55SStephen Boyd 	struct regmap			*regmap;
3845dd0e55SStephen Boyd 	unsigned int			gdscr;
3977ea2bd7SJohan Hovold 	unsigned int			collapse_ctrl;
4077ea2bd7SJohan Hovold 	unsigned int			collapse_mask;
4177b1067aSRajendra Nayak 	unsigned int			gds_hw_ctrl;
42e7cc455fSRajendra Nayak 	unsigned int			clamp_io_ctrl;
43014e193cSRajendra Nayak 	unsigned int			*cxcs;
44014e193cSRajendra Nayak 	unsigned int			cxc_count;
454e7c4d36STaniya Das 	unsigned int			en_rest_wait_val;
464e7c4d36STaniya Das 	unsigned int			en_few_wait_val;
474e7c4d36STaniya Das 	unsigned int			clk_dis_wait_val;
48014e193cSRajendra Nayak 	const u8			pwrsts;
49a823bb9fSRajendra Nayak /* Powerdomain allowable state bitfields */
50a823bb9fSRajendra Nayak #define PWRSTS_OFF		BIT(0)
51*d3997239SRajendra Nayak /*
52*d3997239SRajendra Nayak  * There is no SW control to transition a GDSC into
53*d3997239SRajendra Nayak  * PWRSTS_RET. This happens in HW when the parent
54*d3997239SRajendra Nayak  * domain goes down to a low power state
55*d3997239SRajendra Nayak  */
56a823bb9fSRajendra Nayak #define PWRSTS_RET		BIT(1)
57a823bb9fSRajendra Nayak #define PWRSTS_ON		BIT(2)
58a823bb9fSRajendra Nayak #define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
59a823bb9fSRajendra Nayak #define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
60785c02ebSAngeloGioacchino Del Regno 	const u16			flags;
61a823bb9fSRajendra Nayak #define VOTABLE		BIT(0)
62e7cc455fSRajendra Nayak #define CLAMP_IO	BIT(1)
63904bb4f5SRajendra Nayak #define HW_CTRL		BIT(2)
6444dbeebfSAmit Nischal #define SW_RESET	BIT(3)
6544dbeebfSAmit Nischal #define AON_RESET	BIT(4)
66e892e17dSAmit Nischal #define POLL_CFG_GDSCR	BIT(5)
6777122d6fSStephen Boyd #define ALWAYS_ON	BIT(6)
6817372299STaniya Das #define RETAIN_FF_ENABLE	BIT(7)
69785c02ebSAngeloGioacchino Del Regno #define NO_RET_PERIPH	BIT(8)
703c53f5e2SRajendra Nayak 	struct reset_controller_dev	*rcdev;
713c53f5e2SRajendra Nayak 	unsigned int			*resets;
723c53f5e2SRajendra Nayak 	unsigned int			reset_count;
7337416e55SBjorn Andersson 
7437416e55SBjorn Andersson 	const char 			*supply;
7537416e55SBjorn Andersson 	struct regulator		*rsupply;
7645dd0e55SStephen Boyd };
7745dd0e55SStephen Boyd 
78c2c7f0a4SRajendra Nayak struct gdsc_desc {
79c2c7f0a4SRajendra Nayak 	struct device *dev;
80c2c7f0a4SRajendra Nayak 	struct gdsc **scs;
81c2c7f0a4SRajendra Nayak 	size_t num;
82c2c7f0a4SRajendra Nayak };
83c2c7f0a4SRajendra Nayak 
8445dd0e55SStephen Boyd #ifdef CONFIG_QCOM_GDSC
85c2c7f0a4SRajendra Nayak int gdsc_register(struct gdsc_desc *desc, struct reset_controller_dev *,
86c2c7f0a4SRajendra Nayak 		  struct regmap *);
87c2c7f0a4SRajendra Nayak void gdsc_unregister(struct gdsc_desc *desc);
880638226dSJonathan Marek int gdsc_gx_do_nothing_enable(struct generic_pm_domain *domain);
8945dd0e55SStephen Boyd #else
gdsc_register(struct gdsc_desc * desc,struct reset_controller_dev * rcdev,struct regmap * r)90c2c7f0a4SRajendra Nayak static inline int gdsc_register(struct gdsc_desc *desc,
913c53f5e2SRajendra Nayak 				struct reset_controller_dev *rcdev,
9245dd0e55SStephen Boyd 				struct regmap *r)
9345dd0e55SStephen Boyd {
9445dd0e55SStephen Boyd 	return -ENOSYS;
9545dd0e55SStephen Boyd }
9645dd0e55SStephen Boyd 
gdsc_unregister(struct gdsc_desc * desc)97c2c7f0a4SRajendra Nayak static inline void gdsc_unregister(struct gdsc_desc *desc) {};
9845dd0e55SStephen Boyd #endif /* CONFIG_QCOM_GDSC */
9945dd0e55SStephen Boyd #endif /* __QCOM_GDSC_H__ */
100