xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*b7019ac5SIlia Mirkin /* SPDX-License-Identifier: MIT */
22aa5eac5SBen Skeggs #ifndef __NVKM_I2C_BUS_H__
32aa5eac5SBen Skeggs #define __NVKM_I2C_BUS_H__
42aa5eac5SBen Skeggs #include "pad.h"
52aa5eac5SBen Skeggs 
62aa5eac5SBen Skeggs struct nvkm_i2c_bus_func {
72aa5eac5SBen Skeggs 	void (*init)(struct nvkm_i2c_bus *);
82aa5eac5SBen Skeggs 	void (*drive_scl)(struct nvkm_i2c_bus *, int state);
92aa5eac5SBen Skeggs 	void (*drive_sda)(struct nvkm_i2c_bus *, int state);
102aa5eac5SBen Skeggs 	int (*sense_scl)(struct nvkm_i2c_bus *);
112aa5eac5SBen Skeggs 	int (*sense_sda)(struct nvkm_i2c_bus *);
122aa5eac5SBen Skeggs 	int (*xfer)(struct nvkm_i2c_bus *, struct i2c_msg *, int num);
132aa5eac5SBen Skeggs };
142aa5eac5SBen Skeggs 
152aa5eac5SBen Skeggs int nvkm_i2c_bus_ctor(const struct nvkm_i2c_bus_func *, struct nvkm_i2c_pad *,
162aa5eac5SBen Skeggs 		      int id, struct nvkm_i2c_bus *);
172aa5eac5SBen Skeggs int nvkm_i2c_bus_new_(const struct nvkm_i2c_bus_func *, struct nvkm_i2c_pad *,
182aa5eac5SBen Skeggs 		      int id, struct nvkm_i2c_bus **);
192aa5eac5SBen Skeggs void nvkm_i2c_bus_del(struct nvkm_i2c_bus **);
202aa5eac5SBen Skeggs void nvkm_i2c_bus_init(struct nvkm_i2c_bus *);
21342406e4SLyude Paul void nvkm_i2c_bus_fini(struct nvkm_i2c_bus *);
222aa5eac5SBen Skeggs 
232aa5eac5SBen Skeggs int nvkm_i2c_bit_xfer(struct nvkm_i2c_bus *, struct i2c_msg *, int);
242aa5eac5SBen Skeggs 
252aa5eac5SBen Skeggs int nv04_i2c_bus_new(struct nvkm_i2c_pad *, int, u8, u8,
262aa5eac5SBen Skeggs 		     struct nvkm_i2c_bus **);
272aa5eac5SBen Skeggs 
282aa5eac5SBen Skeggs int nv4e_i2c_bus_new(struct nvkm_i2c_pad *, int, u8, struct nvkm_i2c_bus **);
292aa5eac5SBen Skeggs int nv50_i2c_bus_new(struct nvkm_i2c_pad *, int, u8, struct nvkm_i2c_bus **);
302aa5eac5SBen Skeggs int gf119_i2c_bus_new(struct nvkm_i2c_pad *, int, u8, struct nvkm_i2c_bus **);
312aa5eac5SBen Skeggs 
322aa5eac5SBen Skeggs #define BUS_MSG(b,l,f,a...) do {                                               \
332aa5eac5SBen Skeggs 	struct nvkm_i2c_bus *_bus = (b);                                       \
342aa5eac5SBen Skeggs 	nvkm_##l(&_bus->pad->i2c->subdev, "bus %04x: "f"\n", _bus->id, ##a);   \
352aa5eac5SBen Skeggs } while(0)
362aa5eac5SBen Skeggs #define BUS_ERR(b,f,a...) BUS_MSG((b), error, f, ##a)
372aa5eac5SBen Skeggs #define BUS_DBG(b,f,a...) BUS_MSG((b), debug, f, ##a)
382aa5eac5SBen Skeggs #define BUS_TRACE(b,f,a...) BUS_MSG((b), trace, f, ##a)
392aa5eac5SBen Skeggs #endif
40