Re: [Patch v3] driver/i2c/mux: Add register-based mux i2c-mux-reg

2015-06-19 Thread Alexander Sverdlin
Hi!

On 18/06/15 21:57, ext York Sun wrote:
 Based on i2c-mux-gpio driver, similarly the register-based mux
 switch from one bus to another by setting a single register.
 The register can be on PCIe bus, local bus, or any memory-mapped
 address. The endianness of such register can be specified in device
 tree if used, or in platform data.
 
 Signed-off-by: York Sun york...@freescale.com
 CC: Wolfram Sang w...@the-dreams.de
 CC: Paul Bolle pebo...@tiscali.nl
 CC: Peter Korsgaard peter.korsga...@barco.com
 CC: Alexander Sverdlin alexander.sverd...@nokia.com

I can think about external FPGA applications performing MUX function,
so the code looks useful to me.

Acked-by: Alexander Sverdlin alexander.sverd...@nokia.com

 ---
 According to Alexander's feedback, readback is added. Different sizes
 are supported. I stick with iowrite but adding an option to use iowrite
 big endian in in case needed. Both big- and little-endian are tested.
 Comments are updated.
 
 Change log:
   v3: Add support of both big- and little-endian register
   Add readback after writing to register
   Add no-read option. By default, readback is alowed.
   Fix using chan_id transferred back from i2c-mux. It was mistakenly
 used as an index. It is actually the data to be written.
 
   v2: Update to GPLv2+ licence header
   Use iowrite instead of direct dereference the pointer to write register
   Add support of difference register size of 1/2/4 bytes
   Remove i2c_put_adapter(parent) in probe fucntion
   Replace multiple dev_info() with dev_dbg()
   Add idle_in_use variable to gate using idle value
   Add __iomem for register pointer
   Move platform data header file to include/linux/platform_data/
 
  .../devicetree/bindings/i2c/i2c-mux-reg.txt|   75 +
  drivers/i2c/muxes/Kconfig  |   11 +
  drivers/i2c/muxes/Makefile |1 +
  drivers/i2c/muxes/i2c-mux-reg.c|  299 
 
  include/linux/platform_data/i2c-mux-reg.h  |   44 +++
  5 files changed, 430 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt
  create mode 100644 drivers/i2c/muxes/i2c-mux-reg.c
  create mode 100644 include/linux/platform_data/i2c-mux-reg.h
 
 diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt 
 b/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt
 new file mode 100644
 index 000..6e3197f
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt
 @@ -0,0 +1,75 @@
 +Register-based I2C Bus Mux
 +
 +This binding describes an I2C bus multiplexer that uses a single register
 +to route the I2C signals.
 +
 +Required properties:
 +- compatible: i2c-mux-reg
 +- i2c-parent: The phandle of the I2C bus that this multiplexer's master-side
 +  port is connected to.
 +* Standard I2C mux properties. See mux.txt in this directory.
 +* I2C child bus nodes. See mux.txt in this directory.
 +
 +Optional properties:
 +- reg: this pair of offset size specifies the register to control the mux.
 +  The offset size depends on its parent node. It can be any memory-mapped
 +  address. The size must be either 1, 2, or 4 bytes. If reg is omitted, the
 +  resource of this device will be used.
 +- little-endian: The existence indicates the register is in little endian.
 +  If omitted, the endianness of the host will be used.
 +- no-read: The existence indicates reading the register is not allowed.
 +- idle-state: value to set the muxer to when idle. When no value is
 +  given, it defaults to the last value used.
 +
 +For each i2c child node, an I2C child bus will be created. They will
 +be numbered based on their order in the device tree.
 +
 +Whenever an access is made to a device on a child bus, the value set
 +in the revelant node's reg property will be output to the register.
 +
 +If an idle state is defined, using the idle-state (optional) property,
 +whenever an access is not being made to a device on a child bus, the
 +register will be set according to the idle value.
 +
 +If an idle state is not defined, the most recently used value will be
 +left programmed into the register.
 +
 +Example of a mux on PCIe card, the host is a powerpc SoC (big endian):
 +
 + i2c-mux {
 + /* the offset size depends on the address translation
 +  * of the parent device. If omitted, device resource
 +  * will be used instead. The size is to determine
 +  * whether iowrite32, iowrite16, or iowrite8 will be used.
 +  */
 + reg = 0x6028 0x4;
 + little-endian;  /* little endian register on PCIe */
 + compatible = i2c-mux-reg;
 + #address-cells = 1;
 + #size-cells = 0;
 + i2c-parent = i2c1;
 + i2c@0 {
 + reg = 0;
 + #address-cells = 1;
 + #size-cells = 0;
 +
 +  

Re: lm-sensor.org is down

2015-06-19 Thread Jean Delvare
Hi Angelo,

Le Friday 19 June 2015 à 08:58 +0200, Angelo Compagnucci a écrit :
 lm-sensorg.org is down:
 
 http://isup.me/www.lm-sensor.org
 
 It's not just you! http://www.lm-sensor.org looks down from here. 

I've noticed it too. Hopefully the admin (Axel Thimm) has noticed as
well and is already looking at the problem.

-- 
Jean Delvare
SUSE L3 Support

--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] i2c-tools: add new tool 'i2ctransfer'

2015-06-19 Thread Wolfram Sang
From: Wolfram Sang wsa+rene...@sang-engineering.com

This tool allows to construct and concat multiple I2C messages into one
single transfer. Its aim is to test I2C master controllers, and so there
is no SMBus fallback.

I've been missing such a tool a number of times now, so I finally got
around to writing it myself. As with all I2C tools, it can be dangerous,
but it can also be very useful when developing. I am not sure if distros
should supply it, I'll leave that to Jean's experience. For embedded
build systems, I think this should be selectable.

Tested with various Renesas I2C IP cores as well as Tegra and AT91.

Signed-off-by: Wolfram Sang wsa+rene...@sang-engineering.com
---
 tools/Module.mk |   8 +-
 tools/i2ctransfer.c | 320 
 2 files changed, 327 insertions(+), 1 deletion(-)
 create mode 100644 tools/i2ctransfer.c

diff --git a/tools/Module.mk b/tools/Module.mk
index 641ac81..7192361 100644
--- a/tools/Module.mk
+++ b/tools/Module.mk
@@ -18,7 +18,7 @@ else
 TOOLS_LDFLAGS  += -Llib -li2c
 endif
 
-TOOLS_TARGETS  := i2cdetect i2cdump i2cset i2cget
+TOOLS_TARGETS  := i2cdetect i2cdump i2cset i2cget i2ctransfer
 
 #
 # Programs
@@ -36,6 +36,9 @@ $(TOOLS_DIR)/i2cset: $(TOOLS_DIR)/i2cset.o 
$(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)
 $(TOOLS_DIR)/i2cget: $(TOOLS_DIR)/i2cget.o $(TOOLS_DIR)/i2cbusses.o 
$(TOOLS_DIR)/util.o
$(CC) $(LDFLAGS) -o $@ $^ $(TOOLS_LDFLAGS)
 
+$(TOOLS_DIR)/i2ctransfer: $(TOOLS_DIR)/i2ctransfer.o $(TOOLS_DIR)/i2cbusses.o 
$(TOOLS_DIR)/util.o
+   $(CC) $(LDFLAGS) -o $@ $^ $(TOOLS_LDFLAGS)
+
 #
 # Objects
 #
@@ -52,6 +55,9 @@ $(TOOLS_DIR)/i2cset.o: $(TOOLS_DIR)/i2cset.c 
$(TOOLS_DIR)/i2cbusses.h $(TOOLS_DI
 $(TOOLS_DIR)/i2cget.o: $(TOOLS_DIR)/i2cget.c $(TOOLS_DIR)/i2cbusses.h 
$(TOOLS_DIR)/util.h version.h $(INCLUDE_DIR)/i2c/smbus.h
$(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $ -o $@
 
+$(TOOLS_DIR)/i2ctransfer.o: $(TOOLS_DIR)/i2ctransfer.c 
$(TOOLS_DIR)/i2cbusses.h $(TOOLS_DIR)/util.h version.h
+   $(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $ -o $@
+
 $(TOOLS_DIR)/i2cbusses.o: $(TOOLS_DIR)/i2cbusses.c $(TOOLS_DIR)/i2cbusses.h
$(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $ -o $@
 
diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
new file mode 100644
index 000..27f4d7a
--- /dev/null
+++ b/tools/i2ctransfer.c
@@ -0,0 +1,320 @@
+/*
+i2ctransfer.c - A user-space program to send concatenated i2c messages
+Copyright (C) 2015 Wolfram Sang w...@sang-engineering.com
+Copyright (C) 2015 Renesas Electronics Corporation
+
+Based on i2cget.c:
+Copyright (C) 2005-2012  Jean Delvare jdelv...@suse.de
+
+which is based on i2cset.c:
+Copyright (C) 2001-2003  Frodo Looijaard fro...@dds.nl, and
+ Mark D. Studebaker mdsxyz...@yahoo.com
+Copyright (C) 2004-2005  Jean Delvare
+
+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.
+*/
+
+#include sys/ioctl.h
+#include errno.h
+#include string.h
+#include stdio.h
+#include stdlib.h
+#include unistd.h
+#include linux/i2c.h
+#include linux/i2c-dev.h
+#include i2cbusses.h
+#include util.h
+#include ../version.h
+
+enum parse_state {
+   PARSE_GET_DESC,
+   PARSE_GET_DATA
+};
+
+#define PRINT_STDERR   (1  0)
+#define PRINT_READ_BUF (1  1)
+#define PRINT_WRITE_BUF(1  2)
+#define PRINT_HEADER   (1  3)
+
+static void help(void)
+{
+   fprintf(stderr,
+   Usage: i2ctransfer [-f] [-y] [-v] [-V] I2CBUS DESC [DATA] 
[DESC [DATA]]...\n
+ I2CBUS is an integer or an I2C bus name\n
+ DESC describes the transfer in the form: 
{r|w}LENGTH[@address]\n
+   1) read/write-flag 2) LENGTH (range 0-65535) 3) I2C 
address (use last one if omitted)\n
+ DATA are LENGTH bytes for a write message. They can be 
shortened by a suffix:\n
+   = (keep value constant until LENGTH)\n
+   + (increase value by 1 until LENGTH)\n
+   - (decrease value by 1 until LENGTH)\n
+   \nExample (bus 0, read 8 byte at offset 0x64 from eeprom at 
0x50):\n
+ # i2ctransfer 0 w1@0x50 0x64 r8\n
+   Example (same eeprom, at offset 0x42 write 0xff 0xfe .. 0x00 
):\n
+ # i2ctransfer 0 w257@0x50 0x42 0xff-\n
+   );
+}
+
+static int check_funcs(int file)
+{
+   unsigned long funcs;
+
+   /* check adapter functionality */
+   if (ioctl(file, I2C_FUNCS, funcs)  0) {
+   fprintf(stderr, Error: Could not get 

[PATCH 2/2] i2c-tools: i2ctransfer: clean up allocated resources

2015-06-19 Thread Wolfram Sang
From: Wolfram Sang wsa+rene...@sang-engineering.com

I still think this makes the code less readable and unnecessarily big [1],
but I assume Jean insists on it :) So, here is an add-on patch to squash.

Signed-off-by: Wolfram Sang wsa+rene...@sang-engineering.com

[1] 
http://www.gnu.org/software/libc/manual/html_node/Freeing-after-Malloc.html#Freeing-after-Malloc

There is no point in freeing blocks at the end of a program, because
all of the program’s space is given back to the system when the process
terminates.
---
 tools/i2ctransfer.c | 44 +++-
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
index 27f4d7a..418e303 100644
--- a/tools/i2ctransfer.c
+++ b/tools/i2ctransfer.c
@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
 {
char filename[20];
char *end;
-   int i2cbus, address = -1, file, arg_idx = 1, nmsgs = 0, nmsgs_sent;
+   int i2cbus, address = -1, file, arg_idx = 1, nmsgs = 0, nmsgs_sent, i;
int force = 0, yes = 0, version = 0, verbose = 0;
unsigned buf_idx = 0;
unsigned long len, raw_data;
@@ -138,6 +138,9 @@ int main(int argc, char *argv[])
struct i2c_rdwr_ioctl_data rdwr;
enum parse_state state = PARSE_GET_DESC;
 
+   for (i = 0; i  I2C_RDRW_IOCTL_MAX_MSGS; i++)
+   msgs[i].buf = NULL;
+
/* handle (optional) arg_idx first */
while (arg_idx  argc  argv[arg_idx][0] == '-') {
switch (argv[arg_idx][1]) {
@@ -178,7 +181,7 @@ int main(int argc, char *argv[])
if (nmsgs  I2C_RDRW_IOCTL_MAX_MSGS) {
fprintf(stderr, Error: Too many messages (max: %d)\n,
I2C_RDRW_IOCTL_MAX_MSGS);
-   exit(1);
+   goto err_out;
}
 
switch (state) {
@@ -190,20 +193,20 @@ int main(int argc, char *argv[])
case 'w': break;
default:
fprintf(stderr, Error: Invalid direction\n);
-   goto err_out;
+   goto err_out_with_arg;
}
 
len = strtoul(arg_ptr, end, 0);
if (len  65535) {
fprintf(stderr, Error: Length invalid\n);
-   goto err_out;
+   goto err_out_with_arg;
}
 
arg_ptr = end;
if (*arg_ptr) {
if (*arg_ptr++ != '@') {
fprintf(stderr, Error: No '@' after 
length\n);
-   goto err_out;
+   goto err_out_with_arg;
}
 
/* We skip 10-bit support for now. If we want 
it, it
@@ -213,16 +216,16 @@ int main(int argc, char *argv[])
 
address = parse_i2c_address(arg_ptr);
if (address  0)
-   goto err_out;
+   goto err_out_with_arg;
 
if (!force  set_slave_addr(file, address, 0))
-   goto err_out;
+   goto err_out_with_arg;
 
} else {
/* Reuse last address if possible */
if (address  0) {
fprintf(stderr, Error: No address 
given\n);
-   goto err_out;
+   goto err_out_with_arg;
}
}
 
@@ -234,7 +237,7 @@ int main(int argc, char *argv[])
buf = malloc(len);
if (!buf) {
fprintf(stderr, Error: No memory for 
buffer\n);
-   goto err_out;
+   goto err_out_with_arg;
}
memset(buf, 0, len);
msgs[nmsgs].buf = buf;
@@ -253,7 +256,7 @@ int main(int argc, char *argv[])
raw_data = strtoul(arg_ptr, end, 0);
if (raw_data  255) {
fprintf(stderr, Error: Data byte invalid\n);
-   goto err_out;
+   goto err_out_with_arg;
}
data = raw_data;
len = msgs[nmsgs].len;
@@ -270,7 +273,7 @@ int main(int argc, char *argv[])
case '=': break;
   

[PATCH 0/2] new tool 'i2ctransfer'

2015-06-19 Thread Wolfram Sang
So, here is my updated, better tested, much improved version of i2ctransfer:

* rewrote parser to match agreed syntax (even improved it futher by reusing
  last address if not specified again)

* fixed 0-byte length transfers

* way more error checking

* better error reporting

And further details and cleanups. I still believe we should let Linux clean up
the buffers, but I suspect Jean won't like it, so I added a patch to just do
that.

Please review, test, apply...

Thanks,

   Wolfram


Wolfram Sang (2):
  i2c-tools: add new tool 'i2ctransfer'
  i2c-tools: i2ctransfer: clean up allocated resources

 tools/Module.mk |   8 +-
 tools/i2ctransfer.c | 330 
 2 files changed, 337 insertions(+), 1 deletion(-)
 create mode 100644 tools/i2ctransfer.c

-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


lm-sensor.org is down

2015-06-19 Thread Angelo Compagnucci
Hi Jean,

lm-sensorg.org is down:

http://isup.me/www.lm-sensor.org

It's not just you! http://www.lm-sensor.org looks down from here. 

Sincerely, Angelo

-- 
Profile: http://it.linkedin.com/in/compagnucciangelo
--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC] i2c-tools: allow linker and compile flags from command line

2015-06-19 Thread Wolfram Sang
Mainly for debugging, so one can pass stuff like -O0 or -static.

Signed-off-by: Wolfram Sang w...@the-dreams.de
---
 tools/Module.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/Module.mk b/tools/Module.mk
index 8efddbb..641ac81 100644
--- a/tools/Module.mk
+++ b/tools/Module.mk
@@ -9,13 +9,13 @@
 
 TOOLS_DIR  := tools
 
-TOOLS_CFLAGS   := -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
+TOOLS_CFLAGS   += -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
   -Wcast-align -Wwrite-strings -Wnested-externs -Winline \
   -W -Wundef -Wmissing-prototypes -Iinclude
 ifeq ($(USE_STATIC_LIB),1)
-TOOLS_LDFLAGS  := $(LIB_DIR)/$(LIB_STLIBNAME)
+TOOLS_LDFLAGS  += $(LIB_DIR)/$(LIB_STLIBNAME)
 else
-TOOLS_LDFLAGS  := -Llib -li2c
+TOOLS_LDFLAGS  += -Llib -li2c
 endif
 
 TOOLS_TARGETS  := i2cdetect i2cdump i2cset i2cget
-- 
2.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] i2c: omap: improve duty cycle on SCL

2015-06-19 Thread Felipe Balbi
On Fri, Jun 19, 2015 at 07:41:49AM +0200, Michael Lawnick wrote:
 Am 18.06.2015 um 19:24 schrieb Felipe Balbi:
 On Thu, Jun 18, 2015 at 08:39:11AM +0200, Michael Lawnick wrote:
 Am 17.06.2015 um 17:38 schrieb Felipe Balbi:
 Hi,
 
 On Wed, Jun 17, 2015 at 01:09:53PM +0200, Michael Lawnick wrote:
 Am 16.06.2015 um 21:17 schrieb Felipe Balbi:
 With this patch we try to be as close to 50%
 duty cycle as possible. The reason for this
 is that some devices present an erratic behavior
 with certain duty cycles.
 
 One such example is TPS65218 PMIC which fails
 to change voltages when running @ 400kHz and
 duty cycle is lower than 34%.
 
 The idea of the patch is simple:
 
 calculate desired scl_period from requested scl
 and use 50% for tLow and 50% for tHigh.
 ...
 Hmm, and what's about  Philips I2C specification 2.1, Jan 2000, Table 5?
 
 PARAMETER   SYMBOL  STANDARD-MODE   FAST-MODE 
 UNIT
   MIN. MAX. MIN. MAX.
 LOW period of the SCL clock tLOW  4.7   –   1.3   –   µs
 HIGH period of the SCL clocktHIGH 4.0   –   0.6   –   µs
 
 Your signal is in spec (0.85 µs high, 1,65 low).
 Maybe your TPS65218 is just buggy or signals are bad?
 
 yes, tps is buggy, it's written in the commit log itself.
 
 
 So I think it is unacceptable to change the adapters code violating
 specification because some buggy device doesn't work properly.
 
 read the other thread and you'll see that it's not violating jack
 
 This change for your device has chance to blow up many correctly
 working ones.
 
 How ?
 
 The answer is so obvious that I'm a bit irritated.
 Your patch description tells: 'and use 50% for tLow and 50% for tHigh'

another one who can't do simple algebra.

http://marc.info/?l=linux-i2cm=143456423512634w=2
http://marc.info/?l=linux-i2cm=143456444212698w=2
http://marc.info/?l=linux-omapm=143456762413953w=2

 For 400kHz this means 1.25 us for high and low. This clearly violates the
 specification for minimum low period and will not work with any device that
 relies on it.
 In the other thread it is discussed that your patch does effectively not do
 what you describe but this is something completely independent.

Read the comment where the calculation goes, it states that we try to
get as close to 50% duty cycle while making sure we're within spec.

Also, commit log is saying that we're using 50% of SCL period for tLow
and tHigh calculation, not that duty cycle will be 50%, which it isn't.

-- 
balbi


signature.asc
Description: Digital signature