Skip to content

Commit

Permalink
DEV9 module
Browse files Browse the repository at this point in the history
  • Loading branch information
frno7 committed Dec 31, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b307c22 commit 5ccf9d9
Showing 5 changed files with 128 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -19,9 +19,10 @@ for example the command `make CROSS_COMPILE=mipsr5900el-unknown-linux-gnu-`.

## Modules

Currently four modules are implemented:
Currently five modules are implemented:
[`irq`](module/irq.c),
[`irqrelay`](module/irqrelay.c),
[`dev9`](module/dev9.c),
[`gamepad`](module/gamepad.c) and
[`printk`](module/printk.c).

18 changes: 13 additions & 5 deletions include/iopmod/dev9.h
Original file line number Diff line number Diff line change
@@ -3,12 +3,20 @@
#ifndef IOPMOD_DEV9_H
#define IOPMOD_DEV9_H

#define SSBUS_REG_1418 0xbf801418
#define SSBUS_REG_141c 0xbf80141c
#define SSBUS_REG_1420 0xbf801420
#include "iopmod/module-prototype.h"
#include "iopmod/module/dev9.h"

#define DEV9_REGBASE 0xbf801460
#define DEV9_REG(reg) (DEV9_REGBASE + 2 * (reg))
#define SSBUS_REG_1418 0xbf801418
#define SSBUS_REG_141c 0xbf80141c
#define SSBUS_REG_1420 0xbf801420

#define DEV9_REGBASE 0xbf801460
#define DEV9_REG(reg) (DEV9_REGBASE + 2 * (reg))

#define DEV9_DMAC_BASE 0xbf801510
#define DEV9_DMAC_MADR DEV9_DMAC_BASE
#define DEV9_DMAC_BCR (DEV9_DMAC_BASE + 0x04)
#define DEV9_DMAC_CHCR (DEV9_DMAC_BASE + 0x08)

enum {
DEV9_REG_1460, DEV9_REG_1462, DEV9_REG_1464, DEV9_REG_1466,
22 changes: 22 additions & 0 deletions include/iopmod/module/dev9.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0

MODULE_ID(dev9, 0x0100);
LIBRARY_ID(dev9, 0x0100);

/**
* dev9_request - request DEV9 hardware access
*
* FIXME: The DEV9 hardware is powered on, if necessary.
*
* Return: zero on success, or a negative error number
*/
id_(0) int dev9_request();

/**
* dev9_release - release DEV9 hardware access
*
* FIXME: The DEV9 hardware is powered off, if it's no longer used.
*
* Return: zero on success, or a negative error number
*/
id_(1) int dev9_release();
9 changes: 9 additions & 0 deletions include/iopmod/spd.h
Original file line number Diff line number Diff line change
@@ -15,4 +15,13 @@
#define SPD_REG_INTR_STAT 0x28
#define SPD_REG_INTR_MASK 0x2a

#define SPD_REG_XFR_CTRL 0x32
#define SPD_REG_0x38 0x38
#define SPD_REG_IF_CTRL 0x64
#define SPD_IF_ATA_RESET 0x80
#define SPD_IF_DMA_ENABLE 0x04
#define SPD_REG_PIO_MODE 0x70
#define SPD_REG_MWDMA_MODE 0x72
#define SPD_REG_UDMA_MODE 0x74

#endif /* IOPMOD_SPD_H */
82 changes: 82 additions & 0 deletions module/dev9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: GPL-2.0
/*
* DEV9
*
* Copyright (C) 2021 Fredrik Noring
*/

#include "iopmod/bits.h"
#include "iopmod/dev9.h"
#include "iopmod/errno.h"
#include "iopmod/io.h"
#include "iopmod/iop-error.h"
#include "iopmod/irq.h"
#include "iopmod/module.h"
#include "iopmod/printk.h"
#include "iopmod/spd.h"

/* FIXME: mutex */
static int dev9_use_count;

static void dev9_power_on()
{
iowr32(0x51011, SSBUS_REG_1420);
iowr32(0xe01a3043, SSBUS_REG_1418);
iowr32(0xef1a3043, SSBUS_REG_141c);

if (!(DEV9_REG(DEV9_REG_POWER) & 0x04)) {
pr_info("dev9: power is off\n");

iowr16(1, DEV9_REG(DEV9_REG_1466));
iowr16(0, DEV9_REG(DEV9_REG_1464));
iowr16(iord16(DEV9_REG(DEV9_REG_1464)), DEV9_REG(DEV9_REG_1460));

/* FIXME: Init Speed device */
} else {
pr_info("dev9: power is already on\n");
}

iowr16(0, DEV9_REG(DEV9_REG_1466));

const u16 spdrev = iord16(SPD_REG(SPD_REG_REV_1));
pr_info("dev9: spdrev %x\n", spdrev);

pr_info("dev9: rev %x\n", iord8(DEV9_REG(DEV9_REG_REV)));
}

static void dev9_power_off()
{
/* FIXME */
}

int dev9_request()
{
int err = 0;

if (!dev9_use_count)
dev9_power_on();

dev9_use_count++;

return err;
}

int dev9_release()
{
int err = 0;

dev9_use_count--;

if (!dev9_use_count)
dev9_power_off();

return err;
}

static enum module_init_status dev9_init(int argc, char *argv[])
{
dev9_power_off();

return MODULE_RESIDENT;
}
module_init(dev9_init);

0 comments on commit 5ccf9d9

Please sign in to comment.