1328077bbSEmmanuel Vadot /*- 2328077bbSEmmanuel Vadot * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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, 39328077bbSEmmanuel Vadot }; 40328077bbSEmmanuel Vadot 41328077bbSEmmanuel Vadot struct rk8xx_regdef { 42328077bbSEmmanuel Vadot intptr_t id; 43328077bbSEmmanuel Vadot char *name; 44328077bbSEmmanuel Vadot uint8_t enable_reg; 45328077bbSEmmanuel Vadot uint8_t enable_mask; 46328077bbSEmmanuel Vadot uint8_t voltage_reg; 47328077bbSEmmanuel Vadot uint8_t voltage_mask; 48328077bbSEmmanuel Vadot int voltage_min; 49328077bbSEmmanuel Vadot int voltage_max; 50328077bbSEmmanuel Vadot int voltage_step; 51328077bbSEmmanuel Vadot int voltage_nstep; 52328077bbSEmmanuel Vadot }; 53328077bbSEmmanuel Vadot 54328077bbSEmmanuel Vadot struct rk8xx_reg_sc { 55328077bbSEmmanuel Vadot struct regnode *regnode; 56328077bbSEmmanuel Vadot device_t base_dev; 57328077bbSEmmanuel Vadot struct rk8xx_regdef *def; 58328077bbSEmmanuel Vadot phandle_t xref; 59328077bbSEmmanuel Vadot struct regnode_std_param *param; 60328077bbSEmmanuel Vadot }; 61328077bbSEmmanuel Vadot 62328077bbSEmmanuel Vadot struct reg_list { 63328077bbSEmmanuel Vadot TAILQ_ENTRY(reg_list) next; 64328077bbSEmmanuel Vadot struct rk8xx_reg_sc *reg; 65328077bbSEmmanuel Vadot }; 66328077bbSEmmanuel Vadot 67328077bbSEmmanuel Vadot struct rk8xx_rtc_reg { 68328077bbSEmmanuel Vadot uint8_t secs; 69328077bbSEmmanuel Vadot uint8_t secs_mask; 70328077bbSEmmanuel Vadot uint8_t minutes; 71328077bbSEmmanuel Vadot uint8_t minutes_mask; 72328077bbSEmmanuel Vadot uint8_t hours; 73328077bbSEmmanuel Vadot uint8_t hours_mask; 74328077bbSEmmanuel Vadot uint8_t days; 75328077bbSEmmanuel Vadot uint8_t days_mask; 76328077bbSEmmanuel Vadot uint8_t months; 77328077bbSEmmanuel Vadot uint8_t months_mask; 78328077bbSEmmanuel Vadot uint8_t years; 79328077bbSEmmanuel Vadot uint8_t weeks; 80328077bbSEmmanuel Vadot uint8_t weeks_mask; 81328077bbSEmmanuel Vadot uint8_t ctrl; 82328077bbSEmmanuel Vadot uint8_t ctrl_stop_mask; 83328077bbSEmmanuel Vadot uint8_t ctrl_ampm_mask; 84328077bbSEmmanuel Vadot uint8_t ctrl_gettime_mask; 85328077bbSEmmanuel Vadot uint8_t ctrl_readsel_mask; 86328077bbSEmmanuel Vadot }; 87328077bbSEmmanuel Vadot 88*94f4afd7SAndriy Gapon struct rk8xx_dev_ctrl { 89*94f4afd7SAndriy Gapon uint8_t dev_ctrl_reg; 90*94f4afd7SAndriy Gapon uint8_t pwr_off_mask; 91*94f4afd7SAndriy Gapon }; 92*94f4afd7SAndriy Gapon 93328077bbSEmmanuel Vadot struct rk8xx_softc { 94328077bbSEmmanuel Vadot device_t dev; 95328077bbSEmmanuel Vadot struct mtx mtx; 96328077bbSEmmanuel Vadot struct resource * res[1]; 97328077bbSEmmanuel Vadot void * intrcookie; 98328077bbSEmmanuel Vadot struct intr_config_hook intr_hook; 99328077bbSEmmanuel Vadot enum rk_pmic_type type; 100328077bbSEmmanuel Vadot 10198c60dc3SEmmanuel Vadot struct rk8xx_regdef *regdefs; 102328077bbSEmmanuel Vadot TAILQ_HEAD(, reg_list) regs; 103328077bbSEmmanuel Vadot int nregs; 104328077bbSEmmanuel Vadot 105328077bbSEmmanuel Vadot struct rk8xx_rtc_reg rtc_regs; 106*94f4afd7SAndriy Gapon struct rk8xx_dev_ctrl dev_ctrl; 107328077bbSEmmanuel Vadot }; 108328077bbSEmmanuel Vadot 109328077bbSEmmanuel Vadot int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); 110328077bbSEmmanuel Vadot int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); 111328077bbSEmmanuel Vadot 11298c60dc3SEmmanuel Vadot DECLARE_CLASS(rk8xx_driver); 11398c60dc3SEmmanuel Vadot 11498c60dc3SEmmanuel Vadot int rk8xx_attach(struct rk8xx_softc *sc); 11598c60dc3SEmmanuel Vadot 116cb3c3e0aSEmmanuel Vadot /* rk8xx_clocks.c */ 11798c60dc3SEmmanuel Vadot int rk8xx_attach_clocks(struct rk8xx_softc *sc); 118cb3c3e0aSEmmanuel Vadot 119ad651f17SEmmanuel Vadot /* rk8xx_regulators.c */ 12098c60dc3SEmmanuel Vadot void rk8xx_attach_regulators(struct rk8xx_softc *sc); 121ad651f17SEmmanuel Vadot int rk8xx_map(device_t dev, phandle_t xref, int ncells, 122ad651f17SEmmanuel Vadot pcell_t *cells, intptr_t *id); 123ad651f17SEmmanuel Vadot 124328077bbSEmmanuel Vadot /* rk8xx_rtc.c */ 125328077bbSEmmanuel Vadot int rk8xx_gettime(device_t dev, struct timespec *ts); 126328077bbSEmmanuel Vadot int rk8xx_settime(device_t dev, struct timespec *ts); 127328077bbSEmmanuel Vadot 128328077bbSEmmanuel Vadot #endif /* _RK8XX_H_ */ 129