summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2006-09-29 10:54:01 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2006-09-29 10:54:01 +0000
commit8e1e6f9b2939abd617b84c515a1018701a2cf082 (patch)
tree77ad5bf57a5a14c378869992b0bd3aa2f2e8ab3f
parent3496689c8e1ff48453cb9f46f67b7e36ab9955fd (diff)
downloadrockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.zip
rockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.tar.gz
rockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.tar.bz2
rockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.tar.xz
add the I2C driver for the Gigabeat
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11090 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c121
2 files changed, 122 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 423fe0e..ffc2387 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -302,6 +302,7 @@ target/arm/gigabeat/meg-fx/usb-meg-fx.c
target/arm/gigabeat/meg-fx/lcd-meg-fx.c
target/arm/gigabeat/meg-fx/sc606-meg-fx.c
target/arm/gigabeat/meg-fx/adc-meg-fx.c
+target/arm/gigabeat/meg-fx/i2c-meg-fx.c
#endif
#endif
diff --git a/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c
new file mode 100644
index 0000000..c0e9fb4
--- /dev/null
+++ b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c
@@ -0,0 +1,121 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "cpu.h"
+#include <stdbool.h>
+#include "kernel.h"
+#include "system.h"
+#include "hwcompat.h"
+#include "logf.h"
+#include "debug.h"
+#include "string.h"
+#include "generic_i2c.h"
+
+void i2c_sda_output(void)
+{
+ GPECON |= (1 << 30);
+}
+
+void i2c_sda_input(void)
+{
+ GPECON &= ~(3 << 30);
+}
+
+void i2c_sda_lo(void)
+{
+ GPEDAT &= ~(1 << 15);
+}
+
+void i2c_sda_hi(void)
+{
+ GPEDAT |= (1 << 15);
+}
+
+int i2c_sda(void)
+{
+ return GPEDAT & (1 << 15);
+}
+
+void i2c_scl_output(void)
+{
+ GPECON |= (1 << 28);
+}
+
+void i2c_scl_input(void)
+{
+ GPECON &= ~(3 << 28);
+}
+
+void i2c_scl_lo(void)
+{
+ GPEDAT &= ~(1 << 14);
+}
+
+int i2c_scl(void)
+{
+ return GPEDAT & (1 << 14);
+}
+
+void i2c_scl_hi(void)
+{
+ i2c_scl_input();
+ while(!i2c_scl());
+ GPEDAT |= (1 << 14);
+ i2c_scl_output();
+}
+
+void i2c_delay(void)
+{
+ do { int _x; for(_x=0;_x<2000;_x++);} while (0);
+}
+
+struct i2c_interface s3c2440_i2c = {
+ 0x34, /* Address */
+
+ /* Bit-banged interface definitions */
+ i2c_scl_hi, /* Drive SCL high, might sleep on clk stretch */
+ i2c_scl_lo, /* Drive SCL low */
+ i2c_sda_hi, /* Drive SDA high */
+ i2c_sda_lo, /* Drive SDA low */
+ i2c_sda_input, /* Set SDA as input */
+ i2c_sda_output, /* Set SDA as output */
+ i2c_scl_input, /* Set SCL as input */
+ i2c_scl_output, /* Set SCL as output */
+ i2c_scl, /* Read SCL, returns 0 or nonzero */
+ i2c_sda, /* Read SDA, returns 0 or nonzero */
+
+ i2c_delay, /* START SDA hold time (tHD:SDA) */
+ i2c_delay, /* SDA hold time (tHD:DAT) */
+ i2c_delay, /* SDA setup time (tSU:DAT) */
+ i2c_delay, /* STOP setup time (tSU:STO) */
+ i2c_delay, /* Rep. START setup time (tSU:STA) */
+ i2c_delay, /* SCL high period (tHIGH) */
+};
+
+void i2c_init(void)
+{
+ /* Set GPE15 (SDA) and GPE14 (SCL) to 1 */
+ GPECON = (GPECON & ~(0xF<<28)) | 5<<28;
+ i2c_add_node(&s3c2440_i2c);
+}
+
+void i2c_send(int bus_address, int reg_address, const unsigned char buf)
+{
+ i2c_write_data(bus_address, reg_address, &buf, 1);
+}