diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2014-03-28 06:14:46 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2014-04-24 16:54:15 -0400 |
commit | ee967fffd91031f18dbe36bf6a273d8a75f663cf (patch) | |
tree | 4b503a52143461c679e0df9c40122b04a976b903 | |
parent | ff06d611a31c4b687c7859e3c7516a38194d4d25 (diff) |
can: mcp251x: Improve mcp251x_hw_probe()
This patch adds check for mcp251x_hw_reset() result on startup and
removes unnecessary checking for CANSTAT register since this value
is being checked in mcp251x_hw_reset().
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Tested-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | drivers/net/can/mcp251x.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c index 9a8fd9456979..bc235f9dc754 100644 --- a/drivers/net/can/mcp251x.c +++ b/drivers/net/can/mcp251x.c | |||
@@ -649,23 +649,22 @@ static int mcp251x_hw_reset(struct spi_device *spi) | |||
649 | 649 | ||
650 | static int mcp251x_hw_probe(struct spi_device *spi) | 650 | static int mcp251x_hw_probe(struct spi_device *spi) |
651 | { | 651 | { |
652 | int st1, st2; | 652 | u8 ctrl; |
653 | int ret; | ||
653 | 654 | ||
654 | mcp251x_hw_reset(spi); | 655 | ret = mcp251x_hw_reset(spi); |
656 | if (ret) | ||
657 | return ret; | ||
655 | 658 | ||
656 | /* | 659 | ctrl = mcp251x_read_reg(spi, CANCTRL); |
657 | * Please note that these are "magic values" based on after | 660 | |
658 | * reset defaults taken from data sheet which allows us to see | 661 | dev_dbg(&spi->dev, "CANCTRL 0x%02x\n", ctrl); |
659 | * if we really have a chip on the bus (we avoid common all | ||
660 | * zeroes or all ones situations) | ||
661 | */ | ||
662 | st1 = mcp251x_read_reg(spi, CANSTAT) & 0xEE; | ||
663 | st2 = mcp251x_read_reg(spi, CANCTRL) & 0x17; | ||
664 | 662 | ||
665 | dev_dbg(&spi->dev, "CANSTAT 0x%02x CANCTRL 0x%02x\n", st1, st2); | 663 | /* Check for power up default value */ |
664 | if ((ctrl & 0x17) != 0x07) | ||
665 | return -ENODEV; | ||
666 | 666 | ||
667 | /* Check for power up default values */ | 667 | return 0; |
668 | return (st1 == 0x80 && st2 == 0x07) ? 1 : 0; | ||
669 | } | 668 | } |
670 | 669 | ||
671 | static int mcp251x_power_enable(struct regulator *reg, int enable) | 670 | static int mcp251x_power_enable(struct regulator *reg, int enable) |
@@ -1142,10 +1141,10 @@ static int mcp251x_can_probe(struct spi_device *spi) | |||
1142 | SET_NETDEV_DEV(net, &spi->dev); | 1141 | SET_NETDEV_DEV(net, &spi->dev); |
1143 | 1142 | ||
1144 | /* Here is OK to not lock the MCP, no one knows about it yet */ | 1143 | /* Here is OK to not lock the MCP, no one knows about it yet */ |
1145 | if (!mcp251x_hw_probe(spi)) { | 1144 | ret = mcp251x_hw_probe(spi); |
1146 | ret = -ENODEV; | 1145 | if (ret) |
1147 | goto error_probe; | 1146 | goto error_probe; |
1148 | } | 1147 | |
1149 | mcp251x_hw_sleep(spi); | 1148 | mcp251x_hw_sleep(spi); |
1150 | 1149 | ||
1151 | ret = register_candev(net); | 1150 | ret = register_candev(net); |
@@ -1154,7 +1153,7 @@ static int mcp251x_can_probe(struct spi_device *spi) | |||
1154 | 1153 | ||
1155 | devm_can_led_init(net); | 1154 | devm_can_led_init(net); |
1156 | 1155 | ||
1157 | return ret; | 1156 | return 0; |
1158 | 1157 | ||
1159 | error_probe: | 1158 | error_probe: |
1160 | if (mcp251x_enable_dma) | 1159 | if (mcp251x_enable_dma) |