xref: /freebsd/sys/dev/iicbus/pmic/rockchip/rk8xx.h (revision bdd1243d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 	RK809,
40 	RK817,
41 };
42 
43 struct rk8xx_regdef {
44 	intptr_t		id;
45 	char			*name;
46 	uint8_t			enable_reg;
47 	uint8_t			enable_mask;
48 	uint8_t			voltage_reg;
49 	uint8_t			voltage_mask;
50 	int			voltage_min;
51 	int			voltage_max;
52 	int			voltage_min2;
53 	int			voltage_max2;
54 	int			voltage_step;
55 	int			voltage_step2;
56 	int			voltage_nstep;
57 };
58 
59 struct rk8xx_reg_sc {
60 	struct regnode		*regnode;
61 	device_t		base_dev;
62 	struct rk8xx_regdef	*def;
63 	phandle_t		xref;
64 	struct regnode_std_param *param;
65 };
66 
67 struct reg_list {
68 	TAILQ_ENTRY(reg_list)	next;
69 	struct rk8xx_reg_sc	*reg;
70 };
71 
72 struct rk8xx_rtc_reg {
73 	uint8_t	secs;
74 	uint8_t	secs_mask;
75 	uint8_t	minutes;
76 	uint8_t	minutes_mask;
77 	uint8_t	hours;
78 	uint8_t	hours_mask;
79 	uint8_t	days;
80 	uint8_t	days_mask;
81 	uint8_t	months;
82 	uint8_t	months_mask;
83 	uint8_t	years;
84 	uint8_t	weeks;
85 	uint8_t	weeks_mask;
86 	uint8_t	ctrl;
87 	uint8_t	ctrl_stop_mask;
88 	uint8_t	ctrl_ampm_mask;
89 	uint8_t	ctrl_gettime_mask;
90 	uint8_t	ctrl_readsel_mask;
91 };
92 
93 struct rk8xx_dev_ctrl {
94 	uint8_t	dev_ctrl_reg;
95 	uint8_t	pwr_off_mask;
96 	uint8_t	pwr_rst_mask;
97 };
98 
99 struct rk8xx_softc {
100 	device_t		dev;
101 	struct mtx		mtx;
102 	struct resource *	res[1];
103 	void *			intrcookie;
104 	struct intr_config_hook	intr_hook;
105 	enum rk_pmic_type	type;
106 
107 	struct rk8xx_regdef	*regdefs;
108 	TAILQ_HEAD(, reg_list)	regs;
109 	int			nregs;
110 
111 	struct rk8xx_rtc_reg	rtc_regs;
112 	struct rk8xx_dev_ctrl	dev_ctrl;
113 };
114 
115 int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
116 int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size);
117 
118 DECLARE_CLASS(rk8xx_driver);
119 
120 int rk8xx_attach(struct rk8xx_softc *sc);
121 
122 /* rk8xx_clocks.c */
123 int rk8xx_attach_clocks(struct rk8xx_softc *sc);
124 
125 /* rk8xx_regulators.c */
126 void rk8xx_attach_regulators(struct rk8xx_softc *sc);
127 int rk8xx_map(device_t dev, phandle_t xref, int ncells,
128     pcell_t *cells, intptr_t *id);
129 
130 /* rk8xx_rtc.c */
131 int rk8xx_gettime(device_t dev, struct timespec *ts);
132 int rk8xx_settime(device_t dev, struct timespec *ts);
133 
134 #endif	/* _RK8XX_H_ */
135