Merge tag 'for-linus-20180929' of git://git.kernel.dk/linux-block
[linux-2.6/btrfs-unstable.git] / drivers / i2c / busses / i2c-acorn.c
blobf4a5ae69bf6a48775f9bb58c488eeb158174a797
1 /*
2 * ARM IOC/IOMD i2c driver.
4 * Copyright (C) 2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * On Acorn machines, the following i2c devices are on the bus:
11 * - PCF8583 real time clock & static RAM
13 #include <linux/module.h>
14 #include <linux/i2c.h>
15 #include <linux/i2c-algo-bit.h>
16 #include <linux/io.h>
18 #include <mach/hardware.h>
19 #include <asm/hardware/ioc.h>
21 #define FORCE_ONES 0xdc
22 #define SCL 0x02
23 #define SDA 0x01
26 * We must preserve all non-i2c output bits in IOC_CONTROL.
27 * Note also that we need to preserve the value of SCL and
28 * SDA outputs as well (which may be different from the
29 * values read back from IOC_CONTROL).
31 static u_int force_ones;
33 static void ioc_setscl(void *data, int state)
35 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
36 u_int ones = force_ones;
38 if (state)
39 ones |= SCL;
40 else
41 ones &= ~SCL;
43 force_ones = ones;
45 ioc_writeb(ioc_control | ones, IOC_CONTROL);
48 static void ioc_setsda(void *data, int state)
50 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
51 u_int ones = force_ones;
53 if (state)
54 ones |= SDA;
55 else
56 ones &= ~SDA;
58 force_ones = ones;
60 ioc_writeb(ioc_control | ones, IOC_CONTROL);
63 static int ioc_getscl(void *data)
65 return (ioc_readb(IOC_CONTROL) & SCL) != 0;
68 static int ioc_getsda(void *data)
70 return (ioc_readb(IOC_CONTROL) & SDA) != 0;
73 static struct i2c_algo_bit_data ioc_data = {
74 .setsda = ioc_setsda,
75 .setscl = ioc_setscl,
76 .getsda = ioc_getsda,
77 .getscl = ioc_getscl,
78 .udelay = 80,
79 .timeout = HZ,
82 static struct i2c_adapter ioc_ops = {
83 .nr = 0,
84 .algo_data = &ioc_data,
87 static int __init i2c_ioc_init(void)
89 force_ones = FORCE_ONES | SCL | SDA;
91 return i2c_bit_add_numbered_bus(&ioc_ops);
94 module_init(i2c_ioc_init);
96 MODULE_AUTHOR("Russell King <linux@armlinux.org.uk>");
97 MODULE_DESCRIPTION("ARM IOC/IOMD i2c driver");
98 MODULE_LICENSE("GPL v2");