Line data Source code
1 : /* $OpenBSD: owid.c,v 1.11 2015/03/14 03:38:48 jsg 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/sensors.h>
27 :
28 : #include <dev/onewire/onewiredevs.h>
29 : #include <dev/onewire/onewirereg.h>
30 : #include <dev/onewire/onewirevar.h>
31 :
32 : struct owid_softc {
33 : struct device sc_dev;
34 :
35 : void * sc_onewire;
36 : u_int64_t sc_rom;
37 :
38 : struct ksensor sc_sensor;
39 : struct ksensordev sc_sensordev;
40 :
41 : int sc_dying;
42 : };
43 :
44 : int owid_match(struct device *, void *, void *);
45 : void owid_attach(struct device *, struct device *, void *);
46 : int owid_detach(struct device *, int);
47 : int owid_activate(struct device *, int);
48 :
49 : struct cfattach owid_ca = {
50 : sizeof(struct owid_softc),
51 : owid_match,
52 : owid_attach,
53 : owid_detach,
54 : owid_activate
55 : };
56 :
57 : struct cfdriver owid_cd = {
58 : NULL, "owid", DV_DULL
59 : };
60 :
61 : static const struct onewire_matchfam owid_fams[] = {
62 : { ONEWIRE_FAMILY_DS1990 }
63 : };
64 :
65 : int
66 0 : owid_match(struct device *parent, void *match, void *aux)
67 : {
68 0 : return (onewire_matchbyfam(aux, owid_fams, nitems(owid_fams)));
69 : }
70 :
71 : void
72 0 : owid_attach(struct device *parent, struct device *self, void *aux)
73 : {
74 0 : struct owid_softc *sc = (struct owid_softc *)self;
75 0 : struct onewire_attach_args *oa = aux;
76 :
77 0 : sc->sc_onewire = oa->oa_onewire;
78 0 : sc->sc_rom = oa->oa_rom;
79 :
80 : /* Initialize sensor */
81 0 : strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname,
82 : sizeof(sc->sc_sensordev.xname));
83 0 : sc->sc_sensor.type = SENSOR_INTEGER;
84 0 : sc->sc_sensor.value = ONEWIRE_ROM_SN(sc->sc_rom);
85 0 : snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc), "sn %012llx",
86 0 : ONEWIRE_ROM_SN(oa->oa_rom));
87 0 : sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
88 0 : sensordev_install(&sc->sc_sensordev);
89 :
90 0 : printf("\n");
91 0 : }
92 :
93 : int
94 0 : owid_detach(struct device *self, int flags)
95 : {
96 0 : struct owid_softc *sc = (struct owid_softc *)self;
97 :
98 0 : sensordev_deinstall(&sc->sc_sensordev);
99 :
100 0 : return (0);
101 : }
102 :
103 : int
104 0 : owid_activate(struct device *self, int act)
105 : {
106 0 : struct owid_softc *sc = (struct owid_softc *)self;
107 :
108 0 : switch (act) {
109 : case DVACT_DEACTIVATE:
110 0 : sc->sc_dying = 1;
111 0 : break;
112 : }
113 :
114 0 : return (0);
115 : }
|