Skip to content

Commit adceac2

Browse files
committed
drm: renesas: shmobile: Move interface handling to connector setup
Move legacy interface handling to the connector setup code. Set up bus_flags and bus_formats in display_info according to the bus format and panel information from platform data, to make it more similar with DT-based connector/bridge/panel setup. This will allow us to use the same LCD interface setup code for both legacy and DT-based systems. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/912f615eb87c847804a268200ab57c63453c65d4.1694767209.git.geert+renesas@glider.be
1 parent fa32c6b commit adceac2

File tree

3 files changed

+104
-51
lines changed

3 files changed

+104
-51
lines changed

drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <linux/clk.h>
11+
#include <linux/media-bus-format.h>
1112
#include <linux/pm_runtime.h>
1213

1314
#include <drm/drm_crtc.h>
@@ -39,20 +40,55 @@
3940
* CRTC
4041
*/
4142

43+
static const struct {
44+
u32 fmt;
45+
u32 ldmt1r;
46+
} shmob_drm_bus_fmts[] = {
47+
{ MEDIA_BUS_FMT_RGB888_3X8, LDMT1R_MIFTYP_RGB8 },
48+
{ MEDIA_BUS_FMT_RGB666_2X9_BE, LDMT1R_MIFTYP_RGB9 },
49+
{ MEDIA_BUS_FMT_RGB888_2X12_BE, LDMT1R_MIFTYP_RGB12A },
50+
{ MEDIA_BUS_FMT_RGB444_1X12, LDMT1R_MIFTYP_RGB12B },
51+
{ MEDIA_BUS_FMT_RGB565_1X16, LDMT1R_MIFTYP_RGB16 },
52+
{ MEDIA_BUS_FMT_RGB666_1X18, LDMT1R_MIFTYP_RGB18 },
53+
{ MEDIA_BUS_FMT_RGB888_1X24, LDMT1R_MIFTYP_RGB24 },
54+
{ MEDIA_BUS_FMT_UYVY8_1X16, LDMT1R_MIFTYP_YCBCR },
55+
};
56+
4257
static void shmob_drm_crtc_setup_geometry(struct shmob_drm_crtc *scrtc)
4358
{
4459
struct drm_crtc *crtc = &scrtc->crtc;
4560
struct shmob_drm_device *sdev = to_shmob_device(crtc->dev);
46-
enum display_flags dpy_flags = sdev->connector.mode->flags;
61+
const struct drm_display_info *info = &sdev->connector->display_info;
4762
const struct drm_display_mode *mode = &crtc->mode;
63+
unsigned int i;
4864
u32 value;
4965

50-
value = sdev->ldmt1r
51-
| ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : LDMT1R_VPOL)
52-
| ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : LDMT1R_HPOL)
53-
| ((dpy_flags & DISPLAY_FLAGS_PIXDATA_POSEDGE) ? LDMT1R_DWPOL : 0)
54-
| ((dpy_flags & DISPLAY_FLAGS_DE_LOW) ? LDMT1R_DIPOL : 0);
66+
if (!info->num_bus_formats || !info->bus_formats) {
67+
dev_warn(sdev->dev, "No bus format reported, using RGB888\n");
68+
value = LDMT1R_MIFTYP_RGB24;
69+
} else {
70+
for (i = 0; i < ARRAY_SIZE(shmob_drm_bus_fmts); i++) {
71+
if (shmob_drm_bus_fmts[i].fmt == info->bus_formats[0])
72+
break;
73+
}
74+
if (i < ARRAY_SIZE(shmob_drm_bus_fmts)) {
75+
value = shmob_drm_bus_fmts[i].ldmt1r;
76+
} else {
77+
dev_warn(sdev->dev,
78+
"unsupported bus format 0x%x, using RGB888\n",
79+
info->bus_formats[0]);
80+
value = LDMT1R_MIFTYP_RGB24;
81+
}
82+
}
5583

84+
if (info->bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE)
85+
value |= LDMT1R_DWPOL;
86+
if (info->bus_flags & DRM_BUS_FLAG_DE_LOW)
87+
value |= LDMT1R_DIPOL;
88+
if (mode->flags & DRM_MODE_FLAG_NVSYNC)
89+
value |= LDMT1R_VPOL;
90+
if (mode->flags & DRM_MODE_FLAG_NHSYNC)
91+
value |= LDMT1R_HPOL;
5692
lcdc_write(sdev, LDMT1R, value);
5793

5894
value = ((mode->hdisplay / 8) << 16) /* HDCN */
@@ -479,7 +515,7 @@ static bool shmob_drm_encoder_mode_fixup(struct drm_encoder *encoder,
479515
{
480516
struct drm_device *dev = encoder->dev;
481517
struct shmob_drm_device *sdev = to_shmob_device(dev);
482-
struct drm_connector *connector = &sdev->connector.connector;
518+
struct drm_connector *connector = sdev->connector;
483519
const struct drm_display_mode *panel_mode;
484520

485521
if (list_empty(&connector->modes)) {
@@ -581,6 +617,8 @@ static void shmob_drm_connector_destroy(struct drm_connector *connector)
581617
{
582618
drm_connector_unregister(connector);
583619
drm_connector_cleanup(connector);
620+
621+
kfree(connector);
584622
}
585623

586624
static const struct drm_connector_funcs connector_funcs = {
@@ -589,26 +627,74 @@ static const struct drm_connector_funcs connector_funcs = {
589627
.destroy = shmob_drm_connector_destroy,
590628
};
591629

592-
int shmob_drm_connector_create(struct shmob_drm_device *sdev,
593-
struct drm_encoder *encoder)
630+
static struct drm_connector *
631+
shmob_drm_connector_init(struct shmob_drm_device *sdev,
632+
struct drm_encoder *encoder)
594633
{
595-
struct shmob_drm_connector *scon = &sdev->connector;
596-
struct drm_connector *connector = &scon->connector;
634+
u32 bus_fmt = sdev->pdata->iface.bus_fmt;
635+
struct shmob_drm_connector *scon;
636+
struct drm_connector *connector;
637+
struct drm_display_info *info;
638+
unsigned int i;
597639
int ret;
598640

641+
for (i = 0; i < ARRAY_SIZE(shmob_drm_bus_fmts); i++) {
642+
if (shmob_drm_bus_fmts[i].fmt == bus_fmt)
643+
break;
644+
}
645+
if (i == ARRAY_SIZE(shmob_drm_bus_fmts)) {
646+
dev_err(sdev->dev, "unsupported bus format 0x%x\n", bus_fmt);
647+
return ERR_PTR(-EINVAL);
648+
}
649+
650+
scon = kzalloc(sizeof(*scon), GFP_KERNEL);
651+
if (!scon)
652+
return ERR_PTR(-ENOMEM);
653+
654+
connector = &scon->connector;
599655
scon->encoder = encoder;
600656
scon->mode = &sdev->pdata->panel.mode;
601657

602-
connector->display_info.width_mm = sdev->pdata->panel.width_mm;
603-
connector->display_info.height_mm = sdev->pdata->panel.height_mm;
658+
info = &connector->display_info;
659+
info->width_mm = sdev->pdata->panel.width_mm;
660+
info->height_mm = sdev->pdata->panel.height_mm;
661+
662+
if (scon->mode->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
663+
info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;
664+
if (scon->mode->flags & DISPLAY_FLAGS_DE_LOW)
665+
info->bus_flags |= DRM_BUS_FLAG_DE_LOW;
666+
667+
ret = drm_display_info_set_bus_formats(info, &bus_fmt, 1);
668+
if (ret < 0) {
669+
kfree(scon);
670+
return ERR_PTR(ret);
671+
}
604672

605673
ret = drm_connector_init(&sdev->ddev, connector, &connector_funcs,
606674
DRM_MODE_CONNECTOR_DPI);
607-
if (ret < 0)
608-
return ret;
675+
if (ret < 0) {
676+
kfree(scon);
677+
return ERR_PTR(ret);
678+
}
609679

610680
drm_connector_helper_add(connector, &connector_helper_funcs);
611681

682+
return connector;
683+
}
684+
685+
int shmob_drm_connector_create(struct shmob_drm_device *sdev,
686+
struct drm_encoder *encoder)
687+
{
688+
struct drm_connector *connector;
689+
int ret;
690+
691+
connector = shmob_drm_connector_init(sdev, encoder);
692+
if (IS_ERR(connector)) {
693+
dev_err(sdev->dev, "failed to created connector: %pe\n",
694+
connector);
695+
return PTR_ERR(connector);
696+
}
697+
612698
ret = drm_connector_attach_encoder(connector, encoder);
613699
if (ret < 0)
614700
goto error;
@@ -617,6 +703,8 @@ int shmob_drm_connector_create(struct shmob_drm_device *sdev,
617703
drm_object_property_set_value(&connector->base,
618704
sdev->ddev.mode_config.dpms_property, DRM_MODE_DPMS_OFF);
619705

706+
sdev->connector = connector;
707+
620708
return 0;
621709

622710
error:

drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <linux/clk.h>
1111
#include <linux/io.h>
12-
#include <linux/media-bus-format.h>
1312
#include <linux/mm.h>
1413
#include <linux/module.h>
1514
#include <linux/platform_device.h>
@@ -33,35 +32,6 @@
3332
* Hardware initialization
3433
*/
3534

36-
static int shmob_drm_init_interface(struct shmob_drm_device *sdev)
37-
{
38-
static const struct {
39-
u32 fmt;
40-
u32 ldmt1r;
41-
} bus_fmts[] = {
42-
{ MEDIA_BUS_FMT_RGB888_3X8, LDMT1R_MIFTYP_RGB8 },
43-
{ MEDIA_BUS_FMT_RGB666_2X9_BE, LDMT1R_MIFTYP_RGB9 },
44-
{ MEDIA_BUS_FMT_RGB888_2X12_BE, LDMT1R_MIFTYP_RGB12A },
45-
{ MEDIA_BUS_FMT_RGB444_1X12, LDMT1R_MIFTYP_RGB12B },
46-
{ MEDIA_BUS_FMT_RGB565_1X16, LDMT1R_MIFTYP_RGB16 },
47-
{ MEDIA_BUS_FMT_RGB666_1X18, LDMT1R_MIFTYP_RGB18 },
48-
{ MEDIA_BUS_FMT_RGB888_1X24, LDMT1R_MIFTYP_RGB24 },
49-
{ MEDIA_BUS_FMT_UYVY8_1X16, LDMT1R_MIFTYP_YCBCR },
50-
};
51-
unsigned int i;
52-
53-
for (i = 0; i < ARRAY_SIZE(bus_fmts); i++) {
54-
if (bus_fmts[i].fmt == sdev->pdata->iface.bus_fmt) {
55-
sdev->ldmt1r = bus_fmts[i].ldmt1r;
56-
return 0;
57-
}
58-
}
59-
60-
dev_err(sdev->dev, "unsupported bus format 0x%x\n",
61-
sdev->pdata->iface.bus_fmt);
62-
return -EINVAL;
63-
}
64-
6535
static int shmob_drm_setup_clocks(struct shmob_drm_device *sdev,
6636
enum shmob_drm_clk_source clksrc)
6737
{
@@ -246,10 +216,6 @@ static int shmob_drm_probe(struct platform_device *pdev)
246216
if (ret)
247217
return ret;
248218

249-
ret = shmob_drm_init_interface(sdev);
250-
if (ret < 0)
251-
return ret;
252-
253219
ret = shmob_drm_modeset_init(sdev);
254220
if (ret < 0)
255221
return dev_err_probe(&pdev->dev, ret,

drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct shmob_drm_device {
2727
void __iomem *mmio;
2828
struct clk *clock;
2929
u32 lddckr;
30-
u32 ldmt1r;
3130

3231
unsigned int irq;
3332
spinlock_t irq_lock; /* Protects hardware LDINTR register */
@@ -36,7 +35,7 @@ struct shmob_drm_device {
3635

3736
struct shmob_drm_crtc crtc;
3837
struct drm_encoder encoder;
39-
struct shmob_drm_connector connector;
38+
struct drm_connector *connector;
4039
};
4140

4241
static inline struct shmob_drm_device *to_shmob_device(struct drm_device *dev)

0 commit comments

Comments
 (0)