29 #include <linux/slab.h>
31 #include <linux/device.h>
37 #define HIST_CONFIG_DMA 1
39 #define HIST_USING_DMA(hist) ((hist)->dma_ch >= 0)
44 static void hist_reset_mem(
struct ispstat *hist)
73 static void hist_dma_config(
struct ispstat *hist)
87 static void hist_setup_regs(
struct ispstat *hist,
void *
priv)
112 reg_hor[
c] = conf->
region[
c].h_start <<
114 reg_hor[
c] = conf->
region[
c].h_end <<
116 reg_ver[
c] = conf->
region[
c].v_start <<
118 reg_ver[
c] = conf->
region[
c].v_end <<
146 hist_reset_mem(hist);
178 static int hist_busy(
struct ispstat *hist)
184 static void hist_dma_cb(
int lch,
u16 ch_status,
void *
data)
189 dev_dbg(hist->
isp->dev,
"hist: DMA error. status = 0x%04x\n",
192 hist_reset_mem(hist);
203 static int hist_buf_dma(
struct ispstat *hist)
208 dev_dbg(hist->
isp->dev,
"hist: invalid DMA buffer address\n");
209 hist_reset_mem(hist);
226 static int hist_buf_pio(
struct ispstat *hist)
233 dev_dbg(isp->
dev,
"hist: invalid PIO buffer address\n");
234 hist_reset_mem(hist);
252 for (i = hist->
buf_size / 16; i > 0; i--) {
267 static int hist_buf_process(
struct ispstat *hist)
273 hist_reset_mem(hist);
281 ret = hist_buf_dma(hist);
283 ret = hist_buf_pio(hist);
301 static int hist_validate_params(
struct ispstat *hist,
void *new_conf)
313 (user_cfg->
num_regions > OMAP3ISP_HIST_MAX_REGIONS))
326 if (user_cfg->
region[c].h_start > user_cfg->
region[c].h_end)
328 if (user_cfg->
region[c].v_start > user_cfg->
region[c].v_end)
347 buf_size = hist_get_buf_size(user_cfg);
357 static int hist_comp_params(
struct ispstat *hist,
363 if (cur_cfg->
cfa != user_cfg->
cfa)
375 else if (cur_cfg->
wg[c] != user_cfg->
wg[c])
384 if (cur_cfg->
region[c].h_start != user_cfg->
region[c].h_start)
386 if (cur_cfg->
region[c].h_end != user_cfg->
region[c].h_end)
388 if (cur_cfg->
region[c].v_start != user_cfg->
region[c].v_start)
390 if (cur_cfg->
region[c].v_end != user_cfg->
region[c].v_end)
401 static void hist_set_params(
struct ispstat *hist,
void *new_conf)
406 if (!hist->
configured || hist_comp_params(hist, user_cfg)) {
407 memcpy(cur_cfg, user_cfg,
sizeof(*user_cfg));
418 cur_cfg->
buf_size = hist_get_buf_size(cur_cfg);
443 .validate_params = hist_validate_params,
444 .set_params = hist_set_params,
445 .setup_regs = hist_setup_regs,
446 .enable = hist_enable,
448 .buf_process = hist_buf_process,
462 .core = &hist_subdev_core_ops,
463 .video = &hist_subdev_video_ops,
475 hist_cfg = kzalloc(
sizeof(*hist_cfg),
GFP_KERNEL);
476 if (hist_cfg ==
NULL)
479 memset(hist, 0,
sizeof(*hist));
482 hist_dma_cb, hist, &hist->
dma_ch);
485 dev_warn(isp->
dev,
"hist: DMA request channel failed. "
486 "Using PIO only.\n");
490 hist_dma_config(hist);
494 hist->
ops = &hist_ops;
495 hist->
priv = hist_cfg;