Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/sdmmc Follow the Linux driver an use the FDT "compat...



details:   https://anonhg.NetBSD.org/src/rev/6a2859227d52
branches:  trunk
changeset: 967978:6a2859227d52
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Mon Dec 30 16:28:14 2019 +0000

description:
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.

E.g.

# ofctl -p /
[Caching 123 nodes and 1093 properties]
#address-cells          00000001 ........ ........ ........     1
#size-cells             00000001 ........ ........ ........     1
compatible              73696e6f 766f6970 2c627069 2d6d322d   "sinovoip,bpi-m2-
            0010:       7a65726f 00...... ........ ........   zero"
            0015:       616c6c77 696e6e65 722c7375 6e38692d   "allwinner,sun8i-
            0025:       68322d70 6c757300 ........ ........   h2-plus"
interrupt-parent        00000001 ........ ........ ........   ....
model                   42616e61 6e612050 69204250 492d4d32   "Banana Pi BPI-M2
            0010:       2d5a6572 6f00.... ........ ........   -Zero"
name                    00...... ........ ........ ........   ""
serial-number           30326330 30303432 65636431 36376566   02c00042ecd167ef
            0010:       00...... ........ ........ ........   .


-rw-r--r--  1 root  wheel     875 Nov  2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x  1 root  wheel      29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r--  1 root  wheel     874 Jun 30  2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r--  1 root  wheel    1864 Jun 30  2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x  1 root  wheel      29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt

diffstat:

 sys/dev/sdmmc/if_bwfm_sdio.c |  37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diffs (93 lines):

diff -r 1df5933b8234 -r 6a2859227d52 sys/dev/sdmmc/if_bwfm_sdio.c
--- a/sys/dev/sdmmc/if_bwfm_sdio.c      Mon Dec 30 16:19:27 2019 +0000
+++ b/sys/dev/sdmmc/if_bwfm_sdio.c      Mon Dec 30 16:28:14 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bwfm_sdio.c,v 1.9 2019/10/28 06:37:52 mlelstv Exp $ */
+/* $NetBSD: if_bwfm_sdio.c,v 1.10 2019/12/30 16:28:14 mlelstv Exp $ */
 /* $OpenBSD: if_bwfm_sdio.c,v 1.1 2017/10/11 17:19:50 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -116,6 +116,7 @@
 static int     bwfm_sdio_detach(device_t, int);
 static void    bwfm_sdio_attachhook(device_t);
 static int     bwfm_fdt_find_phandle(device_t, device_t);
+static const char *bwfm_fdt_get_model(void);
 
 static void    bwfm_sdio_backplane(struct bwfm_sdio_softc *, uint32_t);
 static uint8_t bwfm_sdio_read_1(struct bwfm_sdio_softc *, uint32_t);
@@ -377,7 +378,8 @@
        struct bwfm_sdio_softc *sc = device_private(self);
        struct bwfm_softc *bwfm = &sc->sc_sc;
        firmware_handle_t fwh;
-       const char *name, *nvname;
+       const char *name, *nvname, *model;
+       char *nvnamebuf;
        u_char *ucode, *nvram;
        size_t size, nvlen, nvsize;
        uint32_t reg, clk;
@@ -435,6 +437,21 @@
                goto err;
        }
 
+       /* compute a model specific filename for the NV config */
+       nvnamebuf = NULL;
+       model = bwfm_fdt_get_model();
+       if (model != NULL) {
+               /* assume nvname ends in ".txt" */
+               nvnamebuf = kmem_asprintf("%.*s.%s.txt",
+                   (int)(strlen(nvname) - 4),
+                   nvname, model);
+       }
+
+       aprint_verbose_dev(self, "Firmware       %s\n", name);
+       aprint_verbose_dev(self, "Default Config %s\n", nvname);
+       if (nvnamebuf != NULL)
+               aprint_verbose_dev(self, "Model Config   %s\n", nvnamebuf);
+
        if (firmware_open("if_bwfm", name, &fwh) != 0) {
                printf("%s: failed firmware_open of file %s\n",
                    DEVNAME(sc), name);
@@ -456,7 +473,8 @@
                goto err1;
        }
 
-       if (firmware_open("if_bwfm", nvname, &fwh) != 0) {
+       if ((nvnamebuf == NULL || firmware_open("if_bwfm", nvnamebuf, &fwh) != 0)
+           && firmware_open("if_bwfm", nvname, &fwh) != 0) {
                printf("%s: failed firmware_open of file %s\n",
                    DEVNAME(sc), nvname);
                goto err1;
@@ -492,6 +510,8 @@
 
        firmware_free(nvram, nvlen);
        firmware_free(ucode, size);
+       if (nvnamebuf != NULL)
+               kmem_free(nvnamebuf, strlen(nvnamebuf)+1);
 
        sdmmc_pause(hztoms(1)*1000, NULL);
 
@@ -565,6 +585,8 @@
        firmware_free(nvram, nvlen);
 err1:
        firmware_free(ucode, size);
+       if (nvnamebuf != NULL)
+               kmem_free(nvnamebuf, strlen(nvnamebuf)+1);
 err:
        return;
 }
@@ -603,6 +625,15 @@
        return phandle;
 }
 
+static const char *
+bwfm_fdt_get_model(void)
+{
+       int phandle;
+
+       phandle = OF_finddevice("/");
+       return fdtbus_get_string_index(phandle, "compatible", 0);
+}
+
 static int
 bwfm_sdio_detach(device_t self, int flags)
 {



Home | Main Index | Thread Index | Old Index