12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- #include <linux/dma-mapping.h>
- #include <linux/slab.h>
- #include <linux/uaccess.h>
- #include "isp.h"
- #define ISP_STAT_USES_DMAENGINE(stat) ((stat)->dma_ch != NULL)
- #define MAGIC_SIZE 16
- #define MAGIC_NUM 0x55
- #define AF_EXTRA_DATA OMAP3ISP_AF_PAXEL_SIZE
- #define NUM_H3A_RECOVER_BUFS 10
- #define IS_H3A_AF(stat) ((stat) == &(stat)->isp->isp_af)
- #define IS_H3A_AEWB(stat) ((stat) == &(stat)->isp->isp_aewb)
- #define IS_H3A(stat) (IS_H3A_AF(stat) || IS_H3A_AEWB(stat))
- static void __isp_stat_buf_sync_magic(struct ispstat *stat,
- struct ispstat_buffer *buf,
- u32 buf_size, enum dma_data_direction dir,
- void (*dma_sync)(struct device *,
- dma_addr_t, unsigned long, size_t,
- enum dma_data_direction))
- {
-
- dma_sync(stat->isp->dev, buf->dma_addr, 0, MAGIC_SIZE, dir);
- dma_sync(stat->isp->dev, buf->dma_addr + (buf_size & PAGE_MASK),
- buf_size & ~PAGE_MASK, MAGIC_SIZE, dir);
- }
- static void isp_stat_buf_sync_magic_for_device(struct ispstat *stat,
- struct ispstat_buffer *buf,
- u32 buf_size,
- enum dma_data_direction dir)
- {
- if (ISP_STAT_USES_DMAENGINE(stat))
- return;
- __isp_stat_buf_sync_magic(stat, buf, buf_size, dir,
- dma_sync_single_range_for_device);
- }
- static void isp_stat_buf_sync_magic_for_cpu(struct ispstat *stat,
- struct ispstat_buffer *buf,
- u32 buf_size,
- enum dma_data_direction dir)
- {
- if (ISP_STAT_USES_DMAENGINE(stat))
- return;
- __isp_stat_buf_sync_magic(stat, buf, buf_size, dir,
- dma_sync_single_range_for_cpu);
- }
- static int isp_stat_buf_check_magic(struct ispstat *stat,
- struct ispstat_buffer *buf)
- {
- const u32 buf_size = IS_H3A_AF(stat) ?
- buf->buf_size + AF_EXTRA_DATA : buf->buf_size;
- u8 *w;
- u8 *end;
- int ret = -EINVAL;
- isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE);
-
- for (w = buf->virt_addr, end = w + MAGIC_SIZE; w < end; w++)
- if (likely(*w != MAGIC_NUM))
- ret = 0;
- if (ret) {
- dev_dbg(stat->isp->dev,
- "%s: beginning magic check does not match.\n",
- stat->subdev.name);
- return ret;
- }
-
- for (w = buf->virt_addr + buf_size, end = w + MAGIC_SIZE;
- w < end; w++) {
- if (unlikely(*w != MAGIC_NUM)) {
- dev_dbg(stat->isp->dev,
- "%s: ending magic check does not match.\n",
- stat->subdev.name);
- return -EINVAL;
- }
- }
- isp_stat_buf_sync_magic_for_device(stat, buf, buf_size,
- DMA_FROM_DEVICE);
- return 0;
- }
- static void isp_stat_buf_insert_magic(struct ispstat *stat,
- struct ispstat_buffer *buf)
- {
- const u32 buf_size = IS_H3A_AF(stat) ?
- stat->buf_size + AF_EXTRA_DATA : stat->buf_size;
- isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE);
-
- memset(buf->virt_addr, MAGIC_NUM, MAGIC_SIZE);
- memset(buf->virt_addr + buf_size, MAGIC_NUM, MAGIC_SIZE);
- isp_stat_buf_sync_magic_for_device(stat, buf, buf_size,
- DMA_BIDIRECTIONAL);
- }
- static void isp_stat_buf_sync_for_device(struct ispstat *stat,
- struct ispstat_buffer *buf)
- {
- if (ISP_STAT_USES_DMAENGINE(stat))
- return;
- dma_sync_sg_for_device(stat->isp->dev, buf->sgt.sgl,
- buf->sgt.nents, DMA_FROM_DEVICE);
- }
- static void isp_stat_buf_sync_for_cpu(struct ispstat *stat,
- struct ispstat_buffer *buf)
- {
- if (ISP_STAT_USES_DMAENGINE(stat))
- return;
- dma_sync_sg_for_cpu(stat->isp->dev, buf->sgt.sgl,
- buf->sgt.nents, DMA_FROM_DEVICE);
- }
- static void isp_stat_buf_clear(struct ispstat *stat)
- {
- int i;
- for (i = 0; i < STAT_MAX_BUFS; i++)
- stat->buf[i].empty = 1;
- }
- static struct ispstat_buffer *
- __isp_stat_buf_find(struct ispstat *stat, int look_empty)
- {
- struct ispstat_buffer *found = NULL;
- int i;
- for (i = 0; i < STAT_MAX_BUFS; i++) {
- struct ispstat_buffer *curr = &stat->buf[i];
-
- if (curr == stat->locked_buf || curr == stat->active_buf)
- continue;
-
- if (!look_empty && curr->empty)
- continue;
-
- if (curr->empty) {
- found = curr;
- break;
- }
-
- if (!found ||
- (s32)curr->frame_number - (s32)found->frame_number < 0)
- found = curr;
- }
- return found;
- }
- static inline struct ispstat_buffer *
- isp_stat_buf_find_oldest(struct ispstat *stat)
- {
- return __isp_stat_buf_find(stat, 0);
- }
- static inline struct ispstat_buffer *
- isp_stat_buf_find_oldest_or_empty(struct ispstat *stat)
- {
- return __isp_stat_buf_find(stat, 1);
- }
- static int isp_stat_buf_queue(struct ispstat *stat)
- {
- if (!stat->active_buf)
- return STAT_NO_BUF;
- v4l2_get_timestamp(&stat->active_buf->ts);
- stat->active_buf->buf_size = stat->buf_size;
- if (isp_stat_buf_check_magic(stat, stat->active_buf)) {
- dev_dbg(stat->isp->dev, "%s: data wasn't properly written.\n",
- stat->subdev.name);
- return STAT_NO_BUF;
- }
- stat->active_buf->config_counter = stat->config_counter;
- stat->active_buf->frame_number = stat->frame_number;
- stat->active_buf->empty = 0;
- stat->active_buf = NULL;
- return STAT_BUF_DONE;
- }
- static void isp_stat_buf_next(struct ispstat *stat)
- {
- if (unlikely(stat->active_buf))
-
- dev_dbg(stat->isp->dev,
- "%s: new buffer requested without queuing active one.\n",
- stat->subdev.name);
- else
- stat->active_buf = isp_stat_buf_find_oldest_or_empty(stat);
- }
- static void isp_stat_buf_release(struct ispstat *stat)
- {
- unsigned long flags;
- isp_stat_buf_sync_for_device(stat, stat->locked_buf);
- spin_lock_irqsave(&stat->isp->stat_lock, flags);
- stat->locked_buf = NULL;
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- }
- static struct ispstat_buffer *isp_stat_buf_get(struct ispstat *stat,
- struct omap3isp_stat_data *data)
- {
- int rval = 0;
- unsigned long flags;
- struct ispstat_buffer *buf;
- spin_lock_irqsave(&stat->isp->stat_lock, flags);
- while (1) {
- buf = isp_stat_buf_find_oldest(stat);
- if (!buf) {
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- dev_dbg(stat->isp->dev, "%s: cannot find a buffer.\n",
- stat->subdev.name);
- return ERR_PTR(-EBUSY);
- }
- if (isp_stat_buf_check_magic(stat, buf)) {
- dev_dbg(stat->isp->dev,
- "%s: current buffer has corrupted data\n.",
- stat->subdev.name);
-
- buf->empty = 1;
- } else {
-
- break;
- }
- }
- stat->locked_buf = buf;
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- if (buf->buf_size > data->buf_size) {
- dev_warn(stat->isp->dev,
- "%s: userspace's buffer size is not enough.\n",
- stat->subdev.name);
- isp_stat_buf_release(stat);
- return ERR_PTR(-EINVAL);
- }
- isp_stat_buf_sync_for_cpu(stat, buf);
- rval = copy_to_user(data->buf,
- buf->virt_addr,
- buf->buf_size);
- if (rval) {
- dev_info(stat->isp->dev,
- "%s: failed copying %d bytes of stat data\n",
- stat->subdev.name, rval);
- buf = ERR_PTR(-EFAULT);
- isp_stat_buf_release(stat);
- }
- return buf;
- }
- static void isp_stat_bufs_free(struct ispstat *stat)
- {
- struct device *dev = ISP_STAT_USES_DMAENGINE(stat)
- ? NULL : stat->isp->dev;
- unsigned int i;
- for (i = 0; i < STAT_MAX_BUFS; i++) {
- struct ispstat_buffer *buf = &stat->buf[i];
- if (!buf->virt_addr)
- continue;
- sg_free_table(&buf->sgt);
- dma_free_coherent(dev, stat->buf_alloc_size, buf->virt_addr,
- buf->dma_addr);
- buf->dma_addr = 0;
- buf->virt_addr = NULL;
- buf->empty = 1;
- }
- dev_dbg(stat->isp->dev, "%s: all buffers were freed.\n",
- stat->subdev.name);
- stat->buf_alloc_size = 0;
- stat->active_buf = NULL;
- }
- static int isp_stat_bufs_alloc_one(struct device *dev,
- struct ispstat_buffer *buf,
- unsigned int size)
- {
- int ret;
- buf->virt_addr = dma_alloc_coherent(dev, size, &buf->dma_addr,
- GFP_KERNEL | GFP_DMA);
- if (!buf->virt_addr)
- return -ENOMEM;
- ret = dma_get_sgtable(dev, &buf->sgt, buf->virt_addr, buf->dma_addr,
- size);
- if (ret < 0) {
- dma_free_coherent(dev, size, buf->virt_addr, buf->dma_addr);
- buf->virt_addr = NULL;
- buf->dma_addr = 0;
- return ret;
- }
- return 0;
- }
- static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size)
- {
- struct device *dev = ISP_STAT_USES_DMAENGINE(stat)
- ? NULL : stat->isp->dev;
- unsigned long flags;
- unsigned int i;
- spin_lock_irqsave(&stat->isp->stat_lock, flags);
- BUG_ON(stat->locked_buf != NULL);
-
- if (stat->buf_alloc_size >= size) {
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- return 0;
- }
- if (stat->state != ISPSTAT_DISABLED || stat->buf_processing) {
- dev_info(stat->isp->dev,
- "%s: trying to allocate memory when busy\n",
- stat->subdev.name);
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- return -EBUSY;
- }
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- isp_stat_bufs_free(stat);
- stat->buf_alloc_size = size;
- for (i = 0; i < STAT_MAX_BUFS; i++) {
- struct ispstat_buffer *buf = &stat->buf[i];
- int ret;
- ret = isp_stat_bufs_alloc_one(dev, buf, size);
- if (ret < 0) {
- dev_err(stat->isp->dev,
- "%s: Failed to allocate DMA buffer %u\n",
- stat->subdev.name, i);
- isp_stat_bufs_free(stat);
- return ret;
- }
- buf->empty = 1;
- dev_dbg(stat->isp->dev,
- "%s: buffer[%u] allocated. dma=0x%08lx virt=0x%08lx",
- stat->subdev.name, i,
- (unsigned long)buf->dma_addr,
- (unsigned long)buf->virt_addr);
- }
- return 0;
- }
- static void isp_stat_queue_event(struct ispstat *stat, int err)
- {
- struct video_device *vdev = stat->subdev.devnode;
- struct v4l2_event event;
- struct omap3isp_stat_event_status *status = (void *)event.u.data;
- memset(&event, 0, sizeof(event));
- if (!err) {
- status->frame_number = stat->frame_number;
- status->config_counter = stat->config_counter;
- } else {
- status->buf_err = 1;
- }
- event.type = stat->event_type;
- v4l2_event_queue(vdev, &event);
- }
- int omap3isp_stat_request_statistics(struct ispstat *stat,
- struct omap3isp_stat_data *data)
- {
- struct ispstat_buffer *buf;
- if (stat->state != ISPSTAT_ENABLED) {
- dev_dbg(stat->isp->dev, "%s: engine not enabled.\n",
- stat->subdev.name);
- return -EINVAL;
- }
- mutex_lock(&stat->ioctl_lock);
- buf = isp_stat_buf_get(stat, data);
- if (IS_ERR(buf)) {
- mutex_unlock(&stat->ioctl_lock);
- return PTR_ERR(buf);
- }
- data->ts = buf->ts;
- data->config_counter = buf->config_counter;
- data->frame_number = buf->frame_number;
- data->buf_size = buf->buf_size;
- buf->empty = 1;
- isp_stat_buf_release(stat);
- mutex_unlock(&stat->ioctl_lock);
- return 0;
- }
- int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
- {
- int ret;
- unsigned long irqflags;
- struct ispstat_generic_config *user_cfg = new_conf;
- u32 buf_size = user_cfg->buf_size;
- if (!new_conf) {
- dev_dbg(stat->isp->dev, "%s: configuration is NULL\n",
- stat->subdev.name);
- return -EINVAL;
- }
- mutex_lock(&stat->ioctl_lock);
- dev_dbg(stat->isp->dev,
- "%s: configuring module with buffer size=0x%08lx\n",
- stat->subdev.name, (unsigned long)buf_size);
- ret = stat->ops->validate_params(stat, new_conf);
- if (ret) {
- mutex_unlock(&stat->ioctl_lock);
- dev_dbg(stat->isp->dev, "%s: configuration values are invalid.\n",
- stat->subdev.name);
- return ret;
- }
- if (buf_size != user_cfg->buf_size)
- dev_dbg(stat->isp->dev,
- "%s: driver has corrected buffer size request to 0x%08lx\n",
- stat->subdev.name,
- (unsigned long)user_cfg->buf_size);
-
- if (IS_H3A(stat)) {
- buf_size = user_cfg->buf_size * 2 + MAGIC_SIZE;
- if (IS_H3A_AF(stat))
-
- buf_size += AF_EXTRA_DATA * (NUM_H3A_RECOVER_BUFS + 2);
- if (stat->recover_priv) {
- struct ispstat_generic_config *recover_cfg =
- stat->recover_priv;
- buf_size += recover_cfg->buf_size *
- NUM_H3A_RECOVER_BUFS;
- }
- buf_size = PAGE_ALIGN(buf_size);
- } else {
- buf_size = PAGE_ALIGN(user_cfg->buf_size + MAGIC_SIZE);
- }
- ret = isp_stat_bufs_alloc(stat, buf_size);
- if (ret) {
- mutex_unlock(&stat->ioctl_lock);
- return ret;
- }
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
- stat->ops->set_params(stat, new_conf);
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
-
- user_cfg->config_counter = stat->config_counter + stat->inc_config;
-
- stat->configured = 1;
- dev_dbg(stat->isp->dev,
- "%s: module has been successfully configured.\n",
- stat->subdev.name);
- mutex_unlock(&stat->ioctl_lock);
- return 0;
- }
- static int isp_stat_buf_process(struct ispstat *stat, int buf_state)
- {
- int ret = STAT_NO_BUF;
- if (!atomic_add_unless(&stat->buf_err, -1, 0) &&
- buf_state == STAT_BUF_DONE && stat->state == ISPSTAT_ENABLED) {
- ret = isp_stat_buf_queue(stat);
- isp_stat_buf_next(stat);
- }
- return ret;
- }
- int omap3isp_stat_pcr_busy(struct ispstat *stat)
- {
- return stat->ops->busy(stat);
- }
- int omap3isp_stat_busy(struct ispstat *stat)
- {
- return omap3isp_stat_pcr_busy(stat) | stat->buf_processing |
- (stat->state != ISPSTAT_DISABLED);
- }
- static void isp_stat_pcr_enable(struct ispstat *stat, u8 pcr_enable)
- {
- if ((stat->state != ISPSTAT_ENABLING &&
- stat->state != ISPSTAT_ENABLED) && pcr_enable)
-
- return;
- stat->ops->enable(stat, pcr_enable);
- if (stat->state == ISPSTAT_DISABLING && !pcr_enable)
- stat->state = ISPSTAT_DISABLED;
- else if (stat->state == ISPSTAT_ENABLING && pcr_enable)
- stat->state = ISPSTAT_ENABLED;
- }
- void omap3isp_stat_suspend(struct ispstat *stat)
- {
- unsigned long flags;
- spin_lock_irqsave(&stat->isp->stat_lock, flags);
- if (stat->state != ISPSTAT_DISABLED)
- stat->ops->enable(stat, 0);
- if (stat->state == ISPSTAT_ENABLED)
- stat->state = ISPSTAT_SUSPENDED;
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
- }
- void omap3isp_stat_resume(struct ispstat *stat)
- {
-
- if (stat->state == ISPSTAT_SUSPENDED)
- stat->state = ISPSTAT_ENABLING;
- }
- static void isp_stat_try_enable(struct ispstat *stat)
- {
- unsigned long irqflags;
- if (stat->priv == NULL)
-
- return;
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
- if (stat->state == ISPSTAT_ENABLING && !stat->buf_processing &&
- stat->buf_alloc_size) {
-
- stat->update = 1;
- isp_stat_buf_next(stat);
- stat->ops->setup_regs(stat, stat->priv);
- isp_stat_buf_insert_magic(stat, stat->active_buf);
-
- if (!IS_H3A(stat))
- atomic_set(&stat->buf_err, 0);
- isp_stat_pcr_enable(stat, 1);
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- dev_dbg(stat->isp->dev, "%s: module is enabled.\n",
- stat->subdev.name);
- } else {
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- }
- }
- void omap3isp_stat_isr_frame_sync(struct ispstat *stat)
- {
- isp_stat_try_enable(stat);
- }
- void omap3isp_stat_sbl_overflow(struct ispstat *stat)
- {
- unsigned long irqflags;
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
-
- atomic_set(&stat->buf_err, 2);
-
- if (stat->recover_priv)
- stat->sbl_ovl_recover = 1;
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- }
- int omap3isp_stat_enable(struct ispstat *stat, u8 enable)
- {
- unsigned long irqflags;
- dev_dbg(stat->isp->dev, "%s: user wants to %s module.\n",
- stat->subdev.name, enable ? "enable" : "disable");
-
- mutex_lock(&stat->ioctl_lock);
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
- if (!stat->configured && enable) {
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- mutex_unlock(&stat->ioctl_lock);
- dev_dbg(stat->isp->dev,
- "%s: cannot enable module as it's never been successfully configured so far.\n",
- stat->subdev.name);
- return -EINVAL;
- }
- if (enable) {
- if (stat->state == ISPSTAT_DISABLING)
-
- stat->state = ISPSTAT_ENABLED;
- else if (stat->state == ISPSTAT_DISABLED)
-
- stat->state = ISPSTAT_ENABLING;
- } else {
- if (stat->state == ISPSTAT_ENABLING) {
-
- stat->state = ISPSTAT_DISABLED;
- } else if (stat->state == ISPSTAT_ENABLED) {
-
- stat->state = ISPSTAT_DISABLING;
- isp_stat_buf_clear(stat);
- }
- }
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- mutex_unlock(&stat->ioctl_lock);
- return 0;
- }
- int omap3isp_stat_s_stream(struct v4l2_subdev *subdev, int enable)
- {
- struct ispstat *stat = v4l2_get_subdevdata(subdev);
- if (enable) {
-
- isp_stat_try_enable(stat);
- } else {
- unsigned long flags;
-
- omap3isp_stat_enable(stat, 0);
- spin_lock_irqsave(&stat->isp->stat_lock, flags);
- stat->ops->enable(stat, 0);
- spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
-
- if (!omap3isp_stat_pcr_busy(stat))
- omap3isp_stat_isr(stat);
- dev_dbg(stat->isp->dev, "%s: module is being disabled\n",
- stat->subdev.name);
- }
- return 0;
- }
- static void __stat_isr(struct ispstat *stat, int from_dma)
- {
- int ret = STAT_BUF_DONE;
- int buf_processing;
- unsigned long irqflags;
- struct isp_pipeline *pipe;
-
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
- if (stat->state == ISPSTAT_DISABLED) {
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- return;
- }
- buf_processing = stat->buf_processing;
- stat->buf_processing = 1;
- stat->ops->enable(stat, 0);
- if (buf_processing && !from_dma) {
- if (stat->state == ISPSTAT_ENABLED) {
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- dev_err(stat->isp->dev,
- "%s: interrupt occurred when module was still processing a buffer.\n",
- stat->subdev.name);
- ret = STAT_NO_BUF;
- goto out;
- } else {
-
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- return;
- }
- }
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
-
- if (!omap3isp_stat_pcr_busy(stat)) {
- if (!from_dma && stat->ops->buf_process)
-
- ret = stat->ops->buf_process(stat);
- if (ret == STAT_BUF_WAITING_DMA)
-
- return;
- spin_lock_irqsave(&stat->isp->stat_lock, irqflags);
-
- if (stat->state == ISPSTAT_DISABLING) {
- stat->state = ISPSTAT_DISABLED;
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- stat->buf_processing = 0;
- return;
- }
- pipe = to_isp_pipeline(&stat->subdev.entity);
- stat->frame_number = atomic_read(&pipe->frame_number);
-
- ret = isp_stat_buf_process(stat, ret);
- if (likely(!stat->sbl_ovl_recover)) {
- stat->ops->setup_regs(stat, stat->priv);
- } else {
-
- stat->update = 1;
- stat->ops->setup_regs(stat, stat->recover_priv);
- stat->sbl_ovl_recover = 0;
-
- stat->update = 1;
- }
- isp_stat_buf_insert_magic(stat, stat->active_buf);
-
- isp_stat_pcr_enable(stat, 1);
- spin_unlock_irqrestore(&stat->isp->stat_lock, irqflags);
- } else {
-
- if (stat->ops->buf_process)
-
- atomic_set(&stat->buf_err, 1);
- ret = STAT_NO_BUF;
- dev_dbg(stat->isp->dev,
- "%s: cannot process buffer, device is busy.\n",
- stat->subdev.name);
- }
- out:
- stat->buf_processing = 0;
- isp_stat_queue_event(stat, ret != STAT_BUF_DONE);
- }
- void omap3isp_stat_isr(struct ispstat *stat)
- {
- __stat_isr(stat, 0);
- }
- void omap3isp_stat_dma_isr(struct ispstat *stat)
- {
- __stat_isr(stat, 1);
- }
- int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev,
- struct v4l2_fh *fh,
- struct v4l2_event_subscription *sub)
- {
- struct ispstat *stat = v4l2_get_subdevdata(subdev);
- if (sub->type != stat->event_type)
- return -EINVAL;
- return v4l2_event_subscribe(fh, sub, STAT_NEVENTS, NULL);
- }
- int omap3isp_stat_unsubscribe_event(struct v4l2_subdev *subdev,
- struct v4l2_fh *fh,
- struct v4l2_event_subscription *sub)
- {
- return v4l2_event_unsubscribe(fh, sub);
- }
- void omap3isp_stat_unregister_entities(struct ispstat *stat)
- {
- v4l2_device_unregister_subdev(&stat->subdev);
- }
- int omap3isp_stat_register_entities(struct ispstat *stat,
- struct v4l2_device *vdev)
- {
- stat->subdev.dev = vdev->mdev->dev;
- return v4l2_device_register_subdev(vdev, &stat->subdev);
- }
- static int isp_stat_init_entities(struct ispstat *stat, const char *name,
- const struct v4l2_subdev_ops *sd_ops)
- {
- struct v4l2_subdev *subdev = &stat->subdev;
- struct media_entity *me = &subdev->entity;
- v4l2_subdev_init(subdev, sd_ops);
- snprintf(subdev->name, V4L2_SUBDEV_NAME_SIZE, "OMAP3 ISP %s", name);
- subdev->grp_id = 1 << 16;
- subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
- v4l2_set_subdevdata(subdev, stat);
- stat->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
- me->ops = NULL;
- return media_entity_pads_init(me, 1, &stat->pad);
- }
- int omap3isp_stat_init(struct ispstat *stat, const char *name,
- const struct v4l2_subdev_ops *sd_ops)
- {
- int ret;
- stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL);
- if (!stat->buf)
- return -ENOMEM;
- isp_stat_buf_clear(stat);
- mutex_init(&stat->ioctl_lock);
- atomic_set(&stat->buf_err, 0);
- ret = isp_stat_init_entities(stat, name, sd_ops);
- if (ret < 0) {
- mutex_destroy(&stat->ioctl_lock);
- kfree(stat->buf);
- }
- return ret;
- }
- void omap3isp_stat_cleanup(struct ispstat *stat)
- {
- media_entity_cleanup(&stat->subdev.entity);
- mutex_destroy(&stat->ioctl_lock);
- isp_stat_bufs_free(stat);
- kfree(stat->buf);
- }
|