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: 5622521 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 71FAF9F3A0 for ; Tue, 13 Jan 2015 17:12:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A7D502053A for ; Tue, 13 Jan 2015 17:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1185420576 for ; Tue, 13 Jan 2015 17:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753185AbbAMRMl (ORCPT ); Tue, 13 Jan 2015 12:12:41 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:55032 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbbAMRMk (ORCPT ); Tue, 13 Jan 2015 12:12:40 -0500 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: , , , , , CC: , , Jyri Sarha 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 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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