| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* Renesas Mobile SDHI |
| 4 |
* |
| 5 |
* Copyright (C) 2017 Horms Solutions Ltd., Simon Horman |
| 6 |
* Copyright (C) 2017-19 Renesas Electronics Corporation |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef RENESAS_SDHI_H |
| 10 |
#define RENESAS_SDHI_H |
| 11 |
|
| 12 |
#include <linux/device.h> |
| 13 |
#include <linux/dmaengine.h> |
| 14 |
#include <linux/platform_device.h> |
| 15 |
#include <linux/workqueue.h> |
| 16 |
#include "tmio_mmc.h" |
| 17 |
|
| 18 |
struct renesas_sdhi_scc { |
| 19 |
unsigned long clk_rate; /* clock rate for SDR104 */ |
| 20 |
u32 tap; /* sampling clock position for SDR104/HS400 (8 TAP) */ |
| 21 |
u32 tap_hs400_4tap; /* sampling clock position for HS400 (4 TAP) */ |
| 22 |
}; |
| 23 |
|
| 24 |
#define SDHI_FLAG_NEED_CLKH_FALLBACK BIT(0) |
| 25 |
|
| 26 |
struct renesas_sdhi_of_data { |
| 27 |
unsigned long tmio_flags; |
| 28 |
u32 tmio_ocr_mask; |
| 29 |
unsigned long capabilities; |
| 30 |
unsigned long capabilities2; |
| 31 |
enum dma_slave_buswidth dma_buswidth; |
| 32 |
dma_addr_t dma_rx_offset; |
| 33 |
unsigned int bus_shift; |
| 34 |
int scc_offset; |
| 35 |
struct renesas_sdhi_scc *taps; |
| 36 |
int taps_num; |
| 37 |
unsigned int max_blk_count; |
| 38 |
unsigned short max_segs; |
| 39 |
unsigned long sdhi_flags; |
| 40 |
}; |
| 41 |
|
| 42 |
#define SDHI_CALIB_TABLE_MAX 32 |
| 43 |
|
| 44 |
#define sdhi_has_quirk(p, q) ((p)->quirks && (p)->quirks->q) |
| 45 |
|
| 46 |
struct renesas_sdhi_quirks { |
| 47 |
bool hs400_disabled; |
| 48 |
bool hs400_4taps; |
| 49 |
bool fixed_addr_mode; |
| 50 |
bool dma_one_rx_only; |
| 51 |
bool manual_tap_correction; |
| 52 |
bool old_info1_layout; |
| 53 |
u32 hs400_bad_taps; |
| 54 |
const u8 (*hs400_calib_table)[SDHI_CALIB_TABLE_MAX]; |
| 55 |
}; |
| 56 |
|
| 57 |
struct renesas_sdhi_of_data_with_quirks { |
| 58 |
const struct renesas_sdhi_of_data *of_data; |
| 59 |
const struct renesas_sdhi_quirks *quirks; |
| 60 |
}; |
| 61 |
|
| 62 |
/* We want both end_flags to be set before we mark DMA as finished */ |
| 63 |
#define SDHI_DMA_END_FLAG_DMA 0 |
| 64 |
#define SDHI_DMA_END_FLAG_ACCESS 1 |
| 65 |
|
| 66 |
struct renesas_sdhi_dma { |
| 67 |
unsigned long end_flags; |
| 68 |
enum dma_slave_buswidth dma_buswidth; |
| 69 |
dma_filter_fn filter; |
| 70 |
void (*enable)(struct tmio_mmc_host *host, bool enable); |
| 71 |
struct completion dma_dataend; |
| 72 |
struct work_struct dma_complete; |
| 73 |
}; |
| 74 |
|
| 75 |
struct renesas_sdhi { |
| 76 |
struct clk *clk; |
| 77 |
struct clk *clkh; |
| 78 |
struct clk *clk_cd; |
| 79 |
struct tmio_mmc_data mmc_data; |
| 80 |
struct renesas_sdhi_dma dma_priv; |
| 81 |
const struct renesas_sdhi_quirks *quirks; |
| 82 |
struct pinctrl *pinctrl; |
| 83 |
struct pinctrl_state *pins_default, *pins_uhs; |
| 84 |
void __iomem *scc_ctl; |
| 85 |
u32 scc_tappos; |
| 86 |
u32 scc_tappos_hs400; |
| 87 |
const u8 *adjust_hs400_calib_table; |
| 88 |
bool needs_adjust_hs400; |
| 89 |
bool card_is_sdio; |
| 90 |
|
| 91 |
/* Tuning values: 1 for success, 0 for failure */ |
| 92 |
DECLARE_BITMAP(taps, BITS_PER_LONG); |
| 93 |
/* Sampling data comparison: 1 for match, 0 for mismatch */ |
| 94 |
DECLARE_BITMAP(smpcmp, BITS_PER_LONG); |
| 95 |
unsigned int tap_num; |
| 96 |
unsigned int tap_set; |
| 97 |
|
| 98 |
struct reset_control *rstc; |
| 99 |
struct tmio_mmc_host *host; |
| 100 |
struct regulator_dev *rdev; |
| 101 |
}; |
| 102 |
|
| 103 |
#define host_to_priv(host) \ |
| 104 |
container_of((host)->pdata, struct renesas_sdhi, mmc_data) |
| 105 |
|
| 106 |
int renesas_sdhi_probe(struct platform_device *pdev, |
| 107 |
const struct tmio_mmc_dma_ops *dma_ops, |
| 108 |
const struct renesas_sdhi_of_data *of_data, |
| 109 |
const struct renesas_sdhi_quirks *quirks); |
| 110 |
void renesas_sdhi_remove(struct platform_device *pdev); |
| 111 |
int renesas_sdhi_suspend(struct device *dev); |
| 112 |
int renesas_sdhi_resume(struct device *dev); |
| 113 |
#endif |