]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/i2c/i2c-uclass-compat.c
2 * Copyright (c) 2014 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
12 static int cur_busnum
__attribute__((section(".data")));
14 static int i2c_compat_get_device(uint chip_addr
, int alen
,
15 struct udevice
**devp
)
17 struct dm_i2c_chip
*chip
;
20 ret
= i2c_get_chip_for_busnum(cur_busnum
, chip_addr
, alen
, devp
);
23 chip
= dev_get_parent_platdata(*devp
);
24 if (chip
->offset_len
!= alen
) {
25 printf("I2C chip %x: requested alen %d does not match chip offset_len %d\n",
26 chip_addr
, alen
, chip
->offset_len
);
27 return -EADDRNOTAVAIL
;
33 int i2c_probe(uint8_t chip_addr
)
35 struct udevice
*bus
, *dev
;
38 ret
= uclass_get_device_by_seq(UCLASS_I2C
, cur_busnum
, &bus
);
40 debug("Cannot find I2C bus %d: err=%d\n", cur_busnum
, ret
);
47 return dm_i2c_probe(bus
, chip_addr
, 0, &dev
);
50 int i2c_read(uint8_t chip_addr
, unsigned int addr
, int alen
, uint8_t *buffer
,
56 ret
= i2c_compat_get_device(chip_addr
, alen
, &dev
);
60 return dm_i2c_read(dev
, addr
, buffer
, len
);
63 int i2c_write(uint8_t chip_addr
, unsigned int addr
, int alen
, uint8_t *buffer
,
69 ret
= i2c_compat_get_device(chip_addr
, alen
, &dev
);
73 return dm_i2c_write(dev
, addr
, buffer
, len
);
76 int i2c_get_bus_num_fdt(int node
)
81 ret
= uclass_get_device_by_of_offset(UCLASS_I2C
, node
, &bus
);
88 unsigned int i2c_get_bus_num(void)
93 int i2c_set_bus_num(unsigned int bus
)
100 void i2c_init(int speed
, int slaveaddr
)
102 /* Nothing to do here - the init happens through driver model */
105 void board_i2c_init(const void *blob
)
107 /* Nothing to do here - the init happens through driver model */
110 uint8_t i2c_reg_read(uint8_t chip_addr
, uint8_t offset
)
115 ret
= i2c_compat_get_device(chip_addr
, 1, &dev
);
118 return dm_i2c_reg_read(dev
, offset
);
121 void i2c_reg_write(uint8_t chip_addr
, uint8_t offset
, uint8_t val
)
126 ret
= i2c_compat_get_device(chip_addr
, 1, &dev
);
128 dm_i2c_reg_write(dev
, offset
, val
);