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