Commit f7f6ce2d authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] soc-camera: move common code to soc_camera.c

All soc-camera host drivers include a pointer to an soc-camera device in
their host private struct to check, that only one client is connected.
Move this common code to soc_camera.c.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent b9d4b2da
...@@ -102,7 +102,6 @@ struct atmel_isi { ...@@ -102,7 +102,6 @@ struct atmel_isi {
struct list_head video_buffer_list; struct list_head video_buffer_list;
struct frame_buffer *active; struct frame_buffer *active;
struct soc_camera_device *icd;
struct soc_camera_host soc_host; struct soc_camera_host soc_host;
}; };
...@@ -367,7 +366,7 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer) ...@@ -367,7 +366,7 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
/* Check if already in a frame */ /* Check if already in a frame */
if (isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) { if (isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) {
dev_err(isi->icd->parent, "Already in frame handling.\n"); dev_err(isi->soc_host.icd->parent, "Already in frame handling.\n");
return; return;
} }
...@@ -753,9 +752,6 @@ static int isi_camera_add_device(struct soc_camera_device *icd) ...@@ -753,9 +752,6 @@ static int isi_camera_add_device(struct soc_camera_device *icd)
struct atmel_isi *isi = ici->priv; struct atmel_isi *isi = ici->priv;
int ret; int ret;
if (isi->icd)
return -EBUSY;
ret = clk_enable(isi->pclk); ret = clk_enable(isi->pclk);
if (ret) if (ret)
return ret; return ret;
...@@ -766,7 +762,6 @@ static int isi_camera_add_device(struct soc_camera_device *icd) ...@@ -766,7 +762,6 @@ static int isi_camera_add_device(struct soc_camera_device *icd)
return ret; return ret;
} }
isi->icd = icd;
dev_dbg(icd->parent, "Atmel ISI Camera driver attached to camera %d\n", dev_dbg(icd->parent, "Atmel ISI Camera driver attached to camera %d\n",
icd->devnum); icd->devnum);
return 0; return 0;
...@@ -777,11 +772,8 @@ static void isi_camera_remove_device(struct soc_camera_device *icd) ...@@ -777,11 +772,8 @@ static void isi_camera_remove_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct atmel_isi *isi = ici->priv; struct atmel_isi *isi = ici->priv;
BUG_ON(icd != isi->icd);
clk_disable(isi->mck); clk_disable(isi->mck);
clk_disable(isi->pclk); clk_disable(isi->pclk);
isi->icd = NULL;
dev_dbg(icd->parent, "Atmel ISI Camera driver detached from camera %d\n", dev_dbg(icd->parent, "Atmel ISI Camera driver detached from camera %d\n",
icd->devnum); icd->devnum);
......
...@@ -104,7 +104,6 @@ struct mx1_buffer { ...@@ -104,7 +104,6 @@ struct mx1_buffer {
*/ */
struct mx1_camera_dev { struct mx1_camera_dev {
struct soc_camera_host soc_host; struct soc_camera_host soc_host;
struct soc_camera_device *icd;
struct mx1_camera_pdata *pdata; struct mx1_camera_pdata *pdata;
struct mx1_buffer *active; struct mx1_buffer *active;
struct resource *res; struct resource *res;
...@@ -220,7 +219,7 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq, ...@@ -220,7 +219,7 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq,
static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev) static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
{ {
struct videobuf_buffer *vbuf = &pcdev->active->vb; struct videobuf_buffer *vbuf = &pcdev->active->vb;
struct device *dev = pcdev->icd->parent; struct device *dev = pcdev->soc_host.icd->parent;
int ret; int ret;
if (unlikely(!pcdev->active)) { if (unlikely(!pcdev->active)) {
...@@ -331,7 +330,7 @@ static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev, ...@@ -331,7 +330,7 @@ static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev,
static void mx1_camera_dma_irq(int channel, void *data) static void mx1_camera_dma_irq(int channel, void *data)
{ {
struct mx1_camera_dev *pcdev = data; struct mx1_camera_dev *pcdev = data;
struct device *dev = pcdev->icd->parent; struct device *dev = pcdev->soc_host.icd->parent;
struct mx1_buffer *buf; struct mx1_buffer *buf;
struct videobuf_buffer *vb; struct videobuf_buffer *vb;
unsigned long flags; unsigned long flags;
...@@ -389,7 +388,7 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev) ...@@ -389,7 +388,7 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
*/ */
div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
dev_dbg(pcdev->icd->parent, dev_dbg(pcdev->soc_host.icd->parent,
"System clock %lukHz, target freq %dkHz, divisor %lu\n", "System clock %lukHz, target freq %dkHz, divisor %lu\n",
lcdclk / 1000, mclk / 1000, div); lcdclk / 1000, mclk / 1000, div);
...@@ -400,7 +399,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev) ...@@ -400,7 +399,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
{ {
unsigned int csicr1 = CSICR1_EN; unsigned int csicr1 = CSICR1_EN;
dev_dbg(pcdev->icd->parent, "Activate device\n"); dev_dbg(pcdev->soc_host.icd->parent, "Activate device\n");
clk_prepare_enable(pcdev->clk); clk_prepare_enable(pcdev->clk);
...@@ -416,7 +415,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev) ...@@ -416,7 +415,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev) static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
{ {
dev_dbg(pcdev->icd->parent, "Deactivate device\n"); dev_dbg(pcdev->soc_host.icd->parent, "Deactivate device\n");
/* Disable all CSI interface */ /* Disable all CSI interface */
__raw_writel(0x00, pcdev->base + CSICR1); __raw_writel(0x00, pcdev->base + CSICR1);
...@@ -433,16 +432,11 @@ static int mx1_camera_add_device(struct soc_camera_device *icd) ...@@ -433,16 +432,11 @@ static int mx1_camera_add_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct mx1_camera_dev *pcdev = ici->priv; struct mx1_camera_dev *pcdev = ici->priv;
if (pcdev->icd)
return -EBUSY;
dev_info(icd->parent, "MX1 Camera driver attached to camera %d\n", dev_info(icd->parent, "MX1 Camera driver attached to camera %d\n",
icd->devnum); icd->devnum);
mx1_camera_activate(pcdev); mx1_camera_activate(pcdev);
pcdev->icd = icd;
return 0; return 0;
} }
...@@ -452,8 +446,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd) ...@@ -452,8 +446,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
struct mx1_camera_dev *pcdev = ici->priv; struct mx1_camera_dev *pcdev = ici->priv;
unsigned int csicr1; unsigned int csicr1;
BUG_ON(icd != pcdev->icd);
/* disable interrupts */ /* disable interrupts */
csicr1 = __raw_readl(pcdev->base + CSICR1) & ~CSI_IRQ_MASK; csicr1 = __raw_readl(pcdev->base + CSICR1) & ~CSI_IRQ_MASK;
__raw_writel(csicr1, pcdev->base + CSICR1); __raw_writel(csicr1, pcdev->base + CSICR1);
...@@ -465,8 +457,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd) ...@@ -465,8 +457,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
icd->devnum); icd->devnum);
mx1_camera_deactivate(pcdev); mx1_camera_deactivate(pcdev);
pcdev->icd = NULL;
} }
static int mx1_camera_set_bus_param(struct soc_camera_device *icd) static int mx1_camera_set_bus_param(struct soc_camera_device *icd)
......
...@@ -236,7 +236,6 @@ enum mx2_camera_type { ...@@ -236,7 +236,6 @@ enum mx2_camera_type {
struct mx2_camera_dev { struct mx2_camera_dev {
struct device *dev; struct device *dev;
struct soc_camera_host soc_host; struct soc_camera_host soc_host;
struct soc_camera_device *icd;
struct clk *clk_emma_ahb, *clk_emma_ipg; struct clk *clk_emma_ahb, *clk_emma_ipg;
struct clk *clk_csi_ahb, *clk_csi_per; struct clk *clk_csi_ahb, *clk_csi_per;
...@@ -394,8 +393,8 @@ static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev, ...@@ -394,8 +393,8 @@ static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev,
writel(phys, pcdev->base_emma + writel(phys, pcdev->base_emma +
PRP_DEST_Y_PTR - 0x14 * bufnum); PRP_DEST_Y_PTR - 0x14 * bufnum);
if (prp->out_fmt == V4L2_PIX_FMT_YUV420) { if (prp->out_fmt == V4L2_PIX_FMT_YUV420) {
u32 imgsize = pcdev->icd->user_height * u32 imgsize = pcdev->soc_host.icd->user_height *
pcdev->icd->user_width; pcdev->soc_host.icd->user_width;
writel(phys + imgsize, pcdev->base_emma + writel(phys + imgsize, pcdev->base_emma +
PRP_DEST_CB_PTR - 0x14 * bufnum); PRP_DEST_CB_PTR - 0x14 * bufnum);
...@@ -424,9 +423,6 @@ static int mx2_camera_add_device(struct soc_camera_device *icd) ...@@ -424,9 +423,6 @@ static int mx2_camera_add_device(struct soc_camera_device *icd)
int ret; int ret;
u32 csicr1; u32 csicr1;
if (pcdev->icd)
return -EBUSY;
ret = clk_prepare_enable(pcdev->clk_csi_ahb); ret = clk_prepare_enable(pcdev->clk_csi_ahb);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -441,7 +437,6 @@ static int mx2_camera_add_device(struct soc_camera_device *icd) ...@@ -441,7 +437,6 @@ static int mx2_camera_add_device(struct soc_camera_device *icd)
pcdev->csicr1 = csicr1; pcdev->csicr1 = csicr1;
writel(pcdev->csicr1, pcdev->base_csi + CSICR1); writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
pcdev->icd = icd;
pcdev->frame_count = 0; pcdev->frame_count = 0;
dev_info(icd->parent, "Camera driver attached to camera %d\n", dev_info(icd->parent, "Camera driver attached to camera %d\n",
...@@ -460,14 +455,10 @@ static void mx2_camera_remove_device(struct soc_camera_device *icd) ...@@ -460,14 +455,10 @@ static void mx2_camera_remove_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct mx2_camera_dev *pcdev = ici->priv; struct mx2_camera_dev *pcdev = ici->priv;
BUG_ON(icd != pcdev->icd);
dev_info(icd->parent, "Camera driver detached from camera %d\n", dev_info(icd->parent, "Camera driver detached from camera %d\n",
icd->devnum); icd->devnum);
mx2_camera_deactivate(pcdev); mx2_camera_deactivate(pcdev);
pcdev->icd = NULL;
} }
/* /*
......
...@@ -94,7 +94,6 @@ struct mx3_camera_dev { ...@@ -94,7 +94,6 @@ struct mx3_camera_dev {
* Interface. If anyone ever builds hardware to enable more than one * Interface. If anyone ever builds hardware to enable more than one
* camera _simultaneously_, they will have to modify this driver too * camera _simultaneously_, they will have to modify this driver too
*/ */
struct soc_camera_device *icd;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
...@@ -517,13 +516,9 @@ static int mx3_camera_add_device(struct soc_camera_device *icd) ...@@ -517,13 +516,9 @@ static int mx3_camera_add_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct mx3_camera_dev *mx3_cam = ici->priv; struct mx3_camera_dev *mx3_cam = ici->priv;
if (mx3_cam->icd)
return -EBUSY;
mx3_camera_activate(mx3_cam, icd); mx3_camera_activate(mx3_cam, icd);
mx3_cam->buf_total = 0; mx3_cam->buf_total = 0;
mx3_cam->icd = icd;
dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n", dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n",
icd->devnum); icd->devnum);
...@@ -538,8 +533,6 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd) ...@@ -538,8 +533,6 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd)
struct mx3_camera_dev *mx3_cam = ici->priv; struct mx3_camera_dev *mx3_cam = ici->priv;
struct idmac_channel **ichan = &mx3_cam->idmac_channel[0]; struct idmac_channel **ichan = &mx3_cam->idmac_channel[0];
BUG_ON(icd != mx3_cam->icd);
if (*ichan) { if (*ichan) {
dma_release_channel(&(*ichan)->dma_chan); dma_release_channel(&(*ichan)->dma_chan);
*ichan = NULL; *ichan = NULL;
...@@ -547,8 +540,6 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd) ...@@ -547,8 +540,6 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd)
clk_disable_unprepare(mx3_cam->clk); clk_disable_unprepare(mx3_cam->clk);
mx3_cam->icd = NULL;
dev_info(icd->parent, "MX3 Camera driver detached from camera %d\n", dev_info(icd->parent, "MX3 Camera driver detached from camera %d\n",
icd->devnum); icd->devnum);
} }
......
...@@ -150,7 +150,6 @@ struct omap1_cam_buf { ...@@ -150,7 +150,6 @@ struct omap1_cam_buf {
struct omap1_cam_dev { struct omap1_cam_dev {
struct soc_camera_host soc_host; struct soc_camera_host soc_host;
struct soc_camera_device *icd;
struct clk *clk; struct clk *clk;
unsigned int irq; unsigned int irq;
...@@ -564,7 +563,7 @@ static void videobuf_done(struct omap1_cam_dev *pcdev, ...@@ -564,7 +563,7 @@ static void videobuf_done(struct omap1_cam_dev *pcdev,
{ {
struct omap1_cam_buf *buf = pcdev->active; struct omap1_cam_buf *buf = pcdev->active;
struct videobuf_buffer *vb; struct videobuf_buffer *vb;
struct device *dev = pcdev->icd->parent; struct device *dev = pcdev->soc_host.icd->parent;
if (WARN_ON(!buf)) { if (WARN_ON(!buf)) {
suspend_capture(pcdev); suspend_capture(pcdev);
...@@ -790,7 +789,7 @@ static void dma_isr(int channel, unsigned short status, void *data) ...@@ -790,7 +789,7 @@ static void dma_isr(int channel, unsigned short status, void *data)
static irqreturn_t cam_isr(int irq, void *data) static irqreturn_t cam_isr(int irq, void *data)
{ {
struct omap1_cam_dev *pcdev = data; struct omap1_cam_dev *pcdev = data;
struct device *dev = pcdev->icd->parent; struct device *dev = pcdev->soc_host.icd->parent;
struct omap1_cam_buf *buf = pcdev->active; struct omap1_cam_buf *buf = pcdev->active;
u32 it_status; u32 it_status;
unsigned long flags; unsigned long flags;
...@@ -904,9 +903,6 @@ static int omap1_cam_add_device(struct soc_camera_device *icd) ...@@ -904,9 +903,6 @@ static int omap1_cam_add_device(struct soc_camera_device *icd)
struct omap1_cam_dev *pcdev = ici->priv; struct omap1_cam_dev *pcdev = ici->priv;
u32 ctrlclock; u32 ctrlclock;
if (pcdev->icd)
return -EBUSY;
clk_enable(pcdev->clk); clk_enable(pcdev->clk);
/* setup sensor clock */ /* setup sensor clock */
...@@ -941,8 +937,6 @@ static int omap1_cam_add_device(struct soc_camera_device *icd) ...@@ -941,8 +937,6 @@ static int omap1_cam_add_device(struct soc_camera_device *icd)
sensor_reset(pcdev, false); sensor_reset(pcdev, false);
pcdev->icd = icd;
dev_dbg(icd->parent, "OMAP1 Camera driver attached to camera %d\n", dev_dbg(icd->parent, "OMAP1 Camera driver attached to camera %d\n",
icd->devnum); icd->devnum);
return 0; return 0;
...@@ -954,8 +948,6 @@ static void omap1_cam_remove_device(struct soc_camera_device *icd) ...@@ -954,8 +948,6 @@ static void omap1_cam_remove_device(struct soc_camera_device *icd)
struct omap1_cam_dev *pcdev = ici->priv; struct omap1_cam_dev *pcdev = ici->priv;
u32 ctrlclock; u32 ctrlclock;
BUG_ON(icd != pcdev->icd);
suspend_capture(pcdev); suspend_capture(pcdev);
disable_capture(pcdev); disable_capture(pcdev);
...@@ -974,8 +966,6 @@ static void omap1_cam_remove_device(struct soc_camera_device *icd) ...@@ -974,8 +966,6 @@ static void omap1_cam_remove_device(struct soc_camera_device *icd)
clk_disable(pcdev->clk); clk_disable(pcdev->clk);
pcdev->icd = NULL;
dev_dbg(icd->parent, dev_dbg(icd->parent,
"OMAP1 Camera driver detached from camera %d\n", icd->devnum); "OMAP1 Camera driver detached from camera %d\n", icd->devnum);
} }
......
...@@ -200,7 +200,6 @@ struct pxa_camera_dev { ...@@ -200,7 +200,6 @@ struct pxa_camera_dev {
* interface. If anyone ever builds hardware to enable more than * interface. If anyone ever builds hardware to enable more than
* one camera, they will have to modify this driver too * one camera, they will have to modify this driver too
*/ */
struct soc_camera_device *icd;
struct clk *clk; struct clk *clk;
unsigned int irq; unsigned int irq;
...@@ -966,13 +965,8 @@ static int pxa_camera_add_device(struct soc_camera_device *icd) ...@@ -966,13 +965,8 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct pxa_camera_dev *pcdev = ici->priv; struct pxa_camera_dev *pcdev = ici->priv;
if (pcdev->icd)
return -EBUSY;
pxa_camera_activate(pcdev); pxa_camera_activate(pcdev);
pcdev->icd = icd;
dev_info(icd->parent, "PXA Camera driver attached to camera %d\n", dev_info(icd->parent, "PXA Camera driver attached to camera %d\n",
icd->devnum); icd->devnum);
...@@ -985,8 +979,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd) ...@@ -985,8 +979,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct pxa_camera_dev *pcdev = ici->priv; struct pxa_camera_dev *pcdev = ici->priv;
BUG_ON(icd != pcdev->icd);
dev_info(icd->parent, "PXA Camera driver detached from camera %d\n", dev_info(icd->parent, "PXA Camera driver detached from camera %d\n",
icd->devnum); icd->devnum);
...@@ -999,8 +991,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd) ...@@ -999,8 +991,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd)
DCSR(pcdev->dma_chans[2]) = 0; DCSR(pcdev->dma_chans[2]) = 0;
pxa_camera_deactivate(pcdev); pxa_camera_deactivate(pcdev);
pcdev->icd = NULL;
} }
static int test_platform_param(struct pxa_camera_dev *pcdev, static int test_platform_param(struct pxa_camera_dev *pcdev,
...@@ -1596,8 +1586,8 @@ static int pxa_camera_suspend(struct device *dev) ...@@ -1596,8 +1586,8 @@ static int pxa_camera_suspend(struct device *dev)
pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3); pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3);
pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4); pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4);
if (pcdev->icd) { if (pcdev->soc_host.icd) {
struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd); struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd);
ret = v4l2_subdev_call(sd, core, s_power, 0); ret = v4l2_subdev_call(sd, core, s_power, 0);
if (ret == -ENOIOCTLCMD) if (ret == -ENOIOCTLCMD)
ret = 0; ret = 0;
...@@ -1622,8 +1612,8 @@ static int pxa_camera_resume(struct device *dev) ...@@ -1622,8 +1612,8 @@ static int pxa_camera_resume(struct device *dev)
__raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3); __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3);
__raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4); __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4);
if (pcdev->icd) { if (pcdev->soc_host.icd) {
struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd); struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd);
ret = v4l2_subdev_call(sd, core, s_power, 1); ret = v4l2_subdev_call(sd, core, s_power, 1);
if (ret == -ENOIOCTLCMD) if (ret == -ENOIOCTLCMD)
ret = 0; ret = 0;
......
...@@ -95,7 +95,6 @@ struct sh_mobile_ceu_buffer { ...@@ -95,7 +95,6 @@ struct sh_mobile_ceu_buffer {
struct sh_mobile_ceu_dev { struct sh_mobile_ceu_dev {
struct soc_camera_host ici; struct soc_camera_host ici;
struct soc_camera_device *icd;
struct platform_device *csi2_pdev; struct platform_device *csi2_pdev;
unsigned int irq; unsigned int irq;
...@@ -163,7 +162,7 @@ static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs) ...@@ -163,7 +162,7 @@ static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs)
static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev) static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
{ {
int i, success = 0; int i, success = 0;
struct soc_camera_device *icd = pcdev->icd; struct soc_camera_device *icd = pcdev->ici.icd;
ceu_write(pcdev, CAPSR, 1 << 16); /* reset */ ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
...@@ -277,7 +276,7 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq, ...@@ -277,7 +276,7 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
*/ */
static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
{ {
struct soc_camera_device *icd = pcdev->icd; struct soc_camera_device *icd = pcdev->ici.icd;
dma_addr_t phys_addr_top, phys_addr_bottom; dma_addr_t phys_addr_top, phys_addr_bottom;
unsigned long top1, top2; unsigned long top1, top2;
unsigned long bottom1, bottom2; unsigned long bottom1, bottom2;
...@@ -552,9 +551,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) ...@@ -552,9 +551,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
struct v4l2_subdev *csi2_sd; struct v4l2_subdev *csi2_sd;
int ret; int ret;
if (pcdev->icd)
return -EBUSY;
dev_info(icd->parent, dev_info(icd->parent,
"SuperH Mobile CEU driver attached to camera %d\n", "SuperH Mobile CEU driver attached to camera %d\n",
icd->devnum); icd->devnum);
...@@ -583,7 +579,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) ...@@ -583,7 +579,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
*/ */
if (ret == -ENODEV && csi2_sd) if (ret == -ENODEV && csi2_sd)
csi2_sd->grp_id = 0; csi2_sd->grp_id = 0;
pcdev->icd = icd;
return 0; return 0;
} }
...@@ -595,8 +590,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) ...@@ -595,8 +590,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
struct sh_mobile_ceu_dev *pcdev = ici->priv; struct sh_mobile_ceu_dev *pcdev = ici->priv;
struct v4l2_subdev *csi2_sd = find_csi2(pcdev); struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
BUG_ON(icd != pcdev->icd);
v4l2_subdev_call(csi2_sd, core, s_power, 0); v4l2_subdev_call(csi2_sd, core, s_power, 0);
if (csi2_sd) if (csi2_sd)
csi2_sd->grp_id = 0; csi2_sd->grp_id = 0;
...@@ -618,8 +611,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) ...@@ -618,8 +611,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
dev_info(icd->parent, dev_info(icd->parent,
"SuperH Mobile CEU driver detached from camera %d\n", "SuperH Mobile CEU driver detached from camera %d\n",
icd->devnum); icd->devnum);
pcdev->icd = NULL;
} }
/* /*
......
...@@ -504,6 +504,32 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd, ...@@ -504,6 +504,32 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd,
return ici->ops->set_bus_param(icd); return ici->ops->set_bus_param(icd);
} }
static int soc_camera_add_device(struct soc_camera_device *icd)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
int ret;
if (ici->icd)
return -EBUSY;
ret = ici->ops->add(icd);
if (!ret)
ici->icd = icd;
return ret;
}
static void soc_camera_remove_device(struct soc_camera_device *icd)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
if (WARN_ON(icd != ici->icd))
return;
ici->ops->remove(icd);
ici->icd = NULL;
}
static int soc_camera_open(struct file *file) static int soc_camera_open(struct file *file)
{ {
struct video_device *vdev = video_devdata(file); struct video_device *vdev = video_devdata(file);
...@@ -567,7 +593,7 @@ static int soc_camera_open(struct file *file) ...@@ -567,7 +593,7 @@ static int soc_camera_open(struct file *file)
if (sdesc->subdev_desc.reset) if (sdesc->subdev_desc.reset)
sdesc->subdev_desc.reset(icd->pdev); sdesc->subdev_desc.reset(icd->pdev);
ret = ici->ops->add(icd); ret = soc_camera_add_device(icd);
if (ret < 0) { if (ret < 0) {
dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret); dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret);
goto eiciadd; goto eiciadd;
...@@ -618,7 +644,7 @@ static int soc_camera_open(struct file *file) ...@@ -618,7 +644,7 @@ static int soc_camera_open(struct file *file)
eresume: eresume:
__soc_camera_power_off(icd); __soc_camera_power_off(icd);
epower: epower:
ici->ops->remove(icd); soc_camera_remove_device(icd);
eiciadd: eiciadd:
icd->use_count--; icd->use_count--;
mutex_unlock(&ici->host_lock); mutex_unlock(&ici->host_lock);
...@@ -644,7 +670,7 @@ static int soc_camera_close(struct file *file) ...@@ -644,7 +670,7 @@ static int soc_camera_close(struct file *file)
vb2_queue_release(&icd->vb2_vidq); vb2_queue_release(&icd->vb2_vidq);
__soc_camera_power_off(icd); __soc_camera_power_off(icd);
ici->ops->remove(icd); soc_camera_remove_device(icd);
} }
if (icd->streamer == file) if (icd->streamer == file)
...@@ -1137,7 +1163,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1137,7 +1163,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
ssdd->reset(icd->pdev); ssdd->reset(icd->pdev);
mutex_lock(&ici->host_lock); mutex_lock(&ici->host_lock);
ret = ici->ops->add(icd); ret = soc_camera_add_device(icd);
mutex_unlock(&ici->host_lock); mutex_unlock(&ici->host_lock);
if (ret < 0) if (ret < 0)
goto eadd; goto eadd;
...@@ -1210,7 +1236,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1210,7 +1236,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
icd->field = mf.field; icd->field = mf.field;
} }
ici->ops->remove(icd); soc_camera_remove_device(icd);
mutex_unlock(&ici->host_lock); mutex_unlock(&ici->host_lock);
...@@ -1233,7 +1259,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1233,7 +1259,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
icd->vdev = NULL; icd->vdev = NULL;
evdc: evdc:
mutex_lock(&ici->host_lock); mutex_lock(&ici->host_lock);
ici->ops->remove(icd); soc_camera_remove_device(icd);
mutex_unlock(&ici->host_lock); mutex_unlock(&ici->host_lock);
eadd: eadd:
v4l2_ctrl_handler_free(&icd->ctrl_handler); v4l2_ctrl_handler_free(&icd->ctrl_handler);
......
...@@ -64,6 +64,7 @@ struct soc_camera_host { ...@@ -64,6 +64,7 @@ struct soc_camera_host {
struct mutex host_lock; /* Protect pipeline modifications */ struct mutex host_lock; /* Protect pipeline modifications */
unsigned char nr; /* Host number */ unsigned char nr; /* Host number */
u32 capabilities; u32 capabilities;
struct soc_camera_device *icd; /* Currently attached client */
void *priv; void *priv;
const char *drv_name; const char *drv_name;
struct soc_camera_host_ops *ops; struct soc_camera_host_ops *ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment