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