diff mbox series

[v2,08/35] brcmfmac: of: Fetch Apple properties

Message ID 20220104072658.69756-9-marcan@marcan.st (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series brcmfmac: Support Apple T2 and M1 platforms | expand

Commit Message

Hector Martin Jan. 4, 2022, 7:26 a.m. UTC
On Apple ARM64 platforms, firmware selection requires two properties
that come from system firmware: the module-instance (aka "island", a
codename representing a given hardware platform) and the antenna-sku.
We map Apple's module codenames to board_types in the form
"apple,<module-instance>".

The mapped board_type is added to the DTS file in that form, while the
antenna-sku is forwarded by our bootloader from the Apple Device Tree
into the FDT. Grab them from the DT so firmware selection can use
them.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hector Martin <marcan@marcan.st>
---
 .../wireless/broadcom/brcm80211/brcmfmac/common.h    |  1 +
 .../net/wireless/broadcom/brcm80211/brcmfmac/of.c    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Jan. 4, 2022, 11:17 a.m. UTC | #1
On Tue, Jan 4, 2022 at 9:28 AM Hector Martin <marcan@marcan.st> wrote:
>
> On Apple ARM64 platforms, firmware selection requires two properties
> that come from system firmware: the module-instance (aka "island", a
> codename representing a given hardware platform) and the antenna-sku.
> We map Apple's module codenames to board_types in the form
> "apple,<module-instance>".
>
> The mapped board_type is added to the DTS file in that form, while the
> antenna-sku is forwarded by our bootloader from the Apple Device Tree
> into the FDT. Grab them from the DT so firmware selection can use
> them.

> +       /* Apple ARM64 platforms have their own idea of board type, passed in
> +        * via the device tree. They also have an antenna SKU parameter
> +        */
> +       if (!of_property_read_string(np, "brcm,board-type", &prop))
> +               settings->board_type = devm_kstrdup(dev, prop, GFP_KERNEL);
> +
> +       if (!of_property_read_string(np, "apple,antenna-sku", &prop))
> +               settings->antenna_sku = devm_kstrdup(dev, prop, GFP_KERNEL);

No error checks?
But hold on, why do you need to copy them? Are you expecting this to be in DTO?
Hector Martin Jan. 7, 2022, 3:54 a.m. UTC | #2
On 2022/01/04 20:17, Andy Shevchenko wrote:
> On Tue, Jan 4, 2022 at 9:28 AM Hector Martin <marcan@marcan.st> wrote:
>>
>> On Apple ARM64 platforms, firmware selection requires two properties
>> that come from system firmware: the module-instance (aka "island", a
>> codename representing a given hardware platform) and the antenna-sku.
>> We map Apple's module codenames to board_types in the form
>> "apple,<module-instance>".
>>
>> The mapped board_type is added to the DTS file in that form, while the
>> antenna-sku is forwarded by our bootloader from the Apple Device Tree
>> into the FDT. Grab them from the DT so firmware selection can use
>> them.
> 
>> +       /* Apple ARM64 platforms have their own idea of board type, passed in
>> +        * via the device tree. They also have an antenna SKU parameter
>> +        */
>> +       if (!of_property_read_string(np, "brcm,board-type", &prop))
>> +               settings->board_type = devm_kstrdup(dev, prop, GFP_KERNEL);
>> +
>> +       if (!of_property_read_string(np, "apple,antenna-sku", &prop))
>> +               settings->antenna_sku = devm_kstrdup(dev, prop, GFP_KERNEL);
> 
> No error checks?
> But hold on, why do you need to copy them? Are you expecting this to be in DTO?

Yeah, I was wondering about that... indeed it shouldn't be necessary to
copy them.
Arend van Spriel Jan. 8, 2022, 8:03 p.m. UTC | #3
On 1/4/2022 8:26 AM, Hector Martin wrote:
> On Apple ARM64 platforms, firmware selection requires two properties
> that come from system firmware: the module-instance (aka "island", a
> codename representing a given hardware platform) and the antenna-sku.
> We map Apple's module codenames to board_types in the form
> "apple,<module-instance>".
> 
> The mapped board_type is added to the DTS file in that form, while the
> antenna-sku is forwarded by our bootloader from the Apple Device Tree
> into the FDT. Grab them from the DT so firmware selection can use
> them.
Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> ---
>   .../wireless/broadcom/brcm80211/brcmfmac/common.h    |  1 +
>   .../net/wireless/broadcom/brcm80211/brcmfmac/of.c    | 12 +++++++++++-
>   2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> index 8b5f49997c8b..d4aa25d646fe 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> @@ -50,6 +50,7 @@ struct brcmf_mp_device {
>   	bool		ignore_probe_fail;
>   	struct brcmfmac_pd_cc *country_codes;
>   	const char	*board_type;
> +	const char	*antenna_sku;
>   	union {
>   		struct brcmfmac_sdio_pd sdio;
>   	} bus;
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> index 513c7e6421b2..085d34176b78 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> @@ -63,14 +63,24 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
>   {
>   	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
>   	struct device_node *root, *np = dev->of_node;
> +	const char *prop;
>   	int irq;
>   	int err;
>   	u32 irqf;
>   	u32 val;
>   
> +	/* Apple ARM64 platforms have their own idea of board type, passed in
> +	 * via the device tree. They also have an antenna SKU parameter
> +	 */
> +	if (!of_property_read_string(np, "brcm,board-type", &prop))
> +		settings->board_type = devm_kstrdup(dev, prop, GFP_KERNEL);
> +
> +	if (!of_property_read_string(np, "apple,antenna-sku", &prop))
> +		settings->antenna_sku = devm_kstrdup(dev, prop, GFP_KERNEL);
> +
>   	/* Set board-type to the first string of the machine compatible prop */
>   	root = of_find_node_by_path("/");

I assume this only returns NULL when there is no device tree. Is that a 
safe assumption (Rob)? If so you could bail out here if root is NULL...

> -	if (root) {
> +	if (root && !settings->board_type) {

...and only check the board_type here. Or only check board_type and 
lookup the root node inside this if-statement if it is not needed 
elsewhere in this probe function.

>   		int i, len;
>   		char *board_type;
>   		const char *tmp;
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
index 8b5f49997c8b..d4aa25d646fe 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
@@ -50,6 +50,7 @@  struct brcmf_mp_device {
 	bool		ignore_probe_fail;
 	struct brcmfmac_pd_cc *country_codes;
 	const char	*board_type;
+	const char	*antenna_sku;
 	union {
 		struct brcmfmac_sdio_pd sdio;
 	} bus;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index 513c7e6421b2..085d34176b78 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -63,14 +63,24 @@  void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 {
 	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
 	struct device_node *root, *np = dev->of_node;
+	const char *prop;
 	int irq;
 	int err;
 	u32 irqf;
 	u32 val;
 
+	/* Apple ARM64 platforms have their own idea of board type, passed in
+	 * via the device tree. They also have an antenna SKU parameter
+	 */
+	if (!of_property_read_string(np, "brcm,board-type", &prop))
+		settings->board_type = devm_kstrdup(dev, prop, GFP_KERNEL);
+
+	if (!of_property_read_string(np, "apple,antenna-sku", &prop))
+		settings->antenna_sku = devm_kstrdup(dev, prop, GFP_KERNEL);
+
 	/* Set board-type to the first string of the machine compatible prop */
 	root = of_find_node_by_path("/");
-	if (root) {
+	if (root && !settings->board_type) {
 		int i, len;
 		char *board_type;
 		const char *tmp;