Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 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" |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 17 | #include "sti_cursor.h" |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 18 | #include "sti_drm_crtc.h" |
| 19 | #include "sti_drm_drv.h" |
| 20 | #include "sti_drm_plane.h" |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 21 | #include "sti_gdp.h" |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 22 | #include "sti_vid.h" |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 23 | #include "sti_vtg.h" |
| 24 | |
| 25 | /* |
| 26 | * stiH407 compositor properties |
| 27 | */ |
| 28 | struct sti_compositor_data stih407_compositor_data = { |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 29 | .nb_subdev = 8, |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 30 | .subdev_desc = { |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 31 | {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000}, |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 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}, |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 36 | {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700}, |
Benjamin Gaignard | 5e03abc | 2014-12-08 17:32:36 +0100 | [diff] [blame] | 37 | {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}, |
| 38 | {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00}, |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 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 | */ |
| 49 | struct 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 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 58 | static int sti_compositor_bind(struct device *dev, |
| 59 | struct device *master, |
| 60 | void *data) |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 61 | { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 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, plane_id = 0; |
| 65 | struct sti_drm_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; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 70 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 71 | struct sti_plane *plane; |
| 72 | |
| 73 | dev_priv->compo = compo; |
| 74 | |
| 75 | /* Register mixer subdev and video subdev first */ |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 76 | for (i = 0; i < array_size; i++) { |
| 77 | switch (desc[i].type) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 78 | case STI_VID_SUBDEV: |
| 79 | compo->vid[vid_id++] = |
| 80 | sti_vid_create(compo->dev, desc[i].id, |
| 81 | compo->regs + desc[i].offset); |
| 82 | break; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 83 | case STI_MIXER_MAIN_SUBDEV: |
| 84 | case STI_MIXER_AUX_SUBDEV: |
| 85 | compo->mixer[mixer_id++] = |
| 86 | sti_mixer_create(compo->dev, desc[i].id, |
| 87 | compo->regs + desc[i].offset); |
| 88 | break; |
| 89 | case STI_GPD_SUBDEV: |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 90 | case STI_CURSOR_SUBDEV: |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 91 | /* Nothing to do, wait for the second round */ |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 92 | break; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 93 | default: |
| 94 | DRM_ERROR("Unknow subdev compoment type\n"); |
| 95 | return 1; |
| 96 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 97 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 98 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 99 | /* Register the other subdevs, create crtc and planes */ |
| 100 | for (i = 0; i < array_size; i++) { |
| 101 | enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 102 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 103 | if (crtc_id < mixer_id) |
| 104 | plane_type = DRM_PLANE_TYPE_PRIMARY; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 105 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 106 | switch (desc[i].type) { |
| 107 | case STI_MIXER_MAIN_SUBDEV: |
| 108 | case STI_MIXER_AUX_SUBDEV: |
| 109 | case STI_VID_SUBDEV: |
| 110 | /* Nothing to do, already done at the first round */ |
| 111 | break; |
| 112 | case STI_CURSOR_SUBDEV: |
| 113 | plane = sti_cursor_create(compo->dev, desc[i].id, |
| 114 | compo->regs + desc[i].offset); |
| 115 | if (!plane) { |
| 116 | DRM_ERROR("Can't create CURSOR plane\n"); |
Dave Airlie | 8bb652e | 2014-08-05 09:41:42 +1000 | [diff] [blame] | 117 | break; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 118 | } |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 119 | cursor = sti_drm_plane_init(drm_dev, plane, 1, |
| 120 | DRM_PLANE_TYPE_CURSOR); |
| 121 | plane_id++; |
| 122 | break; |
| 123 | case STI_GPD_SUBDEV: |
| 124 | plane = sti_gdp_create(compo->dev, desc[i].id, |
| 125 | compo->regs + desc[i].offset); |
| 126 | if (!plane) { |
| 127 | DRM_ERROR("Can't create GDP plane\n"); |
| 128 | break; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 129 | } |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 130 | primary = sti_drm_plane_init(drm_dev, plane, |
| 131 | (1 << mixer_id) - 1, |
| 132 | plane_type); |
| 133 | plane_id++; |
| 134 | break; |
| 135 | default: |
| 136 | DRM_ERROR("Unknown subdev compoment type\n"); |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | /* The first planes are reserved for primary planes*/ |
| 141 | if (crtc_id < mixer_id && primary) { |
| 142 | sti_drm_crtc_init(drm_dev, compo->mixer[crtc_id], |
| 143 | primary, cursor); |
| 144 | crtc_id++; |
| 145 | cursor = NULL; |
| 146 | primary = NULL; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 147 | } |
| 148 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 149 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 150 | drm_vblank_init(drm_dev, crtc_id); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 151 | /* Allow usage of vblank without having to call drm_irq_install */ |
| 152 | drm_dev->irq_enabled = 1; |
| 153 | |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 154 | DRM_DEBUG_DRIVER("Initialized %d DRM CRTC(s) and %d DRM plane(s)\n", |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame^] | 155 | crtc_id, plane_id); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 156 | DRM_DEBUG_DRIVER("DRM plane(s) for VID/VDP not created yet\n"); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static void sti_compositor_unbind(struct device *dev, struct device *master, |
| 162 | void *data) |
| 163 | { |
| 164 | /* do nothing */ |
| 165 | } |
| 166 | |
| 167 | static const struct component_ops sti_compositor_ops = { |
| 168 | .bind = sti_compositor_bind, |
| 169 | .unbind = sti_compositor_unbind, |
| 170 | }; |
| 171 | |
| 172 | static const struct of_device_id compositor_of_match[] = { |
| 173 | { |
| 174 | .compatible = "st,stih416-compositor", |
| 175 | .data = &stih416_compositor_data, |
| 176 | }, { |
| 177 | .compatible = "st,stih407-compositor", |
| 178 | .data = &stih407_compositor_data, |
| 179 | }, { |
| 180 | /* end node */ |
| 181 | } |
| 182 | }; |
| 183 | MODULE_DEVICE_TABLE(of, compositor_of_match); |
| 184 | |
| 185 | static int sti_compositor_probe(struct platform_device *pdev) |
| 186 | { |
| 187 | struct device *dev = &pdev->dev; |
| 188 | struct device_node *np = dev->of_node; |
| 189 | struct device_node *vtg_np; |
| 190 | struct sti_compositor *compo; |
| 191 | struct resource *res; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 192 | |
| 193 | compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL); |
| 194 | if (!compo) { |
| 195 | DRM_ERROR("Failed to allocate compositor context\n"); |
| 196 | return -ENOMEM; |
| 197 | } |
| 198 | compo->dev = dev; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 199 | compo->vtg_vblank_nb.notifier_call = sti_drm_crtc_vblank_cb; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 200 | |
| 201 | /* populate data structure depending on compatibility */ |
| 202 | BUG_ON(!of_match_node(compositor_of_match, np)->data); |
| 203 | |
| 204 | memcpy(&compo->data, of_match_node(compositor_of_match, np)->data, |
| 205 | sizeof(struct sti_compositor_data)); |
| 206 | |
| 207 | /* Get Memory ressources */ |
| 208 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 209 | if (res == NULL) { |
| 210 | DRM_ERROR("Get memory resource failed\n"); |
| 211 | return -ENXIO; |
| 212 | } |
| 213 | compo->regs = devm_ioremap(dev, res->start, resource_size(res)); |
| 214 | if (compo->regs == NULL) { |
| 215 | DRM_ERROR("Register mapping failed\n"); |
| 216 | return -ENXIO; |
| 217 | } |
| 218 | |
| 219 | /* Get clock resources */ |
| 220 | compo->clk_compo_main = devm_clk_get(dev, "compo_main"); |
| 221 | if (IS_ERR(compo->clk_compo_main)) { |
| 222 | DRM_ERROR("Cannot get compo_main clock\n"); |
| 223 | return PTR_ERR(compo->clk_compo_main); |
| 224 | } |
| 225 | |
| 226 | compo->clk_compo_aux = devm_clk_get(dev, "compo_aux"); |
| 227 | if (IS_ERR(compo->clk_compo_aux)) { |
| 228 | DRM_ERROR("Cannot get compo_aux clock\n"); |
| 229 | return PTR_ERR(compo->clk_compo_aux); |
| 230 | } |
| 231 | |
| 232 | compo->clk_pix_main = devm_clk_get(dev, "pix_main"); |
| 233 | if (IS_ERR(compo->clk_pix_main)) { |
| 234 | DRM_ERROR("Cannot get pix_main clock\n"); |
| 235 | return PTR_ERR(compo->clk_pix_main); |
| 236 | } |
| 237 | |
| 238 | compo->clk_pix_aux = devm_clk_get(dev, "pix_aux"); |
| 239 | if (IS_ERR(compo->clk_pix_aux)) { |
| 240 | DRM_ERROR("Cannot get pix_aux clock\n"); |
| 241 | return PTR_ERR(compo->clk_pix_aux); |
| 242 | } |
| 243 | |
| 244 | /* Get reset resources */ |
| 245 | compo->rst_main = devm_reset_control_get(dev, "compo-main"); |
| 246 | /* Take compo main out of reset */ |
| 247 | if (!IS_ERR(compo->rst_main)) |
| 248 | reset_control_deassert(compo->rst_main); |
| 249 | |
| 250 | compo->rst_aux = devm_reset_control_get(dev, "compo-aux"); |
| 251 | /* Take compo aux out of reset */ |
| 252 | if (!IS_ERR(compo->rst_aux)) |
| 253 | reset_control_deassert(compo->rst_aux); |
| 254 | |
| 255 | vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0); |
| 256 | if (vtg_np) |
| 257 | compo->vtg_main = of_vtg_find(vtg_np); |
| 258 | |
| 259 | vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1); |
| 260 | if (vtg_np) |
| 261 | compo->vtg_aux = of_vtg_find(vtg_np); |
| 262 | |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 263 | platform_set_drvdata(pdev, compo); |
| 264 | |
| 265 | return component_add(&pdev->dev, &sti_compositor_ops); |
| 266 | } |
| 267 | |
| 268 | static int sti_compositor_remove(struct platform_device *pdev) |
| 269 | { |
| 270 | component_del(&pdev->dev, &sti_compositor_ops); |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static struct platform_driver sti_compositor_driver = { |
| 275 | .driver = { |
| 276 | .name = "sti-compositor", |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 277 | .of_match_table = compositor_of_match, |
| 278 | }, |
| 279 | .probe = sti_compositor_probe, |
| 280 | .remove = sti_compositor_remove, |
| 281 | }; |
| 282 | |
| 283 | module_platform_driver(sti_compositor_driver); |
| 284 | |
| 285 | MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>"); |
| 286 | MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver"); |
| 287 | MODULE_LICENSE("GPL"); |