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 | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 17 | #include "sti_crtc.h" |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 18 | #include "sti_cursor.h" |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 19 | #include "sti_drv.h" |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 20 | #include "sti_gdp.h" |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 21 | #include "sti_plane.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 | */ |
Ville Syrjälä | bdfd36e | 2016-09-19 16:33:53 +0300 | [diff] [blame] | 28 | static const 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 | |
Vincent Abriou | 38fdb8d | 2016-09-15 17:11:07 +0200 | [diff] [blame] | 42 | int sti_compositor_debugfs_init(struct sti_compositor *compo, |
| 43 | struct drm_minor *minor) |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 44 | { |
Vincent Abriou | 38fdb8d | 2016-09-15 17:11:07 +0200 | [diff] [blame] | 45 | unsigned int i; |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 46 | |
Vincent Abriou | 38fdb8d | 2016-09-15 17:11:07 +0200 | [diff] [blame] | 47 | for (i = 0; i < STI_MAX_VID; i++) |
| 48 | if (compo->vid[i]) |
| 49 | vid_debugfs_init(compo->vid[i], minor); |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 50 | |
Vincent Abriou | 38fdb8d | 2016-09-15 17:11:07 +0200 | [diff] [blame] | 51 | for (i = 0; i < STI_MAX_MIXER; i++) |
| 52 | if (compo->mixer[i]) |
| 53 | sti_mixer_debugfs_init(compo->mixer[i], minor); |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 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; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 64 | unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0; |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 65 | struct sti_private *dev_priv = drm_dev->dev_private; |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 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 | dev_priv->compo = compo; |
| 72 | |
| 73 | /* Register mixer subdev and video subdev first */ |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 74 | for (i = 0; i < array_size; i++) { |
| 75 | switch (desc[i].type) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 76 | case STI_VID_SUBDEV: |
| 77 | compo->vid[vid_id++] = |
Vincent Abriou | 90dffef | 2016-02-04 16:58:45 +0100 | [diff] [blame] | 78 | sti_vid_create(compo->dev, drm_dev, desc[i].id, |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 79 | compo->regs + desc[i].offset); |
| 80 | break; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 81 | case STI_MIXER_MAIN_SUBDEV: |
| 82 | case STI_MIXER_AUX_SUBDEV: |
| 83 | compo->mixer[mixer_id++] = |
Vincent Abriou | a5f8107 | 2016-02-04 17:44:50 +0100 | [diff] [blame] | 84 | sti_mixer_create(compo->dev, drm_dev, desc[i].id, |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 85 | compo->regs + desc[i].offset); |
| 86 | break; |
| 87 | case STI_GPD_SUBDEV: |
Benjamin Gaignard | 96006a7 | 2014-12-11 13:34:42 +0100 | [diff] [blame] | 88 | case STI_CURSOR_SUBDEV: |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 89 | /* Nothing to do, wait for the second round */ |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 90 | break; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 91 | default: |
| 92 | DRM_ERROR("Unknow subdev compoment type\n"); |
| 93 | return 1; |
| 94 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 95 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 96 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 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; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 100 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 101 | if (crtc_id < mixer_id) |
| 102 | plane_type = DRM_PLANE_TYPE_PRIMARY; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 103 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 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: |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 111 | cursor = sti_cursor_create(drm_dev, compo->dev, |
| 112 | desc[i].id, |
| 113 | compo->regs + desc[i].offset, |
| 114 | 1); |
| 115 | if (!cursor) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 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 | break; |
| 120 | case STI_GPD_SUBDEV: |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 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) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 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 | 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) { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 138 | sti_crtc_init(drm_dev, compo->mixer[crtc_id], |
| 139 | primary, cursor); |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 140 | crtc_id++; |
| 141 | cursor = NULL; |
| 142 | primary = NULL; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 143 | } |
| 144 | } |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 145 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 146 | drm_vblank_init(drm_dev, crtc_id); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 147 | /* Allow usage of vblank without having to call drm_irq_install */ |
| 148 | drm_dev->irq_enabled = 1; |
| 149 | |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static void sti_compositor_unbind(struct device *dev, struct device *master, |
| 154 | void *data) |
| 155 | { |
| 156 | /* do nothing */ |
| 157 | } |
| 158 | |
| 159 | static const struct component_ops sti_compositor_ops = { |
| 160 | .bind = sti_compositor_bind, |
| 161 | .unbind = sti_compositor_unbind, |
| 162 | }; |
| 163 | |
| 164 | static const struct of_device_id compositor_of_match[] = { |
| 165 | { |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 166 | .compatible = "st,stih407-compositor", |
| 167 | .data = &stih407_compositor_data, |
| 168 | }, { |
| 169 | /* end node */ |
| 170 | } |
| 171 | }; |
| 172 | MODULE_DEVICE_TABLE(of, compositor_of_match); |
| 173 | |
| 174 | static int sti_compositor_probe(struct platform_device *pdev) |
| 175 | { |
| 176 | struct device *dev = &pdev->dev; |
| 177 | struct device_node *np = dev->of_node; |
| 178 | struct device_node *vtg_np; |
| 179 | struct sti_compositor *compo; |
| 180 | struct resource *res; |
Fabien Dessenne | ae21785 | 2016-09-06 09:42:13 +0200 | [diff] [blame] | 181 | unsigned int i; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 182 | |
| 183 | compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL); |
| 184 | if (!compo) { |
| 185 | DRM_ERROR("Failed to allocate compositor context\n"); |
| 186 | return -ENOMEM; |
| 187 | } |
| 188 | compo->dev = dev; |
Fabien Dessenne | ae21785 | 2016-09-06 09:42:13 +0200 | [diff] [blame] | 189 | for (i = 0; i < STI_MAX_MIXER; i++) |
| 190 | compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb; |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 191 | |
| 192 | /* populate data structure depending on compatibility */ |
| 193 | BUG_ON(!of_match_node(compositor_of_match, np)->data); |
| 194 | |
| 195 | memcpy(&compo->data, of_match_node(compositor_of_match, np)->data, |
| 196 | sizeof(struct sti_compositor_data)); |
| 197 | |
| 198 | /* Get Memory ressources */ |
| 199 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 200 | if (res == NULL) { |
| 201 | DRM_ERROR("Get memory resource failed\n"); |
| 202 | return -ENXIO; |
| 203 | } |
| 204 | compo->regs = devm_ioremap(dev, res->start, resource_size(res)); |
| 205 | if (compo->regs == NULL) { |
| 206 | DRM_ERROR("Register mapping failed\n"); |
| 207 | return -ENXIO; |
| 208 | } |
| 209 | |
| 210 | /* Get clock resources */ |
| 211 | compo->clk_compo_main = devm_clk_get(dev, "compo_main"); |
| 212 | if (IS_ERR(compo->clk_compo_main)) { |
| 213 | DRM_ERROR("Cannot get compo_main clock\n"); |
| 214 | return PTR_ERR(compo->clk_compo_main); |
| 215 | } |
| 216 | |
| 217 | compo->clk_compo_aux = devm_clk_get(dev, "compo_aux"); |
| 218 | if (IS_ERR(compo->clk_compo_aux)) { |
| 219 | DRM_ERROR("Cannot get compo_aux clock\n"); |
| 220 | return PTR_ERR(compo->clk_compo_aux); |
| 221 | } |
| 222 | |
| 223 | compo->clk_pix_main = devm_clk_get(dev, "pix_main"); |
| 224 | if (IS_ERR(compo->clk_pix_main)) { |
| 225 | DRM_ERROR("Cannot get pix_main clock\n"); |
| 226 | return PTR_ERR(compo->clk_pix_main); |
| 227 | } |
| 228 | |
| 229 | compo->clk_pix_aux = devm_clk_get(dev, "pix_aux"); |
| 230 | if (IS_ERR(compo->clk_pix_aux)) { |
| 231 | DRM_ERROR("Cannot get pix_aux clock\n"); |
| 232 | return PTR_ERR(compo->clk_pix_aux); |
| 233 | } |
| 234 | |
| 235 | /* Get reset resources */ |
Lee Jones | c084c8d | 2016-07-25 11:09:33 +0100 | [diff] [blame] | 236 | compo->rst_main = devm_reset_control_get_shared(dev, "compo-main"); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 237 | /* Take compo main out of reset */ |
| 238 | if (!IS_ERR(compo->rst_main)) |
| 239 | reset_control_deassert(compo->rst_main); |
| 240 | |
Lee Jones | c084c8d | 2016-07-25 11:09:33 +0100 | [diff] [blame] | 241 | compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux"); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 242 | /* Take compo aux out of reset */ |
| 243 | if (!IS_ERR(compo->rst_aux)) |
| 244 | reset_control_deassert(compo->rst_aux); |
| 245 | |
| 246 | vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0); |
| 247 | if (vtg_np) |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 248 | compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np); |
Peter Chen | 9897f79 | 2016-07-05 10:04:49 +0800 | [diff] [blame] | 249 | of_node_put(vtg_np); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 250 | |
| 251 | vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1); |
| 252 | if (vtg_np) |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 253 | compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np); |
Peter Chen | 9897f79 | 2016-07-05 10:04:49 +0800 | [diff] [blame] | 254 | of_node_put(vtg_np); |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 255 | |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 256 | platform_set_drvdata(pdev, compo); |
| 257 | |
| 258 | return component_add(&pdev->dev, &sti_compositor_ops); |
| 259 | } |
| 260 | |
| 261 | static int sti_compositor_remove(struct platform_device *pdev) |
| 262 | { |
| 263 | component_del(&pdev->dev, &sti_compositor_ops); |
| 264 | return 0; |
| 265 | } |
| 266 | |
Thierry Reding | dcec16e | 2015-09-24 19:02:40 +0200 | [diff] [blame] | 267 | struct platform_driver sti_compositor_driver = { |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 268 | .driver = { |
| 269 | .name = "sti-compositor", |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 270 | .of_match_table = compositor_of_match, |
| 271 | }, |
| 272 | .probe = sti_compositor_probe, |
| 273 | .remove = sti_compositor_remove, |
| 274 | }; |
| 275 | |
Benjamin Gaignard | d219673 | 2014-07-30 19:28:27 +0200 | [diff] [blame] | 276 | MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>"); |
| 277 | MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver"); |
| 278 | MODULE_LICENSE("GPL"); |