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 TAILQ_HEAD(, reg_list) regs; 97 int nregs; 98 99 struct rk8xx_rtc_reg rtc_regs; 100 }; 101 102 int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); 103 int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); 104 105 /* rk8xx_regulators.c */ 106 struct rk8xx_reg_sc *rk8xx_reg_attach(device_t dev, phandle_t node, 107 struct rk8xx_regdef *def); 108 int rk8xx_map(device_t dev, phandle_t xref, int ncells, 109 pcell_t *cells, intptr_t *id); 110 111 /* rk8xx_rtc.c */ 112 int rk8xx_gettime(device_t dev, struct timespec *ts); 113 int rk8xx_settime(device_t dev, struct timespec *ts); 114 115 #endif /* _RK8XX_H_ */ 116