drm/nouveau/i2c: start hiding subdev-internal interfaces
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / subdev / i2c / nv4e.c
CommitLineData
7dcd060c
BS
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
7dcd060c
BS
25#include <subdev/vga.h>
26
c26fe843
BS
27#include "priv.h"
28
7dcd060c
BS
29struct nv4e_i2c_priv {
30 struct nouveau_i2c base;
31};
32
33struct nv4e_i2c_port {
34 struct nouveau_i2c_port base;
35 u32 addr;
36};
37
38static void
39nv4e_i2c_drive_scl(struct nouveau_i2c_port *base, int state)
40{
41 struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine;
42 struct nv4e_i2c_port *port = (void *)base;
43 nv_mask(priv, port->addr, 0x2f, state ? 0x21 : 0x01);
44}
45
46static void
47nv4e_i2c_drive_sda(struct nouveau_i2c_port *base, int state)
48{
49 struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine;
50 struct nv4e_i2c_port *port = (void *)base;
51 nv_mask(priv, port->addr, 0x1f, state ? 0x11 : 0x01);
52}
53
54static int
55nv4e_i2c_sense_scl(struct nouveau_i2c_port *base)
56{
57 struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine;
58 struct nv4e_i2c_port *port = (void *)base;
59 return !!(nv_rd32(priv, port->addr) & 0x00040000);
60}
61
62static int
63nv4e_i2c_sense_sda(struct nouveau_i2c_port *base)
64{
65 struct nv4e_i2c_priv *priv = (void *)nv_object(base)->engine;
66 struct nv4e_i2c_port *port = (void *)base;
67 return !!(nv_rd32(priv, port->addr) & 0x00080000);
68}
69
70static const struct nouveau_i2c_func
71nv4e_i2c_func = {
72 .drive_scl = nv4e_i2c_drive_scl,
73 .drive_sda = nv4e_i2c_drive_sda,
74 .sense_scl = nv4e_i2c_sense_scl,
75 .sense_sda = nv4e_i2c_sense_sda,
76};
77
78static int
79nv4e_i2c_port_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
80 struct nouveau_oclass *oclass, void *data, u32 index,
81 struct nouveau_object **pobject)
82{
83 struct dcb_i2c_entry *info = data;
84 struct nv4e_i2c_port *port;
85 int ret;
86
87 ret = nouveau_i2c_port_create(parent, engine, oclass, index,
c865534f
IM
88 &nouveau_i2c_bit_algo, &nv4e_i2c_func,
89 &port);
7dcd060c
BS
90 *pobject = nv_object(port);
91 if (ret)
92 return ret;
93
7dcd060c
BS
94 port->addr = 0x600800 + info->drive;
95 return 0;
96}
97
98static struct nouveau_oclass
99nv4e_i2c_sclass[] = {
100 { .handle = NV_I2C_TYPE_DCBI2C(DCB_I2C_NV4E_BIT),
101 .ofuncs = &(struct nouveau_ofuncs) {
102 .ctor = nv4e_i2c_port_ctor,
103 .dtor = _nouveau_i2c_port_dtor,
104 .init = _nouveau_i2c_port_init,
105 .fini = _nouveau_i2c_port_fini,
106 },
107 },
108 {}
109};
110
c26fe843
BS
111struct nouveau_oclass *
112nv4e_i2c_oclass = &(struct nouveau_i2c_impl) {
113 .base.handle = NV_SUBDEV(I2C, 0x4e),
114 .base.ofuncs = &(struct nouveau_ofuncs) {
115 .ctor = _nouveau_i2c_ctor,
7dcd060c
BS
116 .dtor = _nouveau_i2c_dtor,
117 .init = _nouveau_i2c_init,
118 .fini = _nouveau_i2c_fini,
119 },
c26fe843
BS
120 .sclass = nv4e_i2c_sclass,
121}.base;
This page took 0.101678 seconds and 5 git commands to generate.