Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs
0023  */
0024 #include "priv.h"
0025 
0026 #include <core/option.h>
0027 #include <subdev/vga.h>
0028 
0029 u32
0030 nvkm_devinit_mmio(struct nvkm_devinit *init, u32 addr)
0031 {
0032     if (init->func->mmio)
0033         addr = init->func->mmio(init, addr);
0034     return addr;
0035 }
0036 
0037 int
0038 nvkm_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 khz)
0039 {
0040     return init->func->pll_set(init, type, khz);
0041 }
0042 
0043 void
0044 nvkm_devinit_meminit(struct nvkm_devinit *init)
0045 {
0046     if (init->func->meminit)
0047         init->func->meminit(init);
0048 }
0049 
0050 u64
0051 nvkm_devinit_disable(struct nvkm_devinit *init)
0052 {
0053     if (init && init->func->disable)
0054         return init->func->disable(init);
0055     return 0;
0056 }
0057 
0058 int
0059 nvkm_devinit_post(struct nvkm_devinit *init)
0060 {
0061     int ret = 0;
0062     if (init && init->func->post)
0063         ret = init->func->post(init, init->post);
0064     nvkm_devinit_disable(init);
0065     return ret;
0066 }
0067 
0068 static int
0069 nvkm_devinit_fini(struct nvkm_subdev *subdev, bool suspend)
0070 {
0071     struct nvkm_devinit *init = nvkm_devinit(subdev);
0072     /* force full reinit on resume */
0073     if (suspend)
0074         init->post = true;
0075     return 0;
0076 }
0077 
0078 static int
0079 nvkm_devinit_preinit(struct nvkm_subdev *subdev)
0080 {
0081     struct nvkm_devinit *init = nvkm_devinit(subdev);
0082 
0083     if (init->func->preinit)
0084         init->func->preinit(init);
0085 
0086     /* Override the post flag during the first call if NvForcePost is set */
0087     if (init->force_post) {
0088         init->post = init->force_post;
0089         init->force_post = false;
0090     }
0091 
0092     /* unlock the extended vga crtc regs */
0093     nvkm_lockvgac(subdev->device, false);
0094     return 0;
0095 }
0096 
0097 static int
0098 nvkm_devinit_init(struct nvkm_subdev *subdev)
0099 {
0100     struct nvkm_devinit *init = nvkm_devinit(subdev);
0101     if (init->func->init)
0102         init->func->init(init);
0103     return 0;
0104 }
0105 
0106 static void *
0107 nvkm_devinit_dtor(struct nvkm_subdev *subdev)
0108 {
0109     struct nvkm_devinit *init = nvkm_devinit(subdev);
0110     void *data = init;
0111 
0112     if (init->func->dtor)
0113         data = init->func->dtor(init);
0114 
0115     /* lock crtc regs */
0116     nvkm_lockvgac(subdev->device, true);
0117     return data;
0118 }
0119 
0120 static const struct nvkm_subdev_func
0121 nvkm_devinit = {
0122     .dtor = nvkm_devinit_dtor,
0123     .preinit = nvkm_devinit_preinit,
0124     .init = nvkm_devinit_init,
0125     .fini = nvkm_devinit_fini,
0126 };
0127 
0128 void
0129 nvkm_devinit_ctor(const struct nvkm_devinit_func *func, struct nvkm_device *device,
0130           enum nvkm_subdev_type type, int inst, struct nvkm_devinit *init)
0131 {
0132     nvkm_subdev_ctor(&nvkm_devinit, device, type, inst, &init->subdev);
0133     init->func = func;
0134     init->force_post = nvkm_boolopt(device->cfgopt, "NvForcePost", false);
0135 }