Lines Matching refs:meye
45 #include "meye.h"
46 #include <linux/meye.h>
70 static struct meye meye;
112 * NOTE: The meye device expects DMA addresses on 32 bits, we build
120 memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
123 if (dma_set_mask(&meye.mchip_dev->dev, DMA_BIT_MASK(32)))
126 meye.mchip_ptable_toc = dma_alloc_coherent(&meye.mchip_dev->dev,
128 &meye.mchip_dmahandle,
130 if (!meye.mchip_ptable_toc) {
131 meye.mchip_dmahandle = 0;
135 pt = meye.mchip_ptable_toc;
138 meye.mchip_ptable[i] = dma_alloc_coherent(&meye.mchip_dev->dev,
142 if (!meye.mchip_ptable[i]) {
144 pt = meye.mchip_ptable_toc;
147 dma_free_coherent(&meye.mchip_dev->dev,
149 meye.mchip_ptable[j], dma);
152 dma_free_coherent(&meye.mchip_dev->dev,
154 meye.mchip_ptable_toc,
155 meye.mchip_dmahandle);
156 meye.mchip_ptable_toc = NULL;
157 meye.mchip_dmahandle = 0;
171 pt = meye.mchip_ptable_toc;
174 if (meye.mchip_ptable[i])
175 dma_free_coherent(&meye.mchip_dev->dev,
177 meye.mchip_ptable[i], dma);
181 if (meye.mchip_ptable_toc)
182 dma_free_coherent(&meye.mchip_dev->dev,
184 meye.mchip_ptable_toc,
185 meye.mchip_dmahandle);
187 memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
188 meye.mchip_ptable_toc = NULL;
189 meye.mchip_dmahandle = 0;
198 memcpy(buf + i, meye.mchip_ptable[start++], PAGE_SIZE);
202 memcpy(buf + i, meye.mchip_ptable[start], size % PAGE_SIZE);
347 "meye: invalid quality level %d - using 8\n", quality);
402 return meye.params.subsample ? 320 : 640;
408 return meye.params.subsample ? 240 : 480;
419 status = readl(meye.mchip_mmregs +
422 printk(KERN_WARNING "meye: fifo not ready\n");
433 status = readl(meye.mchip_mmregs + MCHIP_HIC_STATUS);
441 "meye: mchip_sync() timeout on reg 0x%x status=0x%x\n",
449 writel(v, meye.mchip_mmregs + reg);
456 return readl(meye.mchip_mmregs + reg);
471 mchip_set(MCHIP_MCC_R_SAMPLING, meye.params.subsample);
482 mchip_set(MCHIP_HIC_S_RATE, meye.params.framerate);
495 writel(tables[i], meye.mchip_mmregs + MCHIP_VRJ_TABLE_DATA);
497 tables = jpeg_quantisation_tables(&length, meye.params.quality);
499 writel(tables[i], meye.mchip_mmregs + MCHIP_VRJ_TABLE_DATA);
534 meye.mchip_fnum = 0;
540 if (!meye.mchip_dmahandle)
549 if (meye.mchip_dmahandle) {
561 meye.mchip_mode = MCHIP_HIC_MODE_NOOP;
573 printk(KERN_ERR "meye: need to reset HIC!\n");
578 printk(KERN_ERR "meye: resetting HIC hanged!\n");
590 v = mchip_read(MCHIP_MM_FIR(meye.mchip_fnum));
597 mchip_set(MCHIP_MM_FIR(meye.mchip_fnum), 0);
598 meye.mchip_fnum++;
599 meye.mchip_fnum %= 4;
631 printk(KERN_WARNING "meye: oversized compressed frame %d\n",
665 mchip_dma_setup(meye.mchip_dmahandle);
710 mchip_dma_setup(meye.mchip_dmahandle);
712 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
758 mchip_dma_setup(meye.mchip_dmahandle);
760 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
780 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_OUT &&
781 meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
789 if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) {
790 if (kfifo_out_locked(&meye.grabq, (unsigned char *)&reqnr,
791 sizeof(int), &meye.grabq_lock) != sizeof(int)) {
795 mchip_cont_read_frame(v, meye.grab_fbuffer + gbufsize * reqnr,
797 meye.grab_buffer[reqnr].size = mchip_hsize() * mchip_vsize() * 2;
798 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
799 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
800 meye.grab_buffer[reqnr].sequence = sequence++;
801 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr,
802 sizeof(int), &meye.doneq_lock);
803 wake_up_interruptible(&meye.proc_list);
806 size = mchip_comp_read_frame(v, meye.grab_temp, gbufsize);
811 if (kfifo_out_locked(&meye.grabq, (unsigned char *)&reqnr,
812 sizeof(int), &meye.grabq_lock) != sizeof(int)) {
816 memcpy(meye.grab_fbuffer + gbufsize * reqnr, meye.grab_temp,
818 meye.grab_buffer[reqnr].size = size;
819 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
820 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
821 meye.grab_buffer[reqnr].sequence = sequence++;
822 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr,
823 sizeof(int), &meye.doneq_lock);
824 wake_up_interruptible(&meye.proc_list);
838 if (test_and_set_bit(0, &meye.in_use))
844 printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
845 clear_bit(0, &meye.in_use);
850 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
851 kfifo_reset(&meye.grabq);
852 kfifo_reset(&meye.doneq);
860 clear_bit(0, &meye.in_use);
866 *p = meye.params;
884 mutex_lock(&meye.lock);
886 if (meye.params.subsample != jp->subsample ||
887 meye.params.quality != jp->quality)
890 meye.params = *jp;
892 meye.params.sharpness);
894 meye.params.agc);
896 meye.params.picture);
897 mutex_unlock(&meye.lock);
904 if (!meye.grab_fbuffer)
916 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
919 mutex_lock(&meye.lock);
921 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
924 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
925 kfifo_in_locked(&meye.grabq, (unsigned char *)nb, sizeof(int),
926 &meye.grabq_lock);
927 mutex_unlock(&meye.lock);
939 mutex_lock(&meye.lock);
940 switch (meye.grab_buffer[*i].state) {
943 mutex_unlock(&meye.lock);
947 mutex_unlock(&meye.lock);
950 if (wait_event_interruptible(meye.proc_list,
951 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
952 mutex_unlock(&meye.lock);
957 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
958 if (kfifo_out_locked(&meye.doneq, (unsigned char *)&unused,
959 sizeof(int), &meye.doneq_lock) != sizeof(int))
962 *i = meye.grab_buffer[*i].size;
963 mutex_unlock(&meye.lock);
969 if (!meye.grab_fbuffer)
972 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
975 mutex_lock(&meye.lock);
976 meye.grab_buffer[0].state = MEYE_BUF_USING;
979 mchip_get_picture(meye.grab_fbuffer,
982 meye.grab_buffer[0].state = MEYE_BUF_DONE;
983 mutex_unlock(&meye.lock);
990 if (!meye.grab_fbuffer)
993 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
996 mutex_lock(&meye.lock);
997 meye.grab_buffer[0].state = MEYE_BUF_USING;
1002 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1005 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1006 mutex_unlock(&meye.lock);
1013 strcpy(cap->driver, "meye");
1014 strcpy(cap->card, "meye");
1015 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev));
1152 mutex_lock(&meye.lock);
1157 meye.brightness = c->value << 10;
1162 meye.hue = c->value << 10;
1167 meye.contrast = c->value << 10;
1172 meye.colour = c->value << 10;
1177 meye.params.agc = c->value;
1183 meye.params.sharpness = c->value;
1188 meye.params.picture = c->value;
1191 meye.params.quality = c->value;
1194 meye.params.framerate = c->value;
1197 mutex_unlock(&meye.lock);
1200 mutex_unlock(&meye.lock);
1207 mutex_lock(&meye.lock);
1210 c->value = meye.brightness >> 10;
1213 c->value = meye.hue >> 10;
1216 c->value = meye.contrast >> 10;
1219 c->value = meye.colour >> 10;
1222 c->value = meye.params.agc;
1226 c->value = meye.params.sharpness;
1229 c->value = meye.params.picture;
1232 c->value = meye.params.quality;
1235 c->value = meye.params.framerate;
1238 mutex_unlock(&meye.lock);
1241 mutex_unlock(&meye.lock);
1300 switch (meye.mchip_mode) {
1332 mutex_lock(&meye.lock);
1337 meye.params.subsample = 1;
1341 meye.params.subsample = 0;
1346 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
1349 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1353 mutex_unlock(&meye.lock);
1371 if (meye.grab_fbuffer && req->count == gbuffers) {
1376 mutex_lock(&meye.lock);
1377 if (meye.grab_fbuffer) {
1379 if (meye.vma_use_count[i]) {
1380 mutex_unlock(&meye.lock);
1383 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
1384 meye.grab_fbuffer = NULL;
1389 meye.grab_fbuffer = rvmalloc(gbuffers * gbufsize);
1391 if (!meye.grab_fbuffer) {
1392 printk(KERN_ERR "meye: v4l framebuffer allocation"
1394 mutex_unlock(&meye.lock);
1399 meye.vma_use_count[i] = 0;
1401 mutex_unlock(&meye.lock);
1413 buf->bytesused = meye.grab_buffer[index].size;
1416 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1419 if (meye.grab_buffer[index].state == MEYE_BUF_DONE)
1423 buf->timestamp = meye.grab_buffer[index].timestamp;
1424 buf->sequence = meye.grab_buffer[index].sequence;
1440 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1443 mutex_lock(&meye.lock);
1446 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1447 kfifo_in_locked(&meye.grabq, (unsigned char *)&buf->index,
1448 sizeof(int), &meye.grabq_lock);
1449 mutex_unlock(&meye.lock);
1461 mutex_lock(&meye.lock);
1463 if (kfifo_len(&meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
1464 mutex_unlock(&meye.lock);
1468 if (wait_event_interruptible(meye.proc_list,
1469 kfifo_len(&meye.doneq) != 0) < 0) {
1470 mutex_unlock(&meye.lock);
1474 if (!kfifo_out_locked(&meye.doneq, (unsigned char *)&reqnr,
1475 sizeof(int), &meye.doneq_lock)) {
1476 mutex_unlock(&meye.lock);
1480 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) {
1481 mutex_unlock(&meye.lock);
1486 buf->bytesused = meye.grab_buffer[reqnr].size;
1489 buf->timestamp = meye.grab_buffer[reqnr].timestamp;
1490 buf->sequence = meye.grab_buffer[reqnr].sequence;
1494 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED;
1495 mutex_unlock(&meye.lock);
1502 mutex_lock(&meye.lock);
1504 switch (meye.mchip_mode) {
1512 mutex_unlock(&meye.lock);
1516 mutex_unlock(&meye.lock);
1523 mutex_lock(&meye.lock);
1525 kfifo_reset(&meye.grabq);
1526 kfifo_reset(&meye.doneq);
1529 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1531 mutex_unlock(&meye.lock);
1566 mutex_lock(&meye.lock);
1567 poll_wait(file, &meye.proc_list, wait);
1568 if (kfifo_len(&meye.doneq))
1570 mutex_unlock(&meye.lock);
1577 meye.vma_use_count[idx]++;
1583 meye.vma_use_count[idx]--;
1598 mutex_lock(&meye.lock);
1600 mutex_unlock(&meye.lock);
1603 if (!meye.grab_fbuffer) {
1607 meye.grab_fbuffer = rvmalloc(gbuffers*gbufsize);
1608 if (!meye.grab_fbuffer) {
1609 printk(KERN_ERR "meye: v4l framebuffer allocation failed\n");
1610 mutex_unlock(&meye.lock);
1614 meye.vma_use_count[i] = 0;
1616 pos = (unsigned long)meye.grab_fbuffer + offset;
1621 mutex_unlock(&meye.lock);
1638 mutex_unlock(&meye.lock);
1673 .name = "meye",
1683 meye.pm_mchip_mode = meye.mchip_mode;
1692 pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1);
1703 switch (meye.pm_mchip_mode) {
1718 struct v4l2_device *v4l2_dev = &meye.v4l2_dev;
1722 if (meye.mchip_dev != NULL) {
1723 printk(KERN_ERR "meye: only one device allowed!\n");
1733 meye.mchip_dev = pcidev;
1734 meye.vdev = video_device_alloc();
1735 if (!meye.vdev) {
1740 meye.grab_temp = vmalloc(MCHIP_NB_PAGES_MJPEG * PAGE_SIZE);
1741 if (!meye.grab_temp) {
1746 spin_lock_init(&meye.grabq_lock);
1747 if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS,
1752 spin_lock_init(&meye.doneq_lock);
1753 if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS,
1759 memcpy(meye.vdev, &meye_template, sizeof(meye_template));
1760 meye.vdev->v4l2_dev = &meye.v4l2_dev;
1764 v4l2_err(v4l2_dev, "meye: unable to power on the camera\n");
1765 v4l2_err(v4l2_dev, "meye: did you enable the camera in "
1770 if ((ret = pci_enable_device(meye.mchip_dev))) {
1771 v4l2_err(v4l2_dev, "meye: pci_enable_device failed\n");
1775 mchip_adr = pci_resource_start(meye.mchip_dev,0);
1777 v4l2_err(v4l2_dev, "meye: mchip has no device base address\n");
1780 if (!request_mem_region(pci_resource_start(meye.mchip_dev, 0),
1781 pci_resource_len(meye.mchip_dev, 0),
1782 "meye")) {
1783 v4l2_err(v4l2_dev, "meye: request_mem_region failed\n");
1786 meye.mchip_mmregs = ioremap(mchip_adr, MCHIP_MM_REGS);
1787 if (!meye.mchip_mmregs) {
1788 v4l2_err(v4l2_dev, "meye: ioremap failed\n");
1792 meye.mchip_irq = pcidev->irq;
1793 if (request_irq(meye.mchip_irq, meye_irq,
1794 IRQF_DISABLED | IRQF_SHARED, "meye", meye_irq)) {
1799 pci_write_config_byte(meye.mchip_dev, PCI_CACHE_LINE_SIZE, 8);
1800 pci_write_config_byte(meye.mchip_dev, PCI_LATENCY_TIMER, 64);
1802 pci_set_master(meye.mchip_dev);
1805 pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1);
1819 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
1825 mutex_init(&meye.lock);
1826 init_waitqueue_head(&meye.proc_list);
1827 meye.brightness = 32 << 10;
1828 meye.hue = 32 << 10;
1829 meye.colour = 32 << 10;
1830 meye.contrast = 32 << 10;
1831 meye.params.subsample = 0;
1832 meye.params.quality = 8;
1833 meye.params.sharpness = 32;
1834 meye.params.agc = 48;
1835 meye.params.picture = 0;
1836 meye.params.framerate = 0;
1849 meye.mchip_dev->revision, mchip_adr, meye.mchip_irq);
1854 free_irq(meye.mchip_irq, meye_irq);
1856 iounmap(meye.mchip_mmregs);
1858 release_mem_region(pci_resource_start(meye.mchip_dev, 0),
1859 pci_resource_len(meye.mchip_dev, 0));
1861 pci_disable_device(meye.mchip_dev);
1865 kfifo_free(&meye.doneq);
1867 kfifo_free(&meye.grabq);
1869 vfree(meye.grab_temp);
1871 video_device_release(meye.vdev);
1878 video_unregister_device(meye.vdev);
1887 free_irq(meye.mchip_irq, meye_irq);
1889 iounmap(meye.mchip_mmregs);
1891 release_mem_region(pci_resource_start(meye.mchip_dev, 0),
1892 pci_resource_len(meye.mchip_dev, 0));
1894 pci_disable_device(meye.mchip_dev);
1898 kfifo_free(&meye.doneq);
1899 kfifo_free(&meye.grabq);
1901 vfree(meye.grab_temp);
1903 if (meye.grab_fbuffer) {
1904 rvfree(meye.grab_fbuffer, gbuffers*gbufsize);
1905 meye.grab_fbuffer = NULL;
1908 printk(KERN_INFO "meye: removed\n");
1919 .name = "meye",
1935 printk(KERN_INFO "meye: using %d buffers with %dk (%dk total) "