162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Ingenic SoCs USB PHY driver
462306a36Sopenharmony_ci * Copyright (c) Paul Cercueil <paul@crapouillou.net>
562306a36Sopenharmony_ci * Copyright (c) 漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>
662306a36Sopenharmony_ci * Copyright (c) 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/bitfield.h>
1062306a36Sopenharmony_ci#include <linux/clk.h>
1162306a36Sopenharmony_ci#include <linux/delay.h>
1262306a36Sopenharmony_ci#include <linux/io.h>
1362306a36Sopenharmony_ci#include <linux/module.h>
1462306a36Sopenharmony_ci#include <linux/of.h>
1562306a36Sopenharmony_ci#include <linux/phy/phy.h>
1662306a36Sopenharmony_ci#include <linux/platform_device.h>
1762306a36Sopenharmony_ci#include <linux/regulator/consumer.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* OTGPHY register offsets */
2062306a36Sopenharmony_ci#define REG_USBPCR_OFFSET			0x00
2162306a36Sopenharmony_ci#define REG_USBRDT_OFFSET			0x04
2262306a36Sopenharmony_ci#define REG_USBVBFIL_OFFSET			0x08
2362306a36Sopenharmony_ci#define REG_USBPCR1_OFFSET			0x0c
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* bits within the USBPCR register */
2662306a36Sopenharmony_ci#define USBPCR_USB_MODE				BIT(31)
2762306a36Sopenharmony_ci#define USBPCR_AVLD_REG				BIT(30)
2862306a36Sopenharmony_ci#define USBPCR_COMMONONN			BIT(25)
2962306a36Sopenharmony_ci#define USBPCR_VBUSVLDEXT			BIT(24)
3062306a36Sopenharmony_ci#define USBPCR_VBUSVLDEXTSEL		BIT(23)
3162306a36Sopenharmony_ci#define USBPCR_POR					BIT(22)
3262306a36Sopenharmony_ci#define USBPCR_SIDDQ				BIT(21)
3362306a36Sopenharmony_ci#define USBPCR_OTG_DISABLE			BIT(20)
3462306a36Sopenharmony_ci#define USBPCR_TXPREEMPHTUNE		BIT(6)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define USBPCR_IDPULLUP_MASK		GENMASK(29, 28)
3762306a36Sopenharmony_ci#define USBPCR_IDPULLUP_ALWAYS		0x2
3862306a36Sopenharmony_ci#define USBPCR_IDPULLUP_SUSPEND		0x1
3962306a36Sopenharmony_ci#define USBPCR_IDPULLUP_OTG			0x0
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define USBPCR_COMPDISTUNE_MASK		GENMASK(19, 17)
4262306a36Sopenharmony_ci#define USBPCR_COMPDISTUNE_DFT		0x4
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define USBPCR_OTGTUNE_MASK			GENMASK(16, 14)
4562306a36Sopenharmony_ci#define USBPCR_OTGTUNE_DFT			0x4
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define USBPCR_SQRXTUNE_MASK		GENMASK(13, 11)
4862306a36Sopenharmony_ci#define USBPCR_SQRXTUNE_DCR_20PCT	0x7
4962306a36Sopenharmony_ci#define USBPCR_SQRXTUNE_DFT			0x3
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_MASK		GENMASK(10, 7)
5262306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_DCR_50PPT	0xf
5362306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_DCR_25PPT	0x7
5462306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_DFT		0x3
5562306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_INC_25PPT	0x1
5662306a36Sopenharmony_ci#define USBPCR_TXFSLSTUNE_INC_50PPT	0x0
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define USBPCR_TXHSXVTUNE_MASK		GENMASK(5, 4)
5962306a36Sopenharmony_ci#define USBPCR_TXHSXVTUNE_DFT		0x3
6062306a36Sopenharmony_ci#define USBPCR_TXHSXVTUNE_DCR_15MV	0x1
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define USBPCR_TXRISETUNE_MASK		GENMASK(5, 4)
6362306a36Sopenharmony_ci#define USBPCR_TXRISETUNE_DFT		0x3
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define USBPCR_TXVREFTUNE_MASK		GENMASK(3, 0)
6662306a36Sopenharmony_ci#define USBPCR_TXVREFTUNE_INC_75PPT	0xb
6762306a36Sopenharmony_ci#define USBPCR_TXVREFTUNE_INC_25PPT	0x7
6862306a36Sopenharmony_ci#define USBPCR_TXVREFTUNE_DFT		0x5
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* bits within the USBRDTR register */
7162306a36Sopenharmony_ci#define USBRDT_UTMI_RST				BIT(27)
7262306a36Sopenharmony_ci#define USBRDT_HB_MASK				BIT(26)
7362306a36Sopenharmony_ci#define USBRDT_VBFIL_LD_EN			BIT(25)
7462306a36Sopenharmony_ci#define USBRDT_IDDIG_EN				BIT(24)
7562306a36Sopenharmony_ci#define USBRDT_IDDIG_REG			BIT(23)
7662306a36Sopenharmony_ci#define USBRDT_VBFIL_EN				BIT(2)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* bits within the USBPCR1 register */
7962306a36Sopenharmony_ci#define USBPCR1_BVLD_REG			BIT(31)
8062306a36Sopenharmony_ci#define USBPCR1_DPPD				BIT(29)
8162306a36Sopenharmony_ci#define USBPCR1_DMPD				BIT(28)
8262306a36Sopenharmony_ci#define USBPCR1_USB_SEL				BIT(28)
8362306a36Sopenharmony_ci#define USBPCR1_PORT_RST			BIT(21)
8462306a36Sopenharmony_ci#define USBPCR1_WORD_IF_16BIT		BIT(19)
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistruct ingenic_soc_info {
8762306a36Sopenharmony_ci	void (*usb_phy_init)(struct phy *phy);
8862306a36Sopenharmony_ci};
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_cistruct ingenic_usb_phy {
9162306a36Sopenharmony_ci	const struct ingenic_soc_info *soc_info;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	struct phy *phy;
9462306a36Sopenharmony_ci	void __iomem *base;
9562306a36Sopenharmony_ci	struct clk *clk;
9662306a36Sopenharmony_ci	struct regulator *vcc_supply;
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_cistatic int ingenic_usb_phy_init(struct phy *phy)
10062306a36Sopenharmony_ci{
10162306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
10262306a36Sopenharmony_ci	int err;
10362306a36Sopenharmony_ci	u32 reg;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	err = clk_prepare_enable(priv->clk);
10662306a36Sopenharmony_ci	if (err) {
10762306a36Sopenharmony_ci		dev_err(&phy->dev, "Unable to start clock: %d\n", err);
10862306a36Sopenharmony_ci		return err;
10962306a36Sopenharmony_ci	}
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci	priv->soc_info->usb_phy_init(phy);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	/* Wait for PHY to reset */
11462306a36Sopenharmony_ci	usleep_range(30, 300);
11562306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR_OFFSET);
11662306a36Sopenharmony_ci	writel(reg & ~USBPCR_POR, priv->base + REG_USBPCR_OFFSET);
11762306a36Sopenharmony_ci	usleep_range(300, 1000);
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	return 0;
12062306a36Sopenharmony_ci}
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_cistatic int ingenic_usb_phy_exit(struct phy *phy)
12362306a36Sopenharmony_ci{
12462306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci	clk_disable_unprepare(priv->clk);
12762306a36Sopenharmony_ci	regulator_disable(priv->vcc_supply);
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	return 0;
13062306a36Sopenharmony_ci}
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_cistatic int ingenic_usb_phy_power_on(struct phy *phy)
13362306a36Sopenharmony_ci{
13462306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
13562306a36Sopenharmony_ci	int err;
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	err = regulator_enable(priv->vcc_supply);
13862306a36Sopenharmony_ci	if (err) {
13962306a36Sopenharmony_ci		dev_err(&phy->dev, "Unable to enable VCC: %d\n", err);
14062306a36Sopenharmony_ci		return err;
14162306a36Sopenharmony_ci	}
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci	return 0;
14462306a36Sopenharmony_ci}
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_cistatic int ingenic_usb_phy_power_off(struct phy *phy)
14762306a36Sopenharmony_ci{
14862306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci	regulator_disable(priv->vcc_supply);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	return 0;
15362306a36Sopenharmony_ci}
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_cistatic int ingenic_usb_phy_set_mode(struct phy *phy,
15662306a36Sopenharmony_ci				  enum phy_mode mode, int submode)
15762306a36Sopenharmony_ci{
15862306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
15962306a36Sopenharmony_ci	u32 reg;
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci	switch (mode) {
16262306a36Sopenharmony_ci	case PHY_MODE_USB_HOST:
16362306a36Sopenharmony_ci		reg = readl(priv->base + REG_USBPCR_OFFSET);
16462306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_USB_MODE);
16562306a36Sopenharmony_ci		u32p_replace_bits(&reg, 0, USBPCR_VBUSVLDEXT);
16662306a36Sopenharmony_ci		u32p_replace_bits(&reg, 0, USBPCR_VBUSVLDEXTSEL);
16762306a36Sopenharmony_ci		u32p_replace_bits(&reg, 0, USBPCR_OTG_DISABLE);
16862306a36Sopenharmony_ci		writel(reg, priv->base + REG_USBPCR_OFFSET);
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci		break;
17162306a36Sopenharmony_ci	case PHY_MODE_USB_DEVICE:
17262306a36Sopenharmony_ci		reg = readl(priv->base + REG_USBPCR_OFFSET);
17362306a36Sopenharmony_ci		u32p_replace_bits(&reg, 0, USBPCR_USB_MODE);
17462306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_VBUSVLDEXT);
17562306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_VBUSVLDEXTSEL);
17662306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_OTG_DISABLE);
17762306a36Sopenharmony_ci		writel(reg, priv->base + REG_USBPCR_OFFSET);
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci		break;
18062306a36Sopenharmony_ci	case PHY_MODE_USB_OTG:
18162306a36Sopenharmony_ci		reg = readl(priv->base + REG_USBPCR_OFFSET);
18262306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_USB_MODE);
18362306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_VBUSVLDEXT);
18462306a36Sopenharmony_ci		u32p_replace_bits(&reg, 1, USBPCR_VBUSVLDEXTSEL);
18562306a36Sopenharmony_ci		u32p_replace_bits(&reg, 0, USBPCR_OTG_DISABLE);
18662306a36Sopenharmony_ci		writel(reg, priv->base + REG_USBPCR_OFFSET);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci		break;
18962306a36Sopenharmony_ci	default:
19062306a36Sopenharmony_ci		return -EINVAL;
19162306a36Sopenharmony_ci	}
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	return 0;
19462306a36Sopenharmony_ci}
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_cistatic const struct phy_ops ingenic_usb_phy_ops = {
19762306a36Sopenharmony_ci	.init		= ingenic_usb_phy_init,
19862306a36Sopenharmony_ci	.exit		= ingenic_usb_phy_exit,
19962306a36Sopenharmony_ci	.power_on	= ingenic_usb_phy_power_on,
20062306a36Sopenharmony_ci	.power_off	= ingenic_usb_phy_power_off,
20162306a36Sopenharmony_ci	.set_mode	= ingenic_usb_phy_set_mode,
20262306a36Sopenharmony_ci	.owner		= THIS_MODULE,
20362306a36Sopenharmony_ci};
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistatic void jz4770_usb_phy_init(struct phy *phy)
20662306a36Sopenharmony_ci{
20762306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
20862306a36Sopenharmony_ci	u32 reg;
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci	reg = USBPCR_AVLD_REG | USBPCR_COMMONONN | USBPCR_POR |
21162306a36Sopenharmony_ci		FIELD_PREP(USBPCR_IDPULLUP_MASK, USBPCR_IDPULLUP_ALWAYS) |
21262306a36Sopenharmony_ci		FIELD_PREP(USBPCR_COMPDISTUNE_MASK, USBPCR_COMPDISTUNE_DFT) |
21362306a36Sopenharmony_ci		FIELD_PREP(USBPCR_OTGTUNE_MASK, USBPCR_OTGTUNE_DFT) |
21462306a36Sopenharmony_ci		FIELD_PREP(USBPCR_SQRXTUNE_MASK, USBPCR_SQRXTUNE_DFT) |
21562306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXFSLSTUNE_MASK, USBPCR_TXFSLSTUNE_DFT) |
21662306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXRISETUNE_MASK, USBPCR_TXRISETUNE_DFT) |
21762306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXVREFTUNE_MASK, USBPCR_TXVREFTUNE_DFT);
21862306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
21962306a36Sopenharmony_ci}
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_cistatic void jz4775_usb_phy_init(struct phy *phy)
22262306a36Sopenharmony_ci{
22362306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
22462306a36Sopenharmony_ci	u32 reg;
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_USB_SEL |
22762306a36Sopenharmony_ci		USBPCR1_WORD_IF_16BIT;
22862306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR1_OFFSET);
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci	reg = USBPCR_COMMONONN | USBPCR_POR |
23162306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXVREFTUNE_MASK, USBPCR_TXVREFTUNE_INC_75PPT);
23262306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
23362306a36Sopenharmony_ci}
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_cistatic void jz4780_usb_phy_init(struct phy *phy)
23662306a36Sopenharmony_ci{
23762306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
23862306a36Sopenharmony_ci	u32 reg;
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_USB_SEL |
24162306a36Sopenharmony_ci		USBPCR1_WORD_IF_16BIT;
24262306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR1_OFFSET);
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	reg = USBPCR_TXPREEMPHTUNE | USBPCR_COMMONONN | USBPCR_POR;
24562306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
24662306a36Sopenharmony_ci}
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_cistatic void x1000_usb_phy_init(struct phy *phy)
24962306a36Sopenharmony_ci{
25062306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
25162306a36Sopenharmony_ci	u32 reg;
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT;
25462306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR1_OFFSET);
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci	reg = USBPCR_TXPREEMPHTUNE | USBPCR_COMMONONN | USBPCR_POR |
25762306a36Sopenharmony_ci		FIELD_PREP(USBPCR_SQRXTUNE_MASK, USBPCR_SQRXTUNE_DCR_20PCT) |
25862306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXHSXVTUNE_MASK, USBPCR_TXHSXVTUNE_DCR_15MV) |
25962306a36Sopenharmony_ci		FIELD_PREP(USBPCR_TXVREFTUNE_MASK, USBPCR_TXVREFTUNE_INC_25PPT);
26062306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
26162306a36Sopenharmony_ci}
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_cistatic void x1830_usb_phy_init(struct phy *phy)
26462306a36Sopenharmony_ci{
26562306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
26662306a36Sopenharmony_ci	u32 reg;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci	/* rdt */
26962306a36Sopenharmony_ci	writel(USBRDT_VBFIL_EN | USBRDT_UTMI_RST, priv->base + REG_USBRDT_OFFSET);
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT |
27262306a36Sopenharmony_ci		USBPCR1_DMPD | USBPCR1_DPPD;
27362306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR1_OFFSET);
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci	reg = USBPCR_VBUSVLDEXT | USBPCR_TXPREEMPHTUNE | USBPCR_COMMONONN | USBPCR_POR |
27662306a36Sopenharmony_ci		FIELD_PREP(USBPCR_IDPULLUP_MASK, USBPCR_IDPULLUP_OTG);
27762306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
27862306a36Sopenharmony_ci}
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_cistatic void x2000_usb_phy_init(struct phy *phy)
28162306a36Sopenharmony_ci{
28262306a36Sopenharmony_ci	struct ingenic_usb_phy *priv = phy_get_drvdata(phy);
28362306a36Sopenharmony_ci	u32 reg;
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci	reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_DPPD | USBPCR1_DMPD;
28662306a36Sopenharmony_ci	writel(reg & ~USBPCR1_PORT_RST, priv->base + REG_USBPCR1_OFFSET);
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci	reg = USBPCR_POR | FIELD_PREP(USBPCR_IDPULLUP_MASK, USBPCR_IDPULLUP_OTG);
28962306a36Sopenharmony_ci	writel(reg, priv->base + REG_USBPCR_OFFSET);
29062306a36Sopenharmony_ci}
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_cistatic const struct ingenic_soc_info jz4770_soc_info = {
29362306a36Sopenharmony_ci	.usb_phy_init = jz4770_usb_phy_init,
29462306a36Sopenharmony_ci};
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_cistatic const struct ingenic_soc_info jz4775_soc_info = {
29762306a36Sopenharmony_ci	.usb_phy_init = jz4775_usb_phy_init,
29862306a36Sopenharmony_ci};
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistatic const struct ingenic_soc_info jz4780_soc_info = {
30162306a36Sopenharmony_ci	.usb_phy_init = jz4780_usb_phy_init,
30262306a36Sopenharmony_ci};
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_cistatic const struct ingenic_soc_info x1000_soc_info = {
30562306a36Sopenharmony_ci	.usb_phy_init = x1000_usb_phy_init,
30662306a36Sopenharmony_ci};
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_cistatic const struct ingenic_soc_info x1830_soc_info = {
30962306a36Sopenharmony_ci	.usb_phy_init = x1830_usb_phy_init,
31062306a36Sopenharmony_ci};
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_cistatic const struct ingenic_soc_info x2000_soc_info = {
31362306a36Sopenharmony_ci	.usb_phy_init = x2000_usb_phy_init,
31462306a36Sopenharmony_ci};
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_cistatic int ingenic_usb_phy_probe(struct platform_device *pdev)
31762306a36Sopenharmony_ci{
31862306a36Sopenharmony_ci	struct ingenic_usb_phy *priv;
31962306a36Sopenharmony_ci	struct phy_provider *provider;
32062306a36Sopenharmony_ci	struct device *dev = &pdev->dev;
32162306a36Sopenharmony_ci	int err;
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
32462306a36Sopenharmony_ci	if (!priv)
32562306a36Sopenharmony_ci		return -ENOMEM;
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	priv->soc_info = device_get_match_data(dev);
32862306a36Sopenharmony_ci	if (!priv->soc_info) {
32962306a36Sopenharmony_ci		dev_err(dev, "Error: No device match found\n");
33062306a36Sopenharmony_ci		return -ENODEV;
33162306a36Sopenharmony_ci	}
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci	priv->base = devm_platform_ioremap_resource(pdev, 0);
33462306a36Sopenharmony_ci	if (IS_ERR(priv->base)) {
33562306a36Sopenharmony_ci		dev_err(dev, "Failed to map registers\n");
33662306a36Sopenharmony_ci		return PTR_ERR(priv->base);
33762306a36Sopenharmony_ci	}
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci	priv->clk = devm_clk_get(dev, NULL);
34062306a36Sopenharmony_ci	if (IS_ERR(priv->clk)) {
34162306a36Sopenharmony_ci		err = PTR_ERR(priv->clk);
34262306a36Sopenharmony_ci		if (err != -EPROBE_DEFER)
34362306a36Sopenharmony_ci			dev_err(dev, "Failed to get clock\n");
34462306a36Sopenharmony_ci		return err;
34562306a36Sopenharmony_ci	}
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci	priv->vcc_supply = devm_regulator_get(dev, "vcc");
34862306a36Sopenharmony_ci	if (IS_ERR(priv->vcc_supply)) {
34962306a36Sopenharmony_ci		err = PTR_ERR(priv->vcc_supply);
35062306a36Sopenharmony_ci		if (err != -EPROBE_DEFER)
35162306a36Sopenharmony_ci			dev_err(dev, "Failed to get regulator\n");
35262306a36Sopenharmony_ci		return err;
35362306a36Sopenharmony_ci	}
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	priv->phy = devm_phy_create(dev, NULL, &ingenic_usb_phy_ops);
35662306a36Sopenharmony_ci	if (IS_ERR(priv->phy))
35762306a36Sopenharmony_ci		return PTR_ERR(priv->phy);
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci	phy_set_drvdata(priv->phy, priv);
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci	provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci	return PTR_ERR_OR_ZERO(provider);
36462306a36Sopenharmony_ci}
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistatic const struct of_device_id ingenic_usb_phy_of_matches[] = {
36762306a36Sopenharmony_ci	{ .compatible = "ingenic,jz4770-phy", .data = &jz4770_soc_info },
36862306a36Sopenharmony_ci	{ .compatible = "ingenic,jz4775-phy", .data = &jz4775_soc_info },
36962306a36Sopenharmony_ci	{ .compatible = "ingenic,jz4780-phy", .data = &jz4780_soc_info },
37062306a36Sopenharmony_ci	{ .compatible = "ingenic,x1000-phy", .data = &x1000_soc_info },
37162306a36Sopenharmony_ci	{ .compatible = "ingenic,x1830-phy", .data = &x1830_soc_info },
37262306a36Sopenharmony_ci	{ .compatible = "ingenic,x2000-phy", .data = &x2000_soc_info },
37362306a36Sopenharmony_ci	{ /* sentinel */ }
37462306a36Sopenharmony_ci};
37562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, ingenic_usb_phy_of_matches);
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_cistatic struct platform_driver ingenic_usb_phy_driver = {
37862306a36Sopenharmony_ci	.probe		= ingenic_usb_phy_probe,
37962306a36Sopenharmony_ci	.driver		= {
38062306a36Sopenharmony_ci		.name	= "ingenic-usb-phy",
38162306a36Sopenharmony_ci		.of_match_table = ingenic_usb_phy_of_matches,
38262306a36Sopenharmony_ci	},
38362306a36Sopenharmony_ci};
38462306a36Sopenharmony_cimodule_platform_driver(ingenic_usb_phy_driver);
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ciMODULE_AUTHOR("周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>");
38762306a36Sopenharmony_ciMODULE_AUTHOR("漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>");
38862306a36Sopenharmony_ciMODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>");
38962306a36Sopenharmony_ciMODULE_DESCRIPTION("Ingenic SoCs USB PHY driver");
39062306a36Sopenharmony_ciMODULE_LICENSE("GPL");
391