no-OS
Loading...
Searching...
No Matches
adin1140.c File Reference

Source file of the ADIN1140 driver. More...

#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "adin1140.h"
#include "no_os_alloc.h"
#include "no_os_util.h"
Include dependency graph for adin1140.c:

Functions

int adin1140_reg_write (struct adin1140_desc *desc, uint32_t addr, uint32_t data)
 Write a register's value.
 
int adin1140_reg_read (struct adin1140_desc *desc, uint32_t addr, uint32_t *data)
 Read a register's value.
 
int adin1140_reg_update (struct adin1140_desc *desc, uint32_t addr, uint32_t mask, uint32_t data)
 Update a register's value based on a mask.
 
int adin1140_mdio_read_c22 (struct adin1140_desc *desc, uint16_t reg, uint16_t *data)
 Read a PHY register using clause 22 via MMS.
 
int adin1140_mdio_write_c22 (struct adin1140_desc *desc, uint16_t reg, uint16_t data)
 Write a PHY register using clause 22 via MMS.
 
int adin1140_mdio_read_c45 (struct adin1140_desc *desc, uint32_t devnum, uint16_t reg, uint16_t *data)
 Read a PHY register using clause 45 via MMS.
 
int adin1140_mdio_write_c45 (struct adin1140_desc *desc, uint32_t devnum, uint16_t reg, uint16_t data)
 Write a PHY register using clause 45 via MMS.
 
int adin1140_set_mac_addr (struct adin1140_desc *desc, uint8_t mac_address[ADIN1140_ETH_ALEN])
 Add a unicast MAC address filter in the first available slot. Slots 0, 1 and 2 are reserved (multicast, broadcast and the device's own address), so the address is placed in the first free slot starting from ADIN1140_MAC_FILT_UNICAST_SLOT + 1.
 
int adin1140_broadcast_filter (struct adin1140_desc *desc, bool enabled)
 Enable/disable the broadcast filter.
 
int adin1140_multicast_filter (struct adin1140_desc *desc, bool enabled)
 Enable/disable the all-multicast filter. Matches any frame with the multicast bit set in the destination MAC.
 
int adin1140_set_promisc (struct adin1140_desc *desc, bool promisc)
 Set/clear promiscuous mode via CONFIG2 FWD_UNK2HOST.
 
int adin1140_mac_set_cfg (struct adin1140_desc *desc, const struct adin1140_mac_cfg *cfg)
 Apply the MAC CONFIG0 bitfields exposed via struct adin1140_mac_cfg. TXFCSVE is always cleared so the MAC appends the FCS itself. SYNC is preserved (read-modify-write).
 
int adin1140_mac_get_cfg (struct adin1140_desc *desc, struct adin1140_mac_cfg *cfg)
 Read back the MAC CONFIG0 bitfields into struct adin1140_mac_cfg.
 
int adin1140_sw_reset (struct adin1140_desc *desc)
 Trigger a MAC-PHY soft reset via OA-TC6 SWRESET, then re-assert the CONFIG0.SYNC bit so the device is ready to handle traffic.
 
int adin1140_write_fifo (struct adin1140_desc *desc, struct adin1140_eth_buff *eth_buff)
 Write a frame to the TX FIFO via OA TC6.
 
int adin1140_read_fifo (struct adin1140_desc *desc, struct adin1140_eth_buff *eth_buff)
 Read a frame from the RX FIFO via OA TC6.
 
int adin1140_poll (struct adin1140_desc *desc)
 
int adin1140_plca_set_cfg (struct adin1140_desc *desc, const struct adin1140_plca_cfg *cfg)
 Set the PLCA configuration.
 
int adin1140_plca_get_cfg (struct adin1140_desc *desc, struct adin1140_plca_cfg *cfg)
 Get the current PLCA configuration.
 
int adin1140_plca_get_status (struct adin1140_desc *desc, bool *active)
 Get the PLCA status (whether PLCA is active).
 
int adin1140_plca_reset (struct adin1140_desc *desc)
 Reset the PLCA logic by setting CTRL0.PLCARST. The bit is self-clearing once the PLCA state machines and counters have been returned to their reset state. Other CTRL0 bits (notably PLCAEN) are preserved.
 
int adin1140_plca_get_diag (struct adin1140_desc *desc, struct adin1140_plca_diag *diag, bool clear)
 Read the PLCA DIAG register and decode the three latched diagnostic indicators. Bits are RO/W1C on the device; if clear is true, write back any bits that were read as 1 to acknowledge them.
 
int adin1140_link_state (struct adin1140_desc *desc, uint32_t *state)
 Get the link state.
 
int adin1140_get_stats (struct adin1140_desc *desc, struct adin1140_stats *stats)
 Read the MAC hardware statistics counters.
 
int adin1140_register_callback (struct adin1140_desc *desc, void(*callback)(struct adin1140_desc *, uint32_t, void *), void *arg)
 Register a callback for OA TC6 events (e.g. link state change).
 
int adin1140_init (struct adin1140_desc **desc, struct adin1140_init_param *param)
 Initialize the ADIN1140 device.
 
int adin1140_remove (struct adin1140_desc *desc)
 Free the ADIN1140 device descriptor.
 

Detailed Description

Source file of the ADIN1140 driver.

Author
Ciprian Regus (cipri.nosp@m.an.r.nosp@m.egus@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2025-2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ adin1140_broadcast_filter()

int adin1140_broadcast_filter ( struct adin1140_desc * desc,
bool enabled )

Enable/disable the broadcast filter.

Parameters
desc- the device descriptor.
enabled- true to enable, false to disable.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_get_stats()

int adin1140_get_stats ( struct adin1140_desc * desc,
struct adin1140_stats * stats )

Read the MAC hardware statistics counters.

Parameters
desc- the device descriptor.
stats- storage for the counter snapshot.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_init()

int adin1140_init ( struct adin1140_desc ** desc,
struct adin1140_init_param * param )

Initialize the ADIN1140 device.

Parameters
desc- pointer to the device descriptor to be initialized.
param- the device's initialization parameters.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_link_state()

int adin1140_link_state ( struct adin1140_desc * desc,
uint32_t * state )

Get the link state.

Parameters
desc- the device descriptor.
state- pointer to store the link state (1 = up, 0 = down).
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mac_get_cfg()

int adin1140_mac_get_cfg ( struct adin1140_desc * desc,
struct adin1140_mac_cfg * cfg )

Read back the MAC CONFIG0 bitfields into struct adin1140_mac_cfg.

Parameters
desc- the device descriptor.
cfg- pointer to store the configuration values.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mac_set_cfg()

int adin1140_mac_set_cfg ( struct adin1140_desc * desc,
const struct adin1140_mac_cfg * cfg )

Apply the MAC CONFIG0 bitfields exposed via struct adin1140_mac_cfg. TXFCSVE is always cleared so the MAC appends the FCS itself. SYNC is preserved (read-modify-write).

Parameters
desc- the device descriptor.
cfg- configuration values to apply.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mdio_read_c22()

int adin1140_mdio_read_c22 ( struct adin1140_desc * desc,
uint16_t reg,
uint16_t * data )

Read a PHY register using clause 22 via MMS.

Parameters
desc- the device descriptor.
reg- register address (0..31).
data- pointer to store the register value.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mdio_read_c45()

int adin1140_mdio_read_c45 ( struct adin1140_desc * desc,
uint32_t devnum,
uint16_t reg,
uint16_t * data )

Read a PHY register using clause 45 via MMS.

Parameters
desc- the device descriptor.
devnum- MMD device number (1=PMA/PMD, 3=PCS, 31=VEND2).
reg- register address within the MMD.
data- pointer to store the register value.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mdio_write_c22()

int adin1140_mdio_write_c22 ( struct adin1140_desc * desc,
uint16_t reg,
uint16_t data )

Write a PHY register using clause 22 via MMS.

Parameters
desc- the device descriptor.
reg- register address (0..31).
data- value to write.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_mdio_write_c45()

int adin1140_mdio_write_c45 ( struct adin1140_desc * desc,
uint32_t devnum,
uint16_t reg,
uint16_t data )

Write a PHY register using clause 45 via MMS.

Parameters
desc- the device descriptor.
devnum- MMD device number (1=PMA/PMD, 3=PCS, 31=VEND2).
reg- register address within the MMD.
data- value to write.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_multicast_filter()

int adin1140_multicast_filter ( struct adin1140_desc * desc,
bool enabled )

Enable/disable the all-multicast filter. Matches any frame with the multicast bit set in the destination MAC.

Parameters
desc- the device descriptor.
enabled- true to enable, false to disable.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_plca_get_cfg()

int adin1140_plca_get_cfg ( struct adin1140_desc * desc,
struct adin1140_plca_cfg * cfg )

Get the current PLCA configuration.

Parameters
desc- the device descriptor.
cfg- pointer to store the PLCA configuration.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_plca_get_diag()

int adin1140_plca_get_diag ( struct adin1140_desc * desc,
struct adin1140_plca_diag * diag,
bool clear )

Read the PLCA DIAG register and decode the three latched diagnostic indicators. Bits are RO/W1C on the device; if clear is true, write back any bits that were read as 1 to acknowledge them.

Parameters
desc- the device descriptor.
diag- pointer to store the decoded diagnostic values.
clear- true to W1C-clear the latches that were observed set.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_plca_get_status()

int adin1140_plca_get_status ( struct adin1140_desc * desc,
bool * active )

Get the PLCA status (whether PLCA is active).

Parameters
desc- the device descriptor.
active- pointer to store the status (true if PLCA is active).
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_plca_reset()

int adin1140_plca_reset ( struct adin1140_desc * desc)

Reset the PLCA logic by setting CTRL0.PLCARST. The bit is self-clearing once the PLCA state machines and counters have been returned to their reset state. Other CTRL0 bits (notably PLCAEN) are preserved.

Parameters
desc- the device descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_plca_set_cfg()

int adin1140_plca_set_cfg ( struct adin1140_desc * desc,
const struct adin1140_plca_cfg * cfg )

Set the PLCA configuration.

Parameters
desc- the device descriptor.
cfg- PLCA configuration to apply.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_poll()

int adin1140_poll ( struct adin1140_desc * desc)

◆ adin1140_read_fifo()

int adin1140_read_fifo ( struct adin1140_desc * desc,
struct adin1140_eth_buff * eth_buff )

Read a frame from the RX FIFO via OA TC6.

Parameters
desc- the device descriptor.
eth_buff- buffer to receive the frame.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_reg_read()

int adin1140_reg_read ( struct adin1140_desc * desc,
uint32_t addr,
uint32_t * data )

Read a register's value.

Parameters
desc- the device descriptor.
addr- MMS-encoded register address.
data- pointer to store the register value.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_reg_update()

int adin1140_reg_update ( struct adin1140_desc * desc,
uint32_t addr,
uint32_t mask,
uint32_t data )

Update a register's value based on a mask.

Parameters
desc- the device descriptor.
addr- MMS-encoded register address.
mask- the bits that may be modified.
data- new value for the masked bits.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_reg_write()

int adin1140_reg_write ( struct adin1140_desc * desc,
uint32_t addr,
uint32_t data )

Write a register's value.

Parameters
desc- the device descriptor.
addr- MMS-encoded register address.
data- register value to write.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_register_callback()

int adin1140_register_callback ( struct adin1140_desc * desc,
void(* callback )(struct adin1140_desc *, uint32_t, void *),
void * arg )

Register a callback for OA TC6 events (e.g. link state change).

Parameters
desc- the device descriptor.
callback- function called with the device descriptor, the event and the user argument. NULL disables the callback.
arg- user argument passed to the callback.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_remove()

int adin1140_remove ( struct adin1140_desc * desc)

Free the ADIN1140 device descriptor.

Parameters
desc- the device descriptor to be removed.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_set_mac_addr()

int adin1140_set_mac_addr ( struct adin1140_desc * desc,
uint8_t mac_address[ADIN1140_ETH_ALEN] )

Add a unicast MAC address filter in the first available slot. Slots 0, 1 and 2 are reserved (multicast, broadcast and the device's own address), so the address is placed in the first free slot starting from ADIN1140_MAC_FILT_UNICAST_SLOT + 1.

Parameters
desc- the device descriptor.
mac_address- the MAC address to filter on.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_set_promisc()

int adin1140_set_promisc ( struct adin1140_desc * desc,
bool promisc )

Set/clear promiscuous mode via CONFIG2 FWD_UNK2HOST.

Parameters
desc- the device descriptor.
promisc- true to enable promiscuous mode, false to disable.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_sw_reset()

int adin1140_sw_reset ( struct adin1140_desc * desc)

Trigger a MAC-PHY soft reset via OA-TC6 SWRESET, then re-assert the CONFIG0.SYNC bit so the device is ready to handle traffic.

Parameters
desc- the device descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ adin1140_write_fifo()

int adin1140_write_fifo ( struct adin1140_desc * desc,
struct adin1140_eth_buff * eth_buff )

Write a frame to the TX FIFO via OA TC6.

Parameters
desc- the device descriptor.
eth_buff- the frame to be transmitted.
Returns
0 in case of success, negative error code otherwise.