Lines Matching +full:data +full:- +full:addr

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 …* http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Document/W5100_Datasheet_v1.2.6…
9 …* http://wiznethome.cafe24.com/wp-content/uploads/wiznethome/Chip/W5200/Documents/W5200_DS_V140E.p…
26 static int w5100_spi_read(struct net_device *ndev, u32 addr) in w5100_spi_read() argument
28 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5100_spi_read()
29 u8 cmd[3] = { W5100_SPI_READ_OPCODE, addr >> 8, addr & 0xff }; in w5100_spi_read()
30 u8 data; in w5100_spi_read() local
33 ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, 1); in w5100_spi_read()
35 return ret ? ret : data; in w5100_spi_read()
38 static int w5100_spi_write(struct net_device *ndev, u32 addr, u8 data) in w5100_spi_write() argument
40 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5100_spi_write()
41 u8 cmd[4] = { W5100_SPI_WRITE_OPCODE, addr >> 8, addr & 0xff, data}; in w5100_spi_write()
46 static int w5100_spi_read16(struct net_device *ndev, u32 addr) in w5100_spi_read16() argument
48 u16 data; in w5100_spi_read16() local
51 ret = w5100_spi_read(ndev, addr); in w5100_spi_read16()
54 data = ret << 8; in w5100_spi_read16()
55 ret = w5100_spi_read(ndev, addr + 1); in w5100_spi_read16()
57 return ret < 0 ? ret : data | ret; in w5100_spi_read16()
60 static int w5100_spi_write16(struct net_device *ndev, u32 addr, u16 data) in w5100_spi_write16() argument
64 ret = w5100_spi_write(ndev, addr, data >> 8); in w5100_spi_write16()
68 return w5100_spi_write(ndev, addr + 1, data & 0xff); in w5100_spi_write16()
71 static int w5100_spi_readbulk(struct net_device *ndev, u32 addr, u8 *buf, in w5100_spi_readbulk() argument
77 int ret = w5100_spi_read(ndev, addr + i); in w5100_spi_readbulk()
87 static int w5100_spi_writebulk(struct net_device *ndev, u32 addr, const u8 *buf, in w5100_spi_writebulk() argument
93 int ret = w5100_spi_write(ndev, addr + i, buf[i]); in w5100_spi_writebulk()
134 mutex_init(&spi_priv->cmd_lock); in w5200_spi_init()
139 static int w5200_spi_read(struct net_device *ndev, u32 addr) in w5200_spi_read() argument
141 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_read()
142 u8 cmd[4] = { addr >> 8, addr & 0xff, 0, 1 }; in w5200_spi_read()
143 u8 data; in w5200_spi_read() local
146 ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, 1); in w5200_spi_read()
148 return ret ? ret : data; in w5200_spi_read()
151 static int w5200_spi_write(struct net_device *ndev, u32 addr, u8 data) in w5200_spi_write() argument
153 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_write()
154 u8 cmd[5] = { addr >> 8, addr & 0xff, W5200_SPI_WRITE_OPCODE, 1, data }; in w5200_spi_write()
159 static int w5200_spi_read16(struct net_device *ndev, u32 addr) in w5200_spi_read16() argument
161 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_read16()
162 u8 cmd[4] = { addr >> 8, addr & 0xff, 0, 2 }; in w5200_spi_read16()
163 __be16 data; in w5200_spi_read16() local
166 ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, sizeof(data)); in w5200_spi_read16()
168 return ret ? ret : be16_to_cpu(data); in w5200_spi_read16()
171 static int w5200_spi_write16(struct net_device *ndev, u32 addr, u16 data) in w5200_spi_write16() argument
173 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_write16()
175 addr >> 8, addr & 0xff, in w5200_spi_write16()
177 data >> 8, data & 0xff in w5200_spi_write16()
183 static int w5200_spi_readbulk(struct net_device *ndev, u32 addr, u8 *buf, in w5200_spi_readbulk() argument
186 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_readbulk()
190 .tx_buf = spi_priv->cmd_buf, in w5200_spi_readbulk()
191 .len = sizeof(spi_priv->cmd_buf), in w5200_spi_readbulk()
200 mutex_lock(&spi_priv->cmd_lock); in w5200_spi_readbulk()
202 spi_priv->cmd_buf[0] = addr >> 8; in w5200_spi_readbulk()
203 spi_priv->cmd_buf[1] = addr; in w5200_spi_readbulk()
204 spi_priv->cmd_buf[2] = len >> 8; in w5200_spi_readbulk()
205 spi_priv->cmd_buf[3] = len; in w5200_spi_readbulk()
208 mutex_unlock(&spi_priv->cmd_lock); in w5200_spi_readbulk()
213 static int w5200_spi_writebulk(struct net_device *ndev, u32 addr, const u8 *buf, in w5200_spi_writebulk() argument
216 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5200_spi_writebulk()
220 .tx_buf = spi_priv->cmd_buf, in w5200_spi_writebulk()
221 .len = sizeof(spi_priv->cmd_buf), in w5200_spi_writebulk()
230 mutex_lock(&spi_priv->cmd_lock); in w5200_spi_writebulk()
232 spi_priv->cmd_buf[0] = addr >> 8; in w5200_spi_writebulk()
233 spi_priv->cmd_buf[1] = addr; in w5200_spi_writebulk()
234 spi_priv->cmd_buf[2] = W5200_SPI_WRITE_OPCODE | (len >> 8); in w5200_spi_writebulk()
235 spi_priv->cmd_buf[3] = len; in w5200_spi_writebulk()
238 mutex_unlock(&spi_priv->cmd_lock); in w5200_spi_writebulk()
255 #define W5500_SPI_BLOCK_SELECT(addr) (((addr) >> 16) & 0x1f) argument
256 #define W5500_SPI_READ_CONTROL(addr) (W5500_SPI_BLOCK_SELECT(addr) << 3) argument
257 #define W5500_SPI_WRITE_CONTROL(addr) \ argument
258 ((W5500_SPI_BLOCK_SELECT(addr) << 3) | BIT(2))
279 mutex_init(&spi_priv->cmd_lock); in w5500_spi_init()
284 static int w5500_spi_read(struct net_device *ndev, u32 addr) in w5500_spi_read() argument
286 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_read()
288 addr >> 8, in w5500_spi_read()
289 addr, in w5500_spi_read()
290 W5500_SPI_READ_CONTROL(addr) in w5500_spi_read()
292 u8 data; in w5500_spi_read() local
295 ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, 1); in w5500_spi_read()
297 return ret ? ret : data; in w5500_spi_read()
300 static int w5500_spi_write(struct net_device *ndev, u32 addr, u8 data) in w5500_spi_write() argument
302 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_write()
304 addr >> 8, in w5500_spi_write()
305 addr, in w5500_spi_write()
306 W5500_SPI_WRITE_CONTROL(addr), in w5500_spi_write()
307 data in w5500_spi_write()
313 static int w5500_spi_read16(struct net_device *ndev, u32 addr) in w5500_spi_read16() argument
315 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_read16()
317 addr >> 8, in w5500_spi_read16()
318 addr, in w5500_spi_read16()
319 W5500_SPI_READ_CONTROL(addr) in w5500_spi_read16()
321 __be16 data; in w5500_spi_read16() local
324 ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, sizeof(data)); in w5500_spi_read16()
326 return ret ? ret : be16_to_cpu(data); in w5500_spi_read16()
329 static int w5500_spi_write16(struct net_device *ndev, u32 addr, u16 data) in w5500_spi_write16() argument
331 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_write16()
333 addr >> 8, in w5500_spi_write16()
334 addr, in w5500_spi_write16()
335 W5500_SPI_WRITE_CONTROL(addr), in w5500_spi_write16()
336 data >> 8, in w5500_spi_write16()
337 data in w5500_spi_write16()
343 static int w5500_spi_readbulk(struct net_device *ndev, u32 addr, u8 *buf, in w5500_spi_readbulk() argument
346 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_readbulk()
350 .tx_buf = spi_priv->cmd_buf, in w5500_spi_readbulk()
351 .len = sizeof(spi_priv->cmd_buf), in w5500_spi_readbulk()
360 mutex_lock(&spi_priv->cmd_lock); in w5500_spi_readbulk()
362 spi_priv->cmd_buf[0] = addr >> 8; in w5500_spi_readbulk()
363 spi_priv->cmd_buf[1] = addr; in w5500_spi_readbulk()
364 spi_priv->cmd_buf[2] = W5500_SPI_READ_CONTROL(addr); in w5500_spi_readbulk()
367 mutex_unlock(&spi_priv->cmd_lock); in w5500_spi_readbulk()
372 static int w5500_spi_writebulk(struct net_device *ndev, u32 addr, const u8 *buf, in w5500_spi_writebulk() argument
375 struct spi_device *spi = to_spi_device(ndev->dev.parent); in w5500_spi_writebulk()
379 .tx_buf = spi_priv->cmd_buf, in w5500_spi_writebulk()
380 .len = sizeof(spi_priv->cmd_buf), in w5500_spi_writebulk()
389 mutex_lock(&spi_priv->cmd_lock); in w5500_spi_writebulk()
391 spi_priv->cmd_buf[0] = addr >> 8; in w5500_spi_writebulk()
392 spi_priv->cmd_buf[1] = addr; in w5500_spi_writebulk()
393 spi_priv->cmd_buf[2] = W5500_SPI_WRITE_CONTROL(addr); in w5500_spi_writebulk()
396 mutex_unlock(&spi_priv->cmd_lock); in w5500_spi_writebulk()
414 { .compatible = "wiznet,w5100", .data = (const void*)W5100, },
415 { .compatible = "wiznet,w5200", .data = (const void*)W5200, },
416 { .compatible = "wiznet,w5500", .data = (const void*)W5500, },
427 const void *mac = of_get_mac_address(spi->dev.of_node); in w5100_spi_probe()
429 if (spi->dev.of_node) { in w5100_spi_probe()
430 of_id = of_match_device(w5100_of_match, &spi->dev); in w5100_spi_probe()
432 return -ENODEV; in w5100_spi_probe()
433 driver_data = (kernel_ulong_t)of_id->data; in w5100_spi_probe()
435 driver_data = spi_get_device_id(spi)->driver_data; in w5100_spi_probe()
452 return -EINVAL; in w5100_spi_probe()
455 return w5100_probe(&spi->dev, ops, priv_size, mac, spi->irq, -EINVAL); in w5100_spi_probe()
460 return w5100_remove(&spi->dev); in w5100_spi_remove()