@@ -120,6 +120,57 @@ void drm_i2c_encoder_destroy(struct drm_encoder *drm_encoder)
}
EXPORT_SYMBOL(drm_i2c_encoder_destroy);
+/**
+ * drm_i2c_encoder_attach - Attach an I2C slave encoder
+ * @dev: DRM device.
+ * @encoder: Encoder to be attached to the I2C device. You aren't
+ * required to have called drm_encoder_init() before.
+ * @client: I2C encoder to be attached.
+ *
+ * Attach the I2C device specified to the specified &drm_encoder_slave.
+ * The @slave_funcs field will be initialized with the hooks provided by
+ * the slave driver.
+ *
+ * Returns 0 on success or a negative errno on failure, in particular,
+ * -ENODEV is returned when no matching driver is found.
+ */
+int drm_i2c_encoder_attach(struct drm_device *dev,
+ struct drm_encoder_slave *encoder,
+ struct i2c_client *client)
+{
+ struct drm_i2c_encoder_driver *encoder_drv;
+ struct module *module = NULL;
+ int err = 0;
+
+ if (!client->dev.driver) {
+ err = -ENODEV;
+ goto fail;
+ }
+
+ module = client->dev.driver->owner;
+ if (!try_module_get(module)) {
+ err = -ENODEV;
+ goto fail;
+ }
+
+ encoder->bus_priv = client;
+
+ encoder_drv =
+ to_drm_i2c_encoder_driver(to_i2c_driver(client->dev.driver));
+
+ err = encoder_drv->encoder_init(client, dev, encoder);
+ if (err)
+ goto fail_put;
+
+ return 0;
+
+fail_put:
+ module_put(module);
+fail:
+ return err;
+}
+EXPORT_SYMBOL(drm_i2c_encoder_attach);
+
/*
* Wrapper fxns which can be plugged in to drm_encoder_helper_funcs:
*/
@@ -106,6 +106,9 @@ int drm_i2c_encoder_init(struct drm_device *dev,
struct i2c_adapter *adap,
const struct i2c_board_info *info);
+int drm_i2c_encoder_attach(struct drm_device *dev,
+ struct drm_encoder_slave *encoder,
+ struct i2c_client *client);
/**
* struct drm_i2c_encoder_driver
Add drm_i2c_encoder_attach() for attaching an already probed i2c encoder. This is needed for instance if the encoder is probed from device tree. Signed-off-by: Jyri Sarha <jsarha@ti.com> --- drivers/gpu/drm/drm_encoder_slave.c | 51 +++++++++++++++++++++++++++++++++++ include/drm/drm_encoder_slave.h | 3 +++ 2 files changed, 54 insertions(+)