FreeBSD kernel IICBUS device code
iicbb.c File Reference
#include <sys/cdefs.h>
#include "opt_platform.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/sysctl.h>
#include <sys/uio.h>
#include <dev/iicbus/iiconf.h>
#include <dev/iicbus/iicbus.h>
#include <dev/smbus/smbconf.h>
#include "iicbus_if.h"
#include "iicbb_if.h"
Include dependency graph for iicbb.c:

Go to the source code of this file.

Data Structures

struct  iicbb_softc
 

Macros

#define DEFAULT_SCL_LOW_TIMEOUT   (25 * 1000)
 
#define IICBB_DEBUG
 
#define I2C_DEBUG(x)
 
#define I2C_GETSDA(dev)   (IICBB_GETSDA(device_get_parent(dev)))
 
#define I2C_SETSDA(dev, x)   (IICBB_SETSDA(device_get_parent(dev), x))
 
#define I2C_GETSCL(dev)   (IICBB_GETSCL(device_get_parent(dev)))
 
#define I2C_SETSCL(dev, x)   (IICBB_SETSCL(device_get_parent(dev), x))
 

Functions

 __FBSDID ("$FreeBSD$")
 
static int iicbb_attach (device_t)
 
static void iicbb_child_detached (device_t, device_t)
 
static int iicbb_detach (device_t)
 
static int iicbb_print_child (device_t, device_t)
 
static int iicbb_probe (device_t)
 
static int iicbb_callback (device_t, int, caddr_t)
 
static int iicbb_start (device_t, u_char, int)
 
static int iicbb_repstart (device_t, u_char, int)
 
static int iicbb_stop (device_t)
 
static int iicbb_write (device_t, const char *, int, int *, int)
 
static int iicbb_read (device_t, char *, int, int *, int, int)
 
static int iicbb_reset (device_t, u_char, u_char, u_char *)
 
static int iicbb_transfer (device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 
static void iicbb_set_speed (struct iicbb_softc *sc, u_char)
 
 SYSCTL_DECL (_hw_i2c)
 
 SYSCTL_INT (_hw_i2c, OID_AUTO, iicbb_debug, CTLFLAG_RWTUN, &i2c_debug, 0, "Enable i2c bit-banging driver debug")
 
static int iicbb_waitforscl (device_t dev)
 
static int iicbb_clockin (device_t dev, int sda)
 
static void iicbb_clockout (device_t dev)
 
static int iicbb_sendbit (device_t dev, int bit)
 
static int iicbb_getack (device_t dev)
 
static int iicbb_sendbyte (device_t dev, uint8_t data)
 
static int iicbb_readbyte (device_t dev, bool last, uint8_t *data)
 
static int iicbb_start_impl (device_t dev, u_char slave, bool repstart)
 
 DRIVER_MODULE (iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0)
 
 MODULE_DEPEND (iicbb, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
 
 MODULE_VERSION (iicbb, IICBB_MODVER)
 

Variables

static device_method_t iicbb_methods []
 
driver_t iicbb_driver
 
devclass_t iicbb_devclass
 
static int i2c_debug = 0
 

Macro Definition Documentation

◆ DEFAULT_SCL_LOW_TIMEOUT

#define DEFAULT_SCL_LOW_TIMEOUT   (25 * 1000)

Definition at line 73 of file iicbb.c.

◆ I2C_DEBUG

#define I2C_DEBUG (   x)
Value:
do { \
if (i2c_debug) (x); \
} while (0)
static int i2c_debug
Definition: iicbb.c:229

Definition at line 235 of file iicbb.c.

◆ I2C_GETSCL

#define I2C_GETSCL (   dev)    (IICBB_GETSCL(device_get_parent(dev)))

Definition at line 244 of file iicbb.c.

◆ I2C_GETSDA

#define I2C_GETSDA (   dev)    (IICBB_GETSDA(device_get_parent(dev)))

Definition at line 242 of file iicbb.c.

◆ I2C_SETSCL

#define I2C_SETSCL (   dev,
 
)    (IICBB_SETSCL(device_get_parent(dev), x))

Definition at line 245 of file iicbb.c.

◆ I2C_SETSDA

#define I2C_SETSDA (   dev,
 
)    (IICBB_SETSDA(device_get_parent(dev), x))

Definition at line 243 of file iicbb.c.

◆ IICBB_DEBUG

#define IICBB_DEBUG

Definition at line 227 of file iicbb.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DRIVER_MODULE()

DRIVER_MODULE ( iicbus  ,
iicbb  ,
iicbus_driver  ,
iicbus_devclass  ,
,
 
)

◆ iicbb_attach()

static int iicbb_attach ( device_t  dev)
static

◆ iicbb_callback()

static int iicbb_callback ( device_t  dev,
int  index,
caddr_t  data 
)
static

Definition at line 424 of file iicbb.c.

References data, dev, and index.

◆ iicbb_child_detached()

static void iicbb_child_detached ( device_t  dev,
device_t  child 
)
static

Definition at line 195 of file iicbb.c.

References dev, and iicbb_softc::iicbus.

◆ iicbb_clockin()

static int iicbb_clockin ( device_t  dev,
int  sda 
)
static

Definition at line 277 of file iicbb.c.

References dev, I2C_SETSCL, I2C_SETSDA, and iicbb_waitforscl().

Referenced by iicbb_getack(), iicbb_sendbit(), iicbb_start_impl(), and iicbb_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_clockout()

static void iicbb_clockout ( device_t  dev)
static

Definition at line 301 of file iicbb.c.

References dev, I2C_SETSCL, and iicbb_softc::udelay.

Referenced by iicbb_getack(), iicbb_readbyte(), iicbb_sendbit(), and iicbb_start_impl().

Here is the caller graph for this function:

◆ iicbb_detach()

static int iicbb_detach ( device_t  dev)
static

Definition at line 175 of file iicbb.c.

References dev.

◆ iicbb_getack()

static int iicbb_getack ( device_t  dev)
static

Definition at line 343 of file iicbb.c.

References dev, I2C_DEBUG, I2C_GETSDA, IIC_ENOACK, iicbb_clockin(), iicbb_clockout(), and iicbb_softc::udelay.

Referenced by iicbb_start_impl(), and iicbb_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_print_child()

static int iicbb_print_child ( device_t  bus,
device_t  dev 
)
static

Definition at line 204 of file iicbb.c.

References dev, IIC_ENOADDR, IIC_FASTEST, and oldaddr.

◆ iicbb_probe()

static int iicbb_probe ( device_t  dev)
static

Definition at line 138 of file iicbb.c.

References dev.

◆ iicbb_read()

static int iicbb_read ( device_t  dev,
char *  buf,
int  len,
int *  read,
int  last,
int  delay 
)
static

Definition at line 549 of file iicbb.c.

References buf, bytes, dev, iicbb_readbyte(), last, len, and read.

Here is the call graph for this function:

◆ iicbb_readbyte()

static int iicbb_readbyte ( device_t  dev,
bool  last,
uint8_t *  data 
)
static

Definition at line 388 of file iicbb.c.

References data, dev, I2C_DEBUG, I2C_GETSDA, I2C_SETSCL, I2C_SETSDA, iicbb_clockout(), iicbb_sendbit(), iicbb_waitforscl(), last, and iicbb_softc::udelay.

Referenced by iicbb_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_repstart()

static int iicbb_repstart ( device_t  dev,
u_char  slave,
int  timeout 
)
static

Definition at line 498 of file iicbb.c.

References dev, iicbb_start_impl(), and slave.

Here is the call graph for this function:

◆ iicbb_reset()

static int iicbb_reset ( device_t  dev,
u_char  speed,
u_char  addr,
u_char *  oldaddr 
)
static

Definition at line 430 of file iicbb.c.

References addr, dev, iicbb_set_speed(), oldaddr, and speed.

Here is the call graph for this function:

◆ iicbb_sendbit()

static int iicbb_sendbit ( device_t  dev,
int  bit 
)
static

Definition at line 315 of file iicbb.c.

References dev, iicbb_clockin(), iicbb_clockout(), and iicbb_softc::udelay.

Referenced by iicbb_readbyte(), and iicbb_sendbyte().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_sendbyte()

static int iicbb_sendbyte ( device_t  dev,
uint8_t  data 
)
static

Definition at line 372 of file iicbb.c.

References data, dev, I2C_DEBUG, and iicbb_sendbit().

Referenced by iicbb_start_impl(), and iicbb_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_set_speed()

static void iicbb_set_speed ( struct iicbb_softc sc,
u_char  speed 
)
static

Definition at line 584 of file iicbb.c.

References iicbb_softc::iicbus, iicbb_softc::io_latency, speed, and iicbb_softc::udelay.

Referenced by iicbb_reset().

Here is the caller graph for this function:

◆ iicbb_start()

static int iicbb_start ( device_t  dev,
u_char  slave,
int  timeout 
)
static

Definition at line 491 of file iicbb.c.

References dev, iicbb_start_impl(), and slave.

Here is the call graph for this function:

◆ iicbb_start_impl()

static int iicbb_start_impl ( device_t  dev,
u_char  slave,
bool  repstart 
)
static

Definition at line 437 of file iicbb.c.

References dev, I2C_DEBUG, I2C_GETSDA, I2C_SETSDA, IIC_EBUSERR, iicbb_clockin(), iicbb_clockout(), iicbb_getack(), iicbb_sendbyte(), iicbb_stop(), iicbb_waitforscl(), slave, and iicbb_softc::udelay.

Referenced by iicbb_repstart(), and iicbb_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_stop()

static int iicbb_stop ( device_t  dev)
static

Definition at line 504 of file iicbb.c.

References dev, I2C_DEBUG, I2C_SETSDA, iicbb_clockin(), and iicbb_softc::udelay.

Referenced by iicbb_start_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iicbb_transfer()

static int iicbb_transfer ( device_t  dev,
struct iic_msg msgs,
uint32_t  nmsgs 
)
static

Definition at line 569 of file iicbb.c.

References dev, iicbus_transfer_gen(), msgs, and nmsgs.

Here is the call graph for this function:

◆ iicbb_waitforscl()

static int iicbb_waitforscl ( device_t  dev)
static

Definition at line 248 of file iicbb.c.

References dev, I2C_DEBUG, I2C_GETSCL, IIC_ETIMEOUT, iicbb_softc::scl_low_timeout, and timeout.

Referenced by iicbb_clockin(), iicbb_readbyte(), and iicbb_start_impl().

Here is the caller graph for this function:

◆ iicbb_write()

static int iicbb_write ( device_t  dev,
const char *  buf,
int  len,
int *  sent,
int  timeout 
)
static

Definition at line 526 of file iicbb.c.

References buf, bytes, dev, iicbb_getack(), iicbb_sendbyte(), and len.

Here is the call graph for this function:

◆ MODULE_DEPEND()

MODULE_DEPEND ( iicbb  ,
iicbus  ,
IICBUS_MINVER  ,
IICBUS_PREFVER  ,
IICBUS_MAXVER   
)

◆ MODULE_VERSION()

MODULE_VERSION ( iicbb  ,
IICBB_MODVER   
)

◆ SYSCTL_DECL()

SYSCTL_DECL ( _hw_i2c  )

◆ SYSCTL_INT()

SYSCTL_INT ( _hw_i2c  ,
OID_AUTO  ,
iicbb_debug  ,
CTLFLAG_RWTUN  ,
i2c_debug,
,
"Enable i2c bit-banging driver debug"   
)

Variable Documentation

◆ i2c_debug

int i2c_debug = 0
static

Definition at line 229 of file iicbb.c.

◆ iicbb_devclass

devclass_t iicbb_devclass

Definition at line 135 of file iicbb.c.

◆ iicbb_driver

driver_t iicbb_driver
Initial value:
= {
"iicbb",
sizeof(struct iicbb_softc),
}
static device_method_t iicbb_methods[]
Definition: iicbb.c:101

Definition at line 129 of file iicbb.c.

◆ iicbb_methods

device_method_t iicbb_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, iicbb_probe),
DEVMETHOD(device_attach, iicbb_attach),
DEVMETHOD(device_detach, iicbb_detach),
DEVMETHOD(bus_child_detached, iicbb_child_detached),
DEVMETHOD(bus_print_child, iicbb_print_child),
DEVMETHOD(iicbus_callback, iicbb_callback),
DEVMETHOD(iicbus_stop, iicbb_stop),
DEVMETHOD(iicbus_read, iicbb_read),
{ 0, 0 }
}
static int iicbb_stop(device_t)
Definition: iicbb.c:504
static int iicbb_start(device_t, u_char, int)
Definition: iicbb.c:491
static int iicbb_read(device_t, char *, int, int *, int, int)
Definition: iicbb.c:549
static int iicbb_print_child(device_t, device_t)
Definition: iicbb.c:204
static int iicbb_write(device_t, const char *, int, int *, int)
Definition: iicbb.c:526
static int iicbb_callback(device_t, int, caddr_t)
Definition: iicbb.c:424
static int iicbb_repstart(device_t, u_char, int)
Definition: iicbb.c:498
static int iicbb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
Definition: iicbb.c:569
static int iicbb_probe(device_t)
Definition: iicbb.c:138
static int iicbb_attach(device_t)
Definition: iicbb.c:146
static int iicbb_reset(device_t, u_char, u_char, u_char *)
Definition: iicbb.c:430
static int iicbb_detach(device_t)
Definition: iicbb.c:175
static void iicbb_child_detached(device_t, device_t)
Definition: iicbb.c:195
int iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
Definition: iiconf.c:442
int iicbus_read(device_t bus, char *buf, int len, int *read, int last, int delay)
Definition: iiconf.c:339
int iicbus_write(device_t bus, const char *buf, int len, int *sent, int timeout)
Definition: iiconf.c:321
int iicbus_stop(device_t bus)
Definition: iiconf.c:298
int iicbus_repeated_start(device_t bus, u_char slave, int timeout)
Definition: iiconf.c:276
int iicbus_start(device_t bus, u_char slave, int timeout)
Definition: iiconf.c:254
#define iicbus_reset(bus, speed, addr, oldaddr)
Definition: iiconf.h:135

Definition at line 101 of file iicbb.c.