Initial commit of iic and rtc devices.

This commit is contained in:
mark 1996-04-19 19:49:03 +00:00
parent ab4a325e4c
commit 0b22968311
5 changed files with 1813 additions and 0 deletions

403
sys/arch/arm32/dev/iic.c Normal file
View File

@ -0,0 +1,403 @@
/* $NetBSD: iic.c,v 1.1 1996/04/19 19:49:03 mark 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/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <machine/io.h>
#include <machine/iomd.h>
#include <machine/katelib.h>
#include <machine/cpu.h>
#include <machine/irqhandler.h>
#include <machine/iic.h>
#include <arm32/mainbus/mainbus.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));
struct iic_softc {
struct device sc_dev;
int sc_flags;
#define IIC_BROKEN 1
#define IIC_OPEN 2
#define IIC_BUSY 4
};
void iicattach __P((struct device *parent, struct device *self, void *aux));
int iicmatch __P((struct device *parent, void *match, void *aux));
/*
* 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 = ReadByte(IOMD_IOCR);
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) + (ReadByte(IOMD_IOCR) & 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);
}
struct cfattach iic_ca = {
sizeof(struct iic_softc), iicmatch, iicattach
};
struct cfdriver iic_cd = {
NULL, "iic", DV_DULL, 0
};
int
iicmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
int id;
/* Make sure we have an IOMD we understand */
id = ReadByte(IOMD_ID0) | (ReadByte(IOMD_ID1) << 8);
/* So far I only know about this IOMD */
switch (id) {
case RPC600_IOMD_ID:
case RC7500_IOC_ID:
return(1);
break;
default:
printf("iic: Unknown IOMD id=%04x", id);
break;
}
return(0);
}
int
iicprint(aux, name)
void *aux;
char *name;
{
struct iicbus_attach_args *ib = aux;
if (!name) {
if (ib->ib_addr)
printf(" addr 0x%02x", ib->ib_addr);
}
/* XXXX print flags */
return (QUIET);
}
int
iicsubmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
struct cfdata *cf = match;
struct iicbus_attach_args *ib = aux;
if (cf->cf_fstate == FSTATE_STAR)
panic("eekkk, I'm stuffed");
ib->ib_addr = cf->cf_loc[0];
if (ib->ib_addr == -1)
return(0);
return((*cf->cf_attach->ca_match)(parent, match, aux));
}
void
iicattach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct iicbus_attach_args iaa;
printf("\n");
while (config_found_sm(self, &iaa, iicprint, iicsubmatch));
}
int
iicopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct iic_softc *sc;
int unit = minor(dev);
if (unit >= iic_cd.cd_ndevs)
return(ENXIO);
sc = iic_cd.cd_devs[unit];
if (!sc) return(ENXIO);
if (sc->sc_flags & IIC_OPEN) return(EBUSY);
sc->sc_flags |= IIC_OPEN;
return(0);
}
int
iicclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
sc->sc_flags &= ~IIC_OPEN;
return(0);
}
int
iicread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
return(ENXIO);
}
int
iicwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
return(ENXIO);
}
int
iicioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct iic_softc *sc = iic_cd.cd_devs[minor(dev)];
/*
switch (cmd) {
case IICIOC_CONTROL:
if (iiccontrol() != 0) {
return(EIO);
}
return(0);
}
*/
return(EINVAL);
}
/* End of iic.c */

384
sys/arch/arm32/dev/rtc.c Normal file
View File

@ -0,0 +1,384 @@
/* $NetBSD: rtc.c,v 1.1 1996/04/19 19:49:06 mark 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 Brini.
* 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
*
* rtc.c
*
* Routines to read and write the RTC and CMOS RAM
*
* Created : 13/10/94
*/
#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 <machine/iic.h>
#include <machine/rtc.h>
struct rtc_softc {
struct device sc_dev;
int sc_flags;
#define RTC_BROKEN 1
#define RTC_OPEN 2
};
void rtcattach __P((struct device *parent, struct device *self, void *aux));
int rtcmatch __P((struct device *parent, void *match, void *aux));
/* Read a byte from CMOS RAM */
int
cmos_read(location)
int location;
{
u_char buff;
/*
* This commented code dates from when I was translating CMOS address
* from the RISCOS addresses. Now all addresses are specifed as
* actual addresses in the CMOS RAM
*/
/*
if (location > 0xF0)
return(-1);
if (location < 0xC0)
buff = location + 0x40;
else
buff = location - 0xB0;
*/
buff = location;
if (iic_control(RTC_Write, &buff, 1))
return(-1);
if (iic_control(RTC_Read, &buff, 1))
return(-1);
return(buff);
}
/* Write a byte to CMOS RAM */
int
cmos_write(location, value)
int location;
int value;
{
u_char buff[2];
/*
* This commented code dates from when I was translating CMOS address
* from the RISCOS addresses. Now all addresses are specifed as
* actual addresses in the CMOS RAM
*/
/* if (location > 0xF0)
return(-1);
if (location < 0xC0)
buff = location + 0x40;
else
buff = location - 0xB0;
*/
buff[0] = location;
buff[1] = value;
if (iic_control(RTC_Write, buff, 2))
return(-1);
return(0);
}
/* Hex to BCD and BCD to hex conversion routines */
static inline int
hexdectodec(n)
u_char n;
{
return(((n >> 4) & 0x0F) * 10 + (n & 0x0F));
}
static inline int
dectohexdec(n)
u_char n;
{
return(((n / 10) << 4) + (n % 10));
}
/* Write the RTC data from an 8 byte buffer */
int
rtc_write(rtc)
rtc_t *rtc;
{
u_char buff[8];
buff[0] = 1;
buff[1] = dectohexdec(rtc->rtc_centi);
buff[2] = dectohexdec(rtc->rtc_sec);
buff[3] = dectohexdec(rtc->rtc_min);
buff[4] = dectohexdec(rtc->rtc_hour) & 0x3f;
buff[5] = dectohexdec(rtc->rtc_day);
buff[6] = dectohexdec(rtc->rtc_mon);
if (iic_control(RTC_Write, buff, 7))
return(0);
cmos_write(RTC_ADDR_YEAR, rtc->rtc_year);
cmos_write(RTC_ADDR_CENT, rtc->rtc_cen);
return(1);
}
/* Read the RTC data into a 8 byte buffer */
int
rtc_read(rtc)
rtc_t *rtc;
{
u_char buff[8];
int byte;
buff[0] = 0;
if (iic_control(RTC_Write, buff, 1))
return(0);
if (iic_control(RTC_Read, buff, 8))
return(0);
rtc->rtc_micro = 0;
rtc->rtc_centi = hexdectodec(buff[1] & 0xff);
rtc->rtc_sec = hexdectodec(buff[2] & 0x7f);
rtc->rtc_min = hexdectodec(buff[3] & 0x7f);
rtc->rtc_hour = hexdectodec(buff[4] & 0x3f);
/* If in 12 hour mode need to look at the AM/PM flag */
if (buff[4] & 0x80)
rtc->rtc_hour += (buff[4] & 0x40) ? 12 : 0;
rtc->rtc_day = hexdectodec(buff[5] & 0x3f);
rtc->rtc_mon = hexdectodec(buff[6] & 0x1f);
byte = cmos_read(RTC_ADDR_YEAR);
if (byte == -1)
return(0);
rtc->rtc_year = byte;
byte = cmos_read(RTC_ADDR_CENT);
if (byte == -1)
return(0);
rtc->rtc_cen = byte;
return(1);
}
struct cfattach rtc_ca = {
sizeof(struct rtc_softc), rtcmatch, rtcattach
};
struct cfdriver rtc_cd = {
NULL, "rtc", DV_DULL, 0
};
int
rtcmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
/* struct iicbus_attach_args *ib = aux;*/
return(1);
}
void
rtcattach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct rtc_softc *sc = (struct rtc_softc *)self;
struct iicbus_attach_args *ib = aux;
u_char buff[1];
sc->sc_flags |= RTC_BROKEN;
if ((ib->ib_addr & IIC_PCF8583_MASK) == IIC_PCF8583_ADDR) {
printf(": PCF8583");
buff[0] = 0;
if (iic_control(RTC_Write, buff, 1))
return;
if (iic_control(RTC_Read, buff, 1))
return;
printf(" clock base ");
switch (buff[0] & 0x30) {
case 0x00:
printf("32.768KHz");
break;
case 0x10:
printf("50Hz");
break;
case 0x20:
printf("event");
break;
case 0x30:
printf("test mode");
break;
}
if (buff[0] & 0x80)
printf(" stopped");
if (buff[0] & 0x04)
printf(" alarm enabled");
sc->sc_flags &= ~RTC_BROKEN;
}
/*
* Initialise the time of day register.
* This is normally left to the filing system to do but not all
* filing systems call it e.g. cd9660
*/
inittodr(0);
printf("\n");
}
int
rtcopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct rtc_softc *sc;
int unit = minor(dev);
if (unit >= rtc_cd.cd_ndevs)
return(ENXIO);
sc = rtc_cd.cd_devs[unit];
if (!sc) return(ENXIO);
if (sc->sc_flags & RTC_OPEN) return(EBUSY);
sc->sc_flags |= RTC_OPEN;
return(0);
}
int
rtcclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
sc->sc_flags &= ~RTC_OPEN;
return(0);
}
int
rtcread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
return(ENXIO);
}
int
rtcwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
return(ENXIO);
}
int
rtcioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct rtc_softc *sc = rtc_cd.cd_devs[minor(dev)];
/* switch (cmd) {
case RTCIOC_READ:
return(0);
} */
return(EINVAL);
}
/* End of rtc.c */

View File

@ -0,0 +1,403 @@
/* $NetBSD: iic.c,v 1.1 1996/04/19 19:49:03 mark 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/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <machine/io.h>
#include <machine/iomd.h>
#include <machine/katelib.h>
#include <machine/cpu.h>
#include <machine/irqhandler.h>
#include <machine/iic.h>
#include <arm32/mainbus/mainbus.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));
struct iic_softc {
struct device sc_dev;
int sc_flags;
#define IIC_BROKEN 1
#define IIC_OPEN 2
#define IIC_BUSY 4
};
void iicattach __P((struct device *parent, struct device *self, void *aux));
int iicmatch __P((struct device *parent, void *match, void *aux));
/*
* 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 = ReadByte(IOMD_IOCR);
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) + (ReadByte(IOMD_IOCR) & 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);
}
struct cfattach iic_ca = {
sizeof(struct iic_softc), iicmatch, iicattach
};
struct cfdriver iic_cd = {
NULL, "iic", DV_DULL, 0
};
int
iicmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
int id;
/* Make sure we have an IOMD we understand */
id = ReadByte(IOMD_ID0) | (ReadByte(IOMD_ID1) << 8);
/* So far I only know about this IOMD */
switch (id) {
case RPC600_IOMD_ID:
case RC7500_IOC_ID:
return(1);
break;
default:
printf("iic: Unknown IOMD id=%04x", id);
break;
}
return(0);
}
int
iicprint(aux, name)
void *aux;
char *name;
{
struct iicbus_attach_args *ib = aux;
if (!name) {
if (ib->ib_addr)
printf(" addr 0x%02x", ib->ib_addr);
}
/* XXXX print flags */
return (QUIET);
}
int
iicsubmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
struct cfdata *cf = match;
struct iicbus_attach_args *ib = aux;
if (cf->cf_fstate == FSTATE_STAR)
panic("eekkk, I'm stuffed");
ib->ib_addr = cf->cf_loc[0];
if (ib->ib_addr == -1)
return(0);
return((*cf->cf_attach->ca_match)(parent, match, aux));
}
void
iicattach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct iicbus_attach_args iaa;
printf("\n");
while (config_found_sm(self, &iaa, iicprint, iicsubmatch));
}
int
iicopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct iic_softc *sc;
int unit = minor(dev);
if (unit >= iic_cd.cd_ndevs)
return(ENXIO);
sc = iic_cd.cd_devs[unit];
if (!sc) return(ENXIO);
if (sc->sc_flags & IIC_OPEN) return(EBUSY);
sc->sc_flags |= IIC_OPEN;
return(0);
}
int
iicclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
sc->sc_flags &= ~IIC_OPEN;
return(0);
}
int
iicread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
return(ENXIO);
}
int
iicwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct iic_softc *sc = iic_cd.cd_devs[unit];
return(ENXIO);
}
int
iicioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct iic_softc *sc = iic_cd.cd_devs[minor(dev)];
/*
switch (cmd) {
case IICIOC_CONTROL:
if (iiccontrol() != 0) {
return(EIO);
}
return(0);
}
*/
return(EINVAL);
}
/* End of iic.c */

View File

@ -0,0 +1,239 @@
/* $NetBSD: iic_asm.S,v 1.1 1996/04/19 19:49:04 mark 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.s
*
* Low level routines to with IIC devices
*
* Created : 13/10/94
*
* Based of kate/display/iic.s
*/
#include <machine/cpu.h>
#include <machine/iomd.h>
#define IIC_BITDELAY 10
sp .req r13
lr .req r14
pc .req r15
.text
.global _iic_set_state
_iic_set_state:
/*
* Parameters
* r0 - IIC data bit
* r1 - IIC clock bit
*/
/* Store temporary register */
/* stmfd sp!, {r4}*/
/*
* Mask the data and clock bits
* Since these routines are only called from iiccontrol.c this is not
* really needed
*/
and r0, r0, #0x00000001
and r1, r1, #0x00000001
/* Get address of IOMD control register */
mov r2, #(IOMD_BASE)
/* Get the current CPSR */
/* mrs r4, cpsr_all
orr r3, r4, #(I32_bit | F32_bit)
msr cpsr_all, r3
*/
IRQdisable
/* Get current value of control register */
ldrb r3, [r2, #(IOMD_IOCR - IOMD_BASE)]
/* Preserve non-IIC bits */
bic r3, r3, #0x00000003
orr r3, r3, #0x000000c0
/* Set the IIC clock and data bits */
orr r3, r3, r0
orr r3, r3, r1, lsl #1
/* Store the new value of control register */
strb r3, [r2, #(IOMD_IOCR - IOMD_BASE)]
/* Restore CPSR state */
/* msr cpsr_all, r4 */
IRQenable
/* Restore temporary register */
/* ldmfd sp!, {r4} */
/* Pause a bit */
mov r0, #(IIC_BITDELAY)
/* Exit via iic_delay routine */
b _iic_delay
.global _iic_set_state_and_ack
_iic_set_state_and_ack:
/*
* Parameters
* r0 - IIC data bit
* r1 - IIC clock bit
*/
/* Store temporary register */
/* stmfd sp!, {r4} */
/*
* Mask the data and clock bits
* Since these routines are only called from iiccontrol.c this is not
* really needed
*/
and r0, r0, #0x00000001
and r1, r1, #0x00000001
/* Get address of IOMD control register */
mov r2, #(IOMD_BASE)
/* Get the current CPSR */
/* mrs r4, cpsr_all
orr r3, r4, #(I32_bit | F32_bit)
msr cpsr_all, r3
*/
IRQdisable
/* Get current value of control register */
ldrb r3, [r2, #(IOMD_IOCR - IOMD_BASE)]
/* Preserve non-IIC bits */
bic r3, r3, #0x00000003
orr r3, r3, #0x000000c0
/* Set the IIC clock and data bits */
orr r3, r3, r0
orr r3, r3, r1, lsl #1
/* Store the new value of control register */
strb r3, [r2, #(IOMD_IOCR - IOMD_BASE)]
iic_set_state_and_ack_loop:
ldrb r3, [r2, #(IOMD_IOCR - IOMD_BASE)]
tst r3, #0x00000002
beq iic_set_state_and_ack_loop
/* Restore CPSR state */
/* msr cpsr_all, r4 */
IRQenable
/* Restore temporary register */
/* ldmfd sp!, {r4} */
/* Pause a bit */
mov r0, #(IIC_BITDELAY)
/* Exit via iic_delay routine */
b _iic_delay
.global _iic_delay
_iic_delay:
/*
* Parameters
* r0 - time to wait
*/
/* Load address of IOMD */
mov r2, #(IOMD_BASE)
/* Latch current value of timer 1 */
strb r2, [r2, #(IOMD_T0LATCH - IOMD_BASE)]
/* Get the latched value */
ldrb r1, [r2, #(IOMD_T0LOW - IOMD_BASE)]
/* Loop until timer reaches end value */
iic_delay_loop:
/* Latch the current value of timer1 */
strb r2, [r2, #(IOMD_T0LATCH - IOMD_BASE)]
/* Get the latched value */
ldrb r3, [r2, #(IOMD_T0LOW - IOMD_BASE)]
/* Loop until timer reached expected value */
teq r3, r1
movne r1, r3
beq iic_delay_loop
subs r0, r0, #0x00000001
bne iic_delay_loop
/* Exit */
mov pc, lr
/* End of iic_asm.S */

View File

@ -0,0 +1,384 @@
/* $NetBSD: rtc.c,v 1.1 1996/04/19 19:49:06 mark 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 Brini.
* 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
*
* rtc.c
*
* Routines to read and write the RTC and CMOS RAM
*
* Created : 13/10/94
*/
#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 <machine/iic.h>
#include <machine/rtc.h>
struct rtc_softc {
struct device sc_dev;
int sc_flags;
#define RTC_BROKEN 1
#define RTC_OPEN 2
};
void rtcattach __P((struct device *parent, struct device *self, void *aux));
int rtcmatch __P((struct device *parent, void *match, void *aux));
/* Read a byte from CMOS RAM */
int
cmos_read(location)
int location;
{
u_char buff;
/*
* This commented code dates from when I was translating CMOS address
* from the RISCOS addresses. Now all addresses are specifed as
* actual addresses in the CMOS RAM
*/
/*
if (location > 0xF0)
return(-1);
if (location < 0xC0)
buff = location + 0x40;
else
buff = location - 0xB0;
*/
buff = location;
if (iic_control(RTC_Write, &buff, 1))
return(-1);
if (iic_control(RTC_Read, &buff, 1))
return(-1);
return(buff);
}
/* Write a byte to CMOS RAM */
int
cmos_write(location, value)
int location;
int value;
{
u_char buff[2];
/*
* This commented code dates from when I was translating CMOS address
* from the RISCOS addresses. Now all addresses are specifed as
* actual addresses in the CMOS RAM
*/
/* if (location > 0xF0)
return(-1);
if (location < 0xC0)
buff = location + 0x40;
else
buff = location - 0xB0;
*/
buff[0] = location;
buff[1] = value;
if (iic_control(RTC_Write, buff, 2))
return(-1);
return(0);
}
/* Hex to BCD and BCD to hex conversion routines */
static inline int
hexdectodec(n)
u_char n;
{
return(((n >> 4) & 0x0F) * 10 + (n & 0x0F));
}
static inline int
dectohexdec(n)
u_char n;
{
return(((n / 10) << 4) + (n % 10));
}
/* Write the RTC data from an 8 byte buffer */
int
rtc_write(rtc)
rtc_t *rtc;
{
u_char buff[8];
buff[0] = 1;
buff[1] = dectohexdec(rtc->rtc_centi);
buff[2] = dectohexdec(rtc->rtc_sec);
buff[3] = dectohexdec(rtc->rtc_min);
buff[4] = dectohexdec(rtc->rtc_hour) & 0x3f;
buff[5] = dectohexdec(rtc->rtc_day);
buff[6] = dectohexdec(rtc->rtc_mon);
if (iic_control(RTC_Write, buff, 7))
return(0);
cmos_write(RTC_ADDR_YEAR, rtc->rtc_year);
cmos_write(RTC_ADDR_CENT, rtc->rtc_cen);
return(1);
}
/* Read the RTC data into a 8 byte buffer */
int
rtc_read(rtc)
rtc_t *rtc;
{
u_char buff[8];
int byte;
buff[0] = 0;
if (iic_control(RTC_Write, buff, 1))
return(0);
if (iic_control(RTC_Read, buff, 8))
return(0);
rtc->rtc_micro = 0;
rtc->rtc_centi = hexdectodec(buff[1] & 0xff);
rtc->rtc_sec = hexdectodec(buff[2] & 0x7f);
rtc->rtc_min = hexdectodec(buff[3] & 0x7f);
rtc->rtc_hour = hexdectodec(buff[4] & 0x3f);
/* If in 12 hour mode need to look at the AM/PM flag */
if (buff[4] & 0x80)
rtc->rtc_hour += (buff[4] & 0x40) ? 12 : 0;
rtc->rtc_day = hexdectodec(buff[5] & 0x3f);
rtc->rtc_mon = hexdectodec(buff[6] & 0x1f);
byte = cmos_read(RTC_ADDR_YEAR);
if (byte == -1)
return(0);
rtc->rtc_year = byte;
byte = cmos_read(RTC_ADDR_CENT);
if (byte == -1)
return(0);
rtc->rtc_cen = byte;
return(1);
}
struct cfattach rtc_ca = {
sizeof(struct rtc_softc), rtcmatch, rtcattach
};
struct cfdriver rtc_cd = {
NULL, "rtc", DV_DULL, 0
};
int
rtcmatch(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
/* struct iicbus_attach_args *ib = aux;*/
return(1);
}
void
rtcattach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct rtc_softc *sc = (struct rtc_softc *)self;
struct iicbus_attach_args *ib = aux;
u_char buff[1];
sc->sc_flags |= RTC_BROKEN;
if ((ib->ib_addr & IIC_PCF8583_MASK) == IIC_PCF8583_ADDR) {
printf(": PCF8583");
buff[0] = 0;
if (iic_control(RTC_Write, buff, 1))
return;
if (iic_control(RTC_Read, buff, 1))
return;
printf(" clock base ");
switch (buff[0] & 0x30) {
case 0x00:
printf("32.768KHz");
break;
case 0x10:
printf("50Hz");
break;
case 0x20:
printf("event");
break;
case 0x30:
printf("test mode");
break;
}
if (buff[0] & 0x80)
printf(" stopped");
if (buff[0] & 0x04)
printf(" alarm enabled");
sc->sc_flags &= ~RTC_BROKEN;
}
/*
* Initialise the time of day register.
* This is normally left to the filing system to do but not all
* filing systems call it e.g. cd9660
*/
inittodr(0);
printf("\n");
}
int
rtcopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct rtc_softc *sc;
int unit = minor(dev);
if (unit >= rtc_cd.cd_ndevs)
return(ENXIO);
sc = rtc_cd.cd_devs[unit];
if (!sc) return(ENXIO);
if (sc->sc_flags & RTC_OPEN) return(EBUSY);
sc->sc_flags |= RTC_OPEN;
return(0);
}
int
rtcclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
sc->sc_flags &= ~RTC_OPEN;
return(0);
}
int
rtcread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
return(ENXIO);
}
int
rtcwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
int unit = minor(dev);
struct rtc_softc *sc = rtc_cd.cd_devs[unit];
return(ENXIO);
}
int
rtcioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct rtc_softc *sc = rtc_cd.cd_devs[minor(dev)];
/* switch (cmd) {
case RTCIOC_READ:
return(0);
} */
return(EINVAL);
}
/* End of rtc.c */