2017-11-03 10:28:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-12-12 17:25:30 +00:00
|
|
|
/*
|
|
|
|
* phy-keystone - USB PHY, talking to dwc3 controller in Keystone.
|
|
|
|
*
|
2020-07-10 19:18:42 +00:00
|
|
|
* Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com
|
2013-12-12 17:25:30 +00:00
|
|
|
*
|
|
|
|
* Author: WingMan Kwok <w-kwok2@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
2014-04-16 20:28:32 +00:00
|
|
|
#include <linux/usb/usb_phy_generic.h>
|
2013-12-12 17:25:30 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
|
|
|
|
#include "phy-generic.h"
|
|
|
|
|
|
|
|
/* USB PHY control register offsets */
|
|
|
|
#define USB_PHY_CTL_UTMI 0x0000
|
|
|
|
#define USB_PHY_CTL_PIPE 0x0004
|
|
|
|
#define USB_PHY_CTL_PARAM_1 0x0008
|
|
|
|
#define USB_PHY_CTL_PARAM_2 0x000c
|
|
|
|
#define USB_PHY_CTL_CLOCK 0x0010
|
|
|
|
#define USB_PHY_CTL_PLL 0x0014
|
|
|
|
|
|
|
|
#define PHY_REF_SSP_EN BIT(29)
|
|
|
|
|
|
|
|
struct keystone_usbphy {
|
2014-04-16 20:20:44 +00:00
|
|
|
struct usb_phy_generic usb_phy_gen;
|
2013-12-12 17:25:30 +00:00
|
|
|
void __iomem *phy_ctrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline u32 keystone_usbphy_readl(void __iomem *base, u32 offset)
|
|
|
|
{
|
|
|
|
return readl(base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void keystone_usbphy_writel(void __iomem *base,
|
|
|
|
u32 offset, u32 value)
|
|
|
|
{
|
|
|
|
writel(value, base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keystone_usbphy_init(struct usb_phy *phy)
|
|
|
|
{
|
|
|
|
struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev);
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK);
|
|
|
|
keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK,
|
|
|
|
val | PHY_REF_SSP_EN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keystone_usbphy_shutdown(struct usb_phy *phy)
|
|
|
|
{
|
|
|
|
struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev);
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK);
|
|
|
|
keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK,
|
|
|
|
val &= ~PHY_REF_SSP_EN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keystone_usbphy_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct keystone_usbphy *k_phy;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL);
|
|
|
|
if (!k_phy)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-09-04 08:45:58 +00:00
|
|
|
k_phy->phy_ctrl = devm_platform_ioremap_resource(pdev, 0);
|
2013-12-12 17:25:30 +00:00
|
|
|
if (IS_ERR(k_phy->phy_ctrl))
|
|
|
|
return PTR_ERR(k_phy->phy_ctrl);
|
|
|
|
|
2019-12-31 17:42:35 +00:00
|
|
|
ret = usb_phy_gen_create_phy(dev, &k_phy->usb_phy_gen);
|
2013-12-12 17:25:30 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
k_phy->usb_phy_gen.phy.init = keystone_usbphy_init;
|
|
|
|
k_phy->usb_phy_gen.phy.shutdown = keystone_usbphy_shutdown;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, k_phy);
|
|
|
|
|
2015-08-04 14:02:03 +00:00
|
|
|
return usb_add_phy_dev(&k_phy->usb_phy_gen.phy);
|
2013-12-12 17:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int keystone_usbphy_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct keystone_usbphy *k_phy = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
usb_remove_phy(&k_phy->usb_phy_gen.phy);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id keystone_usbphy_ids[] = {
|
|
|
|
{ .compatible = "ti,keystone-usbphy" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, keystone_usbphy_ids);
|
|
|
|
|
|
|
|
static struct platform_driver keystone_usbphy_driver = {
|
|
|
|
.probe = keystone_usbphy_probe,
|
|
|
|
.remove = keystone_usbphy_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "keystone-usbphy",
|
2013-12-21 09:50:07 +00:00
|
|
|
.of_match_table = keystone_usbphy_ids,
|
2013-12-12 17:25:30 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(keystone_usbphy_driver);
|
|
|
|
|
|
|
|
MODULE_ALIAS("platform:keystone-usbphy");
|
|
|
|
MODULE_AUTHOR("Texas Instruments Inc.");
|
|
|
|
MODULE_DESCRIPTION("Keystone USB phy driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|