1/*	$NetBSD: nouveau_nvkm_subdev_i2c_padgm200.c,v 1.2 2021/12/18 23:45:40 riastradh Exp $	*/
2
3/*
4 * Copyright 2014 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_padgm200.c,v 1.2 2021/12/18 23:45:40 riastradh Exp $");
28
29#include "pad.h"
30#include "aux.h"
31#include "bus.h"
32
33static void
34gm200_i2c_pad_mode(struct nvkm_i2c_pad *pad, enum nvkm_i2c_pad_mode mode)
35{
36	struct nvkm_subdev *subdev = &pad->i2c->subdev;
37	struct nvkm_device *device = subdev->device;
38	const u32 base = (pad->id - NVKM_I2C_PAD_HYBRID(0)) * 0x50;
39
40	switch (mode) {
41	case NVKM_I2C_PAD_OFF:
42		nvkm_mask(device, 0x00d97c + base, 0x00000001, 0x00000001);
43		break;
44	case NVKM_I2C_PAD_I2C:
45		nvkm_mask(device, 0x00d970 + base, 0x0000c003, 0x0000c001);
46		nvkm_mask(device, 0x00d97c + base, 0x00000001, 0x00000000);
47		break;
48	case NVKM_I2C_PAD_AUX:
49		nvkm_mask(device, 0x00d970 + base, 0x0000c003, 0x00000002);
50		nvkm_mask(device, 0x00d97c + base, 0x00000001, 0x00000000);
51		break;
52	default:
53		WARN_ON(1);
54		break;
55	}
56}
57
58static const struct nvkm_i2c_pad_func
59gm200_i2c_pad_s_func = {
60	.bus_new_4 = gf119_i2c_bus_new,
61	.aux_new_6 = gm200_i2c_aux_new,
62	.mode = gm200_i2c_pad_mode,
63};
64
65int
66gm200_i2c_pad_s_new(struct nvkm_i2c *i2c, int id, struct nvkm_i2c_pad **ppad)
67{
68	return nvkm_i2c_pad_new_(&gm200_i2c_pad_s_func, i2c, id, ppad);
69}
70
71static const struct nvkm_i2c_pad_func
72gm200_i2c_pad_x_func = {
73	.bus_new_4 = gf119_i2c_bus_new,
74	.aux_new_6 = gm200_i2c_aux_new,
75};
76
77int
78gm200_i2c_pad_x_new(struct nvkm_i2c *i2c, int id, struct nvkm_i2c_pad **ppad)
79{
80	return nvkm_i2c_pad_new_(&gm200_i2c_pad_x_func, i2c, id, ppad);
81}
82