diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2015-02-21 15:59:54 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-02 15:37:13 -0400 |
commit | 0ff4e419dc6a409a60dc492fbbc58288af78bed7 (patch) | |
tree | 2342367556443c50abef812288443c56142ca378 | |
parent | 32346b9cc01566126034f47afd94ff8a39238d3a (diff) |
[media] media: omap3isp: hist: Move histogram DMA to DMA engine
Replace the custom OMAP DMA API usage by DMA engine. Feature-wise the
driver has lost the ability to get notified of DMA transfers failure
through the completion handler, as the DMA engine API doesn't expose
that status information.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r-- | drivers/media/platform/omap3isp/isph3a_aewb.c | 1 | ||||
-rw-r--r-- | drivers/media/platform/omap3isp/isph3a_af.c | 1 | ||||
-rw-r--r-- | drivers/media/platform/omap3isp/isphist.c | 128 | ||||
-rw-r--r-- | drivers/media/platform/omap3isp/ispstat.c | 2 | ||||
-rw-r--r-- | drivers/media/platform/omap3isp/ispstat.h | 5 |
5 files changed, 80 insertions, 57 deletions
diff --git a/drivers/media/platform/omap3isp/isph3a_aewb.c b/drivers/media/platform/omap3isp/isph3a_aewb.c index b208c5417146..ccaf92f39236 100644 --- a/drivers/media/platform/omap3isp/isph3a_aewb.c +++ b/drivers/media/platform/omap3isp/isph3a_aewb.c | |||
@@ -297,7 +297,6 @@ int omap3isp_h3a_aewb_init(struct isp_device *isp) | |||
297 | 297 | ||
298 | aewb->ops = &h3a_aewb_ops; | 298 | aewb->ops = &h3a_aewb_ops; |
299 | aewb->priv = aewb_cfg; | 299 | aewb->priv = aewb_cfg; |
300 | aewb->dma_ch = -1; | ||
301 | aewb->event_type = V4L2_EVENT_OMAP3ISP_AEWB; | 300 | aewb->event_type = V4L2_EVENT_OMAP3ISP_AEWB; |
302 | aewb->isp = isp; | 301 | aewb->isp = isp; |
303 | 302 | ||
diff --git a/drivers/media/platform/omap3isp/isph3a_af.c b/drivers/media/platform/omap3isp/isph3a_af.c index 8a83e195f3e3..92937f7eecef 100644 --- a/drivers/media/platform/omap3isp/isph3a_af.c +++ b/drivers/media/platform/omap3isp/isph3a_af.c | |||
@@ -360,7 +360,6 @@ int omap3isp_h3a_af_init(struct isp_device *isp) | |||
360 | 360 | ||
361 | af->ops = &h3a_af_ops; | 361 | af->ops = &h3a_af_ops; |
362 | af->priv = af_cfg; | 362 | af->priv = af_cfg; |
363 | af->dma_ch = -1; | ||
364 | af->event_type = V4L2_EVENT_OMAP3ISP_AF; | 363 | af->event_type = V4L2_EVENT_OMAP3ISP_AF; |
365 | af->isp = isp; | 364 | af->isp = isp; |
366 | 365 | ||
diff --git a/drivers/media/platform/omap3isp/isphist.c b/drivers/media/platform/omap3isp/isphist.c index ce822c34c843..738b946ddb37 100644 --- a/drivers/media/platform/omap3isp/isphist.c +++ b/drivers/media/platform/omap3isp/isphist.c | |||
@@ -16,20 +16,18 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/device.h> | ||
20 | #include <linux/dmaengine.h> | ||
21 | #include <linux/omap-dmaengine.h> | ||
19 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
20 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
21 | #include <linux/device.h> | ||
22 | 24 | ||
23 | #include "isp.h" | 25 | #include "isp.h" |
24 | #include "ispreg.h" | 26 | #include "ispreg.h" |
25 | #include "isphist.h" | 27 | #include "isphist.h" |
26 | 28 | ||
27 | #define OMAP24XX_DMA_NO_DEVICE 0 | ||
28 | |||
29 | #define HIST_CONFIG_DMA 1 | 29 | #define HIST_CONFIG_DMA 1 |
30 | 30 | ||
31 | #define HIST_USING_DMA(hist) ((hist)->dma_ch >= 0) | ||
32 | |||
33 | /* | 31 | /* |
34 | * hist_reset_mem - clear Histogram memory before start stats engine. | 32 | * hist_reset_mem - clear Histogram memory before start stats engine. |
35 | */ | 33 | */ |
@@ -62,20 +60,6 @@ static void hist_reset_mem(struct ispstat *hist) | |||
62 | hist->wait_acc_frames = conf->num_acc_frames; | 60 | hist->wait_acc_frames = conf->num_acc_frames; |
63 | } | 61 | } |
64 | 62 | ||
65 | static void hist_dma_config(struct ispstat *hist) | ||
66 | { | ||
67 | struct isp_device *isp = hist->isp; | ||
68 | |||
69 | hist->dma_config.data_type = OMAP_DMA_DATA_TYPE_S32; | ||
70 | hist->dma_config.sync_mode = OMAP_DMA_SYNC_ELEMENT; | ||
71 | hist->dma_config.frame_count = 1; | ||
72 | hist->dma_config.src_amode = OMAP_DMA_AMODE_CONSTANT; | ||
73 | hist->dma_config.src_start = isp->mmio_base_phys[OMAP3_ISP_IOMEM_HIST] | ||
74 | + ISPHIST_DATA; | ||
75 | hist->dma_config.dst_amode = OMAP_DMA_AMODE_POST_INC; | ||
76 | hist->dma_config.src_or_dst_synch = OMAP_DMA_SRC_SYNC; | ||
77 | } | ||
78 | |||
79 | /* | 63 | /* |
80 | * hist_setup_regs - Helper function to update Histogram registers. | 64 | * hist_setup_regs - Helper function to update Histogram registers. |
81 | */ | 65 | */ |
@@ -176,17 +160,12 @@ static int hist_busy(struct ispstat *hist) | |||
176 | & ISPHIST_PCR_BUSY; | 160 | & ISPHIST_PCR_BUSY; |
177 | } | 161 | } |
178 | 162 | ||
179 | static void hist_dma_cb(int lch, u16 ch_status, void *data) | 163 | static void hist_dma_cb(void *data) |
180 | { | 164 | { |
181 | struct ispstat *hist = data; | 165 | struct ispstat *hist = data; |
182 | 166 | ||
183 | if (ch_status & ~OMAP_DMA_BLOCK_IRQ) { | 167 | /* FIXME: The DMA engine API can't report transfer errors :-/ */ |
184 | dev_dbg(hist->isp->dev, "hist: DMA error. status = 0x%04x\n", | 168 | |
185 | ch_status); | ||
186 | omap_stop_dma(lch); | ||
187 | hist_reset_mem(hist); | ||
188 | atomic_set(&hist->buf_err, 1); | ||
189 | } | ||
190 | isp_reg_clr(hist->isp, OMAP3_ISP_IOMEM_HIST, ISPHIST_CNT, | 169 | isp_reg_clr(hist->isp, OMAP3_ISP_IOMEM_HIST, ISPHIST_CNT, |
191 | ISPHIST_CNT_CLEAR); | 170 | ISPHIST_CNT_CLEAR); |
192 | 171 | ||
@@ -198,24 +177,58 @@ static void hist_dma_cb(int lch, u16 ch_status, void *data) | |||
198 | static int hist_buf_dma(struct ispstat *hist) | 177 | static int hist_buf_dma(struct ispstat *hist) |
199 | { | 178 | { |
200 | dma_addr_t dma_addr = hist->active_buf->dma_addr; | 179 | dma_addr_t dma_addr = hist->active_buf->dma_addr; |
180 | struct dma_async_tx_descriptor *tx; | ||
181 | struct dma_slave_config cfg; | ||
182 | dma_cookie_t cookie; | ||
183 | int ret; | ||
201 | 184 | ||
202 | if (unlikely(!dma_addr)) { | 185 | if (unlikely(!dma_addr)) { |
203 | dev_dbg(hist->isp->dev, "hist: invalid DMA buffer address\n"); | 186 | dev_dbg(hist->isp->dev, "hist: invalid DMA buffer address\n"); |
204 | hist_reset_mem(hist); | 187 | goto error; |
205 | return STAT_NO_BUF; | ||
206 | } | 188 | } |
207 | 189 | ||
208 | isp_reg_writel(hist->isp, 0, OMAP3_ISP_IOMEM_HIST, ISPHIST_ADDR); | 190 | isp_reg_writel(hist->isp, 0, OMAP3_ISP_IOMEM_HIST, ISPHIST_ADDR); |
209 | isp_reg_set(hist->isp, OMAP3_ISP_IOMEM_HIST, ISPHIST_CNT, | 191 | isp_reg_set(hist->isp, OMAP3_ISP_IOMEM_HIST, ISPHIST_CNT, |
210 | ISPHIST_CNT_CLEAR); | 192 | ISPHIST_CNT_CLEAR); |
211 | omap3isp_flush(hist->isp); | 193 | omap3isp_flush(hist->isp); |
212 | hist->dma_config.dst_start = dma_addr; | ||
213 | hist->dma_config.elem_count = hist->buf_size / sizeof(u32); | ||
214 | omap_set_dma_params(hist->dma_ch, &hist->dma_config); | ||
215 | 194 | ||
216 | omap_start_dma(hist->dma_ch); | 195 | memset(&cfg, 0, sizeof(cfg)); |
196 | cfg.src_addr = hist->isp->mmio_base_phys[OMAP3_ISP_IOMEM_HIST] | ||
197 | + ISPHIST_DATA; | ||
198 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
199 | cfg.src_maxburst = hist->buf_size / 4; | ||
200 | |||
201 | ret = dmaengine_slave_config(hist->dma_ch, &cfg); | ||
202 | if (ret < 0) { | ||
203 | dev_dbg(hist->isp->dev, | ||
204 | "hist: DMA slave configuration failed\n"); | ||
205 | goto error; | ||
206 | } | ||
207 | |||
208 | tx = dmaengine_prep_slave_single(hist->dma_ch, dma_addr, | ||
209 | hist->buf_size, DMA_DEV_TO_MEM, | ||
210 | DMA_CTRL_ACK); | ||
211 | if (tx == NULL) { | ||
212 | dev_dbg(hist->isp->dev, | ||
213 | "hist: DMA slave preparation failed\n"); | ||
214 | goto error; | ||
215 | } | ||
216 | |||
217 | tx->callback = hist_dma_cb; | ||
218 | tx->callback_param = hist; | ||
219 | cookie = tx->tx_submit(tx); | ||
220 | if (dma_submit_error(cookie)) { | ||
221 | dev_dbg(hist->isp->dev, "hist: DMA submission failed\n"); | ||
222 | goto error; | ||
223 | } | ||
224 | |||
225 | dma_async_issue_pending(hist->dma_ch); | ||
217 | 226 | ||
218 | return STAT_BUF_WAITING_DMA; | 227 | return STAT_BUF_WAITING_DMA; |
228 | |||
229 | error: | ||
230 | hist_reset_mem(hist); | ||
231 | return STAT_NO_BUF; | ||
219 | } | 232 | } |
220 | 233 | ||
221 | static int hist_buf_pio(struct ispstat *hist) | 234 | static int hist_buf_pio(struct ispstat *hist) |
@@ -272,7 +285,7 @@ static int hist_buf_process(struct ispstat *hist) | |||
272 | if (--(hist->wait_acc_frames)) | 285 | if (--(hist->wait_acc_frames)) |
273 | return STAT_NO_BUF; | 286 | return STAT_NO_BUF; |
274 | 287 | ||
275 | if (HIST_USING_DMA(hist)) | 288 | if (hist->dma_ch) |
276 | ret = hist_buf_dma(hist); | 289 | ret = hist_buf_dma(hist); |
277 | else | 290 | else |
278 | ret = hist_buf_pio(hist); | 291 | ret = hist_buf_pio(hist); |
@@ -473,18 +486,28 @@ int omap3isp_hist_init(struct isp_device *isp) | |||
473 | 486 | ||
474 | hist->isp = isp; | 487 | hist->isp = isp; |
475 | 488 | ||
476 | if (HIST_CONFIG_DMA) | 489 | if (HIST_CONFIG_DMA) { |
477 | ret = omap_request_dma(OMAP24XX_DMA_NO_DEVICE, "DMA_ISP_HIST", | 490 | struct platform_device *pdev = to_platform_device(isp->dev); |
478 | hist_dma_cb, hist, &hist->dma_ch); | 491 | struct resource *res; |
479 | if (ret) { | 492 | unsigned int sig = 0; |
480 | if (HIST_CONFIG_DMA) | 493 | dma_cap_mask_t mask; |
481 | dev_warn(isp->dev, "hist: DMA request channel failed. " | 494 | |
482 | "Using PIO only.\n"); | 495 | dma_cap_zero(mask); |
483 | hist->dma_ch = -1; | 496 | dma_cap_set(DMA_SLAVE, mask); |
484 | } else { | 497 | |
485 | dev_dbg(isp->dev, "hist: DMA channel = %d\n", hist->dma_ch); | 498 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, |
486 | hist_dma_config(hist); | 499 | "hist"); |
487 | omap_enable_dma_irq(hist->dma_ch, OMAP_DMA_BLOCK_IRQ); | 500 | if (res) |
501 | sig = res->start; | ||
502 | |||
503 | hist->dma_ch = dma_request_slave_channel_compat(mask, | ||
504 | omap_dma_filter_fn, &sig, isp->dev, "hist"); | ||
505 | if (!hist->dma_ch) | ||
506 | dev_warn(isp->dev, | ||
507 | "hist: DMA channel request failed, using PIO\n"); | ||
508 | else | ||
509 | dev_dbg(isp->dev, "hist: using DMA channel %s\n", | ||
510 | dma_chan_name(hist->dma_ch)); | ||
488 | } | 511 | } |
489 | 512 | ||
490 | hist->ops = &hist_ops; | 513 | hist->ops = &hist_ops; |
@@ -493,8 +516,8 @@ int omap3isp_hist_init(struct isp_device *isp) | |||
493 | 516 | ||
494 | ret = omap3isp_stat_init(hist, "histogram", &hist_subdev_ops); | 517 | ret = omap3isp_stat_init(hist, "histogram", &hist_subdev_ops); |
495 | if (ret) { | 518 | if (ret) { |
496 | if (HIST_USING_DMA(hist)) | 519 | if (hist->dma_ch) |
497 | omap_free_dma(hist->dma_ch); | 520 | dma_release_channel(hist->dma_ch); |
498 | } | 521 | } |
499 | 522 | ||
500 | return ret; | 523 | return ret; |
@@ -505,7 +528,10 @@ int omap3isp_hist_init(struct isp_device *isp) | |||
505 | */ | 528 | */ |
506 | void omap3isp_hist_cleanup(struct isp_device *isp) | 529 | void omap3isp_hist_cleanup(struct isp_device *isp) |
507 | { | 530 | { |
508 | if (HIST_USING_DMA(&isp->isp_hist)) | 531 | struct ispstat *hist = &isp->isp_hist; |
509 | omap_free_dma(isp->isp_hist.dma_ch); | 532 | |
510 | omap3isp_stat_cleanup(&isp->isp_hist); | 533 | if (hist->dma_ch) |
534 | dma_release_channel(hist->dma_ch); | ||
535 | |||
536 | omap3isp_stat_cleanup(hist); | ||
511 | } | 537 | } |
diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index a94e8340508f..20434e83e801 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c | |||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | #include "isp.h" | 22 | #include "isp.h" |
23 | 23 | ||
24 | #define ISP_STAT_USES_DMAENGINE(stat) ((stat)->dma_ch >= 0) | 24 | #define ISP_STAT_USES_DMAENGINE(stat) ((stat)->dma_ch != NULL) |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * MAGIC_SIZE must always be the greatest common divisor of | 27 | * MAGIC_SIZE must always be the greatest common divisor of |
diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index b32b29677e2c..b79380d83fcf 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h | |||
@@ -20,7 +20,6 @@ | |||
20 | 20 | ||
21 | #include <linux/types.h> | 21 | #include <linux/types.h> |
22 | #include <linux/omap3isp.h> | 22 | #include <linux/omap3isp.h> |
23 | #include <linux/omap-dma.h> | ||
24 | #include <media/v4l2-event.h> | 23 | #include <media/v4l2-event.h> |
25 | 24 | ||
26 | #include "isp.h" | 25 | #include "isp.h" |
@@ -33,6 +32,7 @@ | |||
33 | #define STAT_NO_BUF 1 /* An error has occurred */ | 32 | #define STAT_NO_BUF 1 /* An error has occurred */ |
34 | #define STAT_BUF_WAITING_DMA 2 /* Histogram only: DMA is running */ | 33 | #define STAT_BUF_WAITING_DMA 2 /* Histogram only: DMA is running */ |
35 | 34 | ||
35 | struct dma_chan; | ||
36 | struct ispstat; | 36 | struct ispstat; |
37 | 37 | ||
38 | struct ispstat_buffer { | 38 | struct ispstat_buffer { |
@@ -96,7 +96,6 @@ struct ispstat { | |||
96 | u8 inc_config; | 96 | u8 inc_config; |
97 | atomic_t buf_err; | 97 | atomic_t buf_err; |
98 | enum ispstat_state_t state; /* enabling/disabling state */ | 98 | enum ispstat_state_t state; /* enabling/disabling state */ |
99 | struct omap_dma_channel_params dma_config; | ||
100 | struct isp_device *isp; | 99 | struct isp_device *isp; |
101 | void *priv; /* pointer to priv config struct */ | 100 | void *priv; /* pointer to priv config struct */ |
102 | void *recover_priv; /* pointer to recover priv configuration */ | 101 | void *recover_priv; /* pointer to recover priv configuration */ |
@@ -110,7 +109,7 @@ struct ispstat { | |||
110 | u32 frame_number; | 109 | u32 frame_number; |
111 | u32 buf_size; | 110 | u32 buf_size; |
112 | u32 buf_alloc_size; | 111 | u32 buf_alloc_size; |
113 | int dma_ch; | 112 | struct dma_chan *dma_ch; |
114 | unsigned long event_type; | 113 | unsigned long event_type; |
115 | struct ispstat_buffer *buf; | 114 | struct ispstat_buffer *buf; |
116 | struct ispstat_buffer *active_buf; | 115 | struct ispstat_buffer *active_buf; |