No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / onewire / onewire_bitbang.c
blob0f270cedc9f36b010dac317fb7885b9a171f3daa
1 /* $NetBSD$ */
2 /* $OpenBSD: onewire_bitbang.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */
4 /*
5 * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
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.
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.
20 #include <sys/cdefs.h>
21 __KERNEL_RCSID(0, "$NetBSD$");
24 * 1-Wire bus bit-banging routines.
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/device.h>
31 #include <dev/onewire/onewirevar.h>
33 int
34 onewire_bb_reset(const struct onewire_bbops *ops, void *arg)
36 int s, rv = 0, i;
38 s = splhigh();
39 ops->bb_tx(arg);
40 ops->bb_set(arg, 0);
41 DELAY(480);
42 ops->bb_set(arg, 1);
43 ops->bb_rx(arg);
44 DELAY(30);
45 for (i = 0; i < 6; i++) {
46 if ((rv = ops->bb_get(arg)) == 0)
47 break;
48 DELAY(20);
50 DELAY(450);
51 splx(s);
53 return (rv);
56 int
57 onewire_bb_bit(const struct onewire_bbops *ops, void *arg, int value)
59 int s, rv = 0, i;
61 s = splhigh();
62 ops->bb_tx(arg);
63 ops->bb_set(arg, 0);
64 DELAY(2);
65 if (value) {
66 ops->bb_set(arg, 1);
67 ops->bb_rx(arg);
68 for (i = 0; i < 15; i++) {
69 if ((rv = ops->bb_get(arg)) == 0)
70 break;
71 DELAY(2);
73 ops->bb_tx(arg);
75 DELAY(60);
76 ops->bb_set(arg, 1);
77 DELAY(5);
78 splx(s);
80 return (rv);