162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * linux/drivers/mmc/host/sdhci.h - Secure Digital Host Controller Interface driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Header file for Host Controller registers and I/O accessors. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci#ifndef __SDHCI_HW_H 1062306a36Sopenharmony_ci#define __SDHCI_HW_H 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/bits.h> 1362306a36Sopenharmony_ci#include <linux/scatterlist.h> 1462306a36Sopenharmony_ci#include <linux/compiler.h> 1562306a36Sopenharmony_ci#include <linux/types.h> 1662306a36Sopenharmony_ci#include <linux/io.h> 1762306a36Sopenharmony_ci#include <linux/leds.h> 1862306a36Sopenharmony_ci#include <linux/interrupt.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <linux/mmc/host.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * Controller registers 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define SDHCI_DMA_ADDRESS 0x00 2762306a36Sopenharmony_ci#define SDHCI_ARGUMENT2 SDHCI_DMA_ADDRESS 2862306a36Sopenharmony_ci#define SDHCI_32BIT_BLK_CNT SDHCI_DMA_ADDRESS 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define SDHCI_BLOCK_SIZE 0x04 3162306a36Sopenharmony_ci#define SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF)) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define SDHCI_BLOCK_COUNT 0x06 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define SDHCI_ARGUMENT 0x08 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define SDHCI_TRANSFER_MODE 0x0C 3862306a36Sopenharmony_ci#define SDHCI_TRNS_DMA 0x01 3962306a36Sopenharmony_ci#define SDHCI_TRNS_BLK_CNT_EN 0x02 4062306a36Sopenharmony_ci#define SDHCI_TRNS_AUTO_CMD12 0x04 4162306a36Sopenharmony_ci#define SDHCI_TRNS_AUTO_CMD23 0x08 4262306a36Sopenharmony_ci#define SDHCI_TRNS_AUTO_SEL 0x0C 4362306a36Sopenharmony_ci#define SDHCI_TRNS_READ 0x10 4462306a36Sopenharmony_ci#define SDHCI_TRNS_MULTI 0x20 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define SDHCI_COMMAND 0x0E 4762306a36Sopenharmony_ci#define SDHCI_CMD_RESP_MASK 0x03 4862306a36Sopenharmony_ci#define SDHCI_CMD_CRC 0x08 4962306a36Sopenharmony_ci#define SDHCI_CMD_INDEX 0x10 5062306a36Sopenharmony_ci#define SDHCI_CMD_DATA 0x20 5162306a36Sopenharmony_ci#define SDHCI_CMD_ABORTCMD 0xC0 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define SDHCI_CMD_RESP_NONE 0x00 5462306a36Sopenharmony_ci#define SDHCI_CMD_RESP_LONG 0x01 5562306a36Sopenharmony_ci#define SDHCI_CMD_RESP_SHORT 0x02 5662306a36Sopenharmony_ci#define SDHCI_CMD_RESP_SHORT_BUSY 0x03 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff)) 5962306a36Sopenharmony_ci#define SDHCI_GET_CMD(c) ((c>>8) & 0x3f) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#define SDHCI_RESPONSE 0x10 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define SDHCI_BUFFER 0x20 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define SDHCI_PRESENT_STATE 0x24 6662306a36Sopenharmony_ci#define SDHCI_CMD_INHIBIT 0x00000001 6762306a36Sopenharmony_ci#define SDHCI_DATA_INHIBIT 0x00000002 6862306a36Sopenharmony_ci#define SDHCI_DOING_WRITE 0x00000100 6962306a36Sopenharmony_ci#define SDHCI_DOING_READ 0x00000200 7062306a36Sopenharmony_ci#define SDHCI_SPACE_AVAILABLE 0x00000400 7162306a36Sopenharmony_ci#define SDHCI_DATA_AVAILABLE 0x00000800 7262306a36Sopenharmony_ci#define SDHCI_CARD_PRESENT 0x00010000 7362306a36Sopenharmony_ci#define SDHCI_CARD_PRES_SHIFT 16 7462306a36Sopenharmony_ci#define SDHCI_CD_STABLE 0x00020000 7562306a36Sopenharmony_ci#define SDHCI_CD_LVL 0x00040000 7662306a36Sopenharmony_ci#define SDHCI_CD_LVL_SHIFT 18 7762306a36Sopenharmony_ci#define SDHCI_WRITE_PROTECT 0x00080000 7862306a36Sopenharmony_ci#define SDHCI_DATA_LVL_MASK 0x00F00000 7962306a36Sopenharmony_ci#define SDHCI_DATA_LVL_SHIFT 20 8062306a36Sopenharmony_ci#define SDHCI_DATA_0_LVL_MASK 0x00100000 8162306a36Sopenharmony_ci#define SDHCI_CMD_LVL 0x01000000 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define SDHCI_HOST_CONTROL 0x28 8462306a36Sopenharmony_ci#define SDHCI_CTRL_LED 0x01 8562306a36Sopenharmony_ci#define SDHCI_CTRL_4BITBUS 0x02 8662306a36Sopenharmony_ci#define SDHCI_CTRL_HISPD 0x04 8762306a36Sopenharmony_ci#define SDHCI_CTRL_DMA_MASK 0x18 8862306a36Sopenharmony_ci#define SDHCI_CTRL_SDMA 0x00 8962306a36Sopenharmony_ci#define SDHCI_CTRL_ADMA1 0x08 9062306a36Sopenharmony_ci#define SDHCI_CTRL_ADMA32 0x10 9162306a36Sopenharmony_ci#define SDHCI_CTRL_ADMA64 0x18 9262306a36Sopenharmony_ci#define SDHCI_CTRL_ADMA3 0x18 9362306a36Sopenharmony_ci#define SDHCI_CTRL_8BITBUS 0x20 9462306a36Sopenharmony_ci#define SDHCI_CTRL_CDTEST_INS 0x40 9562306a36Sopenharmony_ci#define SDHCI_CTRL_CDTEST_EN 0x80 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#define SDHCI_POWER_CONTROL 0x29 9862306a36Sopenharmony_ci#define SDHCI_POWER_ON 0x01 9962306a36Sopenharmony_ci#define SDHCI_POWER_180 0x0A 10062306a36Sopenharmony_ci#define SDHCI_POWER_300 0x0C 10162306a36Sopenharmony_ci#define SDHCI_POWER_330 0x0E 10262306a36Sopenharmony_ci/* 10362306a36Sopenharmony_ci * VDD2 - UHS2 or PCIe/NVMe 10462306a36Sopenharmony_ci * VDD2 power on/off and voltage select 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_ci#define SDHCI_VDD2_POWER_ON 0x10 10762306a36Sopenharmony_ci#define SDHCI_VDD2_POWER_120 0x80 10862306a36Sopenharmony_ci#define SDHCI_VDD2_POWER_180 0xA0 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#define SDHCI_BLOCK_GAP_CONTROL 0x2A 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#define SDHCI_WAKE_UP_CONTROL 0x2B 11362306a36Sopenharmony_ci#define SDHCI_WAKE_ON_INT 0x01 11462306a36Sopenharmony_ci#define SDHCI_WAKE_ON_INSERT 0x02 11562306a36Sopenharmony_ci#define SDHCI_WAKE_ON_REMOVE 0x04 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci#define SDHCI_CLOCK_CONTROL 0x2C 11862306a36Sopenharmony_ci#define SDHCI_DIVIDER_SHIFT 8 11962306a36Sopenharmony_ci#define SDHCI_DIVIDER_HI_SHIFT 6 12062306a36Sopenharmony_ci#define SDHCI_DIV_MASK 0xFF 12162306a36Sopenharmony_ci#define SDHCI_DIV_MASK_LEN 8 12262306a36Sopenharmony_ci#define SDHCI_DIV_HI_MASK 0x300 12362306a36Sopenharmony_ci#define SDHCI_PROG_CLOCK_MODE 0x0020 12462306a36Sopenharmony_ci#define SDHCI_CLOCK_CARD_EN 0x0004 12562306a36Sopenharmony_ci#define SDHCI_CLOCK_PLL_EN 0x0008 12662306a36Sopenharmony_ci#define SDHCI_CLOCK_INT_STABLE 0x0002 12762306a36Sopenharmony_ci#define SDHCI_CLOCK_INT_EN 0x0001 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#define SDHCI_TIMEOUT_CONTROL 0x2E 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci#define SDHCI_SOFTWARE_RESET 0x2F 13262306a36Sopenharmony_ci#define SDHCI_RESET_ALL 0x01 13362306a36Sopenharmony_ci#define SDHCI_RESET_CMD 0x02 13462306a36Sopenharmony_ci#define SDHCI_RESET_DATA 0x04 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define SDHCI_INT_STATUS 0x30 13762306a36Sopenharmony_ci#define SDHCI_INT_ENABLE 0x34 13862306a36Sopenharmony_ci#define SDHCI_SIGNAL_ENABLE 0x38 13962306a36Sopenharmony_ci#define SDHCI_INT_RESPONSE 0x00000001 14062306a36Sopenharmony_ci#define SDHCI_INT_DATA_END 0x00000002 14162306a36Sopenharmony_ci#define SDHCI_INT_BLK_GAP 0x00000004 14262306a36Sopenharmony_ci#define SDHCI_INT_DMA_END 0x00000008 14362306a36Sopenharmony_ci#define SDHCI_INT_SPACE_AVAIL 0x00000010 14462306a36Sopenharmony_ci#define SDHCI_INT_DATA_AVAIL 0x00000020 14562306a36Sopenharmony_ci#define SDHCI_INT_CARD_INSERT 0x00000040 14662306a36Sopenharmony_ci#define SDHCI_INT_CARD_REMOVE 0x00000080 14762306a36Sopenharmony_ci#define SDHCI_INT_CARD_INT 0x00000100 14862306a36Sopenharmony_ci#define SDHCI_INT_RETUNE 0x00001000 14962306a36Sopenharmony_ci#define SDHCI_INT_CQE 0x00004000 15062306a36Sopenharmony_ci#define SDHCI_INT_ERROR 0x00008000 15162306a36Sopenharmony_ci#define SDHCI_INT_TIMEOUT 0x00010000 15262306a36Sopenharmony_ci#define SDHCI_INT_CRC 0x00020000 15362306a36Sopenharmony_ci#define SDHCI_INT_END_BIT 0x00040000 15462306a36Sopenharmony_ci#define SDHCI_INT_INDEX 0x00080000 15562306a36Sopenharmony_ci#define SDHCI_INT_DATA_TIMEOUT 0x00100000 15662306a36Sopenharmony_ci#define SDHCI_INT_DATA_CRC 0x00200000 15762306a36Sopenharmony_ci#define SDHCI_INT_DATA_END_BIT 0x00400000 15862306a36Sopenharmony_ci#define SDHCI_INT_BUS_POWER 0x00800000 15962306a36Sopenharmony_ci#define SDHCI_INT_AUTO_CMD_ERR 0x01000000 16062306a36Sopenharmony_ci#define SDHCI_INT_ADMA_ERROR 0x02000000 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define SDHCI_INT_NORMAL_MASK 0x00007FFF 16362306a36Sopenharmony_ci#define SDHCI_INT_ERROR_MASK 0xFFFF8000 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci#define SDHCI_INT_CMD_MASK (SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | \ 16662306a36Sopenharmony_ci SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX | \ 16762306a36Sopenharmony_ci SDHCI_INT_AUTO_CMD_ERR) 16862306a36Sopenharmony_ci#define SDHCI_INT_DATA_MASK (SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | \ 16962306a36Sopenharmony_ci SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \ 17062306a36Sopenharmony_ci SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \ 17162306a36Sopenharmony_ci SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \ 17262306a36Sopenharmony_ci SDHCI_INT_BLK_GAP) 17362306a36Sopenharmony_ci#define SDHCI_INT_ALL_MASK ((unsigned int)-1) 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci#define SDHCI_CQE_INT_ERR_MASK ( \ 17662306a36Sopenharmony_ci SDHCI_INT_ADMA_ERROR | SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | \ 17762306a36Sopenharmony_ci SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX | \ 17862306a36Sopenharmony_ci SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT) 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci#define SDHCI_CQE_INT_MASK (SDHCI_CQE_INT_ERR_MASK | SDHCI_INT_CQE) 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci#define SDHCI_AUTO_CMD_STATUS 0x3C 18362306a36Sopenharmony_ci#define SDHCI_AUTO_CMD_TIMEOUT 0x00000002 18462306a36Sopenharmony_ci#define SDHCI_AUTO_CMD_CRC 0x00000004 18562306a36Sopenharmony_ci#define SDHCI_AUTO_CMD_END_BIT 0x00000008 18662306a36Sopenharmony_ci#define SDHCI_AUTO_CMD_INDEX 0x00000010 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci#define SDHCI_HOST_CONTROL2 0x3E 18962306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_MASK 0x0007 19062306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_SDR12 0x0000 19162306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_SDR25 0x0001 19262306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_SDR50 0x0002 19362306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_SDR104 0x0003 19462306a36Sopenharmony_ci#define SDHCI_CTRL_UHS_DDR50 0x0004 19562306a36Sopenharmony_ci#define SDHCI_CTRL_HS400 0x0005 /* Non-standard */ 19662306a36Sopenharmony_ci#define SDHCI_CTRL_VDD_180 0x0008 19762306a36Sopenharmony_ci#define SDHCI_CTRL_DRV_TYPE_MASK 0x0030 19862306a36Sopenharmony_ci#define SDHCI_CTRL_DRV_TYPE_B 0x0000 19962306a36Sopenharmony_ci#define SDHCI_CTRL_DRV_TYPE_A 0x0010 20062306a36Sopenharmony_ci#define SDHCI_CTRL_DRV_TYPE_C 0x0020 20162306a36Sopenharmony_ci#define SDHCI_CTRL_DRV_TYPE_D 0x0030 20262306a36Sopenharmony_ci#define SDHCI_CTRL_EXEC_TUNING 0x0040 20362306a36Sopenharmony_ci#define SDHCI_CTRL_TUNED_CLK 0x0080 20462306a36Sopenharmony_ci#define SDHCI_CMD23_ENABLE 0x0800 20562306a36Sopenharmony_ci#define SDHCI_CTRL_V4_MODE 0x1000 20662306a36Sopenharmony_ci#define SDHCI_CTRL_64BIT_ADDR 0x2000 20762306a36Sopenharmony_ci#define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci#define SDHCI_CAPABILITIES 0x40 21062306a36Sopenharmony_ci#define SDHCI_TIMEOUT_CLK_MASK GENMASK(5, 0) 21162306a36Sopenharmony_ci#define SDHCI_TIMEOUT_CLK_SHIFT 0 21262306a36Sopenharmony_ci#define SDHCI_TIMEOUT_CLK_UNIT 0x00000080 21362306a36Sopenharmony_ci#define SDHCI_CLOCK_BASE_MASK GENMASK(13, 8) 21462306a36Sopenharmony_ci#define SDHCI_CLOCK_BASE_SHIFT 8 21562306a36Sopenharmony_ci#define SDHCI_CLOCK_V3_BASE_MASK GENMASK(15, 8) 21662306a36Sopenharmony_ci#define SDHCI_MAX_BLOCK_MASK 0x00030000 21762306a36Sopenharmony_ci#define SDHCI_MAX_BLOCK_SHIFT 16 21862306a36Sopenharmony_ci#define SDHCI_CAN_DO_8BIT 0x00040000 21962306a36Sopenharmony_ci#define SDHCI_CAN_DO_ADMA2 0x00080000 22062306a36Sopenharmony_ci#define SDHCI_CAN_DO_ADMA1 0x00100000 22162306a36Sopenharmony_ci#define SDHCI_CAN_DO_HISPD 0x00200000 22262306a36Sopenharmony_ci#define SDHCI_CAN_DO_SDMA 0x00400000 22362306a36Sopenharmony_ci#define SDHCI_CAN_DO_SUSPEND 0x00800000 22462306a36Sopenharmony_ci#define SDHCI_CAN_VDD_330 0x01000000 22562306a36Sopenharmony_ci#define SDHCI_CAN_VDD_300 0x02000000 22662306a36Sopenharmony_ci#define SDHCI_CAN_VDD_180 0x04000000 22762306a36Sopenharmony_ci#define SDHCI_CAN_64BIT_V4 0x08000000 22862306a36Sopenharmony_ci#define SDHCI_CAN_64BIT 0x10000000 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci#define SDHCI_CAPABILITIES_1 0x44 23162306a36Sopenharmony_ci#define SDHCI_SUPPORT_SDR50 0x00000001 23262306a36Sopenharmony_ci#define SDHCI_SUPPORT_SDR104 0x00000002 23362306a36Sopenharmony_ci#define SDHCI_SUPPORT_DDR50 0x00000004 23462306a36Sopenharmony_ci#define SDHCI_DRIVER_TYPE_A 0x00000010 23562306a36Sopenharmony_ci#define SDHCI_DRIVER_TYPE_C 0x00000020 23662306a36Sopenharmony_ci#define SDHCI_DRIVER_TYPE_D 0x00000040 23762306a36Sopenharmony_ci#define SDHCI_RETUNING_TIMER_COUNT_MASK GENMASK(11, 8) 23862306a36Sopenharmony_ci#define SDHCI_USE_SDR50_TUNING 0x00002000 23962306a36Sopenharmony_ci#define SDHCI_RETUNING_MODE_MASK GENMASK(15, 14) 24062306a36Sopenharmony_ci#define SDHCI_CLOCK_MUL_MASK GENMASK(23, 16) 24162306a36Sopenharmony_ci#define SDHCI_CAN_DO_ADMA3 0x08000000 24262306a36Sopenharmony_ci#define SDHCI_SUPPORT_HS400 0x80000000 /* Non-standard */ 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT 0x48 24562306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT_LIMIT GENMASK(7, 0) 24662306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT_330_MASK GENMASK(7, 0) 24762306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT_300_MASK GENMASK(15, 8) 24862306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT_180_MASK GENMASK(23, 16) 24962306a36Sopenharmony_ci#define SDHCI_MAX_CURRENT_MULTIPLIER 4 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci/* 4C-4F reserved for more max current */ 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci#define SDHCI_SET_ACMD12_ERROR 0x50 25462306a36Sopenharmony_ci#define SDHCI_SET_INT_ERROR 0x52 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci#define SDHCI_ADMA_ERROR 0x54 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci/* 55-57 reserved */ 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci#define SDHCI_ADMA_ADDRESS 0x58 26162306a36Sopenharmony_ci#define SDHCI_ADMA_ADDRESS_HI 0x5C 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci/* 60-FB reserved */ 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_HIGH_SPEED 0x64 26662306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_SDR12 0x66 26762306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_SDR25 0x68 26862306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_SDR50 0x6A 26962306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_SDR104 0x6C 27062306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_DDR50 0x6E 27162306a36Sopenharmony_ci#define SDHCI_PRESET_FOR_HS400 0x74 /* Non-standard */ 27262306a36Sopenharmony_ci#define SDHCI_PRESET_DRV_MASK GENMASK(15, 14) 27362306a36Sopenharmony_ci#define SDHCI_PRESET_CLKGEN_SEL BIT(10) 27462306a36Sopenharmony_ci#define SDHCI_PRESET_SDCLK_FREQ_MASK GENMASK(9, 0) 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci#define SDHCI_SLOT_INT_STATUS 0xFC 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci#define SDHCI_HOST_VERSION 0xFE 27962306a36Sopenharmony_ci#define SDHCI_VENDOR_VER_MASK 0xFF00 28062306a36Sopenharmony_ci#define SDHCI_VENDOR_VER_SHIFT 8 28162306a36Sopenharmony_ci#define SDHCI_SPEC_VER_MASK 0x00FF 28262306a36Sopenharmony_ci#define SDHCI_SPEC_VER_SHIFT 0 28362306a36Sopenharmony_ci#define SDHCI_SPEC_100 0 28462306a36Sopenharmony_ci#define SDHCI_SPEC_200 1 28562306a36Sopenharmony_ci#define SDHCI_SPEC_300 2 28662306a36Sopenharmony_ci#define SDHCI_SPEC_400 3 28762306a36Sopenharmony_ci#define SDHCI_SPEC_410 4 28862306a36Sopenharmony_ci#define SDHCI_SPEC_420 5 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci/* 29162306a36Sopenharmony_ci * End of controller registers. 29262306a36Sopenharmony_ci */ 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci#define SDHCI_MAX_DIV_SPEC_200 256 29562306a36Sopenharmony_ci#define SDHCI_MAX_DIV_SPEC_300 2046 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ci/* 29862306a36Sopenharmony_ci * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2. 29962306a36Sopenharmony_ci */ 30062306a36Sopenharmony_ci#define SDHCI_DEFAULT_BOUNDARY_SIZE (512 * 1024) 30162306a36Sopenharmony_ci#define SDHCI_DEFAULT_BOUNDARY_ARG (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12) 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci/* ADMA2 32-bit DMA descriptor size */ 30462306a36Sopenharmony_ci#define SDHCI_ADMA2_32_DESC_SZ 8 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci/* ADMA2 32-bit descriptor */ 30762306a36Sopenharmony_cistruct sdhci_adma2_32_desc { 30862306a36Sopenharmony_ci __le16 cmd; 30962306a36Sopenharmony_ci __le16 len; 31062306a36Sopenharmony_ci __le32 addr; 31162306a36Sopenharmony_ci} __packed __aligned(4); 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci/* ADMA2 data alignment */ 31462306a36Sopenharmony_ci#define SDHCI_ADMA2_ALIGN 4 31562306a36Sopenharmony_ci#define SDHCI_ADMA2_MASK (SDHCI_ADMA2_ALIGN - 1) 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci/* 31862306a36Sopenharmony_ci * ADMA2 descriptor alignment. Some controllers (e.g. Intel) require 8 byte 31962306a36Sopenharmony_ci * alignment for the descriptor table even in 32-bit DMA mode. Memory 32062306a36Sopenharmony_ci * allocation is at least 8 byte aligned anyway, so just stipulate 8 always. 32162306a36Sopenharmony_ci */ 32262306a36Sopenharmony_ci#define SDHCI_ADMA2_DESC_ALIGN 8 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci/* 32562306a36Sopenharmony_ci * ADMA2 64-bit DMA descriptor size 32662306a36Sopenharmony_ci * According to SD Host Controller spec v4.10, there are two kinds of 32762306a36Sopenharmony_ci * descriptors for 64-bit addressing mode: 96-bit Descriptor and 128-bit 32862306a36Sopenharmony_ci * Descriptor, if Host Version 4 Enable is set in the Host Control 2 32962306a36Sopenharmony_ci * register, 128-bit Descriptor will be selected. 33062306a36Sopenharmony_ci */ 33162306a36Sopenharmony_ci#define SDHCI_ADMA2_64_DESC_SZ(host) ((host)->v4_mode ? 16 : 12) 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_ci/* 33462306a36Sopenharmony_ci * ADMA2 64-bit descriptor. Note 12-byte descriptor can't always be 8-byte 33562306a36Sopenharmony_ci * aligned. 33662306a36Sopenharmony_ci */ 33762306a36Sopenharmony_cistruct sdhci_adma2_64_desc { 33862306a36Sopenharmony_ci __le16 cmd; 33962306a36Sopenharmony_ci __le16 len; 34062306a36Sopenharmony_ci __le32 addr_lo; 34162306a36Sopenharmony_ci __le32 addr_hi; 34262306a36Sopenharmony_ci} __packed __aligned(4); 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci#define ADMA2_TRAN_VALID 0x21 34562306a36Sopenharmony_ci#define ADMA2_NOP_END_VALID 0x3 34662306a36Sopenharmony_ci#define ADMA2_END 0x2 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ci/* 34962306a36Sopenharmony_ci * Maximum segments assuming a 512KiB maximum requisition size and a minimum 35062306a36Sopenharmony_ci * 4KiB page size. Note this also allows enough for multiple descriptors in 35162306a36Sopenharmony_ci * case of PAGE_SIZE >= 64KiB. 35262306a36Sopenharmony_ci */ 35362306a36Sopenharmony_ci#define SDHCI_MAX_SEGS 128 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/* Allow for a command request and a data request at the same time */ 35662306a36Sopenharmony_ci#define SDHCI_MAX_MRQS 2 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci/* 35962306a36Sopenharmony_ci * 48bit command and 136 bit response in 100KHz clock could take upto 2.48ms. 36062306a36Sopenharmony_ci * However since the start time of the command, the time between 36162306a36Sopenharmony_ci * command and response, and the time between response and start of data is 36262306a36Sopenharmony_ci * not known, set the command transfer time to 10ms. 36362306a36Sopenharmony_ci */ 36462306a36Sopenharmony_ci#define MMC_CMD_TRANSFER_TIME (10 * NSEC_PER_MSEC) /* max 10 ms */ 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ci#define sdhci_err_stats_inc(host, err_name) \ 36762306a36Sopenharmony_ci mmc_debugfs_err_stats_inc((host)->mmc, MMC_ERR_##err_name) 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_cienum sdhci_cookie { 37062306a36Sopenharmony_ci COOKIE_UNMAPPED, 37162306a36Sopenharmony_ci COOKIE_PRE_MAPPED, /* mapped by sdhci_pre_req() */ 37262306a36Sopenharmony_ci COOKIE_MAPPED, /* mapped by sdhci_prepare_data() */ 37362306a36Sopenharmony_ci}; 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_cistruct sdhci_host { 37662306a36Sopenharmony_ci /* Data set by hardware interface driver */ 37762306a36Sopenharmony_ci const char *hw_name; /* Hardware bus name */ 37862306a36Sopenharmony_ci 37962306a36Sopenharmony_ci unsigned int quirks; /* Deviations from spec. */ 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci/* Controller doesn't honor resets unless we touch the clock register */ 38262306a36Sopenharmony_ci#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0) 38362306a36Sopenharmony_ci/* Controller has bad caps bits, but really supports DMA */ 38462306a36Sopenharmony_ci#define SDHCI_QUIRK_FORCE_DMA (1<<1) 38562306a36Sopenharmony_ci/* Controller doesn't like to be reset when there is no card inserted. */ 38662306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) 38762306a36Sopenharmony_ci/* Controller doesn't like clearing the power reg before a change */ 38862306a36Sopenharmony_ci#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) 38962306a36Sopenharmony_ci/* Controller has an unusable DMA engine */ 39062306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_DMA (1<<5) 39162306a36Sopenharmony_ci/* Controller has an unusable ADMA engine */ 39262306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_ADMA (1<<6) 39362306a36Sopenharmony_ci/* Controller can only DMA from 32-bit aligned addresses */ 39462306a36Sopenharmony_ci#define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<7) 39562306a36Sopenharmony_ci/* Controller can only DMA chunk sizes that are a multiple of 32 bits */ 39662306a36Sopenharmony_ci#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<8) 39762306a36Sopenharmony_ci/* Controller can only ADMA chunks that are a multiple of 32 bits */ 39862306a36Sopenharmony_ci#define SDHCI_QUIRK_32BIT_ADMA_SIZE (1<<9) 39962306a36Sopenharmony_ci/* Controller needs to be reset after each request to stay stable */ 40062306a36Sopenharmony_ci#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<10) 40162306a36Sopenharmony_ci/* Controller needs voltage and power writes to happen separately */ 40262306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<11) 40362306a36Sopenharmony_ci/* Controller provides an incorrect timeout value for transfers */ 40462306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_TIMEOUT_VAL (1<<12) 40562306a36Sopenharmony_ci/* Controller has an issue with buffer bits for small transfers */ 40662306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13) 40762306a36Sopenharmony_ci/* Controller does not provide transfer-complete interrupt when not busy */ 40862306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_BUSY_IRQ (1<<14) 40962306a36Sopenharmony_ci/* Controller has unreliable card detection */ 41062306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<15) 41162306a36Sopenharmony_ci/* Controller reports inverted write-protect state */ 41262306a36Sopenharmony_ci#define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<16) 41362306a36Sopenharmony_ci/* Controller has unusable command queue engine */ 41462306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_CQE (1<<17) 41562306a36Sopenharmony_ci/* Controller does not like fast PIO transfers */ 41662306a36Sopenharmony_ci#define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<18) 41762306a36Sopenharmony_ci/* Controller does not have a LED */ 41862306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_LED (1<<19) 41962306a36Sopenharmony_ci/* Controller has to be forced to use block size of 2048 bytes */ 42062306a36Sopenharmony_ci#define SDHCI_QUIRK_FORCE_BLK_SZ_2048 (1<<20) 42162306a36Sopenharmony_ci/* Controller cannot do multi-block transfers */ 42262306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_MULTIBLOCK (1<<21) 42362306a36Sopenharmony_ci/* Controller can only handle 1-bit data transfers */ 42462306a36Sopenharmony_ci#define SDHCI_QUIRK_FORCE_1_BIT_DATA (1<<22) 42562306a36Sopenharmony_ci/* Controller needs 10ms delay between applying power and clock */ 42662306a36Sopenharmony_ci#define SDHCI_QUIRK_DELAY_AFTER_POWER (1<<23) 42762306a36Sopenharmony_ci/* Controller uses SDCLK instead of TMCLK for data timeouts */ 42862306a36Sopenharmony_ci#define SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK (1<<24) 42962306a36Sopenharmony_ci/* Controller reports wrong base clock capability */ 43062306a36Sopenharmony_ci#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25) 43162306a36Sopenharmony_ci/* Controller cannot support End Attribute in NOP ADMA descriptor */ 43262306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26) 43362306a36Sopenharmony_ci/* Controller uses Auto CMD12 command to stop the transfer */ 43462306a36Sopenharmony_ci#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28) 43562306a36Sopenharmony_ci/* Controller doesn't have HISPD bit field in HI-SPEED SD card */ 43662306a36Sopenharmony_ci#define SDHCI_QUIRK_NO_HISPD_BIT (1<<29) 43762306a36Sopenharmony_ci/* Controller treats ADMA descriptors with length 0000h incorrectly */ 43862306a36Sopenharmony_ci#define SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC (1<<30) 43962306a36Sopenharmony_ci/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */ 44062306a36Sopenharmony_ci#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31) 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ci unsigned int quirks2; /* More deviations from spec. */ 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci#define SDHCI_QUIRK2_HOST_OFF_CARD_ON (1<<0) 44562306a36Sopenharmony_ci#define SDHCI_QUIRK2_HOST_NO_CMD23 (1<<1) 44662306a36Sopenharmony_ci/* The system physically doesn't support 1.8v, even if the host does */ 44762306a36Sopenharmony_ci#define SDHCI_QUIRK2_NO_1_8_V (1<<2) 44862306a36Sopenharmony_ci#define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3) 44962306a36Sopenharmony_ci#define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4) 45062306a36Sopenharmony_ci/* Controller has a non-standard host control register */ 45162306a36Sopenharmony_ci#define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5) 45262306a36Sopenharmony_ci/* Controller does not support HS200 */ 45362306a36Sopenharmony_ci#define SDHCI_QUIRK2_BROKEN_HS200 (1<<6) 45462306a36Sopenharmony_ci/* Controller does not support DDR50 */ 45562306a36Sopenharmony_ci#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7) 45662306a36Sopenharmony_ci/* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */ 45762306a36Sopenharmony_ci#define SDHCI_QUIRK2_STOP_WITH_TC (1<<8) 45862306a36Sopenharmony_ci/* Controller does not support 64-bit DMA */ 45962306a36Sopenharmony_ci#define SDHCI_QUIRK2_BROKEN_64_BIT_DMA (1<<9) 46062306a36Sopenharmony_ci/* need clear transfer mode register before send cmd */ 46162306a36Sopenharmony_ci#define SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD (1<<10) 46262306a36Sopenharmony_ci/* Capability register bit-63 indicates HS400 support */ 46362306a36Sopenharmony_ci#define SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 (1<<11) 46462306a36Sopenharmony_ci/* forced tuned clock */ 46562306a36Sopenharmony_ci#define SDHCI_QUIRK2_TUNING_WORK_AROUND (1<<12) 46662306a36Sopenharmony_ci/* disable the block count for single block transactions */ 46762306a36Sopenharmony_ci#define SDHCI_QUIRK2_SUPPORT_SINGLE (1<<13) 46862306a36Sopenharmony_ci/* Controller broken with using ACMD23 */ 46962306a36Sopenharmony_ci#define SDHCI_QUIRK2_ACMD23_BROKEN (1<<14) 47062306a36Sopenharmony_ci/* Broken Clock divider zero in controller */ 47162306a36Sopenharmony_ci#define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN (1<<15) 47262306a36Sopenharmony_ci/* Controller has CRC in 136 bit Command Response */ 47362306a36Sopenharmony_ci#define SDHCI_QUIRK2_RSP_136_HAS_CRC (1<<16) 47462306a36Sopenharmony_ci/* 47562306a36Sopenharmony_ci * Disable HW timeout if the requested timeout is more than the maximum 47662306a36Sopenharmony_ci * obtainable timeout. 47762306a36Sopenharmony_ci */ 47862306a36Sopenharmony_ci#define SDHCI_QUIRK2_DISABLE_HW_TIMEOUT (1<<17) 47962306a36Sopenharmony_ci/* 48062306a36Sopenharmony_ci * 32-bit block count may not support eMMC where upper bits of CMD23 are used 48162306a36Sopenharmony_ci * for other purposes. Consequently we support 16-bit block count by default. 48262306a36Sopenharmony_ci * Otherwise, SDHCI_QUIRK2_USE_32BIT_BLK_CNT can be selected to use 32-bit 48362306a36Sopenharmony_ci * block count. 48462306a36Sopenharmony_ci */ 48562306a36Sopenharmony_ci#define SDHCI_QUIRK2_USE_32BIT_BLK_CNT (1<<18) 48662306a36Sopenharmony_ci/* Issue CMD and DATA reset together */ 48762306a36Sopenharmony_ci#define SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER (1<<19) 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ci int irq; /* Device IRQ */ 49062306a36Sopenharmony_ci void __iomem *ioaddr; /* Mapped address */ 49162306a36Sopenharmony_ci phys_addr_t mapbase; /* physical address base */ 49262306a36Sopenharmony_ci char *bounce_buffer; /* For packing SDMA reads/writes */ 49362306a36Sopenharmony_ci dma_addr_t bounce_addr; 49462306a36Sopenharmony_ci unsigned int bounce_buffer_size; 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci const struct sdhci_ops *ops; /* Low level hw interface */ 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci /* Internal data */ 49962306a36Sopenharmony_ci struct mmc_host *mmc; /* MMC structure */ 50062306a36Sopenharmony_ci struct mmc_host_ops mmc_host_ops; /* MMC host ops */ 50162306a36Sopenharmony_ci u64 dma_mask; /* custom DMA mask */ 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_LEDS_CLASS) 50462306a36Sopenharmony_ci struct led_classdev led; /* LED control */ 50562306a36Sopenharmony_ci char led_name[32]; 50662306a36Sopenharmony_ci#endif 50762306a36Sopenharmony_ci 50862306a36Sopenharmony_ci spinlock_t lock; /* Mutex */ 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci int flags; /* Host attributes */ 51162306a36Sopenharmony_ci#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */ 51262306a36Sopenharmony_ci#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */ 51362306a36Sopenharmony_ci#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */ 51462306a36Sopenharmony_ci#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */ 51562306a36Sopenharmony_ci#define SDHCI_SDR50_NEEDS_TUNING (1<<4) /* SDR50 needs tuning */ 51662306a36Sopenharmony_ci#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */ 51762306a36Sopenharmony_ci#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */ 51862306a36Sopenharmony_ci#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */ 51962306a36Sopenharmony_ci#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */ 52062306a36Sopenharmony_ci#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */ 52162306a36Sopenharmony_ci#define SDHCI_SIGNALING_330 (1<<14) /* Host is capable of 3.3V signaling */ 52262306a36Sopenharmony_ci#define SDHCI_SIGNALING_180 (1<<15) /* Host is capable of 1.8V signaling */ 52362306a36Sopenharmony_ci#define SDHCI_SIGNALING_120 (1<<16) /* Host is capable of 1.2V signaling */ 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ci unsigned int version; /* SDHCI spec. version */ 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci unsigned int max_clk; /* Max possible freq (MHz) */ 52862306a36Sopenharmony_ci unsigned int timeout_clk; /* Timeout freq (KHz) */ 52962306a36Sopenharmony_ci u8 max_timeout_count; /* Vendor specific max timeout count */ 53062306a36Sopenharmony_ci unsigned int clk_mul; /* Clock Muliplier value */ 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci unsigned int clock; /* Current clock (MHz) */ 53362306a36Sopenharmony_ci u8 pwr; /* Current voltage */ 53462306a36Sopenharmony_ci u8 drv_type; /* Current UHS-I driver type */ 53562306a36Sopenharmony_ci bool reinit_uhs; /* Force UHS-related re-initialization */ 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ci bool runtime_suspended; /* Host is runtime suspended */ 53862306a36Sopenharmony_ci bool bus_on; /* Bus power prevents runtime suspend */ 53962306a36Sopenharmony_ci bool preset_enabled; /* Preset is enabled */ 54062306a36Sopenharmony_ci bool pending_reset; /* Cmd/data reset is pending */ 54162306a36Sopenharmony_ci bool irq_wake_enabled; /* IRQ wakeup is enabled */ 54262306a36Sopenharmony_ci bool v4_mode; /* Host Version 4 Enable */ 54362306a36Sopenharmony_ci bool use_external_dma; /* Host selects to use external DMA */ 54462306a36Sopenharmony_ci bool always_defer_done; /* Always defer to complete requests */ 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci struct mmc_request *mrqs_done[SDHCI_MAX_MRQS]; /* Requests done */ 54762306a36Sopenharmony_ci struct mmc_command *cmd; /* Current command */ 54862306a36Sopenharmony_ci struct mmc_command *data_cmd; /* Current data command */ 54962306a36Sopenharmony_ci struct mmc_command *deferred_cmd; /* Deferred command */ 55062306a36Sopenharmony_ci struct mmc_data *data; /* Current data request */ 55162306a36Sopenharmony_ci unsigned int data_early:1; /* Data finished before cmd */ 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ci struct sg_mapping_iter sg_miter; /* SG state for PIO */ 55462306a36Sopenharmony_ci unsigned int blocks; /* remaining PIO blocks */ 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ci int sg_count; /* Mapped sg entries */ 55762306a36Sopenharmony_ci int max_adma; /* Max. length in ADMA descriptor */ 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci void *adma_table; /* ADMA descriptor table */ 56062306a36Sopenharmony_ci void *align_buffer; /* Bounce buffer */ 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_ci size_t adma_table_sz; /* ADMA descriptor table size */ 56362306a36Sopenharmony_ci size_t align_buffer_sz; /* Bounce buffer size */ 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci dma_addr_t adma_addr; /* Mapped ADMA descr. table */ 56662306a36Sopenharmony_ci dma_addr_t align_addr; /* Mapped bounce buffer */ 56762306a36Sopenharmony_ci 56862306a36Sopenharmony_ci unsigned int desc_sz; /* ADMA current descriptor size */ 56962306a36Sopenharmony_ci unsigned int alloc_desc_sz; /* ADMA descr. max size host supports */ 57062306a36Sopenharmony_ci 57162306a36Sopenharmony_ci struct workqueue_struct *complete_wq; /* Request completion wq */ 57262306a36Sopenharmony_ci struct work_struct complete_work; /* Request completion work */ 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ci struct timer_list timer; /* Timer for timeouts */ 57562306a36Sopenharmony_ci struct timer_list data_timer; /* Timer for data timeouts */ 57662306a36Sopenharmony_ci 57762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA) 57862306a36Sopenharmony_ci struct dma_chan *rx_chan; 57962306a36Sopenharmony_ci struct dma_chan *tx_chan; 58062306a36Sopenharmony_ci#endif 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci u32 caps; /* CAPABILITY_0 */ 58362306a36Sopenharmony_ci u32 caps1; /* CAPABILITY_1 */ 58462306a36Sopenharmony_ci bool read_caps; /* Capability flags have been read */ 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci bool sdhci_core_to_disable_vqmmc; /* sdhci core can disable vqmmc */ 58762306a36Sopenharmony_ci unsigned int ocr_avail_sdio; /* OCR bit masks */ 58862306a36Sopenharmony_ci unsigned int ocr_avail_sd; 58962306a36Sopenharmony_ci unsigned int ocr_avail_mmc; 59062306a36Sopenharmony_ci u32 ocr_mask; /* available voltages */ 59162306a36Sopenharmony_ci 59262306a36Sopenharmony_ci unsigned timing; /* Current timing */ 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci u32 thread_isr; 59562306a36Sopenharmony_ci 59662306a36Sopenharmony_ci /* cached registers */ 59762306a36Sopenharmony_ci u32 ier; 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ci bool cqe_on; /* CQE is operating */ 60062306a36Sopenharmony_ci u32 cqe_ier; /* CQE interrupt mask */ 60162306a36Sopenharmony_ci u32 cqe_err_ier; /* CQE error interrupt mask */ 60262306a36Sopenharmony_ci 60362306a36Sopenharmony_ci wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */ 60462306a36Sopenharmony_ci unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */ 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci unsigned int tuning_count; /* Timer count for re-tuning */ 60762306a36Sopenharmony_ci unsigned int tuning_mode; /* Re-tuning mode supported by host */ 60862306a36Sopenharmony_ci unsigned int tuning_err; /* Error code for re-tuning */ 60962306a36Sopenharmony_ci#define SDHCI_TUNING_MODE_1 0 61062306a36Sopenharmony_ci#define SDHCI_TUNING_MODE_2 1 61162306a36Sopenharmony_ci#define SDHCI_TUNING_MODE_3 2 61262306a36Sopenharmony_ci /* Delay (ms) between tuning commands */ 61362306a36Sopenharmony_ci int tuning_delay; 61462306a36Sopenharmony_ci int tuning_loop_count; 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_ci /* Host SDMA buffer boundary. */ 61762306a36Sopenharmony_ci u32 sdma_boundary; 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci /* Host ADMA table count */ 62062306a36Sopenharmony_ci u32 adma_table_cnt; 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_ci u64 data_timeout; 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ci unsigned long private[] ____cacheline_aligned; 62562306a36Sopenharmony_ci}; 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_cistruct sdhci_ops { 62862306a36Sopenharmony_ci#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS 62962306a36Sopenharmony_ci u32 (*read_l)(struct sdhci_host *host, int reg); 63062306a36Sopenharmony_ci u16 (*read_w)(struct sdhci_host *host, int reg); 63162306a36Sopenharmony_ci u8 (*read_b)(struct sdhci_host *host, int reg); 63262306a36Sopenharmony_ci void (*write_l)(struct sdhci_host *host, u32 val, int reg); 63362306a36Sopenharmony_ci void (*write_w)(struct sdhci_host *host, u16 val, int reg); 63462306a36Sopenharmony_ci void (*write_b)(struct sdhci_host *host, u8 val, int reg); 63562306a36Sopenharmony_ci#endif 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_ci void (*set_clock)(struct sdhci_host *host, unsigned int clock); 63862306a36Sopenharmony_ci void (*set_power)(struct sdhci_host *host, unsigned char mode, 63962306a36Sopenharmony_ci unsigned short vdd); 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ci u32 (*irq)(struct sdhci_host *host, u32 intmask); 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_ci int (*set_dma_mask)(struct sdhci_host *host); 64462306a36Sopenharmony_ci int (*enable_dma)(struct sdhci_host *host); 64562306a36Sopenharmony_ci unsigned int (*get_max_clock)(struct sdhci_host *host); 64662306a36Sopenharmony_ci unsigned int (*get_min_clock)(struct sdhci_host *host); 64762306a36Sopenharmony_ci /* get_timeout_clock should return clk rate in unit of Hz */ 64862306a36Sopenharmony_ci unsigned int (*get_timeout_clock)(struct sdhci_host *host); 64962306a36Sopenharmony_ci unsigned int (*get_max_timeout_count)(struct sdhci_host *host); 65062306a36Sopenharmony_ci void (*set_timeout)(struct sdhci_host *host, 65162306a36Sopenharmony_ci struct mmc_command *cmd); 65262306a36Sopenharmony_ci void (*set_bus_width)(struct sdhci_host *host, int width); 65362306a36Sopenharmony_ci void (*platform_send_init_74_clocks)(struct sdhci_host *host, 65462306a36Sopenharmony_ci u8 power_mode); 65562306a36Sopenharmony_ci unsigned int (*get_ro)(struct sdhci_host *host); 65662306a36Sopenharmony_ci void (*reset)(struct sdhci_host *host, u8 mask); 65762306a36Sopenharmony_ci int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode); 65862306a36Sopenharmony_ci void (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs); 65962306a36Sopenharmony_ci void (*hw_reset)(struct sdhci_host *host); 66062306a36Sopenharmony_ci void (*adma_workaround)(struct sdhci_host *host, u32 intmask); 66162306a36Sopenharmony_ci void (*card_event)(struct sdhci_host *host); 66262306a36Sopenharmony_ci void (*voltage_switch)(struct sdhci_host *host); 66362306a36Sopenharmony_ci void (*adma_write_desc)(struct sdhci_host *host, void **desc, 66462306a36Sopenharmony_ci dma_addr_t addr, int len, unsigned int cmd); 66562306a36Sopenharmony_ci void (*copy_to_bounce_buffer)(struct sdhci_host *host, 66662306a36Sopenharmony_ci struct mmc_data *data, 66762306a36Sopenharmony_ci unsigned int length); 66862306a36Sopenharmony_ci void (*request_done)(struct sdhci_host *host, 66962306a36Sopenharmony_ci struct mmc_request *mrq); 67062306a36Sopenharmony_ci void (*dump_vendor_regs)(struct sdhci_host *host); 67162306a36Sopenharmony_ci}; 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_ci#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_cistatic inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg) 67662306a36Sopenharmony_ci{ 67762306a36Sopenharmony_ci if (unlikely(host->ops->write_l)) 67862306a36Sopenharmony_ci host->ops->write_l(host, val, reg); 67962306a36Sopenharmony_ci else 68062306a36Sopenharmony_ci writel(val, host->ioaddr + reg); 68162306a36Sopenharmony_ci} 68262306a36Sopenharmony_ci 68362306a36Sopenharmony_cistatic inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg) 68462306a36Sopenharmony_ci{ 68562306a36Sopenharmony_ci if (unlikely(host->ops->write_w)) 68662306a36Sopenharmony_ci host->ops->write_w(host, val, reg); 68762306a36Sopenharmony_ci else 68862306a36Sopenharmony_ci writew(val, host->ioaddr + reg); 68962306a36Sopenharmony_ci} 69062306a36Sopenharmony_ci 69162306a36Sopenharmony_cistatic inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg) 69262306a36Sopenharmony_ci{ 69362306a36Sopenharmony_ci if (unlikely(host->ops->write_b)) 69462306a36Sopenharmony_ci host->ops->write_b(host, val, reg); 69562306a36Sopenharmony_ci else 69662306a36Sopenharmony_ci writeb(val, host->ioaddr + reg); 69762306a36Sopenharmony_ci} 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_cistatic inline u32 sdhci_readl(struct sdhci_host *host, int reg) 70062306a36Sopenharmony_ci{ 70162306a36Sopenharmony_ci if (unlikely(host->ops->read_l)) 70262306a36Sopenharmony_ci return host->ops->read_l(host, reg); 70362306a36Sopenharmony_ci else 70462306a36Sopenharmony_ci return readl(host->ioaddr + reg); 70562306a36Sopenharmony_ci} 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_cistatic inline u16 sdhci_readw(struct sdhci_host *host, int reg) 70862306a36Sopenharmony_ci{ 70962306a36Sopenharmony_ci if (unlikely(host->ops->read_w)) 71062306a36Sopenharmony_ci return host->ops->read_w(host, reg); 71162306a36Sopenharmony_ci else 71262306a36Sopenharmony_ci return readw(host->ioaddr + reg); 71362306a36Sopenharmony_ci} 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_cistatic inline u8 sdhci_readb(struct sdhci_host *host, int reg) 71662306a36Sopenharmony_ci{ 71762306a36Sopenharmony_ci if (unlikely(host->ops->read_b)) 71862306a36Sopenharmony_ci return host->ops->read_b(host, reg); 71962306a36Sopenharmony_ci else 72062306a36Sopenharmony_ci return readb(host->ioaddr + reg); 72162306a36Sopenharmony_ci} 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ci#else 72462306a36Sopenharmony_ci 72562306a36Sopenharmony_cistatic inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg) 72662306a36Sopenharmony_ci{ 72762306a36Sopenharmony_ci writel(val, host->ioaddr + reg); 72862306a36Sopenharmony_ci} 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_cistatic inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg) 73162306a36Sopenharmony_ci{ 73262306a36Sopenharmony_ci writew(val, host->ioaddr + reg); 73362306a36Sopenharmony_ci} 73462306a36Sopenharmony_ci 73562306a36Sopenharmony_cistatic inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg) 73662306a36Sopenharmony_ci{ 73762306a36Sopenharmony_ci writeb(val, host->ioaddr + reg); 73862306a36Sopenharmony_ci} 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_cistatic inline u32 sdhci_readl(struct sdhci_host *host, int reg) 74162306a36Sopenharmony_ci{ 74262306a36Sopenharmony_ci return readl(host->ioaddr + reg); 74362306a36Sopenharmony_ci} 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_cistatic inline u16 sdhci_readw(struct sdhci_host *host, int reg) 74662306a36Sopenharmony_ci{ 74762306a36Sopenharmony_ci return readw(host->ioaddr + reg); 74862306a36Sopenharmony_ci} 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_cistatic inline u8 sdhci_readb(struct sdhci_host *host, int reg) 75162306a36Sopenharmony_ci{ 75262306a36Sopenharmony_ci return readb(host->ioaddr + reg); 75362306a36Sopenharmony_ci} 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_ci#endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */ 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_cistruct sdhci_host *sdhci_alloc_host(struct device *dev, size_t priv_size); 75862306a36Sopenharmony_civoid sdhci_free_host(struct sdhci_host *host); 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_cistatic inline void *sdhci_priv(struct sdhci_host *host) 76162306a36Sopenharmony_ci{ 76262306a36Sopenharmony_ci return host->private; 76362306a36Sopenharmony_ci} 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_civoid __sdhci_read_caps(struct sdhci_host *host, const u16 *ver, 76662306a36Sopenharmony_ci const u32 *caps, const u32 *caps1); 76762306a36Sopenharmony_ciint sdhci_setup_host(struct sdhci_host *host); 76862306a36Sopenharmony_civoid sdhci_cleanup_host(struct sdhci_host *host); 76962306a36Sopenharmony_ciint __sdhci_add_host(struct sdhci_host *host); 77062306a36Sopenharmony_ciint sdhci_add_host(struct sdhci_host *host); 77162306a36Sopenharmony_civoid sdhci_remove_host(struct sdhci_host *host, int dead); 77262306a36Sopenharmony_ci 77362306a36Sopenharmony_cistatic inline void sdhci_read_caps(struct sdhci_host *host) 77462306a36Sopenharmony_ci{ 77562306a36Sopenharmony_ci __sdhci_read_caps(host, NULL, NULL, NULL); 77662306a36Sopenharmony_ci} 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ciu16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, 77962306a36Sopenharmony_ci unsigned int *actual_clock); 78062306a36Sopenharmony_civoid sdhci_set_clock(struct sdhci_host *host, unsigned int clock); 78162306a36Sopenharmony_civoid sdhci_enable_clk(struct sdhci_host *host, u16 clk); 78262306a36Sopenharmony_civoid sdhci_set_power(struct sdhci_host *host, unsigned char mode, 78362306a36Sopenharmony_ci unsigned short vdd); 78462306a36Sopenharmony_civoid sdhci_set_power_and_bus_voltage(struct sdhci_host *host, 78562306a36Sopenharmony_ci unsigned char mode, 78662306a36Sopenharmony_ci unsigned short vdd); 78762306a36Sopenharmony_civoid sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, 78862306a36Sopenharmony_ci unsigned short vdd); 78962306a36Sopenharmony_ciint sdhci_get_cd_nogpio(struct mmc_host *mmc); 79062306a36Sopenharmony_civoid sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq); 79162306a36Sopenharmony_ciint sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq); 79262306a36Sopenharmony_civoid sdhci_set_bus_width(struct sdhci_host *host, int width); 79362306a36Sopenharmony_civoid sdhci_reset(struct sdhci_host *host, u8 mask); 79462306a36Sopenharmony_civoid sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); 79562306a36Sopenharmony_ciint sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode); 79662306a36Sopenharmony_civoid sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios); 79762306a36Sopenharmony_ciint sdhci_start_signal_voltage_switch(struct mmc_host *mmc, 79862306a36Sopenharmony_ci struct mmc_ios *ios); 79962306a36Sopenharmony_civoid sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable); 80062306a36Sopenharmony_civoid sdhci_adma_write_desc(struct sdhci_host *host, void **desc, 80162306a36Sopenharmony_ci dma_addr_t addr, int len, unsigned int cmd); 80262306a36Sopenharmony_ci 80362306a36Sopenharmony_ci#ifdef CONFIG_PM 80462306a36Sopenharmony_ciint sdhci_suspend_host(struct sdhci_host *host); 80562306a36Sopenharmony_ciint sdhci_resume_host(struct sdhci_host *host); 80662306a36Sopenharmony_ciint sdhci_runtime_suspend_host(struct sdhci_host *host); 80762306a36Sopenharmony_ciint sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset); 80862306a36Sopenharmony_ci#endif 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_civoid sdhci_cqe_enable(struct mmc_host *mmc); 81162306a36Sopenharmony_civoid sdhci_cqe_disable(struct mmc_host *mmc, bool recovery); 81262306a36Sopenharmony_cibool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error, 81362306a36Sopenharmony_ci int *data_error); 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_civoid sdhci_dumpregs(struct sdhci_host *host); 81662306a36Sopenharmony_civoid sdhci_enable_v4_mode(struct sdhci_host *host); 81762306a36Sopenharmony_ci 81862306a36Sopenharmony_civoid sdhci_start_tuning(struct sdhci_host *host); 81962306a36Sopenharmony_civoid sdhci_end_tuning(struct sdhci_host *host); 82062306a36Sopenharmony_civoid sdhci_reset_tuning(struct sdhci_host *host); 82162306a36Sopenharmony_civoid sdhci_send_tuning(struct sdhci_host *host, u32 opcode); 82262306a36Sopenharmony_civoid sdhci_abort_tuning(struct sdhci_host *host, u32 opcode); 82362306a36Sopenharmony_civoid sdhci_switch_external_dma(struct sdhci_host *host, bool en); 82462306a36Sopenharmony_civoid sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable); 82562306a36Sopenharmony_civoid __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ci#endif /* __SDHCI_HW_H */ 828