Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3849623rdb; Thu, 14 Sep 2023 04:52:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtbfZ9Mj+2kgfc8K221EQPFYLE2IXge+qOTq36VrNMBj0Wz3O0npRobIgpbF76iv003alJ X-Received: by 2002:a05:6a20:7d8a:b0:129:3bb4:77f1 with SMTP id v10-20020a056a207d8a00b001293bb477f1mr6898262pzj.0.1694692353248; Thu, 14 Sep 2023 04:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694692353; cv=none; d=google.com; s=arc-20160816; b=NsKA0DOI24Qh/e66g4DKjPpnWs0a4QR6t/Rjy3tvf0pjRmTgdn8UbZqxTo4MapHZ/V D9J4fr7ivu6kDSlpb4d5648U9g4whcjMRPK4W+Prmuqrewz9i2jFB8wxdIBsZGpegrfM PKnDBo7yHeJS5wftFPn6ZVXnQCJ7NAiM+8BGsCvVT2yWllcrj0uGOC6JlruTmSqEXPrZ jEjEI0bnQRR2s+l59K5c58aClGX9+LY5NFDAZqNX6cMy/lrO4BrZno7pqH9N6WnVwU9c 6TTz3E/05AlgZ0sVCTsyLtBGkAw1iFo3c1XBMCRT70E9ngSHqdXQZr4aLuG3gqTuVLlA NoVA== 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=d90j3ijyMSPHX2E+Sg30HyU03VvlF+Mxv/PVomj/3ufnGsaju2DqTu/3wHCTuVyskO BZU0ZAsy7DbEORUNkpipgYlIlf8syYgyJdZ+5y8bVHYht/agG2iCQtSQq4kZY3BJipLi VLl3Gxmp3vTnRhcWiMW7rAacp/ltQI2tEZcaIaO8QGo06OMxQBaDFrLueqyn9rXrCmIL H/EUk+OMu7aml6JMjydYQ/BRQC1wxI4tGbs+cXMlOXFdj+dM2szCk+p4GVxoSAtufEWP e3aRU6dt0jc5irnfj/UNiwEII2U9akpQN7+M3TdXI8e8SIgYOg/XTgjwUPJJO/cRZjyO ZI1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=Z4YfJ2hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ls12-20020a17090b350c00b00263f3c1bb86si1611882pjb.158.2023.09.14.04.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 04:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=Z4YfJ2hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 427EE8038FAF; Thu, 14 Sep 2023 04:46:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238356AbjINLpz (ORCPT + 99 others); Thu, 14 Sep 2023 07:45:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238363AbjINLpr (ORCPT ); Thu, 14 Sep 2023 07:45:47 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7C4213A for ; Thu, 14 Sep 2023 04:45:36 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-401b0d97850so8669135e9.2 for ; Thu, 14 Sep 2023 04:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1694691935; x=1695296735; 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=Z4YfJ2hckDlIY1kZSDfstfZbVD0Bu3o+dpFk3GM2v+69bzg0hsv+X9YlRdZ8klAqky H02bfN5UTRL3SLAPAKJuYJhsulnvQFhy5fHok7dKm6OEvFWvpOXyuVHpSeYjpEBrXGru icnQRN3GglxG7qAMg4Md2nVmfTfdQMNepm2DiBwseRao5+CKWDe794tyFl53MxNdcco/ jKtlucurpWnm8QhRpE2SQDHNB/S0W8EgUS4D+AoHjphk8Xo267wwM8/M7yCkQyDWi1G+ wbLWkDwoj38SbKBKooYc5EXvppTSd8F8y5Ze5LS7YRI/ej366J8Dp7mKQ8mePb/4wNEq Pt0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694691935; x=1695296735; 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=QnrLMAVE2Cx2vnisYXf1ge5UJ+BbqufkbLxuH5LBvrmoTfKUfeQOu0LPgUTYike4Ki +tderPxnmae7h08++OF12YQMSeMlmcde9SP+bDI8MUSa0M58g7dhCg01iS8Nz+kLOWbv ZYQm3CccrU+K7T6Y/TBe++PBCeuYqkvn8hrkkXXHhiVwt8a4IbNx+3JDZll1LqeblGBb g7vplhkPAHUkjkq1CH/2Y752nZsLXSB55jcEaLVvWbM5UQaSB8DJOULZGWFEqsoL8CkE 03lhOWoobdhTc2cUQt2eZw5ZrQAIlIu7VQVyxdKB2P4/NGcnEraEedtqPk+q697H3rFI 7Qag== X-Gm-Message-State: AOJu0Yz2daE02TT2l0RpGp6o44HckemnXeC4+xhk/ya5S6rJUbP3+4As 2j5X7DrKoN+6gVUSQb9ghoU6Hg== X-Received: by 2002:a7b:cb85:0:b0:402:ee9e:ed98 with SMTP id m5-20020a7bcb85000000b00402ee9eed98mr4369643wmi.34.1694691934757; Thu, 14 Sep 2023 04:45:34 -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 m18-20020a5d4a12000000b0031f65cdd271sm1547021wrq.100.2023.09.14.04.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 04:45:34 -0700 (PDT) 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, 14 Sep 2023 13:45:20 +0200 Message-ID: <20230914114521.1491390-1-naresh.solanki@9elements.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Sep 2023 04:46:03 -0700 (PDT) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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