Skip to content

Commit 0e8da66

Browse files
authored
Merge pull request #760 from rickgaiser/usb-devnr
Use BDM bd.devNr for port numbers
2 parents b1d7c1a + 8840a75 commit 0e8da66

File tree

8 files changed

+43
-27
lines changed

8 files changed

+43
-27
lines changed

iop/iLink/IEEE1394_bd/src/include/scsi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ struct scsi_interface
55
{
66
void *priv;
77
char *name;
8+
// cppcheck-suppress unusedStructMember
9+
unsigned int devNr;
810
unsigned int max_sectors;
911

1012
int (*get_max_lun)(struct scsi_interface *scsi);

iop/iLink/IEEE1394_bd/src/sbp2_driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void init_ieee1394DiskDriver(void)
9797

9898
SBP2Devices[i].scsi.priv = &SBP2Devices[i];
9999
SBP2Devices[i].scsi.name = "sd";
100+
SBP2Devices[i].scsi.devNr = i;
100101
SBP2Devices[i].scsi.max_sectors = XFER_BLOCK_SIZE / 512;
101102
SBP2Devices[i].scsi.get_max_lun = sbp2_get_max_lun;
102103
SBP2Devices[i].scsi.queue_cmd = sbp2_queue_cmd;

iop/iLink/IEEE1394_bd/src/scsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ void scsi_connect(struct scsi_interface *scsi)
275275

276276
bd->priv = scsi;
277277
bd->name = scsi->name;
278+
bd->devNr = scsi->devNr;
278279
scsi_warmup(bd);
279280
bdm_connect_bd(bd);
280281
break;
@@ -305,7 +306,6 @@ int scsi_init(void)
305306
M_DEBUG("%s\n", __func__);
306307

307308
for (i = 0; i < NUM_DEVICES; ++i) {
308-
g_scsi_bd[i].devNr = i;
309309
g_scsi_bd[i].parNr = 0;
310310
g_scsi_bd[i].parId = 0x00;
311311

iop/sio/mx4sio_bd/src/spi_sdcard_driver.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spisd_t sdcard;
5252
struct block_device bd = {
5353
NULL, /* priv */
5454
"sdc", /* name */
55-
0, /* devNr */
55+
1, /* devNr, mx4sio is always in the second port */
5656
0, /* parNr */
5757
0x00, /* parId */
5858
SECTOR_SIZE, /* sectorSize */
@@ -64,7 +64,7 @@ struct block_device bd = {
6464
spisd_stop };
6565

6666
/* NOTE: SIO2 does *NOT* allow for direct control of /CS line.
67-
* It's controlled by the SIO2 hardware and automatically asserted at the start
67+
* It's controlled by the SIO2 hardware and automatically asserted at the start
6868
* of a transfer and deasserted at the end. This has lead to the need for some
6969
* conditions surrounding dummy writes to avoid timing disruption. */
7070
static uint8_t spisd_send_cmd(uint8_t cmd, uint32_t arg)
@@ -123,12 +123,12 @@ static uint8_t spisd_send_cmd_recv_data(uint8_t cmd, uint32_t arg, uint8_t *data
123123
static uint8_t spisd_read_register(uint8_t *buff, uint32_t len)
124124
{
125125
uint8_t results = SPISD_RESULT_ERROR;
126-
126+
127127
results = mx_sio2_wait_equal(0xFE, 2000);
128128
if (results == SPISD_RESULT_OK) {
129129
/* got read token, start SIO2 PIO RX transfer */
130130
mx_sio2_rx_pio(buff, len);
131-
}
131+
}
132132

133133
return results;
134134
}
@@ -179,11 +179,11 @@ int spisd_init_card()
179179
/* send CMD8 with check pattern, store R3 response in buffer */
180180
response = spisd_send_cmd_recv_data(CMD8, 0x1AA, buffer, sizeof(buffer));
181181

182-
/* if CMD8 response is idle, card is CSD v2 */
182+
/* if CMD8 response is idle, card is CSD v2 */
183183
if (response == SPISD_R1_IDLE_FLAG) {
184-
184+
185185
/* valid check pattern */
186-
if (buffer[2] == 0x01 && buffer[3] == 0xAA) {
186+
if (buffer[2] == 0x01 && buffer[3] == 0xAA) {
187187
/* CMD55 / ACMD41 pairs */
188188
for (int i = 0; i < 0xFFF; i++) {
189189
response = spisd_send_cmd(CMD55, 0);
@@ -262,7 +262,7 @@ int spisd_init_card()
262262
sdcard.card_type = CARD_TYPE_SDV1;
263263
M_DEBUG("Card Type : CSD v1\r\n");
264264
}
265-
265+
266266
/* set baud to 25MHz */
267267
mx_sio2_set_baud(SIO2_BAUD_DIV_FAST);
268268

@@ -280,7 +280,7 @@ int spisd_init_card()
280280
M_DEBUG("ERROR: CMD16 returned 0x%x, exp 0x0\n", response);
281281
return SPISD_RESULT_TIMEOUT;
282282
}
283-
283+
284284
/* CMD8 response invalid */
285285
} else {
286286
M_DEBUG("ERROR: CMD8 returned 0x%x, exp 0x1 or 0x4\n", response);
@@ -295,15 +295,15 @@ int spisd_get_card_info()
295295
{
296296
/* 16 bytes + 2 byte CRC16 */
297297
uint8_t reg_data[18];
298-
298+
299299
/* send CMD9, read CSD */
300300
uint8_t result = spisd_send_cmd(CMD9, 0);
301301
if (result != 0x0) {
302302
return result;
303303
}
304304

305305
result = spisd_read_register(sdcard.csd, sizeof(reg_data));
306-
306+
307307
/* dummy write between reg reads */
308308
mx_sio2_write_dummy();
309309

@@ -319,7 +319,7 @@ int spisd_get_card_info()
319319
}
320320

321321
result = spisd_read_register(reg_data, sizeof(reg_data));
322-
322+
323323
mx_sio2_write_dummy();
324324

325325
if (result != 0x0) {
@@ -362,7 +362,7 @@ int spisd_get_card_info()
362362

363363
struct t_csdVer1 *csdv1 = (struct t_csdVer1 *)sdcard.csd;
364364
struct t_csdVer2 *csdv2 = (struct t_csdVer2 *)sdcard.csd;
365-
365+
366366
/* CSD v1 - SDSC */
367367
if (csdv1->csd_structure == 0) {
368368
unsigned int c_size_mult = (csdv1->c_size_multHi << 1) | csdv1->c_size_multLo;
@@ -418,7 +418,7 @@ static int spisd_read_multi_begin(uint32_t sector)
418418
}
419419

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

450450
if (resbits & EF_SIO2_INTR_REVERSE) {
451451
ClearEventFlag(sio2_event_flag, ~EF_SIO2_INTR_REVERSE);
452-
452+
453453
while (cmd.sectors_reversed < cmd.sectors_transferred && cmd.abort == 0) {
454-
void *buf = (uint32_t *)&cmd.buffer[cmd.sectors_reversed * SECTOR_SIZE];
454+
void *buf = (uint32_t *)&cmd.buffer[cmd.sectors_reversed * SECTOR_SIZE];
455455
reverse_buffer(buf, SECTOR_SIZE / 4);
456456

457457
#ifdef CONFIG_USE_CRC16
@@ -492,7 +492,7 @@ static void spisd_read_multi_end()
492492
static int spisd_write_multi_begin(uint32_t sector, uint16_t count)
493493
{
494494
uint8_t results = SPISD_RESULT_ERROR;
495-
495+
496496
/* get idle */
497497
results = mx_sio2_wait_equal(0xFF, 4000);
498498

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

519519
return results;
520-
}
520+
}
521521

522522
static int spisd_write_multi_do(void* buffer, uint16_t count)
523523
{
@@ -533,7 +533,7 @@ static int spisd_write_multi_do(void* buffer, uint16_t count)
533533

534534
/* send initial write token */
535535
mx_sio2_write_byte(0xFC);
536-
536+
537537
/* start transfer */
538538
mx_sio2_start_tx_dma(buffer);
539539

@@ -603,10 +603,10 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
603603
/* start reading blocks */
604604
results = spisd_read_multi_do(buffer, sectors_left);
605605
sectors_left = sectors_left - results;
606-
606+
607607
/* fail condition */
608608
if (sectors_left > 0) {
609-
buffer = (uint8_t *)buffer + (results * 512);
609+
buffer = (uint8_t *)buffer + (results * 512);
610610
M_DEBUG("ERROR: failed to read all sectors, read:%i, abort:%i\n", sectors_left, cmd.abort);
611611

612612
if (cmd.abort == CMD_ABORT_NO_READ_TOKEN) {
@@ -633,7 +633,7 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
633633
int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, uint16_t count)
634634
{
635635
(void)bd;
636-
636+
637637
uint16_t sectors_left = count;
638638
uint16_t results = 0;
639639
uint16_t retries = 0;
@@ -647,7 +647,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
647647
void *write_buffer = (uint32_t*)buffer;
648648

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

652652
mx_sio2_lock(INTR_TX);
653653

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

683683
sdcard.used = 1;
684-
684+
685685
mx_sio2_unlock(INTR_TX);
686686

687687
return count - sectors_left;
@@ -694,7 +694,7 @@ void spisd_flush(struct block_device *bd)
694694
}
695695

696696
int spisd_stop(struct block_device *bd)
697-
{
697+
{
698698
(void)bd;
699699
return 0;
700700
}

iop/usb/usbmass_bd/src/imports.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ I_sceUsbdClosePipe
3636
I_sceUsbdSetPrivateData
3737
I_sceUsbdTransferPipe
3838
I_sceUsbdRegisterLdd
39+
I_sceUsbdGetDeviceLocation
3940
usbd_IMPORTS_end

iop/usb/usbmass_bd/src/include/scsi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ struct scsi_interface
55
{
66
void *priv;
77
char *name;
8+
// cppcheck-suppress unusedStructMember
9+
unsigned int devNr;
810
unsigned int max_sectors;
911

1012
int (*get_max_lun)(struct scsi_interface *scsi);

iop/usb/usbmass_bd/src/scsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ void scsi_connect(struct scsi_interface *scsi)
300300

301301
bd->priv = scsi;
302302
bd->name = scsi->name;
303+
bd->devNr = scsi->devNr;
303304
scsi_warmup(bd);
304305
bdm_connect_bd(bd);
305306
break;
@@ -330,7 +331,6 @@ int scsi_init(void)
330331
M_DEBUG("%s\n", __func__);
331332

332333
for (i = 0; i < NUM_DEVICES; ++i) {
333-
g_scsi_bd[i].devNr = i;
334334
g_scsi_bd[i].parNr = 0;
335335
g_scsi_bd[i].parId = 0x00;
336336

iop/usb/usbmass_bd/src/usb_mass.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,9 @@ static void usb_mass_update(void *arg)
764764
for (i = 0; i < new_devs_count; i += 1) {
765765
mass_dev *dev = new_devs[i];
766766
{
767+
u8 path[16] = {0};
767768
int ret;
769+
768770
if ((ret = usb_set_configuration(dev, dev->configId)) != USB_RC_OK) {
769771
M_PRINTF("ERROR: sending set_configuration %d\n", ret);
770772
usb_mass_release(dev);
@@ -784,6 +786,14 @@ static void usb_mass_update(void *arg)
784786
}
785787
}
786788

789+
sceUsbdGetDeviceLocation(dev->devId, path);
790+
if (path[0] == 2)
791+
dev->scsi.devNr = 0; // first USB port
792+
else if (path[0] == 1)
793+
dev->scsi.devNr = 1; // second USB port
794+
else
795+
dev->scsi.devNr = 2; // hub?
796+
787797
dev->status |= USBMASS_DEV_STAT_CONF;
788798
scsi_connect(&dev->scsi);
789799

0 commit comments

Comments
 (0)