Re: [PATCH v3 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-08-08 13:50:33+0000, Aditya Garg wrote:
> From: Kerem Karabay <kekrby@xxxxxxxxx>
> 
> This commit adds a driver for the backlight of Apple Touch Bars on x86
> Macs. Note that currently only T2 Macs are supported.
> 
> This driver is based on previous work done by Ronald Tschalär
> <ronald@xxxxxxxxxxxxx>.
> 
> Signed-off-by: Kerem Karabay <kekrby@xxxxxxxxx>
> Co-developed-by: Aditya Garg <gargaditya08@xxxxxxxx>
> Signed-off-by: Aditya Garg <gargaditya08@xxxxxxxx>
> ---
>  MAINTAINERS                  |   6 +
>  drivers/hid/Kconfig          |  10 ++
>  drivers/hid/Makefile         |   1 +
>  drivers/hid/hid-appletb-bl.c | 206 +++++++++++++++++++++++++++++++++++
>  drivers/hid/hid-quirks.c     |   4 +-
>  5 files changed, 226 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/hid/hid-appletb-bl.c
> 

<snip>

> diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
> index e40f1ddeb..1d825a474 100644
> --- a/drivers/hid/Makefile
> +++ b/drivers/hid/Makefile
> @@ -29,6 +29,7 @@ obj-$(CONFIG_HID_ALPS)		+= hid-alps.o
>  obj-$(CONFIG_HID_ACRUX)		+= hid-axff.o
>  obj-$(CONFIG_HID_APPLE)		+= hid-apple.o
>  obj-$(CONFIG_HID_APPLEIR)	+= hid-appleir.o
> +obj-$(CONFIG_HID_APPLETB_BL)	+= hid-appletb-bl.o
>  obj-$(CONFIG_HID_CREATIVE_SB0540)	+= hid-creative-sb0540.o
>  obj-$(CONFIG_HID_ASUS)		+= hid-asus.o
>  obj-$(CONFIG_HID_AUREAL)	+= hid-aureal.o
> diff --git a/drivers/hid/hid-appletb-bl.c b/drivers/hid/hid-appletb-bl.c
> new file mode 100644
> index 000000000..00bbe45df
> --- /dev/null
> +++ b/drivers/hid/hid-appletb-bl.c
> @@ -0,0 +1,206 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Apple Touch Bar Backlight Driver
> + *
> + * Copyright (c) 2017-2018 Ronald Tschalär
> + * Copyright (c) 2022-2023 Kerem Karabay <kekrby@xxxxxxxxx>
> + */
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

This is unused.

#include <linux/device.h>

> +#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 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;


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux