Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2174285lqp; Sun, 24 Mar 2024 06:36:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWH3lGfRvz+boe00zWXpx9XQSshZ1bLF5XVDd5DLB3aKyCL3sx+89XGbCSf4PmcvsX3ZAuMjIqMqGpWAa41m1kqLZzfBzUFpUJhGWidiQ== X-Google-Smtp-Source: AGHT+IGxFtnlwlB+tImglrMfwb0yYt9dHSi6MNs2gruJhT5lAdkj7Ew3Ob9Q3OnRo4Qpa2TcTDKb X-Received: by 2002:a05:6870:d252:b0:229:8aeb:a94c with SMTP id h18-20020a056870d25200b002298aeba94cmr5109693oac.49.1711287360878; Sun, 24 Mar 2024 06:36:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711287360; cv=pass; d=google.com; s=arc-20160816; b=EtXViaR5cMFpLN0AtuQMhjgtnu0uoZ/Mqt/qmi0lxpG4y2mRPHhD/qOFYpXR8AgxXb VVJhyFGYxDQiPCfCiOio/fKtj20KaEqQflps4vY2CC7bUtTuOrZZs1BS7Q79fKARnf05 FkAmoS3HDz2S51MNyKjsisoN3BA12FoWwzz2q4KVGGciGODYDrvjFFWh+i+ix8wEa7UH palz09VVbdHlZ5LvHoYBo/D3L/4cn4WXStlKgQJ4lfnpBvf/YlgpRv5BZnJHpln2HCx2 ndKKR0pLIeefTsjlSHITGjIeRtHlJFfN95gFv2UIKSAc0s8fU1cuKVncIINdYRvkQF4b Scjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=GAFwtu4gVXGCeWu16dBZGDBa4uY13b3h5cmBT5MxcUI=; fh=aO7VwMzXorvFb/cjS7UqKL2BI3mnI34qIdePd4Zg25U=; b=jwDqLB504KwZm2he681T2uPQk99muMreJAuIQkaqf6pB3N/3dmz6mkG8cUHgcoIo4V Tx5+4U1YwCKxCS0P4lEug8/jYUCQFtoPSsPc5sWwoAwIl5fb8JNqTOqlxvyQl9G37fz9 WlHaXLuCOk8Nn2wyMkZFAANrZNfOn4PzlOe9SyVTmfoCbp+cjjs2E/ipVf5mIQj341PF tH45fcRJSCrWN7902K8mk65EQf3pZgwydIhgzp4i13gbV3WVVAtG+PESeqjOeH6o7uUj DJqR+tHiPR9wdzuD7BxYBt/fchJNfoanMOZqMJNUV/ovoL1MuYJG7rE03iYsnFI0J7U+ Nthg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rielj8q0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112678-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r10-20020a056a00216a00b006e6b77f6aabsi3352225pff.263.2024.03.24.06.36.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 06:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112678-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rielj8q0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112678-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 33AB32815FA for ; Sun, 24 Mar 2024 13:36:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 005E617C6A; Sun, 24 Mar 2024 13:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rielj8q0" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E424CA64; Sun, 24 Mar 2024 13:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711287352; cv=none; b=mDQfzaeJXR+n+cVLvQDFdNelOU5Xki43OGjvkkQ7fVXdTnSCgBc+WvVZC29CqRYIQMWE5uKH1k4qlLBhuAff6Q6AuD+K2QOO7/kNAxlrJ6AgdxHPBgDqwBhDYxGvjxS7q+G02wD79PS2UlVX2D/m1LnnAT/lsRkxrZblJnDc1Pg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711287352; c=relaxed/simple; bh=OkxuCRwTUyfG7O9E8DB3iGOMcj/7xSlVhqkGY+Ozj4c=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MDx0iS6+VarVMC/XoKnC+ZnkBv4j5UF0ARPvMmOmCOdsV3BoX3MB5OQCIrc/e35dozDz5TG/dvncTVEkl8Ilajm5Lsk44Hka56k6UJespxaLLC1vMoUG7f+rXiTWl+83kEYap+EwxzINXs27HVJNcs6+2CKfuNRT2Mq1uvC8XKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rielj8q0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B81D8C433C7; Sun, 24 Mar 2024 13:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711287351; bh=OkxuCRwTUyfG7O9E8DB3iGOMcj/7xSlVhqkGY+Ozj4c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rielj8q0mCnEby5eS02HxFl1YtyQgh+X20gfLxbLAxP0jPysUco4gBsCeJIp8uOoP uU3npM8G8C6Gdxckchw8L8m0n5+hKvLiZuu4DhtUKXkkcjW81T3GSNoYLnJ3rndNPJ qALlqSN9sOZ+lQyFq/pcNg9UaCVQXi4NZ4MpFIT4Usg+7MGrtx++NvX1JuN9OVgqIU Di+rEcUZFAYI2IEOSFqK0jZSfroQgZsLGIvKPnv39GxSXoXLJkZASEqMw2E8VRsLd9 8yrWZqSRTHn0gO6wvnImuHXgLG5C8OhpRWmH1eXJV/FXmfFUN4hFxpRVCE+tMEplrn rU04S0JwCrhRg== Date: Sun, 24 Mar 2024 13:35:36 +0000 From: Jonathan Cameron To: Lothar Rubusch Cc: lars@metafoo.de, Michael.Hennerich@analog.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com Subject: Re: [PATCH v3 4/6] iio: accel: adxl345: Remove single info instances Message-ID: <20240324133536.01067770@jic23-huawei> In-Reply-To: <20240323122030.21800-5-l.rubusch@gmail.com> References: <20240323122030.21800-1-l.rubusch@gmail.com> <20240323122030.21800-5-l.rubusch@gmail.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 23 Mar 2024 12:20:28 +0000 Lothar Rubusch wrote: > Add a common array adxl3x5_chip_info and an enum for > indexing. This allows to remove local redundantly > initialized code in the bus specific modules. > > Signed-off-by: Lothar Rubusch > --- > drivers/iio/accel/adxl345.h | 7 +++++++ > drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ > drivers/iio/accel/adxl345_i2c.c | 20 +++++--------------- > drivers/iio/accel/adxl345_spi.c | 20 +++++--------------- > 4 files changed, 29 insertions(+), 30 deletions(-) > > diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h > index 6b84a2cee..de6b1767d 100644 > --- a/drivers/iio/accel/adxl345.h > +++ b/drivers/iio/accel/adxl345.h > @@ -26,11 +26,18 @@ > */ > #define ADXL375_USCALE 480000 > > +enum adxl345_device_type { > + ADXL345, > + ADXL375, > +}; > + > struct adxl345_chip_info { > const char *name; > int uscale; > }; > > +extern const struct adxl345_chip_info adxl3x5_chip_info[]; > + > int adxl345_core_probe(struct device *dev, struct regmap *regmap, > int (*setup)(struct device*, struct regmap*)); > > diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c > index 33424edca..e3718d0dd 100644 > --- a/drivers/iio/accel/adxl345_core.c > +++ b/drivers/iio/accel/adxl345_core.c > @@ -62,6 +62,18 @@ struct adxl345_data { > BIT(IIO_CHAN_INFO_SAMP_FREQ), \ > } > > +const struct adxl345_chip_info adxl3x5_chip_info[] = { > + [ADXL345] = { > + .name = "adxl345", > + .uscale = ADXL345_USCALE, > + }, > + [ADXL375] = { > + .name = "adxl375", > + .uscale = ADXL375_USCALE, > + }, > +}; > +EXPORT_SYMBOL_NS_GPL(adxl3x5_chip_info, IIO_ADXL345); There is little advantage here form using an array. I'd just have two exported structures. Then the name alone is enough in the id tables. And probably no need for the enum definition. This use of arrays is an old pattern that makes little sense if the IDs have no actual meaning and you aren't supporting lots of different parts. For 2 parts I'd argue definitely not worth it. > + > static const struct iio_chan_spec adxl345_channels[] = { > ADXL345_CHANNEL(0, X), > ADXL345_CHANNEL(1, Y), > diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c > index 4065b8f7c..afb2d0b79 100644 > --- a/drivers/iio/accel/adxl345_i2c.c > +++ b/drivers/iio/accel/adxl345_i2c.c > @@ -30,32 +30,22 @@ static int adxl345_i2c_probe(struct i2c_client *client) > return adxl345_core_probe(&client->dev, regmap, NULL); > } > > -static const struct adxl345_chip_info adxl345_i2c_info = { > - .name = "adxl345", > - .uscale = ADXL345_USCALE, > -}; > - > -static const struct adxl345_chip_info adxl375_i2c_info = { > - .name = "adxl375", > - .uscale = ADXL375_USCALE, > -}; > - > static const struct i2c_device_id adxl345_i2c_id[] = { > - { "adxl345", (kernel_ulong_t)&adxl345_i2c_info }, > - { "adxl375", (kernel_ulong_t)&adxl375_i2c_info }, > + { "adxl345", (kernel_ulong_t)&adxl3x5_chip_info[ADXL345] }, > + { "adxl375", (kernel_ulong_t)&adxl3x5_chip_info[ADXL375] }, > { } > }; > MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id); > > static const struct of_device_id adxl345_of_match[] = { > - { .compatible = "adi,adxl345", .data = &adxl345_i2c_info }, > - { .compatible = "adi,adxl375", .data = &adxl375_i2c_info }, > + { .compatible = "adi,adxl345", .data = &adxl3x5_chip_info[ADXL345] }, > + { .compatible = "adi,adxl375", .data = &adxl3x5_chip_info[ADXL375] }, > { } > }; > MODULE_DEVICE_TABLE(of, adxl345_of_match); > > static const struct acpi_device_id adxl345_acpi_match[] = { > - { "ADS0345", (kernel_ulong_t)&adxl345_i2c_info }, > + { "ADS0345", (kernel_ulong_t)&adxl3x5_chip_info[ADXL345] }, > { } > }; > MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match); > diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c > index 1094396ac..5c1109136 100644 > --- a/drivers/iio/accel/adxl345_spi.c > +++ b/drivers/iio/accel/adxl345_spi.c > @@ -46,32 +46,22 @@ static int adxl345_spi_probe(struct spi_device *spi) > return adxl345_core_probe(&spi->dev, regmap, &adxl345_spi_setup); > } > > -static const struct adxl345_chip_info adxl345_spi_info = { > - .name = "adxl345", > - .uscale = ADXL345_USCALE, > -}; > - > -static const struct adxl345_chip_info adxl375_spi_info = { > - .name = "adxl375", > - .uscale = ADXL375_USCALE, > -}; > - > static const struct spi_device_id adxl345_spi_id[] = { > - { "adxl345", (kernel_ulong_t)&adxl345_spi_info }, > - { "adxl375", (kernel_ulong_t)&adxl375_spi_info }, > + { "adxl345", (kernel_ulong_t)&adxl3x5_chip_info[ADXL345] }, > + { "adxl375", (kernel_ulong_t)&adxl3x5_chip_info[ADXL375] }, > { } > }; > MODULE_DEVICE_TABLE(spi, adxl345_spi_id); > > static const struct of_device_id adxl345_of_match[] = { > - { .compatible = "adi,adxl345", .data = &adxl345_spi_info }, > - { .compatible = "adi,adxl375", .data = &adxl375_spi_info }, > + { .compatible = "adi,adxl345", .data = &adxl3x5_chip_info[ADXL345] }, > + { .compatible = "adi,adxl375", .data = &adxl3x5_chip_info[ADXL375] }, > { } > }; > MODULE_DEVICE_TABLE(of, adxl345_of_match); > > static const struct acpi_device_id adxl345_acpi_match[] = { > - { "ADS0345", (kernel_ulong_t)&adxl345_spi_info }, > + { "ADS0345", (kernel_ulong_t)&adxl3x5_chip_info[ADXL345] }, > { } > }; > MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);