162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __ASM_SH_MOBILE_LCDC_H__
362306a36Sopenharmony_ci#define __ASM_SH_MOBILE_LCDC_H__
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/fb.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* Register definitions */
862306a36Sopenharmony_ci#define _LDDCKR			0x410
962306a36Sopenharmony_ci#define LDDCKR_ICKSEL_BUS	(0 << 16)
1062306a36Sopenharmony_ci#define LDDCKR_ICKSEL_MIPI	(1 << 16)
1162306a36Sopenharmony_ci#define LDDCKR_ICKSEL_HDMI	(2 << 16)
1262306a36Sopenharmony_ci#define LDDCKR_ICKSEL_EXT	(3 << 16)
1362306a36Sopenharmony_ci#define LDDCKR_ICKSEL_MASK	(7 << 16)
1462306a36Sopenharmony_ci#define LDDCKR_MOSEL		(1 << 6)
1562306a36Sopenharmony_ci#define _LDDCKSTPR		0x414
1662306a36Sopenharmony_ci#define _LDINTR			0x468
1762306a36Sopenharmony_ci#define LDINTR_FE		(1 << 10)
1862306a36Sopenharmony_ci#define LDINTR_VSE		(1 << 9)
1962306a36Sopenharmony_ci#define LDINTR_VEE		(1 << 8)
2062306a36Sopenharmony_ci#define LDINTR_FS		(1 << 2)
2162306a36Sopenharmony_ci#define LDINTR_VSS		(1 << 1)
2262306a36Sopenharmony_ci#define LDINTR_VES		(1 << 0)
2362306a36Sopenharmony_ci#define LDINTR_STATUS_MASK	(0xff << 0)
2462306a36Sopenharmony_ci#define _LDSR			0x46c
2562306a36Sopenharmony_ci#define LDSR_MSS		(1 << 10)
2662306a36Sopenharmony_ci#define LDSR_MRS		(1 << 8)
2762306a36Sopenharmony_ci#define LDSR_AS			(1 << 1)
2862306a36Sopenharmony_ci#define _LDCNT1R		0x470
2962306a36Sopenharmony_ci#define LDCNT1R_DE		(1 << 0)
3062306a36Sopenharmony_ci#define _LDCNT2R		0x474
3162306a36Sopenharmony_ci#define LDCNT2R_BR		(1 << 8)
3262306a36Sopenharmony_ci#define LDCNT2R_MD		(1 << 3)
3362306a36Sopenharmony_ci#define LDCNT2R_SE		(1 << 2)
3462306a36Sopenharmony_ci#define LDCNT2R_ME		(1 << 1)
3562306a36Sopenharmony_ci#define LDCNT2R_DO		(1 << 0)
3662306a36Sopenharmony_ci#define _LDRCNTR		0x478
3762306a36Sopenharmony_ci#define LDRCNTR_SRS		(1 << 17)
3862306a36Sopenharmony_ci#define LDRCNTR_SRC		(1 << 16)
3962306a36Sopenharmony_ci#define LDRCNTR_MRS		(1 << 1)
4062306a36Sopenharmony_ci#define LDRCNTR_MRC		(1 << 0)
4162306a36Sopenharmony_ci#define _LDDDSR			0x47c
4262306a36Sopenharmony_ci#define LDDDSR_LS		(1 << 2)
4362306a36Sopenharmony_ci#define LDDDSR_WS		(1 << 1)
4462306a36Sopenharmony_ci#define LDDDSR_BS		(1 << 0)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define LDMT1R_VPOL		(1 << 28)
4762306a36Sopenharmony_ci#define LDMT1R_HPOL		(1 << 27)
4862306a36Sopenharmony_ci#define LDMT1R_DWPOL		(1 << 26)
4962306a36Sopenharmony_ci#define LDMT1R_DIPOL		(1 << 25)
5062306a36Sopenharmony_ci#define LDMT1R_DAPOL		(1 << 24)
5162306a36Sopenharmony_ci#define LDMT1R_HSCNT		(1 << 17)
5262306a36Sopenharmony_ci#define LDMT1R_DWCNT		(1 << 16)
5362306a36Sopenharmony_ci#define LDMT1R_IFM		(1 << 12)
5462306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB8	(0x0 << 0)
5562306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB9	(0x4 << 0)
5662306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB12A	(0x5 << 0)
5762306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB12B	(0x6 << 0)
5862306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB16	(0x7 << 0)
5962306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB18	(0xa << 0)
6062306a36Sopenharmony_ci#define LDMT1R_MIFTYP_RGB24	(0xb << 0)
6162306a36Sopenharmony_ci#define LDMT1R_MIFTYP_YCBCR	(0xf << 0)
6262306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS8A	(0x0 << 0)
6362306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS8B	(0x1 << 0)
6462306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS8C	(0x2 << 0)
6562306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS8D	(0x3 << 0)
6662306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS9	(0x4 << 0)
6762306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS12	(0x5 << 0)
6862306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS16A	(0x7 << 0)
6962306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS16B	(0x8 << 0)
7062306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS16C	(0x9 << 0)
7162306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS18	(0xa << 0)
7262306a36Sopenharmony_ci#define LDMT1R_MIFTYP_SYS24	(0xb << 0)
7362306a36Sopenharmony_ci#define LDMT1R_MIFTYP_MASK	(0xf << 0)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define LDDFR_CF1		(1 << 18)
7662306a36Sopenharmony_ci#define LDDFR_CF0		(1 << 17)
7762306a36Sopenharmony_ci#define LDDFR_CC		(1 << 16)
7862306a36Sopenharmony_ci#define LDDFR_YF_420		(0 << 8)
7962306a36Sopenharmony_ci#define LDDFR_YF_422		(1 << 8)
8062306a36Sopenharmony_ci#define LDDFR_YF_444		(2 << 8)
8162306a36Sopenharmony_ci#define LDDFR_YF_MASK		(3 << 8)
8262306a36Sopenharmony_ci#define LDDFR_PKF_ARGB32	(0x00 << 0)
8362306a36Sopenharmony_ci#define LDDFR_PKF_RGB16		(0x03 << 0)
8462306a36Sopenharmony_ci#define LDDFR_PKF_RGB24		(0x0b << 0)
8562306a36Sopenharmony_ci#define LDDFR_PKF_MASK		(0x1f << 0)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define LDSM1R_OS		(1 << 0)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define LDSM2R_OSTRG		(1 << 0)
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define LDPMR_LPS		(3 << 0)
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define _LDDWD0R		0x800
9462306a36Sopenharmony_ci#define LDDWDxR_WDACT		(1 << 28)
9562306a36Sopenharmony_ci#define LDDWDxR_RSW		(1 << 24)
9662306a36Sopenharmony_ci#define _LDDRDR			0x840
9762306a36Sopenharmony_ci#define LDDRDR_RSR		(1 << 24)
9862306a36Sopenharmony_ci#define LDDRDR_DRD_MASK		(0x3ffff << 0)
9962306a36Sopenharmony_ci#define _LDDWAR			0x900
10062306a36Sopenharmony_ci#define LDDWAR_WA		(1 << 0)
10162306a36Sopenharmony_ci#define _LDDRAR			0x904
10262306a36Sopenharmony_ci#define LDDRAR_RA		(1 << 0)
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cienum {
10562306a36Sopenharmony_ci	RGB8	= LDMT1R_MIFTYP_RGB8,	/* 24bpp, 8:8:8 */
10662306a36Sopenharmony_ci	RGB9	= LDMT1R_MIFTYP_RGB9,	/* 18bpp, 9:9 */
10762306a36Sopenharmony_ci	RGB12A	= LDMT1R_MIFTYP_RGB12A,	/* 24bpp, 12:12 */
10862306a36Sopenharmony_ci	RGB12B	= LDMT1R_MIFTYP_RGB12B,	/* 12bpp */
10962306a36Sopenharmony_ci	RGB16	= LDMT1R_MIFTYP_RGB16,	/* 16bpp */
11062306a36Sopenharmony_ci	RGB18	= LDMT1R_MIFTYP_RGB18,	/* 18bpp */
11162306a36Sopenharmony_ci	RGB24	= LDMT1R_MIFTYP_RGB24,	/* 24bpp */
11262306a36Sopenharmony_ci	YUV422	= LDMT1R_MIFTYP_YCBCR,	/* 16bpp */
11362306a36Sopenharmony_ci	SYS8A	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS8A,	/* 24bpp, 8:8:8 */
11462306a36Sopenharmony_ci	SYS8B	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS8B,	/* 18bpp, 8:8:2 */
11562306a36Sopenharmony_ci	SYS8C	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS8C,	/* 18bpp, 2:8:8 */
11662306a36Sopenharmony_ci	SYS8D	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS8D,	/* 16bpp, 8:8 */
11762306a36Sopenharmony_ci	SYS9	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS9,	/* 18bpp, 9:9 */
11862306a36Sopenharmony_ci	SYS12	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS12,	/* 24bpp, 12:12 */
11962306a36Sopenharmony_ci	SYS16A	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS16A,	/* 16bpp */
12062306a36Sopenharmony_ci	SYS16B	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS16B,	/* 18bpp, 16:2 */
12162306a36Sopenharmony_ci	SYS16C	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS16C,	/* 18bpp, 2:16 */
12262306a36Sopenharmony_ci	SYS18	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS18,	/* 18bpp */
12362306a36Sopenharmony_ci	SYS24	= LDMT1R_IFM | LDMT1R_MIFTYP_SYS24,	/* 24bpp */
12462306a36Sopenharmony_ci};
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_cienum { LCDC_CHAN_DISABLED = 0,
12762306a36Sopenharmony_ci       LCDC_CHAN_MAINLCD,
12862306a36Sopenharmony_ci       LCDC_CHAN_SUBLCD };
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cienum { LCDC_CLK_BUS, LCDC_CLK_PERIPHERAL, LCDC_CLK_EXTERNAL };
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define LCDC_FLAGS_DWPOL (1 << 0) /* Rising edge dot clock data latch */
13362306a36Sopenharmony_ci#define LCDC_FLAGS_DIPOL (1 << 1) /* Active low display enable polarity */
13462306a36Sopenharmony_ci#define LCDC_FLAGS_DAPOL (1 << 2) /* Active low display data polarity */
13562306a36Sopenharmony_ci#define LCDC_FLAGS_HSCNT (1 << 3) /* Disable HSYNC during VBLANK */
13662306a36Sopenharmony_ci#define LCDC_FLAGS_DWCNT (1 << 4) /* Disable dotclock during blanking */
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_cistruct sh_mobile_lcdc_sys_bus_cfg {
13962306a36Sopenharmony_ci	unsigned long ldmt2r;
14062306a36Sopenharmony_ci	unsigned long ldmt3r;
14162306a36Sopenharmony_ci	unsigned long deferred_io_msec;
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistruct sh_mobile_lcdc_sys_bus_ops {
14562306a36Sopenharmony_ci	void (*write_index)(void *handle, unsigned long data);
14662306a36Sopenharmony_ci	void (*write_data)(void *handle, unsigned long data);
14762306a36Sopenharmony_ci	unsigned long (*read_data)(void *handle);
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistruct sh_mobile_lcdc_panel_cfg {
15162306a36Sopenharmony_ci	unsigned long width;		/* Panel width in mm */
15262306a36Sopenharmony_ci	unsigned long height;		/* Panel height in mm */
15362306a36Sopenharmony_ci	int (*setup_sys)(void *sys_ops_handle,
15462306a36Sopenharmony_ci			 struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
15562306a36Sopenharmony_ci	void (*start_transfer)(void *sys_ops_handle,
15662306a36Sopenharmony_ci			       struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
15762306a36Sopenharmony_ci	void (*display_on)(void);
15862306a36Sopenharmony_ci	void (*display_off)(void);
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/* backlight info */
16262306a36Sopenharmony_cistruct sh_mobile_lcdc_bl_info {
16362306a36Sopenharmony_ci	const char *name;
16462306a36Sopenharmony_ci	int max_brightness;
16562306a36Sopenharmony_ci	int (*set_brightness)(int brightness);
16662306a36Sopenharmony_ci};
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_cistruct sh_mobile_lcdc_overlay_cfg {
16962306a36Sopenharmony_ci	int fourcc;
17062306a36Sopenharmony_ci	unsigned int max_xres;
17162306a36Sopenharmony_ci	unsigned int max_yres;
17262306a36Sopenharmony_ci};
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_cistruct sh_mobile_lcdc_chan_cfg {
17562306a36Sopenharmony_ci	int chan;
17662306a36Sopenharmony_ci	int fourcc;
17762306a36Sopenharmony_ci	int colorspace;
17862306a36Sopenharmony_ci	int interface_type; /* selects RGBn or SYSn I/F, see above */
17962306a36Sopenharmony_ci	int clock_divider;
18062306a36Sopenharmony_ci	unsigned long flags; /* LCDC_FLAGS_... */
18162306a36Sopenharmony_ci	const struct fb_videomode *lcd_modes;
18262306a36Sopenharmony_ci	int num_modes;
18362306a36Sopenharmony_ci	struct sh_mobile_lcdc_panel_cfg panel_cfg;
18462306a36Sopenharmony_ci	struct sh_mobile_lcdc_bl_info bl_info;
18562306a36Sopenharmony_ci	struct sh_mobile_lcdc_sys_bus_cfg sys_bus_cfg; /* only for SYSn I/F */
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci	struct platform_device *tx_dev;	/* HDMI/DSI transmitter device */
18862306a36Sopenharmony_ci};
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cistruct sh_mobile_lcdc_info {
19162306a36Sopenharmony_ci	int clock_source;
19262306a36Sopenharmony_ci	struct sh_mobile_lcdc_chan_cfg ch[2];
19362306a36Sopenharmony_ci	struct sh_mobile_lcdc_overlay_cfg overlays[4];
19462306a36Sopenharmony_ci};
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#endif /* __ASM_SH_MOBILE_LCDC_H__ */
197