From patchwork Wed Apr 10 13:38:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 162023 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp6221402jan; Wed, 10 Apr 2019 06:39:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7e5AAfaqz6LjNdGiAv4cxvzIXZrkSWSZRQwVNHmVQLHxkz+VJU285zJobBKPFYCak0Nec X-Received: by 2002:a65:4802:: with SMTP id h2mr38158496pgs.98.1554903560601; Wed, 10 Apr 2019 06:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554903560; cv=none; d=google.com; s=arc-20160816; b=nNcDMDXtZJ3ibIevmw77rhS8nUG+3ibUB8RZqi9q3NDDVsSsJ8UzrTFsN246G2pI2C za5g0/A6JptCrN7ZwK6Vt9iJB9ChIXltq5lLiNxabfVSsBmyvgwBUb/XT7br9HhTPY0D vGlkyVhU+BAE52ZzM5NH2vSltILfK+I9o9+8XWWxNaIregUV8auDPFO38Xl1FClvJnpv DYnffMOZAEQDWszD9zzKXo+CKYYe+iKyOUmbyh++MXHKGtUBQcMKM+aweb/rAZsCxPDw PaBM2Jy5gzPD8FNjMQCWrLUJHcSzJ8NyNRR7lgjnQAfq6D5rO2Wf2vSmaoyT8e1sy23C 2Zjg== 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=aX8lwbOZJQ4U89s0jHitfwLBstHyamZsm+uVnSzL8BM=; b=WoC/sT9vEt4P9tedhA61R2yKNevyNhJ387mSH4Wy10B6wAdcSR0uVB7jkhnUyt+esA /cR4UALUNFNqd3lzRlf9C8lsaSb7hLYroJ7B7jXt0NWZu/zYd7qJeRk6ONBmhwKe/wEn At7XR63/gmNhQqeqO4k34DjVrriNMgBucAyoLTrqIujxYM9Lo76xYn1am1SGz7/xiaJ7 ydONcp4LgfnSFuZKgDZBwSz7UNYVvSQduGvYw8FxD2BWa4Wqws16v5HnC0/66US2Lzzz dFyAKWuRhX5HNFVlpADovmBhJfhD3aO5WpdCvWWuRq47ZNoI/OA7tMG3TvwO9JxAtZtD Togw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=DX4SeSV4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 k193si13783609pge.150.2019.04.10.06.39.20; Wed, 10 Apr 2019 06:39:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=DX4SeSV4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1732092AbfDJNjS (ORCPT + 31 others); Wed, 10 Apr 2019 09:39:18 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:49780 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731979AbfDJNiq (ORCPT ); Wed, 10 Apr 2019 09:38:46 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x3ADcaf6020016; Wed, 10 Apr 2019 08:38:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1554903516; bh=aX8lwbOZJQ4U89s0jHitfwLBstHyamZsm+uVnSzL8BM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=DX4SeSV4/276HyXMLyrjSQNS5IbV8Ei8OiclexyB5Ch3Tq9BQ9PgfKrsS7gs6S5VT dq/PM/OQCDVBQo1hiZqjqNg1qbRth0Z06FDCN3SLl4OyzUbQoIPxZKXmhh7FIYeHUO E7fg5QDhe7NTroV54A15XP319DNW7qMgxIhm/VTg= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x3ADcaof085359 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Apr 2019 08:38:36 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) 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.1713.5; Wed, 10 Apr 2019 08:38:35 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE113.ent.ti.com (157.170.170.24) 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; Wed, 10 Apr 2019 08:38:35 -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 x3ADcZAF071533; Wed, 10 Apr 2019 08:38:35 -0500 From: Dan Murphy To: , , , , , CC: , , , Dan Murphy Subject: [PATCH v2 6/6] leds: lm36274: Introduce the TI LM36274 LED driver Date: Wed, 10 Apr 2019 08:38:33 -0500 Message-ID: <20190410133833.28859-6-dmurphy@ti.com> X-Mailer: git-send-email 2.21.0.5.gaeb582a983 In-Reply-To: <20190410133833.28859-1-dmurphy@ti.com> References: <20190410133833.28859-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce the LM36274 LED driver. This driver uses the ti-lmu MFD driver to probe this LED driver. The driver configures only the LED registers and enables the outputs according to the config file. The driver utilizes the ti-lmu-led-common framework to set the brightness bits. Signed-off-by: Dan Murphy --- v2 - No changes - https://lore.kernel.org/patchwork/patch/1058778/ drivers/leds/Kconfig | 9 +- drivers/leds/Makefile | 1 + drivers/leds/leds-lm36274.c | 174 ++++++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 drivers/leds/leds-lm36274.c -- 2.21.0.5.gaeb582a983 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 2d1576f4d5d6..c0bf59544886 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -783,12 +783,19 @@ config LEDS_LM3697 Say Y to enable the LM3697 LED driver for TI LMU devices. This supports the LED device LM3697. +config LEDS_LM36274 + tristate "LED driver for LM36274" + depends on LEDS_TI_LMU_COMMON + help + Say Y to enable the LM36274 LED driver for TI LMU devices. + This supports the LED device LM36274. + config LEDS_TI_LMU_COMMON tristate "LED driver for TI LMU" 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. + LM3633, LM3695, LM3697 and LM36274 comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 2eb0225d8dc6..7ff67215b38c 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -81,6 +81,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_LM36274) += leds-lm36274.o obj-$(CONFIG_LEDS_TI_LMU_COMMON) += ti-lmu-led-common.o # LED SPI Drivers diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c new file mode 100644 index 000000000000..6a419c47c47f --- /dev/null +++ b/drivers/leds/leds-lm36274.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +// TI LM36274 LED chip family driver +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define LM36274_MAX_STRINGS 4 +#define LM36274_BL_EN BIT(4) + +/** + * struct lm36274 + * @pdev: platform device + * @led_dev: led class device + * @lmu_data: Register and setting values for common code + * @regmap: Devices register map + * @dev: Pointer to the devices device struct + * @led_sources - The LED strings supported in this array + * @num_leds - Number of LED strings are supported in this array + */ +struct lm36274 { + struct platform_device *pdev; + struct led_classdev led_dev; + struct ti_lmu_bank lmu_data; + struct regmap *regmap; + struct device *dev; + + u32 led_sources[LM36274_MAX_STRINGS]; + int num_leds; +}; + +static int lm36274_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brt_val) +{ + struct lm36274 *led = container_of(led_cdev, struct lm36274, led_dev); + + return ti_lmu_common_set_brightness(&led->lmu_data, brt_val); +} + +static int lm36274_init(struct lm36274 *lm36274_data) +{ + int enable_val = 0; + int i; + + for (i = 0; i < lm36274_data->num_leds; i++) + enable_val |= (1 << lm36274_data->led_sources[i]); + + if (!enable_val) { + dev_err(lm36274_data->dev, "No LEDs were enabled\n"); + return -EINVAL; + } + + enable_val |= LM36274_BL_EN; + + return regmap_write(lm36274_data->regmap, LM36274_REG_BL_EN, + enable_val); +} + +static int lm36274_parse_dt(struct lm36274 *lm36274_data) +{ + struct fwnode_handle *child = NULL; + char label[LED_MAX_NAME_SIZE]; + struct device *dev = &lm36274_data->pdev->dev; + const char *name; + int child_cnt; + int ret = -EINVAL; + + /* There should only be 1 node */ + child_cnt = device_get_child_node_count(dev); + if (child_cnt != 1) + return ret; + + device_for_each_child_node(dev, child) { + ret = fwnode_property_read_string(child, "label", &name); + if (ret) + snprintf(label, sizeof(label), + "%s::", lm36274_data->pdev->name); + else + snprintf(label, sizeof(label), + "%s:%s", lm36274_data->pdev->name, name); + + lm36274_data->num_leds = fwnode_property_read_u32_array(child, + "led-sources", + NULL, 0); + if (lm36274_data->num_leds <= 0) + return -ENODEV; + + ret = fwnode_property_read_u32_array(child, "led-sources", + lm36274_data->led_sources, + lm36274_data->num_leds); + if (ret) { + dev_err(dev, "led-sources property missing\n"); + return -EINVAL; + } + + fwnode_property_read_string(child, "linux,default-trigger", + &lm36274_data->led_dev.default_trigger); + + } + + lm36274_data->lmu_data.regmap = lm36274_data->regmap; + lm36274_data->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT; + lm36274_data->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB; + lm36274_data->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB; + + lm36274_data->led_dev.name = label; + lm36274_data->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT; + lm36274_data->led_dev.brightness_set_blocking = lm36274_brightness_set; + + return ret; +} + +static int lm36274_probe(struct platform_device *pdev) +{ + struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent); + struct lm36274 *lm36274_data; + int ret; + + lm36274_data = devm_kzalloc(&pdev->dev, sizeof(*lm36274_data), + GFP_KERNEL); + if (!lm36274_data) { + ret = -ENOMEM; + return ret; + } + + lm36274_data->pdev = pdev; + lm36274_data->dev = lmu->dev; + lm36274_data->regmap = lmu->regmap; + dev_set_drvdata(&pdev->dev, lm36274_data); + + ret = lm36274_parse_dt(lm36274_data); + if (ret) { + dev_err(lm36274_data->dev, "Failed to parse DT node\n"); + return ret; + } + + ret = lm36274_init(lm36274_data); + if (ret) { + dev_err(lm36274_data->dev, "Failed to init the device\n"); + return ret; + } + + return devm_led_classdev_register(lm36274_data->dev, + &lm36274_data->led_dev); +} + +static const struct of_device_id of_lm36274_leds_match[] = { + { .compatible = "ti,lm36274-backlight", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_lm36274_leds_match); + +static struct platform_driver lm36274_driver = { + .probe = lm36274_probe, + .driver = { + .name = "lm36274-leds", + }, +}; +module_platform_driver(lm36274_driver) + +MODULE_DESCRIPTION("Texas Instruments LM36274 LED driver"); +MODULE_AUTHOR("Dan Murphy "); +MODULE_LICENSE("GPL v2");