All of lore.kernel.org
 help / color / mirror / Atom feed
From: Piotr Wilczek <p.wilczek@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 5/9] drivers:i2c: Add support for multi I2C
Date: Mon, 22 Oct 2012 09:21:19 +0200	[thread overview]
Message-ID: <1350890483-26579-6-git-send-email-p.wilczek@samsung.com> (raw)
In-Reply-To: <1350890483-26579-1-git-send-email-p.wilczek@samsung.com>

This patch enables use of SOFT I2C and HARD I2C simultaneously.

Signed-off-by: Gwuieon Jin <ge.jin@samsung.com>
Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
CC: Minkyu Kang <mk7.kang@samsung.com>
---
Changes in v2:
	- new patch

 drivers/i2c/Makefile    |    1 +
 drivers/i2c/multi_i2c.c |  124 +++++++++++++++++++++++++++++++++++++++++++++++
 include/multi_i2c.h     |   62 +++++++++++++++++++++++
 3 files changed, 187 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/multi_i2c.c
 create mode 100644 include/multi_i2c.h

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 5dbdbe3..5c82130 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -46,6 +46,7 @@ COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
 COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o
 COBJS-$(CONFIG_SH_I2C) += sh_i2c.o
 COBJS-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o
+COBJS-$(CONFIG_MULTI_I2C) += multi_i2c.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/i2c/multi_i2c.c b/drivers/i2c/multi_i2c.c
new file mode 100644
index 0000000..7751c7b
--- /dev/null
+++ b/drivers/i2c/multi_i2c.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Gwuieon Jin <ge.jin@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 <common.h>
+#include <asm/errno.h>
+#include <multi_i2c.h>
+
+
+static struct multi_i2c_dev multi_i2c_devs[MULTI_I2C_MAX];
+static struct multi_i2c_dev *active_dev;
+static int count_devices;
+
+static struct multi_i2c_dev *multi_i2c_get_by_bus(const unsigned int bus)
+{
+	/* HARD I2C MAX NUM */
+	if (bus > CONFIG_MAX_I2C_NUM)
+		return &multi_i2c_devs[MULTI_I2C_SOFT];
+
+	return &multi_i2c_devs[MULTI_I2C_HARD];
+}
+
+static void multi_i2c_register(struct i2c_ops *ops, u32 flags)
+{
+	int index;
+
+	if (flags & SOFT_I2C_DEV)
+		index = MULTI_I2C_SOFT;
+	else
+		index = MULTI_I2C_HARD;
+
+	multi_i2c_devs[index].ops = ops;
+	active_dev = &multi_i2c_devs[index];
+	count_devices++;
+}
+
+void i2c_init(int speed, int slaveadd)
+{
+	int i;
+
+	count_devices = 0;
+
+#ifdef CONFIG_SOFT_I2C
+	multi_i2c_register(&soft_i2c_ops, SOFT_I2C_DEV);
+#endif
+#ifdef CONFIG_DRIVER_S3C24X0_I2C
+	multi_i2c_register(&s3c24x0_i2c_ops, HARD_I2C_DEV);
+#endif
+	for (i = 0; i < count_devices; i++) {
+		if (multi_i2c_devs[i].ops->init)
+			multi_i2c_devs[i].ops->init(speed, slaveadd);
+	}
+}
+
+int i2c_probe(uchar chip)
+{
+	return active_dev->ops->probe(chip);
+}
+
+int i2c_read(uchar chip, uint addr, int alen,
+		uchar *buffer, int len)
+{
+	return active_dev->ops->read(chip, addr, alen,
+			buffer, len);
+}
+
+int i2c_write(uchar chip, uint addr, int alen,
+		uchar *buffer, int len)
+{
+	return active_dev->ops->write(chip, addr, alen,
+			buffer, len);
+}
+
+unsigned int i2c_get_bus_num(void)
+{
+	return active_dev->ops->get_bus_num();
+}
+
+int i2c_set_bus_num(unsigned int bus)
+{
+	struct multi_i2c_dev *dev;
+
+	if (bus < 0 || bus > CONFIG_SYS_MAX_I2C_BUS)
+		return -1;
+
+	dev = multi_i2c_get_by_bus(bus);
+	if (dev) {
+		active_dev = dev;
+		return dev->ops->set_bus_num(bus);
+	}
+
+	printf("%s: Can not find I2C dev for %d bus\n",
+				__func__, bus);
+	return -EINVAL;
+}
+
+void i2c_reset(void)
+{
+	int i;
+
+	for (i = 0; i < count_devices; i++) {
+		if (multi_i2c_devs[i].ops->reset)
+			multi_i2c_devs[i].ops->reset();
+	}
+}
diff --git a/include/multi_i2c.h b/include/multi_i2c.h
new file mode 100644
index 0000000..795fbf0
--- /dev/null
+++ b/include/multi_i2c.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Gwuieon Jin <ge.jin@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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
+ */
+
+#ifndef _MULTI_I2C_H
+#define _MULTI_I2C_H
+
+#define SOFT_I2C_DEV  (1 << 1)
+#define HARD_I2C_DEV  (1 << 2)
+
+enum {
+	MULTI_I2C_SOFT,
+	MULTI_I2C_HARD,
+	MULTI_I2C_MAX,
+};
+
+struct i2c_ops {
+	void (*init) (int speed, int slaveadd);
+	int (*probe) (uchar chip);
+	int (*read) (uchar chip, uint addr, int alen,
+		uchar *buffer, int len);
+	int (*read_r) (uchar chip, uint addr, int alen,
+		uchar *buffer, int len);
+	int (*write) (uchar chip, uint addr, int alen,
+		uchar *buffer, int len);
+	unsigned int (*get_bus_num) (void);
+	int (*set_bus_num) (unsigned int bus);
+	void (*reset) (void);
+};
+
+/* Device information */
+struct multi_i2c_dev {
+	struct i2c_ops *ops;
+};
+
+#ifdef CONFIG_SOFT_I2C
+extern struct i2c_ops soft_i2c_ops;
+#endif
+#ifdef CONFIG_DRIVER_S3C24X0_I2C
+extern struct i2c_ops s3c24x0_i2c_ops;
+#endif
+
+#endif /* _MULTI_I2C_H */
-- 
1.7.5.4

  parent reply	other threads:[~2012-10-22  7:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22  7:21 [U-Boot] [PATCH v2 0/9] arm:exynos4: Enable Multi I2C Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 1/9] exynos:clock: Add i2c clock Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 2/9] exynos:cpu: Add Exynos4 I2C spacing Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 3/9] exynos:pinmux: Add pinmux support for i2c Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 4/9] drivers:i2c: Modify I2C driver for Exynos4 Piotr Wilczek
2012-10-22  7:21 ` Piotr Wilczek [this message]
2012-10-22  7:21 ` [U-Boot] [PATCH v2 6/9] driver:i2c: Modify Soft I2C driver for Multi-I2C Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 7/9] driver:i2c: Modify s3c24x0_i2c " Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 8/9] drivers:i2c: modify I2C header " Piotr Wilczek
2012-10-22  7:21 ` [U-Boot] [PATCH v2 9/9] arm:trats: Use Multi-I2C on Trarts board Piotr Wilczek
2012-10-22 17:07 ` [U-Boot] [PATCH v2 0/9] arm:exynos4: Enable Multi I2C Heiko Schocher
2012-10-23 11:31   ` Piotr Wilczek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350890483-26579-6-git-send-email-p.wilczek@samsung.com \
    --to=p.wilczek@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.