summaryrefslogtreecommitdiffstats
path: root/drivers/acorn/char
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2000-02-23 00:40:54 +0000
committerRalf Baechle <ralf@linux-mips.org>2000-02-23 00:40:54 +0000
commit529c593ece216e4aaffd36bd940cb94f1fa63129 (patch)
tree78f1c0b805f5656aa7b0417a043c5346f700a2cf /drivers/acorn/char
parent0bd079751d25808d1972baee5c4eaa1db2227257 (diff)
Merge with 2.3.43. I did ignore all modifications to the qlogicisp.c
driver due to the Origin A64 hacks.
Diffstat (limited to 'drivers/acorn/char')
-rw-r--r--drivers/acorn/char/Makefile14
-rw-r--r--drivers/acorn/char/i2c.c203
-rw-r--r--drivers/acorn/char/pcf8583.c232
-rw-r--r--drivers/acorn/char/pcf8583.h32
4 files changed, 473 insertions, 8 deletions
diff --git a/drivers/acorn/char/Makefile b/drivers/acorn/char/Makefile
index bcbb4ba70..2d08a90cb 100644
--- a/drivers/acorn/char/Makefile
+++ b/drivers/acorn/char/Makefile
@@ -11,19 +11,17 @@
O_TARGET := acorn-char.o
M_OBJS :=
-O_OBJS :=
+O_OBJS := i2c.o pcf8583.o
O_OBJS_arc := keyb_arc.o
O_OBJS_a5k := keyb_arc.o
O_OBJS_rpc := keyb_ps2.o
-ifeq ($(MACHINE),rpc)
- ifeq ($(CONFIG_BUSMOUSE),y)
- OX_OBJS += mouse_rpc.o
- else
- ifeq ($(CONFIG_BUSMOUSE),m)
- MX_OBJS += mouse_rpc.o
- endif
+ifeq ($(CONFIG_RPCMOUSE),y)
+ OX_OBJS += mouse_rpc.o
+else
+ ifeq ($(CONFIG_RPCSMOUSE),m)
+ MX_OBJS += mouse_rpc.o
endif
endif
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
new file mode 100644
index 000000000..83ff74d1c
--- /dev/null
+++ b/drivers/acorn/char/i2c.c
@@ -0,0 +1,203 @@
+/*
+ * linux/drivers/acorn/char/i2c.c
+ *
+ * Copyright (C) 2000 Russell King
+ *
+ * ARM IOC/IOMD i2c driver.
+ *
+ * On Acorn machines, the following i2c devices are on the bus:
+ * - PCF8583 real time clock & static RAM
+ */
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/ioc.h>
+#include <asm/system.h>
+
+#include "pcf8583.h"
+
+extern unsigned long
+mktime(unsigned int year, unsigned int mon, unsigned int day,
+ unsigned int hour, unsigned int min, unsigned int sec);
+extern int (*set_rtc)(void);
+
+static struct i2c_client *rtc_client;
+
+static inline int rtc_command(int cmd, void *data)
+{
+ int ret = -EIO;
+
+ if (rtc_client)
+ ret = rtc_client->driver->command(rtc_client, cmd, data);
+
+ return ret;
+}
+
+/*
+ * Read the current RTC time and date, and update xtime.
+ */
+static void get_rtc_time(void)
+{
+ unsigned char ctrl;
+ unsigned char year;
+ struct rtc_tm rtctm;
+ struct mem rtcmem = { 0xc0, 1, &year };
+
+ /*
+ * Ensure that the RTC is running.
+ */
+ rtc_command(RTC_GETCTRL, &ctrl);
+ if (ctrl & 0xc0) {
+ unsigned char new_ctrl;
+
+ new_ctrl = ctrl & ~0xc0;
+
+ printk("RTC: resetting control %02X -> %02X\n",
+ ctrl, new_ctrl);
+
+ rtc_command(RTC_SETCTRL, &new_ctrl);
+ }
+
+ /*
+ * Acorn machines store the year in
+ * the static RAM at location 192.
+ */
+ if (rtc_command(MEM_READ, &rtcmem))
+ return;
+
+ if (rtc_command(RTC_GETDATETIME, &rtctm))
+ return;
+
+ if (year < 70)
+ year += 100;
+
+ xtime.tv_usec = rtctm.cs * 10000;
+ xtime.tv_sec = mktime(1900 + year, rtctm.mon, rtctm.mday,
+ rtctm.hours, rtctm.mins, rtctm.secs);
+}
+
+/*
+ * Set the RTC time only. Note that
+ * we do not touch the date.
+ */
+static int set_rtc_time(void)
+{
+ struct rtc_tm new_rtctm, old_rtctm;
+ unsigned long nowtime = xtime.tv_sec;
+
+ if (rtc_command(RTC_GETDATETIME, &old_rtctm))
+ return 0;
+
+ new_rtctm.cs = xtime.tv_usec / 10000;
+ new_rtctm.secs = nowtime % 60; nowtime /= 60;
+ new_rtctm.mins = nowtime % 60; nowtime /= 60;
+ new_rtctm.hours = nowtime % 24;
+
+ /*
+ * avoid writing when we're going to change the day
+ * of the month. We will retry in the next minute.
+ * This basically means that if the RTC must not drift
+ * by more than 1 minute in 11 minutes.
+ *
+ * [ rtc: 1/1/2000 23:58:00, real 2/1/2000 00:01:00,
+ * rtc gets set to 1/1/2000 00:01:00 ]
+ */
+ if ((old_rtctm.hours == 23 && old_rtctm.mins == 59) ||
+ (new_rtctm.hours == 23 && new_rtctm.mins == 59))
+ return 1;
+
+ return rtc_command(RTC_SETTIME, &new_rtctm);
+}
+
+
+#define FORCE_ONES 0xdc
+#define SCL 0x02
+#define SDA 0x01
+
+static int ioc_control;
+
+static void ioc_setscl(void *data, int state)
+{
+ if (state)
+ ioc_control |= SCL;
+ else
+ ioc_control &= ~SCL;
+ outb(ioc_control, IOC_CONTROL);
+}
+
+static void ioc_setsda(void *data, int state)
+{
+ if (state)
+ ioc_control |= SDA;
+ else
+ ioc_control &= ~SDA;
+ outb(ioc_control, IOC_CONTROL);
+}
+
+static int ioc_getscl(void *data)
+{
+ return (inb(IOC_CONTROL) & SCL) != 0;
+}
+
+static int ioc_getsda(void *data)
+{
+ return (inb(IOC_CONTROL) & SDA) != 0;
+}
+
+static struct i2c_algo_bit_data ioc_data = {
+ NULL,
+ ioc_setsda,
+ ioc_setscl,
+ ioc_getsda,
+ ioc_getscl,
+ 80, 80, 100
+};
+
+static int ioc_client_reg(struct i2c_client *client)
+{
+ if (client->id == I2C_DRIVERID_PCF8583 &&
+ client->addr == 0x50) {
+ rtc_client = client;
+ get_rtc_time();
+ set_rtc = set_rtc_time;
+ }
+
+ return 0;
+}
+
+static int ioc_client_unreg(struct i2c_client *client)
+{
+ if (client == rtc_client) {
+ set_rtc = NULL;
+ rtc_client = NULL;
+ }
+
+ return 0;
+}
+
+static struct i2c_adapter ioc_ops = {
+ "IOC/IOMD",
+ I2C_HW_B_IOC,
+ NULL,
+ &ioc_data,
+ NULL,
+ NULL,
+ ioc_client_reg,
+ ioc_client_unreg
+};
+
+static int __init i2c_ioc_init(void)
+{
+ ioc_control = inb(IOC_CONTROL) | FORCE_ONES;
+
+ ioc_setscl(NULL, 1);
+ ioc_setsda(NULL, 1);
+
+ return i2c_bit_add_bus(&ioc_ops);
+}
+
+__initcall(i2c_ioc_init);
diff --git a/drivers/acorn/char/pcf8583.c b/drivers/acorn/char/pcf8583.c
new file mode 100644
index 000000000..e16fe2f06
--- /dev/null
+++ b/drivers/acorn/char/pcf8583.c
@@ -0,0 +1,232 @@
+/*
+ * linux/drivers/i2c/pcf8583.c
+ *
+ * Copyright (C) 2000 Russell King
+ *
+ * Driver for PCF8583 RTC & RAM chip
+ */
+
+#include <linux/i2c.h>
+#include <linux/malloc.h>
+#include <linux/string.h>
+#include <linux/mc146818rtc.h>
+#include <linux/init.h>
+
+#include "pcf8583.h"
+
+static struct i2c_driver pcf8583_driver;
+
+static unsigned short ignore[] = { I2C_CLIENT_END };
+static unsigned short normal_addr[] = { 0x50, 0x51, I2C_CLIENT_END };
+
+static struct i2c_client_address_data addr_data = {
+ force: ignore,
+ ignore: ignore,
+ ignore_range: ignore,
+ normal_i2c: ignore,
+ normal_i2c_range: normal_addr,
+ probe: ignore,
+ probe_range: ignore
+};
+
+#define DAT(x) ((unsigned int)(x->data))
+
+static int
+pcf8583_attach(struct i2c_adapter *adap, int addr, unsigned short flags,
+ int kind)
+{
+ struct i2c_client *c;
+ unsigned char buf[1], ad[1] = { 0 };
+ struct i2c_msg msgs[2] = {
+ { addr, 0, 1, ad },
+ { addr, I2C_M_RD, 1, buf }
+ };
+
+ c = kmalloc(sizeof(*c), GFP_KERNEL);
+ if (!c)
+ return -ENOMEM;
+
+ strcpy(c->name, "PCF8583");
+ c->id = pcf8583_driver.id;
+ c->flags = 0;
+ c->addr = addr;
+ c->adapter = adap;
+ c->driver = &pcf8583_driver;
+ c->data = NULL;
+
+ if (i2c_transfer(c->adapter, msgs, 2) == 2)
+ DAT(c) = buf[0];
+
+ return i2c_attach_client(c);
+}
+
+static int
+pcf8583_probe(struct i2c_adapter *adap)
+{
+ return i2c_probe(adap, &addr_data, pcf8583_attach);
+}
+
+static int
+pcf8583_detach(struct i2c_client *client)
+{
+ i2c_detach_client(client);
+ return 0;
+}
+
+static int
+pcf8583_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
+{
+ unsigned char buf[8], addr[1] = { 1 };
+ struct i2c_msg msgs[2] = {
+ { client->addr, 0, 1, addr },
+ { client->addr, I2C_M_RD, 6, buf }
+ };
+ int ret = -EIO;
+
+ if (i2c_transfer(client->adapter, msgs, 2) == 2) {
+ dt->year_off = buf[4] >> 6;
+ dt->wday = buf[5] >> 5;
+
+ buf[4] &= 0x3f;
+ buf[5] &= 0x1f;
+
+ dt->cs = BCD_TO_BIN(buf[0]);
+ dt->secs = BCD_TO_BIN(buf[1]);
+ dt->mins = BCD_TO_BIN(buf[2]);
+ dt->hours = BCD_TO_BIN(buf[3]);
+ dt->mday = BCD_TO_BIN(buf[4]);
+ dt->mon = BCD_TO_BIN(buf[5]);
+
+ ret = 0;
+ }
+
+ return ret;
+}
+
+static int
+pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
+{
+ unsigned char buf[8];
+ int ret, len = 6;
+
+ buf[0] = 0;
+ buf[1] = DAT(client) | 0x80;
+ buf[2] = BIN_TO_BCD(dt->cs);
+ buf[3] = BIN_TO_BCD(dt->secs);
+ buf[4] = BIN_TO_BCD(dt->mins);
+ buf[5] = BIN_TO_BCD(dt->hours);
+
+ if (datetoo) {
+ len = 8;
+ buf[6] = BIN_TO_BCD(dt->mday) | (dt->year_off << 6);
+ buf[7] = BIN_TO_BCD(dt->mon) | (dt->wday << 5);
+ }
+
+ ret = i2c_master_send(client, (char *)buf, len);
+
+ buf[1] = DAT(client);
+ i2c_master_send(client, (char *)buf, 2);
+
+ return ret;
+}
+
+static int
+pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl)
+{
+ *ctrl = DAT(client);
+ return 0;
+}
+
+static int
+pcf8583_set_ctrl(struct i2c_client *client, unsigned char *ctrl)
+{
+ unsigned char buf[2];
+
+ buf[0] = 0;
+ buf[1] = *ctrl;
+ DAT(client) = *ctrl;
+
+ return i2c_master_send(client, (char *)buf, 2);
+}
+
+static int
+pcf8583_read_mem(struct i2c_client *client, struct mem *mem)
+{
+ unsigned char addr[1];
+ struct i2c_msg msgs[2] = {
+ { client->addr, 0, 1, addr },
+ { client->addr, I2C_M_RD, 0, mem->data }
+ };
+
+ if (mem->loc < 8)
+ return -EINVAL;
+
+ addr[0] = mem->loc;
+ msgs[1].len = mem->nr;
+
+ return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
+}
+
+static int
+pcf8583_write_mem(struct i2c_client *client, struct mem *mem)
+{
+ unsigned char addr[1];
+ struct i2c_msg msgs[2] = {
+ { client->addr, 0, 1, addr },
+ { client->addr, 0, 0, mem->data }
+ };
+
+ if (mem->loc < 8)
+ return -EINVAL;
+
+ addr[0] = mem->loc;
+ msgs[1].len = mem->nr;
+
+ return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
+}
+
+static int
+pcf8583_command(struct i2c_client *client, unsigned int cmd, void *arg)
+{
+ switch (cmd) {
+ case RTC_GETDATETIME:
+ return pcf8583_get_datetime(client, arg);
+
+ case RTC_SETTIME:
+ return pcf8583_set_datetime(client, arg, 0);
+
+ case RTC_SETDATETIME:
+ return pcf8583_set_datetime(client, arg, 1);
+
+ case RTC_GETCTRL:
+ return pcf8583_get_ctrl(client, arg);
+
+ case RTC_SETCTRL:
+ return pcf8583_set_ctrl(client, arg);
+
+ case MEM_READ:
+ return pcf8583_read_mem(client, arg);
+
+ case MEM_WRITE:
+ return pcf8583_write_mem(client, arg);
+
+ default:
+ return -EINVAL;
+ }
+}
+
+static struct i2c_driver pcf8583_driver = {
+ "PCF8583",
+ I2C_DRIVERID_PCF8583,
+ I2C_DF_NOTIFY,
+ pcf8583_probe,
+ pcf8583_detach,
+ pcf8583_command
+};
+
+static __init int pcf8583_init(void)
+{
+ return i2c_add_driver(&pcf8583_driver);
+}
+
+__initcall(pcf8583_init);
diff --git a/drivers/acorn/char/pcf8583.h b/drivers/acorn/char/pcf8583.h
new file mode 100644
index 000000000..9d52f9133
--- /dev/null
+++ b/drivers/acorn/char/pcf8583.h
@@ -0,0 +1,32 @@
+struct rtc_tm {
+ unsigned char cs;
+ unsigned char secs;
+ unsigned char mins;
+ unsigned char hours;
+ unsigned char mday;
+ unsigned char mon;
+ unsigned char year_off;
+ unsigned char wday;
+};
+
+struct mem {
+ unsigned int loc;
+ unsigned int nr;
+ unsigned char *data;
+};
+
+#define RTC_GETDATETIME 0
+#define RTC_SETTIME 1
+#define RTC_SETDATETIME 2
+#define RTC_GETCTRL 3
+#define RTC_SETCTRL 4
+#define MEM_READ 5
+#define MEM_WRITE 6
+
+#define CTRL_STOP 0x80
+#define CTRL_HOLD 0x40
+#define CTRL_32KHZ 0x00
+#define CTRL_MASK 0x08
+#define CTRL_ALARMEN 0x04
+#define CTRL_ALARM 0x02
+#define CTRL_TIMER 0x01