xref: /linux/drivers/gpu/drm/nouveau/nvif/conn.c (revision 9c93c0b44be36fd5267fb79ae33453f989fbe909)
1 /*
2  * Copyright 2021 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 #include <nvif/conn.h>
23 #include <nvif/disp.h>
24 #include <nvif/printf.h>
25 
26 #include <nvif/class.h>
27 #include <nvif/if0011.h>
28 
29 int
30 nvif_conn_event_ctor(struct nvif_conn *conn, const char *name, nvif_event_func func, u8 types,
31 		     struct nvif_event *event)
32 {
33 	struct {
34 		struct nvif_event_v0 base;
35 		struct nvif_conn_event_v0 conn;
36 	} args;
37 	int ret;
38 
39 	args.conn.version = 0;
40 	args.conn.types = types;
41 
42 	ret = nvif_event_ctor_(&conn->object, name ?: "nvifConnHpd", nvif_conn_id(conn),
43 			       func, true, &args.base, sizeof(args), false, event);
44 	NVIF_DEBUG(&conn->object, "[NEW EVENT:HPD types:%02x]", types);
45 	return ret;
46 }
47 
48 void
49 nvif_conn_dtor(struct nvif_conn *conn)
50 {
51 	nvif_object_dtor(&conn->object);
52 }
53 
54 int
55 nvif_conn_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_conn *conn)
56 {
57 	struct nvif_conn_v0 args;
58 	int ret;
59 
60 	args.version = 0;
61 	args.id = id;
62 
63 	ret = nvif_object_ctor(&disp->object, name ?: "nvifConn", id, NVIF_CLASS_CONN,
64 			       &args, sizeof(args), &conn->object);
65 	NVIF_ERRON(ret, &disp->object, "[NEW conn id:%d]", id);
66 	if (ret)
67 		return ret;
68 
69 	conn->id = id;
70 
71 	switch (args.type) {
72 	case NVIF_CONN_V0_VGA      : conn->info.type = NVIF_CONN_VGA; break;
73 	case NVIF_CONN_V0_TV       : conn->info.type = NVIF_CONN_TV; break;
74 	case NVIF_CONN_V0_DVI_I    : conn->info.type = NVIF_CONN_DVI_I; break;
75 	case NVIF_CONN_V0_DVI_D    : conn->info.type = NVIF_CONN_DVI_D; break;
76 	case NVIF_CONN_V0_LVDS     : conn->info.type = NVIF_CONN_LVDS; break;
77 	case NVIF_CONN_V0_LVDS_SPWG: conn->info.type = NVIF_CONN_LVDS_SPWG; break;
78 	case NVIF_CONN_V0_HDMI     : conn->info.type = NVIF_CONN_HDMI; break;
79 	case NVIF_CONN_V0_DP       : conn->info.type = NVIF_CONN_DP; break;
80 	case NVIF_CONN_V0_EDP      : conn->info.type = NVIF_CONN_EDP; break;
81 	default:
82 		break;
83 	}
84 
85 	return 0;
86 
87 }
88