From patchwork Sat Nov 15 09:54:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kumar X-Patchwork-Id: 5311161 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0CBFB9F440 for ; Sat, 15 Nov 2014 10:01:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DA782010B for ; Sat, 15 Nov 2014 10:01:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA3E02015D for ; Sat, 15 Nov 2014 10:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752215AbaKOKBo (ORCPT ); Sat, 15 Nov 2014 05:01:44 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:30161 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbaKOKBm (ORCPT ); Sat, 15 Nov 2014 05:01:42 -0500 Received: from epcpsbgr4.samsung.com (u144.gpu120.samsung.co.kr [203.254.230.144]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NF2009DURUT3690@mailout1.samsung.com>; Sat, 15 Nov 2014 19:01:41 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.123]) by epcpsbgr4.samsung.com (EPCPMTA) with SMTP id F7.35.18167.48427645; Sat, 15 Nov 2014 19:01:40 +0900 (KST) X-AuditID: cbfee690-f79ab6d0000046f7-03-54672484efd8 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 7F.83.09430.48427645; Sat, 15 Nov 2014 19:01:40 +0900 (KST) Received: from chromebld-server.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NF200LRLRTSF980@mmp1.samsung.com>; Sat, 15 Nov 2014 19:01:40 +0900 (KST) From: Ajay Kumar To: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: inki.dae@samsung.com, kgene.kim@samsung.com, seanpaul@google.com, thierry.reding@gmail.com, daniel.vetter@ffwll.ch, ajaynumb@gmail.com, bhushan.r@samsung.com, prashanth.g@samsung.com, Ajay Kumar Subject: [PATCH V8 04/14] drm/bridge: ptn3460: Convert to i2c driver model Date: Sat, 15 Nov 2014 15:24:59 +0530 Message-id: <1416045309-13359-5-git-send-email-ajaykumar.rs@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1416045309-13359-1-git-send-email-ajaykumar.rs@samsung.com> References: <1416045309-13359-1-git-send-email-ajaykumar.rs@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeLIzCtJLcpLzFFi42JZI2JSrduikh5isP6DtcWB9wdZLDa8Wchs sWztPxaLhQ/vMlvMP3KO1eLK1/dsFpPuT2Cx6F1wlc1i0+NrrBYzzu9jslh1eAO7xdyDuRY/ d81jceD12PttAYvHzll32T0WbCr1uN99nMlj85J6j74tqxg9Pm+SC2CP4rJJSc3JLEst0rdL 4Mro3n2FseCEY8X/nfvZGhgvmXUxcnJICJhI/F3yjQnCFpO4cG89WxcjF4eQwFJGieXfvjHD FD1eeIURIrGIUWL/pOOsEM4EJonpt2ezglSxCWhLbJt+kwUkISLQxSjx/sAqdhCHWeA5o8S8 Cx0sIFXCAl4Sv7bNYwSxWQRUJQ69ewi2g1fAQ+LKoxVANgfQPgWJOZNsQMKcAp4S2z/OB2sV AipZe/Af2H0SAtfYJRpud7NAz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anFhxhNgY6a yCwlmpwPTBd5JfGGxibmpsamliYWJmaWSuK8B1utA4UE0hNLUrNTUwtSi2D6mDg4pRoYK6Mv +Ys9l0zsu8CRd/kJn8i9sqjX7yYpLtMw3sFasYe/pETY+LhHff6TXt0q9zex+hsmL1ZeYPpV aaJbRpxI0neGlT+8Nk6fvihdh3X11n/Pa987amSciRTY3r/j5P0z/v1WTy+5/ij/umva04N8 K058kQ9Y8Kcp5eqdrQyn/ORnWV3a7Tt9oxJLcUaioRZzUXEiAJp2DxffAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@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 Use drm_bridge helpers to modify the driver to support i2c driver model. Signed-off-by: Ajay Kumar --- drivers/gpu/drm/bridge/Kconfig | 2 + drivers/gpu/drm/bridge/ptn3460.c | 124 +++++++++++++++++++++---------- drivers/gpu/drm/exynos/exynos_dp_core.c | 22 ------ 3 files changed, 86 insertions(+), 62 deletions(-) diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index 884923f..4254c2b 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -1,5 +1,7 @@ config DRM_PTN3460 tristate "PTN3460 DP/LVDS bridge" depends on DRM + depends on OF && I2C select DRM_KMS_HELPER ---help--- + ptn3460 eDP-LVDS bridge chip driver. diff --git a/drivers/gpu/drm/bridge/ptn3460.c b/drivers/gpu/drm/bridge/ptn3460.c index 4a818c1..7adeb60 100644 --- a/drivers/gpu/drm/bridge/ptn3460.c +++ b/drivers/gpu/drm/bridge/ptn3460.c @@ -36,7 +36,6 @@ struct ptn3460_bridge { struct drm_connector connector; struct i2c_client *client; - struct drm_encoder *encoder; struct drm_bridge bridge; struct edid *edid; int gpio_pd_n; @@ -176,13 +175,6 @@ static void ptn3460_post_disable(struct drm_bridge *bridge) { } -static struct drm_bridge_funcs ptn3460_bridge_funcs = { - .pre_enable = ptn3460_pre_enable, - .enable = ptn3460_enable, - .disable = ptn3460_disable, - .post_disable = ptn3460_post_disable, -}; - static int ptn3460_get_modes(struct drm_connector *connector) { struct ptn3460_bridge *ptn_bridge; @@ -227,7 +219,7 @@ static struct drm_encoder *ptn3460_best_encoder(struct drm_connector *connector) { struct ptn3460_bridge *ptn_bridge = connector_to_ptn3460(connector); - return ptn_bridge->encoder; + return ptn_bridge->bridge.encoder; } static struct drm_connector_helper_funcs ptn3460_connector_helper_funcs = { @@ -253,31 +245,66 @@ static struct drm_connector_funcs ptn3460_connector_funcs = { .destroy = ptn3460_connector_destroy, }; -int ptn3460_init(struct drm_device *dev, struct drm_encoder *encoder, - struct i2c_client *client, struct device_node *node) +int ptn3460_bridge_attach(struct drm_bridge *bridge) { + struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge); int ret; + + if (!bridge->encoder) { + DRM_ERROR("Parent encoder object not found"); + return -ENODEV; + } + + ret = drm_connector_init(bridge->dev, &ptn_bridge->connector, + &ptn3460_connector_funcs, DRM_MODE_CONNECTOR_LVDS); + if (ret) { + DRM_ERROR("Failed to initialize connector with drm\n"); + return ret; + } + drm_connector_helper_add(&ptn_bridge->connector, + &ptn3460_connector_helper_funcs); + drm_connector_register(&ptn_bridge->connector); + drm_mode_connector_attach_encoder(&ptn_bridge->connector, + bridge->encoder); + + return ret; +} + +static struct drm_bridge_funcs ptn3460_bridge_funcs = { + .pre_enable = ptn3460_pre_enable, + .enable = ptn3460_enable, + .disable = ptn3460_disable, + .post_disable = ptn3460_post_disable, + .attach = ptn3460_bridge_attach, +}; + +static int ptn3460_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; struct ptn3460_bridge *ptn_bridge; + int ret; - ptn_bridge = devm_kzalloc(dev->dev, sizeof(*ptn_bridge), GFP_KERNEL); + ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL); if (!ptn_bridge) { return -ENOMEM; } ptn_bridge->client = client; - ptn_bridge->encoder = encoder; - ptn_bridge->gpio_pd_n = of_get_named_gpio(node, "powerdown-gpio", 0); + ptn_bridge->gpio_pd_n = of_get_named_gpio(dev->of_node, + "powerdown-gpio", 0); if (gpio_is_valid(ptn_bridge->gpio_pd_n)) { ret = gpio_request_one(ptn_bridge->gpio_pd_n, GPIOF_OUT_INIT_HIGH, "PTN3460_PD_N"); if (ret) { - dev_err(&client->dev, - "Request powerdown-gpio failed (%d)\n", ret); + dev_err(dev, "Request powerdown-gpio failed (%d)\n", + ret); return ret; } } - ptn_bridge->gpio_rst_n = of_get_named_gpio(node, "reset-gpio", 0); + ptn_bridge->gpio_rst_n = of_get_named_gpio(dev->of_node, + "reset-gpio", 0); if (gpio_is_valid(ptn_bridge->gpio_rst_n)) { /* * Request the reset pin low to avoid the bridge being @@ -286,39 +313,27 @@ int ptn3460_init(struct drm_device *dev, struct drm_encoder *encoder, ret = gpio_request_one(ptn_bridge->gpio_rst_n, GPIOF_OUT_INIT_LOW, "PTN3460_RST_N"); if (ret) { - dev_err(&client->dev, - "Request reset-gpio failed (%d)\n", ret); + dev_err(dev, "Request reset-gpio failed (%d)\n", ret); gpio_free(ptn_bridge->gpio_pd_n); return ret; } } - ret = of_property_read_u32(node, "edid-emulation", + ret = of_property_read_u32(dev->of_node, "edid-emulation", &ptn_bridge->edid_emulation); if (ret) { - dev_err(&client->dev, "Can't read EDID emulation value\n"); + dev_err(dev, "Can't read EDID emulation value\n"); goto err; } ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs; - ret = drm_bridge_attach(dev, &ptn_bridge->bridge); + ret = drm_bridge_add(&ptn_bridge->bridge); if (ret) { - DRM_ERROR("Failed to initialize bridge with drm\n"); + DRM_ERROR("Failed to add bridge\n"); goto err; } - encoder->bridge = &ptn_bridge->bridge; - - ret = drm_connector_init(dev, &ptn_bridge->connector, - &ptn3460_connector_funcs, DRM_MODE_CONNECTOR_LVDS); - if (ret) { - DRM_ERROR("Failed to initialize connector with drm\n"); - goto err; - } - drm_connector_helper_add(&ptn_bridge->connector, - &ptn3460_connector_helper_funcs); - drm_connector_register(&ptn_bridge->connector); - drm_mode_connector_attach_encoder(&ptn_bridge->connector, encoder); + i2c_set_clientdata(client, ptn_bridge); return 0; @@ -329,16 +344,45 @@ err: gpio_free(ptn_bridge->gpio_rst_n); return ret; } -EXPORT_SYMBOL(ptn3460_init); -void ptn3460_destroy(struct drm_bridge *bridge) +static int ptn3460_remove(struct i2c_client *client) { - struct ptn3460_bridge *ptn_bridge = bridge->driver_private; + struct ptn3460_bridge *ptn_bridge = i2c_get_clientdata(client); + + drm_bridge_remove(&ptn_bridge->bridge); if (gpio_is_valid(ptn_bridge->gpio_pd_n)) gpio_free(ptn_bridge->gpio_pd_n); if (gpio_is_valid(ptn_bridge->gpio_rst_n)) gpio_free(ptn_bridge->gpio_rst_n); - /* Nothing else to free, we've got devm allocated memory */ + + return 0; } -EXPORT_SYMBOL(ptn3460_destroy); + +static const struct i2c_device_id ptn3460_i2c_table[] = { + {"nxp,ptn3460", 0}, + {}, +}; +MODULE_DEVICE_TABLE(i2c, ptn3460_i2c_table); + +static const struct of_device_id ptn3460_match[] = { + { .compatible = "nxp,ptn3460" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ptn3460_match); + +static struct i2c_driver ptn3460_driver = { + .id_table = ptn3460_i2c_table, + .probe = ptn3460_probe, + .remove = ptn3460_remove, + .driver = { + .name = "nxp,ptn3460", + .owner = THIS_MODULE, + .of_match_table = ptn3460_match, + }, +}; +module_i2c_driver(ptn3460_driver); + +MODULE_AUTHOR("Sean Paul "); +MODULE_DESCRIPTION("NXP ptn3460 eDP-LVDS converter driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/gpu/drm/exynos/exynos_dp_core.c b/drivers/gpu/drm/exynos/exynos_dp_core.c index 6adb1e5..5025b70 100644 --- a/drivers/gpu/drm/exynos/exynos_dp_core.c +++ b/drivers/gpu/drm/exynos/exynos_dp_core.c @@ -988,32 +988,10 @@ static struct drm_connector_helper_funcs exynos_dp_connector_helper_funcs = { .best_encoder = exynos_dp_best_encoder, }; -static bool find_bridge(const char *compat, struct bridge_init *bridge) -{ - bridge->client = NULL; - bridge->node = of_find_compatible_node(NULL, NULL, compat); - if (!bridge->node) - return false; - - bridge->client = of_find_i2c_device_by_node(bridge->node); - if (!bridge->client) - return false; - - return true; -} - /* returns the number of bridges attached */ static int exynos_drm_attach_lcd_bridge(struct drm_device *dev, struct drm_encoder *encoder) { - struct bridge_init bridge; - int ret; - - if (find_bridge("nxp,ptn3460", &bridge)) { - ret = ptn3460_init(dev, encoder, bridge.client, bridge.node); - if (!ret) - return 1; - } return 0; }