rtuTemperatureHumidityDataOperation.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Platform level USB initialization for FS USB OTG controller on omap1 and 24xx
  3. *
  4. * Copyright (C) 2004 Texas Instruments, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/io.h>
  25. #include <asm/irq.h>
  26. #include <mach/mux.h>
  27. #include <mach/usb.h>
  28. #include "common.h"
  29. /* These routines should handle the standard chip-specific modes
  30. * for usb0/1/2 ports, covering basic mux and transceiver setup.
  31. *
  32. * Some board-*.c files will need to set up additional mux options,
  33. * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
  34. */
  35. /* TESTED ON:
  36. * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
  37. * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
  38. * - 5912 OSK UDC, with *nonstandard* A-to-A cable
  39. * - 1510 Innovator UDC with bundled usb0 cable
  40. * - 1510 Innovator OHCI with bundled usb1/usb2 cable
  41. * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
  42. * - 1710 custom development board using alternate pin group
  43. * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
  44. */
  45. #define INT_USB_IRQ_GEN IH2_BASE + 20
  46. #define INT_USB_IRQ_NISO IH2_BASE + 30
  47. #define INT_USB_IRQ_ISO IH2_BASE + 29
  48. #define INT_USB_IRQ_HGEN INT_USB_HHC_1
  49. #define INT_USB_IRQ_OTG IH2_BASE + 8
  50. #ifdef CONFIG_ARCH_OMAP_OTG
  51. void __init
  52. omap_otg_init(struct omap_usb_config *config)
  53. {
  54. u32 syscon;
  55. int alt_pingroup = 0;
  56. /* NOTE: no bus or clock setup (yet?) */
  57. syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
  58. if (!(syscon & OTG_RESET_DONE))
  59. pr_debug("USB resets not complete?\n");
  60. //omap_writew(0, OTG_IRQ_EN);
  61. /* pin muxing and transceiver pinouts */
  62. if (config->pins[0] > 2) /* alt pingroup 2 */
  63. alt_pingroup = 1;
  64. syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
  65. syscon |= config->usb1_init(config->pins[1]);
  66. syscon |= config->usb2_init(config->pins[2], alt_pingroup);
  67. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  68. omap_writel(syscon, OTG_SYSCON_1);
  69. syscon = config->hmc_mode;
  70. syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
  71. #ifdef CONFIG_USB_OTG
  72. if (config->otg)
  73. syscon |= OTG_EN;
  74. #endif
  75. if (cpu_class_is_omap1())
  76. pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
  77. omap_readl(USB_TRANSCEIVER_CTRL));
  78. pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
  79. omap_writel(syscon, OTG_SYSCON_2);
  80. printk("USB: hmc %d", config->hmc_mode);
  81. if (!alt_pingroup)
  82. printk(", usb2 alt %d wires", config->pins[2]);
  83. else if (config->pins[0])
  84. printk(", usb0 %d wires%s", config->pins[0],
  85. is_usb0_device(config) ? " (dev)" : "");
  86. if (config->pins[1])
  87. printk(", usb1 %d wires", config->pins[1]);
  88. if (!alt_pingroup && config->pins[2])
  89. printk(", usb2 %d wires", config->pins[2]);
  90. if (config->otg)
  91. printk(", Mini-AB on usb%d", config->otg - 1);
  92. printk("\n");
  93. if (cpu_class_is_omap1()) {
  94. u16 w;
  95. /* leave USB clocks/controllers off until needed */
  96. w = omap_readw(ULPD_SOFT_REQ);
  97. w &= ~SOFT_USB_CLK_REQ;
  98. omap_writew(w, ULPD_SOFT_REQ);
  99. w = omap_readw(ULPD_CLOCK_CTRL);
  100. w &= ~USB_MCLK_EN;
  101. w |= DIS_USB_PVCI_CLK;
  102. omap_writew(w, ULPD_CLOCK_CTRL);
  103. }
  104. syscon = omap_readl(OTG_SYSCON_1);
  105. syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
  106. #ifdef CONFIG_USB_GADGET_OMAP
  107. if (config->otg || config->register_dev) {
  108. struct platform_device *udc_device = config->udc_device;
  109. int status;
  110. syscon &= ~DEV_IDLE_EN;
  111. udc_device->dev.platform_data = config;
  112. status = platform_device_register(udc_device);
  113. if (status)
  114. pr_debug("can't register UDC device, %d\n", status);
  115. }
  116. #endif
  117. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  118. if (config->otg || config->register_host) {
  119. struct platform_device *ohci_device = config->ohci_device;
  120. int status;
  121. syscon &= ~HST_IDLE_EN;
  122. ohci_device->dev.platform_data = config;
  123. status = platform_device_register(ohci_device);
  124. if (status)
  125. pr_debug("can't register OHCI device, %d\n", status);
  126. }
  127. #endif
  128. #ifdef CONFIG_USB_OTG
  129. if (config->otg) {
  130. struct platform_device *otg_device = config->otg_device;
  131. int status;
  132. syscon &= ~OTG_IDLE_EN;
  133. otg_device->dev.platform_data = config;
  134. status = platform_device_register(otg_device);
  135. if (status)
  136. pr_debug("can't register OTG device, %d\n", status);
  137. }
  138. #endif
  139. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  140. omap_writel(syscon, OTG_SYSCON_1);
  141. }
  142. #else
  143. void omap_otg_init(struct omap_usb_config *config) {}
  144. #endif
  145. #ifdef CONFIG_USB_GADGET_OMAP
  146. static struct resource udc_resources[] = {
  147. /* order is significant! */
  148. { /* registers */
  149. .start = UDC_BASE,
  150. .end = UDC_BASE + 0xff,
  151. .flags = IORESOURCE_MEM,
  152. }, { /* general IRQ */
  153. .start = INT_USB_IRQ_GEN,
  154. .flags = IORESOURCE_IRQ,
  155. }, { /* PIO IRQ */
  156. .start = INT_USB_IRQ_NISO,
  157. .flags = IORESOURCE_IRQ,
  158. }, { /* SOF IRQ */
  159. .start = INT_USB_IRQ_ISO,
  160. .flags = IORESOURCE_IRQ,
  161. },
  162. };
  163. static u64 udc_dmamask = ~(u32)0;
  164. static struct platform_device udc_device = {
  165. .name = "omap_udc",
  166. .id = -1,
  167. .dev = {
  168. .dma_mask = &udc_dmamask,
  169. .coherent_dma_mask = 0xffffffff,
  170. },
  171. .num_resources = ARRAY_SIZE(udc_resources),
  172. .resource = udc_resources,
  173. };
  174. static inline void udc_device_init(struct omap_usb_config *pdata)
  175. {
  176. /* IRQ numbers for omap7xx */
  177. if(cpu_is_omap7xx()) {
  178. udc_resources[1].start = INT_7XX_USB_GENI;
  179. udc_resources[2].start = INT_7XX_USB_NON_ISO;
  180. udc_resources[3].start = INT_7XX_USB_ISO;
  181. }
  182. pdata->udc_device = &udc_device;
  183. }
  184. #else
  185. static inline void udc_device_init(struct omap_usb_config *pdata)
  186. {
  187. }
  188. #endif
  189. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  190. /* The dmamask must be set for OHCI to work */
  191. static u64 ohci_dmamask = ~(u32)0;
  192. static struct resource ohci_resources[] = {
  193. {
  194. .start = OMAP_OHCI_BASE,
  195. .end = OMAP_OHCI_BASE + 0xff,
  196. .flags = IORESOURCE_MEM,
  197. },
  198. {
  199. .start = INT_USB_IRQ_HGEN,
  200. .flags = IORESOURCE_IRQ,
  201. },
  202. };
  203. static struct platform_device ohci_device = {
  204. .name = "ohci",
  205. .id = -1,
  206. .dev = {
  207. .dma_mask = &ohci_dmamask,
  208. .coherent_dma_mask = 0xffffffff,
  209. },
  210. .num_resources = ARRAY_SIZE(ohci_resources),
  211. .resource = ohci_resources,
  212. };
  213. static inline void ohci_device_init(struct omap_usb_config *pdata)
  214. {
  215. if (cpu_is_omap7xx())
  216. ohci_resources[1].start = INT_7XX_USB_HHC_1;
  217. pdata->ohci_device = &ohci_device;
  218. pdata->ocpi_enable = &ocpi_enable;
  219. }
  220. #else
  221. static inline void ohci_device_init(struct omap_usb_config *pdata)
  222. {
  223. }
  224. #endif
  225. #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
  226. static struct resource otg_resources[] = {
  227. /* order is significant! */
  228. {
  229. .start = OTG_BASE,
  230. .end = OTG_BASE + 0xff,
  231. .flags = IORESOURCE_MEM,
  232. }, {
  233. .start = INT_USB_IRQ_OTG,
  234. .flags = IORESOURCE_IRQ,
  235. },
  236. };
  237. static struct platform_device otg_device = {
  238. .name = "omap_otg",
  239. .id = -1,
  240. .num_resources = ARRAY_SIZE(otg_resources),
  241. .resource = otg_resources,
  242. };
  243. static inline void otg_device_init(struct omap_usb_config *pdata)
  244. {
  245. if (cpu_is_omap7xx())
  246. otg_resources[1].start = INT_7XX_USB_OTG;
  247. pdata->otg_device = &otg_device;
  248. }
  249. #else
  250. static inline void otg_device_init(struct omap_usb_config *pdata)
  251. {
  252. }