drm/nouveau/bios: have strap reads show on devinit spam debug level
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / core / subdev / i2c / nv04.c
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 #include <subdev/i2c.h>
26 #include <subdev/vga.h>
27
28 struct nv04_i2c_priv {
29         struct nouveau_i2c base;
30 };
31
32 struct nv04_i2c_port {
33         struct nouveau_i2c_port base;
34         u8 drive;
35         u8 sense;
36 };
37
38 static void
39 nv04_i2c_drive_scl(struct nouveau_i2c_port *base, int state)
40 {
41         struct nv04_i2c_priv *priv = (void *)nv_object(base)->engine;
42         struct nv04_i2c_port *port = (void *)base;
43         u8 val = nv_rdvgac(priv, 0, port->drive);
44         if (state) val |= 0x20;
45         else       val &= 0xdf;
46         nv_wrvgac(priv, 0, port->drive, val | 0x01);
47 }
48
49 static void
50 nv04_i2c_drive_sda(struct nouveau_i2c_port *base, int state)
51 {
52         struct nv04_i2c_priv *priv = (void *)nv_object(base)->engine;
53         struct nv04_i2c_port *port = (void *)base;
54         u8 val = nv_rdvgac(priv, 0, port->drive);
55         if (state) val |= 0x10;
56         else       val &= 0xef;
57         nv_wrvgac(priv, 0, port->drive, val | 0x01);
58 }
59
60 static int
61 nv04_i2c_sense_scl(struct nouveau_i2c_port *base)
62 {
63         struct nv04_i2c_priv *priv = (void *)nv_object(base)->engine;
64         struct nv04_i2c_port *port = (void *)base;
65         return !!(nv_rdvgac(priv, 0, port->sense) & 0x04);
66 }
67
68 static int
69 nv04_i2c_sense_sda(struct nouveau_i2c_port *base)
70 {
71         struct nv04_i2c_priv *priv = (void *)nv_object(base)->engine;
72         struct nv04_i2c_port *port = (void *)base;
73         return !!(nv_rdvgac(priv, 0, port->sense) & 0x08);
74 }
75
76 static const struct nouveau_i2c_func
77 nv04_i2c_func = {
78         .drive_scl = nv04_i2c_drive_scl,
79         .drive_sda = nv04_i2c_drive_sda,
80         .sense_scl = nv04_i2c_sense_scl,
81         .sense_sda = nv04_i2c_sense_sda,
82 };
83
84 static int
85 nv04_i2c_port_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
86                    struct nouveau_oclass *oclass, void *data, u32 index,
87                    struct nouveau_object **pobject)
88 {
89         struct dcb_i2c_entry *info = data;
90         struct nv04_i2c_port *port;
91         int ret;
92
93         ret = nouveau_i2c_port_create(parent, engine, oclass, index,
94                                       &nouveau_i2c_bit_algo, &nv04_i2c_func,
95                                       &port);
96         *pobject = nv_object(port);
97         if (ret)
98                 return ret;
99
100         port->drive = info->drive;
101         port->sense = info->sense;
102         return 0;
103 }
104
105 static struct nouveau_oclass
106 nv04_i2c_sclass[] = {
107         { .handle = NV_I2C_TYPE_DCBI2C(DCB_I2C_NV04_BIT),
108           .ofuncs = &(struct nouveau_ofuncs) {
109                   .ctor = nv04_i2c_port_ctor,
110                   .dtor = _nouveau_i2c_port_dtor,
111                   .init = _nouveau_i2c_port_init,
112                   .fini = _nouveau_i2c_port_fini,
113           },
114         },
115         {}
116 };
117
118 static int
119 nv04_i2c_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
120               struct nouveau_oclass *oclass, void *data, u32 size,
121               struct nouveau_object **pobject)
122 {
123         struct nv04_i2c_priv *priv;
124         int ret;
125
126         ret = nouveau_i2c_create(parent, engine, oclass, nv04_i2c_sclass, &priv);
127         *pobject = nv_object(priv);
128         if (ret)
129                 return ret;
130
131         return 0;
132 }
133
134 struct nouveau_oclass
135 nv04_i2c_oclass = {
136         .handle = NV_SUBDEV(I2C, 0x04),
137         .ofuncs = &(struct nouveau_ofuncs) {
138                 .ctor = nv04_i2c_ctor,
139                 .dtor = _nouveau_i2c_dtor,
140                 .init = _nouveau_i2c_init,
141                 .fini = _nouveau_i2c_fini,
142         },
143 };