All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] mmc: omap: Convert to devm_kzalloc
@ 2013-09-11 18:01 Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 2/6] mmc: omap: Remove duplicate host->irq assignment Jarkko Nikula
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
 drivers/mmc/host/omap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index b94f38e..03179da 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1354,7 +1354,8 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	if (res == NULL)
 		return -EBUSY;
 
-	host = kzalloc(sizeof(struct mmc_omap_host), GFP_KERNEL);
+	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
+			    GFP_KERNEL);
 	if (host == NULL) {
 		ret = -ENOMEM;
 		goto err_free_mem_region;
@@ -1473,7 +1474,6 @@ err_free_iclk:
 err_free_mmc_host:
 	iounmap(host->virt_base);
 err_ioremap:
-	kfree(host);
 err_free_mem_region:
 	release_mem_region(res->start, resource_size(res));
 	return ret;
@@ -1508,8 +1508,6 @@ static int mmc_omap_remove(struct platform_device *pdev)
 			   pdev->resource[0].end - pdev->resource[0].start + 1);
 	destroy_workqueue(host->mmc_omap_wq);
 
-	kfree(host);
-
 	return 0;
 }
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/6] mmc: omap: Remove duplicate host->irq assignment
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
@ 2013-09-11 18:01 ` Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 3/6] mmc: omap: Remove mem_res field from struct mmc_omap_host Jarkko Nikula
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

host-irq is set twice so remove needless one.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
 drivers/mmc/host/omap.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 03179da..4d9fc5c 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1384,7 +1384,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->mem_res = res;
 	host->irq = irq;
 	host->use_dma = 1;
-	host->irq = irq;
 	host->phys_base = host->mem_res->start;
 	host->virt_base = ioremap(res->start, resource_size(res));
 	if (!host->virt_base)
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/6] mmc: omap: Remove mem_res field from struct mmc_omap_host
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 2/6] mmc: omap: Remove duplicate host->irq assignment Jarkko Nikula
@ 2013-09-11 18:01 ` Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 4/6] mmc: omap: Convert to devm_ioremap_resource Jarkko Nikula
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

Field mem_res in struct mmc_omap_host is used only once in mmc_omap_probe
when setting the phys_base field so we may just se the phys_base straight
and remove needless mem_res.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
 drivers/mmc/host/omap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 4d9fc5c..088432d 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -141,7 +141,6 @@ struct mmc_omap_host {
 	u32			dma_rx_burst;
 	struct dma_chan		*dma_tx;
 	u32			dma_tx_burst;
-	struct resource		*mem_res;
 	void __iomem		*virt_base;
 	unsigned int		phys_base;
 	int			irq;
@@ -1381,10 +1380,9 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 
 	host->id = pdev->id;
-	host->mem_res = res;
 	host->irq = irq;
 	host->use_dma = 1;
-	host->phys_base = host->mem_res->start;
+	host->phys_base = res->start;
 	host->virt_base = ioremap(res->start, resource_size(res));
 	if (!host->virt_base)
 		goto err_ioremap;
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/6] mmc: omap: Convert to devm_ioremap_resource
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 2/6] mmc: omap: Remove duplicate host->irq assignment Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 3/6] mmc: omap: Remove mem_res field from struct mmc_omap_host Jarkko Nikula
@ 2013-09-11 18:01 ` Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 5/6] mmc: omap: Remove always set use_dma flag from struct mmc_omap_host Jarkko Nikula
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

Simplify probe and cleanup code by using devm_ioremap_resource. This also
makes probe code to follow more common allocate private struct followed by
other initialization style.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
 drivers/mmc/host/omap.c | 41 ++++++++++++-----------------------------
 1 file changed, 12 insertions(+), 29 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 088432d..5ff6da9 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1343,22 +1343,19 @@ static int mmc_omap_probe(struct platform_device *pdev)
 		return -ENXIO;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
+			    GFP_KERNEL);
+	if (host == NULL)
+		return -ENOMEM;
+
 	irq = platform_get_irq(pdev, 0);
-	if (res == NULL || irq < 0)
+	if (irq < 0)
 		return -ENXIO;
 
-	res = request_mem_region(res->start, resource_size(res),
-				 pdev->name);
-	if (res == NULL)
-		return -EBUSY;
-
-	host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host),
-			    GFP_KERNEL);
-	if (host == NULL) {
-		ret = -ENOMEM;
-		goto err_free_mem_region;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	host->virt_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(host->virt_base))
+		return PTR_ERR(host->virt_base);
 
 	INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);
 	INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);
@@ -1383,15 +1380,9 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->irq = irq;
 	host->use_dma = 1;
 	host->phys_base = res->start;
-	host->virt_base = ioremap(res->start, resource_size(res));
-	if (!host->virt_base)
-		goto err_ioremap;
-
 	host->iclk = clk_get(&pdev->dev, "ick");
-	if (IS_ERR(host->iclk)) {
-		ret = PTR_ERR(host->iclk);
-		goto err_free_mmc_host;
-	}
+	if (IS_ERR(host->iclk))
+		return PTR_ERR(host->iclk);
 	clk_enable(host->iclk);
 
 	host->fclk = clk_get(&pdev->dev, "fck");
@@ -1468,11 +1459,6 @@ err_free_dma:
 err_free_iclk:
 	clk_disable(host->iclk);
 	clk_put(host->iclk);
-err_free_mmc_host:
-	iounmap(host->virt_base);
-err_ioremap:
-err_free_mem_region:
-	release_mem_region(res->start, resource_size(res));
 	return ret;
 }
 
@@ -1500,9 +1486,6 @@ static int mmc_omap_remove(struct platform_device *pdev)
 	if (host->dma_rx)
 		dma_release_channel(host->dma_rx);
 
-	iounmap(host->virt_base);
-	release_mem_region(pdev->resource[0].start,
-			   pdev->resource[0].end - pdev->resource[0].start + 1);
 	destroy_workqueue(host->mmc_omap_wq);
 
 	return 0;
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/6] mmc: omap: Remove always set use_dma flag from struct mmc_omap_host
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
                   ` (2 preceding siblings ...)
  2013-09-11 18:01 ` [PATCH 4/6] mmc: omap: Convert to devm_ioremap_resource Jarkko Nikula
@ 2013-09-11 18:01 ` Jarkko Nikula
  2013-09-11 18:01 ` [PATCH 6/6] mmc: omap: Get DMA request numbers via platform resource Jarkko Nikula
  2013-10-06 17:41 ` [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

Because use_dma is set only in mmc_omap_probe and unset nowhere there is no
need to carry that flag in struct mmc_omap_host for mmc_omap_prepare_data
function.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
 drivers/mmc/host/omap.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 5ff6da9..ce455da 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -163,7 +163,6 @@ struct mmc_omap_host {
 	u32			total_bytes_left;
 
 	unsigned		features;
-	unsigned		use_dma:1;
 	unsigned		brs_received:1, dma_done:1;
 	unsigned		dma_in_use:1;
 	spinlock_t		dma_lock;
@@ -955,7 +954,7 @@ static void
 mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 {
 	struct mmc_data *data = req->data;
-	int i, use_dma, block_size;
+	int i, use_dma = 1, block_size;
 	unsigned sg_len;
 
 	host->data = data;
@@ -980,13 +979,10 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 	sg_len = (data->blocks == 1) ? 1 : data->sg_len;
 
 	/* Only do DMA for entire blocks */
-	use_dma = host->use_dma;
-	if (use_dma) {
-		for (i = 0; i < sg_len; i++) {
-			if ((data->sg[i].length % block_size) != 0) {
-				use_dma = 0;
-				break;
-			}
+	for (i = 0; i < sg_len; i++) {
+		if ((data->sg[i].length % block_size) != 0) {
+			use_dma = 0;
+			break;
 		}
 	}
 
@@ -1378,7 +1374,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 
 	host->id = pdev->id;
 	host->irq = irq;
-	host->use_dma = 1;
 	host->phys_base = res->start;
 	host->iclk = clk_get(&pdev->dev, "ick");
 	if (IS_ERR(host->iclk))
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/6] mmc: omap: Get DMA request numbers via platform resource
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
                   ` (3 preceding siblings ...)
  2013-09-11 18:01 ` [PATCH 5/6] mmc: omap: Remove always set use_dma flag from struct mmc_omap_host Jarkko Nikula
@ 2013-09-11 18:01 ` Jarkko Nikula
  2013-10-06 17:41 ` [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-09-11 18:01 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen, Jarkko Nikula

There is no need to define MMC DMA TX and RX request numbers locally for
OMAP1xxx and OMAP24xx and assign them non-portable way since they already
come via platform resources. See commits

6c432f7 ("ARM: OMAP1: Pass dma request lines in platform data to MMC driver")
b955eef ("ARM: OMAP2: Use hwmod to initialize mmc for 2420")

Note that mmc_omap_probe doesn't change failure mechanism in case if it
fails get DMA request number or DMA channel. In that case it just falls
back to PIO transfer for TX and/or RX.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
---
Aaro:
Sorry to bother you but I know you have OMAP1xxx based boards and I
apreciate if you can give a quick test :-)
I have tested this set on OMAP2420 based Nokia N810.
---
 drivers/mmc/host/omap.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index ce455da..5f9e472 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -90,17 +90,6 @@
 #define OMAP_MMC_CMDTYPE_AC	2
 #define OMAP_MMC_CMDTYPE_ADTC	3
 
-#define OMAP_DMA_MMC_TX		21
-#define OMAP_DMA_MMC_RX		22
-#define OMAP_DMA_MMC2_TX	54
-#define OMAP_DMA_MMC2_RX	55
-
-#define OMAP24XX_DMA_MMC2_TX	47
-#define OMAP24XX_DMA_MMC2_RX	48
-#define OMAP24XX_DMA_MMC1_TX	61
-#define OMAP24XX_DMA_MMC1_RX	62
-
-
 #define DRIVER_NAME "mmci-omap"
 
 /* Specifies how often in millisecs to poll for card status changes
@@ -1326,7 +1315,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	struct mmc_omap_host *host = NULL;
 	struct resource *res;
 	dma_cap_mask_t mask;
-	unsigned sig;
 	int i, ret = 0;
 	int irq;
 
@@ -1392,22 +1380,21 @@ static int mmc_omap_probe(struct platform_device *pdev)
 	host->dma_tx_burst = -1;
 	host->dma_rx_burst = -1;
 
-	if (mmc_omap2())
-		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_TX : OMAP24XX_DMA_MMC2_TX;
-	else
-		sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX;
-	host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
+	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
+	if (res)
+		host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn,
+						   &res->start);
 	if (!host->dma_tx)
-		dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n",
-			sig);
-	if (mmc_omap2())
-		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX;
-	else
-		sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX;
-	host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
+		dev_warn(host->dev,
+			 "unable to obtain TX DMA. Falling back to PIO\n");
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
+	if (res)
+		host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn,
+						   &res->start);
 	if (!host->dma_rx)
-		dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n",
-			sig);
+		dev_warn(host->dev,
+			 "unable to obtain RX DMA. Falling back to PIO\n");
 
 	ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
 	if (ret)
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/6] mmc: omap: Convert to devm_kzalloc
  2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
                   ` (4 preceding siblings ...)
  2013-09-11 18:01 ` [PATCH 6/6] mmc: omap: Get DMA request numbers via platform resource Jarkko Nikula
@ 2013-10-06 17:41 ` Jarkko Nikula
  5 siblings, 0 replies; 7+ messages in thread
From: Jarkko Nikula @ 2013-10-06 17:41 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, Aaro Koskinen

Hi

On 09/11/2013 09:01 PM, Jarkko Nikula wrote:
> Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
> ---
>  drivers/mmc/host/omap.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
I resent this set with a subject prefix "PATCH FIX+RESEND" since I found
a NULL pointer dereference case from this driver and I put a fix for it
first and rebased these 6 patches on top of it.

-- 
Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-10-06 17:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-11 18:01 [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula
2013-09-11 18:01 ` [PATCH 2/6] mmc: omap: Remove duplicate host->irq assignment Jarkko Nikula
2013-09-11 18:01 ` [PATCH 3/6] mmc: omap: Remove mem_res field from struct mmc_omap_host Jarkko Nikula
2013-09-11 18:01 ` [PATCH 4/6] mmc: omap: Convert to devm_ioremap_resource Jarkko Nikula
2013-09-11 18:01 ` [PATCH 5/6] mmc: omap: Remove always set use_dma flag from struct mmc_omap_host Jarkko Nikula
2013-09-11 18:01 ` [PATCH 6/6] mmc: omap: Get DMA request numbers via platform resource Jarkko Nikula
2013-10-06 17:41 ` [PATCH 1/6] mmc: omap: Convert to devm_kzalloc Jarkko Nikula

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.