cmd_i2c.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  1. /*
  2. * (C) Copyright 2009
  3. * Sergey Kubushyn, himself, ksi@koi8.net
  4. *
  5. * Changes for unified multibus/multiadapter I2C support.
  6. *
  7. * (C) Copyright 2001
  8. * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. /*
  13. * I2C Functions similar to the standard memory functions.
  14. *
  15. * There are several parameters in many of the commands that bear further
  16. * explanations:
  17. *
  18. * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
  19. * Each I2C chip on the bus has a unique address. On the I2C data bus,
  20. * the address is the upper seven bits and the LSB is the "read/write"
  21. * bit. Note that the {i2c_chip} address specified on the command
  22. * line is not shifted up: e.g. a typical EEPROM memory chip may have
  23. * an I2C address of 0x50, but the data put on the bus will be 0xA0
  24. * for write and 0xA1 for read. This "non shifted" address notation
  25. * matches at least half of the data sheets :-/.
  26. *
  27. * {addr} is the address (or offset) within the chip. Small memory
  28. * chips have 8 bit addresses. Large memory chips have 16 bit
  29. * addresses. Other memory chips have 9, 10, or 11 bit addresses.
  30. * Many non-memory chips have multiple registers and {addr} is used
  31. * as the register index. Some non-memory chips have only one register
  32. * and therefore don't need any {addr} parameter.
  33. *
  34. * The default {addr} parameter is one byte (.1) which works well for
  35. * memories and registers with 8 bits of address space.
  36. *
  37. * You can specify the length of the {addr} field with the optional .0,
  38. * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are
  39. * manipulating a single register device which doesn't use an address
  40. * field, use "0.0" for the address and the ".0" length field will
  41. * suppress the address in the I2C data stream. This also works for
  42. * successive reads using the I2C auto-incrementing memory pointer.
  43. *
  44. * If you are manipulating a large memory with 2-byte addresses, use
  45. * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
  46. *
  47. * Then there are the unfortunate memory chips that spill the most
  48. * significant 1, 2, or 3 bits of address into the chip address byte.
  49. * This effectively makes one chip (logically) look like 2, 4, or
  50. * 8 chips. This is handled (awkwardly) by #defining
  51. * CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
  52. * {addr} field (since .1 is the default, it doesn't actually have to
  53. * be specified). Examples: given a memory chip at I2C chip address
  54. * 0x50, the following would happen...
  55. * i2c md 50 0 10 display 16 bytes starting at 0x000
  56. * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
  57. * i2c md 50 100 10 display 16 bytes starting at 0x100
  58. * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
  59. * i2c md 50 210 10 display 16 bytes starting at 0x210
  60. * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
  61. * This is awfully ugly. It would be nice if someone would think up
  62. * a better way of handling this.
  63. *
  64. * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
  65. */
  66. #include <common.h>
  67. #include <bootretry.h>
  68. #include <cli.h>
  69. #include <command.h>
  70. #include <dm.h>
  71. #include <edid.h>
  72. #include <environment.h>
  73. #include <errno.h>
  74. #include <i2c.h>
  75. #include <malloc.h>
  76. #include <asm/byteorder.h>
  77. #include <linux/compiler.h>
  78. DECLARE_GLOBAL_DATA_PTR;
  79. /* Display values from last command.
  80. * Memory modify remembered values are different from display memory.
  81. */
  82. static uint i2c_dp_last_chip;
  83. static uint i2c_dp_last_addr;
  84. static uint i2c_dp_last_alen;
  85. static uint i2c_dp_last_length = 0x10;
  86. static uint i2c_mm_last_chip;
  87. static uint i2c_mm_last_addr;
  88. static uint i2c_mm_last_alen;
  89. /* If only one I2C bus is present, the list of devices to ignore when
  90. * the probe command is issued is represented by a 1D array of addresses.
  91. * When multiple buses are present, the list is an array of bus-address
  92. * pairs. The following macros take care of this */
  93. #if defined(CONFIG_SYS_I2C_NOPROBES)
  94. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
  95. static struct
  96. {
  97. uchar bus;
  98. uchar addr;
  99. } i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
  100. #define GET_BUS_NUM i2c_get_bus_num()
  101. #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b))
  102. #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a))
  103. #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr
  104. #else /* single bus */
  105. static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
  106. #define GET_BUS_NUM 0
  107. #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
  108. #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
  109. #define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
  110. #endif /* defined(CONFIG_SYS_I2C) */
  111. #endif
  112. #define DISP_LINE_LEN 16
  113. /*
  114. * Default for driver model is to use the chip's existing address length.
  115. * For legacy code, this is not stored, so we need to use a suitable
  116. * default.
  117. */
  118. #ifdef CONFIG_DM_I2C
  119. #define DEFAULT_ADDR_LEN (-1)
  120. #else
  121. #define DEFAULT_ADDR_LEN 1
  122. #endif
  123. #ifdef CONFIG_DM_I2C
  124. static struct udevice *i2c_cur_bus;
  125. static int cmd_i2c_set_bus_num(unsigned int busnum)
  126. {
  127. struct udevice *bus;
  128. int ret;
  129. ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
  130. if (ret) {
  131. debug("%s: No bus %d\n", __func__, busnum);
  132. return ret;
  133. }
  134. i2c_cur_bus = bus;
  135. return 0;
  136. }
  137. static int i2c_get_cur_bus(struct udevice **busp)
  138. {
  139. if (!i2c_cur_bus) {
  140. puts("No I2C bus selected\n");
  141. return -ENODEV;
  142. }
  143. *busp = i2c_cur_bus;
  144. return 0;
  145. }
  146. static int i2c_get_cur_bus_chip(uint chip_addr, struct udevice **devp)
  147. {
  148. struct udevice *bus;
  149. int ret;
  150. ret = i2c_get_cur_bus(&bus);
  151. if (ret)
  152. return ret;
  153. return i2c_get_chip(bus, chip_addr, 1, devp);
  154. }
  155. #endif
  156. /**
  157. * i2c_init_board() - Board-specific I2C bus init
  158. *
  159. * This function is the default no-op implementation of I2C bus
  160. * initialization. This function can be overriden by board-specific
  161. * implementation if needed.
  162. */
  163. __weak
  164. void i2c_init_board(void)
  165. {
  166. }
  167. /* TODO: Implement architecture-specific get/set functions */
  168. /**
  169. * i2c_get_bus_speed() - Return I2C bus speed
  170. *
  171. * This function is the default implementation of function for retrieveing
  172. * the current I2C bus speed in Hz.
  173. *
  174. * A driver implementing runtime switching of I2C bus speed must override
  175. * this function to report the speed correctly. Simple or legacy drivers
  176. * can use this fallback.
  177. *
  178. * Returns I2C bus speed in Hz.
  179. */
  180. #if !defined(CONFIG_SYS_I2C) && !defined(CONFIG_DM_I2C)
  181. /*
  182. * TODO: Implement architecture-specific get/set functions
  183. * Should go away, if we switched completely to new multibus support
  184. */
  185. __weak
  186. unsigned int i2c_get_bus_speed(void)
  187. {
  188. return CONFIG_SYS_I2C_SPEED;
  189. }
  190. /**
  191. * i2c_set_bus_speed() - Configure I2C bus speed
  192. * @speed: Newly set speed of the I2C bus in Hz
  193. *
  194. * This function is the default implementation of function for setting
  195. * the I2C bus speed in Hz.
  196. *
  197. * A driver implementing runtime switching of I2C bus speed must override
  198. * this function to report the speed correctly. Simple or legacy drivers
  199. * can use this fallback.
  200. *
  201. * Returns zero on success, negative value on error.
  202. */
  203. __weak
  204. int i2c_set_bus_speed(unsigned int speed)
  205. {
  206. if (speed != CONFIG_SYS_I2C_SPEED)
  207. return -1;
  208. return 0;
  209. }
  210. #endif
  211. /**
  212. * get_alen() - Small parser helper function to get address length
  213. *
  214. * Returns the address length.
  215. */
  216. static uint get_alen(char *arg, int default_len)
  217. {
  218. int j;
  219. int alen;
  220. alen = default_len;
  221. for (j = 0; j < 8; j++) {
  222. if (arg[j] == '.') {
  223. alen = arg[j+1] - '0';
  224. break;
  225. } else if (arg[j] == '\0')
  226. break;
  227. }
  228. return alen;
  229. }
  230. enum i2c_err_op {
  231. I2C_ERR_READ,
  232. I2C_ERR_WRITE,
  233. };
  234. static int i2c_report_err(int ret, enum i2c_err_op op)
  235. {
  236. printf("Error %s the chip: %d\n",
  237. op == I2C_ERR_READ ? "reading" : "writing", ret);
  238. return CMD_RET_FAILURE;
  239. }
  240. /**
  241. * do_i2c_read() - Handle the "i2c read" command-line command
  242. * @cmdtp: Command data struct pointer
  243. * @flag: Command flag
  244. * @argc: Command-line argument count
  245. * @argv: Array of command-line arguments
  246. *
  247. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  248. * on error.
  249. *
  250. * Syntax:
  251. * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
  252. */
  253. static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  254. {
  255. uint chip;
  256. uint devaddr, length;
  257. int alen;
  258. u_char *memaddr;
  259. int ret;
  260. #ifdef CONFIG_DM_I2C
  261. struct udevice *dev;
  262. #endif
  263. if (argc != 5)
  264. return CMD_RET_USAGE;
  265. /*
  266. * I2C chip address
  267. */
  268. chip = simple_strtoul(argv[1], NULL, 16);
  269. /*
  270. * I2C data address within the chip. This can be 1 or
  271. * 2 bytes long. Some day it might be 3 bytes long :-).
  272. */
  273. devaddr = simple_strtoul(argv[2], NULL, 16);
  274. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  275. if (alen > 3)
  276. return CMD_RET_USAGE;
  277. /*
  278. * Length is the number of objects, not number of bytes.
  279. */
  280. length = simple_strtoul(argv[3], NULL, 16);
  281. /*
  282. * memaddr is the address where to store things in memory
  283. */
  284. memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
  285. #ifdef CONFIG_DM_I2C
  286. ret = i2c_get_cur_bus_chip(chip, &dev);
  287. if (!ret && alen != -1)
  288. ret = i2c_set_chip_offset_len(dev, alen);
  289. if (!ret)
  290. ret = dm_i2c_read(dev, devaddr, memaddr, length);
  291. #else
  292. ret = i2c_read(chip, devaddr, alen, memaddr, length);
  293. #endif
  294. if (ret)
  295. return i2c_report_err(ret, I2C_ERR_READ);
  296. return 0;
  297. }
  298. static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  299. {
  300. uint chip;
  301. uint devaddr, length;
  302. int alen;
  303. u_char *memaddr;
  304. int ret;
  305. #ifdef CONFIG_DM_I2C
  306. struct udevice *dev;
  307. struct dm_i2c_chip *i2c_chip;
  308. #endif
  309. if ((argc < 5) || (argc > 6))
  310. return cmd_usage(cmdtp);
  311. /*
  312. * memaddr is the address where to store things in memory
  313. */
  314. memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
  315. /*
  316. * I2C chip address
  317. */
  318. chip = simple_strtoul(argv[2], NULL, 16);
  319. /*
  320. * I2C data address within the chip. This can be 1 or
  321. * 2 bytes long. Some day it might be 3 bytes long :-).
  322. */
  323. devaddr = simple_strtoul(argv[3], NULL, 16);
  324. alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
  325. if (alen > 3)
  326. return cmd_usage(cmdtp);
  327. /*
  328. * Length is the number of bytes.
  329. */
  330. length = simple_strtoul(argv[4], NULL, 16);
  331. #ifdef CONFIG_DM_I2C
  332. ret = i2c_get_cur_bus_chip(chip, &dev);
  333. if (!ret && alen != -1)
  334. ret = i2c_set_chip_offset_len(dev, alen);
  335. if (ret)
  336. return i2c_report_err(ret, I2C_ERR_WRITE);
  337. i2c_chip = dev_get_parent_platdata(dev);
  338. if (!i2c_chip)
  339. return i2c_report_err(ret, I2C_ERR_WRITE);
  340. #endif
  341. if (argc == 6 && !strcmp(argv[5], "-s")) {
  342. /*
  343. * Write all bytes in a single I2C transaction. If the target
  344. * device is an EEPROM, it is your responsibility to not cross
  345. * a page boundary. No write delay upon completion, take this
  346. * into account if linking commands.
  347. */
  348. #ifdef CONFIG_DM_I2C
  349. i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS;
  350. ret = dm_i2c_write(dev, devaddr, memaddr, length);
  351. #else
  352. ret = i2c_write(chip, devaddr, alen, memaddr, length);
  353. #endif
  354. if (ret)
  355. return i2c_report_err(ret, I2C_ERR_WRITE);
  356. } else {
  357. /*
  358. * Repeated addressing - perform <length> separate
  359. * write transactions of one byte each
  360. */
  361. while (length-- > 0) {
  362. #ifdef CONFIG_DM_I2C
  363. i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS;
  364. ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
  365. #else
  366. ret = i2c_write(chip, devaddr++, alen, memaddr++, 1);
  367. #endif
  368. if (ret)
  369. return i2c_report_err(ret, I2C_ERR_WRITE);
  370. /*
  371. * No write delay with FRAM devices.
  372. */
  373. #if !defined(CONFIG_SYS_I2C_FRAM)
  374. udelay(11000);
  375. #endif
  376. }
  377. }
  378. return 0;
  379. }
  380. #ifdef CONFIG_DM_I2C
  381. static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc,
  382. char *const argv[])
  383. {
  384. struct udevice *dev;
  385. uint flags;
  386. int chip;
  387. int ret;
  388. if (argc < 2)
  389. return CMD_RET_USAGE;
  390. chip = simple_strtoul(argv[1], NULL, 16);
  391. ret = i2c_get_cur_bus_chip(chip, &dev);
  392. if (ret)
  393. return i2c_report_err(ret, I2C_ERR_READ);
  394. if (argc > 2) {
  395. flags = simple_strtoul(argv[2], NULL, 16);
  396. ret = i2c_set_chip_flags(dev, flags);
  397. } else {
  398. ret = i2c_get_chip_flags(dev, &flags);
  399. if (!ret)
  400. printf("%x\n", flags);
  401. }
  402. if (ret)
  403. return i2c_report_err(ret, I2C_ERR_READ);
  404. return 0;
  405. }
  406. #endif
  407. /**
  408. * do_i2c_md() - Handle the "i2c md" command-line command
  409. * @cmdtp: Command data struct pointer
  410. * @flag: Command flag
  411. * @argc: Command-line argument count
  412. * @argv: Array of command-line arguments
  413. *
  414. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  415. * on error.
  416. *
  417. * Syntax:
  418. * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
  419. */
  420. static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  421. {
  422. uint chip;
  423. uint addr, length;
  424. int alen;
  425. int j, nbytes, linebytes;
  426. int ret;
  427. #ifdef CONFIG_DM_I2C
  428. struct udevice *dev;
  429. #endif
  430. /* We use the last specified parameters, unless new ones are
  431. * entered.
  432. */
  433. chip = i2c_dp_last_chip;
  434. addr = i2c_dp_last_addr;
  435. alen = i2c_dp_last_alen;
  436. length = i2c_dp_last_length;
  437. if (argc < 3)
  438. return CMD_RET_USAGE;
  439. if ((flag & CMD_FLAG_REPEAT) == 0) {
  440. /*
  441. * New command specified.
  442. */
  443. /*
  444. * I2C chip address
  445. */
  446. chip = simple_strtoul(argv[1], NULL, 16);
  447. /*
  448. * I2C data address within the chip. This can be 1 or
  449. * 2 bytes long. Some day it might be 3 bytes long :-).
  450. */
  451. addr = simple_strtoul(argv[2], NULL, 16);
  452. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  453. if (alen > 3)
  454. return CMD_RET_USAGE;
  455. /*
  456. * If another parameter, it is the length to display.
  457. * Length is the number of objects, not number of bytes.
  458. */
  459. if (argc > 3)
  460. length = simple_strtoul(argv[3], NULL, 16);
  461. }
  462. #ifdef CONFIG_DM_I2C
  463. ret = i2c_get_cur_bus_chip(chip, &dev);
  464. if (!ret && alen != -1)
  465. ret = i2c_set_chip_offset_len(dev, alen);
  466. if (ret)
  467. return i2c_report_err(ret, I2C_ERR_READ);
  468. #endif
  469. /*
  470. * Print the lines.
  471. *
  472. * We buffer all read data, so we can make sure data is read only
  473. * once.
  474. */
  475. nbytes = length;
  476. do {
  477. unsigned char linebuf[DISP_LINE_LEN];
  478. unsigned char *cp;
  479. linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
  480. #ifdef CONFIG_DM_I2C
  481. ret = dm_i2c_read(dev, addr, linebuf, linebytes);
  482. #else
  483. ret = i2c_read(chip, addr, alen, linebuf, linebytes);
  484. #endif
  485. if (ret)
  486. return i2c_report_err(ret, I2C_ERR_READ);
  487. else {
  488. printf("%04x:", addr);
  489. cp = linebuf;
  490. for (j=0; j<linebytes; j++) {
  491. printf(" %02x", *cp++);
  492. addr++;
  493. }
  494. puts (" ");
  495. cp = linebuf;
  496. for (j=0; j<linebytes; j++) {
  497. if ((*cp < 0x20) || (*cp > 0x7e))
  498. puts (".");
  499. else
  500. printf("%c", *cp);
  501. cp++;
  502. }
  503. putc ('\n');
  504. }
  505. nbytes -= linebytes;
  506. } while (nbytes > 0);
  507. i2c_dp_last_chip = chip;
  508. i2c_dp_last_addr = addr;
  509. i2c_dp_last_alen = alen;
  510. i2c_dp_last_length = length;
  511. return 0;
  512. }
  513. /**
  514. * do_i2c_mw() - Handle the "i2c mw" command-line command
  515. * @cmdtp: Command data struct pointer
  516. * @flag: Command flag
  517. * @argc: Command-line argument count
  518. * @argv: Array of command-line arguments
  519. *
  520. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  521. * on error.
  522. *
  523. * Syntax:
  524. * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
  525. */
  526. static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  527. {
  528. uint chip;
  529. ulong addr;
  530. int alen;
  531. uchar byte;
  532. int count;
  533. int ret;
  534. #ifdef CONFIG_DM_I2C
  535. struct udevice *dev;
  536. #endif
  537. if ((argc < 4) || (argc > 5))
  538. return CMD_RET_USAGE;
  539. /*
  540. * Chip is always specified.
  541. */
  542. chip = simple_strtoul(argv[1], NULL, 16);
  543. /*
  544. * Address is always specified.
  545. */
  546. addr = simple_strtoul(argv[2], NULL, 16);
  547. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  548. if (alen > 3)
  549. return CMD_RET_USAGE;
  550. #ifdef CONFIG_DM_I2C
  551. ret = i2c_get_cur_bus_chip(chip, &dev);
  552. if (!ret && alen != -1)
  553. ret = i2c_set_chip_offset_len(dev, alen);
  554. if (ret)
  555. return i2c_report_err(ret, I2C_ERR_WRITE);
  556. #endif
  557. /*
  558. * Value to write is always specified.
  559. */
  560. byte = simple_strtoul(argv[3], NULL, 16);
  561. /*
  562. * Optional count
  563. */
  564. if (argc == 5)
  565. count = simple_strtoul(argv[4], NULL, 16);
  566. else
  567. count = 1;
  568. while (count-- > 0) {
  569. #ifdef CONFIG_DM_I2C
  570. ret = dm_i2c_write(dev, addr++, &byte, 1);
  571. #else
  572. ret = i2c_write(chip, addr++, alen, &byte, 1);
  573. #endif
  574. if (ret)
  575. return i2c_report_err(ret, I2C_ERR_WRITE);
  576. /*
  577. * Wait for the write to complete. The write can take
  578. * up to 10mSec (we allow a little more time).
  579. */
  580. /*
  581. * No write delay with FRAM devices.
  582. */
  583. #if !defined(CONFIG_SYS_I2C_FRAM)
  584. udelay(11000);
  585. #endif
  586. }
  587. return 0;
  588. }
  589. /**
  590. * do_i2c_crc() - Handle the "i2c crc32" command-line command
  591. * @cmdtp: Command data struct pointer
  592. * @flag: Command flag
  593. * @argc: Command-line argument count
  594. * @argv: Array of command-line arguments
  595. *
  596. * Calculate a CRC on memory
  597. *
  598. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  599. * on error.
  600. *
  601. * Syntax:
  602. * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
  603. */
  604. static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  605. {
  606. uint chip;
  607. ulong addr;
  608. int alen;
  609. int count;
  610. uchar byte;
  611. ulong crc;
  612. ulong err;
  613. int ret = 0;
  614. #ifdef CONFIG_DM_I2C
  615. struct udevice *dev;
  616. #endif
  617. if (argc < 4)
  618. return CMD_RET_USAGE;
  619. /*
  620. * Chip is always specified.
  621. */
  622. chip = simple_strtoul(argv[1], NULL, 16);
  623. /*
  624. * Address is always specified.
  625. */
  626. addr = simple_strtoul(argv[2], NULL, 16);
  627. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  628. if (alen > 3)
  629. return CMD_RET_USAGE;
  630. #ifdef CONFIG_DM_I2C
  631. ret = i2c_get_cur_bus_chip(chip, &dev);
  632. if (!ret && alen != -1)
  633. ret = i2c_set_chip_offset_len(dev, alen);
  634. if (ret)
  635. return i2c_report_err(ret, I2C_ERR_READ);
  636. #endif
  637. /*
  638. * Count is always specified
  639. */
  640. count = simple_strtoul(argv[3], NULL, 16);
  641. printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
  642. /*
  643. * CRC a byte at a time. This is going to be slooow, but hey, the
  644. * memories are small and slow too so hopefully nobody notices.
  645. */
  646. crc = 0;
  647. err = 0;
  648. while (count-- > 0) {
  649. #ifdef CONFIG_DM_I2C
  650. ret = dm_i2c_read(dev, addr, &byte, 1);
  651. #else
  652. ret = i2c_read(chip, addr, alen, &byte, 1);
  653. #endif
  654. if (ret)
  655. err++;
  656. crc = crc32 (crc, &byte, 1);
  657. addr++;
  658. }
  659. if (err > 0)
  660. i2c_report_err(ret, I2C_ERR_READ);
  661. else
  662. printf ("%08lx\n", crc);
  663. return 0;
  664. }
  665. /**
  666. * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
  667. * @cmdtp: Command data struct pointer
  668. * @flag: Command flag
  669. * @argc: Command-line argument count
  670. * @argv: Array of command-line arguments
  671. *
  672. * Modify memory.
  673. *
  674. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  675. * on error.
  676. *
  677. * Syntax:
  678. * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  679. * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  680. */
  681. static int
  682. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
  683. {
  684. uint chip;
  685. ulong addr;
  686. int alen;
  687. ulong data;
  688. int size = 1;
  689. int nbytes;
  690. int ret;
  691. #ifdef CONFIG_DM_I2C
  692. struct udevice *dev;
  693. #endif
  694. if (argc != 3)
  695. return CMD_RET_USAGE;
  696. bootretry_reset_cmd_timeout(); /* got a good command to get here */
  697. /*
  698. * We use the last specified parameters, unless new ones are
  699. * entered.
  700. */
  701. chip = i2c_mm_last_chip;
  702. addr = i2c_mm_last_addr;
  703. alen = i2c_mm_last_alen;
  704. if ((flag & CMD_FLAG_REPEAT) == 0) {
  705. /*
  706. * New command specified. Check for a size specification.
  707. * Defaults to byte if no or incorrect specification.
  708. */
  709. size = cmd_get_data_size(argv[0], 1);
  710. /*
  711. * Chip is always specified.
  712. */
  713. chip = simple_strtoul(argv[1], NULL, 16);
  714. /*
  715. * Address is always specified.
  716. */
  717. addr = simple_strtoul(argv[2], NULL, 16);
  718. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  719. if (alen > 3)
  720. return CMD_RET_USAGE;
  721. }
  722. #ifdef CONFIG_DM_I2C
  723. ret = i2c_get_cur_bus_chip(chip, &dev);
  724. if (!ret && alen != -1)
  725. ret = i2c_set_chip_offset_len(dev, alen);
  726. if (ret)
  727. return i2c_report_err(ret, I2C_ERR_WRITE);
  728. #endif
  729. /*
  730. * Print the address, followed by value. Then accept input for
  731. * the next value. A non-converted value exits.
  732. */
  733. do {
  734. printf("%08lx:", addr);
  735. #ifdef CONFIG_DM_I2C
  736. ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
  737. #else
  738. ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
  739. #endif
  740. if (ret)
  741. return i2c_report_err(ret, I2C_ERR_READ);
  742. data = cpu_to_be32(data);
  743. if (size == 1)
  744. printf(" %02lx", (data >> 24) & 0x000000FF);
  745. else if (size == 2)
  746. printf(" %04lx", (data >> 16) & 0x0000FFFF);
  747. else
  748. printf(" %08lx", data);
  749. nbytes = cli_readline(" ? ");
  750. if (nbytes == 0) {
  751. /*
  752. * <CR> pressed as only input, don't modify current
  753. * location and move to next.
  754. */
  755. if (incrflag)
  756. addr += size;
  757. nbytes = size;
  758. /* good enough to not time out */
  759. bootretry_reset_cmd_timeout();
  760. }
  761. #ifdef CONFIG_BOOT_RETRY_TIME
  762. else if (nbytes == -2)
  763. break; /* timed out, exit the command */
  764. #endif
  765. else {
  766. char *endp;
  767. data = simple_strtoul(console_buffer, &endp, 16);
  768. if (size == 1)
  769. data = data << 24;
  770. else if (size == 2)
  771. data = data << 16;
  772. data = be32_to_cpu(data);
  773. nbytes = endp - console_buffer;
  774. if (nbytes) {
  775. /*
  776. * good enough to not time out
  777. */
  778. bootretry_reset_cmd_timeout();
  779. #ifdef CONFIG_DM_I2C
  780. ret = dm_i2c_write(dev, addr, (uchar *)&data,
  781. size);
  782. #else
  783. ret = i2c_write(chip, addr, alen,
  784. (uchar *)&data, size);
  785. #endif
  786. if (ret)
  787. return i2c_report_err(ret,
  788. I2C_ERR_WRITE);
  789. #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
  790. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  791. #endif
  792. if (incrflag)
  793. addr += size;
  794. }
  795. }
  796. } while (nbytes);
  797. i2c_mm_last_chip = chip;
  798. i2c_mm_last_addr = addr;
  799. i2c_mm_last_alen = alen;
  800. return 0;
  801. }
  802. /**
  803. * do_i2c_probe() - Handle the "i2c probe" command-line command
  804. * @cmdtp: Command data struct pointer
  805. * @flag: Command flag
  806. * @argc: Command-line argument count
  807. * @argv: Array of command-line arguments
  808. *
  809. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  810. * on error.
  811. *
  812. * Syntax:
  813. * i2c probe {addr}
  814. *
  815. * Returns zero (success) if one or more I2C devices was found
  816. */
  817. static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  818. {
  819. int j;
  820. int addr = -1;
  821. int found = 0;
  822. #if defined(CONFIG_SYS_I2C_NOPROBES)
  823. int k, skip;
  824. unsigned int bus = GET_BUS_NUM;
  825. #endif /* NOPROBES */
  826. int ret;
  827. #ifdef CONFIG_DM_I2C
  828. struct udevice *bus, *dev;
  829. if (i2c_get_cur_bus(&bus))
  830. return CMD_RET_FAILURE;
  831. #endif
  832. if (argc == 2)
  833. addr = simple_strtol(argv[1], 0, 16);
  834. puts ("Valid chip addresses:");
  835. for (j = 0; j < 128; j++) {
  836. if ((0 <= addr) && (j != addr))
  837. continue;
  838. #if defined(CONFIG_SYS_I2C_NOPROBES)
  839. skip = 0;
  840. for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
  841. if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
  842. skip = 1;
  843. break;
  844. }
  845. }
  846. if (skip)
  847. continue;
  848. #endif
  849. #ifdef CONFIG_DM_I2C
  850. ret = dm_i2c_probe(bus, j, 0, &dev);
  851. #else
  852. ret = i2c_probe(j);
  853. #endif
  854. if (ret == 0) {
  855. printf(" %02X", j);
  856. found++;
  857. }
  858. }
  859. putc ('\n');
  860. #if defined(CONFIG_SYS_I2C_NOPROBES)
  861. puts ("Excluded chip addresses:");
  862. for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
  863. if (COMPARE_BUS(bus,k))
  864. printf(" %02X", NO_PROBE_ADDR(k));
  865. }
  866. putc ('\n');
  867. #endif
  868. return (0 == found);
  869. }
  870. /**
  871. * do_i2c_loop() - Handle the "i2c loop" command-line command
  872. * @cmdtp: Command data struct pointer
  873. * @flag: Command flag
  874. * @argc: Command-line argument count
  875. * @argv: Array of command-line arguments
  876. *
  877. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  878. * on error.
  879. *
  880. * Syntax:
  881. * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
  882. * {length} - Number of bytes to read
  883. * {delay} - A DECIMAL number and defaults to 1000 uSec
  884. */
  885. static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  886. {
  887. uint chip;
  888. int alen;
  889. uint addr;
  890. uint length;
  891. u_char bytes[16];
  892. int delay;
  893. int ret;
  894. #ifdef CONFIG_DM_I2C
  895. struct udevice *dev;
  896. #endif
  897. if (argc < 3)
  898. return CMD_RET_USAGE;
  899. /*
  900. * Chip is always specified.
  901. */
  902. chip = simple_strtoul(argv[1], NULL, 16);
  903. /*
  904. * Address is always specified.
  905. */
  906. addr = simple_strtoul(argv[2], NULL, 16);
  907. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  908. if (alen > 3)
  909. return CMD_RET_USAGE;
  910. #ifdef CONFIG_DM_I2C
  911. ret = i2c_get_cur_bus_chip(chip, &dev);
  912. if (!ret && alen != -1)
  913. ret = i2c_set_chip_offset_len(dev, alen);
  914. if (ret)
  915. return i2c_report_err(ret, I2C_ERR_WRITE);
  916. #endif
  917. /*
  918. * Length is the number of objects, not number of bytes.
  919. */
  920. length = 1;
  921. length = simple_strtoul(argv[3], NULL, 16);
  922. if (length > sizeof(bytes))
  923. length = sizeof(bytes);
  924. /*
  925. * The delay time (uSec) is optional.
  926. */
  927. delay = 1000;
  928. if (argc > 3)
  929. delay = simple_strtoul(argv[4], NULL, 10);
  930. /*
  931. * Run the loop...
  932. */
  933. while (1) {
  934. #ifdef CONFIG_DM_I2C
  935. ret = dm_i2c_read(dev, addr, bytes, length);
  936. #else
  937. ret = i2c_read(chip, addr, alen, bytes, length);
  938. #endif
  939. if (ret)
  940. i2c_report_err(ret, I2C_ERR_READ);
  941. udelay(delay);
  942. }
  943. /* NOTREACHED */
  944. return 0;
  945. }
  946. /*
  947. * The SDRAM command is separately configured because many
  948. * (most?) embedded boards don't use SDRAM DIMMs.
  949. *
  950. * FIXME: Document and probably move elsewhere!
  951. */
  952. #if defined(CONFIG_CMD_SDRAM)
  953. static void print_ddr2_tcyc (u_char const b)
  954. {
  955. printf ("%d.", (b >> 4) & 0x0F);
  956. switch (b & 0x0F) {
  957. case 0x0:
  958. case 0x1:
  959. case 0x2:
  960. case 0x3:
  961. case 0x4:
  962. case 0x5:
  963. case 0x6:
  964. case 0x7:
  965. case 0x8:
  966. case 0x9:
  967. printf ("%d ns\n", b & 0x0F);
  968. break;
  969. case 0xA:
  970. puts ("25 ns\n");
  971. break;
  972. case 0xB:
  973. puts ("33 ns\n");
  974. break;
  975. case 0xC:
  976. puts ("66 ns\n");
  977. break;
  978. case 0xD:
  979. puts ("75 ns\n");
  980. break;
  981. default:
  982. puts ("?? ns\n");
  983. break;
  984. }
  985. }
  986. static void decode_bits (u_char const b, char const *str[], int const do_once)
  987. {
  988. u_char mask;
  989. for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
  990. if (b & mask) {
  991. puts (*str);
  992. if (do_once)
  993. return;
  994. }
  995. }
  996. }
  997. /*
  998. * Syntax:
  999. * i2c sdram {i2c_chip}
  1000. */
  1001. static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1002. {
  1003. enum { unknown, EDO, SDRAM, DDR2 } type;
  1004. uint chip;
  1005. u_char data[128];
  1006. u_char cksum;
  1007. int j;
  1008. static const char *decode_CAS_DDR2[] = {
  1009. " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
  1010. };
  1011. static const char *decode_CAS_default[] = {
  1012. " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
  1013. };
  1014. static const char *decode_CS_WE_default[] = {
  1015. " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
  1016. };
  1017. static const char *decode_byte21_default[] = {
  1018. " TBD (bit 7)\n",
  1019. " Redundant row address\n",
  1020. " Differential clock input\n",
  1021. " Registerd DQMB inputs\n",
  1022. " Buffered DQMB inputs\n",
  1023. " On-card PLL\n",
  1024. " Registered address/control lines\n",
  1025. " Buffered address/control lines\n"
  1026. };
  1027. static const char *decode_byte22_DDR2[] = {
  1028. " TBD (bit 7)\n",
  1029. " TBD (bit 6)\n",
  1030. " TBD (bit 5)\n",
  1031. " TBD (bit 4)\n",
  1032. " TBD (bit 3)\n",
  1033. " Supports partial array self refresh\n",
  1034. " Supports 50 ohm ODT\n",
  1035. " Supports weak driver\n"
  1036. };
  1037. static const char *decode_row_density_DDR2[] = {
  1038. "512 MiB", "256 MiB", "128 MiB", "16 GiB",
  1039. "8 GiB", "4 GiB", "2 GiB", "1 GiB"
  1040. };
  1041. static const char *decode_row_density_default[] = {
  1042. "512 MiB", "256 MiB", "128 MiB", "64 MiB",
  1043. "32 MiB", "16 MiB", "8 MiB", "4 MiB"
  1044. };
  1045. if (argc < 2)
  1046. return CMD_RET_USAGE;
  1047. /*
  1048. * Chip is always specified.
  1049. */
  1050. chip = simple_strtoul (argv[1], NULL, 16);
  1051. if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) {
  1052. puts ("No SDRAM Serial Presence Detect found.\n");
  1053. return 1;
  1054. }
  1055. cksum = 0;
  1056. for (j = 0; j < 63; j++) {
  1057. cksum += data[j];
  1058. }
  1059. if (cksum != data[63]) {
  1060. printf ("WARNING: Configuration data checksum failure:\n"
  1061. " is 0x%02x, calculated 0x%02x\n", data[63], cksum);
  1062. }
  1063. printf ("SPD data revision %d.%d\n",
  1064. (data[62] >> 4) & 0x0F, data[62] & 0x0F);
  1065. printf ("Bytes used 0x%02X\n", data[0]);
  1066. printf ("Serial memory size 0x%02X\n", 1 << data[1]);
  1067. puts ("Memory type ");
  1068. switch (data[2]) {
  1069. case 2:
  1070. type = EDO;
  1071. puts ("EDO\n");
  1072. break;
  1073. case 4:
  1074. type = SDRAM;
  1075. puts ("SDRAM\n");
  1076. break;
  1077. case 8:
  1078. type = DDR2;
  1079. puts ("DDR2\n");
  1080. break;
  1081. default:
  1082. type = unknown;
  1083. puts ("unknown\n");
  1084. break;
  1085. }
  1086. puts ("Row address bits ");
  1087. if ((data[3] & 0x00F0) == 0)
  1088. printf ("%d\n", data[3] & 0x0F);
  1089. else
  1090. printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
  1091. puts ("Column address bits ");
  1092. if ((data[4] & 0x00F0) == 0)
  1093. printf ("%d\n", data[4] & 0x0F);
  1094. else
  1095. printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
  1096. switch (type) {
  1097. case DDR2:
  1098. printf ("Number of ranks %d\n",
  1099. (data[5] & 0x07) + 1);
  1100. break;
  1101. default:
  1102. printf ("Module rows %d\n", data[5]);
  1103. break;
  1104. }
  1105. switch (type) {
  1106. case DDR2:
  1107. printf ("Module data width %d bits\n", data[6]);
  1108. break;
  1109. default:
  1110. printf ("Module data width %d bits\n",
  1111. (data[7] << 8) | data[6]);
  1112. break;
  1113. }
  1114. puts ("Interface signal levels ");
  1115. switch(data[8]) {
  1116. case 0: puts ("TTL 5.0 V\n"); break;
  1117. case 1: puts ("LVTTL\n"); break;
  1118. case 2: puts ("HSTL 1.5 V\n"); break;
  1119. case 3: puts ("SSTL 3.3 V\n"); break;
  1120. case 4: puts ("SSTL 2.5 V\n"); break;
  1121. case 5: puts ("SSTL 1.8 V\n"); break;
  1122. default: puts ("unknown\n"); break;
  1123. }
  1124. switch (type) {
  1125. case DDR2:
  1126. printf ("SDRAM cycle time ");
  1127. print_ddr2_tcyc (data[9]);
  1128. break;
  1129. default:
  1130. printf ("SDRAM cycle time %d.%d ns\n",
  1131. (data[9] >> 4) & 0x0F, data[9] & 0x0F);
  1132. break;
  1133. }
  1134. switch (type) {
  1135. case DDR2:
  1136. printf ("SDRAM access time 0.%d%d ns\n",
  1137. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  1138. break;
  1139. default:
  1140. printf ("SDRAM access time %d.%d ns\n",
  1141. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  1142. break;
  1143. }
  1144. puts ("EDC configuration ");
  1145. switch (data[11]) {
  1146. case 0: puts ("None\n"); break;
  1147. case 1: puts ("Parity\n"); break;
  1148. case 2: puts ("ECC\n"); break;
  1149. default: puts ("unknown\n"); break;
  1150. }
  1151. if ((data[12] & 0x80) == 0)
  1152. puts ("No self refresh, rate ");
  1153. else
  1154. puts ("Self refresh, rate ");
  1155. switch(data[12] & 0x7F) {
  1156. case 0: puts ("15.625 us\n"); break;
  1157. case 1: puts ("3.9 us\n"); break;
  1158. case 2: puts ("7.8 us\n"); break;
  1159. case 3: puts ("31.3 us\n"); break;
  1160. case 4: puts ("62.5 us\n"); break;
  1161. case 5: puts ("125 us\n"); break;
  1162. default: puts ("unknown\n"); break;
  1163. }
  1164. switch (type) {
  1165. case DDR2:
  1166. printf ("SDRAM width (primary) %d\n", data[13]);
  1167. break;
  1168. default:
  1169. printf ("SDRAM width (primary) %d\n", data[13] & 0x7F);
  1170. if ((data[13] & 0x80) != 0) {
  1171. printf (" (second bank) %d\n",
  1172. 2 * (data[13] & 0x7F));
  1173. }
  1174. break;
  1175. }
  1176. switch (type) {
  1177. case DDR2:
  1178. if (data[14] != 0)
  1179. printf ("EDC width %d\n", data[14]);
  1180. break;
  1181. default:
  1182. if (data[14] != 0) {
  1183. printf ("EDC width %d\n",
  1184. data[14] & 0x7F);
  1185. if ((data[14] & 0x80) != 0) {
  1186. printf (" (second bank) %d\n",
  1187. 2 * (data[14] & 0x7F));
  1188. }
  1189. }
  1190. break;
  1191. }
  1192. if (DDR2 != type) {
  1193. printf ("Min clock delay, back-to-back random column addresses "
  1194. "%d\n", data[15]);
  1195. }
  1196. puts ("Burst length(s) ");
  1197. if (data[16] & 0x80) puts (" Page");
  1198. if (data[16] & 0x08) puts (" 8");
  1199. if (data[16] & 0x04) puts (" 4");
  1200. if (data[16] & 0x02) puts (" 2");
  1201. if (data[16] & 0x01) puts (" 1");
  1202. putc ('\n');
  1203. printf ("Number of banks %d\n", data[17]);
  1204. switch (type) {
  1205. case DDR2:
  1206. puts ("CAS latency(s) ");
  1207. decode_bits (data[18], decode_CAS_DDR2, 0);
  1208. putc ('\n');
  1209. break;
  1210. default:
  1211. puts ("CAS latency(s) ");
  1212. decode_bits (data[18], decode_CAS_default, 0);
  1213. putc ('\n');
  1214. break;
  1215. }
  1216. if (DDR2 != type) {
  1217. puts ("CS latency(s) ");
  1218. decode_bits (data[19], decode_CS_WE_default, 0);
  1219. putc ('\n');
  1220. }
  1221. if (DDR2 != type) {
  1222. puts ("WE latency(s) ");
  1223. decode_bits (data[20], decode_CS_WE_default, 0);
  1224. putc ('\n');
  1225. }
  1226. switch (type) {
  1227. case DDR2:
  1228. puts ("Module attributes:\n");
  1229. if (data[21] & 0x80)
  1230. puts (" TBD (bit 7)\n");
  1231. if (data[21] & 0x40)
  1232. puts (" Analysis probe installed\n");
  1233. if (data[21] & 0x20)
  1234. puts (" TBD (bit 5)\n");
  1235. if (data[21] & 0x10)
  1236. puts (" FET switch external enable\n");
  1237. printf (" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
  1238. if (data[20] & 0x11) {
  1239. printf (" %d active registers on DIMM\n",
  1240. (data[21] & 0x03) + 1);
  1241. }
  1242. break;
  1243. default:
  1244. puts ("Module attributes:\n");
  1245. if (!data[21])
  1246. puts (" (none)\n");
  1247. else
  1248. decode_bits (data[21], decode_byte21_default, 0);
  1249. break;
  1250. }
  1251. switch (type) {
  1252. case DDR2:
  1253. decode_bits (data[22], decode_byte22_DDR2, 0);
  1254. break;
  1255. default:
  1256. puts ("Device attributes:\n");
  1257. if (data[22] & 0x80) puts (" TBD (bit 7)\n");
  1258. if (data[22] & 0x40) puts (" TBD (bit 6)\n");
  1259. if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
  1260. else puts (" Upper Vcc tolerance 10%\n");
  1261. if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
  1262. else puts (" Lower Vcc tolerance 10%\n");
  1263. if (data[22] & 0x08) puts (" Supports write1/read burst\n");
  1264. if (data[22] & 0x04) puts (" Supports precharge all\n");
  1265. if (data[22] & 0x02) puts (" Supports auto precharge\n");
  1266. if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
  1267. break;
  1268. }
  1269. switch (type) {
  1270. case DDR2:
  1271. printf ("SDRAM cycle time (2nd highest CAS latency) ");
  1272. print_ddr2_tcyc (data[23]);
  1273. break;
  1274. default:
  1275. printf ("SDRAM cycle time (2nd highest CAS latency) %d."
  1276. "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
  1277. break;
  1278. }
  1279. switch (type) {
  1280. case DDR2:
  1281. printf ("SDRAM access from clock (2nd highest CAS latency) 0."
  1282. "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  1283. break;
  1284. default:
  1285. printf ("SDRAM access from clock (2nd highest CAS latency) %d."
  1286. "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  1287. break;
  1288. }
  1289. switch (type) {
  1290. case DDR2:
  1291. printf ("SDRAM cycle time (3rd highest CAS latency) ");
  1292. print_ddr2_tcyc (data[25]);
  1293. break;
  1294. default:
  1295. printf ("SDRAM cycle time (3rd highest CAS latency) %d."
  1296. "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
  1297. break;
  1298. }
  1299. switch (type) {
  1300. case DDR2:
  1301. printf ("SDRAM access from clock (3rd highest CAS latency) 0."
  1302. "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  1303. break;
  1304. default:
  1305. printf ("SDRAM access from clock (3rd highest CAS latency) %d."
  1306. "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  1307. break;
  1308. }
  1309. switch (type) {
  1310. case DDR2:
  1311. printf ("Minimum row precharge %d.%02d ns\n",
  1312. (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
  1313. break;
  1314. default:
  1315. printf ("Minimum row precharge %d ns\n", data[27]);
  1316. break;
  1317. }
  1318. switch (type) {
  1319. case DDR2:
  1320. printf ("Row active to row active min %d.%02d ns\n",
  1321. (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
  1322. break;
  1323. default:
  1324. printf ("Row active to row active min %d ns\n", data[28]);
  1325. break;
  1326. }
  1327. switch (type) {
  1328. case DDR2:
  1329. printf ("RAS to CAS delay min %d.%02d ns\n",
  1330. (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
  1331. break;
  1332. default:
  1333. printf ("RAS to CAS delay min %d ns\n", data[29]);
  1334. break;
  1335. }
  1336. printf ("Minimum RAS pulse width %d ns\n", data[30]);
  1337. switch (type) {
  1338. case DDR2:
  1339. puts ("Density of each row ");
  1340. decode_bits (data[31], decode_row_density_DDR2, 1);
  1341. putc ('\n');
  1342. break;
  1343. default:
  1344. puts ("Density of each row ");
  1345. decode_bits (data[31], decode_row_density_default, 1);
  1346. putc ('\n');
  1347. break;
  1348. }
  1349. switch (type) {
  1350. case DDR2:
  1351. puts ("Command and Address setup ");
  1352. if (data[32] >= 0xA0) {
  1353. printf ("1.%d%d ns\n",
  1354. ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
  1355. } else {
  1356. printf ("0.%d%d ns\n",
  1357. ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
  1358. }
  1359. break;
  1360. default:
  1361. printf ("Command and Address setup %c%d.%d ns\n",
  1362. (data[32] & 0x80) ? '-' : '+',
  1363. (data[32] >> 4) & 0x07, data[32] & 0x0F);
  1364. break;
  1365. }
  1366. switch (type) {
  1367. case DDR2:
  1368. puts ("Command and Address hold ");
  1369. if (data[33] >= 0xA0) {
  1370. printf ("1.%d%d ns\n",
  1371. ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
  1372. } else {
  1373. printf ("0.%d%d ns\n",
  1374. ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
  1375. }
  1376. break;
  1377. default:
  1378. printf ("Command and Address hold %c%d.%d ns\n",
  1379. (data[33] & 0x80) ? '-' : '+',
  1380. (data[33] >> 4) & 0x07, data[33] & 0x0F);
  1381. break;
  1382. }
  1383. switch (type) {
  1384. case DDR2:
  1385. printf ("Data signal input setup 0.%d%d ns\n",
  1386. (data[34] >> 4) & 0x0F, data[34] & 0x0F);
  1387. break;
  1388. default:
  1389. printf ("Data signal input setup %c%d.%d ns\n",
  1390. (data[34] & 0x80) ? '-' : '+',
  1391. (data[34] >> 4) & 0x07, data[34] & 0x0F);
  1392. break;
  1393. }
  1394. switch (type) {
  1395. case DDR2:
  1396. printf ("Data signal input hold 0.%d%d ns\n",
  1397. (data[35] >> 4) & 0x0F, data[35] & 0x0F);
  1398. break;
  1399. default:
  1400. printf ("Data signal input hold %c%d.%d ns\n",
  1401. (data[35] & 0x80) ? '-' : '+',
  1402. (data[35] >> 4) & 0x07, data[35] & 0x0F);
  1403. break;
  1404. }
  1405. puts ("Manufacturer's JEDEC ID ");
  1406. for (j = 64; j <= 71; j++)
  1407. printf ("%02X ", data[j]);
  1408. putc ('\n');
  1409. printf ("Manufacturing Location %02X\n", data[72]);
  1410. puts ("Manufacturer's Part Number ");
  1411. for (j = 73; j <= 90; j++)
  1412. printf ("%02X ", data[j]);
  1413. putc ('\n');
  1414. printf ("Revision Code %02X %02X\n", data[91], data[92]);
  1415. printf ("Manufacturing Date %02X %02X\n", data[93], data[94]);
  1416. puts ("Assembly Serial Number ");
  1417. for (j = 95; j <= 98; j++)
  1418. printf ("%02X ", data[j]);
  1419. putc ('\n');
  1420. if (DDR2 != type) {
  1421. printf ("Speed rating PC%d\n",
  1422. data[126] == 0x66 ? 66 : data[126]);
  1423. }
  1424. return 0;
  1425. }
  1426. #endif
  1427. /*
  1428. * Syntax:
  1429. * i2c edid {i2c_chip}
  1430. */
  1431. #if defined(CONFIG_I2C_EDID)
  1432. int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  1433. {
  1434. uint chip;
  1435. struct edid1_info edid;
  1436. int ret;
  1437. #ifdef CONFIG_DM_I2C
  1438. struct udevice *dev;
  1439. #endif
  1440. if (argc < 2) {
  1441. cmd_usage(cmdtp);
  1442. return 1;
  1443. }
  1444. chip = simple_strtoul(argv[1], NULL, 16);
  1445. #ifdef CONFIG_DM_I2C
  1446. ret = i2c_get_cur_bus_chip(chip, &dev);
  1447. if (!ret)
  1448. ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
  1449. #else
  1450. ret = i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid));
  1451. #endif
  1452. if (ret)
  1453. return i2c_report_err(ret, I2C_ERR_READ);
  1454. if (edid_check_info(&edid)) {
  1455. puts("Content isn't valid EDID.\n");
  1456. return 1;
  1457. }
  1458. edid_print_info(&edid);
  1459. return 0;
  1460. }
  1461. #endif /* CONFIG_I2C_EDID */
  1462. #ifdef CONFIG_DM_I2C
  1463. static void show_bus(struct udevice *bus)
  1464. {
  1465. struct udevice *dev;
  1466. printf("Bus %d:\t%s", bus->req_seq, bus->name);
  1467. if (device_active(bus))
  1468. printf(" (active %d)", bus->seq);
  1469. printf("\n");
  1470. for (device_find_first_child(bus, &dev);
  1471. dev;
  1472. device_find_next_child(&dev)) {
  1473. struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
  1474. printf(" %02x: %s, offset len %x, flags %x\n",
  1475. chip->chip_addr, dev->name, chip->offset_len,
  1476. chip->flags);
  1477. }
  1478. }
  1479. #endif
  1480. /**
  1481. * do_i2c_show_bus() - Handle the "i2c bus" command-line command
  1482. * @cmdtp: Command data struct pointer
  1483. * @flag: Command flag
  1484. * @argc: Command-line argument count
  1485. * @argv: Array of command-line arguments
  1486. *
  1487. * Returns zero always.
  1488. */
  1489. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
  1490. static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
  1491. char * const argv[])
  1492. {
  1493. if (argc == 1) {
  1494. /* show all busses */
  1495. #ifdef CONFIG_DM_I2C
  1496. struct udevice *bus;
  1497. struct uclass *uc;
  1498. int ret;
  1499. ret = uclass_get(UCLASS_I2C, &uc);
  1500. if (ret)
  1501. return CMD_RET_FAILURE;
  1502. uclass_foreach_dev(bus, uc)
  1503. show_bus(bus);
  1504. #else
  1505. int i;
  1506. for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
  1507. printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
  1508. #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1509. int j;
  1510. for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
  1511. if (i2c_bus[i].next_hop[j].chip == 0)
  1512. break;
  1513. printf("->%s@0x%2x:%d",
  1514. i2c_bus[i].next_hop[j].mux.name,
  1515. i2c_bus[i].next_hop[j].chip,
  1516. i2c_bus[i].next_hop[j].channel);
  1517. }
  1518. #endif
  1519. printf("\n");
  1520. }
  1521. #endif
  1522. } else {
  1523. int i;
  1524. /* show specific bus */
  1525. i = simple_strtoul(argv[1], NULL, 10);
  1526. #ifdef CONFIG_DM_I2C
  1527. struct udevice *bus;
  1528. int ret;
  1529. ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
  1530. if (ret) {
  1531. printf("Invalid bus %d: err=%d\n", i, ret);
  1532. return CMD_RET_FAILURE;
  1533. }
  1534. show_bus(bus);
  1535. #else
  1536. if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
  1537. printf("Invalid bus %d\n", i);
  1538. return -1;
  1539. }
  1540. printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
  1541. #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1542. int j;
  1543. for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
  1544. if (i2c_bus[i].next_hop[j].chip == 0)
  1545. break;
  1546. printf("->%s@0x%2x:%d",
  1547. i2c_bus[i].next_hop[j].mux.name,
  1548. i2c_bus[i].next_hop[j].chip,
  1549. i2c_bus[i].next_hop[j].channel);
  1550. }
  1551. #endif
  1552. printf("\n");
  1553. #endif
  1554. }
  1555. return 0;
  1556. }
  1557. #endif
  1558. /**
  1559. * do_i2c_bus_num() - Handle the "i2c dev" command-line command
  1560. * @cmdtp: Command data struct pointer
  1561. * @flag: Command flag
  1562. * @argc: Command-line argument count
  1563. * @argv: Array of command-line arguments
  1564. *
  1565. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1566. * on error.
  1567. */
  1568. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
  1569. defined(CONFIG_DM_I2C)
  1570. static int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc,
  1571. char * const argv[])
  1572. {
  1573. int ret = 0;
  1574. int bus_no;
  1575. if (argc == 1) {
  1576. /* querying current setting */
  1577. #ifdef CONFIG_DM_I2C
  1578. struct udevice *bus;
  1579. if (!i2c_get_cur_bus(&bus))
  1580. bus_no = bus->seq;
  1581. else
  1582. bus_no = -1;
  1583. #else
  1584. bus_no = i2c_get_bus_num();
  1585. #endif
  1586. printf("Current bus is %d\n", bus_no);
  1587. } else {
  1588. bus_no = simple_strtoul(argv[1], NULL, 10);
  1589. #if defined(CONFIG_SYS_I2C)
  1590. if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
  1591. printf("Invalid bus %d\n", bus_no);
  1592. return -1;
  1593. }
  1594. #endif
  1595. printf("Setting bus to %d\n", bus_no);
  1596. #ifdef CONFIG_DM_I2C
  1597. ret = cmd_i2c_set_bus_num(bus_no);
  1598. #else
  1599. ret = i2c_set_bus_num(bus_no);
  1600. #endif
  1601. if (ret)
  1602. printf("Failure changing bus number (%d)\n", ret);
  1603. }
  1604. return ret;
  1605. }
  1606. #endif /* defined(CONFIG_SYS_I2C) */
  1607. /**
  1608. * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
  1609. * @cmdtp: Command data struct pointer
  1610. * @flag: Command flag
  1611. * @argc: Command-line argument count
  1612. * @argv: Array of command-line arguments
  1613. *
  1614. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1615. * on error.
  1616. */
  1617. static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1618. {
  1619. int speed, ret=0;
  1620. #ifdef CONFIG_DM_I2C
  1621. struct udevice *bus;
  1622. if (i2c_get_cur_bus(&bus))
  1623. return 1;
  1624. #endif
  1625. if (argc == 1) {
  1626. #ifdef CONFIG_DM_I2C
  1627. speed = dm_i2c_get_bus_speed(bus);
  1628. #else
  1629. speed = i2c_get_bus_speed();
  1630. #endif
  1631. /* querying current speed */
  1632. printf("Current bus speed=%d\n", speed);
  1633. } else {
  1634. speed = simple_strtoul(argv[1], NULL, 10);
  1635. printf("Setting bus speed to %d Hz\n", speed);
  1636. #ifdef CONFIG_DM_I2C
  1637. ret = dm_i2c_set_bus_speed(bus, speed);
  1638. #else
  1639. ret = i2c_set_bus_speed(speed);
  1640. #endif
  1641. if (ret)
  1642. printf("Failure changing bus speed (%d)\n", ret);
  1643. }
  1644. return ret;
  1645. }
  1646. /**
  1647. * do_i2c_mm() - Handle the "i2c mm" command-line command
  1648. * @cmdtp: Command data struct pointer
  1649. * @flag: Command flag
  1650. * @argc: Command-line argument count
  1651. * @argv: Array of command-line arguments
  1652. *
  1653. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1654. * on error.
  1655. */
  1656. static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1657. {
  1658. return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
  1659. }
  1660. /**
  1661. * do_i2c_nm() - Handle the "i2c nm" command-line command
  1662. * @cmdtp: Command data struct pointer
  1663. * @flag: Command flag
  1664. * @argc: Command-line argument count
  1665. * @argv: Array of command-line arguments
  1666. *
  1667. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1668. * on error.
  1669. */
  1670. static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1671. {
  1672. return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
  1673. }
  1674. /**
  1675. * do_i2c_reset() - Handle the "i2c reset" command-line command
  1676. * @cmdtp: Command data struct pointer
  1677. * @flag: Command flag
  1678. * @argc: Command-line argument count
  1679. * @argv: Array of command-line arguments
  1680. *
  1681. * Returns zero always.
  1682. */
  1683. static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1684. {
  1685. #if defined(CONFIG_DM_I2C)
  1686. struct udevice *bus;
  1687. if (i2c_get_cur_bus(&bus))
  1688. return CMD_RET_FAILURE;
  1689. if (i2c_deblock(bus)) {
  1690. printf("Error: Not supported by the driver\n");
  1691. return CMD_RET_FAILURE;
  1692. }
  1693. #elif defined(CONFIG_SYS_I2C)
  1694. i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
  1695. #else
  1696. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  1697. #endif
  1698. return 0;
  1699. }
  1700. static cmd_tbl_t cmd_i2c_sub[] = {
  1701. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
  1702. U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
  1703. #endif
  1704. U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
  1705. #if defined(CONFIG_SYS_I2C) || \
  1706. defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
  1707. U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
  1708. #endif /* CONFIG_I2C_MULTI_BUS */
  1709. #if defined(CONFIG_I2C_EDID)
  1710. U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
  1711. #endif /* CONFIG_I2C_EDID */
  1712. U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
  1713. U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
  1714. U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
  1715. U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
  1716. U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
  1717. U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
  1718. U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
  1719. U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
  1720. #ifdef CONFIG_DM_I2C
  1721. U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
  1722. #endif
  1723. U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
  1724. #if defined(CONFIG_CMD_SDRAM)
  1725. U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
  1726. #endif
  1727. U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
  1728. };
  1729. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  1730. void i2c_reloc(void) {
  1731. fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
  1732. }
  1733. #endif
  1734. /**
  1735. * do_i2c() - Handle the "i2c" command-line command
  1736. * @cmdtp: Command data struct pointer
  1737. * @flag: Command flag
  1738. * @argc: Command-line argument count
  1739. * @argv: Array of command-line arguments
  1740. *
  1741. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1742. * on error.
  1743. */
  1744. static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1745. {
  1746. cmd_tbl_t *c;
  1747. if (argc < 2)
  1748. return CMD_RET_USAGE;
  1749. /* Strip off leading 'i2c' command argument */
  1750. argc--;
  1751. argv++;
  1752. c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
  1753. if (c)
  1754. return c->cmd(cmdtp, flag, argc, argv);
  1755. else
  1756. return CMD_RET_USAGE;
  1757. }
  1758. /***************************************************/
  1759. #ifdef CONFIG_SYS_LONGHELP
  1760. static char i2c_help_text[] =
  1761. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
  1762. "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
  1763. #endif
  1764. "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
  1765. #if defined(CONFIG_SYS_I2C) || \
  1766. defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
  1767. "i2c dev [dev] - show or set current I2C bus\n"
  1768. #endif /* CONFIG_I2C_MULTI_BUS */
  1769. #if defined(CONFIG_I2C_EDID)
  1770. "i2c edid chip - print EDID configuration information\n"
  1771. #endif /* CONFIG_I2C_EDID */
  1772. "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
  1773. "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
  1774. "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
  1775. "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
  1776. "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
  1777. "i2c probe [address] - test for and show device(s) on the I2C bus\n"
  1778. "i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
  1779. "i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory\n"
  1780. " to I2C; the -s option selects bulk write in a single transaction\n"
  1781. #ifdef CONFIG_DM_I2C
  1782. "i2c flags chip [flags] - set or get chip flags\n"
  1783. #endif
  1784. "i2c reset - re-init the I2C Controller\n"
  1785. #if defined(CONFIG_CMD_SDRAM)
  1786. "i2c sdram chip - print SDRAM configuration information\n"
  1787. #endif
  1788. "i2c speed [speed] - show or set I2C bus speed";
  1789. #endif
  1790. U_BOOT_CMD(
  1791. i2c, 7, 1, do_i2c,
  1792. "I2C sub-system",
  1793. i2c_help_text
  1794. );