diff -urN sys.orig/arch/sandpoint/conf/KUROBOX sys/arch/sandpoint/conf/KUROBOX --- sys.orig/arch/sandpoint/conf/KUROBOX 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/conf/KUROBOX 2005-08-26 00:29:25.000000000 +0900 @@ -0,0 +1,173 @@ +# KUROBOX (CPU:200MHz, MEM:64MB) + +include "arch/sandpoint/conf/std.kurobox" + +#options INCLUDE_CONFIG_FILE # embed config file in kernel binary + +maxusers 32 + +options KUROBOX # Enable kurobox depend code +#options KUROBOX_HG # CPU:266MHz, MEM: 128MB (cf. machdep.c) + +#options IPKDBUSERHACK # Allow access to mapped memory via kgdb +#options DEBUG_BY_TOOLS # Allow debugging from toolsnet +# HMAC key to be used for debugging sessions +#options IPKDBKEY="\"HMAC pass phrase text\"" +#options IPKDBSECURE # Allow debugging even when securelevel > 0 +#makeoptions DEBUG="-g" + +#options DEBUG +options DIAGNOSTIC +options TRAP_PANICWAIT +options DDB +#options DDB_HISTORY_SIZE=100 # Enable history editing in DDB +options KTRACE +#options PMAPCHECK +#options PMAPDEBUG +options USERCONF # userconf(4) support +#options PIPE_SOCKETPAIR # smaller, but slower pipe(2) +options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel + +#options COMPAT_43 +#options COMPAT_09 +#options COMPAT_10 +#options COMPAT_12 +#options COMPAT_13 +#options COMPAT_14 +#options COMPAT_16 +#options COMPAT_20 # (In near future) +#options COMPAT_386BSD_MBRPART # recognize old partition ID +#options COMPAT_LINUX # Linux binary compatibility +#options TCP_COMPAT_42 # 4.2BSD TCP/IP bug compat. Not recommended. + +options MSGBUFSIZE=65536 +file-system FFS +file-system EXT2FS +#file-system LFS +file-system MFS +file-system NFS +file-system CD9660 +file-system MSDOSFS +file-system FDESC +file-system KERNFS +#file-system NULLFS +#file-system OVERLAY +#file-system PORTAL +file-system PROCFS +#file-system UMAPFS +file-system UNION + +#options QUOTA # UFS quotas +options SOFTDEP # FFS soft updates support. +options FFS_EI # FFS Endian Independant support +options BSDDISKLABEL_EI # Disklabel Endian Independent support +options EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and + # immutable) behave as system flags. +options NFSSERVER + +options INET +#options INET6 +#options TCP_DEBUG # Record last TCP_NDEBUG packets with SO_DEBUG + +#options ALTQ # Manipulate network interfaces' output queues +#options ALTQ_BLUE # Stochastic Fair Blue +#options ALTQ_CBQ # Class-Based Queueing +#options ALTQ_CDNR # Diffserv Traffic Conditioner +#options ALTQ_FIFOQ # First-In First-Out Queue +#options ALTQ_FLOWVALVE # RED/flow-valve (red-penalty-box) +#options ALTQ_HFSC # Hierarchical Fair Service Curve +#options ALTQ_LOCALQ # Local queueing discipline +#options ALTQ_PRIQ # Priority Queueing +#options ALTQ_RED # Random Early Detection +#options ALTQ_RIO # RED with IN/OUT +#options ALTQ_WFQ # Weighted Fair Queueing + +options NFS_BOOT_BOOTPARAM,NFS_BOOT_BOOTP + +config netbsd root on ? type ? + +# network psuedo-devices +pseudo-device bpfilter 8 # packet filter +pseudo-device pppoe # PPP over Ethernet (RFC 2516) +#pseudo-device bridge # simple inter-network bridging +#options BRIDGE_IPF # bridge uses IP/IPv6 pfil hooks too +pseudo-device ipfilter +pseudo-device loop + +# miscellaneous pseudo-devices +pseudo-device rnd # /dev/random and in-kernel generator +pseudo-device vnd 4 +#pseudo-device cgd 4 # cryptographic disk devices +pseudo-device pty +pseudo-device clockctl # user control of clock subsystem +pseudo-device ksyms # /dev/ksyms +# +# device +# +options RTC_OFFSET="-540" # hardware clock is this many mins. west of GMT + +#options PCIVERBOSE # verbose PCI device messages +#options PCI_CONFIG_DUMP # verbosely dump PCI config space +options PCI_NETBSD_CONFIGURE # Have NetBSD configure PCI I/O & Mem + +mainbus0 at root + +cpu* at mainbus0 +pci* at mainbus0 bus ? + +ppb* at pci? dev ? function ? # PCI-PCI bridges +pci* at ppb? bus ? + +pchb* at pci? dev ? function ? # PCI host bridge + +cmdide* at pci? dev ? function ? # CMD tech IDE controllers +atabus* at ata? + +tlp* at pci? dev ? function ? # DEC Tulip and similar (KUROBOX) +#re* at pci? dev ? function ? # RealTek 8169S/8110S (KUROBOX/HG) + +ukphy* at mii? phy ? # generic unknown PHYs + +sd* at scsibus? target ? lun ? # SCSI disk drives +#st* at scsibus? target ? lun ? # SCSI tape drives +cd* at scsibus? target ? lun ? # SCSI CD-ROM drives +#ch* at scsibus? target ? lun ? # SCSI autochangers +#ses* at scsibus? target ? lun ? # SCSI Enclosure Services devices +#ss* at scsibus? target ? lun ? # SCSI scanners +uk* at scsibus? target ? lun ? # SCSI unknown + +wd* at atabus? drive ? flags 0x0 +atapibus* at atapi? +cd* at atapibus? drive ? flags 0x0 # ATAPI CD-ROM drives +sd* at atapibus? drive ? flags 0x0 # ATAPI disk drives +#st* at atapibus? drive ? flags 0x0 # ATAPI tape drives +uk* at atapibus? drive ? flags 0x0 # ATAPI unknown + +eumb* at mainbus0 # MPC824x Embedded Utility Memory Block +ociic* at eumb? addr ? irq ? # On-Chip IIC +iic* at ociic? # I2C bus +rsrtc* at iic? addr 0x32 # RICOH RS5C372 RTC +com* at eumb? addr ? irq ? # DUART + +include "dev/usb/files.usb" + +ehci* at pci? dev ? function ? +ohci* at pci? dev ? function ? +usb* at ehci? +usb* at ohci? + +uhub* at usb? + +ugen* at uhub? port ? +ulpt* at uhub? port ? configuration ? interface ? +umass* at uhub? port ? configuration ? interface ? +atapibus* at umass? +scsibus* at umass? +wd* at umass? + +aue* at uhub? port ? # ADMtek AN986 Pegasus based adapters +#cue* at uhub? port ? # CATC USB-EL1201A based adapters +#kue* at uhub? port ? # Kawasaki LSI KL5KUSB101B based adapters +uax* at uhub? port ? # ASIX AX88172 based adapters +#udav* at uhub? port ? # Davicom DM9601 based adapters +#url* at uhub? port ? # Realtek RTL8150L based adapters diff -urN sys.orig/arch/sandpoint/conf/KUROBOX_HG sys/arch/sandpoint/conf/KUROBOX_HG --- sys.orig/arch/sandpoint/conf/KUROBOX_HG 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/conf/KUROBOX_HG 2005-08-26 00:29:49.000000000 +0900 @@ -0,0 +1,173 @@ +# KUROBOX_HG (CPU:266MHz, MEM:128MHz) + +include "arch/sandpoint/conf/std.kurobox" + +#options INCLUDE_CONFIG_FILE # embed config file in kernel binary + +maxusers 32 + +options KUROBOX # +options KUROBOX_HG # CPU:266MHz, MEM: 128MB + +#options IPKDBUSERHACK # Allow access to mapped memory via kgdb +#options DEBUG_BY_TOOLS # Allow debugging from toolsnet +# HMAC key to be used for debugging sessions +#options IPKDBKEY="\"HMAC pass phrase text\"" +#options IPKDBSECURE # Allow debugging even when securelevel > 0 +#makeoptions DEBUG="-g" + +#options DEBUG +options DIAGNOSTIC +options TRAP_PANICWAIT +options DDB +#options DDB_HISTORY_SIZE=100 # Enable history editing in DDB +options KTRACE +#options PMAPCHECK +#options PMAPDEBUG +options USERCONF # userconf(4) support +#options PIPE_SOCKETPAIR # smaller, but slower pipe(2) +options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel + +#options COMPAT_43 +#options COMPAT_09 +#options COMPAT_10 +#options COMPAT_12 +#options COMPAT_13 +#options COMPAT_14 +#options COMPAT_16 +#options COMPAT_20 # (In near future) +#options COMPAT_386BSD_MBRPART # recognize old partition ID +#options COMPAT_LINUX # Linux binary compatibility +#options TCP_COMPAT_42 # 4.2BSD TCP/IP bug compat. Not recommended. + +options MSGBUFSIZE=65536 +file-system FFS +file-system EXT2FS +#file-system LFS +file-system MFS +file-system NFS +file-system CD9660 +file-system MSDOSFS +file-system FDESC +file-system KERNFS +#file-system NULLFS +#file-system OVERLAY +#file-system PORTAL +file-system PROCFS +#file-system UMAPFS +file-system UNION + +#options QUOTA # UFS quotas +options SOFTDEP # FFS soft updates support. +options FFS_EI # FFS Endian Independant support +options BSDDISKLABEL_EI # Disklabel Endian Independent support +options EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and + # immutable) behave as system flags. +options NFSSERVER + +options INET +#options INET6 +#options TCP_DEBUG # Record last TCP_NDEBUG packets with SO_DEBUG + +#options ALTQ # Manipulate network interfaces' output queues +#options ALTQ_BLUE # Stochastic Fair Blue +#options ALTQ_CBQ # Class-Based Queueing +#options ALTQ_CDNR # Diffserv Traffic Conditioner +#options ALTQ_FIFOQ # First-In First-Out Queue +#options ALTQ_FLOWVALVE # RED/flow-valve (red-penalty-box) +#options ALTQ_HFSC # Hierarchical Fair Service Curve +#options ALTQ_LOCALQ # Local queueing discipline +#options ALTQ_PRIQ # Priority Queueing +#options ALTQ_RED # Random Early Detection +#options ALTQ_RIO # RED with IN/OUT +#options ALTQ_WFQ # Weighted Fair Queueing + +options NFS_BOOT_BOOTPARAM,NFS_BOOT_BOOTP + +config netbsd root on ? type ? + +# network psuedo-devices +pseudo-device bpfilter 8 # packet filter +pseudo-device pppoe # PPP over Ethernet (RFC 2516) +#pseudo-device bridge # simple inter-network bridging +#options BRIDGE_IPF # bridge uses IP/IPv6 pfil hooks too +pseudo-device ipfilter +pseudo-device loop + +# miscellaneous pseudo-devices +pseudo-device rnd # /dev/random and in-kernel generator +pseudo-device vnd 4 +#pseudo-device cgd 4 # cryptographic disk devices +pseudo-device pty +pseudo-device clockctl # user control of clock subsystem +pseudo-device ksyms # /dev/ksyms +# +# device +# +options RTC_OFFSET="-540" # hardware clock is this many mins. west of GMT + +#options PCIVERBOSE # verbose PCI device messages +#options PCI_CONFIG_DUMP # verbosely dump PCI config space +options PCI_NETBSD_CONFIGURE # Have NetBSD configure PCI I/O & Mem + +mainbus0 at root + +cpu* at mainbus0 +pci* at mainbus0 bus ? + +ppb* at pci? dev ? function ? # PCI-PCI bridges +pci* at ppb? bus ? + +pchb* at pci? dev ? function ? # PCI host bridge + +cmdide* at pci? dev ? function ? # CMD tech IDE controllers +atabus* at ata? + +#tlp* at pci? dev ? function ? # DEC Tulip and similar (KUROBOX) +re* at pci? dev ? function ? # RealTek 8169S/8110S (KUROBOX/HG) + +ukphy* at mii? phy ? # generic unknown PHYs + +sd* at scsibus? target ? lun ? # SCSI disk drives +#st* at scsibus? target ? lun ? # SCSI tape drives +cd* at scsibus? target ? lun ? # SCSI CD-ROM drives +#ch* at scsibus? target ? lun ? # SCSI autochangers +#ses* at scsibus? target ? lun ? # SCSI Enclosure Services devices +#ss* at scsibus? target ? lun ? # SCSI scanners +uk* at scsibus? target ? lun ? # SCSI unknown + +wd* at atabus? drive ? flags 0x0 +atapibus* at atapi? +cd* at atapibus? drive ? flags 0x0 # ATAPI CD-ROM drives +sd* at atapibus? drive ? flags 0x0 # ATAPI disk drives +#st* at atapibus? drive ? flags 0x0 # ATAPI tape drives +uk* at atapibus? drive ? flags 0x0 # ATAPI unknown + +eumb* at mainbus0 # MPC824x Embedded Utility Memory Block +ociic* at eumb? addr ? irq ? # On-Chip IIC +iic* at ociic? # I2C bus +rsrtc* at iic? addr 0x32 # RICOH RS5C372 RTC +com* at eumb? addr ? irq ? # DUART + +include "dev/usb/files.usb" + +ehci* at pci? dev ? function ? +ohci* at pci? dev ? function ? +usb* at ehci? +usb* at ohci? + +uhub* at usb? + +ugen* at uhub? port ? +ulpt* at uhub? port ? configuration ? interface ? +umass* at uhub? port ? configuration ? interface ? +atapibus* at umass? +scsibus* at umass? +wd* at umass? + +aue* at uhub? port ? # ADMtek AN986 Pegasus based adapters +#cue* at uhub? port ? # CATC USB-EL1201A based adapters +#kue* at uhub? port ? # Kawasaki LSI KL5KUSB101B based adapters +uax* at uhub? port ? # ASIX AX88172 based adapters +#udav* at uhub? port ? # Davicom DM9601 based adapters +#url* at uhub? port ? # Realtek RTL8150L based adapters diff -urN sys.orig/arch/sandpoint/conf/files.kurobox sys/arch/sandpoint/conf/files.kurobox --- sys.orig/arch/sandpoint/conf/files.kurobox 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/conf/files.kurobox 2005-08-13 11:34:22.000000000 +0900 @@ -0,0 +1,13 @@ +# EUMB @ MPC824x +device eumb {[addr=-1], [irq=-1]} +attach eumb at mainbus +file arch/sandpoint/kurobox/dev/eumb.c eumb + +# com @ EUMB +attach com at eumb with com_eumb +file arch/sandpoint/kurobox/dev/com_eumb.c com_eumb + +# iic @ EUMB +device ociic: i2cbus +attach ociic at eumb +file arch/sandpoint/kurobox/dev/ociic_eumb.c ociic diff -urN sys.orig/arch/sandpoint/conf/std.kurobox sys/arch/sandpoint/conf/std.kurobox --- sys.orig/arch/sandpoint/conf/std.kurobox 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/conf/std.kurobox 2005-08-13 11:41:08.000000000 +0900 @@ -0,0 +1,25 @@ +# $NetBSD: std.sandpoint,v 1.8 2003/02/03 17:10:13 matt Exp $ +# +# standard, required NetBSD/sandpoint 'options' + +machine sandpoint powerpc + +options PPC_OEA # Sandpoint uses OEA compliant CPUs +makeoptions PPCDIR="oea" # Tell Makefile.powerpc what dir to use + +# Executable support: +options EXEC_ELF32 # exec ELF binaries +options EXEC_SCRIPT # exec #! scripts + +options OPENPIC + +options INTSTK=16384 + +makeoptions TEXTADDR=0x90000 # for nbloader.o +makeoptions NEED_BINARY=yes # for nbloader.o + +makeoptions NEED_SYMTAB=yes +makeoptions DBSYM="dbsym" +options SYMTAB_SPACE=250000 + +include arch/sandpoint/conf/files.kurobox diff -urN sys.orig/arch/sandpoint/kurobox/dev/com_eumb.c sys/arch/sandpoint/kurobox/dev/com_eumb.c --- sys.orig/arch/sandpoint/kurobox/dev/com_eumb.c 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/kurobox/dev/com_eumb.c 2005-08-23 22:35:51.000000000 +0900 @@ -0,0 +1,97 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct com_eumb_softc { + struct com_softc sc_com; + void *sc_ih; +}; + +static int com_eumb_probe(struct device *, struct cfdata *, void *); +static void com_eumb_attach(struct device *, struct device *, void *); + +CFATTACH_DECL(com_eumb, sizeof(struct com_eumb_softc), + com_eumb_probe, com_eumb_attach, NULL, NULL); + +int +com_eumb_probe(struct device *parent, struct cfdata *cf, void *aux) +{ + struct eumb_attach_args *eaa = aux; + + /* match only com devices */ + if (strcmp(eaa->eumb_name, cf->cf_name) != 0) + return 0; + + return (1); +} + +void +com_eumb_attach(struct device *parent, struct device *self, void *aux) +{ + struct com_eumb_softc *msc = (void *)self; + struct com_softc *sc = &msc->sc_com; + struct eumb_attach_args *eaa = aux; + + sc->sc_iot = eaa->eumb_bt; + sc->sc_iobase = eaa->eumb_addr; + + /* console check */ + if (!com_is_console(sc->sc_iot, eaa->eumb_addr, &sc->sc_ioh) && + bus_space_map(sc->sc_iot, eaa->eumb_addr, COM_NPORTS, 0, + &sc->sc_ioh)) { + printf(": can't map i/o space\n"); + return; + } + + /* set freq. */ +#ifdef KUROBOX_HG + sc->sc_frequency = 133000000; /* XXX */ +#else + sc->sc_frequency = 100000000; /* XXX */ +#endif + sc->sc_swflags |= TIOCFLAG_SOFTCAR; /* 3-wired lines */ + com_attach_subr(sc); + intr_establish(eaa->eumb_irq, IST_LEVEL, IPL_SERIAL, comintr, sc); +} diff -urN sys.orig/arch/sandpoint/kurobox/dev/eumb.c sys/arch/sandpoint/kurobox/dev/eumb.c --- sys.orig/arch/sandpoint/kurobox/dev/eumb.c 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/kurobox/dev/eumb.c 2005-08-04 23:43:02.000000000 +0900 @@ -0,0 +1,158 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include "locators.h" + +#include +#include +#include +#include + +#include +#include +#include + +#define MPC824X_IIC_BASE (SANDPOINT_BUS_SPACE_EUMB + 0x3000) +#define MPC8245_UART0_BASE (SANDPOINT_BUS_SPACE_EUMB + 0x4500) +#define MPC8245_UART1_BASE (SANDPOINT_BUS_SPACE_EUMB + 0x4600) + +#include +#include + +/* from mainbus.c */ +union mainbus_attach_args { + const char *mba_busname; + struct pcibus_attach_args mba_pba; +}; + +/* + * The devices on the EUMB of the MPC824X CPU. + */ +const struct eumb_dev { + int pvr; + const char *name; + bus_addr_t addr; + int irq; +} eumb_devs [] = { + /* MPC8240 */ + { MPC8240, "ociic",MPC824X_IIC_BASE, SANDPOINT_INTR_I2C }, + + /* MPC8245 */ + { MPC8245, "ociic",MPC824X_IIC_BASE, SANDPOINT_INTR_I2C }, + { MPC8245, "com", MPC8245_UART1_BASE, SANDPOINT_INTR_UART1 }, + { MPC8245, "com", MPC8245_UART0_BASE, SANDPOINT_INTR_UART0 }, + { 0, NULL } +}; + +static int eumb_match(struct device *, struct cfdata *, void *); +static void eumb_attach(struct device *, struct device *, void *); +static int eumb_submatch(struct device *, struct cfdata *, void *); +static int eumb_print(void *, const char *); + +CFATTACH_DECL(eumb, sizeof(struct device), + eumb_match, eumb_attach, NULL, NULL); + +/* + * Probe for eumb + */ +static int +eumb_match(struct device *parent, struct cfdata *cf, void *aux) +{ + struct eumb_attach_args *eaa = aux; + + /* match only eumb devices */ + if (strcmp(eaa->eumb_name, cf->cf_name) != 0) + return 0; + + return 1; +} + +static int +eumb_submatch(struct device *parent, struct cfdata *cf, void *aux) +{ + struct eumb_attach_args *eaa = aux; + + if (cf->cf_loc[EUMBCF_ADDR] != EUMBCF_ADDR_DEFAULT && + cf->cf_loc[EUMBCF_ADDR] != eaa->eumb_addr) + return 0; + + return config_match(parent, cf, aux); +} + +/* + * Attach the on-chip peripheral bus. + */ +static void +eumb_attach(struct device *parent, struct device *self, void *aux) +{ + union mainbus_attach_args *mba = aux; + struct eumb_attach_args eaa; + bus_space_tag_t tag; + int i, pvr; + + printf("\n"); + pvr = mfpvr() >> 16; + + tag = &sandpoint_mem_bs_tag; + + for (i = 0; eumb_devs[i].name != NULL; i++) { + if (eumb_devs[i].pvr != pvr) + continue; + eaa.eumb_name = eumb_devs[i].name; + eaa.eumb_addr = eumb_devs[i].addr; + eaa.eumb_irq = eumb_devs[i].irq; + eaa.eumb_bt = tag; + eaa.eumb_dmat = mba->mba_pba.pba_dmat; + + (void) config_found_sm(self, &eaa, eumb_print, eumb_submatch); + } +} + +static int +eumb_print(void *aux, const char *pnp) +{ + struct eumb_attach_args *eaa = aux; + + if (pnp) + aprint_normal("%s at %s", eaa->eumb_name, pnp); + + if (eaa->eumb_addr != EUMBCF_ADDR_DEFAULT) + aprint_normal(" addr 0x%08lx", eaa->eumb_addr); + if (eaa->eumb_irq != EUMBCF_IRQ_DEFAULT) + aprint_normal(" irq %d", eaa->eumb_irq); + + return UNCONF; +} diff -urN sys.orig/arch/sandpoint/kurobox/dev/eumbvar.h sys/arch/sandpoint/kurobox/dev/eumbvar.h --- sys.orig/arch/sandpoint/kurobox/dev/eumbvar.h 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/kurobox/dev/eumbvar.h 2005-08-23 23:13:49.000000000 +0900 @@ -0,0 +1,50 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +#ifndef _KUROBOX_EUMBVAR_H_ +#define _KUROBOX_EUMBVAR_H_ + +#include + +struct eumb_attach_args { + const char *eumb_name; + u_long eumb_addr; + int eumb_irq; + bus_space_tag_t eumb_bt; /* Bus space tag */ + bus_dma_tag_t eumb_dmat; /* DMA tag */ +}; + +/* For use before eumb_attach() is called */ +extern bus_space_tag_t eumb_get_bus_space_tag(void); + +#endif /* _KUROBOX_EUMBVAR_H_ */ diff -urN sys.orig/arch/sandpoint/kurobox/dev/ociic_eumb.c sys/arch/sandpoint/kurobox/dev/ociic_eumb.c --- sys.orig/arch/sandpoint/kurobox/dev/ociic_eumb.c 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/kurobox/dev/ociic_eumb.c 2005-08-15 22:16:07.000000000 +0900 @@ -0,0 +1,440 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); +#include "locators.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +struct ociic_softc { + struct device sc_dev; + bus_space_tag_t sc_bust; + bus_space_handle_t sc_bush; + uint8_t sc_txen; + struct i2c_controller sc_i2c; + struct lock sc_buslock; +}; + +static int ociic_match(struct device *, struct cfdata *, void *); +static void ociic_attach(struct device *, struct device *, void *); +static int ociic_acquire_bus(void *, int); +static void ociic_release_bus(void *, int); +static int ociic_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t, + void *, size_t, int); +static int ociic_send_start(void *v, int flags); +static int ociic_send_stop(void *v, int flags); +static int ociic_initiate_xfer(void *v, i2c_addr_t addr, int flags); +static int ociic_read_byte(void *v, uint8_t *valp, int flags); +static int ociic_write_byte(void *v, uint8_t val, int flags); + +#define RETRY_COUNT 10 + +CFATTACH_DECL(ociic, sizeof(struct ociic_softc), + ociic_match, ociic_attach, NULL, NULL); + +#ifdef OCIIC_DEBUG +static u_int32_t RREG(struct ociic_softc *sc, u_int32_t reg); +static void WREG(struct ociic_softc *sc, u_int32_t reg, u_int32_t val); + +static u_int32_t +RREG(struct ociic_softc *sc, u_int32_t reg) +{ + u_int32_t val; + + val = bus_space_read_4(sc->sc_bust, sc->sc_bush, reg); + printf("I2C:R:%02x:%02x\n", reg, val); + return val; +} + +static void +WREG(struct ociic_softc *sc, u_int32_t reg, u_int32_t val) +{ + bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val); + printf("I2C:W:%02x:%02x\n", reg, val); + return; +} +#else /* OCIIC_DEBUG */ +#define RREG(s,r) bus_space_read_4(s->sc_bust, s->sc_bush, r);DELAY(200) +#define WREG(s,r,v) bus_space_write_4(s->sc_bust, s->sc_bush, r, v);DELAY(200) +#endif /* OCIIC_DEBUG */ + +#define BITON(v, c) ((v) |= (c)) +#define BITOFF(v, c) ((v) &= ~(c)) +#define BITCHK(v, c) ((v) & (c)) + +static int +ociic_match(struct device *parent, struct cfdata *cf, void *args) +{ + struct eumb_attach_args *eaa = args; + + if (strcmp(eaa->eumb_name, cf->cf_name) != 0) + return 0; + + return (1); +} + +static void +ociic_attach(struct device *parent, struct device *self, void *args) +{ + struct ociic_softc *sc = (struct ociic_softc *)self; + struct eumb_attach_args *eaa = args; + struct i2cbus_attach_args iba; + uint32_t ctl; + uint32_t v; + + aprint_naive(": I2C controller\n"); + aprint_normal(": On-Chip I2C controller\n"); + + sc->sc_bust = eaa->eumb_bt; + + bus_space_map(sc->sc_bust, eaa->eumb_addr, IIC_NREG, 0, &sc->sc_bush); + + lockinit(&sc->sc_buslock, PRIBIO|PCATCH, "ociiclk", 0, 0); + + sc->sc_txen = 0; + sc->sc_i2c.ic_cookie = sc; + sc->sc_i2c.ic_acquire_bus = ociic_acquire_bus; + sc->sc_i2c.ic_release_bus = ociic_release_bus; + sc->sc_i2c.ic_exec = ociic_exec; + sc->sc_i2c.ic_send_start = NULL; + sc->sc_i2c.ic_send_stop = NULL; + sc->sc_i2c.ic_initiate_xfer = NULL; + sc->sc_i2c.ic_read_byte = NULL; + sc->sc_i2c.ic_write_byte = NULL; + + /* + * Put the controller into Soft Reset. + */ + /* reset */ + ctl = RREG(sc, MPC_I2CCR); + BITOFF(ctl, I2CCR_MEN); + WREG(sc, MPC_I2CCR, ctl); + + /* set freq. divisior */ + v = RREG(sc, MPC_I2CFDR); + BITOFF(v, I2CFDR_FDR_MASK); + BITON(v, I2CFDR_FDR_VALUE); + WREG(sc, MPC_I2CFDR, v); + + /* set slave addr */ + v = RREG(sc, MPC_I2CADR); + BITOFF(v, I2CADR_MASK); + BITON(v, I2CADR_MYADDR << 1); + WREG(sc, MPC_I2CADR, v); + + /* disable interrupt */ + BITOFF(ctl, I2CCR_MIEN); + + /* enable */ + BITON(ctl, I2CCR_MEN); + WREG(sc, MPC_I2CCR, ctl); + + iba.iba_name = "iic"; + iba.iba_tag = &sc->sc_i2c; + (void) config_found(&sc->sc_dev, &iba, iicbus_print); +} + +static int +ociic_acquire_bus(void *arg, int flags) +{ + struct ociic_softc *sc = arg; + + if (flags & I2C_F_POLL) + return (0); + + return (lockmgr(&sc->sc_buslock, LK_EXCLUSIVE, NULL)); +} + +static void +ociic_release_bus(void *arg, int flags) +{ + struct ociic_softc *sc = arg; + + if (flags & I2C_F_POLL) + return; + + (void) lockmgr(&sc->sc_buslock, LK_RELEASE, NULL); +} + +#define I2C_F_CONT (0x80) /* continue, ignore bus busy at initiate */ + +static int +ociic_exec(void *v, i2c_op_t op, i2c_addr_t addr, const void *vcmd, + size_t cmdlen, void *vbuf, size_t buflen, int flags) +{ + const uint8_t *cmd = vcmd; + uint8_t *buf = vbuf; + int error; + size_t len; + int initiate_done = 0; + + if ((flags & I2C_F_POLL) == 0) + return ENODEV; /* XXX */ + + /* Send "start" and the target address(es) */ + if ((len = cmdlen) != 0) { + if ((error = ociic_initiate_xfer(v, addr, flags)) != 0) + goto bad; + while (len--) { + if ((error = ociic_write_byte(v, *cmd++, flags)) != 0) + goto bad; + } + initiate_done = 1; + } + + if (I2C_OP_READ_P(op)) + flags |= I2C_F_READ; + + len = buflen; + while (len--) { + if (len == 0 && I2C_OP_STOP_P(op)) + flags |= I2C_F_STOP; + + if (I2C_OP_READ_P(op)) { + /* Receive */ + if ((len + 1) == buflen) { + if (initiate_done) { + flags |= I2C_F_CONT; /* XXX */ + } + error = ociic_initiate_xfer(v, addr, flags); + if (error) + goto bad; + flags &= ~I2C_F_CONT; /* XXX */ + } + /* NACK on *BEFORE* last byte. (MPC824x is unique ;-) */ + if (len == 1) + flags |= I2C_F_LAST; + error = ociic_read_byte(v, buf++, flags); + if (error) + goto bad; + } else { + /* Send */ + if ((len + 1) == buflen && cmdlen == 0) { + error = ociic_initiate_xfer(v, addr, flags); + if (error) + goto bad; + } + error = ociic_write_byte(v, *buf++, flags); + if (error) + goto bad; + } + } + return 0; + bad: + ociic_send_stop(v, flags); + return error; +} + +static int +ociic_send_start(void *v, int flags) +{ + struct ociic_softc *sc = (struct ociic_softc *)v; + u_int32_t ctrl; + u_int32_t stat; + + ctrl = RREG(sc, MPC_I2CCR); + if (BITCHK(ctrl, I2CCR_MEN) == 0) { + return ENXIO; + } + + stat = RREG(sc, MPC_I2CSR); + if (BITCHK(stat, I2CSR_MBB) && ((flags & I2C_F_CONT) == 0)) { /* XXX */ + return EBUSY; + } + + if (BITCHK(stat, I2CSR_MIF) && (BITCHK(stat, I2CSR_MAL) == 0)) { + return EIO; + } + + BITON(ctrl, I2CCR_MSTA|I2CCR_MTX); + BITOFF(ctrl, I2CCR_TXAK); + + if (flags & I2C_F_READ) { + BITON(ctrl, I2CCR_RSTA); + } + else { + BITOFF(ctrl, I2CCR_RSTA); + } + + /* store ctrl register */ + WREG(sc, MPC_I2CCR, ctrl); + + /* dummy read */ + (void)RREG(sc, MPC_I2CDR); + + return 0; +} + +static int +ociic_send_stop(void *v, int flags) +{ + struct ociic_softc *sc = (struct ociic_softc *)v; + u_int32_t ctl; + + ctl = RREG(sc, MPC_I2CCR); + BITOFF(ctl, I2CCR_MSTA); + WREG(sc, MPC_I2CCR, ctl); + + return 0; +} + +static int +ociic_initiate_xfer(void *v, i2c_addr_t addr, int flags) +{ + struct ociic_softc *sc = (struct ociic_softc *)v; + int i2caddr; + int error; + u_int32_t ctrl; + + if (addr & 0x80) + return EINVAL; + + i2caddr = (addr << 1) | ((flags & I2C_F_READ) ? 1 : 0); + + error = ociic_send_start(v, flags); + if (error) + return error; + + error = ociic_write_byte(v, i2caddr, flags & ~I2C_F_STOP); + if (error) + return error; + + if (flags & I2C_F_READ) { + ctrl = RREG(sc, MPC_I2CCR); + BITOFF(ctrl, I2CCR_MTX); + WREG(sc, MPC_I2CCR, ctrl); + (void)RREG(sc, MPC_I2CDR); /* dummy read */ + } + return 0; +} + +static int +ociic_read_byte(void *v, uint8_t *valp, int flags) +{ + struct ociic_softc *sc = (struct ociic_softc *)v; + u_int32_t ctrl; + u_int32_t stat; + int retry = RETRY_COUNT; + + /* sanity check */ + ctrl = RREG(sc, MPC_I2CCR); + if (BITCHK(ctrl, I2CCR_MSTA) == 0) + return EIO; /* Not master */ + if (BITCHK(ctrl, I2CCR_MTX)) + return EIO; /* Not read phase */ + + /* stat check */ + while (retry --) { + DELAY(10); + stat = RREG(sc, MPC_I2CSR); + if (BITCHK(stat, I2CSR_MCF)) + break; + } + if (retry == 0) + return EIO; + + /* clear interrupt pending flag */ + BITOFF(stat, I2CSR_MIF); + WREG(sc, MPC_I2CSR, stat); + + if (flags & I2C_F_LAST) { + /* no acknoledge (end of receive) */ + BITON(ctrl, I2CCR_TXAK); + WREG(sc, MPC_I2CCR, ctrl); + } + + if ((flags & I2C_F_STOP) == I2C_F_STOP) + ociic_send_stop(v, flags); + + *valp = (u_int8_t)RREG(sc, MPC_I2CDR); + + return 0; +} + +static int +ociic_write_byte(void *v, uint8_t val, int flags) +{ + struct ociic_softc *sc = (struct ociic_softc *)v; + u_int32_t stat; + u_int32_t ctrl; + int retry = RETRY_COUNT; + + WREG(sc, MPC_I2CDR, val); + + /* sanity check */ + ctrl = RREG(sc, MPC_I2CCR); + if (BITCHK(ctrl, I2CCR_MSTA) == 0) + return EIO; /* Not master */ + if (BITCHK(ctrl, I2CCR_MTX) == 0) + return EIO; /* Not write phase */ + + /* stat check */ + while (retry --) { + DELAY(10); + stat = RREG(sc, MPC_I2CSR); +#if 0 + if (BITCHK(stat, I2CSR_RXAK) == 0) +#else + if (BITCHK(stat, I2CSR_MCF)) +#endif + break; + } + if (retry == 0) + return EIO; + + /* clear interrupt pending flag */ + BITOFF(stat, I2CSR_MIF); + WREG(sc, MPC_I2CSR, stat); + + if (BITCHK(stat, I2CSR_MAL)) { + BITOFF(stat, I2CSR_MAL); + WREG(sc, MPC_I2CSR, stat); + return EIO; /* lost arbitration */ + } + + if (flags & I2C_F_STOP) + ociic_send_stop(v, flags); + + return 0; +} diff -urN sys.orig/arch/sandpoint/kurobox/dev/ociicreg.h sys/arch/sandpoint/kurobox/dev/ociicreg.h --- sys.orig/arch/sandpoint/kurobox/dev/ociicreg.h 1970-01-01 09:00:00.000000000 +0900 +++ sys/arch/sandpoint/kurobox/dev/ociicreg.h 2005-08-13 16:13:18.000000000 +0900 @@ -0,0 +1,72 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +#ifndef _MPC824X_OCIICREG_H_ +#define _MPC824X_OCIICREG_H_ + +/* byte offset of registers */ +#define MPC_I2CADR 0x00 +#define MPC_I2CFDR 0x04 +#define MPC_I2CCR 0x08 +#define MPC_I2CSR 0x0c +#define MPC_I2CDR 0x10 + +/* size of regeisters (in byte) */ +#define IIC_NREG 0x14 + +/* Control Register(CR) bits */ +#define I2CCR_MEN (1u<<7) +#define I2CCR_MIEN (1u<<6) +#define I2CCR_MSTA (1u<<5) +#define I2CCR_MTX (1u<<4) +#define I2CCR_TXAK (1u<<3) +#define I2CCR_RSTA (1u<<2) +#define I2CCR_PCII (1u<<1) +#define I2CCR_BCST (1u<<0) + +/* Status Register(SR) bits */ +#define I2CSR_MCF (1u<<7) +#define I2CSR_MAAS (1u<<6) +#define I2CSR_MBB (1u<<5) +#define I2CSR_MAL (1u<<4) +#define I2CSR_BCA (1u<<3) +#define I2CSR_SRW (1u<<2) +#define I2CSR_MIF (1u<<1) +#define I2CSR_RXAK (1u<<0) + +#define I2CFDR_FDR_MASK (0x3f) +#define I2CFDR_FDR_VALUE (0x2d) /* 1536 */ + +#define I2CADR_MASK (0x7f) +#define I2CADR_MYADDR (0x31) /* XXX: != 0x32(rtc) */ +#endif /* _MPC824X_OCIICREG_H_ */ diff -urN sys.orig/dev/i2c/rs5c372.c sys/dev/i2c/rs5c372.c --- sys.orig/dev/i2c/rs5c372.c 1970-01-01 09:00:00.000000000 +0900 +++ sys/dev/i2c/rs5c372.c 2005-08-13 17:17:54.000000000 +0900 @@ -0,0 +1,252 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ +/* + IMPORTANT: Need more codes. (12/24hr check, Alarm timer, etc ...) +*/ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +struct rsrtc_softc { + struct device sc_dev; + i2c_tag_t sc_tag; + int sc_address; + int sc_open; + struct todr_chip_handle sc_todr; +}; + +static void rsrtc_attach(struct device *, struct device *, void *); +static int rsrtc_match(struct device *, struct cfdata *, void *); + +CFATTACH_DECL(rsrtc, sizeof(struct rsrtc_softc), + rsrtc_match, rsrtc_attach, NULL, NULL); +extern struct cfdriver rsrtc_cd; + +static int rsrtc_clock_read(struct rsrtc_softc *, struct clock_ymdhms *); +static int rsrtc_clock_write(struct rsrtc_softc *, struct clock_ymdhms *); +static int rsrtc_gettime(struct todr_chip_handle *, struct timeval *); +static int rsrtc_settime(struct todr_chip_handle *, struct timeval *); +static int rsrtc_getcal(struct todr_chip_handle *, int *); +static int rsrtc_setcal(struct todr_chip_handle *, int); + +/* + * rsrtc_match() + */ +static int +rsrtc_match(struct device *parent, struct cfdata *cf, void *arg) +{ + struct i2c_attach_args *ia = arg; + + /* match only this RTC devices */ + if (ia->ia_addr == RSRTC_ADDR) + return 1; + + return 0; +} + +/* + * rsrtc_attach() + */ +static void +rsrtc_attach(struct device *parent, struct device *self, void *arg) +{ + struct rsrtc_softc *sc = (struct rsrtc_softc *)self; + struct i2c_attach_args *ia = arg; + u_int8_t cmdbuf[2]; + + aprint_naive(": Real-time Clock\n"); + aprint_normal(": Ricoh RS5C372 Real-time Clock\n"); + + sc->sc_tag = ia->ia_tag; + sc->sc_address = ia->ia_addr; + sc->sc_open = 0; + sc->sc_todr.cookie = sc; + sc->sc_todr.todr_gettime = rsrtc_gettime; + sc->sc_todr.todr_settime = rsrtc_settime; + sc->sc_todr.todr_getcal = rsrtc_getcal; + sc->sc_todr.todr_setcal = rsrtc_setcal; + sc->sc_todr.todr_setwen = NULL; + + todr_attach(&sc->sc_todr); + + /* Initialize */ + cmdbuf[0] = RSRTC_REG_CTL2 << 4; + cmdbuf[1] = RSRTC_FLAG_CTL2_24HR; /* 24hour mode*/ + if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, + cmdbuf, 1, &cmdbuf[1], 1, I2C_F_POLL)) { + iic_release_bus(sc->sc_tag, I2C_F_POLL); + printf("%s: rsrtc_attach: failed to set 24h mode\n", + sc->sc_dev.dv_xname); + return ; + } + cmdbuf[0] = RSRTC_REG_TRIM << 4; + cmdbuf[1] = 0x15; /* XXX clock modify value : need correct */ + if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, + cmdbuf, 1, &cmdbuf[1], 1, I2C_F_POLL)) { + iic_release_bus(sc->sc_tag, I2C_F_POLL); + printf("%s: rsrtc_attach: failed to set clock trimming value\n", + sc->sc_dev.dv_xname); + return ; + } + + return; +} + +static int +rsrtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) +{ + struct rsrtc_softc *sc = ch->cookie; + struct clock_ymdhms dt; + + memset(&dt, 0, sizeof(dt)); + + rsrtc_clock_read(sc, &dt); + + tv->tv_sec = clock_ymdhms_to_secs(&dt); + tv->tv_usec = 0; + + return 0; +} + +static int +rsrtc_settime(struct todr_chip_handle *ch, struct timeval *tv) +{ + struct rsrtc_softc *sc = ch->cookie; + struct clock_ymdhms dt; + + clock_secs_to_ymdhms(tv->tv_sec, &dt); + + if (rsrtc_clock_write(sc, &dt) == 0) + return -1; + + return 0; +} + +static int +rsrtc_setcal(struct todr_chip_handle *ch, int cal) +{ + return EOPNOTSUPP; +} + +static int +rsrtc_getcal(struct todr_chip_handle *ch, int *cal) +{ + return EOPNOTSUPP; +} + +static int +rsrtc_clock_read(struct rsrtc_softc *sc, struct clock_ymdhms *dt) +{ + u_int8_t bcd[RSRTC_REG_RTC_SIZE], cmdbuf[1]; + + if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + printf("%s: rsrtc_clock_read: failed to acquire I2C bus\n", + sc->sc_dev.dv_xname); + return 0; + } + + /* read registers */ + cmdbuf[0] = RSRTC_REG_SC << 4; + if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address, + cmdbuf, 1, bcd, RSRTC_REG_RTC_SIZE, I2C_F_POLL)) { + iic_release_bus(sc->sc_tag, I2C_F_POLL); + printf("%s: rsrtc_clock_read: failed to read rtc\n", + sc->sc_dev.dv_xname); + return 0; + } + + iic_release_bus(sc->sc_tag, I2C_F_POLL); + + /* + * Convert BCD values to clock_ymdhms + */ + dt->dt_sec = FROMBCD(bcd[RSRTC_REG_SC] & RSRTC_REG_SC_MASK); + dt->dt_min = FROMBCD(bcd[RSRTC_REG_MN] & RSRTC_REG_MN_MASK); + dt->dt_hour = FROMBCD(bcd[RSRTC_REG_HR] & RSRTC_REG_HR24_MASK); + dt->dt_wday = FROMBCD(bcd[RSRTC_REG_DW] & RSRTC_REG_DT_MASK); + dt->dt_day = FROMBCD(bcd[RSRTC_REG_DT] & RSRTC_REG_DT_MASK); + dt->dt_mon = FROMBCD(bcd[RSRTC_REG_MO] & RSRTC_REG_MO_MASK); + dt->dt_year = FROMBCD(bcd[RSRTC_REG_YR] & RSRTC_REG_YR_MASK) + 2000; + + return 1; +} + +static int +rsrtc_clock_write(struct rsrtc_softc *sc, struct clock_ymdhms *dt) +{ + u_int8_t bcd[RSRTC_REG_RTC_SIZE], cmdbuf[1]; + + /* + * Convert clock_ymdhms to BCD values + */ + bcd[RSRTC_REG_SC] = TOBCD(dt->dt_sec); + bcd[RSRTC_REG_MN] = TOBCD(dt->dt_min); + bcd[RSRTC_REG_HR] = TOBCD(dt->dt_hour); + bcd[RSRTC_REG_DW] = TOBCD(dt->dt_wday); + bcd[RSRTC_REG_DT] = TOBCD(dt->dt_day); + bcd[RSRTC_REG_MO] = TOBCD(dt->dt_mon); + bcd[RSRTC_REG_YR] = TOBCD(dt->dt_year % 100); + + if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) { + printf("%s: rsrtc_clock_write: failed to acquire I2C bus\n", + sc->sc_dev.dv_xname); + return 0; + } + + /* write registers */ + cmdbuf[0] = RSRTC_REG_SC << 4; + if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address, + cmdbuf, 1, bcd, RSRTC_REG_RTC_SIZE, I2C_F_POLL)) { + iic_release_bus(sc->sc_tag, I2C_F_POLL); + printf("%s: rsrtc_clock_write: failed to read rtc\n", + sc->sc_dev.dv_xname); + return 0; + } + + iic_release_bus(sc->sc_tag, I2C_F_POLL); + return 1; +} diff -urN sys.orig/dev/i2c/rs5c372reg.h sys/dev/i2c/rs5c372reg.h --- sys.orig/dev/i2c/rs5c372reg.h 1970-01-01 09:00:00.000000000 +0900 +++ sys/dev/i2c/rs5c372reg.h 2005-08-13 17:19:03.000000000 +0900 @@ -0,0 +1,99 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2005 Eiji Kawauchi. + * All rights reserved. + * + * 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 for the NetBSD Project by + * Eiji Kawauchi. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + */ + +/* + * Ricoh RS5C372 RTC registers + */ + +#ifndef _DEV_I2C_RS5C372REG_H_ +#define _DEV_I2C_RS5C372REG_H_ + +/* + * Ricoh RS5C372 RTC I2C Address: + * + * 011 0010 + */ +#define RSRTC_ADDRMASK 0x7f +#define RSRTC_ADDR 0x32 + +#define RSRTC_REG_RTC_SIZE 7 /* SC to YR (see below)*/ + +/* RTC registers */ +#define RSRTC_REG_SC 0x0 /* BCD second (0-59) */ +#define RSRTC_REG_MN 0x1 /* BCD minute (0-59) */ +#define RSRTC_REG_HR 0x2 /* BCD hour (0-23) */ +#define RSRTC_REG_DW 0x3 /* BCD day of week (0-6) */ +#define RSRTC_REG_DT 0x4 /* BCD day (1-31) */ +#define RSRTC_REG_MO 0x5 /* BCD month (1-12) */ +#define RSRTC_REG_YR 0x6 /* BCD year (0-99) */ +#define RSRTC_REG_TRIM 0x7 /* Trimming register */ +#define RSRTC_REG_ALMA_MN 0x8 /* BCD Alarm-A minute (0-59) */ +#define RSRTC_REG_ALMA_HR 0x9 /* BCD Alarm-A hour (0-23) */ +#define RSRTC_REG_ALMA_DW 0xa /* BCD Alarm-A day of week (0-6) */ +#define RSRTC_REG_ALMB_MN 0xb /* BCD Alarm-B minute (0-59) */ +#define RSRTC_REG_ALMB_HR 0xc /* BCD Alarm-B hour (0-23) */ +#define RSRTC_REG_ALMB_DW 0xd /* BCD Alarm-B day of week (0-6) */ +#define RSRTC_REG_CTL1 0xe /* Control register 1 */ +#define RSRTC_REG_CTL2 0xf /* Control register 2 */ + +/* RTC registers mask */ +#define RSRTC_REG_DW_MASK 0x07 +#define RSRTC_REG_YR_MASK 0xff +#define RSRTC_REG_MO_MASK 0x1f +#define RSRTC_REG_DT_MASK 0x3f +#define RSRTC_REG_HR12_MASK 0x1f +#define RSRTC_REG_HR24_MASK 0x3f +#define RSRTC_REG_MN_MASK 0x7f +#define RSRTC_REG_SC_MASK 0x7f + +/* RTC flags */ +#define RSRTC_FLAG_CTL1_CT0 0x01 +#define RSRTC_FLAG_CTL1_CT1 0x02 +#define RSRTC_FLAG_CTL1_CT2 0x04 +#define RSRTC_FLAG_CTL1_TEST 0x08 +#define RSRTC_FLAG_CTL1_SL1 0x10 +#define RSRTC_FLAG_CTL1_SL2 0x20 +#define RSRTC_FLAG_CTL1_BALE 0x40 +#define RSRTC_FLAG_CTL1_AALE 0x80 + +#define RSRTC_FLAG_CTL2_BAFG 0x01 +#define RSRTC_FLAG_CTL2_AAFG 0x02 +#define RSRTC_FLAG_CTL2_CTFG 0x04 +#define RSRTC_FLAG_CTL2_CLEN_ 0x08 +#define RSRTC_FLAG_CTL2_ADJ 0x10 +#define RSRTC_FLAG_CTL2_XSTP 0x10 +#define RSRTC_FLAG_CTL2_24HR 0x20 + +#define RSRTC_FLAG_TRIM_XSL_ 0x80 + +#endif /* _DEV_I2C_RS5C372REG_H_ */