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 <core/msgqueue.h>
27 #include <subdev/timer.h>
30 nvkm_pmu_pgob(struct nvkm_pmu *pmu, bool enable)
32 if (pmu && pmu->func->pgob)
33 pmu->func->pgob(pmu, enable);
37 nvkm_pmu_recv(struct work_struct *work)
39 struct nvkm_pmu *pmu = container_of(work, typeof(*pmu), recv.work);
40 return pmu->func->recv(pmu);
44 nvkm_pmu_send(struct nvkm_pmu *pmu, u32 reply[2],
45 u32 process, u32 message, u32 data0, u32 data1)
47 if (!pmu || !pmu->func->send)
49 return pmu->func->send(pmu, reply, process, message, data0, data1);
53 nvkm_pmu_intr(struct nvkm_subdev *subdev)
55 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
62 nvkm_pmu_fini(struct nvkm_subdev *subdev, bool suspend)
64 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
69 flush_work(&pmu->recv.work);
74 nvkm_pmu_reset(struct nvkm_pmu *pmu)
76 struct nvkm_device *device = pmu->subdev.device;
78 if (!pmu->func->enabled(pmu))
81 /* Inhibit interrupts, and wait for idle. */
82 nvkm_wr32(device, 0x10a014, 0x0000ffff);
83 nvkm_msec(device, 2000,
84 if (!nvkm_rd32(device, 0x10a04c))
90 pmu->func->reset(pmu);
92 /* Wait for IMEM/DMEM scrubbing to be complete. */
93 nvkm_msec(device, 2000,
94 if (!(nvkm_rd32(device, 0x10a10c) & 0x00000006))
102 nvkm_pmu_preinit(struct nvkm_subdev *subdev)
104 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
105 return nvkm_pmu_reset(pmu);
109 nvkm_pmu_init(struct nvkm_subdev *subdev)
111 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
112 int ret = nvkm_pmu_reset(pmu);
113 if (ret == 0 && pmu->func->init)
114 ret = pmu->func->init(pmu);
119 nvkm_pmu_oneinit(struct nvkm_subdev *subdev)
121 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
122 return nvkm_falcon_v1_new(&pmu->subdev, "PMU", 0x10a000, &pmu->falcon);
126 nvkm_pmu_dtor(struct nvkm_subdev *subdev)
128 struct nvkm_pmu *pmu = nvkm_pmu(subdev);
129 nvkm_msgqueue_del(&pmu->queue);
130 nvkm_falcon_del(&pmu->falcon);
131 return nvkm_pmu(subdev);
134 static const struct nvkm_subdev_func
136 .dtor = nvkm_pmu_dtor,
137 .preinit = nvkm_pmu_preinit,
138 .oneinit = nvkm_pmu_oneinit,
139 .init = nvkm_pmu_init,
140 .fini = nvkm_pmu_fini,
141 .intr = nvkm_pmu_intr,
145 nvkm_pmu_ctor(const struct nvkm_pmu_func *func, struct nvkm_device *device,
146 int index, struct nvkm_pmu *pmu)
148 nvkm_subdev_ctor(&nvkm_pmu, device, index, &pmu->subdev);
150 INIT_WORK(&pmu->recv.work, nvkm_pmu_recv);
151 init_waitqueue_head(&pmu->recv.wait);
156 nvkm_pmu_new_(const struct nvkm_pmu_func *func, struct nvkm_device *device,
157 int index, struct nvkm_pmu **ppmu)
159 struct nvkm_pmu *pmu;
160 if (!(pmu = *ppmu = kzalloc(sizeof(*pmu), GFP_KERNEL)))
162 return nvkm_pmu_ctor(func, device, index, *ppmu);