Skip to content

Commit 6316272

Browse files
superna9999Lorenzo Pieralisi
authored andcommitted
phy: meson-g12a-usb3-pcie: Add support for PCIe mode
This adds extended PCIe PHY functions for the Amlogic G12A USB3+PCIE Combo PHY to support reset, power_on and power_off for PCIe exclusively. With these callbacks, we can handle all the needed operations of the Amlogic PCIe controller driver. Signed-off-by: Neil Armstrong <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Reviewed-by: Andrew Murray <[email protected]>
1 parent 4ff9f68 commit 6316272

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#define PHY_R5_PHY_CR_ACK BIT(16)
5151
#define PHY_R5_PHY_BS_OUT BIT(17)
5252

53+
#define PCIE_RESET_DELAY 500
54+
5355
struct phy_g12a_usb3_pcie_priv {
5456
struct regmap *regmap;
5557
struct regmap *regmap_cr;
@@ -196,6 +198,10 @@ static int phy_g12a_usb3_init(struct phy *phy)
196198
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
197199
int data, ret;
198200

201+
ret = reset_control_reset(priv->reset);
202+
if (ret)
203+
return ret;
204+
199205
/* Switch PHY to USB3 */
200206
/* TODO figure out how to handle when PCIe was set in the bootloader */
201207
regmap_update_bits(priv->regmap, PHY_R0,
@@ -272,32 +278,75 @@ static int phy_g12a_usb3_init(struct phy *phy)
272278
return 0;
273279
}
274280

275-
static int phy_g12a_usb3_pcie_init(struct phy *phy)
281+
static int phy_g12a_usb3_pcie_power_on(struct phy *phy)
282+
{
283+
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
284+
285+
if (priv->mode == PHY_TYPE_USB3)
286+
return 0;
287+
288+
regmap_update_bits(priv->regmap, PHY_R0,
289+
PHY_R0_PCIE_POWER_STATE,
290+
FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1c));
291+
292+
return 0;
293+
}
294+
295+
static int phy_g12a_usb3_pcie_power_off(struct phy *phy)
296+
{
297+
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
298+
299+
if (priv->mode == PHY_TYPE_USB3)
300+
return 0;
301+
302+
regmap_update_bits(priv->regmap, PHY_R0,
303+
PHY_R0_PCIE_POWER_STATE,
304+
FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1d));
305+
306+
return 0;
307+
}
308+
309+
static int phy_g12a_usb3_pcie_reset(struct phy *phy)
276310
{
277311
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
278312
int ret;
279313

280-
ret = reset_control_reset(priv->reset);
314+
if (priv->mode == PHY_TYPE_USB3)
315+
return 0;
316+
317+
ret = reset_control_assert(priv->reset);
281318
if (ret)
282319
return ret;
283320

321+
udelay(PCIE_RESET_DELAY);
322+
323+
ret = reset_control_deassert(priv->reset);
324+
if (ret)
325+
return ret;
326+
327+
udelay(PCIE_RESET_DELAY);
328+
329+
return 0;
330+
}
331+
332+
static int phy_g12a_usb3_pcie_init(struct phy *phy)
333+
{
334+
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
335+
284336
if (priv->mode == PHY_TYPE_USB3)
285337
return phy_g12a_usb3_init(phy);
286338

287-
/* Power UP PCIE */
288-
/* TODO figure out when the bootloader has set USB3 mode before */
289-
regmap_update_bits(priv->regmap, PHY_R0,
290-
PHY_R0_PCIE_POWER_STATE,
291-
FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1c));
292-
293339
return 0;
294340
}
295341

296342
static int phy_g12a_usb3_pcie_exit(struct phy *phy)
297343
{
298344
struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
299345

300-
return reset_control_reset(priv->reset);
346+
if (priv->mode == PHY_TYPE_USB3)
347+
return reset_control_reset(priv->reset);
348+
349+
return 0;
301350
}
302351

303352
static struct phy *phy_g12a_usb3_pcie_xlate(struct device *dev,
@@ -326,6 +375,9 @@ static struct phy *phy_g12a_usb3_pcie_xlate(struct device *dev,
326375
static const struct phy_ops phy_g12a_usb3_pcie_ops = {
327376
.init = phy_g12a_usb3_pcie_init,
328377
.exit = phy_g12a_usb3_pcie_exit,
378+
.power_on = phy_g12a_usb3_pcie_power_on,
379+
.power_off = phy_g12a_usb3_pcie_power_off,
380+
.reset = phy_g12a_usb3_pcie_reset,
329381
.owner = THIS_MODULE,
330382
};
331383

0 commit comments

Comments
 (0)