Skip to content

Commit

Permalink
MIPS: PS2: SCMD: Read system machine name command
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Noring <noring@nocrew.org>
  • Loading branch information
frno7 committed May 13, 2019
1 parent e6c6749 commit e16b1ae
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions arch/mips/include/asm/mach-ps2/scmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ int scmd(u8 cmd,
/* Send power off system command. */
int scmd_power_off(void);

struct scmd_machine_name {
char name[17]; /* NUL terminated string, for example "SCPH-50004" */
};

/*
* Reads the machine name. Returns the empty string on failure, most notably
* for models SCPH-10000 and SCPH-15000. Late SCPH-10000 and all SCPH-15000
* have the name in rom0:OSDSYS instead.
*/
struct scmd_machine_name scmd_read_machine_name(void);

#endif /* __ASM_PS2_SCMD_H */
48 changes: 48 additions & 0 deletions arch/mips/ps2/scmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ int scmd(u8 cmd,
}
EXPORT_SYMBOL_GPL(scmd);

static int scmd_send_byte(u8 cmd, u8 send_byte, void *recv, size_t recv_size)
{
return scmd(cmd, &send_byte, sizeof(send_byte), recv, recv_size);
}

int scmd_power_off(void)
{
u8 status;
Expand All @@ -138,6 +143,49 @@ int scmd_power_off(void)
}
EXPORT_SYMBOL_GPL(scmd_power_off);

struct scmd_machine_name scmd_read_machine_name(void)
{
struct scmd_machine_name machine = { .name = "" };
struct __attribute__ ((packed)) {
u8 status;
char name[8];
} buffer0, buffer8;
int err;

BUILD_BUG_ON(sizeof(buffer0) != 9 ||
sizeof(buffer8) != 9);

/* The machine name comes in two halves that need to be combined. */

err = scmd_send_byte(0x17, 0, &buffer0, sizeof(buffer0));
if (err < 0) {
pr_debug("%s: Read failed with %d at 0\n", __func__, err);
goto out_err;
}

err = scmd_send_byte(0x17, 8, &buffer8, sizeof(buffer8));
if (err < 0) {
pr_debug("%s: Read failed with %d at 8\n", __func__, err);
goto out_err;
}

if (buffer0.status != 0 ||
buffer8.status != 0) {
pr_debug("%s: Invalid results with statuses 0x%x and 0x%x\n",
__func__, buffer0.status, buffer8.status);
goto out_err;
}

BUILD_BUG_ON(sizeof(machine.name) < 17);
memcpy(&machine.name[0], buffer0.name, 8);
memcpy(&machine.name[8], buffer8.name, 8);
machine.name[16] = '\0';

out_err:
return machine;
}
EXPORT_SYMBOL_GPL(scmd_read_machine_name);

MODULE_DESCRIPTION("PlayStation 2 system command driver");
MODULE_AUTHOR("Fredrik Noring");
MODULE_LICENSE("GPL");

0 comments on commit e16b1ae

Please sign in to comment.