From patchwork Thu Aug 24 10:49:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 717074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64862C7113B for ; Thu, 24 Aug 2023 10:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236262AbjHXKtd (ORCPT ); Thu, 24 Aug 2023 06:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240843AbjHXKt3 (ORCPT ); Thu, 24 Aug 2023 06:49:29 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524F81711 for ; Thu, 24 Aug 2023 03:49:27 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b974031aeaso102080731fa.0 for ; Thu, 24 Aug 2023 03:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1692874165; x=1693478965; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U2QSKQ/83/43p/qAa+Lm0R0OYAZElaQVoZevD5EWLWg=; b=KCzIc1MjLtX5BE4+VRpevemNFKGb2TsLLDtvnq8nmjtJ5ztTPV0U9cuTmKjtcCGiQL vb9CpFodiXI8uCZJwLY2+k0Pjpws0By7nuHsUWdycBYGZRtW/1jjC38XiIX8WSwe3yn0 oJ2cV69iq0g8y3YG6gkTdMBBXlfASdfH9MPnndExKR8NTQKzjH3p1fBrGKIdu+7kDgBT jkcK8hrHx0I3PIHw08eOVQzYUsMHIU1+WADHo3fFVT0NA6SS6eZ8c8TqcUecLc5VwsSN NJ2uIgvFJCj9rjgrfLk9j4CZczZPwAZpzO2pcXUibujsQXD1cMvn+Jn4G5ISYuaRoocM Xv0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692874165; x=1693478965; 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=U2QSKQ/83/43p/qAa+Lm0R0OYAZElaQVoZevD5EWLWg=; b=AxLso48emEubLtA/WibGW1zfSbrva9bkR//JEKgimpTqs5JMllUn6+LohGWzDoixc4 Kx/sVDEfoRfHr0HJ1YDhR7Fzq9hWhuDr8TCozZPc4O/BzQRGgsTXYPeUfSx4Ex6aNYDZ ZQ5y0PTZcYElvmCYyuW7+nlfVaMxEMgw3FULJf/4ofXk8hmSj7JdDmIbOHypTnEbmTvT emFm6LNZLm4Kc18iEBb4M1rvhk763Ay9hZpIokuTGMA/to/QQhEVaLi/TI5+eCv37R4g L0TKC9hUwG9ga8Bqj1Jcqv0xXxubWQeQL7HaxIhiZ5rpran0M27qyptuBpTTdmIriNUU MhiA== X-Gm-Message-State: AOJu0Yy5fguYNq7fHpzx025/IzjJ87K2B6oUM52SWf1k3l7b0Sna8rSH zhDvSeCcBAgePppxgfHE/gLt2A== X-Google-Smtp-Source: AGHT+IElyEncgNbRYW+dsOkc7aLQbs5D+YwNHeV6E3BV249cK6RVTDS/4OzZhsIPXWb4GX1jA00G5w== X-Received: by 2002:a2e:9c99:0:b0:2bc:dd6b:9220 with SMTP id x25-20020a2e9c99000000b002bcdd6b9220mr3407626lji.24.1692874165470; Thu, 24 Aug 2023 03:49:25 -0700 (PDT) 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 k25-20020a05600c0b5900b003feea62440bsm2223743wmr.43.2023.08.24.03.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:49:24 -0700 (PDT) From: Naresh Solanki X-Google-Original-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 v2] leds: max5970: Add support for max5970 Date: Thu, 24 Aug 2023 12:49:08 +0200 Message-ID: <20230824104909.2451625-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Patrick Rudolph The MAX5970 is hot swap controller and has 4 indication LED. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- 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 | 110 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 drivers/leds/leds-max5970.c base-commit: baca986e1f2c31f8e4b2a6d99d47c3bc844033e8 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index b92208eccdea..03ef527cc545 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -637,6 +637,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..79277d47e1bc --- /dev/null +++ b/drivers/leds/leds-max5970.c @@ -0,0 +1,110 @@ +// 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; + struct device_node *child; + struct max5970_led *ddata[MAX5970_NUM_LEDS]; + int ret = -ENODEV, num_leds = 0; + + regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!regmap) + return -EPROBE_DEFER; + + 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[num_leds] = devm_kzalloc(dev, sizeof(struct max5970_led), GFP_KERNEL); + if (!ddata[num_leds]) { + of_node_put(child); + return -ENOMEM; + } + + ddata[num_leds]->index = reg; + ddata[num_leds]->regmap = regmap; + ddata[num_leds]->dev = dev; + + if (of_property_read_string(child, "label", &ddata[num_leds]->cdev.name)) + ddata[num_leds]->cdev.name = child->name; + + ddata[num_leds]->cdev.max_brightness = 1; + ddata[num_leds]->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata[num_leds]->cdev.default_trigger = "none"; + + ret = devm_led_classdev_register(ddata[num_leds]->dev, &ddata[num_leds]->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");