From patchwork Fri Sep 13 12:30:58 2024 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: 13803395 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3E9AEEE26C for ; Fri, 13 Sep 2024 12:31:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id E4A7FC4CECE; Fri, 13 Sep 2024 12:31:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744A6C4CEC7; Fri, 13 Sep 2024 12:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726230692; bh=+ctK+EX3ptfMmMS6zGzFfk7fZNhwln/VjVR+eyf8w94=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=F5Vkbo6eCUNSqS/aE/j7LYRcWXLWb3Tk8eoKlAyug8SF4v3PXjzu+2am/J/aoLZpy nZJXPuQQTbTI3ae0oCdebV34d7bOn3gTaDkfYYkohDI035O4aj49Lq1yeE2S4eev4S Qjd6cOf38H6+HBEZfLqPEoaP8eDBePEWae/rk5yI+EsDCTAeVl4r8rkCVDQ36VmcEq vWCAA6mjJ67qdEY6dLJwMfE8hykarI//+P0dHlvq9qmSiMyLsdDWDBItvNlGMFSqSn +NsBTKmtiKDmhQvkRODtE8RvhntJA7ZeoRW3a+Y6TdxQyVJIKmFPn/mBIbRj4JcMtz fsTzPXhLwzAMQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones List-Id: Cc: Pavel Machek , linux-leds@vger.kernel.org, Arnd Bergmann , soc@kernel.org, Gregory CLEMENT , arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andrew Lunn , Sebastian Hesselbarth , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, =?utf-8?q?M?= =?utf-8?q?arek_Beh=C3=BAn?= Subject: [PATCH leds v3 06/11] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Date: Fri, 13 Sep 2024 14:30:58 +0200 Message-ID: <20240913123103.21226-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240913123103.21226-1-kabel@kernel.org> References: <20240913123103.21226-1-kabel@kernel.org> MIME-Version: 1.0 Recall that on Turris Omnia, the LED controller has a global brightness property, which allows the user to make the front LED panel dimmer. There is also a button on the front panel, which by default is configured so that pressing it changes the global brightness to a lower value (unless it is at 0%, in which case pressing the button changes the global brightness to 100%). Newer versions of the MCU firmware support informing the SOC that the brightness was changed by button press event via an interrupt. Now that we have the turris-omnia-mcu driver, which adds support for MCU interrupts, add the ability to inform the userspace (via a sysfs notification) that the global brightness was changed. Signed-off-by: Marek BehĂșn --- drivers/leds/leds-turris-omnia.c | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 82cf58fbe946..a87cdb58e476 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -33,6 +33,7 @@ struct omnia_leds { struct i2c_client *client; struct mutex lock; bool has_gamma_correction; + struct kernfs_node *brightness_kn; struct omnia_led leds[]; }; @@ -357,6 +358,21 @@ static struct attribute *omnia_led_controller_attrs[] = { }; ATTRIBUTE_GROUPS(omnia_led_controller); +static irqreturn_t omnia_brightness_changed_handler(int irq, void *dev_id) +{ + struct omnia_leds *leds = dev_id; + + if (unlikely(!leds->brightness_kn)) { + leds->brightness_kn = sysfs_get_dirent(leds->client->dev.kobj.sd, "brightness"); + if (!leds->brightness_kn) + return IRQ_NONE; + } + + sysfs_notify_dirent(leds->brightness_kn); + + return IRQ_HANDLED; +} + static int omnia_mcu_get_features(const struct i2c_client *client) { struct i2c_client mcu_client = *client; @@ -420,6 +436,14 @@ static int omnia_leds_probe(struct i2c_client *client) "Consider upgrading MCU firmware with the omnia-mcutool utility.\n"); } + if (ret & OMNIA_FEAT_BRIGHTNESS_INT) { + ret = devm_request_any_context_irq(dev, client->irq, + omnia_brightness_changed_handler, IRQF_ONESHOT, + "leds-turris-omnia", leds); + if (ret <= 0) + return dev_err_probe(dev, ret ?: -ENXIO, "Cannot request brightness IRQ\n"); + } + mutex_init(&leds->lock); ret = devm_led_trigger_register(dev, &omnia_hw_trigger); @@ -442,6 +466,19 @@ static int omnia_leds_probe(struct i2c_client *client) static void omnia_leds_remove(struct i2c_client *client) { + struct omnia_leds *leds = i2c_get_clientdata(client); + + /* + * We need to free the brightness IRQ here, before putting away the brightness sysfs node. + * Otherwise devres would free the interrupt only after the sysfs node is removed, and if + * an interrupt occurred between those two events, it would use a removed sysfs node. + */ + devm_free_irq(&client->dev, client->irq, leds); + + /* Now put away the sysfs node we got the first time the interrupt handler was called */ + if (leds->brightness_kn) + sysfs_put(leds->brightness_kn); + /* put all LEDs into default (HW triggered) mode */ omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(OMNIA_BOARD_LEDS));