1 #ifndef __NVKM_I2C_PAD_H__
2 #define __NVKM_I2C_PAD_H__
3 #include <subdev/i2c.h>
4 
5 struct nvkm_i2c_pad {
6 	const struct nvkm_i2c_pad_func *func;
7 	struct nvkm_i2c *i2c;
8 #define NVKM_I2C_PAD_HYBRID(n) /* 'n' is hw pad index */                     (n)
9 #define NVKM_I2C_PAD_CCB(n) /* 'n' is ccb index */                 ((n) + 0x100)
10 #define NVKM_I2C_PAD_EXT(n) /* 'n' is dcb external encoder type */ ((n) + 0x200)
11 	int id;
12 
13 	enum nvkm_i2c_pad_mode {
14 		NVKM_I2C_PAD_OFF,
15 		NVKM_I2C_PAD_I2C,
16 		NVKM_I2C_PAD_AUX,
17 	} mode;
18 	struct mutex mutex;
19 	struct list_head head;
20 };
21 
22 struct nvkm_i2c_pad_func {
23 	int (*bus_new_0)(struct nvkm_i2c_pad *, int id, u8 drive, u8 sense,
24 			 struct nvkm_i2c_bus **);
25 	int (*bus_new_4)(struct nvkm_i2c_pad *, int id, u8 drive,
26 			 struct nvkm_i2c_bus **);
27 
28 	int (*aux_new_6)(struct nvkm_i2c_pad *, int id, u8 drive,
29 			 struct nvkm_i2c_aux **);
30 
31 	void (*mode)(struct nvkm_i2c_pad *, enum nvkm_i2c_pad_mode);
32 };
33 
34 void nvkm_i2c_pad_ctor(const struct nvkm_i2c_pad_func *, struct nvkm_i2c *,
35 		       int id, struct nvkm_i2c_pad *);
36 int nvkm_i2c_pad_new_(const struct nvkm_i2c_pad_func *, struct nvkm_i2c *,
37 		      int id, struct nvkm_i2c_pad **);
38 void nvkm_i2c_pad_del(struct nvkm_i2c_pad **);
39 void nvkm_i2c_pad_init(struct nvkm_i2c_pad *);
40 void nvkm_i2c_pad_fini(struct nvkm_i2c_pad *);
41 void nvkm_i2c_pad_mode(struct nvkm_i2c_pad *, enum nvkm_i2c_pad_mode);
42 int nvkm_i2c_pad_acquire(struct nvkm_i2c_pad *, enum nvkm_i2c_pad_mode);
43 void nvkm_i2c_pad_release(struct nvkm_i2c_pad *);
44 
45 void g94_i2c_pad_mode(struct nvkm_i2c_pad *, enum nvkm_i2c_pad_mode);
46 
47 int nv04_i2c_pad_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
48 int nv4e_i2c_pad_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
49 int nv50_i2c_pad_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
50 int g94_i2c_pad_x_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
51 int gf119_i2c_pad_x_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
52 int gm204_i2c_pad_x_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
53 
54 int g94_i2c_pad_s_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
55 int gf119_i2c_pad_s_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
56 int gm204_i2c_pad_s_new(struct nvkm_i2c *, int, struct nvkm_i2c_pad **);
57 
58 int anx9805_pad_new(struct nvkm_i2c_bus *, int, u8, struct nvkm_i2c_pad **);
59 
60 #define PAD_MSG(p,l,f,a...) do {                                               \
61 	struct nvkm_i2c_pad *_pad = (p);                                       \
62 	nvkm_##l(&_pad->i2c->subdev, "pad %04x: "f"\n", _pad->id, ##a);        \
63 } while(0)
64 #define PAD_ERR(p,f,a...) PAD_MSG((p), error, f, ##a)
65 #define PAD_DBG(p,f,a...) PAD_MSG((p), debug, f, ##a)
66 #define PAD_TRACE(p,f,a...) PAD_MSG((p), trace, f, ##a)
67 #endif
68