Advertisement
Guest User

Untitled

a guest
May 7th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. From d56302dadc3bb3a991bd8b0bd14013e8195a8aa5 Mon Sep 17 00:00:00 2001
  2. From: Kishon Vijay Abraham I <kishon@ti.com>
  3. Date: Mon, 6 May 2013 18:30:34 +0530
  4. Subject: [PATCH] usb: dwc3: use extcon fwrk to receive connect/disconnect
  5. notification
  6.  
  7. Modified dwc3-omap to receive connect and disconnect notification using
  8. extcon framework. Also did the necessary cleanups required after
  9. adapting to extcon framework.
  10.  
  11. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
  12. ---
  13. drivers/usb/dwc3/dwc3-omap.c | 53 +++++++++++++++++++++++++----------------
  14. include/linux/usb/dwc3-omap.h | 30 -----------------------
  15. 2 files changed, 32 insertions(+), 51 deletions(-)
  16. delete mode 100644 include/linux/usb/dwc3-omap.h
  17.  
  18. diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
  19. index 34638b9..4dd51f3 100644
  20. --- a/drivers/usb/dwc3/dwc3-omap.c
  21. +++ b/drivers/usb/dwc3/dwc3-omap.c
  22. @@ -43,13 +43,14 @@
  23. #include <linux/spinlock.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/platform_data/dwc3-omap.h>
  26. -#include <linux/usb/dwc3-omap.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/ioport.h>
  30. #include <linux/io.h>
  31. #include <linux/of.h>
  32. #include <linux/of_platform.h>
  33. +#include <linux/extcon.h>
  34. +#include <linux/extcon/extcon_palmas.h>
  35.  
  36. #include <linux/usb/otg.h>
  37.  
  38. @@ -124,10 +125,9 @@ struct dwc3_omap {
  39. u32 utmi_otg_status;
  40.  
  41. u32 dma_status:1;
  42. + struct notifier_block nb;
  43. };
  44.  
  45. -static struct dwc3_omap *_omap;
  46. -
  47. static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
  48. {
  49. return readl(base + offset);
  50. @@ -138,16 +138,12 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
  51. writel(value, base + offset);
  52. }
  53.  
  54. -int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
  55. +static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, int state)
  56. {
  57. u32 val;
  58. - struct dwc3_omap *omap = _omap;
  59. -
  60. - if (!omap)
  61. - return -EPROBE_DEFER;
  62.  
  63. - switch (status) {
  64. - case OMAP_DWC3_ID_GROUND:
  65. + switch (state) {
  66. + case PALMAS_USB_STATE_ID:
  67. dev_dbg(omap->dev, "ID GND\n");
  68.  
  69. val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
  70. @@ -159,7 +155,7 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
  71. dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
  72. break;
  73.  
  74. - case OMAP_DWC3_VBUS_VALID:
  75. + case PALMAS_USB_STATE_VBUS:
  76. dev_dbg(omap->dev, "VBUS Connect\n");
  77.  
  78. val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
  79. @@ -171,8 +167,7 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
  80. dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
  81. break;
  82.  
  83. - case OMAP_DWC3_ID_FLOAT:
  84. - case OMAP_DWC3_VBUS_OFF:
  85. + case PALMAS_USB_STATE_DISCONNECT:
  86. dev_dbg(omap->dev, "VBUS Disconnect\n");
  87.  
  88. val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
  89. @@ -187,10 +182,18 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
  90. default:
  91. dev_dbg(omap->dev, "ID float\n");
  92. }
  93. +}
  94.  
  95. - return 0;
  96. +static int dwc3_omap_mailbox_notifier(struct notifier_block *nb,
  97. + unsigned long event, void *ptr)
  98. +{
  99. + struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, nb);
  100. + struct extcon_dev *edev = ptr;
  101. +
  102. + dwc3_omap_set_mailbox(omap, edev->state);
  103. +
  104. + return NOTIFY_DONE;
  105. }
  106. -EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
  107.  
  108. static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
  109. {
  110. @@ -289,6 +292,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
  111. struct dwc3_omap *omap;
  112. struct resource *res;
  113. struct device *dev = &pdev->dev;
  114. + struct extcon_dev *edev;
  115.  
  116. int ret = -ENOMEM;
  117. int irq;
  118. @@ -330,19 +334,21 @@ static int dwc3_omap_probe(struct platform_device *pdev)
  119. return -ENOMEM;
  120. }
  121.  
  122. + edev = extcon_get_extcon_dev("palmas_usb");
  123. + if (!edev) {
  124. + dev_dbg(dev, "couldn't get extcon device\n");
  125. + return -EPROBE_DEFER;
  126. + }
  127. +
  128. spin_lock_init(&omap->lock);
  129.  
  130. omap->dev = dev;
  131. omap->irq = irq;
  132. omap->base = base;
  133. + omap->nb.notifier_call = dwc3_omap_mailbox_notifier;
  134. + extcon_register_notifier(edev, &omap->nb);
  135. dev->dma_mask = &dwc3_omap_dma_mask;
  136.  
  137. - /*
  138. - * REVISIT if we ever have two instances of the wrapper, we will be
  139. - * in big trouble
  140. - */
  141. - _omap = omap;
  142. -
  143. pm_runtime_enable(dev);
  144. ret = pm_runtime_get_sync(dev);
  145. if (ret < 0) {
  146. @@ -387,6 +393,11 @@ static int dwc3_omap_probe(struct platform_device *pdev)
  147. return ret;
  148. }
  149.  
  150. + if (extcon_get_cable_state(edev, "USB") == true)
  151. + dwc3_omap_set_mailbox(omap, PALMAS_USB_STATE_VBUS);
  152. + if (extcon_get_cable_state(edev, "USB-HOST") == true)
  153. + dwc3_omap_set_mailbox(omap, PALMAS_USB_STATE_ID);
  154. +
  155. return 0;
  156. }
  157.  
  158. diff --git a/include/linux/usb/dwc3-omap.h b/include/linux/usb/dwc3-omap.h
  159. deleted file mode 100644
  160. index 5615f4d..0000000
  161. --- a/include/linux/usb/dwc3-omap.h
  162. +++ /dev/null
  163. @@ -1,30 +0,0 @@
  164. -/*
  165. - * Copyright (C) 2013 by Texas Instruments
  166. - *
  167. - * The Inventra Controller Driver for Linux is free software; you
  168. - * can redistribute it and/or modify it under the terms of the GNU
  169. - * General Public License version 2 as published by the Free Software
  170. - * Foundation.
  171. - */
  172. -
  173. -#ifndef __DWC3_OMAP_H__
  174. -#define __DWC3_OMAP_H__
  175. -
  176. -enum omap_dwc3_vbus_id_status {
  177. - OMAP_DWC3_UNKNOWN = 0,
  178. - OMAP_DWC3_ID_GROUND,
  179. - OMAP_DWC3_ID_FLOAT,
  180. - OMAP_DWC3_VBUS_VALID,
  181. - OMAP_DWC3_VBUS_OFF,
  182. -};
  183. -
  184. -#if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE))
  185. -extern int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status);
  186. -#else
  187. -static inline int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
  188. -{
  189. - return -ENODEV;
  190. -}
  191. -#endif
  192. -
  193. -#endif /* __DWC3_OMAP_H__ */
  194. --
  195. 1.7.10.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement