From patchwork Mon Mar 5 16:48:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 7098 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 2801923DC3 for ; Mon, 5 Mar 2012 16:49:26 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id D5664A1810C for ; Mon, 5 Mar 2012 16:49:25 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id l4so1999830yen.11 for ; Mon, 05 Mar 2012 08:49:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.42.132 with SMTP id o4mr6080795igl.58.1330966165454; Mon, 05 Mar 2012 08:49:25 -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.231.53.18 with SMTP id k18csp30895ibg; Mon, 5 Mar 2012 08:49:25 -0800 (PST) Received: by 10.236.190.134 with SMTP id e6mr21628315yhn.98.1330966164680; Mon, 05 Mar 2012 08:49:24 -0800 (PST) Received: from mail-gx0-f178.google.com (mail-gx0-f178.google.com [209.85.161.178]) by mx.google.com with ESMTPS id o2si16926353yhn.21.2012.03.05.08.49.24 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Mar 2012 08:49:24 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.161.178 as permitted sender) client-ip=209.85.161.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.161.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-gx0-f178.google.com with SMTP id o1so2032559ggn.37 for ; Mon, 05 Mar 2012 08:49:24 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 10.236.136.4 as permitted sender) client-ip=10.236.136.4; Received: from mr.google.com ([10.236.136.4]) by 10.236.136.4 with SMTP id v4mr27554686yhi.44.1330966164528 (num_hops = 1); Mon, 05 Mar 2012 08:49:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=jzE0sdtprhWRc8xEIulQJmp4V8E/5pOyC5wsnw1qLD0=; b=mXP07xR2OWD/AnTOIyxmZUelmtPG9GVj4zo8oyO4cj4X+rHo0MQWJdq/c90RZfTRFm aKeQxEDzCaED6umQVf3XdrK8geuM/6cF3hhzsGyPOtyVISG8hoOSNYDVf/wrjs8IOREE AB2KgDlH80sSG1vUKH9uUEwyKMWiOeslMsppQ3e/mrToXPpiEtWPP6ROUVMPFyul24Cj jUzjPm6dcnc7c0vlf7GAAPY/FjDaeDOyNvmKFdGdP/zY26wrrjgmS7SfQ0X7uJOFKaAl OY8UIAPL0gUjeMbrGlSfr+DHFGmV4VluJ4veiVlm0sW2XhP+G9TY5rCKFVJM2jzAWprZ WBjQ== Received: by 10.236.136.4 with SMTP id v4mr21752706yhi.44.1330966164470; Mon, 05 Mar 2012 08:49:24 -0800 (PST) Received: from localhost (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id q14sm25370158anj.9.2012.03.05.08.49.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Mar 2012 08:49:24 -0800 (PST) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Andy Gross , Rob Clark Subject: [PATCH 09/10] staging: drm/omap: Get DMM resources from hwmod Date: Mon, 5 Mar 2012 10:48:39 -0600 Message-Id: <1330966120-28582-10-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1330966120-28582-1-git-send-email-rob.clark@linaro.org> References: <1330966120-28582-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQmJeltWstqLoi/+GSD4YRMKCAPcSCmQvNay6K1rN6c1bS3IM+uz7a/nyUOdEVNzmMO69ixP From: Andy Gross This patch splits the DMM off into a separate sub-device, in order to utilize the platform device information that was created as part of the OMAP hwmod entry for the DMM. The driver probe function queries the iomem resource and IRQ using standard platform_get functions. The OMAP DRM driver now calls the platform_driver_register() function for the subordinate DMM driver inside its probe function. This guarantees the required order for the DMM and ensures the DMM resources are available for use by the DRM driver. Signed-off-by: Andy Gross Signed-off-by: Rob Clark --- drivers/staging/omapdrm/omap_dmm_tiler.c | 79 +++++++++++++++++++++-------- drivers/staging/omapdrm/omap_dmm_tiler.h | 11 +--- drivers/staging/omapdrm/omap_drv.c | 6 ++ drivers/staging/omapdrm/omap_gem.c | 8 +-- 4 files changed, 68 insertions(+), 36 deletions(-) diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c index e4c7bb6..1ecb6a7 100644 --- a/drivers/staging/omapdrm/omap_dmm_tiler.c +++ b/drivers/staging/omapdrm/omap_dmm_tiler.c @@ -34,6 +34,8 @@ #include "omap_dmm_tiler.h" #include "omap_dmm_priv.h" +#define DMM_DRIVER_NAME "dmm" + /* mappings for associating views to luts */ static struct tcm *containers[TILFMT_NFORMATS]; static struct dmm *omap_dmm; @@ -465,7 +467,12 @@ size_t tiler_vsize(enum tiler_fmt fmt, uint16_t w, uint16_t h) return round_up(geom[fmt].cpp * w, PAGE_SIZE) * h; } -int omap_dmm_remove(void) +bool dmm_is_initialized(void) +{ + return omap_dmm ? true : false; +} + +static int omap_dmm_remove(struct platform_device *dev) { struct tiler_block *block, *_block; int i; @@ -499,40 +506,49 @@ int omap_dmm_remove(void) if (omap_dmm->irq != -1) free_irq(omap_dmm->irq, omap_dmm); + iounmap(omap_dmm->base); kfree(omap_dmm); + omap_dmm = NULL; } return 0; } -int omap_dmm_init(struct drm_device *dev) +static int omap_dmm_probe(struct platform_device *dev) { int ret = -EFAULT, i; struct tcm_area area = {0}; u32 hwinfo, pat_geom, lut_table_size; - struct omap_drm_platform_data *pdata = dev->dev->platform_data; - - if (!pdata || !pdata->dmm_pdata) { - dev_err(dev->dev, "dmm platform data not present, skipping\n"); - return ret; - } + struct resource *mem; omap_dmm = kzalloc(sizeof(*omap_dmm), GFP_KERNEL); if (!omap_dmm) { - dev_err(dev->dev, "failed to allocate driver data section\n"); + dev_err(&dev->dev, "failed to allocate driver data section\n"); goto fail; } /* lookup hwmod data - base address and irq */ - omap_dmm->base = pdata->dmm_pdata->base; - omap_dmm->irq = pdata->dmm_pdata->irq; - omap_dmm->dev = dev->dev; + mem = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!mem) { + dev_err(&dev->dev, "failed to get base address resource\n"); + goto fail; + } + + omap_dmm->base = ioremap(mem->start, SZ_2K); if (!omap_dmm->base) { - dev_err(dev->dev, "failed to get dmm base address\n"); + dev_err(&dev->dev, "failed to get dmm base address\n"); goto fail; } + omap_dmm->irq = platform_get_irq(dev, 0); + if (omap_dmm->irq < 0) { + dev_err(&dev->dev, "failed to get IRQ resource\n"); + goto fail; + } + + omap_dmm->dev = &dev->dev; + hwinfo = readl(omap_dmm->base + DMM_PAT_HWINFO); omap_dmm->num_engines = (hwinfo >> 24) & 0x1F; omap_dmm->num_lut = (hwinfo >> 16) & 0x1F; @@ -556,7 +572,7 @@ int omap_dmm_init(struct drm_device *dev) "omap_dmm_irq_handler", omap_dmm); if (ret) { - dev_err(dev->dev, "couldn't register IRQ %d, error %d\n", + dev_err(&dev->dev, "couldn't register IRQ %d, error %d\n", omap_dmm->irq, ret); omap_dmm->irq = -1; goto fail; @@ -575,25 +591,30 @@ int omap_dmm_init(struct drm_device *dev) omap_dmm->lut = vmalloc(lut_table_size * sizeof(*omap_dmm->lut)); if (!omap_dmm->lut) { - dev_err(dev->dev, "could not allocate lut table\n"); + dev_err(&dev->dev, "could not allocate lut table\n"); ret = -ENOMEM; goto fail; } omap_dmm->dummy_page = alloc_page(GFP_KERNEL | __GFP_DMA32); if (!omap_dmm->dummy_page) { - dev_err(dev->dev, "could not allocate dummy page\n"); + dev_err(&dev->dev, "could not allocate dummy page\n"); ret = -ENOMEM; goto fail; } + + /* set dma mask for device */ + /* NOTE: this is a workaround for the hwmod not initializing properly */ + dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); + omap_dmm->dummy_pa = page_to_phys(omap_dmm->dummy_page); /* alloc refill memory */ - omap_dmm->refill_va = dma_alloc_coherent(dev->dev, + omap_dmm->refill_va = dma_alloc_coherent(&dev->dev, REFILL_BUFFER_SIZE * omap_dmm->num_engines, &omap_dmm->refill_pa, GFP_KERNEL); if (!omap_dmm->refill_va) { - dev_err(dev->dev, "could not allocate refill memory\n"); + dev_err(&dev->dev, "could not allocate refill memory\n"); goto fail; } @@ -602,7 +623,7 @@ int omap_dmm_init(struct drm_device *dev) omap_dmm->num_engines * sizeof(struct refill_engine), GFP_KERNEL); if (!omap_dmm->engines) { - dev_err(dev->dev, "could not allocate engines\n"); + dev_err(&dev->dev, "could not allocate engines\n"); ret = -ENOMEM; goto fail; } @@ -624,7 +645,7 @@ int omap_dmm_init(struct drm_device *dev) omap_dmm->tcm = kzalloc(omap_dmm->num_lut * sizeof(*omap_dmm->tcm), GFP_KERNEL); if (!omap_dmm->tcm) { - dev_err(dev->dev, "failed to allocate lut ptrs\n"); + dev_err(&dev->dev, "failed to allocate lut ptrs\n"); ret = -ENOMEM; goto fail; } @@ -636,7 +657,7 @@ int omap_dmm_init(struct drm_device *dev) NULL); if (!omap_dmm->tcm[i]) { - dev_err(dev->dev, "failed to allocate container\n"); + dev_err(&dev->dev, "failed to allocate container\n"); ret = -ENOMEM; goto fail; } @@ -676,7 +697,7 @@ int omap_dmm_init(struct drm_device *dev) return 0; fail: - omap_dmm_remove(); + omap_dmm_remove(dev); return ret; } @@ -836,3 +857,17 @@ error: return 0; } #endif + +struct platform_driver omap_dmm_driver = { + .probe = omap_dmm_probe, + .remove = omap_dmm_remove, + .driver = { + .owner = THIS_MODULE, + .name = DMM_DRIVER_NAME, + }, +}; + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Andy Gross "); +MODULE_DESCRIPTION("OMAP DMM/Tiler Driver"); +MODULE_ALIAS("platform:" DMM_DRIVER_NAME); diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.h b/drivers/staging/omapdrm/omap_dmm_tiler.h index 55ab284..7b1052a 100644 --- a/drivers/staging/omapdrm/omap_dmm_tiler.h +++ b/drivers/staging/omapdrm/omap_dmm_tiler.h @@ -73,10 +73,6 @@ struct tiler_block { #define TIL_ADDR(x, orient, a)\ ((u32) (x) | (orient) | ((a) << SHIFT_ACC_MODE)) -/* externally accessible functions */ -int omap_dmm_init(struct drm_device *dev); -int omap_dmm_remove(void); - #ifdef CONFIG_DEBUG_FS int tiler_map_show(struct seq_file *s, void *arg); #endif @@ -98,7 +94,9 @@ uint32_t tiler_stride(enum tiler_fmt fmt); size_t tiler_size(enum tiler_fmt fmt, uint16_t w, uint16_t h); size_t tiler_vsize(enum tiler_fmt fmt, uint16_t w, uint16_t h); void tiler_align(enum tiler_fmt fmt, uint16_t *w, uint16_t *h); +bool dmm_is_initialized(void); +extern struct platform_driver omap_dmm_driver; /* GEM bo flags -> tiler fmt */ static inline enum tiler_fmt gem2fmt(uint32_t flags) @@ -128,11 +126,6 @@ static inline bool validfmt(enum tiler_fmt fmt) } } -struct omap_dmm_platform_data { - void __iomem *base; - int irq; -}; - static inline int dmm_is_available(void) { return cpu_is_omap44xx(); diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c index e2100bb..3df5b4c 100644 --- a/drivers/staging/omapdrm/omap_drv.c +++ b/drivers/staging/omapdrm/omap_drv.c @@ -21,6 +21,7 @@ #include "drm_crtc_helper.h" #include "drm_fb_helper.h" +#include "omap_dmm_tiler.h" #define DRIVER_NAME MODULE_NAME #define DRIVER_DESC "OMAP DRM" @@ -802,6 +803,9 @@ static void pdev_shutdown(struct platform_device *device) static int pdev_probe(struct platform_device *device) { DBG("%s", device->name); + if (platform_driver_register(&omap_dmm_driver)) + dev_err(&device->dev, "DMM registration failed\n"); + return drm_platform_init(&omap_drm_driver, device); } @@ -809,6 +813,8 @@ static int pdev_remove(struct platform_device *device) { DBG(""); drm_platform_exit(&omap_drm_driver, device); + + platform_driver_unregister(&omap_dmm_driver); return 0; } diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index 1d734bc..5abd294 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -1238,12 +1238,11 @@ void omap_gem_init(struct drm_device *dev) const enum tiler_fmt fmts[] = { TILFMT_8BIT, TILFMT_16BIT, TILFMT_32BIT }; - int i, j, ret; + int i, j; - ret = omap_dmm_init(dev); - if (ret) { + if (!dmm_is_initialized()) { /* DMM only supported on OMAP4 and later, so this isn't fatal */ - dev_warn(dev->dev, "omap_dmm_init failed, disabling DMM\n"); + dev_warn(dev->dev, "DMM not available, disable DMM support\n"); return; } @@ -1293,6 +1292,5 @@ void omap_gem_deinit(struct drm_device *dev) /* I believe we can rely on there being no more outstanding GEM * objects which could depend on usergart/dmm at this point. */ - omap_dmm_remove(); kfree(usergart); }