cmd_i2c.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912
  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. #endif
  308. if (argc != 5)
  309. return cmd_usage(cmdtp);
  310. /*
  311. * memaddr is the address where to store things in memory
  312. */
  313. memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
  314. /*
  315. * I2C chip address
  316. */
  317. chip = simple_strtoul(argv[2], NULL, 16);
  318. /*
  319. * I2C data address within the chip. This can be 1 or
  320. * 2 bytes long. Some day it might be 3 bytes long :-).
  321. */
  322. devaddr = simple_strtoul(argv[3], NULL, 16);
  323. alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
  324. if (alen > 3)
  325. return cmd_usage(cmdtp);
  326. /*
  327. * Length is the number of objects, not number of bytes.
  328. */
  329. length = simple_strtoul(argv[4], NULL, 16);
  330. #ifdef CONFIG_DM_I2C
  331. ret = i2c_get_cur_bus_chip(chip, &dev);
  332. if (!ret && alen != -1)
  333. ret = i2c_set_chip_offset_len(dev, alen);
  334. if (ret)
  335. return i2c_report_err(ret, I2C_ERR_WRITE);
  336. #endif
  337. while (length-- > 0) {
  338. #ifdef CONFIG_DM_I2C
  339. ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
  340. #else
  341. ret = i2c_write(chip, devaddr++, alen, memaddr++, 1);
  342. #endif
  343. if (ret)
  344. return i2c_report_err(ret, I2C_ERR_WRITE);
  345. /*
  346. * No write delay with FRAM devices.
  347. */
  348. #if !defined(CONFIG_SYS_I2C_FRAM)
  349. udelay(11000);
  350. #endif
  351. }
  352. return 0;
  353. }
  354. #ifdef CONFIG_DM_I2C
  355. static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc,
  356. char *const argv[])
  357. {
  358. struct udevice *dev;
  359. uint flags;
  360. int chip;
  361. int ret;
  362. if (argc < 2)
  363. return CMD_RET_USAGE;
  364. chip = simple_strtoul(argv[1], NULL, 16);
  365. ret = i2c_get_cur_bus_chip(chip, &dev);
  366. if (ret)
  367. return i2c_report_err(ret, I2C_ERR_READ);
  368. if (argc > 2) {
  369. flags = simple_strtoul(argv[2], NULL, 16);
  370. ret = i2c_set_chip_flags(dev, flags);
  371. } else {
  372. ret = i2c_get_chip_flags(dev, &flags);
  373. if (!ret)
  374. printf("%x\n", flags);
  375. }
  376. if (ret)
  377. return i2c_report_err(ret, I2C_ERR_READ);
  378. return 0;
  379. }
  380. #endif
  381. /**
  382. * do_i2c_md() - Handle the "i2c md" command-line command
  383. * @cmdtp: Command data struct pointer
  384. * @flag: Command flag
  385. * @argc: Command-line argument count
  386. * @argv: Array of command-line arguments
  387. *
  388. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  389. * on error.
  390. *
  391. * Syntax:
  392. * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
  393. */
  394. static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  395. {
  396. uint chip;
  397. uint addr, length;
  398. int alen;
  399. int j, nbytes, linebytes;
  400. int ret;
  401. #ifdef CONFIG_DM_I2C
  402. struct udevice *dev;
  403. #endif
  404. /* We use the last specified parameters, unless new ones are
  405. * entered.
  406. */
  407. chip = i2c_dp_last_chip;
  408. addr = i2c_dp_last_addr;
  409. alen = i2c_dp_last_alen;
  410. length = i2c_dp_last_length;
  411. if (argc < 3)
  412. return CMD_RET_USAGE;
  413. if ((flag & CMD_FLAG_REPEAT) == 0) {
  414. /*
  415. * New command specified.
  416. */
  417. /*
  418. * I2C chip address
  419. */
  420. chip = simple_strtoul(argv[1], NULL, 16);
  421. /*
  422. * I2C data address within the chip. This can be 1 or
  423. * 2 bytes long. Some day it might be 3 bytes long :-).
  424. */
  425. addr = simple_strtoul(argv[2], NULL, 16);
  426. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  427. if (alen > 3)
  428. return CMD_RET_USAGE;
  429. /*
  430. * If another parameter, it is the length to display.
  431. * Length is the number of objects, not number of bytes.
  432. */
  433. if (argc > 3)
  434. length = simple_strtoul(argv[3], NULL, 16);
  435. }
  436. #ifdef CONFIG_DM_I2C
  437. ret = i2c_get_cur_bus_chip(chip, &dev);
  438. if (!ret && alen != -1)
  439. ret = i2c_set_chip_offset_len(dev, alen);
  440. if (ret)
  441. return i2c_report_err(ret, I2C_ERR_READ);
  442. #endif
  443. /*
  444. * Print the lines.
  445. *
  446. * We buffer all read data, so we can make sure data is read only
  447. * once.
  448. */
  449. nbytes = length;
  450. do {
  451. unsigned char linebuf[DISP_LINE_LEN];
  452. unsigned char *cp;
  453. linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
  454. #ifdef CONFIG_DM_I2C
  455. ret = dm_i2c_read(dev, addr, linebuf, linebytes);
  456. #else
  457. ret = i2c_read(chip, addr, alen, linebuf, linebytes);
  458. #endif
  459. if (ret)
  460. i2c_report_err(ret, I2C_ERR_READ);
  461. else {
  462. printf("%04x:", addr);
  463. cp = linebuf;
  464. for (j=0; j<linebytes; j++) {
  465. printf(" %02x", *cp++);
  466. addr++;
  467. }
  468. puts (" ");
  469. cp = linebuf;
  470. for (j=0; j<linebytes; j++) {
  471. if ((*cp < 0x20) || (*cp > 0x7e))
  472. puts (".");
  473. else
  474. printf("%c", *cp);
  475. cp++;
  476. }
  477. putc ('\n');
  478. }
  479. nbytes -= linebytes;
  480. } while (nbytes > 0);
  481. i2c_dp_last_chip = chip;
  482. i2c_dp_last_addr = addr;
  483. i2c_dp_last_alen = alen;
  484. i2c_dp_last_length = length;
  485. return 0;
  486. }
  487. /**
  488. * do_i2c_mw() - Handle the "i2c mw" command-line command
  489. * @cmdtp: Command data struct pointer
  490. * @flag: Command flag
  491. * @argc: Command-line argument count
  492. * @argv: Array of command-line arguments
  493. *
  494. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  495. * on error.
  496. *
  497. * Syntax:
  498. * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
  499. */
  500. static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  501. {
  502. uint chip;
  503. ulong addr;
  504. int alen;
  505. uchar byte;
  506. int count;
  507. int ret;
  508. #ifdef CONFIG_DM_I2C
  509. struct udevice *dev;
  510. #endif
  511. if ((argc < 4) || (argc > 5))
  512. return CMD_RET_USAGE;
  513. /*
  514. * Chip is always specified.
  515. */
  516. chip = simple_strtoul(argv[1], NULL, 16);
  517. /*
  518. * Address is always specified.
  519. */
  520. addr = simple_strtoul(argv[2], NULL, 16);
  521. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  522. if (alen > 3)
  523. return CMD_RET_USAGE;
  524. #ifdef CONFIG_DM_I2C
  525. ret = i2c_get_cur_bus_chip(chip, &dev);
  526. if (!ret && alen != -1)
  527. ret = i2c_set_chip_offset_len(dev, alen);
  528. if (ret)
  529. return i2c_report_err(ret, I2C_ERR_WRITE);
  530. #endif
  531. /*
  532. * Value to write is always specified.
  533. */
  534. byte = simple_strtoul(argv[3], NULL, 16);
  535. /*
  536. * Optional count
  537. */
  538. if (argc == 5)
  539. count = simple_strtoul(argv[4], NULL, 16);
  540. else
  541. count = 1;
  542. while (count-- > 0) {
  543. #ifdef CONFIG_DM_I2C
  544. ret = dm_i2c_write(dev, addr++, &byte, 1);
  545. #else
  546. ret = i2c_write(chip, addr++, alen, &byte, 1);
  547. #endif
  548. if (ret)
  549. i2c_report_err(ret, I2C_ERR_WRITE);
  550. /*
  551. * Wait for the write to complete. The write can take
  552. * up to 10mSec (we allow a little more time).
  553. */
  554. /*
  555. * No write delay with FRAM devices.
  556. */
  557. #if !defined(CONFIG_SYS_I2C_FRAM)
  558. udelay(11000);
  559. #endif
  560. }
  561. return 0;
  562. }
  563. /**
  564. * do_i2c_crc() - Handle the "i2c crc32" command-line command
  565. * @cmdtp: Command data struct pointer
  566. * @flag: Command flag
  567. * @argc: Command-line argument count
  568. * @argv: Array of command-line arguments
  569. *
  570. * Calculate a CRC on memory
  571. *
  572. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  573. * on error.
  574. *
  575. * Syntax:
  576. * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
  577. */
  578. static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  579. {
  580. uint chip;
  581. ulong addr;
  582. int alen;
  583. int count;
  584. uchar byte;
  585. ulong crc;
  586. ulong err;
  587. int ret = 0;
  588. #ifdef CONFIG_DM_I2C
  589. struct udevice *dev;
  590. #endif
  591. if (argc < 4)
  592. return CMD_RET_USAGE;
  593. /*
  594. * Chip is always specified.
  595. */
  596. chip = simple_strtoul(argv[1], NULL, 16);
  597. /*
  598. * Address is always specified.
  599. */
  600. addr = simple_strtoul(argv[2], NULL, 16);
  601. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  602. if (alen > 3)
  603. return CMD_RET_USAGE;
  604. #ifdef CONFIG_DM_I2C
  605. ret = i2c_get_cur_bus_chip(chip, &dev);
  606. if (!ret && alen != -1)
  607. ret = i2c_set_chip_offset_len(dev, alen);
  608. if (ret)
  609. return i2c_report_err(ret, I2C_ERR_READ);
  610. #endif
  611. /*
  612. * Count is always specified
  613. */
  614. count = simple_strtoul(argv[3], NULL, 16);
  615. printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
  616. /*
  617. * CRC a byte at a time. This is going to be slooow, but hey, the
  618. * memories are small and slow too so hopefully nobody notices.
  619. */
  620. crc = 0;
  621. err = 0;
  622. while (count-- > 0) {
  623. #ifdef CONFIG_DM_I2C
  624. ret = dm_i2c_read(dev, addr, &byte, 1);
  625. #else
  626. ret = i2c_read(chip, addr, alen, &byte, 1);
  627. #endif
  628. if (ret)
  629. err++;
  630. crc = crc32 (crc, &byte, 1);
  631. addr++;
  632. }
  633. if (err > 0)
  634. i2c_report_err(ret, I2C_ERR_READ);
  635. else
  636. printf ("%08lx\n", crc);
  637. return 0;
  638. }
  639. /**
  640. * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
  641. * @cmdtp: Command data struct pointer
  642. * @flag: Command flag
  643. * @argc: Command-line argument count
  644. * @argv: Array of command-line arguments
  645. *
  646. * Modify memory.
  647. *
  648. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  649. * on error.
  650. *
  651. * Syntax:
  652. * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  653. * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  654. */
  655. static int
  656. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
  657. {
  658. uint chip;
  659. ulong addr;
  660. int alen;
  661. ulong data;
  662. int size = 1;
  663. int nbytes;
  664. int ret;
  665. #ifdef CONFIG_DM_I2C
  666. struct udevice *dev;
  667. #endif
  668. if (argc != 3)
  669. return CMD_RET_USAGE;
  670. bootretry_reset_cmd_timeout(); /* got a good command to get here */
  671. /*
  672. * We use the last specified parameters, unless new ones are
  673. * entered.
  674. */
  675. chip = i2c_mm_last_chip;
  676. addr = i2c_mm_last_addr;
  677. alen = i2c_mm_last_alen;
  678. if ((flag & CMD_FLAG_REPEAT) == 0) {
  679. /*
  680. * New command specified. Check for a size specification.
  681. * Defaults to byte if no or incorrect specification.
  682. */
  683. size = cmd_get_data_size(argv[0], 1);
  684. /*
  685. * Chip is always specified.
  686. */
  687. chip = simple_strtoul(argv[1], NULL, 16);
  688. /*
  689. * Address is always specified.
  690. */
  691. addr = simple_strtoul(argv[2], NULL, 16);
  692. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  693. if (alen > 3)
  694. return CMD_RET_USAGE;
  695. }
  696. #ifdef CONFIG_DM_I2C
  697. ret = i2c_get_cur_bus_chip(chip, &dev);
  698. if (!ret && alen != -1)
  699. ret = i2c_set_chip_offset_len(dev, alen);
  700. if (ret)
  701. return i2c_report_err(ret, I2C_ERR_WRITE);
  702. #endif
  703. /*
  704. * Print the address, followed by value. Then accept input for
  705. * the next value. A non-converted value exits.
  706. */
  707. do {
  708. printf("%08lx:", addr);
  709. #ifdef CONFIG_DM_I2C
  710. ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
  711. #else
  712. ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
  713. #endif
  714. if (ret)
  715. i2c_report_err(ret, I2C_ERR_READ);
  716. else {
  717. data = cpu_to_be32(data);
  718. if (size == 1)
  719. printf(" %02lx", (data >> 24) & 0x000000FF);
  720. else if (size == 2)
  721. printf(" %04lx", (data >> 16) & 0x0000FFFF);
  722. else
  723. printf(" %08lx", data);
  724. }
  725. nbytes = cli_readline(" ? ");
  726. if (nbytes == 0) {
  727. /*
  728. * <CR> pressed as only input, don't modify current
  729. * location and move to next.
  730. */
  731. if (incrflag)
  732. addr += size;
  733. nbytes = size;
  734. /* good enough to not time out */
  735. bootretry_reset_cmd_timeout();
  736. }
  737. #ifdef CONFIG_BOOT_RETRY_TIME
  738. else if (nbytes == -2)
  739. break; /* timed out, exit the command */
  740. #endif
  741. else {
  742. char *endp;
  743. data = simple_strtoul(console_buffer, &endp, 16);
  744. if (size == 1)
  745. data = data << 24;
  746. else if (size == 2)
  747. data = data << 16;
  748. data = be32_to_cpu(data);
  749. nbytes = endp - console_buffer;
  750. if (nbytes) {
  751. /*
  752. * good enough to not time out
  753. */
  754. bootretry_reset_cmd_timeout();
  755. #ifdef CONFIG_DM_I2C
  756. ret = dm_i2c_write(dev, addr, (uchar *)&data,
  757. size);
  758. #else
  759. ret = i2c_write(chip, addr, alen,
  760. (uchar *)&data, size);
  761. #endif
  762. if (ret)
  763. i2c_report_err(ret, I2C_ERR_WRITE);
  764. #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
  765. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  766. #endif
  767. if (incrflag)
  768. addr += size;
  769. }
  770. }
  771. } while (nbytes);
  772. i2c_mm_last_chip = chip;
  773. i2c_mm_last_addr = addr;
  774. i2c_mm_last_alen = alen;
  775. return 0;
  776. }
  777. /**
  778. * do_i2c_probe() - Handle the "i2c probe" command-line command
  779. * @cmdtp: Command data struct pointer
  780. * @flag: Command flag
  781. * @argc: Command-line argument count
  782. * @argv: Array of command-line arguments
  783. *
  784. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  785. * on error.
  786. *
  787. * Syntax:
  788. * i2c probe {addr}
  789. *
  790. * Returns zero (success) if one or more I2C devices was found
  791. */
  792. static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  793. {
  794. int j;
  795. int addr = -1;
  796. int found = 0;
  797. #if defined(CONFIG_SYS_I2C_NOPROBES)
  798. int k, skip;
  799. unsigned int bus = GET_BUS_NUM;
  800. #endif /* NOPROBES */
  801. int ret;
  802. #ifdef CONFIG_DM_I2C
  803. struct udevice *bus, *dev;
  804. if (i2c_get_cur_bus(&bus))
  805. return CMD_RET_FAILURE;
  806. #endif
  807. if (argc == 2)
  808. addr = simple_strtol(argv[1], 0, 16);
  809. puts ("Valid chip addresses:");
  810. for (j = 0; j < 128; j++) {
  811. if ((0 <= addr) && (j != addr))
  812. continue;
  813. #if defined(CONFIG_SYS_I2C_NOPROBES)
  814. skip = 0;
  815. for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
  816. if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
  817. skip = 1;
  818. break;
  819. }
  820. }
  821. if (skip)
  822. continue;
  823. #endif
  824. #ifdef CONFIG_DM_I2C
  825. ret = dm_i2c_probe(bus, j, 0, &dev);
  826. #else
  827. ret = i2c_probe(j);
  828. #endif
  829. if (ret == 0) {
  830. printf(" %02X", j);
  831. found++;
  832. }
  833. }
  834. putc ('\n');
  835. #if defined(CONFIG_SYS_I2C_NOPROBES)
  836. puts ("Excluded chip addresses:");
  837. for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
  838. if (COMPARE_BUS(bus,k))
  839. printf(" %02X", NO_PROBE_ADDR(k));
  840. }
  841. putc ('\n');
  842. #endif
  843. return (0 == found);
  844. }
  845. /**
  846. * do_i2c_loop() - Handle the "i2c loop" command-line command
  847. * @cmdtp: Command data struct pointer
  848. * @flag: Command flag
  849. * @argc: Command-line argument count
  850. * @argv: Array of command-line arguments
  851. *
  852. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  853. * on error.
  854. *
  855. * Syntax:
  856. * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
  857. * {length} - Number of bytes to read
  858. * {delay} - A DECIMAL number and defaults to 1000 uSec
  859. */
  860. static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  861. {
  862. uint chip;
  863. int alen;
  864. uint addr;
  865. uint length;
  866. u_char bytes[16];
  867. int delay;
  868. int ret;
  869. #ifdef CONFIG_DM_I2C
  870. struct udevice *dev;
  871. #endif
  872. if (argc < 3)
  873. return CMD_RET_USAGE;
  874. /*
  875. * Chip is always specified.
  876. */
  877. chip = simple_strtoul(argv[1], NULL, 16);
  878. /*
  879. * Address is always specified.
  880. */
  881. addr = simple_strtoul(argv[2], NULL, 16);
  882. alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
  883. if (alen > 3)
  884. return CMD_RET_USAGE;
  885. #ifdef CONFIG_DM_I2C
  886. ret = i2c_get_cur_bus_chip(chip, &dev);
  887. if (!ret && alen != -1)
  888. ret = i2c_set_chip_offset_len(dev, alen);
  889. if (ret)
  890. return i2c_report_err(ret, I2C_ERR_WRITE);
  891. #endif
  892. /*
  893. * Length is the number of objects, not number of bytes.
  894. */
  895. length = 1;
  896. length = simple_strtoul(argv[3], NULL, 16);
  897. if (length > sizeof(bytes))
  898. length = sizeof(bytes);
  899. /*
  900. * The delay time (uSec) is optional.
  901. */
  902. delay = 1000;
  903. if (argc > 3)
  904. delay = simple_strtoul(argv[4], NULL, 10);
  905. /*
  906. * Run the loop...
  907. */
  908. while (1) {
  909. #ifdef CONFIG_DM_I2C
  910. ret = dm_i2c_read(dev, addr, bytes, length);
  911. #else
  912. ret = i2c_read(chip, addr, alen, bytes, length);
  913. #endif
  914. if (ret)
  915. i2c_report_err(ret, I2C_ERR_READ);
  916. udelay(delay);
  917. }
  918. /* NOTREACHED */
  919. return 0;
  920. }
  921. /*
  922. * The SDRAM command is separately configured because many
  923. * (most?) embedded boards don't use SDRAM DIMMs.
  924. *
  925. * FIXME: Document and probably move elsewhere!
  926. */
  927. #if defined(CONFIG_CMD_SDRAM)
  928. static void print_ddr2_tcyc (u_char const b)
  929. {
  930. printf ("%d.", (b >> 4) & 0x0F);
  931. switch (b & 0x0F) {
  932. case 0x0:
  933. case 0x1:
  934. case 0x2:
  935. case 0x3:
  936. case 0x4:
  937. case 0x5:
  938. case 0x6:
  939. case 0x7:
  940. case 0x8:
  941. case 0x9:
  942. printf ("%d ns\n", b & 0x0F);
  943. break;
  944. case 0xA:
  945. puts ("25 ns\n");
  946. break;
  947. case 0xB:
  948. puts ("33 ns\n");
  949. break;
  950. case 0xC:
  951. puts ("66 ns\n");
  952. break;
  953. case 0xD:
  954. puts ("75 ns\n");
  955. break;
  956. default:
  957. puts ("?? ns\n");
  958. break;
  959. }
  960. }
  961. static void decode_bits (u_char const b, char const *str[], int const do_once)
  962. {
  963. u_char mask;
  964. for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
  965. if (b & mask) {
  966. puts (*str);
  967. if (do_once)
  968. return;
  969. }
  970. }
  971. }
  972. /*
  973. * Syntax:
  974. * i2c sdram {i2c_chip}
  975. */
  976. static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  977. {
  978. enum { unknown, EDO, SDRAM, DDR2 } type;
  979. uint chip;
  980. u_char data[128];
  981. u_char cksum;
  982. int j;
  983. static const char *decode_CAS_DDR2[] = {
  984. " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
  985. };
  986. static const char *decode_CAS_default[] = {
  987. " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
  988. };
  989. static const char *decode_CS_WE_default[] = {
  990. " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
  991. };
  992. static const char *decode_byte21_default[] = {
  993. " TBD (bit 7)\n",
  994. " Redundant row address\n",
  995. " Differential clock input\n",
  996. " Registerd DQMB inputs\n",
  997. " Buffered DQMB inputs\n",
  998. " On-card PLL\n",
  999. " Registered address/control lines\n",
  1000. " Buffered address/control lines\n"
  1001. };
  1002. static const char *decode_byte22_DDR2[] = {
  1003. " TBD (bit 7)\n",
  1004. " TBD (bit 6)\n",
  1005. " TBD (bit 5)\n",
  1006. " TBD (bit 4)\n",
  1007. " TBD (bit 3)\n",
  1008. " Supports partial array self refresh\n",
  1009. " Supports 50 ohm ODT\n",
  1010. " Supports weak driver\n"
  1011. };
  1012. static const char *decode_row_density_DDR2[] = {
  1013. "512 MiB", "256 MiB", "128 MiB", "16 GiB",
  1014. "8 GiB", "4 GiB", "2 GiB", "1 GiB"
  1015. };
  1016. static const char *decode_row_density_default[] = {
  1017. "512 MiB", "256 MiB", "128 MiB", "64 MiB",
  1018. "32 MiB", "16 MiB", "8 MiB", "4 MiB"
  1019. };
  1020. if (argc < 2)
  1021. return CMD_RET_USAGE;
  1022. /*
  1023. * Chip is always specified.
  1024. */
  1025. chip = simple_strtoul (argv[1], NULL, 16);
  1026. if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) {
  1027. puts ("No SDRAM Serial Presence Detect found.\n");
  1028. return 1;
  1029. }
  1030. cksum = 0;
  1031. for (j = 0; j < 63; j++) {
  1032. cksum += data[j];
  1033. }
  1034. if (cksum != data[63]) {
  1035. printf ("WARNING: Configuration data checksum failure:\n"
  1036. " is 0x%02x, calculated 0x%02x\n", data[63], cksum);
  1037. }
  1038. printf ("SPD data revision %d.%d\n",
  1039. (data[62] >> 4) & 0x0F, data[62] & 0x0F);
  1040. printf ("Bytes used 0x%02X\n", data[0]);
  1041. printf ("Serial memory size 0x%02X\n", 1 << data[1]);
  1042. puts ("Memory type ");
  1043. switch (data[2]) {
  1044. case 2:
  1045. type = EDO;
  1046. puts ("EDO\n");
  1047. break;
  1048. case 4:
  1049. type = SDRAM;
  1050. puts ("SDRAM\n");
  1051. break;
  1052. case 8:
  1053. type = DDR2;
  1054. puts ("DDR2\n");
  1055. break;
  1056. default:
  1057. type = unknown;
  1058. puts ("unknown\n");
  1059. break;
  1060. }
  1061. puts ("Row address bits ");
  1062. if ((data[3] & 0x00F0) == 0)
  1063. printf ("%d\n", data[3] & 0x0F);
  1064. else
  1065. printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
  1066. puts ("Column address bits ");
  1067. if ((data[4] & 0x00F0) == 0)
  1068. printf ("%d\n", data[4] & 0x0F);
  1069. else
  1070. printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
  1071. switch (type) {
  1072. case DDR2:
  1073. printf ("Number of ranks %d\n",
  1074. (data[5] & 0x07) + 1);
  1075. break;
  1076. default:
  1077. printf ("Module rows %d\n", data[5]);
  1078. break;
  1079. }
  1080. switch (type) {
  1081. case DDR2:
  1082. printf ("Module data width %d bits\n", data[6]);
  1083. break;
  1084. default:
  1085. printf ("Module data width %d bits\n",
  1086. (data[7] << 8) | data[6]);
  1087. break;
  1088. }
  1089. puts ("Interface signal levels ");
  1090. switch(data[8]) {
  1091. case 0: puts ("TTL 5.0 V\n"); break;
  1092. case 1: puts ("LVTTL\n"); break;
  1093. case 2: puts ("HSTL 1.5 V\n"); break;
  1094. case 3: puts ("SSTL 3.3 V\n"); break;
  1095. case 4: puts ("SSTL 2.5 V\n"); break;
  1096. case 5: puts ("SSTL 1.8 V\n"); break;
  1097. default: puts ("unknown\n"); break;
  1098. }
  1099. switch (type) {
  1100. case DDR2:
  1101. printf ("SDRAM cycle time ");
  1102. print_ddr2_tcyc (data[9]);
  1103. break;
  1104. default:
  1105. printf ("SDRAM cycle time %d.%d ns\n",
  1106. (data[9] >> 4) & 0x0F, data[9] & 0x0F);
  1107. break;
  1108. }
  1109. switch (type) {
  1110. case DDR2:
  1111. printf ("SDRAM access time 0.%d%d ns\n",
  1112. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  1113. break;
  1114. default:
  1115. printf ("SDRAM access time %d.%d ns\n",
  1116. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  1117. break;
  1118. }
  1119. puts ("EDC configuration ");
  1120. switch (data[11]) {
  1121. case 0: puts ("None\n"); break;
  1122. case 1: puts ("Parity\n"); break;
  1123. case 2: puts ("ECC\n"); break;
  1124. default: puts ("unknown\n"); break;
  1125. }
  1126. if ((data[12] & 0x80) == 0)
  1127. puts ("No self refresh, rate ");
  1128. else
  1129. puts ("Self refresh, rate ");
  1130. switch(data[12] & 0x7F) {
  1131. case 0: puts ("15.625 us\n"); break;
  1132. case 1: puts ("3.9 us\n"); break;
  1133. case 2: puts ("7.8 us\n"); break;
  1134. case 3: puts ("31.3 us\n"); break;
  1135. case 4: puts ("62.5 us\n"); break;
  1136. case 5: puts ("125 us\n"); break;
  1137. default: puts ("unknown\n"); break;
  1138. }
  1139. switch (type) {
  1140. case DDR2:
  1141. printf ("SDRAM width (primary) %d\n", data[13]);
  1142. break;
  1143. default:
  1144. printf ("SDRAM width (primary) %d\n", data[13] & 0x7F);
  1145. if ((data[13] & 0x80) != 0) {
  1146. printf (" (second bank) %d\n",
  1147. 2 * (data[13] & 0x7F));
  1148. }
  1149. break;
  1150. }
  1151. switch (type) {
  1152. case DDR2:
  1153. if (data[14] != 0)
  1154. printf ("EDC width %d\n", data[14]);
  1155. break;
  1156. default:
  1157. if (data[14] != 0) {
  1158. printf ("EDC width %d\n",
  1159. data[14] & 0x7F);
  1160. if ((data[14] & 0x80) != 0) {
  1161. printf (" (second bank) %d\n",
  1162. 2 * (data[14] & 0x7F));
  1163. }
  1164. }
  1165. break;
  1166. }
  1167. if (DDR2 != type) {
  1168. printf ("Min clock delay, back-to-back random column addresses "
  1169. "%d\n", data[15]);
  1170. }
  1171. puts ("Burst length(s) ");
  1172. if (data[16] & 0x80) puts (" Page");
  1173. if (data[16] & 0x08) puts (" 8");
  1174. if (data[16] & 0x04) puts (" 4");
  1175. if (data[16] & 0x02) puts (" 2");
  1176. if (data[16] & 0x01) puts (" 1");
  1177. putc ('\n');
  1178. printf ("Number of banks %d\n", data[17]);
  1179. switch (type) {
  1180. case DDR2:
  1181. puts ("CAS latency(s) ");
  1182. decode_bits (data[18], decode_CAS_DDR2, 0);
  1183. putc ('\n');
  1184. break;
  1185. default:
  1186. puts ("CAS latency(s) ");
  1187. decode_bits (data[18], decode_CAS_default, 0);
  1188. putc ('\n');
  1189. break;
  1190. }
  1191. if (DDR2 != type) {
  1192. puts ("CS latency(s) ");
  1193. decode_bits (data[19], decode_CS_WE_default, 0);
  1194. putc ('\n');
  1195. }
  1196. if (DDR2 != type) {
  1197. puts ("WE latency(s) ");
  1198. decode_bits (data[20], decode_CS_WE_default, 0);
  1199. putc ('\n');
  1200. }
  1201. switch (type) {
  1202. case DDR2:
  1203. puts ("Module attributes:\n");
  1204. if (data[21] & 0x80)
  1205. puts (" TBD (bit 7)\n");
  1206. if (data[21] & 0x40)
  1207. puts (" Analysis probe installed\n");
  1208. if (data[21] & 0x20)
  1209. puts (" TBD (bit 5)\n");
  1210. if (data[21] & 0x10)
  1211. puts (" FET switch external enable\n");
  1212. printf (" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
  1213. if (data[20] & 0x11) {
  1214. printf (" %d active registers on DIMM\n",
  1215. (data[21] & 0x03) + 1);
  1216. }
  1217. break;
  1218. default:
  1219. puts ("Module attributes:\n");
  1220. if (!data[21])
  1221. puts (" (none)\n");
  1222. else
  1223. decode_bits (data[21], decode_byte21_default, 0);
  1224. break;
  1225. }
  1226. switch (type) {
  1227. case DDR2:
  1228. decode_bits (data[22], decode_byte22_DDR2, 0);
  1229. break;
  1230. default:
  1231. puts ("Device attributes:\n");
  1232. if (data[22] & 0x80) puts (" TBD (bit 7)\n");
  1233. if (data[22] & 0x40) puts (" TBD (bit 6)\n");
  1234. if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
  1235. else puts (" Upper Vcc tolerance 10%\n");
  1236. if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
  1237. else puts (" Lower Vcc tolerance 10%\n");
  1238. if (data[22] & 0x08) puts (" Supports write1/read burst\n");
  1239. if (data[22] & 0x04) puts (" Supports precharge all\n");
  1240. if (data[22] & 0x02) puts (" Supports auto precharge\n");
  1241. if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
  1242. break;
  1243. }
  1244. switch (type) {
  1245. case DDR2:
  1246. printf ("SDRAM cycle time (2nd highest CAS latency) ");
  1247. print_ddr2_tcyc (data[23]);
  1248. break;
  1249. default:
  1250. printf ("SDRAM cycle time (2nd highest CAS latency) %d."
  1251. "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
  1252. break;
  1253. }
  1254. switch (type) {
  1255. case DDR2:
  1256. printf ("SDRAM access from clock (2nd highest CAS latency) 0."
  1257. "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  1258. break;
  1259. default:
  1260. printf ("SDRAM access from clock (2nd highest CAS latency) %d."
  1261. "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  1262. break;
  1263. }
  1264. switch (type) {
  1265. case DDR2:
  1266. printf ("SDRAM cycle time (3rd highest CAS latency) ");
  1267. print_ddr2_tcyc (data[25]);
  1268. break;
  1269. default:
  1270. printf ("SDRAM cycle time (3rd highest CAS latency) %d."
  1271. "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
  1272. break;
  1273. }
  1274. switch (type) {
  1275. case DDR2:
  1276. printf ("SDRAM access from clock (3rd highest CAS latency) 0."
  1277. "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  1278. break;
  1279. default:
  1280. printf ("SDRAM access from clock (3rd highest CAS latency) %d."
  1281. "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  1282. break;
  1283. }
  1284. switch (type) {
  1285. case DDR2:
  1286. printf ("Minimum row precharge %d.%02d ns\n",
  1287. (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
  1288. break;
  1289. default:
  1290. printf ("Minimum row precharge %d ns\n", data[27]);
  1291. break;
  1292. }
  1293. switch (type) {
  1294. case DDR2:
  1295. printf ("Row active to row active min %d.%02d ns\n",
  1296. (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
  1297. break;
  1298. default:
  1299. printf ("Row active to row active min %d ns\n", data[28]);
  1300. break;
  1301. }
  1302. switch (type) {
  1303. case DDR2:
  1304. printf ("RAS to CAS delay min %d.%02d ns\n",
  1305. (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
  1306. break;
  1307. default:
  1308. printf ("RAS to CAS delay min %d ns\n", data[29]);
  1309. break;
  1310. }
  1311. printf ("Minimum RAS pulse width %d ns\n", data[30]);
  1312. switch (type) {
  1313. case DDR2:
  1314. puts ("Density of each row ");
  1315. decode_bits (data[31], decode_row_density_DDR2, 1);
  1316. putc ('\n');
  1317. break;
  1318. default:
  1319. puts ("Density of each row ");
  1320. decode_bits (data[31], decode_row_density_default, 1);
  1321. putc ('\n');
  1322. break;
  1323. }
  1324. switch (type) {
  1325. case DDR2:
  1326. puts ("Command and Address setup ");
  1327. if (data[32] >= 0xA0) {
  1328. printf ("1.%d%d ns\n",
  1329. ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
  1330. } else {
  1331. printf ("0.%d%d ns\n",
  1332. ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
  1333. }
  1334. break;
  1335. default:
  1336. printf ("Command and Address setup %c%d.%d ns\n",
  1337. (data[32] & 0x80) ? '-' : '+',
  1338. (data[32] >> 4) & 0x07, data[32] & 0x0F);
  1339. break;
  1340. }
  1341. switch (type) {
  1342. case DDR2:
  1343. puts ("Command and Address hold ");
  1344. if (data[33] >= 0xA0) {
  1345. printf ("1.%d%d ns\n",
  1346. ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
  1347. } else {
  1348. printf ("0.%d%d ns\n",
  1349. ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
  1350. }
  1351. break;
  1352. default:
  1353. printf ("Command and Address hold %c%d.%d ns\n",
  1354. (data[33] & 0x80) ? '-' : '+',
  1355. (data[33] >> 4) & 0x07, data[33] & 0x0F);
  1356. break;
  1357. }
  1358. switch (type) {
  1359. case DDR2:
  1360. printf ("Data signal input setup 0.%d%d ns\n",
  1361. (data[34] >> 4) & 0x0F, data[34] & 0x0F);
  1362. break;
  1363. default:
  1364. printf ("Data signal input setup %c%d.%d ns\n",
  1365. (data[34] & 0x80) ? '-' : '+',
  1366. (data[34] >> 4) & 0x07, data[34] & 0x0F);
  1367. break;
  1368. }
  1369. switch (type) {
  1370. case DDR2:
  1371. printf ("Data signal input hold 0.%d%d ns\n",
  1372. (data[35] >> 4) & 0x0F, data[35] & 0x0F);
  1373. break;
  1374. default:
  1375. printf ("Data signal input hold %c%d.%d ns\n",
  1376. (data[35] & 0x80) ? '-' : '+',
  1377. (data[35] >> 4) & 0x07, data[35] & 0x0F);
  1378. break;
  1379. }
  1380. puts ("Manufacturer's JEDEC ID ");
  1381. for (j = 64; j <= 71; j++)
  1382. printf ("%02X ", data[j]);
  1383. putc ('\n');
  1384. printf ("Manufacturing Location %02X\n", data[72]);
  1385. puts ("Manufacturer's Part Number ");
  1386. for (j = 73; j <= 90; j++)
  1387. printf ("%02X ", data[j]);
  1388. putc ('\n');
  1389. printf ("Revision Code %02X %02X\n", data[91], data[92]);
  1390. printf ("Manufacturing Date %02X %02X\n", data[93], data[94]);
  1391. puts ("Assembly Serial Number ");
  1392. for (j = 95; j <= 98; j++)
  1393. printf ("%02X ", data[j]);
  1394. putc ('\n');
  1395. if (DDR2 != type) {
  1396. printf ("Speed rating PC%d\n",
  1397. data[126] == 0x66 ? 66 : data[126]);
  1398. }
  1399. return 0;
  1400. }
  1401. #endif
  1402. /*
  1403. * Syntax:
  1404. * i2c edid {i2c_chip}
  1405. */
  1406. #if defined(CONFIG_I2C_EDID)
  1407. int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  1408. {
  1409. uint chip;
  1410. struct edid1_info edid;
  1411. int ret;
  1412. #ifdef CONFIG_DM_I2C
  1413. struct udevice *dev;
  1414. #endif
  1415. if (argc < 2) {
  1416. cmd_usage(cmdtp);
  1417. return 1;
  1418. }
  1419. chip = simple_strtoul(argv[1], NULL, 16);
  1420. #ifdef CONFIG_DM_I2C
  1421. ret = i2c_get_cur_bus_chip(chip, &dev);
  1422. if (!ret)
  1423. ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
  1424. #else
  1425. ret = i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid));
  1426. #endif
  1427. if (ret)
  1428. return i2c_report_err(ret, I2C_ERR_READ);
  1429. if (edid_check_info(&edid)) {
  1430. puts("Content isn't valid EDID.\n");
  1431. return 1;
  1432. }
  1433. edid_print_info(&edid);
  1434. return 0;
  1435. }
  1436. #endif /* CONFIG_I2C_EDID */
  1437. /**
  1438. * do_i2c_show_bus() - Handle the "i2c bus" command-line command
  1439. * @cmdtp: Command data struct pointer
  1440. * @flag: Command flag
  1441. * @argc: Command-line argument count
  1442. * @argv: Array of command-line arguments
  1443. *
  1444. * Returns zero always.
  1445. */
  1446. #if defined(CONFIG_SYS_I2C)
  1447. static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
  1448. char * const argv[])
  1449. {
  1450. int i;
  1451. #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1452. int j;
  1453. #endif
  1454. if (argc == 1) {
  1455. /* show all busses */
  1456. for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
  1457. printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
  1458. #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1459. for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
  1460. if (i2c_bus[i].next_hop[j].chip == 0)
  1461. break;
  1462. printf("->%s@0x%2x:%d",
  1463. i2c_bus[i].next_hop[j].mux.name,
  1464. i2c_bus[i].next_hop[j].chip,
  1465. i2c_bus[i].next_hop[j].channel);
  1466. }
  1467. #endif
  1468. printf("\n");
  1469. }
  1470. } else {
  1471. /* show specific bus */
  1472. i = simple_strtoul(argv[1], NULL, 10);
  1473. if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
  1474. printf("Invalid bus %d\n", i);
  1475. return -1;
  1476. }
  1477. printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
  1478. #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1479. for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
  1480. if (i2c_bus[i].next_hop[j].chip == 0)
  1481. break;
  1482. printf("->%s@0x%2x:%d",
  1483. i2c_bus[i].next_hop[j].mux.name,
  1484. i2c_bus[i].next_hop[j].chip,
  1485. i2c_bus[i].next_hop[j].channel);
  1486. }
  1487. #endif
  1488. printf("\n");
  1489. }
  1490. return 0;
  1491. }
  1492. #endif
  1493. /**
  1494. * do_i2c_bus_num() - Handle the "i2c dev" command-line command
  1495. * @cmdtp: Command data struct pointer
  1496. * @flag: Command flag
  1497. * @argc: Command-line argument count
  1498. * @argv: Array of command-line arguments
  1499. *
  1500. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1501. * on error.
  1502. */
  1503. #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
  1504. defined(CONFIG_DM_I2C)
  1505. static int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc,
  1506. char * const argv[])
  1507. {
  1508. int ret = 0;
  1509. int bus_no;
  1510. if (argc == 1) {
  1511. /* querying current setting */
  1512. #ifdef CONFIG_DM_I2C
  1513. struct udevice *bus;
  1514. if (!i2c_get_cur_bus(&bus))
  1515. bus_no = bus->seq;
  1516. else
  1517. bus_no = -1;
  1518. #else
  1519. bus_no = i2c_get_bus_num();
  1520. #endif
  1521. printf("Current bus is %d\n", bus_no);
  1522. } else {
  1523. bus_no = simple_strtoul(argv[1], NULL, 10);
  1524. #if defined(CONFIG_SYS_I2C)
  1525. if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
  1526. printf("Invalid bus %d\n", bus_no);
  1527. return -1;
  1528. }
  1529. #endif
  1530. printf("Setting bus to %d\n", bus_no);
  1531. #ifdef CONFIG_DM_I2C
  1532. ret = cmd_i2c_set_bus_num(bus_no);
  1533. #else
  1534. ret = i2c_set_bus_num(bus_no);
  1535. #endif
  1536. if (ret)
  1537. printf("Failure changing bus number (%d)\n", ret);
  1538. }
  1539. return ret;
  1540. }
  1541. #endif /* defined(CONFIG_SYS_I2C) */
  1542. /**
  1543. * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
  1544. * @cmdtp: Command data struct pointer
  1545. * @flag: Command flag
  1546. * @argc: Command-line argument count
  1547. * @argv: Array of command-line arguments
  1548. *
  1549. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1550. * on error.
  1551. */
  1552. static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1553. {
  1554. int speed, ret=0;
  1555. #ifdef CONFIG_DM_I2C
  1556. struct udevice *bus;
  1557. if (i2c_get_cur_bus(&bus))
  1558. return 1;
  1559. #endif
  1560. if (argc == 1) {
  1561. #ifdef CONFIG_DM_I2C
  1562. speed = dm_i2c_get_bus_speed(bus);
  1563. #else
  1564. speed = i2c_get_bus_speed();
  1565. #endif
  1566. /* querying current speed */
  1567. printf("Current bus speed=%d\n", speed);
  1568. } else {
  1569. speed = simple_strtoul(argv[1], NULL, 10);
  1570. printf("Setting bus speed to %d Hz\n", speed);
  1571. #ifdef CONFIG_DM_I2C
  1572. ret = dm_i2c_set_bus_speed(bus, speed);
  1573. #else
  1574. ret = i2c_set_bus_speed(speed);
  1575. #endif
  1576. if (ret)
  1577. printf("Failure changing bus speed (%d)\n", ret);
  1578. }
  1579. return ret;
  1580. }
  1581. /**
  1582. * do_i2c_mm() - Handle the "i2c mm" command-line command
  1583. * @cmdtp: Command data struct pointer
  1584. * @flag: Command flag
  1585. * @argc: Command-line argument count
  1586. * @argv: Array of command-line arguments
  1587. *
  1588. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1589. * on error.
  1590. */
  1591. static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1592. {
  1593. return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
  1594. }
  1595. /**
  1596. * do_i2c_nm() - Handle the "i2c nm" command-line command
  1597. * @cmdtp: Command data struct pointer
  1598. * @flag: Command flag
  1599. * @argc: Command-line argument count
  1600. * @argv: Array of command-line arguments
  1601. *
  1602. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1603. * on error.
  1604. */
  1605. static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1606. {
  1607. return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
  1608. }
  1609. /**
  1610. * do_i2c_reset() - Handle the "i2c reset" command-line command
  1611. * @cmdtp: Command data struct pointer
  1612. * @flag: Command flag
  1613. * @argc: Command-line argument count
  1614. * @argv: Array of command-line arguments
  1615. *
  1616. * Returns zero always.
  1617. */
  1618. static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1619. {
  1620. #if defined(CONFIG_DM_I2C)
  1621. struct udevice *bus;
  1622. if (i2c_get_cur_bus(&bus))
  1623. return CMD_RET_FAILURE;
  1624. if (i2c_deblock(bus)) {
  1625. printf("Error: Not supported by the driver\n");
  1626. return CMD_RET_FAILURE;
  1627. }
  1628. #elif defined(CONFIG_SYS_I2C)
  1629. i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
  1630. #else
  1631. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  1632. #endif
  1633. return 0;
  1634. }
  1635. static cmd_tbl_t cmd_i2c_sub[] = {
  1636. #if defined(CONFIG_SYS_I2C)
  1637. U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
  1638. #endif
  1639. U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
  1640. #if defined(CONFIG_SYS_I2C) || \
  1641. defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
  1642. U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
  1643. #endif /* CONFIG_I2C_MULTI_BUS */
  1644. #if defined(CONFIG_I2C_EDID)
  1645. U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
  1646. #endif /* CONFIG_I2C_EDID */
  1647. U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
  1648. U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
  1649. U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
  1650. U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
  1651. U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
  1652. U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
  1653. U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
  1654. U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""),
  1655. #ifdef CONFIG_DM_I2C
  1656. U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
  1657. #endif
  1658. U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
  1659. #if defined(CONFIG_CMD_SDRAM)
  1660. U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
  1661. #endif
  1662. U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
  1663. };
  1664. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  1665. void i2c_reloc(void) {
  1666. fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
  1667. }
  1668. #endif
  1669. /**
  1670. * do_i2c() - Handle the "i2c" command-line command
  1671. * @cmdtp: Command data struct pointer
  1672. * @flag: Command flag
  1673. * @argc: Command-line argument count
  1674. * @argv: Array of command-line arguments
  1675. *
  1676. * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
  1677. * on error.
  1678. */
  1679. static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1680. {
  1681. cmd_tbl_t *c;
  1682. if (argc < 2)
  1683. return CMD_RET_USAGE;
  1684. /* Strip off leading 'i2c' command argument */
  1685. argc--;
  1686. argv++;
  1687. c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
  1688. if (c)
  1689. return c->cmd(cmdtp, flag, argc, argv);
  1690. else
  1691. return CMD_RET_USAGE;
  1692. }
  1693. /***************************************************/
  1694. #ifdef CONFIG_SYS_LONGHELP
  1695. static char i2c_help_text[] =
  1696. #if defined(CONFIG_SYS_I2C)
  1697. "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
  1698. #endif
  1699. "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
  1700. #if defined(CONFIG_SYS_I2C) || \
  1701. defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
  1702. "i2c dev [dev] - show or set current I2C bus\n"
  1703. #endif /* CONFIG_I2C_MULTI_BUS */
  1704. #if defined(CONFIG_I2C_EDID)
  1705. "i2c edid chip - print EDID configuration information\n"
  1706. #endif /* CONFIG_I2C_EDID */
  1707. "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
  1708. "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
  1709. "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
  1710. "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
  1711. "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
  1712. "i2c probe [address] - test for and show device(s) on the I2C bus\n"
  1713. "i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
  1714. "i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n"
  1715. #ifdef CONFIG_DM_I2C
  1716. "i2c flags chip [flags] - set or get chip flags\n"
  1717. #endif
  1718. "i2c reset - re-init the I2C Controller\n"
  1719. #if defined(CONFIG_CMD_SDRAM)
  1720. "i2c sdram chip - print SDRAM configuration information\n"
  1721. #endif
  1722. "i2c speed [speed] - show or set I2C bus speed";
  1723. #endif
  1724. U_BOOT_CMD(
  1725. i2c, 6, 1, do_i2c,
  1726. "I2C sub-system",
  1727. i2c_help_text
  1728. );