Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3431564imm; Fri, 19 Oct 2018 10:25:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV60OiHHdafK+mWxL1R180QCaGIddYQ47olgKp0JK/PY/Iz5MeXu4YMit444Eorp9fWQXl/0F X-Received: by 2002:a63:3842:: with SMTP id h2-v6mr33151106pgn.300.1539969959631; Fri, 19 Oct 2018 10:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539969959; cv=none; d=google.com; s=arc-20160816; b=HrvAr1WOXmhh/aXm/4aR+B/ezIm5b9mhBGfg/zN7JJ1YQtkyZPNbyejShrbqNdYSEJ JKH3RM46kV5FTmklOCFg+9VS1sOWupHZA3cf67TmTAL6GqLCC5mgq4IIL18d/lSGMb8w pW6UC4q2EzDLLK3P50GGdSvXPZkSvP4PSb/ctiGebHlLEjtZ5u7MLd/+fXlI3GfWS4R5 ODoNGini0kqGFUtIo0zlbS9Ac0BOvr+8G+pUyPE6uPMtjI6h1jhxoiiIfycFW4ieZSb1 k2HQqghxti27ULgk5OTN5dzXKMlgw26bxr/id1Hh8gpWlJtpj6xyZaczliMnWiG3uIf6 Enww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=7sOtaCfGv3XPmy9eLXbtDvskSPGo9WXp7d0PkNXoOCI=; b=liMpyXLWtfyn3AUT2GSlbil5Az0WA8VUKYexKfFtQ3bP5oEeW1gMe5jqDOB/OQ/qJV hnElBqKTOOSrrulaid4r4a6JsvgIgdKCsViWk7+1N11S5EY93G7EPJVyT4geJD+KIPws mcWi7160SOh6xNhj8VP893IE334xnsfxr6xbohgVGH0N6qtZ63+VHIaI6X/4GJEhd+eH jG6lH6rSM111yz1SSSCB/S3LPmXlgCdIp9kmfdZ9CjkxyMkvkfZd1HwiyIo51nTgqIh6 KBrDrQnmi70X1qAL5oovRJvgSTZaPrlWSx8YujVzLdJ7Bd197ucCgxeY1P3TCqyggszb /Eog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8-v6si26961514pls.13.2018.10.19.10.25.43; Fri, 19 Oct 2018 10:25:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727987AbeJTBcG (ORCPT + 99 others); Fri, 19 Oct 2018 21:32:06 -0400 Received: from mr41.theemaillaundry.net ([109.169.43.45]:38084 "EHLO mr41.theemaillaundry.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727589AbeJTBcF (ORCPT ); Fri, 19 Oct 2018 21:32:05 -0400 X-Greylist: delayed 539 seconds by postgrey-1.27 at vger.kernel.org; Fri, 19 Oct 2018 21:32:03 EDT Received: from mr40.theemaillaundry.net (mr40.theemaillaundry.net [109.169.43.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mr41.theemaillaundry.net (Postfix) with ESMTPS id 1E0AD204BA; Fri, 19 Oct 2018 18:16:06 +0100 (IST) Received: from mr30.theemaillaundry.net (mr30.theemaillaundry.net [78.46.72.43]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mr40.theemaillaundry.net (Postfix) with ESMTPS id 7BED73FE19; Fri, 19 Oct 2018 18:16:04 +0100 (IST) Received: from localhost (localhost [127.0.0.1]) by mr30.theemaillaundry.net (Postfix) with ESMTP id 96CA92416CA; Fri, 19 Oct 2018 18:16:02 +0100 (IST) X-Amavis-Modified: Mail body modified (using disclaimer) - mr30.theemaillaundry.net X-Virus-Scanned: amavisd-new at theemaillaundry.net Received: from mr30.theemaillaundry.net ([127.0.0.1]) by localhost (mr30.theemaillaundry.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M_MtmGFBGKEi; Fri, 19 Oct 2018 18:16:01 +0100 (IST) Received: from statler.emutex.com (unknown [92.51.199.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mr30.theemaillaundry.net (Postfix) with ESMTPS id 801872414F6; Fri, 19 Oct 2018 18:16:01 +0100 (IST) Received: from [10.10.68.81] (helo=dan-Latitude-E5450.emutex.com) by statler.emutex.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84) (envelope-from ) id 1gDYNT-0005CM-LS; Fri, 19 Oct 2018 18:16:01 +0100 From: Dan O'Donovan To: linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Mika Westerberg , Heikki Krogerus , Lee Jones , Linus Walleij , Jacek Anaszewski , Pavel Machek , linux-gpio@vger.kernel.org, linux-leds@vger.kernel.org, Carlos Iglesias , Javier Arteaga , Dan O'Donovan Subject: [PATCH v2 2/3] leds: upboard: Add LED support Date: Fri, 19 Oct 2018 18:15:33 +0100 Message-Id: <1539969334-24577-3-git-send-email-dan@emutex.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1539969334-24577-1-git-send-email-dan@emutex.com> References: <20180421085009.28773-1-javier@emutex.com> <1539969334-24577-1-git-send-email-dan@emutex.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Javier Arteaga Allow userspace to use the on-board LEDs as "upboard::". Acked-by: Pavel Machek Signed-off-by: Javier Arteaga Signed-off-by: Dan O'Donovan --- drivers/leds/Kconfig | 10 +++++ drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 drivers/leds/leds-upboard.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 44097a3..0ed8857 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -756,6 +756,16 @@ config LEDS_NIC78BX To compile this driver as a module, choose M here: the module will be called leds-nic78bx. +config LEDS_UPBOARD + tristate "LED support for the UP Squared" + depends on LEDS_CLASS + depends on MFD_UPBOARD + help + This option enables support for the LEDs on the UP Squared board. + + This driver can also be built as a module. If so, the module + will be called leds-upboard. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 420b5d2..c85f18f 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -78,6 +78,7 @@ obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o +obj-$(CONFIG_LEDS_UPBOARD) += leds-upboard.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o diff --git a/drivers/leds/leds-upboard.c b/drivers/leds/leds-upboard.c new file mode 100644 index 0000000..34a6973 --- /dev/null +++ b/drivers/leds/leds-upboard.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// UP Board LED driver +// +// Copyright (c) 2018, Emutex Ltd. +// +// Author: Javier Arteaga +// + +#include +#include +#include +#include +#include +#include +#include + +#define to_upboard_led(cdev) container_of(cdev, struct upboard_led, cdev) + +static const char * const upboard_led_names[] = { + "upboard:blue:", + "upboard:yellow:", + "upboard:green:", + "upboard:red:", +}; + +struct upboard_led { + struct regmap_field *field; + struct led_classdev cdev; +}; + +static enum led_brightness upboard_led_brightness_get(struct led_classdev *cdev) +{ + struct upboard_led *led = to_upboard_led(cdev); + int brightness = 0; + + regmap_field_read(led->field, &brightness); + + return brightness; +} + +static void upboard_led_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct upboard_led *led = to_upboard_led(cdev); + + regmap_field_write(led->field, brightness); +} + +static int upboard_led_probe(struct platform_device *pdev) +{ + unsigned int led_index = pdev->id; + struct device *dev = &pdev->dev; + struct acpi_device *adev; + struct upboard_led *led; + struct regmap *regmap; + struct reg_field conf = { + .reg = UPBOARD_REG_FUNC_EN0, + .lsb = led_index, + .msb = led_index, + }; + + adev = ACPI_COMPANION(dev); + if (!adev || strcmp(acpi_device_hid(adev), "AANT0F01")) + return -ENODEV; + + if (led_index >= ARRAY_SIZE(upboard_led_names)) + return -EINVAL; + + if (!dev->parent) + return -EINVAL; + + regmap = dev_get_regmap(dev->parent, NULL); + if (!regmap) + return -EINVAL; + + led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + led->field = devm_regmap_field_alloc(dev, regmap, conf); + if (IS_ERR(led->field)) + return PTR_ERR(led->field); + + led->cdev.max_brightness = 1; + led->cdev.brightness_get = upboard_led_brightness_get; + led->cdev.brightness_set = upboard_led_brightness_set; + led->cdev.name = upboard_led_names[led_index]; + + return devm_led_classdev_register(dev, &led->cdev); +} + +static struct platform_driver upboard_led_driver = { + .driver = { + .name = "upboard-led", + }, +}; + +module_platform_driver_probe(upboard_led_driver, upboard_led_probe); + +MODULE_ALIAS("platform:upboard-led"); +MODULE_AUTHOR("Javier Arteaga "); +MODULE_DESCRIPTION("UP Board LED driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4 ------ This email has been scanned for spam and malware by The Email Laundry.