Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 2 | #ifndef MFD_TMIO_H |
| 3 | #define MFD_TMIO_H |
| 4 | |
Guennadi Liakhovetski | c8be24c | 2012-02-09 22:57:09 +0100 | [diff] [blame] | 5 | #include <linux/device.h> |
Dmitry Baryshkov | b53cde3 | 2008-10-15 22:03:55 -0700 | [diff] [blame] | 6 | #include <linux/fb.h> |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 7 | #include <linux/io.h> |
Guennadi Liakhovetski | c8be24c | 2012-02-09 22:57:09 +0100 | [diff] [blame] | 8 | #include <linux/jiffies.h> |
Kuninori Morimoto | bbf0208 | 2014-09-08 23:45:25 -0700 | [diff] [blame] | 9 | #include <linux/mmc/card.h> |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 10 | #include <linux/platform_device.h> |
Guennadi Liakhovetski | 7311bef | 2011-05-11 16:51:11 +0000 | [diff] [blame] | 11 | #include <linux/pm_runtime.h> |
Dmitry Baryshkov | b53cde3 | 2008-10-15 22:03:55 -0700 | [diff] [blame] | 12 | |
Ian Molton | d3a2f71 | 2008-07-31 20:44:28 +0200 | [diff] [blame] | 13 | #define tmio_ioread8(addr) readb(addr) |
| 14 | #define tmio_ioread16(addr) readw(addr) |
| 15 | #define tmio_ioread16_rep(r, b, l) readsw(r, b, l) |
| 16 | #define tmio_ioread32(addr) \ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 17 | (((u32)readw((addr))) | (((u32)readw((addr) + 2)) << 16)) |
Ian Molton | d3a2f71 | 2008-07-31 20:44:28 +0200 | [diff] [blame] | 18 | |
| 19 | #define tmio_iowrite8(val, addr) writeb((val), (addr)) |
| 20 | #define tmio_iowrite16(val, addr) writew((val), (addr)) |
| 21 | #define tmio_iowrite16_rep(r, b, l) writesw(r, b, l) |
| 22 | #define tmio_iowrite32(val, addr) \ |
| 23 | do { \ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 24 | writew((val), (addr)); \ |
| 25 | writew((val) >> 16, (addr) + 2); \ |
Ian Molton | d3a2f71 | 2008-07-31 20:44:28 +0200 | [diff] [blame] | 26 | } while (0) |
| 27 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 28 | #define sd_config_write8(base, shift, reg, val) \ |
| 29 | tmio_iowrite8((val), (base) + ((reg) << (shift))) |
| 30 | #define sd_config_write16(base, shift, reg, val) \ |
| 31 | tmio_iowrite16((val), (base) + ((reg) << (shift))) |
| 32 | #define sd_config_write32(base, shift, reg, val) \ |
| 33 | do { \ |
| 34 | tmio_iowrite16((val), (base) + ((reg) << (shift))); \ |
| 35 | tmio_iowrite16((val) >> 16, (base) + ((reg + 2) << (shift))); \ |
| 36 | } while (0) |
| 37 | |
Guennadi Liakhovetski | ac8fb3e | 2010-05-19 18:36:02 +0000 | [diff] [blame] | 38 | /* tmio MMC platform flags */ |
Yusuke Goda | f1334fb | 2010-08-30 11:50:19 +0100 | [diff] [blame] | 39 | /* |
| 40 | * Some controllers can support a 2-byte block size when the bus width |
| 41 | * is configured in 4-bit mode. |
| 42 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 43 | #define TMIO_MMC_BLKSZ_2BYTES BIT(1) |
Arnd Hannemann | 845ecd2 | 2010-12-28 23:22:31 +0100 | [diff] [blame] | 44 | /* |
| 45 | * Some controllers can support SDIO IRQ signalling. |
| 46 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 47 | #define TMIO_MMC_SDIO_IRQ BIT(2) |
Wolfram Sang | 04e24b8 | 2016-01-19 12:28:31 +0100 | [diff] [blame] | 48 | |
Wolfram Sang | d63c2bf | 2017-05-28 11:30:47 +0200 | [diff] [blame] | 49 | /* Some features are only available or tested on R-Car Gen2 or later */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 50 | #define TMIO_MMC_MIN_RCAR2 BIT(3) |
Wolfram Sang | 04e24b8 | 2016-01-19 12:28:31 +0100 | [diff] [blame] | 51 | |
Guennadi Liakhovetski | 7311bef | 2011-05-11 16:51:11 +0000 | [diff] [blame] | 52 | /* |
Simon Horman | 973ed3a | 2011-06-21 08:00:10 +0900 | [diff] [blame] | 53 | * Some controllers require waiting for the SD bus to become |
| 54 | * idle before writing to some registers. |
| 55 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 56 | #define TMIO_MMC_HAS_IDLE_WAIT BIT(4) |
Linus Walleij | faed930 | 2018-12-02 09:43:19 +0100 | [diff] [blame] | 57 | |
| 58 | /* BIT(5) is unused */ |
Guennadi Liakhovetski | ac8fb3e | 2010-05-19 18:36:02 +0000 | [diff] [blame] | 59 | |
Kuninori Morimoto | 5d60e50 | 2013-11-20 00:31:06 -0800 | [diff] [blame] | 60 | /* |
Shinobu Uehara | b8d1196 | 2014-08-24 20:00:25 -0700 | [diff] [blame] | 61 | * Some controllers have CMD12 automatically |
| 62 | * issue/non-issue register |
| 63 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 64 | #define TMIO_MMC_HAVE_CMD12_CTRL BIT(7) |
Shinobu Uehara | b8d1196 | 2014-08-24 20:00:25 -0700 | [diff] [blame] | 65 | |
Wolfram Sang | 20dd037 | 2017-01-19 21:07:17 +0100 | [diff] [blame] | 66 | /* Controller has some SDIO status bits which must be 1 */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 67 | #define TMIO_MMC_SDIO_STATUS_SETBITS BIT(8) |
Shinobu Uehara | 6b98757 | 2014-08-24 20:00:52 -0700 | [diff] [blame] | 68 | |
Kuninori Morimoto | e85dd04 | 2014-08-24 20:01:54 -0700 | [diff] [blame] | 69 | /* |
Chris Brandt | 8185e51 | 2016-09-12 10:15:06 -0400 | [diff] [blame] | 70 | * Some controllers have a 32-bit wide data port register |
| 71 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 72 | #define TMIO_MMC_32BIT_DATA_PORT BIT(9) |
Chris Brandt | 8185e51 | 2016-09-12 10:15:06 -0400 | [diff] [blame] | 73 | |
| 74 | /* |
Shinobu Uehara | da29fe2 | 2014-08-24 20:03:00 -0700 | [diff] [blame] | 75 | * Some controllers allows to set SDx actual clock |
| 76 | */ |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 77 | #define TMIO_MMC_CLK_ACTUAL BIT(10) |
Shinobu Uehara | da29fe2 | 2014-08-24 20:03:00 -0700 | [diff] [blame] | 78 | |
Wolfram Sang | 5124b59 | 2017-08-09 21:00:41 +0200 | [diff] [blame] | 79 | /* Some controllers have a CBSY bit */ |
| 80 | #define TMIO_MMC_HAVE_CBSY BIT(11) |
| 81 | |
Geert Uytterhoeven | a54e950 | 2018-11-07 14:50:01 +0100 | [diff] [blame] | 82 | /* Some controllers that support HS400 use 4 taps while others use 8. */ |
Masaharu Hayakawa | db924bb | 2018-06-18 14:57:50 +0200 | [diff] [blame] | 83 | #define TMIO_MMC_HAVE_4TAP_HS400 BIT(13) |
| 84 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 85 | int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base); |
| 86 | int tmio_core_mmc_resume(void __iomem *cnf, int shift, unsigned long base); |
| 87 | void tmio_core_mmc_pwr(void __iomem *cnf, int shift, int state); |
| 88 | void tmio_core_mmc_clk_div(void __iomem *cnf, int shift, int state); |
| 89 | |
Guennadi Liakhovetski | 03a0675 | 2013-04-26 17:47:17 +0200 | [diff] [blame] | 90 | struct dma_chan; |
| 91 | |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 92 | /* |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 93 | * data for the MMC controller |
| 94 | */ |
| 95 | struct tmio_mmc_data { |
Kuninori Morimoto | f33c9d6 | 2015-02-24 02:06:43 +0000 | [diff] [blame] | 96 | void *chan_priv_tx; |
| 97 | void *chan_priv_rx; |
Magnus Damm | 707f0b2 | 2010-02-17 16:38:14 +0900 | [diff] [blame] | 98 | unsigned int hclk; |
Yusuke Goda | b741d44 | 2010-02-17 16:37:55 +0900 | [diff] [blame] | 99 | unsigned long capabilities; |
Guennadi Liakhovetski | 02cb322 | 2012-05-23 10:44:37 +0200 | [diff] [blame] | 100 | unsigned long capabilities2; |
Guennadi Liakhovetski | ac8fb3e | 2010-05-19 18:36:02 +0000 | [diff] [blame] | 101 | unsigned long flags; |
Guennadi Liakhovetski | a2b14dc | 2010-05-19 18:37:25 +0000 | [diff] [blame] | 102 | u32 ocr_mask; /* available voltages */ |
Kuninori Morimoto | e471df0 | 2015-01-13 04:58:46 +0000 | [diff] [blame] | 103 | int alignment_shift; |
Kuninori Morimoto | 8b4c8f3 | 2015-01-13 04:58:56 +0000 | [diff] [blame] | 104 | dma_addr_t dma_rx_offset; |
Yoshihiro Shimoda | 603aa14 | 2017-06-21 16:00:27 +0200 | [diff] [blame] | 105 | unsigned int max_blk_count; |
| 106 | unsigned short max_segs; |
Chris Ball | 9d731e7 | 2013-09-06 07:29:05 -0400 | [diff] [blame] | 107 | void (*set_pwr)(struct platform_device *host, int state); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 108 | void (*set_clk_div)(struct platform_device *host, int state); |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 109 | }; |
| 110 | |
Guennadi Liakhovetski | c8be24c | 2012-02-09 22:57:09 +0100 | [diff] [blame] | 111 | /* |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 112 | * data for the NAND controller |
| 113 | */ |
| 114 | struct tmio_nand_data { |
| 115 | struct nand_bbt_descr *badblock_pattern; |
| 116 | struct mtd_partition *partition; |
| 117 | unsigned int num_partitions; |
Andrea Adami | 827dba9 | 2017-08-14 22:48:34 +0200 | [diff] [blame] | 118 | const char *const *part_parsers; |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
Dmitry Baryshkov | b53cde3 | 2008-10-15 22:03:55 -0700 | [diff] [blame] | 121 | #define FBIO_TMIO_ACC_WRITE 0x7C639300 |
| 122 | #define FBIO_TMIO_ACC_SYNC 0x7C639301 |
| 123 | |
| 124 | struct tmio_fb_data { |
| 125 | int (*lcd_set_power)(struct platform_device *fb_dev, |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 126 | bool on); |
Dmitry Baryshkov | b53cde3 | 2008-10-15 22:03:55 -0700 | [diff] [blame] | 127 | int (*lcd_mode)(struct platform_device *fb_dev, |
Simon Horman | f2218db | 2017-06-16 18:11:03 +0200 | [diff] [blame] | 128 | const struct fb_videomode *mode); |
Dmitry Baryshkov | b53cde3 | 2008-10-15 22:03:55 -0700 | [diff] [blame] | 129 | int num_modes; |
| 130 | struct fb_videomode *modes; |
| 131 | |
| 132 | /* in mm: size of screen */ |
| 133 | int height; |
| 134 | int width; |
| 135 | }; |
| 136 | |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 137 | #endif |