History

drm: renesas: shmobile: Add DT support

Add DT support, by: 1. Creating a panel bridge from DT, and attaching it to the encoder, 2. Replacing the custom connector with a bridge connector, 3. Obtaining clock configuration based on the compatible value. Note that for now the driver uses a fixed clock configuration selecting the bus clock, as the current code to select other clock inputs needs changes to support any other SoCs than SH7724.

Geert Uytterhoeven committed 3 years ago

Commit 1399eba1 parent b2b2f7b4 files · +74 −16Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c +43 −13
  2. drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h +1 −0
  3. drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c +24 −3
  4. drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h +6 −0
drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c+43−13
@@ -9,12 +9,16 @@ · 8 unmodified lines
9 9
10#include <linux/clk.h>10#include <linux/clk.h>
11#include <linux/media-bus-format.h>11#include <linux/media-bus-format.h>
12#include <linux/of.h>
13#include <linux/of_graph.h>
12#include <linux/pm_runtime.h>14#include <linux/pm_runtime.h>
13 15
14#include <drm/drm_atomic.h>16#include <drm/drm_atomic.h>
15#include <drm/drm_atomic_helper.h>17#include <drm/drm_atomic_helper.h>
16#include <drm/drm_atomic_state_helper.h>18#include <drm/drm_atomic_state_helper.h>
17#include <drm/drm_atomic_uapi.h>19#include <drm/drm_atomic_uapi.h>
20#include <drm/drm_bridge.h>
21#include <drm/drm_bridge_connector.h>
18#include <drm/drm_crtc.h>22#include <drm/drm_crtc.h>
19#include <drm/drm_crtc_helper.h>23#include <drm/drm_crtc_helper.h>
20#include <drm/drm_fb_dma_helper.h>24#include <drm/drm_fb_dma_helper.h>
@@ -23,6 +27,7 @@ · 2 unmodified lines
23#include <drm/drm_gem_dma_helper.h>27#include <drm/drm_gem_dma_helper.h>
24#include <drm/drm_modeset_helper.h>28#include <drm/drm_modeset_helper.h>
25#include <drm/drm_modeset_helper_vtables.h>29#include <drm/drm_modeset_helper_vtables.h>
30#include <drm/drm_panel.h>
26#include <drm/drm_probe_helper.h>31#include <drm/drm_probe_helper.h>
27#include <drm/drm_simple_kms_helper.h>32#include <drm/drm_simple_kms_helper.h>
28#include <drm/drm_vblank.h>33#include <drm/drm_vblank.h>
@@ -35,10 +40,6 @@ · 6 unmodified lines
35#include "shmob_drm_plane.h"40#include "shmob_drm_plane.h"
36#include "shmob_drm_regs.h"41#include "shmob_drm_regs.h"
37 42
38/*
39 * TODO: panel support
40 */
41
42/* -----------------------------------------------------------------------------43/* -----------------------------------------------------------------------------
43 * Page Flip44 * Page Flip
44 */45 */
@@ -201,7 +202,7 @@ static void shmob_drm_crtc_atomic_enable(struct drm_crtc *crtc, · 156 unmodified lines
201{202{
202 struct shmob_drm_crtc *scrtc = to_shmob_crtc(crtc);203 struct shmob_drm_crtc *scrtc = to_shmob_crtc(crtc);
203 struct shmob_drm_device *sdev = to_shmob_device(crtc->dev);204 struct shmob_drm_device *sdev = to_shmob_device(crtc->dev);
204 const struct shmob_drm_interface_data *idata = &sdev->pdata->iface;205 unsigned int clk_div = sdev->config.clk_div;
205 struct device *dev = sdev->dev;206 struct device *dev = sdev->dev;
206 u32 value;207 u32 value;
207 int ret;208 int ret;
@@ -223,17 +224,17 @@ static void shmob_drm_crtc_atomic_enable(struct drm_crtc *crtc, · 15 unmodified lines
223 lcdc_write(sdev, LDPMR, 0);224 lcdc_write(sdev, LDPMR, 0);
224 225
225 value = sdev->lddckr;226 value = sdev->lddckr;
226 if (idata->clk_div) {227 if (clk_div) {
227 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider228 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
228 * denominator.229 * denominator.
229 */230 */
230 lcdc_write(sdev, LDDCKPAT1R, 0);231 lcdc_write(sdev, LDDCKPAT1R, 0);
231 lcdc_write(sdev, LDDCKPAT2R, (1 << (idata->clk_div / 2)) - 1);232 lcdc_write(sdev, LDDCKPAT2R, (1 << (clk_div / 2)) - 1);
232 233
233 if (idata->clk_div == 1)234 if (clk_div == 1)
234 value |= LDDCKR_MOSEL;235 value |= LDDCKR_MOSEL;
235 else236 else
236 value |= idata->clk_div;237 value |= clk_div;
237 }238 }
238 239
239 lcdc_write(sdev, LDDCKR, value);240 lcdc_write(sdev, LDDCKR, value);
@@ -406,7 +407,7 @@ int shmob_drm_crtc_create(struct shmob_drm_device *sdev) · 166 unmodified lines
406}407}
407 408
408/* -----------------------------------------------------------------------------409/* -----------------------------------------------------------------------------
409 * Encoder410 * Legacy Encoder
410 */411 */
411 412
412static bool shmob_drm_encoder_mode_fixup(struct drm_encoder *encoder,413static bool shmob_drm_encoder_mode_fixup(struct drm_encoder *encoder,
@@ -435,9 +436,14 @@ static const struct drm_encoder_helper_funcs encoder_helper_funcs = { · 22 unmodified lines
435 .mode_fixup = shmob_drm_encoder_mode_fixup,436 .mode_fixup = shmob_drm_encoder_mode_fixup,
436};437};
437 438
439/* -----------------------------------------------------------------------------
440 * Encoder
441 */
442
438int shmob_drm_encoder_create(struct shmob_drm_device *sdev)443int shmob_drm_encoder_create(struct shmob_drm_device *sdev)
439{444{
440 struct drm_encoder *encoder = &sdev->encoder;445 struct drm_encoder *encoder = &sdev->encoder;
446 struct drm_bridge *bridge;
441 int ret;447 int ret;
442 448
443 encoder->possible_crtcs = 1;449 encoder->possible_crtcs = 1;
@@ -447,13 +453,30 @@ int shmob_drm_encoder_create(struct shmob_drm_device *sdev) · 3 unmodified lines
447 if (ret < 0)453 if (ret < 0)
448 return ret;454 return ret;
449 455
450 drm_encoder_helper_add(encoder, &encoder_helper_funcs);456 if (sdev->pdata) {
457 drm_encoder_helper_add(encoder, &encoder_helper_funcs);
458 return 0;
459 }
460
461 /* Create a panel bridge */
462 bridge = devm_drm_of_get_bridge(sdev->dev, sdev->dev->of_node, 0, 0);
463 if (IS_ERR(bridge))
464 return PTR_ERR(bridge);
465
466 /* Attach the bridge to the encoder */
467 ret = drm_bridge_attach(encoder, bridge, NULL,
468 DRM_BRIDGE_ATTACH_NO_CONNECTOR);
469 if (ret) {
470 dev_err(sdev->dev, "failed to attach bridge: %pe\n",
471 ERR_PTR(ret));
472 return ret;
473 }
451 474
452 return 0;475 return 0;
453}476}
454 477
455/* -----------------------------------------------------------------------------478/* -----------------------------------------------------------------------------
456 * Connector479 * Legacy Connector
457 */480 */
458 481
459static inline struct shmob_drm_connector *to_shmob_connector(struct drm_connector *connector)482static inline struct shmob_drm_connector *to_shmob_connector(struct drm_connector *connector)
@@ -563,13 +586,20 @@ shmob_drm_connector_init(struct shmob_drm_device *sdev, · 103 unmodified lines
563 return connector;586 return connector;
564}587}
565 588
589/* -----------------------------------------------------------------------------
590 * Connector
591 */
592
566int shmob_drm_connector_create(struct shmob_drm_device *sdev,593int shmob_drm_connector_create(struct shmob_drm_device *sdev,
567 struct drm_encoder *encoder)594 struct drm_encoder *encoder)
568{595{
569 struct drm_connector *connector;596 struct drm_connector *connector;
570 int ret;597 int ret;
571 598
572 connector = shmob_drm_connector_init(sdev, encoder);599 if (sdev->pdata)
600 connector = shmob_drm_connector_init(sdev, encoder);
601 else
602 connector = drm_bridge_connector_init(&sdev->ddev, encoder);
573 if (IS_ERR(connector)) {603 if (IS_ERR(connector)) {
574 dev_err(sdev->dev, "failed to created connector: %pe\n",604 dev_err(sdev->dev, "failed to created connector: %pe\n",
575 connector);605 connector);
drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h+1−0
@@ -29,6 +29,7 @@ struct shmob_drm_crtc { · 28 unmodified lines
29 wait_queue_head_t flip_wait;29 wait_queue_head_t flip_wait;
30};30};
31 31
32/* Legacy connector */
32struct shmob_drm_connector {33struct shmob_drm_connector {
33 struct drm_connector base;34 struct drm_connector base;
34 struct drm_encoder *encoder;35 struct drm_encoder *encoder;
drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c+24−3
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <linux/io.h>11#include <linux/io.h>
12#include <linux/mm.h>12#include <linux/mm.h>
13#include <linux/module.h>13#include <linux/module.h>
14#include <linux/of.h>
14#include <linux/platform_device.h>15#include <linux/platform_device.h>
15#include <linux/pm.h>16#include <linux/pm.h>
16#include <linux/pm_runtime.h>17#include <linux/pm_runtime.h>
@@ -173,11 +174,13 @@ static void shmob_drm_remove(struct platform_device *pdev) · 156 unmodified lines
173static int shmob_drm_probe(struct platform_device *pdev)174static int shmob_drm_probe(struct platform_device *pdev)
174{175{
175 struct shmob_drm_platform_data *pdata = pdev->dev.platform_data;176 struct shmob_drm_platform_data *pdata = pdev->dev.platform_data;
177 const struct shmob_drm_config *config;
176 struct shmob_drm_device *sdev;178 struct shmob_drm_device *sdev;
177 struct drm_device *ddev;179 struct drm_device *ddev;
178 int ret;180 int ret;
179 181
180 if (pdata == NULL) {182 config = of_device_get_match_data(&pdev->dev);
183 if (!config && !pdata) {
181 dev_err(&pdev->dev, "no platform data\n");184 dev_err(&pdev->dev, "no platform data\n");
182 return -EINVAL;185 return -EINVAL;
183 }186 }
@@ -193,7 +196,13 @@ static int shmob_drm_probe(struct platform_device *pdev) · 9 unmodified lines
193 196
194 ddev = &sdev->ddev;197 ddev = &sdev->ddev;
195 sdev->dev = &pdev->dev;198 sdev->dev = &pdev->dev;
196 sdev->pdata = pdata;199 if (config) {
200 sdev->config = *config;
201 } else {
202 sdev->pdata = pdata;
203 sdev->config.clk_source = pdata->clk_source;
204 sdev->config.clk_div = pdata->iface.clk_div;
205 }
197 spin_lock_init(&sdev->irq_lock);206 spin_lock_init(&sdev->irq_lock);
198 207
199 platform_set_drvdata(pdev, sdev);208 platform_set_drvdata(pdev, sdev);
@@ -202,7 +211,7 @@ static int shmob_drm_probe(struct platform_device *pdev) · 2 unmodified lines
202 if (IS_ERR(sdev->mmio))211 if (IS_ERR(sdev->mmio))
203 return PTR_ERR(sdev->mmio);212 return PTR_ERR(sdev->mmio);
204 213
205 ret = shmob_drm_setup_clocks(sdev, pdata->clk_source);214 ret = shmob_drm_setup_clocks(sdev, sdev->config.clk_source);
206 if (ret < 0)215 if (ret < 0)
207 return ret;216 return ret;
208 217
@@ -250,11 +259,23 @@ err_modeset_cleanup: · 41 unmodified lines
250 return ret;259 return ret;
251}260}
252 261
262static const struct shmob_drm_config shmob_arm_config = {
263 .clk_source = SHMOB_DRM_CLK_BUS,
264 .clk_div = 5,
265};
266
267static const struct of_device_id shmob_drm_of_table[] __maybe_unused = {
268 { .compatible = "renesas,r8a7740-lcdc", .data = &shmob_arm_config, },
269 { .compatible = "renesas,sh73a0-lcdc", .data = &shmob_arm_config, },
270 { /* sentinel */ }
271};
272
253static struct platform_driver shmob_drm_platform_driver = {273static struct platform_driver shmob_drm_platform_driver = {
254 .probe = shmob_drm_probe,274 .probe = shmob_drm_probe,
255 .remove_new = shmob_drm_remove,275 .remove_new = shmob_drm_remove,
256 .driver = {276 .driver = {
257 .name = "shmob-drm",277 .name = "shmob-drm",
278 .of_match_table = of_match_ptr(shmob_drm_of_table),
258 .pm = &shmob_drm_pm_ops,279 .pm = &shmob_drm_pm_ops,
259 },280 },
260};281};
drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h+6−0
@@ -20,9 +20,15 @@ struct clk; · 19 unmodified lines
20struct device;20struct device;
21struct drm_device;21struct drm_device;
22 22
23struct shmob_drm_config {
24 enum shmob_drm_clk_source clk_source;
25 unsigned int clk_div;
26};
27
23struct shmob_drm_device {28struct shmob_drm_device {
24 struct device *dev;29 struct device *dev;
25 const struct shmob_drm_platform_data *pdata;30 const struct shmob_drm_platform_data *pdata;
31 struct shmob_drm_config config;
26 32
27 void __iomem *mmio;33 void __iomem *mmio;
28 struct clk *clock;34 struct clk *clock;