Lines Matching refs:stat

22 #define ISP_STAT_USES_DMAENGINE(stat)	((stat)->dma_ch != NULL)
56 #define IS_H3A_AF(stat) ((stat) == &(stat)->isp->isp_af)
57 #define IS_H3A_AEWB(stat) ((stat) == &(stat)->isp->isp_aewb)
58 #define IS_H3A(stat) (IS_H3A_AF(stat) || IS_H3A_AEWB(stat))
60 static void __isp_stat_buf_sync_magic(struct ispstat *stat,
68 dma_sync(stat->isp->dev, buf->dma_addr, 0, MAGIC_SIZE, dir);
69 dma_sync(stat->isp->dev, buf->dma_addr + (buf_size & PAGE_MASK),
73 static void isp_stat_buf_sync_magic_for_device(struct ispstat *stat,
78 if (ISP_STAT_USES_DMAENGINE(stat))
81 __isp_stat_buf_sync_magic(stat, buf, buf_size, dir,
85 static void isp_stat_buf_sync_magic_for_cpu(struct ispstat *stat,
90 if (ISP_STAT_USES_DMAENGINE(stat))
93 __isp_stat_buf_sync_magic(stat, buf, buf_size, dir,
97 static int isp_stat_buf_check_magic(struct ispstat *stat,
100 const u32 buf_size = IS_H3A_AF(stat) ?
106 isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE);
114 dev_dbg(stat->isp->dev,
116 stat->subdev.name);
124 dev_dbg(stat->isp->dev,
126 stat->subdev.name);
131 isp_stat_buf_sync_magic_for_device(stat, buf, buf_size,
137 static void isp_stat_buf_insert_magic(struct ispstat *stat,
140 const u32 buf_size = IS_H3A_AF(stat) ?
141 stat->buf_size + AF_EXTRA_DATA : stat->buf_size;
143 isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE);
149 * stat->buf_size.
154 isp_stat_buf_sync_magic_for_device(stat, buf, buf_size,
158 static void isp_stat_buf_sync_for_device(struct ispstat *stat,
161 if (ISP_STAT_USES_DMAENGINE(stat))
164 dma_sync_sg_for_device(stat->isp->dev, buf->sgt.sgl,
168 static void isp_stat_buf_sync_for_cpu(struct ispstat *stat,
171 if (ISP_STAT_USES_DMAENGINE(stat))
174 dma_sync_sg_for_cpu(stat->isp->dev, buf->sgt.sgl,
178 static void isp_stat_buf_clear(struct ispstat *stat)
183 stat->buf[i].empty = 1;
187 __isp_stat_buf_find(struct ispstat *stat, int look_empty)
193 struct ispstat_buffer *curr = &stat->buf[i];
199 if (curr == stat->locked_buf || curr == stat->active_buf)
222 isp_stat_buf_find_oldest(struct ispstat *stat)
224 return __isp_stat_buf_find(stat, 0);
228 isp_stat_buf_find_oldest_or_empty(struct ispstat *stat)
230 return __isp_stat_buf_find(stat, 1);
233 static int isp_stat_buf_queue(struct ispstat *stat)
235 if (!stat->active_buf)
238 ktime_get_ts64(&stat->active_buf->ts);
240 stat->active_buf->buf_size = stat->buf_size;
241 if (isp_stat_buf_check_magic(stat, stat->active_buf)) {
242 dev_dbg(stat->isp->dev, "%s: data wasn't properly written.\n",
243 stat->subdev.name);
246 stat->active_buf->config_counter = stat->config_counter;
247 stat->active_buf->frame_number = stat->frame_number;
248 stat->active_buf->empty = 0;
249 stat->active_buf = NULL;
255 static void isp_stat_buf_next(struct ispstat *stat)
257 if (unlikely(stat->active_buf))
259 dev_dbg(stat->isp->dev,
261 stat->subdev.name);
263 stat->active_buf = isp_stat_buf_find_oldest_or_empty(stat);
266 static void isp_stat_buf_release(struct ispstat *stat)
270 isp_stat_buf_sync_for_device(stat, stat->locked_buf);
271 spin_lock_irqsave(&stat->isp->stat_lock, flags);
272 stat->locked_buf = NULL;
273 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
277 static struct ispstat_buffer *isp_stat_buf_get(struct ispstat *stat,
284 spin_lock_irqsave(&stat->isp->stat_lock, flags);
287 buf = isp_stat_buf_find_oldest(stat);
289 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
290 dev_dbg(stat->isp->dev, "%s: cannot find a buffer.\n",
291 stat->subdev.name);
294 if (isp_stat_buf_check_magic(stat, buf)) {
295 dev_dbg(stat->isp->dev,
297 stat->subdev.name);
306 stat->locked_buf = buf;
308 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
311 dev_warn(stat->isp->dev,
313 stat->subdev.name);
314 isp_stat_buf_release(stat);
318 isp_stat_buf_sync_for_cpu(stat, buf);
325 dev_info(stat->isp->dev,
326 "%s: failed copying %d bytes of stat data\n",
327 stat->subdev.name, rval);
329 isp_stat_buf_release(stat);
335 static void isp_stat_bufs_free(struct ispstat *stat)
337 struct device *dev = ISP_STAT_USES_DMAENGINE(stat)
338 ? NULL : stat->isp->dev;
342 struct ispstat_buffer *buf = &stat->buf[i];
349 dma_free_coherent(dev, stat->buf_alloc_size, buf->virt_addr,
357 dev_dbg(stat->isp->dev, "%s: all buffers were freed.\n",
358 stat->subdev.name);
360 stat->buf_alloc_size = 0;
361 stat->active_buf = NULL;
403 static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size)
405 struct device *dev = ISP_STAT_USES_DMAENGINE(stat)
406 ? NULL : stat->isp->dev;
410 spin_lock_irqsave(&stat->isp->stat_lock, flags);
412 BUG_ON(stat->locked_buf != NULL);
415 if (stat->buf_alloc_size >= size) {
416 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
420 if (stat->state != ISPSTAT_DISABLED || stat->buf_processing) {
421 dev_info(stat->isp->dev,
423 stat->subdev.name);
424 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
428 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
430 isp_stat_bufs_free(stat);
432 stat->buf_alloc_size = size;
435 struct ispstat_buffer *buf = &stat->buf[i];
440 dev_err(stat->isp->dev,
442 stat->subdev.name, i);
443 isp_stat_bufs_free(stat);
449 dev_dbg(stat->isp->dev,
451 stat->subdev.name, i, &buf->dma_addr, buf->virt_addr);
457 static void isp_stat_queue_event(struct ispstat *stat, int err)
459 struct video_device *vdev = stat->subdev.devnode;
465 status->frame_number = stat->frame_number;
466 status->config_counter = stat->config_counter;
470 event.type = stat->event_type;
481 int omap3isp_stat_request_statistics(struct ispstat *stat,
486 if (stat->state != ISPSTAT_ENABLED) {
487 dev_dbg(stat->isp->dev, "%s: engine not enabled.\n",
488 stat->subdev.name);
492 mutex_lock(&stat->ioctl_lock);
493 buf = isp_stat_buf_get(stat, data);
495 mutex_unlock(&stat->ioctl_lock);
506 isp_stat_buf_release(stat);
507 mutex_unlock(&stat->ioctl_lock);
512 int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
518 ret = omap3isp_stat_request_statistics(stat, &data64);
537 int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
544 mutex_lock(&stat->ioctl_lock);
546 dev_dbg(stat->isp->dev,
548 stat->subdev.name, (unsigned long)buf_size);
550 ret = stat->ops->validate_params(stat, new_conf);
552 mutex_unlock(&stat->ioctl_lock);
553 dev_dbg(stat->isp->dev, "%s: configuration values are invalid.\n",
554 stat->subdev.name);
559 dev_dbg(stat->isp->dev,
561 stat->subdev.name,
575 if (IS_H3A(stat)) {
577 if (IS_H3A_AF(stat))
583 if (stat->recover_priv) {
585 stat->recover_priv;
594 ret = isp_stat_bufs_alloc(stat, buf_size);
596 mutex_unlock(&stat->ioctl_lock);
600 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
601 stat->ops->set_params(stat, new_conf);
602 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
608 user_cfg->config_counter = stat->config_counter + stat->inc_config;
611 stat->configured = 1;
612 dev_dbg(stat->isp->dev,
614 stat->subdev.name);
616 mutex_unlock(&stat->ioctl_lock);
627 static int isp_stat_buf_process(struct ispstat *stat, int buf_state)
631 if (!atomic_add_unless(&stat->buf_err, -1, 0) &&
632 buf_state == STAT_BUF_DONE && stat->state == ISPSTAT_ENABLED) {
633 ret = isp_stat_buf_queue(stat);
634 isp_stat_buf_next(stat);
640 int omap3isp_stat_pcr_busy(struct ispstat *stat)
642 return stat->ops->busy(stat);
645 int omap3isp_stat_busy(struct ispstat *stat)
647 return omap3isp_stat_pcr_busy(stat) | stat->buf_processing |
648 (stat->state != ISPSTAT_DISABLED);
658 static void isp_stat_pcr_enable(struct ispstat *stat, u8 pcr_enable)
660 if ((stat->state != ISPSTAT_ENABLING &&
661 stat->state != ISPSTAT_ENABLED) && pcr_enable)
665 stat->ops->enable(stat, pcr_enable);
666 if (stat->state == ISPSTAT_DISABLING && !pcr_enable)
667 stat->state = ISPSTAT_DISABLED;
668 else if (stat->state == ISPSTAT_ENABLING && pcr_enable)
669 stat->state = ISPSTAT_ENABLED;
672 void omap3isp_stat_suspend(struct ispstat *stat)
676 spin_lock_irqsave(&stat->isp->stat_lock, flags);
678 if (stat->state != ISPSTAT_DISABLED)
679 stat->ops->enable(stat, 0);
680 if (stat->state == ISPSTAT_ENABLED)
681 stat->state = ISPSTAT_SUSPENDED;
683 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
686 void omap3isp_stat_resume(struct ispstat *stat)
689 if (stat->state == ISPSTAT_SUSPENDED)
690 stat->state = ISPSTAT_ENABLING;
693 static void isp_stat_try_enable(struct ispstat *stat)
697 if (stat->priv == NULL)
701 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
702 if (stat->state == ISPSTAT_ENABLING && !stat->buf_processing &&
703 stat->buf_alloc_size) {
708 stat->update = 1;
709 isp_stat_buf_next(stat);
710 stat->ops->setup_regs(stat, stat->priv);
711 isp_stat_buf_insert_magic(stat, stat->active_buf);
719 if (!IS_H3A(stat))
720 atomic_set(&stat->buf_err, 0);
722 isp_stat_pcr_enable(stat, 1);
723 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
724 dev_dbg(stat->isp->dev, "%s: module is enabled.\n",
725 stat->subdev.name);
727 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
731 void omap3isp_stat_isr_frame_sync(struct ispstat *stat)
733 isp_stat_try_enable(stat);
736 void omap3isp_stat_sbl_overflow(struct ispstat *stat)
740 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
745 atomic_set(&stat->buf_err, 2);
750 * stat->sbl_ovl_recover is set to tell to the driver to temporarily use
753 if (stat->recover_priv)
754 stat->sbl_ovl_recover = 1;
755 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
765 int omap3isp_stat_enable(struct ispstat *stat, u8 enable)
769 dev_dbg(stat->isp->dev, "%s: user wants to %s module.\n",
770 stat->subdev.name, enable ? "enable" : "disable");
773 mutex_lock(&stat->ioctl_lock);
775 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
777 if (!stat->configured && enable) {
778 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
779 mutex_unlock(&stat->ioctl_lock);
780 dev_dbg(stat->isp->dev,
782 stat->subdev.name);
787 if (stat->state == ISPSTAT_DISABLING)
789 stat->state = ISPSTAT_ENABLED;
790 else if (stat->state == ISPSTAT_DISABLED)
792 stat->state = ISPSTAT_ENABLING;
794 if (stat->state == ISPSTAT_ENABLING) {
796 stat->state = ISPSTAT_DISABLED;
797 } else if (stat->state == ISPSTAT_ENABLED) {
799 stat->state = ISPSTAT_DISABLING;
800 isp_stat_buf_clear(stat);
804 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
805 mutex_unlock(&stat->ioctl_lock);
812 struct ispstat *stat = v4l2_get_subdevdata(subdev);
819 isp_stat_try_enable(stat);
823 omap3isp_stat_enable(stat, 0);
824 spin_lock_irqsave(&stat->isp->stat_lock, flags);
825 stat->ops->enable(stat, 0);
826 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
839 if (!omap3isp_stat_pcr_busy(stat))
840 omap3isp_stat_isr(stat);
842 dev_dbg(stat->isp->dev, "%s: module is being disabled\n",
843 stat->subdev.name);
852 static void __stat_isr(struct ispstat *stat, int from_dma)
860 * stat->buf_processing must be set before disable module. It's
864 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
865 if (stat->state == ISPSTAT_DISABLED) {
866 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
869 buf_processing = stat->buf_processing;
870 stat->buf_processing = 1;
871 stat->ops->enable(stat, 0);
874 if (stat->state == ISPSTAT_ENABLED) {
875 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
876 dev_err(stat->isp->dev,
878 stat->subdev.name);
889 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
893 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
896 if (!omap3isp_stat_pcr_busy(stat)) {
897 if (!from_dma && stat->ops->buf_process)
899 ret = stat->ops->buf_process(stat);
904 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
909 * can return only after call stat's buf_process() operator.
911 if (stat->state == ISPSTAT_DISABLING) {
912 stat->state = ISPSTAT_DISABLED;
913 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
914 stat->buf_processing = 0;
917 pipe = to_isp_pipeline(&stat->subdev.entity);
918 stat->frame_number = atomic_read(&pipe->frame_number);
925 ret = isp_stat_buf_process(stat, ret);
927 if (likely(!stat->sbl_ovl_recover)) {
928 stat->ops->setup_regs(stat, stat->priv);
935 stat->update = 1;
936 stat->ops->setup_regs(stat, stat->recover_priv);
937 stat->sbl_ovl_recover = 0;
943 stat->update = 1;
946 isp_stat_buf_insert_magic(stat, stat->active_buf);
959 isp_stat_pcr_enable(stat, 1);
960 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
964 * to process the buffer, stat->buf_err is set and won't be
969 * Do not "stat->buf_err = 0" here.
972 if (stat->ops->buf_process)
979 atomic_set(&stat->buf_err, 1);
982 dev_dbg(stat->isp->dev,
984 stat->subdev.name);
988 stat->buf_processing = 0;
989 isp_stat_queue_event(stat, ret != STAT_BUF_DONE);
992 void omap3isp_stat_isr(struct ispstat *stat)
994 __stat_isr(stat, 0);
997 void omap3isp_stat_dma_isr(struct ispstat *stat)
999 __stat_isr(stat, 1);
1006 struct ispstat *stat = v4l2_get_subdevdata(subdev);
1008 if (sub->type != stat->event_type)
1021 void omap3isp_stat_unregister_entities(struct ispstat *stat)
1023 v4l2_device_unregister_subdev(&stat->subdev);
1026 int omap3isp_stat_register_entities(struct ispstat *stat,
1029 stat->subdev.dev = vdev->mdev->dev;
1031 return v4l2_device_register_subdev(vdev, &stat->subdev);
1034 static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1037 struct v4l2_subdev *subdev = &stat->subdev;
1044 v4l2_set_subdevdata(subdev, stat);
1046 stat->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
1049 return media_entity_pads_init(me, 1, &stat->pad);
1052 int omap3isp_stat_init(struct ispstat *stat, const char *name,
1057 stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL);
1058 if (!stat->buf)
1061 isp_stat_buf_clear(stat);
1062 mutex_init(&stat->ioctl_lock);
1063 atomic_set(&stat->buf_err, 0);
1065 ret = isp_stat_init_entities(stat, name, sd_ops);
1067 mutex_destroy(&stat->ioctl_lock);
1068 kfree(stat->buf);
1074 void omap3isp_stat_cleanup(struct ispstat *stat)
1076 media_entity_cleanup(&stat->subdev.entity);
1077 mutex_destroy(&stat->ioctl_lock);
1078 isp_stat_bufs_free(stat);
1079 kfree(stat->buf);
1080 kfree(stat->priv);
1081 kfree(stat->recover_priv);