Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1941617rdb; Tue, 5 Sep 2023 09:22:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPbx136tpgiX+JRFxyIgCaGDooBDcl2I/XTO/KBQRBdUKAik85iUzv3xSCv6L88VH3+VPp X-Received: by 2002:a17:906:2091:b0:99d:e8da:c20b with SMTP id 17-20020a170906209100b0099de8dac20bmr216759ejq.24.1693930960717; Tue, 05 Sep 2023 09:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693930960; cv=none; d=google.com; s=arc-20160816; b=jA82KU1Ogu52Js1fmPvE0u4GFS9rgG7xNJD3z6Meb1TheeY9OitC1CzocxTS8q0cEz Cu7ZQGrtl7mtJifpCr4MGGxyxohr9TssXtDP7mcksNkmHMSV8j3PP95iyuoQ5t8T7Zu5 mrmdXpxPCt4qorR7PD4OSfauaDi8dtvtrVZlvqMkcv/9LOjuxfbvk9HlxHjeGAdK9aKc nW/kTp5uYvKBAiSW8nsBR7LnfQIt5rn6CyGi1HmXTRQamRQ6jOn0zPxVNgQfi0SRKORc pa/rx2nQ7iLN5psAC/O12ruF5VziRLF/t86a6vCYxegJKvWTeXgJpjDmpS70FNzfl2c3 NQmg== 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=DkwdpEsnZjrBHPvFI7R2mEJyzdrosQr2sd/FTGz51gs=; fh=V7e9qrQHNgJYXy5gWeoIx1R2X/OIfFhN9U+yEV/qiMM=; b=jtbGzi3yh9Q2P35duyLhugVn8CjjEcnQeqtTdreamcPME67WEw9fXB++1s1m9DbrFK fkMvQKV4dWfmOdy7/0RlIKOeYTWiDFGU8+VcT2+iWrpoC2LvImW86J6XCFHjTs1ci4UQ I2awA/qNVsQSO2KpvInuOu6GCpRDLiByHvzpUGEzJiUJhnqRoAdxq8vj/rYsnKiJdxXj KfC7uL/XEd+NLa5rj4seWmjosmjzMbCqyOvGWMIlupyQFNZGbW82dU1ail27Hjuayx5E iuv/hBqSwniLk5B16SvFnC0pctYpkKfgA+aBn5VgnGz187OvgyAqF//qlDi/HdlG9Hfp 6cSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=cUvrqq6C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a17090699ce00b00992fef51a60si7635665ejn.525.2023.09.05.09.22.36; Tue, 05 Sep 2023 09:22:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=cUvrqq6C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238785AbjHaKWl (ORCPT + 8 others); Thu, 31 Aug 2023 06:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjHaKWk (ORCPT ); Thu, 31 Aug 2023 06:22:40 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0423CFF for ; Thu, 31 Aug 2023 03:22:32 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2bcc14ea414so12313601fa.0 for ; Thu, 31 Aug 2023 03:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1693477351; x=1694082151; 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=DkwdpEsnZjrBHPvFI7R2mEJyzdrosQr2sd/FTGz51gs=; b=cUvrqq6CQ3Lcdgg7dEVjpEDppQWts+w8tq/8GJ5bHRJUU/4DCXONDK4f2hbkilaWAz lJQYRT32zHcxX6lOE+2rw2t654+JerL2p3nT73IQEnnbGsw+50TdihzF5GxDy6xu5Jgw uYlsd0l3lBSaU/yWeIrpNZ2/VgYX9uqxEDBNtUOSu/3x53t0okx/3E7rinIeuH0pjbwI gZ3GN0slkBL5qnHY8DHo49UpgKyQjBKN5NnFl9I66fvN9lkO8kWdRzYfRbSyZZysxeRH PWuINa01hkF1q0YLwSlhuL4Vv7WA6J6tvJT4lrIwnzhcYvdihNdYMEQ/JrFYUBpuDWQ5 Lq9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693477351; x=1694082151; 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=DkwdpEsnZjrBHPvFI7R2mEJyzdrosQr2sd/FTGz51gs=; b=Vgj1NEhEhVeEsc9giydsw/m0v3i9XnWXxMkMFVI5QtfyoRL270wCVpa/ATIrHjhIbs w81ov80Iez+LPyEYE2a73S7oSgTF3B1bFH3/WawpfML4d8cting11eJk9txzMJzlnIYq TdcEjpzALnDqBzWLlQ88t6MODQS6I1p14toNisO/zK2laG/Di34f6B/u3j38xbUK5Lu0 tYhDHpVvNevG65R2i9xeOxnfbWqqtUizPCcMoRXvj4w0X0kPaPKLYiIKFWDHvsWWNWGa s7z3U4An9gS2KFw/fuuqC3bHrZ6juVqbtZ0eDdEezBYhIbPvEzLR6b5mPpoHlcW/douC kEuQ== X-Gm-Message-State: AOJu0YxMdoLcWFZrWMXqO60my1QWFarLrnMGz1MRrksVUzj81cy2cAH9 q3NY30vQVgKoI8H2Zb5/stPNzw== X-Received: by 2002:a2e:8190:0:b0:2bd:1681:e8dc with SMTP id e16-20020a2e8190000000b002bd1681e8dcmr3747658ljg.53.1693477350344; Thu, 31 Aug 2023 03:22:30 -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 s5-20020a7bc385000000b003fe61c33df5sm4712472wmj.3.2023.08.31.03.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 03:22:29 -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: [RESEND PATCH v3] leds: max5970: Add support for max5970 Date: Thu, 31 Aug 2023 12:22:26 +0200 Message-ID: <20230831102227.2047009-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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 | 110 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 drivers/leds/leds-max5970.c 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..c9685990e26e --- /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; + 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 = devm_kzalloc(dev, sizeof(struct max5970_led), 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(ddata->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: baca986e1f2c31f8e4b2a6d99d47c3bc844033e8 -- 2.41.0