From: "Ye, Xiang" <xiang.ye@intel.com>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: jikos@kernel.org, jic23@kernel.org,
srinivas.pandruvada@linux.intel.com, linux-input@vger.kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/4] HID: hid-sensor-custom: Add custom sensor iio support
Date: Wed, 25 Nov 2020 10:27:21 +0800 [thread overview]
Message-ID: <20201125022721.GA4958@host> (raw)
In-Reply-To: <20201124113211.00003141@Huawei.com>
On Tue, Nov 24, 2020 at 11:32:11AM +0000, Jonathan Cameron wrote:
> Hi
> ...
> > > > sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
> > > > diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
> > > > index 530c09f3e64a..46db3056f04b 100644
> > > > --- a/include/linux/hid-sensor-ids.h
> > > > +++ b/include/linux/hid-sensor-ids.h
> > > > @@ -128,6 +128,10 @@
> > > > #define HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND 0x15
> > > >
> > > > /* Common selectors */
> > > > +#define HID_USAGE_SENSOR_PROP_DESC 0x200300
> > > > +#define HID_USAGE_SENSOR_PROP_FRIENDLY_NAME 0x200301
> > > > +#define HID_USAGE_SENSOR_PROP_SERIAL_NUM 0x200307
> > > > +#define HID_USAGE_SENSOR_PROP_MANUFACTURER 0x200305
> > > > #define HID_USAGE_SENSOR_PROP_REPORT_INTERVAL 0x20030E
> > > > #define HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS 0x20030F
> > > > #define HID_USAGE_SENSOR_PROP_SENSITIVITY_RANGE_PCT 0x200310
> > > > @@ -159,4 +163,39 @@
> > > > #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM 0x200840
> > > > #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM 0x200841
> > > >
> > > > +/* Custom Sensor (2000e1) */
> > > > +#define HID_USAGE_SENSOR_HINGE 0x20020B
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_LOCATION 0x200400
> > > > +#define HID_USAGE_SENSOR_DATA_FIELE_TIME_SINCE_SYS_BOOT 0x20052B
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_USAGE 0x200541
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE 0x200543
> > > Given these are all defined in a block could we use a macro?
> > > HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(x) 0x200543 + (x)
> > >
> > > perhaps?
> > >
> > > I'm not sure what the preferred convention is in this file.
> > If using HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(x), we should give a range to x, like (1<x<28).
> > How to ensure the x is in the range? It can be an issue when someone using x out of the range.
>
> It can be done via build time checking.
> https://elixir.bootlin.com/linux/latest/source/include/linux/build_bug.h#L49
> Normally we wouldn't bother and would rely on review to pick up on this but
> I'd have no problem with a paranoid check in the macro. Particularly as 28 isn't
> exactly and obvious number to support!
Because HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE is used as case condition, we cannot use
Build_BUG_ON in the macro like below.
#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(x) \
({ \
BUILD_BUG_ON(x > 28); \
BUILD_BUG_ON(x < 0); \
(HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_BASE + (x)); \
})
I can use the define with a comments to declear the range of x.
#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_BASE 0x200543
/* Custom Sensor data 28=>x>=0 */
#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(x) \
(HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_BASE + (x))
Thanks
Ye, Xiang
>
> >
> > Thanks
> > Xiang
> > >
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_1 0x200544
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_2 0x200545
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_3 0x200546
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_4 0x200547
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_5 0x200548
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_6 0x200549
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_7 0x20054A
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_8 0x20054B
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_9 0x20054C
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_10 0x20054D
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_11 0x20054E
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_12 0x20054F
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_13 0x200550
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_14 0x200551
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_15 0x200552
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_16 0x200553
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_17 0x200554
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_18 0x200555
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_19 0x200556
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_20 0x200557
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_21 0x200558
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_22 0x200559
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_23 0x20055A
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_24 0x20055B
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_25 0x20055C
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_26 0x20055D
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_27 0x20055E
> > > > +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_28 0x20055F
> > > > +
> > > > #endif
> > >
>
next prev parent reply other threads:[~2020-11-25 2:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 10:03 [PATCH v2 0/4] add custom hinge sensor support Ye Xiang
2020-11-19 10:03 ` [PATCH v2 1/4] HID: hid-sensor-custom: Add custom sensor iio support Ye Xiang
2020-11-21 17:21 ` Jonathan Cameron
2020-11-24 10:29 ` Ye, Xiang
2020-11-24 11:32 ` Jonathan Cameron
2020-11-25 2:27 ` Ye, Xiang [this message]
2020-11-28 13:29 ` Jonathan Cameron
2020-11-19 10:03 ` [PATCH v2 2/4] iio: hid-sensor-trigger: Decrement runtime pm enable count on driver removal Ye Xiang
2020-11-21 17:22 ` Jonathan Cameron
2020-11-22 1:54 ` Pandruvada, Srinivas
2020-11-19 10:03 ` [PATCH v2 3/4] iio: hid-sensor-trigger: Use iio->trig instead trig field internal structure Ye Xiang
2020-11-21 17:33 ` Jonathan Cameron
2020-11-19 10:03 ` [PATCH v2 4/4] iio: hid-sensors: Add hinge sensor driver Ye Xiang
2020-11-21 17:56 ` Jonathan Cameron
2020-11-22 1:46 ` Pandruvada, Srinivas
2020-11-22 2:14 ` Pandruvada, Srinivas
2020-11-22 14:14 ` Jonathan Cameron
2020-11-22 15:51 ` Pandruvada, Srinivas
2020-11-22 16:50 ` Jonathan Cameron
2020-11-24 3:30 ` Ye, Xiang
2020-11-24 11:36 ` Jonathan Cameron
2020-11-25 3:24 ` Ye, Xiang
2020-11-24 6:43 ` Ye, Xiang
2020-11-24 11:39 ` Jonathan Cameron
2020-11-25 2:39 ` Ye, Xiang
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=20201125022721.GA4958@host \
--to=xiang.ye@intel.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).