diff options
Diffstat (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/volt/gpio.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nvkm/subdev/volt/gpio.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/gpio.c b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/gpio.c new file mode 100644 index 000000000000..755fa91bcd09 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/gpio.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright 2013 Red Hat Inc. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
20 | * OTHER DEALINGS IN THE SOFTWARE. | ||
21 | * | ||
22 | * Authors: Ben Skeggs | ||
23 | */ | ||
24 | |||
25 | #include <subdev/volt.h> | ||
26 | #include <subdev/gpio.h> | ||
27 | #include <subdev/bios/gpio.h> | ||
28 | |||
29 | static const u8 tags[] = { | ||
30 | DCB_GPIO_VID0, DCB_GPIO_VID1, DCB_GPIO_VID2, DCB_GPIO_VID3, | ||
31 | DCB_GPIO_VID4, DCB_GPIO_VID5, DCB_GPIO_VID6, DCB_GPIO_VID7, | ||
32 | }; | ||
33 | |||
34 | int | ||
35 | nouveau_voltgpio_get(struct nouveau_volt *volt) | ||
36 | { | ||
37 | struct nouveau_gpio *gpio = nouveau_gpio(volt); | ||
38 | u8 vid = 0; | ||
39 | int i; | ||
40 | |||
41 | for (i = 0; i < ARRAY_SIZE(tags); i++) { | ||
42 | if (volt->vid_mask & (1 << i)) { | ||
43 | int ret = gpio->get(gpio, 0, tags[i], 0xff); | ||
44 | if (ret < 0) | ||
45 | return ret; | ||
46 | vid |= ret << i; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | return vid; | ||
51 | } | ||
52 | |||
53 | int | ||
54 | nouveau_voltgpio_set(struct nouveau_volt *volt, u8 vid) | ||
55 | { | ||
56 | struct nouveau_gpio *gpio = nouveau_gpio(volt); | ||
57 | int i; | ||
58 | |||
59 | for (i = 0; i < ARRAY_SIZE(tags); i++, vid >>= 1) { | ||
60 | if (volt->vid_mask & (1 << i)) { | ||
61 | int ret = gpio->set(gpio, 0, tags[i], 0xff, vid & 1); | ||
62 | if (ret < 0) | ||
63 | return ret; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | int | ||
71 | nouveau_voltgpio_init(struct nouveau_volt *volt) | ||
72 | { | ||
73 | struct nouveau_gpio *gpio = nouveau_gpio(volt); | ||
74 | struct dcb_gpio_func func; | ||
75 | int i; | ||
76 | |||
77 | /* check we have gpio function info for each vid bit. on some | ||
78 | * boards (ie. nvs295) the vid mask has more bits than there | ||
79 | * are valid gpio functions... from traces, nvidia appear to | ||
80 | * just touch the existing ones, so let's mask off the invalid | ||
81 | * bits and continue with life | ||
82 | */ | ||
83 | for (i = 0; i < ARRAY_SIZE(tags); i++) { | ||
84 | if (volt->vid_mask & (1 << i)) { | ||
85 | int ret = gpio->find(gpio, 0, tags[i], 0xff, &func); | ||
86 | if (ret) { | ||
87 | if (ret != -ENOENT) | ||
88 | return ret; | ||
89 | nv_debug(volt, "VID bit %d has no GPIO\n", i); | ||
90 | volt->vid_mask &= ~(1 << i); | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | return 0; | ||
96 | } | ||