public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: Aditya Garg <gargaditya08@live.com>
Cc: "tzimmermann@suse.de" <tzimmermann@suse.de>,
	 "maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	 "airlied@gmail.com" <airlied@gmail.com>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	 Jiri Kosina <jikos@kernel.org>,
	"bentiss@kernel.org" <bentiss@kernel.org>,
	 Orlando Chamberlain <orlandoch.dev@gmail.com>,
	Kerem Karabay <kekrby@gmail.com>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	 "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v3 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars
Date: Sat, 10 Aug 2024 18:26:18 +0200	[thread overview]
Message-ID: <1166bdaa-ea14-430a-be2e-9593cc08491a@t-8ch.de> (raw)
In-Reply-To: <6340DD46-4537-434E-9E14-EEFE7E04AAD0@live.com>

On 2024-08-10 15:30:58+0000, Aditya Garg wrote:
> 
> > 
> > Also include linux/device.h as you are using functions from there.
> > Like devm_kcalloc().
> 
> Alright, I’ll add that
> > 
> >>> 
> >>>> +#include <linux/hid.h>
> >>>> +#include <linux/backlight.h>
> >>>> +
> >>>> +#include "hid-ids.h"
> >>>> +
> >>>> +#define APPLETB_BL_ON 1
> >>>> +#define APPLETB_BL_DIM 3
> >>>> +#define APPLETB_BL_OFF 4
> >>>> +
> >>>> +#define HID_UP_APPLEVENDOR_TB_BL 0xff120000
> >>>> +
> >>>> +#define HID_VD_APPLE_TB_BRIGHTNESS 0xff120001
> >>>> +#define HID_USAGE_AUX1 0xff120020
> >>>> +#define HID_USAGE_BRIGHTNESS 0xff120021
> >>>> +
> >>>> +static int appletb_bl_def_brightness = 2;
> >>>> +module_param_named(brightness, appletb_bl_def_brightness, int, 0444);
> >>>> +MODULE_PARM_DESC(brightness, "Default brightness:\n"
> >>>> +  "    0 - Touchbar is off\n"
> >>>> +  "    1 - Dim brightness\n"
> >>>> +  "    [2] - Full brightness");
> >>>> +
> >>>> +struct appletb_bl {
> >>>> + struct hid_field *aux1_field, *brightness_field;
> >>>> + struct backlight_device *bdev;
> >>>> +
> >>>> + bool full_on;
> >>>> +};
> >>>> +
> >>>> +const u8 appletb_bl_brightness_map[] = {
> >>> 
> >>> static?
> >>> 
> >>>> + APPLETB_BL_OFF,
> >>>> + APPLETB_BL_DIM,
> >>>> + APPLETB_BL_ON
> >>> 
> >>> The last element is not a sentinel element, so it should have comma.
> >> 
> >> static const u8 appletb_bl_brightness_map[] = {
> >> APPLETB_BL_OFF,
> >> APPLETB_BL_DIM,
> >> APPLETB_BL_ON,
> >> };
> >> 
> >> This?
> > 
> > Yes.
> > 
> >>> 
> >>>> +};
> >>>> +
> >>>> +static int appletb_bl_set_brightness(struct appletb_bl *bl, u8 brightness)
> >>>> +{
> >>>> + struct hid_report *report = bl->brightness_field->report;
> >>>> + struct hid_device *hdev = report->device;
> >>>> + int ret;
> >>>> +
> >>>> + ret = hid_set_field(bl->aux1_field, 0, 1);
> >>>> + if (ret) {
> >>>> + hid_err(hdev, "Failed to set auxiliary field (%pe)\n", ERR_PTR(ret));
> >>>> + return ret;
> >>>> + }
> >>>> +
> >>>> + ret = hid_set_field(bl->brightness_field, 0, brightness);
> >>>> + if (ret) {
> >>>> + hid_err(hdev, "Failed to set brightness field (%pe)\n", ERR_PTR(ret));
> >>>> + return ret;
> >>>> + }
> >>>> +
> >>>> + if (!bl->full_on) {
> >>>> + ret = hid_hw_power(hdev, PM_HINT_FULLON);
> >>>> + if (ret < 0) {
> >>>> + hid_err(hdev, "Device didn't power on (%pe)\n", ERR_PTR(ret));
> >>>> + return ret;
> >>>> + }
> >>>> +
> >>>> + bl->full_on = true;
> >>>> + }
> >>>> +
> >>>> + hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
> >>>> +
> >>>> + if (brightness == APPLETB_BL_OFF) {
> >>>> + hid_hw_power(hdev, PM_HINT_NORMAL);
> >>>> + bl->full_on = false;
> >>>> + }
> >>>> +
> >>>> + return 0;
> >>>> +}
> >>>> +
> >>>> +static int appletb_bl_update_status(struct backlight_device *bdev)
> >>>> +{
> >>>> + struct appletb_bl *bl = bl_get_data(bdev);
> >>>> + u16 brightness;
> >>>> +
> >>>> + if (bdev->props.state & BL_CORE_SUSPENDED)
> >>>> + brightness = 0;
> >>> 
> >>> From backlight.h:
> >>> 
> >>> * backlight drivers are expected to use backlight_is_blank()
> >>> * in their update_status() operation rather than reading the
> >>> * state property.
> >>> 
> >>> Seems to be applicable here.
> >>> 
> >>> Also the hardcoded "0" as index into appletb_bl_brightness_map could be
> >>> avoided by some restructuring.
> >> 
> >> static int appletb_bl_update_status(struct backlight_device *bdev)
> >> {
> >> struct appletb_bl *bl = bl_get_data(bdev);
> >> u16 brightness;
> >> 
> >> if (backlight_is_blank(bdev))
> >> brightness = APPLETB_BL_OFF;
> >> else
> >> brightness = backlight_get_brightness(bdev);
> >> 
> >> return appletb_bl_set_brightness(bl, appletb_bl_brightness_map[brightness]);
> >> }
> >> 
> >> This?
> > 
> > This now looks to be a different logic than before.
> > Below should be the same as in the original patch.
> > 
> > static int appletb_bl_update_status(struct backlight_device *bdev)
> > {
> > struct appletb_bl *bl = bl_get_data(bdev);
> > u8 brightness;
> > 
> > if (backlight_is_blank(bdev))
> > brightness = APPLETB_BL_OFF;
> > else
> > brightness = appletb_bl_brightness_map[backlight_get_brightness(bdev)]);
> > 
> > return appletb_bl_set_brightness(bl, brightness);
> > }
> 
> I’ll replace the original code with this
> 
> > 
> > Maybe it's worth to make APPLETB_BL_* an enum for more clarity.
> 
> I don’t think there is a specific need for an enum here
> 
> If you are fine with these changes, I’ll send a v5

Sounds good.

FYI I'll also review the other patches soonish.
So sending a v5 right away is not necessary.

  reply	other threads:[~2024-08-10 16:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08 13:49 [PATCH v3 0/9] Touch Bar support for T2 Macs Aditya Garg
2024-08-08 13:50 ` [PATCH v3 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Aditya Garg
2024-08-10 12:16   ` Thomas Weißschuh
2024-08-10 13:23     ` Aditya Garg
2024-08-10 14:33       ` Thomas Weißschuh
2024-08-10 15:30         ` Aditya Garg
2024-08-10 16:26           ` Thomas Weißschuh [this message]
2024-08-10 16:42             ` Aditya Garg
2024-08-08 13:51 ` [PATCH v3 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode Aditya Garg
2024-08-08 13:52 ` [PATCH v3 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Aditya Garg
2024-08-08 13:53 ` [PATCH v3 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Aditya Garg
2024-08-08 13:53 ` [PATCH v3 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Aditya Garg
2024-08-08 13:54 ` [PATCH v3 6/9] HID: multitouch: allow specifying if a device is direct in a class Aditya Garg
2024-08-08 13:55 ` [PATCH v3 7/9] HID: multitouch: add device ID for Apple Touch Bars Aditya Garg
2024-08-08 13:56 ` [PATCH v3 8/9] drm/format-helper: Add conversion from XRGB8888 to BGR888 Aditya Garg
2024-08-08 13:57 ` [PATCH v3 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Aditya Garg
2024-08-10  8:51 ` [PATCH v3 0/9] Touch Bar support for T2 Macs Aditya Garg

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=1166bdaa-ea14-430a-be2e-9593cc08491a@t-8ch.de \
    --to=thomas@t-8ch.de \
    --cc=airlied@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gargaditya08@live.com \
    --cc=jikos@kernel.org \
    --cc=kekrby@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=orlandoch.dev@gmail.com \
    --cc=tzimmermann@suse.de \
    /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