xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/gk104.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
10ff32977SBen Skeggs /*
20ff32977SBen Skeggs  * Copyright 2012 Red Hat Inc.
30ff32977SBen Skeggs  *
40ff32977SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
50ff32977SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
60ff32977SBen Skeggs  * to deal in the Software without restriction, including without limitation
70ff32977SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80ff32977SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
90ff32977SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
100ff32977SBen Skeggs  *
110ff32977SBen Skeggs  * The above copyright notice and this permission notice shall be included in
120ff32977SBen Skeggs  * all copies or substantial portions of the Software.
130ff32977SBen Skeggs  *
140ff32977SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150ff32977SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160ff32977SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
170ff32977SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
180ff32977SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
190ff32977SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
200ff32977SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
210ff32977SBen Skeggs  *
220ff32977SBen Skeggs  * Authors: Ben Skeggs
230ff32977SBen Skeggs  */
242aa5eac5SBen Skeggs #include "priv.h"
252aa5eac5SBen Skeggs #include "pad.h"
260ff32977SBen Skeggs 
27c9083577SBen 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)
290ff32977SBen 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;
330ff32977SBen Skeggs 	for (i = 0, *hi = *lo = *rq = *tx = 0; i < 8; i++) {
340ff32977SBen Skeggs 		if ((stat & (1 << (i * 4)))) *hi |= 1 << i;
350ff32977SBen Skeggs 		if ((stat & (2 << (i * 4)))) *lo |= 1 << i;
360ff32977SBen Skeggs 		if ((stat & (4 << (i * 4)))) *rq |= 1 << i;
370ff32977SBen Skeggs 		if ((stat & (8 << (i * 4)))) *tx |= 1 << i;
380ff32977SBen Skeggs 	}
396f227499SBen Skeggs 	nvkm_wr32(device, 0x00dc60, intr);
400ff32977SBen Skeggs }
410ff32977SBen Skeggs 
42c9083577SBen 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)
440ff32977SBen Skeggs {
456f227499SBen Skeggs 	struct nvkm_device *device = i2c->subdev.device;
466f227499SBen Skeggs 	u32 temp = nvkm_rd32(device, 0x00dc68), i;
470ff32977SBen Skeggs 	for (i = 0; i < 8; i++) {
480ff32977SBen Skeggs 		if (mask & (1 << i)) {
490ff32977SBen Skeggs 			if (!(data & (1 << i))) {
500ff32977SBen Skeggs 				temp &= ~(type << (i * 4));
510ff32977SBen Skeggs 				continue;
520ff32977SBen Skeggs 			}
530ff32977SBen Skeggs 			temp |= type << (i * 4);
540ff32977SBen Skeggs 		}
550ff32977SBen Skeggs 	}
566f227499SBen Skeggs 	nvkm_wr32(device, 0x00dc68, temp);
570ff32977SBen Skeggs }
580ff32977SBen 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,
630ff32977SBen 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)69c6ce0861SBen Skeggs gk104_i2c_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
70c6ce0861SBen Skeggs 	      struct nvkm_i2c **pi2c)
7149bd8da5SBen Skeggs {
72c6ce0861SBen Skeggs 	return nvkm_i2c_new_(&gk104_i2c, device, type, inst, pi2c);
7349bd8da5SBen Skeggs }
74