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: 5622531 Return-Path: X-Original-To: patchwork-linux-omap@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 EC9ACC058D for ; Tue, 13 Jan 2015 17:12:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F36D02053A for ; Tue, 13 Jan 2015 17:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AAA9920551 for ; Tue, 13 Jan 2015 17:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753192AbbAMRMn (ORCPT ); Tue, 13 Jan 2015 12:12:43 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:37095 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbbAMRMm (ORCPT ); Tue, 13 Jan 2015 12:12:42 -0500 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: , , , , , CC: , , Jyri Sarha 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 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 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);