Skip to content

Commit 719e469

Browse files
Marek VasutKalle Valo
authored andcommitted
wifi: wilc1000: Clean up usage of wilc_get_chipid()
Reduce the use of wilc_get_chipid(), use cached chip ID wherever possible. Remove duplicated partial chip ID read implementations from the driver. Update wilc_get_chipid() to always read the chip ID out of the hardware and update the cached chip ID, and make it return a proper return value instead of a chipid. Call wilc_get_chipid() early to make the cached chip ID available to various sites using is_wilc1000() to access the cached chip ID. Reviewed-by: Alexis Lothoré <[email protected]> Signed-off-by: Marek Vasut <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 1b292a1 commit 719e469

File tree

5 files changed

+53
-49
lines changed

5 files changed

+53
-49
lines changed

drivers/net/wireless/microchip/wilc1000/netdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ static int wilc_wlan_get_firmware(struct net_device *dev)
195195
{
196196
struct wilc_vif *vif = netdev_priv(dev);
197197
struct wilc *wilc = vif->wilc;
198-
int chip_id;
199198
const struct firmware *wilc_fw;
200199
int ret;
201200

202-
chip_id = wilc_get_chipid(wilc, false);
201+
if (!is_wilc1000(wilc->chipid))
202+
return -EINVAL;
203203

204-
netdev_info(dev, "ChipID [%x] loading firmware [%s]\n", chip_id,
204+
netdev_info(dev, "WILC1000 loading firmware [%s]\n",
205205
WILC1000_FW(WILC1000_API_VER));
206206

207207
ret = request_firmware(&wilc_fw, WILC1000_FW(WILC1000_API_VER),

drivers/net/wireless/microchip/wilc1000/sdio.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ static int wilc_sdio_probe(struct sdio_func *func,
182182

183183
wilc_sdio_init(wilc, false);
184184

185+
ret = wilc_get_chipid(wilc);
186+
if (ret)
187+
goto dispose_irq;
188+
185189
ret = wilc_load_mac_from_nv(wilc);
186190
if (ret) {
187191
pr_err("Can not retrieve MAC address from chip\n");
@@ -667,7 +671,6 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume)
667671
struct wilc_sdio *sdio_priv = wilc->bus_data;
668672
struct sdio_cmd52 cmd;
669673
int loop, ret;
670-
u32 chipid;
671674

672675
/**
673676
* function 0 csa enable
@@ -756,18 +759,6 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume)
756759
return ret;
757760
}
758761

759-
/**
760-
* make sure can read back chip id correctly
761-
**/
762-
if (!resume) {
763-
ret = wilc_sdio_read_reg(wilc, WILC_CHIPID, &chipid);
764-
if (ret) {
765-
dev_err(&func->dev, "Fail cmd read chip id...\n");
766-
return ret;
767-
}
768-
dev_err(&func->dev, "chipid (%08x)\n", chipid);
769-
}
770-
771762
sdio_priv->isinit = true;
772763
return 0;
773764
}

drivers/net/wireless/microchip/wilc1000/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int wilc_bus_probe(struct spi_device *spi)
245245
if (ret)
246246
goto power_down;
247247

248-
ret = wilc_validate_chipid(wilc);
248+
ret = wilc_get_chipid(wilc);
249249
if (ret)
250250
goto power_down;
251251

drivers/net/wireless/microchip/wilc1000/wlan.c

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,19 +1402,50 @@ int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
14021402
return ret;
14031403
}
14041404

1405+
int wilc_get_chipid(struct wilc *wilc)
1406+
{
1407+
u32 chipid = 0;
1408+
u32 rfrevid = 0;
1409+
1410+
if (wilc->chipid == 0) {
1411+
wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &chipid);
1412+
wilc->hif_func->hif_read_reg(wilc, WILC_RF_REVISION_ID,
1413+
&rfrevid);
1414+
if (!is_wilc1000(chipid)) {
1415+
wilc->chipid = 0;
1416+
return -EINVAL;
1417+
}
1418+
if (chipid == WILC_1000_BASE_ID_2A) { /* 0x1002A0 */
1419+
if (rfrevid != 0x1)
1420+
chipid = WILC_1000_BASE_ID_2A_REV1;
1421+
} else if (chipid == WILC_1000_BASE_ID_2B) { /* 0x1002B0 */
1422+
if (rfrevid == 0x4)
1423+
chipid = WILC_1000_BASE_ID_2B_REV1;
1424+
else if (rfrevid != 0x3)
1425+
chipid = WILC_1000_BASE_ID_2B_REV2;
1426+
}
1427+
1428+
wilc->chipid = chipid;
1429+
}
1430+
1431+
return 0;
1432+
}
1433+
EXPORT_SYMBOL_GPL(wilc_get_chipid);
1434+
14051435
static int init_chip(struct net_device *dev)
14061436
{
1407-
u32 chipid;
14081437
u32 reg;
14091438
int ret = 0;
14101439
struct wilc_vif *vif = netdev_priv(dev);
14111440
struct wilc *wilc = vif->wilc;
14121441

14131442
acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
14141443

1415-
chipid = wilc_get_chipid(wilc, true);
1444+
ret = wilc_get_chipid(wilc);
1445+
if (ret)
1446+
goto release;
14161447

1417-
if ((chipid & 0xfff) != 0xa0) {
1448+
if ((wilc->chipid & 0xfff) != 0xa0) {
14181449
ret = wilc->hif_func->hif_read_reg(wilc,
14191450
WILC_CORTUS_RESET_MUX_SEL,
14201451
&reg);
@@ -1445,34 +1476,6 @@ static int init_chip(struct net_device *dev)
14451476
return ret;
14461477
}
14471478

1448-
u32 wilc_get_chipid(struct wilc *wilc, bool update)
1449-
{
1450-
u32 chipid = 0;
1451-
u32 rfrevid = 0;
1452-
1453-
if (wilc->chipid == 0 || update) {
1454-
wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &chipid);
1455-
wilc->hif_func->hif_read_reg(wilc, WILC_RF_REVISION_ID,
1456-
&rfrevid);
1457-
if (!is_wilc1000(chipid)) {
1458-
wilc->chipid = 0;
1459-
return wilc->chipid;
1460-
}
1461-
if (chipid == WILC_1000_BASE_ID_2A) { /* 0x1002A0 */
1462-
if (rfrevid != 0x1)
1463-
chipid = WILC_1000_BASE_ID_2A_REV1;
1464-
} else if (chipid == WILC_1000_BASE_ID_2B) { /* 0x1002B0 */
1465-
if (rfrevid == 0x4)
1466-
chipid = WILC_1000_BASE_ID_2B_REV1;
1467-
else if (rfrevid != 0x3)
1468-
chipid = WILC_1000_BASE_ID_2B_REV2;
1469-
}
1470-
1471-
wilc->chipid = chipid;
1472-
}
1473-
return wilc->chipid;
1474-
}
1475-
14761479
int wilc_load_mac_from_nv(struct wilc *wl)
14771480
{
14781481
int ret = -EINVAL;
@@ -1535,9 +1538,19 @@ int wilc_wlan_init(struct net_device *dev)
15351538
if (!wilc->hif_func->hif_is_init(wilc)) {
15361539
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
15371540
ret = wilc->hif_func->hif_init(wilc, false);
1541+
if (!ret)
1542+
ret = wilc_get_chipid(wilc);
15381543
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
15391544
if (ret)
15401545
goto fail;
1546+
1547+
if (!is_wilc1000(wilc->chipid)) {
1548+
netdev_err(dev, "Unsupported chipid: %x\n", wilc->chipid);
1549+
ret = -EINVAL;
1550+
goto fail;
1551+
}
1552+
1553+
netdev_dbg(dev, "chipid (%08x)\n", wilc->chipid);
15411554
}
15421555

15431556
if (!wilc->vmm_table)

drivers/net/wireless/microchip/wilc1000/wlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,6 @@ void chip_wakeup(struct wilc *wilc);
443443
int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
444444
u32 count);
445445
int wilc_wlan_init(struct net_device *dev);
446-
u32 wilc_get_chipid(struct wilc *wilc, bool update);
446+
int wilc_get_chipid(struct wilc *wilc);
447447
int wilc_load_mac_from_nv(struct wilc *wilc);
448448
#endif

0 commit comments

Comments
 (0)