Skip to content

Commit 7933aec

Browse files
Abhinav Kumarlumag
authored andcommitted
drm: introduce drm_writeback_connector_init_with_encoder() API
For vendors drivers which pass an already allocated and initialized encoder especially for cases where the encoder hardware is shared OR the writeback encoder shares the resources with the rest of the display pipeline introduce a new API, drm_writeback_connector_init_with_encoder() which expects an initialized encoder as a parameter and only sets up the writeback connector. changes in v5: - fix the encoder doc to indicate that its not valid for users of drm_writeback_connector_init_with_encoder() Reviewed-by: Liviu Dudau <[email protected]> Signed-off-by: Abhinav Kumar <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/483500/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 57b8280 commit 7933aec

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

drivers/gpu/drm/drm_writeback.c

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,62 @@ int drm_writeback_connector_init(struct drm_device *dev,
177177
const struct drm_encoder_helper_funcs *enc_helper_funcs,
178178
const u32 *formats, int n_formats,
179179
u32 possible_crtcs)
180+
{
181+
int ret = 0;
182+
183+
drm_encoder_helper_add(&wb_connector->encoder, enc_helper_funcs);
184+
185+
wb_connector->encoder.possible_crtcs = possible_crtcs;
186+
187+
ret = drm_encoder_init(dev, &wb_connector->encoder,
188+
&drm_writeback_encoder_funcs,
189+
DRM_MODE_ENCODER_VIRTUAL, NULL);
190+
if (ret)
191+
return ret;
192+
193+
ret = drm_writeback_connector_init_with_encoder(dev, wb_connector, &wb_connector->encoder,
194+
con_funcs, formats, n_formats);
195+
196+
if (ret)
197+
drm_encoder_cleanup(&wb_connector->encoder);
198+
199+
return ret;
200+
}
201+
EXPORT_SYMBOL(drm_writeback_connector_init);
202+
203+
/**
204+
* drm_writeback_connector_init_with_encoder - Initialize a writeback connector with
205+
* a custom encoder
206+
*
207+
* @dev: DRM device
208+
* @wb_connector: Writeback connector to initialize
209+
* @enc: handle to the already initialized drm encoder
210+
* @con_funcs: Connector funcs vtable
211+
* @formats: Array of supported pixel formats for the writeback engine
212+
* @n_formats: Length of the formats array
213+
*
214+
* This function creates the writeback-connector-specific properties if they
215+
* have not been already created, initializes the connector as
216+
* type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property
217+
* values.
218+
*
219+
* This function assumes that the drm_writeback_connector's encoder has already been
220+
* created and initialized before invoking this function.
221+
*
222+
* In addition, this function also assumes that callers of this API will manage
223+
* assigning the encoder helper functions, possible_crtcs and any other encoder
224+
* specific operation.
225+
*
226+
* Drivers should always use this function instead of drm_connector_init() to
227+
* set up writeback connectors if they want to manage themselves the lifetime of the
228+
* associated encoder.
229+
*
230+
* Returns: 0 on success, or a negative error code
231+
*/
232+
int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
233+
struct drm_writeback_connector *wb_connector, struct drm_encoder *enc,
234+
const struct drm_connector_funcs *con_funcs, const u32 *formats,
235+
int n_formats)
180236
{
181237
struct drm_property_blob *blob;
182238
struct drm_connector *connector = &wb_connector->base;
@@ -191,15 +247,6 @@ int drm_writeback_connector_init(struct drm_device *dev,
191247
if (IS_ERR(blob))
192248
return PTR_ERR(blob);
193249

194-
drm_encoder_helper_add(&wb_connector->encoder, enc_helper_funcs);
195-
196-
wb_connector->encoder.possible_crtcs = possible_crtcs;
197-
198-
ret = drm_encoder_init(dev, &wb_connector->encoder,
199-
&drm_writeback_encoder_funcs,
200-
DRM_MODE_ENCODER_VIRTUAL, NULL);
201-
if (ret)
202-
goto fail;
203250

204251
connector->interlace_allowed = 0;
205252

@@ -208,8 +255,7 @@ int drm_writeback_connector_init(struct drm_device *dev,
208255
if (ret)
209256
goto connector_fail;
210257

211-
ret = drm_connector_attach_encoder(connector,
212-
&wb_connector->encoder);
258+
ret = drm_connector_attach_encoder(connector, enc);
213259
if (ret)
214260
goto attach_fail;
215261

@@ -238,12 +284,10 @@ int drm_writeback_connector_init(struct drm_device *dev,
238284
attach_fail:
239285
drm_connector_cleanup(connector);
240286
connector_fail:
241-
drm_encoder_cleanup(&wb_connector->encoder);
242-
fail:
243287
drm_property_blob_put(blob);
244288
return ret;
245289
}
246-
EXPORT_SYMBOL(drm_writeback_connector_init);
290+
EXPORT_SYMBOL(drm_writeback_connector_init_with_encoder);
247291

248292
int drm_writeback_set_fb(struct drm_connector_state *conn_state,
249293
struct drm_framebuffer *fb)

include/drm/drm_writeback.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct drm_writeback_connector {
3030
* @drm_writeback_connector control the behaviour of the @encoder
3131
* by passing the @enc_funcs parameter to drm_writeback_connector_init()
3232
* function.
33+
* For users of drm_writeback_connector_init_with_encoder(), this field
34+
* is not valid as the encoder is managed within their drivers.
3335
*/
3436
struct drm_encoder encoder;
3537

@@ -153,6 +155,12 @@ int drm_writeback_connector_init(struct drm_device *dev,
153155
const u32 *formats, int n_formats,
154156
u32 possible_crtcs);
155157

158+
int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
159+
struct drm_writeback_connector *wb_connector,
160+
struct drm_encoder *enc,
161+
const struct drm_connector_funcs *con_funcs, const u32 *formats,
162+
int n_formats);
163+
156164
int drm_writeback_set_fb(struct drm_connector_state *conn_state,
157165
struct drm_framebuffer *fb);
158166

0 commit comments

Comments
 (0)