2007-03-05 04:40:50 +08:00
|
|
|
/*
|
2018-01-16 01:41:39 +08:00
|
|
|
* ARM IOC/IOMD i2c driver.
|
2007-03-05 04:40:50 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Russell King
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* On Acorn machines, the following i2c devices are on the bus:
|
|
|
|
* - PCF8583 real time clock & static RAM
|
|
|
|
*/
|
2014-01-22 05:22:33 +08:00
|
|
|
#include <linux/module.h>
|
2007-03-05 04:40:50 +08:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/i2c-algo-bit.h>
|
2009-03-25 18:21:35 +08:00
|
|
|
#include <linux/io.h>
|
2007-03-05 04:40:50 +08:00
|
|
|
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/hardware.h>
|
2007-03-05 04:40:50 +08:00
|
|
|
#include <asm/hardware/ioc.h>
|
|
|
|
|
|
|
|
#define FORCE_ONES 0xdc
|
|
|
|
#define SCL 0x02
|
|
|
|
#define SDA 0x01
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must preserve all non-i2c output bits in IOC_CONTROL.
|
|
|
|
* Note also that we need to preserve the value of SCL and
|
|
|
|
* SDA outputs as well (which may be different from the
|
|
|
|
* values read back from IOC_CONTROL).
|
|
|
|
*/
|
|
|
|
static u_int force_ones;
|
|
|
|
|
|
|
|
static void ioc_setscl(void *data, int state)
|
|
|
|
{
|
|
|
|
u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
|
|
|
|
u_int ones = force_ones;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
ones |= SCL;
|
|
|
|
else
|
|
|
|
ones &= ~SCL;
|
|
|
|
|
|
|
|
force_ones = ones;
|
|
|
|
|
|
|
|
ioc_writeb(ioc_control | ones, IOC_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ioc_setsda(void *data, int state)
|
|
|
|
{
|
|
|
|
u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
|
|
|
|
u_int ones = force_ones;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
ones |= SDA;
|
|
|
|
else
|
|
|
|
ones &= ~SDA;
|
|
|
|
|
|
|
|
force_ones = ones;
|
|
|
|
|
|
|
|
ioc_writeb(ioc_control | ones, IOC_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ioc_getscl(void *data)
|
|
|
|
{
|
|
|
|
return (ioc_readb(IOC_CONTROL) & SCL) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ioc_getsda(void *data)
|
|
|
|
{
|
|
|
|
return (ioc_readb(IOC_CONTROL) & SDA) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_algo_bit_data ioc_data = {
|
|
|
|
.setsda = ioc_setsda,
|
|
|
|
.setscl = ioc_setscl,
|
|
|
|
.getsda = ioc_getsda,
|
|
|
|
.getscl = ioc_getscl,
|
|
|
|
.udelay = 80,
|
2009-02-25 02:19:49 +08:00
|
|
|
.timeout = HZ,
|
2007-03-05 04:40:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_adapter ioc_ops = {
|
2009-02-25 02:19:50 +08:00
|
|
|
.nr = 0,
|
2007-03-05 04:40:50 +08:00
|
|
|
.algo_data = &ioc_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init i2c_ioc_init(void)
|
|
|
|
{
|
|
|
|
force_ones = FORCE_ONES | SCL | SDA;
|
|
|
|
|
2009-02-25 02:19:50 +08:00
|
|
|
return i2c_bit_add_numbered_bus(&ioc_ops);
|
2007-03-05 04:40:50 +08:00
|
|
|
}
|
|
|
|
|
2007-07-16 04:37:16 +08:00
|
|
|
module_init(i2c_ioc_init);
|
2018-01-16 04:28:39 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <linux@armlinux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("ARM IOC/IOMD i2c driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|