From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Marius Cristea <marius.cristea@microchip.com>,
Trevor Gamblin <tgamblin@baylibre.com>,
Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>,
Hans de Goede <hdegoede@redhat.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v3 14/24] iio: accel: kxcjk-1013: Get rid of enum kx_chipset
Date: Sat, 26 Oct 2024 12:37:36 +0100 [thread overview]
Message-ID: <20241026123736.5714fadd@jic23-huawei> (raw)
In-Reply-To: <20241024191200.229894-15-andriy.shevchenko@linux.intel.com>
On Thu, 24 Oct 2024 22:05:03 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> Instead of using enum, out of which only a couple of values
> are being actully used, make a comparisons against pointer
> to the respective chip_info structures.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hmm. Maybe worth a revisit longer term to use callbacks for the
decisions instead of matching at all as this stuff tends not to end
up being specific to one version of a chip as more parts are added.
Anyhow, this is still an improvement so applied.
Jonathan
> ---
> drivers/iio/accel/kxcjk-1013.c | 28 +++++-----------------------
> 1 file changed, 5 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index 91f890275a18..a8c73e401f95 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -169,15 +169,6 @@
>
> #define KXCJK1013_DEFAULT_WAKE_THRES 1
>
> -enum kx_chipset {
> - KXCJK1013,
> - KXCJ91008,
> - KXTJ21009,
> - KXTF9,
> - KX0231025,
> - KX_MAX_CHIPS /* this must be last */
> -};
> -
> /* Refer to section 4 of the specification */
> struct kx_odr_start_up_time {
> int odr_bits;
> @@ -318,59 +309,50 @@ static const struct kx_chipset_regs kx0231025_regs = {
> struct kx_chipset_info {
> const struct kx_chipset_regs *regs;
> const struct kx_odr_start_up_time *times;
> - enum kx_chipset chipset;
> enum kx_acpi_type acpi_type;
> };
>
> static const struct kx_chipset_info kxcjk1013_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxcjk1013_odr_start_up_times),
> - .chipset = KXCJK1013,
> };
>
> static const struct kx_chipset_info kxcj91008_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxcj91008_odr_start_up_times),
> - .chipset = KXCJ91008,
> };
>
> static const struct kx_chipset_info kxcj91008_kiox010a_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxcj91008_odr_start_up_times),
> - .chipset = KXCJ91008,
> .acpi_type = ACPI_KIOX010A,
> };
>
> static const struct kx_chipset_info kxcj91008_kiox020a_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxcj91008_odr_start_up_times),
> - .chipset = KXCJ91008,
> .acpi_type = ACPI_GENERIC,
> };
>
> static const struct kx_chipset_info kxcj91008_smo8500_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxcj91008_odr_start_up_times),
> - .chipset = KXCJ91008,
> .acpi_type = ACPI_SMO8500,
> };
>
> static const struct kx_chipset_info kxtj21009_info = {
> .regs = &kxcjk1013_regs,
> .times = pm_ptr(kxtj21009_odr_start_up_times),
> - .chipset = KXTJ21009,
> };
>
> static const struct kx_chipset_info kxtf9_info = {
> .regs = &kxtf9_regs,
> .times = pm_ptr(kxtf9_odr_start_up_times),
> - .chipset = KXTF9,
> };
>
> static const struct kx_chipset_info kx0231025_info = {
> .regs = &kx0231025_regs,
> .times = pm_ptr(kx0231025_odr_start_up_times),
> - .chipset = KX0231025,
> };
>
> enum kxcjk1013_axis {
> @@ -647,7 +629,7 @@ static int kxcjk1013_chip_init(struct kxcjk1013_data *data)
> }
>
> /* On KX023, route all used interrupts to INT1 for now */
> - if (data->info->chipset == KX0231025 && data->client->irq > 0) {
> + if (data->info == &kx0231025_info && data->client->irq > 0) {
> ret = i2c_smbus_write_byte_data(data->client, KX023_REG_INC4,
> KX023_REG_INC4_DRDY1 |
> KX023_REG_INC4_WUFI1);
> @@ -883,7 +865,7 @@ static int kxcjk1013_set_odr(struct kxcjk1013_data *data, int val, int val2)
> if (ret < 0)
> return ret;
>
> - if (data->info->chipset == KXTF9)
> + if (data->info == &kxtf9_info)
> odr_setting = kxcjk1013_find_odr_value(kxtf9_samp_freq_table,
> ARRAY_SIZE(kxtf9_samp_freq_table),
> val, val2);
> @@ -927,7 +909,7 @@ static int kxcjk1013_set_odr(struct kxcjk1013_data *data, int val, int val2)
>
> static int kxcjk1013_get_odr(struct kxcjk1013_data *data, int *val, int *val2)
> {
> - if (data->info->chipset == KXTF9)
> + if (data->info == &kxtf9_info)
> return kxcjk1013_convert_odr_value(kxtf9_samp_freq_table,
> ARRAY_SIZE(kxtf9_samp_freq_table),
> data->odr_bits, val, val2);
> @@ -1194,7 +1176,7 @@ static ssize_t kxcjk1013_get_samp_freq_avail(struct device *dev,
> struct kxcjk1013_data *data = iio_priv(indio_dev);
> const char *str;
>
> - if (data->info->chipset == KXTF9)
> + if (data->info == &kxtf9_info)
> str = kxtf9_samp_freq_avail;
> else
> str = kxcjk1013_samp_freq_avail;
> @@ -1443,7 +1425,7 @@ static irqreturn_t kxcjk1013_event_handler(int irq, void *private)
> }
>
> if (ret & KXCJK1013_REG_INT_SRC1_BIT_WUFS) {
> - if (data->info->chipset == KXTF9)
> + if (data->info == &kxtf9_info)
> iio_push_event(indio_dev,
> IIO_MOD_EVENT_CODE(IIO_ACCEL,
> 0,
next prev parent reply other threads:[~2024-10-26 11:38 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 19:04 [PATCH v3 00/24] iio: Clean up acpi_match_device() use cases Andy Shevchenko
2024-10-24 19:04 ` [PATCH v3 01/24] iio: magnetometer: bmc150: Drop dead code from the driver Andy Shevchenko
2024-10-26 11:02 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 02/24] iio: adc: pac1934: Replace strange way of checking type of enumeration Andy Shevchenko
2024-10-26 11:03 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 03/24] iio: imu: inv_mpu6050: " Andy Shevchenko
2024-10-26 11:04 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 04/24] iio: acpi: Improve iio_read_acpi_mount_matrix() Andy Shevchenko
2024-10-26 11:07 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 05/24] iio: acpi: Add iio_get_acpi_device_name_and_data() helper function Andy Shevchenko
2024-10-26 11:09 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 06/24] iio: accel: kxcjk-1013: Remove redundant I²C ID Andy Shevchenko
2024-10-26 11:11 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 07/24] iio: accel: kxcjk-1013: Revert "Add support for KX022-1020" Andy Shevchenko
2024-10-26 11:16 ` Jonathan Cameron
2024-10-26 14:58 ` Rayyan Ansari
2024-10-26 17:21 ` Jonathan Cameron
2024-10-28 9:02 ` Andy Shevchenko
2024-10-24 19:04 ` [PATCH v3 08/24] iio: accel: kxcjk-1013: Switch from CONFIG_PM guards to pm_ptr() etc Andy Shevchenko
2024-10-26 11:17 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 09/24] iio: accel: kxcjk-1013: Use local variable for regs Andy Shevchenko
2024-10-26 11:18 ` Jonathan Cameron
2024-10-24 19:04 ` [PATCH v3 10/24] iio: accel: kxcjk-1013: Rename kxcjk1013_info Andy Shevchenko
2024-10-26 11:21 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 11/24] iio: accel: kxcjk-1013: Start using chip_info variables instead of enum Andy Shevchenko
2024-10-26 11:26 ` Jonathan Cameron
2024-10-28 9:48 ` Andy Shevchenko
2024-10-24 19:05 ` [PATCH v3 12/24] iio: accel: kxcjk-1013: Move odr_start_up_times up in the code Andy Shevchenko
2024-10-26 11:30 ` Jonathan Cameron
2024-10-28 9:49 ` Andy Shevchenko
2024-10-24 19:05 ` [PATCH v3 13/24] iio: accel: kxcjk-1013: Convert ODR times array to variable in chip_info Andy Shevchenko
2024-10-26 11:34 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 14/24] iio: accel: kxcjk-1013: Get rid of enum kx_chipset Andy Shevchenko
2024-10-26 11:37 ` Jonathan Cameron [this message]
2024-10-28 9:50 ` Andy Shevchenko
2024-10-24 19:05 ` [PATCH v3 15/24] iio: accel: kxcjk-1013: Replace a variant of iio_get_acpi_device_name_and_data() Andy Shevchenko
2024-10-26 11:38 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 16/24] iio: accel: kxcjk-1013: drop ACPI_PTR() and move ID out of CONFIG_ACPI guards Andy Shevchenko
2024-10-26 11:41 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 17/24] iio: accel: mma9551: Replace custom implementation of iio_get_acpi_device_name() Andy Shevchenko
2024-10-26 11:45 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 18/24] iio: accel: mma9553: " Andy Shevchenko
2024-10-26 11:47 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 19/24] iio: gyro: bmg160: " Andy Shevchenko
2024-10-26 11:48 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 20/24] iio: light: isl29018: Replace a variant of iio_get_acpi_device_name_and_data() Andy Shevchenko
2024-10-26 11:50 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 21/24] iio: light: isl29018: drop ACPI_PTR() and CONFIG_ACPI guards Andy Shevchenko
2024-10-26 11:52 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 22/24] iio: light: ltr501: Drop most likely fake ACPI IDs Andy Shevchenko
2024-10-26 11:54 ` Jonathan Cameron
2024-10-24 19:05 ` [PATCH v3 23/24] iio: light: ltr501: Add LTER0303 to the supported devices Andy Shevchenko
2024-10-26 11:56 ` Jonathan Cameron
2024-10-28 9:52 ` Andy Shevchenko
2024-10-24 19:05 ` [PATCH v3 24/24] iio: light: ltr501: Replace a variant of iio_get_acpi_device_name_and_data() Andy Shevchenko
2024-10-26 11:58 ` Jonathan Cameron
2024-10-29 6:34 ` [PATCH v3 00/24] iio: Clean up acpi_match_device() use cases Matti Vaittinen
2024-10-30 14:56 ` Andy Shevchenko
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=20241026123736.5714fadd@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marius.cristea@microchip.com \
--cc=tgamblin@baylibre.com \
/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.