blob: 9f34fc86436a4ef6b6f744f050de1aef84c4f6fa [file] [log] [blame]
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02001/*
2 * rcar_du_drv.h -- R-Car Display Unit DRM driver
3 *
Laurent Pinchart36d50462014-02-06 18:13:52 +01004 * Copyright (C) 2013-2014 Renesas Electronics Corporation
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02005 *
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef __RCAR_DU_DRV_H__
15#define __RCAR_DU_DRV_H__
16
17#include <linux/kernel.h>
Laurent Pinchart8d3f9b22015-02-23 01:02:15 +020018#include <linux/wait.h>
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020019
20#include "rcar_du_crtc.h"
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020021#include "rcar_du_group.h"
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020022
23struct clk;
24struct device;
25struct drm_device;
Laurent Pinchart3864c6f2013-03-14 22:45:22 +010026struct drm_fbdev_cma;
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020027struct rcar_du_device;
Laurent Pinchart90374b52013-06-17 13:48:27 +020028struct rcar_du_lvdsenc;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020029
Laurent Pinchartf66ee302013-06-14 14:15:01 +020030#define RCAR_DU_FEATURE_CRTC_IRQ_CLOCK (1 << 0) /* Per-CRTC IRQ and clock */
Laurent Pinchart0c1c8772014-12-09 00:21:12 +020031#define RCAR_DU_FEATURE_EXT_CTRL_REGS (1 << 1) /* Has extended control registers */
Laurent Pincharte8355e02013-11-13 13:33:45 +010032
33#define RCAR_DU_QUIRK_ALIGN_128B (1 << 0) /* Align pitches to 128 bytes */
Laurent Pinchart5cca30e2013-11-13 13:35:15 +010034#define RCAR_DU_QUIRK_LVDS_LANES (1 << 1) /* LVDS lanes 1 and 3 inverted */
Laurent Pinchartf66ee302013-06-14 14:15:01 +020035
Laurent Pinchart481d3422013-06-14 13:38:33 +020036/*
Laurent Pinchartef67a902013-06-17 03:13:11 +020037 * struct rcar_du_output_routing - Output routing specification
38 * @possible_crtcs: bitmask of possible CRTCs for the output
39 * @encoder_type: DRM type of the internal encoder associated with the output
Laurent Pinchart96c02692014-01-21 15:57:26 +010040 * @port: device tree port number corresponding to this output route
Laurent Pinchartef67a902013-06-17 03:13:11 +020041 *
42 * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
43 * specify the valid SoC outputs, which CRTCs can drive the output, and the type
44 * of in-SoC encoder for the output.
45 */
46struct rcar_du_output_routing {
47 unsigned int possible_crtcs;
48 unsigned int encoder_type;
Laurent Pinchart96c02692014-01-21 15:57:26 +010049 unsigned int port;
Laurent Pinchartef67a902013-06-17 03:13:11 +020050};
51
52/*
Laurent Pinchart481d3422013-06-14 13:38:33 +020053 * struct rcar_du_device_info - DU model-specific information
54 * @features: device features (RCAR_DU_FEATURE_*)
Laurent Pincharte8355e02013-11-13 13:33:45 +010055 * @quirks: device quirks (RCAR_DU_QUIRK_*)
Laurent Pincharta5f0ef52013-06-17 00:29:25 +020056 * @num_crtcs: total number of CRTCs
Laurent Pinchartef67a902013-06-17 03:13:11 +020057 * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
Laurent Pinchart90374b52013-06-17 13:48:27 +020058 * @num_lvds: number of internal LVDS encoders
Laurent Pinchart481d3422013-06-14 13:38:33 +020059 */
60struct rcar_du_device_info {
61 unsigned int features;
Laurent Pincharte8355e02013-11-13 13:33:45 +010062 unsigned int quirks;
Laurent Pincharta5f0ef52013-06-17 00:29:25 +020063 unsigned int num_crtcs;
Laurent Pinchartef67a902013-06-17 03:13:11 +020064 struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
Laurent Pinchart90374b52013-06-17 13:48:27 +020065 unsigned int num_lvds;
Laurent Pinchart481d3422013-06-14 13:38:33 +020066};
67
Laurent Pincharta64b9c72015-02-25 18:21:12 +020068#define RCAR_DU_MAX_CRTCS 3
69#define RCAR_DU_MAX_GROUPS DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
70#define RCAR_DU_MAX_LVDS 2
71
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020072struct rcar_du_device {
73 struct device *dev;
Laurent Pinchart481d3422013-06-14 13:38:33 +020074 const struct rcar_du_device_info *info;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020075
76 void __iomem *mmio;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020077
78 struct drm_device *ddev;
Laurent Pinchart3864c6f2013-03-14 22:45:22 +010079 struct drm_fbdev_cma *fbdev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020080
Laurent Pincharta64b9c72015-02-25 18:21:12 +020081 struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020082 unsigned int num_crtcs;
83
Laurent Pincharta64b9c72015-02-25 18:21:12 +020084 struct rcar_du_group groups[RCAR_DU_MAX_GROUPS];
Laurent Pinchart7cbc05c2013-06-17 03:20:08 +020085
Laurent Pinchart9f6aee92015-04-28 23:59:29 +030086 struct {
87 struct drm_property *alpha;
88 struct drm_property *colorkey;
89 struct drm_property *zpos;
90 } props;
91
Laurent Pinchart7cbc05c2013-06-17 03:20:08 +020092 unsigned int dpad0_source;
Laurent Pincharta64b9c72015-02-25 18:21:12 +020093 struct rcar_du_lvdsenc *lvds[RCAR_DU_MAX_LVDS];
Laurent Pinchart8d3f9b22015-02-23 01:02:15 +020094
95 struct {
96 wait_queue_head_t wait;
97 u32 pending;
98 } commit;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020099};
100
Laurent Pinchart481d3422013-06-14 13:38:33 +0200101static inline bool rcar_du_has(struct rcar_du_device *rcdu,
102 unsigned int feature)
103{
104 return rcdu->info->features & feature;
105}
106
Laurent Pincharte8355e02013-11-13 13:33:45 +0100107static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
108 unsigned int quirk)
109{
110 return rcdu->info->quirks & quirk;
111}
112
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200113static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
114{
115 return ioread32(rcdu->mmio + reg);
116}
117
118static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
119{
120 iowrite32(data, rcdu->mmio + reg);
121}
122
123#endif /* __RCAR_DU_DRV_H__ */