Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3347838yba; Tue, 23 Apr 2019 02:06:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZyrVQaeErXOn96UzlsIYUyKoofNe1ov4ekDFxxHKeT3NeUdOvgOb6ccs1u8XwkUet7a8Y X-Received: by 2002:a63:1446:: with SMTP id 6mr14765406pgu.227.1556010408977; Tue, 23 Apr 2019 02:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556010408; cv=none; d=google.com; s=arc-20160816; b=H/JIHSz9UgJDJVyYuSCke5QJe0Fg96fY8MTGkVFTxpOfOTmt1+j1B7GTU8WCX29C6N 2KdI47hAweqTCowUedmBLvypk7dXLpPY0GuQ+IyRvpa91wSSog3aSUARj/mpYXCfbLLL iCWU18qxVbpIYB5WIHx0YXfFAKPDG0Cz3am7Zikg4p4d2mvZUTN7vRg1+vUrBKMLPnlB O/vmUCoyXRqo8NPjI87FsEz3xEJZdEj2KaffX2+VfRtFw4YGPqPc/afOmj3x2YwDaQ2c b0mPe6Cw8fig96aTcr0yg/RzXTPGTAjSUk9a1YysgQd2nQaE0IUZS9W1sY3FwwPheHtc 03ug== 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=yPfsZHOrFhAluR8d0b1i0AQn5YZ9ojyzTFq/9FNkWfw=; b=SvBbKBYo2DbgF7A1vNC3nDAhZKX07MCUb2sqpp7mBykiUFO532WRGuEsyQ5cO15cZA RUnWie16xXtD6fR07PUnSs78q6k11+KO2XezUw2NiYV+fSoyt4MRg+zsDRKTef9NPyQ0 Bz5ZUwI5nAb9SZG72jBK2sLshzNaz2PlTq4LZ1H7NET5qo3RTQDNZYG7ZOouy7ZpDpTd X/+8r80xo+Zw1xniqtWyN7hqoBHMgts9MdFryxPSXFrN68uU6Za9MbZXGO3VwBMguFRv wSGb3pQJ78I4V5PdL35FPWwr89eW9nRwy2g7Fu20v55zx6STNVXPD49KevMcUNdEy+zD O6/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=kkjpvv0t; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si15426416pfh.205.2019.04.23.02.06.32; Tue, 23 Apr 2019 02:06:48 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=kkjpvv0t; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727338AbfDWJFQ (ORCPT + 99 others); Tue, 23 Apr 2019 05:05:16 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38863 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727300AbfDWJFO (ORCPT ); Tue, 23 Apr 2019 05:05:14 -0400 Received: by mail-wm1-f65.google.com with SMTP id w15so17804522wmc.3 for ; Tue, 23 Apr 2019 02:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yPfsZHOrFhAluR8d0b1i0AQn5YZ9ojyzTFq/9FNkWfw=; b=kkjpvv0t5moN0OBPvdElWD8mhewxCzyOMiEyNC7p7wAN6gk+fOSDtr3a9y2Wazf5LK vXJ0MBQq8OLOXpK54LetKLx0j3Xs1tyn0fslGT+73LalYi9muYr/8P/kqyXgDRIuOR+P ocikCoO0mAEFE2K8LLbUtoZD5Bc8ozP6jpbcIFMM76hEM4dnHrSN7XTDRBqDYYnSV0+l 6Lv6Vt6K8UQXSqm7xP16BGxA8efm4xYcMX9EbXx1iviVJYBIfK6+G8MwMTB9hEdsI0PD CUUMd+Z8OxAcf7Kq/04UsttwvdhBBzC1y4AvHh8TSo92gMcc0qThP+SVfKm/42/NKiBv oRcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yPfsZHOrFhAluR8d0b1i0AQn5YZ9ojyzTFq/9FNkWfw=; b=QCuu/gmRvo+HCKW0JaOj71aZNZNOLUkwdbD+ay18L7o6WRyeWNXlZJNdQVZpEaUPhP Dej0QpMliqUYmBIshmB9yhH7EsEbEfjpsWaW9FvYV7uypXQnjKZ9LKgjPqkxAkFCEFRu 3pvBcBfcpo38P7RSA1PeNE6QFH36mrecUg7k4fIEJCyBrITzgw9mc2aHZNjkhTbo2UrM k3kIscQAQbSQYYdtodwz3v5O2D6VU3/BSP3olbQX/uPVQiMqg2AH49XPpKKVHFShMiW0 zpw2tVAwW6bLEulg6VeglYuo8H2/Lf0+q9G1AFQvsFBDEMXxcp0U2gPSXPIm8yokKp11 qxhw== X-Gm-Message-State: APjAAAUzr6TkBCRdQTsywAFdNoT//fmW4/GyM2tCQt1g3ePK8EedWdLl wDMCYRNZS2VgRNICndH80EbF7dkTMQY= X-Received: by 2002:a1c:1d49:: with SMTP id d70mr1453837wmd.36.1556010311899; Tue, 23 Apr 2019 02:05:11 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-25-101.w90-86.abo.wanadoo.fr. [90.86.250.101]) by smtp.gmail.com with ESMTPSA id v190sm15360434wme.18.2019.04.23.02.05.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 02:05:11 -0700 (PDT) From: Bartosz Golaszewski To: Rob Herring , Mark Rutland , Linus Walleij , Dmitry Torokhov , Jacek Anaszewski , Pavel Machek , Lee Jones , Sebastian Reichel , Liam Girdwood , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v10 09/11] leds: max77650: add LEDs support Date: Tue, 23 Apr 2019 11:04:49 +0200 Message-Id: <20190423090451.23711-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423090451.23711-1-brgl@bgdev.pl> References: <20190423090451.23711-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski This adds basic support for LEDs for the max77650 PMIC. The device has three current sinks for driving LEDs. Signed-off-by: Bartosz Golaszewski Acked-by: Jacek Anaszewski Acked-by: Pavel Machek --- drivers/leds/Kconfig | 6 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-max77650.c | 147 +++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 drivers/leds/leds-max77650.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index a72f97fca57b..d8c70cc6a714 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -608,6 +608,12 @@ config LEDS_TLC591XX This option enables support for Texas Instruments TLC59108 and TLC59116 LED controllers. +config LEDS_MAX77650 + tristate "LED support for Maxim MAX77650 PMIC" + depends on LEDS_CLASS && MFD_MAX77650 + help + LEDs driver for MAX77650 family of PMICs from Maxim Integrated. + config LEDS_MAX77693 tristate "LED support for MAX77693 Flash" depends on LEDS_CLASS_FLASH diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 4c1b0054f379..f48b2404dbb7 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -61,6 +61,7 @@ obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o obj-$(CONFIG_LEDS_NS2) += leds-ns2.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o +obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX77693) += leds-max77693.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c new file mode 100644 index 000000000000..6b74ce9cac12 --- /dev/null +++ b/drivers/leds/leds-max77650.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 BayLibre SAS +// Author: Bartosz Golaszewski +// +// LED driver for MAXIM 77650/77651 charger/power-supply. + +#include +#include +#include +#include +#include +#include + +#define MAX77650_LED_NUM_LEDS 3 + +#define MAX77650_LED_A_BASE 0x40 +#define MAX77650_LED_B_BASE 0x43 + +#define MAX77650_LED_BR_MASK GENMASK(4, 0) +#define MAX77650_LED_EN_MASK GENMASK(7, 6) + +#define MAX77650_LED_MAX_BRIGHTNESS MAX77650_LED_BR_MASK + +/* Enable EN_LED_MSTR. */ +#define MAX77650_LED_TOP_DEFAULT BIT(0) + +#define MAX77650_LED_ENABLE GENMASK(7, 6) +#define MAX77650_LED_DISABLE 0x00 + +#define MAX77650_LED_A_DEFAULT MAX77650_LED_DISABLE +/* 100% on duty */ +#define MAX77650_LED_B_DEFAULT GENMASK(3, 0) + +struct max77650_led { + struct led_classdev cdev; + struct regmap *map; + unsigned int regA; + unsigned int regB; +}; + +static struct max77650_led *max77650_to_led(struct led_classdev *cdev) +{ + return container_of(cdev, struct max77650_led, cdev); +} + +static int max77650_led_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct max77650_led *led = max77650_to_led(cdev); + int val, mask; + + mask = MAX77650_LED_BR_MASK | MAX77650_LED_EN_MASK; + + if (brightness == LED_OFF) + val = MAX77650_LED_DISABLE; + else + val = MAX77650_LED_ENABLE | brightness; + + return regmap_update_bits(led->map, led->regA, mask, val); +} + +static int max77650_led_probe(struct platform_device *pdev) +{ + struct device_node *of_node, *child; + struct max77650_led *leds, *led; + struct device *parent; + struct device *dev; + struct regmap *map; + const char *label; + int rv, num_leds; + u32 reg; + + dev = &pdev->dev; + parent = dev->parent; + of_node = dev->of_node; + + if (!of_node) + return -ENODEV; + + leds = devm_kcalloc(dev, sizeof(*leds), + MAX77650_LED_NUM_LEDS, GFP_KERNEL); + if (!leds) + return -ENOMEM; + + map = dev_get_regmap(dev->parent, NULL); + if (!map) + return -ENODEV; + + num_leds = of_get_child_count(of_node); + if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS) + return -ENODEV; + + for_each_child_of_node(of_node, child) { + rv = of_property_read_u32(child, "reg", ®); + if (rv || reg >= MAX77650_LED_NUM_LEDS) + return -EINVAL; + + led = &leds[reg]; + led->map = map; + led->regA = MAX77650_LED_A_BASE + reg; + led->regB = MAX77650_LED_B_BASE + reg; + led->cdev.brightness_set_blocking = max77650_led_brightness_set; + led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS; + + label = of_get_property(child, "label", NULL); + if (!label) { + led->cdev.name = "max77650::"; + } else { + led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, + "max77650:%s", label); + if (!led->cdev.name) + return -ENOMEM; + } + + of_property_read_string(child, "linux,default-trigger", + &led->cdev.default_trigger); + + rv = devm_of_led_classdev_register(dev, child, &led->cdev); + if (rv) + return rv; + + rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT); + if (rv) + return rv; + + rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT); + if (rv) + return rv; + } + + return regmap_write(map, + MAX77650_REG_CNFG_LED_TOP, + MAX77650_LED_TOP_DEFAULT); +} + +static struct platform_driver max77650_led_driver = { + .driver = { + .name = "max77650-led", + }, + .probe = max77650_led_probe, +}; +module_platform_driver(max77650_led_driver); + +MODULE_DESCRIPTION("MAXIM 77650/77651 LED driver"); +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_LICENSE("GPL v2"); -- 2.21.0