18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This is a small driver for the dwc3 to provide the glue logic
68c2ecf20Sopenharmony_ci * to configure the controller. Tested on STi platforms.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 2014 Stmicroelectronics
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
118c2ecf20Sopenharmony_ci * Contributors: Aymen Bouattay <aymen.bouattay@st.com>
128c2ecf20Sopenharmony_ci *               Peter Griffin <peter.griffin@linaro.org>
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * Inspired by dwc3-omap.c and dwc3-exynos.c.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/delay.h>
188c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
198c2ecf20Sopenharmony_ci#include <linux/io.h>
208c2ecf20Sopenharmony_ci#include <linux/ioport.h>
218c2ecf20Sopenharmony_ci#include <linux/kernel.h>
228c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
238c2ecf20Sopenharmony_ci#include <linux/module.h>
248c2ecf20Sopenharmony_ci#include <linux/of.h>
258c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
268c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
278c2ecf20Sopenharmony_ci#include <linux/slab.h>
288c2ecf20Sopenharmony_ci#include <linux/regmap.h>
298c2ecf20Sopenharmony_ci#include <linux/reset.h>
308c2ecf20Sopenharmony_ci#include <linux/pinctrl/consumer.h>
318c2ecf20Sopenharmony_ci#include <linux/usb/of.h>
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#include "core.h"
348c2ecf20Sopenharmony_ci#include "io.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* glue registers */
378c2ecf20Sopenharmony_ci#define CLKRST_CTRL		0x00
388c2ecf20Sopenharmony_ci#define AUX_CLK_EN		BIT(0)
398c2ecf20Sopenharmony_ci#define SW_PIPEW_RESET_N	BIT(4)
408c2ecf20Sopenharmony_ci#define EXT_CFG_RESET_N		BIT(8)
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * 1'b0 : The host controller complies with the xHCI revision 0.96
438c2ecf20Sopenharmony_ci * 1'b1 : The host controller complies with the xHCI revision 1.0
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define XHCI_REVISION		BIT(12)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define USB2_VBUS_MNGMNT_SEL1	0x2C
488c2ecf20Sopenharmony_ci/*
498c2ecf20Sopenharmony_ci * For all fields in USB2_VBUS_MNGMNT_SEL1
508c2ecf20Sopenharmony_ci * 2’b00 : Override value from Reg 0x30 is selected
518c2ecf20Sopenharmony_ci * 2’b01 : utmiotg_<signal_name> from usb3_top is selected
528c2ecf20Sopenharmony_ci * 2’b10 : pipew_<signal_name> from PIPEW instance is selected
538c2ecf20Sopenharmony_ci * 2’b11 : value is 1'b0
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_ci#define USB2_VBUS_REG30		0x0
568c2ecf20Sopenharmony_ci#define USB2_VBUS_UTMIOTG	0x1
578c2ecf20Sopenharmony_ci#define USB2_VBUS_PIPEW		0x2
588c2ecf20Sopenharmony_ci#define USB2_VBUS_ZERO		0x3
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define SEL_OVERRIDE_VBUSVALID(n)	(n << 0)
618c2ecf20Sopenharmony_ci#define SEL_OVERRIDE_POWERPRESENT(n)	(n << 4)
628c2ecf20Sopenharmony_ci#define SEL_OVERRIDE_BVALID(n)		(n << 8)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Static DRD configuration */
658c2ecf20Sopenharmony_ci#define USB3_CONTROL_MASK		0xf77
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define USB3_DEVICE_NOT_HOST		BIT(0)
688c2ecf20Sopenharmony_ci#define USB3_FORCE_VBUSVALID		BIT(1)
698c2ecf20Sopenharmony_ci#define USB3_DELAY_VBUSVALID		BIT(2)
708c2ecf20Sopenharmony_ci#define USB3_SEL_FORCE_OPMODE		BIT(4)
718c2ecf20Sopenharmony_ci#define USB3_FORCE_OPMODE(n)		(n << 5)
728c2ecf20Sopenharmony_ci#define USB3_SEL_FORCE_DPPULLDOWN2	BIT(8)
738c2ecf20Sopenharmony_ci#define USB3_FORCE_DPPULLDOWN2		BIT(9)
748c2ecf20Sopenharmony_ci#define USB3_SEL_FORCE_DMPULLDOWN2	BIT(10)
758c2ecf20Sopenharmony_ci#define USB3_FORCE_DMPULLDOWN2		BIT(11)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/**
788c2ecf20Sopenharmony_ci * struct st_dwc3 - dwc3-st driver private structure
798c2ecf20Sopenharmony_ci * @dev:		device pointer
808c2ecf20Sopenharmony_ci * @glue_base:		ioaddr for the glue registers
818c2ecf20Sopenharmony_ci * @regmap:		regmap pointer for getting syscfg
828c2ecf20Sopenharmony_ci * @syscfg_reg_off:	usb syscfg control offset
838c2ecf20Sopenharmony_ci * @dr_mode:		drd static host/device config
848c2ecf20Sopenharmony_ci * @rstc_pwrdn:		rest controller for powerdown signal
858c2ecf20Sopenharmony_ci * @rstc_rst:		reset controller for softreset signal
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct st_dwc3 {
898c2ecf20Sopenharmony_ci	struct device *dev;
908c2ecf20Sopenharmony_ci	void __iomem *glue_base;
918c2ecf20Sopenharmony_ci	struct regmap *regmap;
928c2ecf20Sopenharmony_ci	int syscfg_reg_off;
938c2ecf20Sopenharmony_ci	enum usb_dr_mode dr_mode;
948c2ecf20Sopenharmony_ci	struct reset_control *rstc_pwrdn;
958c2ecf20Sopenharmony_ci	struct reset_control *rstc_rst;
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline u32 st_dwc3_readl(void __iomem *base, u32 offset)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	return readl_relaxed(base + offset);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	writel_relaxed(value, base + offset);
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/**
1098c2ecf20Sopenharmony_ci * st_dwc3_drd_init: program the port
1108c2ecf20Sopenharmony_ci * @dwc3_data: driver private structure
1118c2ecf20Sopenharmony_ci * Description: this function is to program the port as either host or device
1128c2ecf20Sopenharmony_ci * according to the static configuration passed from devicetree.
1138c2ecf20Sopenharmony_ci * OTG and dual role are not yet supported!
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_cistatic int st_dwc3_drd_init(struct st_dwc3 *dwc3_data)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	u32 val;
1188c2ecf20Sopenharmony_ci	int err;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val);
1218c2ecf20Sopenharmony_ci	if (err)
1228c2ecf20Sopenharmony_ci		return err;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	val &= USB3_CONTROL_MASK;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	switch (dwc3_data->dr_mode) {
1278c2ecf20Sopenharmony_ci	case USB_DR_MODE_PERIPHERAL:
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci		val &= ~(USB3_DELAY_VBUSVALID
1308c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3)
1318c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
1328c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci		/*
1358c2ecf20Sopenharmony_ci		 * USB3_PORT2_FORCE_VBUSVALID When '1' and when
1368c2ecf20Sopenharmony_ci		 * USB3_PORT2_DEVICE_NOT_HOST = 1, forces VBUSVLDEXT2 input
1378c2ecf20Sopenharmony_ci		 * of the pico PHY to 1.
1388c2ecf20Sopenharmony_ci		 */
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci		val |= USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID;
1418c2ecf20Sopenharmony_ci		break;
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	case USB_DR_MODE_HOST:
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci		val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID
1468c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_OPMODE	| USB3_FORCE_OPMODE(0x3)
1478c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
1488c2ecf20Sopenharmony_ci			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci		/*
1518c2ecf20Sopenharmony_ci		 * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus,
1528c2ecf20Sopenharmony_ci		 * when set to ‘0‘, it can delay the arrival of VBUSVALID
1538c2ecf20Sopenharmony_ci		 * information to VBUSVLDEXT2 input of the pico PHY.
1548c2ecf20Sopenharmony_ci		 * We don't want to do that so we set the bit to '1'.
1558c2ecf20Sopenharmony_ci		 */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		val |= USB3_DELAY_VBUSVALID;
1588c2ecf20Sopenharmony_ci		break;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	default:
1618c2ecf20Sopenharmony_ci		dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n",
1628c2ecf20Sopenharmony_ci			dwc3_data->dr_mode);
1638c2ecf20Sopenharmony_ci		return -EINVAL;
1648c2ecf20Sopenharmony_ci	}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val);
1678c2ecf20Sopenharmony_ci}
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/**
1708c2ecf20Sopenharmony_ci * st_dwc3_init: init the controller via glue logic
1718c2ecf20Sopenharmony_ci * @dwc3_data: driver private structure
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistatic void st_dwc3_init(struct st_dwc3 *dwc3_data)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION;
1788c2ecf20Sopenharmony_ci	reg &= ~SW_PIPEW_RESET_N;
1798c2ecf20Sopenharmony_ci	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	/* configure mux for vbus, powerpresent and bvalid signals */
1828c2ecf20Sopenharmony_ci	reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) |
1858c2ecf20Sopenharmony_ci		SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) |
1868c2ecf20Sopenharmony_ci		SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
1918c2ecf20Sopenharmony_ci	reg |= SW_PIPEW_RESET_N;
1928c2ecf20Sopenharmony_ci	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic int st_dwc3_probe(struct platform_device *pdev)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	struct st_dwc3 *dwc3_data;
1988c2ecf20Sopenharmony_ci	struct resource *res;
1998c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
2008c2ecf20Sopenharmony_ci	struct device_node *node = dev->of_node, *child;
2018c2ecf20Sopenharmony_ci	struct platform_device *child_pdev;
2028c2ecf20Sopenharmony_ci	struct regmap *regmap;
2038c2ecf20Sopenharmony_ci	int ret;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL);
2068c2ecf20Sopenharmony_ci	if (!dwc3_data)
2078c2ecf20Sopenharmony_ci		return -ENOMEM;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	dwc3_data->glue_base =
2108c2ecf20Sopenharmony_ci		devm_platform_ioremap_resource_byname(pdev, "reg-glue");
2118c2ecf20Sopenharmony_ci	if (IS_ERR(dwc3_data->glue_base))
2128c2ecf20Sopenharmony_ci		return PTR_ERR(dwc3_data->glue_base);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg");
2158c2ecf20Sopenharmony_ci	if (IS_ERR(regmap))
2168c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	dwc3_data->dev = dev;
2198c2ecf20Sopenharmony_ci	dwc3_data->regmap = regmap;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
2228c2ecf20Sopenharmony_ci	if (!res) {
2238c2ecf20Sopenharmony_ci		ret = -ENXIO;
2248c2ecf20Sopenharmony_ci		goto undo_platform_dev_alloc;
2258c2ecf20Sopenharmony_ci	}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	dwc3_data->syscfg_reg_off = res->start;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	dev_vdbg(&pdev->dev, "glue-logic addr 0x%pK, syscfg-reg offset 0x%x\n",
2308c2ecf20Sopenharmony_ci		 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	dwc3_data->rstc_pwrdn =
2338c2ecf20Sopenharmony_ci		devm_reset_control_get_exclusive(dev, "powerdown");
2348c2ecf20Sopenharmony_ci	if (IS_ERR(dwc3_data->rstc_pwrdn)) {
2358c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "could not get power controller\n");
2368c2ecf20Sopenharmony_ci		ret = PTR_ERR(dwc3_data->rstc_pwrdn);
2378c2ecf20Sopenharmony_ci		goto undo_platform_dev_alloc;
2388c2ecf20Sopenharmony_ci	}
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	/* Manage PowerDown */
2418c2ecf20Sopenharmony_ci	reset_control_deassert(dwc3_data->rstc_pwrdn);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	dwc3_data->rstc_rst =
2448c2ecf20Sopenharmony_ci		devm_reset_control_get_shared(dev, "softreset");
2458c2ecf20Sopenharmony_ci	if (IS_ERR(dwc3_data->rstc_rst)) {
2468c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "could not get reset controller\n");
2478c2ecf20Sopenharmony_ci		ret = PTR_ERR(dwc3_data->rstc_rst);
2488c2ecf20Sopenharmony_ci		goto undo_powerdown;
2498c2ecf20Sopenharmony_ci	}
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	/* Manage SoftReset */
2528c2ecf20Sopenharmony_ci	reset_control_deassert(dwc3_data->rstc_rst);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	child = of_get_child_by_name(node, "dwc3");
2558c2ecf20Sopenharmony_ci	if (!child) {
2568c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
2578c2ecf20Sopenharmony_ci		ret = -ENODEV;
2588c2ecf20Sopenharmony_ci		goto err_node_put;
2598c2ecf20Sopenharmony_ci	}
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	/* Allocate and initialize the core */
2628c2ecf20Sopenharmony_ci	ret = of_platform_populate(node, NULL, NULL, dev);
2638c2ecf20Sopenharmony_ci	if (ret) {
2648c2ecf20Sopenharmony_ci		dev_err(dev, "failed to add dwc3 core\n");
2658c2ecf20Sopenharmony_ci		goto err_node_put;
2668c2ecf20Sopenharmony_ci	}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	child_pdev = of_find_device_by_node(child);
2698c2ecf20Sopenharmony_ci	if (!child_pdev) {
2708c2ecf20Sopenharmony_ci		dev_err(dev, "failed to find dwc3 core device\n");
2718c2ecf20Sopenharmony_ci		ret = -ENODEV;
2728c2ecf20Sopenharmony_ci		goto err_node_put;
2738c2ecf20Sopenharmony_ci	}
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
2768c2ecf20Sopenharmony_ci	of_node_put(child);
2778c2ecf20Sopenharmony_ci	of_dev_put(child_pdev);
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	/*
2808c2ecf20Sopenharmony_ci	 * Configure the USB port as device or host according to the static
2818c2ecf20Sopenharmony_ci	 * configuration passed from DT.
2828c2ecf20Sopenharmony_ci	 * DRD is the only mode currently supported so this will be enhanced
2838c2ecf20Sopenharmony_ci	 * as soon as OTG is available.
2848c2ecf20Sopenharmony_ci	 */
2858c2ecf20Sopenharmony_ci	ret = st_dwc3_drd_init(dwc3_data);
2868c2ecf20Sopenharmony_ci	if (ret) {
2878c2ecf20Sopenharmony_ci		dev_err(dev, "drd initialisation failed\n");
2888c2ecf20Sopenharmony_ci		goto undo_softreset;
2898c2ecf20Sopenharmony_ci	}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	/* ST glue logic init */
2928c2ecf20Sopenharmony_ci	st_dwc3_init(dwc3_data);
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	platform_set_drvdata(pdev, dwc3_data);
2958c2ecf20Sopenharmony_ci	return 0;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cierr_node_put:
2988c2ecf20Sopenharmony_ci	of_node_put(child);
2998c2ecf20Sopenharmony_ciundo_softreset:
3008c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_rst);
3018c2ecf20Sopenharmony_ciundo_powerdown:
3028c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_pwrdn);
3038c2ecf20Sopenharmony_ciundo_platform_dev_alloc:
3048c2ecf20Sopenharmony_ci	platform_device_put(pdev);
3058c2ecf20Sopenharmony_ci	return ret;
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic int st_dwc3_remove(struct platform_device *pdev)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	of_platform_depopulate(&pdev->dev);
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_pwrdn);
3158c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_rst);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	return 0;
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
3218c2ecf20Sopenharmony_cistatic int st_dwc3_suspend(struct device *dev)
3228c2ecf20Sopenharmony_ci{
3238c2ecf20Sopenharmony_ci	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_pwrdn);
3268c2ecf20Sopenharmony_ci	reset_control_assert(dwc3_data->rstc_rst);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	pinctrl_pm_select_sleep_state(dev);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	return 0;
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistatic int st_dwc3_resume(struct device *dev)
3348c2ecf20Sopenharmony_ci{
3358c2ecf20Sopenharmony_ci	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
3368c2ecf20Sopenharmony_ci	int ret;
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	pinctrl_pm_select_default_state(dev);
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	reset_control_deassert(dwc3_data->rstc_pwrdn);
3418c2ecf20Sopenharmony_ci	reset_control_deassert(dwc3_data->rstc_rst);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	ret = st_dwc3_drd_init(dwc3_data);
3448c2ecf20Sopenharmony_ci	if (ret) {
3458c2ecf20Sopenharmony_ci		dev_err(dev, "drd initialisation failed\n");
3468c2ecf20Sopenharmony_ci		return ret;
3478c2ecf20Sopenharmony_ci	}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	/* ST glue logic init */
3508c2ecf20Sopenharmony_ci	st_dwc3_init(dwc3_data);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	return 0;
3538c2ecf20Sopenharmony_ci}
3548c2ecf20Sopenharmony_ci#endif /* CONFIG_PM_SLEEP */
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_cistatic const struct of_device_id st_dwc3_match[] = {
3598c2ecf20Sopenharmony_ci	{ .compatible = "st,stih407-dwc3" },
3608c2ecf20Sopenharmony_ci	{ /* sentinel */ },
3618c2ecf20Sopenharmony_ci};
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, st_dwc3_match);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistatic struct platform_driver st_dwc3_driver = {
3668c2ecf20Sopenharmony_ci	.probe = st_dwc3_probe,
3678c2ecf20Sopenharmony_ci	.remove = st_dwc3_remove,
3688c2ecf20Sopenharmony_ci	.driver = {
3698c2ecf20Sopenharmony_ci		.name = "usb-st-dwc3",
3708c2ecf20Sopenharmony_ci		.of_match_table = st_dwc3_match,
3718c2ecf20Sopenharmony_ci		.pm = &st_dwc3_dev_pm_ops,
3728c2ecf20Sopenharmony_ci	},
3738c2ecf20Sopenharmony_ci};
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cimodule_platform_driver(st_dwc3_driver);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ciMODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
3788c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer");
3798c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
380