Mario Scheithauer | 67f63e7 | 2022-11-02 15:57:10 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Werner Zeh | 49ec39f | 2022-11-15 08:27:19 +0100 | [diff] [blame] | 3 | #include <assert.h> |
Mario Scheithauer | 67f63e7 | 2022-11-02 15:57:10 +0100 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/mdio.h> |
| 7 | #include <stddef.h> |
| 8 | |
| 9 | const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev) |
| 10 | { |
| 11 | if (!dev || !dev->ops || !dev->ops->ops_mdio) { |
| 12 | printk(BIOS_ERR, "Could not get MDIO operations.\n"); |
| 13 | return NULL; |
| 14 | } |
| 15 | |
| 16 | return dev->ops->ops_mdio; |
| 17 | } |
Werner Zeh | 49ec39f | 2022-11-15 08:27:19 +0100 | [diff] [blame] | 18 | |
| 19 | uint16_t mdio_read(struct device *dev, uint8_t offset) |
| 20 | { |
| 21 | const struct mdio_bus_operations *mdio_ops; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 22 | struct device *parent = dev->upstream->dev; |
Werner Zeh | 49ec39f | 2022-11-15 08:27:19 +0100 | [diff] [blame] | 23 | |
| 24 | assert(dev->path.type == DEVICE_PATH_MDIO); |
| 25 | mdio_ops = dev_get_mdio_ops(parent); |
| 26 | if (!mdio_ops) |
| 27 | return 0; |
| 28 | return mdio_ops->read(parent, dev->path.mdio.addr, offset); |
| 29 | } |
| 30 | void mdio_write(struct device *dev, uint8_t offset, uint16_t val) |
| 31 | { |
| 32 | const struct mdio_bus_operations *mdio_ops; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 33 | struct device *parent = dev->upstream->dev; |
Werner Zeh | 49ec39f | 2022-11-15 08:27:19 +0100 | [diff] [blame] | 34 | |
| 35 | assert(dev->path.type == DEVICE_PATH_MDIO); |
| 36 | mdio_ops = dev_get_mdio_ops(parent); |
| 37 | if (!mdio_ops) |
| 38 | return; |
| 39 | mdio_ops->write(parent, dev->path.mdio.addr, offset, val); |
| 40 | } |