From patchwork Tue Sep 3 10:19:21 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: 825138 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.subspace.kernel.org (Postfix) with ESMTPS id D43F12904 for ; Tue, 3 Sep 2024 10:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358782; cv=none; b=deoMd2gp8+3UYAqb3T3w9SGsv4n5k7zCVgF0IgK6wC8RIDO4T1h7H3lCZ8D2Qd00HyTHPW19dZ+QckjJMTkgDFxrmvFMAZmLo/7JHBlx7bkNW2NHtO9yfFaQJ9z12lcv3gQGgAZ7lBQRXNtDHJILflMU+bbouSC75sUOxZJC/h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358782; c=relaxed/simple; bh=WfuoYDyRAVmLs649L6nDMKvfBDOvebjwwF3L/PYXCeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bfal6HKjLf4J84h8x/6/nYDwblzm4/LfqNL6Axxo5HxnNU+enLc1ifFrmnqYxCLu8xx957pSYIog7aUp6GG7M3uWACmDq2nmdox0oqKoxlubyddXBSCnQxXOiNHNVaEdSFDZGpo5vjyJ1qpxAcenP9KL5WzlnHlxzqQDsKrql/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t19tPW+n; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t19tPW+n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C24F1C4CEC8; Tue, 3 Sep 2024 10:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725358782; bh=WfuoYDyRAVmLs649L6nDMKvfBDOvebjwwF3L/PYXCeY=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=t19tPW+nOb9QiWRqanrluFHHWHgBZtAKGN3ZfpnlYScxJ7fxrPpDw0+AEZTWEHehn Dr/2PX004vED6lIzShM1H/dRsdqF4OcMrCYzui+Mx8qGVeJjcgOiiSEY34d1H87zKC xF1Fb1L5csyB4TfYxubjAZTMoe2fG4PRJJFD/Jxsh6nz/dwPzvvGdfxkDe1+9RitBy YoAp8l6fqBrpnOwl+rodBrgx+f83NVsIN4UcHKrgTWge4PaJelTpi1p8XRRwmsLYyR 8G0dHgQIBDR35PiLqXAlf6VOHRZvG8EC2+dkKlDx5wBc30JVgzw+ECX8LHdbwM2G66 4UCaVneTHdAZw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones 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 , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds v2 02/11] leds: turris-omnia: Use command execution functions from the MCU driver Date: Tue, 3 Sep 2024 12:19:21 +0200 Message-ID: <20240903101930.16251-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240903101930.16251-1-kabel@kernel.org> References: <20240903101930.16251-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the MCU command execution functions from the MCU driver instead of the ad-hoc implementation in the LED driver. This allows as to drop the LED driver implementation, which is a duplicate. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 110 ++++++++----------------------- 1 file changed, 29 insertions(+), 81 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 4cff8c4b020c..0b71848930dd 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -2,7 +2,7 @@ /* * CZ.NIC's Turris Omnia LEDs driver * - * 2020, 2023 by Marek Behún + * 2020, 2023, 2024 by Marek Behún */ #include @@ -10,6 +10,7 @@ #include #include #include +#include #include "leds.h" #define OMNIA_BOARD_LEDS 12 @@ -57,66 +58,21 @@ struct omnia_leds { struct omnia_led leds[]; }; -static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val) +static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b) { - u8 buf[2] = { cmd, val }; - int ret; - - ret = i2c_master_send(client, buf, sizeof(buf)); + u8 buf[5] = { CMD_LED_COLOR, led, r, g, b }; - return ret < 0 ? ret : 0; -} - -static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd, - void *reply, size_t len) -{ - struct i2c_msg msgs[2]; - int ret; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = 1; - msgs[0].buf = &cmd; - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = len; - msgs[1].buf = reply; - - ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs)); - if (likely(ret == ARRAY_SIZE(msgs))) - return 0; - else if (ret < 0) - return ret; - else - return -EIO; -} - -static int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd) -{ - u8 reply; - int err; - - err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1); - if (err) - return err; - - return reply; + return omnia_cmd_write(client, buf, sizeof(buf)); } static int omnia_led_send_color_cmd(const struct i2c_client *client, struct omnia_led *led) { - char cmd[5]; int ret; - cmd[0] = CMD_LED_COLOR; - cmd[1] = led->reg; - cmd[2] = led->subled_info[0].brightness; - cmd[3] = led->subled_info[1].brightness; - cmd[4] = led->subled_info[2].brightness; - /* Send the color change command */ - ret = i2c_master_send(client, cmd, 5); + ret = omnia_cmd_set_color(client, led->reg, led->subled_info[0].brightness, + led->subled_info[1].brightness, led->subled_info[2].brightness); if (ret < 0) return ret; @@ -352,14 +308,14 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a, char *buf) { struct i2c_client *client = to_i2c_client(dev); - int ret; - - ret = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS); + u8 reply; + int err; - if (ret < 0) - return ret; + err = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS, &reply); + if (err < 0) + return err; - return sysfs_emit(buf, "%d\n", ret); + return sysfs_emit(buf, "%d\n", reply); } static ssize_t brightness_store(struct device *dev, struct device_attribute *a, @@ -386,17 +342,16 @@ static ssize_t gamma_correction_show(struct device *dev, { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); - int ret; + u8 reply = 0; + int err; if (leds->has_gamma_correction) { - ret = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION); - if (ret < 0) - return ret; - } else { - ret = 0; + err = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION, &reply); + if (err < 0) + return err; } - return sysfs_emit(buf, "%d\n", !!ret); + return sysfs_emit(buf, "%d\n", !!reply); } static ssize_t gamma_correction_store(struct device *dev, @@ -429,24 +384,26 @@ ATTRIBUTE_GROUPS(omnia_led_controller); static int omnia_mcu_get_features(const struct i2c_client *client) { + struct i2c_client mcu_client = *client; u16 reply; int err; - err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, - CMD_GET_STATUS_WORD, &reply, sizeof(reply)); + /* We have to read features from different I2C address */ + mcu_client.addr = OMNIA_MCU_I2C_ADDR; + + err = omnia_cmd_read_u16(&mcu_client, CMD_GET_STATUS_WORD, &reply); if (err) return err; /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */ - if (!(le16_to_cpu(reply) & STS_FEATURES_SUPPORTED)) + if (!(reply & STS_FEATURES_SUPPORTED)) return 0; - err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, - CMD_GET_FEATURES, &reply, sizeof(reply)); + err = omnia_cmd_read_u16(&mcu_client, CMD_GET_FEATURES, &reply); if (err) return err; - return le16_to_cpu(reply); + return reply; } static int omnia_leds_probe(struct i2c_client *client) @@ -510,20 +467,11 @@ static int omnia_leds_probe(struct i2c_client *client) static void omnia_leds_remove(struct i2c_client *client) { - u8 buf[5]; - /* put all LEDs into default (HW triggered) mode */ - omnia_cmd_write_u8(client, CMD_LED_MODE, - CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); + omnia_cmd_write_u8(client, CMD_LED_MODE, CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); /* set all LEDs color to [255, 255, 255] */ - buf[0] = CMD_LED_COLOR; - buf[1] = OMNIA_BOARD_LEDS; - buf[2] = 255; - buf[3] = 255; - buf[4] = 255; - - i2c_master_send(client, buf, 5); + omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255); } static const struct of_device_id of_omnia_leds_match[] = { From patchwork Tue Sep 3 10:19:23 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: 825137 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.subspace.kernel.org (Postfix) with ESMTPS id 39D1F2904 for ; Tue, 3 Sep 2024 10:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358789; cv=none; b=ICwZRFUbSlUCf8kXw8Z/HRUce4TYWMcA/jqCQFsZWEq/EuTWBr9wTO62hDwM5mXXhgFDYa0ymPajC3WwFnZ3atsyEMk/yQwI5t0FPLj0rUz1/81utUDX0gfLWSJmaT+KrJ4eGwYtirJqjFB4c0e/hoVopoW3qQ9aj/JxgfIoWLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358789; c=relaxed/simple; bh=UjoHC6ks6QGu6eoUR+CQpPYZRfSgIs1cS6WgfdBRkNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QJZFT025qTZMyIZxYDCuUFFQlM2iM7gB6snRKkvR1EJJ4qgUlAebg9fjpn6hgdLm0t6utRHrws9gEggpmn3PXjhkgB7CEr0xze2oghf6DuLa9NbTp8P03pHVEghMo9imfW4Qow5tY7adkdyx9XiINLsGR9VEwkPASbcudoVrntg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XuUOjgvN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XuUOjgvN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A83FC4CEC4; Tue, 3 Sep 2024 10:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725358788; bh=UjoHC6ks6QGu6eoUR+CQpPYZRfSgIs1cS6WgfdBRkNw=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=XuUOjgvNnIk6qgnyqsmGnJTIfKq5hUzGjbujTVn79UX3xPnnBRKQkNqw0XaW0V0w+ hrbQO4NuFJDvvUz1bYGerjOZwG01rLfOKOi9XhJ/dS5Fjyl073jaL68nWiaBkF8Pb6 mr/vmo2gGQtLAdTblpdtMliByE6pcYl1y8u9pqdrt10C7p1Veor3LlzFenPyYzR9lK mmpo/hT9p6pUUFWnM9JT6I8KOsm0SiANWsL9/acbdI4IV1pTZbcf7Pa+FKJCZxzWg7 0y1r0OxzKFNqXLA9cOR971M1EQMQVDP1gpuv8VWe3N/+ELCLnebzqFyr7eOtgqVph5 kBR4P1OJs0SqA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones 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 , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds v2 04/11] leds: turris-omnia: Use global header for MCU command definitions Date: Tue, 3 Sep 2024 12:19:23 +0200 Message-ID: <20240903101930.16251-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240903101930.16251-1-kabel@kernel.org> References: <20240903101930.16251-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The global turris-omnia-mcu-interface.h header file contains the definitions for MCU commands. Drop the driver-internal definitions and use the global ones. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 71 +++++++++++--------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 0b71848930dd..82cf58fbe946 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -16,30 +16,8 @@ #define OMNIA_BOARD_LEDS 12 #define OMNIA_LED_NUM_CHANNELS 3 -/* MCU controller commands at I2C address 0x2a */ -#define OMNIA_MCU_I2C_ADDR 0x2a - -#define CMD_GET_STATUS_WORD 0x01 -#define STS_FEATURES_SUPPORTED BIT(2) - -#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 +/* MCU controller I2C address 0x2a, needed for detecting MCU features */ +#define OMNIA_MCU_I2C_ADDR 0x2a struct omnia_led { struct led_classdev_mc mc_cdev; @@ -60,7 +38,7 @@ struct omnia_leds { static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b) { - u8 buf[5] = { CMD_LED_COLOR, led, r, g, b }; + u8 buf[5] = { OMNIA_CMD_LED_COLOR, led, r, g, b }; return omnia_cmd_write(client, buf, sizeof(buf)); } @@ -127,12 +105,12 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, * is not being blinked by HW. */ if (!err && !led->hwtrig && !brightness != !led->on) { - u8 state = CMD_LED_STATE_LED(led->reg); + u8 state = OMNIA_CMD_LED_STATE_LED(led->reg); if (brightness) - state |= CMD_LED_STATE_ON; + state |= OMNIA_CMD_LED_STATE_ON; - err = omnia_cmd_write_u8(leds->client, CMD_LED_STATE, state); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_STATE, state); if (!err) led->on = !!brightness; } @@ -167,8 +145,8 @@ static int omnia_hwtrig_activate(struct led_classdev *cdev) if (!err) { /* Put the LED into MCU controlled mode */ - err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg)); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(led->reg)); if (!err) led->hwtrig = true; } @@ -189,9 +167,8 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev) led->hwtrig = false; /* Put the LED into software mode */ - err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg) | - CMD_LED_MODE_USER); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(led->reg) | OMNIA_CMD_LED_MODE_USER); mutex_unlock(&leds->lock); @@ -258,9 +235,8 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, cdev->default_trigger = omnia_hw_trigger.name; /* put the LED into software mode */ - ret = omnia_cmd_write_u8(client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg) | - CMD_LED_MODE_USER); + ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) | + OMNIA_CMD_LED_MODE_USER); if (ret) { dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, ret); @@ -268,8 +244,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, } /* disable the LED */ - ret = omnia_cmd_write_u8(client, CMD_LED_STATE, - CMD_LED_STATE_LED(led->reg)); + ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_STATE, OMNIA_CMD_LED_STATE_LED(led->reg)); if (ret) { dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret); return ret; @@ -311,7 +286,7 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a, u8 reply; int err; - err = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS, &reply); + err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_BRIGHTNESS, &reply); if (err < 0) return err; @@ -331,7 +306,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a, if (brightness > 100) return -EINVAL; - err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness); + err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_BRIGHTNESS, brightness); return err ?: count; } @@ -346,7 +321,7 @@ static ssize_t gamma_correction_show(struct device *dev, int err; if (leds->has_gamma_correction) { - err = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION, &reply); + err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_GAMMA_CORRECTION, &reply); if (err < 0) return err; } @@ -369,7 +344,7 @@ static ssize_t gamma_correction_store(struct device *dev, if (kstrtobool(buf, &val) < 0) return -EINVAL; - err = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val); + err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_GAMMA_CORRECTION, val); return err ?: count; } @@ -391,15 +366,15 @@ static int omnia_mcu_get_features(const struct i2c_client *client) /* We have to read features from different I2C address */ mcu_client.addr = OMNIA_MCU_I2C_ADDR; - err = omnia_cmd_read_u16(&mcu_client, CMD_GET_STATUS_WORD, &reply); + err = omnia_cmd_read_u16(&mcu_client, OMNIA_CMD_GET_STATUS_WORD, &reply); if (err) return err; - /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */ - if (!(reply & STS_FEATURES_SUPPORTED)) + /* Check whether MCU firmware supports the OMNIA_CMD_GET_FEAUTRES command */ + if (!(reply & OMNIA_STS_FEATURES_SUPPORTED)) return 0; - err = omnia_cmd_read_u16(&mcu_client, CMD_GET_FEATURES, &reply); + err = omnia_cmd_read_u16(&mcu_client, OMNIA_CMD_GET_FEATURES, &reply); if (err) return err; @@ -437,7 +412,7 @@ static int omnia_leds_probe(struct i2c_client *client) return ret; } - leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION; + leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION; if (!leds->has_gamma_correction) { dev_info(dev, "Your board's MCU firmware does not support the LED gamma correction feature.\n"); @@ -468,7 +443,7 @@ static int omnia_leds_probe(struct i2c_client *client) static void omnia_leds_remove(struct i2c_client *client) { /* put all LEDs into default (HW triggered) mode */ - omnia_cmd_write_u8(client, CMD_LED_MODE, CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); + omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); /* set all LEDs color to [255, 255, 255] */ omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255); From patchwork Tue Sep 3 10:19:25 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: 825136 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.subspace.kernel.org (Postfix) with ESMTPS id B33821AD254 for ; Tue, 3 Sep 2024 10:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358795; cv=none; b=B5fqCsXQgYkGFNiPUBSQb92QD5VaxTpu7TDTa9Thn5Osbkjodwb9GNN4fWQaUSvo6cV0ocnfThs/fWELahI6EBmLOaDvG/DkybxlJPnIUhkmKm3iOqHYhTztTh2LXbfzEI/tbwHP8GAvsA+PywBED/4iAWx80RnSOz7+FowiHpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358795; c=relaxed/simple; bh=FxPKGWWRKbnhjKzH3b2LpLpPDFpRJp5XiJc4PKVXMLI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kpQv7KKZTVMaiSZ19zaFoo6oKVfhzLVeegK8+yB9E2T9YfwSJs8cKkwMQJRAVt7zTTV3lKKPa0xJrsXn9WaBlfhJyT85cbYI1J8092Wgir2QqJwQbwxfHobQr6AiaHBv0yNPIw1RDITbIKaGayVKEsrQlegxv985acJd3PY7toU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L9h5Mjvv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L9h5Mjvv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 896D6C4CEC5; Tue, 3 Sep 2024 10:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725358795; bh=FxPKGWWRKbnhjKzH3b2LpLpPDFpRJp5XiJc4PKVXMLI=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=L9h5MjvvKcR3OiV9LIUg/LrLhC1Efo24XO3rdporcUB5IrYdi2n+6JsFPYaWEt1C4 JET0MmjoPSosm6n+fvYZJhlerTTwN/tekJXjkKuq1qUNBmmPVGBfo2U8Qfp94Db7iJ lg7ur4DqNF2HIqLlvSup66gd91tL6FPZyhIv0Xag0fd55u0gOqGtzylI9gODHw8t7K WBBDWORUnzZJdHHciKIyEou4eJSvOOEhxhUjlm8Es5q1spQ8l9PkZ5osM7BFNJTWkD mEYqXDhBZrqRpanyVca6fhtQhCBD82lY+2ZBjBW+GQAFvF8eOO/G6PLa1ZzBuR75Gp sD5SQBh8Iz6JA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones 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 , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds v2 06/11] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Date: Tue, 3 Sep 2024 12:19:25 +0200 Message-ID: <20240903101930.16251-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240903101930.16251-1-kabel@kernel.org> References: <20240903101930.16251-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When reading MCU firmware features, check also for the LED panel brightness change interrupt feature, and suggest upgrading the firmware if it is missing. Signed-off-by: Marek Behún --- drivers/platform/cznic/turris-omnia-mcu-base.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/cznic/turris-omnia-mcu-base.c b/drivers/platform/cznic/turris-omnia-mcu-base.c index bb871226e357..3bb4a3cfdb29 100644 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c @@ -258,6 +258,7 @@ static int omnia_mcu_read_features(struct omnia_mcu *mcu) _DEF_FEAT(NEW_INT_API, "new interrupt API"), _DEF_FEAT(POWEROFF_WAKEUP, "poweroff and wakeup"), _DEF_FEAT(TRNG, "true random number generator"), + _DEF_FEAT(BRIGHTNESS_INT, "LED panel brightness change interrupt"), #undef _DEF_FEAT }; struct i2c_client *client = mcu->client; From patchwork Tue Sep 3 10:19:27 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: 825135 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.subspace.kernel.org (Postfix) with ESMTPS id AEF3119F41A for ; Tue, 3 Sep 2024 10:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358801; cv=none; b=CsfagHNAjh6lSOAZUu7ZFQGu3+sfv+NC42dxwbfWCeNpVQLVhKVYZfs+aVxA/DNX2z+WGmnh4AMJ5/sHNIfDKoiErUxL/oNu8fhHE3uxLpt/OAgX0VPicWWMFuKRHN7AATq7F7B+2Ioe5nSpeGGWFi9pGd2R2nsDcI7qkEGMQPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358801; c=relaxed/simple; bh=ChFamoD08/Z3QdWY59A8Si+9qBsHrtVfOvBHL+fQvOQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T9Sw7ZGIUY3bQBa+/5n+RW7c6aKrGcbM78r2qx/jyYZhRAEpcI1dgwUBcc2PEULQ7mm2jU98uBJcb2b8yoESqKXrfz6IA5ubEeF4ccO7xaE+JaOqUYBI+cu5U4HSyptt/NpRIgO5s9IzO32H/7bXCS0tR0/nmt5QoO35H6AEatQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uUztMiQN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uUztMiQN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D51FDC4CECF; Tue, 3 Sep 2024 10:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725358801; bh=ChFamoD08/Z3QdWY59A8Si+9qBsHrtVfOvBHL+fQvOQ=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=uUztMiQNuCpuitsgP+cZeINBTDVaXsfxxsf5dtKmx1367JxTibgWpYA+WSfcsgx4A g5dbLmM4+P/LIie4HPu02zL2fVKBRvT2ZazABENP0HLksBAGTVhG1g/ULQgjAp1OhA M3rDpdSz/b2sB6MFBYDcFFNxJhD4ijr6/ZZJBf2GXg8AeoDfqUjmBS8enY2Ty7QSz6 GDa6WwwUKe3xccfXLJq7BDaXS2is3o6pSwLgAAGFtbAOQldq+kZ/dQf3FOKfQk16JN R2y5tudiG2oJz2RAtOfpTry65EwYoJ3WOyfuzrVPYlqrjF1BrOXA2G+sYtuxMdDr4J lifgspSgmMH6A== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones 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 , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds v2 08/11] leds: turris-omnia: Use dev_err_probe() where appropriate Date: Tue, 3 Sep 2024 12:19:27 +0200 Message-ID: <20240903101930.16251-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240903101930.16251-1-kabel@kernel.org> References: <20240903101930.16251-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use dev_err_probe() instead of dev_err() + separate return where appropriate. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 50 ++++++++++---------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 8d3bddc90fe0..857dba811d5e 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -238,33 +238,23 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, /* put the LED into software mode */ ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) | OMNIA_CMD_LED_MODE_USER); - if (ret) { - dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, - ret); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "Cannot set LED %pOF to software mode\n", np); /* disable the LED */ ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_STATE, OMNIA_CMD_LED_STATE_LED(led->reg)); - if (ret) { - dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "Cannot set LED %pOF brightness\n", np); /* Set initial color and cache it */ ret = omnia_led_send_color_cmd(client, led); - if (ret < 0) { - dev_err(dev, "Cannot set LED %pOF initial color: %i\n", np, - ret); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Cannot set LED %pOF initial color\n", np); ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data); - if (ret < 0) { - dev_err(dev, "Cannot register LED %pOF: %i\n", np, ret); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Cannot register LED %pOF\n", np); return 1; } @@ -406,13 +396,10 @@ static int omnia_leds_probe(struct i2c_client *client) int ret, count; count = of_get_available_child_count(np); - if (!count) { - dev_err(dev, "LEDs are not defined in device tree!\n"); - return -ENODEV; - } else if (count > OMNIA_BOARD_LEDS) { - dev_err(dev, "Too many LEDs defined in device tree!\n"); - return -EINVAL; - } + if (!count) + return dev_err_probe(dev, -ENODEV, "LEDs are not defined in device tree!\n"); + else if (count > OMNIA_BOARD_LEDS) + return dev_err_probe(dev, -EINVAL, "Too many LEDs defined in device tree!\n"); leds = devm_kzalloc(dev, struct_size(leds, leds, count), GFP_KERNEL); if (!leds) @@ -422,11 +409,8 @@ static int omnia_leds_probe(struct i2c_client *client) i2c_set_clientdata(client, leds); ret = omnia_mcu_get_features(client); - if (ret < 0) { - dev_err(dev, "Cannot determine MCU supported features: %d\n", - ret); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Cannot determine MCU supported features\n"); leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION; @@ -441,10 +425,8 @@ 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; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Cannot register private LED trigger\n"); led = &leds->leds[0]; for_each_available_child_of_node_scoped(np, child) { From patchwork Tue Sep 3 10:19:29 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: 825134 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.subspace.kernel.org (Postfix) with ESMTPS id 6192F1AD253 for ; Tue, 3 Sep 2024 10:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358808; cv=none; b=DmDmTro+pA1PPEm+3w/Jw6T0N1jPXIb44HccNdD2hYZVpsVfvgDCr7nFwgNtuQThA+PKsnZgMXVcxaGlxOVFgvgUF2zaGjd2h2TAvvOF6q8X4wWcvx3lQ6ALKY/riPak2UDFzNtyG+G4MJB37FAjlT+os6XyRJaZmw8Z13Wq+8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725358808; c=relaxed/simple; bh=vs8Tsdi6pPQ8xa5suwaesNowGqSnjweIujultdB+tXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JdbbMW9TcLh17mU73Krg6de4PGFDR4URTfkB8HKXb99HGREB7QyPxmQjN/phyjM5UaKv+EiLlvSj2pmofVKieV+/PZtt/7Cua4jAhFrg30QdWcHi+PKycAVvUlT2/dLtJGLwXi1KsMTKJWRLcLwutmaP3awwcfP9rt6uZCg0NOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bEGsYtxn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bEGsYtxn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EC17C4CEC8; Tue, 3 Sep 2024 10:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725358807; bh=vs8Tsdi6pPQ8xa5suwaesNowGqSnjweIujultdB+tXA=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=bEGsYtxnkzrKpretQSo4JKCpY7cbeCnkMDHXvC6m2VTA10+177K1o1qqOvKor+exw Bjne6/gbMcb1YUp2us9WbcNK1zxy13WlXFpiUFbftQqELdMqz1J/R3eKOHKY9DAC/e unlIFZZEJVqWXzGzW1w1w0o+HpBS3GX1Y1csmFjvPd1ZA9Vj8FcW+tz4ZZHxaFI2Mw AUfBddPykKwD6wRYk0E+/sCizICOCeYO5wIzui8OmtXU1otQCngdM0rO+lOjYED+Ks p0TNcqGNzFGlY/MaZH6IBiqD+4FDkqbEJ5PEEPaHLcdlHGnpn0De5Rvh8bmr9v6TBy 2VOeK70Plx9Sw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones 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 , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds v2 10/11] leds: turris-omnia: Use 100 columns in the rest of the code Date: Tue, 3 Sep 2024 12:19:29 +0200 Message-ID: <20240903101930.16251-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240903101930.16251-1-kabel@kernel.org> References: <20240903101930.16251-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are 7 more places in the code where the 100 column limit can be used to make the code more uniform. Do it. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 58c3f3afbca5..4ab76b5b5e68 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -44,8 +44,7 @@ static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 return omnia_cmd_write(client, buf, sizeof(buf)); } -static int omnia_led_send_color_cmd(const struct i2c_client *client, - struct omnia_led *led) +static int omnia_led_send_color_cmd(const struct i2c_client *client, struct omnia_led *led) { int ret; @@ -90,8 +89,7 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, * implement the division instruction). */ if (brightness || led->hwtrig) { - led_mc_calc_color_components(mc_cdev, brightness ?: - cdev->max_brightness); + led_mc_calc_color_components(mc_cdev, brightness ?: cdev->max_brightness); /* * Send color command only if brightness is non-zero and the RGB @@ -174,8 +172,7 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev) mutex_unlock(&leds->lock); if (err) - dev_err(cdev->dev, "Cannot put LED to software mode: %i\n", - err); + dev_err(cdev->dev, "Cannot put LED to software mode: %i\n", err); } static struct led_trigger omnia_hw_trigger = { @@ -251,8 +248,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, if (ret < 0) return dev_err_probe(dev, ret, "Cannot set LED %pOF initial color\n", np); - ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, - &init_data); + ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data); if (ret < 0) return dev_err_probe(dev, ret, "Cannot register LED %pOF\n", np); @@ -270,8 +266,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, * file lives in the device directory of the LED controller, not an individual * LED, so it should not confuse users. */ -static ssize_t brightness_show(struct device *dev, struct device_attribute *a, - char *buf) +static ssize_t brightness_show(struct device *dev, struct device_attribute *a, char *buf) { struct i2c_client *client = to_i2c_client(dev); u8 reply; @@ -303,8 +298,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a, } static DEVICE_ATTR_RW(brightness); -static ssize_t gamma_correction_show(struct device *dev, - struct device_attribute *a, char *buf) +static ssize_t gamma_correction_show(struct device *dev, struct device_attribute *a, char *buf) { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); @@ -320,8 +314,7 @@ static ssize_t gamma_correction_show(struct device *dev, return sysfs_emit(buf, "%d\n", !!reply); } -static ssize_t gamma_correction_store(struct device *dev, - struct device_attribute *a, +static ssize_t gamma_correction_store(struct device *dev, struct device_attribute *a, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev);