Skip to content

Commit a3c7958

Browse files
Hu Kejunrkhuangtao
authored andcommitted
media: rk-isp10: support isp0 and isp1 run at the same time
1. support isp0 and isp1 run at the same time; 2. support VIDIOC_G_INPUT command; 3. support VIDIOC_G_PARM command; 4. support VIDIOC_G_PARM command; 5. add pix.bytesperline and pix.sizeimage in VIDIOC_G_FMT command; Change-Id: I6d0347350a0bef372ee2e01c508b2fb581ea7cfc Signed-off-by: Hu Kejun <william.hu@rock-chips.com>
1 parent 80072db commit a3c7958

9 files changed

Lines changed: 307 additions & 113 deletions

File tree

drivers/media/platform/rk-isp10/cif_isp10.c

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,7 +4690,7 @@ static int cif_isp10_stop(
46904690
{
46914691
unsigned long flags = 0;
46924692
bool stop_all;
4693-
int timeout;
4693+
unsigned long isp_ctrl;
46944694

46954695
cif_isp10_pltfrm_pr_dbg(dev->dev,
46964696
"SP state = %s, MP state = %s, img_src state = %s, stop_sp = %d, stop_mp = %d\n",
@@ -4724,12 +4724,15 @@ static int cif_isp10_stop(
47244724
cif_isp10_stop_sp(dev);
47254725
cif_isp10_stop_dma(dev);
47264726

4727-
local_irq_save(flags);
47284727
/* stop and clear MI, MIPI, and ISP interrupts */
47294728
cif_iowrite32(0, dev->config.base_addr + CIF_MIPI_IMSC);
47304729
cif_iowrite32(~0, dev->config.base_addr + CIF_MIPI_ICR);
47314730

4732-
cif_iowrite32(0, dev->config.base_addr + CIF_ISP_IMSC);
4731+
spin_lock_irqsave(&dev->isp_state_lock, flags);
4732+
dev->isp_state = CIF_ISP10_STATE_STOPPING;
4733+
spin_unlock_irqrestore(&dev->isp_state_lock, flags);
4734+
dev->isp_stop_flags = 0;
4735+
cif_iowrite32(CIF_ISP_OFF, dev->config.base_addr + CIF_ISP_IMSC);
47334736
cif_iowrite32(~0, dev->config.base_addr + CIF_ISP_ICR);
47344737

47354738
cif_iowrite32_verify(0,
@@ -4745,13 +4748,19 @@ static int cif_isp10_stop(
47454748
cif_iowrite32OR(CIF_ISP_CTRL_ISP_CFG_UPD,
47464749
dev->config.base_addr + CIF_ISP_CTRL);
47474750

4748-
timeout = 100;
4749-
while ((timeout-- > 0) &&
4750-
((cif_ioread32(dev->config.base_addr + CIF_ISP_RIS)
4751-
& CIF_ISP_OFF) != CIF_ISP_OFF)) {
4752-
msleep(20);
4753-
};
4754-
local_irq_restore(flags);
4751+
wait_event_interruptible_timeout(dev->isp_stop_wait,
4752+
dev->isp_stop_flags != 0,
4753+
HZ);
4754+
4755+
isp_ctrl = cif_ioread32(dev->config.base_addr + CIF_ISP_CTRL);
4756+
if ((isp_ctrl & 0x0001) != 0) {
4757+
cif_isp10_pltfrm_pr_err(dev->dev,
4758+
"Stop ISP Failure(0x%lx)!\n", isp_ctrl);
4759+
} else {
4760+
spin_lock_irqsave(&dev->isp_state_lock, flags);
4761+
dev->isp_state = CIF_ISP10_STATE_IDLE;
4762+
spin_unlock_irqrestore(&dev->isp_state_lock, flags);
4763+
}
47554764

47564765
if (!CIF_ISP10_INP_IS_DMA(dev->config.input_sel)) {
47574766
if (IS_ERR_VALUE(cif_isp10_img_src_set_state(dev,
@@ -4765,19 +4774,15 @@ static int cif_isp10_stop(
47654774
"unable to put CIF into standby\n");
47664775
} else if (stop_sp) {
47674776
if (!dev->config.mi_config.async_updt) {
4768-
local_irq_save(flags);
47694777
cif_isp10_stop_mi(dev, true, false);
4770-
local_irq_restore(flags);
47714778
}
47724779
cif_isp10_stop_sp(dev);
47734780
cif_iowrite32AND_verify(~CIF_MI_SP_FRAME,
47744781
dev->config.base_addr + CIF_MI_IMSC, ~0);
47754782

47764783
} else /* stop_mp */ {
47774784
if (!dev->config.mi_config.async_updt) {
4778-
local_irq_save(flags);
47794785
cif_isp10_stop_mi(dev, false, true);
4780-
local_irq_restore(flags);
47814786
}
47824787
cif_isp10_stop_mp(dev);
47834788
cif_iowrite32AND_verify(~(CIF_MI_MP_FRAME |
@@ -4825,6 +4830,7 @@ static int cif_isp10_start(
48254830
{
48264831
unsigned int ret;
48274832
struct vb2_buffer *vb, *n;
4833+
unsigned long flags;
48284834

48294835
cif_isp10_pltfrm_pr_dbg(dev->dev,
48304836
"SP state = %s, MP state = %s, DMA state = %s, img_src state = %s, start_sp = %d, start_mp = %d\n",
@@ -4865,6 +4871,10 @@ static int cif_isp10_start(
48654871
CIF_ISP_CTRL_ISP_INFORM_ENABLE |
48664872
CIF_ISP_CTRL_ISP_ENABLE,
48674873
dev->config.base_addr + CIF_ISP_CTRL);
4874+
4875+
spin_lock_irqsave(&dev->isp_state_lock, flags);
4876+
dev->isp_state = CIF_ISP10_STATE_RUNNING;
4877+
spin_unlock_irqrestore(&dev->isp_state_lock, flags);
48684878
}
48694879

48704880
if (start_sp &&
@@ -5809,6 +5819,22 @@ void cif_isp10_destroy(
58095819
kfree(dev);
58105820
}
58115821

5822+
int cif_isp10_g_input(
5823+
struct cif_isp10_device *dev,
5824+
unsigned int *input)
5825+
{
5826+
unsigned int i;
5827+
5828+
for (i = 0; i < dev->img_src_cnt; i++) {
5829+
if (dev->img_src != NULL && dev->img_src == dev->img_src_array[i]) {
5830+
*input = i;
5831+
return 0;
5832+
}
5833+
}
5834+
5835+
return -EINVAL;
5836+
}
5837+
58125838
int cif_isp10_s_input(
58135839
struct cif_isp10_device *dev,
58145840
unsigned int input)
@@ -6502,6 +6528,15 @@ int cif_isp10_isp_isr(unsigned int isp_mis, void *cntxt)
65026528
cif_ioread32(dev->config.base_addr + CIF_ISP_RIS),
65036529
cif_ioread32(dev->config.base_addr + CIF_ISP_IMSC));
65046530

6531+
if (isp_mis & CIF_ISP_OFF) {
6532+
cif_iowrite32(CIF_ISP_OFF,
6533+
dev->config.base_addr + CIF_ISP_ICR);
6534+
cif_isp10_pltfrm_pr_dbg(dev->dev, "ISP Stop Interrupt!\n");
6535+
dev->isp_stop_flags = 1;
6536+
wake_up_interruptible(&dev->isp_stop_wait);
6537+
return 0;
6538+
}
6539+
65056540
if (isp_mis & CIF_ISP_V_START) {
65066541
struct cif_isp10_isp_vs_work *vs_wk;
65076542
struct cif_isp10_img_src_exp *exp;
@@ -6603,14 +6638,18 @@ int cif_isp10_isp_isr(unsigned int isp_mis, void *cntxt)
66036638
CIF_ISP_ICR);
66046639
}
66056640

6606-
/* Stop ISP */
6607-
cif_iowrite32AND(~CIF_ISP_CTRL_ISP_INFORM_ENABLE &
6608-
~CIF_ISP_CTRL_ISP_ENABLE,
6609-
dev->config.base_addr + CIF_ISP_CTRL);
6610-
/* isp_update */
6611-
cif_iowrite32OR(CIF_ISP_CTRL_ISP_CFG_UPD,
6612-
dev->config.base_addr + CIF_ISP_CTRL);
6613-
cif_isp10_hw_restart(dev);
6641+
spin_lock(&dev->isp_state_lock);
6642+
if (dev->isp_state == CIF_ISP10_STATE_RUNNING) {
6643+
/* Stop ISP */
6644+
cif_iowrite32AND(~CIF_ISP_CTRL_ISP_INFORM_ENABLE &
6645+
~CIF_ISP_CTRL_ISP_ENABLE,
6646+
dev->config.base_addr + CIF_ISP_CTRL);
6647+
/* isp_update */
6648+
cif_iowrite32OR(CIF_ISP_CTRL_ISP_CFG_UPD,
6649+
dev->config.base_addr + CIF_ISP_CTRL);
6650+
cif_isp10_hw_restart(dev);
6651+
}
6652+
spin_unlock(&dev->isp_state_lock);
66146653
}
66156654

66166655
if (isp_mis & CIF_ISP_FRAME_IN) {

drivers/media/platform/rk-isp10/cif_isp10.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ enum cif_isp10_pm_state {
9898
CIF_ISP10_PM_STATE_STREAMING
9999
};
100100

101+
enum cif_isp10_ispstate {
102+
CIF_ISP10_STATE_IDLE = 0,
103+
CIF_ISP10_STATE_RUNNING = 1,
104+
CIF_ISP10_STATE_STOPPING = 2
105+
};
106+
101107
enum cif_isp10_inp {
102108
CIF_ISP10_INP_CSI = 0x10000000,
103109
CIF_ISP10_INP_CPI = 0x20000000,
@@ -606,9 +612,15 @@ struct cif_isp10_device {
606612
struct v4l2_device v4l2_dev;
607613
enum cif_isp10_pm_state pm_state;
608614
enum cif_isp10_img_src_state img_src_state;
615+
enum cif_isp10_ispstate isp_state;
609616

610617
spinlock_t vbq_lock; /* spinlock for videobuf queues */
611618
spinlock_t vbreq_lock; /* spinlock for videobuf requeues */
619+
spinlock_t iowrite32_verify_lock;
620+
spinlock_t isp_state_lock;
621+
622+
wait_queue_head_t isp_stop_wait; /* wait while isp stop */
623+
unsigned int isp_stop_flags;
612624

613625
struct cif_isp10_img_src *img_src;
614626
struct cif_isp10_img_src *img_src_array[CIF_ISP10_NUM_INPUTS];
@@ -643,7 +655,7 @@ struct cif_isp10_device {
643655
int otf_zsl_mode;
644656
struct flash_timeinfo_s flash_t;
645657

646-
struct pltfrm_soc_cfg *soc_cfg;
658+
struct pltfrm_soc_cfg soc_cfg;
647659
void *nodes;
648660

649661
};
@@ -705,6 +717,10 @@ int cif_isp10_streamoff(
705717
struct cif_isp10_device *dev,
706718
u32 stream_ids);
707719

720+
int cif_isp10_g_input(
721+
struct cif_isp10_device *dev,
722+
enum cif_isp10_inp *inp);
723+
708724
int cif_isp10_s_input(
709725
struct cif_isp10_device *dev,
710726
enum cif_isp10_inp inp);

drivers/media/platform/rk-isp10/cif_isp10_pltfrm.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,11 +1366,13 @@ int cif_isp10_pltfrm_soc_init(
13661366
if (!IS_ERR_OR_NULL(soc_cfg) && !IS_ERR_OR_NULL(soc_cfg->soc_cfg)) {
13671367
cfg_para.cmd = PLTFRM_SOC_INIT;
13681368
cfg_para.cfg_para = &init_para;
1369+
cfg_para.isp_config = &(soc_cfg->isp_config);
13691370
init_para.pdev = pdev;
13701371
init_para.isp_base = cif_isp10_dev->config.base_addr;
13711372
ret = soc_cfg->soc_cfg(&cfg_para);
13721373
if (ret == 0)
1373-
cif_isp10_dev->soc_cfg = soc_cfg;
1374+
memcpy(&(cif_isp10_dev->soc_cfg), soc_cfg, sizeof(*soc_cfg));
1375+
13741376
}
13751377

13761378
return ret;
@@ -1383,13 +1385,14 @@ int cif_isp10_pltfrm_mipi_dphy_config(
13831385
struct pltfrm_soc_cfg *soc_cfg;
13841386
int ret = 0;
13851387

1386-
soc_cfg = cif_isp10_dev->soc_cfg;
1388+
soc_cfg = &(cif_isp10_dev->soc_cfg);
13871389
if (!IS_ERR_OR_NULL(soc_cfg) &&
13881390
!IS_ERR_OR_NULL(soc_cfg->soc_cfg)) {
13891391
cfg_para.cmd =
13901392
PLTFRM_MIPI_DPHY_CFG;
13911393
cfg_para.cfg_para =
13921394
(void *)(&cif_isp10_dev->config.cam_itf.cfg.mipi);
1395+
cfg_para.isp_config = &(soc_cfg->isp_config);
13931396
ret = soc_cfg->soc_cfg(&cfg_para);
13941397
}
13951398

@@ -1402,20 +1405,22 @@ int cif_isp10_pltfrm_pm_set_state(
14021405
{
14031406
int ret;
14041407
struct cif_isp10_device *cif_isp10_dev = dev_get_drvdata(dev);
1405-
struct pltfrm_soc_cfg *soc_cfg = cif_isp10_dev->soc_cfg;
1408+
struct pltfrm_soc_cfg *soc_cfg = &(cif_isp10_dev->soc_cfg);
14061409
struct pltfrm_soc_cfg_para cfg_para;
14071410

14081411
switch (pm_state) {
14091412
case CIF_ISP10_PM_STATE_OFF:
14101413
case CIF_ISP10_PM_STATE_SUSPENDED:
14111414
cfg_para.cmd = PLTFRM_CLKDIS;
14121415
cfg_para.cfg_para = NULL;
1416+
cfg_para.isp_config = &(soc_cfg->isp_config);
14131417
ret = soc_cfg->soc_cfg(&cfg_para);
14141418
break;
14151419
case CIF_ISP10_PM_STATE_SW_STNDBY:
14161420
case CIF_ISP10_PM_STATE_STREAMING:
14171421
cfg_para.cmd = PLTFRM_CLKEN;
14181422
cfg_para.cfg_para = NULL;
1423+
cfg_para.isp_config = &(soc_cfg->isp_config);
14191424
ret = soc_cfg->soc_cfg(&cfg_para);
14201425
break;
14211426
default:
@@ -1650,7 +1655,7 @@ int cif_isp10_pltfrm_get_img_src_device(
16501655
img_src_array[num_cameras] =
16511656
cif_isp10_img_src_to_img_src(
16521657
&client->dev,
1653-
cif_isp10_dev->soc_cfg);
1658+
&(cif_isp10_dev->soc_cfg));
16541659
if (!IS_ERR_OR_NULL(img_src_array[num_cameras])) {
16551660
cif_isp10_pltfrm_pr_info(dev,
16561661
"%s attach to cif isp10 img_src_array[%d]\n",

drivers/media/platform/rk-isp10/cif_isp10_pltfrm.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ enum cif_isp10_pm_state;
3737
#define CIF_ISP10_PLTFRM_MEM_IO_ADDR void __iomem *
3838
#define CIF_ISP10_PLTFRM_EVENT wait_queue_head_t
3939

40-
extern spinlock_t iowrite32_verify_lock;
4140
#ifdef CONFIG_CIF_ISP10_REG_TRACE
4241
int
4342
cif_isp10_pltfrm_rtrace_printf(
@@ -117,7 +116,7 @@ u32 cif_isp10_pltfrm_read_reg(
117116
{ \
118117
unsigned int i = 0; \
119118
unsigned long flags = 0; \
120-
spin_lock_irqsave(&iowrite32_verify_lock, flags); \
119+
spin_lock_irqsave(&dev->iowrite32_verify_lock, flags); \
121120
do { \
122121
cif_iowrite32(d, a); \
123122
udelay(1); \
@@ -127,7 +126,7 @@ u32 cif_isp10_pltfrm_read_reg(
127126
WARN_ON(1); \
128127
} \
129128
} while ((ioread32(a) & mask) != ((d) & mask)); \
130-
spin_unlock_irqrestore(&iowrite32_verify_lock, flags);\
129+
spin_unlock_irqrestore(&dev->iowrite32_verify_lock, flags);\
131130
}
132131
#define cif_iowrite32OR_verify(d, a, mask) \
133132
cif_iowrite32_verify((u32)(d) | cif_ioread32(a), a, mask)

drivers/media/platform/rk-isp10/cif_isp10_rk3288.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ static int soc_init(struct pltfrm_soc_init_para *init)
568568
return err;
569569
}
570570

571-
int pltfrm_rk3288_cfg(
572-
struct pltfrm_soc_cfg_para *cfg)
571+
int pltfrm_rk3288_cfg(struct pltfrm_soc_cfg_para *cfg)
573572
{
574573
switch (cfg->cmd) {
575574
case PLTFRM_MCLK_CFG: {

0 commit comments

Comments
 (0)