Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 04cea11

Browse files
vdsaogregkh
authored andcommitted
net: dsa: lan9303: ensure chip reset and wait for READY status
commit 5c14e51 upstream. Accessing device registers seems to be not reliable, the chip revision is sometimes detected wrongly (0 instead of expected 1). Ensure that the chip reset is performed via reset GPIO and then wait for 'Device Ready' status in HW_CFG register before doing any register initializations. Cc: stable@vger.kernel.org Fixes: a129259 ("net: dsa: add new DSA switch driver for the SMSC-LAN9303") Signed-off-by: Anatolij Gustschin <agust@denx.de> [alex: reworked using read_poll_timeout()] Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com> Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Link: https://patch.msgid.link/20241004113655.3436296-1-alexander.sverdlin@siemens.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 49f9b72 commit 04cea11

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/net/dsa/lan9303-core.c

+29
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/module.h>
77
#include <linux/gpio/consumer.h>
88
#include <linux/regmap.h>
9+
#include <linux/iopoll.h>
910
#include <linux/mutex.h>
1011
#include <linux/mii.h>
1112
#include <linux/of.h>
@@ -839,6 +840,8 @@ static void lan9303_handle_reset(struct lan9303 *chip)
839840
if (!chip->reset_gpio)
840841
return;
841842

843+
gpiod_set_value_cansleep(chip->reset_gpio, 1);
844+
842845
if (chip->reset_duration != 0)
843846
msleep(chip->reset_duration);
844847

@@ -864,8 +867,34 @@ static int lan9303_disable_processing(struct lan9303 *chip)
864867
static int lan9303_check_device(struct lan9303 *chip)
865868
{
866869
int ret;
870+
int err;
867871
u32 reg;
868872

873+
/* In I2C-managed configurations this polling loop will clash with
874+
* switch's reading of EEPROM right after reset and this behaviour is
875+
* not configurable. While lan9303_read() already has quite long retry
876+
* timeout, seems not all cases are being detected as arbitration error.
877+
*
878+
* According to datasheet, EEPROM loader has 30ms timeout (in case of
879+
* missing EEPROM).
880+
*
881+
* Loading of the largest supported EEPROM is expected to take at least
882+
* 5.9s.
883+
*/
884+
err = read_poll_timeout(lan9303_read, ret,
885+
!ret && reg & LAN9303_HW_CFG_READY,
886+
20000, 6000000, false,
887+
chip->regmap, LAN9303_HW_CFG, &reg);
888+
if (ret) {
889+
dev_err(chip->dev, "failed to read HW_CFG reg: %pe\n",
890+
ERR_PTR(ret));
891+
return ret;
892+
}
893+
if (err) {
894+
dev_err(chip->dev, "HW_CFG not ready: 0x%08x\n", reg);
895+
return err;
896+
}
897+
869898
ret = lan9303_read(chip->regmap, LAN9303_CHIP_REV, &reg);
870899
if (ret) {
871900
dev_err(chip->dev, "failed to read chip revision register: %d\n",

0 commit comments

Comments
 (0)