xref: /freebsd/sys/dev/iicbus/pmic/act8846.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
14388c70cSMichal Meloun /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
34388c70cSMichal Meloun  *
44388c70cSMichal Meloun  * Copyright (c) 2019 Michal Meloun <mmel@FreeBSD.org>
54388c70cSMichal Meloun  * All rights reserved.
64388c70cSMichal Meloun  *
74388c70cSMichal Meloun  * Redistribution and use in source and binary forms, with or without
84388c70cSMichal Meloun  * modification, are permitted provided that the following conditions
94388c70cSMichal Meloun  * are met:
104388c70cSMichal Meloun  * 1. Redistributions of source code must retain the above copyright
114388c70cSMichal Meloun  *    notice, this list of conditions and the following disclaimer.
124388c70cSMichal Meloun  * 2. Redistributions in binary form must reproduce the above copyright
134388c70cSMichal Meloun  *    notice, this list of conditions and the following disclaimer in the
144388c70cSMichal Meloun  *    documentation and/or other materials provided with the distribution.
154388c70cSMichal Meloun  *
164388c70cSMichal Meloun  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174388c70cSMichal Meloun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184388c70cSMichal Meloun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194388c70cSMichal Meloun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204388c70cSMichal Meloun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214388c70cSMichal Meloun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224388c70cSMichal Meloun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234388c70cSMichal Meloun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244388c70cSMichal Meloun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254388c70cSMichal Meloun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264388c70cSMichal Meloun  * SUCH DAMAGE.
274388c70cSMichal Meloun  */
284388c70cSMichal Meloun 
294388c70cSMichal Meloun #ifndef _ACT8846_H_
304388c70cSMichal Meloun #define _ACT8846_H_
314388c70cSMichal Meloun 
324388c70cSMichal Meloun #include <dev/iicbus/pmic/act8846_reg.h>
334388c70cSMichal Meloun 
344388c70cSMichal Meloun struct act8846_reg_sc;
354388c70cSMichal Meloun struct act8846_gpio_pin;
364388c70cSMichal Meloun 
374388c70cSMichal Meloun struct act8846_softc {
384388c70cSMichal Meloun 	device_t		dev;
394388c70cSMichal Meloun 	struct sx		lock;
404388c70cSMichal Meloun 	int			bus_addr;
414388c70cSMichal Meloun 
424388c70cSMichal Meloun 	/* Regulators. */
434388c70cSMichal Meloun 	struct act8846_reg_sc	**regs;
444388c70cSMichal Meloun 	int			nregs;
454388c70cSMichal Meloun };
464388c70cSMichal Meloun 
474388c70cSMichal Meloun #define	RD1(sc, reg, val)	act8846_read(sc, reg, val)
484388c70cSMichal Meloun #define	WR1(sc, reg, val)	act8846_write(sc, reg, val)
494388c70cSMichal Meloun #define	RM1(sc, reg, clr, set)	act8846_modify(sc, reg, clr, set)
504388c70cSMichal Meloun 
514388c70cSMichal Meloun int act8846_read(struct act8846_softc *sc, uint8_t reg, uint8_t *val);
524388c70cSMichal Meloun int act8846_write(struct act8846_softc *sc, uint8_t reg, uint8_t val);
534388c70cSMichal Meloun int act8846_modify(struct act8846_softc *sc, uint8_t reg, uint8_t clear,
544388c70cSMichal Meloun     uint8_t set);
554388c70cSMichal Meloun int act8846_read_buf(struct act8846_softc *sc, uint8_t reg, uint8_t *buf,
564388c70cSMichal Meloun     size_t size);
574388c70cSMichal Meloun int act8846_write_buf(struct act8846_softc *sc, uint8_t reg, uint8_t *buf,
584388c70cSMichal Meloun     size_t size);
594388c70cSMichal Meloun 
604388c70cSMichal Meloun /* Regulators */
614388c70cSMichal Meloun int act8846_regulator_attach(struct act8846_softc *sc, phandle_t node);
624388c70cSMichal Meloun int act8846_regulator_map(device_t dev, phandle_t xref, int ncells,
634388c70cSMichal Meloun     pcell_t *cells, int *num);
644388c70cSMichal Meloun 
654388c70cSMichal Meloun #endif /* _ACT8846_H_ */
66