From patchwork Tue Jul 5 13:49:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majewski?= X-Patchwork-Id: 103296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 54361B6F6B for ; Tue, 5 Jul 2011 23:49:29 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EB3A528086; Tue, 5 Jul 2011 15:49:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2FI4TdczQ4q7; Tue, 5 Jul 2011 15:49:27 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1EFD92808B; Tue, 5 Jul 2011 15:49:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 86C432808B for ; Tue, 5 Jul 2011 15:49:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HSmGUBTH3wa0 for ; Tue, 5 Jul 2011 15:49:19 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by theia.denx.de (Postfix) with ESMTP id 3947828086 for ; Tue, 5 Jul 2011 15:49:17 +0200 (CEST) Received: from spt2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0LNV00LT3523ZX@mailout2.w1.samsung.com> for u-boot@lists.denx.de; Tue, 05 Jul 2011 14:49:15 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LNV00KJ0521ZW@spt2.w1.samsung.com> for u-boot@lists.denx.de; Tue, 05 Jul 2011 14:49:14 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id 38A29270062; Tue, 05 Jul 2011 15:49:46 +0200 (CEST) Date: Tue, 05 Jul 2011 15:49:07 +0200 From: Lukasz Majewski To: u-boot@lists.denx.de Message-id: <1309873747-3488-1-git-send-email-l.majewski@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.2.5 Cc: Minkyu Kang , kyungmin.park@samsung.com, hs@denx.de, m.szyprowski@samsung.com Subject: [U-Boot] [PATCH] i2c:gpio:s5p: I2C GPIO Software implementation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This commit adds I2C software support for Samsung's S5PC110 family of processors. The generic drivers/i2c/soft_i2c framework is used, with routines provided by this commit. Signed-off-by: Lukasz Majewski --- arch/arm/include/asm/arch-s5pc1xx/i2c-gpio.h | 52 +++++++++++ board/samsung/goni/goni.c | 33 +++++++- drivers/i2c/Makefile | 1 + drivers/i2c/s5p_gpio_i2c.c | 123 ++++++++++++++++++++++++++ include/configs/s5p_goni.h | 8 ++ 5 files changed, 216 insertions(+), 1 deletions(-) create mode 100644 arch/arm/include/asm/arch-s5pc1xx/i2c-gpio.h create mode 100644 drivers/i2c/s5p_gpio_i2c.c diff --git a/arch/arm/include/asm/arch-s5pc1xx/i2c-gpio.h b/arch/arm/include/asm/arch-s5pc1xx/i2c-gpio.h new file mode 100644 index 0000000..83b8179 --- /dev/null +++ b/arch/arm/include/asm/arch-s5pc1xx/i2c-gpio.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 Samsung Electronics + * Minkyu Kang + * + * 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 __I2C_GPIO_H_ +#define __I2C_GPIO_H_ + +#ifndef __ASSEMBLY__ +struct i2c_gpio_bus_data { + unsigned int gpio_base; + unsigned int sda_pin; + unsigned int scl_pin; +}; + +struct i2c_gpio_bus { + struct i2c_gpio_bus_data *bus; +}; + +void i2c_gpio_init(struct i2c_gpio_bus *bus, int len, int index); +void i2c_gpio_dir(int dir); +void i2c_gpio_set(int line, int value); +int i2c_gpio_get(void); +void i2c_gpio_set_bus(int index); + +#define I2C_SDA(x) i2c_gpio_set(1, x) +#define I2C_SCL(x) i2c_gpio_set(0, x) +#define I2C_READ (!!i2c_gpio_get()) +#define I2C_ACTIVE i2c_gpio_dir(1) +#define I2C_TRISTATE i2c_gpio_dir(0) +#define I2C_DELAY udelay(5) + +#endif +#endif diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c index 581935d..8149ebf 100644 --- a/board/samsung/goni/goni.c +++ b/board/samsung/goni/goni.c @@ -1,7 +1,8 @@ /* - * Copyright (C) 2008-2009 Samsung Electronics + * Copyright (C) 2008-2011 Samsung Electronics * Minkyu Kang * Kyungmin Park + * Lukasz Majewski * * See file CREDITS for list of people who contributed to this * project. @@ -23,6 +24,7 @@ */ #include +#include #include #include @@ -96,3 +98,32 @@ int board_mmc_init(bd_t *bis) return s5p_mmc_init(0, 4); } #endif + +/* Define I2C parameters to handle usb transmission */ +enum { I2C_PMIC, I2C_NUM, }; + +/* + * i2c pmic + * SDA: GPJ4[0] + * SCL: GPJ4[3] + */ +static struct i2c_gpio_bus_data i2c_pmic = { + .sda_pin = 0, + .scl_pin = 3, +}; + +static struct i2c_gpio_bus i2c_gpio[] = { + { + .bus = &i2c_pmic, + }, +}; + +#define S5PC110_GPIO_J3 0XE02002C0 + +void i2c_init_board(void) +{ + i2c_gpio[I2C_PMIC].bus = &i2c_pmic; + i2c_gpio[I2C_PMIC].bus->gpio_base = S5PC110_GPIO_J3; + + i2c_gpio_init(i2c_gpio, I2C_NUM, I2C_PMIC); +} diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index a48047a..47e9c56 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -42,6 +42,7 @@ COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o COBJS-$(CONFIG_SPEAR_I2C) += spr_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o +COBJS-$(CONFIG_S5P_GPIO_I2C) += s5p_gpio_i2c.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/i2c/s5p_gpio_i2c.c b/drivers/i2c/s5p_gpio_i2c.c new file mode 100644 index 0000000..309bd4d --- /dev/null +++ b/drivers/i2c/s5p_gpio_i2c.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2009 Samsung Electronics + * Minkyu Kang + * + * 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 +#include +#include +#include +#include + +#ifdef CONFIG_SOFT_I2C + +static struct i2c_gpio_bus *i2c_gpio; + +void i2c_gpio_init(struct i2c_gpio_bus *bus, int len, int index) +{ + int i; + struct s5p_gpio_bank *bank; + + i2c_gpio = bus; + + /* init all i2c gpio buses */ + for (i = 0; i < len; i++) { + if (!i2c_gpio[i].bus) + continue; + + bank = (struct s5p_gpio_bank *)i2c_gpio[i].bus->gpio_base; + if (!bank) + continue; + + /* SDA */ + gpio_direction_output(bank, + i2c_gpio[i].bus->sda_pin, 1); + + /* SCL */ + gpio_direction_output(bank, + i2c_gpio[i].bus->scl_pin, 1); + } + + /* set default bus */ + i2c_set_bus_num(index); +} + +void i2c_gpio_set(int line, int value) +{ + struct s5p_gpio_bank *bank; + unsigned int bus_index; + + bus_index = i2c_get_bus_num(); + + if (!i2c_gpio[bus_index].bus) + return; + + bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base; + if (!bank) + return; + + if (line) + line = i2c_gpio[bus_index].bus->sda_pin; + else + line = i2c_gpio[bus_index].bus->scl_pin; + + gpio_set_value(bank, line, value); +} + +int i2c_gpio_get(void) +{ + struct s5p_gpio_bank *bank; + unsigned int bus_index; + + bus_index = i2c_get_bus_num(); + if (!i2c_gpio[bus_index].bus) + return 0; + + bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base; + if (!bank) + return 0; + + return gpio_get_value(bank, i2c_gpio[bus_index].bus->sda_pin); +} + +void i2c_gpio_dir(int dir) +{ + struct s5p_gpio_bank *bank; + unsigned int bus_index; + + bus_index = i2c_get_bus_num(); + if (!i2c_gpio[bus_index].bus) + return; + + bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base; + if (!bank) + return; + + if (dir) { + gpio_direction_output(bank, + i2c_gpio[bus_index].bus->sda_pin, 0); + } else { + gpio_direction_input(bank, + i2c_gpio[bus_index].bus->sda_pin); + } +} + +#endif /* CONFIG_SOFT_I2C */ diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h index d648ce8..50726f7 100644 --- a/include/configs/s5p_goni.h +++ b/include/configs/s5p_goni.h @@ -221,4 +221,12 @@ #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - 0x1000000) +/* I2C Soft */ +#include +#define CONFIG_S5P_GPIO_I2C 1 +#define CONFIG_SOFT_I2C 1 +#define CONFIG_SYS_I2C_INIT_BOARD +#define CONFIG_SYS_I2C_SPEED 50000 +#define CONFIG_I2C_MULTI_BUS +#define CONFIG_SYS_MAX_I2C_BUS 7 #endif /* __CONFIG_H */