2 * Support for Medifield PNW Camera Imaging ISP subsystem.
4 * Copyright (c) 2010-2017 Intel Corporation. All Rights Reserved.
6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/pm_qos.h>
27 #include <linux/timer.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
31 #include <asm/intel-mid.h>
32 #include <asm/iosf_mbi.h>
34 #include "../../include/linux/atomisp_gmin_platform.h"
36 #include "atomisp_cmd.h"
37 #include "atomisp_common.h"
38 #include "atomisp_fops.h"
39 #include "atomisp_file.h"
40 #include "atomisp_ioctl.h"
41 #include "atomisp_internal.h"
42 #include "atomisp_acc.h"
43 #include "atomisp-regs.h"
44 #include "atomisp_dfs_tables.h"
45 #include "atomisp_drvfs.h"
47 #include "atomisp_trace_event.h"
49 #include "hrt/hive_isp_css_mm_hrt.h"
51 #include "device_access.h"
53 /* G-Min addition: pull this in from intel_mid_pm.h */
54 #define CSTATE_EXIT_LATENCY_C1 1
56 static uint skip_fwload
;
57 module_param(skip_fwload
, uint
, 0644);
58 MODULE_PARM_DESC(skip_fwload
, "Skip atomisp firmware load");
60 /* set reserved memory pool size in page */
61 static unsigned int repool_pgnr
;
62 module_param(repool_pgnr
, uint
, 0644);
63 MODULE_PARM_DESC(repool_pgnr
,
64 "Set the reserved memory pool size in page (default:0)");
66 /* set dynamic memory pool size in page */
67 unsigned int dypool_pgnr
= UINT_MAX
;
68 module_param(dypool_pgnr
, uint
, 0644);
69 MODULE_PARM_DESC(dypool_pgnr
,
70 "Set the dynamic memory pool size in page (default:0)");
73 module_param(dypool_enable
, bool, 0644);
74 MODULE_PARM_DESC(dypool_enable
,
75 "dynamic memory pool enable/disable (default:disable)");
77 /* memory optimization: deferred firmware loading */
79 module_param(defer_fw_load
, bool, 0644);
80 MODULE_PARM_DESC(defer_fw_load
,
81 "Defer FW loading until device is opened (default:disable)");
83 /* cross componnet debug message flag */
85 module_param(dbg_level
, int, 0644);
86 MODULE_PARM_DESC(dbg_level
, "debug message on/off (default:off)");
88 /* log function switch */
90 module_param(dbg_func
, int, 0644);
91 MODULE_PARM_DESC(dbg_func
,
92 "log function switch non/trace_printk/printk (default:printk)");
95 module_param(mipicsi_flag
, int, 0644);
96 MODULE_PARM_DESC(mipicsi_flag
, "mipi csi compression predictor algorithm");
98 /*set to 16x16 since this is the amount of lines and pixels the sensor
99 exports extra. If these are kept at the 10x8 that they were on, in yuv
100 downscaling modes incorrect resolutions where requested to the sensor
101 driver with strange outcomes as a result. The proper way tot do this
102 would be to have a list of tables the specify the sensor res, mipi rec,
103 output res, and isp output res. however since we do not have this yet,
104 the chosen solution is the next best thing. */
106 module_param(pad_w
, int, 0644);
107 MODULE_PARM_DESC(pad_w
, "extra data for ISP processing");
110 module_param(pad_h
, int, 0644);
111 MODULE_PARM_DESC(pad_h
, "extra data for ISP processing");
113 struct device
*atomisp_dev
;
115 void __iomem
*atomisp_io_base
;
117 int atomisp_video_init(struct atomisp_video_pipe
*video
, const char *name
)
120 const char *direction
;
122 switch (video
->type
) {
123 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
124 direction
= "output";
125 video
->pad
.flags
= MEDIA_PAD_FL_SINK
;
126 video
->vdev
.fops
= &atomisp_fops
;
127 video
->vdev
.ioctl_ops
= &atomisp_ioctl_ops
;
129 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
131 video
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
132 video
->vdev
.fops
= &atomisp_file_fops
;
133 video
->vdev
.ioctl_ops
= &atomisp_file_ioctl_ops
;
139 ret
= media_entity_pads_init(&video
->vdev
.entity
, 1, &video
->pad
);
143 /* Initialize the video device. */
144 snprintf(video
->vdev
.name
, sizeof(video
->vdev
.name
),
145 "ATOMISP ISP %s %s", name
, direction
);
146 video
->vdev
.release
= video_device_release_empty
;
147 video_set_drvdata(&video
->vdev
, video
->isp
);
152 void atomisp_acc_init(struct atomisp_acc_pipe
*video
, const char *name
)
154 video
->vdev
.fops
= &atomisp_fops
;
155 video
->vdev
.ioctl_ops
= &atomisp_ioctl_ops
;
157 /* Initialize the video device. */
158 snprintf(video
->vdev
.name
, sizeof(video
->vdev
.name
),
159 "ATOMISP ISP %s", name
);
160 video
->vdev
.release
= video_device_release_empty
;
161 video_set_drvdata(&video
->vdev
, video
->isp
);
164 int atomisp_video_register(struct atomisp_video_pipe
*video
,
165 struct v4l2_device
*vdev
)
169 video
->vdev
.v4l2_dev
= vdev
;
171 ret
= video_register_device(&video
->vdev
, VFL_TYPE_GRABBER
, -1);
173 dev_err(vdev
->dev
, "%s: could not register video device (%d)\n",
179 int atomisp_acc_register(struct atomisp_acc_pipe
*video
,
180 struct v4l2_device
*vdev
)
184 video
->vdev
.v4l2_dev
= vdev
;
186 ret
= video_register_device(&video
->vdev
, VFL_TYPE_GRABBER
, -1);
188 dev_err(vdev
->dev
, "%s: could not register video device (%d)\n",
194 void atomisp_video_unregister(struct atomisp_video_pipe
*video
)
196 if (video_is_registered(&video
->vdev
)) {
197 media_entity_cleanup(&video
->vdev
.entity
);
198 video_unregister_device(&video
->vdev
);
202 void atomisp_acc_unregister(struct atomisp_acc_pipe
*video
)
204 if (video_is_registered(&video
->vdev
))
205 video_unregister_device(&video
->vdev
);
208 static int atomisp_save_iunit_reg(struct atomisp_device
*isp
)
210 struct pci_dev
*dev
= isp
->pdev
;
212 dev_dbg(isp
->dev
, "%s\n", __func__
);
214 pci_read_config_word(dev
, PCI_COMMAND
, &isp
->saved_regs
.pcicmdsts
);
215 /* isp->saved_regs.ispmmadr is set from the atomisp_pci_probe() */
216 pci_read_config_dword(dev
, PCI_MSI_CAPID
, &isp
->saved_regs
.msicap
);
217 pci_read_config_dword(dev
, PCI_MSI_ADDR
, &isp
->saved_regs
.msi_addr
);
218 pci_read_config_word(dev
, PCI_MSI_DATA
, &isp
->saved_regs
.msi_data
);
219 pci_read_config_byte(dev
, PCI_INTERRUPT_LINE
, &isp
->saved_regs
.intr
);
220 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
,
221 &isp
->saved_regs
.interrupt_control
);
223 pci_read_config_dword(dev
, MRFLD_PCI_PMCS
,
224 &isp
->saved_regs
.pmcs
);
225 /* Ensure read/write combining is enabled. */
226 pci_read_config_dword(dev
, PCI_I_CONTROL
,
227 &isp
->saved_regs
.i_control
);
228 isp
->saved_regs
.i_control
|=
229 MRFLD_PCI_I_CONTROL_ENABLE_READ_COMBINING
|
230 MRFLD_PCI_I_CONTROL_ENABLE_WRITE_COMBINING
;
231 pci_read_config_dword(dev
, MRFLD_PCI_CSI_ACCESS_CTRL_VIOL
,
232 &isp
->saved_regs
.csi_access_viol
);
233 pci_read_config_dword(dev
, MRFLD_PCI_CSI_RCOMP_CONTROL
,
234 &isp
->saved_regs
.csi_rcomp_config
);
236 * Hardware bugs require setting CSI_HS_OVR_CLK_GATE_ON_UPDATE.
237 * ANN/CHV: RCOMP updates do not happen when using CSI2+ path
238 * and sensor sending "continuous clock".
239 * TNG/ANN/CHV: MIPI packets are lost if the HS entry sequence
240 * is missed, and IUNIT can hang.
241 * For both issues, setting this bit is a workaround.
243 isp
->saved_regs
.csi_rcomp_config
|=
244 MRFLD_PCI_CSI_HS_OVR_CLK_GATE_ON_UPDATE
;
245 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
246 &isp
->saved_regs
.csi_afe_dly
);
247 pci_read_config_dword(dev
, MRFLD_PCI_CSI_CONTROL
,
248 &isp
->saved_regs
.csi_control
);
249 if (isp
->media_dev
.hw_revision
>=
250 (ATOMISP_HW_REVISION_ISP2401
<< ATOMISP_HW_REVISION_SHIFT
))
251 isp
->saved_regs
.csi_control
|=
252 MRFLD_PCI_CSI_CONTROL_PARPATHEN
;
254 * On CHT CSI_READY bit should be enabled before stream on
256 if (IS_CHT
&& (isp
->media_dev
.hw_revision
>= ((ATOMISP_HW_REVISION_ISP2401
<<
257 ATOMISP_HW_REVISION_SHIFT
) | ATOMISP_HW_STEPPING_B0
)))
258 isp
->saved_regs
.csi_control
|=
259 MRFLD_PCI_CSI_CONTROL_CSI_READY
;
260 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_RCOMP_CONTROL
,
261 &isp
->saved_regs
.csi_afe_rcomp_config
);
262 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_HS_CONTROL
,
263 &isp
->saved_regs
.csi_afe_hs_control
);
264 pci_read_config_dword(dev
, MRFLD_PCI_CSI_DEADLINE_CONTROL
,
265 &isp
->saved_regs
.csi_deadline_control
);
269 static int __maybe_unused
atomisp_restore_iunit_reg(struct atomisp_device
*isp
)
271 struct pci_dev
*dev
= isp
->pdev
;
273 dev_dbg(isp
->dev
, "%s\n", __func__
);
275 pci_write_config_word(dev
, PCI_COMMAND
, isp
->saved_regs
.pcicmdsts
);
276 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
277 isp
->saved_regs
.ispmmadr
);
278 pci_write_config_dword(dev
, PCI_MSI_CAPID
, isp
->saved_regs
.msicap
);
279 pci_write_config_dword(dev
, PCI_MSI_ADDR
, isp
->saved_regs
.msi_addr
);
280 pci_write_config_word(dev
, PCI_MSI_DATA
, isp
->saved_regs
.msi_data
);
281 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, isp
->saved_regs
.intr
);
282 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
,
283 isp
->saved_regs
.interrupt_control
);
284 pci_write_config_dword(dev
, PCI_I_CONTROL
,
285 isp
->saved_regs
.i_control
);
287 pci_write_config_dword(dev
, MRFLD_PCI_PMCS
,
288 isp
->saved_regs
.pmcs
);
289 pci_write_config_dword(dev
, MRFLD_PCI_CSI_ACCESS_CTRL_VIOL
,
290 isp
->saved_regs
.csi_access_viol
);
291 pci_write_config_dword(dev
, MRFLD_PCI_CSI_RCOMP_CONTROL
,
292 isp
->saved_regs
.csi_rcomp_config
);
293 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
294 isp
->saved_regs
.csi_afe_dly
);
295 pci_write_config_dword(dev
, MRFLD_PCI_CSI_CONTROL
,
296 isp
->saved_regs
.csi_control
);
297 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_RCOMP_CONTROL
,
298 isp
->saved_regs
.csi_afe_rcomp_config
);
299 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_HS_CONTROL
,
300 isp
->saved_regs
.csi_afe_hs_control
);
301 pci_write_config_dword(dev
, MRFLD_PCI_CSI_DEADLINE_CONTROL
,
302 isp
->saved_regs
.csi_deadline_control
);
305 * for MRFLD, Software/firmware needs to write a 1 to bit0
306 * of the register at CSI_RECEIVER_SELECTION_REG to enable
307 * SH CSI backend write 0 will enable Arasan CSI backend,
308 * which has bugs(like sighting:4567697 and 4567699) and
309 * will be removed in B0
311 atomisp_store_uint32(MRFLD_CSI_RECEIVER_SELECTION_REG
, 1);
315 static int atomisp_mrfld_pre_power_down(struct atomisp_device
*isp
)
317 struct pci_dev
*dev
= isp
->pdev
;
321 spin_lock_irqsave(&isp
->lock
, flags
);
322 if (isp
->sw_contex
.power_state
== ATOM_ISP_POWER_DOWN
) {
323 spin_unlock_irqrestore(&isp
->lock
, flags
);
324 dev_dbg(isp
->dev
, "<%s %d.\n", __func__
, __LINE__
);
328 * MRFLD HAS requirement: cannot power off i-unit if
329 * ISP has IRQ not serviced.
330 * So, here we need to check if there is any pending
331 * IRQ, if so, waiting for it to be served
333 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
334 irq
= irq
& 1 << INTR_IIR
;
335 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
337 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
338 if (!(irq
& (1 << INTR_IIR
)))
341 atomisp_store_uint32(MRFLD_INTR_CLEAR_REG
, 0xFFFFFFFF);
342 atomisp_load_uint32(MRFLD_INTR_STATUS_REG
, &irq
);
345 "%s: fail to clear isp interrupt status reg=0x%x\n",
347 spin_unlock_irqrestore(&isp
->lock
, flags
);
350 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
351 irq
= irq
& 1 << INTR_IIR
;
352 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
354 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
355 if (!(irq
& (1 << INTR_IIR
))) {
356 atomisp_store_uint32(MRFLD_INTR_ENABLE_REG
, 0x0);
360 "%s: error in iunit interrupt. status reg=0x%x\n",
362 spin_unlock_irqrestore(&isp
->lock
, flags
);
368 * before powering off IUNIT, clear the pending interrupts
369 * and disable the interrupt. driver should avoid writing 0
370 * to IIR. It could block subsequent interrupt messages.
371 * HW sighting:4568410.
373 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
374 irq
&= ~(1 << INTR_IER
);
375 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
377 atomisp_msi_irq_uninit(isp
, dev
);
378 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
379 spin_unlock_irqrestore(&isp
->lock
, flags
);
386 * WA for DDR DVFS enable/disable
387 * By default, ISP will force DDR DVFS 1600MHz before disable DVFS
389 static void punit_ddr_dvfs_enable(bool enable
)
391 int door_bell
= 1 << 8;
395 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSDVFS
, ®
);
397 reg
&= ~(MRFLD_BIT0
| MRFLD_BIT1
);
399 reg
|= (MRFLD_BIT1
| door_bell
);
400 reg
&= ~(MRFLD_BIT0
);
402 iosf_mbi_write(BT_MBI_UNIT_PMC
, MBI_REG_WRITE
, MRFLD_ISPSSDVFS
, reg
);
404 /* Check Req_ACK to see freq status, wait until door_bell is cleared */
405 while ((reg
& door_bell
) && max_wait
--) {
406 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSDVFS
, ®
);
407 usleep_range(100, 500);
411 pr_info("DDR DVFS, door bell is not cleared within 3ms\n");
414 /* Workaround for pmu_nc_set_power_state not ready in MRFLD */
415 int atomisp_mrfld_power_down(struct atomisp_device
*isp
)
417 unsigned long timeout
;
420 /* writing 0x3 to ISPSSPM0 bit[1:0] to power off the IUNIT */
421 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSPM0
, ®_value
);
422 reg_value
&= ~MRFLD_ISPSSPM0_ISPSSC_MASK
;
423 reg_value
|= MRFLD_ISPSSPM0_IUNIT_POWER_OFF
;
424 iosf_mbi_write(BT_MBI_UNIT_PMC
, MBI_REG_WRITE
, MRFLD_ISPSSPM0
, reg_value
);
428 punit_ddr_dvfs_enable(true);
431 * There should be no iunit access while power-down is
432 * in progress HW sighting: 4567865
433 * FIXME: msecs_to_jiffies(50)- experienced value
435 timeout
= jiffies
+ msecs_to_jiffies(50);
437 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSPM0
, ®_value
);
438 dev_dbg(isp
->dev
, "power-off in progress, ISPSSPM0: 0x%x\n",
440 /* wait until ISPSSPM0 bit[25:24] shows 0x3 */
441 if ((reg_value
>> MRFLD_ISPSSPM0_ISPSSS_OFFSET
) ==
442 MRFLD_ISPSSPM0_IUNIT_POWER_OFF
) {
447 if (time_after(jiffies
, timeout
)) {
448 dev_err(isp
->dev
, "power-off iunit timeout.\n");
451 /* FIXME: experienced value for delay */
452 usleep_range(100, 150);
457 /* Workaround for pmu_nc_set_power_state not ready in MRFLD */
458 int atomisp_mrfld_power_up(struct atomisp_device
*isp
)
460 unsigned long timeout
;
463 /*WA for PUNIT, if DVFS enabled, ISP timeout observed*/
465 punit_ddr_dvfs_enable(false);
468 * FIXME:WA for ECS28A, with this sleep, CTS
469 * android.hardware.camera2.cts.CameraDeviceTest#testCameraDeviceAbort
470 * PASS, no impact on other platforms
475 /* writing 0x0 to ISPSSPM0 bit[1:0] to power off the IUNIT */
476 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSPM0
, ®_value
);
477 reg_value
&= ~MRFLD_ISPSSPM0_ISPSSC_MASK
;
478 iosf_mbi_write(BT_MBI_UNIT_PMC
, MBI_REG_WRITE
, MRFLD_ISPSSPM0
, reg_value
);
480 /* FIXME: experienced value for delay */
481 timeout
= jiffies
+ msecs_to_jiffies(50);
483 iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, MRFLD_ISPSSPM0
, ®_value
);
484 dev_dbg(isp
->dev
, "power-on in progress, ISPSSPM0: 0x%x\n",
486 /* wait until ISPSSPM0 bit[25:24] shows 0x0 */
487 if ((reg_value
>> MRFLD_ISPSSPM0_ISPSSS_OFFSET
) ==
488 MRFLD_ISPSSPM0_IUNIT_POWER_ON
) {
493 if (time_after(jiffies
, timeout
)) {
494 dev_err(isp
->dev
, "power-on iunit timeout.\n");
497 /* FIXME: experienced value for delay */
498 usleep_range(100, 150);
502 int atomisp_runtime_suspend(struct device
*dev
)
504 struct atomisp_device
*isp
= (struct atomisp_device
*)
505 dev_get_drvdata(dev
);
508 ret
= atomisp_mrfld_pre_power_down(isp
);
512 /*Turn off the ISP d-phy*/
513 ret
= atomisp_ospm_dphy_down(isp
);
516 pm_qos_update_request(&isp
->pm_qos
, PM_QOS_DEFAULT_VALUE
);
517 return atomisp_mrfld_power_down(isp
);
520 int atomisp_runtime_resume(struct device
*dev
)
522 struct atomisp_device
*isp
= (struct atomisp_device
*)
523 dev_get_drvdata(dev
);
526 ret
= atomisp_mrfld_power_up(isp
);
530 pm_qos_update_request(&isp
->pm_qos
, isp
->max_isr_latency
);
531 if (isp
->sw_contex
.power_state
== ATOM_ISP_POWER_DOWN
) {
532 /*Turn on ISP d-phy */
533 ret
= atomisp_ospm_dphy_up(isp
);
535 dev_err(isp
->dev
, "Failed to power up ISP!.\n");
540 /*restore register values for iUnit and iUnitPHY registers*/
541 if (isp
->saved_regs
.pcicmdsts
)
542 atomisp_restore_iunit_reg(isp
);
544 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
548 static int __maybe_unused
atomisp_suspend(struct device
*dev
)
550 struct atomisp_device
*isp
= (struct atomisp_device
*)
551 dev_get_drvdata(dev
);
552 /* FIXME: only has one isp_subdev at present */
553 struct atomisp_sub_device
*asd
= &isp
->asd
[0];
558 * FIXME: Suspend is not supported by sensors. Abort if any video
561 if (atomisp_dev_users(isp
))
564 spin_lock_irqsave(&isp
->lock
, flags
);
565 if (asd
->streaming
!= ATOMISP_DEVICE_STREAMING_DISABLED
) {
566 spin_unlock_irqrestore(&isp
->lock
, flags
);
567 dev_err(isp
->dev
, "atomisp cannot suspend at this time.\n");
570 spin_unlock_irqrestore(&isp
->lock
, flags
);
572 ret
= atomisp_mrfld_pre_power_down(isp
);
576 /*Turn off the ISP d-phy */
577 ret
= atomisp_ospm_dphy_down(isp
);
579 dev_err(isp
->dev
, "fail to power off ISP\n");
582 pm_qos_update_request(&isp
->pm_qos
, PM_QOS_DEFAULT_VALUE
);
583 return atomisp_mrfld_power_down(isp
);
586 static int __maybe_unused
atomisp_resume(struct device
*dev
)
588 struct atomisp_device
*isp
= (struct atomisp_device
*)
589 dev_get_drvdata(dev
);
592 ret
= atomisp_mrfld_power_up(isp
);
596 pm_qos_update_request(&isp
->pm_qos
, isp
->max_isr_latency
);
598 /*Turn on ISP d-phy */
599 ret
= atomisp_ospm_dphy_up(isp
);
601 dev_err(isp
->dev
, "Failed to power up ISP!.\n");
605 /*restore register values for iUnit and iUnitPHY registers*/
606 if (isp
->saved_regs
.pcicmdsts
)
607 atomisp_restore_iunit_reg(isp
);
609 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
613 int atomisp_csi_lane_config(struct atomisp_device
*isp
)
615 static const struct {
617 u8 lanes
[MRFLD_PORT_NUM
];
619 /* Tangier/Merrifield available lane configurations */
620 { 0x00, { 4, 1, 0 } }, /* 00000 */
621 { 0x01, { 3, 1, 0 } }, /* 00001 */
622 { 0x02, { 2, 1, 0 } }, /* 00010 */
623 { 0x03, { 1, 1, 0 } }, /* 00011 */
624 { 0x04, { 2, 1, 2 } }, /* 00100 */
625 { 0x08, { 3, 1, 1 } }, /* 01000 */
626 { 0x09, { 2, 1, 1 } }, /* 01001 */
627 { 0x0a, { 1, 1, 1 } }, /* 01010 */
629 /* Anniedale/Moorefield only configurations */
630 { 0x10, { 4, 2, 0 } }, /* 10000 */
631 { 0x11, { 3, 2, 0 } }, /* 10001 */
632 { 0x12, { 2, 2, 0 } }, /* 10010 */
633 { 0x13, { 1, 2, 0 } }, /* 10011 */
634 { 0x14, { 2, 2, 2 } }, /* 10100 */
635 { 0x18, { 3, 2, 1 } }, /* 11000 */
636 { 0x19, { 2, 2, 1 } }, /* 11001 */
637 { 0x1a, { 1, 2, 1 } }, /* 11010 */
641 u8 sensor_lanes
[MRFLD_PORT_NUM
] = { 0 };
644 u32 port_config_mask
;
645 int port3_lanes_shift
;
647 if (isp
->media_dev
.hw_revision
<
648 ATOMISP_HW_REVISION_ISP2401_LEGACY
<<
649 ATOMISP_HW_REVISION_SHIFT
) {
651 port_config_mask
= MRFLD_PORT_CONFIG_MASK
;
652 port3_lanes_shift
= MRFLD_PORT3_LANES_SHIFT
;
654 /* Moorefield / Cherryview */
655 port_config_mask
= CHV_PORT_CONFIG_MASK
;
656 port3_lanes_shift
= CHV_PORT3_LANES_SHIFT
;
659 if (isp
->media_dev
.hw_revision
<
660 ATOMISP_HW_REVISION_ISP2401
<<
661 ATOMISP_HW_REVISION_SHIFT
) {
662 /* Merrifield / Moorefield legacy input system */
663 nportconfigs
= MRFLD_PORT_CONFIG_NUM
;
665 /* Moorefield / Cherryview new input system */
666 nportconfigs
= ARRAY_SIZE(portconfigs
);
669 for (i
= 0; i
< isp
->input_cnt
; i
++) {
670 struct camera_mipi_info
*mipi_info
;
672 if (isp
->inputs
[i
].type
!= RAW_CAMERA
&&
673 isp
->inputs
[i
].type
!= SOC_CAMERA
)
676 mipi_info
= atomisp_to_sensor_mipi_info(isp
->inputs
[i
].camera
);
680 switch (mipi_info
->port
) {
681 case ATOMISP_CAMERA_PORT_PRIMARY
:
682 sensor_lanes
[0] = mipi_info
->num_lanes
;
684 case ATOMISP_CAMERA_PORT_SECONDARY
:
685 sensor_lanes
[1] = mipi_info
->num_lanes
;
687 case ATOMISP_CAMERA_PORT_TERTIARY
:
688 sensor_lanes
[2] = mipi_info
->num_lanes
;
692 "%s: invalid port: %d for the %dth sensor\n",
693 __func__
, mipi_info
->port
, i
);
698 for (i
= 0; i
< nportconfigs
; i
++) {
699 for (j
= 0; j
< MRFLD_PORT_NUM
; j
++)
700 if (sensor_lanes
[j
] &&
701 sensor_lanes
[j
] != portconfigs
[i
].lanes
[j
])
704 if (j
== MRFLD_PORT_NUM
)
705 break; /* Found matching setting */
708 if (i
>= nportconfigs
) {
710 "%s: could not find the CSI port setting for %d-%d-%d\n",
712 sensor_lanes
[0], sensor_lanes
[1], sensor_lanes
[2]);
716 pci_read_config_dword(isp
->pdev
, MRFLD_PCI_CSI_CONTROL
, &csi_control
);
717 csi_control
&= ~port_config_mask
;
718 csi_control
|= (portconfigs
[i
].code
<< MRFLD_PORT_CONFIGCODE_SHIFT
)
719 | (portconfigs
[i
].lanes
[0] ? 0 : (1 << MRFLD_PORT1_ENABLE_SHIFT
))
720 | (portconfigs
[i
].lanes
[1] ? 0 : (1 << MRFLD_PORT2_ENABLE_SHIFT
))
721 | (portconfigs
[i
].lanes
[2] ? 0 : (1 << MRFLD_PORT3_ENABLE_SHIFT
))
722 | (((1 << portconfigs
[i
].lanes
[0]) - 1) << MRFLD_PORT1_LANES_SHIFT
)
723 | (((1 << portconfigs
[i
].lanes
[1]) - 1) << MRFLD_PORT2_LANES_SHIFT
)
724 | (((1 << portconfigs
[i
].lanes
[2]) - 1) << port3_lanes_shift
);
726 pci_write_config_dword(isp
->pdev
, MRFLD_PCI_CSI_CONTROL
, csi_control
);
729 "%s: the portconfig is %d-%d-%d, CSI_CONTROL is 0x%08X\n",
730 __func__
, portconfigs
[i
].lanes
[0], portconfigs
[i
].lanes
[1],
731 portconfigs
[i
].lanes
[2], csi_control
);
736 static int atomisp_subdev_probe(struct atomisp_device
*isp
)
738 const struct atomisp_platform_data
*pdata
;
739 struct intel_v4l2_subdev_table
*subdevs
;
740 int ret
, raw_index
= -1;
742 pdata
= atomisp_get_platform_data();
744 dev_err(isp
->dev
, "no platform data available\n");
748 for (subdevs
= pdata
->subdevs
; subdevs
->type
; ++subdevs
) {
749 struct v4l2_subdev
*subdev
;
750 struct i2c_board_info
*board_info
=
751 &subdevs
->v4l2_subdev
.board_info
;
752 struct i2c_adapter
*adapter
=
753 i2c_get_adapter(subdevs
->v4l2_subdev
.i2c_adapter_id
);
754 struct camera_sensor_platform_data
*sensor_pdata
;
757 if (adapter
== NULL
) {
759 "Failed to find i2c adapter for subdev %s\n",
764 /* In G-Min, the sensor devices will already be probed
765 * (via ACPI) and registered, do not create new
767 subdev
= atomisp_gmin_find_subdev(adapter
, board_info
);
768 ret
= v4l2_device_register_subdev(&isp
->v4l2_dev
, subdev
);
770 dev_warn(isp
->dev
, "Subdev %s detection fail\n",
775 if (subdev
== NULL
) {
776 dev_warn(isp
->dev
, "Subdev %s detection fail\n",
781 dev_info(isp
->dev
, "Subdev %s successfully register\n",
784 switch (subdevs
->type
) {
786 raw_index
= isp
->input_cnt
;
787 dev_dbg(isp
->dev
, "raw_index: %d\n", raw_index
);
789 dev_dbg(isp
->dev
, "SOC_INDEX: %d\n", isp
->input_cnt
);
790 if (isp
->input_cnt
>= ATOM_ISP_MAX_INPUTS
) {
792 "too many atomisp inputs, ignored\n");
796 isp
->inputs
[isp
->input_cnt
].type
= subdevs
->type
;
797 isp
->inputs
[isp
->input_cnt
].port
= subdevs
->port
;
798 isp
->inputs
[isp
->input_cnt
].camera
= subdev
;
799 isp
->inputs
[isp
->input_cnt
].sensor_index
= 0;
801 * initialize the subdev frame size, then next we can
802 * judge whether frame_size store effective value via
805 isp
->inputs
[isp
->input_cnt
].frame_size
.pixel_format
= 0;
806 sensor_pdata
= (struct camera_sensor_platform_data
*)
807 board_info
->platform_data
;
808 if (sensor_pdata
->get_camera_caps
)
809 isp
->inputs
[isp
->input_cnt
].camera_caps
=
810 sensor_pdata
->get_camera_caps();
812 isp
->inputs
[isp
->input_cnt
].camera_caps
=
813 atomisp_get_default_camera_caps();
814 sensor_num
= isp
->inputs
[isp
->input_cnt
]
815 .camera_caps
->sensor_num
;
817 for (i
= 1; i
< sensor_num
; i
++) {
818 if (isp
->input_cnt
>= ATOM_ISP_MAX_INPUTS
) {
820 "atomisp inputs out of range\n");
823 isp
->inputs
[isp
->input_cnt
] =
824 isp
->inputs
[isp
->input_cnt
- 1];
825 isp
->inputs
[isp
->input_cnt
].sensor_index
= i
;
837 dev_dbg(isp
->dev
, "unknown subdev probed\n");
844 * HACK: Currently VCM belongs to primary sensor only, but correct
845 * approach must be to acquire from platform code which sensor
848 if (isp
->motor
&& raw_index
>= 0)
849 isp
->inputs
[raw_index
].motor
= isp
->motor
;
851 /* Proceed even if no modules detected. For COS mode and no modules. */
852 if (!isp
->inputs
[0].camera
)
853 dev_warn(isp
->dev
, "no camera attached or fail to detect\n");
855 return atomisp_csi_lane_config(isp
);
858 static void atomisp_unregister_entities(struct atomisp_device
*isp
)
861 struct v4l2_subdev
*sd
, *next
;
863 for (i
= 0; i
< isp
->num_of_streams
; i
++)
864 atomisp_subdev_unregister_entities(&isp
->asd
[i
]);
865 atomisp_tpg_unregister_entities(&isp
->tpg
);
866 atomisp_file_input_unregister_entities(&isp
->file_dev
);
867 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++)
868 atomisp_mipi_csi2_unregister_entities(&isp
->csi2_port
[i
]);
870 list_for_each_entry_safe(sd
, next
, &isp
->v4l2_dev
.subdevs
, list
)
871 v4l2_device_unregister_subdev(sd
);
873 v4l2_device_unregister(&isp
->v4l2_dev
);
874 media_device_unregister(&isp
->media_dev
);
877 static int atomisp_register_entities(struct atomisp_device
*isp
)
882 isp
->media_dev
.dev
= isp
->dev
;
884 strlcpy(isp
->media_dev
.model
, "Intel Atom ISP",
885 sizeof(isp
->media_dev
.model
));
887 media_device_init(&isp
->media_dev
);
888 isp
->v4l2_dev
.mdev
= &isp
->media_dev
;
889 ret
= v4l2_device_register(isp
->dev
, &isp
->v4l2_dev
);
891 dev_err(isp
->dev
, "%s: V4L2 device registration failed (%d)\n",
893 goto v4l2_device_failed
;
896 ret
= atomisp_subdev_probe(isp
);
898 goto csi_and_subdev_probe_failed
;
900 /* Register internal entities */
901 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++) {
902 ret
= atomisp_mipi_csi2_register_entities(&isp
->csi2_port
[i
],
908 dev_err(isp
->dev
, "failed to register the CSI port: %d\n", i
);
909 /* deregister all registered CSI ports */
911 atomisp_mipi_csi2_unregister_entities(
914 goto csi_and_subdev_probe_failed
;
918 atomisp_file_input_register_entities(&isp
->file_dev
, &isp
->v4l2_dev
);
920 dev_err(isp
->dev
, "atomisp_file_input_register_entities\n");
921 goto file_input_register_failed
;
924 ret
= atomisp_tpg_register_entities(&isp
->tpg
, &isp
->v4l2_dev
);
926 dev_err(isp
->dev
, "atomisp_tpg_register_entities\n");
927 goto tpg_register_failed
;
930 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
931 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
933 ret
= atomisp_subdev_register_entities(asd
, &isp
->v4l2_dev
);
936 "atomisp_subdev_register_entities fail\n");
938 atomisp_subdev_unregister_entities(
940 goto subdev_register_failed
;
944 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
945 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
947 init_completion(&asd
->init_done
);
949 asd
->delayed_init_workq
=
950 alloc_workqueue(isp
->v4l2_dev
.name
, WQ_CPU_INTENSIVE
,
952 if (asd
->delayed_init_workq
== NULL
) {
954 "Failed to initialize delayed init workq\n");
958 destroy_workqueue(isp
->asd
[i
- 1].
960 goto wq_alloc_failed
;
962 INIT_WORK(&asd
->delayed_init_work
, atomisp_delayed_init_work
);
965 for (i
= 0; i
< isp
->input_cnt
; i
++) {
966 if (isp
->inputs
[i
].port
>= ATOMISP_CAMERA_NR_PORTS
) {
967 dev_err(isp
->dev
, "isp->inputs port %d not supported\n",
968 isp
->inputs
[i
].port
);
975 "FILE_INPUT enable, camera_cnt: %d\n", isp
->input_cnt
);
976 isp
->inputs
[isp
->input_cnt
].type
= FILE_INPUT
;
977 isp
->inputs
[isp
->input_cnt
].port
= -1;
978 isp
->inputs
[isp
->input_cnt
].camera_caps
=
979 atomisp_get_default_camera_caps();
980 isp
->inputs
[isp
->input_cnt
++].camera
= &isp
->file_dev
.sd
;
982 if (isp
->input_cnt
< ATOM_ISP_MAX_INPUTS
) {
984 "TPG detected, camera_cnt: %d\n", isp
->input_cnt
);
985 isp
->inputs
[isp
->input_cnt
].type
= TEST_PATTERN
;
986 isp
->inputs
[isp
->input_cnt
].port
= -1;
987 isp
->inputs
[isp
->input_cnt
].camera_caps
=
988 atomisp_get_default_camera_caps();
989 isp
->inputs
[isp
->input_cnt
++].camera
= &isp
->tpg
.sd
;
991 dev_warn(isp
->dev
, "too many atomisp inputs, TPG ignored.\n");
994 ret
= v4l2_device_register_subdev_nodes(&isp
->v4l2_dev
);
998 return media_device_register(&isp
->media_dev
);
1001 for (i
= 0; i
< isp
->num_of_streams
; i
++)
1002 destroy_workqueue(isp
->asd
[i
].
1003 delayed_init_workq
);
1005 for (i
= 0; i
< isp
->num_of_streams
; i
++)
1006 atomisp_subdev_unregister_entities(
1008 subdev_register_failed
:
1009 atomisp_tpg_unregister_entities(&isp
->tpg
);
1010 tpg_register_failed
:
1011 atomisp_file_input_unregister_entities(&isp
->file_dev
);
1012 file_input_register_failed
:
1013 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++)
1014 atomisp_mipi_csi2_unregister_entities(&isp
->csi2_port
[i
]);
1015 csi_and_subdev_probe_failed
:
1016 v4l2_device_unregister(&isp
->v4l2_dev
);
1018 media_device_unregister(&isp
->media_dev
);
1019 media_device_cleanup(&isp
->media_dev
);
1023 static int atomisp_initialize_modules(struct atomisp_device
*isp
)
1027 ret
= atomisp_mipi_csi2_init(isp
);
1029 dev_err(isp
->dev
, "mipi csi2 initialization failed\n");
1030 goto error_mipi_csi2
;
1033 ret
= atomisp_file_input_init(isp
);
1036 "file input device initialization failed\n");
1037 goto error_file_input
;
1040 ret
= atomisp_tpg_init(isp
);
1042 dev_err(isp
->dev
, "tpg initialization failed\n");
1046 ret
= atomisp_subdev_init(isp
);
1048 dev_err(isp
->dev
, "ISP subdev initialization failed\n");
1049 goto error_isp_subdev
;
1057 atomisp_tpg_cleanup(isp
);
1059 atomisp_file_input_cleanup(isp
);
1061 atomisp_mipi_csi2_cleanup(isp
);
1065 static void atomisp_uninitialize_modules(struct atomisp_device
*isp
)
1067 atomisp_tpg_cleanup(isp
);
1068 atomisp_file_input_cleanup(isp
);
1069 atomisp_mipi_csi2_cleanup(isp
);
1072 const struct firmware
*
1073 atomisp_load_firmware(struct atomisp_device
*isp
)
1075 const struct firmware
*fw
;
1077 char *fw_path
= NULL
;
1082 if (isp
->media_dev
.hw_revision
==
1083 ((ATOMISP_HW_REVISION_ISP2401
<< ATOMISP_HW_REVISION_SHIFT
)
1084 | ATOMISP_HW_STEPPING_A0
))
1085 fw_path
= "shisp_2401a0_v21.bin";
1087 if (isp
->media_dev
.hw_revision
==
1088 ((ATOMISP_HW_REVISION_ISP2401_LEGACY
<< ATOMISP_HW_REVISION_SHIFT
)
1089 | ATOMISP_HW_STEPPING_A0
))
1090 fw_path
= "shisp_2401a0_legacy_v21.bin";
1092 if (isp
->media_dev
.hw_revision
==
1093 ((ATOMISP_HW_REVISION_ISP2400
<< ATOMISP_HW_REVISION_SHIFT
)
1094 | ATOMISP_HW_STEPPING_B0
))
1095 fw_path
= "shisp_2400b0_v21.bin";
1098 dev_err(isp
->dev
, "Unsupported hw_revision 0x%x\n",
1099 isp
->media_dev
.hw_revision
);
1103 rc
= request_firmware(&fw
, fw_path
, isp
->dev
);
1106 "atomisp: Error %d while requesting firmware %s\n",
1115 * Check for flags the driver was compiled with against the PCI
1116 * device. Always returns true on other than ISP 2400.
1118 static bool is_valid_device(struct pci_dev
*dev
,
1119 const struct pci_device_id
*id
)
1121 unsigned int a0_max_id
;
1123 switch (id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) {
1124 case ATOMISP_PCI_DEVICE_SOC_MRFLD
:
1125 a0_max_id
= ATOMISP_PCI_REV_MRFLD_A0_MAX
;
1127 case ATOMISP_PCI_DEVICE_SOC_BYT
:
1128 a0_max_id
= ATOMISP_PCI_REV_BYT_A0_MAX
;
1134 return dev
->revision
> a0_max_id
;
1137 static int init_atomisp_wdts(struct atomisp_device
*isp
)
1141 atomic_set(&isp
->wdt_work_queued
, 0);
1142 isp
->wdt_work_queue
= alloc_workqueue(isp
->v4l2_dev
.name
, 0, 1);
1143 if (isp
->wdt_work_queue
== NULL
) {
1144 dev_err(isp
->dev
, "Failed to initialize wdt work queue\n");
1148 INIT_WORK(&isp
->wdt_work
, atomisp_wdt_work
);
1150 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
1151 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
1154 setup_timer(&asd
->wdt
, atomisp_wdt
, (unsigned long)isp
);
1156 setup_timer(&asd
->video_out_capture
.wdt
,
1157 atomisp_wdt
, (unsigned long)&asd
->video_out_capture
);
1158 setup_timer(&asd
->video_out_preview
.wdt
,
1159 atomisp_wdt
, (unsigned long)&asd
->video_out_preview
);
1160 setup_timer(&asd
->video_out_vf
.wdt
,
1161 atomisp_wdt
, (unsigned long)&asd
->video_out_vf
);
1162 setup_timer(&asd
->video_out_video_capture
.wdt
,
1164 (unsigned long)&asd
->video_out_video_capture
);
1172 static struct pci_driver atomisp_pci_driver
;
1174 #define ATOM_ISP_PCI_BAR 0
1176 static int atomisp_pci_probe(struct pci_dev
*dev
,
1177 const struct pci_device_id
*id
)
1179 const struct atomisp_platform_data
*pdata
;
1180 struct atomisp_device
*isp
;
1187 dev_err(&dev
->dev
, "atomisp: error device ptr\n");
1191 if (!is_valid_device(dev
, id
))
1193 /* Pointer to struct device. */
1194 atomisp_dev
= &dev
->dev
;
1196 pdata
= atomisp_get_platform_data();
1198 dev_warn(&dev
->dev
, "no platform data available\n");
1200 err
= pcim_enable_device(dev
);
1202 dev_err(&dev
->dev
, "Failed to enable CI ISP device (%d)\n",
1207 start
= pci_resource_start(dev
, ATOM_ISP_PCI_BAR
);
1208 dev_dbg(&dev
->dev
, "start: 0x%x\n", start
);
1210 err
= pcim_iomap_regions(dev
, 1 << ATOM_ISP_PCI_BAR
, pci_name(dev
));
1212 dev_err(&dev
->dev
, "Failed to I/O memory remapping (%d)\n",
1217 base
= pcim_iomap_table(dev
)[ATOM_ISP_PCI_BAR
];
1218 dev_dbg(&dev
->dev
, "base: %p\n", base
);
1220 atomisp_io_base
= base
;
1222 dev_dbg(&dev
->dev
, "atomisp_io_base: %p\n", atomisp_io_base
);
1224 isp
= devm_kzalloc(&dev
->dev
, sizeof(struct atomisp_device
), GFP_KERNEL
);
1226 dev_err(&dev
->dev
, "Failed to alloc CI ISP structure\n");
1230 isp
->dev
= &dev
->dev
;
1231 isp
->sw_contex
.power_state
= ATOM_ISP_POWER_UP
;
1232 isp
->pci_root
= pci_get_bus_and_slot(0, 0);
1233 if (!isp
->pci_root
) {
1234 dev_err(&dev
->dev
, "Unable to find PCI host\n");
1237 isp
->saved_regs
.ispmmadr
= start
;
1239 rt_mutex_init(&isp
->mutex
);
1240 mutex_init(&isp
->streamoff_mutex
);
1241 spin_lock_init(&isp
->lock
);
1243 /* This is not a true PCI device on SoC, so the delay is not needed. */
1244 isp
->pdev
->d3_delay
= 0;
1246 switch (id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) {
1247 case ATOMISP_PCI_DEVICE_SOC_MRFLD
:
1248 isp
->media_dev
.hw_revision
=
1249 (ATOMISP_HW_REVISION_ISP2400
1250 << ATOMISP_HW_REVISION_SHIFT
) |
1251 ATOMISP_HW_STEPPING_B0
;
1253 switch (id
->device
) {
1254 case ATOMISP_PCI_DEVICE_SOC_MRFLD_1179
:
1255 isp
->dfs
= &dfs_config_merr_1179
;
1257 case ATOMISP_PCI_DEVICE_SOC_MRFLD_117A
:
1258 isp
->dfs
= &dfs_config_merr_117a
;
1261 isp
->dfs
= &dfs_config_merr
;
1264 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1266 case ATOMISP_PCI_DEVICE_SOC_BYT
:
1267 isp
->media_dev
.hw_revision
=
1268 (ATOMISP_HW_REVISION_ISP2400
1269 << ATOMISP_HW_REVISION_SHIFT
) |
1270 ATOMISP_HW_STEPPING_B0
;
1272 if (INTEL_MID_BOARD(3, TABLET
, BYT
, BLK
, PRO
, CRV2
) ||
1273 INTEL_MID_BOARD(3, TABLET
, BYT
, BLK
, ENG
, CRV2
)) {
1274 isp
->dfs
= &dfs_config_byt_cr
;
1275 isp
->hpll_freq
= HPLL_FREQ_2000MHZ
;
1279 isp
->dfs
= &dfs_config_byt
;
1280 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1282 /* HPLL frequency is known to be device-specific, but we don't
1283 * have specs yet for exactly how it varies. Default to
1284 * BYT-CR but let provisioning set it via EFI variable */
1285 isp
->hpll_freq
= gmin_get_var_int(&dev
->dev
, "HpllFreq",
1289 * for BYT/CHT we are put isp into D3cold to avoid pci registers access
1290 * in power off. Set d3cold_delay to 0 since default 100ms is not
1293 isp
->pdev
->d3cold_delay
= 0;
1295 case ATOMISP_PCI_DEVICE_SOC_ANN
:
1296 isp
->media_dev
.hw_revision
= (
1297 #ifdef ISP2401_NEW_INPUT_SYSTEM
1298 ATOMISP_HW_REVISION_ISP2401
1300 ATOMISP_HW_REVISION_ISP2401_LEGACY
1302 << ATOMISP_HW_REVISION_SHIFT
);
1303 isp
->media_dev
.hw_revision
|= isp
->pdev
->revision
< 2 ?
1304 ATOMISP_HW_STEPPING_A0
: ATOMISP_HW_STEPPING_B0
;
1305 isp
->dfs
= &dfs_config_merr
;
1306 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1308 case ATOMISP_PCI_DEVICE_SOC_CHT
:
1309 isp
->media_dev
.hw_revision
= (
1310 #ifdef ISP2401_NEW_INPUT_SYSTEM
1311 ATOMISP_HW_REVISION_ISP2401
1313 ATOMISP_HW_REVISION_ISP2401_LEGACY
1315 << ATOMISP_HW_REVISION_SHIFT
);
1316 isp
->media_dev
.hw_revision
|= isp
->pdev
->revision
< 2 ?
1317 ATOMISP_HW_STEPPING_A0
: ATOMISP_HW_STEPPING_B0
;
1319 isp
->dfs
= &dfs_config_cht
;
1320 isp
->pdev
->d3cold_delay
= 0;
1322 iosf_mbi_read(CCK_PORT
, MBI_REG_READ
, CCK_FUSE_REG_0
, &val
);
1323 switch (val
& CCK_FUSE_HPLL_FREQ_MASK
) {
1325 isp
->hpll_freq
= HPLL_FREQ_800MHZ
;
1328 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1331 isp
->hpll_freq
= HPLL_FREQ_2000MHZ
;
1334 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1336 "read HPLL from cck failed.default 1600MHz.\n");
1340 dev_err(&dev
->dev
, "un-supported IUNIT device\n");
1344 dev_info(&dev
->dev
, "ISP HPLL frequency base = %d MHz\n",
1347 isp
->max_isr_latency
= ATOMISP_MAX_ISR_LATENCY
;
1349 /* Load isp firmware from user space */
1350 if (!defer_fw_load
) {
1351 isp
->firmware
= atomisp_load_firmware(isp
);
1352 if (!isp
->firmware
) {
1357 err
= atomisp_css_check_firmware_version(isp
);
1359 dev_dbg(&dev
->dev
, "Firmware version check failed\n");
1360 goto fw_validation_fail
;
1364 pci_set_master(dev
);
1365 pci_set_drvdata(dev
, isp
);
1367 err
= pci_enable_msi(dev
);
1369 dev_err(&dev
->dev
, "Failed to enable msi (%d)\n", err
);
1370 goto enable_msi_fail
;
1373 atomisp_msi_irq_init(isp
, dev
);
1375 pm_qos_add_request(&isp
->pm_qos
, PM_QOS_CPU_DMA_LATENCY
,
1376 PM_QOS_DEFAULT_VALUE
);
1379 * for MRFLD, Software/firmware needs to write a 1 to bit 0 of
1380 * the register at CSI_RECEIVER_SELECTION_REG to enable SH CSI
1381 * backend write 0 will enable Arasan CSI backend, which has
1382 * bugs(like sighting:4567697 and 4567699) and will be removed
1385 atomisp_store_uint32(MRFLD_CSI_RECEIVER_SELECTION_REG
, 1);
1387 if ((id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) ==
1388 ATOMISP_PCI_DEVICE_SOC_MRFLD
) {
1392 * Workaround for imbalance data eye issue which is observed
1395 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
1397 csi_afe_trim
&= ~((MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1398 MRFLD_PCI_CSI1_HSRXCLKTRIM_SHIFT
) |
1399 (MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1400 MRFLD_PCI_CSI2_HSRXCLKTRIM_SHIFT
) |
1401 (MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1402 MRFLD_PCI_CSI3_HSRXCLKTRIM_SHIFT
));
1403 csi_afe_trim
|= (MRFLD_PCI_CSI1_HSRXCLKTRIM
<<
1404 MRFLD_PCI_CSI1_HSRXCLKTRIM_SHIFT
) |
1405 (MRFLD_PCI_CSI2_HSRXCLKTRIM
<<
1406 MRFLD_PCI_CSI2_HSRXCLKTRIM_SHIFT
) |
1407 (MRFLD_PCI_CSI3_HSRXCLKTRIM
<<
1408 MRFLD_PCI_CSI3_HSRXCLKTRIM_SHIFT
);
1409 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
1413 err
= atomisp_initialize_modules(isp
);
1415 dev_err(&dev
->dev
, "atomisp_initialize_modules (%d)\n", err
);
1416 goto initialize_modules_fail
;
1419 err
= atomisp_register_entities(isp
);
1421 dev_err(&dev
->dev
, "atomisp_register_entities failed (%d)\n",
1423 goto register_entities_fail
;
1425 err
= atomisp_create_pads_links(isp
);
1427 goto register_entities_fail
;
1428 /* init atomisp wdts */
1429 if (init_atomisp_wdts(isp
) != 0)
1430 goto wdt_work_queue_fail
;
1432 /* save the iunit context only once after all the values are init'ed. */
1433 atomisp_save_iunit_reg(isp
);
1435 pm_runtime_put_noidle(&dev
->dev
);
1436 pm_runtime_allow(&dev
->dev
);
1438 hmm_init_mem_stat(repool_pgnr
, dypool_enable
, dypool_pgnr
);
1439 err
= hmm_pool_register(repool_pgnr
, HMM_POOL_TYPE_RESERVED
);
1441 dev_err(&dev
->dev
, "Failed to register reserved memory pool.\n");
1445 /* Init ISP memory management */
1448 err
= devm_request_threaded_irq(&dev
->dev
, dev
->irq
,
1449 atomisp_isr
, atomisp_isr_thread
,
1450 IRQF_SHARED
, "isp_irq", isp
);
1452 dev_err(&dev
->dev
, "Failed to request irq (%d)\n", err
);
1453 goto request_irq_fail
;
1456 /* Load firmware into ISP memory */
1457 if (!defer_fw_load
) {
1458 err
= atomisp_css_load_firmware(isp
);
1460 dev_err(&dev
->dev
, "Failed to init css.\n");
1464 dev_dbg(&dev
->dev
, "Skip css init.\n");
1466 /* Clear FW image from memory */
1467 release_firmware(isp
->firmware
);
1468 isp
->firmware
= NULL
;
1469 isp
->css_env
.isp_css_fw
.data
= NULL
;
1471 atomisp_drvfs_init(&atomisp_pci_driver
, isp
);
1476 devm_free_irq(&dev
->dev
, dev
->irq
, isp
);
1479 hmm_pool_unregister(HMM_POOL_TYPE_RESERVED
);
1481 destroy_workqueue(isp
->wdt_work_queue
);
1482 wdt_work_queue_fail
:
1483 atomisp_acc_cleanup(isp
);
1484 atomisp_unregister_entities(isp
);
1485 register_entities_fail
:
1486 atomisp_uninitialize_modules(isp
);
1487 initialize_modules_fail
:
1488 pm_qos_remove_request(&isp
->pm_qos
);
1489 atomisp_msi_irq_uninit(isp
, dev
);
1492 release_firmware(isp
->firmware
);
1495 * Switch off ISP, as keeping it powered on would prevent
1496 * reaching S0ix states.
1498 * The following lines have been copied from atomisp suspend path
1501 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
1502 irq
= irq
& 1 << INTR_IIR
;
1503 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
1505 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
1506 irq
&= ~(1 << INTR_IER
);
1507 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
1509 atomisp_msi_irq_uninit(isp
, dev
);
1511 atomisp_ospm_dphy_down(isp
);
1513 /* Address later when we worry about the ...field chips */
1514 if (IS_ENABLED(CONFIG_PM
) && atomisp_mrfld_power_down(isp
))
1515 dev_err(&dev
->dev
, "Failed to switch off ISP\n");
1516 pci_dev_put(isp
->pci_root
);
1520 static void atomisp_pci_remove(struct pci_dev
*dev
)
1522 struct atomisp_device
*isp
= (struct atomisp_device
*)
1523 pci_get_drvdata(dev
);
1525 atomisp_drvfs_exit();
1527 atomisp_acc_cleanup(isp
);
1529 atomisp_css_unload_firmware(isp
);
1532 pm_runtime_forbid(&dev
->dev
);
1533 pm_runtime_get_noresume(&dev
->dev
);
1534 pm_qos_remove_request(&isp
->pm_qos
);
1536 atomisp_msi_irq_uninit(isp
, dev
);
1537 pci_dev_put(isp
->pci_root
);
1539 atomisp_unregister_entities(isp
);
1541 destroy_workqueue(isp
->wdt_work_queue
);
1542 atomisp_file_input_cleanup(isp
);
1544 release_firmware(isp
->firmware
);
1546 hmm_pool_unregister(HMM_POOL_TYPE_RESERVED
);
1549 static const struct pci_device_id atomisp_pci_tbl
[] = {
1550 #if defined(ISP2400) || defined(ISP2400B0)
1552 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1178)},
1553 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1179)},
1554 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x117a)},
1556 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0f38)},
1557 #elif defined(ISP2401)
1558 /* Anniedale (Merrifield+ / Moorefield) */
1559 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1478)},
1561 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x22b8)},
1566 MODULE_DEVICE_TABLE(pci
, atomisp_pci_tbl
);
1568 static const struct dev_pm_ops atomisp_pm_ops
= {
1569 .runtime_suspend
= atomisp_runtime_suspend
,
1570 .runtime_resume
= atomisp_runtime_resume
,
1571 .suspend
= atomisp_suspend
,
1572 .resume
= atomisp_resume
,
1575 static struct pci_driver atomisp_pci_driver
= {
1577 .pm
= &atomisp_pm_ops
,
1579 .name
= "atomisp-isp2",
1580 .id_table
= atomisp_pci_tbl
,
1581 .probe
= atomisp_pci_probe
,
1582 .remove
= atomisp_pci_remove
,
1585 static int __init
atomisp_init(void)
1587 return pci_register_driver(&atomisp_pci_driver
);
1590 static void __exit
atomisp_exit(void)
1592 pci_unregister_driver(&atomisp_pci_driver
);
1595 module_init(atomisp_init
);
1596 module_exit(atomisp_exit
);
1598 MODULE_AUTHOR("Wen Wang <wen.w.wang@intel.com>");
1599 MODULE_AUTHOR("Xiaolin Zhang <xiaolin.zhang@intel.com>");
1600 MODULE_LICENSE("GPL");
1601 MODULE_DESCRIPTION("Intel ATOM Platform ISP Driver");