From: Lee Jones <lee@kernel.org>
To: "Marek Behún" <kabel@kernel.org>
Cc: Pavel Machek <pavel@ucw.cz>, linux-leds@vger.kernel.org
Subject: Re: [PATCH v3 6/6] leds: turris-omnia: add support for enabling/disabling HW gamma correction
Date: Fri, 18 Aug 2023 11:30:03 +0100 [thread overview]
Message-ID: <20230818103003.GS986605@google.com> (raw)
In-Reply-To: <20230802160748.11208-7-kabel@kernel.org>
On Wed, 02 Aug 2023, Marek Behún wrote:
> If the MCU on Turris Omnia is running newer firmware versions, the LED
> controller supports RGB gamma correction (and enables it by default for
> newer boards).
>
> Determine whether the gamma correction setting feature is supported and
> add the ability to set it via sysfs attribute file.
>
> Signed-off-by: Marek Behún <kabel@kernel.org>
> ---
> .../sysfs-class-led-driver-turris-omnia | 14 ++
> drivers/leds/leds-turris-omnia.c | 135 +++++++++++++++---
> 2 files changed, 132 insertions(+), 17 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-class-led-driver-turris-omnia b/Documentation/ABI/testing/sysfs-class-led-driver-turris-omnia
> index c4d46970c1cf..369b4ae8be5f 100644
> --- a/Documentation/ABI/testing/sysfs-class-led-driver-turris-omnia
> +++ b/Documentation/ABI/testing/sysfs-class-led-driver-turris-omnia
> @@ -12,3 +12,17 @@ Description: (RW) On the front panel of the Turris Omnia router there is also
> able to change this setting from software.
>
> Format: %i
> +
> +What: /sys/class/leds/<led>/device/gamma_correction
> +Date: August 2023
> +KernelVersion: 6.6
> +Contact: Marek Behún <kabel@kernel.org>
> +Description: (RW) Newer versions of the microcontroller firmware of the
> + Turris Omnia router support gamma correction for the RGB LEDs.
> + This feature can be enabled/disabled by writing to this file.
> +
> + If the feature is not supported because the MCU firmware is too
> + old, the file always reads as 0, and writing to the file results
> + in the EOPNOTSUPP error.
> +
> + Format: %i
> diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
> index 180b0cbeb92e..75cc7d2cf6d1 100644
> --- a/drivers/leds/leds-turris-omnia.c
> +++ b/drivers/leds/leds-turris-omnia.c
> @@ -15,17 +15,30 @@
> #define OMNIA_BOARD_LEDS 12
> #define OMNIA_LED_NUM_CHANNELS 3
>
> -#define CMD_LED_MODE 3
> -#define CMD_LED_MODE_LED(l) ((l) & 0x0f)
> -#define CMD_LED_MODE_USER 0x10
> +/* MCU controller commands at I2C address 0x2a */
> +#define OMNIA_MCU_I2C_ADDR 0x2a
>
> -#define CMD_LED_STATE 4
> -#define CMD_LED_STATE_LED(l) ((l) & 0x0f)
> -#define CMD_LED_STATE_ON 0x10
> +#define CMD_GET_STATUS_WORD 0x01
> +#define STS_FEATURES_SUPPORTED BIT(2)
>
> -#define CMD_LED_COLOR 5
> -#define CMD_LED_SET_BRIGHTNESS 7
> -#define CMD_LED_GET_BRIGHTNESS 8
> +#define CMD_GET_FEATURES 0x10
> +#define FEAT_LED_GAMMA_CORRECTION BIT(5)
> +
> +/* LED controller commands at I2C address 0x2b */
> +#define CMD_LED_MODE 0x03
> +#define CMD_LED_MODE_LED(l) ((l) & 0x0f)
> +#define CMD_LED_MODE_USER 0x10
> +
> +#define CMD_LED_STATE 0x04
> +#define CMD_LED_STATE_LED(l) ((l) & 0x0f)
> +#define CMD_LED_STATE_ON 0x10
> +
> +#define CMD_LED_COLOR 0x05
> +#define CMD_LED_SET_BRIGHTNESS 0x07
> +#define CMD_LED_GET_BRIGHTNESS 0x08
> +
> +#define CMD_SET_GAMMA_CORRECTION 0x30
> +#define CMD_GET_GAMMA_CORRECTION 0x31
>
> struct omnia_led {
> struct led_classdev_mc mc_cdev;
> @@ -40,6 +53,7 @@ struct omnia_led {
> struct omnia_leds {
> struct i2c_client *client;
> struct mutex lock;
> + bool has_gamma_correction;
> struct omnia_led leds[];
> };
>
> @@ -53,30 +67,42 @@ static int omnia_cmd_write(const struct i2c_client *client, u8 cmd, u8 val)
> return ret < 0 ? ret : 0;
> }
>
> -static int omnia_cmd_read(const struct i2c_client *client, u8 cmd)
> +static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
> + void *reply, size_t len)
> {
> struct i2c_msg msgs[2];
> - u8 reply;
> int ret;
>
> - msgs[0].addr = client->addr;
> + msgs[0].addr = addr;
> msgs[0].flags = 0;
> msgs[0].len = 1;
> msgs[0].buf = &cmd;
> - msgs[1].addr = client->addr;
> + msgs[1].addr = addr;
> msgs[1].flags = I2C_M_RD;
> - msgs[1].len = 1;
> - msgs[1].buf = &reply;
> + msgs[1].len = len;
> + msgs[1].buf = reply;
>
> - ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> + ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> if (likely(ret == ARRAY_SIZE(msgs)))
> - return reply;
> + return 0;
Why not return ret and use that throughout?
> else if (ret < 0)
> return ret;
> else
> return -EIO;
> }
[...]
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2023-08-18 10:32 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 16:07 [PATCH v3 0/6] leds: turris-omnia: updates Marek Behún
2023-08-02 16:07 ` [PATCH v3 1/6] leds: turris-omnia: drop unnecessary mutex locking Marek Behún
2023-08-18 8:09 ` Lee Jones
2023-08-18 9:23 ` (subset) " Lee Jones
2023-08-02 16:07 ` [PATCH v3 2/6] leds: turris-omnia: do not use SMBUS calls Marek Behún
2023-08-18 8:08 ` Lee Jones
2023-08-21 10:01 ` Marek Behún
2023-08-21 12:45 ` Lee Jones
2023-08-02 16:07 ` [PATCH v3 3/6] leds: turris-omnia: use sysfs_emit() instead of sprintf() Marek Behún
2023-08-18 9:18 ` (subset) " Lee Jones
2023-08-02 16:07 ` [PATCH v3 4/6] leds: turris-omnia: make set_brightness() more efficient Marek Behún
2023-08-18 9:42 ` Lee Jones
2023-08-21 10:14 ` Marek Behún
2023-08-21 12:39 ` Lee Jones
2023-08-02 16:07 ` [PATCH v3 5/6] leds: turris-omnia: support HW controlled mode via private trigger Marek Behún
2023-08-02 16:13 ` Marek Behún
2023-08-18 8:00 ` Lee Jones
2023-08-18 21:12 ` Jacek Anaszewski
2023-08-21 8:15 ` Lee Jones
2023-08-18 9:09 ` Lee Jones
2023-08-21 10:34 ` Marek Behún
2023-08-21 12:36 ` Lee Jones
2023-08-02 16:07 ` [PATCH v3 6/6] leds: turris-omnia: add support for enabling/disabling HW gamma correction Marek Behún
2023-08-18 10:30 ` Lee Jones [this message]
2023-08-21 10:46 ` Marek Behún
2023-08-21 12:26 ` Lee Jones
2023-08-14 7:33 ` [PATCH v3 0/6] leds: turris-omnia: updates Marek Behún
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230818103003.GS986605@google.com \
--to=lee@kernel.org \
--cc=kabel@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.