linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy@infradead.org>
To: Aditya Garg <gargaditya08@live.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	"jkosina@suse.cz" <jkosina@suse.cz>,
	"benjamin.tissoires@redhat.com" <benjamin.tissoires@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"ronald@innovation.ch" <ronald@innovation.ch>,
	"kekrby@gmail.com" <kekrby@gmail.com>,
	Orlando Chamberlain <orlandoch.dev@gmail.com>
Subject: Re: [PATCH 2/3] HID: apple-touchbar: Add driver for the Touch Bar on MacBook Pros
Date: Sun, 12 Feb 2023 13:56:01 +0200	[thread overview]
Message-ID: <Y+jT0cDmlutS5CHg@smile.fi.intel.com> (raw)
In-Reply-To: <868AA58D-2399-4E4A-A6C6-73F88DB13992@live.com>

On Fri, Feb 10, 2023 at 03:44:26AM +0000, Aditya Garg wrote:
> From: Ronald Tschalär <ronald@innovation.ch>
> 
> This driver enables basic touch bar functionality: enabling it, switching
> between modes on FN key press, and dimming and turning the display
> off/on when idle/active.

...

> Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
> [Kerem Karabay: use USB product IDs from hid-ids.h]
> [Kerem Karabay: use hid_hw_raw_request except when setting the touchbar mode on T1 Macs]
> [Kerem Karabay: update Kconfig description]
> Signed-off-by: Kerem Karabay <kekrby@gmail.com>
> [Orlando Chamberlain: add usage check to not bind to keyboard backlight interface]
> Signed-off-by: Orlando Chamberlain <orlandoch.dev@gmail.com>
> [Aditya Garg: check if apple-touchbar is enabled in the special driver list]
> [Aditya Garg: fix suspend on T2 Macs]

Are you going to use this as a changelog? Not okay for a list of changes.
Consider Co-developed-by and proper Changelog in the cover letter.

> Signed-off-by: Aditya Garg <gargaditya08@live.com>

...

> +config HID_APPLE_TOUCHBAR
> +	tristate "Apple Touch Bar"
> +	depends on USB_HID
> +	help

> +	Say Y here if you want support for the Touch Bar on x86
> +	MacBook Pros.
> +
> +	To compile this driver as a module, choose M here: the
> +	module will be called apple-touchbar.

Wrong indentation for the help description. Missing two spaces.

...

> +#define dev_fmt(fmt) "tb: " fmt

Do we really need this?

...


> +static ssize_t idle_timeout_show(struct device *dev,
> +				 struct device_attribute *attr, char *buf);
> +static ssize_t idle_timeout_store(struct device *dev,
> +				  struct device_attribute *attr,
> +				  const char *buf, size_t size);

> +static ssize_t dim_timeout_show(struct device *dev,
> +				struct device_attribute *attr, char *buf);
> +static ssize_t dim_timeout_store(struct device *dev,
> +				 struct device_attribute *attr,
> +				 const char *buf, size_t size);

> +static ssize_t fnmode_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf);
> +static ssize_t fnmode_store(struct device *dev, struct device_attribute *attr,
> +			    const char *buf, size_t size);

Make sure you will have no unnecessary forward declarations.

...

> +static struct attribute *appletb_attrs[] = {
> +	&dev_attr_idle_timeout.attr,
> +	&dev_attr_dim_timeout.attr,
> +	&dev_attr_fnmode.attr,

> +	NULL,

No comma for terminator entry.

> +};

...

> +static struct appletb_device *appletb_dev;

Why is it global?

...

> +static bool appletb_disable_autopm(struct hid_device *hdev)
> +{
> +	int rc;
> +
> +	rc = hid_hw_power(hdev, PM_HINT_FULLON);

> +

Redundant blank line and see below.

> +	if (rc == 0)
> +		return true;
> +
> +	hid_err(hdev,
> +		"Failed to disable auto-pm on touch bar device (%d)\n", rc);
> +	return false;


	if (rc)
		hid_err(...);

	return rc == 0;

> +}

...

> +static bool appletb_any_tb_key_pressed(struct appletb_device *tb_dev)
> +{
> +	return !!memchr_inv(tb_dev->last_tb_keys_pressed, 0,
> +			    sizeof(tb_dev->last_tb_keys_pressed));

Sounds like last_tb_keys_pressed should be declared as a bitmap and hence

	return !bitmap_empty(...);

> +}

...

> +static ssize_t idle_timeout_show(struct device *dev,
> +				 struct device_attribute *attr, char *buf)
> +{
> +	struct appletb_device *tb_dev = dev_get_drvdata(dev);
> +
> +	return snprintf(buf, PAGE_SIZE, "%d\n", tb_dev->idle_timeout);

sysfs_emit().

> +}

...

> +static ssize_t idle_timeout_store(struct device *dev,
> +				  struct device_attribute *attr,
> +				  const char *buf, size_t size)
> +{
> +	struct appletb_device *tb_dev = dev_get_drvdata(dev);
> +	long new;
> +	int rc;
> +
> +	rc = kstrtol(buf, 0, &new);
> +	if (rc || new > INT_MAX || new < -2)
> +		return -EINVAL;

Do not shadow the error code.

	if (rc)
		return rc;

Why do you use INT_MAX check with to-long conversion instead of simply calling
kstrtoint()?


> +	appletb_set_idle_timeout(tb_dev, new);
> +	appletb_update_touchbar(tb_dev, true);
> +
> +	return size;
> +}

...

> +static ssize_t dim_timeout_show(struct device *dev,
> +				struct device_attribute *attr, char *buf)
> +{
> +	struct appletb_device *tb_dev = dev_get_drvdata(dev);
> +
> +	return snprintf(buf, PAGE_SIZE, "%d\n",
> +			tb_dev->dim_to_is_calc ? -2 : tb_dev->dim_timeout);

sysfs_emit()

> +}
> +
> +static ssize_t dim_timeout_store(struct device *dev,
> +				 struct device_attribute *attr,
> +				 const char *buf, size_t size)
> +{

As per above.

> +}
> +
> +static ssize_t fnmode_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
> +{

As per above.

> +}
> +
> +static ssize_t fnmode_store(struct device *dev, struct device_attribute *attr,
> +			    const char *buf, size_t size)
> +{

As per above.

> +}

...

> +static int appletb_tb_key_to_slot(unsigned int code)
> +{
> +	switch (code) {
> +	case KEY_ESC:
> +		return 0;
> +	case KEY_F1:
> +	case KEY_F2:
> +	case KEY_F3:
> +	case KEY_F4:
> +	case KEY_F5:
> +	case KEY_F6:
> +	case KEY_F7:
> +	case KEY_F8:
> +	case KEY_F9:
> +	case KEY_F10:
> +		return code - KEY_F1 + 1;
> +	case KEY_F11:
> +	case KEY_F12:
> +		return code - KEY_F11 + 11;
> +	default:
> +		return -1;

Use appropriate error code from errno.h.

> +	}
> +}

...

> +	{ },			/* Terminating zero entry */

No comma.

...

> +static bool appletb_match_internal_device(struct input_handler *handler,
> +					  struct input_dev *inp_dev)
> +{
> +	struct device *dev = &inp_dev->dev;
> +
> +	if (inp_dev->id.bustype == BUS_SPI)
> +		return true;
> +
> +	/* in kernel: dev && !is_usb_device(dev) */
> +	while (dev && !(dev->type && dev->type->name &&
> +			!strcmp(dev->type->name, "usb_device")))
> +		dev = dev->parent;

I believe we have some helpers to mach like this.

> +	/*
> +	 * Apple labels all their internal keyboards and trackpads as such,
> +	 * instead of maintaining an ever expanding list of product-id's we
> +	 * just look at the device's product name.
> +	 */
> +	if (dev)
> +		return !!strstr(to_usb_device(dev)->product, "Internal Keyboard");
> +
> +	return false;
> +}

...

> +static int appletb_probe(struct hid_device *hdev,
> +			 const struct hid_device_id *id)

Can be a single line.

...

> +	rc = hid_parse(hdev);
> +	if (rc) {
> +		dev_err(tb_dev->log_dev, "hid parse failed (%d)\n", rc);
> +		goto error;

return dev_err_probe(...);

(error label seems useless)

> +	}

...

> +	if ((hdev->product == USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) &&
> +			!(hdev->collection && hdev->collection[0].usage ==
> +				HID_USAGE_APPLE_APP)) {

Broken indentation.

> +		return -ENODEV;
> +	}

...

> +	if (rc) {
> +		dev_err(tb_dev->log_dev, "hw start failed (%d)\n", rc);

dev_err_probe()

It will unite the style of error messaging.

> +		goto clear_iface_info;
> +	}

> +	rc = hid_hw_open(hdev);
> +	if (rc) {
> +		dev_err(tb_dev->log_dev, "hw open failed (%d)\n", rc);

Ditto. And so on.

> +		goto stop_hid;
> +	}

...

> +		/* initialize sysfs attributes */
> +		rc = sysfs_create_group(&tb_dev->mode_iface.hdev->dev.kobj,
> +					&appletb_attr_group);
> +		if (rc) {
> +			dev_err(tb_dev->log_dev,
> +				"Failed to create sysfs attributes (%d)\n", rc);
> +			goto unreg_handler;
> +		}

Can't you use .dev_groups?

> +	}

...

> +	/* MacBook Pro's 2018, 2019, with T2 chip: iBridge Display */
> +	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
> +			USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) },
> +	{ },

No comma.

...

> +

Redundant blank line.

> +MODULE_DEVICE_TABLE(hid, appletb_hid_ids);

...

> +#ifdef CONFIG_PM
> +	.suspend = appletb_suspend,
> +	.reset_resume = appletb_reset_resume,
> +#endif

Why not using .driver.pm ?

...

> +module_init(appletb_init);
> +module_exit(appletb_exit);

Just move them closer to the implementation.

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2023-02-12 11:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10  3:41 [PATCH 0/3] Touch Bar and Keyboard backlight driver for Intel Macs Aditya Garg
2023-02-10  3:43 ` [PATCH 1/3] HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip Aditya Garg
2023-02-10  3:44   ` [PATCH 2/3] HID: apple-touchbar: Add driver for the Touch Bar on MacBook Pros Aditya Garg
2023-02-10  3:45     ` [PATCH 3/3] HID: apple-magic-backlight: Add driver for keyboard backlight on internal Magic Keyboards Aditya Garg
2023-02-10 16:25       ` Thomas Weißschuh
2023-02-10 23:24         ` Orlando Chamberlain
2023-02-11  2:23           ` Thomas Weißschuh
2023-02-11  2:42             ` Thomas Weißschuh
2023-02-11 16:56       ` Pavel Machek
2023-02-12  2:28         ` Orlando Chamberlain
2023-02-12  5:16         ` Aditya Garg
2023-02-12 11:18       ` Andy Shevchenko
2023-02-16  1:17         ` Orlando Chamberlain
2023-02-10 16:13     ` [PATCH 2/3] HID: apple-touchbar: Add driver for the Touch Bar on MacBook Pros Thomas Weißschuh
2023-02-12 11:56     ` Andy Shevchenko [this message]
2023-02-10  4:56   ` [PATCH 1/3] HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip Thomas Weißschuh
2023-02-10  8:30     ` Aditya Garg
2023-02-10  8:39       ` Benjamin Tissoires
2023-02-10  8:54         ` Aditya Garg
2023-02-10  9:21           ` Benjamin Tissoires
2023-02-10 12:05     ` Aditya Garg
2023-02-10 12:20       ` Orlando Chamberlain
2023-02-10 13:07         ` Aditya Garg
2023-02-10 14:01           ` Benjamin Tissoires
2023-02-10 15:33       ` Thomas Weißschuh
2023-02-10 15:49         ` Aditya Garg
2023-02-10 18:36           ` Thomas Weißschuh 
2023-02-12 11:35   ` Andy Shevchenko
2023-02-10 10:18 ` [PATCH 0/3] Touch Bar and Keyboard backlight driver for Intel Macs Andy Shevchenko
2023-02-10 10:41   ` Aditya Garg
2023-02-10 10:47     ` Orlando Chamberlain
2023-02-10 11:12       ` Andy Shevchenko

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=Y+jT0cDmlutS5CHg@smile.fi.intel.com \
    --to=andy@infradead.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=gargaditya08@live.com \
    --cc=jikos@kernel.org \
    --cc=jkosina@suse.cz \
    --cc=kekrby@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orlandoch.dev@gmail.com \
    --cc=ronald@innovation.ch \
    /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).