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/re/c/dma_space.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 #include <l4/devices/msc-common.h> 34 35 // MMC/SD controller channel. 36 37 class Msc_jz4780_channel : public Msc_channel 38 { 39 protected: 40 Dma_jz4780_channel *_dma; 41 enum Dma_jz4780_request_type _request_type_in, _request_type_out; 42 43 public: 44 explicit Msc_jz4780_channel(l4_addr_t msc_start, l4_addr_t addr, 45 l4_cap_idx_t irq, Dma_jz4780_channel *dma, 46 enum Dma_jz4780_request_type request_type_in, 47 enum Dma_jz4780_request_type request_type_out); 48 49 uint32_t transfer(l4re_dma_space_dma_addr_t from_paddr, 50 l4re_dma_space_dma_addr_t to_paddr, 51 bool recv, uint32_t count); 52 }; 53 54 55 56 // MMC/SD controller device control. 57 58 class Msc_jz4780_chip : public Msc_chip 59 { 60 protected: 61 unsigned int num_channels() 62 { return 3; } 63 64 public: 65 explicit Msc_jz4780_chip(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end); 66 67 Msc_channel *get_channel(uint8_t channel, l4_cap_idx_t irq, 68 Dma_jz4780_channel *dma); 69 }; 70 71 #endif /* __cplusplus */ 72 73 /* C language interface. */ 74 75 EXTERN_C_BEGIN 76 77 void *jz4780_msc_init(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end); 78 79 void *jz4780_msc_get_channel(void *msc, uint8_t channel, l4_cap_idx_t irq, 80 void *dma); 81 82 uint32_t jz4780_msc_get_status(void *msc_channel); 83 84 void jz4780_msc_enable(void *msc_channel); 85 86 uint32_t jz4780_msc_read_block(void *msc_channel, uint8_t card, 87 l4re_dma_space_dma_addr_t paddr); 88 89 EXTERN_C_END