cmd_i2c.c 48 KB

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