1 /* $NetBSD: nouveau_nvkm_subdev_i2c_g94.c,v 1.4 2021/12/18 23:45:40 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 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_i2c_g94.c,v 1.4 2021/12/18 23:45:40 riastradh Exp $");
28
29 #include "priv.h"
30 #include "pad.h"
31
32 void
g94_aux_stat(struct nvkm_i2c * i2c,u32 * hi,u32 * lo,u32 * rq,u32 * tx)33 g94_aux_stat(struct nvkm_i2c *i2c, u32 *hi, u32 *lo, u32 *rq, u32 *tx)
34 {
35 struct nvkm_device *device = i2c->subdev.device;
36 u32 intr = nvkm_rd32(device, 0x00e06c);
37 u32 stat = nvkm_rd32(device, 0x00e068) & intr, i;
38 for (i = 0, *hi = *lo = *rq = *tx = 0; i < 8; i++) {
39 if ((stat & (1 << (i * 4)))) *hi |= 1 << i;
40 if ((stat & (2 << (i * 4)))) *lo |= 1 << i;
41 if ((stat & (4 << (i * 4)))) *rq |= 1 << i;
42 if ((stat & (8U << (i * 4)))) *tx |= 1 << i;
43 }
44 nvkm_wr32(device, 0x00e06c, intr);
45 }
46
47 void
g94_aux_mask(struct nvkm_i2c * i2c,u32 type,u32 mask,u32 data)48 g94_aux_mask(struct nvkm_i2c *i2c, u32 type, u32 mask, u32 data)
49 {
50 struct nvkm_device *device = i2c->subdev.device;
51 u32 temp = nvkm_rd32(device, 0x00e068), i;
52 for (i = 0; i < 8; i++) {
53 if (mask & (1 << i)) {
54 if (!(data & (1 << i))) {
55 temp &= ~(type << (i * 4));
56 continue;
57 }
58 temp |= type << (i * 4);
59 }
60 }
61 nvkm_wr32(device, 0x00e068, temp);
62 }
63
64 static const struct nvkm_i2c_func
65 g94_i2c = {
66 .pad_x_new = g94_i2c_pad_x_new,
67 .pad_s_new = g94_i2c_pad_s_new,
68 .aux = 4,
69 .aux_stat = g94_aux_stat,
70 .aux_mask = g94_aux_mask,
71 };
72
73 int
g94_i2c_new(struct nvkm_device * device,int index,struct nvkm_i2c ** pi2c)74 g94_i2c_new(struct nvkm_device *device, int index, struct nvkm_i2c **pi2c)
75 {
76 return nvkm_i2c_new_(&g94_i2c, device, index, pi2c);
77 }
78