Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
i2c.c
Go to the documentation of this file.
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
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
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
69 {
70  u8 ver, len;
71  u16 ent = dcb_i2c_entry(bios, idx, &ver, &len);
72  if (ent) {
73  info->data = nv_ro32(bios, ent + 0);
74  info->type = nv_ro08(bios, ent + 3);
75  if (ver < 0x30) {
76  info->type &= 0x07;
77  if (info->type == 0x07)
78  info->type = 0xff;
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);
92  return 0;
93  case DCB_I2C_UNUSED:
94  return 0;
95  default:
96  nv_warn(bios, "unknown i2c type %d\n", info->type);
97  info->type = DCB_I2C_UNUSED;
98  return 0;
99  }
100  }
101 
102  if (bios->bmp_offset && idx < 2) {
103  /* BMP (from v4.0 has i2c info in the structure, it's in a
104  * fixed location on earlier VBIOS
105  */
106  if (nv_ro08(bios, bios->bmp_offset + 5) < 4)
107  ent = 0x0048;
108  else
109  ent = 0x0036 + bios->bmp_offset;
110 
111  if (idx == 0) {
112  info->drive = nv_ro08(bios, ent + 4);
113  if (!info->drive) info->drive = 0x3f;
114  info->sense = nv_ro08(bios, ent + 5);
115  if (!info->sense) info->sense = 0x3e;
116  } else
117  if (idx == 1) {
118  info->drive = nv_ro08(bios, ent + 6);
119  if (!info->drive) info->drive = 0x37;
120  info->sense = nv_ro08(bios, ent + 7);
121  if (!info->sense) info->sense = 0x36;
122  }
123 
124  info->type = DCB_I2C_NV04_BIT;
125  return 0;
126  }
127 
128  return -ENOENT;
129 }