Skip to contentSkip to conversation

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

PATCH Superseded Max Staudt 2 participants 8 messages Aug 11, 2019 – Aug 13, 2019

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Max Staudt

author maintainer
#0 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

Since the 2019 a1k.org community re-print of these PCBs sports an LTC2990 hwmon chip as an example use case, this driver autoprobes for that as well. If it is present, modprobing ltc2990 is sufficient.

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.

---
 MAINTAINERS                  |   6 ++
 drivers/i2c/busses/Kconfig   |  11 +++
 drivers/i2c/busses/Makefile  |   1 +
 drivers/i2c/busses/i2c-icy.c | 224 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 242 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..e798b8517 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 && BROKEN_ON_SMP
+	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 +224 -0

224 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#1 lore raw

drivers/i2c/busses/Kconfig config I2C_ELEKTOR · line 1306

Quoted 10 lines · Max Staudt
drivers/i2c/busses/Kconfig +4 -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 && BROKEN_ON_SMP
+	select I2C_ALGOPCF

I forgot to remove BROKEN_ON_SMP - I see no reason why this would be the case with the polling-only driver as it is now.

Max

#2 lore raw
In reply to Max Staudt

Hi Max,

Thanks for your patch!

Quoted 9 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

Since the 2019 a1k.org community re-print of these PCBs sports an LTC2990 hwmon chip as an example use case, this driver autoprobes for that as well. If it is present, modprobing ltc2990 is sufficient.

What about the RTC? The schematics show both a ds1620 and pcf8583.

Quoted 5 lines

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.

This tag is usually implied for a driver author ;-)

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

Quoted 9 lines
drivers/i2c/busses/i2c-icy.c new file +4 -0
 
+/*
+ * Functions called by i2c-algo-pcf
+ */
+static void icy_pcf_setbyte(void *data, int ctl, int val)

icy_pcf_setpcf(), to match the callback name?

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

Quoted 6 lines
drivers/i2c/busses/i2c-icy.c new file +6 -0
+{
+       struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+       u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
+
+       iowrite8(val, address);

As this is on a Zorro bus, z_writeb()?

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

Quoted 3 lines
drivers/i2c/busses/i2c-icy.c new file +3 -0
+}
+
+static int icy_pcf_getbyte(void *data, int ctl)

icy_pcf_getpcf(), to match the callback name?

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

Quoted 5 lines
drivers/i2c/busses/i2c-icy.c new file +5 -0
+{
+       struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+       u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
+       int val = ioread8(address);

z_readb()

Quoted 21 lines
drivers/i2c/busses/i2c-icy.c new file +20 -0
+
+       return val;
+}
 
+static int icy_probe(struct zorro_dev *z,
+                        const struct zorro_device_id *ent)
+{
+       struct icy_i2c *i2c;
+       struct i2c_algo_pcf_data *algo_data;
+
+
+       i2c = devm_kzalloc(&z->dev, sizeof(*i2c), GFP_KERNEL);
+       if (!i2c)
+               return -ENOMEM;
+
+       algo_data = devm_kzalloc(&z->dev, sizeof(*algo_data), GFP_KERNEL);
+       if (!algo_data)
+               return -ENOMEM;
+
+       dev_set_drvdata(&z->dev, i2c);
+       i2c->adapter.dev.parent = &z->dev;

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

Quoted 10 lines
drivers/i2c/busses/i2c-icy.c new file +10 -0
+       i2c->adapter.owner = THIS_MODULE;
+       i2c->adapter.class = I2C_CLASS_DEPRECATED;
+       /* i2c->adapter.algo assigned by i2c_pcf_add_bus() */
+       i2c->adapter.algo_data = algo_data;
+       strlcpy(i2c->adapter.name, "ICY I2C Zorro adapter",
+               sizeof(i2c->adapter.name));
+
+       if (!devm_request_mem_region(&z->dev,
+                                    z->resource.start,
+                                    4, i2c->adapter.name))

zorro_request_device()?
Ah, there's no devm_*() variant yet. OK.

Quoted 21 lines
drivers/i2c/busses/i2c-icy.c new file +21 -0
+               return -ENXIO;
+
+       /* Driver private data */
+       i2c->reg_s0 = ZTWO_VADDR(z->resource.start);
+       i2c->reg_s1 = ZTWO_VADDR(z->resource.start + 2);
+
+       algo_data->data = (void *)i2c;
+       algo_data->setpcf     = icy_pcf_setbyte;
+       algo_data->getpcf     = icy_pcf_getbyte;
+       algo_data->getown     = icy_pcf_getown;
+       algo_data->getclock   = icy_pcf_getclock;
+       algo_data->waitforpin = icy_pcf_waitforpin;
+
+       if (i2c_pcf_add_bus(&i2c->adapter)) {
+               dev_err(&z->dev, "i2c_pcf_add_bus() failed\n");
+               return -ENXIO;
+       }
+
+       dev_info(&z->dev, "ICY I2C controller at %#x, IRQ not implemented\n",
+                z->resource.start);
+

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

Quoted 10 lines
drivers/i2c/busses/i2c-icy.c new file +10 -0
+       /*
+        * 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.
+        *
+        * Configuration 0x18 enables all sensors on this PCB:
+        *  # modprobe i2c-dev
+        *  # i2cset 0 0x4c 1 0x18

What's the reason for the i2cset command?

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

Quoted 12 lines
drivers/i2c/busses/i2c-icy.c new file +12 -0
+        *  # modprobe ltc2990
+        * 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.
+        */
+       i2c->client_ltc2990 = i2c_new_probed_device(&i2c->adapter,
+                                                   &icy_ltc2990_info,
+                                                   icy_ltc2990_addresses,
+                                                   NULL);
+
+       return 0;
+}

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

Hi Geert,

Thanks for your feedback!
Replies below.

Quoted 1 line · Geert Uytterhoeven

What about the RTC? The schematics show both a ds1620 and pcf8583.

Oh no! I missed those in the original project, in my mind it didn't have any extra hardware at all.

I only own the new board with the LTC2990, and I'm pretty sure there are more of these in circulation than the original board. So if it's okay, I'll skip the DS1620 and PCF8583.

Quoted 3 lines
Quoted 1 line

+static void icy_pcf_setbyte(void *data, int ctl, int val)

icy_pcf_setpcf(), to match the callback name?

Fair. I kept the name when I cloned i2c-elektor.c.

Quoted 2 lines

zorro_request_device()?
Ah, there's no devm_*() variant yet. OK.

Also, I only wanted to reserve the first 4 bytes. Thinking about it now, it makes more sense to reserve the whole AutoConfig'd space, as I don't know whether the bus GAL maps the PCF8584 across the whole 64k repeatedly.

Quoted 11 lines

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

Quoted 10 lines
drivers/i2c/busses/i2c-icy.c new file +10 -0
+       /*
+        * 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.
+        *
+        * Configuration 0x18 enables all sensors on this PCB:
+        *  # modprobe i2c-dev
+        *  # i2cset 0 0x4c 1 0x18
Quoted 1 line

What's the reason for the i2cset command?

It sets the sensor modes in the LTC2990 and enables the three sensors listed below. I should have clarified this.

I tried to integrate this in the driver, but ltc2990 only allows reading this configuration out of a device tree. Is there a good way to fake a DT entry in the init function?

Quoted 13 lines

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

Quoted 13 lines
drivers/i2c/busses/i2c-icy.c new file +12 -0
+        *  # modprobe ltc2990
+        * 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.
+        */
+       i2c->client_ltc2990 = i2c_new_probed_device(&i2c->adapter,
+                                                   &icy_ltc2990_info,
+                                                   icy_ltc2990_addresses,
+                                                   NULL);
+
+       return 0;
+}

Thanks for your feedback,
Max

#4 lore raw

Hi Max,

Quoted 12 lines · Max Staudt
Quoted 11 lines · Geert Uytterhoeven
Quoted 10 lines
drivers/i2c/busses/i2c-icy.c new file +10 -0
+       /*
+        * 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.
+        *
+        * Configuration 0x18 enables all sensors on this PCB:
+        *  # modprobe i2c-dev
+        *  # i2cset 0 0x4c 1 0x18
Quoted 5 lines
Quoted 1 line

What's the reason for the i2cset command?

It sets the sensor modes in the LTC2990 and enables the three sensors listed below. I should have clarified this.

I tried to integrate this in the driver, but ltc2990 only allows reading this configuration out of a device tree. Is there a good way to fake a DT entry in the init function?

You can add platform_data support to the ltc2990 driver, and pass it through i2c_board_info.platform_data.

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
#5 lore raw
Quoted 6 lines · Geert Uytterhoeven
Quoted 3 lines

It sets the sensor modes in the LTC2990 and enables the three sensors listed below. I should have clarified this.

I tried to integrate this in the driver, but ltc2990 only allows reading this configuration out of a device tree. Is there a good way to fake a DT entry in the init function?

You can add platform_data support to the ltc2990 driver, and pass it through i2c_board_info.platform_data.

Thanks, that sounds good and I'll look into it.

Max

author maintainer
#6 lore raw
In reply to Geert Uytterhoeven
Quoted 3 lines · Geert Uytterhoeven
Quoted 1 line

+ iowrite8(val, address);

As this is on a Zorro bus, z_writeb()?

I forgot to ask about this.

What is the reasoning behind having a separate z_writeb() for Zorro?
As far as I can see in arch/m68k/include/asm this maps 1:1 to a direct memory access, and it prohibits cross-arch code as in i2c-elektor.

Thanks,
Max

#7 lore raw

Hi Max,

Quoted 9 lines · Max Staudt
Quoted 3 lines · Geert Uytterhoeven
Quoted 1 line

+ iowrite8(val, address);

As this is on a Zorro bus, z_writeb()?

I forgot to ask about this.

What is the reasoning behind having a separate z_writeb() for Zorro?
As far as I can see in arch/m68k/include/asm this maps 1:1 to a direct memory access, and it prohibits cross-arch code as in i2c-elektor.

write*() and friends are intended for PCI, and thus little endian, while the Zorro bus is big endian. For byte accesses this doesn't matter, obviously.

Note that this predates iowrite*(), which does have *be variants. If you want to add compile-testing to your driver, using iowrite*() is fine.

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