Date: Tue, 4 Apr 2006 17:06:57 GMT From: Warner Losh <imp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 94610 for review Message-ID: <200604041706.k34H6v0c077204@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=94610 Change 94610 by imp@imp_Speedy on 2006/04/04 17:06:05 we don't need our custom cdev, so kill it. Affected files ... .. //depot/projects/arm/src/sys/arm/at91/at91_twi.c#11 edit .. //depot/projects/arm/src/sys/arm/at91/at91_twiio.h#5 delete Differences ... ==== //depot/projects/arm/src/sys/arm/at91/at91_twi.c#11 (text+ko) ==== @@ -54,14 +54,13 @@ struct resource *mem_res; /* Memory resource */ struct mtx sc_mtx; /* basically a perimeter lock */ int flags; -#define OPENED 2 /* Device opened */ #define RXRDY 4 #define STOP_DONE 8 #define TXRDY 0x10 - struct cdev *cdev; uint32_t cwgr; int sc_started; int twi_addr; + device_t iicbus; }; static inline uint32_t @@ -84,7 +83,6 @@ #define AT91_TWI_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); #define AT91_TWI_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); #define AT91_TWI_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED); -#define CDEV2SOFTC(dev) ((dev)->si_drv1) #define TWI_DEF_CLK 100000 static devclass_t at91_twi_devclass; @@ -100,19 +98,6 @@ static int at91_twi_activate(device_t dev); static void at91_twi_deactivate(device_t dev); -/* cdev routines */ -static d_open_t at91_twi_open; -static d_close_t at91_twi_close; -static d_ioctl_t at91_twi_ioctl; - -static struct cdevsw at91_twi_cdevsw = -{ - .d_version = D_VERSION, - .d_open = at91_twi_open, - .d_close = at91_twi_close, - .d_ioctl = at91_twi_ioctl -}; - static int at91_twi_probe(device_t dev) { @@ -142,20 +127,23 @@ AT91_TWI_LOCK_DESTROY(sc); goto out; } - sc->cdev = make_dev(&at91_twi_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, - "twi%d", device_get_unit(dev)); - if (sc->cdev == NULL) { - err = ENOMEM; - goto out; - } - sc->cdev->si_drv1 = sc; - sc->cwgr = TWI_CWGR_CKDIV(1) | + sc->cwgr = TWI_CWGR_CKDIV(8 * AT91C_MASTER_CLOCK / 90000) | TWI_CWGR_CHDIV(TWI_CWGR_DIV(TWI_DEF_CLK)) | TWI_CWGR_CLDIV(TWI_CWGR_DIV(TWI_DEF_CLK)); WR4(sc, TWI_CR, TWI_CR_SWRST); WR4(sc, TWI_CR, TWI_CR_MSEN | TWI_CR_SVDIS); WR4(sc, TWI_CWGR, sc->cwgr); + + WR4(sc, TWI_IER, TWI_SR_TXCOMP | TWI_SR_RXRDY | TWI_SR_TXRDY | + TWI_SR_OVRE | TWI_SR_UNRE | TWI_SR_NACK); + + if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL) + device_printf(dev, "could not allocate iicbus instance\n"); + + /* probe and attach the iicbus */ + bus_generic_attach(dev); + out:; if (err) at91_twi_deactivate(dev); @@ -165,7 +153,13 @@ static int at91_twi_detach(device_t dev) { - return (EBUSY); /* XXX */ + int rv; + + at91_twi_deactivate(dev); + if (sc->iicbus && (rv = device_delete_child(dev, sc->iicbus)) != 0) + return (rv); + + return (0); } static int @@ -248,68 +242,6 @@ return (err); } -static int -at91_twi_open(struct cdev *dev, int oflags, int devtype, struct thread *td) -{ - struct at91_twi_softc *sc; - - sc = CDEV2SOFTC(dev); - AT91_TWI_LOCK(sc); - if (!(sc->flags & OPENED)) { - sc->flags |= OPENED; - WR4(sc, TWI_IER, TWI_SR_TXCOMP | TWI_SR_RXRDY | TWI_SR_TXRDY | - TWI_SR_OVRE | TWI_SR_UNRE | TWI_SR_NACK); - } - AT91_TWI_UNLOCK(sc); - return (0); -} - -static int -at91_twi_close(struct cdev *dev, int fflag, int devtype, struct thread *td) -{ - struct at91_twi_softc *sc; - - sc = CDEV2SOFTC(dev); - AT91_TWI_LOCK(sc); - sc->flags &= ~OPENED; - WR4(sc, TWI_IDR, TWI_SR_TXCOMP | TWI_SR_RXRDY | TWI_SR_TXRDY | - TWI_SR_OVRE | TWI_SR_UNRE | TWI_SR_NACK); - AT91_TWI_UNLOCK(sc); - return (0); -} - -static int -at91_twi_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, - struct thread *td) -{ - int err = 0; - struct at91_twi_softc *sc; - - sc = CDEV2SOFTC(dev); - AT91_TWI_LOCK(sc); - switch (cmd) - { - case TWIIOCSETCLOCK: - { - struct at91_twi_clock *twick = (struct at91_twi_clock *)data; - - sc->cwgr = TWI_CWGR_CKDIV(twick->ckdiv) | - TWI_CWGR_CHDIV(TWI_CWGR_DIV(twick->high_rate)) | - TWI_CWGR_CLDIV(TWI_CWGR_DIV(twick->low_rate)); - WR4(sc, TWI_CR, TWI_CR_SWRST); - WR4(sc, TWI_CR, TWI_CR_MSEN | TWI_CR_SVDIS); - WR4(sc, TWI_CWGR, sc->cwgr); - break; - } - default: - err = ENOTTY; - break; - } - AT91_TWI_UNLOCK(sc); - wakeup(sc); - return err; -} - /* * Stop the transfer by entering a STOP state on the iic bus. For read * operations, we've already entered the STOP state, since we need to do
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604041706.k34H6v0c077204>