add usb support for hi6220
Subsystems (3)
v2 cover add usb support for hi6220
v2:
address comments from Sergei and Peter
add hi6220_phy_setup(false) code
v1:
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host
Zhangfei Gao (4):
Documentation: dt-bindings: add dt binding info for hi6220 dwc2
Documentation: dt-bindings: add dt binding info for hi6220
usb: dwc2: platform: add hi6220 support
usb: phy: add phy-hi6220-usb
Documentation/devicetree/bindings/usb/dwc2.txt | 1 + .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++++ drivers/usb/dwc2/platform.c | 30 +++ drivers/usb/phy/Kconfig | 9 + drivers/usb/phy/Makefile | 1 + drivers/usb/phy/phy-hi6220-usb.c | 297 +++++++++++++++++++++ 6 files changed, 387 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt create mode 100644 drivers/usb/phy/phy-hi6220-usb.c
Signature · 1 line
1.9.1
PATCH v2 1/4 Documentation: dt-bindings: add dt binding info for hi6220 dwc2
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220
--- Documentation/devicetree/bindings/usb/dwc2.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/usb/dwc2.txt +1 -0
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller Required properties: - compatible : One of: - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC. + - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC. - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc; - "rockchip,rk3188-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3188 Soc; - "rockchip,rk3288-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3288 Soc;
Signature · 1 line
1.9.1
PATCH v2 2/4 Documentation: dt-bindings: add dt binding info for hi6220
In reply to Zhangfei Gao--- .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
Documentation/devicetree/bindings/usb/hi6220-usb.txt new file +49 -0
@@ -0,0 +1,49 @@ +Hisilicon hi6220 SoC USB controller +----------------------------- + +usb controller is inherited from dwc2, refer dwc2.txt +----- + +Required properties: +- compatible: "hisilicon,hi6220-usb" +Refer to dwc2.txt for dwc2 usb properties + + +PHY: +----- + +Required properties: +- compatible: "hisilicon,hi6220-usb-phy" +- vcc-supply: phandle to the regulator that provides power to the PHY. +- clocks: phandle and clock specifier of the PHY clock. +- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral. +- hisilicon,gpio-vbus: gpio of detecting vbus. +- hisilicon,gpio-id: gpio of detecting id. + +Example: + + peripheral_ctrl: syscon at f7030000 { + compatible = "syscon"; + reg = <0x0 0xf7030000 0x0 0x1000>; + }; + + usb2_phy: usbphy { + compatible = "hisilicon,hi6220-usb-phy"; + vcc-supply = <&fixed_5v_hub>; + hisilicon,gpio-vbus = <&gpio2 6 0>; + hisilicon,gpio-id = <&gpio2 5 0>; + hisilicon,peripheral-syscon = <&peripheral_ctrl>; + clocks = <&clock_sys HI6220_USBOTG_HCLK>; + }; + + usb: usb at f72c0000 { + compatible = "hisilicon,hi6220-usb"; + reg = <0x0 0xf72c0000 0x0 0x40000>; + phys = <&usb2_phy>; + dr_mode = "otg"; + g-use-dma; + g-rx-fifo-size = <512>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128>; + interrupts = <0 77 0x4>; + };
Signature · 1 line
1.9.1
PATCH v2 3/4 usb: dwc2: platform: add hi6220 support
In reply to Zhangfei Gao--- drivers/usb/dwc2/platform.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/usb/dwc2/platform.c +30 -0
@@ -50,6 +50,35 @@static const char dwc2_driver_name[] ="dwc2" ; +static const struct dwc2_core_params params_hi6220 = { + .otg_cap =2 ,/* No HNP/SRP capable */ + .otg_ver =0 ,/* 1.3 */ + .dma_enable =1 , + .dma_desc_enable =0 , + .speed =0 ,/* High Speed */ + .enable_dynamic_fifo =1 , + .en_multiple_tx_fifo =1 , + .host_rx_fifo_size =512 , + .host_nperio_tx_fifo_size =512 , + .host_perio_tx_fifo_size =512 , + .max_transfer_size =65535 , + .max_packet_count =511 , + .host_channels =16 , + .phy_type =1 ,/* UTMI */ + .phy_utmi_width =8 , + .phy_ulpi_ddr =0 ,/* Single */ + .phy_ulpi_ext_vbus =0 , + .i2c_enable =0 , + .ulpi_fs_ls =0 , + .host_support_fs_ls_low_power =0 , + .host_ls_low_power_phy_clk =0 ,/* 48 MHz */ + .ts_dline =0 , + .reload_ctl =0 , + .ahbcfg =GAHBCFG_HBSTLEN_INCR16 << +GAHBCFG_HBSTLEN_SHIFT , + .uframe_sched =0 , +}; +static const struct dwc2_core_params params_bcm2835 = { .otg_cap =0 ,/* HNP/SRP capable */ .otg_ver =0 ,/* 1.3 */
@@ -129,6 +158,7 @@ static int dwc2_driver_remove(struct platform_device *dev)static const struct of_device_id dwc2_of_match_table[] = { { .compatible ="brcm,bcm2835-usb" , .data = ¶ms_bcm2835 }, + { .compatible ="hisilicon,hi6220-usb" , .data = ¶ms_hi6220 }, { .compatible ="rockchip,rk3066-usb" , .data = ¶ms_rk3066 }, { .compatible ="snps,dwc2" , .data =NULL }, { .compatible ="samsung,s3c6400-hsotg" , .data =NULL },
Signature · 1 line
1.9.1
PATCH v2 4/4 usb: phy: add phy-hi6220-usb
In reply to Zhangfei GaoAdd usb phy controller for hi6220 platform
--- drivers/usb/phy/Kconfig | 9 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/phy-hi6220-usb.c | 297 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 drivers/usb/phy/phy-hi6220-usb.c
drivers/usb/phy/Kconfig +9 -0
@@ -173,6 +173,15 @@ config USB_MXS_PHY MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. +config USB_HI6220_PHY + tristate "hi6220 USB PHY support" + select USB_PHY + select MFD_SYSCON + help + Enable this to support the HISILICON HI6220 USB PHY. + + To compile this driver as a module, choose M here. + config USB_RCAR_PHY tristate "Renesas R-Car USB PHY support" depends on USB || USB_GADGET
drivers/usb/phy/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o +obj-$(CONFIG_USB_HI6220_PHY) += phy-hi6220-usb.o obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
drivers/usb/phy/phy-hi6220-usb.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 4/4 usb: phy: add phy-hi6220-usb
Quoted 116 lines · Zhangfei Gao
Add usb phy controller for hi6220 platform
Signed-off-by Zhangfei Gao <[email protected]>--- drivers/usb/phy/Kconfig | 9 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/phy-hi6220-usb.c | 297 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 drivers/usb/phy/phy-hi6220-usb.cdrivers/usb/phy/Kconfig +9
-0@@ -173,6 +173,15 @@ config USB_MXS_PHY MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. +config USB_HI6220_PHY + tristate "hi6220 USB PHY support" + select USB_PHY + select MFD_SYSCON + help + Enable this to support the HISILICON HI6220 USB PHY. + + To compile this driver as a module, choose M here. + config USB_RCAR_PHY tristate "Renesas R-Car USB PHY support" depends on USB || USB_GADGETdrivers/usb/phy/Makefile +1
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o +obj-$(CONFIG_USB_HI6220_PHY) += phy-hi6220-usb.o obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.odrivers/usb/phy/phy-hi6220-usb.c new file +68
-0@@ -0,0 +1,297 @@ +/* +* Copyright (c) 2015 Linaro Ltd. +* Copyright (c) 2015 Hisilicon Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/clk.h> +#include <linux/mfd/syscon.h> +#include <linux/of_gpio.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/usb/gadget.h> +#include <linux/usb/otg.h> + +#define SC_PERIPH_CTRL4 0x00c + +#define CTRL4_PICO_SIDDQ BIT(6) +#define CTRL4_PICO_OGDISABLE BIT(8) +#define CTRL4_PICO_VBUSVLDEXT BIT(10) +#define CTRL4_PICO_VBUSVLDEXTSEL BIT(11) +#define CTRL4_OTG_PHY_SEL BIT(21) + +#define SC_PERIPH_CTRL5 0x010 + +#define CTRL5_USBOTG_RES_SEL BIT(3) +#define CTRL5_PICOPHY_ACAENB BIT(4) +#define CTRL5_PICOPHY_BC_MODE BIT(5) +#define CTRL5_PICOPHY_CHRGSEL BIT(6) +#define CTRL5_PICOPHY_VDATSRCEND BIT(7) +#define CTRL5_PICOPHY_VDATDETENB BIT(8) +#define CTRL5_PICOPHY_DCDENB BIT(9) +#define CTRL5_PICOPHY_IDDIG BIT(10) + +#define SC_PERIPH_CTRL8 0x018 +#define SC_PERIPH_RSTEN0 0x300 +#define SC_PERIPH_RSTDIS0 0x304 + +#define RST0_USBOTG_BUS BIT(4) +#define RST0_POR_PICOPHY BIT(5) +#define RST0_USBOTG BIT(6) +#define RST0_USBOTG_32K BIT(7) + +#define EYE_PATTERN_PARA 0x7053348c + +struct hi6220_priv { +struct usb_phy phy; +struct delayed_work work; +struct regmap *reg; +struct clk *clk; +struct regulator *vcc; +int gpio_vbus; +int gpio_id; +enum usb_otg_state state; +}; + +static void hi6220_start_periphrals (struct hi6220_priv *priv,bool on) +{ +struct usb_otg *otg = priv->phy.otg; + +if (!otg->gadget) +return ; + +if (on)
drivers/usb/phy/phy-hi6220-usb.c line 78
Quoted 10 lines
drivers/usb/phy/phy-hi6220-usb.c new file +10
-0+usb_gadget_connect (otg->gadget); + else + usb_gadget_disconnect(otg->gadget); +} + +static void hi6220_detect_work (struct work_struct *work) +{ +struct hi6220_priv *priv = + container_of(work, struct hi6220_priv, work.work); +int gpio_id, gpio_vubs;
%s/gpio_vubs/gpio_vbus
Quoted 78 lines
drivers/usb/phy/phy-hi6220-usb.c new file +78
-0+enum usb_otg_state state; + +if (!gpio_is_valid (priv->gpio_id) || !gpio_is_valid (priv->gpio_vbus)) +return ; + + gpio_id =gpio_get_value_cansleep (priv->gpio_id); + gpio_vubs =gpio_get_value_cansleep (priv->gpio_vbus); + +if (gpio_vubs ==0 ) { +if (gpio_id ==1 ) + state =OTG_STATE_B_PERIPHERAL ; +else + state =OTG_STATE_A_HOST ; + }else { + state =OTG_STATE_A_HOST ; + } + +if (priv->state != state) { +hi6220_start_periphrals (priv, state ==OTG_STATE_B_PERIPHERAL ); + priv->state = state; + } +} + +static irqreturn_t hiusb_gpio_intr (int irq,void *data) +{ +struct hi6220_priv *priv = (struct hi6220_priv *)data; + +/* add debounce time */ +schedule_delayed_work (&priv->work,msecs_to_jiffies (100 )); +return IRQ_HANDLED ; +} + +static int hi6220_set_peripheral (struct usb_otg *otg,struct usb_gadget *gadget) +{ + otg->gadget = gadget; +return 0 ; +} + +static void hi6220_phy_setup (struct hi6220_priv *priv,bool on) +{ +struct regmap *reg = priv->reg; +u32 val, mask; +int ret; + +if (priv->reg ==NULL ) +return ; + +if (on) { + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ; + mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_RSTDIS0 , mask, val); +if (ret) +return ; + + ret =regmap_read (reg,SC_PERIPH_CTRL5 , &val); + val =CTRL5_USBOTG_RES_SEL |CTRL5_PICOPHY_ACAENB ; + mask = val |CTRL5_PICOPHY_BC_MODE ; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL5 , mask, val); +if (ret) +return ; + + val =CTRL4_PICO_VBUSVLDEXT |CTRL4_PICO_VBUSVLDEXTSEL | +CTRL4_OTG_PHY_SEL ; + mask = val |CTRL4_PICO_SIDDQ |CTRL4_PICO_OGDISABLE ; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL4 , mask, val); +if (ret) +return ; + + ret =regmap_write (reg,SC_PERIPH_CTRL8 ,EYE_PATTERN_PARA ); +if (ret) +return ; + }else { + val =CTRL4_PICO_SIDDQ ; + mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL4 , mask, val); +if (ret) +return ;
drivers/usb/phy/phy-hi6220-usb.c line 166
Quoted 10 lines
drivers/usb/phy/phy-hi6220-usb.c new file +10
-0+ + ret =regmap_read (reg,SC_PERIPH_CTRL4 , &val); + + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ; + mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_RSTEN0 , mask, val); +if (ret) +return ; + }
You have return value check for regmap API, but no error message or return value for hi6220_phy_setup, it looks strange.
Quoted 35 lines
drivers/usb/phy/phy-hi6220-usb.c new file +35
-0+} + +static int hi6220_phy_probe (struct platform_device *pdev) +{ +struct hi6220_priv *priv; +struct usb_otg *otg; +struct device_node *np = pdev->dev.of_node; +int ret, irq; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + otg =devm_kzalloc (&pdev->dev,sizeof (*otg),GFP_KERNEL ); +if (!otg) +return -ENOMEM ; + + priv->phy.dev = &pdev->dev; + priv->phy.otg = otg; + priv->phy.label ="hi6220" ; + priv->phy.type =USB_PHY_TYPE_USB2 ; + otg->set_peripheral = hi6220_set_peripheral; +platform_set_drvdata (pdev, priv); + + priv->gpio_vbus =of_get_named_gpio (np,"hisilicon,gpio-vbus" ,0 ); +if (priv->gpio_vbus == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +if (!gpio_is_valid (priv->gpio_vbus)) { +dev_err (&pdev->dev,"invalid gpio %d\n" , priv->gpio_vbus); +return -ENODEV ; + } + + priv->gpio_id =of_get_named_gpio (np,"hisilicon,gpio-id" ,0 ); +if (priv->gpio_id == -EPROBE_DEFER ) +return -EPROBE_DEFER ;
drivers/usb/phy/phy-hi6220-usb.c line 211
Quoted 10 lines
drivers/usb/phy/phy-hi6220-usb.c new file +10
-0+if (!gpio_is_valid (priv->gpio_id)) { +dev_err (&pdev->dev,"invalid gpio %d\n" , priv->gpio_id); +return -ENODEV ; + } + + priv->reg =syscon_regmap_lookup_by_phandle (pdev->dev.of_node, +"hisilicon,peripheral-syscon" ); +if (IS_ERR (priv->reg)) + priv->reg =NULL ; +
see my comments at your v1.
Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c new file +8
-0+INIT_DELAYED_WORK (&priv->work, hi6220_detect_work); + + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_vbus, +GPIOF_IN ,"gpio_vbus" ); +if (ret <0 ) { +dev_err (&pdev->dev,"gpio request failed for gpio_vbus\n" ); +return ret; + }
drivers/usb/phy/phy-hi6220-usb.c line 229
Quoted 10 lines
drivers/usb/phy/phy-hi6220-usb.c new file +10
-0+ + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_id, +GPIOF_IN ,"gpio_id" ); +if (ret <0 ) { +dev_err (&pdev->dev,"gpio request failed for gpio_id\n" ); +return ret; + } + + priv->vcc =devm_regulator_get (&pdev->dev,"vcc" ); +if (!IS_ERR (priv->vcc)) {
EPROBE_DEFER?
Quoted 71 lines
drivers/usb/phy/phy-hi6220-usb.c new file +68
-0+ ret =regulator_enable (priv->vcc); +if (ret) { +dev_err (&pdev->dev,"Failed to enable regulator\n" ); +return -ENODEV ; + } + } + + priv->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (priv->clk)) { +regulator_disable (priv->vcc); +return PTR_ERR (priv->clk); + } +clk_prepare_enable (priv->clk); + + irq =gpio_to_irq (priv->gpio_vbus); + ret =devm_request_irq (&pdev->dev,gpio_to_irq (priv->gpio_vbus), + hiusb_gpio_intr,IRQF_NO_SUSPEND | +IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING , +"vbus_gpio_intr" , priv); +if (ret) { +dev_err (&pdev->dev,"request gpio irq failed.\n" ); + goto err_irq; + } + +hi6220_phy_setup (priv, true); + ret =usb_add_phy_dev (&priv->phy); +if (ret) { +dev_err (&pdev->dev,"Can't register transceiver\n" ); + goto err_irq; + } +schedule_delayed_work (&priv->work,0 ); + +return 0 ; +err_irq: +clk_disable_unprepare (priv->clk); +regulator_disable (priv->vcc); +return ret; +} + +static int hi6220_phy_remove (struct platform_device *pdev) +{ +struct hi6220_priv *priv =platform_get_drvdata (pdev); + +hi6220_phy_setup (priv, false); +clk_disable_unprepare (priv->clk); +regulator_disable (priv->vcc); +return 0 ; +} + +static const struct of_device_id hi6220_phy_of_match[] = { + {.compatible ="hisilicon,hi6220-usb-phy" ,}, + { }, +}; +MODULE_DEVICE_TABLE (of, hi6220_phy_of_match); + +static struct platform_driver hi6220_phy_driver = { + .probe = hi6220_phy_probe, + .remove = hi6220_phy_remove, + .driver = { + .name ="hi6220-usb-phy" , + .of_match_table = hi6220_phy_of_match, + } +}; +module_platform_driver (hi6220_phy_driver); + +MODULE_DESCRIPTION ("HISILICON HI6220 USB PHY driver" ); +MODULE_ALIAS ("platform:hi6220-usb-phy" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
1.9.1
Signature · 2 lines
Best Regards, Peter Chen
PATCH v2 4/4 usb: phy: add phy-hi6220-usb
Quoted 7 lines · Peter Chen
drivers/usb/phy/phy-hi6220-usb.c line 78
Quoted 5 lines
drivers/usb/phy/phy-hi6220-usb.c new file +5
-0+static void hi6220_detect_work (struct work_struct *work) +{ +struct hi6220_priv *priv = + container_of(work, struct hi6220_priv, work.work); +int gpio_id, gpio_vubs;%s/gpio_vubs/gpio_vbus
Yes, typo
Quoted 45 lines
Quoted 45 lines
drivers/usb/phy/phy-hi6220-usb.c new file +45
-0+static void hi6220_phy_setup (struct hi6220_priv *priv,bool on) +{ +struct regmap *reg = priv->reg; +u32 val, mask; +int ret; + +if (priv->reg ==NULL ) +return ; + +if (on) { + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ; + mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_RSTDIS0 , mask, val); +if (ret) +return ; + + ret =regmap_read (reg,SC_PERIPH_CTRL5 , &val); + val =CTRL5_USBOTG_RES_SEL |CTRL5_PICOPHY_ACAENB ; + mask = val |CTRL5_PICOPHY_BC_MODE ; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL5 , mask, val); +if (ret) +return ; + + val =CTRL4_PICO_VBUSVLDEXT |CTRL4_PICO_VBUSVLDEXTSEL | +CTRL4_OTG_PHY_SEL ; + mask = val |CTRL4_PICO_SIDDQ |CTRL4_PICO_OGDISABLE ; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL4 , mask, val); +if (ret) +return ; + + ret =regmap_write (reg,SC_PERIPH_CTRL8 ,EYE_PATTERN_PARA ); +if (ret) +return ; + }else { + val =CTRL4_PICO_SIDDQ ; + mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_CTRL4 , mask, val); +if (ret) +return ; + + ret =regmap_read (reg,SC_PERIPH_CTRL4 , &val); + + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ;
Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 166
Quoted 5 lines
drivers/usb/phy/phy-hi6220-usb.c new file +5
-0+ mask = val; + ret =regmap_update_bits (reg,SC_PERIPH_RSTEN0 , mask, val); +if (ret) +return ; + }You have return value check for regmap API, but no error message or return value for
hi6220_phy_setup, it looks strange.
There was dev_err(priv->dev, "failed to setup phy\n"); Then I found priv->dev is the only one place to use, so I remove this for simple.
Quoted 40 lines
Quoted 40 lines
drivers/usb/phy/phy-hi6220-usb.c new file +39
-0+} + +static int hi6220_phy_probe (struct platform_device *pdev) +{ +struct hi6220_priv *priv; +struct usb_otg *otg; +struct device_node *np = pdev->dev.of_node; +int ret, irq; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + otg =devm_kzalloc (&pdev->dev,sizeof (*otg),GFP_KERNEL ); +if (!otg) +return -ENOMEM ; + + priv->phy.dev = &pdev->dev; + priv->phy.otg = otg; + priv->phy.label ="hi6220" ; + priv->phy.type =USB_PHY_TYPE_USB2 ; + otg->set_peripheral = hi6220_set_peripheral; +platform_set_drvdata (pdev, priv); + + priv->gpio_vbus =of_get_named_gpio (np,"hisilicon,gpio-vbus" ,0 ); +if (priv->gpio_vbus == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +if (!gpio_is_valid (priv->gpio_vbus)) { +dev_err (&pdev->dev,"invalid gpio %d\n" , priv->gpio_vbus); +return -ENODEV ; + } + + priv->gpio_id =of_get_named_gpio (np,"hisilicon,gpio-id" ,0 ); +if (priv->gpio_id == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +if (!gpio_is_valid (priv->gpio_id)) { +dev_err (&pdev->dev,"invalid gpio %d\n" , priv->gpio_id); +return -ENODEV ; + }
Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 211
Quoted 6 lines
drivers/usb/phy/phy-hi6220-usb.c new file +6
-0+ + priv->reg =syscon_regmap_lookup_by_phandle (pdev->dev.of_node, +"hisilicon,peripheral-syscon" ); +if (IS_ERR (priv->reg)) + priv->reg =NULL ; +see my comments at your v1.
As replied in v1, EPROBE_DEFER does not needed.
syscon is register far earlier.
Quoted 13 lines
Quoted 13 lines
drivers/usb/phy/phy-hi6220-usb.c new file +12
-0+INIT_DELAYED_WORK (&priv->work, hi6220_detect_work); + + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_vbus, +GPIOF_IN ,"gpio_vbus" ); +if (ret <0 ) { +dev_err (&pdev->dev,"gpio request failed for gpio_vbus\n" ); +return ret; + } + + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_id, +GPIOF_IN ,"gpio_id" ); +if (ret <0 ) {
Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 229
Quoted 6 lines
drivers/usb/phy/phy-hi6220-usb.c new file +6
-0+dev_err (&pdev->dev,"gpio request failed for gpio_id\n" ); +return ret; + } + + priv->vcc =devm_regulator_get (&pdev->dev,"vcc" ); +if (!IS_ERR (priv->vcc)) {
EPROBE_DEFER?
No, this is not needed, since regulator is registered earlier than device.
drivers/Makefile
# regulators early, since some subsystems rely on them to initialize obj-$(CONFIG_REGULATOR) += regulator/
EPROBE_DEFER should be the last option we rely on.
Thanks
PATCH v2 4/4 usb: phy: add phy-hi6220-usb
Quoted 163 lines · zhangfei
Quoted 8 lines · Peter Chen
drivers/usb/phy/phy-hi6220-usb.c line 78
Quoted 5 lines
drivers/usb/phy/phy-hi6220-usb.c new file +5
-0+static void hi6220_detect_work (struct work_struct *work) +{ +struct hi6220_priv *priv = + container_of(work, struct hi6220_priv, work.work); +int gpio_id, gpio_vubs;%s/gpio_vubs/gpio_vbus
Yes, typo
Quoted 52 lines
Quoted 52 lines
drivers/usb/phy/phy-hi6220-usb.c new file +14
-0+static void hi6220_phy_setup (struct hi6220_priv *priv,bool on) +{ +struct regmap *reg = priv->reg; +u32 val, mask; +int ret; + +if (priv->reg ==NULL ) +return ; + +if (on) { + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ; + mask = val; + ret = regmap_update_bits(reg, SC_PERIPH_RSTDIS0, mask,val);
drivers/usb/phy/phy-hi6220-usb.c new file +7
-0+if (ret) +return ; + + ret =regmap_read (reg,SC_PERIPH_CTRL5 , &val); + val =CTRL5_USBOTG_RES_SEL |CTRL5_PICOPHY_ACAENB ; + mask = val |CTRL5_PICOPHY_BC_MODE ; + ret = regmap_update_bits(reg, SC_PERIPH_CTRL5, mask,val);
drivers/usb/phy/phy-hi6220-usb.c new file +7
-0+if (ret) +return ; + + val =CTRL4_PICO_VBUSVLDEXT |CTRL4_PICO_VBUSVLDEXTSEL | +CTRL4_OTG_PHY_SEL ; + mask = val |CTRL4_PICO_SIDDQ |CTRL4_PICO_OGDISABLE ; + ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask,val);
drivers/usb/phy/phy-hi6220-usb.c new file +4
-0+if (ret) +return ; + + ret = regmap_write(reg, SC_PERIPH_CTRL8,
EYE_PATTERN_PARA);drivers/usb/phy/phy-hi6220-usb.c new file +6
-0+if (ret) +return ; + }else { + val =CTRL4_PICO_SIDDQ ; + mask = val; + ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask,val);
drivers/usb/phy/phy-hi6220-usb.c new file +9
-0+if (ret) +return ; + + ret =regmap_read (reg,SC_PERIPH_CTRL4 , &val); + + val =RST0_USBOTG_BUS |RST0_POR_PICOPHY | +RST0_USBOTG |RST0_USBOTG_32K ; + mask = val; + ret = regmap_update_bits(reg, SC_PERIPH_RSTEN0, mask,Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 166
Quoted 4 lines
val);
drivers/usb/phy/phy-hi6220-usb.c new file +3
-0+if (ret) +return ; + }You have return value check for regmap API, but no error message or return value for
hi6220_phy_setup, it looks strange.There was
dev_err(priv->dev, "failed to setup phy\n");
Then I foundpriv->devis the only one place to use, so I remove this for simple.Quoted 43 lines
Quoted 43 lines
drivers/usb/phy/phy-hi6220-usb.c new file +25
-0+} + +static int hi6220_phy_probe (struct platform_device *pdev) +{ +struct hi6220_priv *priv; +struct usb_otg *otg; +struct device_node *np = pdev->dev.of_node; +int ret, irq; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + otg =devm_kzalloc (&pdev->dev,sizeof (*otg),GFP_KERNEL ); +if (!otg) +return -ENOMEM ; + + priv->phy.dev = &pdev->dev; + priv->phy.otg = otg; + priv->phy.label ="hi6220" ; + priv->phy.type =USB_PHY_TYPE_USB2 ; + otg->set_peripheral = hi6220_set_peripheral; +platform_set_drvdata (pdev, priv); + + priv->gpio_vbus = of_get_named_gpio(np, "hisilicon,gpio-vbus",0);
drivers/usb/phy/phy-hi6220-usb.c new file +4
-0+if (priv->gpio_vbus == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +if (!gpio_is_valid (priv->gpio_vbus)) { + dev_err(&pdev->dev, "invalid gpio %d\n",
priv->gpio_vbus);drivers/usb/phy/phy-hi6220-usb.c new file +11
-0+return -ENODEV ; + } + + priv->gpio_id =of_get_named_gpio (np,"hisilicon,gpio-id" ,0 ); +if (priv->gpio_id == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +if (!gpio_is_valid (priv->gpio_id)) { +dev_err (&pdev->dev,"invalid gpio %d\n" , priv->gpio_id); +return -ENODEV ; + } +Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 211
Quoted 5 lines
drivers/usb/phy/phy-hi6220-usb.c new file +5
-0+ priv->reg =syscon_regmap_lookup_by_phandle (pdev->dev.of_node, +"hisilicon,peripheral-syscon" ); +if (IS_ERR (priv->reg)) + priv->reg =NULL ; +see my comments at your v1.
As replied in v1,
EPROBE_DEFERdoes not needed.
syscon is register far earlier.Quoted 15 lines
Quoted 15 lines
drivers/usb/phy/phy-hi6220-usb.c new file +6
-0+INIT_DELAYED_WORK (&priv->work, hi6220_detect_work); + + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_vbus, +GPIOF_IN ,"gpio_vbus" ); +if (ret <0 ) { + dev_err(&pdev->dev, "gpio request failed forgpio_vbus\n");
drivers/usb/phy/phy-hi6220-usb.c new file +7
-0+return ret; + } + + ret =devm_gpio_request_one (&pdev->dev, priv->gpio_id, +GPIOF_IN ,"gpio_id" ); +if (ret <0 ) { +dev_err (&pdev->dev,"gpio request failed for gpio_id\n" );Quoted 8 lines
drivers/usb/phy/phy-hi6220-usb.c line 229
Quoted 5 lines
drivers/usb/phy/phy-hi6220-usb.c new file +5
-0+return ret; + } + + priv->vcc =devm_regulator_get (&pdev->dev,"vcc" ); +if (!IS_ERR (priv->vcc)) {
EPROBE_DEFER?
Quoted 6 lines
No, this is not needed, since regulator is registered earlier than device.
drivers/Makefile# regulators early, since some subsystems rely on them to initialize obj-$(CONFIG_REGULATOR) += regulator/
After reconsideration, EPROBE_DEFER should be added here in case of module.
Thanks