]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/net/fsl_mdio.c
2 * Copyright 2009-2010 Freescale Semiconductor, Inc.
3 * Jun-jie Zhang <b18070@freescale.com>
4 * Mingkai Hu <Mingkai.hu@freescale.com>
6 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/errno.h>
14 #include <asm/fsl_enet.h>
16 void tsec_local_mdio_write(struct tsec_mii_mng
*phyregs
, int port_addr
,
17 int dev_addr
, int regnum
, int value
)
19 int timeout
= 1000000;
21 out_be32(&phyregs
->miimadd
, (port_addr
<< 8) | (regnum
& 0x1f));
22 out_be32(&phyregs
->miimcon
, value
);
25 while ((in_be32(&phyregs
->miimind
) & MIIMIND_BUSY
) && timeout
--)
29 int tsec_local_mdio_read(struct tsec_mii_mng
*phyregs
, int port_addr
,
30 int dev_addr
, int regnum
)
33 int timeout
= 1000000;
35 /* Put the address of the phy, and the register
36 * number into MIIMADD */
37 out_be32(&phyregs
->miimadd
, (port_addr
<< 8) | (regnum
& 0x1f));
39 /* Clear the command register, and wait */
40 out_be32(&phyregs
->miimcom
, 0);
43 /* Initiate a read command, and wait */
44 out_be32(&phyregs
->miimcom
, MIIMCOM_READ_CYCLE
);
47 /* Wait for the the indication that the read is done */
48 while ((in_be32(&phyregs
->miimind
) & (MIIMIND_NOTVALID
| MIIMIND_BUSY
))
52 /* Grab the value read from the PHY */
53 value
= in_be32(&phyregs
->miimstat
);
58 static int fsl_pq_mdio_reset(struct mii_dev
*bus
)
60 struct tsec_mii_mng
*regs
= bus
->priv
;
62 /* Reset MII (due to new addresses) */
63 out_be32(®s
->miimcfg
, MIIMCFG_RESET_MGMT
);
65 out_be32(®s
->miimcfg
, MIIMCFG_INIT_VALUE
);
67 while (in_be32(®s
->miimind
) & MIIMIND_BUSY
)
73 int tsec_phy_read(struct mii_dev
*bus
, int addr
, int dev_addr
, int regnum
)
75 struct tsec_mii_mng
*phyregs
= bus
->priv
;
77 return tsec_local_mdio_read(phyregs
, addr
, dev_addr
, regnum
);
80 int tsec_phy_write(struct mii_dev
*bus
, int addr
, int dev_addr
, int regnum
,
83 struct tsec_mii_mng
*phyregs
= bus
->priv
;
85 tsec_local_mdio_write(phyregs
, addr
, dev_addr
, regnum
, value
);
90 int fsl_pq_mdio_init(bd_t
*bis
, struct fsl_pq_mdio_info
*info
)
92 struct mii_dev
*bus
= mdio_alloc();
95 printf("Failed to allocate FSL MDIO bus\n");
99 bus
->read
= tsec_phy_read
;
100 bus
->write
= tsec_phy_write
;
101 bus
->reset
= fsl_pq_mdio_reset
;
102 sprintf(bus
->name
, info
->name
);
104 bus
->priv
= info
->regs
;
106 return mdio_register(bus
);