From patchwork Wed Jan 9 04:11:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13933 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9862D23E33 for ; Wed, 9 Jan 2013 04:11:53 +0000 (UTC) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by fiordland.canonical.com (Postfix) with ESMTP id 3E036A18F59 for ; Wed, 9 Jan 2013 04:11:53 +0000 (UTC) Received: by mail-vc0-f178.google.com with SMTP id l6so1176494vcl.9 for ; Tue, 08 Jan 2013 20:11:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:dkim-signature:x-received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-gm-message-state; bh=vfxLwrPm+YMKWNmXBBCos4PHwP+FUHs/8+YuFKBZj7M=; b=TMCGq2Gh5zxeuT9hlrDxh9dRF/SjUesvTAnMCbb0MZjGfyBoodaT8UxVOIPZkFkFCC JWV0wlr6RhJyP7LaIdR9lVDv114DrjKeUVcEGO+HRr0lbz6GEBj0sDifjccNnDS0fs3M Ws/hQYu8miWtAWWHdA13EdabTHOzG0MqiAZIfjwCG4x0Frb6tyFqDCgI1njAjDEmyJJ9 /kJukCcn/pxWXMTukWRu+IAF0CoQXliNeuyed6TQGmv/UeMV5DmOWLLVCQtp+MfafHtt 83SSa1YbcwKamfU2+qf4UXFFgUjfdIh9bGncOog+TKr3c4t9O8Q2wnru5KBzCBSL4jqu jvww== X-Received: by 10.58.181.42 with SMTP id dt10mr6518147vec.34.1357704712735; Tue, 08 Jan 2013 20:11:52 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp144954veb; Tue, 8 Jan 2013 20:11:52 -0800 (PST) X-Received: by 10.66.84.10 with SMTP id u10mr186793875pay.24.1357704711753; Tue, 08 Jan 2013 20:11:51 -0800 (PST) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by mx.google.com with ESMTPS id w3si64730144pbz.288.2013.01.08.20.11.51 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 20:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.220.42 as permitted sender) client-ip=209.85.220.42; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.220.42 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-pa0-f42.google.com with SMTP id rl6so759716pac.15 for ; Tue, 08 Jan 2013 20:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=vfxLwrPm+YMKWNmXBBCos4PHwP+FUHs/8+YuFKBZj7M=; b=NU6EHFxN/yIV0Hrmjr7sGOMv0mH3jjjwOjPeHN/2C58LrppqKiPQ9twS/jrb30XOFf gIPtGAQEpq9yfr+Z0YRMBlJGLxglFEoJYOoPsNLBYr5Ov2kevA+movHtPGm4hHFcZM3L pQNPiwRWoa/pmsEY+X5oraylEKme6yMB5ZLaaUelxEbMYpMeyIc8QaDXJch88m7MrDIA Rx1fX6yat//AAfbSCdBGJSt+Z3+T04t8rSdY09/luV93tavZSf3GCpk1el8WN95sYvWT WOhcUpsv4ZJM4gc9XsqwLE7GZPMV+XlYeNJXEZAQggMO2tiWP1y/aDAjd3cI3tX9/Y8e gUYw== X-Received: by 10.66.78.168 with SMTP id c8mr186014566pax.16.1357704711380; Tue, 08 Jan 2013 20:11:51 -0800 (PST) Received: from localhost (pool-74-100-87-234.lsanca.fios.verizon.net. [74.100.87.234]) by mx.google.com with ESMTPS id n10sm31318220pav.18.2013.01.08.20.11.49 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 20:11:50 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rob Clark Subject: [PATCH 4/4] RFC: drm/lcdc: add encoder slave Date: Tue, 8 Jan 2013 22:11:25 -0600 Message-Id: <1357704685-3600-5-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.0.2 In-Reply-To: <1357704685-3600-1-git-send-email-robdclark@gmail.com> References: <1357704685-3600-1-git-send-email-robdclark@gmail.com> X-Gm-Message-State: ALoCoQmht7qlKeZN44DXTIUFxrtumHJ8SHEyBrn7Zxp3nAuVt5prPlqJLlJX613FxDFqOyhaOnMm Add output panel driver for i2c encoder slaves. Signed-off-by: Rob Clark --- drivers/gpu/drm/lcdc/Kconfig | 12 ++ drivers/gpu/drm/lcdc/Makefile | 1 + drivers/gpu/drm/lcdc/lcdc_drv.c | 5 +- drivers/gpu/drm/lcdc/lcdc_slave.c | 384 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/lcdc/lcdc_slave.h | 26 +++ 5 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/lcdc/lcdc_slave.c create mode 100644 drivers/gpu/drm/lcdc/lcdc_slave.h diff --git a/drivers/gpu/drm/lcdc/Kconfig b/drivers/gpu/drm/lcdc/Kconfig index 7806184..e88809c 100644 --- a/drivers/gpu/drm/lcdc/Kconfig +++ b/drivers/gpu/drm/lcdc/Kconfig @@ -10,3 +10,15 @@ config DRM_LCDC Choose this option if you have an TI SoC with LCDC display controller, for example AM33xx in beagle-bone, DA8xx, or OMAP-L1xx. This driver replaces the FB_DA8XX fbdev driver. + +menu "I2C encoder or helper chips" + depends on DRM && DRM_KMS_HELPER && I2C + +config DRM_I2C_NXP_TDA998X + tristate "NXP Semiconductors TDA998X HDMI encoder" + default m if DRM_LCDC + help + Support for NXP Semiconductors TDA998X HDMI encoders. + +endmenu + diff --git a/drivers/gpu/drm/lcdc/Makefile b/drivers/gpu/drm/lcdc/Makefile index 27d19ce..337e22f 100644 --- a/drivers/gpu/drm/lcdc/Makefile +++ b/drivers/gpu/drm/lcdc/Makefile @@ -4,6 +4,7 @@ lcdc-y := \ lcdc_crtc.o \ lcdc_tfp410.o \ lcdc_panel.o \ + lcdc_slave.o \ lcdc_drv.o obj-$(CONFIG_DRM_LCDC) += lcdc.o diff --git a/drivers/gpu/drm/lcdc/lcdc_drv.c b/drivers/gpu/drm/lcdc/lcdc_drv.c index ee892cb..643664f 100644 --- a/drivers/gpu/drm/lcdc/lcdc_drv.c +++ b/drivers/gpu/drm/lcdc/lcdc_drv.c @@ -21,6 +21,7 @@ #include "lcdc_regs.h" #include "lcdc_tfp410.h" #include "lcdc_panel.h" +#include "lcdc_slave.h" #include "drm_fb_helper.h" @@ -586,6 +587,7 @@ static int __init lcdc_drm_init(void) DBG("init"); lcdc_tfp410_init(); lcdc_panel_init(); + lcdc_slave_init(); return platform_driver_register(&lcdc_platform_driver); } @@ -594,10 +596,11 @@ static void __exit lcdc_drm_fini(void) DBG("fini"); lcdc_tfp410_fini(); lcdc_panel_fini(); + lcdc_slave_fini(); platform_driver_unregister(&lcdc_platform_driver); } -module_init(lcdc_drm_init); +late_initcall(lcdc_drm_init); module_exit(lcdc_drm_fini); MODULE_AUTHOR("Rob Clark + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "lcdc_drv.h" + +struct slave_module { + struct lcdc_module base; + struct i2c_adapter *i2c; +}; +#define to_slave_module(x) container_of(x, struct slave_module, base) + +// TODO maybe this should come from DT? +static const struct lcdc_panel_info slave_info = { + .min_bpp = 16, + .max_bpp = 16, + .ac_bias = 255, + .ac_bias_intrpt = 0, + .dma_burst_sz = 16, + .bpp = 16, + .fdd = 0x80, + .tft_alt_mode = 0, + .stn_565_mode = 0, + .mono_8bit_mode = 0, + .invert_line_clock = 1, + .invert_frm_clock = 1, + .sync_edge = 0, + .sync_ctrl = 1, + .raster_order = 0, +}; + + +/* + * Encoder: + */ + +struct slave_encoder { + struct drm_encoder_slave base; + struct slave_module *mod; +}; +#define to_slave_encoder(x) container_of(to_encoder_slave(x), struct slave_encoder, base) + +static inline struct drm_encoder_slave_funcs * +get_slave_funcs(struct drm_encoder *enc) +{ + return to_encoder_slave(enc)->slave_funcs; +} + +static void slave_encoder_destroy(struct drm_encoder *encoder) +{ + struct slave_encoder *slave_encoder = to_slave_encoder(encoder); + if (get_slave_funcs(encoder)) + get_slave_funcs(encoder)->destroy(encoder); + drm_encoder_cleanup(encoder); + kfree(slave_encoder); +} + +static void slave_encoder_prepare(struct drm_encoder *encoder) +{ + drm_i2c_encoder_prepare(encoder); + lcdc_crtc_set_panel_info(encoder->crtc, &slave_info); +} + +static const struct drm_encoder_funcs slave_encoder_funcs = { + .destroy = slave_encoder_destroy, +}; + +static const struct drm_encoder_helper_funcs slave_encoder_helper_funcs = { + .dpms = drm_i2c_encoder_dpms, + .mode_fixup = drm_i2c_encoder_mode_fixup, + .prepare = slave_encoder_prepare, + .commit = drm_i2c_encoder_commit, + .mode_set = drm_i2c_encoder_mode_set, + .save = drm_i2c_encoder_save, + .restore = drm_i2c_encoder_restore, +}; + +/* TODO probably should get this from DT.. */ +static const struct i2c_board_info info = { + I2C_BOARD_INFO("tda998x", 0x70) +}; + +static struct drm_encoder *slave_encoder_create(struct drm_device *dev, + struct slave_module *mod) +{ + struct slave_encoder *slave_encoder; + struct drm_encoder *encoder; + int ret; + + slave_encoder = kzalloc(sizeof(*slave_encoder), GFP_KERNEL); + if (!slave_encoder) { + dev_err(dev->dev, "allocation failed\n"); + return NULL; + } + + slave_encoder->mod = mod; + + encoder = &slave_encoder->base.base; + encoder->possible_crtcs = 1; + + ret = drm_encoder_init(dev, encoder, &slave_encoder_funcs, + DRM_MODE_ENCODER_LVDS); + if (ret) + goto fail; + + drm_encoder_helper_add(encoder, &slave_encoder_helper_funcs); + + ret = drm_i2c_encoder_init(dev, to_encoder_slave(encoder), mod->i2c, &info); + if (ret) + goto fail; + + return encoder; + +fail: + slave_encoder_destroy(encoder); + return NULL; +} + +/* + * Connector: + */ + +struct slave_connector { + struct drm_connector base; + + struct drm_encoder *encoder; /* our connected encoder */ + struct slave_module *mod; +}; +#define to_slave_connector(x) container_of(x, struct slave_connector, base) + +static void slave_connector_destroy(struct drm_connector *connector) +{ + struct slave_connector *slave_connector = to_slave_connector(connector); + drm_connector_cleanup(connector); + kfree(slave_connector); +} + +static enum drm_connector_status slave_connector_detect( + struct drm_connector *connector, + bool force) +{ + struct drm_encoder *encoder = to_slave_connector(connector)->encoder; + return get_slave_funcs(encoder)->detect(encoder, connector); +} + +static int slave_connector_get_modes(struct drm_connector *connector) +{ + struct drm_encoder *encoder = to_slave_connector(connector)->encoder; + return get_slave_funcs(encoder)->get_modes(encoder, connector); +} + +static int slave_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) +{ + struct drm_encoder *encoder = to_slave_connector(connector)->encoder; + struct lcdc_drm_private *priv = connector->dev->dev_private; + int ret; + + ret = lcdc_crtc_mode_valid(priv->crtc, mode); + if (ret != MODE_OK) + return ret; + + return get_slave_funcs(encoder)->mode_valid(encoder, mode); +} + +static struct drm_encoder *slave_connector_best_encoder( + struct drm_connector *connector) +{ + struct slave_connector *slave_connector = to_slave_connector(connector); + return slave_connector->encoder; +} + +static int slave_connector_set_property(struct drm_connector *connector, + struct drm_property *property, uint64_t value) +{ + struct drm_encoder *encoder = to_slave_connector(connector)->encoder; + return get_slave_funcs(encoder)->set_property(encoder, + connector, property, value); +} + +static const struct drm_connector_funcs slave_connector_funcs = { + .destroy = slave_connector_destroy, + .dpms = drm_helper_connector_dpms, + .detect = slave_connector_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .set_property = slave_connector_set_property, +}; + +static const struct drm_connector_helper_funcs slave_connector_helper_funcs = { + .get_modes = slave_connector_get_modes, + .mode_valid = slave_connector_mode_valid, + .best_encoder = slave_connector_best_encoder, +}; + +static struct drm_connector *slave_connector_create(struct drm_device *dev, + struct slave_module *mod, struct drm_encoder *encoder) +{ + struct slave_connector *slave_connector; + struct drm_connector *connector; + int ret; + + slave_connector = kzalloc(sizeof(*slave_connector), GFP_KERNEL); + if (!slave_connector) { + dev_err(dev->dev, "allocation failed\n"); + return NULL; + } + + slave_connector->encoder = encoder; + slave_connector->mod = mod; + + connector = &slave_connector->base; + + drm_connector_init(dev, connector, &slave_connector_funcs, + DRM_MODE_CONNECTOR_HDMIA); + drm_connector_helper_add(connector, &slave_connector_helper_funcs); + + connector->polled = DRM_CONNECTOR_POLL_CONNECT | + DRM_CONNECTOR_POLL_DISCONNECT; + + connector->interlace_allowed = 0; + connector->doublescan_allowed = 0; + + get_slave_funcs(encoder)->create_resources(encoder, connector); + + ret = drm_mode_connector_attach_encoder(connector, encoder); + if (ret) + goto fail; + + drm_sysfs_connector_add(connector); + + return connector; + +fail: + slave_connector_destroy(connector); + return NULL; +} + +/* + * Module: + */ + +static int slave_modeset_init(struct lcdc_module *mod, struct drm_device *dev) +{ + struct slave_module *slave_mod = to_slave_module(mod); + struct lcdc_drm_private *priv = dev->dev_private; + struct drm_encoder *encoder; + struct drm_connector *connector; + + encoder = slave_encoder_create(dev, slave_mod); + if (!encoder) + return -ENOMEM; + + connector = slave_connector_create(dev, slave_mod, encoder); + if (!connector) + return -ENOMEM; + + priv->encoders[priv->num_encoders++] = encoder; + priv->connectors[priv->num_connectors++] = connector; + + return 0; +} + +static void slave_destroy(struct lcdc_module *mod) +{ + struct slave_module *slave_mod = to_slave_module(mod); + + lcdc_module_cleanup(mod); + kfree(slave_mod); +} + +static const struct lcdc_module_ops slave_module_ops = { + .modeset_init = slave_modeset_init, + .destroy = slave_destroy, +}; + +/* + * Device: + */ + +static struct of_device_id slave_of_match[]; + +static int __devinit slave_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct device_node *i2c_node; + struct slave_module *slave_mod; + struct lcdc_module *mod; + struct pinctrl *pinctrl; + uint32_t i2c_phandle; + int ret = -EINVAL; + + /* bail out early if no DT data: */ + if (!of_match_device(slave_of_match, &pdev->dev)) { + dev_err(&pdev->dev, "device-tree data is missing\n"); + return -ENXIO; + } + + slave_mod = kzalloc(sizeof(*slave_mod), GFP_KERNEL); + if (!slave_mod) + return -ENOMEM; + + mod = &slave_mod->base; + + lcdc_module_init(mod, "slave", &slave_module_ops); + + pinctrl = devm_pinctrl_get_select_default(&pdev->dev); + if (IS_ERR(pinctrl)) + dev_warn(&pdev->dev, "pins are not configured\n"); + + if (of_property_read_u32(node, "i2c", &i2c_phandle)) { + dev_err(&pdev->dev, "could not get i2c bus phandle\n"); + goto fail; + } + + i2c_node = of_find_node_by_phandle(i2c_phandle); + if (!i2c_node) { + dev_err(&pdev->dev, "could not get i2c bus node\n"); + goto fail; + } + + slave_mod->i2c = of_find_i2c_adapter_by_node(i2c_node); + if (!slave_mod->i2c) { + dev_err(&pdev->dev, "could not get i2c\n"); + goto fail; + } + + of_node_put(i2c_node); + + return 0; + +fail: + slave_destroy(mod); + return ret; +} + +static int __devexit slave_remove(struct platform_device *pdev) +{ + return 0; +} + +static struct of_device_id slave_of_match[] = { + { .compatible = "lcdc,slave", }, + { }, +}; +MODULE_DEVICE_TABLE(of, slave_of_match); + +struct platform_driver slave_driver = { + .probe = slave_probe, + .remove = slave_remove, + .driver = { + .owner = THIS_MODULE, + .name = "slave", + .of_match_table = slave_of_match, + }, +}; + +int __init lcdc_slave_init(void) +{ + return platform_driver_register(&slave_driver); +} + +void __exit lcdc_slave_fini(void) +{ + platform_driver_unregister(&slave_driver); +} diff --git a/drivers/gpu/drm/lcdc/lcdc_slave.h b/drivers/gpu/drm/lcdc/lcdc_slave.h new file mode 100644 index 0000000..825aeca --- /dev/null +++ b/drivers/gpu/drm/lcdc/lcdc_slave.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 Texas Instruments + * Author: Rob Clark + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef __LCDC_SLAVE_H__ +#define __LCDC_SLAVE_H__ + +/* sub-module for i2c slave encoder output */ + +int lcdc_slave_init(void); +void lcdc_slave_fini(void); + +#endif /* __LCDC_SLAVE_H__ */