sti_compositor.c 7.8 KB
Newer Older
B
Benjamin Gaignard 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (C) STMicroelectronics SA 2014
 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
 *          Fabien Dessenne <fabien.dessenne@st.com>
 *          for STMicroelectronics.
 * License terms:  GNU General Public License (GPL), version 2
 */

#include <linux/component.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/reset.h>

#include <drm/drmP.h>

#include "sti_compositor.h"
17
#include "sti_crtc.h"
V
Vincent Abriou 已提交
18
#include "sti_cursor.h"
19
#include "sti_drv.h"
B
Benjamin Gaignard 已提交
20
#include "sti_gdp.h"
21
#include "sti_plane.h"
V
Vincent Abriou 已提交
22
#include "sti_vid.h"
B
Benjamin Gaignard 已提交
23 24 25 26 27
#include "sti_vtg.h"

/*
 * stiH407 compositor properties
 */
V
Ville Syrjälä 已提交
28
static const struct sti_compositor_data stih407_compositor_data = {
B
Benjamin Gaignard 已提交
29
	.nb_subdev = 8,
B
Benjamin Gaignard 已提交
30
	.subdev_desc = {
B
Benjamin Gaignard 已提交
31
			{STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
B
Benjamin Gaignard 已提交
32 33 34 35
			{STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
			{STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
			{STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
			{STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
V
Vincent Abriou 已提交
36
			{STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
37 38
			{STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
			{STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
B
Benjamin Gaignard 已提交
39 40 41 42 43 44 45 46 47 48
	},
};

/*
 * stiH416 compositor properties
 * Note:
 * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
 * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
 * not fit for stiH416 if we want to enable the MIXER_AUX.
 */
V
Ville Syrjälä 已提交
49
static const struct sti_compositor_data stih416_compositor_data = {
B
Benjamin Gaignard 已提交
50 51 52 53 54 55 56 57
	.nb_subdev = 3,
	.subdev_desc = {
			{STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
			{STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
			{STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
	},
};

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
int sti_compositor_debufs_init(struct sti_compositor *compo,
			       struct drm_minor *minor)
{
	int ret = 0, i;

	for (i = 0; compo->vid[i]; i++) {
		ret = vid_debugfs_init(compo->vid[i], minor);
		if (ret)
			return ret;
	}

	for (i = 0; compo->mixer[i]; i++) {
		ret = sti_mixer_debugfs_init(compo->mixer[i], minor);
		if (ret)
			return ret;
	}

	return 0;
}

V
Vincent Abriou 已提交
78 79 80
static int sti_compositor_bind(struct device *dev,
			       struct device *master,
			       void *data)
B
Benjamin Gaignard 已提交
81
{
V
Vincent Abriou 已提交
82 83
	struct sti_compositor *compo = dev_get_drvdata(dev);
	struct drm_device *drm_dev = data;
84
	unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
85
	struct sti_private *dev_priv = drm_dev->dev_private;
V
Vincent Abriou 已提交
86 87 88 89 90 91 92 93
	struct drm_plane *cursor = NULL;
	struct drm_plane *primary = NULL;
	struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
	unsigned int array_size = compo->data.nb_subdev;

	dev_priv->compo = compo;

	/* Register mixer subdev and video subdev first */
B
Benjamin Gaignard 已提交
94 95
	for (i = 0; i < array_size; i++) {
		switch (desc[i].type) {
V
Vincent Abriou 已提交
96 97
		case STI_VID_SUBDEV:
			compo->vid[vid_id++] =
98
			    sti_vid_create(compo->dev, drm_dev, desc[i].id,
V
Vincent Abriou 已提交
99 100
					   compo->regs + desc[i].offset);
			break;
B
Benjamin Gaignard 已提交
101 102 103
		case STI_MIXER_MAIN_SUBDEV:
		case STI_MIXER_AUX_SUBDEV:
			compo->mixer[mixer_id++] =
104
			    sti_mixer_create(compo->dev, drm_dev, desc[i].id,
B
Benjamin Gaignard 已提交
105 106 107
					     compo->regs + desc[i].offset);
			break;
		case STI_GPD_SUBDEV:
B
Benjamin Gaignard 已提交
108
		case STI_CURSOR_SUBDEV:
V
Vincent Abriou 已提交
109
			/* Nothing to do, wait for the second round */
B
Benjamin Gaignard 已提交
110 111 112 113 114 115 116
			break;
		default:
			DRM_ERROR("Unknow subdev compoment type\n");
			return 1;
		}
	}

V
Vincent Abriou 已提交
117 118 119
	/* Register the other subdevs, create crtc and planes */
	for (i = 0; i < array_size; i++) {
		enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
120

V
Vincent Abriou 已提交
121 122
		if (crtc_id < mixer_id)
			plane_type = DRM_PLANE_TYPE_PRIMARY;
123

V
Vincent Abriou 已提交
124 125 126 127 128 129 130
		switch (desc[i].type) {
		case STI_MIXER_MAIN_SUBDEV:
		case STI_MIXER_AUX_SUBDEV:
		case STI_VID_SUBDEV:
			/* Nothing to do, already done at the first round */
			break;
		case STI_CURSOR_SUBDEV:
131 132 133 134 135
			cursor = sti_cursor_create(drm_dev, compo->dev,
						   desc[i].id,
						   compo->regs + desc[i].offset,
						   1);
			if (!cursor) {
V
Vincent Abriou 已提交
136
				DRM_ERROR("Can't create CURSOR plane\n");
137
				break;
V
Vincent Abriou 已提交
138 139 140
			}
			break;
		case STI_GPD_SUBDEV:
141 142 143 144 145 146
			primary = sti_gdp_create(drm_dev, compo->dev,
						 desc[i].id,
						 compo->regs + desc[i].offset,
						 (1 << mixer_id) - 1,
						 plane_type);
			if (!primary) {
V
Vincent Abriou 已提交
147
				DRM_ERROR("Can't create GDP plane\n");
D
Dave Airlie 已提交
148
				break;
149
			}
V
Vincent Abriou 已提交
150 151 152 153 154
			break;
		default:
			DRM_ERROR("Unknown subdev compoment type\n");
			return 1;
		}
155

V
Vincent Abriou 已提交
156 157
		/* The first planes are reserved for primary planes*/
		if (crtc_id < mixer_id && primary) {
158 159
			sti_crtc_init(drm_dev, compo->mixer[crtc_id],
				      primary, cursor);
V
Vincent Abriou 已提交
160 161 162
			crtc_id++;
			cursor = NULL;
			primary = NULL;
163 164
		}
	}
B
Benjamin Gaignard 已提交
165

V
Vincent Abriou 已提交
166
	drm_vblank_init(drm_dev, crtc_id);
B
Benjamin Gaignard 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
	/* Allow usage of vblank without having to call drm_irq_install */
	drm_dev->irq_enabled = 1;

	return 0;
}

static void sti_compositor_unbind(struct device *dev, struct device *master,
	void *data)
{
	/* do nothing */
}

static const struct component_ops sti_compositor_ops = {
	.bind	= sti_compositor_bind,
	.unbind	= sti_compositor_unbind,
};

static const struct of_device_id compositor_of_match[] = {
	{
		.compatible = "st,stih416-compositor",
		.data = &stih416_compositor_data,
	}, {
		.compatible = "st,stih407-compositor",
		.data = &stih407_compositor_data,
	}, {
		/* end node */
	}
};
MODULE_DEVICE_TABLE(of, compositor_of_match);

static int sti_compositor_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct device_node *np = dev->of_node;
	struct device_node *vtg_np;
	struct sti_compositor *compo;
	struct resource *res;

	compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
	if (!compo) {
		DRM_ERROR("Failed to allocate compositor context\n");
		return -ENOMEM;
	}
	compo->dev = dev;
211
	compo->vtg_vblank_nb.notifier_call = sti_crtc_vblank_cb;
B
Benjamin Gaignard 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

	/* populate data structure depending on compatibility */
	BUG_ON(!of_match_node(compositor_of_match, np)->data);

	memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
	       sizeof(struct sti_compositor_data));

	/* Get Memory ressources */
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (res == NULL) {
		DRM_ERROR("Get memory resource failed\n");
		return -ENXIO;
	}
	compo->regs = devm_ioremap(dev, res->start, resource_size(res));
	if (compo->regs == NULL) {
		DRM_ERROR("Register mapping failed\n");
		return -ENXIO;
	}

	/* Get clock resources */
	compo->clk_compo_main = devm_clk_get(dev, "compo_main");
	if (IS_ERR(compo->clk_compo_main)) {
		DRM_ERROR("Cannot get compo_main clock\n");
		return PTR_ERR(compo->clk_compo_main);
	}

	compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
	if (IS_ERR(compo->clk_compo_aux)) {
		DRM_ERROR("Cannot get compo_aux clock\n");
		return PTR_ERR(compo->clk_compo_aux);
	}

	compo->clk_pix_main = devm_clk_get(dev, "pix_main");
	if (IS_ERR(compo->clk_pix_main)) {
		DRM_ERROR("Cannot get pix_main clock\n");
		return PTR_ERR(compo->clk_pix_main);
	}

	compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
	if (IS_ERR(compo->clk_pix_aux)) {
		DRM_ERROR("Cannot get pix_aux clock\n");
		return PTR_ERR(compo->clk_pix_aux);
	}

	/* Get reset resources */
L
Lee Jones 已提交
257
	compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
B
Benjamin Gaignard 已提交
258 259 260 261
	/* Take compo main out of reset */
	if (!IS_ERR(compo->rst_main))
		reset_control_deassert(compo->rst_main);

L
Lee Jones 已提交
262
	compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
B
Benjamin Gaignard 已提交
263 264 265 266 267 268 269
	/* Take compo aux out of reset */
	if (!IS_ERR(compo->rst_aux))
		reset_control_deassert(compo->rst_aux);

	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
	if (vtg_np)
		compo->vtg_main = of_vtg_find(vtg_np);
270
	of_node_put(vtg_np);
B
Benjamin Gaignard 已提交
271 272 273 274

	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
	if (vtg_np)
		compo->vtg_aux = of_vtg_find(vtg_np);
275
	of_node_put(vtg_np);
B
Benjamin Gaignard 已提交
276 277 278 279 280 281 282 283 284 285 286 287

	platform_set_drvdata(pdev, compo);

	return component_add(&pdev->dev, &sti_compositor_ops);
}

static int sti_compositor_remove(struct platform_device *pdev)
{
	component_del(&pdev->dev, &sti_compositor_ops);
	return 0;
}

T
Thierry Reding 已提交
288
struct platform_driver sti_compositor_driver = {
B
Benjamin Gaignard 已提交
289 290 291 292 293 294 295 296 297 298 299
	.driver = {
		.name = "sti-compositor",
		.of_match_table = compositor_of_match,
	},
	.probe = sti_compositor_probe,
	.remove = sti_compositor_remove,
};

MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
MODULE_LICENSE("GPL");