Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions iop/iLink/IEEE1394_bd/src/include/scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ struct scsi_interface
{
void *priv;
char *name;
// cppcheck-suppress unusedStructMember
unsigned int devNr;
unsigned int max_sectors;

int (*get_max_lun)(struct scsi_interface *scsi);
Expand Down
1 change: 1 addition & 0 deletions iop/iLink/IEEE1394_bd/src/sbp2_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void init_ieee1394DiskDriver(void)

SBP2Devices[i].scsi.priv = &SBP2Devices[i];
SBP2Devices[i].scsi.name = "sd";
SBP2Devices[i].scsi.devNr = i;
SBP2Devices[i].scsi.max_sectors = XFER_BLOCK_SIZE / 512;
SBP2Devices[i].scsi.get_max_lun = sbp2_get_max_lun;
SBP2Devices[i].scsi.queue_cmd = sbp2_queue_cmd;
Expand Down
2 changes: 1 addition & 1 deletion iop/iLink/IEEE1394_bd/src/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void scsi_connect(struct scsi_interface *scsi)

bd->priv = scsi;
bd->name = scsi->name;
bd->devNr = scsi->devNr;
scsi_warmup(bd);
bdm_connect_bd(bd);
break;
Expand Down Expand Up @@ -305,7 +306,6 @@ int scsi_init(void)
M_DEBUG("%s\n", __func__);

for (i = 0; i < NUM_DEVICES; ++i) {
g_scsi_bd[i].devNr = i;
g_scsi_bd[i].parNr = 0;
g_scsi_bd[i].parId = 0x00;

Expand Down
50 changes: 25 additions & 25 deletions iop/sio/mx4sio_bd/src/spi_sdcard_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spisd_t sdcard;
struct block_device bd = {
NULL, /* priv */
"sdc", /* name */
0, /* devNr */
1, /* devNr, mx4sio is always in the second port */
0, /* parNr */
0x00, /* parId */
SECTOR_SIZE, /* sectorSize */
Expand All @@ -64,7 +64,7 @@ struct block_device bd = {
spisd_stop };

/* NOTE: SIO2 does *NOT* allow for direct control of /CS line.
* It's controlled by the SIO2 hardware and automatically asserted at the start
* It's controlled by the SIO2 hardware and automatically asserted at the start
* of a transfer and deasserted at the end. This has lead to the need for some
* conditions surrounding dummy writes to avoid timing disruption. */
static uint8_t spisd_send_cmd(uint8_t cmd, uint32_t arg)
Expand Down Expand Up @@ -123,12 +123,12 @@ static uint8_t spisd_send_cmd_recv_data(uint8_t cmd, uint32_t arg, uint8_t *data
static uint8_t spisd_read_register(uint8_t *buff, uint32_t len)
{
uint8_t results = SPISD_RESULT_ERROR;

results = mx_sio2_wait_equal(0xFE, 2000);
if (results == SPISD_RESULT_OK) {
/* got read token, start SIO2 PIO RX transfer */
mx_sio2_rx_pio(buff, len);
}
}

return results;
}
Expand Down Expand Up @@ -179,11 +179,11 @@ int spisd_init_card()
/* send CMD8 with check pattern, store R3 response in buffer */
response = spisd_send_cmd_recv_data(CMD8, 0x1AA, buffer, sizeof(buffer));

/* if CMD8 response is idle, card is CSD v2 */
/* if CMD8 response is idle, card is CSD v2 */
if (response == SPISD_R1_IDLE_FLAG) {

/* valid check pattern */
if (buffer[2] == 0x01 && buffer[3] == 0xAA) {
if (buffer[2] == 0x01 && buffer[3] == 0xAA) {
/* CMD55 / ACMD41 pairs */
for (int i = 0; i < 0xFFF; i++) {
response = spisd_send_cmd(CMD55, 0);
Expand Down Expand Up @@ -262,7 +262,7 @@ int spisd_init_card()
sdcard.card_type = CARD_TYPE_SDV1;
M_DEBUG("Card Type : CSD v1\r\n");
}

/* set baud to 25MHz */
mx_sio2_set_baud(SIO2_BAUD_DIV_FAST);

Expand All @@ -280,7 +280,7 @@ int spisd_init_card()
M_DEBUG("ERROR: CMD16 returned 0x%x, exp 0x0\n", response);
return SPISD_RESULT_TIMEOUT;
}

/* CMD8 response invalid */
} else {
M_DEBUG("ERROR: CMD8 returned 0x%x, exp 0x1 or 0x4\n", response);
Expand All @@ -295,15 +295,15 @@ int spisd_get_card_info()
{
/* 16 bytes + 2 byte CRC16 */
uint8_t reg_data[18];

/* send CMD9, read CSD */
uint8_t result = spisd_send_cmd(CMD9, 0);
if (result != 0x0) {
return result;
}

result = spisd_read_register(sdcard.csd, sizeof(reg_data));

/* dummy write between reg reads */
mx_sio2_write_dummy();

Expand All @@ -319,7 +319,7 @@ int spisd_get_card_info()
}

result = spisd_read_register(reg_data, sizeof(reg_data));

mx_sio2_write_dummy();

if (result != 0x0) {
Expand Down Expand Up @@ -362,7 +362,7 @@ int spisd_get_card_info()

struct t_csdVer1 *csdv1 = (struct t_csdVer1 *)sdcard.csd;
struct t_csdVer2 *csdv2 = (struct t_csdVer2 *)sdcard.csd;

/* CSD v1 - SDSC */
if (csdv1->csd_structure == 0) {
unsigned int c_size_mult = (csdv1->c_size_multHi << 1) | csdv1->c_size_multLo;
Expand Down Expand Up @@ -418,7 +418,7 @@ static int spisd_read_multi_begin(uint32_t sector)
}

/* send CMD18 to being multi block read */
results = spisd_send_cmd(CMD18, sector);
results = spisd_send_cmd(CMD18, sector);
if (results == SPISD_RESULT_OK) {
/* wait for first read token (0xFE) */
results = mx_sio2_wait_equal(0xFE, 100000);
Expand Down Expand Up @@ -449,9 +449,9 @@ static int spisd_read_multi_do(void *buffer, uint16_t count)

if (resbits & EF_SIO2_INTR_REVERSE) {
ClearEventFlag(sio2_event_flag, ~EF_SIO2_INTR_REVERSE);

while (cmd.sectors_reversed < cmd.sectors_transferred && cmd.abort == 0) {
void *buf = (uint32_t *)&cmd.buffer[cmd.sectors_reversed * SECTOR_SIZE];
void *buf = (uint32_t *)&cmd.buffer[cmd.sectors_reversed * SECTOR_SIZE];
reverse_buffer(buf, SECTOR_SIZE / 4);

#ifdef CONFIG_USE_CRC16
Expand Down Expand Up @@ -492,7 +492,7 @@ static void spisd_read_multi_end()
static int spisd_write_multi_begin(uint32_t sector, uint16_t count)
{
uint8_t results = SPISD_RESULT_ERROR;

/* get idle */
results = mx_sio2_wait_equal(0xFF, 4000);

Expand All @@ -517,7 +517,7 @@ static int spisd_write_multi_begin(uint32_t sector, uint16_t count)
mx_sio2_write_dummy();

return results;
}
}

static int spisd_write_multi_do(void* buffer, uint16_t count)
{
Expand All @@ -533,7 +533,7 @@ static int spisd_write_multi_do(void* buffer, uint16_t count)

/* send initial write token */
mx_sio2_write_byte(0xFC);

/* start transfer */
mx_sio2_start_tx_dma(buffer);

Expand Down Expand Up @@ -603,10 +603,10 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
/* start reading blocks */
results = spisd_read_multi_do(buffer, sectors_left);
sectors_left = sectors_left - results;

/* fail condition */
if (sectors_left > 0) {
buffer = (uint8_t *)buffer + (results * 512);
buffer = (uint8_t *)buffer + (results * 512);
M_DEBUG("ERROR: failed to read all sectors, read:%i, abort:%i\n", sectors_left, cmd.abort);

if (cmd.abort == CMD_ABORT_NO_READ_TOKEN) {
Expand All @@ -633,7 +633,7 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, uint16_t count)
{
(void)bd;

uint16_t sectors_left = count;
uint16_t results = 0;
uint16_t retries = 0;
Expand All @@ -647,7 +647,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
void *write_buffer = (uint32_t*)buffer;

/* pre-reverse the entire buffer */
reverse_buffer(write_buffer, ((count * SECTOR_SIZE) / 4));
reverse_buffer(write_buffer, ((count * SECTOR_SIZE) / 4));

mx_sio2_lock(INTR_TX);

Expand Down Expand Up @@ -681,7 +681,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
}

sdcard.used = 1;

mx_sio2_unlock(INTR_TX);

return count - sectors_left;
Expand All @@ -694,7 +694,7 @@ void spisd_flush(struct block_device *bd)
}

int spisd_stop(struct block_device *bd)
{
{
(void)bd;
return 0;
}
1 change: 1 addition & 0 deletions iop/usb/usbmass_bd/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ I_sceUsbdClosePipe
I_sceUsbdSetPrivateData
I_sceUsbdTransferPipe
I_sceUsbdRegisterLdd
I_sceUsbdGetDeviceLocation
usbd_IMPORTS_end
2 changes: 2 additions & 0 deletions iop/usb/usbmass_bd/src/include/scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ struct scsi_interface
{
void *priv;
char *name;
// cppcheck-suppress unusedStructMember
unsigned int devNr;
unsigned int max_sectors;

int (*get_max_lun)(struct scsi_interface *scsi);
Expand Down
2 changes: 1 addition & 1 deletion iop/usb/usbmass_bd/src/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ void scsi_connect(struct scsi_interface *scsi)

bd->priv = scsi;
bd->name = scsi->name;
bd->devNr = scsi->devNr;
scsi_warmup(bd);
bdm_connect_bd(bd);
break;
Expand Down Expand Up @@ -330,7 +331,6 @@ int scsi_init(void)
M_DEBUG("%s\n", __func__);

for (i = 0; i < NUM_DEVICES; ++i) {
g_scsi_bd[i].devNr = i;
g_scsi_bd[i].parNr = 0;
g_scsi_bd[i].parId = 0x00;

Expand Down
10 changes: 10 additions & 0 deletions iop/usb/usbmass_bd/src/usb_mass.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,9 @@ static void usb_mass_update(void *arg)
for (i = 0; i < new_devs_count; i += 1) {
mass_dev *dev = new_devs[i];
{
u8 path[16] = {0};
int ret;

if ((ret = usb_set_configuration(dev, dev->configId)) != USB_RC_OK) {
M_PRINTF("ERROR: sending set_configuration %d\n", ret);
usb_mass_release(dev);
Expand All @@ -784,6 +786,14 @@ static void usb_mass_update(void *arg)
}
}

sceUsbdGetDeviceLocation(dev->devId, path);
if (path[0] == 2)
dev->scsi.devNr = 0; // first USB port
else if (path[0] == 1)
dev->scsi.devNr = 1; // second USB port
else
dev->scsi.devNr = 2; // hub?

dev->status |= USBMASS_DEV_STAT_CONF;
scsi_connect(&dev->scsi);

Expand Down