1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/msc/include/msc.h Fri Feb 16 23:11:25 2024 +0100
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 + * MSC (MMC/SD controller) structures.
1.6 + *
1.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <stdint.h>
1.28 +
1.29 +
1.30 +
1.31 +/* MMC/SD structures. */
1.32 +
1.33 +struct CID
1.34 +{
1.35 + uint16_t month:4, year:8, reserved:4;
1.36 + uint32_t serial;
1.37 + uint8_t revision;
1.38 + char name[5];
1.39 + uint16_t oem;
1.40 + uint8_t manufacturer;
1.41 +} __attribute__((packed));
1.42 +
1.43 +struct CSD
1.44 +{
1.45 + uint8_t reserved0:2,
1.46 + format:2,
1.47 + temp_write_prot:1,
1.48 + perm_write_prot:1,
1.49 + copy:1,
1.50 + format_group:1;
1.51 + uint16_t reserved1:5,
1.52 + write_block_partial:1,
1.53 + write_blocklen:4,
1.54 + write_time_factor:3,
1.55 + reserved2:2,
1.56 + write_prot_group_enable:1;
1.57 + uint64_t write_prot_group_size:7,
1.58 + erase_sector_size:7,
1.59 + erase_single_block_enable:1,
1.60 + device_size_multiplier:3,
1.61 + max_write_current_max:3,
1.62 + max_write_current_min:3,
1.63 + max_read_current_max:3,
1.64 + max_read_current_min:3,
1.65 + device_size:12,
1.66 + reserved3:2,
1.67 + dsr_implemented:1,
1.68 + read_block_misalign:1,
1.69 + write_block_misalign:1,
1.70 + read_block_partial:1,
1.71 + read_blocklen:4,
1.72 + card_command_classes:12;
1.73 + uint8_t tran_speed,
1.74 + data_read_access_time_2,
1.75 + data_read_access_time_1,
1.76 + reserved4:6,
1.77 + csd:2;
1.78 +} __attribute__((packed));
1.79 +
1.80 +
1.81 +
1.82 +/* Generic card structure. */
1.83 +
1.84 +struct msc_card
1.85 +{
1.86 + uint16_t rca;
1.87 + uint32_t ocr;
1.88 + uint8_t bus_width;
1.89 + struct CID cid;
1.90 + struct CSD csd;
1.91 +};