From patchwork Fri Jul 14 08:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 703057 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 3864CC001DF for ; Fri, 14 Jul 2023 08:53:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235677AbjGNIxM (ORCPT ); Fri, 14 Jul 2023 04:53:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235753AbjGNIxB (ORCPT ); Fri, 14 Jul 2023 04:53:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE072120 for ; Fri, 14 Jul 2023 01:53:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C6F6761C9C for ; Fri, 14 Jul 2023 08:52:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4457EC433CB; Fri, 14 Jul 2023 08:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689324779; bh=7/e4SBxn7hv2OmNuhqD/9ZmO4FGuiP/KNu8UxBKbWc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UzjYx0r6PusLvZ4sX9zbW9vyJydVmyaAIRVTNzWAA7604UR+v3nihfp44YFZdUG6o cZDdK3+oS3yVGc5u6r79KhmIsACp1CRFR5ALEMz+NE+zgBqT0ZjsSgH5XjJDCwjhV1 p1fFFtpeJvBXoupqaZWdEy9aMn4nO8QUXksG7n7QMba9uEzi7FBWqieFBcNnHS7f4c CPjpJEjEraJecvz8ZAfLlO7mYwleoPee5cD0MkXip9fUFGt2ta6SvFsm3LqTEluv49 y63uFLaXH+MQlLIbz43U2yrLgbSJ4QGRaQzdhOwZawfrqXgiNJ8BVwYi99EI22ook7 efGn2x3Ws+Eog== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org, Pavel Machek , Lee Jones Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v2 1/3] leds: turris-omnia: change max brightness from 255 to 1 Date: Fri, 14 Jul 2023 10:52:51 +0200 Message-ID: <20230714085253.13544-2-kabel@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714085253.13544-1-kabel@kernel.org> References: <20230714085253.13544-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Using binary brightness makes more sense for this controller, because internally in the MCU it works that way: the LED has a color, and a state whether it is ON or OFF. The resulting brightness computation with led_mc_calc_color_components() will now always result in either (0, 0, 0) or the multi_intensity value. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 64b2d7b6d3f3..c063b6b710f9 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -110,7 +110,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, init_data.fwnode = &np->fwnode; cdev = &led->mc_cdev.led_cdev; - cdev->max_brightness = 255; + cdev->max_brightness = 1; cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; /* put the LED into software mode */ From patchwork Fri Jul 14 08:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 703631 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 9C2B7EB64DA for ; Fri, 14 Jul 2023 08:53:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234549AbjGNIxN (ORCPT ); Fri, 14 Jul 2023 04:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235756AbjGNIxC (ORCPT ); Fri, 14 Jul 2023 04:53:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9868B198A for ; Fri, 14 Jul 2023 01:53:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2DB8A61CA0 for ; Fri, 14 Jul 2023 08:53:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F476C433CA; Fri, 14 Jul 2023 08:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689324780; bh=hfhVlSbfqvPK76cxdTnugo9OdIJZfmc1WJ2D+X21X2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjyaopTzTB12udXKp+kCYT8I32qafqg7o69HUc5sxhomVBeMvcTx64wfxO9ua2VLf gFb8r7cWWYLyol+iHdi7HnSAX+22DGmRJXntlEaTfIQSTQrGbW4e39MsG4GbotaJ38 2wW87qhqefBuYuteYW5L+UgWSRgoAxF3vtf8EqOF3M9aRLQz7boAk0LOA3iubWlnJL a+VBvVGFLkGlniqUEZUa9TqAKjnTgkaa9RxqDgSmRL8YmLxv3t/Z2oRtJT5JHPL4eS Dug32kBmLkvvekncXnRPgqDOBuAKV6KiA8UEbTZAVwadqBfVXL+S5X+F2aVEMmtaRQ u9dqHYS2OvZnw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org, Pavel Machek , Lee Jones Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v2 2/3] leds: turris-omnia: initialize multi-intensity to full Date: Fri, 14 Jul 2023 10:52:52 +0200 Message-ID: <20230714085253.13544-3-kabel@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714085253.13544-1-kabel@kernel.org> References: <20230714085253.13544-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org The default color of each LED before driver probe is (255, 255, 255). Initialize multi_intensity to this value, so that it corresponds to the reality. Signed-off-by: Marek Behún Reviewed-by: Pavel Machek --- drivers/leds/leds-turris-omnia.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index c063b6b710f9..7977c0372667 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -98,10 +98,13 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, } led->subled_info[0].color_index = LED_COLOR_ID_RED; + led->subled_info[0].intensity = 255; led->subled_info[0].channel = 0; led->subled_info[1].color_index = LED_COLOR_ID_GREEN; + led->subled_info[1].intensity = 255; led->subled_info[1].channel = 1; led->subled_info[2].color_index = LED_COLOR_ID_BLUE; + led->subled_info[2].intensity = 255; led->subled_info[2].channel = 2; led->mc_cdev.subled_info = led->subled_info; From patchwork Fri Jul 14 08:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 703056 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 DF4B3EB64DC for ; Fri, 14 Jul 2023 08:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235653AbjGNIxM (ORCPT ); Fri, 14 Jul 2023 04:53:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235768AbjGNIxD (ORCPT ); Fri, 14 Jul 2023 04:53:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10AE02683 for ; Fri, 14 Jul 2023 01:53:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8E59961CA0 for ; Fri, 14 Jul 2023 08:53:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06744C433CB; Fri, 14 Jul 2023 08:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689324782; bh=nNLdCehayE1U0hFM3WDRzJ1MqL143Yu7ZqdB/bxPsso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9aJxDV+By76PZZbiQIuFlpp4jE8qXcSg89nfZ+fiFK+wxPqqT8RRfr5dYG4ZDCu4 9rZkAYUuuj0/O5TGGX0yeZ6SiGqSEtPu4V0dS/5bcBbLJuyNsAwvnO+wKCkqUwgMoo ql3IpN5ieFtgEq7hnWdOsQdBbGqROI5rORhJPO5OTRd+fcqV1L972MHHJXSgTaLt26 dmMBBd9U885vlXHxrl1p07RRkx70AGBqna+RqTxfSOQckSSLjY3HX/+7eBHxCXHPtl aUMoCkM63lxWk2QXlYQRiF2UaX9UjcW05p0ScHJS1b8h530w1vXfzZnTu/iUXpqnf6 goFulUKDm/dsw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org, Pavel Machek , Lee Jones Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v2 3/3] leds: turris-omnia: support HW controlled mode via private trigger Date: Fri, 14 Jul 2023 10:52:53 +0200 Message-ID: <20230714085253.13544-4-kabel@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714085253.13544-1-kabel@kernel.org> References: <20230714085253.13544-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add support for enabling MCU controlled mode of the Turris Omnia LEDs via a LED private trigger called "omnia-mcu". When in MCU controlled mode, the user can still set LED color, but the blinking is done by MCU, which does different things for various LEDs: - WAN LED is blinked according to the LED[0] pin of the WAN PHY - LAN LEDs are blinked according to the LED[0] output of corresponding port of the LAN switch - PCIe LEDs are blinked according to the logical OR of the MiniPCIe port LED pins For a long time I wanted to actually do this differently: I wanted to make the netdev trigger to transparently offload the blinking to the HW if user set compatible settings for the netdev trigger. There was some work on this, and hopefully we will be able to complete it sometime, but since there are various complications, it will probably not be soon. In the meantime let's support HW controlled mode via this private LED trigger. If, in the future, we manage to complete the netdev trigger offloading, we can still keep this private trigger for backwards compatibility, if needed. We also set "omnia-mcu" to cdev->default_trigger, so that the MCU keeps control until the user first wants to take over it. If a different default trigger is specified in device-tree via the `linux,default-trigger` property, LED class will overwrite cdev->default_trigger, and so the DT property will be respected. Signed-off-by: Marek Behún --- drivers/leds/Kconfig | 1 + drivers/leds/leds-turris-omnia.c | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 6046dfeca16f..ebb3b84d7a4f 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -187,6 +187,7 @@ config LEDS_TURRIS_OMNIA depends on I2C depends on MACH_ARMADA_38X || COMPILE_TEST depends on OF + select LEDS_TRIGGERS help This option enables basic support for the LEDs found on the front side of CZ.NIC's Turris Omnia router. There are 12 RGB LEDs on the diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 7977c0372667..6ce66e79096c 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -41,6 +41,39 @@ struct omnia_leds { struct omnia_led leds[]; }; +static struct led_hw_trigger_type omnia_hw_trigger_type; + +static int omnia_hwtrig_activate(struct led_classdev *cdev) +{ + struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); + struct omnia_led *led = to_omnia_led(lcdev_to_mccdev(cdev)); + + /* put the LED into MCU controlled mode */ + return i2c_smbus_write_byte_data(leds->client, CMD_LED_MODE, + CMD_LED_MODE_LED(led->reg)); +} + +static void omnia_hwtrig_deactivate(struct led_classdev *cdev) +{ + struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); + struct omnia_led *led = to_omnia_led(lcdev_to_mccdev(cdev)); + int ret; + + /* put the LED into software mode */ + ret = i2c_smbus_write_byte_data(leds->client, CMD_LED_MODE, + CMD_LED_MODE_LED(led->reg) | + CMD_LED_MODE_USER); + if (ret < 0) + dev_err(cdev->dev, "Cannot put to software mode: %i\n", ret); +} + +static struct led_trigger omnia_hw_trigger = { + .name = "omnia-mcu", + .activate = omnia_hwtrig_activate, + .deactivate = omnia_hwtrig_deactivate, + .trigger_type = &omnia_hw_trigger_type, +}; + static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, enum led_brightness brightness) { @@ -115,6 +148,8 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, cdev = &led->mc_cdev.led_cdev; cdev->max_brightness = 1; cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; + cdev->trigger_type = &omnia_hw_trigger_type; + cdev->default_trigger = omnia_hw_trigger.name; /* put the LED into software mode */ ret = i2c_smbus_write_byte_data(client, CMD_LED_MODE, @@ -230,6 +265,12 @@ static int omnia_leds_probe(struct i2c_client *client) mutex_init(&leds->lock); + ret = devm_led_trigger_register(dev, &omnia_hw_trigger); + if (ret < 0) { + dev_err(dev, "Cannot register private LED trigger: %d\n", ret); + return ret; + } + led = &leds->leds[0]; for_each_available_child_of_node(np, child) { ret = omnia_led_register(client, led, child);