1 | /* $NetBSD: nouveau_subdev_i2c_nvd0.c,v 1.1.1.1 2014/08/06 12:36:30 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_i2c_nvd0.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
29 | |
30 | #include "nv50.h" |
31 | |
32 | static int |
33 | nvd0_i2c_sense_scl(struct nouveau_i2c_port *base) |
34 | { |
35 | struct nv50_i2c_priv *priv = (void *)nv_object(base)->engine; |
36 | struct nv50_i2c_port *port = (void *)base; |
37 | return !!(nv_rd32(priv, port->addr) & 0x00000010); |
38 | } |
39 | |
40 | static int |
41 | nvd0_i2c_sense_sda(struct nouveau_i2c_port *base) |
42 | { |
43 | struct nv50_i2c_priv *priv = (void *)nv_object(base)->engine; |
44 | struct nv50_i2c_port *port = (void *)base; |
45 | return !!(nv_rd32(priv, port->addr) & 0x00000020); |
46 | } |
47 | |
48 | static const struct nouveau_i2c_func |
49 | nvd0_i2c_func = { |
50 | .acquire = nv94_i2c_acquire, |
51 | .release = nv94_i2c_release, |
52 | .drive_scl = nv50_i2c_drive_scl, |
53 | .drive_sda = nv50_i2c_drive_sda, |
54 | .sense_scl = nvd0_i2c_sense_scl, |
55 | .sense_sda = nvd0_i2c_sense_sda, |
56 | }; |
57 | |
58 | static int |
59 | nvd0_i2c_port_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
60 | struct nouveau_oclass *oclass, void *data, u32 index, |
61 | struct nouveau_object **pobject) |
62 | { |
63 | struct dcb_i2c_entry *info = data; |
64 | struct nv50_i2c_port *port; |
65 | int ret; |
66 | |
67 | ret = nouveau_i2c_port_create(parent, engine, oclass, index, |
68 | &nouveau_i2c_bit_algo, &nvd0_i2c_func, |
69 | &port); |
70 | *pobject = nv_object(port); |
71 | if (ret) |
72 | return ret; |
73 | |
74 | port->state = 0x00000007; |
75 | port->addr = 0x00d014 + (info->drive * 0x20); |
76 | if (info->share != DCB_I2C_UNUSED) { |
77 | port->ctrl = 0x00e500 + (info->share * 0x50); |
78 | port->data = 0x0000e001; |
79 | } |
80 | return 0; |
81 | } |
82 | |
83 | static struct nouveau_oclass |
84 | nvd0_i2c_sclass[] = { |
85 | { .handle = NV_I2C_TYPE_DCBI2C(DCB_I2C_NVIO_BIT), |
86 | .ofuncs = &(struct nouveau_ofuncs) { |
87 | .ctor = nvd0_i2c_port_ctor, |
88 | .dtor = _nouveau_i2c_port_dtor, |
89 | .init = nv50_i2c_port_init, |
90 | .fini = _nouveau_i2c_port_fini, |
91 | }, |
92 | }, |
93 | { .handle = NV_I2C_TYPE_DCBI2C(DCB_I2C_NVIO_AUX), |
94 | .ofuncs = &(struct nouveau_ofuncs) { |
95 | .ctor = nv94_aux_port_ctor, |
96 | .dtor = _nouveau_i2c_port_dtor, |
97 | .init = _nouveau_i2c_port_init, |
98 | .fini = _nouveau_i2c_port_fini, |
99 | }, |
100 | }, |
101 | {} |
102 | }; |
103 | |
104 | static int |
105 | nvd0_i2c_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
106 | struct nouveau_oclass *oclass, void *data, u32 size, |
107 | struct nouveau_object **pobject) |
108 | { |
109 | struct nv50_i2c_priv *priv; |
110 | int ret; |
111 | |
112 | ret = nouveau_i2c_create(parent, engine, oclass, nvd0_i2c_sclass, &priv); |
113 | *pobject = nv_object(priv); |
114 | if (ret) |
115 | return ret; |
116 | |
117 | return 0; |
118 | } |
119 | |
120 | struct nouveau_oclass |
121 | nvd0_i2c_oclass = { |
122 | .handle = NV_SUBDEV(I2C, 0xd0), |
123 | .ofuncs = &(struct nouveau_ofuncs) { |
124 | .ctor = nvd0_i2c_ctor, |
125 | .dtor = _nouveau_i2c_dtor, |
126 | .init = _nouveau_i2c_init, |
127 | .fini = _nouveau_i2c_fini, |
128 | }, |
129 | }; |
130 | |