Received: by 10.192.165.148 with SMTP id m20csp1137358imm; Sat, 21 Apr 2018 01:56:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49u7rtOMucdpOj+gbCAIl+EveB5VGgX6snN/XcBokY7FhugBDauboz+J2NBibRZa7qi7L3K X-Received: by 10.99.148.1 with SMTP id m1mr10851974pge.140.1524301012606; Sat, 21 Apr 2018 01:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524301012; cv=none; d=google.com; s=arc-20160816; b=K9Ix6pcrxGJF0fM3PXL5e1L2xcM7lw+t0aSs118w2pGjQMQ3c//dDMcWcJLqSfLvGb aROmpyNTR/0lYcxLrV7ti70BRk2Dl5OcWyoumUexiDe6Xu262786w8C3uk3CmgujXZR1 JNaorgjfzdEnqwNH0PjOvQrHryHUXYM7tTrvZwdUDXhMkdEzgPgTz4sSOuP1D3ljud+d 0nLA3FJnOZ8KoytOrOTvJ3lfjQHoLiX286aORZ8CRgHoJ/nOYqjH0YyJSGU42hrZPZEQ MCBdQ+6244ArocgN+LMVeeLKmwL+q3TVsahQe55/DBXbMrthRdQhVSrlcIKN6xcpbadv TN+Q== 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:arc-authentication-results; bh=v7ndC8FKOu5Y288F7QkVi5Pi3q0Ofa7LMGuLhH8xPWQ=; b=A5OjBbCCcjMoqeoAY9MPbrZfwOKxk2JvuO28al94AtvcNu1AOwwWnSv5PnDDsy2ojt La5MQiluwWBVtpzWr3cpSyqg8L+qFihayUb8cvtYsO2laS6BOkZmz5OvsQnuavzit+Lx ORU2GPT0WHTcF9zuw38LhlI2n6g40YVt2mxYqXY00v6MfTgaWH1gMs8UWpHpWSfoq/Yc HcwnqN4iOLjly6zKEKos2CHNeCuxwSO1doeL/VsGNIXgyaqt5T2IyjQ4CCkZmoGX5p7q vaHaTpv10RstyftvGRCz5rVniDOxVnFv/kWJedKFJnTl/i9VwCejr9pfBM6rbRrIBKJ9 +0RA== 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 e19si6679175pff.73.2018.04.21.01.56.15; Sat, 21 Apr 2018 01:56:52 -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 S1753041AbeDUIvS (ORCPT + 99 others); Sat, 21 Apr 2018 04:51:18 -0400 Received: from bert.emutex.com ([91.103.1.109]:53863 "EHLO bert.emutex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547AbeDUIur (ORCPT ); Sat, 21 Apr 2018 04:50:47 -0400 Received: from [92.51.199.138] (helo=statler.emutex.com) by bert.emutex.com with esmtp (Exim 4.84) (envelope-from ) id 1f9oEu-0005dl-G0; Sat, 21 Apr 2018 09:51:24 +0100 Received: from 182.red-79-157-43.dynamicip.rima-tde.net ([79.157.43.182] helo=localhost) by statler.emutex.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84) (envelope-from ) id 1f9oEG-0006La-DT; Sat, 21 Apr 2018 09:50:44 +0100 From: Javier Arteaga To: Jacek Anaszewski , Pavel Machek Cc: Javier Arteaga , Dan O'Donovan , Andy Shevchenko , Mika Westerberg , Heikki Krogerus , Lee Jones , Linus Walleij , linux-gpio@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH RESEND 2/3] leds: upboard: Add LED support Date: Sat, 21 Apr 2018 09:50:08 +0100 Message-Id: <20180421085009.28773-3-javier@emutex.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180421085009.28773-1-javier@emutex.com> References: <20180421085009.28773-1-javier@emutex.com> X-Spam-Score: -1.0 (-) X-Spam-Report: Spam detection software, running on the system "statler.emutex.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Allow userspace to use the on-board LEDs as "upboard::". Signed-off-by: Javier Arteaga --- drivers/leds/Kconfig | 10 +++++ drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 87 +++++++++++++++++++++++++++++++++++++ drivers/mfd/upboard.c | 19 ++++++++ include/linux/mfd/upboard.h | 5 +++ 5 files changed, 122 insertions(+) create mode 100644 drivers/leds/leds-upboard.c [...] Content analysis details: (-1.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow userspace to use the on-board LEDs as "upboard::". Signed-off-by: Javier Arteaga --- drivers/leds/Kconfig | 10 +++++ drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 87 +++++++++++++++++++++++++++++++++++++ drivers/mfd/upboard.c | 19 ++++++++ include/linux/mfd/upboard.h | 5 +++ 5 files changed, 122 insertions(+) create mode 100644 drivers/leds/leds-upboard.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 2c896c0e69e1..2e77b46f2802 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -722,6 +722,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 91eca81cae82..4008e2061e1f 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o +obj-$(CONFIG_LEDS_UPBOARD) += leds-upboard.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-upboard.c b/drivers/leds/leds-upboard.c new file mode 100644 index 000000000000..e9d7a1fbcde4 --- /dev/null +++ b/drivers/leds/leds-upboard.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * UP Board LED driver + * + * Copyright (c) 2018, Emutex Ltd. + * + * Author: Javier Arteaga + */ + +#include +#include +#include +#include +#include +#include + +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 = container_of(cdev, struct 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 = container_of(cdev, struct upboard_led, cdev); + + regmap_field_write(led->field, brightness != LED_OFF); +}; + +static int __init upboard_led_probe(struct platform_device *pdev) +{ + struct upboard_led_data * const pdata = pdev->dev.platform_data; + struct upboard *upboard; + struct upboard_led *led; + struct reg_field conf = { + .reg = UPBOARD_REG_FUNC_EN0, + }; + + if (!pdev->dev.parent) + return -EINVAL; + + upboard = dev_get_drvdata(pdev->dev.parent); + if (!upboard || !pdata) + return -EINVAL; + + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + conf.lsb = pdata->id; + conf.msb = pdata->id; + led->field = devm_regmap_field_alloc(&pdev->dev, upboard->regmap, conf); + if (IS_ERR(led->field)) + return PTR_ERR(led->field); + + led->cdev.brightness_get = upboard_led_brightness_get; + led->cdev.brightness_set = upboard_led_brightness_set; + led->cdev.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "upboard:%s:", + pdata->color); + if (!led->cdev.name) + return -ENOMEM; + + return devm_led_classdev_register(&pdev->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"); diff --git a/drivers/mfd/upboard.c b/drivers/mfd/upboard.c index 8bae450cb83d..6e4767e4dc41 100644 --- a/drivers/mfd/upboard.c +++ b/drivers/mfd/upboard.c @@ -79,6 +79,14 @@ struct upboard_data { size_t ncells; }; +#define UPBOARD_LED_CELL(led_data, n) \ + { \ + .name = "upboard-led", \ + .id = (n), \ + .platform_data = &led_data[(n)], \ + .pdata_size = sizeof(*(led_data)), \ + } + /* UP Squared */ static const struct regmap_range upboard_up2_readable_ranges[] = { @@ -116,7 +124,18 @@ static const struct regmap_config upboard_up2_regmap_config = { .wr_table = &upboard_up2_writable_table, }; +static struct upboard_led_data upboard_up2_led_data[] = { + { .id = 0, .color = "blue" }, + { .id = 1, .color = "yellow" }, + { .id = 2, .color = "green" }, + { .id = 3, .color = "red" }, +}; + static const struct mfd_cell upboard_up2_mfd_cells[] = { + UPBOARD_LED_CELL(upboard_up2_led_data, 0), + UPBOARD_LED_CELL(upboard_up2_led_data, 1), + UPBOARD_LED_CELL(upboard_up2_led_data, 2), + UPBOARD_LED_CELL(upboard_up2_led_data, 3), }; static const struct upboard_data upboard_up2_data = { diff --git a/include/linux/mfd/upboard.h b/include/linux/mfd/upboard.h index d9dd214f4d29..eed68caa23ce 100644 --- a/include/linux/mfd/upboard.h +++ b/include/linux/mfd/upboard.h @@ -62,4 +62,9 @@ struct upboard { struct gpio_desc *dataout_gpio; }; +struct upboard_led_data { + unsigned int id; + const char *color; +}; + #endif /* __LINUX_MFD_UPBOARD_H */ -- 2.17.0