1 /*
2  * Copyright 2012 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 #include "priv.h"
25 
26 #include <core/option.h>
27 #include <subdev/vga.h>
28 
29 int
30 _nvkm_devinit_fini(struct nvkm_object *object, bool suspend)
31 {
32 	struct nvkm_devinit *init = (void *)object;
33 
34 	/* force full reinit on resume */
35 	if (suspend)
36 		init->post = true;
37 
38 	/* unlock the extended vga crtc regs */
39 	nv_lockvgac(init, false);
40 
41 	return nvkm_subdev_fini(&init->subdev, suspend);
42 }
43 
44 int
45 _nvkm_devinit_init(struct nvkm_object *object)
46 {
47 	struct nvkm_devinit_impl *impl = (void *)object->oclass;
48 	struct nvkm_devinit *init = (void *)object;
49 	int ret;
50 
51 	ret = nvkm_subdev_init(&init->subdev);
52 	if (ret)
53 		return ret;
54 
55 	ret = impl->post(&init->subdev, init->post);
56 	if (ret)
57 		return ret;
58 
59 	if (impl->disable)
60 		nv_device(init)->disable_mask |= impl->disable(init);
61 	return 0;
62 }
63 
64 void
65 _nvkm_devinit_dtor(struct nvkm_object *object)
66 {
67 	struct nvkm_devinit *init = (void *)object;
68 
69 	/* lock crtc regs */
70 	nv_lockvgac(init, true);
71 
72 	nvkm_subdev_destroy(&init->subdev);
73 }
74 
75 int
76 nvkm_devinit_create_(struct nvkm_object *parent, struct nvkm_object *engine,
77 		     struct nvkm_oclass *oclass, int size, void **pobject)
78 {
79 	struct nvkm_devinit_impl *impl = (void *)oclass;
80 	struct nvkm_device *device = nv_device(parent);
81 	struct nvkm_devinit *init;
82 	int ret;
83 
84 	ret = nvkm_subdev_create_(parent, engine, oclass, 0, "DEVINIT",
85 				  "init", size, pobject);
86 	init = *pobject;
87 	if (ret)
88 		return ret;
89 
90 	init->post = nvkm_boolopt(device->cfgopt, "NvForcePost", false);
91 	init->meminit = impl->meminit;
92 	init->pll_set = impl->pll_set;
93 	init->mmio    = impl->mmio;
94 	return 0;
95 }
96