2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <subdev/i2c.h>
26 #include <subdev/vga.h>
28 struct nv04_i2c_priv {
29 struct nouveau_i2c base;
32 struct nv04_i2c_port {
33 struct nouveau_i2c_port base;
39 nv04_i2c_drive_scl(struct nouveau_i2c_port *base, int state)
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;
46 nv_wrvgac(priv, 0, port->drive, val | 0x01);
50 nv04_i2c_drive_sda(struct nouveau_i2c_port *base, int state)
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;
57 nv_wrvgac(priv, 0, port->drive, val | 0x01);
61 nv04_i2c_sense_scl(struct nouveau_i2c_port *base)
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);
69 nv04_i2c_sense_sda(struct nouveau_i2c_port *base)
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);
76 static const struct nouveau_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,
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)
89 struct dcb_i2c_entry *info = data;
90 struct nv04_i2c_port *port;
93 ret = nouveau_i2c_port_create(parent, engine, oclass, index,
94 &nouveau_i2c_bit_algo, &nv04_i2c_func,
96 *pobject = nv_object(port);
100 port->drive = info->drive;
101 port->sense = info->sense;
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,
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)
123 struct nv04_i2c_priv *priv;
126 ret = nouveau_i2c_create(parent, engine, oclass, nv04_i2c_sclass, &priv);
127 *pobject = nv_object(priv);
134 struct nouveau_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,