From eaef5f0af874690ec58b14be728d2e3d3df66579 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Fri, 18 Jun 2010 14:06:27 +0000 Subject: Provide for multiple, cascaded PICs on PowerPC systems, and extend the OFW interrupt map interface to also return the device's interrupt parent. MFC after: 8.1-RELEASE --- sys/dev/iicbus/iiconf.c | 34 +++++++++++++++++++++++++++++----- sys/dev/ofw/ofw_bus_subr.c | 9 ++++++--- sys/dev/ofw/ofw_bus_subr.h | 7 +++++-- 3 files changed, 40 insertions(+), 10 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/iicbus/iiconf.c b/sys/dev/iicbus/iiconf.c index 1610b351e7453..e59dc35f18cd1 100644 --- a/sys/dev/iicbus/iiconf.c +++ b/sys/dev/iicbus/iiconf.c @@ -363,7 +363,7 @@ iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs) int iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) { - int i, error, lenread, lenwrote, nkid; + int i, error, lenread, lenwrote, nkid, rpstart, addr; device_t *children, bus; if ((error = device_get_children(dev, &children, &nkid)) != 0) @@ -373,14 +373,38 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) return (EIO); } bus = children[0]; + rpstart = 0; free(children, M_TEMP); for (i = 0, error = 0; i < nmsgs && error == 0; i++) { + addr = msgs[i].slave; if (msgs[i].flags & IIC_M_RD) - error = iicbus_block_read(bus, msgs[i].slave, - msgs[i].buf, msgs[i].len, &lenread); + addr |= LSB; else - error = iicbus_block_write(bus, msgs[i].slave, - msgs[i].buf, msgs[i].len, &lenwrote); + addr &= ~LSB; + + if (!(msgs[i].flags & IIC_M_NOSTART)) { + if (rpstart) + error = iicbus_repeated_start(bus, addr, 0); + else + error = iicbus_start(bus, addr, 0); + } + + if (error) + break; + + if (msgs[i].flags & IIC_M_RD) + error = iicbus_read(bus, msgs[i].buf, msgs[i].len, + &lenread, IIC_LAST_READ, 0); + else + error = iicbus_write(bus, msgs[i].buf, msgs[i].len, + &lenwrote, 0); + + if (!(msgs[i].flags & IIC_M_NOSTOP)) { + rpstart = 0; + iicbus_stop(bus); + } else { + rpstart = 1; /* Next message gets repeated start */ + } } return (error); } diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index ae9379fd9af4c..cc648f5fc5c9f 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -222,7 +222,7 @@ ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz) int ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz, - void *maskbuf) + phandle_t *iparent, void *maskbuf) { int rv; @@ -236,7 +236,7 @@ ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, panic("ofw_bus_lookup_imap: could not get reg property"); return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc, ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr, - mintrsz)); + mintrsz, iparent)); } /* @@ -259,7 +259,7 @@ ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, int ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result, - int rintrsz) + int rintrsz, phandle_t *iparent) { phandle_t parent; uint8_t *ref = maskbuf; @@ -303,6 +303,9 @@ ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, if (bcmp(ref, mptr, physsz + intrsz) == 0) { bcopy(mptr + physsz + intrsz + sizeof(parent), result, rintrsz); + + if (iparent != NULL) + *iparent = parent; return (1); } mptr += tsz; diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 1e8376602da2d..512e8b38d07ed 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -63,9 +63,12 @@ bus_child_pnpinfo_str_t ofw_bus_gen_child_pnpinfo_str; /* Routines for processing firmware interrupt maps */ void ofw_bus_setup_iinfo(phandle_t, struct ofw_bus_iinfo *, int); int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int, - void *, int, void *, int, void *); + void *, int, void *, int, phandle_t *, void *); int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, - void *, void *, int); + void *, void *, int, phandle_t *); + +/* Helper to get node's interrupt parent */ +void ofw_bus_find_iparent(phandle_t); /* Helper routine for checking compat prop */ int ofw_bus_is_compatible(device_t, const char *); -- cgit v1.3