1b7019ac5SIlia Mirkin /* SPDX-License-Identifier: MIT */ 27632b30eSBen Skeggs #ifndef __NVKM_CLK_H__ 37632b30eSBen Skeggs #define __NVKM_CLK_H__ 4f3867f43SBen Skeggs #include <core/subdev.h> 5d3b378c0SKarol Herbst #include <subdev/pci.h> 6f3867f43SBen Skeggs struct nvbios_pll; 77632b30eSBen Skeggs struct nvkm_pll_vals; 8f3867f43SBen Skeggs 90d6f8100SKarol Herbst #define NVKM_CLK_CSTATE_DEFAULT -1 /* POSTed default */ 100d6f8100SKarol Herbst #define NVKM_CLK_CSTATE_BASE -2 /* pstate base */ 110d6f8100SKarol Herbst #define NVKM_CLK_CSTATE_HIGHEST -3 /* highest possible */ 120d6f8100SKarol Herbst 13f3867f43SBen Skeggs enum nv_clk_src { 14f3867f43SBen Skeggs nv_clk_src_crystal, 15f3867f43SBen Skeggs nv_clk_src_href, 16f3867f43SBen Skeggs 17f3867f43SBen Skeggs nv_clk_src_hclk, 18f3867f43SBen Skeggs nv_clk_src_hclkm3, 19f3867f43SBen Skeggs nv_clk_src_hclkm3d2, 20f3867f43SBen Skeggs nv_clk_src_hclkm2d3, /* NVAA */ 21f3867f43SBen Skeggs nv_clk_src_hclkm4, /* NVAA */ 22f3867f43SBen Skeggs nv_clk_src_cclk, /* NVAA */ 23f3867f43SBen Skeggs 24f3867f43SBen Skeggs nv_clk_src_host, 25f3867f43SBen Skeggs 26f3867f43SBen Skeggs nv_clk_src_sppll0, 27f3867f43SBen Skeggs nv_clk_src_sppll1, 28f3867f43SBen Skeggs 29f3867f43SBen Skeggs nv_clk_src_mpllsrcref, 30f3867f43SBen Skeggs nv_clk_src_mpllsrc, 31f3867f43SBen Skeggs nv_clk_src_mpll, 32f3867f43SBen Skeggs nv_clk_src_mdiv, 33f3867f43SBen Skeggs 34f3867f43SBen Skeggs nv_clk_src_core, 35f3867f43SBen Skeggs nv_clk_src_core_intm, 36f3867f43SBen Skeggs nv_clk_src_shader, 37f3867f43SBen Skeggs 38f3867f43SBen Skeggs nv_clk_src_mem, 39f3867f43SBen Skeggs 40f3867f43SBen Skeggs nv_clk_src_gpc, 41f3867f43SBen Skeggs nv_clk_src_rop, 42f3867f43SBen Skeggs nv_clk_src_hubk01, 43f3867f43SBen Skeggs nv_clk_src_hubk06, 44f3867f43SBen Skeggs nv_clk_src_hubk07, 45f3867f43SBen Skeggs nv_clk_src_copy, 46547dd271SBen Skeggs nv_clk_src_pmu, 47f3867f43SBen Skeggs nv_clk_src_disp, 48f3867f43SBen Skeggs nv_clk_src_vdec, 49f3867f43SBen Skeggs 50f3867f43SBen Skeggs nv_clk_src_dom6, 51f3867f43SBen Skeggs 52f3867f43SBen Skeggs nv_clk_src_max, 53f3867f43SBen Skeggs }; 54f3867f43SBen Skeggs 557632b30eSBen Skeggs struct nvkm_cstate { 56f3867f43SBen Skeggs struct list_head head; 57f3867f43SBen Skeggs u8 voltage; 58f3867f43SBen Skeggs u32 domain[nv_clk_src_max]; 59761c8f69SKarol Herbst u8 id; 60f3867f43SBen Skeggs }; 61f3867f43SBen Skeggs 627632b30eSBen Skeggs struct nvkm_pstate { 63f3867f43SBen Skeggs struct list_head head; 64f3867f43SBen Skeggs struct list_head list; /* c-states */ 657632b30eSBen Skeggs struct nvkm_cstate base; 66f3867f43SBen Skeggs u8 pstate; 67f3867f43SBen Skeggs u8 fanspeed; 68d3b378c0SKarol Herbst enum nvkm_pcie_speed pcie_speed; 69d3b378c0SKarol Herbst u8 pcie_width; 70f3867f43SBen Skeggs }; 71f3867f43SBen Skeggs 727632b30eSBen Skeggs struct nvkm_domain { 737632b30eSBen Skeggs enum nv_clk_src name; 747632b30eSBen Skeggs u8 bios; /* 0xff for none */ 757632b30eSBen Skeggs #define NVKM_CLK_DOM_FLAG_CORE 0x01 764b9ce6e7SKarol Herbst #define NVKM_CLK_DOM_FLAG_VPSTATE 0x02 777632b30eSBen Skeggs u8 flags; 787632b30eSBen Skeggs const char *mname; 797632b30eSBen Skeggs int mdiv; 807632b30eSBen Skeggs }; 81f3867f43SBen Skeggs 827632b30eSBen Skeggs struct nvkm_clk { 836625f55cSBen Skeggs const struct nvkm_clk_func *func; 843eca809bSBen Skeggs struct nvkm_subdev subdev; 857632b30eSBen Skeggs 866625f55cSBen Skeggs const struct nvkm_domain *domains; 877632b30eSBen Skeggs struct nvkm_pstate bstate; 88f3867f43SBen Skeggs 89f3867f43SBen Skeggs struct list_head states; 90f3867f43SBen Skeggs int state_nr; 91f3867f43SBen Skeggs 92f3867f43SBen Skeggs struct work_struct work; 93f3867f43SBen Skeggs wait_queue_head_t wait; 94f3867f43SBen Skeggs atomic_t waiting; 95f3867f43SBen Skeggs 96f3867f43SBen Skeggs int pwrsrc; 97f3867f43SBen Skeggs int pstate; /* current */ 98f3867f43SBen Skeggs int ustate_ac; /* user-requested (-1 disabled, -2 perfmon) */ 99f3867f43SBen Skeggs int ustate_dc; /* user-requested (-1 disabled, -2 perfmon) */ 100f3867f43SBen Skeggs int astate; /* perfmon adjustment (base) */ 101f3867f43SBen Skeggs int dstate; /* display adjustment (min+) */ 10261a8b84fSKarol Herbst u8 temp; 103f3867f43SBen Skeggs 104f3867f43SBen Skeggs bool allow_reclock; 1054b9ce6e7SKarol Herbst #define NVKM_CLK_BOOST_NONE 0x0 1064b9ce6e7SKarol Herbst #define NVKM_CLK_BOOST_BIOS 0x1 1074b9ce6e7SKarol Herbst #define NVKM_CLK_BOOST_FULL 0x2 1084b9ce6e7SKarol Herbst u8 boost_mode; 1094b9ce6e7SKarol Herbst u32 base_khz; 1104b9ce6e7SKarol Herbst u32 boost_khz; 111f3867f43SBen Skeggs 112f3867f43SBen Skeggs /*XXX: die, these are here *only* to support the completely 1136625f55cSBen Skeggs * bat-shit insane what-was-nouveau_hw.c code 114f3867f43SBen Skeggs */ 1157632b30eSBen Skeggs int (*pll_calc)(struct nvkm_clk *, struct nvbios_pll *, int clk, 1167632b30eSBen Skeggs struct nvkm_pll_vals *pv); 1177632b30eSBen Skeggs int (*pll_prog)(struct nvkm_clk *, u32 reg1, struct nvkm_pll_vals *pv); 118f3867f43SBen Skeggs }; 119f3867f43SBen Skeggs 1206625f55cSBen Skeggs int nvkm_clk_read(struct nvkm_clk *, enum nv_clk_src); 1217632b30eSBen Skeggs int nvkm_clk_ustate(struct nvkm_clk *, int req, int pwr); 1227632b30eSBen Skeggs int nvkm_clk_astate(struct nvkm_clk *, int req, int rel, bool wait); 1237632b30eSBen Skeggs int nvkm_clk_dstate(struct nvkm_clk *, int req, int rel); 12461a8b84fSKarol Herbst int nvkm_clk_tstate(struct nvkm_clk *, u8 temperature); 125*0196cc65SBen Skeggs int nvkm_clk_pwrsrc(struct nvkm_device *); 1266625f55cSBen Skeggs 12798fd7f83SBen Skeggs int nv04_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 12898fd7f83SBen Skeggs int nv40_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 12998fd7f83SBen Skeggs int nv50_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13098fd7f83SBen Skeggs int g84_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13198fd7f83SBen Skeggs int mcp77_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13298fd7f83SBen Skeggs int gt215_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13398fd7f83SBen Skeggs int gf100_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13498fd7f83SBen Skeggs int gk104_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13598fd7f83SBen Skeggs int gk20a_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 13698fd7f83SBen Skeggs int gm20b_clk_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_clk **); 137f3867f43SBen Skeggs #endif 138