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