From patchwork Sun Oct 2 22:50:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9359837 X-Patchwork-Delegate: kvalo@adurom.com 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 8C9C9601C0 for ; Sun, 2 Oct 2016 22:51:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A011289FA for ; Sun, 2 Oct 2016 22:51:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EF4028A24; Sun, 2 Oct 2016 22:51:17 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 DB017289FA for ; Sun, 2 Oct 2016 22:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752111AbcJBWvM (ORCPT ); Sun, 2 Oct 2016 18:51:12 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33511 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbcJBWvK (ORCPT ); Sun, 2 Oct 2016 18:51:10 -0400 Received: by mail-wm0-f66.google.com with SMTP id p138so12055901wmb.0; Sun, 02 Oct 2016 15:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EMBikZKAvb/yIAxYPjAhIuDliulePPMxzZ+vKtEvb5s=; b=NzKDq6FmUqoOFnpNs+3UeWH3UqijqL59Z/GGpWAI1GIlWoj3ibEti2yROXxxNb8uD+ MlR/b3hntd4jLyISmYQPcYkM0Cd+QIbZUFOkBcoeWer8Fu1eK7kyIUavvCO4vL7lxq1V 72xVVXUXFjGYvSlyWaMPjKT8cMrdWGhNrFr/iqouq7g1Mszbr85U8JDaXkh/aUgqFThl JzMW23pmTNocQRUHLmfJVqXn+uEgSUIo4wMZN3SBFquLxgv/jDVDrVthXrko12h4BMU8 S44TvK5WUvd4GUd46wcEfsXLIJ1xWmQrEVw7Qt4STiGgXSPw2zpsBfZsqbhQtFBYIKaB VbNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EMBikZKAvb/yIAxYPjAhIuDliulePPMxzZ+vKtEvb5s=; b=mH2fu5LxiGEtXi+RXoqoLRV3qR/WQqrrahT+B/pvU4r45oXEyTQPN+rNFCTtmr3X15 qLsq9dmTagy1QqQE9tfAY8E7OKneje1h4P9FSpiQv0miVfmC9xqz0kKtWGNRrXkZ88Ic es2hlDXOVO1pdz3Kx97GihfNqrjPFqmFaXj48kZXbRYKmoeJG2QafJrNVb8KCejBMMb2 Eyg/l+1FhRKdBOi3mAwnwlIKUL/aWqRp833F+DpPkE9CBr22rVS4mA+bUknF6AzYHWVJ JqjSudylrdzmf78xRRwAcWP1U04utbGYNxAXqGy0ws5U3p+HUjFo4Qvt4C+zqHU5tzmv i3Vg== X-Gm-Message-State: AA6/9Rkjac6ucMHNMOmRnUwqEZxBuonNTuXSfBr7nHcmSEM1Gx5wCEtZL/AdspezGcj3VA== X-Received: by 10.28.158.2 with SMTP id h2mr7977729wme.48.1475448668263; Sun, 02 Oct 2016 15:51:08 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3D4610440DF0B34A14E22AB.dip0.t-ipconnect.de. [2003:dc:d3d4:6104:40df:b34:a14e:22ab]) by smtp.googlemail.com with ESMTPSA id l206sm15868863wmf.15.2016.10.02.15.51.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Oct 2016 15:51:07 -0700 (PDT) From: Martin Blumenstingl To: robh+dt@kernel.org, mark.rutland@arm.com, frowand.list@gmail.com, devicetree@vger.kernel.org, nbd@nbd.name Cc: linux-wireless@vger.kernel.org, ath9k-devel@qca.qualcomm.com, ath9k-devel@lists.ath9k.org, kvalo@codeaurora.org, Martin Blumenstingl Subject: [RFC 2/3] of: add IEEE 802.11 device configuration support code Date: Mon, 3 Oct 2016 00:50:58 +0200 Message-Id: <20161002225059.16757-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161002225059.16757-1-martin.blumenstingl@googlemail.com> References: <20161002225059.16757-1-martin.blumenstingl@googlemail.com> 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 Add support for parsing the device tree of IEEE 802.11 devices. Some drivers (for example ath9k) already have custom platform_data code to enable/disable specific bands. There are some other drivers (for example the currently out-of-tree mt76 driver) which need similar logic. Thus we provide a generic implementation for IEEE 802.11 device configuration OF properties, which can be used by all drivers. Signed-off-by: Martin Blumenstingl --- drivers/of/Kconfig | 4 +++ drivers/of/Makefile | 1 + drivers/of/of_ieee80211.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_ieee80211.h | 38 ++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 drivers/of/of_ieee80211.c create mode 100644 include/linux/of_ieee80211.h diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index bc07ad3..3ef5e12 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -116,4 +116,8 @@ config OF_OVERLAY config OF_NUMA bool +config OF_IEEE80211 + depends on CFG80211 || WLAN + def_bool y + endif # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index d7efd9d..00bd746 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -14,5 +14,6 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_OF_IEEE80211) += of_ieee80211.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/of_ieee80211.c b/drivers/of/of_ieee80211.c new file mode 100644 index 0000000..f529058 --- /dev/null +++ b/drivers/of/of_ieee80211.c @@ -0,0 +1,83 @@ +/* + * OF helpers for IEEE 802.11 devices. + * + * Copyright (C) 2016 Martin Blumenstingl + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * This file contains the code used to make IRQ descriptions in the + * device tree to actual irq numbers on an interrupt controller + * driver. + */ +#include +#include +#include + +/** + * of_ieee80211_is_2ghz_enabled - Check if the IEEE 802.11 2.4GHz frequency + * band is enabled for the given device_node + * @np: Pointer to the given device_node + * + * When the the 2.4GHz band is defined in an conflicting state (both enabled + * and disabled are set) then we leave it disabled. + */ +bool of_ieee80211_is_2ghz_enabled(struct device_node *np) +{ + bool enabled = of_property_read_bool(np, "enable-ieee80211-2ghz"); + + if (enabled && of_ieee80211_is_2ghz_disabled(np)) { + pr_err("%s: conflicting configuration for the 2.4GHz band\n", + of_node_full_name(np)); + return false; + } + + return enabled; +} +EXPORT_SYMBOL(of_ieee80211_is_2ghz_enabled); + +/** + * of_ieee80211_is_5ghz_enabled - Check if the IEEE 802.11 5GHz frequency band + * is enabled for the given device_node + * @np: Pointer to the given device_node + * + * When the the 5GHz band is defined in an conflicting state (both enabled + * and disabled are set) then we leave it disabled. + */ +bool of_ieee80211_is_5ghz_enabled(struct device_node *np) +{ + bool enabled = of_property_read_bool(np, "enable-ieee80211-5ghz"); + + if (enabled && of_ieee80211_is_2ghz_disabled(np)) { + pr_err("%s: conflicting configuration for the 5GHz band\n", + of_node_full_name(np)); + return false; + } + + return enabled; +} +EXPORT_SYMBOL(of_ieee80211_is_5ghz_enabled); + +/** + * of_ieee80211_is_2ghz_disabled - Check if the IEEE 802.11 2.4GHz frequency + * band is disabled for the given device_node + * @np: Pointer to the given device_node + */ +bool of_ieee80211_is_2ghz_disabled(struct device_node *np) +{ + return of_property_read_bool(np, "disable-ieee80211-2ghz"); +} +EXPORT_SYMBOL(of_ieee80211_is_2ghz_disabled); + +/** + * of_ieee80211_is_5ghz_disabled - Check if the IEEE 802.11 5GHz frequency + * band is disabled for the given device_node + * @np: Pointer to the given device_node + */ +bool of_ieee80211_is_5ghz_disabled(struct device_node *np) +{ + return of_property_read_bool(np, "disable-ieee80211-5ghz"); +} +EXPORT_SYMBOL(of_ieee80211_is_5ghz_disabled); diff --git a/include/linux/of_ieee80211.h b/include/linux/of_ieee80211.h new file mode 100644 index 0000000..a25a66e --- /dev/null +++ b/include/linux/of_ieee80211.h @@ -0,0 +1,38 @@ +#ifndef __OF_IEEE80211_H +#define __OF_IEEE80211_H + +struct device_node; + +#ifdef CONFIG_OF_IEEE80211 + +bool of_ieee80211_is_2ghz_enabled(struct device_node *np); +bool of_ieee80211_is_5ghz_enabled(struct device_node *np); + +bool of_ieee80211_is_2ghz_disabled(struct device_node *np); +bool of_ieee80211_is_5ghz_disabled(struct device_node *np); + +#else /* CONFIG_OF_IEEE80211 */ + +static inline bool of_ieee80211_is_2ghz_enabled(struct device_node *np) +{ + return false; +} + +static inline bool of_ieee80211_is_5ghz_enabled(struct device_node *np) +{ + return false; +} + +static inline bool of_ieee80211_is_2ghz_disabled(struct device_node *np) +{ + return false; +} + +static inline bool of_ieee80211_is_5ghz_disabled(struct device_node *np) +{ + return false; +} + +#endif /* CONFIG_OF_IEEE80211 */ + +#endif /* __OF_IEEE80211_H */