xref: /freebsd/sys/dev/iicbus/pmic/rockchip/rk8xx.h (revision 833a452e9f082a7982a31c21f0da437dbbe0a39d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2021 Emmanuel Vadot <manu@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _RK8XX_H_
29 #define	_RK8XX_H_
30 
31 #include <sys/kernel.h>
32 
33 #include <dev/ofw/ofw_bus.h>
34 #include <dev/ofw/ofw_bus_subr.h>
35 
36 enum rk_pmic_type {
37 	RK805 = 1,
38 	RK808,
39 };
40 
41 struct rk8xx_regdef {
42 	intptr_t		id;
43 	char			*name;
44 	uint8_t			enable_reg;
45 	uint8_t			enable_mask;
46 	uint8_t			voltage_reg;
47 	uint8_t			voltage_mask;
48 	int			voltage_min;
49 	int			voltage_max;
50 	int			voltage_step;
51 	int			voltage_nstep;
52 };
53 
54 struct rk8xx_reg_sc {
55 	struct regnode		*regnode;
56 	device_t		base_dev;
57 	struct rk8xx_regdef	*def;
58 	phandle_t		xref;
59 	struct regnode_std_param *param;
60 };
61 
62 struct reg_list {
63 	TAILQ_ENTRY(reg_list)	next;
64 	struct rk8xx_reg_sc	*reg;
65 };
66 
67 struct rk8xx_rtc_reg {
68 	uint8_t	secs;
69 	uint8_t	secs_mask;
70 	uint8_t	minutes;
71 	uint8_t	minutes_mask;
72 	uint8_t	hours;
73 	uint8_t	hours_mask;
74 	uint8_t	days;
75 	uint8_t	days_mask;
76 	uint8_t	months;
77 	uint8_t	months_mask;
78 	uint8_t	years;
79 	uint8_t	weeks;
80 	uint8_t	weeks_mask;
81 	uint8_t	ctrl;
82 	uint8_t	ctrl_stop_mask;
83 	uint8_t	ctrl_ampm_mask;
84 	uint8_t	ctrl_gettime_mask;
85 	uint8_t	ctrl_readsel_mask;
86 };
87 
88 struct rk8xx_dev_ctrl {
89 	uint8_t	dev_ctrl_reg;
90 	uint8_t	pwr_off_mask;
91 };
92 
93 struct rk8xx_softc {
94 	device_t		dev;
95 	struct mtx		mtx;
96 	struct resource *	res[1];
97 	void *			intrcookie;
98 	struct intr_config_hook	intr_hook;
99 	enum rk_pmic_type	type;
100 
101 	struct rk8xx_regdef	*regdefs;
102 	TAILQ_HEAD(, reg_list)	regs;
103 	int			nregs;
104 
105 	struct rk8xx_rtc_reg	rtc_regs;
106 	struct rk8xx_dev_ctrl	dev_ctrl;
107 };
108 
109 int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
110 int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
111 
112 DECLARE_CLASS(rk8xx_driver);
113 
114 int rk8xx_attach(struct rk8xx_softc *sc);
115 
116 /* rk8xx_clocks.c */
117 int rk8xx_attach_clocks(struct rk8xx_softc *sc);
118 
119 /* rk8xx_regulators.c */
120 void rk8xx_attach_regulators(struct rk8xx_softc *sc);
121 int rk8xx_map(device_t dev, phandle_t xref, int ncells,
122     pcell_t *cells, intptr_t *id);
123 
124 /* rk8xx_rtc.c */
125 int rk8xx_gettime(device_t dev, struct timespec *ts);
126 int rk8xx_settime(device_t dev, struct timespec *ts);
127 
128 #endif	/* _RK8XX_H_ */
129