Annotation of sys/dev/onewire/owid.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: owid.c,v 1.5 2007/06/01 21:30:31 cnst Exp $ */
2:
3: /*
4: * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: /*
20: * 1-Wire ID family type device driver.
21: */
22:
23: #include <sys/param.h>
24: #include <sys/systm.h>
25: #include <sys/device.h>
26: #include <sys/kernel.h>
27: #include <sys/proc.h>
28: #include <sys/sensors.h>
29:
30: #include <dev/onewire/onewiredevs.h>
31: #include <dev/onewire/onewirereg.h>
32: #include <dev/onewire/onewirevar.h>
33:
34: struct owid_softc {
35: struct device sc_dev;
36:
37: void * sc_onewire;
38: u_int64_t sc_rom;
39:
40: struct ksensor sc_sensor;
41: struct ksensordev sc_sensordev;
42:
43: int sc_dying;
44: };
45:
46: int owid_match(struct device *, void *, void *);
47: void owid_attach(struct device *, struct device *, void *);
48: int owid_detach(struct device *, int);
49: int owid_activate(struct device *, enum devact);
50:
51: struct cfattach owid_ca = {
52: sizeof(struct owid_softc),
53: owid_match,
54: owid_attach,
55: owid_detach,
56: owid_activate
57: };
58:
59: struct cfdriver owid_cd = {
60: NULL, "owid", DV_DULL
61: };
62:
63: static const struct onewire_matchfam owid_fams[] = {
64: { ONEWIRE_FAMILY_DS1990 }
65: };
66:
67: int
68: owid_match(struct device *parent, void *match, void *aux)
69: {
70: return (onewire_matchbyfam(aux, owid_fams,
71: sizeof(owid_fams) /sizeof(owid_fams[0])));
72: }
73:
74: void
75: owid_attach(struct device *parent, struct device *self, void *aux)
76: {
77: struct owid_softc *sc = (struct owid_softc *)self;
78: struct onewire_attach_args *oa = aux;
79:
80: sc->sc_onewire = oa->oa_onewire;
81: sc->sc_rom = oa->oa_rom;
82:
83: /* Initialize sensor */
84: strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname,
85: sizeof(sc->sc_sensordev.xname));
86: sc->sc_sensor.type = SENSOR_INTEGER;
87: sc->sc_sensor.value = ONEWIRE_ROM_SN(sc->sc_rom);
88: sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
89: sensordev_install(&sc->sc_sensordev);
90:
91: printf("\n");
92: }
93:
94: int
95: owid_detach(struct device *self, int flags)
96: {
97: struct owid_softc *sc = (struct owid_softc *)self;
98:
99: sensordev_deinstall(&sc->sc_sensordev);
100:
101: return (0);
102: }
103:
104: int
105: owid_activate(struct device *self, enum devact act)
106: {
107: struct owid_softc *sc = (struct owid_softc *)self;
108:
109: switch (act) {
110: case DVACT_ACTIVATE:
111: break;
112: case DVACT_DEACTIVATE:
113: sc->sc_dying = 1;
114: break;
115: }
116:
117: return (0);
118: }
CVSweb