Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11831293rwl; Tue, 3 Jan 2023 05:29:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXtY1oleZ6/yFCmltZ1g9DPA30++oror3SIOeBexEQKZztb3q5KFoo+YwbWiUT4xOCXXfk0z X-Received: by 2002:a17:90a:7d13:b0:223:21d5:6901 with SMTP id g19-20020a17090a7d1300b0022321d56901mr45919084pjl.45.1672752567890; Tue, 03 Jan 2023 05:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672752567; cv=none; d=google.com; s=arc-20160816; b=oaU6eLHnL8+ph6wEMiJqIANRwdS4NLVSGtXbd6483MgkzAoo9JVmCV+hfxCxrUZHxA eSX6sVA0ttSJ2W8eg8A7Ajq7SijM7vBof3hNm+CjGP/uYCGQyRdm6nmB54VhTZV7Bx7a 3y4sN8lcV/wNvvRlytSqqtYukRj2af/gUU6gLgPSx+6WdHv0r27mFvTSwUM/5QbSi7Kp gff6r8pUOhmD74JlSPi44NWp822dQ6p0aL/+IUgKsCa5vUTmZRxrFqzpdO3i9faRqaIw rRiTVaL0lD0FCK89jxsF1nVBGwCuEJsi9ICIaeXx11Z6lu1lMCM/xfDrJZnW96cyr2Aj c8eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=B8eiPjXkkQb03Ja6E46VqXgqls7y1zhoNzwuQWkHhwE=; b=udBCtbSdKsp9U39HwAs4cH//UaRDR8CKSPtlIe6AejJ7QFwpYMU1pwJjlrDg+hCZb3 0DV4xc4EVSooVdQioxBYrkguelSQOp8bxwU9/cvLZoGxIAqUSPDEMyRa3jdXATFvI+T2 E5Qdz5aCMAZZ5SC8DKeQxMI1bMLZG4ijXNRnUZD5iTzxev9MkpXKK35KALHDPgqmQxNi XPBoYpTiNLpXKIJe/pwqnnZObIWogWi6MAX8CANmp2bX7xuPXrHcGhfiM2UGeCAG3Vlj eAXG3Y9WitFaX8YfZ58QU9b+oQHXz+Ef+Qn3o6seb5CxunY4glsQRwCi0e9I98ifDt0z qoQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YwlayVUa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d59-20020a17090a6f4100b0021917840676si8441784pjk.31.2023.01.03.05.29.20; Tue, 03 Jan 2023 05:29:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YwlayVUa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237397AbjACMp2 (ORCPT + 60 others); Tue, 3 Jan 2023 07:45:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjACMp0 (ORCPT ); Tue, 3 Jan 2023 07:45:26 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 341F1DFD9; Tue, 3 Jan 2023 04:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672749924; x=1704285924; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=lwU98dyaymbW2/sk3kp9r5ZvEL697tsRK3f7uEUqPpM=; b=YwlayVUaEb28gRft5ju20ZozxHl9T83ehtmmrOnJIhKBAf/C36oi/Ndx za/tzr2/vZ2/jDL4Ka25PXxI37w4EYYPy51LVaTvPpncqFqQ6zmcCO9FO eSZ3hgDkx1W+j/jSP+ocZrvYbb+woYnH11dfLmQF9ugVSCxxIwRkJNd4h /XxFvoMoXXFagDx2A1RjwrZAjJhBD4hlU0wt3r7vxdotX7F/m5miaxHxy 1qktd1D6h4yagwsVIca9Ae6Ojv64cOAHFVfJrz5KG+Y+lLjdi5OJXz+nz dHK3lMSQvCvv49Hap/nG7gcOJifY+mAEv64XSF2nOC6tcavnIVI11AAJn w==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="383948134" X-IronPort-AV: E=Sophos;i="5.96,297,1665471600"; d="scan'208";a="383948134" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 04:45:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="685386050" X-IronPort-AV: E=Sophos;i="5.96,297,1665471600"; d="scan'208";a="685386050" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga008.jf.intel.com with ESMTP; 03 Jan 2023 04:45:20 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pCgfO-003t61-15; Tue, 03 Jan 2023 14:45:18 +0200 Date: Tue, 3 Jan 2023 14:45:17 +0200 From: Andy Shevchenko To: ChiaEn Wu Cc: pavel@ucw.cz, lee@kernel.org, matthias.bgg@gmail.com, chiaen_wu@richtek.com, cy_huang@richtek.com, linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, szunichen@gmail.com, AngeloGioacchino Del Regno , Alice Chen Subject: Re: [PATCH v15 RESEND 1/2] leds: rgb: mt6370: Add MediaTek MT6370 current sink type LED Indicator support Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 03, 2023 at 03:00:07PM +0800, ChiaEn Wu wrote: > From: ChiYuan Huang > > The MediaTek MT6370 is a highly-integrated smart power management IC, > which includes a single cell Li-Ion/Li-Polymer switching battery > charger, a USB Type-C & Power Delivery (PD) controller, dual > Flash LED current sources, a RGB LED driver, a backlight WLED driver, > a display bias driver and a general LDO for portable devices. > > Add support for the MediaTek MT6370 Current Sink Type LED Indicator > driver. It can control four channels current-sink RGB LEDs with 3 modes: > constant current, PWM, and breath mode. ... > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2022 Richtek Technology Corp. > + * > + * Authors: > + * ChiYuan Huang > + * Alice Chen > + * Redundant blank line. > + */ ... > +#include asm/unaligned should work, no? ... > +struct mt6370_pdata { > + const unsigned int *tfreq; > + unsigned int tfreq_len; > + u8 pwm_duty; You may save a few bytes by moving this to the end of the structure. > + u16 reg_rgb1_tr; > + s16 reg_rgb_chrind_tr; > +}; ... > +struct mt6370_priv { > + /* Per LED access lock */ > + struct mutex lock; > + struct device *dev; > + struct regmap *regmap; Isn't one can be derived from the other? > + struct regmap_field *fields[F_MAX_FIELDS]; > + const struct reg_field *reg_fields; > + const struct linear_range *ranges; > + struct reg_cfg *reg_cfgs; > + const struct mt6370_pdata *pdata; > + unsigned int leds_count; > + unsigned int leds_active; > + struct mt6370_led leds[]; > +}; ... > +static int mt6370_isnk_brightness_set(struct led_classdev *lcdev, > + enum led_brightness level) > +{ > + struct mt6370_led *led = container_of(lcdev, struct mt6370_led, isink); > + struct mt6370_priv *priv = led->priv; > + unsigned int enable; > + int ret; > + > + mutex_lock(&priv->lock); > + > + ret = regmap_field_read(priv->fields[F_RGB_EN], &enable); > + if (ret) > + goto out_unlock; > + if (level == 0) { > + enable &= ~MT6370_CHEN_BIT(led->index); > + > + ret = mt6370_set_led_mode(priv, led->index, > + MT6370_LED_REG_MODE); > + if (ret) > + goto out_unlock; > + > + ret = regmap_field_write(priv->fields[F_RGB_EN], enable); > + } else { > + enable |= MT6370_CHEN_BIT(led->index); > + > + ret = mt6370_set_led_brightness(priv, led->index, level); > + if (ret) > + goto out_unlock; > + > + ret = regmap_field_write(priv->fields[F_RGB_EN], enable); > + } Hmm... Wouldn't be below the equivalent? if (level == 0) { enable &= ~MT6370_CHEN_BIT(led->index); ret = mt6370_set_led_mode(priv, led->index, MT6370_LED_REG_MODE); if (ret) goto out_unlock; } else { enable |= MT6370_CHEN_BIT(led->index); ret = mt6370_set_led_brightness(priv, led->index, level); if (ret) goto out_unlock; } ret = regmap_field_write(priv->fields[F_RGB_EN], enable); (Of course even if (ret) goto... is duplicated, but probably better to leave it as is now) > +out_unlock: > + mutex_unlock(&priv->lock); > + > + return ret; > +} ... > + fwnode_for_each_child_node(init_data->fwnode, child) { > + u32 reg, color; > + > + ret = fwnode_property_read_u32(child, "reg", ®); > + if (ret || reg > MT6370_LED_ISNK3 || > + priv->leds_active & BIT(reg)) I don't see where you drop a reference count. > + return -EINVAL; > + > + ret = fwnode_property_read_u32(child, "color", &color); > + if (ret) Ditto. > + return dev_err_probe(dev, ret, > + "LED %d, no color specified\n", > + led->index); > + > + priv->leds_active |= BIT(reg); > + sub_led[num_color].color_index = color; > + sub_led[num_color].channel = reg; > + sub_led[num_color].intensity = 0; > + num_color++; > + } ... > + count = device_get_child_node_count(dev); > + if (!count || count > MT6370_MAX_LEDS) Is the second really critical? Can it be just a warning and clamping of the counter to the upper limit? > + return dev_err_probe(dev, -EINVAL, > + "No child node or node count over max LED number %zu\n", > + count); ... > + device_for_each_child_node(dev, child) { > + struct mt6370_led *led = priv->leds + i++; > + struct led_init_data init_data = { .fwnode = child }; > + u32 reg, color; > + > + ret = fwnode_property_read_u32(child, "reg", ®); > + if (ret) What about reference count? > + return dev_err_probe(dev, ret, "Failed to parse reg property\n"); > + > + if (reg >= MT6370_MAX_LEDS) Ditto. > + return dev_err_probe(dev, -EINVAL, "Error reg property number\n"); > + > + ret = fwnode_property_read_u32(child, "color", &color); > + if (ret) Ditto. > + return dev_err_probe(dev, ret, "Failed to parse color property\n"); > + > + if (color == LED_COLOR_ID_RGB || color == LED_COLOR_ID_MULTI) > + reg = MT6370_VIRTUAL_MULTICOLOR; > + > + if (priv->leds_active & BIT(reg)) Ditto. > + return dev_err_probe(dev, -EINVAL, "Duplicate reg property\n"); > + > + priv->leds_active |= BIT(reg); > + > + led->index = reg; > + led->priv = priv; > + > + ret = mt6370_init_led_properties(led, &init_data); > + if (ret) Ditto. > + return ret; > + > + ret = mt6370_led_register(&pdev->dev, led, &init_data); > + if (ret) Ditto. > + return ret; > + } > + > + return 0; > +} -- With Best Regards, Andy Shevchenko