Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/module.h>
  3#include <linux/platform_device.h>
  4#include <linux/dma-mapping.h>
  5#include <linux/usb/otg.h>
  6#include <linux/usb/usb_phy_generic.h>
  7#include <linux/slab.h>
  8#include <linux/clk.h>
  9#include <linux/of.h>
 10#include <linux/of_address.h>
 11#include <linux/usb/of.h>
 12
 13#include "phy-am335x-control.h"
 14#include "phy-generic.h"
 15
 16struct am335x_phy {
 17	struct usb_phy_generic usb_phy_gen;
 18	struct phy_control *phy_ctrl;
 19	int id;
 20	enum usb_dr_mode dr_mode;
 21};
 22
 23static int am335x_init(struct usb_phy *phy)
 24{
 25	struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
 26
 27	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
 28	return 0;
 29}
 30
 31static void am335x_shutdown(struct usb_phy *phy)
 32{
 33	struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
 34
 35	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
 36}
 37
 38static int am335x_phy_probe(struct platform_device *pdev)
 39{
 40	struct am335x_phy *am_phy;
 41	struct device *dev = &pdev->dev;
 42	int ret;
 43
 44	am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
 45	if (!am_phy)
 46		return -ENOMEM;
 47
 48	am_phy->phy_ctrl = am335x_get_phy_control(dev);
 49	if (!am_phy->phy_ctrl)
 50		return -EPROBE_DEFER;
 51
 52	am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
 53	if (am_phy->id < 0) {
 54		dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
 55		return am_phy->id;
 56	}
 57
 58	am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1);
 59
 60	ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen);
 61	if (ret)
 62		return ret;
 63
 
 
 
 64	am_phy->usb_phy_gen.phy.init = am335x_init;
 65	am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
 66
 67	platform_set_drvdata(pdev, am_phy);
 68	device_init_wakeup(dev, true);
 69
 70	/*
 71	 * If we leave PHY wakeup enabled then AM33XX wakes up
 72	 * immediately from DS0. To avoid this we mark dev->power.can_wakeup
 73	 * to false. The same is checked in suspend routine to decide
 74	 * on whether to enable PHY wakeup or not.
 75	 * PHY wakeup works fine in standby mode, there by allowing us to
 76	 * handle remote wakeup, wakeup on disconnect and connect.
 77	 */
 78
 79	device_set_wakeup_enable(dev, false);
 80	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
 81
 82	return usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
 83}
 84
 85static void am335x_phy_remove(struct platform_device *pdev)
 86{
 87	struct am335x_phy *am_phy = platform_get_drvdata(pdev);
 88
 89	usb_remove_phy(&am_phy->usb_phy_gen.phy);
 
 90}
 91
 92#ifdef CONFIG_PM_SLEEP
 93static int am335x_phy_suspend(struct device *dev)
 94{
 95	struct am335x_phy *am_phy = dev_get_drvdata(dev);
 
 96
 97	/*
 98	 * Enable phy wakeup only if dev->power.can_wakeup is true.
 99	 * Make sure to enable wakeup to support remote wakeup	in
100	 * standby mode ( same is not supported in OFF(DS0) mode).
101	 * Enable it by doing
102	 * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup
103	 */
104
105	if (device_may_wakeup(dev))
106		phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
107
108	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
109
110	return 0;
111}
112
113static int am335x_phy_resume(struct device *dev)
114{
115	struct am335x_phy	*am_phy = dev_get_drvdata(dev);
 
116
117	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
118
119	if (device_may_wakeup(dev))
120		phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
121
122	return 0;
123}
124#endif
125
126static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
127
128static const struct of_device_id am335x_phy_ids[] = {
129	{ .compatible = "ti,am335x-usb-phy" },
130	{ }
131};
132MODULE_DEVICE_TABLE(of, am335x_phy_ids);
133
134static struct platform_driver am335x_phy_driver = {
135	.probe          = am335x_phy_probe,
136	.remove_new     = am335x_phy_remove,
137	.driver         = {
138		.name   = "am335x-phy-driver",
139		.pm = &am335x_pm_ops,
140		.of_match_table = am335x_phy_ids,
141	},
142};
143
144module_platform_driver(am335x_phy_driver);
145MODULE_LICENSE("GPL v2");
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/module.h>
  3#include <linux/platform_device.h>
  4#include <linux/dma-mapping.h>
  5#include <linux/usb/otg.h>
  6#include <linux/usb/usb_phy_generic.h>
  7#include <linux/slab.h>
  8#include <linux/clk.h>
  9#include <linux/of.h>
 10#include <linux/of_address.h>
 11#include <linux/usb/of.h>
 12
 13#include "phy-am335x-control.h"
 14#include "phy-generic.h"
 15
 16struct am335x_phy {
 17	struct usb_phy_generic usb_phy_gen;
 18	struct phy_control *phy_ctrl;
 19	int id;
 20	enum usb_dr_mode dr_mode;
 21};
 22
 23static int am335x_init(struct usb_phy *phy)
 24{
 25	struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
 26
 27	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
 28	return 0;
 29}
 30
 31static void am335x_shutdown(struct usb_phy *phy)
 32{
 33	struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
 34
 35	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
 36}
 37
 38static int am335x_phy_probe(struct platform_device *pdev)
 39{
 40	struct am335x_phy *am_phy;
 41	struct device *dev = &pdev->dev;
 42	int ret;
 43
 44	am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
 45	if (!am_phy)
 46		return -ENOMEM;
 47
 48	am_phy->phy_ctrl = am335x_get_phy_control(dev);
 49	if (!am_phy->phy_ctrl)
 50		return -EPROBE_DEFER;
 51
 52	am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
 53	if (am_phy->id < 0) {
 54		dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
 55		return am_phy->id;
 56	}
 57
 58	am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1);
 59
 60	ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL);
 61	if (ret)
 62		return ret;
 63
 64	ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
 65	if (ret)
 66		return ret;
 67	am_phy->usb_phy_gen.phy.init = am335x_init;
 68	am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
 69
 70	platform_set_drvdata(pdev, am_phy);
 71	device_init_wakeup(dev, true);
 72
 73	/*
 74	 * If we leave PHY wakeup enabled then AM33XX wakes up
 75	 * immediately from DS0. To avoid this we mark dev->power.can_wakeup
 76	 * to false. The same is checked in suspend routine to decide
 77	 * on whether to enable PHY wakeup or not.
 78	 * PHY wakeup works fine in standby mode, there by allowing us to
 79	 * handle remote wakeup, wakeup on disconnect and connect.
 80	 */
 81
 82	device_set_wakeup_enable(dev, false);
 83	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
 84
 85	return 0;
 86}
 87
 88static int am335x_phy_remove(struct platform_device *pdev)
 89{
 90	struct am335x_phy *am_phy = platform_get_drvdata(pdev);
 91
 92	usb_remove_phy(&am_phy->usb_phy_gen.phy);
 93	return 0;
 94}
 95
 96#ifdef CONFIG_PM_SLEEP
 97static int am335x_phy_suspend(struct device *dev)
 98{
 99	struct platform_device	*pdev = to_platform_device(dev);
100	struct am335x_phy *am_phy = platform_get_drvdata(pdev);
101
102	/*
103	 * Enable phy wakeup only if dev->power.can_wakeup is true.
104	 * Make sure to enable wakeup to support remote wakeup	in
105	 * standby mode ( same is not supported in OFF(DS0) mode).
106	 * Enable it by doing
107	 * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup
108	 */
109
110	if (device_may_wakeup(dev))
111		phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
112
113	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
114
115	return 0;
116}
117
118static int am335x_phy_resume(struct device *dev)
119{
120	struct platform_device	*pdev = to_platform_device(dev);
121	struct am335x_phy	*am_phy = platform_get_drvdata(pdev);
122
123	phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
124
125	if (device_may_wakeup(dev))
126		phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
127
128	return 0;
129}
130#endif
131
132static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
133
134static const struct of_device_id am335x_phy_ids[] = {
135	{ .compatible = "ti,am335x-usb-phy" },
136	{ }
137};
138MODULE_DEVICE_TABLE(of, am335x_phy_ids);
139
140static struct platform_driver am335x_phy_driver = {
141	.probe          = am335x_phy_probe,
142	.remove         = am335x_phy_remove,
143	.driver         = {
144		.name   = "am335x-phy-driver",
145		.pm = &am335x_pm_ops,
146		.of_match_table = am335x_phy_ids,
147	},
148};
149
150module_platform_driver(am335x_phy_driver);
151MODULE_LICENSE("GPL v2");