drm/gf117/i2c: no aux channels on this chipset
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / include / subdev / i2c.h
1 #ifndef __NOUVEAU_I2C_H__
2 #define __NOUVEAU_I2C_H__
3
4 #include <core/subdev.h>
5 #include <core/device.h>
6
7 #include <subdev/bios.h>
8 #include <subdev/bios/i2c.h>
9
10 #define NV_I2C_PORT(n) (0x00 + (n))
11 #define NV_I2C_DEFAULT(n) (0x80 + (n))
12
13 #define NV_I2C_TYPE_DCBI2C(n) (0x0000 | (n))
14 #define NV_I2C_TYPE_EXTDDC(e) (0x0005 | (e) << 8)
15 #define NV_I2C_TYPE_EXTAUX(e) (0x0006 | (e) << 8)
16
17 enum nvkm_i2c_event {
18 NVKM_I2C_PLUG = 1,
19 NVKM_I2C_UNPLUG = 2,
20 NVKM_I2C_IRQ = 4,
21 NVKM_I2C_DONE = 8,
22 NVKM_I2C_ANY = (NVKM_I2C_PLUG |
23 NVKM_I2C_UNPLUG |
24 NVKM_I2C_IRQ |
25 NVKM_I2C_DONE),
26 };
27
28 struct nouveau_i2c_port {
29 struct nouveau_object base;
30 struct i2c_adapter adapter;
31 struct mutex mutex;
32
33 struct list_head head;
34 u8 index;
35 int aux;
36
37 const struct nouveau_i2c_func *func;
38 };
39
40 struct nouveau_i2c_func {
41 void (*drive_scl)(struct nouveau_i2c_port *, int);
42 void (*drive_sda)(struct nouveau_i2c_port *, int);
43 int (*sense_scl)(struct nouveau_i2c_port *);
44 int (*sense_sda)(struct nouveau_i2c_port *);
45
46 int (*aux)(struct nouveau_i2c_port *, bool, u8, u32, u8 *, u8);
47 int (*pattern)(struct nouveau_i2c_port *, int pattern);
48 int (*lnk_ctl)(struct nouveau_i2c_port *, int nr, int bw, bool enh);
49 int (*drv_ctl)(struct nouveau_i2c_port *, int lane, int sw, int pe);
50 };
51
52 struct nouveau_i2c_board_info {
53 struct i2c_board_info dev;
54 u8 udelay; /* set to 0 to use the standard delay */
55 };
56
57 struct nouveau_i2c {
58 struct nouveau_subdev base;
59 struct nouveau_event *ntfy;
60
61 struct nouveau_i2c_port *(*find)(struct nouveau_i2c *, u8 index);
62 struct nouveau_i2c_port *(*find_type)(struct nouveau_i2c *, u16 type);
63 int (*acquire_pad)(struct nouveau_i2c_port *, unsigned long timeout);
64 void (*release_pad)(struct nouveau_i2c_port *);
65 int (*acquire)(struct nouveau_i2c_port *, unsigned long timeout);
66 void (*release)(struct nouveau_i2c_port *);
67 int (*identify)(struct nouveau_i2c *, int index,
68 const char *what, struct nouveau_i2c_board_info *,
69 bool (*match)(struct nouveau_i2c_port *,
70 struct i2c_board_info *, void *), void *);
71
72 wait_queue_head_t wait;
73 struct list_head ports;
74 };
75
76 static inline struct nouveau_i2c *
77 nouveau_i2c(void *obj)
78 {
79 return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_I2C];
80 }
81
82 extern struct nouveau_oclass *nv04_i2c_oclass;
83 extern struct nouveau_oclass *nv4e_i2c_oclass;
84 extern struct nouveau_oclass *nv50_i2c_oclass;
85 extern struct nouveau_oclass *nv94_i2c_oclass;
86 extern struct nouveau_oclass *nvd0_i2c_oclass;
87 extern struct nouveau_oclass *gf117_i2c_oclass;
88 extern struct nouveau_oclass *nve0_i2c_oclass;
89
90 static inline int
91 nv_rdi2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg)
92 {
93 u8 val;
94 struct i2c_msg msgs[] = {
95 { .addr = addr, .flags = 0, .len = 1, .buf = &reg },
96 { .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = &val },
97 };
98
99 int ret = i2c_transfer(&port->adapter, msgs, 2);
100 if (ret != 2)
101 return -EIO;
102
103 return val;
104 }
105
106 static inline int
107 nv_wri2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg, u8 val)
108 {
109 u8 buf[2] = { reg, val };
110 struct i2c_msg msgs[] = {
111 { .addr = addr, .flags = 0, .len = 2, .buf = buf },
112 };
113
114 int ret = i2c_transfer(&port->adapter, msgs, 1);
115 if (ret != 1)
116 return -EIO;
117
118 return 0;
119 }
120
121 static inline bool
122 nv_probe_i2c(struct nouveau_i2c_port *port, u8 addr)
123 {
124 return nv_rdi2cr(port, addr, 0) >= 0;
125 }
126
127 int nv_rdaux(struct nouveau_i2c_port *, u32 addr, u8 *data, u8 size);
128 int nv_wraux(struct nouveau_i2c_port *, u32 addr, u8 *data, u8 size);
129
130 #endif
This page took 0.032901 seconds and 5 git commands to generate.