1 | /* $NetBSD: nouveau_subdev_gpio_nvd0.c,v 1.1.1.1 2014/08/06 12:36:30 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 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_gpio_nvd0.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
29 | |
30 | #include "priv.h" |
31 | |
32 | struct nvd0_gpio_priv { |
33 | struct nouveau_gpio base; |
34 | }; |
35 | |
36 | void |
37 | nvd0_gpio_reset(struct nouveau_gpio *gpio, u8 match) |
38 | { |
39 | struct nouveau_bios *bios = nouveau_bios(gpio); |
40 | struct nvd0_gpio_priv *priv = (void *)gpio; |
41 | u8 ver, len; |
42 | u16 entry; |
43 | int ent = -1; |
44 | |
45 | while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) { |
46 | u32 data = nv_ro32(bios, entry); |
47 | u8 line = (data & 0x0000003f); |
48 | u8 defs = !!(data & 0x00000080); |
49 | u8 func = (data & 0x0000ff00) >> 8; |
50 | u8 unk0 = (data & 0x00ff0000) >> 16; |
51 | u8 unk1 = (data & 0x1f000000) >> 24; |
52 | |
53 | if ( func == DCB_GPIO_UNUSED || |
54 | (match != DCB_GPIO_UNUSED && match != func)) |
55 | continue; |
56 | |
57 | gpio->set(gpio, 0, func, line, defs); |
58 | |
59 | nv_mask(priv, 0x00d610 + (line * 4), 0xff, unk0); |
60 | if (unk1--) |
61 | nv_mask(priv, 0x00d740 + (unk1 * 4), 0xff, line); |
62 | } |
63 | } |
64 | |
65 | int |
66 | nvd0_gpio_drive(struct nouveau_gpio *gpio, int line, int dir, int out) |
67 | { |
68 | u32 data = ((dir ^ 1) << 13) | (out << 12); |
69 | nv_mask(gpio, 0x00d610 + (line * 4), 0x00003000, data); |
70 | nv_mask(gpio, 0x00d604, 0x00000001, 0x00000001); /* update? */ |
71 | return 0; |
72 | } |
73 | |
74 | int |
75 | nvd0_gpio_sense(struct nouveau_gpio *gpio, int line) |
76 | { |
77 | return !!(nv_rd32(gpio, 0x00d610 + (line * 4)) & 0x00004000); |
78 | } |
79 | |
80 | static int |
81 | nvd0_gpio_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
82 | struct nouveau_oclass *oclass, void *data, u32 size, |
83 | struct nouveau_object **pobject) |
84 | { |
85 | struct nvd0_gpio_priv *priv; |
86 | int ret; |
87 | |
88 | ret = nouveau_gpio_create(parent, engine, oclass, 32, &priv); |
89 | *pobject = nv_object(priv); |
90 | if (ret) |
91 | return ret; |
92 | |
93 | priv->base.reset = nvd0_gpio_reset; |
94 | priv->base.drive = nvd0_gpio_drive; |
95 | priv->base.sense = nvd0_gpio_sense; |
96 | priv->base.events->priv = priv; |
97 | priv->base.events->enable = nv50_gpio_intr_enable; |
98 | priv->base.events->disable = nv50_gpio_intr_disable; |
99 | nv_subdev(priv)->intr = nv50_gpio_intr; |
100 | return 0; |
101 | } |
102 | |
103 | struct nouveau_oclass |
104 | nvd0_gpio_oclass = { |
105 | .handle = NV_SUBDEV(GPIO, 0xd0), |
106 | .ofuncs = &(struct nouveau_ofuncs) { |
107 | .ctor = nvd0_gpio_ctor, |
108 | .dtor = nv50_gpio_dtor, |
109 | .init = nv50_gpio_init, |
110 | .fini = nv50_gpio_fini, |
111 | }, |
112 | }; |
113 | |