Skip to content

Commit

Permalink
platform-rcbus-z180: wiznet FDM mode for use on boards with no SPI ch…
Browse files Browse the repository at this point in the history
…ip select logic e.g. SC111
  • Loading branch information
electrified committed Apr 26, 2023
1 parent c979c42 commit 3edd5cd
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Kernel/platform-rcbus-z180/config.h
Expand Up @@ -78,8 +78,9 @@ extern uint16_t swap_dev;
fit the networking */
#define CONFIG_NET
#define CONFIG_NET_WIZNET
#undef CONFIG_NET_W5200 /* WizNET 5200 */
#define CONFIG_NET_W5500 /* WizNET 5500 */
#undef CONFIG_NET_W5200 /* WizNET 5200 */
#define CONFIG_NET_W5500 /* WizNET 5500 */
#undef CONFIG_NET_W5500_FDM /* Fixed Data Mode - if you can't use VDM because chip select is tied low */

/* I2C device */
#define CONFIG_DEV_I2C
Expand Down
2 changes: 2 additions & 0 deletions Kernel/platform-rcbus-z180/discard.c
Expand Up @@ -47,9 +47,11 @@ void pagemap_init(void)
if (has_1mb)
for (i = 0x01; i < (512 >> 2); i += 0x10)
pagemap_add(i);
#ifdef CONFIG_RTC_DS1302
ds1302_init();
if (ds1302_present)
kputs("DS1302 detected at 0x0C.\n");
#endif
}

void map_init(void)
Expand Down
4 changes: 4 additions & 0 deletions Kernel/platform-rcbus-z180/i2c.c
Expand Up @@ -53,14 +53,18 @@ int i2c_claim_bus(uint_fast8_t bus)
return -1;
}
/* Don't poll the RTC whilst we are busy with the port */
#ifdef CONFIG_RTC_DS1302
rtc_defer = 1;
#endif
return 0;
}

void i2c_release_bus(uint_fast8_t bus)
{
used(bus);
#ifdef CONFIG_RTC_DS1302
rtc_defer = 0;
#endif
}

int plt_i2c_msg(struct i2c_msg *m, uint8_t *kbuf)
Expand Down
140 changes: 140 additions & 0 deletions Kernel/platform-rcbus-z180/wiznet.c
Expand Up @@ -142,7 +142,146 @@ void w5x00_setup(void)
#define SOCK2BANK_R(x) ((_SLOT(x) | 3) << 3)
#define W_WRITE 0x04

#ifdef CONFIG_NET_W5500_FDM
/* We can optimize this lot later when it works nicely */
static void spi_transaction(uint8_t ctrl, uint16_t off,
uint8_t *out, uint16_t outlen, uint8_t *in, uint16_t inlen)
{
int i;
irqflags_t irq = di();
spi_select_port(2);
while (outlen >= 4) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 3);

for(i=0;i<4;i++) {
spi_send(*out++);
}
off += 4;
outlen -= 4;
}
if (outlen & 2) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 2);
for(i=0;i<2;i++) {
spi_send(*out++);
}
off += 2;
outlen -= 2;
}
if (outlen & 1) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 1);
spi_send(*out++);
off += 1;
outlen -= 1;
}

while (inlen >= 4) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 3);

for(i=0;i<4;i++) {
*in++ = spi_recv();
}
off += 4;
inlen -= 4;
}
if (inlen & 2) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 2);
for(i=0;i<2;i++) {
*in++ = spi_recv();
}
off += 2;
inlen -= 2;
}
if (inlen & 1) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 1);
*in++ = spi_recv();
off += 1;
inlen -= 1;
}
spi_select_none();
irqrestore(irq);
}

static void spi_transaction_u(uint8_t ctrl, uint16_t off,
uint8_t *out, uint16_t outlen, uint8_t *in, uint16_t inlen)
{
int i;
irqflags_t irq = di();
spi_select_port(2);
while (outlen >= 4) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 3);

for(i=0;i<4;i++) {
spi_send(_ugetc(out++));
}
off += 4;
outlen -= 4;
}
if (outlen & 2) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 2);
for(i=0;i<2;i++) {
spi_send(_ugetc(out++));
}
off += 2;
outlen -= 2;
}
if (outlen & 1) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 1);
spi_send(_ugetc(out++));
off += 1;
outlen -= 1;
}

while (inlen >= 4) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 3);

for(i=0;i<4;i++) {
_uputc(spi_recv(), in++);
}
off += 4;
inlen -= 4;
}
if (inlen & 2) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 2);
for(i=0;i<2;i++) {
_uputc(spi_recv(), in++);
}
off += 2;
inlen -= 2;
}
if (inlen & 1) {
spi_send(off >> 8);
spi_send(off);
spi_send(ctrl | 1);
_uputc(spi_recv(), in++);
off += 1;
inlen -= 1;
}
spi_select_none();
irqrestore(irq);
}
#else
static void spi_transaction(uint8_t ctrl, uint16_t off,
uint8_t *out, uint16_t outlen, uint8_t *in, uint16_t inlen)
{
Expand Down Expand Up @@ -174,6 +313,7 @@ static void spi_transaction_u(uint8_t ctrl, uint16_t off,
spi_select_none();
irqrestore(irq);
}
#endif

uint8_t w5x00_readcb(uint16_t off)
{
Expand Down

0 comments on commit 3edd5cd

Please sign in to comment.