Skip to content

Commit 5417750

Browse files
committed
drm: renesas: shmobile: Embed drm_device in shmob_drm_device
Embedding drm_device in shmob_drm_device allows us to use the DRM managed API to allocate both structures in one go, simplifying error handling. Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/abbf95021191824f44cc8c52e4afbde93d44363a.1694767209.git.geert+renesas@glider.be
1 parent 3d77d2a commit 5417750

File tree

5 files changed

+34
-44
lines changed

5 files changed

+34
-44
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void shmob_drm_crtc_start(struct shmob_drm_crtc *scrtc)
116116
struct shmob_drm_device *sdev = crtc->dev->dev_private;
117117
const struct shmob_drm_interface_data *idata = &sdev->pdata->iface;
118118
const struct shmob_drm_format_info *format;
119-
struct drm_device *dev = sdev->ddev;
119+
struct drm_device *dev = &sdev->ddev;
120120
struct drm_plane *plane;
121121
u32 value;
122122
int ret;
@@ -439,7 +439,7 @@ int shmob_drm_crtc_create(struct shmob_drm_device *sdev)
439439

440440
sdev->crtc.dpms = DRM_MODE_DPMS_OFF;
441441

442-
primary = __drm_universal_plane_alloc(sdev->ddev, sizeof(*primary), 0,
442+
primary = __drm_universal_plane_alloc(&sdev->ddev, sizeof(*primary), 0,
443443
0, &primary_plane_funcs,
444444
modeset_formats,
445445
ARRAY_SIZE(modeset_formats),
@@ -448,7 +448,7 @@ int shmob_drm_crtc_create(struct shmob_drm_device *sdev)
448448
if (IS_ERR(primary))
449449
return PTR_ERR(primary);
450450

451-
ret = drm_crtc_init_with_planes(sdev->ddev, crtc, primary, NULL,
451+
ret = drm_crtc_init_with_planes(&sdev->ddev, crtc, primary, NULL,
452452
&crtc_funcs, NULL);
453453
if (ret < 0) {
454454
drm_plane_cleanup(primary);
@@ -524,7 +524,7 @@ int shmob_drm_encoder_create(struct shmob_drm_device *sdev)
524524

525525
encoder->possible_crtcs = 1;
526526

527-
ret = drm_simple_encoder_init(sdev->ddev, encoder,
527+
ret = drm_simple_encoder_init(&sdev->ddev, encoder,
528528
DRM_MODE_ENCODER_DPI);
529529
if (ret < 0)
530530
return ret;
@@ -604,7 +604,7 @@ int shmob_drm_connector_create(struct shmob_drm_device *sdev,
604604
connector->display_info.width_mm = sdev->pdata->panel.width_mm;
605605
connector->display_info.height_mm = sdev->pdata->panel.height_mm;
606606

607-
ret = drm_connector_init(sdev->ddev, connector, &connector_funcs,
607+
ret = drm_connector_init(&sdev->ddev, connector, &connector_funcs,
608608
DRM_MODE_CONNECTOR_DPI);
609609
if (ret < 0)
610610
return ret;
@@ -617,7 +617,7 @@ int shmob_drm_connector_create(struct shmob_drm_device *sdev,
617617

618618
drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
619619
drm_object_property_set_value(&connector->base,
620-
sdev->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
620+
sdev->ddev.mode_config.dpms_property, DRM_MODE_DPMS_OFF);
621621

622622
return 0;
623623

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int shmob_drm_pm_suspend(struct device *dev)
137137
{
138138
struct shmob_drm_device *sdev = dev_get_drvdata(dev);
139139

140-
drm_kms_helper_poll_disable(sdev->ddev);
140+
drm_kms_helper_poll_disable(&sdev->ddev);
141141
shmob_drm_crtc_suspend(&sdev->crtc);
142142

143143
return 0;
@@ -147,11 +147,11 @@ static int shmob_drm_pm_resume(struct device *dev)
147147
{
148148
struct shmob_drm_device *sdev = dev_get_drvdata(dev);
149149

150-
drm_modeset_lock_all(sdev->ddev);
150+
drm_modeset_lock_all(&sdev->ddev);
151151
shmob_drm_crtc_resume(&sdev->crtc);
152-
drm_modeset_unlock_all(sdev->ddev);
152+
drm_modeset_unlock_all(&sdev->ddev);
153153

154-
drm_kms_helper_poll_enable(sdev->ddev);
154+
drm_kms_helper_poll_enable(&sdev->ddev);
155155
return 0;
156156
}
157157

@@ -192,11 +192,10 @@ static const struct dev_pm_ops shmob_drm_pm_ops = {
192192
static void shmob_drm_remove(struct platform_device *pdev)
193193
{
194194
struct shmob_drm_device *sdev = platform_get_drvdata(pdev);
195-
struct drm_device *ddev = sdev->ddev;
195+
struct drm_device *ddev = &sdev->ddev;
196196

197197
drm_dev_unregister(ddev);
198198
drm_kms_helper_poll_fini(ddev);
199-
drm_dev_put(ddev);
200199
}
201200

202201
static int shmob_drm_probe(struct platform_device *pdev)
@@ -213,13 +212,15 @@ static int shmob_drm_probe(struct platform_device *pdev)
213212
}
214213

215214
/*
216-
* Allocate and initialize the driver private data, I/O resources and
217-
* clocks.
215+
* Allocate and initialize the DRM device, driver private data, I/O
216+
* resources and clocks.
218217
*/
219-
sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL);
220-
if (sdev == NULL)
221-
return -ENOMEM;
218+
sdev = devm_drm_dev_alloc(&pdev->dev, &shmob_drm_driver,
219+
struct shmob_drm_device, ddev);
220+
if (IS_ERR(sdev))
221+
return PTR_ERR(sdev);
222222

223+
ddev = &sdev->ddev;
223224
sdev->dev = &pdev->dev;
224225
sdev->pdata = pdata;
225226
spin_lock_init(&sdev->irq_lock);
@@ -242,20 +243,12 @@ static int shmob_drm_probe(struct platform_device *pdev)
242243
if (ret < 0)
243244
return ret;
244245

245-
/* Allocate and initialize the DRM device. */
246-
ddev = drm_dev_alloc(&shmob_drm_driver, &pdev->dev);
247-
if (IS_ERR(ddev))
248-
return PTR_ERR(ddev);
249-
250-
sdev->ddev = ddev;
251246
ddev->dev_private = sdev;
252247

253248
ret = shmob_drm_modeset_init(sdev);
254-
if (ret < 0) {
255-
dev_err_probe(&pdev->dev, ret,
256-
"failed to initialize mode setting\n");
257-
goto err_free_drm_dev;
258-
}
249+
if (ret < 0)
250+
return dev_err_probe(&pdev->dev, ret,
251+
"failed to initialize mode setting\n");
259252

260253
for (i = 0; i < 4; ++i) {
261254
ret = shmob_drm_plane_create(sdev, i);
@@ -297,9 +290,6 @@ static int shmob_drm_probe(struct platform_device *pdev)
297290

298291
err_modeset_cleanup:
299292
drm_kms_helper_poll_fini(ddev);
300-
err_free_drm_dev:
301-
drm_dev_put(ddev);
302-
303293
return ret;
304294
}
305295

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct shmob_drm_device {
3232
unsigned int irq;
3333
spinlock_t irq_lock; /* Protects hardware LDINTR register */
3434

35-
struct drm_device *ddev;
35+
struct drm_device ddev;
3636

3737
struct shmob_drm_crtc crtc;
3838
struct drm_encoder encoder;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int shmob_drm_modeset_init(struct shmob_drm_device *sdev)
153153
{
154154
int ret;
155155

156-
ret = drmm_mode_config_init(sdev->ddev);
156+
ret = drmm_mode_config_init(&sdev->ddev);
157157
if (ret)
158158
return ret;
159159

@@ -169,15 +169,15 @@ int shmob_drm_modeset_init(struct shmob_drm_device *sdev)
169169
if (ret < 0)
170170
return ret;
171171

172-
drm_kms_helper_poll_init(sdev->ddev);
172+
drm_kms_helper_poll_init(&sdev->ddev);
173173

174-
sdev->ddev->mode_config.min_width = 0;
175-
sdev->ddev->mode_config.min_height = 0;
176-
sdev->ddev->mode_config.max_width = 4095;
177-
sdev->ddev->mode_config.max_height = 4095;
178-
sdev->ddev->mode_config.funcs = &shmob_drm_mode_config_funcs;
174+
sdev->ddev.mode_config.min_width = 0;
175+
sdev->ddev.mode_config.min_height = 0;
176+
sdev->ddev.mode_config.max_width = 4095;
177+
sdev->ddev.mode_config.max_height = 4095;
178+
sdev->ddev.mode_config.funcs = &shmob_drm_mode_config_funcs;
179179

180-
drm_helper_disable_unused_functions(sdev->ddev);
180+
drm_helper_disable_unused_functions(&sdev->ddev);
181181

182182
return 0;
183183
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void __shmob_drm_plane_setup(struct shmob_drm_plane *splane,
6868
splane->format->ldbbsifr;
6969

7070
#define plane_reg_dump(sdev, splane, reg) \
71-
dev_dbg(sdev->ddev->dev, "%s(%u): %s 0x%08x 0x%08x\n", __func__, \
71+
dev_dbg(sdev->ddev.dev, "%s(%u): %s 0x%08x 0x%08x\n", __func__, \
7272
splane->index, #reg, \
7373
lcdc_read(sdev, reg(splane->index)), \
7474
lcdc_read(sdev, reg(splane->index) + LCDC_SIDE_B_OFFSET))
@@ -81,7 +81,7 @@ static void __shmob_drm_plane_setup(struct shmob_drm_plane *splane,
8181
plane_reg_dump(sdev, splane, LDBnBSACR);
8282

8383
lcdc_write(sdev, LDBCR, LDBCR_UPC(splane->index));
84-
dev_dbg(sdev->ddev->dev, "%s(%u): %s 0x%08x\n", __func__, splane->index,
84+
dev_dbg(sdev->ddev.dev, "%s(%u): %s 0x%08x\n", __func__, splane->index,
8585
"LDBCR", lcdc_read(sdev, LDBCR));
8686

8787
lcdc_write(sdev, LDBnBSIFR(splane->index), format);
@@ -103,7 +103,7 @@ static void __shmob_drm_plane_setup(struct shmob_drm_plane *splane,
103103

104104
lcdc_write(sdev, LDBCR,
105105
LDBCR_UPF(splane->index) | LDBCR_UPD(splane->index));
106-
dev_dbg(sdev->ddev->dev, "%s(%u): %s 0x%08x\n", __func__, splane->index,
106+
dev_dbg(sdev->ddev.dev, "%s(%u): %s 0x%08x\n", __func__, splane->index,
107107
"LDBCR", lcdc_read(sdev, LDBCR));
108108

109109
plane_reg_dump(sdev, splane, LDBnBSIFR);
@@ -198,7 +198,7 @@ int shmob_drm_plane_create(struct shmob_drm_device *sdev, unsigned int index)
198198
{
199199
struct shmob_drm_plane *splane;
200200

201-
splane = drmm_universal_plane_alloc(sdev->ddev, struct shmob_drm_plane,
201+
splane = drmm_universal_plane_alloc(&sdev->ddev, struct shmob_drm_plane,
202202
plane, 1, &shmob_drm_plane_funcs,
203203
formats, ARRAY_SIZE(formats), NULL,
204204
DRM_PLANE_TYPE_OVERLAY, NULL);

0 commit comments

Comments
 (0)