aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pxa_camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/pxa_camera.c')
-rw-r--r--drivers/media/video/pxa_camera.c92
1 files changed, 49 insertions, 43 deletions
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index b42bfa5ccdf2..d07df22a5ec6 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -22,7 +22,6 @@
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
24#include <linux/time.h> 24#include <linux/time.h>
25#include <linux/version.h>
26#include <linux/device.h> 25#include <linux/device.h>
27#include <linux/platform_device.h> 26#include <linux/platform_device.h>
28#include <linux/clk.h> 27#include <linux/clk.h>
@@ -40,7 +39,7 @@
40#include <mach/dma.h> 39#include <mach/dma.h>
41#include <mach/camera.h> 40#include <mach/camera.h>
42 41
43#define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5) 42#define PXA_CAM_VERSION "0.0.6"
44#define PXA_CAM_DRV_NAME "pxa27x-camera" 43#define PXA_CAM_DRV_NAME "pxa27x-camera"
45 44
46/* Camera Interface */ 45/* Camera Interface */
@@ -247,7 +246,7 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
247 if (bytes_per_line < 0) 246 if (bytes_per_line < 0)
248 return bytes_per_line; 247 return bytes_per_line;
249 248
250 dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); 249 dev_dbg(icd->parent, "count=%d, size=%d\n", *count, *size);
251 250
252 *size = bytes_per_line * icd->user_height; 251 *size = bytes_per_line * icd->user_height;
253 252
@@ -262,13 +261,13 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
262static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) 261static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
263{ 262{
264 struct soc_camera_device *icd = vq->priv_data; 263 struct soc_camera_device *icd = vq->priv_data;
265 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 264 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
266 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); 265 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
267 int i; 266 int i;
268 267
269 BUG_ON(in_interrupt()); 268 BUG_ON(in_interrupt());
270 269
271 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 270 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
272 &buf->vb, buf->vb.baddr, buf->vb.bsize); 271 &buf->vb, buf->vb.baddr, buf->vb.bsize);
273 272
274 /* 273 /*
@@ -429,7 +428,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
429 struct videobuf_buffer *vb, enum v4l2_field field) 428 struct videobuf_buffer *vb, enum v4l2_field field)
430{ 429{
431 struct soc_camera_device *icd = vq->priv_data; 430 struct soc_camera_device *icd = vq->priv_data;
432 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 431 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
433 struct pxa_camera_dev *pcdev = ici->priv; 432 struct pxa_camera_dev *pcdev = ici->priv;
434 struct device *dev = pcdev->soc_host.v4l2_dev.dev; 433 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
435 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 434 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
@@ -636,11 +635,11 @@ static void pxa_videobuf_queue(struct videobuf_queue *vq,
636 struct videobuf_buffer *vb) 635 struct videobuf_buffer *vb)
637{ 636{
638 struct soc_camera_device *icd = vq->priv_data; 637 struct soc_camera_device *icd = vq->priv_data;
639 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 638 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
640 struct pxa_camera_dev *pcdev = ici->priv; 639 struct pxa_camera_dev *pcdev = ici->priv;
641 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 640 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
642 641
643 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d active=%p\n", 642 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d active=%p\n",
644 __func__, vb, vb->baddr, vb->bsize, pcdev->active); 643 __func__, vb, vb->baddr, vb->bsize, pcdev->active);
645 644
646 list_add_tail(&vb->queue, &pcdev->capture); 645 list_add_tail(&vb->queue, &pcdev->capture);
@@ -658,7 +657,7 @@ static void pxa_videobuf_release(struct videobuf_queue *vq,
658 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 657 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
659#ifdef DEBUG 658#ifdef DEBUG
660 struct soc_camera_device *icd = vq->priv_data; 659 struct soc_camera_device *icd = vq->priv_data;
661 struct device *dev = icd->dev.parent; 660 struct device *dev = icd->parent;
662 661
663 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 662 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
664 vb, vb->baddr, vb->bsize); 663 vb, vb->baddr, vb->bsize);
@@ -843,7 +842,7 @@ static struct videobuf_queue_ops pxa_videobuf_ops = {
843static void pxa_camera_init_videobuf(struct videobuf_queue *q, 842static void pxa_camera_init_videobuf(struct videobuf_queue *q,
844 struct soc_camera_device *icd) 843 struct soc_camera_device *icd)
845{ 844{
846 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 845 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
847 struct pxa_camera_dev *pcdev = ici->priv; 846 struct pxa_camera_dev *pcdev = ici->priv;
848 847
849 /* 848 /*
@@ -972,7 +971,7 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
972 */ 971 */
973static int pxa_camera_add_device(struct soc_camera_device *icd) 972static int pxa_camera_add_device(struct soc_camera_device *icd)
974{ 973{
975 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 974 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
976 struct pxa_camera_dev *pcdev = ici->priv; 975 struct pxa_camera_dev *pcdev = ici->priv;
977 976
978 if (pcdev->icd) 977 if (pcdev->icd)
@@ -982,7 +981,7 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
982 981
983 pcdev->icd = icd; 982 pcdev->icd = icd;
984 983
985 dev_info(icd->dev.parent, "PXA Camera driver attached to camera %d\n", 984 dev_info(icd->parent, "PXA Camera driver attached to camera %d\n",
986 icd->devnum); 985 icd->devnum);
987 986
988 return 0; 987 return 0;
@@ -991,12 +990,12 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
991/* Called with .video_lock held */ 990/* Called with .video_lock held */
992static void pxa_camera_remove_device(struct soc_camera_device *icd) 991static void pxa_camera_remove_device(struct soc_camera_device *icd)
993{ 992{
994 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 993 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
995 struct pxa_camera_dev *pcdev = ici->priv; 994 struct pxa_camera_dev *pcdev = ici->priv;
996 995
997 BUG_ON(icd != pcdev->icd); 996 BUG_ON(icd != pcdev->icd);
998 997
999 dev_info(icd->dev.parent, "PXA Camera driver detached from camera %d\n", 998 dev_info(icd->parent, "PXA Camera driver detached from camera %d\n",
1000 icd->devnum); 999 icd->devnum);
1001 1000
1002 /* disable capture, disable interrupts */ 1001 /* disable capture, disable interrupts */
@@ -1057,7 +1056,7 @@ static int test_platform_param(struct pxa_camera_dev *pcdev,
1057static void pxa_camera_setup_cicr(struct soc_camera_device *icd, 1056static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1058 unsigned long flags, __u32 pixfmt) 1057 unsigned long flags, __u32 pixfmt)
1059{ 1058{
1060 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1059 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1061 struct pxa_camera_dev *pcdev = ici->priv; 1060 struct pxa_camera_dev *pcdev = ici->priv;
1062 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1061 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1063 unsigned long dw, bpp; 1062 unsigned long dw, bpp;
@@ -1152,7 +1151,7 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1152 1151
1153static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 1152static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1154{ 1153{
1155 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1154 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1156 struct pxa_camera_dev *pcdev = ici->priv; 1155 struct pxa_camera_dev *pcdev = ici->priv;
1157 unsigned long bus_flags, camera_flags, common_flags; 1156 unsigned long bus_flags, camera_flags, common_flags;
1158 int ret; 1157 int ret;
@@ -1210,7 +1209,7 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1210static int pxa_camera_try_bus_param(struct soc_camera_device *icd, 1209static int pxa_camera_try_bus_param(struct soc_camera_device *icd,
1211 unsigned char buswidth) 1210 unsigned char buswidth)
1212{ 1211{
1213 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1212 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1214 struct pxa_camera_dev *pcdev = ici->priv; 1213 struct pxa_camera_dev *pcdev = ici->priv;
1215 unsigned long bus_flags, camera_flags; 1214 unsigned long bus_flags, camera_flags;
1216 int ret = test_platform_param(pcdev, buswidth, &bus_flags); 1215 int ret = test_platform_param(pcdev, buswidth, &bus_flags);
@@ -1247,7 +1246,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1247 struct soc_camera_format_xlate *xlate) 1246 struct soc_camera_format_xlate *xlate)
1248{ 1247{
1249 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1248 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1250 struct device *dev = icd->dev.parent; 1249 struct device *dev = icd->parent;
1251 int formats = 0, ret; 1250 int formats = 0, ret;
1252 struct pxa_cam *cam; 1251 struct pxa_cam *cam;
1253 enum v4l2_mbus_pixelcode code; 1252 enum v4l2_mbus_pixelcode code;
@@ -1335,9 +1334,9 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1335 struct v4l2_crop *a) 1334 struct v4l2_crop *a)
1336{ 1335{
1337 struct v4l2_rect *rect = &a->c; 1336 struct v4l2_rect *rect = &a->c;
1338 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1337 struct device *dev = icd->parent;
1338 struct soc_camera_host *ici = to_soc_camera_host(dev);
1339 struct pxa_camera_dev *pcdev = ici->priv; 1339 struct pxa_camera_dev *pcdev = ici->priv;
1340 struct device *dev = icd->dev.parent;
1341 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1340 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1342 struct soc_camera_sense sense = { 1341 struct soc_camera_sense sense = {
1343 .master_clock = pcdev->mclk, 1342 .master_clock = pcdev->mclk,
@@ -1379,7 +1378,7 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1379 return ret; 1378 return ret;
1380 1379
1381 if (pxa_camera_check_frame(mf.width, mf.height)) { 1380 if (pxa_camera_check_frame(mf.width, mf.height)) {
1382 dev_warn(icd->dev.parent, 1381 dev_warn(icd->parent,
1383 "Inconsistent state. Use S_FMT to repair\n"); 1382 "Inconsistent state. Use S_FMT to repair\n");
1384 return -EINVAL; 1383 return -EINVAL;
1385 } 1384 }
@@ -1406,9 +1405,9 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1406static int pxa_camera_set_fmt(struct soc_camera_device *icd, 1405static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1407 struct v4l2_format *f) 1406 struct v4l2_format *f)
1408{ 1407{
1409 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1408 struct device *dev = icd->parent;
1409 struct soc_camera_host *ici = to_soc_camera_host(dev);
1410 struct pxa_camera_dev *pcdev = ici->priv; 1410 struct pxa_camera_dev *pcdev = ici->priv;
1411 struct device *dev = icd->dev.parent;
1412 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1411 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1413 const struct soc_camera_format_xlate *xlate = NULL; 1412 const struct soc_camera_format_xlate *xlate = NULL;
1414 struct soc_camera_sense sense = { 1413 struct soc_camera_sense sense = {
@@ -1485,7 +1484,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1485 1484
1486 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 1485 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1487 if (!xlate) { 1486 if (!xlate) {
1488 dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt); 1487 dev_warn(icd->parent, "Format %x not found\n", pixfmt);
1489 return -EINVAL; 1488 return -EINVAL;
1490 } 1489 }
1491 1490
@@ -1499,16 +1498,11 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1499 &pix->height, 32, 2048, 0, 1498 &pix->height, 32, 2048, 0,
1500 pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0); 1499 pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0);
1501 1500
1502 pix->bytesperline = soc_mbus_bytes_per_line(pix->width,
1503 xlate->host_fmt);
1504 if (pix->bytesperline < 0)
1505 return pix->bytesperline;
1506 pix->sizeimage = pix->height * pix->bytesperline;
1507
1508 /* limit to sensor capabilities */ 1501 /* limit to sensor capabilities */
1509 mf.width = pix->width; 1502 mf.width = pix->width;
1510 mf.height = pix->height; 1503 mf.height = pix->height;
1511 mf.field = pix->field; 1504 /* Only progressive video supported so far */
1505 mf.field = V4L2_FIELD_NONE;
1512 mf.colorspace = pix->colorspace; 1506 mf.colorspace = pix->colorspace;
1513 mf.code = xlate->code; 1507 mf.code = xlate->code;
1514 1508
@@ -1527,7 +1521,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1527 break; 1521 break;
1528 default: 1522 default:
1529 /* TODO: support interlaced at least in pass-through mode */ 1523 /* TODO: support interlaced at least in pass-through mode */
1530 dev_err(icd->dev.parent, "Field type %d unsupported.\n", 1524 dev_err(icd->parent, "Field type %d unsupported.\n",
1531 mf.field); 1525 mf.field);
1532 return -EINVAL; 1526 return -EINVAL;
1533 } 1527 }
@@ -1578,15 +1572,14 @@ static int pxa_camera_querycap(struct soc_camera_host *ici,
1578{ 1572{
1579 /* cap->name is set by the firendly caller:-> */ 1573 /* cap->name is set by the firendly caller:-> */
1580 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card)); 1574 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
1581 cap->version = PXA_CAM_VERSION_CODE;
1582 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 1575 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1583 1576
1584 return 0; 1577 return 0;
1585} 1578}
1586 1579
1587static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state) 1580static int pxa_camera_suspend(struct device *dev)
1588{ 1581{
1589 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1582 struct soc_camera_host *ici = to_soc_camera_host(dev);
1590 struct pxa_camera_dev *pcdev = ici->priv; 1583 struct pxa_camera_dev *pcdev = ici->priv;
1591 int i = 0, ret = 0; 1584 int i = 0, ret = 0;
1592 1585
@@ -1596,15 +1589,19 @@ static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state)
1596 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3); 1589 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3);
1597 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4); 1590 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4);
1598 1591
1599 if ((pcdev->icd) && (pcdev->icd->ops->suspend)) 1592 if (pcdev->icd) {
1600 ret = pcdev->icd->ops->suspend(pcdev->icd, state); 1593 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd);
1594 ret = v4l2_subdev_call(sd, core, s_power, 0);
1595 if (ret == -ENOIOCTLCMD)
1596 ret = 0;
1597 }
1601 1598
1602 return ret; 1599 return ret;
1603} 1600}
1604 1601
1605static int pxa_camera_resume(struct soc_camera_device *icd) 1602static int pxa_camera_resume(struct device *dev)
1606{ 1603{
1607 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1604 struct soc_camera_host *ici = to_soc_camera_host(dev);
1608 struct pxa_camera_dev *pcdev = ici->priv; 1605 struct pxa_camera_dev *pcdev = ici->priv;
1609 int i = 0, ret = 0; 1606 int i = 0, ret = 0;
1610 1607
@@ -1618,8 +1615,12 @@ static int pxa_camera_resume(struct soc_camera_device *icd)
1618 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3); 1615 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3);
1619 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4); 1616 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4);
1620 1617
1621 if ((pcdev->icd) && (pcdev->icd->ops->resume)) 1618 if (pcdev->icd) {
1622 ret = pcdev->icd->ops->resume(pcdev->icd); 1619 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd);
1620 ret = v4l2_subdev_call(sd, core, s_power, 1);
1621 if (ret == -ENOIOCTLCMD)
1622 ret = 0;
1623 }
1623 1624
1624 /* Restart frame capture if active buffer exists */ 1625 /* Restart frame capture if active buffer exists */
1625 if (!ret && pcdev->active) 1626 if (!ret && pcdev->active)
@@ -1632,8 +1633,6 @@ static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
1632 .owner = THIS_MODULE, 1633 .owner = THIS_MODULE,
1633 .add = pxa_camera_add_device, 1634 .add = pxa_camera_add_device,
1634 .remove = pxa_camera_remove_device, 1635 .remove = pxa_camera_remove_device,
1635 .suspend = pxa_camera_suspend,
1636 .resume = pxa_camera_resume,
1637 .set_crop = pxa_camera_set_crop, 1636 .set_crop = pxa_camera_set_crop,
1638 .get_formats = pxa_camera_get_formats, 1637 .get_formats = pxa_camera_get_formats,
1639 .put_formats = pxa_camera_put_formats, 1638 .put_formats = pxa_camera_put_formats,
@@ -1818,9 +1817,15 @@ static int __devexit pxa_camera_remove(struct platform_device *pdev)
1818 return 0; 1817 return 0;
1819} 1818}
1820 1819
1820static struct dev_pm_ops pxa_camera_pm = {
1821 .suspend = pxa_camera_suspend,
1822 .resume = pxa_camera_resume,
1823};
1824
1821static struct platform_driver pxa_camera_driver = { 1825static struct platform_driver pxa_camera_driver = {
1822 .driver = { 1826 .driver = {
1823 .name = PXA_CAM_DRV_NAME, 1827 .name = PXA_CAM_DRV_NAME,
1828 .pm = &pxa_camera_pm,
1824 }, 1829 },
1825 .probe = pxa_camera_probe, 1830 .probe = pxa_camera_probe,
1826 .remove = __devexit_p(pxa_camera_remove), 1831 .remove = __devexit_p(pxa_camera_remove),
@@ -1843,4 +1848,5 @@ module_exit(pxa_camera_exit);
1843MODULE_DESCRIPTION("PXA27x SoC Camera Host driver"); 1848MODULE_DESCRIPTION("PXA27x SoC Camera Host driver");
1844MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); 1849MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1845MODULE_LICENSE("GPL"); 1850MODULE_LICENSE("GPL");
1851MODULE_VERSION(PXA_CAM_VERSION);
1846MODULE_ALIAS("platform:" PXA_CAM_DRV_NAME); 1852MODULE_ALIAS("platform:" PXA_CAM_DRV_NAME);