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 "../../include/linux/atomisp_gmin_platform.h"
33 #include "atomisp_cmd.h"
34 #include "atomisp_common.h"
35 #include "atomisp_fops.h"
36 #include "atomisp_file.h"
37 #include "atomisp_ioctl.h"
38 #include "atomisp_internal.h"
39 #include "atomisp_acc.h"
40 #include "atomisp-regs.h"
41 #include "atomisp_dfs_tables.h"
42 #include "atomisp_drvfs.h"
44 #include "atomisp_trace_event.h"
46 #include "hrt/hive_isp_css_mm_hrt.h"
48 #include "device_access.h"
49 #include <asm/intel-mid.h>
51 /* G-Min addition: pull this in from intel_mid_pm.h */
52 #define CSTATE_EXIT_LATENCY_C1 1
54 static uint skip_fwload
;
55 module_param(skip_fwload
, uint
, 0644);
56 MODULE_PARM_DESC(skip_fwload
, "Skip atomisp firmware load");
58 /* set reserved memory pool size in page */
59 static unsigned int repool_pgnr
;
60 module_param(repool_pgnr
, uint
, 0644);
61 MODULE_PARM_DESC(repool_pgnr
,
62 "Set the reserved memory pool size in page (default:0)");
64 /* set dynamic memory pool size in page */
65 unsigned int dypool_pgnr
= UINT_MAX
;
66 module_param(dypool_pgnr
, uint
, 0644);
67 MODULE_PARM_DESC(dypool_pgnr
,
68 "Set the dynamic memory pool size in page (default:0)");
71 module_param(dypool_enable
, bool, 0644);
72 MODULE_PARM_DESC(dypool_enable
,
73 "dynamic memory pool enable/disable (default:disable)");
75 /* memory optimization: deferred firmware loading */
77 module_param(defer_fw_load
, bool, 0644);
78 MODULE_PARM_DESC(defer_fw_load
,
79 "Defer FW loading until device is opened (default:disable)");
81 /* cross componnet debug message flag */
83 module_param(dbg_level
, int, 0644);
84 MODULE_PARM_DESC(dbg_level
, "debug message on/off (default:off)");
86 /* log function switch */
88 module_param(dbg_func
, int, 0644);
89 MODULE_PARM_DESC(dbg_func
,
90 "log function switch non/trace_printk/printk (default:printk)");
93 module_param(mipicsi_flag
, int, 0644);
94 MODULE_PARM_DESC(mipicsi_flag
, "mipi csi compression predictor algorithm");
96 /*set to 16x16 since this is the amount of lines and pixels the sensor
97 exports extra. If these are kept at the 10x8 that they were on, in yuv
98 downscaling modes incorrect resolutions where requested to the sensor
99 driver with strange outcomes as a result. The proper way tot do this
100 would be to have a list of tables the specify the sensor res, mipi rec,
101 output res, and isp output res. however since we do not have this yet,
102 the chosen solution is the next best thing. */
104 module_param(pad_w
, int, 0644);
105 MODULE_PARM_DESC(pad_w
, "extra data for ISP processing");
108 module_param(pad_h
, int, 0644);
109 MODULE_PARM_DESC(pad_h
, "extra data for ISP processing");
111 struct device
*atomisp_dev
;
113 void __iomem
*atomisp_io_base
;
115 int atomisp_video_init(struct atomisp_video_pipe
*video
, const char *name
)
118 const char *direction
;
120 switch (video
->type
) {
121 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
122 direction
= "output";
123 video
->pad
.flags
= MEDIA_PAD_FL_SINK
;
124 video
->vdev
.fops
= &atomisp_fops
;
125 video
->vdev
.ioctl_ops
= &atomisp_ioctl_ops
;
127 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
129 video
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
130 video
->vdev
.fops
= &atomisp_file_fops
;
131 video
->vdev
.ioctl_ops
= &atomisp_file_ioctl_ops
;
137 ret
= media_entity_pads_init(&video
->vdev
.entity
, 1, &video
->pad
);
141 /* Initialize the video device. */
142 snprintf(video
->vdev
.name
, sizeof(video
->vdev
.name
),
143 "ATOMISP ISP %s %s", name
, direction
);
144 video
->vdev
.release
= video_device_release_empty
;
145 video_set_drvdata(&video
->vdev
, video
->isp
);
150 void atomisp_acc_init(struct atomisp_acc_pipe
*video
, const char *name
)
152 video
->vdev
.fops
= &atomisp_fops
;
153 video
->vdev
.ioctl_ops
= &atomisp_ioctl_ops
;
155 /* Initialize the video device. */
156 snprintf(video
->vdev
.name
, sizeof(video
->vdev
.name
),
157 "ATOMISP ISP %s", name
);
158 video
->vdev
.release
= video_device_release_empty
;
159 video_set_drvdata(&video
->vdev
, video
->isp
);
162 int atomisp_video_register(struct atomisp_video_pipe
*video
,
163 struct v4l2_device
*vdev
)
167 video
->vdev
.v4l2_dev
= vdev
;
169 ret
= video_register_device(&video
->vdev
, VFL_TYPE_GRABBER
, -1);
171 dev_err(vdev
->dev
, "%s: could not register video device (%d)\n",
177 int atomisp_acc_register(struct atomisp_acc_pipe
*video
,
178 struct v4l2_device
*vdev
)
182 video
->vdev
.v4l2_dev
= vdev
;
184 ret
= video_register_device(&video
->vdev
, VFL_TYPE_GRABBER
, -1);
186 dev_err(vdev
->dev
, "%s: could not register video device (%d)\n",
192 void atomisp_video_unregister(struct atomisp_video_pipe
*video
)
194 if (video_is_registered(&video
->vdev
)) {
195 media_entity_cleanup(&video
->vdev
.entity
);
196 video_unregister_device(&video
->vdev
);
200 void atomisp_acc_unregister(struct atomisp_acc_pipe
*video
)
202 if (video_is_registered(&video
->vdev
))
203 video_unregister_device(&video
->vdev
);
206 static int atomisp_save_iunit_reg(struct atomisp_device
*isp
)
208 struct pci_dev
*dev
= isp
->pdev
;
210 dev_dbg(isp
->dev
, "%s\n", __func__
);
212 pci_read_config_word(dev
, PCI_COMMAND
, &isp
->saved_regs
.pcicmdsts
);
213 /* isp->saved_regs.ispmmadr is set from the atomisp_pci_probe() */
214 pci_read_config_dword(dev
, PCI_MSI_CAPID
, &isp
->saved_regs
.msicap
);
215 pci_read_config_dword(dev
, PCI_MSI_ADDR
, &isp
->saved_regs
.msi_addr
);
216 pci_read_config_word(dev
, PCI_MSI_DATA
, &isp
->saved_regs
.msi_data
);
217 pci_read_config_byte(dev
, PCI_INTERRUPT_LINE
, &isp
->saved_regs
.intr
);
218 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
,
219 &isp
->saved_regs
.interrupt_control
);
221 pci_read_config_dword(dev
, MRFLD_PCI_PMCS
,
222 &isp
->saved_regs
.pmcs
);
223 /* Ensure read/write combining is enabled. */
224 pci_read_config_dword(dev
, PCI_I_CONTROL
,
225 &isp
->saved_regs
.i_control
);
226 isp
->saved_regs
.i_control
|=
227 MRFLD_PCI_I_CONTROL_ENABLE_READ_COMBINING
|
228 MRFLD_PCI_I_CONTROL_ENABLE_WRITE_COMBINING
;
229 pci_read_config_dword(dev
, MRFLD_PCI_CSI_ACCESS_CTRL_VIOL
,
230 &isp
->saved_regs
.csi_access_viol
);
231 pci_read_config_dword(dev
, MRFLD_PCI_CSI_RCOMP_CONTROL
,
232 &isp
->saved_regs
.csi_rcomp_config
);
234 * Hardware bugs require setting CSI_HS_OVR_CLK_GATE_ON_UPDATE.
235 * ANN/CHV: RCOMP updates do not happen when using CSI2+ path
236 * and sensor sending "continuous clock".
237 * TNG/ANN/CHV: MIPI packets are lost if the HS entry sequence
238 * is missed, and IUNIT can hang.
239 * For both issues, setting this bit is a workaround.
241 isp
->saved_regs
.csi_rcomp_config
|=
242 MRFLD_PCI_CSI_HS_OVR_CLK_GATE_ON_UPDATE
;
243 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
244 &isp
->saved_regs
.csi_afe_dly
);
245 pci_read_config_dword(dev
, MRFLD_PCI_CSI_CONTROL
,
246 &isp
->saved_regs
.csi_control
);
247 if (isp
->media_dev
.hw_revision
>=
248 (ATOMISP_HW_REVISION_ISP2401
<< ATOMISP_HW_REVISION_SHIFT
))
249 isp
->saved_regs
.csi_control
|=
250 MRFLD_PCI_CSI_CONTROL_PARPATHEN
;
252 * On CHT CSI_READY bit should be enabled before stream on
254 if (IS_CHT
&& (isp
->media_dev
.hw_revision
>= ((ATOMISP_HW_REVISION_ISP2401
<<
255 ATOMISP_HW_REVISION_SHIFT
) | ATOMISP_HW_STEPPING_B0
)))
256 isp
->saved_regs
.csi_control
|=
257 MRFLD_PCI_CSI_CONTROL_CSI_READY
;
258 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_RCOMP_CONTROL
,
259 &isp
->saved_regs
.csi_afe_rcomp_config
);
260 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_HS_CONTROL
,
261 &isp
->saved_regs
.csi_afe_hs_control
);
262 pci_read_config_dword(dev
, MRFLD_PCI_CSI_DEADLINE_CONTROL
,
263 &isp
->saved_regs
.csi_deadline_control
);
267 static int __maybe_unused
atomisp_restore_iunit_reg(struct atomisp_device
*isp
)
269 struct pci_dev
*dev
= isp
->pdev
;
271 dev_dbg(isp
->dev
, "%s\n", __func__
);
273 pci_write_config_word(dev
, PCI_COMMAND
, isp
->saved_regs
.pcicmdsts
);
274 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
275 isp
->saved_regs
.ispmmadr
);
276 pci_write_config_dword(dev
, PCI_MSI_CAPID
, isp
->saved_regs
.msicap
);
277 pci_write_config_dword(dev
, PCI_MSI_ADDR
, isp
->saved_regs
.msi_addr
);
278 pci_write_config_word(dev
, PCI_MSI_DATA
, isp
->saved_regs
.msi_data
);
279 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, isp
->saved_regs
.intr
);
280 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
,
281 isp
->saved_regs
.interrupt_control
);
282 pci_write_config_dword(dev
, PCI_I_CONTROL
,
283 isp
->saved_regs
.i_control
);
285 pci_write_config_dword(dev
, MRFLD_PCI_PMCS
,
286 isp
->saved_regs
.pmcs
);
287 pci_write_config_dword(dev
, MRFLD_PCI_CSI_ACCESS_CTRL_VIOL
,
288 isp
->saved_regs
.csi_access_viol
);
289 pci_write_config_dword(dev
, MRFLD_PCI_CSI_RCOMP_CONTROL
,
290 isp
->saved_regs
.csi_rcomp_config
);
291 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
292 isp
->saved_regs
.csi_afe_dly
);
293 pci_write_config_dword(dev
, MRFLD_PCI_CSI_CONTROL
,
294 isp
->saved_regs
.csi_control
);
295 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_RCOMP_CONTROL
,
296 isp
->saved_regs
.csi_afe_rcomp_config
);
297 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_HS_CONTROL
,
298 isp
->saved_regs
.csi_afe_hs_control
);
299 pci_write_config_dword(dev
, MRFLD_PCI_CSI_DEADLINE_CONTROL
,
300 isp
->saved_regs
.csi_deadline_control
);
303 * for MRFLD, Software/firmware needs to write a 1 to bit0
304 * of the register at CSI_RECEIVER_SELECTION_REG to enable
305 * SH CSI backend write 0 will enable Arasan CSI backend,
306 * which has bugs(like sighting:4567697 and 4567699) and
307 * will be removed in B0
309 atomisp_store_uint32(MRFLD_CSI_RECEIVER_SELECTION_REG
, 1);
313 static int atomisp_mrfld_pre_power_down(struct atomisp_device
*isp
)
315 struct pci_dev
*dev
= isp
->pdev
;
319 spin_lock_irqsave(&isp
->lock
, flags
);
320 if (isp
->sw_contex
.power_state
== ATOM_ISP_POWER_DOWN
) {
321 spin_unlock_irqrestore(&isp
->lock
, flags
);
322 dev_dbg(isp
->dev
, "<%s %d.\n", __func__
, __LINE__
);
326 * MRFLD HAS requirement: cannot power off i-unit if
327 * ISP has IRQ not serviced.
328 * So, here we need to check if there is any pending
329 * IRQ, if so, waiting for it to be served
331 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
332 irq
= irq
& 1 << INTR_IIR
;
333 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
335 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
336 if (!(irq
& (1 << INTR_IIR
)))
339 atomisp_store_uint32(MRFLD_INTR_CLEAR_REG
, 0xFFFFFFFF);
340 atomisp_load_uint32(MRFLD_INTR_STATUS_REG
, &irq
);
343 "%s: fail to clear isp interrupt status reg=0x%x\n",
345 spin_unlock_irqrestore(&isp
->lock
, flags
);
348 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
349 irq
= irq
& 1 << INTR_IIR
;
350 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
352 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
353 if (!(irq
& (1 << INTR_IIR
))) {
354 atomisp_store_uint32(MRFLD_INTR_ENABLE_REG
, 0x0);
358 "%s: error in iunit interrupt. status reg=0x%x\n",
360 spin_unlock_irqrestore(&isp
->lock
, flags
);
366 * before powering off IUNIT, clear the pending interrupts
367 * and disable the interrupt. driver should avoid writing 0
368 * to IIR. It could block subsequent interrupt messages.
369 * HW sighting:4568410.
371 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
372 irq
&= ~(1 << INTR_IER
);
373 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
375 atomisp_msi_irq_uninit(isp
, dev
);
376 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
377 spin_unlock_irqrestore(&isp
->lock
, flags
);
384 * WA for DDR DVFS enable/disable
385 * By default, ISP will force DDR DVFS 1600MHz before disable DVFS
387 static void punit_ddr_dvfs_enable(bool enable
)
389 int reg
= intel_mid_msgbus_read32(PUNIT_PORT
, MRFLD_ISPSSDVFS
);
390 int door_bell
= 1 << 8;
394 reg
&= ~(MRFLD_BIT0
| MRFLD_BIT1
);
396 reg
|= (MRFLD_BIT1
| door_bell
);
397 reg
&= ~(MRFLD_BIT0
);
400 intel_mid_msgbus_write32(PUNIT_PORT
, MRFLD_ISPSSDVFS
, reg
);
402 /*Check Req_ACK to see freq status, wait until door_bell is cleared*/
403 if (reg
& door_bell
) {
405 if (0 == (intel_mid_msgbus_read32(PUNIT_PORT
,
406 MRFLD_ISPSSDVFS
) & door_bell
))
409 usleep_range(100, 500);
414 pr_info("DDR DVFS, door bell is not cleared within 3ms\n");
417 /* Workaround for pmu_nc_set_power_state not ready in MRFLD */
418 int atomisp_mrfld_power_down(struct atomisp_device
*isp
)
420 unsigned long timeout
;
423 /* writing 0x3 to ISPSSPM0 bit[1:0] to power off the IUNIT */
424 reg_value
= intel_mid_msgbus_read32(PUNIT_PORT
, MRFLD_ISPSSPM0
);
425 reg_value
&= ~MRFLD_ISPSSPM0_ISPSSC_MASK
;
426 reg_value
|= MRFLD_ISPSSPM0_IUNIT_POWER_OFF
;
427 intel_mid_msgbus_write32(PUNIT_PORT
, MRFLD_ISPSSPM0
, reg_value
);
431 punit_ddr_dvfs_enable(true);
434 * There should be no iunit access while power-down is
435 * in progress HW sighting: 4567865
436 * FIXME: msecs_to_jiffies(50)- experienced value
438 timeout
= jiffies
+ msecs_to_jiffies(50);
440 reg_value
= intel_mid_msgbus_read32(PUNIT_PORT
,
442 dev_dbg(isp
->dev
, "power-off in progress, ISPSSPM0: 0x%x\n",
444 /* wait until ISPSSPM0 bit[25:24] shows 0x3 */
445 if ((reg_value
>> MRFLD_ISPSSPM0_ISPSSS_OFFSET
) ==
446 MRFLD_ISPSSPM0_IUNIT_POWER_OFF
) {
451 if (time_after(jiffies
, timeout
)) {
452 dev_err(isp
->dev
, "power-off iunit timeout.\n");
455 /* FIXME: experienced value for delay */
456 usleep_range(100, 150);
461 /* Workaround for pmu_nc_set_power_state not ready in MRFLD */
462 int atomisp_mrfld_power_up(struct atomisp_device
*isp
)
464 unsigned long timeout
;
467 /*WA for PUNIT, if DVFS enabled, ISP timeout observed*/
469 punit_ddr_dvfs_enable(false);
472 * FIXME:WA for ECS28A, with this sleep, CTS
473 * android.hardware.camera2.cts.CameraDeviceTest#testCameraDeviceAbort
474 * PASS, no impact on other platforms
479 /* writing 0x0 to ISPSSPM0 bit[1:0] to power off the IUNIT */
480 reg_value
= intel_mid_msgbus_read32(PUNIT_PORT
, MRFLD_ISPSSPM0
);
481 reg_value
&= ~MRFLD_ISPSSPM0_ISPSSC_MASK
;
482 intel_mid_msgbus_write32(PUNIT_PORT
, MRFLD_ISPSSPM0
, reg_value
);
484 /* FIXME: experienced value for delay */
485 timeout
= jiffies
+ msecs_to_jiffies(50);
487 reg_value
= intel_mid_msgbus_read32(PUNIT_PORT
, MRFLD_ISPSSPM0
);
488 dev_dbg(isp
->dev
, "power-on in progress, ISPSSPM0: 0x%x\n",
490 /* wait until ISPSSPM0 bit[25:24] shows 0x0 */
491 if ((reg_value
>> MRFLD_ISPSSPM0_ISPSSS_OFFSET
) ==
492 MRFLD_ISPSSPM0_IUNIT_POWER_ON
) {
497 if (time_after(jiffies
, timeout
)) {
498 dev_err(isp
->dev
, "power-on iunit timeout.\n");
501 /* FIXME: experienced value for delay */
502 usleep_range(100, 150);
506 int atomisp_runtime_suspend(struct device
*dev
)
508 struct atomisp_device
*isp
= (struct atomisp_device
*)
509 dev_get_drvdata(dev
);
512 ret
= atomisp_mrfld_pre_power_down(isp
);
516 /*Turn off the ISP d-phy*/
517 ret
= atomisp_ospm_dphy_down(isp
);
520 pm_qos_update_request(&isp
->pm_qos
, PM_QOS_DEFAULT_VALUE
);
521 return atomisp_mrfld_power_down(isp
);
524 int atomisp_runtime_resume(struct device
*dev
)
526 struct atomisp_device
*isp
= (struct atomisp_device
*)
527 dev_get_drvdata(dev
);
530 ret
= atomisp_mrfld_power_up(isp
);
534 pm_qos_update_request(&isp
->pm_qos
, isp
->max_isr_latency
);
535 if (isp
->sw_contex
.power_state
== ATOM_ISP_POWER_DOWN
) {
536 /*Turn on ISP d-phy */
537 ret
= atomisp_ospm_dphy_up(isp
);
539 dev_err(isp
->dev
, "Failed to power up ISP!.\n");
544 /*restore register values for iUnit and iUnitPHY registers*/
545 if (isp
->saved_regs
.pcicmdsts
)
546 atomisp_restore_iunit_reg(isp
);
548 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
552 static int __maybe_unused
atomisp_suspend(struct device
*dev
)
554 struct atomisp_device
*isp
= (struct atomisp_device
*)
555 dev_get_drvdata(dev
);
556 /* FIXME: only has one isp_subdev at present */
557 struct atomisp_sub_device
*asd
= &isp
->asd
[0];
562 * FIXME: Suspend is not supported by sensors. Abort if any video
565 if (atomisp_dev_users(isp
))
568 spin_lock_irqsave(&isp
->lock
, flags
);
569 if (asd
->streaming
!= ATOMISP_DEVICE_STREAMING_DISABLED
) {
570 spin_unlock_irqrestore(&isp
->lock
, flags
);
571 dev_err(isp
->dev
, "atomisp cannot suspend at this time.\n");
574 spin_unlock_irqrestore(&isp
->lock
, flags
);
576 ret
= atomisp_mrfld_pre_power_down(isp
);
580 /*Turn off the ISP d-phy */
581 ret
= atomisp_ospm_dphy_down(isp
);
583 dev_err(isp
->dev
, "fail to power off ISP\n");
586 pm_qos_update_request(&isp
->pm_qos
, PM_QOS_DEFAULT_VALUE
);
587 return atomisp_mrfld_power_down(isp
);
590 static int __maybe_unused
atomisp_resume(struct device
*dev
)
592 struct atomisp_device
*isp
= (struct atomisp_device
*)
593 dev_get_drvdata(dev
);
596 ret
= atomisp_mrfld_power_up(isp
);
600 pm_qos_update_request(&isp
->pm_qos
, isp
->max_isr_latency
);
602 /*Turn on ISP d-phy */
603 ret
= atomisp_ospm_dphy_up(isp
);
605 dev_err(isp
->dev
, "Failed to power up ISP!.\n");
609 /*restore register values for iUnit and iUnitPHY registers*/
610 if (isp
->saved_regs
.pcicmdsts
)
611 atomisp_restore_iunit_reg(isp
);
613 atomisp_freq_scaling(isp
, ATOMISP_DFS_MODE_LOW
, true);
617 int atomisp_csi_lane_config(struct atomisp_device
*isp
)
619 static const struct {
621 u8 lanes
[MRFLD_PORT_NUM
];
623 /* Tangier/Merrifield available lane configurations */
624 { 0x00, { 4, 1, 0 } }, /* 00000 */
625 { 0x01, { 3, 1, 0 } }, /* 00001 */
626 { 0x02, { 2, 1, 0 } }, /* 00010 */
627 { 0x03, { 1, 1, 0 } }, /* 00011 */
628 { 0x04, { 2, 1, 2 } }, /* 00100 */
629 { 0x08, { 3, 1, 1 } }, /* 01000 */
630 { 0x09, { 2, 1, 1 } }, /* 01001 */
631 { 0x0a, { 1, 1, 1 } }, /* 01010 */
633 /* Anniedale/Moorefield only configurations */
634 { 0x10, { 4, 2, 0 } }, /* 10000 */
635 { 0x11, { 3, 2, 0 } }, /* 10001 */
636 { 0x12, { 2, 2, 0 } }, /* 10010 */
637 { 0x13, { 1, 2, 0 } }, /* 10011 */
638 { 0x14, { 2, 2, 2 } }, /* 10100 */
639 { 0x18, { 3, 2, 1 } }, /* 11000 */
640 { 0x19, { 2, 2, 1 } }, /* 11001 */
641 { 0x1a, { 1, 2, 1 } }, /* 11010 */
645 u8 sensor_lanes
[MRFLD_PORT_NUM
] = { 0 };
648 u32 port_config_mask
;
649 int port3_lanes_shift
;
651 if (isp
->media_dev
.hw_revision
<
652 ATOMISP_HW_REVISION_ISP2401_LEGACY
<<
653 ATOMISP_HW_REVISION_SHIFT
) {
655 port_config_mask
= MRFLD_PORT_CONFIG_MASK
;
656 port3_lanes_shift
= MRFLD_PORT3_LANES_SHIFT
;
658 /* Moorefield / Cherryview */
659 port_config_mask
= CHV_PORT_CONFIG_MASK
;
660 port3_lanes_shift
= CHV_PORT3_LANES_SHIFT
;
663 if (isp
->media_dev
.hw_revision
<
664 ATOMISP_HW_REVISION_ISP2401
<<
665 ATOMISP_HW_REVISION_SHIFT
) {
666 /* Merrifield / Moorefield legacy input system */
667 nportconfigs
= MRFLD_PORT_CONFIG_NUM
;
669 /* Moorefield / Cherryview new input system */
670 nportconfigs
= ARRAY_SIZE(portconfigs
);
673 for (i
= 0; i
< isp
->input_cnt
; i
++) {
674 struct camera_mipi_info
*mipi_info
;
676 if (isp
->inputs
[i
].type
!= RAW_CAMERA
&&
677 isp
->inputs
[i
].type
!= SOC_CAMERA
)
680 mipi_info
= atomisp_to_sensor_mipi_info(isp
->inputs
[i
].camera
);
684 switch (mipi_info
->port
) {
685 case ATOMISP_CAMERA_PORT_PRIMARY
:
686 sensor_lanes
[0] = mipi_info
->num_lanes
;
688 case ATOMISP_CAMERA_PORT_SECONDARY
:
689 sensor_lanes
[1] = mipi_info
->num_lanes
;
691 case ATOMISP_CAMERA_PORT_TERTIARY
:
692 sensor_lanes
[2] = mipi_info
->num_lanes
;
696 "%s: invalid port: %d for the %dth sensor\n",
697 __func__
, mipi_info
->port
, i
);
702 for (i
= 0; i
< nportconfigs
; i
++) {
703 for (j
= 0; j
< MRFLD_PORT_NUM
; j
++)
704 if (sensor_lanes
[j
] &&
705 sensor_lanes
[j
] != portconfigs
[i
].lanes
[j
])
708 if (j
== MRFLD_PORT_NUM
)
709 break; /* Found matching setting */
712 if (i
>= nportconfigs
) {
714 "%s: could not find the CSI port setting for %d-%d-%d\n",
716 sensor_lanes
[0], sensor_lanes
[1], sensor_lanes
[2]);
720 pci_read_config_dword(isp
->pdev
, MRFLD_PCI_CSI_CONTROL
, &csi_control
);
721 csi_control
&= ~port_config_mask
;
722 csi_control
|= (portconfigs
[i
].code
<< MRFLD_PORT_CONFIGCODE_SHIFT
)
723 | (portconfigs
[i
].lanes
[0] ? 0 : (1 << MRFLD_PORT1_ENABLE_SHIFT
))
724 | (portconfigs
[i
].lanes
[1] ? 0 : (1 << MRFLD_PORT2_ENABLE_SHIFT
))
725 | (portconfigs
[i
].lanes
[2] ? 0 : (1 << MRFLD_PORT3_ENABLE_SHIFT
))
726 | (((1 << portconfigs
[i
].lanes
[0]) - 1) << MRFLD_PORT1_LANES_SHIFT
)
727 | (((1 << portconfigs
[i
].lanes
[1]) - 1) << MRFLD_PORT2_LANES_SHIFT
)
728 | (((1 << portconfigs
[i
].lanes
[2]) - 1) << port3_lanes_shift
);
730 pci_write_config_dword(isp
->pdev
, MRFLD_PCI_CSI_CONTROL
, csi_control
);
733 "%s: the portconfig is %d-%d-%d, CSI_CONTROL is 0x%08X\n",
734 __func__
, portconfigs
[i
].lanes
[0], portconfigs
[i
].lanes
[1],
735 portconfigs
[i
].lanes
[2], csi_control
);
740 static int atomisp_subdev_probe(struct atomisp_device
*isp
)
742 const struct atomisp_platform_data
*pdata
;
743 struct intel_v4l2_subdev_table
*subdevs
;
744 int ret
, raw_index
= -1;
746 pdata
= atomisp_get_platform_data();
748 dev_err(isp
->dev
, "no platform data available\n");
752 for (subdevs
= pdata
->subdevs
; subdevs
->type
; ++subdevs
) {
753 struct v4l2_subdev
*subdev
;
754 struct i2c_board_info
*board_info
=
755 &subdevs
->v4l2_subdev
.board_info
;
756 struct i2c_adapter
*adapter
=
757 i2c_get_adapter(subdevs
->v4l2_subdev
.i2c_adapter_id
);
758 struct camera_sensor_platform_data
*sensor_pdata
;
761 if (adapter
== NULL
) {
763 "Failed to find i2c adapter for subdev %s\n",
768 /* In G-Min, the sensor devices will already be probed
769 * (via ACPI) and registered, do not create new
771 subdev
= atomisp_gmin_find_subdev(adapter
, board_info
);
772 ret
= v4l2_device_register_subdev(&isp
->v4l2_dev
, subdev
);
774 dev_warn(isp
->dev
, "Subdev %s detection fail\n",
779 if (subdev
== NULL
) {
780 dev_warn(isp
->dev
, "Subdev %s detection fail\n",
785 dev_info(isp
->dev
, "Subdev %s successfully register\n",
788 switch (subdevs
->type
) {
790 raw_index
= isp
->input_cnt
;
791 dev_dbg(isp
->dev
, "raw_index: %d\n", raw_index
);
793 dev_dbg(isp
->dev
, "SOC_INDEX: %d\n", isp
->input_cnt
);
794 if (isp
->input_cnt
>= ATOM_ISP_MAX_INPUTS
) {
796 "too many atomisp inputs, ignored\n");
800 isp
->inputs
[isp
->input_cnt
].type
= subdevs
->type
;
801 isp
->inputs
[isp
->input_cnt
].port
= subdevs
->port
;
802 isp
->inputs
[isp
->input_cnt
].camera
= subdev
;
803 isp
->inputs
[isp
->input_cnt
].sensor_index
= 0;
805 * initialize the subdev frame size, then next we can
806 * judge whether frame_size store effective value via
809 isp
->inputs
[isp
->input_cnt
].frame_size
.pixel_format
= 0;
810 sensor_pdata
= (struct camera_sensor_platform_data
*)
811 board_info
->platform_data
;
812 if (sensor_pdata
->get_camera_caps
)
813 isp
->inputs
[isp
->input_cnt
].camera_caps
=
814 sensor_pdata
->get_camera_caps();
816 isp
->inputs
[isp
->input_cnt
].camera_caps
=
817 atomisp_get_default_camera_caps();
818 sensor_num
= isp
->inputs
[isp
->input_cnt
]
819 .camera_caps
->sensor_num
;
821 for (i
= 1; i
< sensor_num
; i
++) {
822 if (isp
->input_cnt
>= ATOM_ISP_MAX_INPUTS
) {
824 "atomisp inputs out of range\n");
827 isp
->inputs
[isp
->input_cnt
] =
828 isp
->inputs
[isp
->input_cnt
- 1];
829 isp
->inputs
[isp
->input_cnt
].sensor_index
= i
;
841 dev_dbg(isp
->dev
, "unknown subdev probed\n");
848 * HACK: Currently VCM belongs to primary sensor only, but correct
849 * approach must be to acquire from platform code which sensor
852 if (isp
->motor
&& raw_index
>= 0)
853 isp
->inputs
[raw_index
].motor
= isp
->motor
;
855 /* Proceed even if no modules detected. For COS mode and no modules. */
856 if (!isp
->inputs
[0].camera
)
857 dev_warn(isp
->dev
, "no camera attached or fail to detect\n");
859 return atomisp_csi_lane_config(isp
);
862 static void atomisp_unregister_entities(struct atomisp_device
*isp
)
865 struct v4l2_subdev
*sd
, *next
;
867 for (i
= 0; i
< isp
->num_of_streams
; i
++)
868 atomisp_subdev_unregister_entities(&isp
->asd
[i
]);
869 atomisp_tpg_unregister_entities(&isp
->tpg
);
870 atomisp_file_input_unregister_entities(&isp
->file_dev
);
871 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++)
872 atomisp_mipi_csi2_unregister_entities(&isp
->csi2_port
[i
]);
874 list_for_each_entry_safe(sd
, next
, &isp
->v4l2_dev
.subdevs
, list
)
875 v4l2_device_unregister_subdev(sd
);
877 v4l2_device_unregister(&isp
->v4l2_dev
);
878 media_device_unregister(&isp
->media_dev
);
881 static int atomisp_register_entities(struct atomisp_device
*isp
)
886 isp
->media_dev
.dev
= isp
->dev
;
888 strlcpy(isp
->media_dev
.model
, "Intel Atom ISP",
889 sizeof(isp
->media_dev
.model
));
891 media_device_init(&isp
->media_dev
);
892 isp
->v4l2_dev
.mdev
= &isp
->media_dev
;
893 ret
= v4l2_device_register(isp
->dev
, &isp
->v4l2_dev
);
895 dev_err(isp
->dev
, "%s: V4L2 device registration failed (%d)\n",
897 goto v4l2_device_failed
;
900 ret
= atomisp_subdev_probe(isp
);
902 goto csi_and_subdev_probe_failed
;
904 /* Register internal entities */
905 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++) {
906 ret
= atomisp_mipi_csi2_register_entities(&isp
->csi2_port
[i
],
912 dev_err(isp
->dev
, "failed to register the CSI port: %d\n", i
);
913 /* deregister all registered CSI ports */
915 atomisp_mipi_csi2_unregister_entities(
918 goto csi_and_subdev_probe_failed
;
922 atomisp_file_input_register_entities(&isp
->file_dev
, &isp
->v4l2_dev
);
924 dev_err(isp
->dev
, "atomisp_file_input_register_entities\n");
925 goto file_input_register_failed
;
928 ret
= atomisp_tpg_register_entities(&isp
->tpg
, &isp
->v4l2_dev
);
930 dev_err(isp
->dev
, "atomisp_tpg_register_entities\n");
931 goto tpg_register_failed
;
934 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
935 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
937 ret
= atomisp_subdev_register_entities(asd
, &isp
->v4l2_dev
);
940 "atomisp_subdev_register_entities fail\n");
942 atomisp_subdev_unregister_entities(
944 goto subdev_register_failed
;
948 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
949 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
951 init_completion(&asd
->init_done
);
953 asd
->delayed_init_workq
=
954 alloc_workqueue(isp
->v4l2_dev
.name
, WQ_CPU_INTENSIVE
,
956 if (asd
->delayed_init_workq
== NULL
) {
958 "Failed to initialize delayed init workq\n");
962 destroy_workqueue(isp
->asd
[i
- 1].
964 goto wq_alloc_failed
;
966 INIT_WORK(&asd
->delayed_init_work
, atomisp_delayed_init_work
);
969 for (i
= 0; i
< isp
->input_cnt
; i
++) {
970 if (isp
->inputs
[i
].port
>= ATOMISP_CAMERA_NR_PORTS
) {
971 dev_err(isp
->dev
, "isp->inputs port %d not supported\n",
972 isp
->inputs
[i
].port
);
979 "FILE_INPUT enable, camera_cnt: %d\n", isp
->input_cnt
);
980 isp
->inputs
[isp
->input_cnt
].type
= FILE_INPUT
;
981 isp
->inputs
[isp
->input_cnt
].port
= -1;
982 isp
->inputs
[isp
->input_cnt
].camera_caps
=
983 atomisp_get_default_camera_caps();
984 isp
->inputs
[isp
->input_cnt
++].camera
= &isp
->file_dev
.sd
;
986 if (isp
->input_cnt
< ATOM_ISP_MAX_INPUTS
) {
988 "TPG detected, camera_cnt: %d\n", isp
->input_cnt
);
989 isp
->inputs
[isp
->input_cnt
].type
= TEST_PATTERN
;
990 isp
->inputs
[isp
->input_cnt
].port
= -1;
991 isp
->inputs
[isp
->input_cnt
].camera_caps
=
992 atomisp_get_default_camera_caps();
993 isp
->inputs
[isp
->input_cnt
++].camera
= &isp
->tpg
.sd
;
995 dev_warn(isp
->dev
, "too many atomisp inputs, TPG ignored.\n");
998 ret
= v4l2_device_register_subdev_nodes(&isp
->v4l2_dev
);
1002 return media_device_register(&isp
->media_dev
);
1005 for (i
= 0; i
< isp
->num_of_streams
; i
++)
1006 destroy_workqueue(isp
->asd
[i
].
1007 delayed_init_workq
);
1009 for (i
= 0; i
< isp
->num_of_streams
; i
++)
1010 atomisp_subdev_unregister_entities(
1012 subdev_register_failed
:
1013 atomisp_tpg_unregister_entities(&isp
->tpg
);
1014 tpg_register_failed
:
1015 atomisp_file_input_unregister_entities(&isp
->file_dev
);
1016 file_input_register_failed
:
1017 for (i
= 0; i
< ATOMISP_CAMERA_NR_PORTS
; i
++)
1018 atomisp_mipi_csi2_unregister_entities(&isp
->csi2_port
[i
]);
1019 csi_and_subdev_probe_failed
:
1020 v4l2_device_unregister(&isp
->v4l2_dev
);
1022 media_device_unregister(&isp
->media_dev
);
1023 media_device_cleanup(&isp
->media_dev
);
1027 static int atomisp_initialize_modules(struct atomisp_device
*isp
)
1031 ret
= atomisp_mipi_csi2_init(isp
);
1033 dev_err(isp
->dev
, "mipi csi2 initialization failed\n");
1034 goto error_mipi_csi2
;
1037 ret
= atomisp_file_input_init(isp
);
1040 "file input device initialization failed\n");
1041 goto error_file_input
;
1044 ret
= atomisp_tpg_init(isp
);
1046 dev_err(isp
->dev
, "tpg initialization failed\n");
1050 ret
= atomisp_subdev_init(isp
);
1052 dev_err(isp
->dev
, "ISP subdev initialization failed\n");
1053 goto error_isp_subdev
;
1061 atomisp_tpg_cleanup(isp
);
1063 atomisp_file_input_cleanup(isp
);
1065 atomisp_mipi_csi2_cleanup(isp
);
1069 static void atomisp_uninitialize_modules(struct atomisp_device
*isp
)
1071 atomisp_tpg_cleanup(isp
);
1072 atomisp_file_input_cleanup(isp
);
1073 atomisp_mipi_csi2_cleanup(isp
);
1076 const struct firmware
*
1077 atomisp_load_firmware(struct atomisp_device
*isp
)
1079 const struct firmware
*fw
;
1081 char *fw_path
= NULL
;
1086 if (isp
->media_dev
.driver_version
== ATOMISP_CSS_VERSION_21
) {
1087 if (isp
->media_dev
.hw_revision
==
1088 ((ATOMISP_HW_REVISION_ISP2401
<< ATOMISP_HW_REVISION_SHIFT
)
1089 | ATOMISP_HW_STEPPING_A0
))
1090 fw_path
= "shisp_2401a0_v21.bin";
1092 if (isp
->media_dev
.hw_revision
==
1093 ((ATOMISP_HW_REVISION_ISP2401_LEGACY
<< ATOMISP_HW_REVISION_SHIFT
)
1094 | ATOMISP_HW_STEPPING_A0
))
1095 fw_path
= "shisp_2401a0_legacy_v21.bin";
1097 if (isp
->media_dev
.hw_revision
==
1098 ((ATOMISP_HW_REVISION_ISP2400
<< ATOMISP_HW_REVISION_SHIFT
)
1099 | ATOMISP_HW_STEPPING_B0
))
1100 fw_path
= "shisp_2400b0_v21.bin";
1105 "Unsupported driver_version 0x%x, hw_revision 0x%x\n",
1106 isp
->media_dev
.driver_version
,
1107 isp
->media_dev
.hw_revision
);
1111 rc
= request_firmware(&fw
, fw_path
, isp
->dev
);
1114 "atomisp: Error %d while requesting firmware %s\n",
1123 * Check for flags the driver was compiled with against the PCI
1124 * device. Always returns true on other than ISP 2400.
1126 static bool is_valid_device(struct pci_dev
*dev
,
1127 const struct pci_device_id
*id
)
1129 unsigned int a0_max_id
;
1131 switch (id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) {
1132 case ATOMISP_PCI_DEVICE_SOC_MRFLD
:
1133 a0_max_id
= ATOMISP_PCI_REV_MRFLD_A0_MAX
;
1135 case ATOMISP_PCI_DEVICE_SOC_BYT
:
1136 a0_max_id
= ATOMISP_PCI_REV_BYT_A0_MAX
;
1142 return dev
->revision
> a0_max_id
;
1145 static int init_atomisp_wdts(struct atomisp_device
*isp
)
1149 atomic_set(&isp
->wdt_work_queued
, 0);
1150 isp
->wdt_work_queue
= alloc_workqueue(isp
->v4l2_dev
.name
, 0, 1);
1151 if (isp
->wdt_work_queue
== NULL
) {
1152 dev_err(isp
->dev
, "Failed to initialize wdt work queue\n");
1156 INIT_WORK(&isp
->wdt_work
, atomisp_wdt_work
);
1158 for (i
= 0; i
< isp
->num_of_streams
; i
++) {
1159 struct atomisp_sub_device
*asd
= &isp
->asd
[i
];
1162 setup_timer(&asd
->wdt
, atomisp_wdt
, (unsigned long)isp
);
1164 setup_timer(&asd
->video_out_capture
.wdt
,
1165 atomisp_wdt
, (unsigned long)&asd
->video_out_capture
);
1166 setup_timer(&asd
->video_out_preview
.wdt
,
1167 atomisp_wdt
, (unsigned long)&asd
->video_out_preview
);
1168 setup_timer(&asd
->video_out_vf
.wdt
,
1169 atomisp_wdt
, (unsigned long)&asd
->video_out_vf
);
1170 setup_timer(&asd
->video_out_video_capture
.wdt
,
1172 (unsigned long)&asd
->video_out_video_capture
);
1180 static struct pci_driver atomisp_pci_driver
;
1182 #define ATOM_ISP_PCI_BAR 0
1184 static int atomisp_pci_probe(struct pci_dev
*dev
,
1185 const struct pci_device_id
*id
)
1187 const struct atomisp_platform_data
*pdata
;
1188 struct atomisp_device
*isp
;
1195 dev_err(&dev
->dev
, "atomisp: error device ptr\n");
1199 if (!is_valid_device(dev
, id
))
1201 /* Pointer to struct device. */
1202 atomisp_dev
= &dev
->dev
;
1204 pdata
= atomisp_get_platform_data();
1206 dev_warn(&dev
->dev
, "no platform data available\n");
1208 err
= pcim_enable_device(dev
);
1210 dev_err(&dev
->dev
, "Failed to enable CI ISP device (%d)\n",
1215 start
= pci_resource_start(dev
, ATOM_ISP_PCI_BAR
);
1216 dev_dbg(&dev
->dev
, "start: 0x%x\n", start
);
1218 err
= pcim_iomap_regions(dev
, 1 << ATOM_ISP_PCI_BAR
, pci_name(dev
));
1220 dev_err(&dev
->dev
, "Failed to I/O memory remapping (%d)\n",
1225 base
= pcim_iomap_table(dev
)[ATOM_ISP_PCI_BAR
];
1226 dev_dbg(&dev
->dev
, "base: %p\n", base
);
1228 atomisp_io_base
= base
;
1230 dev_dbg(&dev
->dev
, "atomisp_io_base: %p\n", atomisp_io_base
);
1232 isp
= devm_kzalloc(&dev
->dev
, sizeof(struct atomisp_device
), GFP_KERNEL
);
1234 dev_err(&dev
->dev
, "Failed to alloc CI ISP structure\n");
1238 isp
->dev
= &dev
->dev
;
1239 isp
->sw_contex
.power_state
= ATOM_ISP_POWER_UP
;
1240 isp
->pci_root
= pci_get_bus_and_slot(0, 0);
1241 if (!isp
->pci_root
) {
1242 dev_err(&dev
->dev
, "Unable to find PCI host\n");
1245 isp
->saved_regs
.ispmmadr
= start
;
1247 rt_mutex_init(&isp
->mutex
);
1248 mutex_init(&isp
->streamoff_mutex
);
1249 spin_lock_init(&isp
->lock
);
1251 /* This is not a true PCI device on SoC, so the delay is not needed. */
1252 isp
->pdev
->d3_delay
= 0;
1254 isp
->media_dev
.driver_version
= ATOMISP_CSS_VERSION_21
;
1255 switch (id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) {
1256 case ATOMISP_PCI_DEVICE_SOC_MRFLD
:
1257 isp
->media_dev
.hw_revision
=
1258 (ATOMISP_HW_REVISION_ISP2400
1259 << ATOMISP_HW_REVISION_SHIFT
) |
1260 ATOMISP_HW_STEPPING_B0
;
1262 switch (id
->device
) {
1263 case ATOMISP_PCI_DEVICE_SOC_MRFLD_1179
:
1264 isp
->dfs
= &dfs_config_merr_1179
;
1266 case ATOMISP_PCI_DEVICE_SOC_MRFLD_117A
:
1267 isp
->dfs
= &dfs_config_merr_117a
;
1270 isp
->dfs
= &dfs_config_merr
;
1273 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1275 case ATOMISP_PCI_DEVICE_SOC_BYT
:
1276 isp
->media_dev
.hw_revision
=
1277 (ATOMISP_HW_REVISION_ISP2400
1278 << ATOMISP_HW_REVISION_SHIFT
) |
1279 ATOMISP_HW_STEPPING_B0
;
1281 if (INTEL_MID_BOARD(3, TABLET
, BYT
, BLK
, PRO
, CRV2
) ||
1282 INTEL_MID_BOARD(3, TABLET
, BYT
, BLK
, ENG
, CRV2
)) {
1283 isp
->dfs
= &dfs_config_byt_cr
;
1284 isp
->hpll_freq
= HPLL_FREQ_2000MHZ
;
1288 isp
->dfs
= &dfs_config_byt
;
1289 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1291 /* HPLL frequency is known to be device-specific, but we don't
1292 * have specs yet for exactly how it varies. Default to
1293 * BYT-CR but let provisioning set it via EFI variable */
1294 isp
->hpll_freq
= gmin_get_var_int(&dev
->dev
, "HpllFreq",
1298 * for BYT/CHT we are put isp into D3cold to avoid pci registers access
1299 * in power off. Set d3cold_delay to 0 since default 100ms is not
1302 isp
->pdev
->d3cold_delay
= 0;
1304 case ATOMISP_PCI_DEVICE_SOC_ANN
:
1305 isp
->media_dev
.hw_revision
= (
1306 #ifdef ISP2401_NEW_INPUT_SYSTEM
1307 ATOMISP_HW_REVISION_ISP2401
1309 ATOMISP_HW_REVISION_ISP2401_LEGACY
1311 << ATOMISP_HW_REVISION_SHIFT
);
1312 isp
->media_dev
.hw_revision
|= isp
->pdev
->revision
< 2 ?
1313 ATOMISP_HW_STEPPING_A0
: ATOMISP_HW_STEPPING_B0
;
1314 isp
->dfs
= &dfs_config_merr
;
1315 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1317 case ATOMISP_PCI_DEVICE_SOC_CHT
:
1318 isp
->media_dev
.hw_revision
= (
1319 #ifdef ISP2401_NEW_INPUT_SYSTEM
1320 ATOMISP_HW_REVISION_ISP2401
1322 ATOMISP_HW_REVISION_ISP2401_LEGACY
1324 << ATOMISP_HW_REVISION_SHIFT
);
1325 isp
->media_dev
.hw_revision
|= isp
->pdev
->revision
< 2 ?
1326 ATOMISP_HW_STEPPING_A0
: ATOMISP_HW_STEPPING_B0
;
1328 isp
->dfs
= &dfs_config_cht
;
1329 isp
->pdev
->d3cold_delay
= 0;
1331 val
= intel_mid_msgbus_read32(CCK_PORT
, CCK_FUSE_REG_0
);
1332 switch (val
& CCK_FUSE_HPLL_FREQ_MASK
) {
1334 isp
->hpll_freq
= HPLL_FREQ_800MHZ
;
1337 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1340 isp
->hpll_freq
= HPLL_FREQ_2000MHZ
;
1343 isp
->hpll_freq
= HPLL_FREQ_1600MHZ
;
1345 "read HPLL from cck failed.default 1600MHz.\n");
1349 dev_err(&dev
->dev
, "un-supported IUNIT device\n");
1353 dev_info(&dev
->dev
, "ISP HPLL frequency base = %d MHz\n",
1356 isp
->max_isr_latency
= ATOMISP_MAX_ISR_LATENCY
;
1358 /* Load isp firmware from user space */
1359 if (!defer_fw_load
) {
1360 isp
->firmware
= atomisp_load_firmware(isp
);
1361 if (!isp
->firmware
) {
1366 err
= atomisp_css_check_firmware_version(isp
);
1368 dev_dbg(&dev
->dev
, "Firmware version check failed\n");
1369 goto fw_validation_fail
;
1373 pci_set_master(dev
);
1374 pci_set_drvdata(dev
, isp
);
1376 err
= pci_enable_msi(dev
);
1378 dev_err(&dev
->dev
, "Failed to enable msi (%d)\n", err
);
1379 goto enable_msi_fail
;
1382 atomisp_msi_irq_init(isp
, dev
);
1384 pm_qos_add_request(&isp
->pm_qos
, PM_QOS_CPU_DMA_LATENCY
,
1385 PM_QOS_DEFAULT_VALUE
);
1388 * for MRFLD, Software/firmware needs to write a 1 to bit 0 of
1389 * the register at CSI_RECEIVER_SELECTION_REG to enable SH CSI
1390 * backend write 0 will enable Arasan CSI backend, which has
1391 * bugs(like sighting:4567697 and 4567699) and will be removed
1394 atomisp_store_uint32(MRFLD_CSI_RECEIVER_SELECTION_REG
, 1);
1396 if ((id
->device
& ATOMISP_PCI_DEVICE_SOC_MASK
) ==
1397 ATOMISP_PCI_DEVICE_SOC_MRFLD
) {
1401 * Workaround for imbalance data eye issue which is observed
1404 pci_read_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
1406 csi_afe_trim
&= ~((MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1407 MRFLD_PCI_CSI1_HSRXCLKTRIM_SHIFT
) |
1408 (MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1409 MRFLD_PCI_CSI2_HSRXCLKTRIM_SHIFT
) |
1410 (MRFLD_PCI_CSI_HSRXCLKTRIM_MASK
<<
1411 MRFLD_PCI_CSI3_HSRXCLKTRIM_SHIFT
));
1412 csi_afe_trim
|= (MRFLD_PCI_CSI1_HSRXCLKTRIM
<<
1413 MRFLD_PCI_CSI1_HSRXCLKTRIM_SHIFT
) |
1414 (MRFLD_PCI_CSI2_HSRXCLKTRIM
<<
1415 MRFLD_PCI_CSI2_HSRXCLKTRIM_SHIFT
) |
1416 (MRFLD_PCI_CSI3_HSRXCLKTRIM
<<
1417 MRFLD_PCI_CSI3_HSRXCLKTRIM_SHIFT
);
1418 pci_write_config_dword(dev
, MRFLD_PCI_CSI_AFE_TRIM_CONTROL
,
1422 err
= atomisp_initialize_modules(isp
);
1424 dev_err(&dev
->dev
, "atomisp_initialize_modules (%d)\n", err
);
1425 goto initialize_modules_fail
;
1428 err
= atomisp_register_entities(isp
);
1430 dev_err(&dev
->dev
, "atomisp_register_entities failed (%d)\n",
1432 goto register_entities_fail
;
1434 err
= atomisp_create_pads_links(isp
);
1436 goto register_entities_fail
;
1437 /* init atomisp wdts */
1438 if (init_atomisp_wdts(isp
) != 0)
1439 goto wdt_work_queue_fail
;
1441 /* save the iunit context only once after all the values are init'ed. */
1442 atomisp_save_iunit_reg(isp
);
1444 pm_runtime_put_noidle(&dev
->dev
);
1445 pm_runtime_allow(&dev
->dev
);
1447 hmm_init_mem_stat(repool_pgnr
, dypool_enable
, dypool_pgnr
);
1448 err
= hmm_pool_register(repool_pgnr
, HMM_POOL_TYPE_RESERVED
);
1450 dev_err(&dev
->dev
, "Failed to register reserved memory pool.\n");
1454 /* Init ISP memory management */
1457 err
= devm_request_threaded_irq(&dev
->dev
, dev
->irq
,
1458 atomisp_isr
, atomisp_isr_thread
,
1459 IRQF_SHARED
, "isp_irq", isp
);
1461 dev_err(&dev
->dev
, "Failed to request irq (%d)\n", err
);
1462 goto request_irq_fail
;
1465 /* Load firmware into ISP memory */
1466 if (!defer_fw_load
) {
1467 err
= atomisp_css_load_firmware(isp
);
1469 dev_err(&dev
->dev
, "Failed to init css.\n");
1473 dev_dbg(&dev
->dev
, "Skip css init.\n");
1475 /* Clear FW image from memory */
1476 release_firmware(isp
->firmware
);
1477 isp
->firmware
= NULL
;
1478 isp
->css_env
.isp_css_fw
.data
= NULL
;
1480 atomisp_drvfs_init(&atomisp_pci_driver
, isp
);
1485 devm_free_irq(&dev
->dev
, dev
->irq
, isp
);
1488 hmm_pool_unregister(HMM_POOL_TYPE_RESERVED
);
1490 destroy_workqueue(isp
->wdt_work_queue
);
1491 wdt_work_queue_fail
:
1492 atomisp_acc_cleanup(isp
);
1493 atomisp_unregister_entities(isp
);
1494 register_entities_fail
:
1495 atomisp_uninitialize_modules(isp
);
1496 initialize_modules_fail
:
1497 pm_qos_remove_request(&isp
->pm_qos
);
1498 atomisp_msi_irq_uninit(isp
, dev
);
1501 release_firmware(isp
->firmware
);
1504 * Switch off ISP, as keeping it powered on would prevent
1505 * reaching S0ix states.
1507 * The following lines have been copied from atomisp suspend path
1510 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
1511 irq
= irq
& 1 << INTR_IIR
;
1512 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
1514 pci_read_config_dword(dev
, PCI_INTERRUPT_CTRL
, &irq
);
1515 irq
&= ~(1 << INTR_IER
);
1516 pci_write_config_dword(dev
, PCI_INTERRUPT_CTRL
, irq
);
1518 atomisp_msi_irq_uninit(isp
, dev
);
1520 atomisp_ospm_dphy_down(isp
);
1522 /* Address later when we worry about the ...field chips */
1523 if (IS_ENABLED(CONFIG_PM
) && atomisp_mrfld_power_down(isp
))
1524 dev_err(&dev
->dev
, "Failed to switch off ISP\n");
1525 pci_dev_put(isp
->pci_root
);
1529 static void atomisp_pci_remove(struct pci_dev
*dev
)
1531 struct atomisp_device
*isp
= (struct atomisp_device
*)
1532 pci_get_drvdata(dev
);
1534 atomisp_drvfs_exit();
1536 atomisp_acc_cleanup(isp
);
1538 atomisp_css_unload_firmware(isp
);
1541 pm_runtime_forbid(&dev
->dev
);
1542 pm_runtime_get_noresume(&dev
->dev
);
1543 pm_qos_remove_request(&isp
->pm_qos
);
1545 atomisp_msi_irq_uninit(isp
, dev
);
1546 pci_dev_put(isp
->pci_root
);
1548 atomisp_unregister_entities(isp
);
1550 destroy_workqueue(isp
->wdt_work_queue
);
1551 atomisp_file_input_cleanup(isp
);
1553 release_firmware(isp
->firmware
);
1555 hmm_pool_unregister(HMM_POOL_TYPE_RESERVED
);
1558 static const struct pci_device_id atomisp_pci_tbl
[] = {
1559 #if defined(ISP2400) || defined(ISP2400B0)
1561 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1178)},
1562 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1179)},
1563 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x117a)},
1565 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0f38)},
1566 #elif defined(ISP2401)
1567 /* Anniedale (Merrifield+ / Moorefield) */
1568 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1478)},
1570 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x22b8)},
1575 MODULE_DEVICE_TABLE(pci
, atomisp_pci_tbl
);
1577 static const struct dev_pm_ops atomisp_pm_ops
= {
1578 .runtime_suspend
= atomisp_runtime_suspend
,
1579 .runtime_resume
= atomisp_runtime_resume
,
1580 .suspend
= atomisp_suspend
,
1581 .resume
= atomisp_resume
,
1584 static struct pci_driver atomisp_pci_driver
= {
1586 .pm
= &atomisp_pm_ops
,
1588 .name
= "atomisp-isp2",
1589 .id_table
= atomisp_pci_tbl
,
1590 .probe
= atomisp_pci_probe
,
1591 .remove
= atomisp_pci_remove
,
1594 static int __init
atomisp_init(void)
1596 return pci_register_driver(&atomisp_pci_driver
);
1599 static void __exit
atomisp_exit(void)
1601 pci_unregister_driver(&atomisp_pci_driver
);
1604 module_init(atomisp_init
);
1605 module_exit(atomisp_exit
);
1607 MODULE_AUTHOR("Wen Wang <wen.w.wang@intel.com>");
1608 MODULE_AUTHOR("Xiaolin Zhang <xiaolin.zhang@intel.com>");
1609 MODULE_LICENSE("GPL");
1610 MODULE_DESCRIPTION("Intel ATOM Platform ISP Driver");