usb_host.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2012 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. /*
  15. *
  16. * Implementation of USB gxio calls.
  17. */
  18. #include <linux/io.h>
  19. #include <linux/errno.h>
  20. #include <linux/module.h>
  21. #include <gxio/iorpc_globals.h>
  22. #include <gxio/iorpc_usb_host.h>
  23. #include <gxio/kiorpc.h>
  24. #include <gxio/usb_host.h>
  25. int gxio_usb_host_init(gxio_usb_host_context_t *context, int usb_index,
  26. int is_ehci)
  27. {
  28. char file[32];
  29. int fd;
  30. if (is_ehci)
  31. snprintf(file, sizeof(file), "usb_host/%d/iorpc/ehci",
  32. usb_index);
  33. else
  34. snprintf(file, sizeof(file), "usb_host/%d/iorpc/ohci",
  35. usb_index);
  36. fd = hv_dev_open((HV_VirtAddr) file, 0);
  37. if (fd < 0) {
  38. if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
  39. return fd;
  40. else
  41. return -ENODEV;
  42. }
  43. context->fd = fd;
  44. // Map in the MMIO space.
  45. context->mmio_base =
  46. (void __force *)iorpc_ioremap(fd, 0, HV_USB_HOST_MMIO_SIZE);
  47. if (context->mmio_base == NULL) {
  48. hv_dev_close(context->fd);
  49. return -ENODEV;
  50. }
  51. return 0;
  52. }
  53. EXPORT_SYMBOL_GPL(gxio_usb_host_init);
  54. int gxio_usb_host_destroy(gxio_usb_host_context_t *context)
  55. {
  56. iounmap((void __force __iomem *)(context->mmio_base));
  57. hv_dev_close(context->fd);
  58. context->mmio_base = NULL;
  59. context->fd = -1;
  60. return 0;
  61. }
  62. EXPORT_SYMBOL_GPL(gxio_usb_host_destroy);
  63. void *gxio_usb_host_get_reg_start(gxio_usb_host_context_t *context)
  64. {
  65. return context->mmio_base;
  66. }
  67. EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_start);
  68. size_t gxio_usb_host_get_reg_len(gxio_usb_host_context_t *context)
  69. {
  70. return HV_USB_HOST_MMIO_SIZE;
  71. }
  72. EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_len);