]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/net/fsl_mdio.c
2 * Copyright 2009-2010, 2013 Freescale Semiconductor, Inc.
3 * Jun-jie Zhang <b18070@freescale.com>
4 * Mingkai Hu <Mingkai.hu@freescale.com>
6 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/errno.h>
16 void tsec_local_mdio_write(struct tsec_mii_mng __iomem
*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
);
26 while ((in_be32(&phyregs
->miimind
) & MIIMIND_BUSY
) && timeout
--)
30 int tsec_local_mdio_read(struct tsec_mii_mng __iomem
*phyregs
, int port_addr
,
31 int dev_addr
, int regnum
)
34 int timeout
= 1000000;
36 /* Put the address of the phy, and the register 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);
44 /* Initiate a read command, and wait */
45 out_be32(&phyregs
->miimcom
, MIIMCOM_READ_CYCLE
);
49 /* Wait for the the indication that the read is done */
50 while ((in_be32(&phyregs
->miimind
) & (MIIMIND_NOTVALID
| MIIMIND_BUSY
))
54 /* Grab the value read from the PHY */
55 value
= in_be32(&phyregs
->miimstat
);
60 static int fsl_pq_mdio_reset(struct mii_dev
*bus
)
62 struct tsec_mii_mng __iomem
*regs
=
63 (struct tsec_mii_mng __iomem
*)bus
->priv
;
65 /* Reset MII (due to new addresses) */
66 out_be32(®s
->miimcfg
, MIIMCFG_RESET_MGMT
);
68 out_be32(®s
->miimcfg
, MIIMCFG_INIT_VALUE
);
70 while (in_be32(®s
->miimind
) & MIIMIND_BUSY
)
76 int tsec_phy_read(struct mii_dev
*bus
, int addr
, int dev_addr
, int regnum
)
78 struct tsec_mii_mng __iomem
*phyregs
=
79 (struct tsec_mii_mng __iomem
*)bus
->priv
;
81 return tsec_local_mdio_read(phyregs
, addr
, dev_addr
, regnum
);
84 int tsec_phy_write(struct mii_dev
*bus
, int addr
, int dev_addr
, int regnum
,
87 struct tsec_mii_mng __iomem
*phyregs
=
88 (struct tsec_mii_mng __iomem
*)bus
->priv
;
90 tsec_local_mdio_write(phyregs
, addr
, dev_addr
, regnum
, value
);
95 int fsl_pq_mdio_init(bd_t
*bis
, struct fsl_pq_mdio_info
*info
)
97 struct mii_dev
*bus
= mdio_alloc();
100 printf("Failed to allocate FSL MDIO bus\n");
104 bus
->read
= tsec_phy_read
;
105 bus
->write
= tsec_phy_write
;
106 bus
->reset
= fsl_pq_mdio_reset
;
107 strcpy(bus
->name
, info
->name
);
109 bus
->priv
= (void *)info
->regs
;
111 return mdio_register(bus
);