From patchwork Tue Aug 20 19:53:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 171831 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4886744ily; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTDPhkw8iYAa0i8YxZ0uSAXqWnQXE/uomVxqO3WiwCdGpHDz6/fdbD2rCXmcqcfUyeQjgD X-Received: by 2002:a17:90a:c24e:: with SMTP id d14mr1638708pjx.129.1566330809513; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566330809; cv=none; d=google.com; s=arc-20160816; b=tqaYfoDUqdZSAJdRy1vhUuWNc2eGIU+vgmu+dNGI8Zini2snmsGwinQgYia8SBNMT9 nbZ3AWT5Gq196t/nVQNoXtoeEBw0OuAzF3UYE55RZuTVWDOPGpp5iC/Pdrl5SMVOPB1n GXIfTozjOqZb8dUsL7c22EqR1zTxY5o549YkLfhVtJObqDCWb0gszjT8eF0crAl6Rh5y zm8xATknHGr3HckJuK1BQA8+89+K/VX6YhS22vP98HAIxTSaAUY2JEfzQCk45DlDtPqx Ku7gx864PuwUfVo5pJgr6BbMncM/HZ5F8xlGDXIwnk5+PMaq4KBSFfTDXRltBEoG4tSo FcHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=1Y9+XjYRFLbflyvbX9e5HxjQ1hWCEl4/iaqYE2kemX4=; b=0y6K8MI2fghz9KQ+n31qSZYQm/fPxUmlVTbPm/GyACsMREZXy6YsBz5lgLqWusQlhw r1cjjcb3qgmeAbxCaQ0zm+leu3aXCDOmbUiptywtLNLX5lDvGHjSWsKPb7PpyZiuzbbw KzzNWTqjC9kZXVn15ECbtVLGSAmVNyf3E+Et3rdT4+pxcLJHCveg6s0so/PXfOmu+5z6 dEik7bKVNJTGJX8V95WHla7bpevJ5vAVAZeZ2IKtUrA/l2Nrs7eH9bf4bWzi29kjg/qW 1SmyvHUIXrD/5KcsnJ6qob4l66TV/Kgl2Tm/t/6iJUvH6A5ImJC5jeD5X79WTstKo+mi OEBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Rb+6JZPY; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si7757005pgr.184.2019.08.20.12.53.29; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Rb+6JZPY; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730701AbfHTTx3 (ORCPT + 1 other); Tue, 20 Aug 2019 15:53:29 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:60928 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729833AbfHTTx2 (ORCPT ); Tue, 20 Aug 2019 15:53:28 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrIXt074392; Tue, 20 Aug 2019 14:53:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1566330798; bh=1Y9+XjYRFLbflyvbX9e5HxjQ1hWCEl4/iaqYE2kemX4=; h=From:To:CC:Subject:Date; b=Rb+6JZPYr59IO1UO6kJUW1G9u+WIezIgkmGJuujLw/QMXUDwpdkciaY78ySDKNmOF dKLVesqMW2FI3JZbe1o5hGvZJkoar2+vi1zu3C7aPuHNpMgsiH7nmUYVpCHzT+B9Fi +DIQzVPvz4WZqJXC7ToQJELFfk/7B6iVdjUY+1uE= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x7KJrHIq116193 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 20 Aug 2019 14:53:18 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 20 Aug 2019 14:53:17 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 20 Aug 2019 14:53:17 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrHx3070705; Tue, 20 Aug 2019 14:53:17 -0500 From: Dan Murphy To: , , , , , , CC: , , Dan Murphy Subject: [PATCH v3 1/5] leds: lm3532: Fix brightness control for i2c mode Date: Tue, 20 Aug 2019 14:53:03 -0500 Message-ID: <20190820195307.27590-1-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Fix the brightness control for I2C mode. Instead of changing the full scale current register update the ALS target register for the appropriate banks. In addition clean up some code errors and random misspellings found during coding. Tested on Droid4 as well as LM3532 EVM connected to a BeagleBoneBlack Fixes: e37a7f8d77e1 ("leds: lm3532: Introduce the lm3532 LED driver") Reported-by: Pavel Machek Signed-off-by: Dan Murphy --- v3 - Removed register define updates - https://lore.kernel.org/patchwork/patch/1114542/ drivers/leds/leds-lm3532.c | 44 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) -- 2.22.0.214.g8dca754b1e Acked-by: Pavel Machek Signed-off-by: Pavel Machek diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index 646100724971..8132d05f7add 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -38,6 +38,9 @@ #define LM3532_REG_ZN_2_LO 0x65 #define LM3532_REG_ZN_3_HI 0x66 #define LM3532_REG_ZN_3_LO 0x67 +#define LM3532_REG_ZONE_TRGT_A 0x70 +#define LM3532_REG_ZONE_TRGT_B 0x75 +#define LM3532_REG_ZONE_TRGT_C 0x7a #define LM3532_REG_MAX 0x7e /* Contorl Enable */ @@ -116,6 +119,7 @@ struct lm3532_als_data { * @priv - Pointer the device data structure * @control_bank - Control bank the LED is associated to * @mode - Mode of the LED string + * @ctrl_brt_pointer - Zone target register that controls the sink * @num_leds - Number of LED strings are supported in this array * @led_strings - The LED strings supported in this array * @label - LED label @@ -126,6 +130,7 @@ struct lm3532_led { int control_bank; int mode; + int ctrl_brt_pointer; int num_leds; u32 led_strings[LM3532_MAX_CONTROL_BANKS]; char label[LED_MAX_NAME_SIZE]; @@ -339,8 +344,8 @@ static int lm3532_brightness_set(struct led_classdev *led_cdev, if (ret) goto unlock; - brightness_reg = LM3532_REG_CTRL_A_BRT + led->control_bank * 2; - brt_val = brt_val / LM3532_BRT_VAL_ADJUST; + brightness_reg = LM3532_REG_ZONE_TRGT_A + led->control_bank * 5 + + (led->ctrl_brt_pointer >> 2); ret = regmap_write(led->priv->regmap, brightness_reg, brt_val); @@ -356,8 +361,30 @@ static int lm3532_init_registers(struct lm3532_led *led) unsigned int output_cfg_val = 0; unsigned int output_cfg_shift = 0; unsigned int output_cfg_mask = 0; + unsigned int brightness_config_reg; + unsigned int brightness_config_val; int ret, i; + if (drvdata->enable_gpio) + gpiod_direction_output(drvdata->enable_gpio, 1); + + brightness_config_reg = LM3532_REG_ZONE_CFG_A + led->control_bank * 2; + /* + * This could be hard coded to the default value but the control + * brightness register may have changed during boot. + */ + ret = regmap_read(drvdata->regmap, brightness_config_reg, + &led->ctrl_brt_pointer); + if (ret) + return ret; + + led->ctrl_brt_pointer &= LM3532_ZONE_MASK; + brightness_config_val = led->ctrl_brt_pointer | led->mode; + ret = regmap_write(drvdata->regmap, brightness_config_reg, + brightness_config_val); + if (ret) + return ret; + for (i = 0; i < led->num_leds; i++) { output_cfg_shift = led->led_strings[i] * 2; output_cfg_val |= (led->control_bank << output_cfg_shift); @@ -382,7 +409,6 @@ static int lm3532_als_configure(struct lm3532_data *priv, struct lm3532_als_data *als = priv->als_data; u32 als_vmin, als_vmax, als_vstep; int zone_reg = LM3532_REG_ZN_0_HI; - int brightnes_config_reg; int ret; int i; @@ -411,14 +437,7 @@ static int lm3532_als_configure(struct lm3532_data *priv, als->config = (als->als_avrg_time | (LM3532_ENABLE_ALS) | (als->als_input_mode << LM3532_ALS_SEL_SHIFT)); - ret = regmap_write(priv->regmap, LM3532_ALS_CONFIG, als->config); - if (ret) - return ret; - - brightnes_config_reg = LM3532_REG_ZONE_CFG_A + led->control_bank * 2; - - return regmap_update_bits(priv->regmap, brightnes_config_reg, - LM3532_I2C_CTRL, LM3532_ALS_CTRL); + return regmap_write(priv->regmap, LM3532_ALS_CONFIG, als->config); } static int lm3532_parse_als(struct lm3532_data *priv) @@ -634,9 +653,6 @@ static int lm3532_probe(struct i2c_client *client, return ret; } - if (drvdata->enable_gpio) - gpiod_direction_output(drvdata->enable_gpio, 1); - return ret; } From patchwork Tue Aug 20 19:53:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 171830 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4886737ily; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzg2P84WFF5QDS4dX5Tw10gYBtj5dMd5b/qA8oUF7mgh0erXP3XjsbHcFuezN4VK/hQdBge X-Received: by 2002:a17:902:306:: with SMTP id 6mr29980990pld.86.1566330809143; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566330809; cv=none; d=google.com; s=arc-20160816; b=jnHufjUIcuB6aWmK25rIpNzipGP77TlFh56yT7TKKPXdOR5u5INliDe79e4gu7fEvP 7lCCOW+5nh3fTvcdLyisdJTw/HhxsKqi2ufdGo3DHrs4ku1zmriSlMp3j5UJbcCm3OLb +QzzpCKnfNz3Urn3U9GhE6vXWHVEKAHiNOEIM4+0FdqlhB+AVLv8gD3yXq5a0W8kUntM MllJD4IVHB8qNTwvLAg3eACejIlwNWw5TxT7aLaN/WPqP7Ilq1ZKcRx55Ck5fjOvY6fO eApsRWLpU4/tVuuyN7JVQNoY2pXZIIQiyZ67yuXtPQy82u3k6SsHRue5Z7U5Zv1zReSl 4NUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SoaUx4hsoNivA4WY8SmxX4gYKChR8ekucNpgYs7oGOU=; b=fCAfmcsS307bBeIm5zImk79dOtoIufZQYNLgU4Qv3/0mCBYVz1Qz5p7R6Qy7WwS06w D0sZxpAC6bzZ4bKa3bbCOC6SEfbj5NYJVqJPT81l8ovZbVXDamNjzjA/4Unr/dNPgTBu DQFGr0CSqVnGpGWsEG4Jvv/B/0hY/MepdsVd7E2BhvBYQ10G2/i+PC4BhJR4fTlSU2bV HcfHmyAAHbfQpY8w+FVFwBtojVvHlAHu4+bD94hE/O5OMY20jEjY9/CNuQeLLSJBs1Ri kPvx6YLlwgQkJkx7bUVkR148s4+sE3Y7xtqenU4/VErMBkVSkNIN1zSK07feOMbtNIqF thDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Hy340tu5; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si7757005pgr.184.2019.08.20.12.53.29; Tue, 20 Aug 2019 12:53:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Hy340tu5; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730088AbfHTTx2 (ORCPT + 1 other); Tue, 20 Aug 2019 15:53:28 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:60924 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729639AbfHTTx2 (ORCPT ); Tue, 20 Aug 2019 15:53:28 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrIFA074400; Tue, 20 Aug 2019 14:53:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1566330798; bh=SoaUx4hsoNivA4WY8SmxX4gYKChR8ekucNpgYs7oGOU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Hy340tu5ou14SvE18E+vON9oaCf/IDpFPZzgdYuv7qdLP8bCheSZGeEOWh5Mx15wA FzFQpTp77swGYDq0yGyRDxecTjRYFKu3zz1mN8/5R9SrkjQOH6frCwkti7CdhM605W HOoIx3CN7imoY7Xc+ubIvn7JHDuIJg8h4oItNC44= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x7KJrIXR026918 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 20 Aug 2019 14:53:18 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 20 Aug 2019 14:53:18 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 20 Aug 2019 14:53:18 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrIAB098256; Tue, 20 Aug 2019 14:53:18 -0500 From: Dan Murphy To: , , , , , , CC: , , Dan Murphy Subject: [PATCH v3 4/5] dt: lm3532: Add property for full scale current. Date: Tue, 20 Aug 2019 14:53:06 -0500 Message-ID: <20190820195307.27590-4-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20190820195307.27590-1-dmurphy@ti.com> References: <20190820195307.27590-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add a property for each control bank to configure the full scale current setting for the device. Acked-by: Pavel Machek Signed-off-by: Dan Murphy --- v3 - No changes - https://lore.kernel.org/patchwork/patch/1114540/ Documentation/devicetree/bindings/leds/leds-lm3532.txt | 4 ++++ 1 file changed, 4 insertions(+) -- 2.22.0.214.g8dca754b1e diff --git a/Documentation/devicetree/bindings/leds/leds-lm3532.txt b/Documentation/devicetree/bindings/leds/leds-lm3532.txt index c087f85ddddc..53793213dd52 100644 --- a/Documentation/devicetree/bindings/leds/leds-lm3532.txt +++ b/Documentation/devicetree/bindings/leds/leds-lm3532.txt @@ -62,6 +62,9 @@ Optional LED child properties: - label : see Documentation/devicetree/bindings/leds/common.txt - linux,default-trigger : see Documentation/devicetree/bindings/leds/common.txt + - led-max-microamp : Defines the full scale current value for each control + bank. The range is from 5000uA-29800uA in increments + of 800uA. Example: led-controller@38 { @@ -85,6 +88,7 @@ led-controller@38 { reg = <0>; led-sources = <2>; ti,led-mode = <1>; + led-max-microamp = <21800>; label = ":backlight"; linux,default-trigger = "backlight"; }; From patchwork Tue Aug 20 19:53:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 171834 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4887018ily; Tue, 20 Aug 2019 12:53:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxE41TKS3O9n+7ayr5PioXPdCpIdbEAf3MMdaNns5NquAz3x5XLwoLGMvLoKcAVERBpDf+P X-Received: by 2002:a05:6a00:cd:: with SMTP id e13mr32904436pfj.202.1566330824984; Tue, 20 Aug 2019 12:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566330824; cv=none; d=google.com; s=arc-20160816; b=tFKHYPYOy6RRDvIuQzgUiJeT/oXRxPhVpUZAG0fZG7SntdM6jFDOMpRwvSNk5/OSeU YSYsixgUGgcvVVK3wxUAXXUfCb81LTeZW7B7halRM+QnFQdDfv5sDq5gjU1BIwI7HEst hqbbYfkY23gIKztOXtoz8BxJkDFcmO4O5cJUiT+CFP1tAzTKnxBZ6GcSs2RnhpKRT/h7 NZxsBztHkhJy8vlQUTQoDtRmHXvogbV7fuEGwaNTlNzKLvPIPydKcMUB1rMFAsMuXhG2 uewCMcqEcL1+B70kR4skjt1w3W3hMmPZjpsTS5GRdCQweuvuIE14tRloURgKVHWaw07N 0qqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oH8rA+GYC1E9/xLKHbjhVcCj8L8mfXzFysEW/hW1eI0=; b=LRforzFeJOfd/fEE2/vJ/KFWv/CpovgFnSHHMcSFkVgbT9YhiNxTwdOW4onr0bxGDN UE5oW/1oDiE4c4C68F2UggsqSDrQnVx4IrUUHWRLe0rwfcf8ZDxGZrGutdhfWcCqqXCF I5FfJpvHhqo9EMeWaH09jZ3G0henBuZY2lkz7C0iy9kTmA8zsczZ8fy5z3E/IDWn4SMz lTKaMZsJdfdkSdAAaN8UykVHPV1ruzn3g1WdBmEwYWJpl0Ntk5HdxSoyRKb6BFrW1L+r OE8dihLCHreBS4nfUnAXUe6ncN6GxZezmSTL1ZdCWVF4HCetob69i/1Cgz6o2HT/ak0o 2xKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=tOaiQTuJ; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si12759359pgd.554.2019.08.20.12.53.44; Tue, 20 Aug 2019 12:53:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=tOaiQTuJ; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730825AbfHTTxo (ORCPT + 1 other); Tue, 20 Aug 2019 15:53:44 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:44754 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729950AbfHTTx2 (ORCPT ); Tue, 20 Aug 2019 15:53:28 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrJbC074736; Tue, 20 Aug 2019 14:53:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1566330799; bh=oH8rA+GYC1E9/xLKHbjhVcCj8L8mfXzFysEW/hW1eI0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tOaiQTuJK7qdWCykBw0JATVt68L+WHITg5DIClTAwTCS4ir3zWkliUGY2HT1c2v4p vCowxpSetk6j7TRqkEAE1g6QWRoghXU2Dn0P4raYQx/sHktW/YbvVuzLCCyGyJyFZ3 D06+ttDrb4ecteDoTLaqlnpkm09l7IxWDTAIfWJ8= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x7KJrJNS116203 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 20 Aug 2019 14:53:19 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 20 Aug 2019 14:53:18 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 20 Aug 2019 14:53:18 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x7KJrIqu008196; Tue, 20 Aug 2019 14:53:18 -0500 From: Dan Murphy To: , , , , , , CC: , , Dan Murphy Subject: [PATCH v3 5/5] leds: lm3532: Add full scale current configuration Date: Tue, 20 Aug 2019 14:53:07 -0500 Message-ID: <20190820195307.27590-5-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20190820195307.27590-1-dmurphy@ti.com> References: <20190820195307.27590-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Allow the full scale current to be configured at init. Valid rangles are 5mA->29.8mA. Signed-off-by: Dan Murphy --- v3 - Fixed variable movement change and updated the fs current register calculation - https://lore.kernel.org/patchwork/patch/1114544/ drivers/leds/leds-lm3532.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index 5e33ae4561f2..ba352d76a8fb 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -89,6 +89,10 @@ #define LM3532_NUM_AVG_VALS 8 #define LM3532_NUM_IMP_VALS 32 +#define LM3532_FS_CURR_MIN 5000 +#define LM3532_FS_CURR_MAX 29800 +#define LM3532_FS_CURR_STEP 800 + /* * struct lm3532_als_data * @config - value of ALS configuration register @@ -121,6 +125,7 @@ struct lm3532_als_data { * @mode - Mode of the LED string * @ctrl_brt_pointer - Zone target register that controls the sink * @num_leds - Number of LED strings are supported in this array + * @full_scale_current - The full-scale current setting for the current sink. * @led_strings - The LED strings supported in this array * @label - LED label */ @@ -132,6 +137,7 @@ struct lm3532_led { int mode; int ctrl_brt_pointer; int num_leds; + int full_scale_current; u32 led_strings[LM3532_MAX_CONTROL_BANKS]; char label[LED_MAX_NAME_SIZE]; }; @@ -363,6 +369,8 @@ static int lm3532_init_registers(struct lm3532_led *led) unsigned int output_cfg_mask = 0; unsigned int brightness_config_reg; unsigned int brightness_config_val; + int fs_current_reg; + int fs_current_val; int ret, i; if (drvdata->enable_gpio) @@ -385,6 +393,17 @@ static int lm3532_init_registers(struct lm3532_led *led) if (ret) return ret; + if (led->full_scale_current) { + fs_current_reg = LM3532_REG_CTRL_A_FS_CURR + led->control_bank * 2; + fs_current_val = (led->full_scale_current - LM3532_FS_CURR_MIN) / + LM3532_FS_CURR_STEP; + + ret = regmap_write(drvdata->regmap, fs_current_reg, + fs_current_val); + if (ret) + return ret; + } + for (i = 0; i < led->num_leds; i++) { output_cfg_shift = led->led_strings[i] * 2; output_cfg_val |= (led->control_bank << output_cfg_shift); @@ -560,6 +579,12 @@ static int lm3532_parse_node(struct lm3532_data *priv) goto child_out; } + ret = fwnode_property_read_u32(child, "led-max-microamp", + &led->full_scale_current); + + if (led->full_scale_current > LM3532_FS_CURR_MAX) + led->full_scale_current = LM3532_FS_CURR_MAX; + if (led->mode == LM3532_BL_MODE_ALS) { led->mode = LM3532_ALS_CTRL; ret = lm3532_parse_als(priv);