xref: /netbsd-src/sys/dev/onewire/onewirevar.h (revision 6a40aed596861505f8e28ed60975e665d9b97e7b)
1*6a40aed5Sriastradh /* $NetBSD: onewirevar.h,v 1.7 2024/11/06 19:40:11 riastradh Exp $ */
2637bfc29Sriz /*	$OpenBSD: onewirevar.h,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
3637bfc29Sriz 
4637bfc29Sriz /*
5637bfc29Sriz  * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
6637bfc29Sriz  *
7637bfc29Sriz  * Permission to use, copy, modify, and distribute this software for any
8637bfc29Sriz  * purpose with or without fee is hereby granted, provided that the above
9637bfc29Sriz  * copyright notice and this permission notice appear in all copies.
10637bfc29Sriz  *
11637bfc29Sriz  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12637bfc29Sriz  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13637bfc29Sriz  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14637bfc29Sriz  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15637bfc29Sriz  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16637bfc29Sriz  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17637bfc29Sriz  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18637bfc29Sriz  */
19637bfc29Sriz 
20637bfc29Sriz #ifndef _DEV_ONEWIRE_ONEWIREVAR_H_
21637bfc29Sriz #define _DEV_ONEWIRE_ONEWIREVAR_H_
22637bfc29Sriz 
23*6a40aed5Sriastradh #include <sys/types.h>
24*6a40aed5Sriastradh 
25637bfc29Sriz /*
26637bfc29Sriz  * 1-Wire bus interface.
27637bfc29Sriz  */
28637bfc29Sriz 
29637bfc29Sriz /* Bus master interface */
30637bfc29Sriz struct onewire_bus {
31637bfc29Sriz 	void *	bus_cookie;
32637bfc29Sriz 
33637bfc29Sriz 	int	(*bus_reset)(void *);
34e7a559b6Sad 	int	(*bus_read_bit)(void *);
35e7a559b6Sad 	void	(*bus_write_bit)(void *, int);
36637bfc29Sriz 	int	(*bus_read_byte)(void *);
37637bfc29Sriz 	void	(*bus_write_byte)(void *, int);
38637bfc29Sriz 	int	(*bus_triplet)(void *, int);
39637bfc29Sriz };
40637bfc29Sriz 
41637bfc29Sriz /* Bus methods */
42f5ad5900Sxtraeme void		onewire_lock(void *);
43637bfc29Sriz void		onewire_unlock(void *);
44637bfc29Sriz int		onewire_reset(void *);
45e7a559b6Sad int		onewire_read_bit(void *);
46e7a559b6Sad void		onewire_write_bit(void *, int);
47637bfc29Sriz int		onewire_read_byte(void *);
48637bfc29Sriz void		onewire_write_byte(void *, int);
49637bfc29Sriz int		onewire_triplet(void *, int);
50637bfc29Sriz void		onewire_read_block(void *, void *, int);
51637bfc29Sriz void		onewire_write_block(void *, const void *, int);
52*6a40aed5Sriastradh void		onewire_matchrom(void *, uint64_t);
53637bfc29Sriz 
54637bfc29Sriz /* Bus attachment */
55637bfc29Sriz struct onewirebus_attach_args {
56637bfc29Sriz 	struct onewire_bus *	oba_bus;
57637bfc29Sriz };
58637bfc29Sriz 
59637bfc29Sriz int	onewirebus_print(void *, const char *);
60637bfc29Sriz 
61637bfc29Sriz /* Device attachment */
62637bfc29Sriz struct onewire_attach_args {
63637bfc29Sriz 	void *			oa_onewire;
64*6a40aed5Sriastradh 	uint64_t		oa_rom;
65637bfc29Sriz };
66637bfc29Sriz 
67637bfc29Sriz /* Family matching */
68637bfc29Sriz struct onewire_matchfam {
69637bfc29Sriz 	int om_type;
70637bfc29Sriz };
71637bfc29Sriz 
72637bfc29Sriz /* Miscellaneous routines */
73637bfc29Sriz int		onewire_crc(const void *, int);
74637bfc29Sriz const char *	onewire_famname(int);
75637bfc29Sriz int		onewire_matchbyfam(struct onewire_attach_args *,
76637bfc29Sriz 		    const struct onewire_matchfam *, int);
77637bfc29Sriz 
78637bfc29Sriz /* Bus bit-banging */
79637bfc29Sriz struct onewire_bbops {
80637bfc29Sriz 	void	(*bb_rx)(void *);
81637bfc29Sriz 	void	(*bb_tx)(void *);
82637bfc29Sriz 	int	(*bb_get)(void *);
83637bfc29Sriz 	void	(*bb_set)(void *, int);
84637bfc29Sriz };
85637bfc29Sriz 
86637bfc29Sriz int		onewire_bb_reset(const struct onewire_bbops *, void *);
87e7a559b6Sad int		onewire_bb_read_bit(const struct onewire_bbops *, void *);
88e7a559b6Sad void		onewire_bb_write_bit(const struct onewire_bbops *, void *, int);
89637bfc29Sriz 
90637bfc29Sriz #endif	/* !_DEV_ONEWIRE_ONEWIREVAR_H_ */
91