blob: c843c3134498a985b5e56151e1ececbb5bef49eb [file] [log] [blame]
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02001/*
2 * rcar_du_drv.h -- R-Car Display Unit DRM driver
3 *
Laurent Pinchart2427b302015-09-07 17:34:26 +03004 * Copyright (C) 2013-2015 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 Pinchart6d62ef32015-09-07 17:14:58 +030022#include "rcar_du_vsp.h"
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020023
24struct clk;
25struct device;
26struct drm_device;
Laurent Pinchart3864c6f2013-03-14 22:45:22 +010027struct drm_fbdev_cma;
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020028struct rcar_du_device;
Laurent Pinchart90374b52013-06-17 13:48:27 +020029struct rcar_du_lvdsenc;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020030
Laurent Pinchartf66ee302013-06-14 14:15:01 +020031#define RCAR_DU_FEATURE_CRTC_IRQ_CLOCK (1 << 0) /* Per-CRTC IRQ and clock */
Laurent Pinchart0c1c8772014-12-09 00:21:12 +020032#define RCAR_DU_FEATURE_EXT_CTRL_REGS (1 << 1) /* Has extended control registers */
Laurent Pinchart6d62ef32015-09-07 17:14:58 +030033#define RCAR_DU_FEATURE_VSP1_SOURCE (1 << 2) /* Has inputs from VSP1 */
Laurent Pincharte8355e02013-11-13 13:33:45 +010034
35#define RCAR_DU_QUIRK_ALIGN_128B (1 << 0) /* Align pitches to 128 bytes */
Laurent Pinchart5cca30e2013-11-13 13:35:15 +010036#define RCAR_DU_QUIRK_LVDS_LANES (1 << 1) /* LVDS lanes 1 and 3 inverted */
Laurent Pinchartf66ee302013-06-14 14:15:01 +020037
Laurent Pinchart481d3422013-06-14 13:38:33 +020038/*
Laurent Pinchartef67a902013-06-17 03:13:11 +020039 * struct rcar_du_output_routing - Output routing specification
40 * @possible_crtcs: bitmask of possible CRTCs for the output
41 * @encoder_type: DRM type of the internal encoder associated with the output
Laurent Pinchart96c02692014-01-21 15:57:26 +010042 * @port: device tree port number corresponding to this output route
Laurent Pinchartef67a902013-06-17 03:13:11 +020043 *
44 * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
45 * specify the valid SoC outputs, which CRTCs can drive the output, and the type
46 * of in-SoC encoder for the output.
47 */
48struct rcar_du_output_routing {
49 unsigned int possible_crtcs;
50 unsigned int encoder_type;
Laurent Pinchart96c02692014-01-21 15:57:26 +010051 unsigned int port;
Laurent Pinchartef67a902013-06-17 03:13:11 +020052};
53
54/*
Laurent Pinchart481d3422013-06-14 13:38:33 +020055 * struct rcar_du_device_info - DU model-specific information
Laurent Pinchart2427b302015-09-07 17:34:26 +030056 * @gen: device generation (2 or 3)
Laurent Pinchart481d3422013-06-14 13:38:33 +020057 * @features: device features (RCAR_DU_FEATURE_*)
Laurent Pincharte8355e02013-11-13 13:33:45 +010058 * @quirks: device quirks (RCAR_DU_QUIRK_*)
Laurent Pincharta5f0ef52013-06-17 00:29:25 +020059 * @num_crtcs: total number of CRTCs
Laurent Pinchartef67a902013-06-17 03:13:11 +020060 * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
Laurent Pinchart90374b52013-06-17 13:48:27 +020061 * @num_lvds: number of internal LVDS encoders
Laurent Pinchart481d3422013-06-14 13:38:33 +020062 */
63struct rcar_du_device_info {
Laurent Pinchart2427b302015-09-07 17:34:26 +030064 unsigned int gen;
Laurent Pinchart481d3422013-06-14 13:38:33 +020065 unsigned int features;
Laurent Pincharte8355e02013-11-13 13:33:45 +010066 unsigned int quirks;
Laurent Pincharta5f0ef52013-06-17 00:29:25 +020067 unsigned int num_crtcs;
Laurent Pinchartef67a902013-06-17 03:13:11 +020068 struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
Laurent Pinchart90374b52013-06-17 13:48:27 +020069 unsigned int num_lvds;
Laurent Pinchart481d3422013-06-14 13:38:33 +020070};
71
Koji Matsuoka6a8c49f2015-09-04 19:49:05 +090072#define RCAR_DU_MAX_CRTCS 4
Laurent Pincharta64b9c72015-02-25 18:21:12 +020073#define RCAR_DU_MAX_GROUPS DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
74#define RCAR_DU_MAX_LVDS 2
Laurent Pinchart6d62ef32015-09-07 17:14:58 +030075#define RCAR_DU_MAX_VSPS 4
Laurent Pincharta64b9c72015-02-25 18:21:12 +020076
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020077struct rcar_du_device {
78 struct device *dev;
Laurent Pinchart481d3422013-06-14 13:38:33 +020079 const struct rcar_du_device_info *info;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020080
81 void __iomem *mmio;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020082
83 struct drm_device *ddev;
Laurent Pinchart3864c6f2013-03-14 22:45:22 +010084 struct drm_fbdev_cma *fbdev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020085
Laurent Pincharta64b9c72015-02-25 18:21:12 +020086 struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020087 unsigned int num_crtcs;
88
Laurent Pincharta64b9c72015-02-25 18:21:12 +020089 struct rcar_du_group groups[RCAR_DU_MAX_GROUPS];
Laurent Pinchart6d62ef32015-09-07 17:14:58 +030090 struct rcar_du_vsp vsps[RCAR_DU_MAX_VSPS];
Laurent Pinchart7cbc05c2013-06-17 03:20:08 +020091
Laurent Pinchart9f6aee92015-04-28 23:59:29 +030092 struct {
93 struct drm_property *alpha;
94 struct drm_property *colorkey;
Laurent Pinchart9f6aee92015-04-28 23:59:29 +030095 } props;
96
Laurent Pinchart7cbc05c2013-06-17 03:20:08 +020097 unsigned int dpad0_source;
Laurent Pinchart34a04f22013-06-21 17:54:50 +020098 unsigned int vspd1_sink;
99
Laurent Pincharta64b9c72015-02-25 18:21:12 +0200100 struct rcar_du_lvdsenc *lvds[RCAR_DU_MAX_LVDS];
Laurent Pinchart8d3f9b22015-02-23 01:02:15 +0200101
102 struct {
103 wait_queue_head_t wait;
104 u32 pending;
105 } commit;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200106};
107
Laurent Pinchart481d3422013-06-14 13:38:33 +0200108static inline bool rcar_du_has(struct rcar_du_device *rcdu,
109 unsigned int feature)
110{
111 return rcdu->info->features & feature;
112}
113
Laurent Pincharte8355e02013-11-13 13:33:45 +0100114static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
115 unsigned int quirk)
116{
117 return rcdu->info->quirks & quirk;
118}
119
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200120static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
121{
122 return ioread32(rcdu->mmio + reg);
123}
124
125static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
126{
127 iowrite32(data, rcdu->mmio + reg);
128}
129
130#endif /* __RCAR_DU_DRV_H__ */