• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 
25 
26 #include "subdev/bios.h"
27 #include "subdev/bios/dcb.h"
28 #include "subdev/bios/i2c.h"
29 
30 u16
dcb_i2c_table(struct nouveau_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)31 dcb_i2c_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
32 {
33 	u16 i2c = 0x0000;
34 	u16 dcb = dcb_table(bios, ver, hdr, cnt, len);
35 	if (dcb) {
36 		if (*ver >= 0x15)
37 			i2c = nv_ro16(bios, dcb + 2);
38 		if (*ver >= 0x30)
39 			i2c = nv_ro16(bios, dcb + 4);
40 	}
41 
42 	if (i2c && *ver >= 0x30) {
43 		*ver = nv_ro08(bios, i2c + 0);
44 		*hdr = nv_ro08(bios, i2c + 1);
45 		*cnt = nv_ro08(bios, i2c + 2);
46 		*len = nv_ro08(bios, i2c + 3);
47 	} else {
48 		*ver = *ver; /* use DCB version */
49 		*hdr = 0;
50 		*cnt = 16;
51 		*len = 4;
52 	}
53 
54 	return i2c;
55 }
56 
57 u16
dcb_i2c_entry(struct nouveau_bios * bios,u8 idx,u8 * ver,u8 * len)58 dcb_i2c_entry(struct nouveau_bios *bios, u8 idx, u8 *ver, u8 *len)
59 {
60 	u8  hdr, cnt;
61 	u16 i2c = dcb_i2c_table(bios, ver, &hdr, &cnt, len);
62 	if (i2c && idx < cnt)
63 		return i2c + hdr + (idx * *len);
64 	return 0x0000;
65 }
66 
67 int
dcb_i2c_parse(struct nouveau_bios * bios,u8 idx,struct dcb_i2c_entry * info)68 dcb_i2c_parse(struct nouveau_bios *bios, u8 idx, struct dcb_i2c_entry *info)
69 {
70 	u8  ver, len;
71 	u16 ent = dcb_i2c_entry(bios, idx, &ver, &len);
72 	if (ent) {
73 		info->type  = nv_ro08(bios, ent + 3);
74 		info->share = DCB_I2C_UNUSED;
75 		if (ver < 0x30) {
76 			info->type &= 0x07;
77 			if (info->type == 0x07)
78 				info->type = DCB_I2C_UNUSED;
79 		}
80 
81 		switch (info->type) {
82 		case DCB_I2C_NV04_BIT:
83 			info->drive = nv_ro08(bios, ent + 0);
84 			info->sense = nv_ro08(bios, ent + 1);
85 			return 0;
86 		case DCB_I2C_NV4E_BIT:
87 			info->drive = nv_ro08(bios, ent + 1);
88 			return 0;
89 		case DCB_I2C_NVIO_BIT:
90 		case DCB_I2C_NVIO_AUX:
91 			info->drive = nv_ro08(bios, ent + 0) & 0x0f;
92 			if (nv_ro08(bios, ent + 1) & 0x01) {
93 				info->share  = nv_ro08(bios, ent + 1) >> 1;
94 				info->share &= 0x0f;
95 			}
96 			return 0;
97 		case DCB_I2C_UNUSED:
98 			return 0;
99 		default:
100 			nv_warn(bios, "unknown i2c type %d\n", info->type);
101 			info->type = DCB_I2C_UNUSED;
102 			return 0;
103 		}
104 	}
105 
106 	if (bios->bmp_offset && idx < 2) {
107 		/* BMP (from v4.0 has i2c info in the structure, it's in a
108 		 * fixed location on earlier VBIOS
109 		 */
110 		if (nv_ro08(bios, bios->bmp_offset + 5) < 4)
111 			ent = 0x0048;
112 		else
113 			ent = 0x0036 + bios->bmp_offset;
114 
115 		if (idx == 0) {
116 			info->drive = nv_ro08(bios, ent + 4);
117 			if (!info->drive) info->drive = 0x3f;
118 			info->sense = nv_ro08(bios, ent + 5);
119 			if (!info->sense) info->sense = 0x3e;
120 		} else
121 		if (idx == 1) {
122 			info->drive = nv_ro08(bios, ent + 6);
123 			if (!info->drive) info->drive = 0x37;
124 			info->sense = nv_ro08(bios, ent + 7);
125 			if (!info->sense) info->sense = 0x36;
126 		}
127 
128 		info->type  = DCB_I2C_NV04_BIT;
129 		info->share = DCB_I2C_UNUSED;
130 		return 0;
131 	}
132 
133 	return -ENOENT;
134 }
135