1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
28d91cbadSRussell King /*
3f89813ecSWolfram Sang * ARM IOC/IOMD i2c driver.
48d91cbadSRussell King *
58d91cbadSRussell King * Copyright (C) 2000 Russell King
68d91cbadSRussell King *
78d91cbadSRussell King * On Acorn machines, the following i2c devices are on the bus:
88d91cbadSRussell King * - PCF8583 real time clock & static RAM
98d91cbadSRussell King */
1066769330SPaul Gortmaker #include <linux/module.h>
118d91cbadSRussell King #include <linux/i2c.h>
128d91cbadSRussell King #include <linux/i2c-algo-bit.h>
1399730225SRussell King #include <linux/io.h>
148d91cbadSRussell King
15a09e64fbSRussell King #include <mach/hardware.h>
168d91cbadSRussell King #include <asm/hardware/ioc.h>
178d91cbadSRussell King
188d91cbadSRussell King #define FORCE_ONES 0xdc
198d91cbadSRussell King #define SCL 0x02
208d91cbadSRussell King #define SDA 0x01
218d91cbadSRussell King
228d91cbadSRussell King /*
238d91cbadSRussell King * We must preserve all non-i2c output bits in IOC_CONTROL.
248d91cbadSRussell King * Note also that we need to preserve the value of SCL and
258d91cbadSRussell King * SDA outputs as well (which may be different from the
268d91cbadSRussell King * values read back from IOC_CONTROL).
278d91cbadSRussell King */
288d91cbadSRussell King static u_int force_ones;
298d91cbadSRussell King
ioc_setscl(void * data,int state)308d91cbadSRussell King static void ioc_setscl(void *data, int state)
318d91cbadSRussell King {
328d91cbadSRussell King u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
338d91cbadSRussell King u_int ones = force_ones;
348d91cbadSRussell King
358d91cbadSRussell King if (state)
368d91cbadSRussell King ones |= SCL;
378d91cbadSRussell King else
388d91cbadSRussell King ones &= ~SCL;
398d91cbadSRussell King
408d91cbadSRussell King force_ones = ones;
418d91cbadSRussell King
428d91cbadSRussell King ioc_writeb(ioc_control | ones, IOC_CONTROL);
438d91cbadSRussell King }
448d91cbadSRussell King
ioc_setsda(void * data,int state)458d91cbadSRussell King static void ioc_setsda(void *data, int state)
468d91cbadSRussell King {
478d91cbadSRussell King u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
488d91cbadSRussell King u_int ones = force_ones;
498d91cbadSRussell King
508d91cbadSRussell King if (state)
518d91cbadSRussell King ones |= SDA;
528d91cbadSRussell King else
538d91cbadSRussell King ones &= ~SDA;
548d91cbadSRussell King
558d91cbadSRussell King force_ones = ones;
568d91cbadSRussell King
578d91cbadSRussell King ioc_writeb(ioc_control | ones, IOC_CONTROL);
588d91cbadSRussell King }
598d91cbadSRussell King
ioc_getscl(void * data)608d91cbadSRussell King static int ioc_getscl(void *data)
618d91cbadSRussell King {
628d91cbadSRussell King return (ioc_readb(IOC_CONTROL) & SCL) != 0;
638d91cbadSRussell King }
648d91cbadSRussell King
ioc_getsda(void * data)658d91cbadSRussell King static int ioc_getsda(void *data)
668d91cbadSRussell King {
678d91cbadSRussell King return (ioc_readb(IOC_CONTROL) & SDA) != 0;
688d91cbadSRussell King }
698d91cbadSRussell King
708d91cbadSRussell King static struct i2c_algo_bit_data ioc_data = {
718d91cbadSRussell King .setsda = ioc_setsda,
728d91cbadSRussell King .setscl = ioc_setscl,
738d91cbadSRussell King .getsda = ioc_getsda,
748d91cbadSRussell King .getscl = ioc_getscl,
758d91cbadSRussell King .udelay = 80,
76082a4cf8SJean Delvare .timeout = HZ,
778d91cbadSRussell King };
788d91cbadSRussell King
798d91cbadSRussell King static struct i2c_adapter ioc_ops = {
80531660efSRussell King .nr = 0,
81ca21f851SRussell King .name = "ioc",
828d91cbadSRussell King .algo_data = &ioc_data,
838d91cbadSRussell King };
848d91cbadSRussell King
i2c_ioc_init(void)858d91cbadSRussell King static int __init i2c_ioc_init(void)
868d91cbadSRussell King {
878d91cbadSRussell King force_ones = FORCE_ONES | SCL | SDA;
888d91cbadSRussell King
89531660efSRussell King return i2c_bit_add_numbered_bus(&ioc_ops);
908d91cbadSRussell King }
918d91cbadSRussell King
922a9915c8SAl Viro module_init(i2c_ioc_init);
93e199c285SArnd Bergmann
94e199c285SArnd Bergmann MODULE_AUTHOR("Russell King <linux@armlinux.org.uk>");
95e199c285SArnd Bergmann MODULE_DESCRIPTION("ARM IOC/IOMD i2c driver");
96e199c285SArnd Bergmann MODULE_LICENSE("GPL v2");
97