1 /* 2 * MSC (MMC/SD controller) peripheral support. 3 * 4 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/devices/msc-common.h> 25 #include <l4/sys/types.h> 26 #include <stdint.h> 27 28 29 30 #ifdef __cplusplus 31 32 #include <l4/devices/dma-x1600.h> 33 34 // MMC/SD controller channel. 35 36 class Msc_x1600_channel : public Msc_channel 37 { 38 protected: 39 Dma_x1600_channel *_dma; 40 enum Dma_x1600_request_type _request_type_in, _request_type_out; 41 42 // Special overridden method. 43 44 void reset(); 45 46 public: 47 explicit Msc_x1600_channel(l4_addr_t msc_start, l4_addr_t addr, 48 l4_cap_idx_t irq, Cpm_chip *cpm, 49 enum Clock_identifiers clock, 50 Dma_x1600_channel *dma, 51 enum Dma_x1600_request_type request_type_in, 52 enum Dma_x1600_request_type request_type_out); 53 54 uint32_t transfer(l4re_dma_space_dma_addr_t from_paddr, 55 l4re_dma_space_dma_addr_t to_paddr, 56 bool recv, uint32_t count); 57 }; 58 59 // MMC/SD controller device control. 60 61 class Msc_x1600_chip : public Msc_chip 62 { 63 protected: 64 const enum Dma_x1600_request_type _in_types[2] = 65 {Dma_request_msc0_in, Dma_request_msc1_in}; 66 67 const enum Dma_x1600_request_type _out_types[2] = 68 {Dma_request_msc0_out, Dma_request_msc1_out}; 69 70 const enum Clock_identifiers _clocks[2] = 71 {Clock_msc0, Clock_msc1}; 72 73 unsigned int num_channels() 74 { return 2; } 75 76 public: 77 explicit Msc_x1600_chip(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end, 78 Cpm_chip *cpm); 79 80 Msc_channel *get_channel(uint8_t channel, l4_cap_idx_t irq, 81 Dma_x1600_channel *dma); 82 }; 83 84 #endif /* __cplusplus */ 85 86 /* C language interface. */ 87 88 EXTERN_C_BEGIN 89 90 void *x1600_msc_init(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end, 91 void *cpm); 92 93 void *x1600_msc_get_channel(void *msc, uint8_t channel, l4_cap_idx_t irq, 94 void *dma); 95 96 struct msc_card *x1600_msc_get_cards(void *msc_channel); 97 98 uint8_t x1600_msc_num_cards(void *msc_channel); 99 100 void x1600_msc_enable(void *msc_channel); 101 102 uint32_t x1600_msc_read(void *msc_channel, uint8_t card, 103 struct dma_region *region, 104 uint32_t address, uint32_t count); 105 106 uint32_t x1600_msc_read_blocks(void *msc_channel, uint8_t card, 107 struct dma_region *region, 108 uint32_t block_address, uint32_t block_count); 109 110 EXTERN_C_END