From patchwork Sat Apr 17 07:54:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 423409 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp1036706jaf; Sat, 17 Apr 2021 00:54:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOMQjzHoNBs8BWtBXuwFZ+hKWLKehRt1Kp2MSuu7xXDpNhv/58zHCdD2ZqHAFgJb7PJ9gK X-Received: by 2002:a17:90b:228a:: with SMTP id kx10mr14115759pjb.105.1618646086258; Sat, 17 Apr 2021 00:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618646086; cv=none; d=google.com; s=arc-20160816; b=JlcF+X9/dc3I4UfLtAuZzRwNKTwSbt5RctQMinwdZCeQ5IEAwfhTlSqoxA52eSHeYX R13vAgxtPzA0P6RNdv4NNV/YfByOvVEPCUu3aCoXkh+xq973auB2NhJgbdm1wZ+yLG1v kFfx9vGYWMAWpDie0A/oRWPYlEOMawS09szNvoajevq++Txm3Jsgb9I73K80ctE41aAe Qj26hWnepXTk1PEAWyJ7+RhWaV5gLAv/fJXjseYveZQ0+RwLwQZyYQ6oYjXHe8LIcH64 +PWMvhipvh+TGCS+Gwn/oMBAgEaj9FrGVE3nLy5X2WYuhGbXR9QpYOQFq+d3Iz5mNZCh 003g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=kyDOfNlO5v5BNocRUhW3soIeQiOs29dwPp3e5LBPghA=; b=YUcrXbSFuIiUJ1JBG9RuCpvGBuxf5fpfdPFthz/l8exj57Fm73L87N3gyu3wtYXonE FMPMyfCM5CX3u8efvDZ6FnNTn7i3hGJIKAYSTWCXyHg33dJIkhgidgUDo+NOsCn8ADqr T2ZU7qjW8G5qicpeWsSS6wVX0sZrypvCi7X02uYj64CLkUMEOaQO8n7Or8cvbV7OXgU5 uxU1ZbJ+Zz01rXIEbGPMoZO6GdETlGt8ReE5a6n4cmR5nsbWZpOy/4N/SLTh2BIybwuD P09aa/EJhWswUBsCOsorWNVhrmXRLl77XiqfKl1h+KzmM1uJ0AGF/4ixUmj7oDdxPFL4 uUVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZpSz0nHB; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k136si11996978pgc.155.2021.04.17.00.54.46; Sat, 17 Apr 2021 00:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZpSz0nHB; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235968AbhDQHzL (ORCPT + 6 others); Sat, 17 Apr 2021 03:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbhDQHzK (ORCPT ); Sat, 17 Apr 2021 03:55:10 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E6CBC061574 for ; Sat, 17 Apr 2021 00:54:44 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id e8-20020a17090a7288b029014e51f5a6baso10610669pjg.2 for ; Sat, 17 Apr 2021 00:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=kyDOfNlO5v5BNocRUhW3soIeQiOs29dwPp3e5LBPghA=; b=ZpSz0nHBHKx6SCNZijL6Y+WXj9cWQ4MoEeV3tf+u0cLeL3es/YPptsX/GJzjPfEdwJ zOtUqAXSKu4afgcZx79N08Iw0CxTQmubHheJdCzYUhBhTN3u/Ol1F03/0CznvmbfS+hM rPSdfIMM+/HrizcMi9p7aI6+1Lo/K4u0vTENzexJOtyt8JgE0B5Wz1ipZp1r2NaYnqIv iViO1gBP1AWenpyRCC6jTJYj7qyHLQjfxKpfWf83YKOlPloY4/SLWLyEwkkduXH68u2K SSJtIqCtkhiqq3jT3Q9v0fQACscFnP4VAiMTF+nh9WX5a3LvtqV/htu6vmTeH94LxeDu Qgcg== 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; bh=kyDOfNlO5v5BNocRUhW3soIeQiOs29dwPp3e5LBPghA=; b=trD6s8aagAe9mnpOZByL/SkZMN9w/SI5YfEEYQ3LqR0fEhN5aOcnDVqNJ0TovvToie tww9oXOldMk5ZAZXSOTl0nYGWQ/9pSBR9E8j3wO08cDBg2YdrXNL4Dk1UHe2ynDQWHE2 Ye7IYw5dB3S2pk6nI35Q8K/ZXnYFFWtaWvsnN5I4ftSv6+7zVTxpiwaNm8a0UaUirLwb v3S4gMVyQKyTd5VdMqoY8SstCKSonzuVgQE7v20NyvGwtOvY3OhK/kxXaU71e14E+iKB 4EA3XbbxHv5nVwYoFTH/PhKbc6iZHASjNMhdipL4GTqUIMVSAMiaXp5FLqo6Qrl9zCeB hfjQ== X-Gm-Message-State: AOAM533nO+NIrhNZdIDYoxyvxzsWw3XIEhZdfG23TlsvrVk50iXHVioS LSuzXHxq6D7EQIa7E66PIisz1g== X-Received: by 2002:a17:90a:6385:: with SMTP id f5mr13821314pjj.212.1618646084083; Sat, 17 Apr 2021 00:54:44 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id w75sm7087179pfc.135.2021.04.17.00.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Apr 2021 00:54:43 -0700 (PDT) From: Shawn Guo To: Kalle Valo Cc: Rob Herring , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Arend van Spriel , Franky Lin , Hante Meuleman , Chi-hsien Lin , Wright Feng , Chung-hsien Hsu , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, Shawn Guo Subject: [PATCH v3] brcmfmac: support parse country code map from DT Date: Sat, 17 Apr 2021 15:54:28 +0800 Message-Id: <20210417075428.2671-1-shawn.guo@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org With any regulatory domain requests coming from either user space or 802.11 IE (Information Element), the country is coded in ISO3166 standard. It needs to be translated to firmware country code and revision with the mapping info in settings->country_codes table. Support populate country_codes table by parsing the mapping from DT. The BRCMF_BUSTYPE_SDIO bus_type check gets separated from general DT validation, so that country code can be handled as general part rather than SDIO bus specific one. Signed-off-by: Shawn Guo Reviewed-by: Arend van Spriel --- Changes for v3: - Add missing terminating '\n' in brcmf_dbg(INFO, ...) format string. .../wireless/broadcom/brcm80211/brcmfmac/of.c | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c index a7554265f95f..2f7bc3a70c65 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c @@ -12,12 +12,59 @@ #include "common.h" #include "of.h" +static int brcmf_of_get_country_codes(struct device *dev, + struct brcmf_mp_device *settings) +{ + struct device_node *np = dev->of_node; + struct brcmfmac_pd_cc_entry *cce; + struct brcmfmac_pd_cc *cc; + int count; + int i; + + count = of_property_count_strings(np, "brcm,ccode-map"); + if (count < 0) { + /* The property is optional, so return success if it doesn't + * exist. Otherwise propagate the error code. + */ + return (count == -EINVAL) ? 0 : count; + } + + cc = devm_kzalloc(dev, sizeof(*cc) + count * sizeof(*cce), GFP_KERNEL); + if (!cc) + return -ENOMEM; + + cc->table_size = count; + + for (i = 0; i < count; i++) { + const char *map; + + cce = &cc->table[i]; + + if (of_property_read_string_index(np, "brcm,ccode-map", + i, &map)) + continue; + + /* String format e.g. US-Q2-86 */ + if (sscanf(map, "%2c-%2c-%d", cce->iso3166, cce->cc, + &cce->rev) != 3) + brcmf_err("failed to read country map %s\n", map); + else + brcmf_dbg(INFO, "%s-%s-%d\n", cce->iso3166, cce->cc, + cce->rev); + } + + settings->country_codes = cc; + + return 0; +} + void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type, struct brcmf_mp_device *settings) { struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio; struct device_node *root, *np = dev->of_node; int irq; + int err; u32 irqf; u32 val; @@ -43,8 +90,14 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type, of_node_put(root); } - if (!np || bus_type != BRCMF_BUSTYPE_SDIO || - !of_device_is_compatible(np, "brcm,bcm4329-fmac")) + if (!np || !of_device_is_compatible(np, "brcm,bcm4329-fmac")) + return; + + err = brcmf_of_get_country_codes(dev, settings); + if (err) + brcmf_err("failed to get OF country code map (err=%d)\n", err); + + if (bus_type != BRCMF_BUSTYPE_SDIO) return; if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)