test.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Test-related constants for sandbox
  4. *
  5. * Copyright (c) 2014 Google, Inc
  6. */
  7. #ifndef __ASM_TEST_H
  8. #define __ASM_TEST_H
  9. /* The sandbox driver always permits an I2C device with this address */
  10. #define SANDBOX_I2C_TEST_ADDR 0x59
  11. #define SANDBOX_PCI_VENDOR_ID 0x1234
  12. #define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678
  13. #define SANDBOX_PCI_PMC_EMUL_ID 0x5677
  14. #define SANDBOX_PCI_P2SB_EMUL_ID 0x5676
  15. #define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM
  16. #define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
  17. #define PCI_CAP_ID_PM_OFFSET 0x50
  18. #define PCI_CAP_ID_EXP_OFFSET 0x60
  19. #define PCI_CAP_ID_MSIX_OFFSET 0x70
  20. #define PCI_CAP_ID_EA_OFFSET 0x80
  21. #define PCI_EXT_CAP_ID_ERR_OFFSET 0x100
  22. #define PCI_EXT_CAP_ID_VC_OFFSET 0x200
  23. #define PCI_EXT_CAP_ID_DSN_OFFSET 0x300
  24. /* Useful for PCI_VDEVICE() macro */
  25. #define PCI_VENDOR_ID_SANDBOX SANDBOX_PCI_VENDOR_ID
  26. #define SWAP_CASE_DRV_DATA 0x55aa
  27. #define SANDBOX_CLK_RATE 32768
  28. /* Macros used to test PCI EA capability structure */
  29. #define PCI_CAP_EA_BASE_LO0 0x00100000
  30. #define PCI_CAP_EA_BASE_LO1 0x00110000
  31. #define PCI_CAP_EA_BASE_LO2 0x00120000
  32. #define PCI_CAP_EA_BASE_LO4 0x00140000
  33. #define PCI_CAP_EA_BASE_HI2 0x00020000ULL
  34. #define PCI_CAP_EA_BASE_HI4 0x00040000ULL
  35. #define PCI_CAP_EA_SIZE_LO 0x0000ffff
  36. #define PCI_CAP_EA_SIZE_HI 0x00000010ULL
  37. #define PCI_EA_BAR2_MAGIC 0x72727272
  38. #define PCI_EA_BAR4_MAGIC 0x74747474
  39. enum {
  40. SANDBOX_IRQN_PEND = 1, /* Interrupt number for 'pending' test */
  41. };
  42. /* System controller driver data */
  43. enum {
  44. SYSCON0 = 32,
  45. SYSCON1,
  46. SYSCON_COUNT
  47. };
  48. /**
  49. */
  50. enum cros_ec_test_t {
  51. CROSECT_BREAK_HELLO = BIT(1),
  52. CROSECT_LID_OPEN = BIT(2),
  53. };
  54. /**
  55. * sandbox_i2c_set_test_mode() - set test mode for running unit tests
  56. *
  57. * See sandbox_i2c_xfer() for the behaviour changes.
  58. *
  59. * @bus: sandbox I2C bus to adjust
  60. * @test_mode: true to select test mode, false to run normally
  61. */
  62. void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode);
  63. enum sandbox_i2c_eeprom_test_mode {
  64. SIE_TEST_MODE_NONE,
  65. /* Permits read/write of only one byte per I2C transaction */
  66. SIE_TEST_MODE_SINGLE_BYTE,
  67. };
  68. void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,
  69. enum sandbox_i2c_eeprom_test_mode mode);
  70. void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len);
  71. void sandbox_i2c_eeprom_set_chip_addr_offset_mask(struct udevice *dev,
  72. uint mask);
  73. uint sanbox_i2c_eeprom_get_prev_addr(struct udevice *dev);
  74. uint sanbox_i2c_eeprom_get_prev_offset(struct udevice *dev);
  75. /**
  76. * sandbox_i2c_rtc_set_offset() - set the time offset from system/base time
  77. *
  78. * @dev: RTC device to adjust
  79. * @use_system_time: true to use system time, false to use @base_time
  80. * @offset: RTC offset from current system/base time (-1 for no
  81. * change)
  82. * @return old value of RTC offset
  83. */
  84. long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time,
  85. int offset);
  86. /**
  87. * sandbox_i2c_rtc_get_set_base_time() - get and set the base time
  88. *
  89. * @dev: RTC device to adjust
  90. * @base_time: New base system time (set to -1 for no change)
  91. * @return old base time
  92. */
  93. long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time);
  94. int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str);
  95. /**
  96. * sandbox_osd_get_mem() - get the internal memory of a sandbox OSD
  97. *
  98. * @dev: OSD device for which to access the internal memory for
  99. * @buf: pointer to buffer to receive the OSD memory data
  100. * @buflen: length of buffer in bytes
  101. */
  102. int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen);
  103. /**
  104. * sandbox_pwm_get_config() - get the PWM config for a channel
  105. *
  106. * @dev: Device to check
  107. * @channel: Channel number to check
  108. * @period_ns: Period of the PWM in nanoseconds
  109. * @duty_ns: Current duty cycle of the PWM in nanoseconds
  110. * @enable: true if the PWM is enabled
  111. * @polarity: true if the PWM polarity is active high
  112. * @return 0 if OK, -ENOSPC if the PWM number is invalid
  113. */
  114. int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
  115. uint *duty_nsp, bool *enablep, bool *polarityp);
  116. /**
  117. * sandbox_sf_set_block_protect() - Set the BP bits of the status register
  118. *
  119. * @dev: Device to update
  120. * @bp_mask: BP bits to set (bits 2:0, so a value of 0 to 7)
  121. */
  122. void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask);
  123. /**
  124. * sandbox_get_codec_params() - Read back codec parameters
  125. *
  126. * This reads back the parameters set by audio_codec_set_params() for the
  127. * sandbox audio driver. Arguments are as for that function.
  128. */
  129. void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
  130. int *mclk_freqp, int *bits_per_samplep,
  131. uint *channelsp);
  132. /**
  133. * sandbox_get_i2s_sum() - Read back the sum of the audio data so far
  134. *
  135. * This data is provided to the sandbox driver by the I2S tx_data() method.
  136. *
  137. * @dev: Device to check
  138. * @return sum of audio data
  139. */
  140. int sandbox_get_i2s_sum(struct udevice *dev);
  141. /**
  142. * sandbox_get_setup_called() - Returns the number of times setup(*) was called
  143. *
  144. * This is used in the sound test
  145. *
  146. * @dev: Device to check
  147. * @return call count for the setup() method
  148. */
  149. int sandbox_get_setup_called(struct udevice *dev);
  150. /**
  151. * sandbox_get_sound_active() - Returns whether sound play is in progress
  152. *
  153. * @return true if active, false if not
  154. */
  155. int sandbox_get_sound_active(struct udevice *dev);
  156. /**
  157. * sandbox_get_sound_sum() - Read back the sum of the sound data so far
  158. *
  159. * This data is provided to the sandbox driver by the sound play() method.
  160. *
  161. * @dev: Device to check
  162. * @return sum of audio data
  163. */
  164. int sandbox_get_sound_sum(struct udevice *dev);
  165. /**
  166. * sandbox_set_allow_beep() - Set whether the 'beep' interface is supported
  167. *
  168. * @dev: Device to update
  169. * @allow: true to allow the start_beep() method, false to disallow it
  170. */
  171. void sandbox_set_allow_beep(struct udevice *dev, bool allow);
  172. /**
  173. * sandbox_get_beep_frequency() - Get the frequency of the current beep
  174. *
  175. * @dev: Device to check
  176. * @return frequency of beep, if there is an active beep, else 0
  177. */
  178. int sandbox_get_beep_frequency(struct udevice *dev);
  179. /**
  180. * sandbox_spi_get_speed() - Get current speed setting of a sandbox spi bus
  181. *
  182. * @dev: Device to check
  183. * @return current bus speed
  184. */
  185. uint sandbox_spi_get_speed(struct udevice *dev);
  186. /**
  187. * sandbox_spi_get_mode() - Get current mode setting of a sandbox spi bus
  188. *
  189. * @dev: Device to check
  190. * @return current mode
  191. */
  192. uint sandbox_spi_get_mode(struct udevice *dev);
  193. /**
  194. * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
  195. *
  196. * @dev: Device to check
  197. * @return 0 if not protected, 1 if protected
  198. */
  199. int sandbox_get_pch_spi_protect(struct udevice *dev);
  200. /**
  201. * sandbox_get_pci_ep_irq_count() - Get the PCI EP IRQ count
  202. *
  203. * @dev: Device to check
  204. * @return irq count
  205. */
  206. int sandbox_get_pci_ep_irq_count(struct udevice *dev);
  207. /**
  208. * sandbox_pci_read_bar() - Read the BAR value for a read_config operation
  209. *
  210. * This is used in PCI emulators to read a base address reset. This has special
  211. * rules because when the register is set to 0xffffffff it can be used to
  212. * discover the type and size of the BAR.
  213. *
  214. * @barval: Current value of the BAR
  215. * @type: Type of BAR (PCI_BASE_ADDRESS_SPACE_IO or
  216. * PCI_BASE_ADDRESS_MEM_TYPE_32)
  217. * @size: Size of BAR in bytes
  218. * @return BAR value to return from emulator
  219. */
  220. uint sandbox_pci_read_bar(u32 barval, int type, uint size);
  221. /**
  222. * sandbox_set_enable_memio() - Enable readl/writel() for sandbox
  223. *
  224. * Normally these I/O functions do nothing with sandbox. Certain tests need them
  225. * to work as for other architectures, so this function can be used to enable
  226. * them.
  227. *
  228. * @enable: true to enable, false to disable
  229. */
  230. void sandbox_set_enable_memio(bool enable);
  231. /**
  232. * sandbox_cros_ec_set_test_flags() - Set behaviour for testing purposes
  233. *
  234. * @dev: Device to check
  235. * @flags: Flags to control behaviour (CROSECT_...)
  236. */
  237. void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags);
  238. /**
  239. * sandbox_cros_ec_get_pwm_duty() - Get EC PWM config for testing purposes
  240. *
  241. * @dev: Device to check
  242. * @index: PWM channel index
  243. * @duty: Current duty cycle in 0..EC_PWM_MAX_DUTY range.
  244. * @return 0 if OK, -ENOSPC if the PWM number is invalid
  245. */
  246. int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty);
  247. #endif