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