All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michał Kępień" <kernel@kempniu.pl>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>,
	Jonathan Woithe <jwoithe@just42.net>,
	Andy Shevchenko <andy@infradead.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/7] platform/x86: fujitsu-laptop: Define constants for FUNC operations
Date: Tue, 6 Mar 2018 21:59:20 +0100	[thread overview]
Message-ID: <20180306205920.GA786@kmp-mobile.hq.kempniu.pl> (raw)
In-Reply-To: <CAHp75VeB6PjacT4V_gsVOYCvJJK2fT3Oi6HONHdqJyCn+CeWNw@mail.gmail.com>

Andy,

> What I'm trying to tell is about consistency of style.

I completely agree with all you wrote, those are all good suggestions.
But you started your reasoning with:

> So, imagine if we have two bitfields in some register, one with one
> bit and the other with two.

We are not looking at a hardware register here.  Rather, I am trying to
bring at least _some_ order to an arbitrary set of values that the
vendor assumed would be fun to scatter around a dozen of firmware
functions.  Some hardware features are controlled by setting a specific
bit in the value being passed to a function; in other cases entire
integers are taken into account; in yet another case *two* bits in a
value control state.  There is no reason or order to be found here.

In the case of OP_* constants, perhaps the simplest thing to do would be
to define them as integers, not bitfields.  But that still results in a
mess:

#define OP_GET		0x2
#define OP_GET_CAPS	0x0
#define OP_GET_EVENTS	0x1
#define OP_GET_EXT	0x4
#define OP_SET		0x1
#define OP_SET_EXT	0x5

or:

#define OP_GET_CAPS	0x0
#define OP_GET_EVENTS	0x1
#define OP_SET		0x1
#define OP_GET		0x2
#define OP_GET_EXT	0x4
#define OP_SET_EXT	0x5

Even worse, what am I supposed to do with crap like radio LED control,
where 0x20 (bit 5) is passed in one argument to select the desired
feature and 0x20 or 0 is passed as another argument to select the
desired state of that feature?  How do I name and define constants that
I can subsequently use in call_fext_func() invocations to spare the
reader the need to learn the hard way that this:

    return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);

is actually supposed to turn the radio LED *off*?

This is the best I could come up with:

#define FEAT_RADIO_LED		BIT(5)
#define STATE_RADIO_LED_OFF	(0 << 0)
#define STATE_RADIO_LED_ON	BIT(5)

Yes, it is ugly.  But the resulting call is (IMHO) a lot more clear than
the original one:

    return fext_flags(device, OP_SET_EXT, FEAT_RADIO_LED, STATE_RADIO_LED_OFF);

All of the above is why I was inclined to just use alphabetic ordering
for all constants defined in fujitsu-laptop.  This approach brings at
least _some_ consistency to this mess (which only the vendor is to blame
for, of course).  If you would rather have me take a different approach,
I am all ears.

-- 
Best regards,
Michał Kępień

  reply	other threads:[~2018-03-06 20:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 21:15 [PATCH 0/7] fujitsu-laptop: Consistent naming of constants Michał Kępień
2018-02-27 21:15 ` [PATCH 1/7] platform/x86: fujitsu-laptop: Define constants for FUNC operations Michał Kępień
2018-02-28 16:08   ` Andy Shevchenko
2018-03-04  5:08     ` Jonathan Woithe
2018-03-04 19:44       ` Michał Kępień
2018-03-04 22:49         ` Jonathan Woithe
2018-03-05 23:16         ` Darren Hart
2018-03-06  9:37           ` Andy Shevchenko
2018-03-06 20:59             ` Michał Kępień [this message]
2018-03-07 12:34               ` Andy Shevchenko
2018-03-10 20:10                 ` Michał Kępień
2018-03-12  9:27                   ` Andy Shevchenko
2018-02-27 21:15 ` [PATCH 2/7] platform/x86: fujitsu-laptop: Define constants for FUNC features Michał Kępień
2018-02-27 21:15 ` [PATCH 3/7] platform/x86: fujitsu-laptop: Define constants for FUNC feature states Michał Kępień
2018-02-27 21:15 ` [PATCH 4/7] platform/x86: fujitsu-laptop: Rename constants defining hotkey codes Michał Kępień
2018-02-27 21:15 ` [PATCH 5/7] platform/x86: fujitsu-laptop: Tweak how constants are commented and laid out Michał Kępień
2018-02-27 21:15 ` [PATCH 6/7] platform/x86: fujitsu-laptop: More accurately represent the hotkey ring buffer managed by firmware Michał Kępień
2018-02-28 16:13   ` Andy Shevchenko
2018-03-04 19:57     ` Michał Kępień
2018-02-27 21:15 ` [PATCH 7/7] platform/x86: fujitsu-laptop: Introduce fext_*() helper functions Michał Kępień
2018-03-04  5:37 ` [PATCH 0/7] fujitsu-laptop: Consistent naming of constants Jonathan Woithe
2018-03-21 23:25 ` Darren Hart

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=20180306205920.GA786@kmp-mobile.hq.kempniu.pl \
    --to=kernel@kempniu.pl \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@infradead.org \
    --cc=dvhart@infradead.org \
    --cc=jwoithe@just42.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.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.