From patchwork Wed Apr 1 10:09:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 6138871 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 017849F6E1 for ; Wed, 1 Apr 2015 10:10:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C78A820259 for ; Wed, 1 Apr 2015 10:10:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8487C20123 for ; Wed, 1 Apr 2015 10:10:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 41C716E813; Wed, 1 Apr 2015 03:10:00 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from gloria.sntech.de (gloria.sntech.de [95.129.55.99]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E9E36E814 for ; Wed, 1 Apr 2015 03:09:58 -0700 (PDT) Received: from ip92344031.dynamic.kabel-deutschland.de ([146.52.64.49] helo=diego.lan) by gloria.sntech.de with esmtpsa (TLS1.1:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YdFaq-0002on-Bs; Wed, 01 Apr 2015 12:09:52 +0200 From: Heiko Stuebner To: airlied@linux.ie, mark.yao@rock-chips.com, laurent.pinchart@ideasonboard.com Subject: [PATCH RFC v2 04/12] drm/components: add generic vga encoder driver Date: Wed, 1 Apr 2015 12:09:38 +0200 Message-Id: <1427882986-19110-5-git-send-email-heiko@sntech.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1427882986-19110-1-git-send-email-heiko@sntech.de> References: <1427882986-19110-1-git-send-email-heiko@sntech.de> Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org 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: , MIME-Version: 1.0 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 This adds a driver for generic vga encoders like the Analog Devices adv7123 and similar ics. These chips do not have any special configuration options except a powersafe gpio. An exception is added for the rcar-du driver which also implements support for the adv7123 internally but is not yet converted to the component framework. Signed-off-by: Heiko Stuebner --- drivers/gpu/drm/components/Kconfig | 5 + drivers/gpu/drm/components/Makefile | 2 + drivers/gpu/drm/components/vga-encoder.c | 315 +++++++++++++++++++++++++++++++ 3 files changed, 322 insertions(+) create mode 100644 drivers/gpu/drm/components/vga-encoder.c diff --git a/drivers/gpu/drm/components/Kconfig b/drivers/gpu/drm/components/Kconfig index 9d5d462..647cea6 100644 --- a/drivers/gpu/drm/components/Kconfig +++ b/drivers/gpu/drm/components/Kconfig @@ -1,4 +1,9 @@ menu "Standalone components for use with the component framework" depends on DRM && DRM_KMS_HELPER +config DRM_COMPONENTS_VGA_ENCODER + tristate "Generic vga encoder" + help + Support for generic vga encoder chips without any special controls. + endmenu diff --git a/drivers/gpu/drm/components/Makefile b/drivers/gpu/drm/components/Makefile index be16eca..719b1c9 100644 --- a/drivers/gpu/drm/components/Makefile +++ b/drivers/gpu/drm/components/Makefile @@ -1 +1,3 @@ ccflags-y := -Iinclude/drm + +obj-$(CONFIG_DRM_COMPONENTS_VGA_ENCODER) += vga-encoder.o diff --git a/drivers/gpu/drm/components/vga-encoder.c b/drivers/gpu/drm/components/vga-encoder.c new file mode 100644 index 0000000..f559b5e --- /dev/null +++ b/drivers/gpu/drm/components/vga-encoder.c @@ -0,0 +1,315 @@ +/* + * Simple vga encoder driver + * + * Copyright (C) 2014 Heiko Stuebner + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define encoder_to_vga_encoder(x) container_of(x, struct vga_encoder, encoder) + +struct vga_encoder { + struct drm_encoder encoder; + struct device *dev; + struct regulator *vaa_reg; + struct gpio_desc *psave_gpio; + + struct mutex enable_lock; + bool enabled; +}; + +static void vga_encoder_destroy(struct drm_encoder *encoder) +{ + drm_encoder_cleanup(encoder); +} + +static const struct drm_encoder_funcs vga_encoder_funcs = { + .destroy = vga_encoder_destroy, +}; + +static void vga_encoder_dpms(struct drm_encoder *encoder, int mode) +{ + struct vga_encoder *vga = encoder_to_vga_encoder(encoder); + + mutex_lock(&vga->enable_lock); + + switch (mode) { + case DRM_MODE_DPMS_ON: + if (vga->enabled) + goto out; + + if (!IS_ERR(vga->vaa_reg)) + regulator_enable(vga->vaa_reg); + + if (vga->psave_gpio) + gpiod_set_value(vga->psave_gpio, 1); + + vga->enabled = true; + break; + case DRM_MODE_DPMS_STANDBY: + case DRM_MODE_DPMS_SUSPEND: + case DRM_MODE_DPMS_OFF: + if (!vga->enabled) + goto out; + + if (vga->psave_gpio) + gpiod_set_value(vga->psave_gpio, 0); + + if (!IS_ERR(vga->vaa_reg)) + regulator_enable(vga->vaa_reg); + + vga->enabled = false; + break; + default: + break; + } + +out: + mutex_unlock(&vga->enable_lock); +} + +static bool vga_encoder_mode_fixup(struct drm_encoder *encoder, + const struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + return true; +} + +static void vga_encoder_prepare(struct drm_encoder *encoder) +{ +} + +static void vga_encoder_mode_set(struct drm_encoder *encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ +} + +static void vga_encoder_commit(struct drm_encoder *encoder) +{ + vga_encoder_dpms(encoder, DRM_MODE_DPMS_ON); +} + +static void vga_encoder_disable(struct drm_encoder *encoder) +{ + vga_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); +} + +static const struct drm_encoder_helper_funcs vga_encoder_helper_funcs = { + .dpms = vga_encoder_dpms, + .mode_fixup = vga_encoder_mode_fixup, + .prepare = vga_encoder_prepare, + .mode_set = vga_encoder_mode_set, + .commit = vga_encoder_commit, + .disable = vga_encoder_disable, +}; + +/* + * Component helper functions + */ + +static int vga_encoder_bind(struct device *dev, struct device *master, + void *data) +{ + struct vga_encoder *vga = dev_get_drvdata(dev); + struct device_node *np = vga->encoder.of_node; + struct drm_device *drm_dev = data; + + vga->encoder.possible_crtcs = drm_of_find_possible_crtcs(drm_dev, np); + + drm_encoder_helper_add(&vga->encoder, &vga_encoder_helper_funcs); + drm_encoder_init(drm_dev, &vga->encoder, &vga_encoder_funcs, + DRM_MODE_ENCODER_DAC); + + return component_bind_all(dev, drm_dev); +} + +static void vga_encoder_unbind(struct device *dev, struct device *master, + void *data) +{ + struct vga_encoder *vga = dev_get_drvdata(dev); + struct drm_device *drm_dev = data; + + component_unbind_all(dev, drm_dev); + vga->encoder.funcs->destroy(&vga->encoder); +} + +static const struct component_ops vga_encoder_ops = { + .bind = vga_encoder_bind, + .unbind = vga_encoder_unbind, +}; + +static int compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +static int vga_encoder_master_bind(struct device *dev) +{ + return 0; +} + +static void vga_encoder_master_unbind(struct device *dev) +{ + /* do nothing */ +} + +static const struct component_master_ops vga_encoder_master_ops = { + .bind = vga_encoder_master_bind, + .unbind = vga_encoder_master_unbind, +}; + +static int vga_encoder_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device_node *port, *connector_node; + struct device *dev = &pdev->dev; + struct component_match *match = NULL; + struct vga_encoder *vga; + int ret; + + if (!np) + return -ENODEV; + + vga = devm_kzalloc(dev, sizeof(*vga), GFP_KERNEL); + if (!vga) + return -ENOMEM; + + vga->dev = dev; + dev_set_drvdata(dev, vga); + mutex_init(&vga->enable_lock); + + vga->psave_gpio = devm_gpiod_get_optional(dev, "psave", + GPIOD_OUT_LOW); + if (IS_ERR(vga->psave_gpio)) { + ret = PTR_ERR(vga->psave_gpio); + dev_err(dev, "failed to request GPIO: %d\n", ret); + return ret; + } + + vga->enabled = false; + vga->vaa_reg = devm_regulator_get_optional(dev, "vaa"); + vga->encoder.of_node = np; + + port = of_graph_get_port_by_id(dev->of_node, 1); + if (port) { + struct device_node *endpoint; + + endpoint = of_get_child_by_name(port, "endpoint"); + if (endpoint) { + connector_node = of_graph_get_remote_port_parent(endpoint); + of_node_put(endpoint); + } + + of_node_put(port); + } + + if (!of_drm_find_connector(connector_node)) + return -EPROBE_DEFER; + + component_match_add(dev, &match, compare_of, connector_node); + + ret = drm_encoder_add(&vga->encoder); + if (ret < 0) + return ret; + + ret = component_master_add_with_match(dev, &vga_encoder_master_ops, match); + if (ret < 0) + goto err_encoder_remove; + + ret = component_add(dev, &vga_encoder_ops); + if (ret < 0) + goto err_master_remove; + + return 0; + +err_master_remove: + component_master_del(&pdev->dev, &vga_encoder_master_ops); +err_encoder_remove: + drm_encoder_remove(&vga->encoder); + + return ret; +} + +static int vga_encoder_remove(struct platform_device *pdev) +{ + struct vga_encoder *vga = dev_get_drvdata(&pdev->dev); + + component_del(&pdev->dev, &vga_encoder_ops); + component_master_del(&pdev->dev, &vga_encoder_master_ops); + drm_encoder_remove(&vga->encoder); + + return 0; +} + +static const struct of_device_id vga_encoder_ids[] = { + { .compatible = "adi,adv7123", }, + {}, +}; +MODULE_DEVICE_TABLE(of, vga_encoder_ids); + +static struct platform_driver vga_encoder_driver = { + .probe = vga_encoder_probe, + .remove = vga_encoder_remove, + .driver = { + .name = "vga-encoder", + .of_match_table = vga_encoder_ids, + }, +}; + +static const struct of_device_id rcar_du_of_table[] = { + { .compatible = "renesas,du-r8a7779" }, + { .compatible = "renesas,du-r8a7790" }, + { .compatible = "renesas,du-r8a7791" }, + { } +}; + +static int __init vga_encoder_init(void) +{ + struct device_node *np; + + /* + * Play nice with rcar-du that is having its own implementation + * of the adv7123 binding implementation and is not yet + * converted to using components. + */ + np = of_find_matching_node(NULL, rcar_du_of_table); + if (np) { + of_node_put(np); + return 0; + } + + return platform_driver_register(&vga_encoder_driver); +} + +static void __exit vga_encoder_exit(void) +{ + platform_driver_unregister(&vga_encoder_driver); +} + +module_init(vga_encoder_init); +module_exit(vga_encoder_exit); + +MODULE_AUTHOR("Heiko Stuebner "); +MODULE_DESCRIPTION("Simple vga converter"); +MODULE_LICENSE("GPL");