Skip to content

Commit 1f9c4ee

Browse files
ParthibanI17164kuba-moo
authored andcommitted
net: ethernet: oa_tc6: implement software reset
Reset complete bit is set when the MAC-PHY reset completes and ready for configuration. Additionally reset complete bit in the STS0 register has to be written by one upon reset complete to clear the interrupt. Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Parthiban Veerasooran <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 375d1e0 commit 1f9c4ee

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

drivers/net/ethernet/oa_tc6.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66
*/
77

88
#include <linux/bitfield.h>
9+
#include <linux/iopoll.h>
910
#include <linux/oa_tc6.h>
1011

12+
/* OPEN Alliance TC6 registers */
13+
/* Reset Control and Status Register */
14+
#define OA_TC6_REG_RESET 0x0003
15+
#define RESET_SWRESET BIT(0) /* Software Reset */
16+
17+
/* Status Register #0 */
18+
#define OA_TC6_REG_STATUS0 0x0008
19+
#define STATUS0_RESETC BIT(6) /* Reset Complete */
20+
1121
/* Control command header */
1222
#define OA_TC6_CTRL_HEADER_DATA_NOT_CTRL BIT(31)
1323
#define OA_TC6_CTRL_HEADER_WRITE_NOT_READ BIT(29)
@@ -24,6 +34,8 @@
2434
(OA_TC6_CTRL_MAX_REGISTERS *\
2535
OA_TC6_CTRL_REG_VALUE_SIZE) +\
2636
OA_TC6_CTRL_IGNORED_SIZE)
37+
#define STATUS0_RESETC_POLL_DELAY 1000
38+
#define STATUS0_RESETC_POLL_TIMEOUT 1000000
2739

2840
/* Internal structure for MAC-PHY drivers */
2941
struct oa_tc6 {
@@ -279,6 +291,42 @@ int oa_tc6_write_register(struct oa_tc6 *tc6, u32 address, u32 value)
279291
}
280292
EXPORT_SYMBOL_GPL(oa_tc6_write_register);
281293

294+
static int oa_tc6_read_status0(struct oa_tc6 *tc6)
295+
{
296+
u32 regval;
297+
int ret;
298+
299+
ret = oa_tc6_read_register(tc6, OA_TC6_REG_STATUS0, &regval);
300+
if (ret) {
301+
dev_err(&tc6->spi->dev, "STATUS0 register read failed: %d\n",
302+
ret);
303+
return 0;
304+
}
305+
306+
return regval;
307+
}
308+
309+
static int oa_tc6_sw_reset_macphy(struct oa_tc6 *tc6)
310+
{
311+
u32 regval = RESET_SWRESET;
312+
int ret;
313+
314+
ret = oa_tc6_write_register(tc6, OA_TC6_REG_RESET, regval);
315+
if (ret)
316+
return ret;
317+
318+
/* Poll for soft reset complete for every 1ms until 1s timeout */
319+
ret = readx_poll_timeout(oa_tc6_read_status0, tc6, regval,
320+
regval & STATUS0_RESETC,
321+
STATUS0_RESETC_POLL_DELAY,
322+
STATUS0_RESETC_POLL_TIMEOUT);
323+
if (ret)
324+
return -ENODEV;
325+
326+
/* Clear the reset complete status */
327+
return oa_tc6_write_register(tc6, OA_TC6_REG_STATUS0, regval);
328+
}
329+
282330
/**
283331
* oa_tc6_init - allocates and initializes oa_tc6 structure.
284332
* @spi: device with which data will be exchanged.
@@ -289,6 +337,7 @@ EXPORT_SYMBOL_GPL(oa_tc6_write_register);
289337
struct oa_tc6 *oa_tc6_init(struct spi_device *spi)
290338
{
291339
struct oa_tc6 *tc6;
340+
int ret;
292341

293342
tc6 = devm_kzalloc(&spi->dev, sizeof(*tc6), GFP_KERNEL);
294343
if (!tc6)
@@ -313,6 +362,13 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi)
313362
if (!tc6->spi_ctrl_rx_buf)
314363
return NULL;
315364

365+
ret = oa_tc6_sw_reset_macphy(tc6);
366+
if (ret) {
367+
dev_err(&tc6->spi->dev,
368+
"MAC-PHY software reset failed: %d\n", ret);
369+
return NULL;
370+
}
371+
316372
return tc6;
317373
}
318374
EXPORT_SYMBOL_GPL(oa_tc6_init);

0 commit comments

Comments
 (0)