Skip to content

Commit 71cb7fd

Browse files
committed
[fw-isoldr] Introduced GPIO support for reset button handling.
1 parent eb63fbd commit 71cb7fd

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* DreamShell ISO Loader
3+
* SH4 GPIO
4+
* (c)2025 SWAT <http://www.dc-swat.ru>
5+
*/
6+
#ifndef __GPIO_H__
7+
#define __GPIO_H__
8+
9+
#include <main.h>
10+
#include <exception.h>
11+
#include <kos/regfield.h>
12+
13+
/* GPIO registers */
14+
#define PCTRA (*(volatile unsigned int *)0xFF80002C)
15+
#define PDTRA (*(volatile unsigned short *)0xFF800030)
16+
#define GPIOIC (*(volatile unsigned int *)0xFFD8001C)
17+
18+
/* Bit positions in PCTRA */
19+
#define GPIO_PIN_POS(pin) (pin * 2)
20+
21+
/* Bit masks for PCTRA */
22+
#define GPIO_PIN_MASK(pin) GENMASK(GPIO_PIN_POS(pin) + 1, GPIO_PIN_POS(pin)) /* 2 bits */
23+
#define GPIO_PIN_CFG_IN 0 /* Configure as input */
24+
#define GPIO_PIN_CFG_OUT(pin) BIT(GPIO_PIN_POS(pin)) /* Configure as output (01b) */
25+
26+
static inline void gpio_set_as_input(int pin) {
27+
PCTRA = (PCTRA & ~GPIO_PIN_MASK(pin)) | GPIO_PIN_CFG_IN;
28+
}
29+
30+
static inline void gpio_set_as_output(int pin) {
31+
PCTRA = (PCTRA & ~GPIO_PIN_MASK(pin)) | GPIO_PIN_CFG_OUT(pin);
32+
}
33+
34+
static inline int gpio_read_pin(int pin) {
35+
return (PDTRA >> pin) & 1;
36+
}
37+
38+
static inline void gpio_write_pin(int pin, int value) {
39+
if (value)
40+
PDTRA |= BIT(pin);
41+
else
42+
PDTRA &= ~BIT(pin);
43+
}
44+
45+
static inline void gpio_enable_interrupt(int pin) {
46+
GPIOIC |= BIT(pin);
47+
}
48+
49+
static inline void gpio_disable_interrupt(int pin) {
50+
GPIOIC &= ~BIT(pin);
51+
}
52+
53+
#endif /* __GPIO_H__ */

firmware/isoldr/loader/include/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
#define HOLLY_REV_VA0 0x0b
6969
#define holly_revision() (*(vuint32 *)NONCACHED_ADDR(0x005f689c))
7070

71+
#define GPIO_PIN_RESET_BUTTON 0
72+
7173
extern isoldr_info_t *IsoInfo;
7274
extern uint32 loader_size;
7375
extern uint32 loader_addr;

firmware/isoldr/loader/include/syscalls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,6 @@ void restore_syscalls(void);
222222

223223
int sys_misc_init(void);
224224

225+
void menu_exit(void);
226+
225227
#endif

firmware/isoldr/loader/syscalls.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <mmu.h>
1212
#include <cdda.h>
1313
#include <maple.h>
14+
#include <gpio.h>
1415
#include <arch/cache.h>
1516
#include <arch/timer.h>
1617
#include <arch/gdb.h>
@@ -869,6 +870,10 @@ void gdcMainLoop(void) {
869870
}
870871
#endif
871872

873+
if(gpio_read_pin(GPIO_PIN_RESET_BUTTON) == 0) {
874+
menu_exit();
875+
}
876+
872877
if(GDS->status == CMD_STAT_PROCESSING) {
873878
#ifdef HAVE_MULTI_DISC
874879
if (GDS->need_reinit == 1 && GDS->cmd != CMD_INIT) {
@@ -1052,6 +1057,10 @@ int gdcGetDrvStat(uint32 *status) {
10521057
}
10531058
#endif
10541059

1060+
if(gpio_read_pin(GPIO_PIN_RESET_BUTTON) == 0) {
1061+
menu_exit();
1062+
}
1063+
10551064
if(lock_gdsys()) {
10561065
DBGFF("Busy\n");
10571066
return CMD_STAT_BUSY;
@@ -1141,6 +1150,8 @@ void gdcInitSystem(void) {
11411150
}
11421151
#endif
11431152

1153+
gpio_set_as_input(GPIO_PIN_RESET_BUTTON);
1154+
11441155
reset_GDS(GDS);
11451156
gdcMainLoop();
11461157
}
@@ -1392,6 +1403,7 @@ void gdcDummy(int gd_chn, int *arg2) {
13921403
void menu_exit(void) {
13931404
LOGFF(NULL);
13941405

1406+
do {} while(pre_read_xfer_busy());
13951407
fs_enable_dma(FS_DMA_DISABLED);
13961408
shutdown_machine();
13971409

firmware/isoldr/loader/utils.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ void setup_machine(void) {
7373

7474
void shutdown_machine(void) {
7575

76+
/* FIXME
7677
const uint32 reset_regs[] = {
7778
0xa05f6808, 0xa05f6820, 0xa05f6c14, 0xa05f7414,
7879
0xa05f7814, 0xa05f7834, 0xa05f7854, 0xa05f7874,
7980
0xa05f7c14, 0xffa0001c, 0xffa0002c, 0xffa0003c
8081
};
81-
82+
*/
8283
irq_disable();
8384

8485
*(vuint32 *)(0xff000010) = 0;
@@ -104,7 +105,7 @@ void shutdown_machine(void) {
104105
addr2 += *(vuint32 *)(addr1);
105106

106107
*(vuint32 *)(0xa05f8044) = (*(vuint32 *)(0xa05f8044) & 0xfffffffe);
107-
108+
/*
108109
for (uint32 i = 0; i < ((sizeof(reset_regs)) >> 2); ++i) {
109110
*(vuint32 *)(reset_regs[i]) = (*(vuint32 *)(reset_regs[i]) & 0xfffffffe);
110111
for (uint32 j = 0; j < 127; ++j) {
@@ -113,6 +114,7 @@ void shutdown_machine(void) {
113114
}
114115
}
115116
}
117+
*/
116118
}
117119

118120
uint Load_BootBin() {

0 commit comments

Comments
 (0)