Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (C) STMicroelectronics SA 2014
  3 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4 *          Fabien Dessenne <fabien.dessenne@st.com>
  5 *          for STMicroelectronics.
  6 * License terms:  GNU General Public License (GPL), version 2
  7 */
  8
  9#include <linux/component.h>
 
 10#include <linux/module.h>
 11#include <linux/platform_device.h>
 12#include <linux/reset.h>
 13
 14#include <drm/drmP.h>
 
 
 15
 16#include "sti_compositor.h"
 17#include "sti_crtc.h"
 18#include "sti_cursor.h"
 19#include "sti_drv.h"
 20#include "sti_gdp.h"
 21#include "sti_plane.h"
 22#include "sti_vid.h"
 23#include "sti_vtg.h"
 24
 25/*
 26 * stiH407 compositor properties
 27 */
 28struct sti_compositor_data stih407_compositor_data = {
 29	.nb_subdev = 8,
 30	.subdev_desc = {
 31			{STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
 32			{STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
 33			{STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
 34			{STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
 35			{STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
 36			{STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
 37			{STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
 38			{STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
 39	},
 40};
 41
 42/*
 43 * stiH416 compositor properties
 44 * Note:
 45 * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
 46 * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
 47 * not fit for stiH416 if we want to enable the MIXER_AUX.
 48 */
 49struct sti_compositor_data stih416_compositor_data = {
 50	.nb_subdev = 3,
 51	.subdev_desc = {
 52			{STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
 53			{STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
 54			{STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
 55	},
 56};
 57
 58static int sti_compositor_bind(struct device *dev,
 59			       struct device *master,
 60			       void *data)
 61{
 62	struct sti_compositor *compo = dev_get_drvdata(dev);
 63	struct drm_device *drm_dev = data;
 64	unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
 65	struct sti_private *dev_priv = drm_dev->dev_private;
 66	struct drm_plane *cursor = NULL;
 67	struct drm_plane *primary = NULL;
 68	struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
 69	unsigned int array_size = compo->data.nb_subdev;
 70
 71	dev_priv->compo = compo;
 72
 73	/* Register mixer subdev and video subdev first */
 74	for (i = 0; i < array_size; i++) {
 75		switch (desc[i].type) {
 76		case STI_VID_SUBDEV:
 77			compo->vid[vid_id++] =
 78			    sti_vid_create(compo->dev, drm_dev, desc[i].id,
 79					   compo->regs + desc[i].offset);
 80			break;
 81		case STI_MIXER_MAIN_SUBDEV:
 82		case STI_MIXER_AUX_SUBDEV:
 83			compo->mixer[mixer_id++] =
 84			    sti_mixer_create(compo->dev, drm_dev, desc[i].id,
 85					     compo->regs + desc[i].offset);
 86			break;
 87		case STI_GPD_SUBDEV:
 88		case STI_CURSOR_SUBDEV:
 89			/* Nothing to do, wait for the second round */
 90			break;
 91		default:
 92			DRM_ERROR("Unknow subdev compoment type\n");
 93			return 1;
 94		}
 95	}
 96
 97	/* Register the other subdevs, create crtc and planes */
 98	for (i = 0; i < array_size; i++) {
 99		enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
100
101		if (crtc_id < mixer_id)
102			plane_type = DRM_PLANE_TYPE_PRIMARY;
103
104		switch (desc[i].type) {
105		case STI_MIXER_MAIN_SUBDEV:
106		case STI_MIXER_AUX_SUBDEV:
107		case STI_VID_SUBDEV:
108			/* Nothing to do, already done at the first round */
109			break;
110		case STI_CURSOR_SUBDEV:
111			cursor = sti_cursor_create(drm_dev, compo->dev,
112						   desc[i].id,
113						   compo->regs + desc[i].offset,
114						   1);
115			if (!cursor) {
116				DRM_ERROR("Can't create CURSOR plane\n");
117				break;
118			}
119			break;
120		case STI_GPD_SUBDEV:
121			primary = sti_gdp_create(drm_dev, compo->dev,
122						 desc[i].id,
123						 compo->regs + desc[i].offset,
124						 (1 << mixer_id) - 1,
125						 plane_type);
126			if (!primary) {
127				DRM_ERROR("Can't create GDP plane\n");
128				break;
129			}
130			break;
131		default:
132			DRM_ERROR("Unknown subdev compoment type\n");
133			return 1;
134		}
135
136		/* The first planes are reserved for primary planes*/
137		if (crtc_id < mixer_id && primary) {
138			sti_crtc_init(drm_dev, compo->mixer[crtc_id],
139				      primary, cursor);
140			crtc_id++;
141			cursor = NULL;
142			primary = NULL;
143		}
144	}
145
146	drm_vblank_init(drm_dev, crtc_id);
147	/* Allow usage of vblank without having to call drm_irq_install */
148	drm_dev->irq_enabled = 1;
149
150	return 0;
151}
152
153static void sti_compositor_unbind(struct device *dev, struct device *master,
154	void *data)
155{
156	/* do nothing */
157}
158
159static const struct component_ops sti_compositor_ops = {
160	.bind	= sti_compositor_bind,
161	.unbind	= sti_compositor_unbind,
162};
163
164static const struct of_device_id compositor_of_match[] = {
165	{
166		.compatible = "st,stih416-compositor",
167		.data = &stih416_compositor_data,
168	}, {
169		.compatible = "st,stih407-compositor",
170		.data = &stih407_compositor_data,
171	}, {
172		/* end node */
173	}
174};
175MODULE_DEVICE_TABLE(of, compositor_of_match);
176
177static int sti_compositor_probe(struct platform_device *pdev)
178{
179	struct device *dev = &pdev->dev;
180	struct device_node *np = dev->of_node;
181	struct device_node *vtg_np;
182	struct sti_compositor *compo;
183	struct resource *res;
 
184
185	compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
186	if (!compo) {
187		DRM_ERROR("Failed to allocate compositor context\n");
188		return -ENOMEM;
189	}
190	compo->dev = dev;
191	compo->vtg_vblank_nb.notifier_call = sti_crtc_vblank_cb;
 
192
193	/* populate data structure depending on compatibility */
194	BUG_ON(!of_match_node(compositor_of_match, np)->data);
195
196	memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
197	       sizeof(struct sti_compositor_data));
198
199	/* Get Memory ressources */
200	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201	if (res == NULL) {
202		DRM_ERROR("Get memory resource failed\n");
203		return -ENXIO;
204	}
205	compo->regs = devm_ioremap(dev, res->start, resource_size(res));
206	if (compo->regs == NULL) {
207		DRM_ERROR("Register mapping failed\n");
208		return -ENXIO;
209	}
210
211	/* Get clock resources */
212	compo->clk_compo_main = devm_clk_get(dev, "compo_main");
213	if (IS_ERR(compo->clk_compo_main)) {
214		DRM_ERROR("Cannot get compo_main clock\n");
215		return PTR_ERR(compo->clk_compo_main);
216	}
217
218	compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
219	if (IS_ERR(compo->clk_compo_aux)) {
220		DRM_ERROR("Cannot get compo_aux clock\n");
221		return PTR_ERR(compo->clk_compo_aux);
222	}
223
224	compo->clk_pix_main = devm_clk_get(dev, "pix_main");
225	if (IS_ERR(compo->clk_pix_main)) {
226		DRM_ERROR("Cannot get pix_main clock\n");
227		return PTR_ERR(compo->clk_pix_main);
228	}
229
230	compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
231	if (IS_ERR(compo->clk_pix_aux)) {
232		DRM_ERROR("Cannot get pix_aux clock\n");
233		return PTR_ERR(compo->clk_pix_aux);
234	}
235
236	/* Get reset resources */
237	compo->rst_main = devm_reset_control_get(dev, "compo-main");
238	/* Take compo main out of reset */
239	if (!IS_ERR(compo->rst_main))
240		reset_control_deassert(compo->rst_main);
241
242	compo->rst_aux = devm_reset_control_get(dev, "compo-aux");
243	/* Take compo aux out of reset */
244	if (!IS_ERR(compo->rst_aux))
245		reset_control_deassert(compo->rst_aux);
246
247	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
248	if (vtg_np)
249		compo->vtg_main = of_vtg_find(vtg_np);
 
250
251	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
252	if (vtg_np)
253		compo->vtg_aux = of_vtg_find(vtg_np);
 
254
255	platform_set_drvdata(pdev, compo);
256
257	return component_add(&pdev->dev, &sti_compositor_ops);
258}
259
260static int sti_compositor_remove(struct platform_device *pdev)
261{
262	component_del(&pdev->dev, &sti_compositor_ops);
263	return 0;
264}
265
266struct platform_driver sti_compositor_driver = {
267	.driver = {
268		.name = "sti-compositor",
269		.of_match_table = compositor_of_match,
270	},
271	.probe = sti_compositor_probe,
272	.remove = sti_compositor_remove,
273};
274
275MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
276MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
277MODULE_LICENSE("GPL");
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) STMicroelectronics SA 2014
  4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5 *          Fabien Dessenne <fabien.dessenne@st.com>
  6 *          for STMicroelectronics.
 
  7 */
  8
  9#include <linux/component.h>
 10#include <linux/io.h>
 11#include <linux/module.h>
 12#include <linux/platform_device.h>
 13#include <linux/reset.h>
 14
 15#include <drm/drm_device.h>
 16#include <drm/drm_print.h>
 17#include <drm/drm_vblank.h>
 18
 19#include "sti_compositor.h"
 20#include "sti_crtc.h"
 21#include "sti_cursor.h"
 22#include "sti_drv.h"
 23#include "sti_gdp.h"
 24#include "sti_plane.h"
 25#include "sti_vid.h"
 26#include "sti_vtg.h"
 27
 28/*
 29 * stiH407 compositor properties
 30 */
 31static const struct sti_compositor_data stih407_compositor_data = {
 32	.nb_subdev = 8,
 33	.subdev_desc = {
 34			{STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
 35			{STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
 36			{STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
 37			{STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
 38			{STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
 39			{STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
 40			{STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
 41			{STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
 42	},
 43};
 44
 45void sti_compositor_debugfs_init(struct sti_compositor *compo,
 46				 struct drm_minor *minor)
 47{
 48	unsigned int i;
 49
 50	for (i = 0; i < STI_MAX_VID; i++)
 51		if (compo->vid[i])
 52			vid_debugfs_init(compo->vid[i], minor);
 53
 54	for (i = 0; i < STI_MAX_MIXER; i++)
 55		if (compo->mixer[i])
 56			sti_mixer_debugfs_init(compo->mixer[i], minor);
 57}
 
 
 58
 59static int sti_compositor_bind(struct device *dev,
 60			       struct device *master,
 61			       void *data)
 62{
 63	struct sti_compositor *compo = dev_get_drvdata(dev);
 64	struct drm_device *drm_dev = data;
 65	unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
 66	struct sti_private *dev_priv = drm_dev->dev_private;
 67	struct drm_plane *cursor = NULL;
 68	struct drm_plane *primary = NULL;
 69	struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
 70	unsigned int array_size = compo->data.nb_subdev;
 71
 72	dev_priv->compo = compo;
 73
 74	/* Register mixer subdev and video subdev first */
 75	for (i = 0; i < array_size; i++) {
 76		switch (desc[i].type) {
 77		case STI_VID_SUBDEV:
 78			compo->vid[vid_id++] =
 79			    sti_vid_create(compo->dev, drm_dev, desc[i].id,
 80					   compo->regs + desc[i].offset);
 81			break;
 82		case STI_MIXER_MAIN_SUBDEV:
 83		case STI_MIXER_AUX_SUBDEV:
 84			compo->mixer[mixer_id++] =
 85			    sti_mixer_create(compo->dev, drm_dev, desc[i].id,
 86					     compo->regs + desc[i].offset);
 87			break;
 88		case STI_GPD_SUBDEV:
 89		case STI_CURSOR_SUBDEV:
 90			/* Nothing to do, wait for the second round */
 91			break;
 92		default:
 93			DRM_ERROR("Unknown subdev component type\n");
 94			return 1;
 95		}
 96	}
 97
 98	/* Register the other subdevs, create crtc and planes */
 99	for (i = 0; i < array_size; i++) {
100		enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
101
102		if (crtc_id < mixer_id)
103			plane_type = DRM_PLANE_TYPE_PRIMARY;
104
105		switch (desc[i].type) {
106		case STI_MIXER_MAIN_SUBDEV:
107		case STI_MIXER_AUX_SUBDEV:
108		case STI_VID_SUBDEV:
109			/* Nothing to do, already done at the first round */
110			break;
111		case STI_CURSOR_SUBDEV:
112			cursor = sti_cursor_create(drm_dev, compo->dev,
113						   desc[i].id,
114						   compo->regs + desc[i].offset,
115						   1);
116			if (!cursor) {
117				DRM_ERROR("Can't create CURSOR plane\n");
118				break;
119			}
120			break;
121		case STI_GPD_SUBDEV:
122			primary = sti_gdp_create(drm_dev, compo->dev,
123						 desc[i].id,
124						 compo->regs + desc[i].offset,
125						 (1 << mixer_id) - 1,
126						 plane_type);
127			if (!primary) {
128				DRM_ERROR("Can't create GDP plane\n");
129				break;
130			}
131			break;
132		default:
133			DRM_ERROR("Unknown subdev component type\n");
134			return 1;
135		}
136
137		/* The first planes are reserved for primary planes*/
138		if (crtc_id < mixer_id && primary) {
139			sti_crtc_init(drm_dev, compo->mixer[crtc_id],
140				      primary, cursor);
141			crtc_id++;
142			cursor = NULL;
143			primary = NULL;
144		}
145	}
146
147	drm_vblank_init(drm_dev, crtc_id);
148	/* Allow usage of vblank without having to call drm_irq_install */
149	drm_dev->irq_enabled = 1;
150
151	return 0;
152}
153
154static void sti_compositor_unbind(struct device *dev, struct device *master,
155	void *data)
156{
157	/* do nothing */
158}
159
160static const struct component_ops sti_compositor_ops = {
161	.bind	= sti_compositor_bind,
162	.unbind	= sti_compositor_unbind,
163};
164
165static const struct of_device_id compositor_of_match[] = {
166	{
 
 
 
167		.compatible = "st,stih407-compositor",
168		.data = &stih407_compositor_data,
169	}, {
170		/* end node */
171	}
172};
173MODULE_DEVICE_TABLE(of, compositor_of_match);
174
175static int sti_compositor_probe(struct platform_device *pdev)
176{
177	struct device *dev = &pdev->dev;
178	struct device_node *np = dev->of_node;
179	struct device_node *vtg_np;
180	struct sti_compositor *compo;
181	struct resource *res;
182	unsigned int i;
183
184	compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
185	if (!compo) {
186		DRM_ERROR("Failed to allocate compositor context\n");
187		return -ENOMEM;
188	}
189	compo->dev = dev;
190	for (i = 0; i < STI_MAX_MIXER; i++)
191		compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb;
192
193	/* populate data structure depending on compatibility */
194	BUG_ON(!of_match_node(compositor_of_match, np)->data);
195
196	memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
197	       sizeof(struct sti_compositor_data));
198
199	/* Get Memory ressources */
200	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201	if (res == NULL) {
202		DRM_ERROR("Get memory resource failed\n");
203		return -ENXIO;
204	}
205	compo->regs = devm_ioremap(dev, res->start, resource_size(res));
206	if (compo->regs == NULL) {
207		DRM_ERROR("Register mapping failed\n");
208		return -ENXIO;
209	}
210
211	/* Get clock resources */
212	compo->clk_compo_main = devm_clk_get(dev, "compo_main");
213	if (IS_ERR(compo->clk_compo_main)) {
214		DRM_ERROR("Cannot get compo_main clock\n");
215		return PTR_ERR(compo->clk_compo_main);
216	}
217
218	compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
219	if (IS_ERR(compo->clk_compo_aux)) {
220		DRM_ERROR("Cannot get compo_aux clock\n");
221		return PTR_ERR(compo->clk_compo_aux);
222	}
223
224	compo->clk_pix_main = devm_clk_get(dev, "pix_main");
225	if (IS_ERR(compo->clk_pix_main)) {
226		DRM_ERROR("Cannot get pix_main clock\n");
227		return PTR_ERR(compo->clk_pix_main);
228	}
229
230	compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
231	if (IS_ERR(compo->clk_pix_aux)) {
232		DRM_ERROR("Cannot get pix_aux clock\n");
233		return PTR_ERR(compo->clk_pix_aux);
234	}
235
236	/* Get reset resources */
237	compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
238	/* Take compo main out of reset */
239	if (!IS_ERR(compo->rst_main))
240		reset_control_deassert(compo->rst_main);
241
242	compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
243	/* Take compo aux out of reset */
244	if (!IS_ERR(compo->rst_aux))
245		reset_control_deassert(compo->rst_aux);
246
247	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
248	if (vtg_np)
249		compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np);
250	of_node_put(vtg_np);
251
252	vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
253	if (vtg_np)
254		compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np);
255	of_node_put(vtg_np);
256
257	platform_set_drvdata(pdev, compo);
258
259	return component_add(&pdev->dev, &sti_compositor_ops);
260}
261
262static int sti_compositor_remove(struct platform_device *pdev)
263{
264	component_del(&pdev->dev, &sti_compositor_ops);
265	return 0;
266}
267
268struct platform_driver sti_compositor_driver = {
269	.driver = {
270		.name = "sti-compositor",
271		.of_match_table = compositor_of_match,
272	},
273	.probe = sti_compositor_probe,
274	.remove = sti_compositor_remove,
275};
276
277MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
278MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
279MODULE_LICENSE("GPL");