diff mbox series

[v5,4/8] hwmon: (amc6821) add support for tsd,mule

Message ID 20240708-dev-mule-i2c-mux-v5-4-71446d3f0b8d@cherry.de (mailing list archive)
State New
Headers show
Series Add tsd,mule-i2c-mux support | expand

Commit Message

Farouk Bouabid July 8, 2024, 4:12 p.m. UTC
Theobroma Systems Mule is an MCU that emulates a set of I2C devices,
among which is an amc6821 and other devices that are reachable through
an I2C-mux.

The devices on the mux can be selected by writing the appropriate device
number to an I2C config register (amc6821: reg 0xff)

Implement "tsd,mule" compatible to instantiate the I2C-mux platform device
when probing the amc6821.

Signed-off-by: Farouk Bouabid <farouk.bouabid@cherry.de>
---
 drivers/hwmon/amc6821.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Guenter Roeck July 8, 2024, 9:45 p.m. UTC | #1
On 7/8/24 09:12, Farouk Bouabid wrote:
> Theobroma Systems Mule is an MCU that emulates a set of I2C devices,
> among which is an amc6821 and other devices that are reachable through
> an I2C-mux.
> 
> The devices on the mux can be selected by writing the appropriate device
> number to an I2C config register (amc6821: reg 0xff)
> 
> Implement "tsd,mule" compatible to instantiate the I2C-mux platform device
> when probing the amc6821.
> 
> Signed-off-by: Farouk Bouabid <farouk.bouabid@cherry.de>
> ---
>   drivers/hwmon/amc6821.c | 25 ++++++++++++++++++++++++-
>   1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
> index 0661cc6a6f8e..93c3b79b5f13 100644
> --- a/drivers/hwmon/amc6821.c
> +++ b/drivers/hwmon/amc6821.c
> @@ -22,6 +22,7 @@
>   #include <linux/minmax.h>
>   #include <linux/module.h>
>   #include <linux/mutex.h>
> +#include <linux/of_platform.h>
>   #include <linux/regmap.h>
>   #include <linux/slab.h>
>   
> @@ -895,8 +896,17 @@ static const struct regmap_config amc6821_regmap_config = {
>   	.cache_type = REGCACHE_MAPLE,
>   };
>   
> +static const struct regmap_config amc6821_mule_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = 0xff,

Unnecessary since the maximum possible register address is 0xff.

> +	.volatile_reg = amc6821_volatile_reg,
> +	.cache_type = REGCACHE_MAPLE,
> +};
> +

Anyway, don't bother. Just drop max_register from amc6821_regmap_config.

Thanks,
Guenter

>   static int amc6821_probe(struct i2c_client *client)
>   {
> +	const struct regmap_config *config;
>   	struct device *dev = &client->dev;
>   	struct amc6821_data *data;
>   	struct device *hwmon_dev;
> @@ -907,7 +917,10 @@ static int amc6821_probe(struct i2c_client *client)
>   	if (!data)
>   		return -ENOMEM;
>   
> -	regmap = devm_regmap_init_i2c(client, &amc6821_regmap_config);
> +	config = of_device_is_compatible(dev->of_node, "tsd,mule") ?
> +		&amc6821_mule_regmap_config : &amc6821_regmap_config;
> +
> +	regmap = devm_regmap_init_i2c(client, config);
>   	if (IS_ERR(regmap))
>   		return dev_err_probe(dev, PTR_ERR(regmap),
>   				     "Failed to initialize regmap\n");
> @@ -917,6 +930,13 @@ static int amc6821_probe(struct i2c_client *client)
>   	if (err)
>   		return err;
>   
> +	if (of_device_is_compatible(dev->of_node, "tsd,mule")) {
> +		err = devm_of_platform_populate(dev);
> +		if (err)
> +			return dev_err_probe(dev, err,
> +				     "Failed to create sub-devices\n");
> +	}
> +
>   	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
>   							 data, &amc6821_chip_info,
>   							 amc6821_groups);
> @@ -934,6 +954,9 @@ static const struct of_device_id __maybe_unused amc6821_of_match[] = {
>   	{
>   		.compatible = "ti,amc6821",
>   	},
> +	{
> +		.compatible = "tsd,mule",
> +	},
>   	{ }
>   };
>   
>
diff mbox series

Patch

diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 0661cc6a6f8e..93c3b79b5f13 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -22,6 +22,7 @@ 
 #include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of_platform.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
@@ -895,8 +896,17 @@  static const struct regmap_config amc6821_regmap_config = {
 	.cache_type = REGCACHE_MAPLE,
 };
 
+static const struct regmap_config amc6821_mule_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = 0xff,
+	.volatile_reg = amc6821_volatile_reg,
+	.cache_type = REGCACHE_MAPLE,
+};
+
 static int amc6821_probe(struct i2c_client *client)
 {
+	const struct regmap_config *config;
 	struct device *dev = &client->dev;
 	struct amc6821_data *data;
 	struct device *hwmon_dev;
@@ -907,7 +917,10 @@  static int amc6821_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	regmap = devm_regmap_init_i2c(client, &amc6821_regmap_config);
+	config = of_device_is_compatible(dev->of_node, "tsd,mule") ?
+		&amc6821_mule_regmap_config : &amc6821_regmap_config;
+
+	regmap = devm_regmap_init_i2c(client, config);
 	if (IS_ERR(regmap))
 		return dev_err_probe(dev, PTR_ERR(regmap),
 				     "Failed to initialize regmap\n");
@@ -917,6 +930,13 @@  static int amc6821_probe(struct i2c_client *client)
 	if (err)
 		return err;
 
+	if (of_device_is_compatible(dev->of_node, "tsd,mule")) {
+		err = devm_of_platform_populate(dev);
+		if (err)
+			return dev_err_probe(dev, err,
+				     "Failed to create sub-devices\n");
+	}
+
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
 							 data, &amc6821_chip_info,
 							 amc6821_groups);
@@ -934,6 +954,9 @@  static const struct of_device_id __maybe_unused amc6821_of_match[] = {
 	{
 		.compatible = "ti,amc6821",
 	},
+	{
+		.compatible = "tsd,mule",
+	},
 	{ }
 };