1998-09-03 20:52:54 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2002-03-23 15:49:15 +00:00
|
|
|
* Copyright (c) 1998, 2001 Nicolas Souchu
|
1998-09-03 20:52:54 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2003-08-24 18:03:45 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1998-09-03 20:52:54 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
#include <sys/lock.h>
|
2016-10-12 06:58:01 +00:00
|
|
|
#include <sys/malloc.h>
|
1998-09-03 20:52:54 +00:00
|
|
|
#include <sys/module.h>
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
#include <sys/mutex.h>
|
2015-04-25 16:15:01 +00:00
|
|
|
#include <sys/bus.h>
|
1998-09-03 20:52:54 +00:00
|
|
|
|
|
|
|
#include <dev/smbus/smbconf.h>
|
|
|
|
#include <dev/smbus/smbus.h>
|
|
|
|
|
2015-04-25 16:15:01 +00:00
|
|
|
#include "smbus_if.h"
|
|
|
|
#include "bus_if.h"
|
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
struct smbus_ivar
|
|
|
|
{
|
|
|
|
uint8_t addr;
|
|
|
|
};
|
2015-04-25 16:15:01 +00:00
|
|
|
|
1998-09-03 20:52:54 +00:00
|
|
|
/*
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
* Autoconfiguration and support routines for System Management bus
|
1998-09-03 20:52:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbus_probe(device_t dev)
|
|
|
|
{
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
|
1998-10-31 11:39:54 +00:00
|
|
|
device_set_desc(dev, "System Management Bus");
|
1998-12-28 19:07:51 +00:00
|
|
|
|
1998-09-03 20:52:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-12-20 21:06:57 +00:00
|
|
|
static int
|
|
|
|
smbus_attach(device_t dev)
|
|
|
|
{
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
struct smbus_softc *sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
mtx_init(&sc->lock, device_get_nameunit(dev), "smbus", MTX_DEF);
|
|
|
|
bus_generic_probe(dev);
|
2016-10-12 06:58:01 +00:00
|
|
|
bus_enumerate_hinted_children(dev);
|
2005-12-20 21:06:57 +00:00
|
|
|
bus_generic_attach(dev);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
static int
|
|
|
|
smbus_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct smbus_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = bus_generic_detach(dev);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2016-10-12 06:58:01 +00:00
|
|
|
device_delete_children(dev);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
mtx_destroy(&sc->lock);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
void
|
2009-03-09 13:30:00 +00:00
|
|
|
smbus_generic_intr(device_t dev, u_char devaddr, char low, char high, int err)
|
1998-09-03 20:52:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
static device_t
|
|
|
|
smbus_add_child(device_t dev, u_int order, const char *name, int unit)
|
|
|
|
{
|
|
|
|
struct smbus_ivar *devi;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
child = device_add_child_ordered(dev, order, name, unit);
|
|
|
|
if (child == NULL)
|
|
|
|
return (child);
|
|
|
|
devi = malloc(sizeof(struct smbus_ivar), M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (devi == NULL) {
|
|
|
|
device_delete_child(dev, child);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
device_set_ivars(child, devi);
|
|
|
|
return (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
smbus_hinted_child(device_t bus, const char *dname, int dunit)
|
|
|
|
{
|
|
|
|
struct smbus_ivar *devi;
|
|
|
|
device_t child;
|
|
|
|
int addr;
|
|
|
|
|
|
|
|
addr = 0;
|
|
|
|
resource_int_value(dname, dunit, "addr", &addr);
|
|
|
|
if (addr > UINT8_MAX) {
|
|
|
|
device_printf(bus, "ignored incorrect slave address hint 0x%x"
|
|
|
|
" for %s%d\n", addr, dname, dunit);
|
|
|
|
return;
|
2015-04-25 16:15:01 +00:00
|
|
|
}
|
2016-10-12 06:58:01 +00:00
|
|
|
child = BUS_ADD_CHILD(bus, SMBUS_ORDER_HINTED, dname, dunit);
|
|
|
|
if (child == NULL)
|
|
|
|
return;
|
|
|
|
devi = device_get_ivars(child);
|
|
|
|
devi->addr = addr;
|
2015-04-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
|
2015-04-25 16:15:01 +00:00
|
|
|
static int
|
|
|
|
smbus_child_location_str(device_t parent, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
2016-10-12 06:58:01 +00:00
|
|
|
struct smbus_ivar *devi;
|
2015-04-25 16:15:01 +00:00
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
devi = device_get_ivars(child);
|
|
|
|
if (devi->addr != 0)
|
|
|
|
snprintf(buf, buflen, "addr=0x%x", devi->addr);
|
2015-04-25 16:15:01 +00:00
|
|
|
else if (buflen)
|
|
|
|
buf[0] = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbus_print_child(device_t parent, device_t child)
|
|
|
|
{
|
2016-10-12 06:58:01 +00:00
|
|
|
struct smbus_ivar *devi;
|
2015-04-25 16:15:01 +00:00
|
|
|
int retval;
|
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
devi = device_get_ivars(child);
|
2015-04-25 16:15:01 +00:00
|
|
|
retval = bus_print_child_header(parent, child);
|
2016-10-12 06:58:01 +00:00
|
|
|
if (devi->addr != 0)
|
|
|
|
retval += printf(" at addr 0x%x", devi->addr);
|
2015-04-25 16:15:01 +00:00
|
|
|
retval += bus_print_child_footer(parent, child);
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-10-12 06:58:01 +00:00
|
|
|
smbus_read_ivar(device_t parent, device_t child, int which, uintptr_t *result)
|
2015-04-25 16:15:01 +00:00
|
|
|
{
|
2016-10-12 06:58:01 +00:00
|
|
|
struct smbus_ivar *devi;
|
2015-04-25 16:15:01 +00:00
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
devi = device_get_ivars(child);
|
2015-04-25 16:15:01 +00:00
|
|
|
switch (which) {
|
|
|
|
case SMBUS_IVAR_ADDR:
|
2016-10-12 06:58:01 +00:00
|
|
|
if (devi->addr != 0)
|
|
|
|
*result = devi->addr;
|
|
|
|
else
|
|
|
|
*result = -1;
|
2015-04-25 16:15:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-12 06:58:01 +00:00
|
|
|
static int
|
|
|
|
smbus_write_ivar(device_t parent, device_t child, int which, uintptr_t value)
|
|
|
|
{
|
|
|
|
struct smbus_ivar *devi;
|
|
|
|
|
|
|
|
devi = device_get_ivars(child);
|
|
|
|
switch (which) {
|
|
|
|
case SMBUS_IVAR_ADDR:
|
|
|
|
/* Allow to set but no change the slave address. */
|
|
|
|
if (devi->addr != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
devi->addr = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
smbus_probe_nomatch(device_t bus, device_t child)
|
|
|
|
{
|
|
|
|
struct smbus_ivar *devi = device_get_ivars(child);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore (self-identified) devices without a slave address set.
|
|
|
|
* For example, smb(4).
|
|
|
|
*/
|
|
|
|
if (devi->addr != 0)
|
|
|
|
device_printf(bus, "<unknown device> at addr %#x\n",
|
|
|
|
devi->addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device methods
|
|
|
|
*/
|
|
|
|
static device_method_t smbus_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_probe, smbus_probe),
|
|
|
|
DEVMETHOD(device_attach, smbus_attach),
|
|
|
|
DEVMETHOD(device_detach, smbus_detach),
|
|
|
|
|
|
|
|
/* bus interface */
|
|
|
|
DEVMETHOD(bus_add_child, smbus_add_child),
|
|
|
|
DEVMETHOD(bus_hinted_child, smbus_hinted_child),
|
|
|
|
DEVMETHOD(bus_probe_nomatch, smbus_probe_nomatch),
|
|
|
|
DEVMETHOD(bus_child_location_str, smbus_child_location_str),
|
|
|
|
DEVMETHOD(bus_print_child, smbus_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, smbus_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, smbus_write_ivar),
|
|
|
|
|
|
|
|
DEVMETHOD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
driver_t smbus_driver = {
|
|
|
|
"smbus",
|
|
|
|
smbus_methods,
|
|
|
|
sizeof(struct smbus_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
devclass_t smbus_devclass;
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
MODULE_VERSION(smbus, SMBUS_MODVER);
|