1/* $NetBSD: onewirereg.h,v 1.2 2006/04/08 23:41:46 riz Exp $ */
2/*	$OpenBSD: onewirereg.h,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
3
4/*
5 * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef _DEV_ONEWIRE_ONEWIREREG_H_
21#define _DEV_ONEWIRE_ONEWIREREG_H_
22
23/*
24 * 1-Wire bus protocol definitions.
25 */
26
27/*
28 * 64-bit ROM section.
29 */
30
31/* Family code */
32#define ONEWIRE_ROM_FAMILY(x)		((x) & 0xff)
33#define ONEWIRE_ROM_FAMILY_TYPE(x)	((x) & 0x7f)
34#define ONEWIRE_ROM_FAMILY_CUSTOM(x)	(((x) >> 7) & 0x1)
35
36/* Serial number */
37#define ONEWIRE_ROM_SN(x)		(((x) >> 8) & 0xffffffffffffULL)
38
39/* CRC */
40#define ONEWIRE_ROM_CRC(x)		(((x) >> 56) & 0xff)
41
42/*
43 * Command set.
44 */
45
46/* ROM commands */
47#define ONEWIRE_CMD_READ_ROM		0x33
48#define ONEWIRE_CMD_SKIP_ROM		0xcc
49#define ONEWIRE_CMD_MATCH_ROM		0x55
50#define ONEWIRE_CMD_SEARCH_ROM		0xf0
51#define ONEWIRE_CMD_OVERDRIVE_SKIP_ROM	0x3c
52#define ONEWIRE_CMD_OVERDRIVE_MATCH_ROM	0x69
53
54/* Scratchpad commands */
55#define ONEWIRE_CMD_READ_SCRATCHPAD	0xaa
56#define ONEWIRE_CMD_WRITE_SCRATCHPAD	0x0f
57#define ONEWIRE_CMD_COPY_SCRATCHPAD	0x55
58
59/* Memory commands */
60#define ONEWIRE_CMD_READ_MEMORY		0xf0
61#define ONEWIRE_CMD_WRITE_MEMORY	0x0f
62#define ONEWIRE_CMD_EXT_READ_MEMORY	0xa5
63
64/* Password commands */
65#define ONEWIRE_CMD_READ_SUBKEY		0x66
66#define ONEWIRE_CMD_WRITE_SUBKEY	0x99
67#define ONEWIRE_CMD_WRITE_PASSWORD	0x5a
68
69/* Status commands */
70#define ONEWIRE_CMD_READ_STATUS		0xaa
71#define ONEWIRE_CMD_WRITE_STATUS	0x55
72
73#endif	/* !_DEV_ONEWIRE_ONEWIREREG_H_ */
74