| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for the MMC / SD / SDIO cell found in: |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3 |
|---|
| 5 | 6 | * |
|---|
| 6 | | - * Copyright (C) 2015-17 Renesas Electronics Corporation |
|---|
| 7 | | - * Copyright (C) 2016-17 Sang Engineering, Wolfram Sang |
|---|
| 7 | + * Copyright (C) 2015-19 Renesas Electronics Corporation |
|---|
| 8 | + * Copyright (C) 2016-19 Sang Engineering, Wolfram Sang |
|---|
| 8 | 9 | * Copyright (C) 2016-17 Horms Solutions, Simon Horman |
|---|
| 9 | 10 | * Copyright (C) 2007 Ian Molton |
|---|
| 10 | 11 | * Copyright (C) 2004 Ian Molton |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 13 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 14 | | - * published by the Free Software Foundation. |
|---|
| 15 | | - * |
|---|
| 16 | 12 | */ |
|---|
| 17 | 13 | |
|---|
| 18 | 14 | #ifndef TMIO_MMC_H |
|---|
| .. | .. |
|---|
| 47 | 43 | #define CTL_RESET_SD 0xe0 |
|---|
| 48 | 44 | #define CTL_VERSION 0xe2 |
|---|
| 49 | 45 | #define CTL_SDIF_MODE 0xe6 |
|---|
| 50 | | -#define CTL_SDIO_REGS 0x100 |
|---|
| 51 | | -#define CTL_CLK_AND_WAIT_CTL 0x138 |
|---|
| 52 | | -#define CTL_RESET_SDIO 0x1e0 |
|---|
| 53 | 46 | |
|---|
| 54 | 47 | /* Definitions for values the CTL_STOP_INTERNAL_ACTION register can take */ |
|---|
| 55 | 48 | #define TMIO_STOP_STP BIT(0) |
|---|
| .. | .. |
|---|
| 77 | 70 | #define TMIO_STAT_DAT0 BIT(23) /* only known on R-Car so far */ |
|---|
| 78 | 71 | #define TMIO_STAT_RXRDY BIT(24) |
|---|
| 79 | 72 | #define TMIO_STAT_TXRQ BIT(25) |
|---|
| 73 | +#define TMIO_STAT_ALWAYS_SET_27 BIT(27) /* only known on R-Car 2+ so far */ |
|---|
| 80 | 74 | #define TMIO_STAT_ILL_FUNC BIT(29) /* only when !TMIO_MMC_HAS_IDLE_WAIT */ |
|---|
| 81 | 75 | #define TMIO_STAT_SCLKDIVEN BIT(29) /* only when TMIO_MMC_HAS_IDLE_WAIT */ |
|---|
| 82 | 76 | #define TMIO_STAT_CMD_BUSY BIT(30) |
|---|
| .. | .. |
|---|
| 103 | 97 | |
|---|
| 104 | 98 | /* Define some IRQ masks */ |
|---|
| 105 | 99 | /* This is the mask used at reset by the chip */ |
|---|
| 100 | +#define TMIO_MASK_INIT_RCAR2 0x8b7f031d /* Initial value for R-Car Gen2+ */ |
|---|
| 106 | 101 | #define TMIO_MASK_ALL 0x837f031d |
|---|
| 107 | 102 | #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND) |
|---|
| 108 | 103 | #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND) |
|---|
| 109 | 104 | #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \ |
|---|
| 110 | 105 | TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT) |
|---|
| 111 | 106 | #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD) |
|---|
| 107 | + |
|---|
| 108 | +#define TMIO_MAX_BLK_SIZE 512 |
|---|
| 112 | 109 | |
|---|
| 113 | 110 | struct tmio_mmc_data; |
|---|
| 114 | 111 | struct tmio_mmc_host; |
|---|
| .. | .. |
|---|
| 121 | 118 | void (*release)(struct tmio_mmc_host *host); |
|---|
| 122 | 119 | void (*abort)(struct tmio_mmc_host *host); |
|---|
| 123 | 120 | void (*dataend)(struct tmio_mmc_host *host); |
|---|
| 121 | + |
|---|
| 122 | + /* optional */ |
|---|
| 123 | + void (*end)(struct tmio_mmc_host *host); /* held host->lock */ |
|---|
| 124 | 124 | }; |
|---|
| 125 | 125 | |
|---|
| 126 | 126 | struct tmio_mmc_host { |
|---|
| .. | .. |
|---|
| 133 | 133 | |
|---|
| 134 | 134 | /* Callbacks for clock / power control */ |
|---|
| 135 | 135 | void (*set_pwr)(struct platform_device *host, int state); |
|---|
| 136 | | - void (*set_clk_div)(struct platform_device *host, int state); |
|---|
| 137 | 136 | |
|---|
| 138 | 137 | /* pio related stuff */ |
|---|
| 139 | 138 | struct scatterlist *sg_ptr; |
|---|
| .. | .. |
|---|
| 146 | 145 | struct tmio_mmc_data *pdata; |
|---|
| 147 | 146 | |
|---|
| 148 | 147 | /* DMA support */ |
|---|
| 149 | | - bool force_pio; |
|---|
| 148 | + bool dma_on; |
|---|
| 150 | 149 | struct dma_chan *chan_rx; |
|---|
| 151 | 150 | struct dma_chan *chan_tx; |
|---|
| 152 | 151 | struct tasklet_struct dma_issue; |
|---|
| .. | .. |
|---|
| 161 | 160 | u32 sdcard_irq_mask; |
|---|
| 162 | 161 | u32 sdio_irq_mask; |
|---|
| 163 | 162 | unsigned int clk_cache; |
|---|
| 163 | + u32 sdcard_irq_setbit_mask; |
|---|
| 164 | 164 | |
|---|
| 165 | 165 | spinlock_t lock; /* protect host private data */ |
|---|
| 166 | 166 | unsigned long last_req_ts; |
|---|
| .. | .. |
|---|
| 170 | 170 | |
|---|
| 171 | 171 | /* Mandatory callback */ |
|---|
| 172 | 172 | int (*clk_enable)(struct tmio_mmc_host *host); |
|---|
| 173 | + void (*set_clock)(struct tmio_mmc_host *host, unsigned int clock); |
|---|
| 173 | 174 | |
|---|
| 174 | 175 | /* Optional callbacks */ |
|---|
| 175 | | - unsigned int (*clk_update)(struct tmio_mmc_host *host, |
|---|
| 176 | | - unsigned int new_clock); |
|---|
| 177 | 176 | void (*clk_disable)(struct tmio_mmc_host *host); |
|---|
| 178 | 177 | int (*multi_io_quirk)(struct mmc_card *card, |
|---|
| 179 | 178 | unsigned int direction, int blk_size); |
|---|
| 180 | 179 | int (*write16_hook)(struct tmio_mmc_host *host, int addr); |
|---|
| 181 | | - void (*hw_reset)(struct tmio_mmc_host *host); |
|---|
| 182 | | - void (*prepare_tuning)(struct tmio_mmc_host *host, unsigned long tap); |
|---|
| 183 | | - bool (*check_scc_error)(struct tmio_mmc_host *host); |
|---|
| 184 | | - |
|---|
| 185 | | - /* |
|---|
| 186 | | - * Mandatory callback for tuning to occur which is optional for SDR50 |
|---|
| 187 | | - * and mandatory for SDR104. |
|---|
| 188 | | - */ |
|---|
| 189 | | - unsigned int (*init_tuning)(struct tmio_mmc_host *host); |
|---|
| 190 | | - int (*select_tuning)(struct tmio_mmc_host *host); |
|---|
| 191 | | - |
|---|
| 192 | | - /* Tuning values: 1 for success, 0 for failure */ |
|---|
| 193 | | - DECLARE_BITMAP(taps, BITS_PER_BYTE * sizeof(long)); |
|---|
| 194 | | - unsigned int tap_num; |
|---|
| 195 | | - unsigned long tap_set; |
|---|
| 180 | + void (*reset)(struct tmio_mmc_host *host); |
|---|
| 181 | + bool (*check_retune)(struct tmio_mmc_host *host); |
|---|
| 182 | + void (*fixup_request)(struct tmio_mmc_host *host, struct mmc_request *mrq); |
|---|
| 196 | 183 | |
|---|
| 197 | 184 | void (*prepare_hs400_tuning)(struct tmio_mmc_host *host); |
|---|
| 198 | 185 | void (*hs400_downgrade)(struct tmio_mmc_host *host); |
|---|
| .. | .. |
|---|
| 275 | 262 | static inline void sd_ctrl_write32_as_16_and_16(struct tmio_mmc_host *host, |
|---|
| 276 | 263 | int addr, u32 val) |
|---|
| 277 | 264 | { |
|---|
| 265 | + if (addr == CTL_IRQ_MASK || addr == CTL_STATUS) |
|---|
| 266 | + val |= host->sdcard_irq_setbit_mask; |
|---|
| 267 | + |
|---|
| 278 | 268 | iowrite16(val & 0xffff, host->ctl + (addr << host->bus_shift)); |
|---|
| 279 | 269 | iowrite16(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); |
|---|
| 280 | 270 | } |
|---|