No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ic / ds.h
blob43fb79e9cf46920094840c72757b48e8253ea2f8
1 /* $NetBSD: ds.h,v 1.8 2006/02/16 20:17:16 perry Exp $ */
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Definitions for access to Dallas Semiconductor chips which attach to
34 * the same 1-wire bus as the DS2404 RTC.
37 #ifndef DALLAS_SEMI_CHIPS_H
38 #define DALLAS_SEMI_CHIPS_H
40 /* Family codes (low byte of the ROM) */
42 #define DS_FAMILY_2401 0x01 /* DS2401 Silicon Serial Number */
43 #define DS_FAMILY_2404 0x04 /* DS2404 Econoram Time Chip */
46 * ROM access codes. These are only available from the 1-wire bus, and one
47 * of them MUST be used before a memory access code is called. If you want
48 * to detect which devices are on the bus, you have to issue the ROM search
49 * function (see data sheet).
50 * If only one device is on the BUS, and you don't want any ROM function,
51 * issue the SKIP function.
52 * READ ROM works only if only one device is on the bus.
55 #define DS_ROM_MATCH 0x55 /* 55 8-bytes-of-ROM-to-select */
56 #define DS_ROM_SEARCH 0xf0 /* see data sheet */
57 #define DS_ROM_SKIP 0xCC /* don't do ROM function */
58 #define DS_ROM_READ 0x33 /* 33 -> 8 bytes of ROM */
61 * Memory access codes. These are available from the 1- or 3-wire bus, and
62 * but you must use one of the ROM access codes first, if using the 1-wire
63 * bus.
65 * You can read from any starting address up to the end of the chip, or
66 * abort the read with a reset pulse.
67 * You first write 2-32 bytes beginning some address to the scratchpad.
68 * Starting address and final byte stream length are remembered by the
69 * chip. After reading data and address/length back from the scratchpad,
70 * and verifying the information, you can issue the copy scratchpad command
71 * to copy the written parts of the scratchpad to the corresponding parts
72 * of the implied (in the address) memory page.
75 #define DS_MEM_WRITE_SCRATCH 0x0f /* 0F low-ads high-ads data ... */
76 #define DS_MEM_READ_SCRATCH 0xaa /* AA -> low-ads high-ads end-ofs
77 * data ... */
78 #define DS_MEM_COPY_SCRATCH 0x55 /* 55 low-ads high-ads end-ofs */
79 #define DS_MEM_READ_MEMORY 0xf0 /* F0 low-ads high-ads -> data ...*/
82 * Hardware handle for access functions
85 struct ds_handle {
86 int (*ds_read_bit)(void *);
87 void (*ds_write_bit)(void *, int);
88 void (*ds_reset)(void *);
89 void *ds_hw_handle;
93 * Functions for access to Dallas Semiconductor chips which attach to
94 * the same 1-wire bus as the DS2404 RTC.
97 static u_int8_t ds_read_byte(struct ds_handle *);
98 static void ds_write_byte(struct ds_handle *, unsigned int);
100 static __inline u_int8_t
101 ds_read_byte(dsh)
102 struct ds_handle *dsh;
104 u_int8_t buf;
105 int i;
107 for (i=buf=0; i<8; ++i)
108 buf |= (dsh->ds_read_bit)(dsh->ds_hw_handle) << i;
110 return buf;
113 static __inline void
114 ds_write_byte(dsh, b)
115 struct ds_handle *dsh;
116 unsigned int b;
118 int i;
120 for (i=0; i<8; ++i) {
121 (dsh->ds_write_bit)(dsh->ds_hw_handle, b & 1);
122 b >>= 1;
126 #endif /* DALLAS_SEMI_CHIPS_H */