2 * Copyright 2013 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <subdev/timer.h>
29 nvkm_pmu_pgob(struct nvkm_pmu *pmu, bool enable)
31 if (pmu && pmu->func->pgob)
32 pmu->func->pgob(pmu, enable);
36 nvkm_pmu_recv(struct work_struct *work)
38 struct nvkm_pmu *pmu = container_of(work, typeof(*pmu), recv.work);
39 return pmu->func->recv(pmu);
43 nvkm_pmu_send(struct nvkm_pmu *pmu, u32 reply[2],
44 u32 process, u32 message, u32 data0, u32 data1)
46 if (!pmu || !pmu->func->send)
48 return pmu->func->send(pmu, reply, process, message, data0, data1);
52 nvkm_pmu_intr(struct nvkm_subdev *subdev)
54 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
61 nvkm_pmu_fini(struct nvkm_subdev *subdev, bool suspend)
63 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
68 flush_work(&pmu->recv.work);
73 nvkm_pmu_reset(struct nvkm_pmu *pmu)
75 struct nvkm_device *device = pmu->subdev.device;
77 if (!(nvkm_rd32(device, 0x000200) & 0x00002000))
80 /* Inhibit interrupts, and wait for idle. */
81 nvkm_wr32(device, 0x10a014, 0x0000ffff);
82 nvkm_msec(device, 2000,
83 if (!nvkm_rd32(device, 0x10a04c))
88 pmu->func->reset(pmu);
90 /* Wait for IMEM/DMEM scrubbing to be complete. */
91 nvkm_msec(device, 2000,
92 if (!(nvkm_rd32(device, 0x10a10c) & 0x00000006))
100 nvkm_pmu_preinit(struct nvkm_subdev *subdev)
102 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
103 return nvkm_pmu_reset(pmu);
107 nvkm_pmu_init(struct nvkm_subdev *subdev)
109 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
110 int ret = nvkm_pmu_reset(pmu);
111 if (ret == 0 && pmu->func->init)
112 ret = pmu->func->init(pmu);
117 nvkm_pmu_dtor(struct nvkm_subdev *subdev)
119 return nvkm_pmu(subdev);
122 static const struct nvkm_subdev_func
124 .dtor = nvkm_pmu_dtor,
125 .preinit = nvkm_pmu_preinit,
126 .init = nvkm_pmu_init,
127 .fini = nvkm_pmu_fini,
128 .intr = nvkm_pmu_intr,
132 nvkm_pmu_new_(const struct nvkm_pmu_func *func, struct nvkm_device *device,
133 int index, struct nvkm_pmu **ppmu)
135 struct nvkm_pmu *pmu;
136 if (!(pmu = *ppmu = kzalloc(sizeof(*pmu), GFP_KERNEL)))
138 nvkm_subdev_ctor(&nvkm_pmu, device, index, &pmu->subdev);
140 INIT_WORK(&pmu->recv.work, nvkm_pmu_recv);
141 init_waitqueue_head(&pmu->recv.wait);