1 |
4 |
DFC |
/******************************************************************************
|
2 |
|
|
**
|
3 |
|
|
** (C) Copyright 2017 DFC Design, s.r.o., Brno, Czech Republic
|
4 |
|
|
** Author: Marek Kvas (m.kvas@dspfpga.com)
|
5 |
|
|
**
|
6 |
|
|
****************************************************************************
|
7 |
|
|
**
|
8 |
|
|
** This file is part of Xenia Ethernet Example project.
|
9 |
|
|
**
|
10 |
|
|
** Xenia Ethernet Example project is free software: you can
|
11 |
|
|
** redistribute it and/or modify it under the terms of
|
12 |
|
|
** the GNU Lesser General Public License as published by the Free
|
13 |
|
|
** Software Foundation, either version 3 of the License, or
|
14 |
|
|
** (at your option) any later version.
|
15 |
|
|
**
|
16 |
|
|
** Xenia Ethernet Example project is distributed in the hope that
|
17 |
|
|
** it will be useful, but WITHOUT ANY WARRANTY; without even
|
18 |
|
|
** the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
19 |
|
|
** PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
20 |
|
|
** for more details.
|
21 |
|
|
**
|
22 |
|
|
** You should have received a copy of the GNU Lesser General Public
|
23 |
|
|
** License along with Xenia Ethernet Example project. If not,
|
24 |
|
|
** see <http://www.gnu.org/licenses/>.
|
25 |
|
|
****************************************************************************
|
26 |
|
|
*/
|
27 |
|
|
|
28 |
|
|
#ifndef __MDIO_H__
|
29 |
|
|
#define __MDIO_H__
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#undef USE_ONE_WRITE_COMMANDING
|
33 |
|
|
#define USE_CMD_FIFO
|
34 |
|
|
#define CMD_FIFO_DEPTH 18
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
struct mdio_struct {
|
38 |
|
|
unsigned int volatile divr; /* 8 bit divider */
|
39 |
|
|
unsigned int volatile ctrl; /* control register (RUN, BUSY) */
|
40 |
|
|
unsigned int volatile dout; /* data to be sent */
|
41 |
|
|
unsigned int volatile din; /* received data */
|
42 |
|
|
unsigned int volatile opst; /* start sequence and operation */
|
43 |
|
|
unsigned int volatile addr; /* register and phy address */
|
44 |
|
|
unsigned int volatile occmd; /* one write cycle commanding(contains all info) - WO */
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
#define MDIO_RUN (1<<1)
|
49 |
|
|
#define MDIO_BUSY (1<<0)
|
50 |
|
|
#define MDIO_CMD_FIFO_FULL (1<<13)
|
51 |
|
|
|
52 |
|
|
#define MDIO_START_SEQ_MASK (0x0300)
|
53 |
|
|
#define MDIO_START_SEQ_SHIFT (8)
|
54 |
|
|
|
55 |
|
|
#define MDIO_OPERATION_MASK (0x0003)
|
56 |
|
|
#define MDIO_OPEARTION_SHIFT (0)
|
57 |
|
|
|
58 |
|
|
#define MDIO_PHYADDR_MASK (0x1f00)
|
59 |
|
|
#define MDIO_PHYADDR_SHIFT (8)
|
60 |
|
|
|
61 |
|
|
#define MDIO_PHYREG_MASK (0x001f)
|
62 |
|
|
#define MDIO_PHYREG_SHIFT (0)
|
63 |
|
|
|
64 |
|
|
#define MDIO_PREAMBLE_SUPPRESSION (1<<8)
|
65 |
|
|
|
66 |
|
|
/* These are used when one write cycle commanding is used */
|
67 |
|
|
#define MDIO_OC_RUN (1<<31)
|
68 |
|
|
|
69 |
|
|
#define MDIO_OC_START_SEQ_MASK (0x30000000)
|
70 |
|
|
#define MDIO_OC_START_SEQ_SHIFT (28)
|
71 |
|
|
|
72 |
|
|
#define MDIO_OC_OPERATION_MASK (0x0c000000)
|
73 |
|
|
#define MDIO_OC_OPERATION_SHIFT (26)
|
74 |
|
|
|
75 |
|
|
#define MDIO_OC_PHYADDR_MASK (0x03e00000)
|
76 |
|
|
#define MDIO_OC_PHYADDR_SHIFT (21)
|
77 |
|
|
|
78 |
|
|
#define MDIO_OC_PHYREG_MASK (0x001f0000)
|
79 |
|
|
#define MDIO_OC_PHYREG_SHIFT (16)
|
80 |
|
|
|
81 |
|
|
#define MDIO_OC_DATA_MASK (0x0000ffff)
|
82 |
|
|
#define MDIO_OC_DATA_SHIFT (0)
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
int mdio_send(volatile struct mdio_struct *dev, unsigned int start_seq,
|
86 |
|
|
unsigned int operation, unsigned int phy_addr,
|
87 |
|
|
unsigned int reg_addr, unsigned int data, int blocking);
|
88 |
|
|
int mdio_read(volatile struct mdio_struct *dev, unsigned int start_seq,
|
89 |
|
|
unsigned int operation, unsigned int phy_addr,
|
90 |
|
|
unsigned int reg_addr, unsigned int *data);
|
91 |
|
|
|
92 |
|
|
int mdio_set_options(volatile struct mdio_struct *dev, unsigned int div, int preamble_suppression);
|
93 |
|
|
|
94 |
|
|
int mdio_write_indirect(volatile struct mdio_struct *dev, uint16_t phyaddr,
|
95 |
|
|
uint16_t devaddr, uint16_t regaddr, uint16_t data);
|
96 |
|
|
int mdio_write_indirect_nonblocking(volatile struct mdio_struct *dev, uint16_t phyaddr,
|
97 |
|
|
uint16_t devaddr, uint16_t regaddr, uint16_t data);
|
98 |
|
|
int mdio_read_indirect(volatile struct mdio_struct *dev, uint16_t phyaddr,
|
99 |
|
|
uint16_t devaddr, uint16_t regaddr, uint16_t *data);
|
100 |
|
|
int mdio_write_indirect_burst(volatile struct mdio_struct *dev, uint16_t phyaddr,
|
101 |
|
|
uint16_t devaddr, uint16_t regaddr, uint8_t *data, int size);
|
102 |
|
|
|
103 |
|
|
#endif
|
104 |
|
|
|