From owner-p4-projects@FreeBSD.ORG Tue Apr 4 17:06:58 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CB0D216A422; Tue, 4 Apr 2006 17:06:58 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 78BBD16A400 for ; Tue, 4 Apr 2006 17:06:58 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3C6F243D68 for ; Tue, 4 Apr 2006 17:06:58 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k34H6wAN077208 for ; Tue, 4 Apr 2006 17:06:58 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k34H6v0c077204 for perforce@freebsd.org; Tue, 4 Apr 2006 17:06:57 GMT (envelope-from imp@freebsd.org) Date: Tue, 4 Apr 2006 17:06:57 GMT Message-Id: <200604041706.k34H6v0c077204@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 94610 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2006 17:06:59 -0000 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