From patchwork Tue Nov 8 16:38:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "larry.lai" X-Patchwork-Id: 623140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28277C4332F for ; Tue, 8 Nov 2022 16:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234340AbiKHQk3 (ORCPT ); Tue, 8 Nov 2022 11:40:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233914AbiKHQkO (ORCPT ); Tue, 8 Nov 2022 11:40:14 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2128.outbound.protection.outlook.com [40.107.215.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D266F57B5B; Tue, 8 Nov 2022 08:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ss5C3g9cDAHERxQyGB3Xmz4tyJm6w6X+vcf0FX7RUsc3rUnV/E+3YFk4n4wNjmN+sSwYursHWbsaxWo38q6zZQxsUs6tMM/eWnUQzFVWPJlcrZVkV25snCJx9XOZUEKH7GZ+jQPqEoFfHj6jxdiOWHiM4/mM5IpjcF5Smlnwuo6p9WwGOnjrwPc6xLYQrUzYU4zasnlzHm6HKLD52Ctw3GSq4bmhv3EVtceL8GxygFB8re9PmfVB8j3d7reE/RFuGUc0b73X8JsSf4q9FuWCVrcHaWR1krQAg5skgB9va8pZbzp/wkig+qlLrNe0xHLtpKXtaMzB09v3d0siHVks0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=thpcfEjkT6M3Cbh0jMprMM++zM74T/WSw+KO6E7QZfI=; b=cArlejMg4uFprozlJyfi1fQ2fz/IFdwb31GbG3ckMygDLyA/+wqzAuzltTBRdEBm6V6H5+FXSpFxYUPo6Dbfn3gX4jLigv2dvY9DqweB7/VkE7hhyuafAspdwsO+iC+ukTQL/fXCNN74NWdIPoE99OAslYqp1yFYLHetdN7m0RB467CMaW4wg7qxhIjPKoDAj57/AwfhIjaO+hUExNc1yJT5hp9eTrehTCt0yDdehGi33Jbgmb1kEYnw85VzO3pUN6BSp5YyjviSuhZoBPrdtYxp7IVpvdZKqg56asYLDClRf3NVh7e2WTCGaX6s/JOItWTKuclQn/hhK72qWC54Sg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=yunjingtech.com; dmarc=pass action=none header.from=yunjingtech.com; dkim=pass header.d=yunjingtech.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=yunjingtech.com; Received: from SG2PR06MB3742.apcprd06.prod.outlook.com (2603:1096:4:d8::14) by PSAPR06MB4454.apcprd06.prod.outlook.com (2603:1096:301:8a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 16:40:06 +0000 Received: from SG2PR06MB3742.apcprd06.prod.outlook.com ([fe80::9ac2:8b0a:9ad:24b5]) by SG2PR06MB3742.apcprd06.prod.outlook.com ([fe80::9ac2:8b0a:9ad:24b5%5]) with mapi id 15.20.5791.025; Tue, 8 Nov 2022 16:40:06 +0000 From: chengwei To: lee@kernel.org, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, pavel@ucw.cz Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-leds@vger.kernel.org, GaryWang@aaeon.com.tw, musa.lin@yunjingtech.com, jack.chang@yunjingtech.com, noah.hung@yunjingtech.com, chengwei Subject: [PATCH V2 3/3] leds: Add support for UP board CPLD onboard LEDS Date: Wed, 9 Nov 2022 00:38:52 +0800 Message-Id: <20221108163852.15926-4-larry.lai@yunjingtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221108163852.15926-1-larry.lai@yunjingtech.com> References: <20221108163852.15926-1-larry.lai@yunjingtech.com> X-ClientProxiedBy: SI2PR02CA0001.apcprd02.prod.outlook.com (2603:1096:4:194::10) To SG2PR06MB3742.apcprd06.prod.outlook.com (2603:1096:4:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3742:EE_|PSAPR06MB4454:EE_ X-MS-Office365-Filtering-Correlation-Id: 15baacfb-5a4a-4fba-0642-08dac1a7e453 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x6BajtPAVjCMYqPp/nUVVFH6m+HJgY653mpyMKnj7njkBv6LHVH463IDE503wNM7omgXKMeCtNai+dqDmtp6mzKZvmadtMVejUqpzXBxqV7M9dhvIF3qoRIUJ1Ejw0ZJOJvcBlsVStST2KNxT78BQUhZpLsNSc/0lHF35wI5Ftp5vwc+YNgQPH0AaUIbje/yRvX+99YOqMI1tCBaBH0o/n4C3g0juCz1pXEZm2W6U2nlLT5K5Y9q7Dz53O3ZNuxf+zWGJO4+tNVvYFJpzGIf8Ds4QdwV0tECBxhj+pfC+h/pGaaPMa8opci1TVEK/3Gs+jN1HXZ6JabzFKmnhDUFTAuf1fDDboo9xRRXps1CPKNl2Bl5JvU6hH8EjL2J/OvQar5IuXj9+d7VEtBvvgxza/Bzs9QBEjRY77pU3yiC4oNiojABrmwrs9B2PtA+BAUhYuIRDz4n6P2owG6cJ3pcB7jwkpuL1V/VB5pUA13afbhd++keOjSa3TJhipw63ugOpFe2LKz9hRAovocgP0OzcqZFd0FjCjt2RolaAvoOWf54KxSlBfLtyi5KMQBG7ZTTd7+JXIuoEzzSPHDM05q5L4HQRMffQ0rdyy/msPk8i90w9By7fQq4wHKE9uR/HKkq7b+PDfyj7B5PFSCdnrvspuWpNtgUgnZItIsMaJ7VV7ClmcpS/Zg6X/rPBCcXtCSo2EqRpc8mGmblzo2ohdPcgulW4I/pnesg3BmifCSZZcMZ6M4vBWLLowa5L4xI34Anlyx9jrePSShZi/4aYA1NwA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SG2PR06MB3742.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(376002)(39830400003)(396003)(366004)(136003)(451199015)(8936002)(41300700001)(38350700002)(38100700002)(52116002)(6666004)(6506007)(4326008)(66946007)(2906002)(66556008)(66476007)(6512007)(26005)(316002)(5660300002)(86362001)(478600001)(107886003)(6486002)(186003)(36756003)(2616005)(8676002)(1076003)(43062005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XBV74zgWRBvsNUnS5Y0ZHvgp7dhgEQcPINHms4bnh3LGNOUk6NbuLJ+o+Agr8tJZuMtRFz2xDwTTkNo0s9zYxvntB1x+YihqovHtlT0A93pSSNEK+jywanxu3pGsu1jEkFgrdT4gXUgTH62evn4F/mNHODbiqxfOYYTC52M51sDZx5cseMhIcfOnhGqFtKRF6pZTP54bNF+gH1/G5omiWtuHZQC2T2cQYdoxF9nXU8ubxB0gVa4pz+fCBFsPEBg57rFvxd9I43E1Qp0xZDoxAYvM/MfkcyQc52bYIEAZlcLcTMGBM3VAN2jhJ9SLT9itKRxg99W74Tx0ih19EWZb0bymoINedmcLwf1TGRvkSZUGHdZYVA0etnDOwBwDauK6nR56tb43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TzcSQQOQrOJ7fvvCzWQYvnXRs/Vq8LK6PvBXCpmtfwa5ZEArpNJt5dV9RjI0t9+6aqhhK8fg8zjhRwxuosjDExGNN6JXCGhCiO4NfQHfhPXMJeZVT4ryH3MShMDnV2TVW3+7DevlC36Yu74ON36Z+jlfx6o/A== X-OriginatorOrg: yunjingtech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15baacfb-5a4a-4fba-0642-08dac1a7e453 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3742.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 16:40:06.2723 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: be2d5505-f7e6-4600-bbe2-b3201c91b344 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IIXBSawxESFiz4lvXHt2KGXEvHc9O0SwJYKn2Z2Eod70WjL69xuYPVjoSADwJAbSOjo4sWQhdbqIXT7kngmQ8fb10gyzzbvSP58H3zsgdU8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR06MB4454 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The UP boards come with a few FPGA-controlled onboard LEDs: * UP Board: yellow, green, red * UP Squared: blue, yellow, green, red this patch depends on patch "mfd: Add support for UP board CPLD/FPGA" Signed-off-by: chengwei --- drivers/leds/Kconfig | 10 +++++ drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 78 +++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 drivers/leds/leds-upboard.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 499d0f215a8b..80b9c394c5b6 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -872,6 +872,16 @@ source "drivers/leds/flash/Kconfig" comment "RGB LED drivers" source "drivers/leds/rgb/Kconfig" +config LEDS_UPBOARD + tristate "LED support for the UP board" + depends on LEDS_CLASS + depends on MFD_UPBOARD_FPGA + help + This option enables support for the UP board LEDs. + + To compile this driver as a module, choose M here: 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 4fd2f92cd198..e72956645646 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -83,6 +83,7 @@ obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o obj-$(CONFIG_LEDS_TURRIS_OMNIA) += leds-turris-omnia.o +obj-$(CONFIG_LEDS_UPBOARD) += leds-upboard.o obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o diff --git a/drivers/leds/leds-upboard.c b/drivers/leds/leds-upboard.c new file mode 100644 index 000000000000..214325442f3b --- /dev/null +++ b/drivers/leds/leds-upboard.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * UP Board FPGA-based LED driver + * + * Copyright (c) 2017, Emutex Ltd. All rights reserved. + * + * Author: Javier Arteaga + */ + +#include +#include +#include +#include +#include +#include + +struct upboard_led { + struct led_classdev cdev; + struct regmap_field *field; +}; + +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_fpga * const up_fpga = dev_get_drvdata(pdev->dev.parent); + struct reg_field fldconf = { + .reg = UPFPGA_REG_FUNC_EN0, + }; + struct upboard_led_data * const pdata = pdev->dev.platform_data; + struct upboard_led *led; + + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + fldconf.lsb = pdata->bit; + fldconf.msb = pdata->bit; + led->field = devm_regmap_field_alloc(&pdev->dev, up_fpga->regmap, fldconf); + 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->colour); + 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_AUTHOR("Javier Arteaga "); +MODULE_DESCRIPTION("UP Board LED driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:upboard-led");