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

2015-08-14 Thread Wolfram Sang

  Do I have to add myself to MAINTAINER file for this driver?
  
  Do you want to maintain this driver?
 
 I prefer not, if that is OK.

Not my most favourite answer, but yes, it is ok ;)

--
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 v3] driver/i2c/mux: Add register-based mux i2c-mux-reg

2015-08-13 Thread York Sun


On 08/11/2015 06:35 PM, Wolfram Sang wrote:
 
 Do I have to add myself to MAINTAINER file for this driver?
 
 Do you want to maintain this driver?
 

I prefer not, if that is OK.

York
--
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 v3] driver/i2c/mux: Add register-based mux i2c-mux-reg

2015-08-11 Thread Wolfram Sang
On Thu, Jun 18, 2015 at 12:57:38PM -0700, 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

Thanks for this driver!

...

 +- no-read: The existence indicates reading the register is not allowed.

Given that we have read-only properties already, I'd prefer this one
to be write-only.

 +For each i2c child node, an I2C child bus will be created. They will
 +be numbered based on their order in the device tree.

This is a Linux specific detail (which can be overridden by aliases), so
it should not be in this document, I'd say.

 diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
 index f6d313e..77c1257 100644
 --- a/drivers/i2c/muxes/Kconfig
 +++ b/drivers/i2c/muxes/Kconfig
 @@ -29,6 +29,17 @@ config I2C_MUX_GPIO
 This driver can also be built as a module.  If so, the module
 will be called i2c-mux-gpio.
  
 +config I2C_MUX_REG
 + tristate Register-based I2C multiplexer
 + help
 +   If you say yes to this option, support will be included for a
 +   register based I2C multiplexer. This driver provides access to
 +   I2C busses connected through a MUX, which is controlled
 +   by a sinple register.

Typo here. And keep the sorting, please.

  obj-$(CONFIG_I2C_MUX_GPIO)   += i2c-mux-gpio.o
 +obj-$(CONFIG_I2C_MUX_REG)+= i2c-mux-reg.o

Keep the sorting, please.

  obj-$(CONFIG_I2C_MUX_PCA9541)+= i2c-mux-pca9541.o
  obj-$(CONFIG_I2C_MUX_PCA954x)+= i2c-mux-pca954x.o
  obj-$(CONFIG_I2C_MUX_PINCTRL)+= i2c-mux-pinctrl.o

 + adapter = of_find_i2c_adapter_by_node(adapter_np);
 + if (!adapter) {
 + dev_err(pdev-dev, Cannot find parent bus\n);

I don't think we should print something when deferring.

 + return -EPROBE_DEFER;
 + }
 + mux-parent = adapter;
 + mux-data.parent = i2c_adapter_id(adapter);
 + put_device(adapter-dev);
 +
 + mux-data.n_values = of_get_child_count(np);
 + if (of_find_property(np, little-endian, NULL)) {

You should check for a big-endian property as well, no?

 + parent = i2c_get_adapter(mux-data.parent);
 + if (!parent) {
 + dev_err(pdev-dev, Parent adapter (%d) not found\n,
 + mux-data.parent);
 + return -EPROBE_DEFER;

Ditto about printing when deferred probing.

 +static int i2c_mux_reg_remove(struct platform_device *pdev)
 +{
 + struct regmux *mux = platform_get_drvdata(pdev);
 + int i;
 +
 + for (i = 0; i  mux-data.n_values; i++)
 + i2c_del_mux_adapter(mux-adap[i]);
 +
 + i2c_put_adapter(mux-parent);
 +
 + dev_dbg(pdev-dev, Removed\n);

No need for that debug. The driver core has debug output for that.

Thanks,

   Wolfram



signature.asc
Description: Digital signature


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

2015-08-11 Thread York Sun


On 08/11/2015 08:39 AM, Wolfram Sang wrote:
 On Thu, Jun 18, 2015 at 12:57:38PM -0700, 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
 
 Thanks for this driver!
 
 ...
 
 +- no-read: The existence indicates reading the register is not allowed.
 
 Given that we have read-only properties already, I'd prefer this one
 to be write-only.

Sure. That's easy to fix.

 
 +For each i2c child node, an I2C child bus will be created. They will
 +be numbered based on their order in the device tree.
 
 This is a Linux specific detail (which can be overridden by aliases), so
 it should not be in this document, I'd say.

OK. I can remove it.

 
 diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
 index f6d313e..77c1257 100644
 --- a/drivers/i2c/muxes/Kconfig
 +++ b/drivers/i2c/muxes/Kconfig
 @@ -29,6 +29,17 @@ config I2C_MUX_GPIO
This driver can also be built as a module.  If so, the module
will be called i2c-mux-gpio.
  
 +config I2C_MUX_REG
 +tristate Register-based I2C multiplexer
 +help
 +  If you say yes to this option, support will be included for a
 +  register based I2C multiplexer. This driver provides access to
 +  I2C busses connected through a MUX, which is controlled
 +  by a sinple register.
 
 Typo here. And keep the sorting, please.

Will fix.

 
  obj-$(CONFIG_I2C_MUX_GPIO)  += i2c-mux-gpio.o
 +obj-$(CONFIG_I2C_MUX_REG)   += i2c-mux-reg.o
 
 Keep the sorting, please.
 
  obj-$(CONFIG_I2C_MUX_PCA9541)   += i2c-mux-pca9541.o
  obj-$(CONFIG_I2C_MUX_PCA954x)   += i2c-mux-pca954x.o
  obj-$(CONFIG_I2C_MUX_PINCTRL)   += i2c-mux-pinctrl.o
 
 +adapter = of_find_i2c_adapter_by_node(adapter_np);
 +if (!adapter) {
 +dev_err(pdev-dev, Cannot find parent bus\n);
 
 I don't think we should print something when deferring.

OK.

 
 +return -EPROBE_DEFER;
 +}
 +mux-parent = adapter;
 +mux-data.parent = i2c_adapter_id(adapter);
 +put_device(adapter-dev);
 +
 +mux-data.n_values = of_get_child_count(np);
 +if (of_find_property(np, little-endian, NULL)) {
 
 You should check for a big-endian property as well, no?

I use the little-endian as an option to indicate the nature of litten-endian
register. It is default to big-endian if this property doesn't exist. I prefer
this way unless you strongly suggest to add both and throw out an error if
neither exists.

 
 +parent = i2c_get_adapter(mux-data.parent);
 +if (!parent) {
 +dev_err(pdev-dev, Parent adapter (%d) not found\n,
 +mux-data.parent);
 +return -EPROBE_DEFER;
 
 Ditto about printing when deferred probing.

OK.

 
 +static int i2c_mux_reg_remove(struct platform_device *pdev)
 +{
 +struct regmux *mux = platform_get_drvdata(pdev);
 +int i;
 +
 +for (i = 0; i  mux-data.n_values; i++)
 +i2c_del_mux_adapter(mux-adap[i]);
 +
 +i2c_put_adapter(mux-parent);
 +
 +dev_dbg(pdev-dev, Removed\n);
 
 No need for that debug. The driver core has debug output for that.

Will remove.

Thanks for reviewing. I will send a new version after testing.

York
--
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 v3] driver/i2c/mux: Add register-based mux i2c-mux-reg

2015-08-11 Thread Wolfram Sang
  +  if (of_find_property(np, little-endian, NULL)) {
  
  You should check for a big-endian property as well, no?
 
 I use the little-endian as an option to indicate the nature of litten-endian
 register. It is default to big-endian if this property doesn't exist. I prefer
 this way unless you strongly suggest to add both and throw out an error if
 neither exists.

I'd think that little-endian or big-endian force a setting. If none
is present, we shall take the CPU endianess. Or am I overlooking
something?

Oh, and I forgot the biggest issue: I get build errors, because
__LITTLE_ENDIAN__ should be __LITTLE_ENDIAN. Is this a recent change or
why did it work for you?

Thanks for the quick response,

   Wolfram



signature.asc
Description: Digital signature


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

2015-08-11 Thread York Sun


On 08/11/2015 09:16 AM, Wolfram Sang wrote:
 +  if (of_find_property(np, little-endian, NULL)) {

 You should check for a big-endian property as well, no?

 I use the little-endian as an option to indicate the nature of litten-endian
 register. It is default to big-endian if this property doesn't exist. I 
 prefer
 this way unless you strongly suggest to add both and throw out an error if
 neither exists.
 
 I'd think that little-endian or big-endian force a setting. If none
 is present, we shall take the CPU endianess. Or am I overlooking
 something?

You are right. The current code checks for littel-endian property. If missing,
the CPU endianess is used. Do you prefer to check littlen-endian first, if
missing then big-endian, if both missing then use CPU endianess?

 
 Oh, and I forgot the biggest issue: I get build errors, because
 __LITTLE_ENDIAN__ should be __LITTLE_ENDIAN. Is this a recent change or
 why did it work for you?
 

I tested it on 4.0.4 kernel. I see a lot of reference of __LITTLE_ENDIAN__. I
will test the new patch on the latest kernel.

York
--
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 v3] driver/i2c/mux: Add register-based mux i2c-mux-reg

2015-08-11 Thread Wolfram Sang
  I'd think that little-endian or big-endian force a setting. If none
  is present, we shall take the CPU endianess. Or am I overlooking
  something?
 
 You are right. The current code checks for littel-endian property. If missing,
 the CPU endianess is used. Do you prefer to check littlen-endian first, if
 missing then big-endian, if both missing then use CPU endianess?

Yes. Do it like this.



signature.asc
Description: Digital signature


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

2015-08-11 Thread Wolfram Sang

 Do I have to add myself to MAINTAINER file for this driver?

Do you want to maintain this driver?



signature.asc
Description: Digital signature


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;
 +
 +