1*fbae48b9Sperry /* $NetBSD: ds.h,v 1.8 2006/02/16 20:17:16 perry Exp $ */ 23040e924Sis 33040e924Sis /*- 42c7fa23cSis * Copyright (c) 1997 The NetBSD Foundation, Inc. 5dc068e0dSis * All rights reserved. 6dc068e0dSis * 7dc068e0dSis * This code is derived from software contributed to The NetBSD Foundation 8dc068e0dSis * by Ignatios Souvatzis. 93040e924Sis * 103040e924Sis * Redistribution and use in source and binary forms, with or without 113040e924Sis * modification, are permitted provided that the following conditions 123040e924Sis * are met: 133040e924Sis * 1. Redistributions of source code must retain the above copyright 143040e924Sis * notice, this list of conditions and the following disclaimer. 153040e924Sis * 2. Redistributions in binary form must reproduce the above copyright 163040e924Sis * notice, this list of conditions and the following disclaimer in the 173040e924Sis * documentation and/or other materials provided with the distribution. 18dc068e0dSis * 3. All advertising materials mentioning features or use of this software 19dc068e0dSis * must display the following acknowledgement: 20dc068e0dSis * This product includes software developed by the NetBSD 21dc068e0dSis * Foundation, Inc. and its contributors. 22dc068e0dSis * 4. Neither the name of The NetBSD Foundation nor the names of its 23dc068e0dSis * contributors may be used to endorse or promote products derived 24dc068e0dSis * from this software without specific prior written permission. 253040e924Sis * 26dc068e0dSis * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27dc068e0dSis * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28dc068e0dSis * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29dc068e0dSis * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30dc068e0dSis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31dc068e0dSis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32dc068e0dSis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33dc068e0dSis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34dc068e0dSis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35dc068e0dSis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36dc068e0dSis * POSSIBILITY OF SUCH DAMAGE. 373040e924Sis */ 383040e924Sis 393040e924Sis /* 403040e924Sis * Definitions for access to Dallas Semiconductor chips which attach to 413040e924Sis * the same 1-wire bus as the DS2404 RTC. 423040e924Sis */ 433040e924Sis 443040e924Sis #ifndef DALLAS_SEMI_CHIPS_H 453040e924Sis #define DALLAS_SEMI_CHIPS_H 463040e924Sis 473040e924Sis /* Family codes (low byte of the ROM) */ 483040e924Sis 49a90a7a1aSbjh21 #define DS_FAMILY_2401 0x01 /* DS2401 Silicon Serial Number */ 503040e924Sis #define DS_FAMILY_2404 0x04 /* DS2404 Econoram Time Chip */ 513040e924Sis 523040e924Sis /* 533040e924Sis * ROM access codes. These are only available from the 1-wire bus, and one 543040e924Sis * of them MUST be used before a memory access code is called. If you want 553040e924Sis * to detect which devices are on the bus, you have to issue the ROM search 563040e924Sis * function (see data sheet). 573040e924Sis * If only one device is on the BUS, and you don't want any ROM function, 583040e924Sis * issue the SKIP function. 593040e924Sis * READ ROM works only if only one device is on the bus. 603040e924Sis */ 613040e924Sis 623040e924Sis #define DS_ROM_MATCH 0x55 /* 55 8-bytes-of-ROM-to-select */ 633040e924Sis #define DS_ROM_SEARCH 0xf0 /* see data sheet */ 643040e924Sis #define DS_ROM_SKIP 0xCC /* don't do ROM function */ 653040e924Sis #define DS_ROM_READ 0x33 /* 33 -> 8 bytes of ROM */ 663040e924Sis 673040e924Sis /* 683040e924Sis * Memory access codes. These are available from the 1- or 3-wire bus, and 693040e924Sis * but you must use one of the ROM access codes first, if using the 1-wire 703040e924Sis * bus. 713040e924Sis * 723040e924Sis * You can read from any starting address up to the end of the chip, or 733040e924Sis * abort the read with a reset pulse. 743040e924Sis * You first write 2-32 bytes beginning some address to the scratchpad. 753040e924Sis * Starting address and final byte stream length are remembered by the 763040e924Sis * chip. After reading data and address/length back from the scratchpad, 773040e924Sis * and verifying the information, you can issue the copy scratchpad command 783040e924Sis * to copy the written parts of the scratchpad to the corresponding parts 793040e924Sis * of the implied (in the address) memory page. 803040e924Sis */ 813040e924Sis 823040e924Sis #define DS_MEM_WRITE_SCRATCH 0x0f /* 0F low-ads high-ads data ... */ 833040e924Sis #define DS_MEM_READ_SCRATCH 0xaa /* AA -> low-ads high-ads end-ofs 843040e924Sis * data ... */ 853040e924Sis #define DS_MEM_COPY_SCRATCH 0x55 /* 55 low-ads high-ads end-ofs */ 863040e924Sis #define DS_MEM_READ_MEMORY 0xf0 /* F0 low-ads high-ads -> data ...*/ 873040e924Sis 883040e924Sis /* 893040e924Sis * Hardware handle for access functions 903040e924Sis */ 913040e924Sis 923040e924Sis struct ds_handle { 9318db93c7Sperry int (*ds_read_bit)(void *); 9418db93c7Sperry void (*ds_write_bit)(void *, int); 9518db93c7Sperry void (*ds_reset)(void *); 963040e924Sis void *ds_hw_handle; 973040e924Sis }; 983040e924Sis 993040e924Sis /* 1003040e924Sis * Functions for access to Dallas Semiconductor chips which attach to 1013040e924Sis * the same 1-wire bus as the DS2404 RTC. 1023040e924Sis */ 1033040e924Sis 10418db93c7Sperry static u_int8_t ds_read_byte(struct ds_handle *); 10518db93c7Sperry static void ds_write_byte(struct ds_handle *, unsigned int); 1063040e924Sis 107*fbae48b9Sperry static __inline u_int8_t 1083040e924Sis ds_read_byte(dsh) 1093040e924Sis struct ds_handle *dsh; 1103040e924Sis { 1113040e924Sis u_int8_t buf; 1123040e924Sis int i; 1133040e924Sis 1143040e924Sis for (i=buf=0; i<8; ++i) 1153040e924Sis buf |= (dsh->ds_read_bit)(dsh->ds_hw_handle) << i; 1163040e924Sis 1173040e924Sis return buf; 1183040e924Sis } 1193040e924Sis 120*fbae48b9Sperry static __inline void 1213040e924Sis ds_write_byte(dsh, b) 1223040e924Sis struct ds_handle *dsh; 1233040e924Sis unsigned int b; 1243040e924Sis { 1253040e924Sis int i; 1263040e924Sis 1273040e924Sis for (i=0; i<8; ++i) { 1283040e924Sis (dsh->ds_write_bit)(dsh->ds_hw_handle, b & 1); 1293040e924Sis b >>= 1; 1303040e924Sis } 1313040e924Sis } 1323040e924Sis 1333040e924Sis #endif /* DALLAS_SEMI_CHIPS_H */ 134