From patchwork Tue Jan 13 17:12:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyri Sarha X-Patchwork-Id: 5625581 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 970A8C058F for ; Wed, 14 Jan 2015 03:22:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA5202039C for ; Wed, 14 Jan 2015 03:22:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C6ECE20396 for ; Wed, 14 Jan 2015 03:22:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C5E456E6EB; Tue, 13 Jan 2015 19:22:46 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by gabe.freedesktop.org (Postfix) with ESMTP id 770696E61D for ; Tue, 13 Jan 2015 09:12:39 -0800 (PST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id t0DHCatP029551; Tue, 13 Jan 2015 11:12:36 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t0DHCZlS026554; Tue, 13 Jan 2015 11:12:35 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Tue, 13 Jan 2015 11:12:35 -0600 Received: from imryr.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t0DHCUxA016658; Tue, 13 Jan 2015 11:12:33 -0600 From: Jyri Sarha To: , , , , , Subject: [PATCH RFC 1/3] drm: encoder_slave: Add drm_i2c_encoder_attach() Date: Tue, 13 Jan 2015 19:12:26 +0200 Message-ID: <03c8beb19439c8c20770bba34178c8b7053a5f1d.1421167634.git.jsarha@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 13 Jan 2015 19:22:45 -0800 Cc: detheridge@ti.com, tomi.valkeinen@ti.com, Jyri Sarha X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/gpu/drm/drm_encoder_slave.c | 51 +++++++++++++++++++++++++++++++++++ include/drm/drm_encoder_slave.h | 3 +++ 2 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c index d18b88b..ed627f7 100644 --- a/drivers/gpu/drm/drm_encoder_slave.c +++ b/drivers/gpu/drm/drm_encoder_slave.c @@ -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: */ diff --git a/include/drm/drm_encoder_slave.h b/include/drm/drm_encoder_slave.h index 8b9cc36..4f7f8d5 100644 --- a/include/drm/drm_encoder_slave.h +++ b/include/drm/drm_encoder_slave.h @@ -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