Re: [PATCH] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-29 Thread Max Staudt
On 08/29/2019 09:00 PM, Wolfram Sang wrote:
> Thanks for the changelog; it should go below the '---' line, however.

Thanks if you fixed it up!


> Fixed a freshly introduced checkpatch warning for you.

Ditto.


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

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



Max


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

2019-08-20 Thread Max Staudt
On 08/20/2019 05:07 PM, Guenter Roeck wrote:
> On Mon, Aug 19, 2019 at 02:16:17PM +0200, Max Staudt wrote:
>> 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().
>>
>> Signed-off-by: Max Staudt 
>> Reviewed-by: Geert Uytterhoeven 
> 
> Applied to hwmon-next.
> 
> Thanks,
> Guenter

Thanks for your help, reviewing, and applying!

Max


Re: [PATCH v5 1/3] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-20 Thread Max



On August 20, 2019 11:08:00 AM GMT+02:00, Geert Uytterhoeven 
 wrote:
>> +   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


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

2019-08-19 Thread 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().

Signed-off-by: Max Staudt 
---
 drivers/hwmon/ltc2990.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
index f9431ad43..53ff50517 100644
--- a/drivers/hwmon/ltc2990.c
+++ b/drivers/hwmon/ltc2990.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #define LTC2990_STATUS 0x00
 #define LTC2990_CONTROL0x01
@@ -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(>dev)) {
+   ret = device_property_read_u32_array(>dev,
+"lltc,meas-mode",
+data->mode, 2);
if (ret < 0)
return ret;
 
-- 
2.11.0



[PATCH v5 1/3] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-19 Thread 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.

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

Signed-off-by: Max Staudt 
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 1be025959..70336c083 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7705,6 +7705,12 @@ S:   Maintained
 F: drivers/mfd/lpc_ich.c
 F: drivers/gpio/gpio-ich.c
 
+ICY I2C DRIVER
+M: Max Staudt 
+L: linux-...@vger.kernel.org
+S: Maintained
+F: drivers/i2c/busses/i2c-icy.c
+
 IDE SUBSYSTEM
 M: "David S. Miller" 
 L: linux-...@vger.kernel.org
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ee5dfb5ae..9e57e1101 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a3245231b..d0e1c3d4e 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -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
diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
new file mode 100644
index 0..20c0fbacf
--- /dev/null
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * I2C driver for stand-alone PCF8584 style adapters on Zorro cards
+ *
+ * Original ICY documentation can be found on Aminet:
+ * https://aminet.net/package/docs/hard/icy
+ *
+ * There has been a modern community re-print of this design in 2019:
+ * https://www.a1k.org/forum/index.php?threads/70106/
+ *
+ * The card is basically a Philips PCF8584 connected straight to the
+ * beginning of the AutoConfig'd address space (register S1 on base+2),
+ * with /INT on /INT2 on the Zorro bus.
+ *
+ * Copyright (c) 2019 Max Staudt 
+ *
+ * This started as a fork of i2c-elektor.c and has evolved since.
+ * Thanks go to its authors for providing a base to grow on.
+ *
+ *
+ * IRQ support is currently not implemented.
+ *
+ * As it turns out, i2c-algo-pcf is really written with i2c-elektor's
+ * edge-triggered ISA interrupts in mind, while the Amiga's Zorro bus has
+ * level-triggered interrupts. This means that once an interrupt occurs, we
+ * have to tell the PCF8584 to shut up immediately, or it will keep the
+ * interrupt line busy and cause an IRQ storm.
+
+ * However, because of the PCF8584's host-side protocol, there is no good
+ * way to just quieten it without side effects. Rather, we have to perform
+ * the next read/write operation straight away, which will reset the /INT
+ * pin. This entails re-designing the core of i2c-algo-pcf in the future.
+ * For now, we never request an IRQ from the PCF8584, and poll it instead.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include "../algos/i2c-algo-pcf.h"
+
+struct icy_i2c {
+   struct i2c_adapter adapter;
+
+   void __iomem *reg_s0;
+   void __iomem *reg_s1;
+};
+
+/*
+ * Functions called by i2c-algo-pcf
+ */
+static void icy_pcf_setpcf(void *data, int ctl, int val)
+{
+   struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+   u8 __iomem *a

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

2019-08-19 Thread Max Staudt
On 08/16/2019 06:09 PM, Wolfram Sang wrote:
> 
>>> Braces for both blocks. Did you run checkpatch?
>>
>> I did, and it didn't say anything.
> 
> Hmm, strange, does is complain when you use '--strict'?

Yes, --strict catches it. Thanks, I didn't know about that parameter.

I'll send a v5 with all requested fixes.


Max


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

2019-08-16 Thread 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().

Signed-off-by: Max Staudt 
---
 drivers/hwmon/ltc2990.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
index f9431ad43..53ff50517 100644
--- a/drivers/hwmon/ltc2990.c
+++ b/drivers/hwmon/ltc2990.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #define LTC2990_STATUS 0x00
 #define LTC2990_CONTROL0x01
@@ -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(>dev)) {
+   ret = device_property_read_u32_array(>dev,
+"lltc,meas-mode",
+data->mode, 2);
if (ret < 0)
return ret;
 
-- 
2.11.0



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

2019-08-16 Thread 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.

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.

Signed-off-by: Max Staudt 
---
 drivers/i2c/busses/Kconfig   |  3 +++
 drivers/i2c/busses/i2c-icy.c | 58 
 2 files changed, 61 insertions(+)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9e57e1101..a311d07f3 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
index edac515da..c30431653 100644
--- a/drivers/i2c/busses/i2c-icy.c
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -54,6 +54,8 @@ struct icy_i2c {
 
void __iomem *reg_s0;
void __iomem *reg_s1;
+   struct fwnode_handle *ltc2990_fwnode;
+   struct i2c_client *ltc2990_client;
 };
 
 
@@ -100,11 +102,35 @@ static void icy_pcf_waitforpin(void *data)
 /*
  * Main i2c-icy part
  */
+static unsigned short const icy_ltc2990_addresses[] = {
+   0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END
+};
+
+/*
+ * Additional sensors exposed once this property is applied:
+ *
+ * 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.
+ */
+static const u32 icy_ltc2990_meas_mode[] = {0, 3};
+
+static const struct property_entry icy_ltc2990_props[] = {
+   PROPERTY_ENTRY_U32_ARRAY("lltc,meas-mode", icy_ltc2990_meas_mode),
+   { }
+};
+
+
 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;
+   struct fwnode_handle *new_fwnode;
+   struct i2c_board_info ltc2990_info = {
+   .type   = "ltc2990",
+   .addr   = 0x4c,
+   };
 
 
i2c = devm_kzalloc(>dev, sizeof(*i2c), GFP_KERNEL);
@@ -147,6 +173,35 @@ static int icy_probe(struct zorro_dev *z,
dev_info(>dev, "ICY I2C controller at %pa, IRQ not implemented\n",
 >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(>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;
+
+   i2c->ltc2990_client =
+   i2c_new_probed_device(>adapter,
+ _info,
+ icy_ltc2990_addresses,
+ NULL);
+   }
+
return 0;
 }
 
@@ -154,6 +209,9 @@ static void icy_remove(struct zorro_dev *z)
 {
struct icy_i2c *i2c = dev_get_drvdata(>dev);
 
+   i2c_unregister_device(i2c->ltc2990_client);
+   fwnode_remove_software_node(i2c->ltc2990_fwnode);
+
i2c_del_adapter(>adapter);
 }
 
-- 
2.11.0



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

2019-08-16 Thread Max Staudt
On 08/16/2019 02:36 PM, Geert Uytterhoeven wrote:
> Hi Max,
> 
> On Fri, Aug 16, 2019 at 2:25 PM Max Staudt  wrote:
>> On 08/16/2019 01:07 PM, Geert Uytterhoeven wrote:
>>> One minor nit: as the driver no longer uses any of_*() symbols, you can 
>>> replace
>>> #include  by #include .
>>
>> I should have thought of that, sorry.
>>
>> Another patch, or will you do it?
> 
> As the patch won't go through my tree, I cannot, but the hwmon maintainer
> might do.

As I'll be fixing one of the I2C patches, I'll send an updated hwmon patch with 
it.


Thanks!
Max


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

2019-08-16 Thread Max Staudt
On 08/16/2019 01:51 PM, Wolfram Sang wrote:
> 
>> +if (IS_ERR(new_fwnode))
>> +dev_info(>dev, "Failed to create fwnode for LTC2990, error: 
>> %ld\n",
>> + PTR_ERR(new_fwnode));
>> +else {
> 
> Braces for both blocks. Did you run checkpatch?

I did, and it didn't say anything.

Turns out I misremembered the CodingStyle as having a corner case where it 
doesn't. I'll fix the style - I dislike the above, too ;)


>> +/*
>> + * 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;
>> +
>> +i2c->ltc2990_client =
>> +i2c_new_probed_device(>adapter,
>> +  _info,
>> +  icy_ltc2990_addresses,
>> +  NULL);
> 
> i2c_new_device (or better, the new i2c_new_client_device) should be
> sufficient, or? You only have one potential address.

Yes and no. Now that you mention it - the LTC2990 can be at four addresses 
(0x4c - 0x4f), and there are jumpers (solder pads) on the PCB to select its 
address. Shall I add all 4 addresses to the array?

It's also possible that there is no LTC2990 at all (because it's hard to solder 
at home), and that's why we need to probe for it first. I believe 
i2c_new[_client]_device doesn't do probing, but rather assumes the device to be 
there. Correct?


Max


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

2019-08-16 Thread Max Staudt
On 08/16/2019 01:07 PM, Geert Uytterhoeven wrote:
> Reviewed-by: Geert Uytterhoeven 

Thank you!


> One minor nit: as the driver no longer uses any of_*() symbols, you can 
> replace
> #include  by #include .

I should have thought of that, sorry.

Another patch, or will you do it?


Max


[PATCH] hwmon/ltc2990: Generalise DT to fwnode support

2019-08-16 Thread 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().

Signed-off-by: Max Staudt 
---
 drivers/hwmon/ltc2990.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
index f9431ad43..ff11189ea 100644
--- a/drivers/hwmon/ltc2990.c
+++ b/drivers/hwmon/ltc2990.c
@@ -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(>dev)) {
+   ret = device_property_read_u32_array(>dev,
+"lltc,meas-mode",
+data->mode, 2);
if (ret < 0)
return ret;
 
-- 
2.11.0



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

2019-08-16 Thread Max Staudt
On 08/16/2019 12:43 AM, Guenter Roeck wrote:
> On Fri, Aug 16, 2019 at 12:19:42AM +0200, Max Staudt wrote:
>> On 08/15/2019 02:58 PM, Max Staudt wrote:
>>> -   if (of_node) {
>>> -   ret = of_property_read_u32_array(of_node, "lltc,meas-mode",
>>> -data->mode, 2);
>>> +   if (i2c->dev.of_node || i2c->dev.fwnode) {
>>
>> One more idea, would it be better here to do the following?
>>
>>  if (device_property_present(i2c->dev, "lltc,meas-mode")) {
>>  ret = of_property_read_u32_array(of_node, "lltc,meas-mode",
>>   data->mode, 2);
>>  }
>>
>> I'm happy to prepare a patch if you wish to have this in - just let me know 
>> whether it should be on top of the last one, or instead of it.
> 
> That would be semantically different. The property is currently mandatory.
> The above code would make it optional. This might work:
> 
>   if (dev_fwnode(>dev)) {
>   ret = device_property_read_u32_array(...);
>   ...
>   }

Fair point. The semantic change was part of my question, but the more I think 
about it, the less I want to open this can of worms. We can still make the 
property optional later on, while it's not as easy to make it mandatory.

I'll send a patch with your suggestion.

Thanks!
Max


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

2019-08-15 Thread Max Staudt
On 08/15/2019 08:33 PM, Guenter Roeck wrote:
> On Thu, Aug 15, 2019 at 02:58:01PM +0200, Max Staudt wrote:
>> 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.
>>
>> Signed-off-by: Max Staudt 
> 
> Applied to hwmon-next.

Hi Guenter,

Thank you for reviewing and taking this patch, as well as teaching me about 
swnode.


Max


[PATCH v3 1/3] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-15 Thread 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.

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

Signed-off-by: Max Staudt 
---
 MAINTAINERS  |   6 ++
 drivers/i2c/busses/Kconfig   |  11 +++
 drivers/i2c/busses/Makefile  |   1 +
 drivers/i2c/busses/i2c-icy.c | 183 +++
 4 files changed, 201 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-icy.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 1be025959..70336c083 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7705,6 +7705,12 @@ S:   Maintained
 F: drivers/mfd/lpc_ich.c
 F: drivers/gpio/gpio-ich.c
 
+ICY I2C DRIVER
+M: Max Staudt 
+L: linux-...@vger.kernel.org
+S: Maintained
+F: drivers/i2c/busses/i2c-icy.c
+
 IDE SUBSYSTEM
 M: "David S. Miller" 
 L: linux-...@vger.kernel.org
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ee5dfb5ae..9e57e1101 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a3245231b..d0e1c3d4e 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -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
diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
new file mode 100644
index 0..edac515da
--- /dev/null
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * I2C driver for stand-alone PCF8584 style adapters on Zorro cards
+ *
+ * Original ICY documentation can be found on Aminet:
+ * https://aminet.net/package/docs/hard/icy
+ *
+ * There has been a modern community re-print of this design in 2019:
+ * https://www.a1k.org/forum/index.php?threads/70106/
+ *
+ * The card is basically a Philips PCF8584 connected straight to the
+ * beginning of the AutoConfig'd address space (register S1 on base+2),
+ * with /INT on /INT2 on the Zorro bus.
+ *
+ * Copyright (c) 2019 Max Staudt 
+ *
+ * This started as a fork of i2c-elektor.c and has evolved since.
+ * Thanks go to its authors for providing a base to grow on.
+ *
+ *
+ * IRQ support is currently not implemented.
+ *
+ * As it turns out, i2c-algo-pcf is really written with i2c-elektor's
+ * edge-triggered ISA interrupts in mind, while the Amiga's Zorro bus has
+ * level-triggered interrupts. This means that once an interrupt occurs, we
+ * have to tell the PCF8584 to shut up immediately, or it will keep the
+ * interrupt line busy and cause an IRQ storm.
+
+ * However, because of the PCF8584's host-side protocol, there is no good
+ * way to just quieten it without side effects. Rather, we have to perform
+ * the next read/write operation straight away, which will reset the /INT
+ * pin. This entails re-designing the core of i2c-algo-pcf in the future.
+ * For now, we never request an IRQ from the PCF8584, and poll it instead.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include "../algos/i2c-algo-pcf.h"
+
+
+struct icy_i2c {
+   struct i2c_adapter adapter;
+
+   void __iomem *reg_s0;
+   void __iomem *reg_s1;
+};
+
+
+
+/*
+ * Functions called by i2c-algo-pcf
+ */
+static void icy_pcf_setpcf(void *data, int ctl, int val)
+{
+   struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+   u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
+
+ 

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

2019-08-15 Thread 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.

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

Signed-off-by: Max Staudt 
---
 drivers/i2c/busses/Kconfig   |  3 +++
 drivers/i2c/busses/i2c-icy.c | 56 
 2 files changed, 59 insertions(+)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9e57e1101..a311d07f3 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
index edac515da..c43cd170f 100644
--- a/drivers/i2c/busses/i2c-icy.c
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -54,6 +54,8 @@ struct icy_i2c {
 
void __iomem *reg_s0;
void __iomem *reg_s1;
+   struct fwnode_handle *ltc2990_fwnode;
+   struct i2c_client *ltc2990_client;
 };
 
 
@@ -100,11 +102,33 @@ static void icy_pcf_waitforpin(void *data)
 /*
  * Main i2c-icy part
  */
+static unsigned short const icy_ltc2990_addresses[] = {0x4c, I2C_CLIENT_END};
+
+/*
+ * Additional sensors exposed once this property is applied:
+ *
+ * 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.
+ */
+static const u32 icy_ltc2990_meas_mode[] = {0, 3};
+
+static const struct property_entry icy_ltc2990_props[] = {
+   PROPERTY_ENTRY_U32_ARRAY("lltc,meas-mode", icy_ltc2990_meas_mode),
+   { }
+};
+
+
 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;
+   struct fwnode_handle *new_fwnode;
+   struct i2c_board_info ltc2990_info = {
+   .type   = "ltc2990",
+   .addr   = 0x4c,
+   };
 
 
i2c = devm_kzalloc(>dev, sizeof(*i2c), GFP_KERNEL);
@@ -147,6 +171,35 @@ static int icy_probe(struct zorro_dev *z,
dev_info(>dev, "ICY I2C controller at %pa, IRQ not implemented\n",
 >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(>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;
+
+   i2c->ltc2990_client =
+   i2c_new_probed_device(>adapter,
+ _info,
+ icy_ltc2990_addresses,
+ NULL);
+   }
+
return 0;
 }
 
@@ -154,6 +207,9 @@ static void icy_remove(struct zorro_dev *z)
 {
struct icy_i2c *i2c = dev_get_drvdata(>dev);
 
+   i2c_unregister_device(i2c->ltc2990_client);
+   fwnode_remove_software_node(i2c->ltc2990_fwnode);
+
i2c_del_adapter(>adapter);
 }
 
-- 
2.11.0



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

2019-08-15 Thread 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.

Signed-off-by: Max Staudt 
---
 drivers/hwmon/ltc2990.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
index f9431ad43..e06619ac9 100644
--- a/drivers/hwmon/ltc2990.c
+++ b/drivers/hwmon/ltc2990.c
@@ -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 (i2c->dev.of_node || i2c->dev.fwnode) {
+   ret = device_property_read_u32_array(>dev,
+"lltc,meas-mode",
+data->mode, 2);
if (ret < 0)
return ret;
 
-- 
2.11.0



Re: [PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-15 Thread Max Staudt
On 08/15/2019 02:04 PM, Wolfram Sang wrote:
>>   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


Re: [PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-15 Thread Max
On 08/15/2019 01:48 PM, Wolfram Sang wrote:
>> 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.


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


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


Re: [PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-15 Thread Max Staudt
On 08/15/2019 09:12 AM, Wolfram Sang wrote:
>> 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


Re: [PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-14 Thread Max Staudt
Hi Wolfram,

Thanks for your input!
Replies below.


On 08/14/2019 09:47 PM, Wolfram Sang wrote:
>> +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.


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


>> +algo_data->data = (void *)i2c;
> 
> You don't need the cast, do you?

True. Dropped, thanks.


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


Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support

2019-08-14 Thread Max Staudt
Hi Guenter,

Thanks for your feedback!
Reply below.


On 08/13/2019 03:24 PM, Guenter Roeck wrote:
> 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 ?

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


Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support

2019-08-13 Thread Max
On 08/13/2019 03:24 PM, Guenter Roeck wrote:
> 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 ?

Sorry, I was unaware of this option. This sounds good, I'll look into it.

Max


Re: [PATCH v2 3/4] hwmon/ltc2990: Add platform_data support

2019-08-13 Thread Max Staudt
On 08/13/2019 10:02 AM, Guenter Roeck wrote:
> On Tue, Aug 13, 2019 at 01:52:36AM +0200, Max Staudt wrote:
>> This allows code using i2c_new_device() to specify a measurement mode.
>>
>> Signed-off-by: Max Staudt 
>> Reviewed-by: Geert Uytterhoeven 
>> ---
>>  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
>>
>> diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
>> index f9431ad43..f19b9c50c 100644
>> --- a/drivers/hwmon/ltc2990.c
>> +++ b/drivers/hwmon/ltc2990.c
>> @@ -14,6 +14,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #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(>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;
> 
> 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


Re: [PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-13 Thread Max Staudt
On 08/13/2019 09:08 AM, Geert Uytterhoeven wrote:
>> +   dev_info(>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

Ack, this snuck in from the early days. Thanks for pointing this out!


Max


Re: [PATCH v2 2/4] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

2019-08-13 Thread Max Staudt
On 08/13/2019 09:03 AM, Geert Uytterhoeven wrote:
> Hi Max,
> 
> On Tue, Aug 13, 2019 at 1:53 AM Max Staudt  wrote:
>> 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 
> 
> Thanks for your patch!
> 
>> --- a/drivers/i2c/busses/i2c-icy.c
>> +++ b/drivers/i2c/busses/i2c-icy.c
>> @@ -160,6 +180,8 @@ static void icy_remove(struct zorro_dev *z)
>>  {
>> struct icy_i2c *i2c = dev_get_drvdata(>dev);
>>
>> +   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(>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


[PATCH v2 4/4] i2c/busses/i2c-icy: Add platform_data for LTC2990

2019-08-12 Thread 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 
---
 drivers/i2c/busses/i2c-icy.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
index 8125683c5..6ad9910a0 100644
--- a/drivers/i2c/busses/i2c-icy.c
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -42,6 +42,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -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  = _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(>adapter,
_ltc2990_info,
-- 
2.11.0



[PATCH v2 3/4] hwmon/ltc2990: Add platform_data support

2019-08-12 Thread Max Staudt
This allows code using i2c_new_device() to specify a measurement mode.

Signed-off-by: Max Staudt 
---
 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

diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c
index f9431ad43..f19b9c50c 100644
--- a/drivers/hwmon/ltc2990.c
+++ b/drivers/hwmon/ltc2990.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define LTC2990_STATUS 0x00
 #define LTC2990_CONTROL0x01
@@ -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(>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)
diff --git a/include/linux/platform_data/ltc2990.h 
b/include/linux/platform_data/ltc2990.h
new file mode 100644
index 0..7ec89e784
--- /dev/null
+++ b/include/linux/platform_data/ltc2990.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LTC2990_PDATA_H
+#define LTC2990_PDATA_H
+
+#include 
+
+struct ltc2990_platform_data {
+   u8 meas_mode[2];
+};
+
+#endif /* LTC2990_PDATA_H */
-- 
2.11.0



[PATCH v2 1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga

2019-08-12 Thread 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.

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

Signed-off-by: Max Staudt 
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 1be025959..70336c083 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7705,6 +7705,12 @@ S:   Maintained
 F: drivers/mfd/lpc_ich.c
 F: drivers/gpio/gpio-ich.c
 
+ICY I2C DRIVER
+M: Max Staudt 
+L: linux-...@vger.kernel.org
+S: Maintained
+F: drivers/i2c/busses/i2c-icy.c
+
 IDE SUBSYSTEM
 M: "David S. Miller" 
 L: linux-...@vger.kernel.org
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ee5dfb5ae..9e57e1101 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a3245231b..d0e1c3d4e 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -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
diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
new file mode 100644
index 0..7910f035b
--- /dev/null
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * I2C driver for stand-alone PCF8584 style adapters on Zorro cards
+ *
+ * Original ICY documentation can be found on Aminet:
+ * https://aminet.net/package/docs/hard/icy
+ *
+ * There has been a modern community re-print of this design in 2019:
+ * https://www.a1k.org/forum/index.php?threads/70106/
+ *
+ * The card is basically a Philips PCF8584 connected straight to the
+ * beginning of the AutoConfig'd address space (register S1 on base+2),
+ * with /INT on /INT2 on the Zorro bus.
+ *
+ * Copyright (c) 2019 Max Staudt 
+ *
+ * This started as a fork of i2c-elektor.c and has evolved since.
+ * Thanks go to its authors for providing a base to grow on.
+ *
+ *
+ * IRQ support is currently not implemented.
+ *
+ * As it turns out, i2c-algo-pcf is really written with i2c-elektor's
+ * edge-triggered ISA interrupts in mind, while the Amiga's Zorro bus has
+ * level-triggered interrupts. This means that once an interrupt occurs, we
+ * have to tell the PCF8584 to shut up immediately, or it will keep the
+ * interrupt line busy and cause an IRQ storm.
+
+ * However, because of the PCF8584's host-side protocol, there is no good
+ * way to just quieten it without side effects. Rather, we have to perform
+ * the next read/write operation straight away, which will reset the /INT
+ * pin. This entails re-designing the core of i2c-algo-pcf in the future.
+ * For now, we never request an IRQ from the PCF8584, and poll it instead.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include "../algos/i2c-algo-pcf.h"
+
+
+static int clock = 0x1c;
+module_param(clock, int, 0444);
+
+
+
+struct icy_i2c {
+   struct i2c_adapter adapter;
+
+   void __iomem *reg_s0;
+   void __iomem *reg_s1;
+};
+
+
+
+/*
+ * Functions called by i2c-algo-pcf
+ */
+static void icy_pcf_setpcf(void *data, int ctl, int val)
+{
+   struct icy_i2c *i2c = (struct icy_i2c *)data;
+
+   u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
+
+   z_writeb(val, address);
+}
+

[PATCH v2 2/4] i2c/busses/i2c-icy: Add LTC2990 present on 2019 board revision

2019-08-12 Thread 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 
---
 drivers/i2c/busses/i2c-icy.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c
index 7910f035b..8125683c5 100644
--- a/drivers/i2c/busses/i2c-icy.c
+++ b/drivers/i2c/busses/i2c-icy.c
@@ -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(>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(>adapter,
+   _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(>dev);
 
+   i2c_unregister_device(i2c->client_ltc2990);
+
i2c_del_adapter(>adapter);
 }
 
-- 
2.11.0