[PATCH 3/3] qi-6410-i2c-bitbang.patch
Andy Green
andy at openmoko.com
Fri Oct 31 11:53:01 CET 2008
Signed-off-by: Andy Green <andy at openmoko.com>
---
include/i2c-bitbang-s3c6410.h | 3 +
src/cpu/s3c2442/i2c-bitbang-s3c24xx.c | 2 -
src/cpu/s3c6410/i2c-bitbang-s3c6410.c | 69 +++++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+), 1 deletions(-)
create mode 100644 include/i2c-bitbang-s3c6410.h
create mode 100644 src/cpu/s3c6410/i2c-bitbang-s3c6410.c
diff --git a/include/i2c-bitbang-s3c6410.h b/include/i2c-bitbang-s3c6410.h
new file mode 100644
index 0000000..b1c3ed5
--- /dev/null
+++ b/include/i2c-bitbang-s3c6410.h
@@ -0,0 +1,3 @@
+#include <i2c-bitbang.h>
+
+extern struct i2c_bitbang bb_s3c6410;
diff --git a/src/cpu/s3c2442/i2c-bitbang-s3c24xx.c b/src/cpu/s3c2442/i2c-bitbang-s3c24xx.c
index c2d46ed..e68b9b9 100644
--- a/src/cpu/s3c2442/i2c-bitbang-s3c24xx.c
+++ b/src/cpu/s3c2442/i2c-bitbang-s3c24xx.c
@@ -2,7 +2,7 @@
* (C) Copyright 2007 OpenMoko, Inc.
* Author: Andy Green <andy at openmoko.com>
*
- * s3c24xx-specific i2c shared by, eg, GTA02 and GTA03
+ * s3c24xx-specific i2c used by, eg, GTA02
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/cpu/s3c6410/i2c-bitbang-s3c6410.c b/src/cpu/s3c6410/i2c-bitbang-s3c6410.c
new file mode 100644
index 0000000..0d1236d
--- /dev/null
+++ b/src/cpu/s3c6410/i2c-bitbang-s3c6410.c
@@ -0,0 +1,69 @@
+/*
+ * (C) Copyright 2007 OpenMoko, Inc.
+ * Author: Andy Green <andy at openmoko.com>
+ *
+ * s3c6410-specific i2c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <qi.h>
+#include <i2c-bitbang.h>
+#include <s3c6410.h>
+
+static char i2c_read_sda_s3c6410(void)
+{
+ return !!(__REG(GPBDAT) & (1 << 6));
+}
+
+static void i2c_set_s3c6410(char clock, char data)
+{
+ if (clock) /* SCL <- input */
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4)));
+ else { /* SCL <- output 0 */
+ __REG(GPBDAT) = (__REG(GPBDAT) & ~(1 << 5));
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4))) | (1 << (5 * 4));
+ }
+ if (data) /* SDA <- input */
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4)));
+ else { /* SDA <- output 0 */
+ __REG(GPBDAT) = (__REG(GPBDAT) & ~(1 << 6));
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4))) | (1 << (6 * 4));
+ }
+}
+
+static void i2c_close_s3c6410(void)
+{
+ /* set back to hardware I2C ready for Linux */
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4))) | (2 << (5 * 4));
+ __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4))) | (2 << (6 * 4));
+}
+
+static void i2c_spin_s3c6410(void)
+{
+ int n;
+
+ for (n = 0; n < 1000; n++)
+ __REG(GPBDAT) = __REG(GPBDAT);
+}
+
+struct i2c_bitbang bb_s3c6410 = {
+ .read_sda = i2c_read_sda_s3c6410,
+ .set = i2c_set_s3c6410,
+ .spin = i2c_spin_s3c6410,
+ .close = i2c_close_s3c6410,
+};
More information about the openmoko-kernel
mailing list