ihs_fpga.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. *
  6. * based on the ioep-fpga driver, which is
  7. *
  8. * (C) Copyright 2014
  9. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  10. */
  11. #include <common.h>
  12. #include <dm.h>
  13. #include <regmap.h>
  14. #include <asm/gpio.h>
  15. #include "ihs_fpga.h"
  16. /**
  17. * struct ihs_fpga_priv - Private data structure for IHS FPGA driver
  18. * @map: Register map for the FPGA's own register space
  19. * @reset_gpio: GPIO to start FPGA reconfiguration
  20. * @done_gpio: GPOI to read the 'ready' status of the FPGA
  21. */
  22. struct ihs_fpga_priv {
  23. struct regmap *map;
  24. struct gpio_desc reset_gpio;
  25. struct gpio_desc done_gpio;
  26. };
  27. /* Test pattern for reflection test */
  28. const u16 REFLECTION_TESTPATTERN = 0xdead;
  29. /* Delay (in ms) for each round in the reflection test */
  30. const uint REFLECTION_TEST_DELAY = 100;
  31. /* Maximum number of rounds in the reflection test */
  32. const uint REFLECTION_TEST_ROUNDS = 5;
  33. /* Delay (in ms) for each round waiting for the FPGA's done GPIO */
  34. const uint FPGA_DONE_WAIT_DELAY = 100;
  35. /* Maximum number of rounds for waiting for the FPGA's done GPIO */
  36. const uint FPGA_DONE_WAIT_ROUND = 5;
  37. /**
  38. * enum pcb_video_type - Video type of the PCB
  39. * @PCB_DVI_SL: Video type is DVI single-link
  40. * @PCB_DP_165MPIX: Video type is DisplayPort (165Mpix)
  41. * @PCB_DP_300MPIX: Video type is DisplayPort (300Mpix)
  42. * @PCB_HDMI: Video type is HDMI
  43. * @PCB_DP_1_2: Video type is DisplayPort 1.2
  44. * @PCB_HDMI_2_0: Video type is HDMI 2.0
  45. */
  46. enum pcb_video_type {
  47. PCB_DVI_SL,
  48. PCB_DP_165MPIX,
  49. PCB_DP_300MPIX,
  50. PCB_HDMI,
  51. PCB_DP_1_2,
  52. PCB_HDMI_2_0,
  53. };
  54. /**
  55. * enum pcb_transmission_type - Transmission type of the PCB
  56. * @PCB_CAT_1G: Transmission type is 1G Ethernet
  57. * @PCB_FIBER_3G: Transmission type is 3G Fiber
  58. * @PCB_CAT_10G: Transmission type is 10G Ethernet
  59. * @PCB_FIBER_10G: Transmission type is 10G Fiber
  60. */
  61. enum pcb_transmission_type {
  62. PCB_CAT_1G,
  63. PCB_FIBER_3G,
  64. PCB_CAT_10G,
  65. PCB_FIBER_10G,
  66. };
  67. /**
  68. * enum carrier_speed - Speed of the FPGA's carrier
  69. * @CARRIER_SPEED_1G: The carrier speed is 1G
  70. * @CARRIER_SPEED_2_5G: The carrier speed is 2.5G
  71. * @CARRIER_SPEED_3G: The carrier speed is 3G
  72. * @CARRIER_SPEED_10G: The carrier speed is 10G
  73. */
  74. enum carrier_speed {
  75. CARRIER_SPEED_1G,
  76. CARRIER_SPEED_3G,
  77. CARRIER_SPEED_2_5G = CARRIER_SPEED_3G,
  78. CARRIER_SPEED_10G,
  79. };
  80. /**
  81. * enum ram_config - FPGA's RAM configuration
  82. * @RAM_DDR2_32BIT_295MBPS: DDR2 32 bit at 295Mb/s
  83. * @RAM_DDR3_32BIT_590MBPS: DDR3 32 bit at 590Mb/s
  84. * @RAM_DDR3_48BIT_590MBPS: DDR3 48 bit at 590Mb/s
  85. * @RAM_DDR3_64BIT_1800MBPS: DDR3 64 bit at 1800Mb/s
  86. * @RAM_DDR3_48BIT_1800MBPS: DDR3 48 bit at 1800Mb/s
  87. */
  88. enum ram_config {
  89. RAM_DDR2_32BIT_295MBPS,
  90. RAM_DDR3_32BIT_590MBPS,
  91. RAM_DDR3_48BIT_590MBPS,
  92. RAM_DDR3_64BIT_1800MBPS,
  93. RAM_DDR3_48BIT_1800MBPS,
  94. };
  95. /**
  96. * enum sysclock - Speed of the FPGA's system clock
  97. * @SYSCLK_147456: System clock is 147.456 MHz
  98. */
  99. enum sysclock {
  100. SYSCLK_147456,
  101. };
  102. /**
  103. * struct fpga_versions - Data read from the versions register
  104. * @video_channel: Is the FPGA for a video channel (true) or main
  105. * channel (false) device?
  106. * @con_side: Is the FPGA for a CON (true) or a CPU (false) device?
  107. * @pcb_video_type: Defines for whch video type the FPGA is configured
  108. * @pcb_transmission_type: Defines for which transmission type the FPGA is
  109. * configured
  110. * @hw_version: Hardware version of the FPGA
  111. */
  112. struct fpga_versions {
  113. bool video_channel;
  114. bool con_side;
  115. enum pcb_video_type pcb_video_type;
  116. enum pcb_transmission_type pcb_transmission_type;
  117. unsigned int hw_version;
  118. };
  119. /**
  120. * struct fpga_features - Data read from the features register
  121. * @video_channels: Number of video channels supported
  122. * @carriers: Number of carrier channels supported
  123. * @carrier_speed: Speed of carriers
  124. * @ram_config: RAM configuration of FPGA
  125. * @sysclock: System clock speed of FPGA
  126. * @pcm_tx: Support for PCM transmission
  127. * @pcm_rx: Support for PCM reception
  128. * @spdif_tx: Support for SPDIF audio transmission
  129. * @spdif_rx: Support for SPDIF audio reception
  130. * @usb2: Support for transparent USB2.0
  131. * @rs232: Support for bidirectional RS232
  132. * @compression_type1: Support for compression type 1
  133. * @compression_type2: Support for compression type 2
  134. * @compression_type3: Support for compression type 3
  135. * @interlace: Support for interlace image formats
  136. * @osd: Support for a OSD
  137. * @compression_pipes: Number of compression pipes supported
  138. */
  139. struct fpga_features {
  140. u8 video_channels;
  141. u8 carriers;
  142. enum carrier_speed carrier_speed;
  143. enum ram_config ram_config;
  144. enum sysclock sysclock;
  145. bool pcm_tx;
  146. bool pcm_rx;
  147. bool spdif_tx;
  148. bool spdif_rx;
  149. bool usb2;
  150. bool rs232;
  151. bool compression_type1;
  152. bool compression_type2;
  153. bool compression_type3;
  154. bool interlace;
  155. bool osd;
  156. bool compression_pipes;
  157. };
  158. #ifdef CONFIG_SYS_FPGA_FLAVOR_GAZERBEAM
  159. /**
  160. * get_versions() - Fill structure with info from version register.
  161. * @dev: FPGA device to be queried for information
  162. * @versions: Pointer to the structure to fill with information from the
  163. * versions register
  164. * Return: 0
  165. */
  166. static int get_versions(struct udevice *dev, struct fpga_versions *versions)
  167. {
  168. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  169. enum {
  170. VERSIONS_FPGA_VIDEO_CHANNEL = BIT(12),
  171. VERSIONS_FPGA_CON_SIDE = BIT(13),
  172. VERSIONS_FPGA_SC = BIT(14),
  173. VERSIONS_PCB_CON = BIT(9),
  174. VERSIONS_PCB_SC = BIT(8),
  175. VERSIONS_PCB_VIDEO_MASK = 0x3 << 6,
  176. VERSIONS_PCB_VIDEO_DP_1_2 = 0x0 << 6,
  177. VERSIONS_PCB_VIDEO_HDMI_2_0 = 0x1 << 6,
  178. VERSIONS_PCB_TRANSMISSION_MASK = 0x3 << 4,
  179. VERSIONS_PCB_TRANSMISSION_FIBER_10G = 0x0 << 4,
  180. VERSIONS_PCB_TRANSMISSION_CAT_10G = 0x1 << 4,
  181. VERSIONS_PCB_TRANSMISSION_FIBER_3G = 0x2 << 4,
  182. VERSIONS_PCB_TRANSMISSION_CAT_1G = 0x3 << 4,
  183. VERSIONS_HW_VER_MASK = 0xf << 0,
  184. };
  185. u16 raw_versions;
  186. memset(versions, 0, sizeof(struct fpga_versions));
  187. ihs_fpga_get(priv->map, versions, &raw_versions);
  188. versions->video_channel = raw_versions & VERSIONS_FPGA_VIDEO_CHANNEL;
  189. versions->con_side = raw_versions & VERSIONS_FPGA_CON_SIDE;
  190. switch (raw_versions & VERSIONS_PCB_VIDEO_MASK) {
  191. case VERSIONS_PCB_VIDEO_DP_1_2:
  192. versions->pcb_video_type = PCB_DP_1_2;
  193. break;
  194. case VERSIONS_PCB_VIDEO_HDMI_2_0:
  195. versions->pcb_video_type = PCB_HDMI_2_0;
  196. break;
  197. }
  198. switch (raw_versions & VERSIONS_PCB_TRANSMISSION_MASK) {
  199. case VERSIONS_PCB_TRANSMISSION_FIBER_10G:
  200. versions->pcb_transmission_type = PCB_FIBER_10G;
  201. break;
  202. case VERSIONS_PCB_TRANSMISSION_CAT_10G:
  203. versions->pcb_transmission_type = PCB_CAT_10G;
  204. break;
  205. case VERSIONS_PCB_TRANSMISSION_FIBER_3G:
  206. versions->pcb_transmission_type = PCB_FIBER_3G;
  207. break;
  208. case VERSIONS_PCB_TRANSMISSION_CAT_1G:
  209. versions->pcb_transmission_type = PCB_CAT_1G;
  210. break;
  211. }
  212. versions->hw_version = raw_versions & VERSIONS_HW_VER_MASK;
  213. return 0;
  214. }
  215. /**
  216. * get_features() - Fill structure with info from features register.
  217. * @dev: FPGA device to be queried for information
  218. * @features: Pointer to the structure to fill with information from the
  219. * features register
  220. * Return: 0
  221. */
  222. static int get_features(struct udevice *dev, struct fpga_features *features)
  223. {
  224. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  225. enum {
  226. FEATURE_SPDIF_RX = BIT(15),
  227. FEATURE_SPDIF_TX = BIT(14),
  228. FEATURE_PCM_RX = BIT(13),
  229. FEATURE_PCM_TX = BIT(12),
  230. FEATURE_RAM_MASK = GENMASK(11, 8),
  231. FEATURE_RAM_DDR2_32BIT_295MBPS = 0x0 << 8,
  232. FEATURE_RAM_DDR3_32BIT_590MBPS = 0x1 << 8,
  233. FEATURE_RAM_DDR3_48BIT_590MBPS = 0x2 << 8,
  234. FEATURE_RAM_DDR3_64BIT_1800MBPS = 0x3 << 8,
  235. FEATURE_RAM_DDR3_48BIT_1800MBPS = 0x4 << 8,
  236. FEATURE_CARRIER_SPEED_MASK = GENMASK(7, 6),
  237. FEATURE_CARRIER_SPEED_1G = 0x0 << 6,
  238. FEATURE_CARRIER_SPEED_2_5G = 0x1 << 6,
  239. FEATURE_CARRIER_SPEED_10G = 0x2 << 6,
  240. FEATURE_CARRIERS_MASK = GENMASK(5, 4),
  241. FEATURE_CARRIERS_0 = 0x0 << 4,
  242. FEATURE_CARRIERS_1 = 0x1 << 4,
  243. FEATURE_CARRIERS_2 = 0x2 << 4,
  244. FEATURE_CARRIERS_4 = 0x3 << 4,
  245. FEATURE_USB2 = BIT(3),
  246. FEATURE_VIDEOCHANNELS_MASK = GENMASK(2, 0),
  247. FEATURE_VIDEOCHANNELS_0 = 0x0 << 0,
  248. FEATURE_VIDEOCHANNELS_1 = 0x1 << 0,
  249. FEATURE_VIDEOCHANNELS_1_1 = 0x2 << 0,
  250. FEATURE_VIDEOCHANNELS_2 = 0x3 << 0,
  251. };
  252. enum {
  253. EXT_FEATURE_OSD = BIT(15),
  254. EXT_FEATURE_ETHERNET = BIT(9),
  255. EXT_FEATURE_INTERLACE = BIT(8),
  256. EXT_FEATURE_RS232 = BIT(7),
  257. EXT_FEATURE_COMPRESSION_PERF_MASK = GENMASK(6, 4),
  258. EXT_FEATURE_COMPRESSION_PERF_1X = 0x0 << 4,
  259. EXT_FEATURE_COMPRESSION_PERF_2X = 0x1 << 4,
  260. EXT_FEATURE_COMPRESSION_PERF_4X = 0x2 << 4,
  261. EXT_FEATURE_COMPRESSION_TYPE1 = BIT(0),
  262. EXT_FEATURE_COMPRESSION_TYPE2 = BIT(1),
  263. EXT_FEATURE_COMPRESSION_TYPE3 = BIT(2),
  264. };
  265. u16 raw_features;
  266. u16 raw_extended_features;
  267. memset(features, 0, sizeof(struct fpga_features));
  268. ihs_fpga_get(priv->map, features, &raw_features);
  269. ihs_fpga_get(priv->map, extended_features, &raw_extended_features);
  270. switch (raw_features & FEATURE_VIDEOCHANNELS_MASK) {
  271. case FEATURE_VIDEOCHANNELS_0:
  272. features->video_channels = 0;
  273. break;
  274. case FEATURE_VIDEOCHANNELS_1:
  275. features->video_channels = 1;
  276. break;
  277. case FEATURE_VIDEOCHANNELS_1_1:
  278. case FEATURE_VIDEOCHANNELS_2:
  279. features->video_channels = 2;
  280. break;
  281. };
  282. switch (raw_features & FEATURE_CARRIERS_MASK) {
  283. case FEATURE_CARRIERS_0:
  284. features->carriers = 0;
  285. break;
  286. case FEATURE_CARRIERS_1:
  287. features->carriers = 1;
  288. break;
  289. case FEATURE_CARRIERS_2:
  290. features->carriers = 2;
  291. break;
  292. case FEATURE_CARRIERS_4:
  293. features->carriers = 4;
  294. break;
  295. }
  296. switch (raw_features & FEATURE_CARRIER_SPEED_MASK) {
  297. case FEATURE_CARRIER_SPEED_1G:
  298. features->carrier_speed = CARRIER_SPEED_1G;
  299. break;
  300. case FEATURE_CARRIER_SPEED_2_5G:
  301. features->carrier_speed = CARRIER_SPEED_2_5G;
  302. break;
  303. case FEATURE_CARRIER_SPEED_10G:
  304. features->carrier_speed = CARRIER_SPEED_10G;
  305. break;
  306. }
  307. switch (raw_features & FEATURE_RAM_MASK) {
  308. case FEATURE_RAM_DDR2_32BIT_295MBPS:
  309. features->ram_config = RAM_DDR2_32BIT_295MBPS;
  310. break;
  311. case FEATURE_RAM_DDR3_32BIT_590MBPS:
  312. features->ram_config = RAM_DDR3_32BIT_590MBPS;
  313. break;
  314. case FEATURE_RAM_DDR3_48BIT_590MBPS:
  315. features->ram_config = RAM_DDR3_48BIT_590MBPS;
  316. break;
  317. case FEATURE_RAM_DDR3_64BIT_1800MBPS:
  318. features->ram_config = RAM_DDR3_64BIT_1800MBPS;
  319. break;
  320. case FEATURE_RAM_DDR3_48BIT_1800MBPS:
  321. features->ram_config = RAM_DDR3_48BIT_1800MBPS;
  322. break;
  323. }
  324. features->pcm_tx = raw_features & FEATURE_PCM_TX;
  325. features->pcm_rx = raw_features & FEATURE_PCM_RX;
  326. features->spdif_tx = raw_features & FEATURE_SPDIF_TX;
  327. features->spdif_rx = raw_features & FEATURE_SPDIF_RX;
  328. features->usb2 = raw_features & FEATURE_USB2;
  329. features->rs232 = raw_extended_features & EXT_FEATURE_RS232;
  330. features->compression_type1 = raw_extended_features &
  331. EXT_FEATURE_COMPRESSION_TYPE1;
  332. features->compression_type2 = raw_extended_features &
  333. EXT_FEATURE_COMPRESSION_TYPE2;
  334. features->compression_type3 = raw_extended_features &
  335. EXT_FEATURE_COMPRESSION_TYPE3;
  336. features->interlace = raw_extended_features & EXT_FEATURE_INTERLACE;
  337. features->osd = raw_extended_features & EXT_FEATURE_OSD;
  338. features->compression_pipes = raw_extended_features &
  339. EXT_FEATURE_COMPRESSION_PERF_MASK;
  340. return 0;
  341. }
  342. #else
  343. /**
  344. * get_versions() - Fill structure with info from version register.
  345. * @fpga: Identifier of the FPGA device to be queried for information
  346. * @versions: Pointer to the structure to fill with information from the
  347. * versions register
  348. *
  349. * This is the legacy version and should be considered deprecated for new
  350. * devices.
  351. *
  352. * Return: 0
  353. */
  354. static int get_versions(unsigned int fpga, struct fpga_versions *versions)
  355. {
  356. enum {
  357. /* HW version encoding is a mess, leave it for the moment */
  358. VERSIONS_HW_VER_MASK = 0xf << 0,
  359. VERSIONS_PIX_CLOCK_GEN_IDT8N3QV01 = BIT(4),
  360. VERSIONS_SFP = BIT(5),
  361. VERSIONS_VIDEO_MASK = 0x7 << 6,
  362. VERSIONS_VIDEO_DVI = 0x0 << 6,
  363. VERSIONS_VIDEO_DP_165 = 0x1 << 6,
  364. VERSIONS_VIDEO_DP_300 = 0x2 << 6,
  365. VERSIONS_VIDEO_HDMI = 0x3 << 6,
  366. VERSIONS_UT_MASK = 0xf << 12,
  367. VERSIONS_UT_MAIN_SERVER = 0x0 << 12,
  368. VERSIONS_UT_MAIN_USER = 0x1 << 12,
  369. VERSIONS_UT_VIDEO_SERVER = 0x2 << 12,
  370. VERSIONS_UT_VIDEO_USER = 0x3 << 12,
  371. };
  372. u16 raw_versions;
  373. memset(versions, 0, sizeof(struct fpga_versions));
  374. FPGA_GET_REG(fpga, versions, &raw_versions);
  375. switch (raw_versions & VERSIONS_UT_MASK) {
  376. case VERSIONS_UT_MAIN_SERVER:
  377. versions->video_channel = false;
  378. versions->con_side = false;
  379. break;
  380. case VERSIONS_UT_MAIN_USER:
  381. versions->video_channel = false;
  382. versions->con_side = true;
  383. break;
  384. case VERSIONS_UT_VIDEO_SERVER:
  385. versions->video_channel = true;
  386. versions->con_side = false;
  387. break;
  388. case VERSIONS_UT_VIDEO_USER:
  389. versions->video_channel = true;
  390. versions->con_side = true;
  391. break;
  392. }
  393. switch (raw_versions & VERSIONS_VIDEO_MASK) {
  394. case VERSIONS_VIDEO_DVI:
  395. versions->pcb_video_type = PCB_DVI_SL;
  396. break;
  397. case VERSIONS_VIDEO_DP_165:
  398. versions->pcb_video_type = PCB_DP_165MPIX;
  399. break;
  400. case VERSIONS_VIDEO_DP_300:
  401. versions->pcb_video_type = PCB_DP_300MPIX;
  402. break;
  403. case VERSIONS_VIDEO_HDMI:
  404. versions->pcb_video_type = PCB_HDMI;
  405. break;
  406. }
  407. versions->hw_version = raw_versions & VERSIONS_HW_VER_MASK;
  408. if (raw_versions & VERSIONS_SFP)
  409. versions->pcb_transmission_type = PCB_FIBER_3G;
  410. else
  411. versions->pcb_transmission_type = PCB_CAT_1G;
  412. return 0;
  413. }
  414. /**
  415. * get_features() - Fill structure with info from features register.
  416. * @fpga: Identifier of the FPGA device to be queried for information
  417. * @features: Pointer to the structure to fill with information from the
  418. * features register
  419. *
  420. * This is the legacy version and should be considered deprecated for new
  421. * devices.
  422. *
  423. * Return: 0
  424. */
  425. static int get_features(unsigned int fpga, struct fpga_features *features)
  426. {
  427. enum {
  428. FEATURE_CARRIER_SPEED_2_5 = BIT(4),
  429. FEATURE_RAM_MASK = 0x7 << 5,
  430. FEATURE_RAM_DDR2_32BIT = 0x0 << 5,
  431. FEATURE_RAM_DDR3_32BIT = 0x1 << 5,
  432. FEATURE_RAM_DDR3_48BIT = 0x2 << 5,
  433. FEATURE_PCM_AUDIO_TX = BIT(9),
  434. FEATURE_PCM_AUDIO_RX = BIT(10),
  435. FEATURE_OSD = BIT(11),
  436. FEATURE_USB20 = BIT(12),
  437. FEATURE_COMPRESSION_MASK = 7 << 13,
  438. FEATURE_COMPRESSION_TYPE1 = 0x1 << 13,
  439. FEATURE_COMPRESSION_TYPE1_TYPE2 = 0x3 << 13,
  440. FEATURE_COMPRESSION_TYPE1_TYPE2_TYPE3 = 0x7 << 13,
  441. };
  442. enum {
  443. EXTENDED_FEATURE_SPDIF_AUDIO_TX = BIT(0),
  444. EXTENDED_FEATURE_SPDIF_AUDIO_RX = BIT(1),
  445. EXTENDED_FEATURE_RS232 = BIT(2),
  446. EXTENDED_FEATURE_COMPRESSION_PIPES = BIT(3),
  447. EXTENDED_FEATURE_INTERLACE = BIT(4),
  448. };
  449. u16 raw_features;
  450. u16 raw_extended_features;
  451. memset(features, 0, sizeof(struct fpga_features));
  452. FPGA_GET_REG(fpga, fpga_features, &raw_features);
  453. FPGA_GET_REG(fpga, fpga_ext_features, &raw_extended_features);
  454. features->video_channels = raw_features & 0x3;
  455. features->carriers = (raw_features >> 2) & 0x3;
  456. features->carrier_speed = (raw_features & FEATURE_CARRIER_SPEED_2_5)
  457. ? CARRIER_SPEED_2_5G : CARRIER_SPEED_1G;
  458. switch (raw_features & FEATURE_RAM_MASK) {
  459. case FEATURE_RAM_DDR2_32BIT:
  460. features->ram_config = RAM_DDR2_32BIT_295MBPS;
  461. break;
  462. case FEATURE_RAM_DDR3_32BIT:
  463. features->ram_config = RAM_DDR3_32BIT_590MBPS;
  464. break;
  465. case FEATURE_RAM_DDR3_48BIT:
  466. features->ram_config = RAM_DDR3_48BIT_590MBPS;
  467. break;
  468. }
  469. features->pcm_tx = raw_features & FEATURE_PCM_AUDIO_TX;
  470. features->pcm_rx = raw_features & FEATURE_PCM_AUDIO_RX;
  471. features->spdif_tx = raw_extended_features &
  472. EXTENDED_FEATURE_SPDIF_AUDIO_TX;
  473. features->spdif_rx = raw_extended_features &
  474. EXTENDED_FEATURE_SPDIF_AUDIO_RX;
  475. features->usb2 = raw_features & FEATURE_USB20;
  476. features->rs232 = raw_extended_features & EXTENDED_FEATURE_RS232;
  477. features->compression_type1 = false;
  478. features->compression_type2 = false;
  479. features->compression_type3 = false;
  480. switch (raw_features & FEATURE_COMPRESSION_MASK) {
  481. case FEATURE_COMPRESSION_TYPE1_TYPE2_TYPE3:
  482. features->compression_type3 = true;
  483. /* fall-through */
  484. case FEATURE_COMPRESSION_TYPE1_TYPE2:
  485. features->compression_type2 = true;
  486. /* fall-through */
  487. case FEATURE_COMPRESSION_TYPE1:
  488. features->compression_type1 = true;
  489. break;
  490. }
  491. features->interlace = raw_extended_features &
  492. EXTENDED_FEATURE_INTERLACE;
  493. features->osd = raw_features & FEATURE_OSD;
  494. features->compression_pipes = raw_extended_features &
  495. EXTENDED_FEATURE_COMPRESSION_PIPES;
  496. return 0;
  497. }
  498. #endif
  499. /**
  500. * fpga_print_info() - Print information about FPGA device
  501. * @dev: FPGA device to print information about
  502. */
  503. static void fpga_print_info(struct udevice *dev)
  504. {
  505. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  506. u16 fpga_version;
  507. struct fpga_versions versions;
  508. struct fpga_features features;
  509. ihs_fpga_get(priv->map, fpga_version, &fpga_version);
  510. get_versions(dev, &versions);
  511. get_features(dev, &features);
  512. if (versions.video_channel)
  513. printf("Videochannel");
  514. else
  515. printf("Mainchannel");
  516. if (versions.con_side)
  517. printf(" User");
  518. else
  519. printf(" Server");
  520. switch (versions.pcb_transmission_type) {
  521. case PCB_CAT_1G:
  522. case PCB_CAT_10G:
  523. printf(" CAT");
  524. break;
  525. case PCB_FIBER_3G:
  526. case PCB_FIBER_10G:
  527. printf(" Fiber");
  528. break;
  529. };
  530. switch (versions.pcb_video_type) {
  531. case PCB_DVI_SL:
  532. printf(" DVI,");
  533. break;
  534. case PCB_DP_165MPIX:
  535. printf(" DP 165MPix/s,");
  536. break;
  537. case PCB_DP_300MPIX:
  538. printf(" DP 300MPix/s,");
  539. break;
  540. case PCB_HDMI:
  541. printf(" HDMI,");
  542. break;
  543. case PCB_DP_1_2:
  544. printf(" DP 1.2,");
  545. break;
  546. case PCB_HDMI_2_0:
  547. printf(" HDMI 2.0,");
  548. break;
  549. }
  550. printf(" FPGA V %d.%02d\n features: ",
  551. fpga_version / 100, fpga_version % 100);
  552. if (!features.compression_type1 &&
  553. !features.compression_type2 &&
  554. !features.compression_type3)
  555. printf("no compression, ");
  556. if (features.compression_type1)
  557. printf("type1, ");
  558. if (features.compression_type2)
  559. printf("type2, ");
  560. if (features.compression_type3)
  561. printf("type3, ");
  562. printf("%sosd", features.osd ? "" : "no ");
  563. if (features.pcm_rx && features.pcm_tx)
  564. printf(", pcm rx+tx");
  565. else if (features.pcm_rx)
  566. printf(", pcm rx");
  567. else if (features.pcm_tx)
  568. printf(", pcm tx");
  569. if (features.spdif_rx && features.spdif_tx)
  570. printf(", spdif rx+tx");
  571. else if (features.spdif_rx)
  572. printf(", spdif rx");
  573. else if (features.spdif_tx)
  574. printf(", spdif tx");
  575. puts(",\n ");
  576. switch (features.sysclock) {
  577. case SYSCLK_147456:
  578. printf("clock 147.456 MHz");
  579. break;
  580. }
  581. switch (features.ram_config) {
  582. case RAM_DDR2_32BIT_295MBPS:
  583. printf(", RAM 32 bit DDR2");
  584. break;
  585. case RAM_DDR3_32BIT_590MBPS:
  586. printf(", RAM 32 bit DDR3");
  587. break;
  588. case RAM_DDR3_48BIT_590MBPS:
  589. case RAM_DDR3_48BIT_1800MBPS:
  590. printf(", RAM 48 bit DDR3");
  591. break;
  592. case RAM_DDR3_64BIT_1800MBPS:
  593. printf(", RAM 64 bit DDR3");
  594. break;
  595. }
  596. printf(", %d carrier(s)", features.carriers);
  597. switch (features.carrier_speed) {
  598. case CARRIER_SPEED_1G:
  599. printf(", 1Gbit/s");
  600. break;
  601. case CARRIER_SPEED_3G:
  602. printf(", 3Gbit/s");
  603. break;
  604. case CARRIER_SPEED_10G:
  605. printf(", 10Gbit/s");
  606. break;
  607. }
  608. printf(", %d video channel(s)\n", features.video_channels);
  609. }
  610. /**
  611. * do_reflection_test() - Run reflection test on a FPGA device
  612. * @dev: FPGA device to run reflection test on
  613. *
  614. * Return: 0 if reflection test succeeded, -ve on error
  615. */
  616. static int do_reflection_test(struct udevice *dev)
  617. {
  618. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  619. int ctr = 0;
  620. while (1) {
  621. u16 val;
  622. ihs_fpga_set(priv->map, reflection_low, REFLECTION_TESTPATTERN);
  623. ihs_fpga_get(priv->map, reflection_low, &val);
  624. if (val == (~REFLECTION_TESTPATTERN & 0xffff))
  625. return -EIO;
  626. mdelay(REFLECTION_TEST_DELAY);
  627. if (ctr++ > REFLECTION_TEST_ROUNDS)
  628. return 0;
  629. }
  630. }
  631. /**
  632. * wait_for_fpga_done() - Wait until 'done'-flag is set for FPGA device
  633. * @dev: FPGA device whose done flag to wait for
  634. *
  635. * This function waits until it detects that the done-GPIO's value was changed
  636. * to 1 by the FPGA, which indicates that the device is configured and ready to
  637. * use.
  638. *
  639. * Return: 0 if done flag was detected, -ve on error
  640. */
  641. static int wait_for_fpga_done(struct udevice *dev)
  642. {
  643. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  644. int ctr = 0;
  645. int done_val;
  646. while (1) {
  647. done_val = dm_gpio_get_value(&priv->done_gpio);
  648. if (done_val < 0) {
  649. debug("%s: Error while reading done-GPIO (err = %d)\n",
  650. dev->name, done_val);
  651. return done_val;
  652. }
  653. if (done_val)
  654. return 0;
  655. mdelay(FPGA_DONE_WAIT_DELAY);
  656. if (ctr++ > FPGA_DONE_WAIT_ROUND) {
  657. debug("%s: FPGA init failed (done not detected)\n",
  658. dev->name);
  659. return -EIO;
  660. }
  661. }
  662. }
  663. static int ihs_fpga_probe(struct udevice *dev)
  664. {
  665. struct ihs_fpga_priv *priv = dev_get_priv(dev);
  666. int ret;
  667. /* TODO(mario.six@gdsys.cc): Case of FPGA attached to MCLink bus */
  668. ret = regmap_init_mem(dev_ofnode(dev), &priv->map);
  669. if (ret) {
  670. debug("%s: Could not initialize regmap (err = %d)",
  671. dev->name, ret);
  672. return ret;
  673. }
  674. ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset_gpio,
  675. GPIOD_IS_OUT);
  676. if (ret) {
  677. debug("%s: Could not get reset-GPIO (err = %d)\n",
  678. dev->name, ret);
  679. return ret;
  680. }
  681. if (!priv->reset_gpio.dev) {
  682. debug("%s: Could not get reset-GPIO\n", dev->name);
  683. return -ENOENT;
  684. }
  685. ret = gpio_request_by_name(dev, "done-gpios", 0, &priv->done_gpio,
  686. GPIOD_IS_IN);
  687. if (ret) {
  688. debug("%s: Could not get done-GPIO (err = %d)\n",
  689. dev->name, ret);
  690. return ret;
  691. }
  692. if (!priv->done_gpio.dev) {
  693. debug("%s: Could not get done-GPIO\n", dev->name);
  694. return -ENOENT;
  695. }
  696. ret = dm_gpio_set_value(&priv->reset_gpio, 1);
  697. if (ret) {
  698. debug("%s: Error while setting reset-GPIO (err = %d)\n",
  699. dev->name, ret);
  700. return ret;
  701. }
  702. /* If FPGA already runs, don't initialize again */
  703. if (do_reflection_test(dev))
  704. goto reflection_ok;
  705. ret = dm_gpio_set_value(&priv->reset_gpio, 0);
  706. if (ret) {
  707. debug("%s: Error while setting reset-GPIO (err = %d)\n",
  708. dev->name, ret);
  709. return ret;
  710. }
  711. ret = wait_for_fpga_done(dev);
  712. if (ret) {
  713. debug("%s: Error while waiting for FPGA done (err = %d)\n",
  714. dev->name, ret);
  715. return ret;
  716. }
  717. udelay(10);
  718. ret = dm_gpio_set_value(&priv->reset_gpio, 1);
  719. if (ret) {
  720. debug("%s: Error while setting reset-GPIO (err = %d)\n",
  721. dev->name, ret);
  722. return ret;
  723. }
  724. if (!do_reflection_test(dev)) {
  725. debug("%s: Reflection test FAILED\n", dev->name);
  726. return -EIO;
  727. }
  728. reflection_ok:
  729. printf("%s: Reflection test passed.\n", dev->name);
  730. fpga_print_info(dev);
  731. return 0;
  732. }
  733. static const struct udevice_id ihs_fpga_ids[] = {
  734. { .compatible = "gdsys,iocon_fpga" },
  735. { .compatible = "gdsys,iocpu_fpga" },
  736. { }
  737. };
  738. U_BOOT_DRIVER(ihs_fpga_bus) = {
  739. .name = "ihs_fpga_bus",
  740. .id = UCLASS_MISC,
  741. .of_match = ihs_fpga_ids,
  742. .probe = ihs_fpga_probe,
  743. .priv_auto_alloc_size = sizeof(struct ihs_fpga_priv),
  744. };