From patchwork Thu Oct 3 08:28:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 175060 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1882255ill; Thu, 3 Oct 2019 01:28:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqznfjGw56K8TbTzpVTW7tp7bLWlQsb1ojie+Kt4EFC5R+EXpDt+yS2YcvHm4Tuk1daLt6TS X-Received: by 2002:a17:90a:8e84:: with SMTP id f4mr9308660pjo.122.1570091312936; Thu, 03 Oct 2019 01:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570091312; cv=none; d=google.com; s=arc-20160816; b=mTQNQbOUacocMyIlG51ZberLzN+gNAiFTPiqVB0abuihyvFfX92hbctGeBqvsgBvhQ SefdU+VjdJl6eBLFcLYZvjx9n+mW5TzIF8scMEbp0U4dhkbtdA/HQ+jzxiRS+aolvbig xGvU9CCQI1uMKWnzI/nyZQjqegy5cpk5u+ub3/uQCNclIOGxbHi0DLpQkchsiCSs99B+ g433pkQyUchY+rTwIa4MNldOGcsJbxlVelmKm6aRIGuYdVorZPGfWBixyPvSNnmXO+tP cdeoOCPIW2ZFwpNypoXAHXjsuFTBPHhgDzOgY+TNnJxA/fNHKi2LfVIeFl0owgV4jODX jMCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=4IqUxOOiWTKAPQnO2Lr4r6IetxxjJxO1HpYY8jA9RSE=; b=YeWDvCZpuACjDvPj+gmf7NI7uW6eMUYdzNzB6drFsWgNV/1F4NIQMKTSEIEUYEayFl 3MUX4lIEzkTcoI2YDuEuUmaNIDOeD/8mgkZnJaitnbWFt5QKgUJrCSuT9LwB/udHo8VI O+2yJWwVAhGh7OeoQu3VIu1uDPohTUNboFxq1VtuDGKgH1793+faZnOnrgm0/BhjPxPN a8A+ryhD3AYAsZfr/76cN6okp9bfGgE4Ecjh6F/0lx64948OZ+1uch5FjWbOVoT6mDss sTWCv82JtEF4vGQTkhcoMi8BKxAGGPbkzqoL5FP7V39LBcM/5Gp3W1iOLqeqe+3ZABTz OvGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 65si1846088plf.242.2019.10.03.01.28.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Oct 2019 01:28:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C2DB6E962; Thu, 3 Oct 2019 08:28:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1C536E889 for ; Thu, 3 Oct 2019 08:28:28 +0000 (UTC) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x938SLgb086242; Thu, 3 Oct 2019 03:28:21 -0500 Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x938SLKH126572 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 3 Oct 2019 03:28:21 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Thu, 3 Oct 2019 03:28:21 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Thu, 3 Oct 2019 03:28:21 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x938SKoB082944; Thu, 3 Oct 2019 03:28:21 -0500 From: Jean-Jacques Hiblot To: , , , , , Subject: [PATCH v8 2/5] leds: Add of_led_get() and led_put() Date: Thu, 3 Oct 2019 10:28:09 +0200 Message-ID: <20191003082812.28491-3-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003082812.28491-1-jjhiblot@ti.com> References: <20191003082812.28491-1-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570091302; bh=yyKxKbudwxLXBSDguFTMwG1Eg09KWJYS2pNsYIzkHKo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=gudradjfj+O7Qb2WhJoH6cCDEZWElgyiQ1eB3T//DV6rsA8EMqwrVYSqus+RdYTlw 4pAFjy69Dc7aBvt9yVpr3+u4W1tOjYv7pPrsbaqmlPK/zL9+kjGVAR5Hs8fBuf0plG F5LPLASVjiz5Xa6mGUDNoC2VTCiKuZGaPEzZ5HGw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, tomi.valkeinen@ti.com, dmurphy@ti.com, Jean-Jacques Hiblot , linux-leds@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomi Valkeinen This patch adds basic support for a kernel driver to get a LED device. This will be used by the led-backlight driver. Only OF version is implemented for now, and the behavior is similar to PWM's of_pwm_get() and pwm_put(). Signed-off-by: Tomi Valkeinen Signed-off-by: Jean-Jacques Hiblot Acked-by: Pavel Machek --- drivers/leds/led-class.c | 44 ++++++++++++++++++++++++++++++++++++++++ include/linux/leds.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index c2167b66b61f..455545f5d663 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "leds.h" static struct class *leds_class; @@ -214,6 +215,49 @@ static int led_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume); +/** + * of_led_get() - request a LED device via the LED framework + * @np: device node to get the LED device from + * @index: the index of the LED + * + * Returns the LED device parsed from the phandle specified in the "leds" + * property of a device tree node or a negative error-code on failure. + */ +struct led_classdev *of_led_get(struct device_node *np, int index) +{ + struct device *led_dev; + struct led_classdev *led_cdev; + struct device_node *led_node; + + led_node = of_parse_phandle(np, "leds", index); + if (!led_node) + return ERR_PTR(-ENOENT); + + led_dev = class_find_device_by_of_node(leds_class, led_node); + of_node_put(led_node); + + if (!led_dev) + return ERR_PTR(-EPROBE_DEFER); + + led_cdev = dev_get_drvdata(led_dev); + + if (!try_module_get(led_cdev->dev->parent->driver->owner)) + return ERR_PTR(-ENODEV); + + return led_cdev; +} +EXPORT_SYMBOL_GPL(of_led_get); + +/** + * led_put() - release a LED device + * @led_cdev: LED device + */ +void led_put(struct led_classdev *led_cdev) +{ + module_put(led_cdev->dev->parent->driver->owner); +} +EXPORT_SYMBOL_GPL(led_put); + static int led_classdev_next_name(const char *init_name, char *name, size_t len) { diff --git a/include/linux/leds.h b/include/linux/leds.h index b8df71193329..6f7371bc7757 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -20,6 +20,7 @@ struct device; struct led_pattern; +struct device_node; /* * LED Core */ @@ -196,6 +197,9 @@ extern void devm_led_classdev_unregister(struct device *parent, extern void led_classdev_suspend(struct led_classdev *led_cdev); extern void led_classdev_resume(struct led_classdev *led_cdev); +extern struct led_classdev *of_led_get(struct device_node *np, int index); +extern void led_put(struct led_classdev *led_cdev); + /** * led_blink_set - set blinking with software fallback * @led_cdev: the LED to start blinking