From patchwork Tue Jan 13 17:12:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyri Sarha X-Patchwork-Id: 5625611 Return-Path: X-Original-To: patchwork-dri-devel@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 8BC909F406 for ; Wed, 14 Jan 2015 03:23:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A0A0D203A1 for ; Wed, 14 Jan 2015 03:23:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 681C6203A0 for ; Wed, 14 Jan 2015 03:23:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 632096E6F9; Tue, 13 Jan 2015 19:22:47 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 337 seconds by postgrey-1.34 at gabe; Tue, 13 Jan 2015 09:18:18 PST Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by gabe.freedesktop.org (Postfix) with ESMTP id 509B56E43D for ; Tue, 13 Jan 2015 09:18:18 -0800 (PST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id t0DHCc1Y021138; Tue, 13 Jan 2015 11:12:38 -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 t0DHCcrh026566; Tue, 13 Jan 2015 11:12:38 -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:37 -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 t0DHCUxB016658; Tue, 13 Jan 2015 11:12:35 -0600 From: Jyri Sarha To: , , , , , Subject: [PATCH RFC 2/3] drm/tilcdc: slave: Add support for "i2c-slave" DT-parameter Date: Tue, 13 Jan 2015 19:12:27 +0200 Message-ID: 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 It is more convenient to refer to the i2c slave encoder directly with phandle than to refer to the i2c bus and to create the device "manually". Signed-off-by: Jyri Sarha --- .../devicetree/bindings/drm/tilcdc/slave.txt | 4 +- drivers/gpu/drm/tilcdc/tilcdc_slave.c | 50 ++++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Documentation/devicetree/bindings/drm/tilcdc/slave.txt b/Documentation/devicetree/bindings/drm/tilcdc/slave.txt index 3d2c524..930550f 100644 --- a/Documentation/devicetree/bindings/drm/tilcdc/slave.txt +++ b/Documentation/devicetree/bindings/drm/tilcdc/slave.txt @@ -2,6 +2,8 @@ Device-Tree bindings for tilcdc DRM encoder slave output driver Required properties: - compatible: value should be "ti,tilcdc,slave". + - i2c-slave: phandle for the encoder slave device + or - i2c: the phandle for the i2c device the encoder slave is connected to Recommended properties: @@ -12,7 +14,7 @@ Example: hdmi { compatible = "ti,tilcdc,slave"; - i2c = <&i2c0>; + i2c-slave = <&tda19988>; pinctrl-names = "default"; pinctrl-0 = <&nxp_hdmi_bonelt_pins>; }; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_slave.c b/drivers/gpu/drm/tilcdc/tilcdc_slave.c index 3775fd4..a1e2f86 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_slave.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_slave.c @@ -25,6 +25,7 @@ struct slave_module { struct tilcdc_module base; struct i2c_adapter *i2c; + struct i2c_client *slave; }; #define to_slave_module(x) container_of(x, struct slave_module, base) @@ -140,7 +141,12 @@ static struct drm_encoder *slave_encoder_create(struct drm_device *dev, drm_encoder_helper_add(encoder, &slave_encoder_helper_funcs); - ret = drm_i2c_encoder_init(dev, to_encoder_slave(encoder), mod->i2c, &info); + if (mod->slave) + ret = drm_i2c_encoder_attach(dev, to_encoder_slave(encoder), + mod->slave); + else + ret = drm_i2c_encoder_init(dev, to_encoder_slave(encoder), + mod->i2c, &info); if (ret) goto fail; @@ -309,12 +315,12 @@ static struct of_device_id slave_of_match[]; static int slave_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; - struct device_node *i2c_node; + struct device_node *slave_node; struct slave_module *slave_mod; struct tilcdc_module *mod; struct pinctrl *pinctrl; - uint32_t i2c_phandle; - struct i2c_adapter *slavei2c; + struct i2c_adapter *slavei2c = NULL; + struct i2c_client *slave = NULL; int ret = -EINVAL; /* bail out early if no DT data: */ @@ -323,26 +329,29 @@ static int slave_probe(struct platform_device *pdev) return -ENXIO; } - /* Bail out early if i2c not specified */ - if (of_property_read_u32(node, "i2c", &i2c_phandle)) { - dev_err(&pdev->dev, "could not get i2c bus phandle\n"); - return ret; - } - - i2c_node = of_find_node_by_phandle(i2c_phandle); - if (!i2c_node) { - dev_err(&pdev->dev, "could not get i2c bus node\n"); - return ret; + slave_node = of_parse_phandle(node, "i2c-slave", 0); + if (slave_node) { + slave = of_find_i2c_device_by_node(slave_node); + of_node_put(slave_node); + } else { + struct device_node *i2c_node = of_parse_phandle(node, "i2c", 0); + + if (!i2c_node) { + dev_err(&pdev->dev, + "phandle for i2c-slave or i2c not found\n"); + return -ENODEV; + } + slavei2c = of_find_i2c_adapter_by_node(i2c_node); + of_node_put(i2c_node); } - /* but defer the probe if it can't be initialized it might come later */ - slavei2c = of_find_i2c_adapter_by_node(i2c_node); - of_node_put(i2c_node); - - if (!slavei2c) { + /* defer the probe if either slave device or the i2c bus + was not found, they might come later */ + if (!slavei2c && !slave) { ret = -EPROBE_DEFER; tilcdc_slave_probedefer(true); - dev_err(&pdev->dev, "could not get i2c\n"); + dev_info(&pdev->dev, + "could not get i2c-slave or i2c, probe defered\n"); return ret; } @@ -358,6 +367,7 @@ static int slave_probe(struct platform_device *pdev) mod->preferred_bpp = slave_info.bpp; slave_mod->i2c = slavei2c; + slave_mod->slave = slave; tilcdc_module_init(mod, "slave", &slave_module_ops);