Skip to contentSkip to conversation

i2c/busses: Add i2c-icy for I2C on m68k/Amiga

PATCH Applied Max Staudt 4 participants 14 messages Aug 19, 2019 – Aug 29, 2019

Subsystems (3)
lore
Share & tools
lore

Max Staudt

author maintainer
#0 lore raw

PATCH v5 1/3 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.

v5: usleep_range() instead of udelay()
Style

v3: Fixed %pa format string
Dropped adapter class.
Clarified licence.
Removed clock parameter.

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 | 174 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 192 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-icy.c
MAINTAINERS +6 -0
index 1be025959..70336c083 100644
@@ -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
index ee5dfb5ae..9e57e1101 100644
@@ -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
index a3245231b..d0e1c3d4e 100644
@@ -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 +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH v5 2/3 hwmon/ltc2990: Generalise DT to fwnode support

ltc2990 will now use device_property_read_u32_array() instead of of_property_read_u32_array() - allowing the use of software nodes via fwnode_create_software_node().

This allows code using i2c_new_device() to specify a default measurement mode for the LTC2990 via fwnode_create_software_node().

---
 drivers/hwmon/ltc2990.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/hwmon/ltc2990.c +5 -5
index f9431ad43..53ff50517 100644
@@ -13,7 +13,7 @@
 #include <linux/i2c.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/of.h>
+#include <linux/property.h>
 
 #define LTC2990_STATUS	0x00
 #define LTC2990_CONTROL	0x01
@@ -206,7 +206,6 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,
 	int ret;
 	struct device *hwmon_dev;
 	struct ltc2990_data *data;
-	struct device_node *of_node = i2c->dev.of_node;
 
 	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
 				     I2C_FUNC_SMBUS_WORD_DATA))
@@ -218,9 +217,10 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,
 
 	data->i2c = i2c;
 
-	if (of_node) {
-		ret = of_property_read_u32_array(of_node, "lltc,meas-mode",
-						 data->mode, 2);
+	if (dev_fwnode(&i2c->dev)) {
+		ret = device_property_read_u32_array(&i2c->dev,
+						     "lltc,meas-mode",
+						     data->mode, 2);
 		if (ret < 0)
 			return ret;
 
Signature · 1 line
2.11.0
Reviewed-by on v5 2/3
#2 lore raw

Re: [PATCH v5 2/3] hwmon/ltc2990: Generalise DT to fwnode support

Quoted 8 lines · Max Staudt

ltc2990 will now use device_property_read_u32_array() instead of of_property_read_u32_array() - allowing the use of software nodes via fwnode_create_software_node().

This allows code using i2c_new_device() to specify a default measurement mode for the LTC2990 via fwnode_create_software_node().

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
maintainer Applied
#3 lore raw

Re: [PATCH v5 2/3] hwmon/ltc2990: Generalise DT to fwnode support

In reply to Max Staudt
Quoted 9 lines · Max Staudt

ltc2990 will now use device_property_read_u32_array() instead of of_property_read_u32_array() - allowing the use of software nodes via fwnode_create_software_node().

This allows code using i2c_new_device() to specify a default measurement mode for the LTC2990 via fwnode_create_software_node().

Applied to hwmon-next.

Thanks,
Guenter

Quoted 39 lines
---
 drivers/hwmon/ltc2990.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/hwmon/ltc2990.c +5 -5
index f9431ad43..53ff50517 100644
@@ -13,7 +13,7 @@
 #include <linux/i2c.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/of.h>
+#include <linux/property.h>
 
 #define LTC2990_STATUS	0x00
 #define LTC2990_CONTROL	0x01
@@ -206,7 +206,6 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,
 	int ret;
 	struct device *hwmon_dev;
 	struct ltc2990_data *data;
-	struct device_node *of_node = i2c->dev.of_node;
 
 	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
 				     I2C_FUNC_SMBUS_WORD_DATA))
@@ -218,9 +217,10 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c,
 
 	data->i2c = i2c;
 
-	if (of_node) {
-		ret = of_property_read_u32_array(of_node, "lltc,meas-mode",
-						 data->mode, 2);
+	if (dev_fwnode(&i2c->dev)) {
+		ret = device_property_read_u32_array(&i2c->dev,
+						     "lltc,meas-mode",
+						     data->mode, 2);
 		if (ret < 0)
 			return ret;
 
author maintainer
#4 lore raw

Re: [PATCH v5 2/3] hwmon/ltc2990: Generalise DT to fwnode support

Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Max Staudt

ltc2990 will now use device_property_read_u32_array() instead of of_property_read_u32_array() - allowing the use of software nodes via fwnode_create_software_node().

This allows code using i2c_new_device() to specify a default measurement mode for the LTC2990 via fwnode_create_software_node().

Quoted 7 lines
Quoted 2 lines

Applied to hwmon-next.

Thanks,
Guenter

Thanks for your help, reviewing, and applying!

Max

author maintainer
#5 lore raw

PATCH v5 3/3 i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

In reply to 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.

The property_entry enables the three additional inputs available on this particular 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.

v5: Style

v4: Style
Added other possible addresses for LTC2990.

v3: Merged with initial LTC2990 support on ICY.
Moved defaults from platform_data to swnode.
Added note to Kconfig.

---
 drivers/i2c/busses/Kconfig   |  3 +++
 drivers/i2c/busses/i2c-icy.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
drivers/i2c/busses/Kconfig +3 -0
index 9e57e1101..a311d07f3 100644
@@ -1311,6 +1311,9 @@ config I2C_ICY
 	  This support is also available as a module.  If so, the module
 	  will be called i2c-icy.
 
+	  If you have a 2019 edition board with an LTC2990 sensor at address
+	  0x4c, loading the module 'ltc2990' is sufficient to enable it.
+
 config I2C_MLXCPLD
 	tristate "Mellanox I2C driver"
 	depends on X86_64
drivers/i2c/busses/i2c-icy.c +57 -0

86 lines not on this page · raw message

Signature · 1 line
2.11.0
Reviewed-by on v5 3/3
#6 lore raw

Re: [PATCH v5 3/3] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

Quoted 13 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.

The property_entry enables the three additional inputs available on this particular 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.

v5: Style

Quoted 8 lines

v4: Style
Added other possible addresses for LTC2990.

v3: Merged with initial LTC2990 support on ICY.
Moved defaults from platform_data to swnode.
Added note to Kconfig.

One comment below...

Quoted 28 lines
drivers/i2c/busses/i2c-icy.c +21 -0
@@ -141,6 +166,35 @@ static int icy_probe(struct zorro_dev *z,
        dev_info(&z->dev, "ICY I2C controller at %pa, 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.
+        *
+        * See property_entry above for in1, in2, temp3.
+        */
+       new_fwnode = fwnode_create_software_node(icy_ltc2990_props, NULL);
+       if (IS_ERR(new_fwnode)) {
+               dev_info(&z->dev, "Failed to create fwnode for LTC2990, error: %ld\n",
+                        PTR_ERR(new_fwnode));
+       } else {
+               /*
+                * Store the fwnode so we can destroy it on .remove().
+                * Only store it on success, as fwnode_remove_software_node()
+                * is NULL safe, but not PTR_ERR safe.
+                */
+               i2c->ltc2990_fwnode = new_fwnode;
+               ltc2990_info.fwnode = new_fwnode;

drivers/i2c/busses/i2c-icy.c static int icy_probe(struct zorro_dev *z, · line 199

Quoted 10 lines
drivers/i2c/busses/i2c-icy.c +8 -0
+
+               i2c->ltc2990_client =
+                       i2c_new_probed_device(&i2c->adapter,
+                                             &ltc2990_info,
+                                             icy_ltc2990_addresses,
+                                             NULL);
+       }
+
        return 0;
 }

Since commit d3e1b617ae20c459 ("i2c: allow specify device properties in i2c_board_info"), the properties could be provided by info->properties, too. However, according to the comments for device_add_properties(), this is valid only if there is a real firmware node present.

If that is true, Max' use is correct, while e.g. commit 6a7836ba7fb4abf6 ("ARM: imx: pca100: use device properties for at24 eeprom") isn't?

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
author maintainer
#7 lore raw

Re: [PATCH v5 3/3] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

Quoted 9 lines · Geert Uytterhoeven

Since commit d3e1b617ae20c459 ("i2c: allow specify device properties in i2c_board_info"), the properties could be provided by info->properties, too.
However, according to the comments for device_add_properties(), this is valid only if there is a real firmware node present.

If that is true, Max' use is correct, while e.g. commit 6a7836ba7fb4abf6
("ARM: imx: pca100: use device properties for at24 eeprom") isn't?

Yup, I saw that too. Any hints would be greatly appreciated!

Max

Applied
#8 lore raw

Re: [PATCH v5 3/3] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

In reply to Max Staudt
Quoted 13 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.

The property_entry enables the three additional inputs available on this particular 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.

v5: Style

Quoted 8 lines

v4: Style
Added other possible addresses for LTC2990.

v3: Merged with initial LTC2990 support on ICY.
Moved defaults from platform_data to swnode.
Added note to Kconfig.

Applied to for-next, thanks!

Reviewed-by on v5 1/3
#9 lore raw
In reply to Max Staudt
Quoted 18 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.

v5: usleep_range() instead of udelay()
Style

v3: Fixed %pa format string
Dropped adapter class.
Clarified licence.
Removed clock parameter.

Quoted 6 lines

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

drivers/i2c/busses/i2c-icy.c line 77

Quoted 11 lines
drivers/i2c/busses/i2c-icy.c new file +8 -0
 
+static int icy_pcf_getpcf(void *data, int ctl)
+{
+       struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+       u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
+       int val = z_readb(address);
+
+       return val;

return z_readb(address);

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
author maintainer
#10 lore raw
Quoted 5 lines · Geert Uytterhoeven

drivers/i2c/busses/i2c-icy.c line 77

Quoted 3 lines
drivers/i2c/busses/i2c-icy.c new file +3 -0
+       int val = z_readb(address);
+
+       return val;

return z_readb(address);

Argh, that slipped through the cracks. I'll mend it later. Thank you.

Max

author maintainer
#11 lore raw

PATCH 1/1 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.

v5: usleep_range() instead of udelay()
Style

v3: Fixed %pa format string
Dropped adapter class.
Clarified licence.
Removed clock parameter.

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 | 172 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 190 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-icy.c
MAINTAINERS +6 -0
index 1be025959..70336c083 100644
@@ -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
index ee5dfb5ae..9e57e1101 100644
@@ -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
index a3245231b..d0e1c3d4e 100644
@@ -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 +172 -0

172 lines not on this page · raw message

Signature · 1 line
2.11.0
#12 lore raw
Quoted 18 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.

v5: usleep_range() instead of udelay()
Style

v3: Fixed %pa format string
Dropped adapter class.
Clarified licence.
Removed clock parameter.

Quoted 4 lines

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

Thanks for the changelog; it should go below the '---' line, however.

Quoted 2 lines

Fixed a freshly introduced checkpatch warning for you.

But most importantly, applied to for-next, thanks!

author maintainer
#13 lore raw
Quoted 1 line · Wolfram Sang

Thanks for the changelog; it should go below the '---' line, however.

Thanks if you fixed it up!

Quoted 1 line

Fixed a freshly introduced checkpatch warning for you.

Ditto.

Quoted 1 line

But most importantly, applied to for-next, thanks!

Thank you too for taking this, and Geert for the extra reviews.

Max