xref: /freebsd/sys/dev/iicbus/pmic/rockchip/rk8xx.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1328077bbSEmmanuel Vadot /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3328077bbSEmmanuel Vadot  *
4328077bbSEmmanuel Vadot  * Copyright (c) 2021 Emmanuel Vadot <manu@FreeBSD.org>
5328077bbSEmmanuel Vadot  *
6328077bbSEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
7328077bbSEmmanuel Vadot  * modification, are permitted provided that the following conditions
8328077bbSEmmanuel Vadot  * are met:
9328077bbSEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
10328077bbSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
11328077bbSEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
12328077bbSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
13328077bbSEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
14328077bbSEmmanuel Vadot  *
15328077bbSEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16328077bbSEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17328077bbSEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18328077bbSEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19328077bbSEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20328077bbSEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21328077bbSEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22328077bbSEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23328077bbSEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24328077bbSEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25328077bbSEmmanuel Vadot  * SUCH DAMAGE.
26328077bbSEmmanuel Vadot  */
27328077bbSEmmanuel Vadot 
28328077bbSEmmanuel Vadot #ifndef _RK8XX_H_
29328077bbSEmmanuel Vadot #define	_RK8XX_H_
30328077bbSEmmanuel Vadot 
31328077bbSEmmanuel Vadot #include <sys/kernel.h>
32328077bbSEmmanuel Vadot 
33328077bbSEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
34328077bbSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
35328077bbSEmmanuel Vadot 
36328077bbSEmmanuel Vadot enum rk_pmic_type {
37328077bbSEmmanuel Vadot 	RK805 = 1,
38328077bbSEmmanuel Vadot 	RK808,
3966a3e513SSøren Schmidt 	RK809,
4066a3e513SSøren Schmidt 	RK817,
41328077bbSEmmanuel Vadot };
42328077bbSEmmanuel Vadot 
43328077bbSEmmanuel Vadot struct rk8xx_regdef {
44328077bbSEmmanuel Vadot 	intptr_t		id;
45328077bbSEmmanuel Vadot 	char			*name;
46328077bbSEmmanuel Vadot 	uint8_t			enable_reg;
47328077bbSEmmanuel Vadot 	uint8_t			enable_mask;
48328077bbSEmmanuel Vadot 	uint8_t			voltage_reg;
49328077bbSEmmanuel Vadot 	uint8_t			voltage_mask;
50328077bbSEmmanuel Vadot 	int			voltage_min;
51328077bbSEmmanuel Vadot 	int			voltage_max;
5266a3e513SSøren Schmidt 	int			voltage_min2;
5366a3e513SSøren Schmidt 	int			voltage_max2;
54328077bbSEmmanuel Vadot 	int			voltage_step;
5566a3e513SSøren Schmidt 	int			voltage_step2;
56328077bbSEmmanuel Vadot 	int			voltage_nstep;
57328077bbSEmmanuel Vadot };
58328077bbSEmmanuel Vadot 
59328077bbSEmmanuel Vadot struct rk8xx_reg_sc {
60328077bbSEmmanuel Vadot 	struct regnode		*regnode;
61328077bbSEmmanuel Vadot 	device_t		base_dev;
62328077bbSEmmanuel Vadot 	struct rk8xx_regdef	*def;
63328077bbSEmmanuel Vadot 	phandle_t		xref;
64328077bbSEmmanuel Vadot 	struct regnode_std_param *param;
65328077bbSEmmanuel Vadot };
66328077bbSEmmanuel Vadot 
67328077bbSEmmanuel Vadot struct reg_list {
68328077bbSEmmanuel Vadot 	TAILQ_ENTRY(reg_list)	next;
69328077bbSEmmanuel Vadot 	struct rk8xx_reg_sc	*reg;
70328077bbSEmmanuel Vadot };
71328077bbSEmmanuel Vadot 
72328077bbSEmmanuel Vadot struct rk8xx_rtc_reg {
73328077bbSEmmanuel Vadot 	uint8_t	secs;
74328077bbSEmmanuel Vadot 	uint8_t	secs_mask;
75328077bbSEmmanuel Vadot 	uint8_t	minutes;
76328077bbSEmmanuel Vadot 	uint8_t	minutes_mask;
77328077bbSEmmanuel Vadot 	uint8_t	hours;
78328077bbSEmmanuel Vadot 	uint8_t	hours_mask;
79328077bbSEmmanuel Vadot 	uint8_t	days;
80328077bbSEmmanuel Vadot 	uint8_t	days_mask;
81328077bbSEmmanuel Vadot 	uint8_t	months;
82328077bbSEmmanuel Vadot 	uint8_t	months_mask;
83328077bbSEmmanuel Vadot 	uint8_t	years;
84328077bbSEmmanuel Vadot 	uint8_t	weeks;
85328077bbSEmmanuel Vadot 	uint8_t	weeks_mask;
86328077bbSEmmanuel Vadot 	uint8_t	ctrl;
87328077bbSEmmanuel Vadot 	uint8_t	ctrl_stop_mask;
88328077bbSEmmanuel Vadot 	uint8_t	ctrl_ampm_mask;
89328077bbSEmmanuel Vadot 	uint8_t	ctrl_gettime_mask;
90328077bbSEmmanuel Vadot 	uint8_t	ctrl_readsel_mask;
91328077bbSEmmanuel Vadot };
92328077bbSEmmanuel Vadot 
9394f4afd7SAndriy Gapon struct rk8xx_dev_ctrl {
9494f4afd7SAndriy Gapon 	uint8_t	dev_ctrl_reg;
9594f4afd7SAndriy Gapon 	uint8_t	pwr_off_mask;
9666a3e513SSøren Schmidt 	uint8_t	pwr_rst_mask;
9794f4afd7SAndriy Gapon };
9894f4afd7SAndriy Gapon 
99328077bbSEmmanuel Vadot struct rk8xx_softc {
100328077bbSEmmanuel Vadot 	device_t		dev;
101328077bbSEmmanuel Vadot 	struct mtx		mtx;
102328077bbSEmmanuel Vadot 	struct resource *	res[1];
103328077bbSEmmanuel Vadot 	void *			intrcookie;
104328077bbSEmmanuel Vadot 	struct intr_config_hook	intr_hook;
105328077bbSEmmanuel Vadot 	enum rk_pmic_type	type;
106328077bbSEmmanuel Vadot 
10798c60dc3SEmmanuel Vadot 	struct rk8xx_regdef	*regdefs;
108328077bbSEmmanuel Vadot 	TAILQ_HEAD(, reg_list)	regs;
109328077bbSEmmanuel Vadot 	int			nregs;
110328077bbSEmmanuel Vadot 
111328077bbSEmmanuel Vadot 	struct rk8xx_rtc_reg	rtc_regs;
11294f4afd7SAndriy Gapon 	struct rk8xx_dev_ctrl	dev_ctrl;
113328077bbSEmmanuel Vadot };
114328077bbSEmmanuel Vadot 
115328077bbSEmmanuel Vadot int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
116328077bbSEmmanuel Vadot int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
117328077bbSEmmanuel Vadot 
11898c60dc3SEmmanuel Vadot DECLARE_CLASS(rk8xx_driver);
11998c60dc3SEmmanuel Vadot 
12098c60dc3SEmmanuel Vadot int rk8xx_attach(struct rk8xx_softc *sc);
12198c60dc3SEmmanuel Vadot 
122cb3c3e0aSEmmanuel Vadot /* rk8xx_clocks.c */
12398c60dc3SEmmanuel Vadot int rk8xx_attach_clocks(struct rk8xx_softc *sc);
124cb3c3e0aSEmmanuel Vadot 
125ad651f17SEmmanuel Vadot /* rk8xx_regulators.c */
12698c60dc3SEmmanuel Vadot void rk8xx_attach_regulators(struct rk8xx_softc *sc);
127ad651f17SEmmanuel Vadot int rk8xx_map(device_t dev, phandle_t xref, int ncells,
128ad651f17SEmmanuel Vadot     pcell_t *cells, intptr_t *id);
129ad651f17SEmmanuel Vadot 
130328077bbSEmmanuel Vadot /* rk8xx_rtc.c */
131328077bbSEmmanuel Vadot int rk8xx_gettime(device_t dev, struct timespec *ts);
132328077bbSEmmanuel Vadot int rk8xx_settime(device_t dev, struct timespec *ts);
133328077bbSEmmanuel Vadot 
134328077bbSEmmanuel Vadot #endif	/* _RK8XX_H_ */
135