xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/gk104.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
1b9ec1424SBen Skeggs /*
2b9ec1424SBen Skeggs  * Copyright 2012 Red Hat Inc.
3b9ec1424SBen Skeggs  *
4b9ec1424SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5b9ec1424SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6b9ec1424SBen Skeggs  * to deal in the Software without restriction, including without limitation
7b9ec1424SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b9ec1424SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9b9ec1424SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10b9ec1424SBen Skeggs  *
11b9ec1424SBen Skeggs  * The above copyright notice and this permission notice shall be included in
12b9ec1424SBen Skeggs  * all copies or substantial portions of the Software.
13b9ec1424SBen Skeggs  *
14b9ec1424SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b9ec1424SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b9ec1424SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b9ec1424SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b9ec1424SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b9ec1424SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b9ec1424SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21b9ec1424SBen Skeggs  *
22b9ec1424SBen Skeggs  * Authors: Ben Skeggs
23b9ec1424SBen Skeggs  */
242aa5eac5SBen Skeggs #include "priv.h"
252aa5eac5SBen Skeggs #include "pad.h"
26b9ec1424SBen Skeggs 
27b9ec1424SBen Skeggs void
gk104_aux_stat(struct nvkm_i2c * i2c,u32 * hi,u32 * lo,u32 * rq,u32 * tx)28b9ec1424SBen Skeggs gk104_aux_stat(struct nvkm_i2c *i2c, u32 *hi, u32 *lo, u32 *rq, u32 *tx)
29b9ec1424SBen Skeggs {
306f227499SBen Skeggs 	struct nvkm_device *device = i2c->subdev.device;
316f227499SBen Skeggs 	u32 intr = nvkm_rd32(device, 0x00dc60);
326f227499SBen Skeggs 	u32 stat = nvkm_rd32(device, 0x00dc68) & intr, i;
33b9ec1424SBen Skeggs 	for (i = 0, *hi = *lo = *rq = *tx = 0; i < 8; i++) {
34b9ec1424SBen Skeggs 		if ((stat & (1 << (i * 4)))) *hi |= 1 << i;
35b9ec1424SBen Skeggs 		if ((stat & (2 << (i * 4)))) *lo |= 1 << i;
36b9ec1424SBen Skeggs 		if ((stat & (4 << (i * 4)))) *rq |= 1 << i;
37b9ec1424SBen Skeggs 		if ((stat & (8 << (i * 4)))) *tx |= 1 << i;
38b9ec1424SBen Skeggs 	}
396f227499SBen Skeggs 	nvkm_wr32(device, 0x00dc60, intr);
40b9ec1424SBen Skeggs }
41b9ec1424SBen Skeggs 
42b9ec1424SBen Skeggs void
gk104_aux_mask(struct nvkm_i2c * i2c,u32 type,u32 mask,u32 data)43b9ec1424SBen Skeggs gk104_aux_mask(struct nvkm_i2c *i2c, u32 type, u32 mask, u32 data)
44b9ec1424SBen Skeggs {
456f227499SBen Skeggs 	struct nvkm_device *device = i2c->subdev.device;
466f227499SBen Skeggs 	u32 temp = nvkm_rd32(device, 0x00dc68), i;
47b9ec1424SBen Skeggs 	for (i = 0; i < 8; i++) {
48b9ec1424SBen Skeggs 		if (mask & (1 << i)) {
49b9ec1424SBen Skeggs 			if (!(data & (1 << i))) {
50b9ec1424SBen Skeggs 				temp &= ~(type << (i * 4));
51b9ec1424SBen Skeggs 				continue;
52b9ec1424SBen Skeggs 			}
53b9ec1424SBen Skeggs 			temp |= type << (i * 4);
54b9ec1424SBen Skeggs 		}
55b9ec1424SBen Skeggs 	}
566f227499SBen Skeggs 	nvkm_wr32(device, 0x00dc68, temp);
57b9ec1424SBen Skeggs }
58b9ec1424SBen Skeggs 
5949bd8da5SBen Skeggs static const struct nvkm_i2c_func
6049bd8da5SBen Skeggs gk104_i2c = {
612aa5eac5SBen Skeggs 	.pad_x_new = gf119_i2c_pad_x_new,
622aa5eac5SBen Skeggs 	.pad_s_new = gf119_i2c_pad_s_new,
63b9ec1424SBen Skeggs 	.aux = 4,
64b9ec1424SBen Skeggs 	.aux_stat = gk104_aux_stat,
65b9ec1424SBen Skeggs 	.aux_mask = gk104_aux_mask,
6649bd8da5SBen Skeggs };
6749bd8da5SBen Skeggs 
6849bd8da5SBen Skeggs int
gk104_i2c_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_i2c ** pi2c)69*c6ce0861SBen Skeggs gk104_i2c_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
70*c6ce0861SBen Skeggs 	      struct nvkm_i2c **pi2c)
7149bd8da5SBen Skeggs {
72*c6ce0861SBen Skeggs 	return nvkm_i2c_new_(&gk104_i2c, device, type, inst, pi2c);
7349bd8da5SBen Skeggs }
74