xref: /freebsd/sys/dev/ow/ow.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * Copyright (c) 2015 M. Warner Losh <imp@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice unmodified, this list of conditions, and the following
9  *    disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef DEV_OW_OW_H
27 #define DEV_OW_OW_H 1
28 
29 enum ow_device_ivars {
30 	OW_IVAR_FAMILY,
31 	OW_IVAR_ROMID
32 };
33 
34 #define OW_ACCESSOR(var, ivar, type)					\
35 	__BUS_ACCESSOR(ow, var, OW, ivar, type);
36 
37 OW_ACCESSOR(family,	FAMILY,	uint8_t)
38 OW_ACCESSOR(romid,	ROMID, uint8_t *)
39 
40 #undef OW_ACCSSOR
41 
42 /*
43  * The following likely should be in the own.h file, but needs to be here to
44  * avoid recursive issues when defining the own_if.m interface.
45  */
46 
47 /*
48  * Generalized command structure for a 1wire bus transaction. Not all possible
49  * transactions on the 1wire bus can be represented here (a notable exception
50  * being both the search ROM commands), but most of them can be, allowing for
51  * general transactions from userland. A lower-level interface to the link
52  * layer is also provided.
53  */
54 #define MAX_ROM		10
55 #define MAX_XPT		32
56 #define MAX_READ	32
57 struct ow_cmd
58 {
59 	uint32_t	flags;		/* Various flags */
60 #define OW_FLAG_OVERDRIVE	1	/* Send xpt stuff overdrive speed */
61 #define OW_FLAG_READ_BIT	2	/* Read a single bit after xpt_cmd */
62 	uint8_t		rom_len;	/* Number of ROM bytes to send */
63 	uint8_t		rom_cmd[MAX_ROM]; /* Rom command to send */
64 	uint8_t		rom_read_len;	/* Number of bytes to read */
65 	uint8_t		rom_read[MAX_ROM]; /* Extra bytes read */
66 	uint8_t		xpt_len;	/* Total transport bytes to send */
67 	uint8_t		xpt_cmd[MAX_XPT]; /* Device specific command to send, if flagged */
68 	uint8_t		xpt_read_len;	/* Number of bytes to read after */
69 	uint8_t		xpt_read[MAX_READ]; /* Buffer for read bytes */
70 };
71 
72 typedef uint64_t romid_t;
73 
74 #endif /* DEV_OW_OW_H */
75