smb.c (83366) | smb.c (93023) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1998 Nicolas Souchu | 2 * Copyright (c) 1998, 2001 Nicolas Souchu |
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/dev/smbus/smb.c 83366 2001-09-12 08:38:13Z julian $ | 26 * $FreeBSD: head/sys/dev/smbus/smb.c 93023 2002-03-23 15:49:15Z nsouch $ |
27 * 28 */ 29#include <sys/param.h> 30#include <sys/kernel.h> 31#include <sys/systm.h> 32#include <sys/module.h> 33#include <sys/bus.h> 34#include <sys/conf.h> --- 6 unchanged lines hidden (view full) --- 41#include <machine/smb.h> 42 43#include "smbus_if.h" 44 45#define BUFSIZE 1024 46 47struct smb_softc { 48 | 27 * 28 */ 29#include <sys/param.h> 30#include <sys/kernel.h> 31#include <sys/systm.h> 32#include <sys/module.h> 33#include <sys/bus.h> 34#include <sys/conf.h> --- 6 unchanged lines hidden (view full) --- 41#include <machine/smb.h> 42 43#include "smbus_if.h" 44 45#define BUFSIZE 1024 46 47struct smb_softc { 48 |
49 int sc_addr; /* address on smbus */ | |
50 int sc_count; /* >0 if device opened */ | 49 int sc_count; /* >0 if device opened */ |
51 52 char *sc_cp; /* output buffer pointer */ 53 54 char sc_buffer[BUFSIZE]; /* output buffer */ 55 char sc_inbuf[BUFSIZE]; /* input buffer */ | 50 dev_t sc_devnode; |
56}; 57 58#define IIC_SOFTC(unit) \ 59 ((struct smb_softc *)devclass_get_softc(smb_devclass, (unit))) 60 61#define IIC_DEVICE(unit) \ 62 (devclass_get_device(smb_devclass, (unit))) 63 64static int smb_probe(device_t); 65static int smb_attach(device_t); | 51}; 52 53#define IIC_SOFTC(unit) \ 54 ((struct smb_softc *)devclass_get_softc(smb_devclass, (unit))) 55 56#define IIC_DEVICE(unit) \ 57 (devclass_get_device(smb_devclass, (unit))) 58 59static int smb_probe(device_t); 60static int smb_attach(device_t); |
61static int smb_detach(device_t); 62static void smb_identify(driver_t *driver, device_t parent); |
|
66 67static devclass_t smb_devclass; 68 69static device_method_t smb_methods[] = { 70 /* device interface */ | 63 64static devclass_t smb_devclass; 65 66static device_method_t smb_methods[] = { 67 /* device interface */ |
68 DEVMETHOD(device_identify, smb_identify), |
|
71 DEVMETHOD(device_probe, smb_probe), 72 DEVMETHOD(device_attach, smb_attach), | 69 DEVMETHOD(device_probe, smb_probe), 70 DEVMETHOD(device_attach, smb_attach), |
71 DEVMETHOD(device_detach, smb_detach), |
|
73 74 /* smbus interface */ 75 DEVMETHOD(smbus_intr, smbus_generic_intr), 76 77 { 0, 0 } 78}; 79 80static driver_t smb_driver = { --- 20 unchanged lines hidden (view full) --- 101 /* strategy */ nostrategy, 102 /* name */ "smb", 103 /* maj */ CDEV_MAJOR, 104 /* dump */ nodump, 105 /* psize */ nopsize, 106 /* flags */ 0, 107}; 108 | 72 73 /* smbus interface */ 74 DEVMETHOD(smbus_intr, smbus_generic_intr), 75 76 { 0, 0 } 77}; 78 79static driver_t smb_driver = { --- 20 unchanged lines hidden (view full) --- 100 /* strategy */ nostrategy, 101 /* name */ "smb", 102 /* maj */ CDEV_MAJOR, 103 /* dump */ nodump, 104 /* psize */ nopsize, 105 /* flags */ 0, 106}; 107 |
109/* 110 * smbprobe() 111 */ | 108static void 109smb_identify(driver_t *driver, device_t parent) 110{ 111 BUS_ADD_CHILD(parent, 0, "smb", 0); 112} 113 |
112static int 113smb_probe(device_t dev) 114{ | 114static int 115smb_probe(device_t dev) 116{ |
115 struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); | 117 device_set_desc(dev, "SMBus generic I/O"); |
116 | 118 |
117 sc->sc_addr = smbus_get_addr(dev); 118 119 /* XXX detect chip with start/stop conditions */ 120 | |
121 return (0); 122} 123 | 119 return (0); 120} 121 |
124/* 125 * smbattach() 126 */ | |
127static int 128smb_attach(device_t dev) 129{ | 122static int 123smb_attach(device_t dev) 124{ |
130 make_dev(&smb_cdevsw, device_get_unit(dev), /* XXX cleanup */ | 125 struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); 126 127 if (!sc) 128 return (ENOMEM); 129 130 bzero(sc, sizeof(struct smb_softc *)); 131 132 sc->sc_devnode = make_dev(&smb_cdevsw, device_get_unit(dev), |
131 UID_ROOT, GID_WHEEL, 132 0600, "smb%d", device_get_unit(dev)); | 133 UID_ROOT, GID_WHEEL, 134 0600, "smb%d", device_get_unit(dev)); |
135 |
|
133 return (0); 134} 135 136static int | 136 return (0); 137} 138 139static int |
140smb_detach(device_t dev) 141{ 142 struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); 143 144 if (sc->sc_devnode) 145 destroy_dev(sc->sc_devnode); 146 147 return (0); 148} 149 150static int |
|
137smbopen (dev_t dev, int flags, int fmt, struct thread *td) 138{ 139 struct smb_softc *sc = IIC_SOFTC(minor(dev)); 140 141 if (!sc) 142 return (EINVAL); 143 144 if (sc->sc_count) --- 117 unchanged lines hidden (view full) --- 262 263 /* release the bus */ 264 smbus_release_bus(parent, smbdev); 265 266 return (error); 267} 268 269DRIVER_MODULE(smb, smbus, smb_driver, smb_devclass, 0, 0); | 151smbopen (dev_t dev, int flags, int fmt, struct thread *td) 152{ 153 struct smb_softc *sc = IIC_SOFTC(minor(dev)); 154 155 if (!sc) 156 return (EINVAL); 157 158 if (sc->sc_count) --- 117 unchanged lines hidden (view full) --- 276 277 /* release the bus */ 278 smbus_release_bus(parent, smbdev); 279 280 return (error); 281} 282 283DRIVER_MODULE(smb, smbus, smb_driver, smb_devclass, 0, 0); |
284MODULE_DEPEND(smb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); 285MODULE_VERSION(smb, 1); |
|