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-jz4780.h> 33 34 // MMC/SD controller channel. 35 36 class Msc_jz4780_channel : public Msc_channel 37 { 38 protected: 39 Dma_jz4780_channel *_dma; 40 enum Dma_jz4780_request_type _request_type_in, _request_type_out; 41 42 public: 43 explicit Msc_jz4780_channel(l4_addr_t msc_start, l4_addr_t addr, 44 l4_cap_idx_t irq, Cpm_chip *cpm, 45 enum Clock_identifiers clock, 46 Dma_jz4780_channel *dma, 47 enum Dma_jz4780_request_type request_type_in, 48 enum Dma_jz4780_request_type request_type_out); 49 50 uint32_t transfer(l4re_dma_space_dma_addr_t from_paddr, 51 l4re_dma_space_dma_addr_t to_paddr, 52 bool recv, uint32_t count); 53 }; 54 55 56 57 // MMC/SD controller device control. 58 59 class Msc_jz4780_chip : public Msc_chip 60 { 61 protected: 62 const enum Dma_jz4780_request_type _in_types[3] = 63 {Dma_request_msc0_in, Dma_request_msc1_in, Dma_request_msc2_in}; 64 65 const enum Dma_jz4780_request_type _out_types[3] = 66 {Dma_request_msc0_out, Dma_request_msc1_out, Dma_request_msc2_out}; 67 68 const enum Clock_identifiers _clocks[3] = 69 {Clock_msc0, Clock_msc1, Clock_msc2}; 70 71 unsigned int num_channels() 72 { return 3; } 73 74 public: 75 explicit Msc_jz4780_chip(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end, 76 Cpm_chip *cpm); 77 78 Msc_channel *get_channel(uint8_t channel, l4_cap_idx_t irq, 79 Dma_jz4780_channel *dma); 80 }; 81 82 #endif /* __cplusplus */ 83 84 /* C language interface. */ 85 86 EXTERN_C_BEGIN 87 88 void *jz4780_msc_init(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end, 89 void *cpm); 90 91 void *jz4780_msc_get_channel(void *msc, uint8_t channel, l4_cap_idx_t irq, 92 void *dma); 93 94 struct msc_card *jz4780_msc_get_cards(void *msc_channel); 95 96 uint8_t jz4780_msc_num_cards(void *msc_channel); 97 98 void jz4780_msc_enable(void *msc_channel); 99 100 uint32_t jz4780_msc_read(void *msc_channel, uint8_t card, 101 struct dma_region *region, 102 uint32_t address, uint32_t count); 103 104 uint32_t jz4780_msc_read_blocks(void *msc_channel, uint8_t card, 105 struct dma_region *region, 106 uint32_t block_address, uint32_t block_count); 107 108 EXTERN_C_END