From patchwork Tue Apr 8 12:19:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 27960 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1B9AE20553 for ; Tue, 8 Apr 2014 12:20:46 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id md12sf2639089pbc.8 for ; Tue, 08 Apr 2014 05:20:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:in-reply-to:references:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=mTofMUExlDY2Y9JiScBV66HaaNkllBrjQMClljfjgn0=; b=mczZwthl/Gnn+6VTxhfi7/ododSBDX7cBEJR1hq1gCvGjgbylJEoUda26qzlzHDXqr Ou41gHPq5DG+Ge5AzHsrI/kUoBjhPzWkQuowfEeaM39OiZhKB+qqQt/58In5+sprY7Th t8mbf0/cgnuxtf/n6hMvztqE/P0s2mrMV6yGFXWVXgpVxJlGTN8NtN8TExwc+kIJpi/C t1k5FwmUL1ont5snlUnvlicoUjixkf1PDbpX3H6g2d+G4Up2KWuhM4Qvq+jFdlhWpX1L wnUTKBmF6X5Jaeii3S9PMNRmXLqiNAh1XWB76lQYJW8+b/3RKregDk8j30nQpjjcJc6r eLmA== X-Gm-Message-State: ALoCoQlhINt6pU5jpIllJqXqHgPLTaBZRN0lodnHMj8WL3eGPZJJ7fJ6yvJZpNJzKLX0qft/YuKs X-Received: by 10.66.66.163 with SMTP id g3mr1596203pat.3.1396959646321; Tue, 08 Apr 2014 05:20:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.137 with SMTP id j9ls178975qgd.70.gmail; Tue, 08 Apr 2014 05:20:46 -0700 (PDT) X-Received: by 10.58.31.136 with SMTP id a8mr3145559vei.20.1396959646106; Tue, 08 Apr 2014 05:20:46 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id dh4si357112veb.103.2014.04.08.05.20.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 05:20:46 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id jy13so699054veb.30 for ; Tue, 08 Apr 2014 05:20:46 -0700 (PDT) X-Received: by 10.52.249.105 with SMTP id yt9mr58713vdc.34.1396959645992; Tue, 08 Apr 2014 05:20:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp240704vcv; Tue, 8 Apr 2014 05:20:45 -0700 (PDT) X-Received: by 10.66.164.135 with SMTP id yq7mr4201449pab.126.1396959642121; Tue, 08 Apr 2014 05:20:42 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id fd9si990444pad.224.2014.04.08.05.20.33 for ; Tue, 08 Apr 2014 05:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BCA26E9D3; Tue, 8 Apr 2014 05:20:32 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by gabe.freedesktop.org (Postfix) with ESMTP id 33C966E9D6 for ; Tue, 8 Apr 2014 05:20:29 -0700 (PDT) Received: by mail-wi0-f169.google.com with SMTP id hm4so7774014wib.2 for ; Tue, 08 Apr 2014 05:20:28 -0700 (PDT) X-Received: by 10.180.211.207 with SMTP id ne15mr31457689wic.31.1396959628357; Tue, 08 Apr 2014 05:20:28 -0700 (PDT) Received: from lmenx321.lme.st.com (LPuteaux-656-01-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPSA id v6sm2683904wif.0.2014.04.08.05.20.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 05:20:27 -0700 (PDT) From: Benjamin Gaignard To: dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH v1 03/19] drm: sti: add VTAC drivers Date: Tue, 8 Apr 2014 14:19:10 +0200 Message-Id: <1396959566-2960-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396959566-2960-1-git-send-email-benjamin.gaignard@linaro.org> References: <1396959566-2960-1-git-send-email-benjamin.gaignard@linaro.org> Cc: Fabien Dessenne , Benjamin Gaignard X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: benjamin.gaignard@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Video Trafic Advance Communication Rx and Tx drivers are designed for inter-die communication. Both Tx and Rx must share the same configuration to communicate that is why vtac_mode[] is shared in sti_vtac_utils.h. Signed-off-by: Benjamin Gaignard Signed-off-by: Vincent Abriou Signed-off-by: Fabien Dessenne --- drivers/gpu/drm/sti/Kconfig | 6 ++ drivers/gpu/drm/sti/Makefile | 1 + drivers/gpu/drm/sti/sti_vtac_rx.c | 140 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/sti/sti_vtac_tx.c | 152 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sti/sti_vtac_utils.h | 52 ++++++++++++ 5 files changed, 351 insertions(+) create mode 100644 drivers/gpu/drm/sti/sti_vtac_rx.c create mode 100644 drivers/gpu/drm/sti/sti_vtac_tx.c create mode 100644 drivers/gpu/drm/sti/sti_vtac_utils.h diff --git a/drivers/gpu/drm/sti/Kconfig b/drivers/gpu/drm/sti/Kconfig index b3c751c..e33b618 100644 --- a/drivers/gpu/drm/sti/Kconfig +++ b/drivers/gpu/drm/sti/Kconfig @@ -4,6 +4,12 @@ config DRM_STI help Choose this option to enable DRM on STM stiH41x chipset +config VTAC_STI + tristate "Video Trafic Advance Communication Rx and Tx for STMicroelectronics SoC stiH41x Series" + depends on DRM_STI + help + Choose this option to enable VTAC on STM stiH41x chipset + config VTG_STI tristate "Video Timing Generator for STMicroelectronics SoC stiH41x Series" depends on DRM_STI diff --git a/drivers/gpu/drm/sti/Makefile b/drivers/gpu/drm/sti/Makefile index 33216e1..79fdcb6 100644 --- a/drivers/gpu/drm/sti/Makefile +++ b/drivers/gpu/drm/sti/Makefile @@ -1,3 +1,4 @@ ccflags-y := -Iinclude/drm +obj-$(CONFIG_VTAC_STI) += sti_vtac_tx.o sti_vtac_rx.o obj-$(CONFIG_VTG_STI) += sti_vtg.o sti_vtg_utils.o diff --git a/drivers/gpu/drm/sti/sti_vtac_rx.c b/drivers/gpu/drm/sti/sti_vtac_rx.c new file mode 100644 index 0000000..c089489 --- /dev/null +++ b/drivers/gpu/drm/sti/sti_vtac_rx.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) STMicroelectronics SA 2013 + * Author: Benjamin Gaignard for STMicroelectronics. + * License terms: GNU General Public License (GPL), version 2 + */ +#include +#include +#include +#include +#include + +#include + +#include "sti_vtac_utils.h" + +#define VTAC_RX_CONFIG 0x00 +#define VTAC_RX_FIFO_CONFIG 0x04 + +#define VTAC_SW_RST_AUTOC 0x02 +#define VTAC_FIFO_CONFIG_VAL 0x04 + +/* + * VTAC RX structure + * + * @dev: pointer to device structure + * @regs: ioremapped regsiters + * @clk: clock + * @type: main or aux device + */ +struct sti_vtac_rx { + struct device *dev; + void __iomem *regs; + struct clk *clk; + int type; +}; + +static void sti_vtac_rx_reg_dump(struct sti_vtac_rx *vtac_rx) +{ + dev_dbg(vtac_rx->dev, "vtac_rx->regs %p\n", vtac_rx->regs); + dev_dbg(vtac_rx->dev, "VTAC_RX_CONFIG 0x%x\n", + readl(vtac_rx->regs + VTAC_RX_CONFIG)); + dev_dbg(vtac_rx->dev, "VTAC_RX_FIFO_CONFIG 0x%x\n", + readl(vtac_rx->regs + VTAC_RX_FIFO_CONFIG)); +} + +static void sti_vtac_rx_set_config(struct sti_vtac_rx *vtac_rx) +{ + int i; + u32 rx_config = EVEN_PARITY | ODD_PARITY | SW_RST_AUTOC | ENABLE; + + /* Enable VTAC clock */ + if (clk_prepare_enable(vtac_rx->clk)) + DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n"); + + for (i = 0; i < ARRAY_SIZE(vtac_modes); i++) { + if (vtac_modes[i].type == vtac_rx->type) { + writel(VTAC_FIFO_CONFIG_VAL, + vtac_rx->regs + VTAC_RX_FIFO_CONFIG); + rx_config |= vtac_modes[i].vid_in_width << 4; + rx_config |= vtac_modes[i].phyts_width << 16; + rx_config |= vtac_modes[i].phyts_per_pixel << 23; + rx_config |= VTAC_SW_RST_AUTOC; + writel(rx_config, vtac_rx->regs + VTAC_RX_CONFIG); + } + } +} + +static int sti_vtac_rx_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct sti_vtac_rx *vtac_rx; + struct resource *res; + + vtac_rx = devm_kzalloc(dev, sizeof(*vtac_rx), GFP_KERNEL); + if (!vtac_rx) { + DRM_ERROR("Failed to allocate VTAC RX context\n"); + return -ENOMEM; + } + vtac_rx->dev = dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + DRM_ERROR("Invalid resource\n"); + return -ENOMEM; + } + vtac_rx->regs = devm_ioremap_resource(dev, res); + if (IS_ERR(vtac_rx->regs)) + return PTR_ERR(vtac_rx->regs); + + vtac_rx->type = VTAC_MAIN; + if (np) + if (of_property_read_bool(np, "vtac-rx-aux")) + vtac_rx->type = VTAC_AUX; + + if (vtac_rx->type == VTAC_MAIN) { + vtac_rx->clk = devm_clk_get(dev, "vtac_main_phy"); + if (IS_ERR(vtac_rx->clk)) { + DRM_ERROR("Cannot get vtac_main_phy clock\n"); + return PTR_ERR(vtac_rx->clk); + } + } else { + vtac_rx->clk = devm_clk_get(dev, "vtac_aux_phy"); + if (IS_ERR(vtac_rx->clk)) { + DRM_ERROR("Cannot get vtac_aux_phy clock\n"); + return PTR_ERR(vtac_rx->clk); + } + } + + sti_vtac_rx_set_config(vtac_rx); + sti_vtac_rx_reg_dump(vtac_rx); + + platform_set_drvdata(pdev, vtac_rx); + DRM_INFO("%s VTAC RX %s\n", __func__, + vtac_rx->type == VTAC_MAIN ? "main" : "aux"); + return 0; +} + +static struct of_device_id vtac_rx_match_types[] = { + { + .compatible = "st,stih416-vtac-rx", + }, { + /* end node */ + } +}; + +MODULE_DEVICE_TABLE(of, vtac_rx_match_types); + +struct platform_driver sti_vtac_rx_driver = { + .driver = { + .name = "sti-vtac-rx", + .owner = THIS_MODULE, + .of_match_table = vtac_rx_match_types, + }, + .probe = sti_vtac_rx_probe, +}; + +MODULE_AUTHOR("Benjamin Gaignard "); +MODULE_DESCRIPTION("STMicroelectronics SoC VTAC_RX driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/sti/sti_vtac_tx.c b/drivers/gpu/drm/sti/sti_vtac_tx.c new file mode 100644 index 0000000..807d2e9 --- /dev/null +++ b/drivers/gpu/drm/sti/sti_vtac_tx.c @@ -0,0 +1,152 @@ +/* + * Copyright (C) STMicroelectronics SA 2013 + * Author: Benjamin Gaignard for STMicroelectronics. + * License terms: GNU General Public License (GPL), version 2 + */ +#include +#include +#include +#include +#include +#include + +#include "sti_vtac_utils.h" + +#define VTAC_TX_CONFIG 0x00 + +#define VTAC_SW_RST_AUTOC 0x02 + +#define VTAC_TX_PHY_ENABLE_CLK_PHY (0x01 << 0) +#define VTAC_TX_PHY_PROG_N3 (0x04 << 7) +#define VTAC_TX_PHY_ENABLE_CLK_DLL (0x01 << 1) +#define VTAC_TX_PHY_RST_N_DLL_SWITCH (0x01 << 4) +#define VTAC_TX_PHY_PLL_NOT_OSC_MODE (0x01 << 3) + +/* + * VTAC TX structure + * + * @dev: pointer to device structure + * @regs: ioremapped regsiters + * @clk: clock + * @type: main or aux device + */ +struct sti_vtac_tx { + struct device *dev; + void __iomem *tx_regs; + void __iomem *phy_regs; + struct clk *clk; + int type; +}; + +static void sti_vtac_tx_set_config(struct sti_vtac_tx *vtac_tx) +{ + int i; + u32 phy_config; + u32 tx_config = EVEN_PARITY | ODD_PARITY | SW_RST_AUTOC | ENABLE; + + /* Enable VTAC clock */ + if (clk_prepare_enable(vtac_tx->clk)) + DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n"); + + /* Configure vtac phy */ + phy_config = 0x00000000; + writel(phy_config, vtac_tx->phy_regs + 0x828); /* SYS_CFG8522 */ + phy_config = VTAC_TX_PHY_ENABLE_CLK_PHY; + writel(phy_config, vtac_tx->phy_regs + 0x824); /* SYS_CFG8521 */ + phy_config = readl(vtac_tx->phy_regs + 0x824); + phy_config |= VTAC_TX_PHY_PROG_N3; + writel(phy_config, vtac_tx->phy_regs + 0x824); /* SYS_CFG8521 */ + phy_config = readl(vtac_tx->phy_regs + 0x824); + phy_config |= VTAC_TX_PHY_ENABLE_CLK_DLL; + writel(phy_config, vtac_tx->phy_regs + 0x824); /* SYS_CFG8521 */ + phy_config = readl(vtac_tx->phy_regs + 0x824); + phy_config |= VTAC_TX_PHY_RST_N_DLL_SWITCH; + writel(phy_config, vtac_tx->phy_regs + 0x824); /* SYS_CFG8521 */ + phy_config = readl(vtac_tx->phy_regs + 0x824); + phy_config |= VTAC_TX_PHY_PLL_NOT_OSC_MODE; + writel(phy_config, vtac_tx->phy_regs + 0x824); /* SYS_CFG8521 */ + + /* Configure vtac tx */ + for (i = 0; i < ARRAY_SIZE(vtac_modes); i++) { + if (vtac_modes[i].type == vtac_tx->type) { + tx_config |= vtac_modes[i].vid_in_width << 4; + tx_config |= vtac_modes[i].phyts_width << 16; + tx_config |= vtac_modes[i].phyts_per_pixel << 23; + tx_config |= VTAC_SW_RST_AUTOC; + writel(tx_config, vtac_tx->tx_regs + VTAC_TX_CONFIG); + } + } +} + +static int sti_vtac_tx_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct sti_vtac_tx *vtac_tx; + struct resource *res; + + vtac_tx = devm_kzalloc(dev, sizeof(*vtac_tx), GFP_KERNEL); + if (!vtac_tx) { + DRM_ERROR("Failed to allocate VTAC TX context\n"); + return -ENOMEM; + } + vtac_tx->dev = dev; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vtac-tx"); + if (!res) { + DRM_ERROR("Invalid resource 'vtac-tx'\n"); + return -ENOMEM; + } + vtac_tx->tx_regs = devm_ioremap_resource(dev, res); + if (IS_ERR(vtac_tx->tx_regs)) + return PTR_ERR(vtac_tx->tx_regs); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vtac-phy"); + if (!res) { + DRM_ERROR("Invalid resource 'vtac-phy'\n"); + return -ENOMEM; + } + vtac_tx->phy_regs = devm_ioremap_nocache(dev, res->start, + resource_size(res)); + if (IS_ERR(vtac_tx->phy_regs)) + return PTR_ERR(vtac_tx->phy_regs); + + vtac_tx->type = VTAC_MAIN; + if (np) + if (of_property_read_bool(np, "vtac-tx-aux")) + vtac_tx->type = VTAC_AUX; + + vtac_tx->clk = devm_clk_get(dev, "vtac_tx_phy"); + if (IS_ERR(vtac_tx->clk)) { + DRM_ERROR("Cannot get vtac_tx_phy clock\n"); + return PTR_ERR(vtac_tx->clk); + } + + sti_vtac_tx_set_config(vtac_tx); + + platform_set_drvdata(pdev, vtac_tx); + DRM_INFO("%s VTAC TX %s\n", __func__, + vtac_tx->type == VTAC_MAIN ? "main" : "aux"); + return 0; +} + +static struct of_device_id vtac_tx_match_types[] = { + { + .compatible = "st,stih416-vtac-tx", + }, { + /* end node */ + } +}; + +struct platform_driver sti_vtac_tx_driver = { + .driver = { + .name = "sti-vtac-tx", + .owner = THIS_MODULE, + .of_match_table = vtac_tx_match_types, + }, + .probe = sti_vtac_tx_probe, +}; + +MODULE_AUTHOR("Benjamin Gaignard "); +MODULE_DESCRIPTION("STMicroelectronics SoC VTAC_TX driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/sti/sti_vtac_utils.h b/drivers/gpu/drm/sti/sti_vtac_utils.h new file mode 100644 index 0000000..ce549de --- /dev/null +++ b/drivers/gpu/drm/sti/sti_vtac_utils.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) STMicroelectronics SA 2013 + * Author: Benjamin Gaignard for STMicroelectronics. + * License terms: GNU General Public License (GPL), version 2 + */ + +#ifndef _STI_VTAC_UTILS_H_ +#define _STI_VTAC_UTILS_H_ + +#define VTAC_MAIN 0x8000 +#define VTAC_AUX 0x4000 + +/* Number of phyts per pixel */ +#define VTAC_2_5_PPP 0x0005 +#define VTAC_3_PPP 0x0006 +#define VTAC_4_PPP 0x0008 +#define VTAC_5_PPP 0x000A +#define VTAC_6_PPP 0x000C +#define VTAC_13_PPP 0x001A +#define VTAC_14_PPP 0x001C +#define VTAC_15_PPP 0x001E +#define VTAC_16_PPP 0x0020 +#define VTAC_17_PPP 0x0022 +#define VTAC_18_PPP 0x0024 + +/* enable bits */ +#define EVEN_PARITY (1 << 13) +#define ODD_PARITY (1 << 12) +#define SW_RST_AUTOC (1 << 1) +#define ENABLE (1 << 0) + +/* + * VTAC mode structure + * + * @type: main, aux or dvo device + * @vid_in_width: Video Data Resolution + * @phyts_width: Width of phyt buses(phyt low and phyt high). + * @phyts_per_pixel: Number of phyts sent per pixel + */ +struct sti_vtac_mode { + int type; + int vid_in_width; + int phyts_width; + int phyts_per_pixel; +}; + +static struct sti_vtac_mode vtac_modes[] = { + {VTAC_MAIN, 0x2, 0x2, VTAC_5_PPP}, /* Main RGB 12 */ + {VTAC_AUX, 0x1, 0x0, VTAC_17_PPP}, /* Aux 10 */ +}; + +#endif