i2c/busses: Add i2c-icy for I2C on m68k/Amiga
Subsystems (3)
Max Staudt
maintainerPATCH v2 1/4 i2c/busses: Add i2c-icy for I2C on m68k/Amiga
This is the i2c-icy driver for the ICY board for Amiga computers. It connects a PCF8584 I2C controller to the Zorro bus, providing I2C connectivity. The original documentation can be found on Aminet:
https://aminet.net/package/docs/hard/icy
IRQ support is currently not implemented, as i2c-algo-pcf is built for the ISA bus and a straight implementation of the same stack locks up a Zorro machine.
v2: Matched function names to callbacks from i2c-algo-pcf
Used z_readb()/z_writeb()
Removed BROKEN_ON_SMP in Kconfig
Moved LTC2990 to a separate commit
--- MAINTAINERS | 6 ++ drivers/i2c/busses/Kconfig | 11 +++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-icy.c | 189 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 drivers/i2c/busses/i2c-icy.c
MAINTAINERS +6 -0
@@ -7705,6 +7705,12 @@ S: Maintained F: drivers/mfd/lpc_ich.c F: drivers/gpio/gpio-ich.c +ICY I2C DRIVER +M: Max Staudt <[email protected]> +L: [email protected] +S: Maintained +F: drivers/i2c/busses/i2c-icy.c + IDE SUBSYSTEM M: "David S. Miller" <[email protected]> L: [email protected]
drivers/i2c/busses/Kconfig +11 -0
@@ -1300,6 +1300,17 @@ config I2C_ELEKTOR This support is also available as a module. If so, the module will be called i2c-elektor. +config I2C_ICY + tristate "ICY Zorro card" + depends on ZORRO + select I2C_ALGOPCF + help + This supports the PCF8584 Zorro bus I2C adapter, known as ICY. + Say Y if you own such an adapter. + + This support is also available as a module. If so, the module + will be called i2c-icy. + config I2C_MLXCPLD tristate "Mellanox I2C driver" depends on X86_64
drivers/i2c/busses/Makefile +1 -0
@@ -139,6 +139,7 @@ obj-$(CONFIG_I2C_BCM_KONA) += i2c-bcm-kona.o obj-$(CONFIG_I2C_BRCMSTB) += i2c-brcmstb.o obj-$(CONFIG_I2C_CROS_EC_TUNNEL) += i2c-cros-ec-tunnel.o obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o +obj-$(CONFIG_I2C_ICY) += i2c-icy.o obj-$(CONFIG_I2C_MLXCPLD) += i2c-mlxcpld.o obj-$(CONFIG_I2C_OPAL) += i2c-opal.o obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
drivers/i2c/busses/i2c-icy.c new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.11.0
Max Staudt
maintainerPATCH v2 2/4 i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision
Since the 2019 a1k.org community re-print of these PCBs sports an LTC2990 hwmon chip as an example use case, let this driver autoprobe for that as well. If it is present, modprobing ltc2990 is sufficient.
--- drivers/i2c/busses/i2c-icy.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/i2c/busses/i2c-icy.c +22 -0
@@ -59,6 +59,7 @@ struct icy_i2c {void __iomem *reg_s0;void __iomem *reg_s1; +struct i2c_client *client_ltc2990; };
@@ -105,6 +106,13 @@ static void icy_pcf_waitforpin(void *data)/* * Main i2c-icy part */ +static struct i2c_board_info icy_ltc2990_info = { +I2C_BOARD_INFO ("ltc2990" ,0x4c ), +}; + +static unsigned short const icy_ltc2990_addresses[] = {0x4c ,I2C_CLIENT_END }; + +static int icy_probe (struct zorro_dev *z,const struct zorro_device_id *ent) {
@@ -153,6 +161,18 @@ static int icy_probe(struct zorro_dev *z,dev_info (&z->dev,"ICY I2C controller at %#x, IRQ not implemented\n" , z->resource.start); +/* +* The 2019 a1k.org PCBs have an LTC2990 at 0x4c, so start +* it automatically once ltc2990 is modprobed. +* +* in0 is the voltage of the internal 5V power supply. +* temp1 is the temperature inside the chip. +*/ + i2c->client_ltc2990 =i2c_new_probed_device (&i2c->adapter, + &icy_ltc2990_info, + icy_ltc2990_addresses, +NULL ); +return 0 ; }
@@ -160,6 +180,8 @@ static void icy_remove(struct zorro_dev *z) {struct icy_i2c *i2c =dev_get_drvdata (&z->dev); +i2c_unregister_device (i2c->client_ltc2990); +i2c_del_adapter (&i2c->adapter); }
Signature · 1 line
2.11.0
Re: [PATCH v2 2/4] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision
Hi Max,
Quoted 5 lines · Max Staudt
Since the 2019 a1k.org community re-print of these PCBs sports an LTC2990 hwmon chip as an example use case, let this driver autoprobe for that as well. If it is present, modprobing ltc2990 is sufficient.
Signed-off-by Max Staudt <[email protected]>
Thanks for your patch!
drivers/i2c/busses/i2c-icy.c static void icy_remove(struct zorro_dev *z) · line 183
Quoted 7 lines
drivers/i2c/busses/i2c-icy.c +1
-0@@ -160,6 +180,8 @@ static void icy_remove(struct zorro_dev *z) {struct icy_i2c *i2c =dev_get_drvdata (&z->dev); +i2c_unregister_device (i2c->client_ltc2990);
Is this needed?
In my understanding, i2c_del_adapter() below takes care of that.
Apart from that, this looks good to me.
drivers/i2c/busses/i2c-icy.c static void icy_remove(struct zorro_dev *z) · line 186
Quoted 3 lines
drivers/i2c/busses/i2c-icy.c +1
-0+i2c_del_adapter (&i2c->adapter); }
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Max Staudt
maintainerRe: [PATCH v2 2/4] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision
Quoted 17 lines · Geert Uytterhoeven
Hi Max,
Quoted 5 lines · Max Staudt
Since the 2019 a1k.org community re-print of these PCBs sports an LTC2990 hwmon chip as an example use case, let this driver autoprobe for that as well. If it is present, modprobing ltc2990 is sufficient.
Signed-off-by Max Staudt <[email protected]>Thanks for your patch!
Quoted 6 lines
drivers/i2c/busses/i2c-icy.c +0
-0@@ -160,6 +180,8 @@ static void icy_remove(struct zorro_dev *z) {struct icy_i2c *i2c =dev_get_drvdata (&z->dev);
Quoted 4 lines
drivers/i2c/busses/i2c-icy.c static void icy_remove(struct zorro_dev *z) · line 183
Quoted 1 line
drivers/i2c/busses/i2c-icy.c +1
-0+i2c_unregister_device (i2c->client_ltc2990);Is this needed?
In my understanding,i2c_del_adapter()below takes care of that.
It seems to do that in i2c_del_adapter():
device_for_each_child(&adap->dev, NULL, __unregister_dummy);
However, I'm not sure I'm supposed to do that. I went by Documentation/i2c/instantiating-devices, which in "Method 2" says:
The driver which instantiated the I2C device is responsible for destroying it on cleanup. This is done by calling i2c_unregister_device() on the pointer that was earlier returned by i2c_new_device() or i2c_new_probed_device().
So, what is preferred and why?
Thanks!
Max
Re: [PATCH v2 2/4] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision
Quoted 9 lines
However, I'm not sure I'm supposed to do that. I went by
Documentation/i2c/instantiating-devices, which in "Method 2" says:The driver which instantiated the I2C device is responsible for destroying it on cleanup. This is done by calling
i2c_unregister_device()on the pointer that was earlier returned byi2c_new_device()ori2c_new_probed_device().So, what is preferred and why?
What the documentation says is preferred. For consistency and because of the general "free what you allocated" rule. If we have arguments to change that for i2c_unregister_device(), we would need to do this tree-wide anyhow. Until then, the above is valid.
Max Staudt
maintainerPATCH v2 3/4 hwmon/ltc2990: Add platform_data support
In reply to Max StaudtThis allows code using i2c_new_device() to specify a measurement mode.
--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 include/linux/platform_data/ltc2990.h
drivers/hwmon/ltc2990.c +9 -0
@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01
@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node; if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ; }else { ret =i2c_smbus_read_byte_data (i2c,LTC2990_CONTROL );if (ret <0 )
include/linux/platform_data/ltc2990.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef LTC2990_PDATA_H +#define LTC2990_PDATA_H + +#include <linux/types.h> + +struct ltc2990_platform_data { +u8 meas_mode[2 ]; +}; + +#endif /* LTC2990_PDATA_H */
Signature · 1 line
2.11.0
Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Quoted 3 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Guenter Roeck
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
In reply to Max StaudtQuoted 31 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node; if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 10 lines
drivers/hwmon/ltc2990.c +7
-0@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;
I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
Thanks,
Guenter
Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Hi Günter,
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node;
Quoted 16 lines
drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 12 lines
drivers/hwmon/ltc2990.c +7
-0if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
That was my first thought as well, but isn't that limited to DT and ACPI properties (for now)?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Guenter Roeck
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Quoted 50 lines · Geert Uytterhoeven
Hi Günter,
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+)create mode 100644
include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node;Quoted 16 lines
drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 12 lines
drivers/hwmon/ltc2990.c +7
-0if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
Quoted 3 lines
That was my first thought as well, but isn't that limited to DT and ACPI properties (for now)?
tcpm and, for example, the wcove driver don't seem to have a problem using it, I don't see acpi involved there. Also, the code resides in the core driver code and is always enabled unless I am missing something. What am I missing ?
Guenter
Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Hi Günter,
Quoted 49 lines · Guenter Roeck
Quoted 48 lines · Geert Uytterhoeven
Quoted 46 lines · Guenter Roeck
Quoted 31 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+)create mode 100644
include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node; if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 10 lines
drivers/hwmon/ltc2990.c +7
-0@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
Quoted 5 lines
Quoted 2 lines
That was my first thought as well, but isn't that limited to DT and ACPI properties (for now)?
tcpm and, for example, the wcove driver don't seem to have a problem using it, I don't see acpi involved there. Also, the code resides in the core driver
Cool, just discovered that, following your other fwnode_create_software_node() pointer...
Quoted 1 line
code and is always enabled unless I am missing something. What am I missing ?
You're missing that I'm not up-to-date w.r.t. the latest fwnode properties development ;-)
Thanks a lot!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Max Staudt
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
In reply to Guenter RoeckQuoted 30 lines · Guenter Roeck
Quoted 29 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node;
Quoted 16 lines
drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 12 lines
drivers/hwmon/ltc2990.c +7
-0if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
The driver does have DT support implemented right above my new platform_data code, and DT takes precedence. However, I can't set DT data programatically when instantiating the client using i2c_new_device() - hence the platform_data support.
Max
Guenter Roeck
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Quoted 48 lines · Max Staudt
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Max Staudt
This allows code using
i2c_new_device()to specify a measurement mode.Signed-off-by Max Staudt <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>--- drivers/hwmon/ltc2990.c | 9 +++++++++ include/linux/platform_data/ltc2990.h | 11 +++++++++++ 2 files changed, 20 insertions(+)create mode 100644
include/linux/platform_data/ltc2990.hdrivers/hwmon/ltc2990.c +2
-0@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_data/ltc2990.h> #define LTC2990_STATUS 0x00#define LTC2990_CONTROL 0x01@@ -206,6 +207,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,int ret;struct device *hwmon_dev;struct ltc2990_data *data; +struct ltc2990_platform_data *pdata =dev_get_platdata (&i2c->dev);struct device_node *of_node = i2c->dev.of_node;Quoted 16 lines
drivers/hwmon/ltc2990.c static int ltc2990_i2c_probe(struct i2c_client *i2c, · line 238
Quoted 12 lines
drivers/hwmon/ltc2990.c +7
-0if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |@@ -227,6 +229,13 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,if (data->mode[0 ] & ~LTC2990_MODE0_MASK || data->mode[1 ] & ~LTC2990_MODE1_MASK )return -EINVAL ; + }else if (pdata) { + data->mode[0 ] = pdata->meas_mode[0 ]; + data->mode[1 ] = pdata->meas_mode[1 ]; + +if (data->mode[0 ] & ~LTC2990_MODE0_MASK || + data->mode[1 ] & ~LTC2990_MODE1_MASK ) +return -EINVAL ;I would prefer if the driver was modified to accept device properties, and if those were set using the appropriate fwnode function. Any reason for not doing that ?
Quoted 2 lines
The driver does have DT support implemented right above my new
platform_datacode, and DT takes precedence. However, I can't set DT data programatically when instantiating the client usingi2c_new_device()- hence theplatform_datasupport.
Sorry, I don't understand. Why exactly can't you replace of_property_read_u32_array() with device_property_read_u32_array() and use fwnode_create_software_node() in the calling code to set the properties ?
Guenter
Max
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
Quoted 3 lines · Guenter Roeck
Sorry, I don't understand. Why exactly can't you replace
of_property_read_u32_array()withdevice_property_read_u32_array()and usefwnode_create_software_node()in the calling code to set the properties ?
Sorry, I was unaware of this option. This sounds good, I'll look into it.
Max
Max Staudt
maintainerRe: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support
In reply to Guenter RoeckHi Guenter,
Thanks for your feedback!
Reply below.
Quoted 3 lines · Guenter Roeck
Sorry, I don't understand. Why exactly can't you replace
of_property_read_u32_array()withdevice_property_read_u32_array()and usefwnode_create_software_node()in the calling code to set the properties ?
Thanks for this hint.
Turns out wcove is the only user of fwnode_create_software_node(), and intel_cht_int33fe is the only other driver to contain the string "software_node". Please bear with us if we didn't know about this handy trick yet. And handy it is!
device_property_read_*() is also really helpful to know about, as it covers both the DT case, as well as other firmware interfaces - thanks for the hint. Is there any reason to ever use of_property_read_*() anymore?
I've applied your suggested changes, and will send another patch round soon (I want to try one last thing). Please let me/us know what you think once it's on the list.
Max
Max Staudt
maintainerPATCH v2 4/4 i2c/busses/i2c-icy: Add platform_data for LTC2990
In reply to Max StaudtThis enables the three additional inputs available on the 2019 a1k.org reprint of the ICY board:
in1 will be the voltage of the 5V rail, divided by 2. in2 will be the voltage of the 12V rail, divided by 4. temp3 will be measured using a PCB loop next the chip.
--- drivers/i2c/busses/i2c-icy.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-icy.c +17 -1
@@ -42,6 +42,7 @@#include <linux/i2c.h> #include <linux/i2c-algo-pcf.h> +#include <linux/platform_data/ltc2990.h> #include <asm/amigaints.h> #include <linux/zorro.h>
@@ -106,8 +107,21 @@ static void icy_pcf_waitforpin(void *data)/* * Main i2c-icy part */ +static struct ltc2990_platform_data icy_ltc2990_platform_data = { +/* +* Additional sensors exposed by this platform data: +* +* in1 will be the voltage of the 5V rail, divided by 2. +* in2 will be the voltage of the 12V rail, divided by 4. +* temp3 will be measured using a PCB loop next the chip. +*/ + .meas_mode = {0 ,3 }, +}; +static struct i2c_board_info icy_ltc2990_info = { -I2C_BOARD_INFO ("ltc2990" ,0x4c ), + .type ="ltc2990" , + .addr =0x4c , + .platform_data = &icy_ltc2990_platform_data, };static unsigned short const icy_ltc2990_addresses[] = {0x4c ,I2C_CLIENT_END };
@@ -167,6 +181,8 @@ static int icy_probe(struct zorro_dev *z,* * in0 is the voltage of the internal 5V power supply. * temp1 is the temperature inside the chip. +* +* See platform data above for in1, in2, temp3. */ i2c->client_ltc2990 = i2c_new_probed_device(&i2c->adapter, &icy_ltc2990_info,
Signature · 1 line
2.11.0
Re: [PATCH v2 4/4] i2c/busses/i2c-icy: Add platform_data for LTC2990
Hi Max,
Quoted 8 lines · Max Staudt
This enables the three additional inputs available on the 2019 a1k.org reprint of the ICY board:
in1 will be the voltage of the 5V rail, divided by 2. in2 will be the voltage of the 12V rail, divided by 4. temp3 will be measured using a PCB loop next the chip.
Signed-off-by Max Staudt <[email protected]>
However, I would merge patches 2/4 and 4/4, and move the result after patch 3.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Max,
Quoted 10 lines · Max Staudt
This is the i2c-icy driver for the ICY board for Amiga computers. It connects a PCF8584 I2C controller to the Zorro bus, providing I2C connectivity. The original documentation can be found on Aminet:
https://aminet.net/package/docs/hard/icy
IRQ support is currently not implemented, as i2c-algo-pcf is built for the ISA bus and a straight implementation of the same stack locks up a Zorro machine.
Quoted 6 lines
v2: Matched function names to callbacks from i2c-algo-pcf
Used z_readb()/z_writeb()
RemovedBROKEN_ON_SMPinKconfig
Moved LTC2990 to a separate commitSigned-off-by Max Staudt <[email protected]>
Thanks for the update!
drivers/i2c/busses/i2c-icy.c line 154
Quoted 6 lines
drivers/i2c/busses/i2c-icy.c new file +2
-0@@ -0,0 +1,189 @@ +dev_info (&z->dev,"ICY I2C controller at %#x, IRQ not implemented\n" , + z->resource.start);
z->resource.start has type phys_addr_t, so you should pas a reference, and use %pa to print it.
Alternatively, you can print the full resource using %pR.
See Documentation/core-api/printk-formats.rst
drivers/i2c/busses/i2c-icy.c line 157
Quoted 3 lines
drivers/i2c/busses/i2c-icy.c new file +3
-0+ +return 0 ; +}
The rest looks fine to me.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Max Staudt
maintainerQuoted 7 lines · Geert Uytterhoeven
drivers/i2c/busses/i2c-icy.c line 154
Quoted 2 lines
drivers/i2c/busses/i2c-icy.c new file +2
-0+dev_info (&z->dev,"ICY I2C controller at %#x, IRQ not implemented\n" , + z->resource.start);
z->resource.starthas typephys_addr_t, so you should pas a reference, and use %pa to print it.
Alternatively, you can print the full resource using %pR.
SeeDocumentation/core-api/printk-formats.rst
Ack, this snuck in from the early days. Thanks for pointing this out!
Max
Hi,
Thanks for the patch. It looks mostly good.
drivers/i2c/busses/i2c-icy.c line 53
Quoted 2 lines
drivers/i2c/busses/i2c-icy.c new file +2
-0+static int clock =0x1c ; +module_param (clock, int,0444 );
'clock' determines the bus speed?
drivers/i2c/busses/i2c-icy.c line 126
Quoted 1 line
drivers/i2c/busses/i2c-icy.c new file +1
-0+ i2c->adapter.class =I2C_CLASS_DEPRECATED ;
This is only needed for drivers which used to have a class and decided to drop it. You can leave it empty.
drivers/i2c/busses/i2c-icy.c line 141
Quoted 1 line
drivers/i2c/busses/i2c-icy.c new file +1
-0+ algo_data->data = (void *)i2c;
You don't need the cast, do you?
Quoted 1 line
+MODULE_LICENSE("GPL");
Your SPDX header says GPL 2.0 only.
Kind regards,
Wolfram
Max Staudt
maintainerHi Wolfram,
Thanks for your input!
Replies below.
Quoted 4 lines · Wolfram Sang
drivers/i2c/busses/i2c-icy.c line 53
Quoted 2 lines
drivers/i2c/busses/i2c-icy.c new file +2
-0+static int clock =0x1c ; +module_param (clock, int,0444 );'clock' determines the bus speed?
Yes, but it also determines the frequency of the oscillator driving the PCF8584. It doesn't usually need to be touched, the current setting drives at the maximum I2C bus speed, with the maximum oscillator (12 MHz). I kept it in because i2c-elektor also exposes it in the same way, and it seems useful.
Quoted 4 lines
drivers/i2c/busses/i2c-icy.c line 126
Quoted 1 line
drivers/i2c/busses/i2c-icy.c new file +1
-0+ i2c->adapter.class =I2C_CLASS_DEPRECATED ;This is only needed for drivers which used to have a class and decided to drop it. You can leave it empty.
Thanks, I'll drop it.
Quoted 3 lines
drivers/i2c/busses/i2c-icy.c line 141
Quoted 1 line
drivers/i2c/busses/i2c-icy.c new file +1
-0+ algo_data->data = (void *)i2c;You don't need the cast, do you?
True. Dropped, thanks.
Quoted 3 lines
Quoted 1 line
+MODULE_LICENSE("GPL");
Your SPDX header says GPL 2.0 only.
Thanks! I'll change it to "GPL v2", but unfortunately there is no option for "only" in include/linux/module.h.
Cheers
Max
Quoted 3 lines
I kept it in because i2c-elektor also exposes it in the same way, and it seems useful.
Yeah, I noticed. I don't know how useful it is in practice (same for the getown callback) but I don't have better ideas, so let's just keep this to be consistent.
Quoted 4 lines
Quoted 1 line
Your SPDX header says GPL 2.0 only.
Thanks! I'll change it to "GPL v2", but unfortunately there is no option for "only" in
include/linux/module.h.
That's the correct option.
Thanks!
Max Staudt
maintainerQuoted 6 lines · Wolfram Sang
Quoted 2 lines
I kept it in because i2c-elektor also exposes it in the same way, and it seems useful.
Yeah, I noticed. I don't know how useful it is in practice (same for the getown callback) but I don't have better ideas, so let's just keep this to be consistent.
Well, the other option is to remove it, and then add it back once somebody complains - which is unlikely to happen. The clock parameter is PCF8584 specific anyway, and I think removing it is a good option, as I've done the same with getown() (where in i2c-elektor, 'own' sets the PCF8584's own address).
Question is, if I remove the parameter, I'd like it to be non-destructive. Do you know of anything that can go wrong if the I2C master is running the bus on a wrong clock?
Thanks
Max
Quoted 4 lines
Well, the other option is to remove it, and then add it back once somebody complains - which is unlikely to happen. The clock parameter is PCF8584 specific anyway, and I think removing it is a good option,
My suggestion is to do that incrementally. First, get your driver accepted. Second, do the cleanups which affect elektor as well later.
Quoted 2 lines
as I've done the same with
getown()(where in i2c-elektor, 'own' sets the PCF8584's own address).
I wondered about that. Can the PCF8584 really act as a slave, too? Somewhen I need to check its datasheet.
Quoted 3 lines
Question is, if I remove the parameter, I'd like it to be non-destructive. Do you know of anything that can go wrong if the I2C master is running the bus on a wrong clock?
Not sure if I understand you correctly, but if the bus freq is too fast then devices won't respond. Too slow is not a problem.
Max
maintainerQuoted 6 lines · Wolfram Sang
Quoted 3 lines
Well, the other option is to remove it, and then add it back once somebody complains - which is unlikely to happen. The clock parameter is PCF8584 specific anyway, and I think removing it is a good option,
My suggestion is to do that incrementally. First, get your driver accepted. Second, do the cleanups which affect elektor as well later.
My suggestion is to not touch i2c-elektor at all for now, and remove the 'clock' parameter from the first iteration of i2c-icy. It can be added back in case someone complains, which I deem unlikely.
Quoted 5 lines
Quoted 2 lines
as I've done the same with
getown()(where in i2c-elektor, 'own' sets the PCF8584's own address).I wondered about that. Can the PCF8584 really act as a slave, too? Somewhen I need to check its datasheet.
Yes it can, but this driver does not implement this.
In fact, I just remembered that the own address, while set, is not used at all in master mode!
Quote from the datasheet:
https://www.nxp.com/docs/en/data-sheet/PCF8584.pdf
6.4 Own address register S0'
When the PCF8584 is addressed as slave, this register must be loaded with the 7-bit I 2 C-bus address to which the PCF8584 is to respond. During initialization, the own address register S0' must be written to, regardless whether it is later used.
Quoted 6 lines
Quoted 3 lines
Question is, if I remove the parameter, I'd like it to be non-destructive. Do you know of anything that can go wrong if the I2C master is running the bus on a wrong clock?
Not sure if I understand you correctly, but if the bus freq is too fast then devices won't respond. Too slow is not a problem.
Okay, so we don't care. Cool, then it's safe to kick the 'clock' parameter from i2c-icy. All 2019 boards (which should be the vast majority in existence) came with a 12 MHz oscillator AFAIK, so the default should be good.
Max
Quoted 4 lines
My suggestion is to not touch i2c-elektor at all for now, and remove the 'clock' parameter from the first iteration of i2c-icy. It can be added back in case someone complains, which I deem unlikely.
Full ack.
Quoted 5 lines
When the PCF8584 is addressed as slave, this register must be loaded with the 7-bit I 2 C-bus address to which the PCF8584 is to respond. During initialization, the own address register S0' must be written to, regardless whether it is later used.
I see. It must be written a non-zero value to leave the monitor mode. But this really needs no callback, we can hardcode any non-zero value. If slave support is (ever) to be implemented, the own address will come from the I2C core.
Quoted 4 lines
Okay, so we don't care. Cool, then it's safe to kick the 'clock' parameter from i2c-icy. All 2019 boards (which should be the vast majority in existence) came with a 12 MHz oscillator AFAIK, so the default should be good.
Most drivers don't allow users to change the bus speed, so I think it is safe to remove.
Max Staudt
maintainerQuoted 10 lines · Wolfram Sang
Quoted 5 lines
When the PCF8584 is addressed as slave, this register must be loaded with the 7-bit I 2 C-bus address to which the PCF8584 is to respond. During initialization, the own address register S0' must be written to, regardless whether it is later used.
I see. It must be written a non-zero value to leave the monitor mode. But this really needs no callback, we can hardcode any non-zero value. If slave support is (ever) to be implemented, the own address will come from the I2C core.
The callback, just like getclock(), is from the existing i2c-algo-pcf, which I don't want to touch right now. So I'm afraid it has to stay, even if it returns a fixed number.
Touching or forking i2c-algo-pcf will be necessary in order to implement IRQ support, if I ever get around to it. I've wasted too much time on debugging IRQ support, and would rather do it another time, if ever ;) I've left a comment block at the start of i2c-icy.c for anyone interested in the gory details.
If this is okay with you, I'll send another round of patches. :)
Thanks!
Max
Quoted 4 lines
The callback, just like
getclock(), is from the existing i2c-algo-pcf, which I don't want to touch right now. So I'm afraid it has to stay, even if it returns a fixed number.
Sure. I was just thinking loud and did not expect you to do it. Maybe I will do it once your driver is upstream.
Quoted 5 lines
Touching or forking i2c-algo-pcf will be necessary in order to implement IRQ support, if I ever get around to it. I've wasted too much time on debugging IRQ support, and would rather do it another time, if ever ;) I've left a comment block at the start of
i2c-icy.cfor anyone interested in the gory details.
Yeah, I read it. I like such documentation. Really helpful!
Quoted 1 line
If this is okay with you, I'll send another round of patches. :)
Perfect!