0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/component.h>
0010 #include <linux/io.h>
0011 #include <linux/module.h>
0012 #include <linux/of.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/reset.h>
0015
0016 #include <drm/drm_device.h>
0017 #include <drm/drm_print.h>
0018 #include <drm/drm_vblank.h>
0019
0020 #include "sti_compositor.h"
0021 #include "sti_crtc.h"
0022 #include "sti_cursor.h"
0023 #include "sti_drv.h"
0024 #include "sti_gdp.h"
0025 #include "sti_plane.h"
0026 #include "sti_vid.h"
0027 #include "sti_vtg.h"
0028
0029
0030
0031
0032 static const struct sti_compositor_data stih407_compositor_data = {
0033 .nb_subdev = 8,
0034 .subdev_desc = {
0035 {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
0036 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
0037 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
0038 {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
0039 {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
0040 {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
0041 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
0042 {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
0043 },
0044 };
0045
0046 void sti_compositor_debugfs_init(struct sti_compositor *compo,
0047 struct drm_minor *minor)
0048 {
0049 unsigned int i;
0050
0051 for (i = 0; i < STI_MAX_VID; i++)
0052 if (compo->vid[i])
0053 vid_debugfs_init(compo->vid[i], minor);
0054
0055 for (i = 0; i < STI_MAX_MIXER; i++)
0056 if (compo->mixer[i])
0057 sti_mixer_debugfs_init(compo->mixer[i], minor);
0058 }
0059
0060 static int sti_compositor_bind(struct device *dev,
0061 struct device *master,
0062 void *data)
0063 {
0064 struct sti_compositor *compo = dev_get_drvdata(dev);
0065 struct drm_device *drm_dev = data;
0066 unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
0067 struct sti_private *dev_priv = drm_dev->dev_private;
0068 struct drm_plane *cursor = NULL;
0069 struct drm_plane *primary = NULL;
0070 struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
0071 unsigned int array_size = compo->data.nb_subdev;
0072
0073 dev_priv->compo = compo;
0074
0075
0076 for (i = 0; i < array_size; i++) {
0077 switch (desc[i].type) {
0078 case STI_VID_SUBDEV:
0079 compo->vid[vid_id++] =
0080 sti_vid_create(compo->dev, drm_dev, desc[i].id,
0081 compo->regs + desc[i].offset);
0082 break;
0083 case STI_MIXER_MAIN_SUBDEV:
0084 case STI_MIXER_AUX_SUBDEV:
0085 compo->mixer[mixer_id++] =
0086 sti_mixer_create(compo->dev, drm_dev, desc[i].id,
0087 compo->regs + desc[i].offset);
0088 break;
0089 case STI_GPD_SUBDEV:
0090 case STI_CURSOR_SUBDEV:
0091
0092 break;
0093 default:
0094 DRM_ERROR("Unknown subdev component type\n");
0095 return 1;
0096 }
0097 }
0098
0099
0100 for (i = 0; i < array_size; i++) {
0101 enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
0102
0103 if (crtc_id < mixer_id)
0104 plane_type = DRM_PLANE_TYPE_PRIMARY;
0105
0106 switch (desc[i].type) {
0107 case STI_MIXER_MAIN_SUBDEV:
0108 case STI_MIXER_AUX_SUBDEV:
0109 case STI_VID_SUBDEV:
0110
0111 break;
0112 case STI_CURSOR_SUBDEV:
0113 cursor = sti_cursor_create(drm_dev, compo->dev,
0114 desc[i].id,
0115 compo->regs + desc[i].offset,
0116 1);
0117 if (!cursor) {
0118 DRM_ERROR("Can't create CURSOR plane\n");
0119 break;
0120 }
0121 break;
0122 case STI_GPD_SUBDEV:
0123 primary = sti_gdp_create(drm_dev, compo->dev,
0124 desc[i].id,
0125 compo->regs + desc[i].offset,
0126 (1 << mixer_id) - 1,
0127 plane_type);
0128 if (!primary) {
0129 DRM_ERROR("Can't create GDP plane\n");
0130 break;
0131 }
0132 break;
0133 default:
0134 DRM_ERROR("Unknown subdev component type\n");
0135 return 1;
0136 }
0137
0138
0139 if (crtc_id < mixer_id && primary) {
0140 sti_crtc_init(drm_dev, compo->mixer[crtc_id],
0141 primary, cursor);
0142 crtc_id++;
0143 cursor = NULL;
0144 primary = NULL;
0145 }
0146 }
0147
0148 drm_vblank_init(drm_dev, crtc_id);
0149
0150 return 0;
0151 }
0152
0153 static void sti_compositor_unbind(struct device *dev, struct device *master,
0154 void *data)
0155 {
0156
0157 }
0158
0159 static const struct component_ops sti_compositor_ops = {
0160 .bind = sti_compositor_bind,
0161 .unbind = sti_compositor_unbind,
0162 };
0163
0164 static const struct of_device_id compositor_of_match[] = {
0165 {
0166 .compatible = "st,stih407-compositor",
0167 .data = &stih407_compositor_data,
0168 }, {
0169
0170 }
0171 };
0172 MODULE_DEVICE_TABLE(of, compositor_of_match);
0173
0174 static int sti_compositor_probe(struct platform_device *pdev)
0175 {
0176 struct device *dev = &pdev->dev;
0177 struct device_node *np = dev->of_node;
0178 struct device_node *vtg_np;
0179 struct sti_compositor *compo;
0180 struct resource *res;
0181 unsigned int i;
0182
0183 compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
0184 if (!compo) {
0185 DRM_ERROR("Failed to allocate compositor context\n");
0186 return -ENOMEM;
0187 }
0188 compo->dev = dev;
0189 for (i = 0; i < STI_MAX_MIXER; i++)
0190 compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb;
0191
0192
0193 BUG_ON(!of_match_node(compositor_of_match, np)->data);
0194
0195 memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
0196 sizeof(struct sti_compositor_data));
0197
0198
0199 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0200 if (res == NULL) {
0201 DRM_ERROR("Get memory resource failed\n");
0202 return -ENXIO;
0203 }
0204 compo->regs = devm_ioremap(dev, res->start, resource_size(res));
0205 if (compo->regs == NULL) {
0206 DRM_ERROR("Register mapping failed\n");
0207 return -ENXIO;
0208 }
0209
0210
0211 compo->clk_compo_main = devm_clk_get(dev, "compo_main");
0212 if (IS_ERR(compo->clk_compo_main)) {
0213 DRM_ERROR("Cannot get compo_main clock\n");
0214 return PTR_ERR(compo->clk_compo_main);
0215 }
0216
0217 compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
0218 if (IS_ERR(compo->clk_compo_aux)) {
0219 DRM_ERROR("Cannot get compo_aux clock\n");
0220 return PTR_ERR(compo->clk_compo_aux);
0221 }
0222
0223 compo->clk_pix_main = devm_clk_get(dev, "pix_main");
0224 if (IS_ERR(compo->clk_pix_main)) {
0225 DRM_ERROR("Cannot get pix_main clock\n");
0226 return PTR_ERR(compo->clk_pix_main);
0227 }
0228
0229 compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
0230 if (IS_ERR(compo->clk_pix_aux)) {
0231 DRM_ERROR("Cannot get pix_aux clock\n");
0232 return PTR_ERR(compo->clk_pix_aux);
0233 }
0234
0235
0236 compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
0237
0238 if (!IS_ERR(compo->rst_main))
0239 reset_control_deassert(compo->rst_main);
0240
0241 compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
0242
0243 if (!IS_ERR(compo->rst_aux))
0244 reset_control_deassert(compo->rst_aux);
0245
0246 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
0247 if (vtg_np)
0248 compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np);
0249 of_node_put(vtg_np);
0250
0251 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
0252 if (vtg_np)
0253 compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np);
0254 of_node_put(vtg_np);
0255
0256 platform_set_drvdata(pdev, compo);
0257
0258 return component_add(&pdev->dev, &sti_compositor_ops);
0259 }
0260
0261 static int sti_compositor_remove(struct platform_device *pdev)
0262 {
0263 component_del(&pdev->dev, &sti_compositor_ops);
0264 return 0;
0265 }
0266
0267 struct platform_driver sti_compositor_driver = {
0268 .driver = {
0269 .name = "sti-compositor",
0270 .of_match_table = compositor_of_match,
0271 },
0272 .probe = sti_compositor_probe,
0273 .remove = sti_compositor_remove,
0274 };
0275
0276 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
0277 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
0278 MODULE_LICENSE("GPL");