Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp336086rdh; Thu, 23 Nov 2023 05:28:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxDOfv212bXxbQ8oFCQ7WBxZ2U9l+gT9Q3cy43uZUy8mDPgg+Hbxe4UMqRVgshSNnjv4Oz X-Received: by 2002:a17:90b:1d92:b0:280:48d4:1eb3 with SMTP id pf18-20020a17090b1d9200b0028048d41eb3mr5830777pjb.8.1700746119474; Thu, 23 Nov 2023 05:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746119; cv=none; d=google.com; s=arc-20160816; b=YxrbQzuhA+d9HP3Mr9TQ7HThSx3haXN5+Qx72rfeqQkE9avzNJE8nlVq+Xf5vDoZHV +Db7NatzKYUJ9oySwAqcXS8ayNX2y6D8NulErIPWtbUK5SCioLXn4mIZhPK+eFyW3Z8d ctcFmXm+BSRwrQarDbYrZp+V8a1vxRJSmEbwf6OXPMIGrCvKwwmbirF5Lfe7Fty+ASP6 WUtCUx9Q0xNrT9UMtRjI84aVDNVvUjilyAmSYvyCkusCAcA8lZti1nc783xbfqVvQjc+ ZB6Oh0fTELCwDRtKP8Q8yPQAyhD9GfmekGNOHhxMGdmsfXUdO7myo7YrRVV7CGxtK2S8 knjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QV98IcOEB2mGkUK9HbyaOsyZut+dAy3dRloMdrb/xJo=; fh=V7e9qrQHNgJYXy5gWeoIx1R2X/OIfFhN9U+yEV/qiMM=; b=oufK1cRgR7MrvMtJ1uaBYqs5rOj5WrB8dNKBTQdrryTn2Xyh8OnlWsalla+D7kmBVZ qX+DdIlpwP7usY4qeyiBSG4lGD73tmsWseALWmEh0q8QHyvlvABC/bz1fymJJpNeSdX6 893aXvMbvdqzx2DulR972fRZq9p1cXtNGv1j57L0ijmWT6S6fhLkX+761NmrExlI9AKT SCZMU+L+3KX/AsVj4BVgszFv/8FdC3nX6QIQ5Gk81yVgDhz6xqLoXmjPZaOAvv7AT7Xr Bd5yov/6ni9DN5nsHu0bwcXfatRTCx2sddqVmh9EtG0b/d0D3asUalisylrQWGE23AX1 XIgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=YU0iYCwl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id p3-20020a17090adf8300b002851a01b0absi1272048pjv.151.2023.11.23.05.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:28:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=YU0iYCwl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8D8CC82AD726; Thu, 23 Nov 2023 05:28:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345485AbjKWN2H (ORCPT + 99 others); Thu, 23 Nov 2023 08:28:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345466AbjKWN2E (ORCPT ); Thu, 23 Nov 2023 08:28:04 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EABC1D62 for ; Thu, 23 Nov 2023 05:28:07 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a00a9c6f283so120319766b.0 for ; Thu, 23 Nov 2023 05:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1700746086; x=1701350886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QV98IcOEB2mGkUK9HbyaOsyZut+dAy3dRloMdrb/xJo=; b=YU0iYCwlFYsueB9XF2q0CXCHuzTNsKnYWHlBTLuRIhRml/EdQH2BSLe5ueAu7TCUCI jTuZFXX3zb4nqrEAYvbe9l/jIttZZv/L4PMG5DOwybix84jieNA78gGmpMY/VkHLmaeX B6kU3w25WlrrTmbJ0C84BpTWs98YBjTeR0GfLT7BEqv0lUT1AK4GLWOOI6rE9qS9s6d7 kJzZFRd94abiJVjGxZNSqottPAxP0S/f8Lu6kX6UOHecSnGslNM49AhpZqnjvoLTLdae JLNF2jLn05rDmlruNBT3+6mPX5DDC67k9uYewuMI56ZArq4Wdbgcn4CY2RjVuni/tEEd EpBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700746086; x=1701350886; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QV98IcOEB2mGkUK9HbyaOsyZut+dAy3dRloMdrb/xJo=; b=spVzd+ryVzN4CadHQArZgzl9Vb+qpuJEVbytku8gGLTeCUUcEIrbYzC80NABhIr1tz LVndu54mNeVnZZ6kwBWid9pKJ9ilTqlWM+xtRzn3fIvKku88GVCXkSJoC+lJslf1crSz EwLQwEaCSi6eB6WifvwfImgjreuUJRkwTHtLrKBJpc7XwRF5rcGdwXE/fMUEDJquaMAa 72OZW6f013yq0D6UM0FDlP95+XNju2MGaDF6F4hQzM2cxjvCriUdDFPVaS3mBJkoXxwn 7AQ+dD4N1fptgT70KISWpUBvOFOhi8XAyuhgGYEYmDAQ6TYuESqMMqTRMZJli/F9lZGF piVA== X-Gm-Message-State: AOJu0YykHBckXd5sqwtUbYLXqsRgBWDV0lL2UxZh+nvtOhl07PdLQ4wO 6xWzu9hr3F4tcNckVn364CrYvw== X-Received: by 2002:a17:906:2249:b0:9fd:4bed:72af with SMTP id 9-20020a170906224900b009fd4bed72afmr4260455ejr.72.1700746085961; Thu, 23 Nov 2023 05:28:05 -0800 (PST) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id q22-20020a1709064c9600b009ae69c303aasm778834eju.137.2023.11.23.05.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:28:05 -0800 (PST) From: Naresh Solanki To: Pavel Machek , Lee Jones Cc: Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org Subject: [PATCH v5] leds: max5970: Add support for max5970 Date: Thu, 23 Nov 2023 13:28:02 +0000 Message-ID: <20231123132803.1107174-1-naresh.solanki@9elements.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:28:36 -0800 (PST) From: Patrick Rudolph The MAX5970 is hot swap controller and has 4 indication LED. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki Reviewed-by: Lee Jones --- Changes in V5: - Replace -EPROBE_DEFER with -ENODEV Changes in V4: - Compact declaration of variable to single line - Use sizeof(*ddata) instead of sizeof(struct max5970_led). - Use the shorter 'dev' version whilst it's available Changes in V3: - Drop array for ddata variable. Changes in V2: - Add of_node_put before return. - Code cleanup - Refactor code & remove max5970_setup_led function. --- drivers/leds/Kconfig | 11 ++++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 109 ++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/leds/leds-max5970.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 6292fddcc55c..da60940d711f 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -638,6 +638,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d7348e8bc019..6eaee0a753c6 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c new file mode 100644 index 000000000000..456a16a47450 --- /dev/null +++ b/drivers/leds/leds-max5970.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Device driver for leds in MAX5970 and MAX5978 IC + * + * Copyright (c) 2022 9elements GmbH + * + * Author: Patrick Rudolph + */ + +#include +#include +#include +#include +#include + +#define ldev_to_maxled(c) container_of(c, struct max5970_led, cdev) + +struct max5970_led { + struct device *dev; + struct regmap *regmap; + struct led_classdev cdev; + unsigned int index; +}; + +static int max5970_led_set_brightness(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct max5970_led *ddata = ldev_to_maxled(cdev); + int ret, val; + + /* Set/clear corresponding bit for given led index */ + val = !brightness ? BIT(ddata->index) : 0; + + ret = regmap_update_bits(ddata->regmap, MAX5970_REG_LED_FLASH, BIT(ddata->index), val); + if (ret < 0) + dev_err(cdev->dev, "failed to set brightness %d", ret); + + return ret; +} + +static int max5970_led_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev_of_node(dev->parent); + struct regmap *regmap; + struct device_node *led_node, *child; + struct max5970_led *ddata; + int ret = -ENODEV, num_leds = 0; + + regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!regmap) + return -ENODEV; + + led_node = of_get_child_by_name(np, "leds"); + if (!led_node) + return -ENODEV; + + for_each_available_child_of_node(led_node, child) { + u32 reg; + + if (of_property_read_u32(child, "reg", ®)) + continue; + + if (reg >= MAX5970_NUM_LEDS) { + dev_err(dev, "invalid LED (%u >= %d)\n", reg, MAX5970_NUM_LEDS); + continue; + } + + ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + if (!ddata) { + of_node_put(child); + return -ENOMEM; + } + + ddata->index = reg; + ddata->regmap = regmap; + ddata->dev = dev; + + if (of_property_read_string(child, "label", &ddata->cdev.name)) + ddata->cdev.name = child->name; + + ddata->cdev.max_brightness = 1; + ddata->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata->cdev.default_trigger = "none"; + + ret = devm_led_classdev_register(dev, &ddata->cdev); + if (ret < 0) { + of_node_put(child); + dev_err(dev, "Failed to initialize LED %u\n", reg); + return ret; + } + num_leds++; + } + + return ret; +} + +static struct platform_driver max5970_led_driver = { + .driver = { + .name = "max5970-led", + }, + .probe = max5970_led_probe, +}; + +module_platform_driver(max5970_led_driver); +MODULE_AUTHOR("Patrick Rudolph "); +MODULE_AUTHOR("Naresh Solanki "); +MODULE_DESCRIPTION("MAX5970_hot-swap controller LED driver"); +MODULE_LICENSE("GPL"); base-commit: b9604be241587fb29c0f40450e53d0a37dc611b5 -- 2.41.0