cvmx-spi.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. *
  29. * This file contains defines for the SPI interface
  30. */
  31. #ifndef __CVMX_SPI_H__
  32. #define __CVMX_SPI_H__
  33. #include "cvmx-gmxx-defs.h"
  34. /* CSR typedefs have been moved to cvmx-csr-*.h */
  35. typedef enum {
  36. CVMX_SPI_MODE_UNKNOWN = 0,
  37. CVMX_SPI_MODE_TX_HALFPLEX = 1,
  38. CVMX_SPI_MODE_RX_HALFPLEX = 2,
  39. CVMX_SPI_MODE_DUPLEX = 3
  40. } cvmx_spi_mode_t;
  41. /** Callbacks structure to customize SPI4 initialization sequence */
  42. typedef struct {
  43. /** Called to reset SPI4 DLL */
  44. int (*reset_cb) (int interface, cvmx_spi_mode_t mode);
  45. /** Called to setup calendar */
  46. int (*calendar_setup_cb) (int interface, cvmx_spi_mode_t mode,
  47. int num_ports);
  48. /** Called for Tx and Rx clock detection */
  49. int (*clock_detect_cb) (int interface, cvmx_spi_mode_t mode,
  50. int timeout);
  51. /** Called to perform link training */
  52. int (*training_cb) (int interface, cvmx_spi_mode_t mode, int timeout);
  53. /** Called for calendar data synchronization */
  54. int (*calendar_sync_cb) (int interface, cvmx_spi_mode_t mode,
  55. int timeout);
  56. /** Called when interface is up */
  57. int (*interface_up_cb) (int interface, cvmx_spi_mode_t mode);
  58. } cvmx_spi_callbacks_t;
  59. /**
  60. * Return true if the supplied interface is configured for SPI
  61. *
  62. * @interface: Interface to check
  63. * Returns True if interface is SPI
  64. */
  65. static inline int cvmx_spi_is_spi_interface(int interface)
  66. {
  67. uint64_t gmxState = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  68. return (gmxState & 0x2) && (gmxState & 0x1);
  69. }
  70. /**
  71. * Initialize and start the SPI interface.
  72. *
  73. * @interface: The identifier of the packet interface to configure and
  74. * use as a SPI interface.
  75. * @mode: The operating mode for the SPI interface. The interface
  76. * can operate as a full duplex (both Tx and Rx data paths
  77. * active) or as a halfplex (either the Tx data path is
  78. * active or the Rx data path is active, but not both).
  79. * @timeout: Timeout to wait for clock synchronization in seconds
  80. * @num_ports: Number of SPI ports to configure
  81. *
  82. * Returns Zero on success, negative of failure.
  83. */
  84. extern int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode,
  85. int timeout, int num_ports);
  86. /**
  87. * This routine restarts the SPI interface after it has lost synchronization
  88. * with its corespondant system.
  89. *
  90. * @interface: The identifier of the packet interface to configure and
  91. * use as a SPI interface.
  92. * @mode: The operating mode for the SPI interface. The interface
  93. * can operate as a full duplex (both Tx and Rx data paths
  94. * active) or as a halfplex (either the Tx data path is
  95. * active or the Rx data path is active, but not both).
  96. * @timeout: Timeout to wait for clock synchronization in seconds
  97. * Returns Zero on success, negative of failure.
  98. */
  99. extern int cvmx_spi_restart_interface(int interface, cvmx_spi_mode_t mode,
  100. int timeout);
  101. /**
  102. * Return non-zero if the SPI interface has a SPI4000 attached
  103. *
  104. * @interface: SPI interface the SPI4000 is connected to
  105. *
  106. * Returns
  107. */
  108. static inline int cvmx_spi4000_is_present(int interface)
  109. {
  110. return 0;
  111. }
  112. /**
  113. * Initialize the SPI4000 for use
  114. *
  115. * @interface: SPI interface the SPI4000 is connected to
  116. */
  117. static inline int cvmx_spi4000_initialize(int interface)
  118. {
  119. return 0;
  120. }
  121. /**
  122. * Poll all the SPI4000 port and check its speed
  123. *
  124. * @interface: Interface the SPI4000 is on
  125. * @port: Port to poll (0-9)
  126. * Returns Status of the port. 0=down. All other values the port is up.
  127. */
  128. static inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed(
  129. int interface,
  130. int port)
  131. {
  132. union cvmx_gmxx_rxx_rx_inbnd r;
  133. r.u64 = 0;
  134. return r;
  135. }
  136. /**
  137. * Get current SPI4 initialization callbacks
  138. *
  139. * @callbacks: Pointer to the callbacks structure.to fill
  140. *
  141. * Returns Pointer to cvmx_spi_callbacks_t structure.
  142. */
  143. extern void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks);
  144. /**
  145. * Set new SPI4 initialization callbacks
  146. *
  147. * @new_callbacks: Pointer to an updated callbacks structure.
  148. */
  149. extern void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks);
  150. /**
  151. * Callback to perform SPI4 reset
  152. *
  153. * @interface: The identifier of the packet interface to configure and
  154. * use as a SPI interface.
  155. * @mode: The operating mode for the SPI interface. The interface
  156. * can operate as a full duplex (both Tx and Rx data paths
  157. * active) or as a halfplex (either the Tx data path is
  158. * active or the Rx data path is active, but not both).
  159. *
  160. * Returns Zero on success, non-zero error code on failure (will cause
  161. * SPI initialization to abort)
  162. */
  163. extern int cvmx_spi_reset_cb(int interface, cvmx_spi_mode_t mode);
  164. /**
  165. * Callback to setup calendar and miscellaneous settings before clock
  166. * detection
  167. *
  168. * @interface: The identifier of the packet interface to configure and
  169. * use as a SPI interface.
  170. * @mode: The operating mode for the SPI interface. The interface
  171. * can operate as a full duplex (both Tx and Rx data paths
  172. * active) or as a halfplex (either the Tx data path is
  173. * active or the Rx data path is active, but not both).
  174. * @num_ports: Number of ports to configure on SPI
  175. *
  176. * Returns Zero on success, non-zero error code on failure (will cause
  177. * SPI initialization to abort)
  178. */
  179. extern int cvmx_spi_calendar_setup_cb(int interface, cvmx_spi_mode_t mode,
  180. int num_ports);
  181. /**
  182. * Callback to perform clock detection
  183. *
  184. * @interface: The identifier of the packet interface to configure and
  185. * use as a SPI interface.
  186. * @mode: The operating mode for the SPI interface. The interface
  187. * can operate as a full duplex (both Tx and Rx data paths
  188. * active) or as a halfplex (either the Tx data path is
  189. * active or the Rx data path is active, but not both).
  190. * @timeout: Timeout to wait for clock synchronization in seconds
  191. *
  192. * Returns Zero on success, non-zero error code on failure (will cause
  193. * SPI initialization to abort)
  194. */
  195. extern int cvmx_spi_clock_detect_cb(int interface, cvmx_spi_mode_t mode,
  196. int timeout);
  197. /**
  198. * Callback to perform link training
  199. *
  200. * @interface: The identifier of the packet interface to configure and
  201. * use as a SPI interface.
  202. * @mode: The operating mode for the SPI interface. The interface
  203. * can operate as a full duplex (both Tx and Rx data paths
  204. * active) or as a halfplex (either the Tx data path is
  205. * active or the Rx data path is active, but not both).
  206. * @timeout: Timeout to wait for link to be trained (in seconds)
  207. *
  208. * Returns Zero on success, non-zero error code on failure (will cause
  209. * SPI initialization to abort)
  210. */
  211. extern int cvmx_spi_training_cb(int interface, cvmx_spi_mode_t mode,
  212. int timeout);
  213. /**
  214. * Callback to perform calendar data synchronization
  215. *
  216. * @interface: The identifier of the packet interface to configure and
  217. * use as a SPI interface.
  218. * @mode: The operating mode for the SPI interface. The interface
  219. * can operate as a full duplex (both Tx and Rx data paths
  220. * active) or as a halfplex (either the Tx data path is
  221. * active or the Rx data path is active, but not both).
  222. * @timeout: Timeout to wait for calendar data in seconds
  223. *
  224. * Returns Zero on success, non-zero error code on failure (will cause
  225. * SPI initialization to abort)
  226. */
  227. extern int cvmx_spi_calendar_sync_cb(int interface, cvmx_spi_mode_t mode,
  228. int timeout);
  229. /**
  230. * Callback to handle interface up
  231. *
  232. * @interface: The identifier of the packet interface to configure and
  233. * use as a SPI interface.
  234. * @mode: The operating mode for the SPI interface. The interface
  235. * can operate as a full duplex (both Tx and Rx data paths
  236. * active) or as a halfplex (either the Tx data path is
  237. * active or the Rx data path is active, but not both).
  238. *
  239. * Returns Zero on success, non-zero error code on failure (will cause
  240. * SPI initialization to abort)
  241. */
  242. extern int cvmx_spi_interface_up_cb(int interface, cvmx_spi_mode_t mode);
  243. #endif /* __CVMX_SPI_H__ */