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);
538 int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
545 mutex_lock(&stat->ioctl_lock);
547 dev_dbg(stat->isp->dev,
549 stat->subdev.name, (unsigned long)buf_size);
551 ret = stat->ops->validate_params(stat, new_conf);
553 mutex_unlock(&stat->ioctl_lock);
554 dev_dbg(stat->isp->dev, "%s: configuration values are invalid.\n",
555 stat->subdev.name);
560 dev_dbg(stat->isp->dev,
562 stat->subdev.name,
576 if (IS_H3A(stat)) {
578 if (IS_H3A_AF(stat))
584 if (stat->recover_priv) {
586 stat->recover_priv;
595 ret = isp_stat_bufs_alloc(stat, buf_size);
597 mutex_unlock(&stat->ioctl_lock);
601 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
602 stat->ops->set_params(stat, new_conf);
603 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
609 user_cfg->config_counter = stat->config_counter + stat->inc_config;
612 stat->configured = 1;
613 dev_dbg(stat->isp->dev,
615 stat->subdev.name);
617 mutex_unlock(&stat->ioctl_lock);
628 static int isp_stat_buf_process(struct ispstat *stat, int buf_state)
632 if (!atomic_add_unless(&stat->buf_err, -1, 0) &&
633 buf_state == STAT_BUF_DONE && stat->state == ISPSTAT_ENABLED) {
634 ret = isp_stat_buf_queue(stat);
635 isp_stat_buf_next(stat);
641 int omap3isp_stat_pcr_busy(struct ispstat *stat)
643 return stat->ops->busy(stat);
646 int omap3isp_stat_busy(struct ispstat *stat)
648 return omap3isp_stat_pcr_busy(stat) | stat->buf_processing |
649 (stat->state != ISPSTAT_DISABLED);
659 static void isp_stat_pcr_enable(struct ispstat *stat, u8 pcr_enable)
661 if ((stat->state != ISPSTAT_ENABLING &&
662 stat->state != ISPSTAT_ENABLED) && pcr_enable)
666 stat->ops->enable(stat, pcr_enable);
667 if (stat->state == ISPSTAT_DISABLING && !pcr_enable)
668 stat->state = ISPSTAT_DISABLED;
669 else if (stat->state == ISPSTAT_ENABLING && pcr_enable)
670 stat->state = ISPSTAT_ENABLED;
673 void omap3isp_stat_suspend(struct ispstat *stat)
677 spin_lock_irqsave(&stat->isp->stat_lock, flags);
679 if (stat->state != ISPSTAT_DISABLED)
680 stat->ops->enable(stat, 0);
681 if (stat->state == ISPSTAT_ENABLED)
682 stat->state = ISPSTAT_SUSPENDED;
684 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
687 void omap3isp_stat_resume(struct ispstat *stat)
690 if (stat->state == ISPSTAT_SUSPENDED)
691 stat->state = ISPSTAT_ENABLING;
694 static void isp_stat_try_enable(struct ispstat *stat)
698 if (stat->priv == NULL)
702 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
703 if (stat->state == ISPSTAT_ENABLING && !stat->buf_processing &&
704 stat->buf_alloc_size) {
709 stat->update = 1;
710 isp_stat_buf_next(stat);
711 stat->ops->setup_regs(stat, stat->priv);
712 isp_stat_buf_insert_magic(stat, stat->active_buf);
720 if (!IS_H3A(stat))
721 atomic_set(&stat->buf_err, 0);
723 isp_stat_pcr_enable(stat, 1);
724 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
725 dev_dbg(stat->isp->dev, "%s: module is enabled.\n",
726 stat->subdev.name);
728 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
732 void omap3isp_stat_isr_frame_sync(struct ispstat *stat)
734 isp_stat_try_enable(stat);
737 void omap3isp_stat_sbl_overflow(struct ispstat *stat)
741 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
746 atomic_set(&stat->buf_err, 2);
751 * stat->sbl_ovl_recover is set to tell to the driver to temporarily use
754 if (stat->recover_priv)
755 stat->sbl_ovl_recover = 1;
756 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
766 int omap3isp_stat_enable(struct ispstat *stat, u8 enable)
770 dev_dbg(stat->isp->dev, "%s: user wants to %s module.\n",
771 stat->subdev.name, enable ? "enable" : "disable");
774 mutex_lock(&stat->ioctl_lock);
776 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
778 if (!stat->configured && enable) {
779 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
780 mutex_unlock(&stat->ioctl_lock);
781 dev_dbg(stat->isp->dev,
783 stat->subdev.name);
788 if (stat->state == ISPSTAT_DISABLING)
790 stat->state = ISPSTAT_ENABLED;
791 else if (stat->state == ISPSTAT_DISABLED)
793 stat->state = ISPSTAT_ENABLING;
795 if (stat->state == ISPSTAT_ENABLING) {
797 stat->state = ISPSTAT_DISABLED;
798 } else if (stat->state == ISPSTAT_ENABLED) {
800 stat->state = ISPSTAT_DISABLING;
801 isp_stat_buf_clear(stat);
805 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
806 mutex_unlock(&stat->ioctl_lock);
813 struct ispstat *stat = v4l2_get_subdevdata(subdev);
820 isp_stat_try_enable(stat);
824 omap3isp_stat_enable(stat, 0);
825 spin_lock_irqsave(&stat->isp->stat_lock, flags);
826 stat->ops->enable(stat, 0);
827 spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
840 if (!omap3isp_stat_pcr_busy(stat))
841 omap3isp_stat_isr(stat);
843 dev_dbg(stat->isp->dev, "%s: module is being disabled\n",
844 stat->subdev.name);
853 static void __stat_isr(struct ispstat *stat, int from_dma)
861 * stat->buf_processing must be set before disable module. It's
865 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
866 if (stat->state == ISPSTAT_DISABLED) {
867 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
870 buf_processing = stat->buf_processing;
871 stat->buf_processing = 1;
872 stat->ops->enable(stat, 0);
875 if (stat->state == ISPSTAT_ENABLED) {
876 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
877 dev_err(stat->isp->dev,
879 stat->subdev.name);
890 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
894 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
897 if (!omap3isp_stat_pcr_busy(stat)) {
898 if (!from_dma && stat->ops->buf_process)
900 ret = stat->ops->buf_process(stat);
905 spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
910 * can return only after call stat's buf_process() operator.
912 if (stat->state == ISPSTAT_DISABLING) {
913 stat->state = ISPSTAT_DISABLED;
914 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
915 stat->buf_processing = 0;
918 pipe = to_isp_pipeline(&stat->subdev.entity);
919 stat->frame_number = atomic_read(&pipe->frame_number);
926 ret = isp_stat_buf_process(stat, ret);
928 if (likely(!stat->sbl_ovl_recover)) {
929 stat->ops->setup_regs(stat, stat->priv);
936 stat->update = 1;
937 stat->ops->setup_regs(stat, stat->recover_priv);
938 stat->sbl_ovl_recover = 0;
944 stat->update = 1;
947 isp_stat_buf_insert_magic(stat, stat->active_buf);
960 isp_stat_pcr_enable(stat, 1);
961 spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
965 * to process the buffer, stat->buf_err is set and won't be
970 * Do not "stat->buf_err = 0" here.
973 if (stat->ops->buf_process)
980 atomic_set(&stat->buf_err, 1);
983 dev_dbg(stat->isp->dev,
985 stat->subdev.name);
989 stat->buf_processing = 0;
990 isp_stat_queue_event(stat, ret != STAT_BUF_DONE);
993 void omap3isp_stat_isr(struct ispstat *stat)
995 __stat_isr(stat, 0);
998 void omap3isp_stat_dma_isr(struct ispstat *stat)
1000 __stat_isr(stat, 1);
1007 struct ispstat *stat = v4l2_get_subdevdata(subdev);
1009 if (sub->type != stat->event_type)
1022 void omap3isp_stat_unregister_entities(struct ispstat *stat)
1024 v4l2_device_unregister_subdev(&stat->subdev);
1027 int omap3isp_stat_register_entities(struct ispstat *stat,
1030 stat->subdev.dev = vdev->mdev->dev;
1032 return v4l2_device_register_subdev(vdev, &stat->subdev);
1035 static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1038 struct v4l2_subdev *subdev = &stat->subdev;
1045 v4l2_set_subdevdata(subdev, stat);
1047 stat->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
1050 return media_entity_pads_init(me, 1, &stat->pad);
1053 int omap3isp_stat_init(struct ispstat *stat, const char *name,
1058 stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL);
1059 if (!stat->buf)
1062 isp_stat_buf_clear(stat);
1063 mutex_init(&stat->ioctl_lock);
1064 atomic_set(&stat->buf_err, 0);
1066 ret = isp_stat_init_entities(stat, name, sd_ops);
1068 mutex_destroy(&stat->ioctl_lock);
1069 kfree(stat->buf);
1075 void omap3isp_stat_cleanup(struct ispstat *stat)
1077 media_entity_cleanup(&stat->subdev.entity);
1078 mutex_destroy(&stat->ioctl_lock);
1079 isp_stat_bufs_free(stat);
1080 kfree(stat->buf);
1081 kfree(stat->priv);
1082 kfree(stat->recover_priv);