xref: /freebsd/sys/dev/ow/ow.h (revision 580744621f33383027108364dcadad718df46ffe)
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  * $FreeBSD$
26  */
27 
28 #ifndef DEV_OW_OW_H
29 #define DEV_OW_OW_H 1
30 
31 enum ow_device_ivars {
32 	OW_IVAR_FAMILY,
33 	OW_IVAR_ROMID
34 };
35 
36 #define OW_ACCESSOR(var, ivar, type)					\
37 	__BUS_ACCESSOR(ow, var, OW, ivar, type);
38 
39 OW_ACCESSOR(family,	FAMILY,	uint8_t)
40 OW_ACCESSOR(romid,	ROMID, uint8_t *)
41 
42 #undef OW_ACCSSOR
43 
44 /*
45  * The following likely should be in the own.h file, but needs to be here to
46  * avoid recursive issues when defining the own_if.m interface.
47  */
48 
49 /*
50  * Generalized command structure for a 1wire bus transaction. Not all possible
51  * transactions on the 1wire bus can be represented here (a notable exception
52  * being both the search ROM commands), but most of them can be, allowing for
53  * general transactions from userland. A lower-level interface to the link
54  * layer is also provided.
55  */
56 #define MAX_ROM		10
57 #define MAX_XPT		32
58 #define MAX_READ	32
59 struct ow_cmd
60 {
61 	uint32_t	flags;		/* Various flags */
62 #define OW_FLAG_OVERDRIVE	1	/* Send xpt stuff overdrive speed */
63 #define OW_FLAG_READ_BIT	2	/* Read a single bit after xpt_cmd */
64 	uint8_t		rom_len;	/* Number of ROM bytes to send */
65 	uint8_t		rom_cmd[MAX_ROM]; /* Rom command to send */
66 	uint8_t		rom_read_len;	/* Number of bytes to read */
67 	uint8_t		rom_read[MAX_ROM]; /* Extra bytes read */
68 	uint8_t		xpt_len;	/* Total transport bytes to send */
69 	uint8_t		xpt_cmd[MAX_XPT]; /* Device specific command to send, if flagged */
70 	uint8_t		xpt_read_len;	/* Number of bytes to read after */
71 	uint8_t		xpt_read[MAX_READ]; /* Buffer for read bytes */
72 };
73 
74 typedef uint64_t romid_t;
75 
76 #endif /* DEV_OW_OW_H */
77