From patchwork Tue Nov 1 10:58:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 9407173 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6DF4B60721 for ; Tue, 1 Nov 2016 11:04:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F47E29823 for ; Tue, 1 Nov 2016 11:04:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63E7029825; Tue, 1 Nov 2016 11:04:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5665529823 for ; Tue, 1 Nov 2016 11:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1168879AbcKALEY (ORCPT ); Tue, 1 Nov 2016 07:04:24 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:33854 "EHLO outils.crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1168811AbcKALEX (ORCPT ); Tue, 1 Nov 2016 07:04:23 -0400 X-Greylist: delayed 327 seconds by postgrey-1.27 at vger.kernel.org; Tue, 01 Nov 2016 07:04:22 EDT From: Paul Cercueil To: Johannes Berg , "David S . Miller" , Rob Herring , Mark Rutland , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org Cc: Maarten ter Huurne , Paul Cercueil Subject: [PATCH 2/2] net: rfkill-regulator: Add devicetree support Date: Tue, 1 Nov 2016 11:58:40 +0100 Message-Id: <20161101105840.24313-2-paul@crapouillou.net> In-Reply-To: <20161101105840.24313-1-paul@crapouillou.net> References: <20161101105840.24313-1-paul@crapouillou.net> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1477997933; bh=Jbg7sDDjzKg+4hLDvZt8pnHVha03a1Co9eGf2uQR7Ic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=XkLKDpvDpF8Dz8TJm/hJW3O17OtdgCFxmb4reZc+iEhxv/nCKYQkd3pdmXiw4ULPADVG5G1YGD+3q4V2y5/22/9QqxheGOVNJ6/6c+F/eORj62Zzj95hbac3A8t+f1AeCuE0oZ61fB9JOdVr3NFkGZZFp+J0rbQdbwido98bK4s= Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit adds the support for probing the rfkill-regulator from devicetree. Information about the devicetree bindings can be found here: Documentation/devicetree/bindings/net/rfkill-regulator.txt Signed-off-by: Paul Cercueil --- net/rfkill/rfkill-regulator.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/net/rfkill/rfkill-regulator.c b/net/rfkill/rfkill-regulator.c index 50cd26a..29ded4c 100644 --- a/net/rfkill/rfkill-regulator.c +++ b/net/rfkill/rfkill-regulator.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -60,24 +61,38 @@ static struct rfkill_ops rfkill_regulator_ops = { static int rfkill_regulator_probe(struct platform_device *pdev) { struct rfkill_regulator_platform_data *pdata = pdev->dev.platform_data; + struct device_node *node = pdev->dev.of_node; struct rfkill_regulator_data *rfkill_data; struct regulator *vcc; struct rfkill *rf_kill; + const char *name; + u32 type; int ret = 0; - if (pdata == NULL) { + if (pdata) { + if (!pdata->name || !pdata->type) { + dev_err(&pdev->dev, "invalid name or type in platform data\n"); + return -EINVAL; + } + + name = pdata->name; + type = pdata->type; + } else if (node) { + ret = of_property_read_u32(node, "rfkill-type", &type); + if (ret < 0) + return ret; + + ret = of_property_read_string(node, "rfkill-name", &name); + if (ret < 0) + return ret; + } else { dev_err(&pdev->dev, "no platform data\n"); return -ENODEV; } - if (pdata->name == NULL || pdata->type == 0) { - dev_err(&pdev->dev, "invalid name or type in platform data\n"); - return -EINVAL; - } - vcc = regulator_get_exclusive(&pdev->dev, "vrfkill"); if (IS_ERR(vcc)) { - dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name); + dev_err(&pdev->dev, "Cannot get vcc for %s\n", name); ret = PTR_ERR(vcc); goto out; } @@ -88,9 +103,8 @@ static int rfkill_regulator_probe(struct platform_device *pdev) goto err_data_alloc; } - rf_kill = rfkill_alloc(pdata->name, &pdev->dev, - pdata->type, - &rfkill_regulator_ops, rfkill_data); + rf_kill = rfkill_alloc(name, &pdev->dev, type, + &rfkill_regulator_ops, rfkill_data); if (rf_kill == NULL) { ret = -ENOMEM; goto err_rfkill_alloc; @@ -110,7 +124,7 @@ static int rfkill_regulator_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, rfkill_data); - dev_info(&pdev->dev, "%s initialized\n", pdata->name); + dev_info(&pdev->dev, "%s initialized\n", name); return 0; @@ -137,11 +151,18 @@ static int rfkill_regulator_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id rfkill_regulator_of_match[] = { + { .compatible = "rfkill-regulator" }, + {}, +}; +MODULE_DEVICE_TABLE(of, rfkill_regulator_of_match); + static struct platform_driver rfkill_regulator_driver = { .probe = rfkill_regulator_probe, .remove = rfkill_regulator_remove, .driver = { .name = "rfkill-regulator", + .of_match_table = of_match_ptr(rfkill_regulator_of_match), }, };