1 | /* $NetBSD: nouveau_engine_disp_dacnv50.c,v 1.2 2014/08/23 08:03:33 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_engine_disp_dacnv50.c,v 1.2 2014/08/23 08:03:33 riastradh Exp $" ); |
29 | |
30 | #include <core/os.h> |
31 | #include <core/class.h> |
32 | |
33 | #include <subdev/bios.h> |
34 | #include <subdev/bios/dcb.h> |
35 | #include <subdev/timer.h> |
36 | |
37 | #include "nv50.h" |
38 | |
39 | int |
40 | nv50_dac_power(struct nv50_disp_priv *priv, int or, u32 data) |
41 | { |
42 | const u32 stat = (data & NV50_DISP_DAC_PWR_HSYNC) | |
43 | (data & NV50_DISP_DAC_PWR_VSYNC) | |
44 | (data & NV50_DISP_DAC_PWR_DATA) | |
45 | (data & NV50_DISP_DAC_PWR_STATE); |
46 | const u32 doff = (or * 0x800); |
47 | nv_wait(priv, 0x61a004 + doff, 0x80000000, 0x00000000); |
48 | nv_mask(priv, 0x61a004 + doff, 0xc000007f, 0x80000000 | stat); |
49 | nv_wait(priv, 0x61a004 + doff, 0x80000000, 0x00000000); |
50 | return 0; |
51 | } |
52 | |
53 | int |
54 | nv50_dac_sense(struct nv50_disp_priv *priv, int or, u32 loadval) |
55 | { |
56 | const u32 doff = (or * 0x800); |
57 | |
58 | nv_mask(priv, 0x61a004 + doff, 0x807f0000, 0x80150000); |
59 | nv_wait(priv, 0x61a004 + doff, 0x80000000, 0x00000000); |
60 | |
61 | nv_wr32(priv, 0x61a00c + doff, 0x00100000 | loadval); |
62 | mdelay(9); |
63 | udelay(500); |
64 | loadval = nv_mask(priv, 0x61a00c + doff, 0xffffffff, 0x00000000); |
65 | |
66 | nv_mask(priv, 0x61a004 + doff, 0x807f0000, 0x80550000); |
67 | nv_wait(priv, 0x61a004 + doff, 0x80000000, 0x00000000); |
68 | |
69 | nv_debug(priv, "DAC%d sense: 0x%08x\n" , or, loadval); |
70 | if (!(loadval & 0x80000000)) |
71 | return -ETIMEDOUT; |
72 | |
73 | return (loadval & 0x38000000) >> 27; |
74 | } |
75 | |
76 | int |
77 | nv50_dac_mthd(struct nouveau_object *object, u32 mthd, void *args, u32 size) |
78 | { |
79 | struct nv50_disp_priv *priv = (void *)object->engine; |
80 | const u8 or = (mthd & NV50_DISP_DAC_MTHD_OR); |
81 | u32 *data = args; |
82 | int ret; |
83 | |
84 | if (size < sizeof(u32)) |
85 | return -EINVAL; |
86 | |
87 | switch (mthd & ~0x3f) { |
88 | case NV50_DISP_DAC_PWR: |
89 | ret = priv->dac.power(priv, or, data[0]); |
90 | break; |
91 | case NV50_DISP_DAC_LOAD: |
92 | ret = priv->dac.sense(priv, or, data[0]); |
93 | if (ret >= 0) { |
94 | data[0] = ret; |
95 | ret = 0; |
96 | } |
97 | break; |
98 | default: |
99 | BUG_ON(1); |
100 | ret = -EIO; /* XXX GCC */ |
101 | } |
102 | |
103 | return ret; |
104 | } |
105 | |