mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-18 02:19:39 +00:00
Convert the BSC (i2c) driver to use the new iicbus_get_frequency().
Tested on: Raspberry pi
This commit is contained in:
parent
535508f74a
commit
9e93dfcf25
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=276314
@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include "iicbus_if.h"
|
||||
|
||||
static void bcm_bsc_intr(void *);
|
||||
static int bcm_bsc_detach(device_t);
|
||||
|
||||
static void
|
||||
bcm_bsc_modifyreg(struct bcm_bsc_softc *sc, uint32_t off, uint32_t mask,
|
||||
@ -72,10 +73,8 @@ bcm_bsc_clock_proc(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
struct bcm_bsc_softc *sc;
|
||||
uint32_t clk;
|
||||
int error;
|
||||
|
||||
sc = (struct bcm_bsc_softc *)arg1;
|
||||
|
||||
BCM_BSC_LOCK(sc);
|
||||
clk = BCM_BSC_READ(sc, BCM_BSC_CLOCK);
|
||||
BCM_BSC_UNLOCK(sc);
|
||||
@ -83,20 +82,8 @@ bcm_bsc_clock_proc(SYSCTL_HANDLER_ARGS)
|
||||
if (clk == 0)
|
||||
clk = 32768;
|
||||
clk = BCM_BSC_CORE_CLK / clk;
|
||||
error = sysctl_handle_int(oidp, &clk, sizeof(clk), req);
|
||||
if (error != 0 || req->newptr == NULL)
|
||||
return (error);
|
||||
|
||||
clk = BCM_BSC_CORE_CLK / clk;
|
||||
if (clk % 2)
|
||||
clk--;
|
||||
if (clk > 0xffff)
|
||||
clk = 0xffff;
|
||||
BCM_BSC_LOCK(sc);
|
||||
BCM_BSC_WRITE(sc, BCM_BSC_CLOCK, clk);
|
||||
BCM_BSC_UNLOCK(sc);
|
||||
|
||||
return (0);
|
||||
return (sysctl_handle_int(oidp, &clk, 0, req));
|
||||
}
|
||||
|
||||
static int
|
||||
@ -192,7 +179,7 @@ bcm_bsc_sysctl_init(struct bcm_bsc_softc *sc)
|
||||
ctx = device_get_sysctl_ctx(sc->sc_dev);
|
||||
tree_node = device_get_sysctl_tree(sc->sc_dev);
|
||||
tree = SYSCTL_CHILDREN(tree_node);
|
||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "clock",
|
||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "frequency",
|
||||
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
|
||||
bcm_bsc_clock_proc, "IU", "I2C BUS clock frequency");
|
||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "clock_stretch",
|
||||
@ -307,7 +294,11 @@ bcm_bsc_attach(device_t dev)
|
||||
bcm_bsc_reset(sc);
|
||||
BCM_BSC_UNLOCK(sc);
|
||||
|
||||
device_add_child(dev, "iicbus", -1);
|
||||
sc->sc_iicbus = device_add_child(dev, "iicbus", -1);
|
||||
if (sc->sc_iicbus == NULL) {
|
||||
bcm_bsc_detach(dev);
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
return (bus_generic_attach(dev));
|
||||
}
|
||||
@ -462,29 +453,16 @@ static int
|
||||
bcm_bsc_iicbus_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
|
||||
{
|
||||
struct bcm_bsc_softc *sc;
|
||||
uint32_t freq;
|
||||
|
||||
uint32_t busfreq;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
BCM_BSC_LOCK(sc);
|
||||
bcm_bsc_reset(sc);
|
||||
freq = 0;
|
||||
switch (speed) {
|
||||
case IIC_SLOW:
|
||||
freq = BCM_BSC_SLOW;
|
||||
break;
|
||||
case IIC_FAST:
|
||||
freq = BCM_BSC_FAST;
|
||||
break;
|
||||
case IIC_FASTEST:
|
||||
freq = BCM_BSC_FASTEST;
|
||||
break;
|
||||
case IIC_UNKNOWN:
|
||||
default:
|
||||
/* Reuse last frequency. */
|
||||
break;
|
||||
}
|
||||
if (freq != 0)
|
||||
BCM_BSC_WRITE(sc, BCM_BSC_CLOCK, BCM_BSC_CORE_CLK / freq);
|
||||
if (sc->sc_iicbus == NULL)
|
||||
busfreq = 100000;
|
||||
else
|
||||
busfreq = IICBUS_GET_FREQUENCY(sc->sc_iicbus, speed);
|
||||
BCM_BSC_WRITE(sc, BCM_BSC_CLOCK, BCM_BSC_CORE_CLK / busfreq);
|
||||
BCM_BSC_UNLOCK(sc);
|
||||
|
||||
return (IIC_ENOADDR);
|
||||
|
@ -41,6 +41,7 @@ struct {
|
||||
|
||||
struct bcm_bsc_softc {
|
||||
device_t sc_dev;
|
||||
device_t sc_iicbus;
|
||||
struct mtx sc_mtx;
|
||||
struct resource * sc_mem_res;
|
||||
struct resource * sc_irq_res;
|
||||
@ -56,10 +57,6 @@ struct bcm_bsc_softc {
|
||||
#define BCM_I2C_READ 0x02
|
||||
#define BCM_I2C_ERROR 0x04
|
||||
|
||||
#define BCM_BSC_SLOW 10000 /* 10 kHz. */
|
||||
#define BCM_BSC_FAST 50000 /* 50 kHz. */
|
||||
#define BCM_BSC_FASTEST 100000 /* 100 kHz. */
|
||||
|
||||
#define BCM_BSC_WRITE(_sc, _off, _val) \
|
||||
bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val)
|
||||
#define BCM_BSC_READ(_sc, _off) \
|
||||
|
Loading…
Reference in New Issue
Block a user