* [PATCH 1/6] i2c-imx: change log level for No ACK
@ 2010-05-25 8:37 Eric Bénard
2010-05-25 8:37 ` [PATCH v2 2/6] i2c: implement i2c_get_adapter() Eric Bénard
0 siblings, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
drivers/i2c/i2c-imx.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/i2c-imx.c b/drivers/i2c/i2c-imx.c
index 03e3785..cc64d94 100644
--- a/drivers/i2c/i2c-imx.c
+++ b/drivers/i2c/i2c-imx.c
@@ -214,7 +214,7 @@ static int i2c_imx_acked(struct i2c_adapter *adapter)
break;
if (is_timeout(start, MSECOND)) {
- dev_err(adapter->dev, "<%s> No ACK\n", __func__);
+ dev_dbg(adapter->dev, "<%s> No ACK\n", __func__);
return -EIO;
}
}
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 2/6] i2c: implement i2c_get_adapter()
2010-05-25 8:37 [PATCH 1/6] i2c-imx: change log level for No ACK Eric Bénard
@ 2010-05-25 8:37 ` Eric Bénard
2010-05-25 8:37 ` [PATCH v4 3/6] commands: add i2c commands Eric Bénard
0 siblings, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
From: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
v2 : add i2c_get_adapter to include/i2c/i2c.h
drivers/i2c/i2c.c | 24 +++++++++++++++++++++++-
include/i2c/i2c.h | 2 ++
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 32fd026..1fa114a 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -39,7 +39,7 @@ struct boardinfo {
};
static LIST_HEAD(board_list);
-
+static LIST_HEAD(adapter_list);
/**
* i2c_transfer - execute a single or combined I2C message
@@ -327,6 +327,23 @@ static void scan_boardinfo(struct i2c_adapter *adapter)
}
/**
+ *
+ * i2c_get_adapter - get an i2c adapter from its busnum
+ *
+ * @param busnum the desired bus number
+ *
+ */
+struct i2c_adapter *i2c_get_adapter(int busnum)
+{
+ struct i2c_adapter *adap;
+
+ list_for_each_entry(adap, &adapter_list, list)
+ if (adap->nr == busnum)
+ return adap;
+ return NULL;
+}
+
+/**
* i2c_register_master - register I2C master controller
*
* @param master initialized master, originally from i2c_alloc_master()
@@ -345,6 +362,11 @@ static void scan_boardinfo(struct i2c_adapter *adapter)
*/
int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
{
+ if (i2c_get_adapter(adapter->nr))
+ return -EBUSY;
+
+ list_add_tail(&adapter_list, &adapter->list);
+
/* populate children from any i2c device tables */
scan_boardinfo(adapter);
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index 0760fdc..c031bbb 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -66,6 +66,7 @@ struct i2c_adapter {
struct device_d *dev; /* ptr to device */
int nr; /* bus number */
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
+ struct list_head list;
};
@@ -120,6 +121,7 @@ static inline int i2c_register_board_info(int busnum,
}
#endif
extern int i2c_add_numbered_adapter(struct i2c_adapter *adapter);
+struct i2c_adapter *i2c_get_adapter(int busnum);
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
extern int i2c_master_send(struct i2c_client *client, const char *buf, int count);
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 3/6] commands: add i2c commands
2010-05-25 8:37 ` [PATCH v2 2/6] i2c: implement i2c_get_adapter() Eric Bénard
@ 2010-05-25 8:37 ` Eric Bénard
2010-05-25 8:37 ` [PATCH 4/6] eukrea_cpuimx27: add fb support Eric Bénard
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
0 siblings, 2 replies; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
theses commands allow low level access to i2c bus and can be useful
to setup an i2c device without having to add code, compile and flash
barebox.
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
v4 :
updated as per Sascha and Marc's comments
use bus 0 as a default for i2c_read & write
replace malloc with xmalloc
fix simple_strtol configuration for parameters
v3 :
enable brain and fix v2
tested on iMX27
v2 :
updated as per Sascha's comments
commands/Kconfig | 8 ++
commands/Makefile | 1 +
commands/i2c.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 221 insertions(+), 0 deletions(-)
create mode 100644 commands/i2c.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 0c09f91..0ea32d9 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -314,4 +314,12 @@ config CMD_UNLZO
Say yes here to get the unlzo command. lzo is a fast compression
algorithm by Markus Franz Xaver Johannes Oberhumer.
+config CMD_I2C
+ bool
+ depends on I2C
+ prompt "i2c commands"
+ help
+ include i2c_probe, i2c_read and i2c_write commands to communicate
+ on i2c bus.
+
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 74b0994..3eef5de 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -48,3 +48,4 @@ obj-$(CONFIG_CMD_BMP) += bmp.o
obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
obj-$(CONFIG_CMD_GPIO) += gpio.o
obj-$(CONFIG_CMD_UNLZO) += unlzo.o
+obj-$(CONFIG_CMD_I2C) += i2c.o
diff --git a/commands/i2c.c b/commands/i2c.c
new file mode 100644
index 0000000..1e617f6
--- /dev/null
+++ b/commands/i2c.c
@@ -0,0 +1,212 @@
+/*
+ * i2c.c - i2c commands
+ *
+ * Copyright (c) 2010 Eric Bénard <eric@eukrea.Com>, Eukréa Electromatique
+ *
+ * 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 <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <i2c/i2c.h>
+
+static int do_i2c_probe(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter;
+ struct i2c_client client;
+ int startaddr = -1, stopaddr = -1, addr, ret;
+ u8 reg;
+
+ if (argc < 4)
+ return COMMAND_ERROR_USAGE;
+
+ adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
+ if (!adapter)
+ return -ENODEV;
+ client.adapter = adapter;
+
+ startaddr = simple_strtol(argv[2], NULL, 0);
+ stopaddr = simple_strtol(argv[3], NULL, 0);
+ if ((startaddr == -1) || (stopaddr == -1) || (startaddr > stopaddr))
+ return COMMAND_ERROR_USAGE;
+
+ if (stopaddr > 0x7F)
+ stopaddr = 0x7F;
+
+ printf("probing i2c range 0X%02x - 0x%02x :\n", startaddr, stopaddr);
+ for (addr = startaddr; addr <= stopaddr; addr++) {
+ client.addr = addr;
+ ret = i2c_write_reg(&client, 0x00, ®, 0);
+ if (ret == 0)
+ printf("0x%02x ", addr);
+ }
+ printf("\n");
+ return 0;
+}
+
+static const __maybe_unused char cmd_i2c_probe_help[] =
+"Usage: i2c_probe bus 0xstartaddr 0xstopaddr\n"
+"probe a range of i2c addresses.\n";
+
+BAREBOX_CMD_START(i2c_probe)
+ .cmd = do_i2c_probe,
+ .usage = "probe for an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_probe_help)
+BAREBOX_CMD_END
+
+static int do_i2c_write(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter = NULL;
+ struct i2c_client client;
+ int addr = -1, reg = -1, count = -1, verbose = 0, ret = 0, opt, i;
+ u8 *buf;
+ u8 tmp;
+
+ while ((opt = getopt(argc, argv, "a:b:r:v")) > 0) {
+ switch (opt) {
+ case 'a':
+ addr = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'r':
+ reg = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'b':
+ adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ }
+ }
+
+ count = argc - optind;
+
+ if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+ return COMMAND_ERROR_USAGE;
+
+ if (!adapter)
+ adapter = i2c_get_adapter(0);
+ if (!adapter)
+ return -ENODEV;
+
+ client.adapter = adapter;
+ client.addr = addr;
+
+ buf = xmalloc(count);
+ for (i = 0; i < count; i++)
+ *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
+
+ ret = i2c_write_reg(&client, reg, buf, count);
+ if (ret != count)
+ goto out;
+
+ if (verbose) {
+ printf("wrote %i bytes starting at reg 0x%02x to i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ for (i = 0; i < count; i++)
+ printf("0x%02x ", *(buf + i));
+ printf("\n");
+ }
+
+out:
+ free(buf);
+ return 0;
+}
+
+static const __maybe_unused char cmd_i2c_write_help[] =
+"Usage: i2c_write [OPTION] ... hexdatas\n"
+"write to i2c device.\n"
+" -a 0x<addr> i2c device address\n"
+" -b <bus_num> i2c bus number (default = 0)\n"
+" -r 0x<reg> start register\n";
+
+BAREBOX_CMD_START(i2c_write)
+ .cmd = do_i2c_write,
+ .usage = "write to an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_write_help)
+BAREBOX_CMD_END
+
+static int do_i2c_read(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter = NULL;
+ struct i2c_client client;
+ u8 *buf;
+ int count = -1, addr = -1, reg = -1, verbose = 0, ret = 0, opt;
+
+ while ((opt = getopt(argc, argv, "a:b:c:r:v")) > 0) {
+ switch (opt) {
+ case 'a':
+ addr = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'c':
+ count = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'b':
+ adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
+ break;
+ case 'r':
+ reg = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ }
+ }
+
+ if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+ return COMMAND_ERROR_USAGE;
+
+ if (!adapter)
+ adapter = i2c_get_adapter(0);
+ if (!adapter)
+ return -ENODEV;
+
+ client.adapter = adapter;
+ client.addr = addr;
+
+ buf = xmalloc(count);
+ ret = i2c_read_reg(&client, reg, buf, count);
+ if (ret == count) {
+ int i;
+ if (verbose)
+ printf("read %i bytes starting at reg 0x%02x from i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ for (i = 0; i < count; i++)
+ printf("0x%02x ", *(buf + i));
+ printf("\n");
+ ret = 0;
+ }
+
+ free(buf);
+ return ret;
+}
+
+static const __maybe_unused char cmd_i2c_read_help[] =
+"Usage: i2c_read [OPTION]\n"
+"read i2c device.\n"
+" -a 0x<addr> i2c device address\n"
+" -b <bus_num> i2c bus number (default = 0)\n"
+" -r 0x<reg> start register\n"
+" -c <count> byte count\n";
+
+BAREBOX_CMD_START(i2c_read)
+ .cmd = do_i2c_read,
+ .usage = "read from an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_read_help)
+BAREBOX_CMD_END
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/6] eukrea_cpuimx27: add fb support
2010-05-25 8:37 ` [PATCH v4 3/6] commands: add i2c commands Eric Bénard
@ 2010-05-25 8:37 ` Eric Bénard
2010-05-25 8:37 ` [PATCH 5/6] eukrea_cpuimx27: update env Eric Bénard
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
1 sibling, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
board/eukrea_cpuimx27/eukrea_cpuimx27.c | 67 ++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 1 deletions(-)
diff --git a/board/eukrea_cpuimx27/eukrea_cpuimx27.c b/board/eukrea_cpuimx27/eukrea_cpuimx27.c
index ef57a96..e40c260 100644
--- a/board/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/board/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -40,6 +40,7 @@
#include <asm/io.h>
#include <mach/imx-nand.h>
#include <mach/imx-pll.h>
+#include <mach/imxfb.h>
#include <ns16550.h>
#include <asm/mmu.h>
#include <i2c/i2c.h>
@@ -176,6 +177,39 @@ static void eukrea_cpuimx27_mmu_init(void)
}
#endif
+#ifdef CONFIG_DRIVER_VIDEO_IMX
+static struct imx_fb_videomode imxfb_mode = {
+ .mode = {
+ .name = "CMO-QVGA",
+ .refresh = 60,
+ .xres = 320,
+ .yres = 240,
+ .pixclock = 156000,
+ .hsync_len = 30,
+ .left_margin = 38,
+ .right_margin = 20,
+ .vsync_len = 3,
+ .upper_margin = 15,
+ .lower_margin = 4,
+ },
+ .pcr = 0xFAD08B80,
+ .bpp = 16,};
+
+static struct imx_fb_platform_data eukrea_cpuimx27_fb_data = {
+ .mode = &imxfb_mode,
+ .pwmr = 0x00A903FF,
+ .lscr1 = 0x00120300,
+ .dmacr = 0x00020010,
+};
+
+static struct device_d imxfb_dev = {
+ .name = "imxfb",
+ .map_base = 0x10021000,
+ .size = 0x1000,
+ .platform_data = &eukrea_cpuimx27_fb_data,
+};
+#endif
+
static int eukrea_cpuimx27_devices_init(void)
{
char *envdev = "no";
@@ -208,6 +242,31 @@ static int eukrea_cpuimx27_devices_init(void)
PE14_PF_UART1_CTS,
PE15_PF_UART1_RTS,
#endif
+#ifdef CONFIG_DRIVER_VIDEO_IMX
+ PA5_PF_LSCLK,
+ PA6_PF_LD0,
+ PA7_PF_LD1,
+ PA8_PF_LD2,
+ PA9_PF_LD3,
+ PA10_PF_LD4,
+ PA11_PF_LD5,
+ PA12_PF_LD6,
+ PA13_PF_LD7,
+ PA14_PF_LD8,
+ PA15_PF_LD9,
+ PA16_PF_LD10,
+ PA17_PF_LD11,
+ PA18_PF_LD12,
+ PA19_PF_LD13,
+ PA20_PF_LD14,
+ PA21_PF_LD15,
+ PA22_PF_LD16,
+ PA23_PF_LD17,
+ PA28_PF_HSYNC,
+ PA29_PF_VSYNC,
+ PA31_PF_OE_ACD,
+ GPIO_PORTE | 5 | GPIO_GPIO | GPIO_OUT,
+#endif
};
eukrea_cpuimx27_mmu_init();
@@ -217,7 +276,7 @@ static int eukrea_cpuimx27_devices_init(void)
CS0L = 0xA0330D01;
CS0A = 0x002208C0;
- /* initizalize gpios */
+ /* initialize gpios */
for (i = 0; i < ARRAY_SIZE(mode); i++)
imx_gpio_mode(mode[i]);
@@ -239,6 +298,12 @@ static int eukrea_cpuimx27_devices_init(void)
printf("Using environment in %s Flash\n", envdev);
+#ifdef CONFIG_DRIVER_VIDEO_IMX
+ register_device(&imxfb_dev);
+ gpio_direction_output(GPIO_PORTE | 5, 0);
+ gpio_set_value(GPIO_PORTE | 5, 1);
+#endif
+
armlinux_add_dram(&sdram_dev);
armlinux_set_bootparams((void *)0xa0000100);
armlinux_set_architecture(MACH_TYPE_CPUIMX27);
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 5/6] eukrea_cpuimx27: update env
2010-05-25 8:37 ` [PATCH 4/6] eukrea_cpuimx27: add fb support Eric Bénard
@ 2010-05-25 8:37 ` Eric Bénard
2010-05-25 8:37 ` [PATCH 6/6] eukrea_cpuimx27: update defconfig Eric Bénard
0 siblings, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
board/eukrea_cpuimx27/env/bin/boot | 10 +++++++---
board/eukrea_cpuimx27/env/config | 14 +++++++-------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/board/eukrea_cpuimx27/env/bin/boot b/board/eukrea_cpuimx27/env/bin/boot
index 7bbff2d..7272e56 100644
--- a/board/eukrea_cpuimx27/env/bin/boot
+++ b/board/eukrea_cpuimx27/env/bin/boot
@@ -17,10 +17,14 @@ if [ x$1 = xnor ]; then
kernel=nor
fi
-if [ x$ip = xdhcp ]; then
- bootargs="$bootargs ip=dhcp"
+if [ x$root = xnet ]; then
+ if [ x$ip = xdhcp ]; then
+ bootargs="$bootargs ip=dhcp"
+ else
+ bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
+ fi
else
- bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
+ bootargs="$bootargs ip=off"
fi
if [ x$root = xnand ]; then
diff --git a/board/eukrea_cpuimx27/env/config b/board/eukrea_cpuimx27/env/config
index 183787e..505ada3 100644
--- a/board/eukrea_cpuimx27/env/config
+++ b/board/eukrea_cpuimx27/env/config
@@ -4,16 +4,16 @@
kernel=nor
root=nor
-uimage=cpuimx27/uImage
-jffs2=cpuimx27/rootfs.jffs2
+uimage=mx27/uImage
+jffs2=mx27/rootfs.jffs2
-autoboot_timeout=3
+autoboot_timeout=1
-# TFP410-SVGA TFP410-VGA CMO-QVGA Optrex-WVGA Sharp-QVGA-EK
+# DVI-SVGA DVI-VGA CMO-QVGA
video="CMO-QVGA"
-bootargs="console=ttymxc0,115200 fec_mac=$eth0.ethaddr rtc-pcf8563.probe=0,0x51 video=mxcfb:$video"
+bootargs="console=ttymxc0,115200 fec_mac=$eth0.ethaddr video=mxcfb:$video"
-nor_parts="256k(barebox)ro,128k(bareboxenv),1792k(kernel),-(root)"
+nor_parts="256k(barebox)ro,128k(bareboxenv),2176k(kernel),-(root)"
rootpart_nor="/dev/mtdblock3"
nand_parts="-(nand)"
@@ -28,4 +28,4 @@ ip=dhcp
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
-eth0.serverip=192.168.1.15
+#eth0.serverip=a.b.c.d
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 6/6] eukrea_cpuimx27: update defconfig
2010-05-25 8:37 ` [PATCH 5/6] eukrea_cpuimx27: update env Eric Bénard
@ 2010-05-25 8:37 ` Eric Bénard
0 siblings, 0 replies; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 8:37 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
arch/arm/configs/eukrea_cpuimx27_defconfig | 79 ++++++++++++++++-----------
1 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/arch/arm/configs/eukrea_cpuimx27_defconfig b/arch/arm/configs/eukrea_cpuimx27_defconfig
index b1624de..3b92c37 100644
--- a/arch/arm/configs/eukrea_cpuimx27_defconfig
+++ b/arch/arm/configs/eukrea_cpuimx27_defconfig
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
-# barebox version: 2.0.0-rc10
-# Fri Dec 18 11:47:22 2009
+# barebox version: 2010.05.0
+# Tue May 25 09:57:55 2010
#
# CONFIG_BOARD_LINKER_SCRIPT is not set
CONFIG_GENERIC_LINKER_SCRIPT=y
@@ -12,6 +12,7 @@ CONFIG_ARM=y
#
# CONFIG_ARCH_AT91 is not set
# CONFIG_ARCH_AT91RM9200 is not set
+# CONFIG_ARCH_EP93XX is not set
CONFIG_ARCH_IMX=y
# CONFIG_ARCH_NETX is not set
# CONFIG_ARCH_OMAP is not set
@@ -46,7 +47,7 @@ CONFIG_MACH_EUKREA_CPUIMX27=y
# CONFIG_MACH_PCM038 is not set
#
-# Board specific settings
+# Board specific settings
#
CONFIG_EUKREA_CPUIMX27_SDRAM_128MB=y
# CONFIG_EUKREA_CPUIMX27_SDRAM_256MB is not set
@@ -58,18 +59,15 @@ CONFIG_EUKREA_CPUIMX27_QUART1=y
# CONFIG_EUKREA_CPUIMX27_QUART4 is not set
#
-# i.MX specific settings
+# i.MX specific settings
#
CONFIG_IMX_CLKO=y
# CONFIG_AEABI is not set
#
-# Arm specific settings
+# Arm specific settings
#
CONFIG_CMD_ARM_CPUINFO=y
-CONFIG_CMDLINE_TAG=y
-CONFIG_SETUP_MEMORY_TAGS=y
-# CONFIG_INITRD_TAG is not set
CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
CONFIG_GREGORIAN_CALENDER=y
CONFIG_HAS_KALLSYMS=y
@@ -79,12 +77,12 @@ CONFIG_ENV_HANDLING=y
CONFIG_GENERIC_GPIO=y
#
-# General Settings
+# General Settings
#
CONFIG_LOCALVERSION_AUTO=y
#
-# memory layout
+# memory layout
#
CONFIG_HAVE_MMU=y
CONFIG_MMU=y
@@ -108,6 +106,7 @@ CONFIG_SHELL_HUSH=y
# CONFIG_SHELL_SIMPLE is not set
CONFIG_GLOB=y
CONFIG_PROMPT_HUSH_PS2="> "
+CONFIG_HUSH_FANCY_PROMPT=y
CONFIG_CMDLINE_EDITING=y
CONFIG_AUTO_COMPLETE=y
CONFIG_DYNAMIC_CRC_TABLE=y
@@ -122,7 +121,7 @@ CONFIG_DEFAULT_ENVIRONMENT=y
CONFIG_DEFAULT_ENVIRONMENT_PATH="board/eukrea_cpuimx27/env"
#
-# Debugging
+# Debugging
#
# CONFIG_DEBUG_INFO is not set
# CONFIG_ENABLE_FLASH_NOISE is not set
@@ -130,11 +129,11 @@ CONFIG_DEFAULT_ENVIRONMENT_PATH="board/eukrea_cpuimx27/env"
# CONFIG_ENABLE_DEVICE_NOISE is not set
#
-# Commands
+# Commands
#
#
-# scripting
+# scripting
#
CONFIG_CMD_EDIT=y
CONFIG_CMD_SLEEP=y
@@ -147,7 +146,7 @@ CONFIG_CMD_TRUE=y
CONFIG_CMD_FALSE=y
#
-# file commands
+# file commands
#
CONFIG_CMD_LS=y
CONFIG_CMD_RM=y
@@ -161,13 +160,14 @@ CONFIG_CMD_MOUNT=y
CONFIG_CMD_UMOUNT=y
#
-# console
+# console
#
CONFIG_CMD_CLEAR=y
CONFIG_CMD_ECHO=y
+CONFIG_CMD_ECHO_E=y
#
-# memory
+# memory
#
# CONFIG_CMD_LOADB is not set
CONFIG_CMD_MEMINFO=y
@@ -176,19 +176,20 @@ CONFIG_CMD_MTEST=y
# CONFIG_CMD_MTEST_ALTERNATIVE is not set
#
-# flash
+# flash
#
CONFIG_CMD_FLASH=y
#
-# booting
+# booting
#
CONFIG_CMD_BOOTM=y
# CONFIG_CMD_BOOTM_ZLIB is not set
# CONFIG_CMD_BOOTM_BZLIB is not set
-# CONFIG_CMD_BOOTM_SHOW_TYPE is not set
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
CONFIG_CMD_BOOTZ=y
CONFIG_CMD_BOOTU=y
+# CONFIG_CMD_LINUX16 is not set
CONFIG_CMD_RESET=y
CONFIG_CMD_GO=y
CONFIG_CMD_TIMEOUT=y
@@ -197,7 +198,10 @@ CONFIG_CMD_TEST=y
CONFIG_CMD_VERSION=y
CONFIG_CMD_HELP=y
CONFIG_CMD_DEVINFO=y
+CONFIG_CMD_BMP=y
CONFIG_CMD_GPIO=y
+CONFIG_CMD_UNLZO=y
+CONFIG_CMD_I2C=y
CONFIG_NET=y
CONFIG_NET_DHCP=y
# CONFIG_NET_RARP is not set
@@ -206,11 +210,11 @@ CONFIG_NET_PING=y
CONFIG_NET_TFTP=y
#
-# Drivers
+# Drivers
#
#
-# serial drivers
+# serial drivers
#
# CONFIG_DRIVER_SERIAL_ARM_DCC is not set
CONFIG_DRIVER_SERIAL_IMX=y
@@ -218,27 +222,33 @@ CONFIG_DRIVER_SERIAL_NS16550=y
CONFIG_MIIPHY=y
#
-# Network drivers
+# Network drivers
#
# CONFIG_DRIVER_NET_SMC911X is not set
# CONFIG_DRIVER_NET_SMC91111 is not set
CONFIG_DRIVER_NET_FEC_IMX=y
#
-# SPI drivers
+# SPI drivers
#
-CONFIG_SPI=y
-CONFIG_DRIVER_SPI_IMX=y
-CONFIG_DRIVER_SPI_MC13783=y
-# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_I2C=y
+CONFIG_DRIVER_I2C_IMX=y
+# CONFIG_DRIVER_I2C_MC13892 is not set
+# CONFIG_DRIVER_I2C_MC9SDZ60 is not set
+CONFIG_DRIVER_I2C_LP3972=y
#
-# flash drivers
+# flash drivers
#
CONFIG_HAS_CFI=y
CONFIG_DRIVER_CFI=y
-# CONFIG_DRIVER_CFI_NEW is not set
-CONFIG_DRIVER_CFI_OLD=y
+CONFIG_DRIVER_CFI_INTEL=y
+# CONFIG_DRIVER_CFI_AMD is not set
+# CONFIG_DRIVER_CFI_BANK_WIDTH_1 is not set
+CONFIG_DRIVER_CFI_BANK_WIDTH_2=y
+# CONFIG_DRIVER_CFI_BANK_WIDTH_4 is not set
+# CONFIG_DRIVER_CFI_BANK_WIDTH_8 is not set
CONFIG_CFI_BUFFER_WRITE=y
CONFIG_NAND=y
CONFIG_NAND_IMX=y
@@ -246,15 +256,20 @@ CONFIG_NAND_IMX=y
# CONFIG_MTD_NAND_VERIFY_WRITE is not set
# CONFIG_MTD_NAND_ECC_SMC is not set
CONFIG_MTD_NAND_IDS=y
+# CONFIG_ATA is not set
# CONFIG_USB is not set
# CONFIG_USB_GADGET is not set
-# CONFIG_VIDEO is not set
+CONFIG_VIDEO=y
+CONFIG_DRIVER_VIDEO_IMX=y
+# CONFIG_IMXFB_DRIVER_VIDEO_IMX_OVERLAY is not set
#
-# Filesystem support
+# Filesystem support
#
# CONFIG_FS_CRAMFS is not set
CONFIG_FS_RAMFS=y
CONFIG_FS_DEVFS=y
CONFIG_CRC32=y
# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_PROCESS_ESCAPE_SEQUENCE=y
+CONFIG_LZO_DECOMPRESS=y
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 8:37 ` [PATCH v4 3/6] commands: add i2c commands Eric Bénard
2010-05-25 8:37 ` [PATCH 4/6] eukrea_cpuimx27: add fb support Eric Bénard
@ 2010-05-25 9:02 ` Marc Kleine-Budde
2010-05-25 9:17 ` Eric Bénard
2010-05-25 9:25 ` [PATCH v5] " Eric Bénard
1 sibling, 2 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2010-05-25 9:02 UTC (permalink / raw)
To: Eric Bénard; +Cc: barebox
[-- Attachment #1.1: Type: text/plain, Size: 8505 bytes --]
Eric Bénard wrote:
> theses commands allow low level access to i2c bus and can be useful
> to setup an i2c device without having to add code, compile and flash
> barebox.
>
> Signed-off-by: Eric Bénard <eric@eukrea.com>
> ---
> v4 :
> updated as per Sascha and Marc's comments
> use bus 0 as a default for i2c_read & write
> replace malloc with xmalloc
> fix simple_strtol configuration for parameters
> v3 :
> enable brain and fix v2
> tested on iMX27
> v2 :
> updated as per Sascha's comments
>
> commands/Kconfig | 8 ++
> commands/Makefile | 1 +
> commands/i2c.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 221 insertions(+), 0 deletions(-)
> create mode 100644 commands/i2c.c
>
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 0c09f91..0ea32d9 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -314,4 +314,12 @@ config CMD_UNLZO
> Say yes here to get the unlzo command. lzo is a fast compression
> algorithm by Markus Franz Xaver Johannes Oberhumer.
>
> +config CMD_I2C
> + bool
> + depends on I2C
> + prompt "i2c commands"
> + help
> + include i2c_probe, i2c_read and i2c_write commands to communicate
> + on i2c bus.
> +
> endmenu
> diff --git a/commands/Makefile b/commands/Makefile
> index 74b0994..3eef5de 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -48,3 +48,4 @@ obj-$(CONFIG_CMD_BMP) += bmp.o
> obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
> obj-$(CONFIG_CMD_GPIO) += gpio.o
> obj-$(CONFIG_CMD_UNLZO) += unlzo.o
> +obj-$(CONFIG_CMD_I2C) += i2c.o
> diff --git a/commands/i2c.c b/commands/i2c.c
> new file mode 100644
> index 0000000..1e617f6
> --- /dev/null
> +++ b/commands/i2c.c
> @@ -0,0 +1,212 @@
> +/*
> + * i2c.c - i2c commands
> + *
> + * Copyright (c) 2010 Eric Bénard <eric@eukrea.Com>, Eukréa Electromatique
> + *
> + * 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 <command.h>
> +#include <errno.h>
> +#include <malloc.h>
> +#include <getopt.h>
> +#include <i2c/i2c.h>
> +
> +static int do_i2c_probe(struct command *cmdtp, int argc, char *argv[])
> +{
> + struct i2c_adapter *adapter;
> + struct i2c_client client;
> + int startaddr = -1, stopaddr = -1, addr, ret;
> + u8 reg;
> +
> + if (argc < 4)
> + return COMMAND_ERROR_USAGE;
> +
> + adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
> + if (!adapter)
> + return -ENODEV;
> + client.adapter = adapter;
> +
> + startaddr = simple_strtol(argv[2], NULL, 0);
> + stopaddr = simple_strtol(argv[3], NULL, 0);
> + if ((startaddr == -1) || (stopaddr == -1) || (startaddr > stopaddr))
> + return COMMAND_ERROR_USAGE;
> +
> + if (stopaddr > 0x7F)
> + stopaddr = 0x7F;
> +
> + printf("probing i2c range 0X%02x - 0x%02x :\n", startaddr, stopaddr);
> + for (addr = startaddr; addr <= stopaddr; addr++) {
> + client.addr = addr;
> + ret = i2c_write_reg(&client, 0x00, ®, 0);
> + if (ret == 0)
> + printf("0x%02x ", addr);
> + }
> + printf("\n");
> + return 0;
> +}
> +
> +static const __maybe_unused char cmd_i2c_probe_help[] =
> +"Usage: i2c_probe bus 0xstartaddr 0xstopaddr\n"
> +"probe a range of i2c addresses.\n";
> +
> +BAREBOX_CMD_START(i2c_probe)
> + .cmd = do_i2c_probe,
> + .usage = "probe for an i2c device",
> + BAREBOX_CMD_HELP(cmd_i2c_probe_help)
> +BAREBOX_CMD_END
> +
> +static int do_i2c_write(struct command *cmdtp, int argc, char *argv[])
> +{
> + struct i2c_adapter *adapter = NULL;
> + struct i2c_client client;
> + int addr = -1, reg = -1, count = -1, verbose = 0, ret = 0, opt, i;
> + u8 *buf;
> + u8 tmp;
> +
> + while ((opt = getopt(argc, argv, "a:b:r:v")) > 0) {
> + switch (opt) {
> + case 'a':
> + addr = simple_strtol(optarg, NULL, 0);
> + break;
> + case 'r':
> + reg = simple_strtol(optarg, NULL, 0);
> + break;
> + case 'b':
> + adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
I'd just save the optarg in a variable...
> + break;
> + case 'v':
> + verbose = 1;
> + break;
> + }
> + }
> +
> + count = argc - optind;
> +
> + if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
> + return COMMAND_ERROR_USAGE;
> +
> + if (!adapter)
> + adapter = i2c_get_adapter(0);
and use it here. Because if you specify an invalid adapter number,
adapter 0 will be used silently (if it exists).
> + if (!adapter)
> + return -ENODEV;
> +
> + client.adapter = adapter;
> + client.addr = addr;
> +
> + buf = xmalloc(count);
> + for (i = 0; i < count; i++)
> + *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
> +
> + ret = i2c_write_reg(&client, reg, buf, count);
> + if (ret != count)
> + goto out;
better set a return value indicating an error here...
> +
> + if (verbose) {
> + printf("wrote %i bytes starting at reg 0x%02x to i2cdev 0x%02x on bus %i\n",
> + count, reg, addr, adapter->nr);
> + for (i = 0; i < count; i++)
> + printf("0x%02x ", *(buf + i));
> + printf("\n");
> + }
> +
> +out:
> + free(buf);
> + return 0;
... and return it here.
> +}
> +
> +static const __maybe_unused char cmd_i2c_write_help[] =
> +"Usage: i2c_write [OPTION] ... hexdatas\n"
> +"write to i2c device.\n"
> +" -a 0x<addr> i2c device address\n"
> +" -b <bus_num> i2c bus number (default = 0)\n"
> +" -r 0x<reg> start register\n";
> +
> +BAREBOX_CMD_START(i2c_write)
> + .cmd = do_i2c_write,
> + .usage = "write to an i2c device",
> + BAREBOX_CMD_HELP(cmd_i2c_write_help)
> +BAREBOX_CMD_END
> +
> +static int do_i2c_read(struct command *cmdtp, int argc, char *argv[])
> +{
> + struct i2c_adapter *adapter = NULL;
> + struct i2c_client client;
> + u8 *buf;
> + int count = -1, addr = -1, reg = -1, verbose = 0, ret = 0, opt;
> +
> + while ((opt = getopt(argc, argv, "a:b:c:r:v")) > 0) {
> + switch (opt) {
> + case 'a':
> + addr = simple_strtol(optarg, NULL, 0);
> + break;
> + case 'c':
> + count = simple_strtoul(optarg, NULL, 0);
> + break;
> + case 'b':
> + adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
> + break;
> + case 'r':
> + reg = simple_strtol(optarg, NULL, 0);
> + break;
> + case 'v':
> + verbose = 1;
> + break;
> + }
> + }
> +
> + if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
> + return COMMAND_ERROR_USAGE;
> +
> + if (!adapter)
> + adapter = i2c_get_adapter(0);
> + if (!adapter)
> + return -ENODEV;
> +
> + client.adapter = adapter;
> + client.addr = addr;
> +
> + buf = xmalloc(count);
> + ret = i2c_read_reg(&client, reg, buf, count);
> + if (ret == count) {
> + int i;
> + if (verbose)
> + printf("read %i bytes starting at reg 0x%02x from i2cdev 0x%02x on bus %i\n",
> + count, reg, addr, adapter->nr);
> + for (i = 0; i < count; i++)
> + printf("0x%02x ", *(buf + i));
> + printf("\n");
> + ret = 0;
> + }
> +
> + free(buf);
> + return ret;
> +}
> +
> +static const __maybe_unused char cmd_i2c_read_help[] =
> +"Usage: i2c_read [OPTION]\n"
> +"read i2c device.\n"
> +" -a 0x<addr> i2c device address\n"
> +" -b <bus_num> i2c bus number (default = 0)\n"
> +" -r 0x<reg> start register\n"
> +" -c <count> byte count\n";
> +
> +BAREBOX_CMD_START(i2c_read)
> + .cmd = do_i2c_read,
> + .usage = "read from an i2c device",
> + BAREBOX_CMD_HELP(cmd_i2c_read_help)
> +BAREBOX_CMD_END
cheers, Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
@ 2010-05-25 9:17 ` Eric Bénard
2010-05-25 9:32 ` Marc Kleine-Budde
2010-05-25 9:25 ` [PATCH v5] " Eric Bénard
1 sibling, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 9:17 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
Le 25/05/2010 11:02, Marc Kleine-Budde a écrit :
>> + case 'b':
>> + adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
>
> I'd just save the optarg in a variable...
>
>> + break;
>> + case 'v':
>> + verbose = 1;
>> + break;
>> + }
>> + }
>> +
>> + count = argc - optind;
>> +
>> + if ((addr< 0) || (reg< 0) || (count == 0) || (addr> 0x7F))
>> + return COMMAND_ERROR_USAGE;
>> +
>> + if (!adapter)
>> + adapter = i2c_get_adapter(0);
>
> and use it here. Because if you specify an invalid adapter number,
> adapter 0 will be used silently (if it exists).
>
you're right, in fact I should exit in the case 'b' handling if the
adapter doesn't exist, that will be simpler.
>> + if (!adapter)
>> + return -ENODEV;
>> +
>> + client.adapter = adapter;
>> + client.addr = addr;
>> +
>> + buf = xmalloc(count);
>> + for (i = 0; i< count; i++)
>> + *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
>> +
>> + ret = i2c_write_reg(&client, reg, buf, count);
>> + if (ret != count)
>> + goto out;
>
> better set a return value indicating an error here...
ret should already be set by i2c_write_reg so it there is no error, I
can simply set ret to 0.
>
>> +
>> + if (verbose) {
>> + printf("wrote %i bytes starting at reg 0x%02x to i2cdev 0x%02x on bus %i\n",
>> + count, reg, addr, adapter->nr);
>> + for (i = 0; i< count; i++)
>> + printf("0x%02x ", *(buf + i));
>> + printf("\n");
>> + }
>> +
>> +out:
>> + free(buf);
>> + return 0;
>
> ... and return it here.
yes, that should be return ret
Eric
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5] commands: add i2c commands
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
2010-05-25 9:17 ` Eric Bénard
@ 2010-05-25 9:25 ` Eric Bénard
1 sibling, 0 replies; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 9:25 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
theses commands allow low level access to i2c bus and can be useful
to setup an i2c device without having to add code, compile and flash
barebox.
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
v5 :
updated as per Marc's comments
better error handling in write
better default bus handling in read & write
v4 :
updated as per Sascha and Marc's comments
use bus 0 as a default for i2c_read & write
replace malloc with xmalloc
fix simple_strtol configuration for parameters
v3 :
enable brain and fix v2
tested on iMX27
v2 :
updated as per Sascha's comments
commands/Kconfig | 8 ++
commands/Makefile | 1 +
commands/i2c.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 220 insertions(+), 0 deletions(-)
create mode 100644 commands/i2c.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 0c09f91..0ea32d9 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -314,4 +314,12 @@ config CMD_UNLZO
Say yes here to get the unlzo command. lzo is a fast compression
algorithm by Markus Franz Xaver Johannes Oberhumer.
+config CMD_I2C
+ bool
+ depends on I2C
+ prompt "i2c commands"
+ help
+ include i2c_probe, i2c_read and i2c_write commands to communicate
+ on i2c bus.
+
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 74b0994..3eef5de 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -48,3 +48,4 @@ obj-$(CONFIG_CMD_BMP) += bmp.o
obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
obj-$(CONFIG_CMD_GPIO) += gpio.o
obj-$(CONFIG_CMD_UNLZO) += unlzo.o
+obj-$(CONFIG_CMD_I2C) += i2c.o
diff --git a/commands/i2c.c b/commands/i2c.c
new file mode 100644
index 0000000..b8f2ee6
--- /dev/null
+++ b/commands/i2c.c
@@ -0,0 +1,211 @@
+/*
+ * i2c.c - i2c commands
+ *
+ * Copyright (c) 2010 Eric Bénard <eric@eukrea.Com>, Eukréa Electromatique
+ *
+ * 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 <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <i2c/i2c.h>
+
+static int do_i2c_probe(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter;
+ struct i2c_client client;
+ int startaddr = -1, stopaddr = -1, addr, ret;
+ u8 reg;
+
+ if (argc < 4)
+ return COMMAND_ERROR_USAGE;
+
+ adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
+ if (!adapter)
+ return -ENODEV;
+ client.adapter = adapter;
+
+ startaddr = simple_strtol(argv[2], NULL, 0);
+ stopaddr = simple_strtol(argv[3], NULL, 0);
+ if ((startaddr == -1) || (stopaddr == -1) || (startaddr > stopaddr))
+ return COMMAND_ERROR_USAGE;
+
+ if (stopaddr > 0x7F)
+ stopaddr = 0x7F;
+
+ printf("probing i2c range 0X%02x - 0x%02x :\n", startaddr, stopaddr);
+ for (addr = startaddr; addr <= stopaddr; addr++) {
+ client.addr = addr;
+ ret = i2c_write_reg(&client, 0x00, ®, 0);
+ if (ret == 0)
+ printf("0x%02x ", addr);
+ }
+ printf("\n");
+ return 0;
+}
+
+static const __maybe_unused char cmd_i2c_probe_help[] =
+"Usage: i2c_probe bus 0xstartaddr 0xstopaddr\n"
+"probe a range of i2c addresses.\n";
+
+BAREBOX_CMD_START(i2c_probe)
+ .cmd = do_i2c_probe,
+ .usage = "probe for an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_probe_help)
+BAREBOX_CMD_END
+
+static int do_i2c_write(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter = NULL;
+ struct i2c_client client;
+ int addr = -1, reg = -1, count = -1, verbose = 0, ret, opt, i, bus = 0;
+ u8 *buf;
+ u8 tmp;
+
+ while ((opt = getopt(argc, argv, "a:b:r:v")) > 0) {
+ switch (opt) {
+ case 'a':
+ addr = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'r':
+ reg = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'b':
+ bus = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ }
+ }
+
+ count = argc - optind;
+
+ if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+ return COMMAND_ERROR_USAGE;
+
+ adapter = i2c_get_adapter(bus);
+ if (!adapter)
+ return -ENODEV;
+
+ client.adapter = adapter;
+ client.addr = addr;
+
+ buf = xmalloc(count);
+ for (i = 0; i < count; i++)
+ *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
+
+ ret = i2c_write_reg(&client, reg, buf, count);
+ if (ret != count)
+ goto out;
+ ret = 0;
+
+ if (verbose) {
+ printf("wrote %i bytes starting at reg 0x%02x to i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ for (i = 0; i < count; i++)
+ printf("0x%02x ", *(buf + i));
+ printf("\n");
+ }
+
+out:
+ free(buf);
+ return ret;
+}
+
+static const __maybe_unused char cmd_i2c_write_help[] =
+"Usage: i2c_write [OPTION] ... hexdatas\n"
+"write to i2c device.\n"
+" -a 0x<addr> i2c device address\n"
+" -b <bus_num> i2c bus number (default = 0)\n"
+" -r 0x<reg> start register\n";
+
+BAREBOX_CMD_START(i2c_write)
+ .cmd = do_i2c_write,
+ .usage = "write to an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_write_help)
+BAREBOX_CMD_END
+
+static int do_i2c_read(struct command *cmdtp, int argc, char *argv[])
+{
+ struct i2c_adapter *adapter = NULL;
+ struct i2c_client client;
+ u8 *buf;
+ int count = -1, addr = -1, reg = -1, verbose = 0, ret, opt, bus = 0;
+
+ while ((opt = getopt(argc, argv, "a:b:c:r:v")) > 0) {
+ switch (opt) {
+ case 'a':
+ addr = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'c':
+ count = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'b':
+ bus = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'r':
+ reg = simple_strtol(optarg, NULL, 0);
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ }
+ }
+
+ if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+ return COMMAND_ERROR_USAGE;
+
+ adapter = i2c_get_adapter(bus);
+ if (!adapter)
+ return -ENODEV;
+
+ client.adapter = adapter;
+ client.addr = addr;
+
+ buf = xmalloc(count);
+ ret = i2c_read_reg(&client, reg, buf, count);
+ if (ret == count) {
+ int i;
+ if (verbose)
+ printf("read %i bytes starting at reg 0x%02x from i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ for (i = 0; i < count; i++)
+ printf("0x%02x ", *(buf + i));
+ printf("\n");
+ ret = 0;
+ }
+
+ free(buf);
+ return ret;
+}
+
+static const __maybe_unused char cmd_i2c_read_help[] =
+"Usage: i2c_read [OPTION]\n"
+"read i2c device.\n"
+" -a 0x<addr> i2c device address\n"
+" -b <bus_num> i2c bus number (default = 0)\n"
+" -r 0x<reg> start register\n"
+" -c <count> byte count\n";
+
+BAREBOX_CMD_START(i2c_read)
+ .cmd = do_i2c_read,
+ .usage = "read from an i2c device",
+ BAREBOX_CMD_HELP(cmd_i2c_read_help)
+BAREBOX_CMD_END
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 9:17 ` Eric Bénard
@ 2010-05-25 9:32 ` Marc Kleine-Budde
2010-05-25 9:43 ` Eric Bénard
0 siblings, 1 reply; 14+ messages in thread
From: Marc Kleine-Budde @ 2010-05-25 9:32 UTC (permalink / raw)
To: Eric Bénard; +Cc: barebox
[-- Attachment #1.1: Type: text/plain, Size: 2569 bytes --]
Hey,
Eric Bénard wrote:
> Le 25/05/2010 11:02, Marc Kleine-Budde a écrit :
>>> + case 'b':
>>> + adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
>>
>> I'd just save the optarg in a variable...
>>
>>> + break;
>>> + case 'v':
>>> + verbose = 1;
>>> + break;
>>> + }
>>> + }
>>> +
>>> + count = argc - optind;
>>> +
>>> + if ((addr< 0) || (reg< 0) || (count == 0) || (addr> 0x7F))
>>> + return COMMAND_ERROR_USAGE;
>>> +
>>> + if (!adapter)
>>> + adapter = i2c_get_adapter(0);
>>
>> and use it here. Because if you specify an invalid adapter number,
>> adapter 0 will be used silently (if it exists).
>>
> you're right, in fact I should exit in the case 'b' handling if the
> adapter doesn't exist, that will be simpler.
ACK, I'd do that here.....
int adapter_number = 0;
...
case 'b':
adapter_number = simple_strtoul(optarg, NULL, 0);
break;
...
adapter = i2c_get_adapter(adapter_number);
if (!adapter) {
printf("adapter %d not found\n", adapter_number);
return -ENODEV
}
>>> + if (!adapter)
>>> + return -ENODEV;
>>> +
>>> + client.adapter = adapter;
>>> + client.addr = addr;
>>> +
>>> + buf = xmalloc(count);
>>> + for (i = 0; i< count; i++)
>>> + *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
codingstyle...no space after the cast, but before and after the "+"
(char)simple_strtol(argv[optind + i], NULL, 16);
>>> +
>>> + ret = i2c_write_reg(&client, reg, buf, count);
>>> + if (ret != count)
>>> + goto out;
>>
>> better set a return value indicating an error here...
> ret should already be set by i2c_write_reg so it there is no error, I
> can simply set ret to 0.
ACK
>>
>>> +
>>> + if (verbose) {
>>> + printf("wrote %i bytes starting at reg 0x%02x to i2cdev
>>> 0x%02x on bus %i\n",
>>> + count, reg, addr, adapter->nr);
>>> + for (i = 0; i< count; i++)
>>> + printf("0x%02x ", *(buf + i));
>>> + printf("\n");
>>> + }
>>> +
>>> +out:
>>> + free(buf);
>>> + return 0;
>>
>> ... and return it here.
>
> yes, that should be return ret
>
> Eric
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 9:32 ` Marc Kleine-Budde
@ 2010-05-25 9:43 ` Eric Bénard
2010-05-25 9:47 ` Marc Kleine-Budde
0 siblings, 1 reply; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 9:43 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
Hi,
Le 25/05/2010 11:32, Marc Kleine-Budde a écrit :
>
> adapter = i2c_get_adapter(adapter_number);
> if (!adapter) {
> printf("adapter %d not found\n", adapter_number);
> return -ENODEV
> }
>
I did that without the log after sending the email (should have think a
little bit more before sending the mail) : is a v6 necessary for this log ?
Eric
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 9:43 ` Eric Bénard
@ 2010-05-25 9:47 ` Marc Kleine-Budde
2010-05-25 9:57 ` Eric Bénard
0 siblings, 1 reply; 14+ messages in thread
From: Marc Kleine-Budde @ 2010-05-25 9:47 UTC (permalink / raw)
To: Eric Bénard; +Cc: barebox
[-- Attachment #1.1: Type: text/plain, Size: 807 bytes --]
Eric Bénard wrote:
> Hi,
>
> Le 25/05/2010 11:32, Marc Kleine-Budde a écrit :
>>
>> adapter = i2c_get_adapter(adapter_number);
>> if (!adapter) {
>> printf("adapter %d not found\n", adapter_number);
>> return -ENODEV
>> }
>>
> I did that without the log after sending the email (should have think a
> little bit more before sending the mail) : is a v6 necessary for this log ?
I think sha would be happier if he can just apply your patch series (or
even pull it) without the need to modify it.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/6] commands: add i2c commands
2010-05-25 9:47 ` Marc Kleine-Budde
@ 2010-05-25 9:57 ` Eric Bénard
0 siblings, 0 replies; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 9:57 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
Le 25/05/2010 11:47, Marc Kleine-Budde a écrit :
> I think sha would be happier if he can just apply your patch series (or
> even pull it) without the need to modify it.
>
OK patch serie following soon, hope no more changes are needed ;-)
Eric
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/6] i2c-imx: change log level for No ACK
@ 2010-05-25 10:01 Eric Bénard
0 siblings, 0 replies; 14+ messages in thread
From: Eric Bénard @ 2010-05-25 10:01 UTC (permalink / raw)
To: s.hauer; +Cc: barebox
Signed-off-by: Eric Bénard <eric@eukrea.com>
---
drivers/i2c/i2c-imx.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/i2c-imx.c b/drivers/i2c/i2c-imx.c
index 03e3785..cc64d94 100644
--- a/drivers/i2c/i2c-imx.c
+++ b/drivers/i2c/i2c-imx.c
@@ -214,7 +214,7 @@ static int i2c_imx_acked(struct i2c_adapter *adapter)
break;
if (is_timeout(start, MSECOND)) {
- dev_err(adapter->dev, "<%s> No ACK\n", __func__);
+ dev_dbg(adapter->dev, "<%s> No ACK\n", __func__);
return -EIO;
}
}
--
1.6.3.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2010-05-25 10:01 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-25 8:37 [PATCH 1/6] i2c-imx: change log level for No ACK Eric Bénard
2010-05-25 8:37 ` [PATCH v2 2/6] i2c: implement i2c_get_adapter() Eric Bénard
2010-05-25 8:37 ` [PATCH v4 3/6] commands: add i2c commands Eric Bénard
2010-05-25 8:37 ` [PATCH 4/6] eukrea_cpuimx27: add fb support Eric Bénard
2010-05-25 8:37 ` [PATCH 5/6] eukrea_cpuimx27: update env Eric Bénard
2010-05-25 8:37 ` [PATCH 6/6] eukrea_cpuimx27: update defconfig Eric Bénard
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
2010-05-25 9:17 ` Eric Bénard
2010-05-25 9:32 ` Marc Kleine-Budde
2010-05-25 9:43 ` Eric Bénard
2010-05-25 9:47 ` Marc Kleine-Budde
2010-05-25 9:57 ` Eric Bénard
2010-05-25 9:25 ` [PATCH v5] " Eric Bénard
2010-05-25 10:01 [PATCH 1/6] i2c-imx: change log level for No ACK Eric Bénard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox