All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacek Anaszewski <j.anaszewski@samsung.com>
To: Simon Que <sque@chromium.org>
Cc: Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	linux-leds@vger.kernel.org, Sameer Nanda <snanda@chromium.org>,
	Todd Broch <tbroch@chromium.org>,
	Duncan Laurie <dlaurie@chromium.org>,
	Evan McClain <aeroevan@gmail.com>
Subject: Re: [PATCH v3] leds: Add Chrome OS keyboard LEDs driver
Date: Thu, 21 Jan 2016 11:23:53 +0100	[thread overview]
Message-ID: <56A0B1B9.3060607@samsung.com> (raw)
In-Reply-To: <1452625899-13306-1-git-send-email-sque@chromium.org>

Hi Simon,

Thanks for the patch.

On 01/12/2016 08:11 PM, Simon Que wrote:
> Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
>
> Enable with menuconfig option under Device Drivers -> LED Support.
>
> Signed-off-by: Simon Que <sque@chromium.org>
> ---
>   drivers/leds/Kconfig                  |   7 +++
>   drivers/leds/Makefile                 |   1 +
>   drivers/leds/leds-chromeos-keyboard.c | 115 ++++++++++++++++++++++++++++++++++
>   3 files changed, 123 insertions(+)
>   create mode 100644 drivers/leds/leds-chromeos-keyboard.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 7f940c2..38d2997 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -607,6 +607,13 @@ config LEDS_VERSATILE
>   	  This option enabled support for the LEDs on the ARM Versatile
>   	  and RealView boards. Say Y to enabled these.
>
> +config LEDS_CHROMEOS_KEYBOARD
> +	tristate "LED support for Chrome OS keyboards"
> +	depends on LEDS_CLASS && ACPI
> +	help
> +	  This option enables support for the LEDs on Chrome OS keyboards.
> +	  Say Y to enable keyboard LEDs on Chrome OS systems.
> +
>   comment "LED Triggers"
>   source "drivers/leds/trigger/Kconfig"
>
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index e9d53092..2d7f73a 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MENF21BMC)		+= leds-menf21bmc.o
>   obj-$(CONFIG_LEDS_KTD2692)		+= leds-ktd2692.o
>   obj-$(CONFIG_LEDS_POWERNV)		+= leds-powernv.o
>   obj-$(CONFIG_LEDS_SEAD3)		+= leds-sead3.o
> +obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD)	+= leds-chromeos-keyboard.o
>
>   # LED SPI Drivers
>   obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
> diff --git a/drivers/leds/leds-chromeos-keyboard.c b/drivers/leds/leds-chromeos-keyboard.c
> new file mode 100644
> index 0000000..32d70c0
> --- /dev/null
> +++ b/drivers/leds/leds-chromeos-keyboard.c
> @@ -0,0 +1,115 @@
> +/*
> + *  LED driver for Chrome OS keyboard backlight
> + *
> + *  Copyright (C) 2012 Google, Inc.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/leds.h>
> +#include <linux/delay.h>
> +#include <linux/err.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +/* Keyboard LED ACPI Device must be defined in firmware */
> +#define ACPI_KEYBOARD_BACKLIGHT_DEVICE	"\\_SB.KBLT"
> +#define ACPI_KEYBOARD_BACKLIGHT_READ	ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
> +#define ACPI_KEYBOARD_BACKLIGHT_WRITE	ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
> +
> +#define ACPI_KEYBOARD_BACKLIGHT_MAX		100
> +
> +static void keyboard_led_set_brightness(struct led_classdev *cdev,
> +					enum led_brightness brightness)
> +{
> +	union acpi_object param;
> +	struct acpi_object_list input;
> +	acpi_status status;
> +
> +	if (!(cdev->flags & LED_SUSPENDED))
> +		cdev->brightness = brightness;
> +
> +	param.type = ACPI_TYPE_INTEGER;
> +	param.integer.value = brightness;
> +	input.count = 1;
> +	input.pointer = &param;
> +
> +	status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
> +					  &input, NULL);
> +	if (ACPI_FAILURE(status))
> +		dev_err(cdev->dev, "Error setting keyboard LED value");
> +}
> +
> +static int keyboard_led_probe(struct platform_device *pdev)
> +{
> +	struct led_classdev *cdev;
> +	acpi_handle handle;
> +	acpi_status status;
> +	int ret;
> +
> +	/* Look for the keyboard LED ACPI Device */
> +	status = acpi_get_handle(ACPI_ROOT_OBJECT,
> +				 ACPI_KEYBOARD_BACKLIGHT_DEVICE,
> +				 &handle);
> +	if (ACPI_FAILURE(status)) {
> +		dev_err(&pdev->dev, "Unable fo find ACPI device %s\n",
> +			ACPI_KEYBOARD_BACKLIGHT_DEVICE);
> +		return -ENODEV;
> +	}
> +
> +	cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
> +	if (!cdev)
> +		return -ENOMEM;
> +	cdev->name = "chromeos::kbd_backlight";
> +	cdev->brightness_set = keyboard_led_set_brightness;
> +	cdev->max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX;
> +	cdev->brightness = cdev->max_brightness;
> +	cdev->flags |= LED_CORE_SUSPENDRESUME;
> +
> +	ret = led_classdev_register(&pdev->dev, cdev);
> +	if (ret)
> +		goto err;
> +
> +	platform_set_drvdata(pdev, cdev);
> +	return 0;
> +err:
> +	kfree(cdev);
> +	return ret;
> +}
> +
> +static int keyboard_led_remove(struct platform_device *pdev)
> +{
> +	struct led_classdev *cdev = platform_get_drvdata(pdev);

You're missing led_classdev_unregister here.
It wouldn't be required if the LED was registered with
devm_led_classdev_register.

Please switch to devm_led_classdev_register.
kzalloc has to be switched to devm_kzalloc in this case too.

> +
> +	platform_set_drvdata(pdev, NULL);
> +	kfree(cdev);
> +	return 0;
> +}
> +
> +static struct platform_driver keyboard_led_driver = {
> +	.driver		= {
> +		.name	= "chromeos-keyboard-leds",
> +		.owner	= THIS_MODULE,
> +	},
> +	.probe		= keyboard_led_probe,
> +	.remove		= keyboard_led_remove,
> +};
> +
> +module_platform_driver(keyboard_led_driver);
> +
> +MODULE_AUTHOR("Simon Que <sque@chromium.org>");
> +MODULE_DESCRIPTION("ChromeOS Keyboard LED Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:chromeos-keyboard-leds");
>


-- 
Best Regards,
Jacek Anaszewski

      parent reply	other threads:[~2016-01-21 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 19:11 [PATCH v3] leds: Add Chrome OS keyboard LEDs driver Simon Que
2016-01-14  2:23 ` [PATCH 2/2] leds: leds-chromeos-keyboard: Add ACPI _HID probing Evan McClain
2016-02-21 19:07   ` [PATCH] leds: chromeos: Use devm_led_classdev_register Evan McClain
2016-02-22  8:04     ` Jacek Anaszewski
2016-01-21 10:23 ` Jacek Anaszewski [this message]

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=56A0B1B9.3060607@samsung.com \
    --to=j.anaszewski@samsung.com \
    --cc=aeroevan@gmail.com \
    --cc=cooloney@gmail.com \
    --cc=dlaurie@chromium.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    --cc=snanda@chromium.org \
    --cc=sque@chromium.org \
    --cc=tbroch@chromium.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.