2 * Copyright (C) 2016 CSI Project. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _CSI_ETH_PHY_H_
18 #define _CSI_ETH_PHY_H_
26 typedef void *eth_phy_handle_t;
28 #define CSI_ETH_PHY_API_VERSION CSI_ETH_VERSION_MAJOR_MINOR(2,1) /* API version */
31 #define _CSI_Driver_ETH_PHY_(n) Driver_ETH_PHY##n
32 #define CSI_Driver_ETH_PHY_(n) _CSI_Driver_ETH_PHY_(n)
35 /****** Ethernet PHY Mode *****/
36 #define CSI_ETH_PHY_SPEED_Pos 0
37 #define CSI_ETH_PHY_SPEED_Msk (3UL << CSI_ETH_PHY_SPEED_Pos)
38 #define CSI_ETH_PHY_SPEED_10M (CSI_ETH_SPEED_10M << CSI_ETH_PHY_SPEED_Pos) ///< 10 Mbps link speed
39 #define CSI_ETH_PHY_SPEED_100M (CSI_ETH_SPEED_100M << CSI_ETH_PHY_SPEED_Pos) ///< 100 Mbps link speed
40 #define CSI_ETH_PHY_SPEED_1G (CSI_ETH_SPEED_1G << CSI_ETH_PHY_SPEED_Pos) ///< 1 Gpbs link speed
41 #define CSI_ETH_PHY_DUPLEX_Pos 2
42 #define CSI_ETH_PHY_DUPLEX_Msk (1UL << CSI_ETH_PHY_DUPLEX_Pos)
43 #define CSI_ETH_PHY_DUPLEX_HALF (CSI_ETH_DUPLEX_HALF << CSI_ETH_PHY_DUPLEX_Pos) ///< Half duplex link
44 #define CSI_ETH_PHY_DUPLEX_FULL (CSI_ETH_DUPLEX_FULL << CSI_ETH_PHY_DUPLEX_Pos) ///< Full duplex link
45 #define CSI_ETH_PHY_AUTO_NEGOTIATE (1UL << 3) ///< Auto Negotiation mode
46 #define CSI_ETH_PHY_LOOPBACK (1UL << 4) ///< Loop-back test mode
47 #define CSI_ETH_PHY_ISOLATE (1UL << 5) ///< Isolate PHY from MII/RMII interface
49 typedef int32_t (*csi_eth_phy_read_t) (uint8_t phy_addr, uint8_t reg_addr, uint16_t *data); ///< Read Ethernet PHY Register.
50 typedef int32_t (*csi_eth_phy_write_t) (uint8_t phy_addr, uint8_t reg_addr, uint16_t data); ///< Write Ethernet PHY Register.
53 csi_eth_phy_read_t phy_read;
54 csi_eth_phy_write_t phy_write;
55 eth_link_info_t link_info;
58 // Function documentation
60 \brief Get driver version.
61 \param[in] handle ethernet phy handle
62 \return driver version
64 csi_drv_version_t csi_eth_phy_get_version(eth_phy_handle_t handle);
67 \brief Initialize Ethernet PHY Device.
70 \return ethernet phy handle
72 eth_phy_handle_t csi_eth_phy_initialize(csi_eth_phy_read_t fn_read, csi_eth_phy_write_t fn_write);
75 \brief De-initialize Ethernet PHY Device.
76 \param[in] handle ethernet phy handle
79 int32_t csi_eth_phy_uninitialize(eth_phy_handle_t handle);
82 \brief Control Ethernet PHY Device Power.
83 \param[in] handle ethernet phy handle
84 \param[in] state Power state
87 int32_t csi_eth_phy_power_control(eth_phy_handle_t handle, eth_power_state_t state);
90 \brief Set Ethernet Media Interface.
91 \param[in] handle ethernet phy handle
92 \param[in] interface Media Interface type
95 int32_t csi_eth_phy_set_interface(eth_phy_handle_t handle, uint32_t interface);
98 \brief Set Ethernet PHY Device Operation mode.
99 \param[in] handle ethernet phy handle
100 \param[in] mode Operation Mode
103 int32_t csi_eth_phy_set_mode(eth_phy_handle_t handle, uint32_t mode);
106 \brief Get Ethernet PHY Device Link state.
107 \param[in] handle ethernet phy handle
108 \return current link status \ref eth_link_state_t
110 eth_link_state_t csi_eth_phy_get_linkstate(eth_phy_handle_t handle);
113 \brief Get Ethernet PHY Device Link information.
114 \param[in] handle ethernet phy handle
115 \return current link parameters \ref eth_link_info_t
117 eth_link_info_t csi_eth_phy_get_linkinfo(eth_phy_handle_t handle);