wilc1000: invoke chip reset register before firmware download
authorAjay Singh <ajay.kathat@microchip.com>
Thu, 16 Sep 2021 16:49:21 +0000 (16:49 +0000)
committerKalle Valo <kvalo@codeaurora.org>
Tue, 21 Sep 2021 15:08:17 +0000 (18:08 +0300)
Add the chip reset command to initialize the WILC chip before downloading
the firmware. Also, put the chip in wake-up mode so it is ready to receive
the firmware binary from the host.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210916164902.74629-9-ajay.kathat@microchip.com
drivers/net/wireless/microchip/wilc1000/wlan.c

index f9256c1..de5287c 100644 (file)
@@ -1080,6 +1080,7 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
        u32 addr, size, size2, blksz;
        u8 *dma_buffer;
        int ret = 0;
+       u32 reg = 0;
 
        blksz = BIT(12);
 
@@ -1088,10 +1089,22 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
                return -EIO;
 
        offset = 0;
+       pr_debug("%s: Downloading firmware size = %d\n", __func__, buffer_size);
+
+       acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
+
+       wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
+       reg &= ~BIT(10);
+       ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
+       wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
+       if (reg & BIT(10))
+               pr_err("%s: Failed to reset\n", __func__);
+
+       release_bus(wilc, WILC_BUS_RELEASE_ONLY);
        do {
                addr = get_unaligned_le32(&buffer[offset]);
                size = get_unaligned_le32(&buffer[offset + 4]);
-               acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
+               acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
                offset += 8;
                while (((int)size) && (offset < buffer_size)) {
                        if (size <= blksz)
@@ -1109,10 +1122,13 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
                        offset += size2;
                        size -= size2;
                }
-               release_bus(wilc, WILC_BUS_RELEASE_ONLY);
+               release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 
-               if (ret)
+               if (ret) {
+                       pr_err("%s Bus error\n", __func__);
                        goto fail;
+               }
+               pr_debug("%s Offset = %d\n", __func__, offset);
        } while (offset < buffer_size);
 
 fail: