From patchwork Thu Oct 11 16:51:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 148658 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2358571lji; Thu, 11 Oct 2018 09:51:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/pRayVHdHUh+8tV9SAmN7HiqMKTWA0Dr1UPUO8308zTvWtk6sjpjfDnM1XL7JFbfl9FEY X-Received: by 2002:a17:902:6a4:: with SMTP id 33-v6mr2237445plh.11.1539276701608; Thu, 11 Oct 2018 09:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539276701; cv=none; d=google.com; s=arc-20160816; b=o6ligkYW0jXOm85sDU0/IDxWgMnXvAI2VXWCgmSpmz2EAdbiqGnoG0+il7au/2bp0F qh1Hw0pZ6saGTvjeZsxLkAXZzOIo/38WR6wleXDAzt8tMsvyYeZ64xpPTmfLNUBgFpP2 b8aLJx4i9C0xBxB5hZKQqtJOskh6uo/iB3cpqknm3PjF1bVIEIggAdEq8vTHK8pPteo+ Lvcc8RRMyg6gtFXjD7ARx6E8X3nFpaL3xRHD+0eK5aFDYZ4hApsVEb4jxWqNlTovI6uY 8z28Fpk7ZOvwTyRa7lT3WU65Alg4Q7uXjAeWBjnSMqb6rtBqP4dxXDx5TFNsw8Pt9sKl M2BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Qsk91Rabv/MYjOIz9wKyIa0ngOo+H7GslCCP+ybv22s=; b=NmCCxha/isZsQ9eEG7OLcBqxcRMfxBbG9z5+eLo20gOoxVLpd+CY0pBILSS8KcMK0a ESm3fGEkg4nsd3yLWuq05uU7Zll4h3Ztm7d7km9RLUioyak3g2m5CaKzeBQMXhZeZcMG rwNInDyosdlbZ2IRLJ0FSf+x0qg7Fo7KTb1zG1TvIenjYU2X6lwQZcVUz0ySBNCBR1DO 1rYmi72AGMu4uk2BUZ8Mmsg8KgquTDCkiY4HBTonGEya+bi6KLDbHXoEVqh7pSjP0UXf afj6dWd+AXuXy/1RbW6fae7VLN1Wd8hdmhCd8GM0CS4klx53Agm2zhBuAnnSK2LdOBH/ Lxnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=e4bpul6z; 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 z13-v6si25343867pgc.119.2018.10.11.09.51.41; Thu, 11 Oct 2018 09:51:41 -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=e4bpul6z; 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 S1730826AbeJLATm (ORCPT + 1 other); Thu, 11 Oct 2018 20:19:42 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:48456 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730551AbeJLATl (ORCPT ); Thu, 11 Oct 2018 20:19:41 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w9BGpR5C031420; Thu, 11 Oct 2018 11:51:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1539276687; bh=Qsk91Rabv/MYjOIz9wKyIa0ngOo+H7GslCCP+ybv22s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=e4bpul6zYQrqljKSGzqsPg0X6y3LYIKksmxYDkxjGod59f9e8U8u4hODYLsgQoiRY DZSgPzaGH2akFBIj52OYB136mCuLeJ9C6Ov8TNsLGE5PAgzyOe8g1q36OM48jedDHP eOkcI/zaOXkQYuVnoaYTKLYviV4NyfEF0uK0omdo= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpRBj026737; Thu, 11 Oct 2018 11:51:27 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 11 Oct 2018 11:51:27 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Thu, 11 Oct 2018 11:51:27 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpRTR027679; Thu, 11 Oct 2018 11:51:27 -0500 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.172.124]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w9BGpQx20795; Thu, 11 Oct 2018 11:51:26 -0500 (CDT) From: Dan Murphy To: , , CC: , , , , , Milo Kim , Sebastian Reichel Subject: [PATCH v3 1/9] leds: add TI LMU backlight driver Date: Thu, 11 Oct 2018 11:51:15 -0500 Message-ID: <20181011165123.32198-2-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20181011165123.32198-1-dmurphy@ti.com> References: <20181011165123.32198-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 From: Pavel Machek This adds backlight support for the following TI LMU chips: LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697. It controls LEDs on Droid 4 smartphone, including keyboard and screen backlights. Signed-off-by: Milo Kim [add LED subsystem support for keyboard backlight and rework DT binding according to Rob Herrings feedback] Signed-off-by: Sebastian Reichel [remove backlight subsystem support for now] Signed-off-by: Pavel Machek --- drivers/leds/Kconfig | 8 ++ drivers/leds/Makefile | 1 + drivers/leds/ti-lmu-led-common.c | 138 ++++++++++++++++++++++++++++++ include/linux/ti-lmu-led-common.h | 59 +++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 drivers/leds/ti-lmu-led-common.c create mode 100644 include/linux/ti-lmu-led-common.h -- 2.19.0 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 44097a3e0fcc..dc717b30d9d3 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -756,6 +756,14 @@ config LEDS_NIC78BX To compile this driver as a module, choose M here: the module will be called leds-nic78bx. +config LEDS_TI_LMU_COMMON + tristate "LED driver for TI LMU" + depends on REGMAP + help + Say Y to enable the LED driver for TI LMU devices. + This supports common features between the TI LM3532, LM3631, LM3632, + LM3633, LM3695 and LM3697. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 420b5d2cfa62..e09bb27bc7ea 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -78,6 +78,7 @@ obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o +obj-$(CONFIG_LEDS_TI_LMU_COMMON) += ti-lmu-led-common.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o diff --git a/drivers/leds/ti-lmu-led-common.c b/drivers/leds/ti-lmu-led-common.c new file mode 100644 index 000000000000..a4435bd1d248 --- /dev/null +++ b/drivers/leds/ti-lmu-led-common.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2015 Texas Instruments + * Copyright 2018 Sebastian Reichel + * Copyright 2018 Pavel Machek + * + * TI LMU Led driver, based on previous work from + * Milo Kim + */ + +#include +#include +#include +#include +#include + +#include + +const static int ramp_table[16] = { 2, 262, 524, 1049, 2090, 4194, 8389, + 16780, 33550, 41940, 50330, 58720, + 67110, 83880, 100660, 117440}; + +static int ti_lmu_common_update_brightness_register(struct ti_lmu_bank *lmu_bank, + int brightness) +{ + struct regmap *regmap = lmu_bank->regmap; + u8 reg, val; + int ret; + + /* + * Brightness register update + * + * 11 bit dimming: update LSB bits and write MSB byte. + * MSB brightness should be shifted. + * 8 bit dimming: write MSB byte. + */ + if (lmu_bank->max_brightness == MAX_BRIGHTNESS_11BIT) { + reg = lmu_bank->lsb_brightness_reg; + ret = regmap_update_bits(regmap, reg, + LMU_11BIT_LSB_MASK, + brightness); + if (ret) + return ret; + + val = brightness >> LMU_11BIT_MSB_SHIFT; + } else { + val = brightness; + } + + reg = lmu_bank->msb_brightness_reg; + + return regmap_write(regmap, reg, val); +} + +int ti_lmu_common_set_brightness(struct ti_lmu_bank *lmu_bank, + int brightness) +{ + lmu_bank->current_brightness = brightness; + + return ti_lmu_common_update_brightness_register(lmu_bank, brightness); +} +EXPORT_SYMBOL(ti_lmu_common_set_brightness); + +static int ti_lmu_common_convert_ramp_to_index(unsigned int msec) +{ + int size = ARRAY_SIZE(ramp_table); + int i; + + if (msec <= ramp_table[0]) + return 0; + + if (msec > ramp_table[size - 1]) + return size - 1; + + for (i = 1; i < size; i++) { + if (msec == ramp_table[i]) + return i; + + /* Find an approximate index by looking up the table */ + if (msec > ramp_table[i - 1] && msec < ramp_table[i]) { + if (msec - ramp_table[i - 1] < ramp_table[i] - msec) + return i - 1; + else + return i; + } + } + + return -EINVAL; +} + +int ti_lmu_common_set_ramp(struct ti_lmu_bank *lmu_bank) +{ + struct regmap *regmap = lmu_bank->regmap; + u8 ramp, ramp_up, ramp_down; + + if (lmu_bank->ramp_up_msec == 0 && lmu_bank->ramp_down_msec == 0) { + ramp_up = 0; + ramp_down = 0; + } else { + ramp_up = ti_lmu_common_convert_ramp_to_index(lmu_bank->ramp_up_msec); + ramp_down = ti_lmu_common_convert_ramp_to_index(lmu_bank->ramp_down_msec); + } + + if (ramp_up < 0 || ramp_down < 0) + return -EINVAL; + + ramp = (ramp_up << 4) | ramp_down; + + return regmap_write(regmap, lmu_bank->runtime_ramp_reg, ramp); + +} +EXPORT_SYMBOL(ti_lmu_common_set_ramp); + +int ti_lmu_common_get_ramp_params(struct device *dev, + struct fwnode_handle *child, + struct ti_lmu_bank *lmu_data) +{ + int ret; + + ret = fwnode_property_read_u32(child, "ramp-up-ms", + &lmu_data->ramp_up_msec); + if (ret) + dev_warn(dev, "ramp-up-ms property missing\n"); + + + ret = fwnode_property_read_u32(child, "ramp-down-ms", + &lmu_data->ramp_down_msec); + if (ret) + dev_warn(dev, "ramp-down-ms property missing\n"); + + return 0; +} +EXPORT_SYMBOL(ti_lmu_common_get_ramp_params); + +MODULE_DESCRIPTION("TI LMU LED Driver"); +MODULE_AUTHOR("Sebastian Reichel"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:ti-lmu-led"); diff --git a/include/linux/ti-lmu-led-common.h b/include/linux/ti-lmu-led-common.h new file mode 100644 index 000000000000..b0fe08f05be2 --- /dev/null +++ b/include/linux/ti-lmu-led-common.h @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +// TI LMU Common Core +// Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + +#ifndef _TI_LMU_COMMON_H_ +#define _TI_LMU_COMMON_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LMU_DUAL_CHANNEL_USED (BIT(0) | BIT(1)) +#define LMU_11BIT_LSB_MASK (BIT(0) | BIT(1) | BIT(2)) +#define LMU_11BIT_MSB_SHIFT 3 + +#define MAX_BRIGHTNESS_8BIT 255 +#define MAX_BRIGHTNESS_11BIT 2047 + +#define NUM_DUAL_CHANNEL 2 + +struct ti_lmu_bank { + struct regmap *regmap; + + int bank_id; + int fault_monitor_used; + + u8 enable_reg; + unsigned long enable_usec; + + int current_brightness; + u32 default_brightness; + int max_brightness; + + u8 lsb_brightness_reg; + u8 msb_brightness_reg; + + u8 runtime_ramp_reg; + u32 ramp_up_msec; + u32 ramp_down_msec; +}; + + +int ti_lmu_common_set_brightness(struct ti_lmu_bank *lmu_bank, + int brightness); + +int ti_lmu_common_set_ramp(struct ti_lmu_bank *lmu_bank); + +int ti_lmu_common_get_ramp_params(struct device *dev, + struct fwnode_handle *child, + struct ti_lmu_bank *lmu_data); + +#endif /* _TI_LMU_COMMON_H_ */ From patchwork Thu Oct 11 16:51:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 148660 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2358894lji; Thu, 11 Oct 2018 09:51:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Fif2yASrXs7uW574usqNx5eWMxc+1Ec0QFNV7LFVlrOETE12W8yYfC3QQWFTlUKd3g6t9 X-Received: by 2002:a63:e04d:: with SMTP id n13-v6mr2145352pgj.426.1539276718724; Thu, 11 Oct 2018 09:51:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539276718; cv=none; d=google.com; s=arc-20160816; b=0WX6/qxicluZi2jvSEHO71jGkdHY6zSkOaQtrjIpBHInS6TaS5FkC88rBddfVMDY0H kA3w8Unf/q4UpkH3k16Pf2VWeLcdD3CmGtyZ2anx57GlFegHicjkzJN9OG0Jk9Uu+0d3 Ntg67Jg4bGYD+zvRL8+KiLpI1Xg4axVKbi1sTggeQ7iJpsvog5UXTYIzaW2i2FBzNV1Z 69QvcKlaFYTZqQnEmXZWn85mQMO0mtXnYBjLX1WAAEYjjSHuQVYtjqu77B4+/6580WPb qe86gmqqSE7RDP+B42oMrQT3Lhk9UXwIUFwOCkVgg2ApQ7ghXggr//hfQOpFYDNtfyiK W4KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Di5TTVK8nMsFF6vs8+PC410nXwy/9n2E3w86bq7ehcw=; b=olWguD2Kx6K83selQKjlsRIel5OssH4LVnmWzc/CPnJxnrc6cGECbEuDWAF7XP5bcj h+s1C9tcnJ0DqCTq49wAZJMZVfWX0LQiCYS5l+9Fo+qWlJNexTi4/jSw/Hw8/xBQM9w3 H8WlMHOsfSxNBLzSbxGZx9AD0cRbgBjdcSudzc/7yP5af3yTazgvaj5vyUXi/Lj9WujY TOLwQmgPXRCkW7ggNVbLRhh7gYFt01VjD0Dg16sXTMIFxsr3IRU9f6bOr+fznXwtqT0P 6ifqqzjncW2zvS6uOdmwZx1MDaN4Kvl2Uz+HcspSGLKt7XOQD7QKK9w/VUPKvY55oihh 4vpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GqAJzLt5; 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 e39-v6si29420595plg.188.2018.10.11.09.51.58; Thu, 11 Oct 2018 09:51:58 -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=GqAJzLt5; 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 S1730900AbeJLAUA (ORCPT + 1 other); Thu, 11 Oct 2018 20:20:00 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:48458 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730718AbeJLATl (ORCPT ); Thu, 11 Oct 2018 20:19:41 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w9BGpVHI031427; Thu, 11 Oct 2018 11:51:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1539276691; bh=Di5TTVK8nMsFF6vs8+PC410nXwy/9n2E3w86bq7ehcw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=GqAJzLt5enXvn9zWp1quQwTGd5Cjn5kWwrMtiMA8gg9NAabaBmwFL4iwCd1mTn+/3 oZikwoxYj9LUrzLgTtMMlYo1I2JROaBU6OH4HiU1cOMc3NnOA0gCdKgZ++F+rDlqj3 7iO83RvwLXDzQ2qj74H1lTRQHGA6o/8fvU2VzlUU= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpV7o026853; Thu, 11 Oct 2018 11:51:31 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 11 Oct 2018 11:51:31 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Thu, 11 Oct 2018 11:51:31 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpUAr027742; Thu, 11 Oct 2018 11:51:30 -0500 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.172.124]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w9BGpUx20823; Thu, 11 Oct 2018 11:51:30 -0500 (CDT) From: Dan Murphy To: , , CC: , , , , , Dan Murphy Subject: [PATCH v3 8/9] dt-bindings: leds: Add support for the LM3633 Date: Thu, 11 Oct 2018 11:51:22 -0500 Message-ID: <20181011165123.32198-9-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20181011165123.32198-1-dmurphy@ti.com> References: <20181011165123.32198-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 support for the TI LM3633 LED driver. This device has 9 control banks 3 high voltage LED channels and 6 low voltage LED channels. Data sheet: http://www.ti.com/lit/ds/symlink/lm3633.pdf Signed-off-by: Dan Murphy --- .../devicetree/bindings/leds/leds-lm3633.txt | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt -- 2.19.0 diff --git a/Documentation/devicetree/bindings/leds/leds-lm3633.txt b/Documentation/devicetree/bindings/leds/leds-lm3633.txt new file mode 100644 index 000000000000..d791b891ea6e --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-lm3633.txt @@ -0,0 +1,102 @@ +* Texas Instruments - LM3633 Lighting Power Solution for Smartphone Handsets + +The LM3633 is a complete power source for +backlight, keypad, and indicator LEDs in smartphone +handsets. + +This device is suitable for display and keypad Lighting + +Required properties: + - compatible: + "ti,lm3633" + - reg : I2C slave address + - #address-cells : 1 + - #size-cells : 0 + +Optional properties: + - enable-gpios : GPIO pin to enable/disable the device + - vled-supply : LED supply + +Required child properties: + - reg : 0 - HVLED is Controlled by bank A + 1 - HVLED is Controlled by bank B + 2,3,4 - LVLED1, 2 and 3 are Controlled by bank C, D and E + 5,6,7 - LVLED4, 5 and 6 are Controlled by bank F, G and H + - led-sources : Indicates which LED string is associated to which + control bank. + 0 - LED is not active in this control bank + 1 - LED string is controlled by this control bank + +Optional child properties: + - runtime-ramp-up-msec: Current ramping from one brightness level to + the a higher brightness level. + Range from 2048 us - 117.44 s + - runtime-ramp-down-msec: Current ramping from one brightness level to + the a lower brightness level. + Range from 2048 us - 117.44 s + - label : see Documentation/devicetree/bindings/leds/common.txt + - linux,default-trigger : + see Documentation/devicetree/bindings/leds/common.txt + +Example: +Control bank C output to 3 LVLEDs and Control F, G and H have independent +controls of the LVLEDs. + +led-controller@36 { + compatible = "ti,lm3633"; + reg = <0x36>; + #address-cells = <1>; + #size-cells = <0>; + + enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; + led@0 { + reg = <0>; + led-sources = < 1 0 1 >; + label = "white:backlight"; + ramp-up-ms = <100000>; + ramp-down-ms = <1000>; + linux,default-trigger = "backlight"; + }; + + led@1 { + reg = <1>; + led-sources = < 0 1 0 >; + label = "white:light"; + ramp-up-ms = <100000>; + ramp-down-ms = <1000>; + }; + + led@2 { + reg = <2>; + led-sources = <1>; + ramp-up-ms = <100000>; + ramp-down-ms = <1000>; + label = "white:indicator1"; + }; + + led@5 { + reg = <5>; + led-sources = <1>; + ramp-up-ms = <100000>; + ramp-down-ms = <1000>; + label = "red:light"; + }; + + led@6 { + reg = <6>; + led-sources = <1>; + ramp-up-ms = <41940>; + ramp-down-ms = <1000>; + label = "green:light"; + }; + + led@7 { + reg = <7>; + led-sources = <1>; + ramp-up-ms = <100000>; + ramp-down-ms = <1000>; + label = "blue:light"; + }; +}; +For more product information please see the link below: +http://www.ti.com/lit/ds/symlink/lm3633.pdf From patchwork Thu Oct 11 16:51:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 148659 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2358767lji; Thu, 11 Oct 2018 09:51:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV62/4SMwkfMFVauuhYDfnIGCoPGkqTiRt0SmeXfLuXklwJ4UZlm3SW2+dFgHseRNZvEKO5O3 X-Received: by 2002:a62:5441:: with SMTP id i62-v6mr2332400pfb.155.1539276712235; Thu, 11 Oct 2018 09:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539276712; cv=none; d=google.com; s=arc-20160816; b=noq4h/l3Tuh3LzFgJ6PoLVoOWdS3M8BfQEuotOgTpd1yxaKLfLjXQVaZ0+2CUtqcNL Q4ln4yhWeqpnCdkCDWaxWL+IpoyPcmyurPGo/6fBdXqyPklZpPsSSHI5q6Ic8yoWEZfP Y1MpjU11kX649qXqjFe7ri581cjkSI+hlTP1SZFh+SSwggTRT8HYDAKx5AJzBM2qBXcR WEWoAfOW8iYEvSf3MrMZGmw02d8mpqOKeA/1jmpm3Azv4tdDbbyIdjG6UwpItuKPQRrN asSFzA0RCXHD1oyysvZOHuIxNmMH2JsV6/kBd3/ObDFXmuNQVJ+I6oA2RqFBfuXL+zdT l98A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=yiHRg4Y5HJRHXP1rqwJbTt9p8seCtUnJxInDTKGc2KI=; b=XCqBdXBvck7bPgN3dao0tIv/zEjJCxfbAYdsah3aMvaNqV9YTr7XCA3VbTZAr4lrsS SgH4TcUARt9OF0cFJNWojAL0zHAAHC6OBhsk55JLQ9RpIB7/zR/sLY675RTI+TyDGZfN TPCsgLslkeEjFQVZtZe+zWm3p4cetRtrSFmVsJ9W19AmtZHLy0lffQUMCSo3c2PjUCKI Do3auTMu1Jg9u+0Hk3LfMB2kx5m2Ulcai0yiVIEus29GDhzvclxFoR/t86stbt5PKpdJ /GAXAVsSNHYxZqpgvmdfhKOC0aAr/1nUgbN1Y5SWwgNEYcUpVgZCa98Ih8a/F4/CpBUC T7uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jKDcYtw7; 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 q143-v6si23478110pgq.483.2018.10.11.09.51.52; Thu, 11 Oct 2018 09:51:52 -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=jKDcYtw7; 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 S1730792AbeJLATl (ORCPT + 1 other); Thu, 11 Oct 2018 20:19:41 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:48454 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730679AbeJLATl (ORCPT ); Thu, 11 Oct 2018 20:19:41 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w9BGpVGY031431; Thu, 11 Oct 2018 11:51:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1539276691; bh=yiHRg4Y5HJRHXP1rqwJbTt9p8seCtUnJxInDTKGc2KI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jKDcYtw79NckvA5ZDmR3LICGmN0Jx4XYtf8bN3U1n2R3ZolEeeeVWK+7GZJ9WDSgx hDGvhHdA1HaFiMBIKmk5btg51JsFOwimgyYiUTbdDoizvE6hR6Dqy6dKNBVqIdZIwY tPw73Utyn6f0rE5Gfq2gohXf2NQvQIyO0UIweJKg= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpV6f030245; Thu, 11 Oct 2018 11:51:31 -0500 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 11 Oct 2018 11:51:31 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Thu, 11 Oct 2018 11:51:31 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9BGpVdG029936; Thu, 11 Oct 2018 11:51:31 -0500 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.172.124]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w9BGpVx20827; Thu, 11 Oct 2018 11:51:31 -0500 (CDT) From: Dan Murphy To: , , CC: , , , , , Dan Murphy Subject: [PATCH v3 9/9] leds: lm3633: Introduce the lm3633 driver Date: Thu, 11 Oct 2018 11:51:23 -0500 Message-ID: <20181011165123.32198-10-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20181011165123.32198-1-dmurphy@ti.com> References: <20181011165123.32198-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 Introduce the LED LM3633 driver. This LED driver has 9 total LED outputs with runtime internal ramp configurations. Data sheet: http://www.ti.com/lit/ds/symlink/lm3633.pdf Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-lm3633.c | 556 +++++++++++++++++++++++++++++++++++++ 3 files changed, 565 insertions(+) create mode 100644 drivers/leds/leds-lm3633.c -- 2.19.0 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 7d9a98044be4..1f9093e5d902 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -763,8 +763,16 @@ config LEDS_LM3697 Say Y to enable the LED driver for TI LMU devices. This supports the LED device LM3697. +config LEDS_LM3633 + tristate "LED driver for LM3633" + depends on LEDS_TI_LMU_COMMON + help + Say Y to enable the LED driver for TI LMU devices. + This supports the LED device LM3633. + config LEDS_TI_LMU_COMMON tristate "LED driver for TI LMU" + depends on REGMAP help Say Y to enable the LED driver for TI LMU devices. This supports common features between the TI LM3532, LM3631, LM3632, diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 6fbce7cfc41c..6ec006892fc0 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -79,6 +79,7 @@ obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o +obj-$(CONFIG_LEDS_LM3633) += leds-lm3633.o obj-$(CONFIG_LEDS_TI_LMU_COMMON) += ti-lmu-led-common.o # LED SPI Drivers diff --git a/drivers/leds/leds-lm3633.c b/drivers/leds/leds-lm3633.c new file mode 100644 index 000000000000..de8eb7b83d20 --- /dev/null +++ b/drivers/leds/leds-lm3633.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +// TI LM3633 LED chip family driver +// Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + +#include +#include +#include +#include +#include + +#define LM3633_REV 0x0 +#define LM3633_RESET 0x1 +#define LM3633_HVLED_OUTPUT_CONFIG 0x10 +#define LM3633_LVLED_OUTPUT_CONFIG 0x11 + +#define LM3633_CTRL_A_RAMP 0x12 +#define LM3633_CTRL_B_RAMP 0x13 +#define LM3633_CTRL_C_RAMP 0x14 +#define LM3633_CTRL_D_RAMP 0x15 +#define LM3633_CTRL_E_RAMP 0x16 +#define LM3633_CTRL_F_RAMP 0x17 +#define LM3633_CTRL_G_RAMP 0x18 +#define LM3633_CTRL_H_RAMP 0x19 + +#define LM3633_CTRL_A_B_RT_RAMP 0x1a +#define LM3633_CTRL_A_B_RAMP_CFG 0x1b +#define LM3633_CTRL_C_E_RT_RAMP 0x1c +#define LM3633_CTRL_F_H_RT_RAMP 0x1d + +#define LM3633_CTRL_A_B_BRT_CFG 0x16 +#define LM3633_CTRL_A_FS_CURR_CFG 0x17 +#define LM3633_CTRL_B_FS_CURR_CFG 0x18 +#define LM3633_PWM_CFG 0x1c + +#define LM3633_CTRL_ENABLE 0x2b + +#define LM3633_CTRL_A_BRT_LSB 0x40 +#define LM3633_CTRL_A_BRT_MSB 0x41 +#define LM3633_CTRL_B_BRT_LSB 0x42 +#define LM3633_CTRL_B_BRT_MSB 0x43 +#define LM3633_CTRL_C_BRT 0x44 +#define LM3633_CTRL_D_BRT 0x45 +#define LM3633_CTRL_E_BRT 0x46 +#define LM3633_CTRL_F_BRT 0x47 +#define LM3633_CTRL_G_BRT 0x48 +#define LM3633_CTRL_H_BRT 0x49 + +#define LM3633_SW_RESET BIT(0) + +#define LM3633_CTRL_A_EN BIT(0) +#define LM3633_CTRL_B_EN BIT(1) +#define LM3633_CTRL_C_EN BIT(2) +#define LM3633_CTRL_D_EN BIT(3) +#define LM3633_CTRL_E_EN BIT(4) +#define LM3633_CTRL_F_EN BIT(5) +#define LM3633_CTRL_G_EN BIT(6) +#define LM3633_CTRL_H_EN BIT(7) + +#define LM3633_MAX_HVLED_STRINGS 3 +#define LM3633_MAX_LVLED_STRINGS 6 + +#define LM3633_CONTROL_A 0 +#define LM3633_CONTROL_B 1 +#define LM3633_CONTROL_C 2 +#define LM3633_CONTROL_D 3 +#define LM3633_CONTROL_E 4 +#define LM3633_CONTROL_F 5 +#define LM3633_CONTROL_G 6 +#define LM3633_CONTROL_H 7 + +#define LM3633_MAX_CONTROL_BANKS 8 + +#define LM3633_LED_ASSIGNMENT 1 + +#define LM3633_CTRL_F_EN_MASK 0x07 +#define LM3633_CTRL_EN_OFFSET 2 + +/** + * struct lm3633_led - + * @hvled_strings: Array of high voltage LED strings associated to control bank + * @lvled_strings: Array of low voltage LED strings associated to a control bank + * @label: LED label + * @led_dev: LED class device + * @priv: Pointer to the device struct + * @lmu_data: Register and setting values for common code + * @control_bank: Control bank the LED is associated to + */ +struct lm3633_led { + u32 hvled_strings[LM3633_MAX_HVLED_STRINGS]; + u32 lvled_strings[LM3633_MAX_LVLED_STRINGS]; + char label[LED_MAX_NAME_SIZE]; + struct led_classdev led_dev; + struct lm3633 *priv; + struct ti_lmu_bank lmu_data; + int control_bank; +}; + +/** + * struct lm3633 - + * @enable_gpio - Hardware enable gpio + * @regulator - LED supply regulator pointer + * @client - Pointer to the I2C client + * @regmap - Devices register map + * @dev - Pointer to the devices device struct + * @lock - Lock for reading/writing the device + * @leds - Array of LED strings + */ +struct lm3633 { + struct gpio_desc *enable_gpio; + struct regulator *regulator; + struct i2c_client *client; + struct regmap *regmap; + struct device *dev; + struct mutex lock; + struct lm3633_led leds[]; +}; + +static const struct reg_default lm3633_reg_defs[] = { + {LM3633_HVLED_OUTPUT_CONFIG, 0x6}, + {LM3633_LVLED_OUTPUT_CONFIG, 0x36}, + {LM3633_CTRL_A_RAMP, 0x0}, + {LM3633_CTRL_B_RAMP, 0x0}, + {LM3633_CTRL_A_B_RT_RAMP, 0x0}, + {LM3633_CTRL_A_B_RAMP_CFG, 0x0}, + {LM3633_CTRL_A_B_BRT_CFG, 0x0}, + {LM3633_CTRL_A_FS_CURR_CFG, 0x13}, + {LM3633_CTRL_B_FS_CURR_CFG, 0x13}, + {LM3633_PWM_CFG, 0xc}, + {LM3633_CTRL_A_BRT_LSB, 0x0}, + {LM3633_CTRL_A_BRT_MSB, 0x0}, + {LM3633_CTRL_B_BRT_LSB, 0x0}, + {LM3633_CTRL_B_BRT_MSB, 0x0}, + {LM3633_CTRL_ENABLE, 0x0}, +}; + +static const struct regmap_config lm3633_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = LM3633_CTRL_H_BRT, + .reg_defaults = lm3633_reg_defs, + .num_reg_defaults = ARRAY_SIZE(lm3633_reg_defs), + .cache_type = REGCACHE_FLAT, +}; + +static int lm3633_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brt_val) +{ + struct lm3633_led *led = container_of(led_cdev, struct lm3633_led, + led_dev); + int ctrl_en_val; + int ret; + + mutex_lock(&led->priv->lock); + + switch (led->control_bank) { + case LM3633_CONTROL_A: + ctrl_en_val = LM3633_CTRL_A_EN; + break; + case LM3633_CONTROL_B: + ctrl_en_val = LM3633_CTRL_B_EN; + break; + case LM3633_CONTROL_C: + ctrl_en_val = LM3633_CTRL_C_EN; + break; + case LM3633_CONTROL_D: + ctrl_en_val = LM3633_CTRL_D_EN; + break; + case LM3633_CONTROL_E: + ctrl_en_val = LM3633_CTRL_E_EN; + break; + case LM3633_CONTROL_F: + ctrl_en_val = LM3633_CTRL_F_EN; + break; + case LM3633_CONTROL_G: + ctrl_en_val = LM3633_CTRL_G_EN; + break; + case LM3633_CONTROL_H: + ctrl_en_val = LM3633_CTRL_H_EN; + break; + default: + dev_err(&led->priv->client->dev, "Cannot write brightness\n"); + ret = -EINVAL; + goto out; + } + + if (brt_val == LED_OFF) + ret = regmap_update_bits(led->priv->regmap, LM3633_CTRL_ENABLE, + ctrl_en_val, ~ctrl_en_val); + else + ret = regmap_update_bits(led->priv->regmap, LM3633_CTRL_ENABLE, + ctrl_en_val, ctrl_en_val); + + ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val); + if (ret) + dev_err(&led->priv->client->dev, "Cannot write brightness\n"); +out: + mutex_unlock(&led->priv->lock); + return ret; +} + +static void lm3633_set_control_bank_regs(struct lm3633_led *led) +{ + switch (led->control_bank) { + case LM3633_CONTROL_A: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_A_BRT_MSB; + led->lmu_data.lsb_brightness_reg = LM3633_CTRL_A_BRT_LSB; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_A_RAMP; + case LM3633_CONTROL_B: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_B_BRT_MSB; + led->lmu_data.lsb_brightness_reg = LM3633_CTRL_B_BRT_LSB; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_B_RAMP; + break; + case LM3633_CONTROL_C: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_C_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_C_E_RT_RAMP; + break; + case LM3633_CONTROL_D: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_D_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_C_E_RT_RAMP; + break; + case LM3633_CONTROL_E: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_E_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_C_E_RT_RAMP; + break; + case LM3633_CONTROL_F: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_F_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_F_H_RT_RAMP; + break; + case LM3633_CONTROL_G: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_G_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_F_H_RT_RAMP; + break; + case LM3633_CONTROL_H: + led->lmu_data.msb_brightness_reg = LM3633_CTRL_H_BRT; + led->lmu_data.runtime_ramp_reg = LM3633_CTRL_F_H_RT_RAMP; + break; + default: + dev_err(&led->priv->client->dev, + "Control bank is out of bounds\n"); + } +} + +static int lm3633_set_control_bank(struct lm3633 *priv) +{ + u8 control_bank_config = 0; + struct lm3633_led *led; + int ret, i; + + led = &priv->leds[0]; + if (led->control_bank == LM3633_CONTROL_A) { + lm3633_set_control_bank_regs(led); + led = &priv->leds[1]; + } + + if (led->control_bank >= LM3633_CONTROL_C) + return 0; + + lm3633_set_control_bank_regs(led); + for (i = 0; i < LM3633_MAX_HVLED_STRINGS; i++) + if (led->hvled_strings[i] == LM3633_LED_ASSIGNMENT) + control_bank_config |= 1 << i; + + ret = regmap_write(priv->regmap, LM3633_HVLED_OUTPUT_CONFIG, + control_bank_config); + if (ret) + dev_err(&priv->client->dev, "Cannot write OUTPUT config\n"); + + return ret; +} + +static int lm3633_set_lvled_control_bank(struct lm3633 *priv) +{ + u8 control_bank_config = 0; + struct lm3633_led *led; + int ret, i; + + for (i = 0; i <= LM3633_MAX_CONTROL_BANKS; i++) { + led = &priv->leds[i]; + if (led) { + if (led->control_bank < LM3633_CONTROL_C) + continue; + + if (led->lvled_strings[0]) { + if (led->control_bank == LM3633_CONTROL_C) + control_bank_config = 0x0; + else if (led->control_bank == LM3633_CONTROL_F) + control_bank_config &= LM3633_CTRL_F_EN_MASK; + else + control_bank_config |= 1 << (led->control_bank - LM3633_CTRL_EN_OFFSET); + } + } else + continue; + + lm3633_set_control_bank_regs(led); + } + + ret = regmap_write(priv->regmap, LM3633_LVLED_OUTPUT_CONFIG, + control_bank_config); + if (ret) + dev_err(&priv->client->dev, "Cannot write OUTPUT config\n"); + + return ret; +} + +static int lm3633_init(struct lm3633 *priv) +{ + struct lm3633_led *led; + int i, ret; + + if (priv->enable_gpio) { + gpiod_direction_output(priv->enable_gpio, 1); + } else { + ret = regmap_write(priv->regmap, LM3633_RESET, LM3633_SW_RESET); + if (ret) { + dev_err(&priv->client->dev, + "Cannot reset the device\n"); + goto out; + } + } + + ret = regmap_write(priv->regmap, LM3633_CTRL_ENABLE, 0x0); + if (ret) { + dev_err(&priv->client->dev, "Cannot write ctrl enable\n"); + goto out; + } + + ret = lm3633_set_control_bank(priv); + if (ret) + dev_err(&priv->client->dev, "Setting the CRTL bank failed\n"); + + ret = lm3633_set_lvled_control_bank(priv); + if (ret) + dev_err(&priv->client->dev, + "Setting the lvled CRTL bank failed\n"); + + for (i = 0; i < LM3633_MAX_CONTROL_BANKS; i++) { + led = &priv->leds[i]; + if (led->lmu_data.runtime_ramp_reg) { + ti_lmu_common_set_ramp(&led->lmu_data); + if (ret) + dev_err(&priv->client->dev, + "Setting the ramp rate failed\n"); + } + } +out: + return ret; +} + +static int lm3633_parse_hvled_sources(struct fwnode_handle *child, + struct lm3633_led *led) +{ + struct lm3633 *priv = led->priv; + int ret; + + ret = fwnode_property_read_u32_array(child, "led-sources", + led->hvled_strings, + LM3633_MAX_HVLED_STRINGS); + + if (ret) + dev_err(&priv->client->dev, "Cannot write OUTPUT config\n"); + + return ret; +} + +static int lm3633_parse_lvled_sources(struct fwnode_handle *child, + struct lm3633_led *led) +{ + struct lm3633 *priv = led->priv; + int ret; + + ret = fwnode_property_read_u32_array(child, "led-sources", + led->lvled_strings, 1); + if (ret) + dev_err(&priv->client->dev, "Cannot write OUTPUT config\n"); + + led->lmu_data.max_brightness = MAX_BRIGHTNESS_8BIT; + + return 0; +} + +static int lm3633_probe_dt(struct lm3633 *priv) +{ + struct fwnode_handle *child = NULL; + struct lm3633_led *led; + const char *name; + int control_bank; + size_t i = 0; + int ret; + + priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev, + "enable", GPIOD_OUT_LOW); + if (IS_ERR(priv->enable_gpio)) { + ret = PTR_ERR(priv->enable_gpio); + dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n", + ret); + return ret; + } + + priv->regulator = devm_regulator_get(&priv->client->dev, "vled"); + if (IS_ERR(priv->regulator)) + priv->regulator = NULL; + + device_for_each_child_node(priv->dev, child) { + ret = fwnode_property_read_u32(child, "reg", &control_bank); + if (ret) { + dev_err(&priv->client->dev, "reg property missing\n"); + fwnode_handle_put(child); + goto child_out; + } + + if (control_bank > LM3633_MAX_CONTROL_BANKS) { + dev_err(&priv->client->dev, + "reg property is invalid\n"); + ret = -EINVAL; + fwnode_handle_put(child); + goto child_out; + } + + led = &priv->leds[i]; + led->control_bank = control_bank; + led->lmu_data.bank_id = control_bank; + led->lmu_data.regmap = priv->regmap; + led->lmu_data.enable_reg = LM3633_CTRL_ENABLE; + + if (control_bank > LM3633_CONTROL_B) + lm3633_parse_lvled_sources(child, led); + else + lm3633_parse_hvled_sources(child, led); + + ret = ti_lmu_common_get_ramp_params(&priv->client->dev, + child, &led->lmu_data); + if (ret) + dev_warn(&priv->client->dev, + "runtime-ramp properties missing\n"); + + fwnode_property_read_string(child, "linux,default-trigger", + &led->led_dev.default_trigger); + + ret = fwnode_property_read_string(child, "label", &name); + if (ret) + snprintf(led->label, sizeof(led->label), + "%s::", priv->client->name); + else + snprintf(led->label, sizeof(led->label), + "%s:%s", priv->client->name, name); + + led->priv = priv; + led->led_dev.name = led->label; + led->led_dev.brightness_set_blocking = lm3633_brightness_set; + + ret = devm_led_classdev_register(priv->dev, &led->led_dev); + if (ret) { + dev_err(&priv->client->dev, "led register err: %d\n", + ret); + fwnode_handle_put(child); + goto child_out; + } + + i++; + } + +child_out: + return ret; +} + +static int lm3633_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct lm3633 *led; + int count; + int ret; + + count = device_get_child_node_count(&client->dev); + if (!count) { + dev_err(&client->dev, "LEDs are not defined in device tree!"); + return -ENODEV; + } + + led = devm_kzalloc(&client->dev, struct_size(led, leds, count), + GFP_KERNEL); + if (!led) + return -ENOMEM; + + mutex_init(&led->lock); + i2c_set_clientdata(client, led); + + led->client = client; + led->dev = &client->dev; + led->regmap = devm_regmap_init_i2c(client, &lm3633_regmap_config); + if (IS_ERR(led->regmap)) { + ret = PTR_ERR(led->regmap); + dev_err(&client->dev, "Failed to allocate register map: %d\n", + ret); + return ret; + } + + ret = lm3633_probe_dt(led); + if (ret) + return ret; + + return lm3633_init(led); +} + +static int lm3633_remove(struct i2c_client *client) +{ + struct lm3633 *led = i2c_get_clientdata(client); + int ret; + + ret = regmap_write(led->regmap, LM3633_CTRL_ENABLE, 0); + if (ret) { + dev_err(&led->client->dev, "Failed to disable the device\n"); + return ret; + } + + if (led->enable_gpio) + gpiod_direction_output(led->enable_gpio, 0); + + if (led->regulator) { + ret = regulator_disable(led->regulator); + if (ret) + dev_err(&led->client->dev, + "Failed to disable regulator\n"); + } + + mutex_destroy(&led->lock); + + return 0; +} + +static const struct i2c_device_id lm3633_id[] = { + { "lm3633", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, lm3633_id); + +static const struct of_device_id of_lm3633_leds_match[] = { + { .compatible = "ti,lm3633", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_lm3633_leds_match); + +static struct i2c_driver lm3633_driver = { + .driver = { + .name = "lm3633", + .of_match_table = of_lm3633_leds_match, + }, + .probe = lm3633_probe, + .remove = lm3633_remove, + .id_table = lm3633_id, +}; +module_i2c_driver(lm3633_driver); + +MODULE_DESCRIPTION("Texas Instruments LM3633 LED driver"); +MODULE_AUTHOR("Dan Murphy "); +MODULE_LICENSE("GPL v2");