From patchwork Sun Sep 20 00:24:54 2020 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: 255365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12B9FC43465 for ; Sun, 20 Sep 2020 00:25:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C42CA235F8 for ; Sun, 20 Sep 2020 00:25:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nic.cz header.i=@nic.cz header.b="D/J1QSE+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726794AbgITAZE (ORCPT ); Sat, 19 Sep 2020 20:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726788AbgITAZE (ORCPT ); Sat, 19 Sep 2020 20:25:04 -0400 Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24EFAC061755 for ; Sat, 19 Sep 2020 17:25:04 -0700 (PDT) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id C6E681409FE; Sun, 20 Sep 2020 02:25:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1600561501; bh=c36vTawmxUEpQjE8ats+SMT3UvI5xX5w3mAfE+naLCI=; h=From:To:Date; b=D/J1QSE+BEP2V//+k1bk3oemnVdkM1XW1fuWAWbc7ewnjmENE85d68+HQ2knNDhDw Al5rkXiuCF6VvuJR04phHwgmqgYEBlGckj4xiZ8BM+ILk9cuLcc8MIx2nxFks+WiMR UT/LceajvJbuB4BZcHmPZ+Bb65sEoMRX3rdt1BsI= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: Pavel Machek , Dan Murphy , =?utf-8?q?Ma?= =?utf-8?q?rek_Beh=C3=BAn?= , Peter Meerwald , Ricardo Ribalda , Zahari Petkov Subject: [PATCH leds 1/7] leds: pca963x: cosmetic: use helper variables, better indentation Date: Sun, 20 Sep 2020 02:24:54 +0200 Message-Id: <20200920002500.5851-2-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200920002500.5851-1-marek.behun@nic.cz> References: <20200920002500.5851-1-marek.behun@nic.cz> MIME-Version: 1.0 X-Spamd-Bar: / X-Virus-Scanned: clamav-milter 0.102.2 at mail X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Use helper variables: instead of writing &client->dev at many places, write only dev. The same with pca963x->chip->chipdef, pca963x->chip->client). Use helper variable u8 val for i2c_smbus_write_byte_data, for better indentation. Indent better on various places. Signed-off-by: Marek Behún Cc: Peter Meerwald Cc: Ricardo Ribalda Cc: Zahari Petkov --- drivers/leds/leds-pca963x.c | 139 ++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 68 deletions(-) diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index d288acbc99c7c..c03871f92fecc 100644 --- a/drivers/leds/leds-pca963x.c +++ b/drivers/leds/leds-pca963x.c @@ -116,35 +116,38 @@ struct pca963x_led { }; static int pca963x_brightness(struct pca963x_led *pca963x, - enum led_brightness brightness) + enum led_brightness brightness) { - u8 ledout_addr = pca963x->chip->chipdef->ledout_base - + (pca963x->led_num / 4); - u8 ledout; - int shift = 2 * (pca963x->led_num % 4); - u8 mask = 0x3 << shift; + struct i2c_client *client = pca963x->chip->client; + struct pca963x_chipdef *chipdef = pca963x->chip->chipdef; + u8 ledout_addr, ledout, mask, val; + int shift; int ret; - ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr); + ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4); + shift = 2 * (pca963x->led_num % 4); + mask = 0x3 << shift; + ledout = i2c_smbus_read_byte_data(client, ledout_addr); + switch (brightness) { case LED_FULL: - ret = i2c_smbus_write_byte_data(pca963x->chip->client, - ledout_addr, - (ledout & ~mask) | (PCA963X_LED_ON << shift)); + val = (ledout & ~mask) | (PCA963X_LED_ON << shift); + ret = i2c_smbus_write_byte_data(client, ledout_addr, val); break; case LED_OFF: - ret = i2c_smbus_write_byte_data(pca963x->chip->client, - ledout_addr, ledout & ~mask); + val = ledout & ~mask; + ret = i2c_smbus_write_byte_data(client, ledout_addr, val); break; default: - ret = i2c_smbus_write_byte_data(pca963x->chip->client, - PCA963X_PWM_BASE + pca963x->led_num, - brightness); + ret = i2c_smbus_write_byte_data(client, + PCA963X_PWM_BASE + + pca963x->led_num, + brightness); if (ret < 0) return ret; - ret = i2c_smbus_write_byte_data(pca963x->chip->client, - ledout_addr, - (ledout & ~mask) | (PCA963X_LED_PWM << shift)); + + val = (ledout & ~mask) | (PCA963X_LED_PWM << shift); + ret = i2c_smbus_write_byte_data(client, ledout_addr, val); break; } @@ -153,36 +156,40 @@ static int pca963x_brightness(struct pca963x_led *pca963x, static void pca963x_blink(struct pca963x_led *pca963x) { - u8 ledout_addr = pca963x->chip->chipdef->ledout_base + - (pca963x->led_num / 4); - u8 ledout; - u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client, - PCA963X_MODE2); - int shift = 2 * (pca963x->led_num % 4); - u8 mask = 0x3 << shift; + struct i2c_client *client = pca963x->chip->client; + struct pca963x_chipdef *chipdef = pca963x->chip->chipdef; + u8 ledout_addr, ledout, mask, val, mode2; + int shift; + + ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4); + shift = 2 * (pca963x->led_num % 4); + mask = 0x3 << shift; + mode2 = i2c_smbus_read_byte_data(client, PCA963X_MODE2); - i2c_smbus_write_byte_data(pca963x->chip->client, - pca963x->chip->chipdef->grppwm, pca963x->gdc); + i2c_smbus_write_byte_data(client, chipdef->grppwm, pca963x->gdc); - i2c_smbus_write_byte_data(pca963x->chip->client, - pca963x->chip->chipdef->grpfreq, pca963x->gfrq); + i2c_smbus_write_byte_data(client, chipdef->grpfreq, pca963x->gfrq); if (!(mode2 & PCA963X_MODE2_DMBLNK)) - i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2, - mode2 | PCA963X_MODE2_DMBLNK); + i2c_smbus_write_byte_data(client, PCA963X_MODE2, + mode2 | PCA963X_MODE2_DMBLNK); mutex_lock(&pca963x->chip->mutex); - ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr); - if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift)) - i2c_smbus_write_byte_data(pca963x->chip->client, ledout_addr, - (ledout & ~mask) | (PCA963X_LED_GRP_PWM << shift)); + + ledout = i2c_smbus_read_byte_data(client, ledout_addr); + if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift)) { + val = (ledout & ~mask) | (PCA963X_LED_GRP_PWM << shift); + i2c_smbus_write_byte_data(client, ledout_addr, val); + } + mutex_unlock(&pca963x->chip->mutex); } static int pca963x_power_state(struct pca963x_led *pca963x) { + struct i2c_client *client = pca963x->chip->client; unsigned long *leds_on = &pca963x->chip->leds_on; - unsigned long cached_leds = pca963x->chip->leds_on; + unsigned long cached_leds = *leds_on; if (pca963x->led_cdev.brightness) set_bit(pca963x->led_num, leds_on); @@ -190,14 +197,14 @@ static int pca963x_power_state(struct pca963x_led *pca963x) clear_bit(pca963x->led_num, leds_on); if (!(*leds_on) != !cached_leds) - return i2c_smbus_write_byte_data(pca963x->chip->client, - PCA963X_MODE1, *leds_on ? 0 : BIT(4)); + return i2c_smbus_write_byte_data(client, PCA963X_MODE1, + *leds_on ? 0 : BIT(4)); return 0; } static int pca963x_led_set(struct led_classdev *led_cdev, - enum led_brightness value) + enum led_brightness value) { struct pca963x_led *pca963x; int ret; @@ -217,7 +224,7 @@ static int pca963x_led_set(struct led_classdev *led_cdev, } static unsigned int pca963x_period_scale(struct pca963x_led *pca963x, - unsigned int val) + unsigned int val) { unsigned int scaling = pca963x->chip->chipdef->scaling; @@ -225,7 +232,7 @@ static unsigned int pca963x_period_scale(struct pca963x_led *pca963x, } static int pca963x_blink_set(struct led_classdev *led_cdev, - unsigned long *delay_on, unsigned long *delay_off) + unsigned long *delay_on, unsigned long *delay_off) { struct pca963x_led *pca963x; unsigned long time_on, time_off, period; @@ -278,23 +285,23 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, } static struct pca963x_platform_data * -pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) +pca963x_get_pdata(struct device *dev, struct pca963x_chipdef *chip) { struct pca963x_platform_data *pdata; struct led_info *pca963x_leds; struct fwnode_handle *child; int count; - count = device_get_child_node_count(&client->dev); + count = device_get_child_node_count(dev); if (!count || count > chip->n_leds) return ERR_PTR(-ENODEV); - pca963x_leds = devm_kcalloc(&client->dev, - chip->n_leds, sizeof(struct led_info), GFP_KERNEL); + pca963x_leds = devm_kcalloc(dev, chip->n_leds, sizeof(struct led_info), + GFP_KERNEL); if (!pca963x_leds) return ERR_PTR(-ENOMEM); - device_for_each_child_node(&client->dev, child) { + device_for_each_child_node(dev, child) { struct led_info led = {}; u32 reg; int res; @@ -312,8 +319,8 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) pca963x_leds[reg] = led; } - pdata = devm_kzalloc(&client->dev, - sizeof(struct pca963x_platform_data), GFP_KERNEL); + pdata = devm_kzalloc(dev, sizeof(struct pca963x_platform_data), + GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); @@ -321,23 +328,23 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) pdata->leds.num_leds = chip->n_leds; /* default to open-drain unless totem pole (push-pull) is specified */ - if (device_property_read_bool(&client->dev, "nxp,totem-pole")) + if (device_property_read_bool(dev, "nxp,totem-pole")) pdata->outdrv = PCA963X_TOTEM_POLE; else pdata->outdrv = PCA963X_OPEN_DRAIN; /* default to software blinking unless hardware blinking is specified */ - if (device_property_read_bool(&client->dev, "nxp,hw-blink")) + if (device_property_read_bool(dev, "nxp,hw-blink")) pdata->blink_type = PCA963X_HW_BLINK; else pdata->blink_type = PCA963X_SW_BLINK; - if (device_property_read_u32(&client->dev, "nxp,period-scale", + if (device_property_read_u32(dev, "nxp,period-scale", &chip->scaling)) chip->scaling = 1000; /* default to non-inverted output, unless inverted is specified */ - if (device_property_read_bool(&client->dev, "nxp,inverted-out")) + if (device_property_read_bool(dev, "nxp,inverted-out")) pdata->dir = PCA963X_INVERTED; else pdata->dir = PCA963X_NORMAL; @@ -355,8 +362,9 @@ static const struct of_device_id of_pca963x_match[] = { MODULE_DEVICE_TABLE(of, of_pca963x_match); static int pca963x_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct pca963x *pca963x_chip; struct pca963x_led *pca963x; struct pca963x_platform_data *pdata; @@ -364,29 +372,26 @@ static int pca963x_probe(struct i2c_client *client, int i, err; chip = &pca963x_chipdefs[id->driver_data]; - pdata = dev_get_platdata(&client->dev); + pdata = dev_get_platdata(dev); if (!pdata) { - pdata = pca963x_get_pdata(client, chip); + pdata = pca963x_get_pdata(dev, chip); if (IS_ERR(pdata)) { - dev_warn(&client->dev, "could not parse configuration\n"); + dev_warn(dev, "could not parse configuration\n"); pdata = NULL; } } if (pdata && (pdata->leds.num_leds < 1 || - pdata->leds.num_leds > chip->n_leds)) { - dev_err(&client->dev, "board info must claim 1-%d LEDs", - chip->n_leds); + pdata->leds.num_leds > chip->n_leds)) { + dev_err(dev, "board info must claim 1-%d LEDs", chip->n_leds); return -EINVAL; } - pca963x_chip = devm_kzalloc(&client->dev, sizeof(*pca963x_chip), - GFP_KERNEL); + pca963x_chip = devm_kzalloc(dev, sizeof(*pca963x_chip), GFP_KERNEL); if (!pca963x_chip) return -ENOMEM; - pca963x = devm_kcalloc(&client->dev, chip->n_leds, sizeof(*pca963x), - GFP_KERNEL); + pca963x = devm_kcalloc(dev, chip->n_leds, sizeof(*pca963x), GFP_KERNEL); if (!pca963x) return -ENOMEM; @@ -427,7 +432,7 @@ static int pca963x_probe(struct i2c_client *client, if (pdata && pdata->blink_type == PCA963X_HW_BLINK) pca963x[i].led_cdev.blink_set = pca963x_blink_set; - err = led_classdev_register(&client->dev, &pca963x[i].led_cdev); + err = led_classdev_register(dev, &pca963x[i].led_cdev); if (err < 0) goto exit; } @@ -436,8 +441,7 @@ static int pca963x_probe(struct i2c_client *client, i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4)); if (pdata) { - u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client, - PCA963X_MODE2); + u8 mode2 = i2c_smbus_read_byte_data(client, PCA963X_MODE2); /* Configure output: open-drain or totem pole (push-pull) */ if (pdata->outdrv == PCA963X_OPEN_DRAIN) mode2 &= ~PCA963X_MODE2_OUTDRV; @@ -446,8 +450,7 @@ static int pca963x_probe(struct i2c_client *client, /* Configure direction: normal or inverted */ if (pdata->dir == PCA963X_INVERTED) mode2 |= PCA963X_MODE2_INVRT; - i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2, - mode2); + i2c_smbus_write_byte_data(client, PCA963X_MODE2, mode2); } return 0; From patchwork Sun Sep 20 00:24:57 2020 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: 255364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF6BBC43463 for ; Sun, 20 Sep 2020 00:25:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E3BF2192A for ; Sun, 20 Sep 2020 00:25:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nic.cz header.i=@nic.cz header.b="k6H9HP2i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726707AbgITAZE (ORCPT ); Sat, 19 Sep 2020 20:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgITAZE (ORCPT ); Sat, 19 Sep 2020 20:25:04 -0400 Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1A0C0613CE for ; Sat, 19 Sep 2020 17:25:04 -0700 (PDT) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id 6412D140A7F; Sun, 20 Sep 2020 02:25:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1600561502; bh=4knxJBh8MOyONPnfVXDOtZ74q0g5oHvMRrhfmyUEMlA=; h=From:To:Date; b=k6H9HP2ivvb37rO61bu34n5xrt0Eqfv+fLQAsFQmk8qfWnfK/o11jCSeUx0aU9jZ8 esuxJB2Xeqv2kvKCroP5f2zsoeGvDEjY+aRmXcdnkkOqS3rWGfE746lTVL2iPT39kC iV0XZ5lmCXDZufyiplAE33XKCgovqpHEH4Adac+Q= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: Pavel Machek , Dan Murphy , =?utf-8?q?Ma?= =?utf-8?q?rek_Beh=C3=BAn?= , Peter Meerwald , Ricardo Ribalda , Zahari Petkov Subject: [PATCH leds 4/7] leds: pca963x: cosmetic: rename variables Date: Sun, 20 Sep 2020 02:24:57 +0200 Message-Id: <20200920002500.5851-5-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200920002500.5851-1-marek.behun@nic.cz> References: <20200920002500.5851-1-marek.behun@nic.cz> MIME-Version: 1.0 X-Spamd-Bar: / X-Virus-Scanned: clamav-milter 0.102.2 at mail X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Rename variable of type struct pca963x_led from pca963x to simple led. Signed-off-by: Marek Behún Cc: Peter Meerwald Cc: Ricardo Ribalda Cc: Zahari Petkov --- drivers/leds/leds-pca963x.c | 104 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index bdb014c76a078..a4096694925f5 100644 --- a/drivers/leds/leds-pca963x.c +++ b/drivers/leds/leds-pca963x.c @@ -115,17 +115,17 @@ struct pca963x_led { u8 gfrq; }; -static int pca963x_brightness(struct pca963x_led *pca963x, +static int pca963x_brightness(struct pca963x_led *led, enum led_brightness brightness) { - struct i2c_client *client = pca963x->chip->client; - struct pca963x_chipdef *chipdef = pca963x->chip->chipdef; + struct i2c_client *client = led->chip->client; + struct pca963x_chipdef *chipdef = led->chip->chipdef; u8 ledout_addr, ledout, mask, val; int shift; int ret; - ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4); - shift = 2 * (pca963x->led_num % 4); + ledout_addr = chipdef->ledout_base + (led->led_num / 4); + shift = 2 * (led->led_num % 4); mask = 0x3 << shift; ledout = i2c_smbus_read_byte_data(client, ledout_addr); @@ -141,7 +141,7 @@ static int pca963x_brightness(struct pca963x_led *pca963x, default: ret = i2c_smbus_write_byte_data(client, PCA963X_PWM_BASE + - pca963x->led_num, + led->led_num, brightness); if (ret < 0) return ret; @@ -154,27 +154,27 @@ static int pca963x_brightness(struct pca963x_led *pca963x, return ret; } -static void pca963x_blink(struct pca963x_led *pca963x) +static void pca963x_blink(struct pca963x_led *led) { - struct i2c_client *client = pca963x->chip->client; - struct pca963x_chipdef *chipdef = pca963x->chip->chipdef; + struct i2c_client *client = led->chip->client; + struct pca963x_chipdef *chipdef = led->chip->chipdef; u8 ledout_addr, ledout, mask, val, mode2; int shift; - ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4); - shift = 2 * (pca963x->led_num % 4); + ledout_addr = chipdef->ledout_base + (led->led_num / 4); + shift = 2 * (led->led_num % 4); mask = 0x3 << shift; mode2 = i2c_smbus_read_byte_data(client, PCA963X_MODE2); - i2c_smbus_write_byte_data(client, chipdef->grppwm, pca963x->gdc); + i2c_smbus_write_byte_data(client, chipdef->grppwm, led->gdc); - i2c_smbus_write_byte_data(client, chipdef->grpfreq, pca963x->gfrq); + i2c_smbus_write_byte_data(client, chipdef->grpfreq, led->gfrq); if (!(mode2 & PCA963X_MODE2_DMBLNK)) i2c_smbus_write_byte_data(client, PCA963X_MODE2, mode2 | PCA963X_MODE2_DMBLNK); - mutex_lock(&pca963x->chip->mutex); + mutex_lock(&led->chip->mutex); ledout = i2c_smbus_read_byte_data(client, ledout_addr); if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift)) { @@ -182,19 +182,19 @@ static void pca963x_blink(struct pca963x_led *pca963x) i2c_smbus_write_byte_data(client, ledout_addr, val); } - mutex_unlock(&pca963x->chip->mutex); + mutex_unlock(&led->chip->mutex); } -static int pca963x_power_state(struct pca963x_led *pca963x) +static int pca963x_power_state(struct pca963x_led *led) { - struct i2c_client *client = pca963x->chip->client; - unsigned long *leds_on = &pca963x->chip->leds_on; + struct i2c_client *client = led->chip->client; + unsigned long *leds_on = &led->chip->leds_on; unsigned long cached_leds = *leds_on; - if (pca963x->led_cdev.brightness) - set_bit(pca963x->led_num, leds_on); + if (led->led_cdev.brightness) + set_bit(led->led_num, leds_on); else - clear_bit(pca963x->led_num, leds_on); + clear_bit(led->led_num, leds_on); if (!(*leds_on) != !cached_leds) return i2c_smbus_write_byte_data(client, PCA963X_MODE1, @@ -206,27 +206,27 @@ static int pca963x_power_state(struct pca963x_led *pca963x) static int pca963x_led_set(struct led_classdev *led_cdev, enum led_brightness value) { - struct pca963x_led *pca963x; + struct pca963x_led *led; int ret; - pca963x = container_of(led_cdev, struct pca963x_led, led_cdev); + led = container_of(led_cdev, struct pca963x_led, led_cdev); - mutex_lock(&pca963x->chip->mutex); + mutex_lock(&led->chip->mutex); - ret = pca963x_brightness(pca963x, value); + ret = pca963x_brightness(led, value); if (ret < 0) goto unlock; - ret = pca963x_power_state(pca963x); + ret = pca963x_power_state(led); unlock: - mutex_unlock(&pca963x->chip->mutex); + mutex_unlock(&led->chip->mutex); return ret; } -static unsigned int pca963x_period_scale(struct pca963x_led *pca963x, +static unsigned int pca963x_period_scale(struct pca963x_led *led, unsigned int val) { - unsigned int scaling = pca963x->chip->chipdef->scaling; + unsigned int scaling = led->chip->chipdef->scaling; return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val; } @@ -234,11 +234,11 @@ static unsigned int pca963x_period_scale(struct pca963x_led *pca963x, static int pca963x_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { - struct pca963x_led *pca963x; unsigned long time_on, time_off, period; + struct pca963x_led *led; u8 gdc, gfrq; - pca963x = container_of(led_cdev, struct pca963x_led, led_cdev); + led = container_of(led_cdev, struct pca963x_led, led_cdev); time_on = *delay_on; time_off = *delay_off; @@ -249,14 +249,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, time_off = 500; } - period = pca963x_period_scale(pca963x, time_on + time_off); + period = pca963x_period_scale(led, time_on + time_off); /* If period not supported by hardware, default to someting sane. */ if ((period < PCA963X_BLINK_PERIOD_MIN) || (period > PCA963X_BLINK_PERIOD_MAX)) { time_on = 500; time_off = 500; - period = pca963x_period_scale(pca963x, 1000); + period = pca963x_period_scale(led, 1000); } /* @@ -264,7 +264,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, * (time_on / period) = (GDC / 256) -> * GDC = ((time_on * 256) / period) */ - gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period; + gdc = (pca963x_period_scale(led, time_on) * 256) / period; /* * From manual: period = ((GFRQ + 1) / 24) in seconds. @@ -273,10 +273,10 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, */ gfrq = (period * 24 / 1000) - 1; - pca963x->gdc = gdc; - pca963x->gfrq = gfrq; + led->gdc = gdc; + led->gfrq = gfrq; - pca963x_blink(pca963x); + pca963x_blink(led); *delay_on = time_on; *delay_off = time_off; @@ -367,7 +367,7 @@ static int pca963x_probe(struct i2c_client *client, struct device *dev = &client->dev; struct pca963x_chipdef *chipdef; struct pca963x_platform_data *pdata; - struct pca963x_led *pca963x; + struct pca963x_led *leds; struct pca963x *chip; int i, err; @@ -392,8 +392,8 @@ static int pca963x_probe(struct i2c_client *client, chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - pca963x = devm_kcalloc(dev, chipdef->n_leds, sizeof(*pca963x), GFP_KERNEL); - if (!pca963x) + leds = devm_kcalloc(dev, chipdef->n_leds, sizeof(*leds), GFP_KERNEL); + if (!leds) return -ENOMEM; i2c_set_clientdata(client, chip); @@ -401,39 +401,41 @@ static int pca963x_probe(struct i2c_client *client, mutex_init(&chip->mutex); chip->chipdef = chipdef; chip->client = client; - chip->leds = pca963x; + chip->leds = leds; /* Turn off LEDs by default*/ for (i = 0; i < chipdef->n_leds / 4; i++) i2c_smbus_write_byte_data(client, chipdef->ledout_base + i, 0x00); for (i = 0; i < chipdef->n_leds; i++) { - pca963x[i].led_num = i; - pca963x[i].chip = chip; + struct pca963x_led *led = &leds[i]; + + led->led_num = i; + led->chip = chip; /* Platform data can specify LED names and default triggers */ if (pdata && i < pdata->leds.num_leds) { if (pdata->leds.leds[i].name) - snprintf(pca963x[i].name, - sizeof(pca963x[i].name), "pca963x:%s", + snprintf(led->name, + sizeof(led->name), "pca963x:%s", pdata->leds.leds[i].name); if (pdata->leds.leds[i].default_trigger) - pca963x[i].led_cdev.default_trigger = + led->led_cdev.default_trigger = pdata->leds.leds[i].default_trigger; } if (!pdata || i >= pdata->leds.num_leds || !pdata->leds.leds[i].name) - snprintf(pca963x[i].name, sizeof(pca963x[i].name), + snprintf(led->name, sizeof(led->name), "pca963x:%d:%.2x:%d", client->adapter->nr, client->addr, i); - pca963x[i].led_cdev.name = pca963x[i].name; - pca963x[i].led_cdev.brightness_set_blocking = pca963x_led_set; + led->led_cdev.name = led->name; + led->led_cdev.brightness_set_blocking = pca963x_led_set; if (pdata && pdata->blink_type == PCA963X_HW_BLINK) - pca963x[i].led_cdev.blink_set = pca963x_blink_set; + led->led_cdev.blink_set = pca963x_blink_set; - err = devm_led_classdev_register(dev, &pca963x[i].led_cdev); + err = devm_led_classdev_register(dev, &led->led_cdev); if (err < 0) return err; } From patchwork Sun Sep 20 00:25:00 2020 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: 255363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D430FC43469 for ; Sun, 20 Sep 2020 00:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B81F20E65 for ; Sun, 20 Sep 2020 00:25:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nic.cz header.i=@nic.cz header.b="XA1b/JGm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726806AbgITAZF (ORCPT ); Sat, 19 Sep 2020 20:25:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbgITAZF (ORCPT ); Sat, 19 Sep 2020 20:25:05 -0400 Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E578C061755 for ; Sat, 19 Sep 2020 17:25:05 -0700 (PDT) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id 0CEC2140A99; Sun, 20 Sep 2020 02:25:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1600561503; bh=wCHcJGOtTztFA3VOpQ+2gTSFQn1wILFtTiwAsFMseXo=; h=From:To:Date; b=XA1b/JGmt8WHZqy9C3PtK0j2/evis1YQgP7LJHMfa9s56+2dImvGPQUSJFooDlmuS IUDxX3We3NdHw6I+rid6OoO6M0zk3QWbrAisyqFzoYQtfoZaXUmKFcwEk83EGPIZTY tRuT61lSkb6i/PJAGkOp1R9ZSM56cssxTLTjSrRQ= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: Pavel Machek , Dan Murphy , =?utf-8?q?Ma?= =?utf-8?q?rek_Beh=C3=BAn?= , Peter Meerwald , Ricardo Ribalda , Zahari Petkov Subject: [PATCH leds 7/7] leds: pca963x: use struct led_init_data when registering Date: Sun, 20 Sep 2020 02:25:00 +0200 Message-Id: <20200920002500.5851-8-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200920002500.5851-1-marek.behun@nic.cz> References: <20200920002500.5851-1-marek.behun@nic.cz> MIME-Version: 1.0 X-Spamd-Bar: / X-Virus-Scanned: clamav-milter 0.102.2 at mail X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org By using struct led_init_data when registering we do not need to parse `label` DT property. Moreover `label` is deprecated and if it is not present but `color` and `function` are, LED core will compose a name from these properties instead. Previously if the `label` DT property was not present, the code composed name for the LED in the form "pca963x:%d:%.2x:%u" For backwards compatibility we therefore set init_data->default_label to this value so that the LED will not get a different name if `label` property is not present, nor are `color` and `function`. Signed-off-by: Marek Behún Cc: Peter Meerwald Cc: Ricardo Ribalda Cc: Zahari Petkov --- drivers/leds/leds-pca963x.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index 5083ccce1a519..00aecd67e3483 100644 --- a/drivers/leds/leds-pca963x.c +++ b/drivers/leds/leds-pca963x.c @@ -289,8 +289,6 @@ static int pca963x_register_leds(struct i2c_client *client, struct pca963x_led *led = chip->leds; struct device *dev = &client->dev; struct fwnode_handle *child; - const char *name; - char label[64]; bool hw_blink; s32 mode2; u32 reg; @@ -323,6 +321,9 @@ static int pca963x_register_leds(struct i2c_client *client, return ret; device_for_each_child_node(dev, child) { + struct led_init_data init_data = {}; + char default_label[32]; + ret = fwnode_property_read_u32(child, "reg", ®); if (ret || reg >= chipdef->n_leds) { dev_err(dev, "Invalid 'reg' property for node %pfw\n", @@ -331,23 +332,21 @@ static int pca963x_register_leds(struct i2c_client *client, goto err; } - ret = fwnode_property_read_string(child, "label", &name); - if (!fwnode_property_read_string(child, "label", &name)) - snprintf(label, sizeof(label), "pca963x:%s", name); - else - snprintf(label, sizeof(label), "pca963x::"); - - fwnode_property_read_string(child, "linux,default-trigger", - &led->led_cdev.default_trigger); - led->led_num = reg; led->chip = chip; - led->led_cdev.name = label; led->led_cdev.brightness_set_blocking = pca963x_led_set; if (hw_blink) led->led_cdev.blink_set = pca963x_blink_set; - ret = devm_led_classdev_register(dev, &led->led_cdev); + init_data.fwnode = child; + /* for backwards compatibility */ + init_data.devicename = "pca963x"; + snprintf(default_label, sizeof(default_label), "%d:%.2x:%u", + client->adapter->nr, client->addr, reg); + init_data.default_label = default_label; + + ret = devm_led_classdev_register_ext(dev, &led->led_cdev, + &init_data); if (ret) { dev_err(dev, "Failed to register LED for node %pfw\n", child);