| 1 | /* $NetBSD: nouveau_subdev_bios_mxm.c,v 1.1.1.1 2014/08/06 12:36:29 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 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bios_mxm.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/bios.h> |
| 31 | #include <subdev/bios/bit.h> |
| 32 | #include <subdev/bios/mxm.h> |
| 33 | |
| 34 | u16 |
| 35 | mxm_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr) |
| 36 | { |
| 37 | struct bit_entry x; |
| 38 | |
| 39 | if (bit_entry(bios, 'x', &x)) { |
| 40 | nv_debug(bios, "BIT 'x' table not present\n" ); |
| 41 | return 0x0000; |
| 42 | } |
| 43 | |
| 44 | *ver = x.version; |
| 45 | *hdr = x.length; |
| 46 | if (*ver != 1 || *hdr < 3) { |
| 47 | nv_warn(bios, "BIT 'x' table %d/%d unknown\n" , *ver, *hdr); |
| 48 | return 0x0000; |
| 49 | } |
| 50 | |
| 51 | return x.offset; |
| 52 | } |
| 53 | |
| 54 | /* These map MXM v2.x digital connection values to the appropriate SOR/link, |
| 55 | * hopefully they're correct for all boards within the same chipset... |
| 56 | * |
| 57 | * MXM v3.x VBIOS are nicer and provide pointers to these tables. |
| 58 | */ |
| 59 | static u8 nv84_sor_map[16] = { |
| 60 | 0x00, 0x12, 0x22, 0x11, 0x32, 0x31, 0x11, 0x31, |
| 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 62 | }; |
| 63 | |
| 64 | static u8 nv92_sor_map[16] = { |
| 65 | 0x00, 0x12, 0x22, 0x11, 0x32, 0x31, 0x11, 0x31, |
| 66 | 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 67 | }; |
| 68 | |
| 69 | static u8 nv94_sor_map[16] = { |
| 70 | 0x00, 0x14, 0x24, 0x11, 0x34, 0x31, 0x11, 0x31, |
| 71 | 0x11, 0x31, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 72 | }; |
| 73 | |
| 74 | static u8 nv98_sor_map[16] = { |
| 75 | 0x00, 0x14, 0x12, 0x11, 0x00, 0x31, 0x11, 0x31, |
| 76 | 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 77 | }; |
| 78 | |
| 79 | u8 |
| 80 | mxm_sor_map(struct nouveau_bios *bios, u8 conn) |
| 81 | { |
| 82 | u8 ver, hdr; |
| 83 | u16 mxm = mxm_table(bios, &ver, &hdr); |
| 84 | if (mxm && hdr >= 6) { |
| 85 | u16 map = nv_ro16(bios, mxm + 4); |
| 86 | if (map) { |
| 87 | ver = nv_ro08(bios, map); |
| 88 | if (ver == 0x10) { |
| 89 | if (conn < nv_ro08(bios, map + 3)) { |
| 90 | map += nv_ro08(bios, map + 1); |
| 91 | map += conn; |
| 92 | return nv_ro08(bios, map); |
| 93 | } |
| 94 | |
| 95 | return 0x00; |
| 96 | } |
| 97 | |
| 98 | nv_warn(bios, "unknown sor map v%02x\n" , ver); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (bios->version.chip == 0x84 || bios->version.chip == 0x86) |
| 103 | return nv84_sor_map[conn]; |
| 104 | if (bios->version.chip == 0x92) |
| 105 | return nv92_sor_map[conn]; |
| 106 | if (bios->version.chip == 0x94 || bios->version.chip == 0x96) |
| 107 | return nv94_sor_map[conn]; |
| 108 | if (bios->version.chip == 0x98) |
| 109 | return nv98_sor_map[conn]; |
| 110 | |
| 111 | nv_warn(bios, "missing sor map\n" ); |
| 112 | return 0x00; |
| 113 | } |
| 114 | |
| 115 | u8 |
| 116 | mxm_ddc_map(struct nouveau_bios *bios, u8 port) |
| 117 | { |
| 118 | u8 ver, hdr; |
| 119 | u16 mxm = mxm_table(bios, &ver, &hdr); |
| 120 | if (mxm && hdr >= 8) { |
| 121 | u16 map = nv_ro16(bios, mxm + 6); |
| 122 | if (map) { |
| 123 | ver = nv_ro08(bios, map); |
| 124 | if (ver == 0x10) { |
| 125 | if (port < nv_ro08(bios, map + 3)) { |
| 126 | map += nv_ro08(bios, map + 1); |
| 127 | map += port; |
| 128 | return nv_ro08(bios, map); |
| 129 | } |
| 130 | |
| 131 | return 0x00; |
| 132 | } |
| 133 | |
| 134 | nv_warn(bios, "unknown ddc map v%02x\n" , ver); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* v2.x: directly write port as dcb i2cidx */ |
| 139 | return (port << 4) | port; |
| 140 | } |
| 141 | |