fusb_generic_hub.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fusb_generic_hub.h
  15. * Date: 2022-02-11 13:33:11
  16. * LastEditTime: 2022-02-18 09:20:23
  17. * Description:  This files is for definition of generic hub function
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. * 1.0 Zhugengyu 2022/2/7 init commit
  23. */
  24. #ifndef DRIVERS_FUSB_GENERIC_HUB_H
  25. #define DRIVERS_FUSB_GENERIC_HUB_H
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. #include "fusb_private.h"
  31. typedef struct
  32. {
  33. /* negative results denote an error */
  34. /* returns 1 if the hub's status changed since the last call (optional) */
  35. FUsbTransCode(*hub_status_changed)(FUsbDev *);
  36. /* returns 1 if the port's status changed since the last call */
  37. FUsbTransCode(*port_status_changed)(FUsbDev *, int port);
  38. /* returns 1 if something is connected to the port */
  39. FUsbTransCode(*port_connected)(FUsbDev *, int port);
  40. /* returns 1 if port is currently resetting */
  41. FUsbTransCode(*port_in_reset)(FUsbDev *, int port);
  42. /* returns 1 if the port is enabled */
  43. FUsbTransCode(*port_enabled)(FUsbDev *, int port);
  44. /* returns speed if port is enabled, negative value if not */
  45. FUsbSpeed(*port_speed)(FUsbDev *, int port);
  46. /* enables (powers up) a port (optional) */
  47. FUsbTransCode(*enable_port)(FUsbDev *, int port);
  48. /* disables (powers down) a port (optional) */
  49. FUsbTransCode(*disable_port)(FUsbDev *, int port);
  50. /* starts a port reset (required if reset_port is set to a generic one from below) */
  51. FUsbTransCode(*start_port_reset)(FUsbDev *, int port);
  52. /* performs a port reset (optional, generic implementations below) */
  53. FUsbTransCode(*reset_port)(FUsbDev *, int port);
  54. } FUsbGenericHubOps;
  55. typedef struct
  56. {
  57. int num_ports;
  58. /* port numbers are always 1 based,
  59. so we waste one int for convenience */
  60. int *ports; /* allocated to sizeof(*ports)*(num_ports+1) */
  61. #define FUSB_NO_DEV_ADDR -1
  62. const FUsbGenericHubOps *ops;
  63. void *data;
  64. } FUsbGenericHub;
  65. void FUsbGenericHubDestory(FUsbDev *);
  66. int FUsbGenericHubWaitForPort(FUsbDev *const dev, const int port,
  67. const int wait_for,
  68. int (*const port_op)(FUsbDev *, int),
  69. int timeout_steps, const int step_us);
  70. int FUsbGenericHubResetPort(FUsbDev *, int port);
  71. int FUsbGenericHubScanPort(FUsbDev *, int port);
  72. /* the provided generic_hub_ops struct has to be static */
  73. int FUsbGenericHubInit(FUsbDev *, int num_ports, const FUsbGenericHubOps *);
  74. #define FUSB_GEN_HUB_GET(FUsbDev) ((FUsbGenericHub *)(FUsbDev)->data)
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif