From 84b880f29cc5d1d59ea727101eece65ef8279d69 Mon Sep 17 00:00:00 2001 From: Patrik Jakobsson Date: Sat, 28 Nov 2015 12:12:31 +0100 Subject: [PATCH 1/5] facetimehd: Don't do a full memory verification It can probably be skipped all together but let's settle for a short one for now. --- fthd_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fthd_hw.c b/fthd_hw.c index aae2f15..7cca533 100644 --- a/fthd_hw.c +++ b/fthd_hw.c @@ -697,7 +697,7 @@ int fthd_hw_init(struct fthd_private *dev_priv) } */ - ret = fthd_ddr_verify_mem(dev_priv, 0, MEM_VERIFY_NUM_FULL); + ret = fthd_ddr_verify_mem(dev_priv, 0, MEM_VERIFY_NUM); if (ret) { dev_err(&dev_priv->pdev->dev, "Full memory verification failed! (%d)\n", ret); From 29e8243acf15ec3c91cb6fed871f41faf31fdbe4 Mon Sep 17 00:00:00 2001 From: Patrik Jakobsson Date: Sat, 28 Nov 2015 12:45:19 +0100 Subject: [PATCH 2/5] facetimehd: Use module_pci_driver() helper macro --- fthd_drv.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/fthd_drv.c b/fthd_drv.c index 09e343f..f180545 100644 --- a/fthd_drv.c +++ b/fthd_drv.c @@ -517,25 +517,7 @@ static struct pci_driver fthd_pci_driver = { #endif }; -static int __init fthd_init(void) -{ - int ret = 0; - - ret = pci_register_driver(&fthd_pci_driver); - - if (ret) - pr_err("Couldn't find any devices (ret=%d)\n", ret); - - return ret; -} - -static void __exit fthd_exit(void) -{ - pci_unregister_driver(&fthd_pci_driver); -} - -module_init(fthd_init); -module_exit(fthd_exit); +module_pci_driver(fthd_pci_driver); MODULE_AUTHOR("Patrik Jakobsson "); MODULE_DESCRIPTION("Broadcom PCIe 1570 webcam driver"); From ed773c8268b2720d6d4c5be2a6fd56fa6c3471fa Mon Sep 17 00:00:00 2001 From: Patrik Jakobsson Date: Sat, 28 Nov 2015 13:07:08 +0100 Subject: [PATCH 3/5] facetimehd: More Broadcom to FacetimeHD renaming --- fthd_buffer.c | 2 +- fthd_ddr.c | 2 +- fthd_drv.c | 6 +++--- fthd_hw.c | 2 +- fthd_isp.c | 2 +- fthd_ringbuf.c | 2 +- fthd_v4l2.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fthd_buffer.c b/fthd_buffer.c index 4f71020..e0aec19 100644 --- a/fthd_buffer.c +++ b/fthd_buffer.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2015 Sven Schnelle * diff --git a/fthd_ddr.c b/fthd_ddr.c index 7676dc2..80fc0ce 100644 --- a/fthd_ddr.c +++ b/fthd_ddr.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2014 Patrik Jakobsson (patrik.r.jakobsson@gmail.com) * diff --git a/fthd_drv.c b/fthd_drv.c index f180545..63993e3 100644 --- a/fthd_drv.c +++ b/fthd_drv.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2014 Patrik Jakobsson (patrik.r.jakobsson@gmail.com) * @@ -425,7 +425,7 @@ static int fthd_pci_probe(struct pci_dev *pdev, struct fthd_private *dev_priv; int ret; - dev_info(&pdev->dev, "Found Broadcom PCIe webcam with device id: %x\n", + dev_info(&pdev->dev, "Found FaceTime HD camera with device id: %x\n", pdev->device); dev_priv = kzalloc(sizeof(struct fthd_private), GFP_KERNEL); @@ -520,5 +520,5 @@ static struct pci_driver fthd_pci_driver = { module_pci_driver(fthd_pci_driver); MODULE_AUTHOR("Patrik Jakobsson "); -MODULE_DESCRIPTION("Broadcom PCIe 1570 webcam driver"); +MODULE_DESCRIPTION("FacetimeHD camera driver"); MODULE_LICENSE("GPL"); diff --git a/fthd_hw.c b/fthd_hw.c index 7cca533..15eaf66 100644 --- a/fthd_hw.c +++ b/fthd_hw.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2014 Patrik Jakobsson (patrik.r.jakobsson@gmail.com) * diff --git a/fthd_isp.c b/fthd_isp.c index debced8..7a5c414 100644 --- a/fthd_isp.c +++ b/fthd_isp.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2014 Patrik Jakobsson (patrik.r.jakobsson@gmail.com) * diff --git a/fthd_ringbuf.c b/fthd_ringbuf.c index 5617041..d1ae28f 100644 --- a/fthd_ringbuf.c +++ b/fthd_ringbuf.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2015 Sven Schnelle * diff --git a/fthd_v4l2.c b/fthd_v4l2.c index 6807f55..436fb36 100644 --- a/fthd_v4l2.c +++ b/fthd_v4l2.c @@ -1,5 +1,5 @@ /* - * Broadcom PCIe 1570 webcam driver + * FacetimeHD camera driver * * Copyright (C) 2015 Sven Schnelle * From 4ffc88f155f73d58eb9074d486de28970c79355a Mon Sep 17 00:00:00 2001 From: Patrik Jakobsson Date: Sat, 28 Nov 2015 13:33:47 +0100 Subject: [PATCH 4/5] facetimehd: Use the max macro from linux/kernel.h --- fthd_drv.h | 2 -- fthd_isp.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fthd_drv.h b/fthd_drv.h index c6eae90..3e4f768 100644 --- a/fthd_drv.h +++ b/fthd_drv.h @@ -35,8 +35,6 @@ #define FTHD_PCI_S2_MEM 2 #define FTHD_PCI_ISP_IO 4 -#define MAX(a, b) ((a)>(b)?(a):(b)) - #define FTHD_BUFFERS 4 struct fthd_reg { diff --git a/fthd_isp.c b/fthd_isp.c index 7a5c414..4f98790 100644 --- a/fthd_isp.c +++ b/fthd_isp.c @@ -17,6 +17,7 @@ * */ +#include #include #include #include @@ -276,7 +277,7 @@ static int fthd_isp_cmd(struct fthd_private *dev_priv, enum fthd_isp_cmds comman memset(&cmd, 0, sizeof(cmd)); if (response_len) { - len = MAX(request_len, *response_len); + len = max(request_len, *response_len); } else { len = request_len; } From 311137ba01b9df468710de5314a6d189f1ed88f3 Mon Sep 17 00:00:00 2001 From: Patrik Jakobsson Date: Sat, 28 Nov 2015 20:53:42 +0100 Subject: [PATCH 5/5] facetimehd: Prep the DDR PHY save/restore functions --- fthd_drv.h | 9 +-------- fthd_hw.c | 55 +++++++++++++++++++----------------------------------- fthd_hw.h | 2 ++ fthd_reg.h | 28 +++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/fthd_drv.h b/fthd_drv.h index 3e4f768..3bc8082 100644 --- a/fthd_drv.h +++ b/fthd_drv.h @@ -37,11 +37,6 @@ #define FTHD_BUFFERS 4 -struct fthd_reg { - u32 offset; - u32 value; -}; - enum FW_CHAN_TYPE { FW_CHAN_TYPE_OUT=0, FW_CHAN_TYPE_IN=1, @@ -93,9 +88,7 @@ struct fthd_private { u32 ddr_speed; u32 vdl_step_size; - /* DDR_PHY saved registers. Offsets need to be initialized somewhere */ - u32 ddr_phy_num_regs; - struct fthd_reg ddr_phy_reg_map[DDR_PHY_NUM_REGS]; + u32 ddr_phy_regs[DDR_PHY_NUM_REG]; /* Root resource for memory management */ struct resource *mem; diff --git a/fthd_hw.c b/fthd_hw.c index 15eaf66..98ac3ed 100644 --- a/fthd_hw.c +++ b/fthd_hw.c @@ -23,26 +23,6 @@ #include "fthd_ddr.h" #include "fthd_isp.h" -/* FIXME: Double check these */ -static u32 ddr_phy_reg_map[] = { - 0x0000, 0x0004, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0030, - 0x0034, 0x0038, 0x003c, 0x0040, 0x0044, 0x0048, 0x004c, 0x0050, - 0x0054, 0x0058, 0x005c, 0x0060, 0x0064, 0x0068, 0x006c, 0x0070, - 0x0074, 0x0078, 0x007c, 0x0080, 0x0084, 0x0090, 0x0094, 0x0098, - 0x009c, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x00b8, 0x00bc, 0x00c0, - 0x0200, 0x0204, 0x0208, 0x020c, 0x0210, 0x0214, 0x0218, 0x021c, - 0x0220, 0x0224, 0x0228, 0x022c, 0x0230, 0x0234, 0x0238, 0x023c, - 0x0240, 0x0244, 0x0248, 0x024c, 0x0250, 0x0254, 0x0258, 0x025c, - 0x0260, 0x0264, 0x0268, 0x026c, 0x0270, 0x0274, 0x02a4, 0x02a8, - 0x02ac, 0x02b0, 0x02b4, 0x02b8, 0x02bc, 0x02c0, 0x02c4, 0x02c8, - 0x02cc, 0x02d0, 0x02d4, 0x02d8, 0x02dc, 0x02e0, 0x02e4, 0x02e8, - 0x02ec, 0x02f0, 0x02f4, 0x02f8, 0x02fc, 0x0300, 0x0304, 0x0308, - 0x030c, 0x0310, 0x0314, 0x0328, 0x032c, 0x0330, 0x0334, 0x0338, - 0x033c, 0x0348, 0x034c, 0x0350, 0x0354, 0x0358, 0x035c, 0x0360, - 0x0364, 0x0370, 0x0374, 0x0378, 0x037c, 0x0380, 0x0384, 0x0388, - 0x038c, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03a8, 0x03ac, -}; - static int fthd_hw_s2_pll_reset(struct fthd_private *dev_priv) { FTHD_S2_REG_WRITE(0x40, S2_PLL_CTRL_2C); @@ -636,21 +616,28 @@ static int fthd_hw_s2_init_ddr_controller_soc(struct fthd_private *dev_priv) return 0; } -static int fthd_hw_ddr_phy_save_regs(struct fthd_private *dev_priv) +void fthd_ddr_phy_save_regs(struct fthd_private *dev_priv) { - u32 reg, offset; + u32 offset; int i; - if (dev_priv->ddr_phy_num_regs == 0) - return -ENOENT; - - for (i = 0; i < dev_priv->ddr_phy_num_regs; i++) { - offset = dev_priv->ddr_phy_reg_map[i].offset; - reg = FTHD_ISP_REG_READ(offset + DDR_PHY_REG_BASE); - dev_priv->ddr_phy_reg_map[i].value = reg; + for (i = 0; i < DDR_PHY_NUM_REG; i++) { + offset = fthd_ddr_phy_reg_map[i]; + dev_priv->ddr_phy_regs[i] = + FTHD_ISP_REG_READ(DDR_PHY_REG_BASE + offset); } +} - return 0; +void fthd_ddr_phy_restore_regs(struct fthd_private *dev_priv) +{ + u32 offset; + int i; + + for (i = 0; i < DDR_PHY_NUM_REG; i++) { + offset = fthd_ddr_phy_reg_map[i]; + FTHD_S2_REG_WRITE(dev_priv->ddr_phy_regs[i], + DDR_PHY_REG_BASE + offset); + } } static int fthd_hw_irq_enable(struct fthd_private *dev_priv) @@ -670,7 +657,7 @@ static int fthd_hw_irq_disable(struct fthd_private *dev_priv) int fthd_hw_init(struct fthd_private *dev_priv) { - int ret, i; + int ret; ret = fthd_hw_s2_init_pcie_link(dev_priv); if (ret) @@ -679,10 +666,6 @@ int fthd_hw_init(struct fthd_private *dev_priv) fthd_hw_s2_preinit_ddr_controller_soc(dev_priv); fthd_hw_s2_init_ddr_controller_soc(dev_priv); - /* Initialize the reg map */ - for (i = 0; i < DDR_PHY_NUM_REGS; i++) - dev_priv->ddr_phy_reg_map[i].offset = ddr_phy_reg_map[i]; - /* dev_info(&dev_priv->pdev->dev, "Dumping DDR PHY reg map before shmoo\n"); @@ -713,7 +696,7 @@ int fthd_hw_init(struct fthd_private *dev_priv) } /* Save our working configuration */ - fthd_hw_ddr_phy_save_regs(dev_priv); + fthd_ddr_phy_save_regs(dev_priv); FTHD_S2_REG_WRITE(0x8, S2_D108); FTHD_S2_REG_WRITE(0xc, S2_D104); diff --git a/fthd_hw.h b/fthd_hw.h index 7982c7b..3a9f595 100644 --- a/fthd_hw.h +++ b/fthd_hw.h @@ -131,4 +131,6 @@ static inline void _FTHD_ISP_REG_WRITE(struct fthd_private *dev_priv, u32 val, extern int fthd_hw_init(struct fthd_private *dev_priv); extern void fthd_hw_deinit(struct fthd_private *priv); +extern void fthd_ddr_phy_save_regs(struct fthd_private *dev_priv); +extern void fthd_ddr_phy_restore_regs(struct fthd_private *dev_priv); #endif diff --git a/fthd_reg.h b/fthd_reg.h index e169a59..b81b85e 100644 --- a/fthd_reg.h +++ b/fthd_reg.h @@ -20,6 +20,8 @@ #ifndef _FTHD_REG_H #define _FTHD_REG_H +#include + /* PCIE link regs */ #define S2_PCIE_LINK_D000 0xd000 #define S2_PCIE_LINK_D120 0xd120 @@ -86,11 +88,33 @@ #define S2_DDR_PLL_STATUS_2444 0x2444 #define S2_DDR_PLL_STATUS_2444_LOCKED (1 << 13) +/* + * These registers must be saved and restored across suspend/resume + * FIXME: Double check these + */ +static const u32 fthd_ddr_phy_reg_map[] = { + 0x0000, 0x0004, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0030, + 0x0034, 0x0038, 0x003c, 0x0040, 0x0044, 0x0048, 0x004c, 0x0050, + 0x0054, 0x0058, 0x005c, 0x0060, 0x0064, 0x0068, 0x006c, 0x0070, + 0x0074, 0x0078, 0x007c, 0x0080, 0x0084, 0x0090, 0x0094, 0x0098, + 0x009c, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x00b8, 0x00bc, 0x00c0, + 0x0200, 0x0204, 0x0208, 0x020c, 0x0210, 0x0214, 0x0218, 0x021c, + 0x0220, 0x0224, 0x0228, 0x022c, 0x0230, 0x0234, 0x0238, 0x023c, + 0x0240, 0x0244, 0x0248, 0x024c, 0x0250, 0x0254, 0x0258, 0x025c, + 0x0260, 0x0264, 0x0268, 0x026c, 0x0270, 0x0274, 0x02a4, 0x02a8, + 0x02ac, 0x02b0, 0x02b4, 0x02b8, 0x02bc, 0x02c0, 0x02c4, 0x02c8, + 0x02cc, 0x02d0, 0x02d4, 0x02d8, 0x02dc, 0x02e0, 0x02e4, 0x02e8, + 0x02ec, 0x02f0, 0x02f4, 0x02f8, 0x02fc, 0x0300, 0x0304, 0x0308, + 0x030c, 0x0310, 0x0314, 0x0328, 0x032c, 0x0330, 0x0334, 0x0338, + 0x033c, 0x0348, 0x034c, 0x0350, 0x0354, 0x0358, 0x035c, 0x0360, + 0x0364, 0x0370, 0x0374, 0x0378, 0x037c, 0x0380, 0x0384, 0x0388, + 0x038c, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03a8, 0x03ac, +}; + +#define DDR_PHY_NUM_REG ARRAY_SIZE(fthd_ddr_phy_reg_map) #define DDR_PHY_REG_BASE 0x2800 -#define DDR_PHY_NUM_REGS 127 /* Found in AppleCamIn::Start() */ /* DDR40 */ -#define S2_DDR40_PHY_BASE 0x2800 #define S2_DDR40_PHY_PLL_STATUS 0x2810 #define S2_DDR40_PHY_PLL_STATUS_LOCKED (1 << 0) #define S2_DDR40_PHY_PLL_CFG 0x2814