Home | History | Annotate | Line # | Download | only in onewire
      1 /* $NetBSD: onewirevar.h,v 1.7 2024/11/06 19:40:11 riastradh Exp $ */
      2 /*	$OpenBSD: onewirevar.h,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 2006 Alexander Yurchenko <grange (at) openbsd.org>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 
     20 #ifndef _DEV_ONEWIRE_ONEWIREVAR_H_
     21 #define _DEV_ONEWIRE_ONEWIREVAR_H_
     22 
     23 #include <sys/types.h>
     24 
     25 /*
     26  * 1-Wire bus interface.
     27  */
     28 
     29 /* Bus master interface */
     30 struct onewire_bus {
     31 	void *	bus_cookie;
     32 
     33 	int	(*bus_reset)(void *);
     34 	int	(*bus_read_bit)(void *);
     35 	void	(*bus_write_bit)(void *, int);
     36 	int	(*bus_read_byte)(void *);
     37 	void	(*bus_write_byte)(void *, int);
     38 	int	(*bus_triplet)(void *, int);
     39 };
     40 
     41 /* Bus methods */
     42 void		onewire_lock(void *);
     43 void		onewire_unlock(void *);
     44 int		onewire_reset(void *);
     45 int		onewire_read_bit(void *);
     46 void		onewire_write_bit(void *, int);
     47 int		onewire_read_byte(void *);
     48 void		onewire_write_byte(void *, int);
     49 int		onewire_triplet(void *, int);
     50 void		onewire_read_block(void *, void *, int);
     51 void		onewire_write_block(void *, const void *, int);
     52 void		onewire_matchrom(void *, uint64_t);
     53 
     54 /* Bus attachment */
     55 struct onewirebus_attach_args {
     56 	struct onewire_bus *	oba_bus;
     57 };
     58 
     59 int	onewirebus_print(void *, const char *);
     60 
     61 /* Device attachment */
     62 struct onewire_attach_args {
     63 	void *			oa_onewire;
     64 	uint64_t		oa_rom;
     65 };
     66 
     67 /* Family matching */
     68 struct onewire_matchfam {
     69 	int om_type;
     70 };
     71 
     72 /* Miscellaneous routines */
     73 int		onewire_crc(const void *, int);
     74 const char *	onewire_famname(int);
     75 int		onewire_matchbyfam(struct onewire_attach_args *,
     76 		    const struct onewire_matchfam *, int);
     77 
     78 /* Bus bit-banging */
     79 struct onewire_bbops {
     80 	void	(*bb_rx)(void *);
     81 	void	(*bb_tx)(void *);
     82 	int	(*bb_get)(void *);
     83 	void	(*bb_set)(void *, int);
     84 };
     85 
     86 int		onewire_bb_reset(const struct onewire_bbops *, void *);
     87 int		onewire_bb_read_bit(const struct onewire_bbops *, void *);
     88 void		onewire_bb_write_bit(const struct onewire_bbops *, void *, int);
     89 
     90 #endif	/* !_DEV_ONEWIRE_ONEWIREVAR_H_ */
     91