usb: add usb power control [1/1]
authorYue Wang <yue.wang@amlogic.com>
Fri, 29 Mar 2019 09:32:18 +0000 (17:32 +0800)
committerJianxiong Pan <jianxiong.pan@amlogic.com>
Fri, 29 Mar 2019 12:33:32 +0000 (20:33 +0800)
PD#SWPL-6186

Problem:
add usb power control

Solution:
add usb power control

Verify:
sm1

Test: pass
Change-Id: I6c2822105ae02f955e56dc4d64163e8e14a7e329
Signed-off-by: Yue Wang <yue.wang@amlogic.com>
arch/arm/boot/dts/amlogic/mesonsm1.dtsi
arch/arm64/boot/dts/amlogic/mesonsm1.dtsi
drivers/amlogic/pci/pcie-amlogic-v2.c
drivers/amlogic/pci/pcie-amlogic.h
drivers/amlogic/usb/phy/phy-aml-new-usb2-v2.c
drivers/amlogic/usb/phy/phy-aml-new-usb3-v2.c
include/linux/amlogic/usb-v2.h

index 44e8741..b85bc43 100644 (file)
                reg = <0xffe09000 0x80
                                0xffd01008 0x100
                                0xff636000 0x2000
-                               0xff63a000 0x2000
-                               0xff8000e8 0x10
-                               0xff63c100 0x4>;
+                               0xff63a000 0x2000>;
                pll-setting-1 = <0x09400414>;
                pll-setting-2 = <0x927E0000>;
                pll-setting-3 = <0xac5f69e5>;
                pll-setting-8 = <0xe000c>;
                version = <2>;
                pwr-ctl = <1>;
+               u2-ctrl-sleep-shift = <17>;
+               u2-hhi-mem-pd-shift = <30>;
+               u2-hhi-mem-pd-mask = <0x3>;
+               u2-ctrl-iso-shift = <17>;
        };
 
        usb3_phy_v2: usb3phy@ffe09080 {
                compatible = "amlogic, amlogic-new-usb3-v2";
                status = "disable";
                reg = <0xffe09080 0x20
-                       0xff8000e8 0x10
-                       0xff63c100 0x4
                        0xffd01008 0x100>;
                phy-reg = <0xff646000>;
                phy-reg-size = <0x2000>;
                clocks = <&clkc CLKID_PCIE_PLL>;
                clock-names = "pcie_refpll";
                pwr-ctl = <1>;
+               u3-ctrl-sleep-shift = <18>;
+               u3-hhi-mem-pd-shift = <26>;
+               u3-hhi-mem-pd-mask = <0xf>;
+               u3-ctrl-iso-shift = <18>;
        };
 
        dwc2_a: dwc2_a@ff400000 {
                        0xff648000 0x2000
                        0xfc400000 0x200000
                        0xff646000 0x2000
-                       0xffd01080 0x10
-                       0xff8000e8 0x8
-                       0xff63c100 0x4>;
+                       0xffd01080 0x10>;
                reg-names = "elbi", "cfg", "config", "phy",
-                               "reset", "pwr", "hii";
+                               "reset";
                interrupts = <0 221 0>;
                #interrupt-cells = <1>;
                bus-range = <0x0 0xff>;
                pcie-phy-rst-bit = <14>;
                pcie-ctrl-a-rst-bit = <12>;
                pwr-ctl = <1>;
+               pcie-ctrl-sleep-shift = <18>;
+               pcie-hhi-mem-pd-shift = <26>;
+               pcie-hhi-mem-pd-mask = <0xf>;
+               pcie-ctrl-iso-shift = <18>;
                status = "disabled";
        };
 
index faddaa9..f79caef 100644 (file)
                reg = <0x0 0xffe09000 0x0 0x80
                                0x0 0xffd01008 0x0 0x100
                                0x0 0xff636000 0x0 0x2000
-                               0x0 0xff63a000 0x0 0x2000
-                               0x0 0xff8000e8 0x0 0x10
-                               0x0 0xff63c100 0x0 0x4>;
+                               0x0 0xff63a000 0x0 0x2000>;
                pll-setting-1 = <0x09400414>;
                pll-setting-2 = <0x927E0000>;
                pll-setting-3 = <0xac5f69e5>;
                pll-setting-8 = <0xe000c>;
                version = <2>;
                pwr-ctl = <1>;
+               u2-ctrl-sleep-shift = <17>;
+               u2-hhi-mem-pd-shift = <30>;
+               u2-hhi-mem-pd-mask = <0x3>;
+               u2-ctrl-iso-shift = <17>;
        };
 
        usb3_phy_v2: usb3phy@ffe09080 {
                compatible = "amlogic, amlogic-new-usb3-v2";
                status = "disable";
                reg = <0x0 0xffe09080 0x0 0x20
-                       0x0 0xff8000e8 0x0 0x10
-                       0x0 0xff63c100 0x0 0x4
                        0x0 0xffd01008 0x0 0x100>;
                phy-reg = <0xff646000>;
                phy-reg-size = <0x2000>;
                clocks = <&clkc CLKID_PCIE_PLL>;
                clock-names = "pcie_refpll";
                pwr-ctl = <1>;
+               u3-ctrl-sleep-shift = <18>;
+               u3-hhi-mem-pd-shift = <26>;
+               u3-hhi-mem-pd-mask = <0xf>;
+               u3-ctrl-iso-shift = <18>;
        };
 
        dwc2_a: dwc2_a@ff400000 {
                        0x0 0xff648000 0x0 0x2000
                        0x0 0xfc400000 0x0 0x200000
                        0x0 0xff646000 0x0 0x2000
-                       0x0 0xffd01080 0x0 0x10
-                       0x0 0xff8000e8 0x0 0x8
-                       0x0 0xff63c100 0x0 0x4>;
-               reg-names = "elbi", "cfg", "config", "phy",
-                               "reset", "pwr", "hii";
+                       0x0 0xffd01080 0x0 0x10>;
+               reg-names = "elbi", "cfg", "config", "phy", "reset";
                interrupts = <0 221 0>;
                #interrupt-cells = <1>;
                bus-range = <0x0 0xff>;
                pcie-phy-rst-bit = <14>;
                pcie-ctrl-a-rst-bit = <12>;
                pwr-ctl = <1>;
+               pcie-ctrl-sleep-shift = <18>;
+               pcie-hhi-mem-pd-shift = <26>;
+               pcie-hhi-mem-pd-mask = <0xf>;
+               pcie-ctrl-iso-shift = <18>;
                status = "disabled";
        };
 
index 8b9454f..479e445 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/signal.h>
 #include <linux/types.h>
 #include <linux/module.h>
+#include <linux/amlogic/power_ctrl.h>
 #include "../drivers/pci/host/pcie-designware.h"
 #include "pcie-amlogic.h"
 
@@ -684,10 +685,10 @@ static void power_switch_to_pcie(struct pcie_phy *phy)
 {
        u32 val;
 
-       writel(readl(phy->power_base) & (~(0x1<<18)), phy->power_base);
+       power_ctrl_sleep(1, phy->pcie_ctrl_sleep_shift);
 
-       writel(readl(phy->hhi_mem_pd_base) & (~(0xf<<26)),
-                       phy->hhi_mem_pd_base);
+       power_ctrl_mempd0(1, phy->pcie_hhi_mem_pd_mask,
+                       phy->pcie_hhi_mem_pd_shift);
        udelay(100);
 
        val = readl((void __iomem *)(unsigned long)phy->reset_base);
@@ -695,8 +696,7 @@ static void power_switch_to_pcie(struct pcie_phy *phy)
                (void __iomem *)(unsigned long)phy->reset_base);
        udelay(100);
 
-       writel(readl(phy->power_base+0x4) & (~(0x1<<18)),
-                       phy->power_base + 0x4);
+       power_ctrl_iso(1, phy->pcie_ctrl_iso_shift);
 
        val = readl((void __iomem *)(unsigned long)phy->reset_base);
        writel((val | (0x1<<12)),
@@ -716,8 +716,6 @@ static int __init amlogic_pcie_probe(struct platform_device *pdev)
        struct resource *phy_base;
        struct resource *cfg_base;
        struct resource *reset_base;
-       struct resource *power_base = NULL;
-       struct resource *hhi_mem_pd_base = NULL;
        int ret;
        int pcie_num = 0;
        int num_lanes = 0;
@@ -732,6 +730,7 @@ static int __init amlogic_pcie_probe(struct platform_device *pdev)
        int pcie_phy_rst_bit = 0;
        int pcie_ctrl_a_rst_bit = 0;
        u32 pwr_ctl = 0;
+       const void *prop;
 
        dev_info(&pdev->dev, "amlogic_pcie_probe!\n");
 
@@ -793,26 +792,37 @@ static int __init amlogic_pcie_probe(struct platform_device *pdev)
                amlogic_pcie->pwr_ctl = pwr_ctl;
 
        if (pwr_ctl) {
-               power_base = platform_get_resource_byname(
-                       pdev, IORESOURCE_MEM, "pwr");
-               if (power_base) {
-                       amlogic_pcie->phy->power_base =
-                               ioremap(power_base->start,
-                               resource_size(power_base));
-                       if (IS_ERR(amlogic_pcie->phy->power_base))
-                               return PTR_ERR(amlogic_pcie->phy->power_base);
-               }
-
-               hhi_mem_pd_base = platform_get_resource_byname(
-                       pdev, IORESOURCE_MEM, "hii");
-               if (hhi_mem_pd_base) {
-                       amlogic_pcie->phy->hhi_mem_pd_base =
-                               ioremap(hhi_mem_pd_base->start,
-                               resource_size(hhi_mem_pd_base));
-                       if (IS_ERR(amlogic_pcie->phy->hhi_mem_pd_base))
-                               return PTR_ERR(amlogic_pcie->
-                                               phy->hhi_mem_pd_base);
-               }
+               prop = of_get_property(dev->of_node,
+                       "pcie-ctrl-sleep-shift", NULL);
+               if (prop)
+                       amlogic_pcie->phy->pcie_ctrl_sleep_shift =
+                               of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "pcie-hhi-mem-pd-shift", NULL);
+               if (prop)
+                       amlogic_pcie->phy->pcie_hhi_mem_pd_shift =
+                               of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "pcie-hhi-mem-pd-mask", NULL);
+               if (prop)
+                       amlogic_pcie->phy->pcie_hhi_mem_pd_mask =
+                               of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "pcie-ctrl-iso-shift", NULL);
+               if (prop)
+                       amlogic_pcie->phy->pcie_ctrl_iso_shift =
+                               of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
        }
 
        if (!amlogic_pcie->phy->reset_base) {
index 88a6b87..394a33a 100644 (file)
@@ -162,8 +162,10 @@ struct pcie_phy {
        u32 reset_state;
        void __iomem            *phy_base;      /* DT 1st resource */
        void __iomem            *reset_base;/* DT 3nd resource */
-       void __iomem            *power_base;
-       void __iomem            *hhi_mem_pd_base;
+       u32 pcie_ctrl_sleep_shift;
+       u32 pcie_hhi_mem_pd_mask;
+       u32 pcie_ctrl_iso_shift;
+       u32 pcie_hhi_mem_pd_shift;
 };
 
 
index ad9bec2..6aaf4f9 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/usb/phy.h>
 #include <linux/amlogic/usb-v2.h>
 #include <linux/amlogic/cpu_version.h>
+#include <linux/amlogic/power_ctrl.h>
 #include "phy-aml-new-usb-v2.h"
 
 struct amlogic_usb_v2  *g_phy2_v2;
@@ -227,17 +228,15 @@ static void amlogic_new_usb2phy_shutdown(struct usb_phy *x)
 void power_switch_to_usb(struct amlogic_usb_v2 *phy)
 {
        /* Powerup usb_comb */
-       writel(readl(phy->power_base) & (~(0x1<<17)), phy->power_base);
-       writel(readl(phy->hhi_mem_pd_base) & (~(0x3<<30)),
-               phy->hhi_mem_pd_base);
+       power_ctrl_sleep(1, phy->u2_ctrl_sleep_shift);
+       power_ctrl_mempd0(1, phy->u2_hhi_mem_pd_mask, phy->u2_hhi_mem_pd_shift);
        udelay(100);
 
        writel((readl(phy->reset_regs + (0x21 * 4 - 0x8)) & ~(0x1 << 2)),
                phy->reset_regs + (0x21 * 4 - 0x8));
 
        udelay(100);
-       writel(readl(phy->power_base+0x4) & (~(0x1<<17)),
-               phy->power_base + 0x4);
+       power_ctrl_iso(1, phy->u2_ctrl_iso_shift);
 
        writel((readl(phy->reset_regs + (0x21 * 4 - 0x8)) | (0x1 << 2)),
                phy->reset_regs + (0x21 * 4 - 0x8));
@@ -251,13 +250,9 @@ static int amlogic_new_usb2_probe(struct platform_device *pdev)
        struct resource *phy_mem;
        struct resource *reset_mem;
        struct resource *phy_cfg_mem[4];
-       struct resource *power_mem = NULL;
-       struct resource *hhi_mem_pd_mem = NULL;
        void __iomem    *phy_base;
        void __iomem    *reset_base = NULL;
        void __iomem    *phy_cfg_base[4];
-       void __iomem    *power_base = NULL;
-       void __iomem    *hhi_mem_pd_base = NULL;
        int portnum = 0;
        int phy_version = 0;
        const void *prop;
@@ -265,6 +260,10 @@ static int amlogic_new_usb2_probe(struct platform_device *pdev)
        int retval;
        u32 pll_setting[8];
        u32 pwr_ctl = 0;
+       u32 u2_ctrl_sleep_shift = 0;
+       u32 u2_hhi_mem_pd_shift = 0;
+       u32 u2_hhi_mem_pd_mask = 0;
+       u32 u2_ctrl_iso_shift = 0;
 
        prop = of_get_property(dev->of_node, "portnum", NULL);
        if (prop)
@@ -317,23 +316,33 @@ static int amlogic_new_usb2_probe(struct platform_device *pdev)
                pwr_ctl = 0;
 
        if (pwr_ctl) {
-               power_mem = platform_get_resource
-                       (pdev, IORESOURCE_MEM, 2 + portnum);
-               if (power_mem) {
-                       power_base = ioremap(power_mem->start,
-                               resource_size(power_mem));
-                       if (IS_ERR(power_base))
-                               return PTR_ERR(power_base);
-               }
-
-               hhi_mem_pd_mem = platform_get_resource
-                               (pdev, IORESOURCE_MEM, 3 + portnum);
-               if (hhi_mem_pd_mem) {
-                       hhi_mem_pd_base = ioremap(hhi_mem_pd_mem->start,
-                               resource_size(hhi_mem_pd_mem));
-                       if (IS_ERR(hhi_mem_pd_base))
-                               return PTR_ERR(hhi_mem_pd_base);
-               }
+               prop = of_get_property(dev->of_node,
+                       "u2-ctrl-sleep-shift", NULL);
+               if (prop)
+                       u2_ctrl_sleep_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u2-hhi-mem-pd-shift", NULL);
+               if (prop)
+                       u2_hhi_mem_pd_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u2-hhi-mem-pd-mask", NULL);
+               if (prop)
+                       u2_hhi_mem_pd_mask = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u2-ctrl-iso-shift", NULL);
+               if (prop)
+                       u2_ctrl_iso_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
        }
 
        phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
@@ -411,8 +420,10 @@ static int amlogic_new_usb2_probe(struct platform_device *pdev)
        }
 
        if (pwr_ctl) {
-               phy->power_base = power_base;
-               phy->hhi_mem_pd_base = hhi_mem_pd_base;
+               phy->u2_ctrl_sleep_shift = u2_ctrl_sleep_shift;
+               phy->u2_hhi_mem_pd_shift = u2_hhi_mem_pd_shift;
+               phy->u2_hhi_mem_pd_mask = u2_hhi_mem_pd_mask;
+               phy->u2_ctrl_iso_shift = u2_ctrl_iso_shift;
                power_switch_to_usb(phy);
        }
 
index 0f1839b..3c97500 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/workqueue.h>
 #include <linux/notifier.h>
 #include <linux/amlogic/usbtype.h>
+#include <linux/amlogic/power_ctrl.h>
 #include "phy-aml-new-usb-v2.h"
 
 #define HOST_MODE      0
@@ -486,10 +487,8 @@ static void power_switch_to_pcie(struct amlogic_usb_v2 *phy)
 {
        u32 val;
 
-       writel(readl(phy->power_base) & (~(0x1<<18)), phy->power_base);
-
-       writel(readl(phy->hhi_mem_pd_base) & (~(0xf<<26)),
-               phy->hhi_mem_pd_base);
+       power_ctrl_sleep(1, phy->u3_ctrl_sleep_shift);
+       power_ctrl_mempd0(1, phy->u3_hhi_mem_pd_mask, phy->u3_hhi_mem_pd_shift);
        udelay(100);
 
        val = readl((void __iomem *)
@@ -498,8 +497,8 @@ static void power_switch_to_pcie(struct amlogic_usb_v2 *phy)
                ((unsigned long)phy->reset_regs + (0x20 * 4 - 0x8)));
        udelay(100);
 
-       writel(readl(phy->power_base+0x4) & (~(0x1<<18)),
-               phy->power_base + 0x4);
+       power_ctrl_iso(1, phy->u3_ctrl_iso_shift);
+
        val = readl((void __iomem *)
                ((unsigned long)phy->reset_regs + (0x20 * 4 - 0x8)));
        writel((val | (0x1<<12)), (void __iomem *)
@@ -512,13 +511,9 @@ static int amlogic_new_usb3_v2_probe(struct platform_device *pdev)
        struct amlogic_usb_v2                   *phy;
        struct device *dev = &pdev->dev;
        struct resource *phy_mem;
-       struct resource *power_mem = NULL;
-       struct resource *hhi_mem_pd_mem = NULL;
        struct resource *reset_mem;
        void __iomem *phy_base;
        void __iomem *phy3_base;
-       void __iomem    *power_base = NULL;
-       void __iomem    *hhi_mem_pd_base = NULL;
        void __iomem    *reset_base = NULL;
        unsigned int phy3_mem;
        unsigned int phy3_mem_size = 0;
@@ -536,6 +531,10 @@ static int amlogic_new_usb3_v2_probe(struct platform_device *pdev)
        int ret;
        struct device_node *tsi_pci;
        u32 pwr_ctl = 0;
+       u32 u3_ctrl_sleep_shift = 0;
+       u32 u3_hhi_mem_pd_shift = 0;
+       u32 u3_hhi_mem_pd_mask = 0;
+       u32 u3_ctrl_iso_shift = 0;
 
        gpio_name = of_get_property(dev->of_node, "gpio-vbus-power", NULL);
        if (gpio_name) {
@@ -593,29 +592,41 @@ static int amlogic_new_usb3_v2_probe(struct platform_device *pdev)
                pwr_ctl = 0;
 
        if (pwr_ctl) {
-               power_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-               if (power_mem) {
-                       power_base = ioremap(power_mem->start,
-                               resource_size(power_mem));
-                       if (IS_ERR(power_base))
-                               return PTR_ERR(power_base);
-               }
-
-               hhi_mem_pd_mem = platform_get_resource(pdev, IORESOURCE_MEM, 2);
-               if (hhi_mem_pd_mem) {
-                       hhi_mem_pd_base = ioremap(hhi_mem_pd_mem->start,
-                               resource_size(hhi_mem_pd_mem));
-                       if (IS_ERR(hhi_mem_pd_base))
-                               return PTR_ERR(hhi_mem_pd_base);
-               }
-
-               reset_mem = platform_get_resource(pdev, IORESOURCE_MEM, 3);
+               reset_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
                if (reset_mem) {
                        reset_base = ioremap(reset_mem->start,
                                resource_size(reset_mem));
                        if (IS_ERR(reset_base))
                                return PTR_ERR(reset_base);
                }
+
+               prop = of_get_property(dev->of_node,
+                       "u3-ctrl-sleep-shift", NULL);
+               if (prop)
+                       u3_ctrl_sleep_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u3-hhi-mem-pd-shift", NULL);
+               if (prop)
+                       u3_hhi_mem_pd_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u3-hhi-mem-pd-mask", NULL);
+               if (prop)
+                       u3_hhi_mem_pd_mask = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
+
+               prop = of_get_property(dev->of_node,
+                       "u3-ctrl-iso-shift", NULL);
+               if (prop)
+                       u3_ctrl_iso_shift = of_read_ulong(prop, 1);
+               else
+                       pwr_ctl = 0;
        }
 
        retval = of_property_read_u32
@@ -684,8 +695,10 @@ static int amlogic_new_usb3_v2_probe(struct platform_device *pdev)
        /* set the phy from pcie to usb3 */
        if (phy->portnum > 0) {
                if (phy->pwr_ctl) {
-                       phy->power_base = power_base;
-                       phy->hhi_mem_pd_base = hhi_mem_pd_base;
+                       phy->u3_ctrl_sleep_shift = u3_ctrl_sleep_shift;
+                       phy->u3_hhi_mem_pd_shift = u3_hhi_mem_pd_shift;
+                       phy->u3_hhi_mem_pd_mask = u3_hhi_mem_pd_mask;
+                       phy->u3_ctrl_iso_shift = u3_ctrl_iso_shift;
                        phy->reset_regs = reset_base;
                        power_switch_to_pcie(phy);
                }
index dc3774e..4d5df3a 100644 (file)
@@ -169,8 +169,6 @@ struct amlogic_usb_v2 {
        void __iomem    *phy3_cfg_r4;
        void __iomem    *phy3_cfg_r5;
        void __iomem    *usb2_phy_cfg;
-       void __iomem    *power_base;
-       void __iomem    *hhi_mem_pd_base;
        u32 pll_setting[8];
        int phy_cfg_state[4];
        /* Set VBus Power though GPIO */
@@ -183,6 +181,14 @@ struct amlogic_usb_v2 {
        int suspend_flag;
        int phy_version;
        int pwr_ctl;
+       u32 u2_ctrl_sleep_shift;
+       u32 u2_hhi_mem_pd_mask;
+       u32 u2_ctrl_iso_shift;
+       u32 u2_hhi_mem_pd_shift;
+       u32 u3_ctrl_sleep_shift;
+       u32 u3_hhi_mem_pd_mask;
+       u32 u3_ctrl_iso_shift;
+       u32 u3_hhi_mem_pd_shift;
        struct clk              *clk;
 };