UDM-spi.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. The U-Boot Driver Model Project
  2. ===============================
  3. SPI analysis
  4. ============
  5. Viktor Krivak <viktor.krivak@gmail.com>
  6. 2012-03-03
  7. I) Overview
  8. -----------
  9. 1) The SPI driver
  10. -----------------
  11. At this moment U-Boot provides standard API that consist of 7 functions:
  12. void spi_init(void);
  13. struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
  14. unsigned int max_hz, unsigned int mode);
  15. void spi_free_slave(struct spi_slave *slave);
  16. int spi_claim_bus(struct spi_slave *slave);
  17. void spi_release_bus(struct spi_slave *slave);
  18. int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
  19. const void *dout, void *din, unsigned long flags);
  20. int spi_cs_is_valid(unsigned int bus, unsigned int cs);
  21. void spi_cs_activate(struct spi_slave *slave);
  22. void spi_cs_deactivate(struct spi_slave *slave);
  23. void spi_set_speed(struct spi_slave *slave, uint hz);
  24. Method spi_init() is usually empty. All necessary configuration are sets by
  25. spi_setup_slave(). But this configuration is usually stored only in memory.
  26. No real hardware sets are made. All hardware settings are provided by method
  27. spi_claim_bus(). This method claims the bus and it can't be claimed again
  28. until it's release. That's mean all calls of method spi_claim_bus() will
  29. fail. But lots of cpu implementation don't meet this behaviour.
  30. Method spi_release_bus() does exact opposite. It release bus directly by
  31. some hardware sets. spi_free_slave() only free memory allocated by
  32. spi_setup_slave(). Method spi_xfer() do actually read and write operation
  33. throw specified bus and cs. Other methods are self explanatory.
  34. 2) Current limitations
  35. ----------------------
  36. Theoretically at this moment api allows use more then one bus per device at
  37. the time. But in real this can be achieved only when all buses have their
  38. own base addresses in memory.
  39. II) Approach
  40. ------------
  41. 1) Claiming bus
  42. ---------------
  43. The current api cannot be used because struct spi_slave have to be in
  44. private data. In that case user are prohibited to use different bus on one
  45. device at same time. But when base memory address for bus are different.
  46. It's possible make more instance of this driver. Otherwise it can't can be
  47. done because of hardware limitation.
  48. 2) API change
  49. -------------
  50. Method spi_init() is moved to probe. Methods spi_setup_slave() and
  51. spi_claim_bus() are joined to one method. This method checks if desired bus
  52. exists and is available then configure necessary hardware and claims bus.
  53. Method spi_release_bus() and spi_free_slave() are also joined to meet this
  54. new approach. Other function remain same. Only struct spi_slave was change
  55. to instance.
  56. struct ops {
  57. int (*spi_request_bus)(struct instance *i, unsigned int bus,
  58. unsigned int cs, unsigned int max_hz,
  59. unsigned int mode);
  60. void (*spi_release_bus)(struct instance *i);
  61. int (*spi_xfer) (struct instance *i, unsigned int bitlen,
  62. const void *dout, void *din, unsigned long flags);
  63. int (*spi_cs_is_valid)(struct instance *i, unsigned int bus,
  64. unsigned int cs);
  65. void (*spi_cs_activate)(struct instance *i);
  66. void (*spi_cs_deactivate)(struct instance *i);
  67. void (*spi_set_speed)(struct instance *i, uint hz);
  68. }
  69. 3) Legacy API
  70. -------------
  71. To easy conversion of the whole driver. Original and new api can exist next
  72. to each other. New API is designed to be only a wrapper that extracts
  73. necessary information from private_data and use old api. When driver can
  74. use more than one bus at the time. New API require multiple instance. One
  75. for each bus. In this case spi_slave have to be copied in each instance.
  76. 4) Conversion TIME-LINE
  77. -----------------------
  78. To prevent build corruption api conversion have to be processed in several
  79. independent steps. In first step all old API methods are renamed. After that
  80. new API and core function are implemented. Next step is conversion of all
  81. board init methods to set platform data. After all these steps it is possible
  82. to start conversion of all remaining calls. This procedure guarantees that
  83. build procedure and binaries are never broken.
  84. III) Analysis of in-tree drivers
  85. --------------------------------
  86. 1) altera_spi.c
  87. ---------------
  88. All methods have designated structure. Simple conversion possible.
  89. 2) andes_spi.c
  90. --------------
  91. All methods have designated structure. Simple conversion possible.
  92. 3) andes_spi.h
  93. --------------
  94. Support file for andes_spi.c. No conversion is needed.
  95. 4) armada100_spi.c
  96. ------------------
  97. All methods have designated structure. Simple conversion possible.
  98. 5) atmel_dataflash_spi.c
  99. ------------------------
  100. Wrong placement. Will be moved to another location.
  101. 6) atmel_spi.c
  102. --------------
  103. Supports more than one bus. Need some minor change.
  104. 7) atmel_spi.h
  105. --------------
  106. Support file for andes_spi.c. No conversion is needed.
  107. 8) bfin_spi.c
  108. -------------
  109. Supports more than one bus. Need some minor change.
  110. 9) cf_spi.c
  111. -----------
  112. Cooperate with some cpu specific methods from other files. Hard conversion.
  113. 10) davinci_spi.c
  114. -----------------
  115. All methods have designated structure. Simple conversion possible.
  116. 11) davinci_spi.h
  117. -----------------
  118. Support file for davinci_spi.h. No conversion is needed.
  119. 12) fsl_espi.c
  120. --------------
  121. All methods have designated structure. Simple conversion possible.
  122. 13) kirkwood_spi.c
  123. ------------------
  124. All methods have designated structure. Simple conversion possible.
  125. 14) mpc8xxx_spi.c
  126. -----------------
  127. All methods have designated structure. Simple conversion possible.
  128. 15) mpc52xx_spi.c
  129. -----------------
  130. All methods have designated structure. Simple conversion possible.
  131. 16) mxc_spi.c
  132. -------------
  133. All methods have designated structure. Simple conversion possible.
  134. 17) mxs_spi.c
  135. -------------
  136. All methods have designated structure. Simple conversion possible.
  137. 18) oc_tiny_spi.c
  138. -----------------
  139. Supports more than one bus. Need some minor change.
  140. 19) omap3_spi.c
  141. ---------------
  142. Supports more than one bus. Need some minor change.
  143. 20) omap3_spi.h
  144. ---------------
  145. Support file for omap3_spi.c. No conversion is needed.
  146. 21) sh_spi.c
  147. ------------
  148. All methods have designated structure. Simple conversion possible.
  149. 22) sh_spi.h
  150. ------------
  151. Support file for sh_spi.h. No conversion is needed.
  152. 23) soft_spi.c
  153. --------------
  154. Use many board specific method linked from other files. Need careful debugging.
  155. 24) tegra2_spi.c
  156. ----------------
  157. Some hardware specific problem when releasing bus.