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