* pairs. The following macros take care of this */
#if defined(CONFIG_SYS_I2C_NOPROBES)
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || defined(CONFIG_I2C_MULTI_BUS)
static struct
{
uchar bus;
#define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
#define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
#define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
-#endif /* defined(CONFIG_SYS_I2C) */
+#endif /* CONFIG_IS_ENABLED(SYS_I2C_LEGACY) */
#endif
#define DISP_LINE_LEN 16
* For legacy code, this is not stored, so we need to use a suitable
* default.
*/
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
#define DEFAULT_ADDR_LEN (-1)
#else
#define DEFAULT_ADDR_LEN 1
#endif
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
static struct udevice *i2c_cur_bus;
static int cmd_i2c_set_bus_num(unsigned int busnum)
*
* Returns I2C bus speed in Hz.
*/
-#if !defined(CONFIG_SYS_I2C) && !defined(CONFIG_DM_I2C)
+#if !CONFIG_IS_ENABLED(SYS_I2C_LEGACY) && !CONFIG_IS_ENABLED(DM_I2C)
/*
* TODO: Implement architecture-specific get/set functions
* Should go away, if we switched completely to new multibus support
int alen;
u_char *memaddr;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* I2C chip address
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* I2C data address within the chip. This can be 1 or
* 2 bytes long. Some day it might be 3 bytes long :-).
*/
- devaddr = simple_strtoul(argv[2], NULL, 16);
+ devaddr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
/*
* Length is the number of objects, not number of bytes.
*/
- length = simple_strtoul(argv[3], NULL, 16);
+ length = hextoul(argv[3], NULL);
/*
* memaddr is the address where to store things in memory
*/
- memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
+ memaddr = (u_char *)hextoul(argv[4], NULL);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
int alen;
u_char *memaddr;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
struct dm_i2c_chip *i2c_chip;
#endif
/*
* memaddr is the address where to store things in memory
*/
- memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
+ memaddr = (u_char *)hextoul(argv[1], NULL);
/*
* I2C chip address
*/
- chip = simple_strtoul(argv[2], NULL, 16);
+ chip = hextoul(argv[2], NULL);
/*
* I2C data address within the chip. This can be 1 or
* 2 bytes long. Some day it might be 3 bytes long :-).
*/
- devaddr = simple_strtoul(argv[3], NULL, 16);
+ devaddr = hextoul(argv[3], NULL);
alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
if (alen > 3)
return cmd_usage(cmdtp);
/*
* Length is the number of bytes.
*/
- length = simple_strtoul(argv[4], NULL, 16);
+ length = hextoul(argv[4], NULL);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
* a page boundary. No write delay upon completion, take this
* into account if linking commands.
*/
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS;
ret = dm_i2c_write(dev, devaddr, memaddr, length);
#else
* write transactions of one byte each
*/
while (length-- > 0) {
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS;
ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
#else
return 0;
}
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
static int do_i2c_flags(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
if (argc < 2)
return CMD_RET_USAGE;
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
ret = i2c_get_cur_bus_chip(chip, &dev);
if (ret)
return i2c_report_err(ret, I2C_ERR_READ);
if (argc > 2) {
- flags = simple_strtoul(argv[2], NULL, 16);
+ flags = hextoul(argv[2], NULL);
ret = i2c_set_chip_flags(dev, flags);
} else {
ret = i2c_get_chip_flags(dev, &flags);
if (argc < 2)
return CMD_RET_USAGE;
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
ret = i2c_get_cur_bus_chip(chip, &dev);
if (ret)
return i2c_report_err(ret, I2C_ERR_READ);
if (argc > 2) {
- olen = simple_strtoul(argv[2], NULL, 16);
+ olen = hextoul(argv[2], NULL);
ret = i2c_set_chip_offset_len(dev, olen);
} else {
ret = i2c_get_chip_offset_len(dev);
int alen;
int j, nbytes, linebytes;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* I2C chip address
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* I2C data address within the chip. This can be 1 or
* 2 bytes long. Some day it might be 3 bytes long :-).
*/
- addr = simple_strtoul(argv[2], NULL, 16);
+ addr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
* Length is the number of objects, not number of bytes.
*/
if (argc > 3)
- length = simple_strtoul(argv[3], NULL, 16);
+ length = hextoul(argv[3], NULL);
}
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_read(dev, addr, linebuf, linebytes);
#else
ret = i2c_read(chip, addr, alen, linebuf, linebytes);
uchar byte;
int count;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* Chip is always specified.
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* Address is always specified.
*/
- addr = simple_strtoul(argv[2], NULL, 16);
+ addr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
/*
* Value to write is always specified.
*/
- byte = simple_strtoul(argv[3], NULL, 16);
+ byte = hextoul(argv[3], NULL);
/*
* Optional count
*/
if (argc == 5)
- count = simple_strtoul(argv[4], NULL, 16);
+ count = hextoul(argv[4], NULL);
else
count = 1;
while (count-- > 0) {
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_write(dev, addr++, &byte, 1);
#else
ret = i2c_write(chip, addr++, alen, &byte, 1);
ulong crc;
ulong err;
int ret = 0;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* Chip is always specified.
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* Address is always specified.
*/
- addr = simple_strtoul(argv[2], NULL, 16);
+ addr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
/*
* Count is always specified
*/
- count = simple_strtoul(argv[3], NULL, 16);
+ count = hextoul(argv[3], NULL);
printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
/*
crc = 0;
err = 0;
while (count-- > 0) {
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_read(dev, addr, &byte, 1);
#else
ret = i2c_read(chip, addr, alen, &byte, 1);
int size = 1;
int nbytes;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* Chip is always specified.
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* Address is always specified.
*/
- addr = simple_strtoul(argv[2], NULL, 16);
+ addr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
}
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
*/
do {
printf("%08lx:", addr);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
#else
ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
else {
char *endp;
- data = simple_strtoul(console_buffer, &endp, 16);
+ data = hextoul(console_buffer, &endp);
if (size == 1)
data = data << 24;
else if (size == 2)
* good enough to not time out
*/
bootretry_reset_cmd_timeout();
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_write(dev, addr, (uchar *)&data,
size);
#else
if (ret)
return i2c_report_err(ret,
I2C_ERR_WRITE);
-#ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+#if CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS > 0
udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
#endif
if (incrflag)
unsigned int bus = GET_BUS_NUM;
#endif /* NOPROBES */
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus, *dev;
if (i2c_get_cur_bus(&bus))
if (skip)
continue;
#endif
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_probe(bus, j, 0, &dev);
#else
ret = i2c_probe(j);
u_char bytes[16];
int delay;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* Chip is always specified.
*/
- chip = simple_strtoul(argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
/*
* Address is always specified.
*/
- addr = simple_strtoul(argv[2], NULL, 16);
+ addr = hextoul(argv[2], NULL);
alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
if (alen > 3)
return CMD_RET_USAGE;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret && alen != -1)
ret = i2c_set_chip_offset_len(dev, alen);
* Length is the number of objects, not number of bytes.
*/
length = 1;
- length = simple_strtoul(argv[3], NULL, 16);
+ length = hextoul(argv[3], NULL);
if (length > sizeof(bytes))
length = sizeof(bytes);
*/
delay = 1000;
if (argc > 3)
- delay = simple_strtoul(argv[4], NULL, 10);
+ delay = dectoul(argv[4], NULL);
/*
* Run the loop...
*/
while (1) {
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_read(dev, addr, bytes, length);
#else
ret = i2c_read(chip, addr, alen, bytes, length);
u_char data[128];
u_char cksum;
int j, ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
/*
* Chip is always specified.
*/
- chip = simple_strtoul (argv[1], NULL, 16);
+ chip = hextoul(argv[1], NULL);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret)
ret = dm_i2c_read(dev, 0, data, sizeof(data));
uint chip;
struct edid1_info edid;
int ret;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *dev;
#endif
return 1;
}
- chip = simple_strtoul(argv[1], NULL, 16);
-#ifdef CONFIG_DM_I2C
+ chip = hextoul(argv[1], NULL);
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = i2c_get_cur_bus_chip(chip, &dev);
if (!ret)
ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
}
#endif /* CONFIG_I2C_EDID */
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
static void show_bus(struct udevice *bus)
{
struct udevice *dev;
*
* Returns zero always.
*/
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || CONFIG_IS_ENABLED(DM_I2C)
static int do_i2c_show_bus(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
if (argc == 1) {
/* show all busses */
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus;
struct uclass *uc;
int ret;
int i;
/* show specific bus */
- i = simple_strtoul(argv[1], NULL, 10);
-#ifdef CONFIG_DM_I2C
+ i = dectoul(argv[1], NULL);
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus;
int ret;
* Returns zero on success, CMD_RET_USAGE in case of misuse and negative
* on error.
*/
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
- defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || defined(CONFIG_I2C_MULTI_BUS) || \
+ CONFIG_IS_ENABLED(DM_I2C)
static int do_i2c_bus_num(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
if (argc == 1) {
/* querying current setting */
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus;
if (!i2c_get_cur_bus(&bus))
#endif
printf("Current bus is %d\n", bus_no);
} else {
- bus_no = simple_strtoul(argv[1], NULL, 10);
-#if defined(CONFIG_SYS_I2C)
+ bus_no = dectoul(argv[1], NULL);
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
printf("Invalid bus %d\n", bus_no);
return -1;
}
#endif
printf("Setting bus to %d\n", bus_no);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = cmd_i2c_set_bus_num(bus_no);
#else
ret = i2c_set_bus_num(bus_no);
return ret ? CMD_RET_FAILURE : 0;
}
-#endif /* defined(CONFIG_SYS_I2C) */
+#endif /* CONFIG_IS_ENABLED(SYS_I2C_LEGACY) */
/**
* do_i2c_bus_speed() - Handle the "i2c speed" command-line command
{
int speed, ret=0;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus;
if (i2c_get_cur_bus(&bus))
return 1;
#endif
if (argc == 1) {
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
speed = dm_i2c_get_bus_speed(bus);
#else
speed = i2c_get_bus_speed();
/* querying current speed */
printf("Current bus speed=%d\n", speed);
} else {
- speed = simple_strtoul(argv[1], NULL, 10);
+ speed = dectoul(argv[1], NULL);
printf("Setting bus speed to %d Hz\n", speed);
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
ret = dm_i2c_set_bus_speed(bus, speed);
#else
ret = i2c_set_bus_speed(speed);
static int do_i2c_reset(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
-#if defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(DM_I2C)
struct udevice *bus;
if (i2c_get_cur_bus(&bus))
printf("Error: Not supported by the driver\n");
return CMD_RET_FAILURE;
}
-#elif defined(CONFIG_SYS_I2C)
+#elif CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
#else
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
}
static struct cmd_tbl cmd_i2c_sub[] = {
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || CONFIG_IS_ENABLED(DM_I2C)
U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
#endif
U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
-#if defined(CONFIG_SYS_I2C) || \
- defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || \
+ defined(CONFIG_I2C_MULTI_BUS) || CONFIG_IS_ENABLED(DM_I2C)
U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
#endif /* CONFIG_I2C_MULTI_BUS */
#if defined(CONFIG_I2C_EDID)
U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
#endif
/***************************************************/
#ifdef CONFIG_SYS_LONGHELP
static char i2c_help_text[] =
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || CONFIG_IS_ENABLED(DM_I2C)
"bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
"i2c " /* That's the prefix for the crc32 command below. */
#endif
"crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
-#if defined(CONFIG_SYS_I2C) || \
- defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
+#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) || \
+ defined(CONFIG_I2C_MULTI_BUS) || CONFIG_IS_ENABLED(DM_I2C)
"i2c dev [dev] - show or set current I2C bus\n"
#endif /* CONFIG_I2C_MULTI_BUS */
#if defined(CONFIG_I2C_EDID)
"i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
"i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory\n"
" to I2C; the -s option selects bulk write in a single transaction\n"
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
"i2c flags chip [flags] - set or get chip flags\n"
"i2c olen chip [offset_length] - set or get chip offset length\n"
#endif