Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux-2.6-block.git] / drivers / mmc / host / renesas_sdhi.h
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/dmaengine.h>
13 #include <linux/platform_device.h>
14 #include "tmio_mmc.h"
15
16 struct renesas_sdhi_scc {
17         unsigned long clk_rate; /* clock rate for SDR104 */
18         u32 tap;                /* sampling clock position for SDR104/HS400 (8 TAP) */
19         u32 tap_hs400_4tap;     /* sampling clock position for HS400 (4 TAP) */
20 };
21
22 #define SDHI_FLAG_NEED_CLKH_FALLBACK    BIT(0)
23
24 struct renesas_sdhi_of_data {
25         unsigned long tmio_flags;
26         u32           tmio_ocr_mask;
27         unsigned long capabilities;
28         unsigned long capabilities2;
29         enum dma_slave_buswidth dma_buswidth;
30         dma_addr_t dma_rx_offset;
31         unsigned int bus_shift;
32         int scc_offset;
33         struct renesas_sdhi_scc *taps;
34         int taps_num;
35         unsigned int max_blk_count;
36         unsigned short max_segs;
37         unsigned long sdhi_flags;
38 };
39
40 #define SDHI_CALIB_TABLE_MAX 32
41
42 #define sdhi_has_quirk(p, q) ((p)->quirks && (p)->quirks->q)
43
44 struct renesas_sdhi_quirks {
45         bool hs400_disabled;
46         bool hs400_4taps;
47         bool fixed_addr_mode;
48         bool dma_one_rx_only;
49         bool manual_tap_correction;
50         bool old_info1_layout;
51         u32 hs400_bad_taps;
52         const u8 (*hs400_calib_table)[SDHI_CALIB_TABLE_MAX];
53 };
54
55 struct renesas_sdhi_of_data_with_quirks {
56         const struct renesas_sdhi_of_data *of_data;
57         const struct renesas_sdhi_quirks *quirks;
58 };
59
60 /* We want both end_flags to be set before we mark DMA as finished */
61 #define SDHI_DMA_END_FLAG_DMA           0
62 #define SDHI_DMA_END_FLAG_ACCESS        1
63
64 struct renesas_sdhi_dma {
65         unsigned long end_flags;
66         enum dma_slave_buswidth dma_buswidth;
67         dma_filter_fn filter;
68         void (*enable)(struct tmio_mmc_host *host, bool enable);
69         struct completion dma_dataend;
70         struct tasklet_struct dma_complete;
71 };
72
73 struct renesas_sdhi {
74         struct clk *clk;
75         struct clk *clkh;
76         struct clk *clk_cd;
77         struct tmio_mmc_data mmc_data;
78         struct renesas_sdhi_dma dma_priv;
79         const struct renesas_sdhi_quirks *quirks;
80         struct pinctrl *pinctrl;
81         struct pinctrl_state *pins_default, *pins_uhs;
82         void __iomem *scc_ctl;
83         u32 scc_tappos;
84         u32 scc_tappos_hs400;
85         const u8 *adjust_hs400_calib_table;
86         bool needs_adjust_hs400;
87
88         /* Tuning values: 1 for success, 0 for failure */
89         DECLARE_BITMAP(taps, BITS_PER_LONG);
90         /* Sampling data comparison: 1 for match, 0 for mismatch */
91         DECLARE_BITMAP(smpcmp, BITS_PER_LONG);
92         unsigned int tap_num;
93         unsigned int tap_set;
94
95         struct reset_control *rstc;
96 };
97
98 #define host_to_priv(host) \
99         container_of((host)->pdata, struct renesas_sdhi, mmc_data)
100
101 int renesas_sdhi_probe(struct platform_device *pdev,
102                        const struct tmio_mmc_dma_ops *dma_ops,
103                        const struct renesas_sdhi_of_data *of_data,
104                        const struct renesas_sdhi_quirks *quirks);
105 void renesas_sdhi_remove(struct platform_device *pdev);
106 #endif