@@ -340,6 +340,80 @@ int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
340340}
341341EXPORT_SYMBOL (drm_writeback_connector_init_with_encoder );
342342
343+ /**
344+ * drm_writeback_connector_cleanup - Cleanup the writeback connector
345+ * @dev: DRM device
346+ * @wb_connector: Pointer to the writeback connector to clean up
347+ *
348+ * This will decrement the reference counter of blobs and destroy properties. It
349+ * will also clean the remaining jobs in this writeback connector. Caution: This helper will not
350+ * clean up the attached encoder and the drm_connector.
351+ */
352+ static void drm_writeback_connector_cleanup (struct drm_device * dev ,
353+ struct drm_writeback_connector * wb_connector )
354+ {
355+ unsigned long flags ;
356+ struct drm_writeback_job * pos , * n ;
357+
358+ delete_writeback_properties (dev );
359+ drm_property_blob_put (wb_connector -> pixel_formats_blob_ptr );
360+
361+ spin_lock_irqsave (& wb_connector -> job_lock , flags );
362+ list_for_each_entry_safe (pos , n , & wb_connector -> job_queue , list_entry ) {
363+ drm_writeback_cleanup_job (pos );
364+ list_del (& pos -> list_entry );
365+ }
366+ spin_unlock_irqrestore (& wb_connector -> job_lock , flags );
367+ }
368+
369+ /**
370+ * drmm_writeback_connector_init - Initialize a writeback connector with
371+ * a custom encoder
372+ *
373+ * @dev: DRM device
374+ * @wb_connector: Writeback connector to initialize
375+ * @con_funcs: Connector funcs vtable
376+ * @enc: Encoder to connect this writeback connector
377+ * @formats: Array of supported pixel formats for the writeback engine
378+ * @n_formats: Length of the formats array
379+ *
380+ * This function initialize a writeback connector and register its cleanup.
381+ *
382+ * This function creates the writeback-connector-specific properties if they
383+ * have not been already created, initializes the connector as
384+ * type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property
385+ * values.
386+ *
387+ * Returns: 0 on success, or a negative error code
388+ */
389+ int drmm_writeback_connector_init (struct drm_device * dev ,
390+ struct drm_writeback_connector * wb_connector ,
391+ const struct drm_connector_funcs * con_funcs ,
392+ struct drm_encoder * enc ,
393+ const u32 * formats , int n_formats )
394+ {
395+ struct drm_connector * connector = & wb_connector -> base ;
396+ int ret ;
397+
398+ ret = drmm_connector_init (dev , connector , con_funcs ,
399+ DRM_MODE_CONNECTOR_WRITEBACK , NULL );
400+ if (ret )
401+ return ret ;
402+
403+ ret = __drm_writeback_connector_init (dev , wb_connector , enc , formats ,
404+ n_formats );
405+ if (ret )
406+ return ret ;
407+
408+ ret = drmm_add_action_or_reset (dev , (void * )drm_writeback_connector_cleanup ,
409+ wb_connector );
410+ if (ret )
411+ return ret ;
412+
413+ return 0 ;
414+ }
415+ EXPORT_SYMBOL (drmm_writeback_connector_init );
416+
343417int drm_writeback_set_fb (struct drm_connector_state * conn_state ,
344418 struct drm_framebuffer * fb )
345419{
0 commit comments