1.1 --- a/pkg/devices/lib/msc/include/msc-common.h Sun Feb 11 00:39:56 2024 +0100
1.2 +++ b/pkg/devices/lib/msc/include/msc-common.h Sun Feb 11 18:47:06 2024 +0100
1.3 @@ -75,6 +75,7 @@
1.4 struct CID _cid[8];
1.5 struct CSD _csd[8];
1.6 uint16_t _rca[8], _current_rca;
1.7 + uint8_t _bus_width[8], _current_bus_width;
1.8 uint8_t _cards;
1.9
1.10 // Utility methods.
1.11 @@ -96,6 +97,10 @@
1.12 bool command_with_data(uint8_t index);
1.13 bool command_uses_busy(uint8_t index);
1.14 uint8_t get_response_format(uint8_t index);
1.15 +
1.16 + bool app_command_will_write(uint8_t index);
1.17 + bool app_command_with_data(uint8_t index);
1.18 + bool app_command_uses_busy(uint8_t index);
1.19 uint8_t get_app_response_format(uint8_t index);
1.20
1.21 // Command initiation.
2.1 --- a/pkg/devices/lib/msc/src/common.cc Sun Feb 11 00:39:56 2024 +0100
2.2 +++ b/pkg/devices/lib/msc/src/common.cc Sun Feb 11 18:47:06 2024 +0100
2.3 @@ -563,6 +563,21 @@
2.4
2.5
2.6
2.7 +// Utilities.
2.8 +
2.9 +static enum Command_data_control_bits
2.10 +encode_bus_width(uint8_t width)
2.11 +{
2.12 + switch (width)
2.13 + {
2.14 + case 4: return Cdc_bus_width_field_4bit;
2.15 + case 1: return Cdc_bus_width_field_1bit;
2.16 + default: return Cdc_bus_width_field_1bit;
2.17 + }
2.18 +}
2.19 +
2.20 +
2.21 +
2.22 // Channel abstraction.
2.23
2.24 Msc_channel::Msc_channel(l4_addr_t msc_start, l4_addr_t addr, l4_cap_idx_t irq)
2.25 @@ -608,6 +623,16 @@
2.26 }
2.27
2.28 bool
2.29 +Msc_channel::app_command_will_write(uint8_t index)
2.30 +{
2.31 + // NOTE: Probably incomplete coverage.
2.32 +
2.33 + (void) index;
2.34 +
2.35 + return false;
2.36 +}
2.37 +
2.38 +bool
2.39 Msc_channel::command_with_data(uint8_t index)
2.40 {
2.41 // NOTE: Probably incomplete coverage.
2.42 @@ -628,6 +653,20 @@
2.43 }
2.44
2.45 bool
2.46 +Msc_channel::app_command_with_data(uint8_t index)
2.47 +{
2.48 + // NOTE: Probably incomplete coverage.
2.49 +
2.50 + switch (index)
2.51 + {
2.52 + case App_command_sd_status: return true;
2.53 + case App_command_send_num_wr_blocks: return true;
2.54 + case App_command_send_scr: return true;
2.55 + default: return false;
2.56 + }
2.57 +}
2.58 +
2.59 +bool
2.60 Msc_channel::command_uses_busy(uint8_t index)
2.61 {
2.62 // NOTE: Probably incomplete coverage.
2.63 @@ -640,6 +679,16 @@
2.64 }
2.65 }
2.66
2.67 +bool
2.68 +Msc_channel::app_command_uses_busy(uint8_t index)
2.69 +{
2.70 + // NOTE: Probably incomplete coverage.
2.71 +
2.72 + (void) index;
2.73 +
2.74 + return false;
2.75 +}
2.76 +
2.77 uint8_t
2.78 Msc_channel::get_response_format(uint8_t index)
2.79 {
2.80 @@ -776,11 +825,13 @@
2.81 bool
2.82 Msc_channel::send_app_command(uint8_t index, uint32_t arg)
2.83 {
2.84 - if (!send_command(Command_app_cmd, 0, get_app_response_format(index),
2.85 - false, false, false))
2.86 + if (!send_command(Command_app_cmd, _current_rca << 16))
2.87 return false;
2.88
2.89 - return send_command(index, arg);
2.90 + return send_command(index, arg, get_app_response_format(index),
2.91 + app_command_with_data(index),
2.92 + app_command_will_write(index),
2.93 + app_command_uses_busy(index));
2.94 }
2.95
2.96 // Send a common MMC/SD command.
2.97 @@ -789,7 +840,8 @@
2.98 Msc_channel::send_command(uint8_t index, uint32_t arg)
2.99 {
2.100 return send_command(index, arg, get_response_format(index),
2.101 - command_with_data(index), command_will_write(index),
2.102 + command_with_data(index),
2.103 + command_will_write(index),
2.104 command_uses_busy(index));
2.105 }
2.106
2.107 @@ -821,7 +873,7 @@
2.108 // NOTE: May need to set the SD bus width.
2.109
2.110 set_field(Msc_command_data_control, Cdc_bus_width_field_mask,
2.111 - Cdc_bus_width_field_shift, Cdc_bus_width_field_1bit);
2.112 + Cdc_bus_width_field_shift, encode_bus_width(_current_bus_width));
2.113
2.114 set_field(Msc_command_data_control, Cdc_recv_fifo_level_field_mask,
2.115 Cdc_recv_fifo_level_field_shift, Cdc_fifo_level_16);
2.116 @@ -1075,6 +1127,10 @@
2.117 else
2.118 return;
2.119
2.120 + // Set the default bus width.
2.121 +
2.122 + _bus_width[_cards] = 0;
2.123 +
2.124 _cards++;
2.125 }
2.126 }
2.127 @@ -1167,13 +1223,19 @@
2.128 _current_rca = _rca[card];
2.129 }
2.130
2.131 -#if 0
2.132 - // NOTE: SMEM cards should allow bus width setting.
2.133 + // NOTE: SMEM cards should allow bus width setting with the SCR register
2.134 + // NOTE: describing the permitted values.
2.135 // NOTE: SDIO cards have their bus width set in CCCR via CMD52.
2.136
2.137 - printf("set bus width -> %s\n",
2.138 - send_app_command(App_command_set_bus_width, Bus_width_4bit) ? "set" : "not set");
2.139 -#endif
2.140 + if (!_bus_width[card])
2.141 + {
2.142 + if (send_app_command(App_command_set_bus_width, Bus_width_4bit))
2.143 + _bus_width[card] = 4;
2.144 + else
2.145 + _bus_width[card] = 1;
2.146 + }
2.147 +
2.148 + _current_bus_width = _bus_width[card];
2.149
2.150 if (!send_command(Command_set_blocklen, block_size))
2.151 return 0;