Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/iomd New generic I2C framework. Supports bit-b...



details:   https://anonhg.NetBSD.org/src/rev/4856dd2a6d79
branches:  trunk
changeset: 552923:4856dd2a6d79
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Oct 06 16:11:19 2003 +0000

description:
New generic I2C framework.  Supports bit-bang and "intelligent" I2C
interface controllers (of varying intelligence levels).

Contributed by Wasabi Systems, Inc.  Primarily written by Steve Woodford,
with some modification by me.

(NOTE: "cvs ci" was missed on this directory during the initial checkin
of the new I2C code.)

diffstat:

 sys/arch/arm/iomd/files.iomd    |   25 +-
 sys/arch/arm/iomd/iic.c         |  343 ---------------------------
 sys/arch/arm/iomd/iic.h         |   72 -----
 sys/arch/arm/iomd/iic_iomd.c    |  110 --------
 sys/arch/arm/iomd/iomd_clock.c  |   91 +++++++-
 sys/arch/arm/iomd/iomd_iic.S    |  247 --------------------
 sys/arch/arm/iomd/iomdiic.c     |  232 ++++++++++++++++++
 sys/arch/arm/iomd/iomdiicvar.h  |   44 +++
 sys/arch/arm/iomd/rtc.c         |  491 ----------------------------------------
 sys/arch/arm/iomd/todclock.c    |  333 ---------------------------
 sys/arch/arm/iomd/todclockvar.h |   55 ----
 11 files changed, 372 insertions(+), 1671 deletions(-)

diffs (truncated from 2117 to 300 lines):

diff -r 764e7ca0c68e -r 4856dd2a6d79 sys/arch/arm/iomd/files.iomd
--- a/sys/arch/arm/iomd/files.iomd      Mon Oct 06 16:08:42 2003 +0000
+++ b/sys/arch/arm/iomd/files.iomd      Mon Oct 06 16:11:19 2003 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: files.iomd,v 1.2 2002/06/16 13:20:14 bjh21 Exp $
+#      $NetBSD: files.iomd,v 1.3 2003/10/06 16:11:19 thorpej Exp $
 #
 # IOMD-specific configuration data
 #
 
 # IOMD device
-# parent to kbd, qms, opms, iic
+# parent to kbd, qms, opms, iomdiic
 # also provides irq and timer services
 device iomd {}
 attach iomd at mainbus
@@ -16,23 +16,10 @@
 file   arch/arm/iomd/iomd_fiq.S                iomd
 file   arch/arm/iomd/iomd_dma.c                iomd
 
-# IIC device
-device iic { addr = -1 }
-file   arch/arm/iomd/iic.c                     iic             needs-flag
-
-attach iic at iomd with iic_iomd
-file   arch/arm/iomd/iic_iomd.c                iic_iomd
-file   arch/arm/iomd/iomd_iic.S                iic_iomd
-
-# IIC based RTC
-define todservice {}
-device rtc : todservice
-attach rtc at iic
-file   arch/arm/iomd/rtc.c                     rtc             needs-flag
-
-device todclock
-attach todclock at todservice
-file   arch/arm/iomd/todclock.c                todclock        needs-count
+# I^2C bus (bit-banged through IOMD control register)
+device iomdiic: i2cbus, i2c_bitbang
+attach iomdiic at iomd
+file   arch/arm/iomd/iomdiic.c                 iomdiic
 
 # IOMD mouse devices
 # clock device
diff -r 764e7ca0c68e -r 4856dd2a6d79 sys/arch/arm/iomd/iic.c
--- a/sys/arch/arm/iomd/iic.c   Mon Oct 06 16:08:42 2003 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-/*     $NetBSD: iic.c,v 1.8 2003/07/15 00:24:44 lukem Exp $    */
-
-/*
- * Copyright (c) 1994-1996 Mark Brinicombe.
- * Copyright (c) 1994 Brini.
- * All rights reserved.
- *
- * This code is derived from software written for Brini by Mark Brinicombe
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by Mark Brinicombe.
- * 4. The name of the company nor the name of the author may be used to
- *    endorse or promote products derived from this software without specific
- *    prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * RiscBSD kernel project
- *
- * iic.c
- *
- * Routines to communicate with IIC devices
- *
- * Created      : 13/10/94
- *
- * Based of kate/display/iiccontrol.c
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: iic.c,v 1.8 2003/07/15 00:24:44 lukem Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/conf.h>
-#include <sys/malloc.h>
-#include <sys/device.h>
-#include <sys/event.h>
-
-#include <machine/bus.h>
-#include <machine/cpu.h>
-
-#include <arm/cpufunc.h>
-
-#include <arm/iomd/iic.h>
-#include <arm/iomd/iicvar.h>
-
-#include "locators.h"
-
-/* Local function prototypes */
-
-static int iic_getack          __P((void));
-static void iic_write_bit      __P((int bit));
-static int iic_write_byte      __P((u_char value));
-static u_char iic_read_byte    __P((void));
-static void iic_start_bit      __P((void));
-static void iic_stop_bit       __P((void));
-
-static int  iicprint  __P((void *aux, const char *name));
-
-/* External functions that do the bit twiddling */
-extern int  iic_getstate               __P((void));
-extern void iic_set_state_and_ack      __P((int, int));
-extern void iic_set_state              __P((int, int));
-extern void iic_delay                  __P((int));
-
-extern struct cfdriver iic_cd;
-
-dev_type_open(iicopen);
-dev_type_close(iicclose);
-
-const struct cdevsw iic_cdevsw = {
-       iicopen, iicclose, noread, nowrite, noioctl,
-       nostop, notty, nopoll, nommap, nokqfilter,
-};
-
-/*
- * Main entry to IIC driver.
- */
-
-int
-iic_control(address, buffer, count)
-       u_char address;
-       u_char *buffer;
-       int count;
-{
-       int loop;
-
-       /* Send the start bit */
-
-       iic_start_bit();
-
-       /* Send the address */
-
-       if (!iic_write_byte(address)) {
-               iic_stop_bit();
-               return(-1);
-       }
-
-       /* Read or write the data as required */
-
-       if ((address & 1) == 0) {
-               /* Write bytes */
-               for (loop = 0; loop < count; ++loop) {
-                       if (!iic_write_byte(buffer[loop])) {
-                               iic_stop_bit();
-                               return(-1);
-                       }
-               }
-       }
-       else {
-               /* Read bytes */
-               for (loop = 0; loop < count; ++loop) {
-                       buffer[loop] = iic_read_byte();
-
-                       /* Send final acknowledge */
-
-                       if (loop == (count - 1))
-                               iic_write_bit(1);
-                       else
-                               iic_write_bit(0);
-               }
-       }
-
-       /* Send stop bit */
-
-       iic_stop_bit();
-
-       return(0);
-}
-
-
-static int
-iic_getack()
-{
-       u_int oldirqstate;
-       int ack;
-
-       iic_set_state(1, 0);
-       oldirqstate = disable_interrupts(I32_bit);
-       iic_set_state_and_ack(1, 1);
-       ack = iic_getstate();
-       iic_set_state(1, 0);
-       restore_interrupts(oldirqstate);
-
-       return((ack & 1) == 0);
-}
-
-
-static void
-iic_write_bit(bit)
-       int bit;
-{
-       u_int oldirqstate;
-
-       iic_set_state(bit, 0);
-       oldirqstate = disable_interrupts(I32_bit);
-       iic_set_state_and_ack(bit, 1);
-       iic_set_state(bit, 0);
-       restore_interrupts(oldirqstate);
-}
-
-
-static int
-iic_write_byte(value)
-       u_char value;
-{
-       int loop;
-       int bit;
-
-       for (loop = 0x80; loop != 0; loop = loop >> 1) {
-               bit = ((value & loop) != 0);
-               iic_write_bit(bit);
-       }
-
-       return(iic_getack());
-}
-
-
-static u_char
-iic_read_byte()
-{
-       int loop;
-       u_char byte;
-       u_int oldirqstate;
-
-       iic_set_state(1,0);
-
-       byte = 0;
-
-       for (loop = 0; loop < 8; ++loop) {
-               oldirqstate = disable_interrupts(I32_bit);
-               iic_set_state_and_ack(1, 1);
-               byte = (byte << 1) + (iic_getstate() & 1);
-               iic_set_state(1, 0);
-               restore_interrupts(oldirqstate);
-       }
-
-       return(byte);
-}
-
-
-static void
-iic_start_bit()
-{
-       iic_set_state(1, 1);
-       iic_set_state(0, 1);
-       iic_delay(10);
-       iic_set_state(0, 0);
-}
-
-
-static void
-iic_stop_bit()
-{
-       iic_set_state(0, 1);
-       iic_set_state(1, 1);
-}
-
-/* driver structures */
-
-/*
- * int iicprint(void *aux, const char *name)
- *
- * print function for child device configuration
- */
-
-static int
-iicprint(aux, name)
-       void *aux;
-       const char *name;
-{
-       struct iicbus_attach_args *iba = aux;



Home | Main Index | Thread Index | Old Index