Skip to content

Commit d4a2a2e

Browse files
maass-hamburgaescolar
authored andcommitted
drivers: ethernet: adin2111: make register access independent
don't use global buffers for reg_read and reg_write, so we only need to rely on the spi drivers lock and don't have to use our lock. Signed-off-by: Fin Maaß <[email protected]>
1 parent 3de5883 commit d4a2a2e

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

drivers/ethernet/eth_adin2111.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ static int eth_adin2111_reg_read_oa(const struct device *dev, const uint16_t reg
173173
uint32_t *val)
174174
{
175175
struct adin2111_data *ctx = dev->data;
176+
uint8_t rx_buf[ADIN2111_OA_CTL_LEN_PROT] = {0};
177+
uint8_t tx_buf[ADIN2111_OA_CTL_LEN_PROT] = {0};
176178
uint32_t pval;
177-
uint32_t *hdr = (uint32_t *)ctx->oa_tx_buf;
179+
uint32_t *hdr = (uint32_t *)tx_buf;
178180
int len;
179181
int ret;
180182

@@ -188,16 +190,16 @@ static int eth_adin2111_reg_read_oa(const struct device *dev, const uint16_t reg
188190

189191
len = (ctx->oa_prot) ? ADIN2111_OA_CTL_LEN_PROT : ADIN2111_OA_CTL_LEN;
190192

191-
ret = eth_adin2111_oa_spi_xfer(dev, ctx->oa_rx_buf, ctx->oa_tx_buf, len);
193+
ret = eth_adin2111_oa_spi_xfer(dev, rx_buf, tx_buf, len);
192194
if (ret < 0) {
193195
return ret;
194196
}
195197

196-
*val = sys_be32_to_cpu(*(uint32_t *)&ctx->oa_rx_buf[8]);
198+
*val = sys_be32_to_cpu(*(uint32_t *)&rx_buf[8]);
197199

198200
/* In protected mode read data is followed by its compliment value */
199201
if (ctx->oa_prot) {
200-
pval = sys_be32_to_cpu(*(uint32_t *)&ctx->oa_rx_buf[12]);
202+
pval = sys_be32_to_cpu(*(uint32_t *)&rx_buf[12]);
201203
if (*val != ~pval) {
202204
LOG_ERR("OA protected mode rx error !");
203205
return -1;
@@ -211,8 +213,10 @@ static int eth_adin2111_reg_write_oa(const struct device *dev, const uint16_t re
211213
uint32_t val)
212214
{
213215
struct adin2111_data *ctx = dev->data;
216+
uint8_t rx_buf[ADIN2111_OA_CTL_LEN_PROT] = {0};
217+
uint8_t tx_buf[ADIN2111_OA_CTL_LEN_PROT] = {0};
214218
uint32_t pval;
215-
uint32_t *hdr = (uint32_t *)ctx->oa_tx_buf;
219+
uint32_t *hdr = (uint32_t *)tx_buf;
216220
int len;
217221
int ret;
218222

@@ -226,18 +230,18 @@ static int eth_adin2111_reg_write_oa(const struct device *dev, const uint16_t re
226230

227231
len = (ctx->oa_prot) ? ADIN2111_OA_CTL_LEN_PROT : ADIN2111_OA_CTL_LEN;
228232

229-
*(uint32_t *)&ctx->oa_tx_buf[4] = sys_cpu_to_be32(val);
233+
*(uint32_t *)&tx_buf[4] = sys_cpu_to_be32(val);
230234
if (ctx->oa_prot) {
231-
*(uint32_t *)&ctx->oa_tx_buf[8] = sys_cpu_to_be32(~val);
235+
*(uint32_t *)&tx_buf[8] = sys_cpu_to_be32(~val);
232236
}
233237

234-
ret = eth_adin2111_oa_spi_xfer(dev, ctx->oa_rx_buf, ctx->oa_tx_buf, len);
238+
ret = eth_adin2111_oa_spi_xfer(dev, rx_buf, tx_buf, len);
235239
if (ret < 0) {
236240
return ret;
237241
}
238242

239243
if (ctx->oa_prot) {
240-
pval = sys_be32_to_cpu(*(uint32_t *)&ctx->oa_rx_buf[12]);
244+
pval = sys_be32_to_cpu(*(uint32_t *)&rx_buf[12]);
241245
if (val != ~pval) {
242246
LOG_ERR("OA protected mode tx error !");
243247
return -1;

drivers/mdio/mdio_adin2111.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,11 @@ static int mdio_adin2111_write(const struct device *dev, uint8_t prtad,
173173
return ret;
174174
}
175175

176-
static void mdio_adin2111_bus_enable(const struct device *dev)
177-
{
178-
const struct mdio_adin2111_config *const cfg = dev->config;
179-
180-
eth_adin2111_lock(cfg->adin, K_FOREVER);
181-
}
182-
183-
static void mdio_adin2111_bus_disable(const struct device *dev)
184-
{
185-
const struct mdio_adin2111_config *const cfg = dev->config;
186-
187-
eth_adin2111_unlock(cfg->adin);
188-
}
189-
190176
static DEVICE_API(mdio, mdio_adin2111_api) = {
191177
.read = mdio_adin2111_read,
192178
.write = mdio_adin2111_write,
193179
.read_c45 = mdio_adin2111_read_c45,
194180
.write_c45 = mdio_adin2111_write_c45,
195-
.bus_enable = mdio_adin2111_bus_enable,
196-
.bus_disable = mdio_adin2111_bus_disable
197181
};
198182

199183
#define ADIN2111_MDIO_INIT(n) \

include/zephyr/drivers/ethernet/eth_adin2111.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ int eth_adin2111_unlock(const struct device *dev);
4343
/**
4444
* @brief Writes host MAC interface register over SPI
4545
*
46-
* @note The caller is responsible for device lock.
47-
* Shall not be called from ISR.
46+
* @note Shall not be called from ISR.
4847
*
4948
* @param[in] dev ADIN2111 device.
5049
* @param reg Register address.
@@ -58,8 +57,7 @@ int eth_adin2111_reg_write(const struct device *dev, const uint16_t reg, uint32_
5857
/**
5958
* @brief Reads host MAC interface register over SPI
6059
*
61-
* @note The caller is responsible for device lock.
62-
* Shall not be called from ISR.
60+
* @note Shall not be called from ISR.
6361
*
6462
* @param[in] dev ADIN2111 device.
6563
* @param reg Register address.
@@ -73,8 +71,7 @@ int eth_adin2111_reg_read(const struct device *dev, const uint16_t reg, uint32_t
7371
/**
7472
* @brief Update host MAC interface register over SPI
7573
*
76-
* @note The caller is responsible for device lock.
77-
* Shall not be called from ISR.
74+
* @note Shall not be called from ISR.
7875
*
7976
* @param[in] dev ADIN2111 device.
8077
* @param reg Register address.

0 commit comments

Comments
 (0)