Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <liviu.dudau@arm.com>
Signed-off-by: Abhinav Kumar <quic_abhinavk@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Patchwork: https://patchwork.freedesktop.org/patch/483500/
Link: https://lore.kernel.org/r/1650984096-9964-3-git-send-email-quic_abhinavk@quicinc.com
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

authored by

Abhinav Kumar and committed by
Dmitry Baryshkov
7933aecf 57b8280a

+66 -14
+58 -14
drivers/gpu/drm/drm_writeback.c
··· 178 178 const u32 *formats, int n_formats, 179 179 u32 possible_crtcs) 180 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) 236 + { 181 237 struct drm_property_blob *blob; 182 238 struct drm_connector *connector = &wb_connector->base; 183 239 struct drm_mode_config *config = &dev->mode_config; ··· 247 191 if (IS_ERR(blob)) 248 192 return PTR_ERR(blob); 249 193 250 - drm_encoder_helper_add(&wb_connector->encoder, enc_helper_funcs); 251 - 252 - wb_connector->encoder.possible_crtcs = possible_crtcs; 253 - 254 - ret = drm_encoder_init(dev, &wb_connector->encoder, 255 - &drm_writeback_encoder_funcs, 256 - DRM_MODE_ENCODER_VIRTUAL, NULL); 257 - if (ret) 258 - goto fail; 259 194 260 195 connector->interlace_allowed = 0; 261 196 ··· 255 208 if (ret) 256 209 goto connector_fail; 257 210 258 - ret = drm_connector_attach_encoder(connector, 259 - &wb_connector->encoder); 211 + ret = drm_connector_attach_encoder(connector, enc); 260 212 if (ret) 261 213 goto attach_fail; 262 214 ··· 284 238 attach_fail: 285 239 drm_connector_cleanup(connector); 286 240 connector_fail: 287 - drm_encoder_cleanup(&wb_connector->encoder); 288 - fail: 289 241 drm_property_blob_put(blob); 290 242 return ret; 291 243 } 292 - EXPORT_SYMBOL(drm_writeback_connector_init); 244 + EXPORT_SYMBOL(drm_writeback_connector_init_with_encoder); 293 245 294 246 int drm_writeback_set_fb(struct drm_connector_state *conn_state, 295 247 struct drm_framebuffer *fb)
+8
include/drm/drm_writeback.h
··· 30 30 * @drm_writeback_connector control the behaviour of the @encoder 31 31 * by passing the @enc_funcs parameter to drm_writeback_connector_init() 32 32 * 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. 33 35 */ 34 36 struct drm_encoder encoder; 35 37 ··· 154 152 const struct drm_encoder_helper_funcs *enc_helper_funcs, 155 153 const u32 *formats, int n_formats, 156 154 u32 possible_crtcs); 155 + 156 + int drm_writeback_connector_init_with_encoder(struct drm_device *dev, 157 + struct drm_writeback_connector *wb_connector, 158 + struct drm_encoder *enc, 159 + const struct drm_connector_funcs *con_funcs, const u32 *formats, 160 + int n_formats); 157 161 158 162 int drm_writeback_set_fb(struct drm_connector_state *conn_state, 159 163 struct drm_framebuffer *fb);