xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/padg94.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
1b9ec1424SBen Skeggs /*
2b9ec1424SBen Skeggs  * Copyright 2014 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  */
24b9ec1424SBen Skeggs #include "pad.h"
25*2aa5eac5SBen Skeggs #include "aux.h"
26*2aa5eac5SBen Skeggs #include "bus.h"
27b9ec1424SBen Skeggs 
28*2aa5eac5SBen Skeggs void
g94_i2c_pad_mode(struct nvkm_i2c_pad * pad,enum nvkm_i2c_pad_mode mode)29*2aa5eac5SBen Skeggs g94_i2c_pad_mode(struct nvkm_i2c_pad *pad, enum nvkm_i2c_pad_mode mode)
30b9ec1424SBen Skeggs {
31*2aa5eac5SBen Skeggs 	struct nvkm_subdev *subdev = &pad->i2c->subdev;
32*2aa5eac5SBen Skeggs 	struct nvkm_device *device = subdev->device;
33*2aa5eac5SBen Skeggs 	const u32 base = (pad->id - NVKM_I2C_PAD_HYBRID(0)) * 0x50;
34b9ec1424SBen Skeggs 
35*2aa5eac5SBen Skeggs 	switch (mode) {
36*2aa5eac5SBen Skeggs 	case NVKM_I2C_PAD_OFF:
37*2aa5eac5SBen Skeggs 		nvkm_mask(device, 0x00e50c + base, 0x00000001, 0x00000001);
38b9ec1424SBen Skeggs 		break;
39*2aa5eac5SBen Skeggs 	case NVKM_I2C_PAD_I2C:
40*2aa5eac5SBen Skeggs 		nvkm_mask(device, 0x00e500 + base, 0x0000c003, 0x0000c001);
41*2aa5eac5SBen Skeggs 		nvkm_mask(device, 0x00e50c + base, 0x00000001, 0x00000000);
42*2aa5eac5SBen Skeggs 		break;
43*2aa5eac5SBen Skeggs 	case NVKM_I2C_PAD_AUX:
44*2aa5eac5SBen Skeggs 		nvkm_mask(device, 0x00e500 + base, 0x0000c003, 0x00000002);
45*2aa5eac5SBen Skeggs 		nvkm_mask(device, 0x00e50c + base, 0x00000001, 0x00000000);
46*2aa5eac5SBen Skeggs 		break;
47b9ec1424SBen Skeggs 	default:
48*2aa5eac5SBen Skeggs 		WARN_ON(1);
49b9ec1424SBen Skeggs 		break;
50b9ec1424SBen Skeggs 	}
51b9ec1424SBen Skeggs }
52b9ec1424SBen Skeggs 
53*2aa5eac5SBen Skeggs static const struct nvkm_i2c_pad_func
54*2aa5eac5SBen Skeggs g94_i2c_pad_s_func = {
55*2aa5eac5SBen Skeggs 	.bus_new_4 = nv50_i2c_bus_new,
56*2aa5eac5SBen Skeggs 	.aux_new_6 = g94_i2c_aux_new,
57*2aa5eac5SBen Skeggs 	.mode = g94_i2c_pad_mode,
58b9ec1424SBen Skeggs };
59*2aa5eac5SBen Skeggs 
60*2aa5eac5SBen Skeggs int
g94_i2c_pad_s_new(struct nvkm_i2c * i2c,int id,struct nvkm_i2c_pad ** ppad)61*2aa5eac5SBen Skeggs g94_i2c_pad_s_new(struct nvkm_i2c *i2c, int id, struct nvkm_i2c_pad **ppad)
62*2aa5eac5SBen Skeggs {
63*2aa5eac5SBen Skeggs 	return nvkm_i2c_pad_new_(&g94_i2c_pad_s_func, i2c, id, ppad);
64*2aa5eac5SBen Skeggs }
65*2aa5eac5SBen Skeggs 
66*2aa5eac5SBen Skeggs static const struct nvkm_i2c_pad_func
67*2aa5eac5SBen Skeggs g94_i2c_pad_x_func = {
68*2aa5eac5SBen Skeggs 	.bus_new_4 = nv50_i2c_bus_new,
69*2aa5eac5SBen Skeggs 	.aux_new_6 = g94_i2c_aux_new,
70*2aa5eac5SBen Skeggs };
71*2aa5eac5SBen Skeggs 
72*2aa5eac5SBen Skeggs int
g94_i2c_pad_x_new(struct nvkm_i2c * i2c,int id,struct nvkm_i2c_pad ** ppad)73*2aa5eac5SBen Skeggs g94_i2c_pad_x_new(struct nvkm_i2c *i2c, int id, struct nvkm_i2c_pad **ppad)
74*2aa5eac5SBen Skeggs {
75*2aa5eac5SBen Skeggs 	return nvkm_i2c_pad_new_(&g94_i2c_pad_x_func, i2c, id, ppad);
76*2aa5eac5SBen Skeggs }
77