Re: [PATCH v3 1/4] i2c: tegra: implement slave mode
On 24.07.2015 13:52, Wolfram Sang wrote: At the begin of my work on this patchset I even denied clock disable call if slave is registered (to minimize code that can affect transfer). I hacked something like this, but it seems it was not enough. If only slave mode is used, then this logic is not needed. This is not sufficent. We shouldn't break being a master only because we also listen to a slave address (as long as the HW supports that of course). tegra_i2c_init is called on probe and resume. Also it is called in case of xfer fail. If xfer is ok, then I think slave addr must be kept unchanged. This is fragile. Try scanning the bus with i2cdetect and slave setup will be gone. As far as I understand it is a loopback mode. Probably it will not work (Stephen Warren already mentioned this). Just to make clear: I am not saying we should support talking to our own slave address. But it should still be possible to communicate with other remote devices on the bus. Sorry for the long delay. I tried to analyze the issue. Attached patch works on AC100 (Misha Komarovsky helped me with testing). Wolfram could you please try the patch with your environment? Thanks. From 0927b4007786b19e51415c4900863dd4e74fa034 Mon Sep 17 00:00:00 2001 From: Andrey Danin danind...@mail.ru Date: Thu, 20 Aug 2015 00:41:39 +0300 Subject: [PATCH] i2c: tegra: don't reset I2C slave address on init Init function is called multuple times. If I2C controller works in slave mode, then driver must keep slave registers otherwise slave configuration will be reseted. Signed-off-by: Andrey Danin danind...@mail.ru --- drivers/i2c/busses/i2c-tegra.c | 42 +-- 1 files changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 6467ce0..50250a1 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -402,6 +402,22 @@ static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) dvc_writel(i2c_dev, val, DVC_CTRL_REG1); } +static int tegra_i2c_init_slave(struct tegra_i2c_dev *i2c_dev, u32 addr, u32 flags) +{ + int addr2 = 0; + + i2c_writel(i2c_dev, I2C_SL_CNFG_NEWSL, I2C_SL_CNFG); + i2c_writel(i2c_dev, I2C_SL_DELAY_COUNT_DEFAULT, I2C_SL_DELAY_COUNT); + + if (flags I2C_CLIENT_TEN) + addr2 = (addr 7) | I2C_SL_ADDR2_TEN_BIT_MODE; + + i2c_writel(i2c_dev, addr, I2C_SL_ADDR1); + i2c_writel(i2c_dev, addr2, I2C_SL_ADDR2); + + return 0; +} + static inline int tegra_i2c_clock_enable(struct tegra_i2c_dev *i2c_dev) { int ret; @@ -461,12 +477,16 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); if (!i2c_dev-is_dvc) { - u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); - sl_cfg |= I2C_SL_CNFG_NACK | I2C_SL_CNFG_NEWSL; - i2c_writel(i2c_dev, sl_cfg, I2C_SL_CNFG); - i2c_writel(i2c_dev, 0xfc, I2C_SL_ADDR1); - i2c_writel(i2c_dev, 0x00, I2C_SL_ADDR2); - + if (i2c_dev-slave) { + tegra_i2c_init_slave(i2c_dev, i2c_dev-slave-addr, + i2c_dev-slave-flags); + } else { + u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); + sl_cfg |= I2C_SL_CNFG_NACK | I2C_SL_CNFG_NEWSL; + i2c_writel(i2c_dev, sl_cfg, I2C_SL_CNFG); + i2c_writel(i2c_dev, 0xfc, I2C_SL_ADDR1); + i2c_writel(i2c_dev, 0x00, I2C_SL_ADDR2); + } } val = 7 I2C_FIFO_CONTROL_TX_TRIG_SHIFT | @@ -767,7 +787,6 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) static int tegra_reg_slave(struct i2c_client *slave) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(slave-adapter); - int addr2 = 0; if (i2c_dev-slave) return -EBUSY; @@ -776,14 +795,7 @@ static int tegra_reg_slave(struct i2c_client *slave) tegra_i2c_clock_enable(i2c_dev); - i2c_writel(i2c_dev, I2C_SL_CNFG_NEWSL, I2C_SL_CNFG); - i2c_writel(i2c_dev, I2C_SL_DELAY_COUNT_DEFAULT, I2C_SL_DELAY_COUNT); - - if (slave-flags I2C_CLIENT_TEN) - addr2 = (slave-addr 7) | I2C_SL_ADDR2_TEN_BIT_MODE; - - i2c_writel(i2c_dev, slave-addr, I2C_SL_ADDR1); - i2c_writel(i2c_dev, addr2, I2C_SL_ADDR2); + tegra_i2c_init_slave(i2c_dev, slave-addr, slave-flags); return 0; } -- 1.7.1
Re: [PATCH] i2c: mux: reg: simplify register size checking
Sorry for top posting, I am out and replying using web access. This patch looks OK. I cannot test it until earliest next Friday. York From: Wolfram Sang w...@the-dreams.de Sent: Thursday, August 20, 2015 2:40 PM To: linux-i2c@vger.kernel.org Cc: Wolfram Sang; Sun York-R58495 Subject: [PATCH] i2c: mux: reg: simplify register size checking Checking was done at three different locations, just do it once and properly at probing time. Signed-off-by: Wolfram Sang w...@the-dreams.de Cc: York Sun york...@freescale.com --- York Sun: Can you test this patch? I can only build test. drivers/i2c/muxes/i2c-mux-reg.c | 17 ++--- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index 86d41d36a78340..da8926d816c8cc 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -59,9 +59,6 @@ static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id) if (!mux-data.write_only) ioread8(mux-data.reg); break; - default: - pr_err(Invalid register size\n); - return -EINVAL; } return 0; @@ -154,10 +151,6 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux, /* map address from reg if exists */ if (of_address_to_resource(np, 0, res)) { mux-data.reg_size = resource_size(res); - if (mux-data.reg_size 4) { - dev_err(pdev-dev, Invalid address size\n); - return -EINVAL; - } mux-data.reg = devm_ioremap_resource(pdev-dev, res); if (IS_ERR(mux-data.reg)) return PTR_ERR(mux-data.reg); @@ -210,15 +203,17 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) Register not set, using platform resource\n); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mux-data.reg_size = resource_size(res); - if (mux-data.reg_size 4) { - dev_err(pdev-dev, Invalid resource size\n); - return -EINVAL; - } mux-data.reg = devm_ioremap_resource(pdev-dev, res); if (IS_ERR(mux-data.reg)) return PTR_ERR(mux-data.reg); } + if (mux-data.reg_size != 4 mux-data.reg_size != 2 + mux-data.reg_size != 1) { + dev_err(pdev-dev, Invalid register size\n); + return -EINVAL; + } + mux-adap = devm_kzalloc(pdev-dev, sizeof(*mux-adap) * mux-data.n_values, GFP_KERNEL); -- 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 v2 7/7] i2c: img-scb: verify support for requested bit rate
Wolfram: are you happy to fix the %u thing when applying it, or would you prefer me to submit a fixed patch (Sifan is off for a few weeks I believe). If this is the only thing to be fixed, I can do it. If more things accumulate, I'd prefer a new version. Thanks, Wolfram signature.asc Description: Digital signature
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework
Wolfram Sang has been maintaining the AT24 driver since 2008. We need his ACK to this change, and since this is an i2c driver, he is also probably the path into mainline for this change. Yes, currently I pick up at24 patches. I am open to move it to some NVMEM framework in the future... But we should also look at the bigger picture. The AT25, MAX6875 and sunxi_sid drivers also have a binary file in /sys. It would be good to have some sort of plan what to do with these drivers, even if at the moment only AT24 is under discussion. ... but this surely has to be solved first. Regards, Wolfram signature.asc Description: Digital signature
[PATCH] i2c: mux: reg: simplify register size checking
Checking was done at three different locations, just do it once and properly at probing time. Signed-off-by: Wolfram Sang w...@the-dreams.de Cc: York Sun york...@freescale.com --- York Sun: Can you test this patch? I can only build test. drivers/i2c/muxes/i2c-mux-reg.c | 17 ++--- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index 86d41d36a78340..da8926d816c8cc 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -59,9 +59,6 @@ static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id) if (!mux-data.write_only) ioread8(mux-data.reg); break; - default: - pr_err(Invalid register size\n); - return -EINVAL; } return 0; @@ -154,10 +151,6 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux, /* map address from reg if exists */ if (of_address_to_resource(np, 0, res)) { mux-data.reg_size = resource_size(res); - if (mux-data.reg_size 4) { - dev_err(pdev-dev, Invalid address size\n); - return -EINVAL; - } mux-data.reg = devm_ioremap_resource(pdev-dev, res); if (IS_ERR(mux-data.reg)) return PTR_ERR(mux-data.reg); @@ -210,15 +203,17 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) Register not set, using platform resource\n); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mux-data.reg_size = resource_size(res); - if (mux-data.reg_size 4) { - dev_err(pdev-dev, Invalid resource size\n); - return -EINVAL; - } mux-data.reg = devm_ioremap_resource(pdev-dev, res); if (IS_ERR(mux-data.reg)) return PTR_ERR(mux-data.reg); } + if (mux-data.reg_size != 4 mux-data.reg_size != 2 + mux-data.reg_size != 1) { + dev_err(pdev-dev, Invalid register size\n); + return -EINVAL; + } + mux-adap = devm_kzalloc(pdev-dev, sizeof(*mux-adap) * mux-data.n_values, GFP_KERNEL); -- 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 RFC] eeprom: at24: extend driver to plug into the NVMEM framework
On Thu, Aug 20, 2015 at 06:38:51PM +0200, Andrew Lunn wrote: It's true that this is something that we might have overlooked. Is it expected to maintain that compatibility when moving a driver from one framework to another (and this is a real question, not a troll)? Yes. There will be user space applications reading from the eeprom file in /sys. In fact, until the NVMEM framework arrived, it was not easy to access the eeprom from kernel space, meaning the majority of users must of been user space... Ack. If so, we might provide a compatibility layer to add the former file too, protected by a kconfig option maybe ? There is one other detail you might of missed. Both AT24 and AT25 do have an in kernel API. In the at24_platform_data you can have a callback function setup which gets called when the device is probed. setup() is called with a struct memory_accessor which contains function pointers for reading and writing to the EEPROM. A few platforms use these for getting the MAC address out of the EEPROM. And these platforms are old style, not DT. Actually, we took it into account. The in-kernel API is even a big chunk of the framework. The only thing we still need to figure out is what interface we need to register cells statically. AT25's memory accessor can be removed, there's no users for it. The only user of the AT24 is some omap l138 boards is mach-davinci. Maxime -- Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com signature.asc Description: Digital signature
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework
It's true that this is something that we might have overlooked. Is it expected to maintain that compatibility when moving a driver from one framework to another (and this is a real question, not a troll)? Yes. There will be user space applications reading from the eeprom file in /sys. In fact, until the NVMEM framework arrived, it was not easy to access the eeprom from kernel space, meaning the majority of users must of been user space... If so, we might provide a compatibility layer to add the former file too, protected by a kconfig option maybe ? There is one other detail you might of missed. Both AT24 and AT25 do have an in kernel API. In the at24_platform_data you can have a callback function setup which gets called when the device is probed. setup() is called with a struct memory_accessor which contains function pointers for reading and writing to the EEPROM. A few platforms use these for getting the MAC address out of the EEPROM. And these platforms are old style, not DT. Andrew -- 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 RFC] eeprom: at24: extend driver to plug into the NVMEM framework
On Mon, Aug 17, 2015 at 05:25:04PM +0200, Andrew Lunn wrote: On Mon, Aug 17, 2015 at 03:59:23PM +0100, Srinivas Kandagatla wrote: On 17/08/15 14:09, Andrew Lunn wrote: On Mon, Aug 17, 2015 at 02:01:24PM +0100, Srinivas Kandagatla wrote: +Adding Maxime in the loop On 16/08/15 16:37, Stefan Wahren wrote: Another question which spring to mind is, do we want the eeprom to be in /sys twice, the old and the new way? Backwards compatibility says the old must stay. Do we want a way to suppress the new? Or should we be going as far as refractoring the code into a core library, and two wrapper drivers, old and new? I think these are questions for the framework maintainers. One of the reasons for the NVMEM framework is to remove that duplicate code in the every driver. There was no framework/ABI which was guiding such old eeprom sysfs entry in first place, so I dont see an issue in removing it for good. Correct me if am wrong. The reason for keeping it is backwards compatibility. Having the contents of the EEPROM as a file in /sys via this driver is now a part of the Linux ABI. You cannot argue it is not an ABI, just because there is no framework. Userspace will be assuming it exists at the specified location. So we cannot remove it, for existing uses of the driver. Am Ok as long as someone is happy to maintain it. Wolfram Sang has been maintaining the AT24 driver since 2008. We need his ACK to this change, and since this is an i2c driver, he is also probably the path into mainline for this change. But we should also look at the bigger picture. The AT25, MAX6875 and sunxi_sid drivers also have a binary file in /sys. It would be good to have some sort of plan what to do with these drivers, even if at the moment only AT24 is under discussion. It's true that this is something that we might have overlooked. Is it expected to maintain that compatibility when moving a driver from one framework to another (and this is a real question, not a troll)? If so, we might provide a compatibility layer to add the former file too, protected by a kconfig option maybe ? In the sunxi_sid case, I'm not sure anyone will really notice. It wasn't used for anything but debug at this point, but it will be noticed for the much more generic AT24 and At25 drivers. Maxime -- Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com signature.asc Description: Digital signature