Commit ff5d2dce1e8b24e9f4d85db3906c5d2e25b0cedf

Authored by York Sun
Committed by Heiko Schocher
1 parent f539094f48
Exists in master and in 55 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf_v2022.04, emb_lf_v2023.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

common/i2c: Add i2c write command

Add i2c write command to write data from memory to i2c devices.

Signed-off-by: York Sun <yorksun@freescale.com>

Showing 1 changed file with 50 additions and 0 deletions Side-by-side Diff

... ... @@ -223,7 +223,55 @@
223 223 return 0;
224 224 }
225 225  
  226 +static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  227 +{
  228 + u_char chip;
  229 + uint devaddr, alen, length;
  230 + u_char *memaddr;
  231 +
  232 + if (argc != 5)
  233 + return cmd_usage(cmdtp);
  234 +
  235 + /*
  236 + * memaddr is the address where to store things in memory
  237 + */
  238 + memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
  239 +
  240 + /*
  241 + * I2C chip address
  242 + */
  243 + chip = simple_strtoul(argv[2], NULL, 16);
  244 +
  245 + /*
  246 + * I2C data address within the chip. This can be 1 or
  247 + * 2 bytes long. Some day it might be 3 bytes long :-).
  248 + */
  249 + devaddr = simple_strtoul(argv[3], NULL, 16);
  250 + alen = get_alen(argv[3]);
  251 + if (alen > 3)
  252 + return cmd_usage(cmdtp);
  253 +
  254 + /*
  255 + * Length is the number of objects, not number of bytes.
  256 + */
  257 + length = simple_strtoul(argv[4], NULL, 16);
  258 +
  259 + while (length-- > 0) {
  260 + if (i2c_write(chip, devaddr++, alen, memaddr++, 1) != 0) {
  261 + puts("Error writing to the chip.\n");
  262 + return 1;
  263 + }
226 264 /*
  265 + * No write delay with FRAM devices.
  266 + */
  267 +#if !defined(CONFIG_SYS_I2C_FRAM)
  268 + udelay(11000);
  269 +#endif
  270 + }
  271 + return 0;
  272 +}
  273 +
  274 +/*
227 275 * Syntax:
228 276 * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
229 277 */
... ... @@ -1282,6 +1330,7 @@
1282 1330 U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
1283 1331 U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
1284 1332 U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
  1333 + U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""),
1285 1334 U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
1286 1335 #if defined(CONFIG_CMD_SDRAM)
1287 1336 U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
... ... @@ -1333,6 +1382,7 @@
1333 1382 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
1334 1383 "i2c probe - show devices on the I2C bus\n"
1335 1384 "i2c read chip address[.0, .1, .2] length memaddress - read to memory \n"
  1385 + "i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n"
1336 1386 "i2c reset - re-init the I2C Controller\n"
1337 1387 #if defined(CONFIG_CMD_SDRAM)
1338 1388 "i2c sdram chip - print SDRAM configuration information\n"