xref: /freebsd/sys/dev/smbus/smbus.c (revision 7048a99c)
1d70424edSNicolas Souchu /*-
2c17d4340SNicolas Souchu  * Copyright (c) 1998, 2001 Nicolas Souchu
3d70424edSNicolas Souchu  * All rights reserved.
4d70424edSNicolas Souchu  *
5d70424edSNicolas Souchu  * Redistribution and use in source and binary forms, with or without
6d70424edSNicolas Souchu  * modification, are permitted provided that the following conditions
7d70424edSNicolas Souchu  * are met:
8d70424edSNicolas Souchu  * 1. Redistributions of source code must retain the above copyright
9d70424edSNicolas Souchu  *    notice, this list of conditions and the following disclaimer.
10d70424edSNicolas Souchu  * 2. Redistributions in binary form must reproduce the above copyright
11d70424edSNicolas Souchu  *    notice, this list of conditions and the following disclaimer in the
12d70424edSNicolas Souchu  *    documentation and/or other materials provided with the distribution.
13d70424edSNicolas Souchu  *
14d70424edSNicolas Souchu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15d70424edSNicolas Souchu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16d70424edSNicolas Souchu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17d70424edSNicolas Souchu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18d70424edSNicolas Souchu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19d70424edSNicolas Souchu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20d70424edSNicolas Souchu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21d70424edSNicolas Souchu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22d70424edSNicolas Souchu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23d70424edSNicolas Souchu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24d70424edSNicolas Souchu  * SUCH DAMAGE.
25d70424edSNicolas Souchu  *
26d70424edSNicolas Souchu  *
27d70424edSNicolas Souchu  */
28945ff31aSDavid E. O'Brien 
29945ff31aSDavid E. O'Brien #include <sys/cdefs.h>
30945ff31aSDavid E. O'Brien __FBSDID("$FreeBSD$");
31d70424edSNicolas Souchu #include <sys/param.h>
32d70424edSNicolas Souchu #include <sys/systm.h>
337048a99cSJohn Baldwin #include <sys/lock.h>
34d70424edSNicolas Souchu #include <sys/module.h>
357048a99cSJohn Baldwin #include <sys/mutex.h>
36d70424edSNicolas Souchu #include <sys/bus.h>
37d70424edSNicolas Souchu 
38d70424edSNicolas Souchu #include <dev/smbus/smbconf.h>
39d70424edSNicolas Souchu #include <dev/smbus/smbus.h>
40d70424edSNicolas Souchu 
41d70424edSNicolas Souchu /*
427048a99cSJohn Baldwin  * Autoconfiguration and support routines for System Management bus
43d70424edSNicolas Souchu  */
44d70424edSNicolas Souchu 
45d70424edSNicolas Souchu /*
46d70424edSNicolas Souchu  * Device methods
47d70424edSNicolas Souchu  */
48d70424edSNicolas Souchu static int smbus_probe(device_t);
499a77af90SRuslan Ermilov static int smbus_attach(device_t);
507048a99cSJohn Baldwin static int smbus_detach(device_t);
51d70424edSNicolas Souchu 
52d70424edSNicolas Souchu static device_method_t smbus_methods[] = {
53d70424edSNicolas Souchu         /* device interface */
54d70424edSNicolas Souchu         DEVMETHOD(device_probe,         smbus_probe),
559a77af90SRuslan Ermilov         DEVMETHOD(device_attach,        smbus_attach),
567048a99cSJohn Baldwin         DEVMETHOD(device_detach,        smbus_detach),
57d70424edSNicolas Souchu 
58d70424edSNicolas Souchu         /* bus interface */
5915317dd8SMatthew N. Dodd         DEVMETHOD(bus_print_child,	bus_generic_print_child),
60d70424edSNicolas Souchu 
61d70424edSNicolas Souchu         { 0, 0 }
62d70424edSNicolas Souchu };
63d70424edSNicolas Souchu 
647048a99cSJohn Baldwin driver_t smbus_driver = {
65d70424edSNicolas Souchu         "smbus",
66d70424edSNicolas Souchu         smbus_methods,
67d70424edSNicolas Souchu         sizeof(struct smbus_softc),
68d70424edSNicolas Souchu };
69d70424edSNicolas Souchu 
707048a99cSJohn Baldwin devclass_t smbus_devclass;
717048a99cSJohn Baldwin 
72d70424edSNicolas Souchu /*
73d70424edSNicolas Souchu  * At 'probe' time, we add all the devices which we know about to the
74d70424edSNicolas Souchu  * bus.  The generic attach routine will probe and attach them if they
75d70424edSNicolas Souchu  * are alive.
76d70424edSNicolas Souchu  */
77d70424edSNicolas Souchu static int
78d70424edSNicolas Souchu smbus_probe(device_t dev)
79d70424edSNicolas Souchu {
807048a99cSJohn Baldwin 
813ab1f056SNicolas Souchu 	device_set_desc(dev, "System Management Bus");
82517e2485SNicolas Souchu 
83d70424edSNicolas Souchu 	return (0);
84d70424edSNicolas Souchu }
85d70424edSNicolas Souchu 
869a77af90SRuslan Ermilov static int
879a77af90SRuslan Ermilov smbus_attach(device_t dev)
889a77af90SRuslan Ermilov {
897048a99cSJohn Baldwin 	struct smbus_softc *sc = device_get_softc(dev);
907048a99cSJohn Baldwin 
917048a99cSJohn Baldwin 	mtx_init(&sc->lock, device_get_nameunit(dev), "smbus", MTX_DEF);
927048a99cSJohn Baldwin 	bus_generic_probe(dev);
939a77af90SRuslan Ermilov 	bus_generic_attach(dev);
949a77af90SRuslan Ermilov 
959a77af90SRuslan Ermilov 	return (0);
969a77af90SRuslan Ermilov }
979a77af90SRuslan Ermilov 
987048a99cSJohn Baldwin static int
997048a99cSJohn Baldwin smbus_detach(device_t dev)
1007048a99cSJohn Baldwin {
1017048a99cSJohn Baldwin 	struct smbus_softc *sc = device_get_softc(dev);
1027048a99cSJohn Baldwin 	int error;
1037048a99cSJohn Baldwin 
1047048a99cSJohn Baldwin 	error = bus_generic_detach(dev);
1057048a99cSJohn Baldwin 	if (error)
1067048a99cSJohn Baldwin 		return (error);
1077048a99cSJohn Baldwin 	mtx_destroy(&sc->lock);
1087048a99cSJohn Baldwin 
1097048a99cSJohn Baldwin 	return (0);
1107048a99cSJohn Baldwin }
1117048a99cSJohn Baldwin 
112d70424edSNicolas Souchu void
113d70424edSNicolas Souchu smbus_generic_intr(device_t dev, u_char devaddr, char low, char high)
114d70424edSNicolas Souchu {
115d70424edSNicolas Souchu }
116d70424edSNicolas Souchu 
117c17d4340SNicolas Souchu MODULE_VERSION(smbus, SMBUS_MODVER);
118