Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * SD Association Host Standard Specification v2.0 controller emulation |
| 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 5 | * Mitsyanko Igor <i.mitsyanko@samsung.com> |
| 6 | * Peter A.G. Crosthwaite <peter.crosthwaite@petalogix.com> |
| 7 | * |
| 8 | * Based on MMC controller for Samsung S5PC1xx-based board emulation |
| 9 | * by Alexey Merkulov and Vladimir Monakhov. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 | * See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU _General Public License along |
| 22 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
| 23 | */ |
| 24 | |
| 25 | #ifndef SDHCI_H |
| 26 | #define SDHCI_H |
| 27 | |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 28 | #include "hw/pci/pci.h" |
| 29 | #include "hw/sysbus.h" |
| 30 | #include "hw/sd/sd.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 31 | #include "qom/object.h" |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 32 | |
| 33 | /* SD/MMC host controller state */ |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 34 | struct SDHCIState { |
Philippe Mathieu-Daudé | f82a0f4 | 2018-01-16 13:28:15 +0000 | [diff] [blame] | 35 | /*< private >*/ |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 36 | union { |
| 37 | PCIDevice pcidev; |
| 38 | SysBusDevice busdev; |
| 39 | }; |
Philippe Mathieu-Daudé | f82a0f4 | 2018-01-16 13:28:15 +0000 | [diff] [blame] | 40 | |
| 41 | /*< public >*/ |
Peter Maydell | 40bbc19 | 2016-02-18 14:16:18 +0000 | [diff] [blame] | 42 | SDBus sdbus; |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 43 | MemoryRegion iomem; |
Philippe Mathieu-Daudé | 02e57e1 | 2018-01-25 11:45:30 +0000 | [diff] [blame] | 44 | AddressSpace sysbus_dma_as; |
Philippe Mathieu-Daudé | dd55c48 | 2018-01-16 13:28:21 +0000 | [diff] [blame] | 45 | AddressSpace *dma_as; |
Philippe Mathieu-Daudé | 60765b6 | 2018-01-16 13:28:21 +0000 | [diff] [blame] | 46 | MemoryRegion *dma_mr; |
Andrey Smirnov | fd1e5c8 | 2018-02-09 10:40:29 +0000 | [diff] [blame] | 47 | const MemoryRegionOps *io_ops; |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 48 | |
| 49 | QEMUTimer *insert_timer; /* timer for 'changing' sd card. */ |
| 50 | QEMUTimer *transfer_timer; |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 51 | qemu_irq irq; |
| 52 | |
Philippe Mathieu-Daudé | f82a0f4 | 2018-01-16 13:28:15 +0000 | [diff] [blame] | 53 | /* Registers cleared on reset */ |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 54 | uint32_t sdmasysad; /* SDMA System Address register */ |
| 55 | uint16_t blksize; /* Host DMA Buff Boundary and Transfer BlkSize Reg */ |
| 56 | uint16_t blkcnt; /* Blocks count for current transfer */ |
| 57 | uint32_t argument; /* Command Argument Register */ |
| 58 | uint16_t trnmod; /* Transfer Mode Setting Register */ |
| 59 | uint16_t cmdreg; /* Command Register */ |
| 60 | uint32_t rspreg[4]; /* Response Registers 0-3 */ |
| 61 | uint32_t prnsts; /* Present State Register */ |
Philippe Mathieu-Daudé | 06c5120 | 2018-02-08 13:48:06 -0300 | [diff] [blame] | 62 | uint8_t hostctl1; /* Host Control Register */ |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 63 | uint8_t pwrcon; /* Power control Register */ |
| 64 | uint8_t blkgap; /* Block Gap Control Register */ |
| 65 | uint8_t wakcon; /* WakeUp Control Register */ |
| 66 | uint16_t clkcon; /* Clock control Register */ |
| 67 | uint8_t timeoutcon; /* Timeout Control Register */ |
| 68 | uint8_t admaerr; /* ADMA Error Status Register */ |
| 69 | uint16_t norintsts; /* Normal Interrupt Status Register */ |
| 70 | uint16_t errintsts; /* Error Interrupt Status Register */ |
| 71 | uint16_t norintstsen; /* Normal Interrupt Status Enable Register */ |
| 72 | uint16_t errintstsen; /* Error Interrupt Status Enable Register */ |
| 73 | uint16_t norintsigen; /* Normal Interrupt Signal Enable Register */ |
| 74 | uint16_t errintsigen; /* Error Interrupt Signal Enable Register */ |
| 75 | uint16_t acmd12errsts; /* Auto CMD12 error status register */ |
Philippe Mathieu-Daudé | ea55a22 | 2018-02-08 13:48:07 -0300 | [diff] [blame] | 76 | uint16_t hostctl2; /* Host Control 2 */ |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 77 | uint64_t admasysaddr; /* ADMA System Address Register */ |
Guenter Roeck | 3b2d817 | 2020-06-16 10:32:29 +0100 | [diff] [blame] | 78 | uint16_t vendor_spec; /* Vendor specific register */ |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 79 | |
Philippe Mathieu-Daudé | f82a0f4 | 2018-01-16 13:28:15 +0000 | [diff] [blame] | 80 | /* Read-only registers */ |
Philippe Mathieu-Daudé | 5efc901 | 2018-01-16 13:28:20 +0000 | [diff] [blame] | 81 | uint64_t capareg; /* Capabilities Register */ |
| 82 | uint64_t maxcurr; /* Maximum Current Capabilities Register */ |
Philippe Mathieu-Daudé | aceb5b0 | 2018-02-08 13:47:55 -0300 | [diff] [blame] | 83 | uint16_t version; /* Host Controller Version Register */ |
Philippe Mathieu-Daudé | f82a0f4 | 2018-01-16 13:28:15 +0000 | [diff] [blame] | 84 | |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 85 | uint8_t *fifo_buffer; /* SD host i/o FIFO buffer */ |
| 86 | uint32_t buf_maxsz; |
| 87 | uint16_t data_count; /* current element in FIFO buffer */ |
| 88 | uint8_t stopped_state;/* Current SDHC state */ |
Andrew Baumann | 0a7ac9f | 2016-02-25 13:35:30 -0800 | [diff] [blame] | 89 | bool pending_insert_state; |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 90 | /* Buffer Data Port Register - virtual access point to R and W buffers */ |
| 91 | /* Software Reset Register - always reads as 0 */ |
| 92 | /* Force Event Auto CMD12 Error Interrupt Reg - write only */ |
| 93 | /* Force Event Error Interrupt Register- write only */ |
| 94 | /* RO Host Controller Version Register always reads as 0x2401 */ |
Philippe Mathieu-Daudé | b635d98 | 2018-01-16 13:28:16 +0000 | [diff] [blame] | 95 | |
| 96 | /* Configurable properties */ |
| 97 | bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ |
Andrey Smirnov | fd1e5c8 | 2018-02-09 10:40:29 +0000 | [diff] [blame] | 98 | uint32_t quirks; |
Philippe Mathieu-Daudé | aceb5b0 | 2018-02-08 13:47:55 -0300 | [diff] [blame] | 99 | uint8_t sd_spec_version; |
Philippe Mathieu-Daudé | 0034ebe | 2018-02-08 13:48:09 -0300 | [diff] [blame] | 100 | uint8_t uhs_mode; |
Guenter Roeck | 3b2d817 | 2020-06-16 10:32:29 +0100 | [diff] [blame] | 101 | uint8_t vendor; /* For vendor specific functionality */ |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 102 | }; |
| 103 | typedef struct SDHCIState SDHCIState; |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 104 | |
Guenter Roeck | 3b2d817 | 2020-06-16 10:32:29 +0100 | [diff] [blame] | 105 | #define SDHCI_VENDOR_NONE 0 |
| 106 | #define SDHCI_VENDOR_IMX 1 |
| 107 | |
Andrey Smirnov | fd1e5c8 | 2018-02-09 10:40:29 +0000 | [diff] [blame] | 108 | /* |
| 109 | * Controller does not provide transfer-complete interrupt when not |
| 110 | * busy. |
| 111 | * |
| 112 | * NOTE: This definition is taken out of Linux kernel and so the |
| 113 | * original bit number is preserved |
| 114 | */ |
| 115 | #define SDHCI_QUIRK_NO_BUSY_IRQ BIT(14) |
| 116 | |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 117 | #define TYPE_PCI_SDHCI "sdhci-pci" |
Eduardo Habkost | 8110fa1 | 2020-08-31 17:07:33 -0400 | [diff] [blame] | 118 | DECLARE_INSTANCE_CHECKER(SDHCIState, PCI_SDHCI, |
| 119 | TYPE_PCI_SDHCI) |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 120 | |
| 121 | #define TYPE_SYSBUS_SDHCI "generic-sdhci" |
Eduardo Habkost | 8110fa1 | 2020-08-31 17:07:33 -0400 | [diff] [blame] | 122 | DECLARE_INSTANCE_CHECKER(SDHCIState, SYSBUS_SDHCI, |
| 123 | TYPE_SYSBUS_SDHCI) |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 124 | |
Andrey Smirnov | fd1e5c8 | 2018-02-09 10:40:29 +0000 | [diff] [blame] | 125 | #define TYPE_IMX_USDHC "imx-usdhc" |
| 126 | |
Philippe Mathieu-Daudé | c85fba5 | 2019-10-22 16:50:37 +0100 | [diff] [blame] | 127 | #define TYPE_S3C_SDHCI "s3c-sdhci" |
| 128 | |
Sai Pavan Boddu | 637d23b | 2015-10-08 18:51:02 +0530 | [diff] [blame] | 129 | #endif /* SDHCI_H */ |