mux-internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Based on the linux multiplexer framework
  4. *
  5. * Copyright (C) 2017 Axentia Technologies AB
  6. * Author: Peter Rosin <peda@axentia.se>
  7. *
  8. * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
  9. * Jean-Jacques Hiblot <jjhiblot@ti.com>
  10. */
  11. #ifndef _MUX_INTERNAL_H
  12. #define _MUX_INTERNAL_H
  13. /* See mux.h for background documentation. */
  14. struct ofnode_phandle_args;
  15. /**
  16. * struct mux_chip - Represents a chip holding mux controllers.
  17. * @controllers: Number of mux controllers handled by the chip.
  18. * @mux: Array of mux controllers that are handled.
  19. *
  20. * This a per-device uclass-private data.
  21. */
  22. struct mux_chip {
  23. unsigned int controllers;
  24. struct mux_control *mux;
  25. };
  26. /**
  27. * struct mux_control_ops - Mux controller operations for a mux chip.
  28. * @set: Set the state of the given mux controller.
  29. */
  30. struct mux_control_ops {
  31. /**
  32. * set - Apply a state to a multiplexer control
  33. *
  34. * @mux: A multiplexer control
  35. * @return 0 if OK, or a negative error code.
  36. */
  37. int (*set)(struct mux_control *mux, int state);
  38. /**
  39. * of_xlate - Translate a client's device-tree (OF) multiplexer
  40. * specifier.
  41. *
  42. * If this function pointer is set to NULL, the multiplexer core will
  43. * use a default implementation, which assumes #mux-control-cells = <1>
  44. * and that the DT cell contains a simple integer channel ID.
  45. *
  46. * @dev_mux: The multiplexer device. A single device may handle
  47. * several multiplexer controls.
  48. * @args: The multiplexer specifier values from device tree.
  49. * @muxp: (out) A multiplexer control
  50. * @return 0 if OK, or a negative error code.
  51. */
  52. int (*of_xlate)(struct mux_chip *dev_mux,
  53. struct ofnode_phandle_args *args,
  54. struct mux_control **muxp);
  55. };
  56. /**
  57. * struct mux_control - Represents a mux controller.
  58. * @in_use: Whether the mux controller is in use or not.
  59. * @dev: The client device.
  60. * @cached_state: The current mux controller state, or -1 if none.
  61. * @states: The number of mux controller states.
  62. * @idle_state: The mux controller state to use when inactive, or one
  63. * of MUX_IDLE_AS_IS and MUX_IDLE_DISCONNECT.
  64. * @id: The index of the mux controller within the mux chip
  65. * it is a part of.
  66. *
  67. * Mux drivers may only change @states and @idle_state, and may only do so
  68. * between allocation and registration of the mux controller. Specifically,
  69. * @cached_state is internal to the mux core and should never be written by
  70. * mux drivers.
  71. */
  72. struct mux_control {
  73. bool in_use;
  74. struct udevice *dev;
  75. int cached_state;
  76. unsigned int states;
  77. int idle_state;
  78. int id;
  79. };
  80. /**
  81. * mux_control_get_index() - Get the index of the given mux controller
  82. * @mux: The mux-control to get the index for.
  83. *
  84. * Return: The index of the mux controller within the mux chip the mux
  85. * controller is a part of.
  86. */
  87. static inline unsigned int mux_control_get_index(struct mux_control *mux)
  88. {
  89. return mux->id;
  90. }
  91. /**
  92. * mux_alloc_controllers() - Allocate the given number of mux controllers.
  93. * @dev: The client device.
  94. * controllers: Number of controllers to allocate.
  95. *
  96. * Return: 0 of OK, -errno otherwise.
  97. */
  98. int mux_alloc_controllers(struct udevice *dev, unsigned int controllers);
  99. #endif