From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: Ming Yu <a0282524688@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-can@vger.kernel.org,
netdev@vger.kernel.org, linux-watchdog@vger.kernel.org,
linux-hwmon@vger.kernel.org, linux-rtc@vger.kernel.org,
tmyu0@nuvoton.com, lee@kernel.org, linus.walleij@linaro.org,
brgl@bgdev.pl, andi.shyti@kernel.org, mkl@pengutronix.de,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, wim@linux-watchdog.org,
linux@roeck-us.net, jdelvare@suse.com,
alexandre.belloni@bootlin.com, linux-usb@vger.kernel.org
Subject: Re: [PATCH v4 1/7] mfd: Add core driver for Nuvoton NCT6694
Date: Mon, 30 Dec 2024 18:38:08 +0900 [thread overview]
Message-ID: <994bc47c-7d9e-4519-be30-cab5be4f7bb4@wanadoo.fr> (raw)
In-Reply-To: <CAOoeyxXOa-JK1-wRn0hsD1nuTOLs-5NBv5-YswOSS1JJbGmU_A@mail.gmail.com>
On 30/12/2024 at 17:47, Ming Yu wrote:
> Vincent Mailhol <mailhol.vincent@wanadoo.fr> 於 2024年12月30日 週一 下午3:34寫道:
(...)
>> If the two bytes may be used separately or in combination, then I think
>> it is better to describe this in your structure. Something like this:
>>
>> struct nct6694_cmd_header {
>> u8 rsv1;
>> u8 mod;
>> union {
>> __le16 offset;
>> struct {
>> u8 cmd;
>> u8 sel;
>> }; __packed
>> } __packed;
>> u8 hctrl;
>> u8 rsv2;
>> __le16 len;
>> } __packed;
>>
>
> Sorry for forgetting to list the structure in last mail, but the
> revised structure is same as yours.
>
>> Then, your prototype becomes:
>>
>> int nct6694_read_msg(struct nct6694 *nct6694,
>> struct nct6694_cmd_header *cmd_hd,
>> void *buf)
>>
>> If the caller needs to pass an offset:
>>
>> void foo(struct nct6694 *nct6694, u8 mod, u16 offset, u16 length)
>> {
>> struct nct6694_cmd_header cmd_hd = { 0 };
>>
>> cmd_hd.mod = mod;
>> cmd_hd.offset = cpu_to_le16(offset);
>> cmd_hd.len = cpu_to_le16(length);
>>
>> nct6694_read_msg(nct6694, &cmd_hd, NULL);
>> }
>>
>> If the caller needs to pass a cmd and sel pair:
>>
>> void foo(struct nct6694 *nct6694, u8 mod, u8 cmd, u8 sel, u16 length)
>> {
>> struct nct6694_cmd_header cmd_hd = { 0 };
>>
>> cmd_hd.mod = mod;
>> cmd_hd.cmd = cmd;
>> cmd_hd.sel = sel;
>> cmd_hd.len = cpu_to_le16(length);
>>
>> nct6694_read_msg(nct6694, &cmd_hd, NULL);
>> }
>>
>> This way, no more cmd and sel concatenation/deconcatenation and no
>> conditional if/else logic.
>>
>> cmd_hd.hctrl (and other similar fields which are common to everyone) may
>> be set in nct6694_read_msg().
>>
>
> Understood, that means I need to export these four function, right?
> - int nct6694_read_msg(struct nct6694 *nct6694, u8 mod, u8 cmd,
> u8 sel, u16 length, void *buf);
> - int nct6694_read_rpt(struct nct6694 *nct6694, u8 mod, u16 offset,
> u16 length, void *buf);
> - int nct6694_write_msg(struct nct6694 *nct6694, u8 mod, u8 cmd,
> u8 sel, u16 length, void *buf);
> - int nct6694_write_rpt(struct nct6694 *nct6694, u8 mod, u16 offset,
> u16 length, void *buf);
>
> Both nct6694_read_msg() and nct6694_read_rpt() call
> nct6694_read(struct nct6694 *nct6694, struct nct6694_cmd_header
> cmd_hd, void *buf),
> then nct6694_write_msg() and nct6694_write_rpt() call
> nct6694_write(struct nct6694 *nct6694, struct nct6694_cmd_header
> cmd_hd, void *buf).
> (nct6694_read/nct6694_write is origin nct6694_read_msg/nct6694_write_msg)
I was more thinking of exposing:
int nct6694_read_msg(struct nct6694 *nct6694,
struct nct6694_cmd_header *cmd_hd,
void *buf);
and:
int nct6694_write_msg(struct nct6694 *nct6694,
struct nct6694_cmd_header *cmd_hd,
void *buf);
and then the different modules fill the cmd_hd argument themselves and
directly call one of those two functions with no intermediaries.
But your solution is also acceptable. The core issue is the artificial
packing and depacking of the cmd and sel pair. As long as this core
issue is resolved and as long as the ugly concatenation macro can be
removed, I think it is OK. Choose the approach you prefer :)
Yours sincerely,
Vincent Mailhol
next prev parent reply other threads:[~2024-12-30 9:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 9:57 [PATCH v4 0/7] Add Nuvoton NCT6694 MFD drivers Ming Yu
2024-12-27 9:57 ` [PATCH v4 1/7] mfd: Add core driver for Nuvoton NCT6694 Ming Yu
2024-12-27 15:34 ` Vincent Mailhol
2024-12-30 6:32 ` Ming Yu
2024-12-30 7:33 ` Vincent Mailhol
2024-12-30 8:47 ` Ming Yu
2024-12-30 9:38 ` Vincent Mailhol [this message]
2024-12-27 9:57 ` [PATCH v4 2/7] gpio: Add Nuvoton NCT6694 GPIO support Ming Yu
2025-01-13 14:27 ` Linus Walleij
2024-12-27 9:57 ` [PATCH v4 3/7] i2c: Add Nuvoton NCT6694 I2C support Ming Yu
2024-12-27 9:57 ` [PATCH v4 4/7] can: Add Nuvoton NCT6694 CAN support Ming Yu
2024-12-27 15:59 ` Vincent Mailhol
2025-01-02 5:25 ` Ming Yu
2024-12-30 5:56 ` Vincent Mailhol
2025-01-02 5:40 ` Ming Yu
2025-01-02 9:03 ` Vincent Mailhol
2024-12-27 9:57 ` [PATCH v4 5/7] watchdog: Add Nuvoton NCT6694 WDT support Ming Yu
2024-12-27 9:57 ` [PATCH v4 6/7] hwmon: Add Nuvoton NCT6694 HWMON support Ming Yu
2025-01-06 13:51 ` Simon Horman
2025-01-13 3:00 ` Ming Yu
2024-12-27 9:57 ` [PATCH v4 7/7] rtc: Add Nuvoton NCT6694 RTC support Ming Yu
2024-12-30 15:39 ` Alexandre Belloni
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=994bc47c-7d9e-4519-be30-cab5be4f7bb4@wanadoo.fr \
--to=mailhol.vincent@wanadoo.fr \
--cc=a0282524688@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andi.shyti@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=brgl@bgdev.pl \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jdelvare@suse.com \
--cc=kuba@kernel.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tmyu0@nuvoton.com \
--cc=wim@linux-watchdog.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox