diff mbox series

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

Message ID 20190812235237.21797-2-max@enpas.org
State Changes Requested
Headers show
Series [v2,1/4] i2c/busses: Add i2c-icy for I2C on m68k/Amiga | expand

Commit Message

Max Staudt Aug. 12, 2019, 11:52 p.m. UTC
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 <max@enpas.org>
---
 drivers/i2c/busses/i2c-icy.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Geert Uytterhoeven Aug. 13, 2019, 7:03 a.m. UTC | #1
Hi Max,

On Tue, Aug 13, 2019 at 1:53 AM Max Staudt <max@enpas.org> 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 <max@enpas.org>

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

> +
>         i2c_del_adapter(&i2c->adapter);
>  }

Gr{oetje,eeting}s,

                        Geert
Max Staudt Aug. 13, 2019, 9:49 a.m. UTC | #2
On 08/13/2019 09:03 AM, Geert Uytterhoeven wrote:
> Hi Max,
> 
> On Tue, Aug 13, 2019 at 1:53 AM Max Staudt <max@enpas.org> 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 <max@enpas.org>
> 
> 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(&z->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(&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
Wolfram Sang Aug. 14, 2019, 7:52 p.m. UTC | #3
> 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?

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.
diff mbox series

Patch

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(&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);
 }