When responding to an interrupt in the am335x_pmic driver, use a taskqueue

thread to do the work that involves i2c IO, which sleeps while the IO is
in progress.
This commit is contained in:
Ian Lepore 2019-08-10 17:48:11 +00:00
parent 0ad8b8edc4
commit 7596e192fb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350841

View File

@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/reboot.h>
#include <sys/resource.h>
#include <sys/rman.h>
#include <sys/taskqueue.h>
#include <dev/iicbus/iicbus.h>
#include <dev/iicbus/iiconf.h>
@ -62,6 +63,7 @@ struct am335x_pmic_softc {
struct intr_config_hook enum_hook;
struct resource *sc_irq_res;
void *sc_intrhand;
struct task intr_task;
};
static const char *tps65217_voreg_c[4] = {"4.10V", "4.15V", "4.20V", "4.25V"};
@ -86,7 +88,7 @@ am335x_pmic_write(device_t dev, uint8_t address, uint8_t *data, uint8_t size)
}
static void
am335x_pmic_intr(void *arg)
am335x_pmic_intrtask(void *arg, int pending)
{
struct am335x_pmic_softc *sc = (struct am335x_pmic_softc *)arg;
struct tps65217_status_reg status_reg;
@ -94,20 +96,16 @@ am335x_pmic_intr(void *arg)
int rv;
char notify_buf[16];
THREAD_SLEEPING_OK();
rv = am335x_pmic_read(sc->sc_dev, TPS65217_INT_REG, (uint8_t *)&int_reg, 1);
if (rv != 0) {
device_printf(sc->sc_dev, "Cannot read interrupt register\n");
THREAD_NO_SLEEPING();
return;
}
rv = am335x_pmic_read(sc->sc_dev, TPS65217_STATUS_REG, (uint8_t *)&status_reg, 1);
if (rv != 0) {
device_printf(sc->sc_dev, "Cannot read status register\n");
THREAD_NO_SLEEPING();
return;
}
THREAD_NO_SLEEPING();
if (int_reg.pbi && status_reg.pb)
shutdown_nice(RB_POWEROFF);
@ -118,6 +116,18 @@ am335x_pmic_intr(void *arg)
}
}
static void
am335x_pmic_intr(void *arg)
{
struct am335x_pmic_softc *sc = arg;
/*
* Handling the interrupt requires doing i2c IO, which sleeps while the
* IO is in progress, so do the processing on a taskqueue thread.
*/
taskqueue_enqueue(taskqueue_thread, &sc->intr_task);
}
static int
am335x_pmic_probe(device_t dev)
{
@ -280,6 +290,8 @@ am335x_pmic_attach(device_t dev)
sc = device_get_softc(dev);
TASK_INIT(&sc->intr_task, 0, am335x_pmic_intrtask, sc);
rid = 0;
sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);