xref: /freebsd/sys/dev/iicbus/pmic/rockchip/rk8xx.h (revision 266f97b5)
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_softc {
89 	device_t		dev;
90 	struct mtx		mtx;
91 	struct resource *	res[1];
92 	void *			intrcookie;
93 	struct intr_config_hook	intr_hook;
94 	enum rk_pmic_type	type;
95 
96 	struct rk8xx_regdef	*regdefs;
97 	TAILQ_HEAD(, reg_list)	regs;
98 	int			nregs;
99 
100 	struct rk8xx_rtc_reg	rtc_regs;
101 };
102 
103 int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
104 int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
105 
106 DECLARE_CLASS(rk8xx_driver);
107 
108 int rk8xx_attach(struct rk8xx_softc *sc);
109 
110 /* rk8xx_clocks.c */
111 int rk8xx_attach_clocks(struct rk8xx_softc *sc);
112 
113 /* rk8xx_regulators.c */
114 void rk8xx_attach_regulators(struct rk8xx_softc *sc);
115 int rk8xx_map(device_t dev, phandle_t xref, int ncells,
116     pcell_t *cells, intptr_t *id);
117 
118 /* rk8xx_rtc.c */
119 int rk8xx_gettime(device_t dev, struct timespec *ts);
120 int rk8xx_settime(device_t dev, struct timespec *ts);
121 
122 #endif	/* _RK8XX_H_ */
123