History

usb: ulpi: Add resource-managed variant of otg_ulpi_create()

Now drivers (like NVIDIA Tegra USB PHY for example) will be able to benefit from the resource-managed variant, making driver's code a bit cleaner.

Dmitry Osipenko committed 6 years ago

Commit dea75ee1 parent 9df3adc2 files · +50 −9Browse files

Unified · Split

2 files
  1. drivers/usb/phy/phy-ulpi.c +39 −9
  2. include/linux/usb/ulpi.h +11 −0
drivers/usb/phy/phy-ulpi.c+39−9
@@ -240,6 +240,21 @@ static int ulpi_set_vbus(struct usb_otg *otg, bool on) · 239 unmodified lines
240240 return usb_phy_io_write(phy, flags, ULPI_OTG_CTRL);
241241 }
242242
243+static void otg_ulpi_init(struct usb_phy *phy, struct usb_otg *otg,
244+ struct usb_phy_io_ops *ops,
245+ unsigned int flags)
246+{
247+ phy->label = "ULPI";
248+ phy->flags = flags;
249+ phy->io_ops = ops;
250+ phy->otg = otg;
251+ phy->init = ulpi_init;
252+
253+ otg->usb_phy = phy;
254+ otg->set_host = ulpi_set_host;
255+ otg->set_vbus = ulpi_set_vbus;
256+}
257+
243258 struct usb_phy *
244259 otg_ulpi_create(struct usb_phy_io_ops *ops,
245260 unsigned int flags)
@@ -257,17 +272,32 @@ otg_ulpi_create(struct usb_phy_io_ops *ops, · 11 unmodified lines
257272 return NULL;
258273 }
259274
260− phy->label = "ULPI";
261− phy->flags = flags;
262− phy->io_ops = ops;
263− phy->otg = otg;
264− phy->init = ulpi_init;
265−
266− otg->usb_phy = phy;
267− otg->set_host = ulpi_set_host;
268− otg->set_vbus = ulpi_set_vbus;
275+ otg_ulpi_init(phy, otg, ops, flags);
269276
270277 return phy;
271278 }
272279 EXPORT_SYMBOL_GPL(otg_ulpi_create);
273280
281+struct usb_phy *
282+devm_otg_ulpi_create(struct device *dev,
283+ struct usb_phy_io_ops *ops,
284+ unsigned int flags)
285+{
286+ struct usb_phy *phy;
287+ struct usb_otg *otg;
288+
289+ phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
290+ if (!phy)
291+ return NULL;
292+
293+ otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
294+ if (!otg) {
295+ devm_kfree(dev, phy);
296+ return NULL;
297+ }
298+
299+ otg_ulpi_init(phy, otg, ops, flags);
300+
301+ return phy;
302+}
303+EXPORT_SYMBOL_GPL(devm_otg_ulpi_create);
include/linux/usb/ulpi.h+11−0
@@ -55,12 +55,23 @@ · 54 unmodified lines
5555 #if IS_ENABLED(CONFIG_USB_ULPI)
5656 struct usb_phy *otg_ulpi_create(struct usb_phy_io_ops *ops,
5757 unsigned int flags);
58+
59+struct usb_phy *devm_otg_ulpi_create(struct device *dev,
60+ struct usb_phy_io_ops *ops,
61+ unsigned int flags);
5862 #else
5963 static inline struct usb_phy *otg_ulpi_create(struct usb_phy_io_ops *ops,
6064 unsigned int flags)
6165 {
6266 return NULL;
6367 }
68+
69+static inline struct usb_phy *devm_otg_ulpi_create(struct device *dev,
70+ struct usb_phy_io_ops *ops,
71+ unsigned int flags)
72+{
73+ return NULL;
74+}
6475 #endif
6576
6677 #ifdef CONFIG_USB_ULPI_VIEWPORT