From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: marius.cristea@microchip.com, jic23@kernel.org, lars@metafoo.de,
robh+dt@kernel.org
Cc: krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: adding support for pac193x
Date: Fri, 27 Oct 2023 14:20:09 +0200 [thread overview]
Message-ID: <42fd061d-7832-4531-bb85-eb8860c7e5e1@linaro.org> (raw)
In-Reply-To: <20231025134404.131485-3-marius.cristea@microchip.com>
On 25/10/2023 15:44, marius.cristea@microchip.com wrote:
> From: Marius Cristea <marius.cristea@microchip.com>
>
> This is the iio driver for Microchip
> PAC193X series of Power Monitor with Accumulator chip family.
>
> Signed-off-by: Marius Cristea <marius.cristea@microchip.com>
> ---
...
> +
> +static ssize_t reset_accumulators_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct pac1934_chip_info *info = iio_priv(indio_dev);
> + int ret, i;
> + u8 refresh_cmd = PAC1934_REFRESH_REG_ADDR;
> +
> + ret = i2c_smbus_write_byte(info->client, refresh_cmd);
> + if (ret) {
> + dev_err(&indio_dev->dev,
> + "%s - cannot send 0x%02X\n",
> + __func__, refresh_cmd);
> + }
> +
> + for (i = 0 ; i < info->phys_channels; i++)
> + info->chip_reg_data.energy_sec_acc[i] = 0;
> +
> + return count;
> +}
> +
> +static IIO_DEVICE_ATTR(in_shunt_resistor_1, 0644, shunt_value_show, shunt_value_store, 0);
> +static IIO_DEVICE_ATTR(in_shunt_resistor_2, 0644, shunt_value_show, shunt_value_store, 0);
> +static IIO_DEVICE_ATTR(in_shunt_resistor_3, 0644, shunt_value_show, shunt_value_store, 0);
> +static IIO_DEVICE_ATTR(in_shunt_resistor_4, 0644, shunt_value_show, shunt_value_store, 0);
> +static IIO_DEVICE_ATTR(reset_accumulators, 0200, NULL, reset_accumulators_store, 0);
> +
> +static struct attribute *pac1934_all_attributes[] = {
> + PAC1934_DEV_ATTR(in_shunt_resistor_1),
> + PAC1934_DEV_ATTR(in_shunt_resistor_2),
> + PAC1934_DEV_ATTR(in_shunt_resistor_3),
> + PAC1934_DEV_ATTR(in_shunt_resistor_4),
> + PAC1934_DEV_ATTR(reset_accumulators),
> + NULL
> +};
> +
> +static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info,
> + struct iio_dev *indio_dev)
> +{
> + int i, j, active_channels_count = 0;
> + struct attribute **pac1934_custom_attributes;
> + struct attribute_group *pac1934_group;
> + struct i2c_client *client = info->client;
> +
> + for (i = 0 ; i < info->phys_channels; i++)
> + if (info->active_channels[i])
> + active_channels_count++;
> +
> + pac1934_group = devm_kzalloc(&client->dev, sizeof(*pac1934_group), GFP_KERNEL);
> +
> + pac1934_custom_attributes = devm_kzalloc(&client->dev,
> + (PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
> + active_channels_count +
> + PAC1934_SHARED_DEVATTRS_COUNT)
> + * sizeof(*pac1934_group) + 1,
> + GFP_KERNEL);
> + j = 0;
> +
> + for (i = 0 ; i < info->phys_channels; i++) {
> + if (info->active_channels[i]) {
> + pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * j] =
> + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * i];
> + pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * j + 1] =
> + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * i + 1];
> + j++;
> + }
> + }
> +
> + for (i = 0; i < PAC1934_SHARED_DEVATTRS_COUNT; i++)
> + pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
> + active_channels_count + i] =
> + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
> + info->phys_channels + i];
> +
> + pac1934_group->attrs = pac1934_custom_attributes;
> + info->pac1934_info.attrs = pac1934_group;
> +
> + return 0;
> +}
> +
> +static void pac1934_remove(struct i2c_client *client)
Remove functions goes always after probe.
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(&client->dev);
> + struct pac1934_chip_info *info = iio_priv(indio_dev);
> +
> + cancel_delayed_work_sync(&info->work_chip_rfsh);
> +}
> +
> +static int pac1934_probe(struct i2c_client *client)
> +{
> + struct pac1934_chip_info *info;
> + struct iio_dev *indio_dev;
> + const char *name = NULL;
> + int cnt, ret;
> +
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*info));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + info = iio_priv(indio_dev);
> +
> + i2c_set_clientdata(client, indio_dev);
> + info->client = client;
> +
> + /*
> + * load default settings - all channels disabled,
> + * uni directional flow
> + */
> + for (cnt = 0; cnt < PAC1934_MAX_NUM_CHANNELS; cnt++) {
> + info->active_channels[cnt] = false;
> + info->bi_dir[cnt] = false;
> + }
> +
> + info->crt_samp_spd_bitfield = PAC1934_SAMP_1024SPS;
> +
> + ret = pac1934_chip_identify(info);
> + if (ret)
> + return -EINVAL;
> +
> + if (ACPI_HANDLE(&client->dev)) {
> + if (!info->phys_channels)
> + /* failed to identify part number, unknown number of channels available */
> + return -EINVAL;
> +
> + name = pac1934_match_acpi_device(client, info);
> + } else {
> + name = pac1934_match_of_device(client, info);
> + }
> +
> + if (!name) {
> + dev_dbg(&client->dev, "parameter parsing returned an error\n");
> + return -EINVAL;
> + }
> +
> + mutex_init(&info->lock);
> +
> + /*
> + * do now any chip specific initialization (e.g. read/write
> + * some registers), enable/disable certain channels, change the sampling
> + * rate to the requested value
> + */
> + ret = pac1934_chip_configure(info);
> + if (ret < 0)
> + goto fail;
Why do you need to go to fail here? Is the work scheduled in error cases?
> +
> + /* prepare the channel information */
> + ret = pac1934_prep_iio_channels(info, indio_dev);
> + if (ret < 0)
> + goto fail;
> +
> + ret = pac1934_prep_custom_attributes(info, indio_dev);
> + if (ret < 0) {
> + dev_err_probe(&indio_dev->dev, ret,
> + "Can't configure custom attributes for PAC1934 device\n");
> + goto fail;
> + }
> +
> + info->pac1934_info.read_raw = pac1934_read_raw;
> + info->pac1934_info.read_avail = pac1934_read_avail;
> + info->pac1934_info.write_raw = pac1934_write_raw;
> + info->pac1934_info.read_label = pac1934_read_label;
> +
> + indio_dev->info = &info->pac1934_info;
> + indio_dev->name = name;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> +
> + /*
> + * read whatever has been accumulated in the chip so far
> + * and reset the accumulators
> + */
> + ret = pac1934_reg_snapshot(info, true, PAC1934_REFRESH_REG_ADDR,
> + PAC1934_MIN_UPDATE_WAIT_TIME_US);
> + if (ret < 0)
> + goto fail;
> +
> + ret = devm_iio_device_register(&client->dev, indio_dev);
> + if (ret < 0) {
> + dev_err_probe(&indio_dev->dev, ret,
> + "Can't register IIO device\n");
> + goto fail;
> + }
> +
> + return 0;
> +
> +fail:
> + cancel_delayed_work_sync(&info->work_chip_rfsh);
> +
> + return ret;
> +}
> +
> +static const struct i2c_device_id pac1934_id[] = {
> + { .name = "pac1931", .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1931] },
> + { .name = "pac1932", .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1932] },
> + { .name = "pac1933", .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1933] },
> + { .name = "pac1934", .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1934] },
> + {}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, pac1934_id);
> +
> +static const struct of_device_id pac1934_of_match[] = {
> + {
> + .compatible = "microchip,pac1931",
> + .data = &pac1934_chip_config[PAC1931]
> + },
> + {
> + .compatible = "microchip,pac1932",
> + .data = &pac1934_chip_config[PAC1932]
> + },
> + {
> + .compatible = "microchip,pac1933",
> + .data = &pac1934_chip_config[PAC1933]
> + },
> + {
> + .compatible = "microchip,pac1934",
> + .data = &pac1934_chip_config[PAC1934]
> + },
> + {}
> +};
> +
> +MODULE_DEVICE_TABLE(of, pac1934_of_match);
> +
> +/* using MCHP1930 to be compatible with WINDOWS ACPI */
> +static const struct acpi_device_id pac1934_acpi_match[] = {
> + {"MCHP1930", 0},
> + { }
> +};
> +
> +MODULE_DEVICE_TABLE(acpi, pac1934_acpi_match);
> +
> +static struct i2c_driver pac1934_driver = {
> + .driver = {
> + .name = "pac1934",
> + .of_match_table = pac1934_of_match,
> + .acpi_match_table = ACPI_PTR(pac1934_acpi_match)
Drop ACPI_PTR, causes warnings.
Best regards,
Krzysztof
next prev parent reply other threads:[~2023-10-27 12:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 13:44 [PATCH v2 0/2] adding support for Microchip PAC193X Power Monitor marius.cristea
2023-10-25 13:44 ` [PATCH v2 1/2] dt-bindings: iio: adc: adding dt-bindings for PAC193X marius.cristea
2023-10-25 15:08 ` Conor Dooley
2023-10-26 15:23 ` Marius.Cristea
2023-10-26 16:08 ` Conor Dooley
2023-10-27 14:26 ` Jonathan Cameron
2023-11-07 8:55 ` Marius.Cristea
2023-12-04 9:41 ` Jonathan Cameron
2023-11-10 16:27 ` Marius.Cristea
2023-12-04 9:43 ` Jonathan Cameron
2023-10-27 12:13 ` Krzysztof Kozlowski
2023-10-25 13:44 ` [PATCH v2 2/2] iio: adc: adding support for pac193x marius.cristea
2023-10-25 14:38 ` Nuno Sá
2023-10-26 15:03 ` Marius.Cristea
2023-10-27 8:40 ` Nuno Sá
2023-10-27 14:29 ` Jonathan Cameron
2023-10-25 17:23 ` kernel test robot
2023-10-27 12:20 ` Krzysztof Kozlowski [this message]
2023-10-27 15:18 ` Jonathan Cameron
2023-11-02 14:28 ` Robin Getz
2023-11-07 12:55 ` Marius.Cristea
2023-11-07 15:39 ` Robin Getz
2023-10-27 12:10 ` [PATCH v2 0/2] adding support for Microchip PAC193X Power Monitor Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42fd061d-7832-4531-bb85-eb8860c7e5e1@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marius.cristea@microchip.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.