blob: 739b7bf37eaa5aa615d44fee25de958f61cc8f0f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +01002#ifndef MFD_TMIO_H
3#define MFD_TMIO_H
4
Guennadi Liakhovetskic8be24c2012-02-09 22:57:09 +01005#include <linux/device.h>
Dmitry Baryshkovb53cde32008-10-15 22:03:55 -07006#include <linux/fb.h>
Ian Molton64e88672010-01-06 13:51:48 +01007#include <linux/io.h>
Guennadi Liakhovetskic8be24c2012-02-09 22:57:09 +01008#include <linux/jiffies.h>
Kuninori Morimotobbf02082014-09-08 23:45:25 -07009#include <linux/mmc/card.h>
Ian Molton64e88672010-01-06 13:51:48 +010010#include <linux/platform_device.h>
Guennadi Liakhovetski7311bef2011-05-11 16:51:11 +000011#include <linux/pm_runtime.h>
Dmitry Baryshkovb53cde32008-10-15 22:03:55 -070012
Ian Moltond3a2f712008-07-31 20:44:28 +020013#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 Hormanf2218db2017-06-16 18:11:03 +020017 (((u32)readw((addr))) | (((u32)readw((addr) + 2)) << 16))
Ian Moltond3a2f712008-07-31 20:44:28 +020018
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 Hormanf2218db2017-06-16 18:11:03 +020024 writew((val), (addr)); \
25 writew((val) >> 16, (addr) + 2); \
Ian Moltond3a2f712008-07-31 20:44:28 +020026 } while (0)
27
Ian Molton64e88672010-01-06 13:51:48 +010028#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 Liakhovetskiac8fb3e2010-05-19 18:36:02 +000038/* tmio MMC platform flags */
Yusuke Godaf1334fb2010-08-30 11:50:19 +010039/*
40 * Some controllers can support a 2-byte block size when the bus width
41 * is configured in 4-bit mode.
42 */
Simon Hormanf2218db2017-06-16 18:11:03 +020043#define TMIO_MMC_BLKSZ_2BYTES BIT(1)
Arnd Hannemann845ecd22010-12-28 23:22:31 +010044/*
45 * Some controllers can support SDIO IRQ signalling.
46 */
Simon Hormanf2218db2017-06-16 18:11:03 +020047#define TMIO_MMC_SDIO_IRQ BIT(2)
Wolfram Sang04e24b82016-01-19 12:28:31 +010048
Wolfram Sangd63c2bf2017-05-28 11:30:47 +020049/* Some features are only available or tested on R-Car Gen2 or later */
Simon Hormanf2218db2017-06-16 18:11:03 +020050#define TMIO_MMC_MIN_RCAR2 BIT(3)
Wolfram Sang04e24b82016-01-19 12:28:31 +010051
Guennadi Liakhovetski7311bef2011-05-11 16:51:11 +000052/*
Simon Horman973ed3a2011-06-21 08:00:10 +090053 * Some controllers require waiting for the SD bus to become
54 * idle before writing to some registers.
55 */
Simon Hormanf2218db2017-06-16 18:11:03 +020056#define TMIO_MMC_HAS_IDLE_WAIT BIT(4)
Linus Walleijfaed9302018-12-02 09:43:19 +010057
58/* BIT(5) is unused */
Guennadi Liakhovetskiac8fb3e2010-05-19 18:36:02 +000059
Kuninori Morimoto5d60e502013-11-20 00:31:06 -080060/*
Shinobu Ueharab8d11962014-08-24 20:00:25 -070061 * Some controllers have CMD12 automatically
62 * issue/non-issue register
63 */
Simon Hormanf2218db2017-06-16 18:11:03 +020064#define TMIO_MMC_HAVE_CMD12_CTRL BIT(7)
Shinobu Ueharab8d11962014-08-24 20:00:25 -070065
Wolfram Sang20dd0372017-01-19 21:07:17 +010066/* Controller has some SDIO status bits which must be 1 */
Simon Hormanf2218db2017-06-16 18:11:03 +020067#define TMIO_MMC_SDIO_STATUS_SETBITS BIT(8)
Shinobu Uehara6b987572014-08-24 20:00:52 -070068
Kuninori Morimotoe85dd042014-08-24 20:01:54 -070069/*
Chris Brandt8185e512016-09-12 10:15:06 -040070 * Some controllers have a 32-bit wide data port register
71 */
Simon Hormanf2218db2017-06-16 18:11:03 +020072#define TMIO_MMC_32BIT_DATA_PORT BIT(9)
Chris Brandt8185e512016-09-12 10:15:06 -040073
74/*
Shinobu Ueharada29fe22014-08-24 20:03:00 -070075 * Some controllers allows to set SDx actual clock
76 */
Simon Hormanf2218db2017-06-16 18:11:03 +020077#define TMIO_MMC_CLK_ACTUAL BIT(10)
Shinobu Ueharada29fe22014-08-24 20:03:00 -070078
Wolfram Sang5124b592017-08-09 21:00:41 +020079/* Some controllers have a CBSY bit */
80#define TMIO_MMC_HAVE_CBSY BIT(11)
81
Geert Uytterhoevena54e9502018-11-07 14:50:01 +010082/* Some controllers that support HS400 use 4 taps while others use 8. */
Masaharu Hayakawadb924bb2018-06-18 14:57:50 +020083#define TMIO_MMC_HAVE_4TAP_HS400 BIT(13)
84
Ian Molton64e88672010-01-06 13:51:48 +010085int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base);
86int tmio_core_mmc_resume(void __iomem *cnf, int shift, unsigned long base);
87void tmio_core_mmc_pwr(void __iomem *cnf, int shift, int state);
88void tmio_core_mmc_clk_div(void __iomem *cnf, int shift, int state);
89
Guennadi Liakhovetski03a06752013-04-26 17:47:17 +020090struct dma_chan;
91
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +010092/*
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020093 * data for the MMC controller
94 */
95struct tmio_mmc_data {
Kuninori Morimotof33c9d62015-02-24 02:06:43 +000096 void *chan_priv_tx;
97 void *chan_priv_rx;
Magnus Damm707f0b22010-02-17 16:38:14 +090098 unsigned int hclk;
Yusuke Godab741d442010-02-17 16:37:55 +090099 unsigned long capabilities;
Guennadi Liakhovetski02cb3222012-05-23 10:44:37 +0200100 unsigned long capabilities2;
Guennadi Liakhovetskiac8fb3e2010-05-19 18:36:02 +0000101 unsigned long flags;
Guennadi Liakhovetskia2b14dc2010-05-19 18:37:25 +0000102 u32 ocr_mask; /* available voltages */
Kuninori Morimotoe471df02015-01-13 04:58:46 +0000103 int alignment_shift;
Kuninori Morimoto8b4c8f32015-01-13 04:58:56 +0000104 dma_addr_t dma_rx_offset;
Yoshihiro Shimoda603aa142017-06-21 16:00:27 +0200105 unsigned int max_blk_count;
106 unsigned short max_segs;
Chris Ball9d731e72013-09-06 07:29:05 -0400107 void (*set_pwr)(struct platform_device *host, int state);
Ian Molton64e88672010-01-06 13:51:48 +0100108 void (*set_clk_div)(struct platform_device *host, int state);
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200109};
110
Guennadi Liakhovetskic8be24c2012-02-09 22:57:09 +0100111/*
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100112 * data for the NAND controller
113 */
114struct tmio_nand_data {
115 struct nand_bbt_descr *badblock_pattern;
116 struct mtd_partition *partition;
117 unsigned int num_partitions;
Andrea Adami827dba92017-08-14 22:48:34 +0200118 const char *const *part_parsers;
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100119};
120
Dmitry Baryshkovb53cde32008-10-15 22:03:55 -0700121#define FBIO_TMIO_ACC_WRITE 0x7C639300
122#define FBIO_TMIO_ACC_SYNC 0x7C639301
123
124struct tmio_fb_data {
125 int (*lcd_set_power)(struct platform_device *fb_dev,
Simon Hormanf2218db2017-06-16 18:11:03 +0200126 bool on);
Dmitry Baryshkovb53cde32008-10-15 22:03:55 -0700127 int (*lcd_mode)(struct platform_device *fb_dev,
Simon Hormanf2218db2017-06-16 18:11:03 +0200128 const struct fb_videomode *mode);
Dmitry Baryshkovb53cde32008-10-15 22:03:55 -0700129 int num_modes;
130 struct fb_videomode *modes;
131
132 /* in mm: size of screen */
133 int height;
134 int width;
135};
136
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100137#endif