clk/tegra: improve code and add DFS support
cover clk/tegra: improve code and add DFS support
This series adds support for GM20B PLL's Maxwell features, namely glitchless switch and (more importantly) DFS support. DFS lets the PLL lower its output speed according to input current variations, making the clock more stable and allowing it to run safely at lower voltage.
All GM20B additions are done in the last patch, which consequently ends up being considerably big ; fortunately, it only consists of code additions thanks to the big refactoring work done by the first 14 patches.
This refactoring makes GK20A's clock code much simpler to read and understand, and flexible enough to be reused by GM20B's when relevant. Note that the sliding and MNP programming had to be re-implemented due to the differences introduced by DFS - trying to factor them out with more abstractions resulted in rather ugly code IMHO.
The first few patches also improve GK20A's volt driver a bit, mainly in order to support a minimum voltage that GM20B requires.
Alexandre Courbot (15):
tegra: fetch gpu_speedo_id
volt/gk20a: make unused public functions static volt/gk20a: constify and name v_scale volt/gk20a: rename constructor volt/gm20b: add support for vmin parameter clk/gk20a: properly protect macro argument clk/gk20a: setup slide once during init clk/gk20a: reorganize MNP calculation a bit clk/gk20a: use nvkm_ functions in slide() clk/gk20a: add and use MNP programming functions clk/gk20a: parameterize PLL settings clk/gk20a: factorize n_lo computation code clk/gk20a: improve MNP programming clk/gk20a: rename constructor
clk/gm20b: add glitchless and DFS support
drm/nouveau/include/nvkm/core/tegra.h | 1 + drm/nouveau/nvkm/engine/device/tegra.c | 1 + drm/nouveau/nvkm/subdev/clk/gk20a.c | 394 +++++++-------- drm/nouveau/nvkm/subdev/clk/gk20a.h | 96 +++- drm/nouveau/nvkm/subdev/clk/gm20b.c | 894 ++++++++++++++++++++++++++++++++- drm/nouveau/nvkm/subdev/volt/gk20a.c | 27 +- drm/nouveau/nvkm/subdev/volt/gk20a.h | 11 +- drm/nouveau/nvkm/subdev/volt/gm20b.c | 40 +- lib/include/nvif/os.h | 1 + 9 files changed, 1216 insertions(+), 249 deletions(-)
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 1/15 tegra: fetch gpu_speedo_id
In reply to a message not in the archiveThe GPU speedo ID is required to select the right clk/volt parameters on GM20B.
--- drm/nouveau/include/nvkm/core/tegra.h | 1 + drm/nouveau/nvkm/engine/device/tegra.c | 1 + lib/include/nvif/os.h | 1 + 3 files changed, 3 insertions(+)
drm/nouveau/include/nvkm/core/tegra.h +1 -0
@@ -28,6 +28,7 @@ struct nvkm_device_tegra { } iommu;int gpu_speedo; +int gpu_speedo_id; };struct nvkm_device_tegra_func {
drm/nouveau/nvkm/engine/device/tegra.c +1 -0
@@ -311,6 +311,7 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func, goto remove; tdev->gpu_speedo = tegra_sku_info.gpu_speedo_value; + tdev->gpu_speedo_id = tegra_sku_info.gpu_speedo_id; ret = nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev, NVKM_DEVICE_TEGRA, pdev->id, NULL, cfg, dbg, detect, mmio, subdev_mask,
lib/include/nvif/os.h +1 -0
@@ -1546,6 +1546,7 @@ reset_control_deassert(struct reset_control *reset)*****************************************************************************/ struct tegra_sku_info {int gpu_speedo_value; +int gpu_speedo_id; };extern struct tegra_sku_info tegra_sku_info;
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 2/15 volt/gk20a: make unused public functions static
In reply to a message not in the archiveNobody else is using these, so make them private.
--- drm/nouveau/nvkm/subdev/volt/gk20a.c | 8 ++++---- drm/nouveau/nvkm/subdev/volt/gk20a.h | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-)
drm/nouveau/nvkm/subdev/volt/gk20a.c +4 -4
@@ -77,7 +77,7 @@ gk20a_volt_get_cvb_t_voltage(int speedo, int temp, int s_scale, int t_scale,return mv; } -int +static int gk20a_volt_calc_voltage (const struct cvb_coef *coef,int speedo) {int mv;
@@ -88,7 +88,7 @@ gk20a_volt_calc_voltage(const struct cvb_coef *coef, int speedo)return mv *1000 ; } -int +static int gk20a_volt_vid_get (struct nvkm_volt *base) {struct gk20a_volt *volt =gk20a_volt (base);
@@ -103,7 +103,7 @@ gk20a_volt_vid_get(struct nvkm_volt *base)return -EINVAL ; } -int +static int gk20a_volt_vid_set (struct nvkm_volt *base,u8 vid) {struct gk20a_volt *volt =gk20a_volt (base);
@@ -113,7 +113,7 @@ gk20a_volt_vid_set(struct nvkm_volt *base, u8 vid)return regulator_set_voltage (volt->vdd, volt->base.vid[vid].uv,1200000 ); } -int +static int gk20a_volt_set_id (struct nvkm_volt *base,u8 id,int condition) {struct gk20a_volt *volt =gk20a_volt (base);
drm/nouveau/nvkm/subdev/volt/gk20a.h +0 -5
@@ -41,9 +41,4 @@ int _gk20a_volt_ctor(struct nvkm_device *device, int index, const struct cvb_coef *coefs, int nb_coefs, struct gk20a_volt *volt); -int gk20a_volt_calc_voltage (const struct cvb_coef *coef,int speedo); -int gk20a_volt_vid_get (struct nvkm_volt *volt); -int gk20a_volt_vid_set (struct nvkm_volt *volt,u8 vid); -int gk20a_volt_set_id (struct nvkm_volt *volt,u8 id,int condition); -#endif
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 3/15 volt/gk20a: constify and name v_scale
In reply to a message not in the archiveGive a name to this constant so we at least get an idea of what it is for.
--- drm/nouveau/nvkm/subdev/volt/gk20a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drm/nouveau/nvkm/subdev/volt/gk20a.c +2 -1
@@ -80,10 +80,11 @@ gk20a_volt_get_cvb_t_voltage(int speedo, int temp, int s_scale, int t_scale,static int gk20a_volt_calc_voltage (const struct cvb_coef *coef,int speedo) { +static const int v_scale =1000 ;int mv; mv =gk20a_volt_get_cvb_t_voltage (speedo,-10 ,100 ,10 , coef); - mv =DIV_ROUND_UP (mv,1000 ); + mv =DIV_ROUND_UP (mv, v_scale);return mv *1000 ; }
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 4/15 volt/gk20a: rename constructor
In reply to a message not in the archiveStrip the _ prefix off the gk20a volt constructor.
--- drm/nouveau/nvkm/subdev/volt/gk20a.c | 10 +++++----- drm/nouveau/nvkm/subdev/volt/gk20a.h | 6 +++--- drm/nouveau/nvkm/subdev/volt/gm20b.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-)
drm/nouveau/nvkm/subdev/volt/gk20a.c +5 -5
@@ -144,9 +144,9 @@ gk20a_volt = { };int -_gk20a_volt_ctor (struct nvkm_device *device,int index, -const struct cvb_coef *coefs,int nb_coefs, -struct gk20a_volt *volt) +gk20a_volt_ctor (struct nvkm_device *device,int index, +const struct cvb_coef *coefs,int nb_coefs, +struct gk20a_volt *volt) {struct nvkm_device_tegra *tdev = device->func->tegra (device);int i, uv;
@@ -181,6 +181,6 @@ gk20a_volt_new(struct nvkm_device *device, int index, struct nvkm_volt **pvolt)return -ENOMEM ; *pvolt = &volt->base; -return _gk20a_volt_ctor (device, index, gk20a_cvb_coef, -ARRAY_SIZE (gk20a_cvb_coef), volt); +return gk20a_volt_ctor (device, index, gk20a_cvb_coef, +ARRAY_SIZE (gk20a_cvb_coef), volt); }
drm/nouveau/nvkm/subdev/volt/gk20a.h +3 -3
@@ -37,8 +37,8 @@ struct gk20a_volt { struct regulator *vdd; }; -int _gk20a_volt_ctor (struct nvkm_device *device,int index, -const struct cvb_coef *coefs,int nb_coefs, -struct gk20a_volt *volt); +int gk20a_volt_ctor (struct nvkm_device *device,int index, +const struct cvb_coef *coefs,int nb_coefs, +struct gk20a_volt *volt);#endif
drm/nouveau/nvkm/subdev/volt/gm20b.c +2 -2
@@ -51,6 +51,6 @@ gm20b_volt_new(struct nvkm_device *device, int index, struct nvkm_volt **pvolt)return -ENOMEM ; *pvolt = &volt->base; -return _gk20a_volt_ctor (device, index, gm20b_cvb_coef, -ARRAY_SIZE (gm20b_cvb_coef), volt); +return gk20a_volt_ctor (device, index, gm20b_cvb_coef, +ARRAY_SIZE (gm20b_cvb_coef), volt); }
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 5/15 volt/gm20b: add support for vmin parameter
In reply to a message not in the archiveChips may be characterized for a minimum voltage. Support this extra parameter and select the appropriate minimum voltage for the detected GPU speedo.
--- drm/nouveau/nvkm/subdev/volt/gk20a.c | 10 +++++----- drm/nouveau/nvkm/subdev/volt/gk20a.h | 2 +- drm/nouveau/nvkm/subdev/volt/gm20b.c | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-)
drm/nouveau/nvkm/subdev/volt/gk20a.c +5 -5
@@ -146,7 +146,7 @@ gk20a_volt = {int gk20a_volt_ctor (struct nvkm_device *device,int index,const struct cvb_coef *coefs,int nb_coefs, -struct gk20a_volt *volt) +int vmin,struct gk20a_volt *volt) {struct nvkm_device_tegra *tdev = device->func->tegra (device);int i, uv;
@@ -161,9 +161,9 @@ gk20a_volt_ctor(struct nvkm_device *device, int index, volt->base.vid_nr = nb_coefs;for (i =0 ; i < volt->base.vid_nr; i++) { volt->base.vid[i].vid = i; - volt->base.vid[i].uv = -gk20a_volt_calc_voltage (&coefs[i], - tdev->gpu_speedo); + volt->base.vid[i].uv =max ( +gk20a_volt_calc_voltage (&coefs[i], tdev->gpu_speedo), + vmin);nvkm_debug (&volt->base.subdev,"%2d: vid=%d, uv=%d\n" , i, volt->base.vid[i].vid, volt->base.vid[i].uv); }
@@ -182,5 +182,5 @@ gk20a_volt_new(struct nvkm_device *device, int index, struct nvkm_volt **pvolt) *pvolt = &volt->base;return gk20a_volt_ctor (device, index, gk20a_cvb_coef, -ARRAY_SIZE (gk20a_cvb_coef), volt); +ARRAY_SIZE (gk20a_cvb_coef),0 , volt); }
drm/nouveau/nvkm/subdev/volt/gk20a.h +1 -1
@@ -39,6 +39,6 @@ struct gk20a_volt {int gk20a_volt_ctor (struct nvkm_device *device,int index,const struct cvb_coef *coefs,int nb_coefs, -struct gk20a_volt *volt); +int vmin,struct gk20a_volt *volt);#endif
drm/nouveau/nvkm/subdev/volt/gm20b.c +16 -1
@@ -41,16 +41,31 @@ const struct cvb_coef gm20b_cvb_coef[] = { /* 921600 */ { 2647676, -106455, 1632 }, }; +const u32 speedo_to_vmin[] = { +/* 0, 1, 2, 3, 4, */ +950000 ,840000 ,818750 ,840000 ,810000 , +}; +int gm20b_volt_new (struct nvkm_device *device,int index,struct nvkm_volt **pvolt) { +struct nvkm_device_tegra *tdev = device->func->tegra (device);struct gk20a_volt *volt; +u32 vmin; + +if (tdev->gpu_speedo_id >=ARRAY_SIZE (speedo_to_vmin)) { +nvdev_error (device,"unsupported speedo %d\n" , + tdev->gpu_speedo_id); +return -EINVAL ; + } volt =kzalloc (sizeof (*volt),GFP_KERNEL );if (!volt)return -ENOMEM ; *pvolt = &volt->base; + vmin = speedo_to_vmin[tdev->gpu_speedo_id]; +return gk20a_volt_ctor (device, index, gm20b_cvb_coef, -ARRAY_SIZE (gm20b_cvb_coef), volt); +ARRAY_SIZE (gm20b_cvb_coef), vmin, volt); }
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 6/15 clk/gk20a: properly protect macro argument
In reply to a message not in the archive--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 2 +- drm/nouveau/nvkm/subdev/clk/gm20b.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +1 -1
@@ -31,7 +31,7 @@#define KHZ (1000)#define MHZ (KHZ * 1000) -#define MASK (w) ((1 << w) - 1) +#define MASK (w) ((1 << (w)) - 1)#define GPCPLL_CFG (SYS_GPCPLL_CFG_BASE + 0)#define GPCPLL_CFG_ENABLE BIT(0)
drm/nouveau/nvkm/subdev/clk/gm20b.c +1 -1
@@ -29,7 +29,7 @@#define KHZ (1000)#define MHZ (KHZ * 1000) -#define MASK (w) ((1 << w) - 1) +#define MASK (w) ((1 << (w)) - 1)#define BYPASSCTRL_SYS (SYS_GPCPLL_CFG_BASE + 0x340)#define BYPASSCTRL_SYS_GPCPLL_SHIFT 0
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 7/15 clk/gk20a: setup slide once during init
In reply to a message not in the archiveSlide setup needs to be performed only once, during init. Also use the proper parameters for different clock speeds.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 46 ++++++++++++++++++++++++++++++++----- drm/nouveau/nvkm/subdev/clk/gk20a.h | 2 ++ drm/nouveau/nvkm/subdev/clk/gm20b.c | 4 ++++ 3 files changed, 46 insertions(+), 6 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +40 -6
@@ -274,12 +274,6 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n)if (n == ((val >>GPCPLL_COEFF_N_SHIFT ) &MASK (GPCPLL_COEFF_N_WIDTH )))return 0 ; -/* setup */ -nvkm_mask (device,GPCPLL_CFG2 ,0xff <<GPCPLL_CFG2_PLL_STEPA_SHIFT , -0x2b <<GPCPLL_CFG2_PLL_STEPA_SHIFT ); -nvkm_mask (device,GPCPLL_CFG3 ,0xff <<GPCPLL_CFG3_PLL_STEPB_SHIFT , -0xb <<GPCPLL_CFG3_PLL_STEPB_SHIFT ); -/* pll slowdown mode */ nvkm_mask(device, GPCPLL_NDIV_SLOWDOWN, BIT(GPCPLL_NDIV_SLOWDOWN_SLOWDOWN_USING_PLL_SHIFT),
@@ -581,6 +575,42 @@ gk20a_clk_tidy(struct nvkm_clk *base) { } +int +gk20a_clk_setup_slide (struct gk20a_clk *clk) +{ +struct nvkm_subdev *subdev = &clk->base.subdev; +struct nvkm_device *device = subdev->device; +u32 step_a, step_b; + +switch (clk->parent_rate) { +case 12000000 : +case 12800000 : +case 13000000 : + step_a =0x2b ; + step_b =0x0b ; +break ; +case 19200000 : + step_a =0x12 ; + step_b =0x08 ; +break ; +case 38400000 : + step_a =0x04 ; + step_b =0x05 ; +break ; +default : +nvkm_error (subdev,"invalid parent clock rate %u KHz" , + clk->parent_rate /KHZ ); +return -EINVAL ; + } + +nvkm_mask (device,GPCPLL_CFG2 ,0xff <<GPCPLL_CFG2_PLL_STEPA_SHIFT , + step_a <<GPCPLL_CFG2_PLL_STEPA_SHIFT ); +nvkm_mask (device,GPCPLL_CFG3 ,0xff <<GPCPLL_CFG3_PLL_STEPB_SHIFT , + step_b <<GPCPLL_CFG3_PLL_STEPB_SHIFT ); + +return 0 ; +} +void gk20a_clk_fini (struct nvkm_clk *base) {
@@ -617,6 +647,10 @@ gk20a_clk_init(struct nvkm_clk *base)nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_INIT_MASK ,GPC2CLK_OUT_INIT_VAL ); + ret =gk20a_clk_setup_slide (clk); +if (ret) +return ret; +/* Start with lowest frequency */ base->func->calc (base, &base->func->pstates[0 ].base); ret = base->func->prog (&clk->base);
drm/nouveau/nvkm/subdev/clk/gk20a.h +2 -0
@@ -62,4 +62,6 @@ int gk20a_clk_calc(struct nvkm_clk *, struct nvkm_cstate *);int gk20a_clk_prog (struct nvkm_clk *);void gk20a_clk_tidy (struct nvkm_clk *); +int gk20a_clk_setup_slide (struct gk20a_clk *); +#endif
drm/nouveau/nvkm/subdev/clk/gm20b.c +4 -0
@@ -144,6 +144,10 @@ gm20b_clk_init(struct nvkm_clk *base)struct nvkm_device *device = subdev->device;int ret; + ret =gk20a_clk_setup_slide (clk); +if (ret) +return ret; +/* Set the global bypass control to VCO */ nvkm_mask(device, BYPASSCTRL_SYS, MASK(BYPASSCTRL_SYS_GPCPLL_WIDTH) << BYPASSCTRL_SYS_GPCPLL_SHIFT,
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 8/15 clk/gk20a: reorganize MNP calculation a bit
In reply to a message not in the archiveMove variables declarations to their actual scope of use, and simplify code a bit.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +5 -8
@@ -163,16 +163,13 @@ gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate) target_clk_f = rate *2 /KHZ ; ref_clk_f = clk->parent_rate /KHZ ; - max_vco_f = clk->params->max_vco; + target_vco_f = target_clk_f + target_clk_f /50 ; + max_vco_f =max (clk->params->max_vco, target_vco_f); min_vco_f = clk->params->min_vco; best_m = clk->params->max_m; best_n = clk->params->min_n; best_pl = clk->params->min_pl; - target_vco_f = target_clk_f + target_clk_f /50 ; -if (max_vco_f < target_vco_f) - max_vco_f = target_vco_f; -/* min_pl <= high_pl <= max_pl */ high_pl = (max_vco_f + target_vco_f -1 ) / target_vco_f; high_pl =min (high_pl, clk->params->max_pl);
@@ -195,9 +192,7 @@ gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate) target_vco_f = target_clk_f * clk->pl_to_div (pl);for (m = clk->params->min_m; m <= clk->params->max_m; m++) { -u32 u_f, vco_f; - - u_f = ref_clk_f / m; +u32 u_f = ref_clk_f / m;if (u_f < clk->params->min_u)break ;
@@ -211,6 +206,8 @@ gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate)break ;for (; n <= n2; n++) { +u32 vco_f; +if (n < clk->params->min_n)continue ;if (n > clk->params->max_n)
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 9/15 clk/gk20a: use nvkm_ functions in slide()
In reply to a message not in the archive--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +10 -16
@@ -263,7 +263,7 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n)struct nvkm_subdev *subdev = &clk->base.subdev;struct nvkm_device *device = subdev->device;u32 val; -int ramp_timeout; +int ret =0 ;/* get old coefficients */ val =nvkm_rd32 (device,GPCPLL_COEFF );
@@ -284,17 +284,16 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n)nvkm_wr32 (device,GPCPLL_COEFF , val);/* dynamic ramp to new ndiv */ - val =nvkm_rd32 (device,GPCPLL_NDIV_SLOWDOWN ); - val |=0x1 <<GPCPLL_NDIV_SLOWDOWN_EN_DYNRAMP_SHIFT ;udelay (1 ); -nvkm_wr32 (device,GPCPLL_NDIV_SLOWDOWN , val); +nvkm_mask (device,GPCPLL_NDIV_SLOWDOWN , +BIT (GPCPLL_NDIV_SLOWDOWN_EN_DYNRAMP_SHIFT ), +BIT (GPCPLL_NDIV_SLOWDOWN_EN_DYNRAMP_SHIFT )); -for (ramp_timeout =500 ; ramp_timeout >0 ; ramp_timeout--) { -udelay (1 ); - val =nvkm_rd32 (device,GPC_BCAST_NDIV_SLOWDOWN_DEBUG ); -if (val &GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_MASK ) -break ; - } +/* wait for ramping to complete */ +if (nvkm_wait_usec (device,500 ,GPC_BCAST_NDIV_SLOWDOWN_DEBUG , +GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_MASK , +GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_MASK ) <0 ) + ret = -ETIMEDOUT ;/* exit slowdown mode */ nvkm_mask(device, GPCPLL_NDIV_SLOWDOWN,
@@ -302,12 +301,7 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n) BIT(GPCPLL_NDIV_SLOWDOWN_EN_DYNRAMP_SHIFT), 0);nvkm_rd32 (device,GPCPLL_NDIV_SLOWDOWN ); -if (ramp_timeout <=0 ) { -nvkm_error (subdev,"gpcpll dynamic ramp timeout\n" ); -return -ETIMEDOUT ; - } - -return 0 ; +return ret; } static void
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 10/15 clk/gk20a: add and use MNP programming functions
In reply to a message not in the archiveAdd relevant functions to work with the gk20a_pll structure and use them where they ought to be instead of directly manipulating registers.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +22 -13
@@ -136,6 +136,18 @@ gk20a_pllg_read_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll) pll->pl = (val >>GPCPLL_COEFF_P_SHIFT ) &MASK (GPCPLL_COEFF_P_WIDTH ); } +static void +gk20a_pllg_write_mnp (struct gk20a_clk *clk,const struct gk20a_pll *pll) +{ +struct nvkm_device *device = clk->base.subdev.device; +u32 val; + + val = (pll->m &MASK (GPCPLL_COEFF_M_WIDTH )) <<GPCPLL_COEFF_M_SHIFT ; + val |= (pll->n &MASK (GPCPLL_COEFF_N_WIDTH )) <<GPCPLL_COEFF_N_SHIFT ; + val |= (pll->pl &MASK (GPCPLL_COEFF_P_WIDTH )) <<GPCPLL_COEFF_P_SHIFT ; +nvkm_wr32 (device,GPCPLL_COEFF , val); +} +static u32 gk20a_pllg_calc_rate (struct gk20a_clk *clk) {
@@ -262,13 +274,13 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n) {struct nvkm_subdev *subdev = &clk->base.subdev;struct nvkm_device *device = subdev->device; -u32 val; +struct gk20a_pll pll;int ret =0 ;/* get old coefficients */ - val =nvkm_rd32 (device,GPCPLL_COEFF ); +gk20a_pllg_read_mnp (clk, &pll);/* do nothing if NDIV is the same */ -if (n == ((val >>GPCPLL_COEFF_N_SHIFT ) &MASK (GPCPLL_COEFF_N_WIDTH ))) +if (n == pll.n)return 0 ;/* pll slowdown mode */
@@ -277,11 +289,9 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n) BIT(GPCPLL_NDIV_SLOWDOWN_SLOWDOWN_USING_PLL_SHIFT));/* new ndiv ready for ramp */ - val =nvkm_rd32 (device,GPCPLL_COEFF ); - val &= ~(MASK (GPCPLL_COEFF_N_WIDTH ) <<GPCPLL_COEFF_N_SHIFT ); - val |= (n &MASK (GPCPLL_COEFF_N_WIDTH )) <<GPCPLL_COEFF_N_SHIFT ; + pll.n = n;udelay (1 ); -nvkm_wr32 (device,GPCPLL_COEFF , val); +gk20a_pllg_write_mnp (clk, &pll);/* dynamic ramp to new ndiv */ udelay (1 );
@@ -377,12 +387,11 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)nvkm_debug (subdev,"%s: m=%d n=%d pl=%d\n" , __func__, clk->pll.m, clk->pll.n, clk->pll.pl); - n_lo =DIV_ROUND_UP (clk->pll.m * clk->params->min_vco, - clk->parent_rate /KHZ ); - val = clk->pll.m <<GPCPLL_COEFF_M_SHIFT ; - val |= (allow_slide ? n_lo : clk->pll.n) <<GPCPLL_COEFF_N_SHIFT ; - val |= clk->pll.pl <<GPCPLL_COEFF_P_SHIFT ; -nvkm_wr32 (device,GPCPLL_COEFF , val); + old_pll = clk->pll; +if (allow_slide) + old_pll.n =DIV_ROUND_UP (clk->pll.m * clk->params->min_vco, + clk->parent_rate /KHZ ); +gk20a_pllg_write_mnp (clk, &old_pll);gk20a_pllg_enable (clk);
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 11/15 clk/gk20a: parameterize PLL settings
In reply to a message not in the archiveMake functions manipulating PLL settings take them as an argument, instead of assuming we want to work on the copy in the gk20a_clk structure. This makes these functions more flexible, which we will need in GM20B.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +27 -24
@@ -149,19 +149,20 @@ gk20a_pllg_write_mnp(struct gk20a_clk *clk, const struct gk20a_pll *pll) }static u32 -gk20a_pllg_calc_rate (struct gk20a_clk *clk) +gk20a_pllg_calc_rate (struct gk20a_clk *clk,struct gk20a_pll *pll) {u32 rate;u32 divider; - rate = clk->parent_rate * clk->pll.n; - divider = clk->pll.m * clk->pl_to_div (clk->pll.pl); + rate = clk->parent_rate * pll->n; + divider = pll->m * clk->pl_to_div (pll->pl);return rate / divider /2 ; }static int -gk20a_pllg_calc_mnp (struct gk20a_clk *clk,unsigned long rate) +gk20a_pllg_calc_mnp (struct gk20a_clk *clk,unsigned long rate, +struct gk20a_pll *pll) {struct nvkm_subdev *subdev = &clk->base.subdev;u32 target_clk_f, ref_clk_f, target_freq;
@@ -256,16 +257,16 @@ found_match:"no best match for target @ %dMHz on gpc_pll" , target_clk_f / KHZ); - clk->pll.m = best_m; - clk->pll.n = best_n; - clk->pll.pl = best_pl; + pll->m = best_m; + pll->n = best_n; + pll->pl = best_pl; - target_freq =gk20a_pllg_calc_rate (clk); + target_freq =gk20a_pllg_calc_rate (clk, pll);nvkm_debug (subdev, -"actual target freq %d MHz, M %d, N %d, PL %d(div%d)\n" , - target_freq /MHZ , clk->pll.m, clk->pll.n, clk->pll.pl, - clk->pl_to_div (clk->pll.pl)); +"actual target freq %d KHz, M %d, N %d, PL %d(div%d)\n" , + target_freq /KHZ , pll->m, pll->n, pll->pl, + clk->pl_to_div (pll->pl));return 0 ; }
@@ -333,7 +334,8 @@ gk20a_pllg_disable(struct gk20a_clk *clk) }static int -_gk20a_pllg_program_mnp (struct gk20a_clk *clk,bool allow_slide) +_gk20a_pllg_program_mnp (struct gk20a_clk *clk,struct gk20a_pll *pll, +bool allow_slide) {struct nvkm_subdev *subdev = &clk->base.subdev;struct nvkm_device *device = subdev->device;
@@ -346,9 +348,9 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)/* do NDIV slide if there is no change in M and PL */ cfg =nvkm_rd32 (device,GPCPLL_CFG ); -if (allow_slide && clk->pll.m == old_pll.m && - clk->pll.pl == old_pll.pl && (cfg &GPCPLL_CFG_ENABLE )) { -return gk20a_pllg_slide (clk, clk->pll.n); +if (allow_slide && pll->m == old_pll.m && + pll->pl == old_pll.pl && (cfg &GPCPLL_CFG_ENABLE )) { +return gk20a_pllg_slide (clk, pll->n); }/* slide down to NDIV_LO */
@@ -385,11 +387,11 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)gk20a_pllg_disable (clk);nvkm_debug (subdev,"%s: m=%d n=%d pl=%d\n" , __func__, - clk->pll.m, clk->pll.n, clk->pll.pl); + pll->m, pll->n, pll->pl); - old_pll = clk->pll; + old_pll = *pll;if (allow_slide) - old_pll.n =DIV_ROUND_UP (clk->pll.m * clk->params->min_vco, + old_pll.n =DIV_ROUND_UP (pll->m * clk->params->min_vco, clk->parent_rate /KHZ );gk20a_pllg_write_mnp (clk, &old_pll);
@@ -425,7 +427,7 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide) }/* slide up to new NDIV */ -return allow_slide ?gk20a_pllg_slide (clk, clk->pll.n) :0 ; +return allow_slide ?gk20a_pllg_slide (clk, pll->n) :0 ; } static int
@@ -433,9 +435,9 @@ gk20a_pllg_program_mnp(struct gk20a_clk *clk) {int err; - err =_gk20a_pllg_program_mnp (clk, true); + err =_gk20a_pllg_program_mnp (clk, &clk->pll, true);if (err) - err =_gk20a_pllg_program_mnp (clk, false); + err =_gk20a_pllg_program_mnp (clk, &clk->pll, false);return err; }
@@ -540,13 +542,14 @@ gk20a_clk_read(struct nvkm_clk *base, enum nv_clk_src src)struct gk20a_clk *clk =gk20a_clk (base);struct nvkm_subdev *subdev = &clk->base.subdev;struct nvkm_device *device = subdev->device; +struct gk20a_pll pll;switch (src) {case nv_clk_src_crystal:return device->crystal;case nv_clk_src_gpc: -gk20a_pllg_read_mnp (clk, &clk->pll); -return gk20a_pllg_calc_rate (clk) /GK20A_CLK_GPC_MDIV ; +gk20a_pllg_read_mnp (clk, &pll); +return gk20a_pllg_calc_rate (clk, &pll) /GK20A_CLK_GPC_MDIV ;default :nvkm_error (subdev,"invalid clock source %d\n" , src);return -EINVAL ;
@@ -559,7 +562,7 @@ gk20a_clk_calc(struct nvkm_clk *base, struct nvkm_cstate *cstate)struct gk20a_clk *clk =gk20a_clk (base);return gk20a_pllg_calc_mnp (clk, cstate->domain[nv_clk_src_gpc] * -GK20A_CLK_GPC_MDIV ); +GK20A_CLK_GPC_MDIV , &clk->pll); }int
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 12/15 clk/gk20a: factorize n_lo computation code
In reply to a message not in the archiveUse a dedicated function instead of always calculating n_lo on the fly.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +10 -9
@@ -160,6 +160,13 @@ gk20a_pllg_calc_rate(struct gk20a_clk *clk, struct gk20a_pll *pll)return rate / divider /2 ; } +static u32 +gk20a_pllg_n_lo (struct gk20a_clk *clk,struct gk20a_pll *pll) +{ +return DIV_ROUND_UP (pll->m * clk->params->min_vco, + clk->parent_rate /KHZ ); +} +static int gk20a_pllg_calc_mnp (struct gk20a_clk *clk,unsigned long rate,struct gk20a_pll *pll)
@@ -341,7 +348,6 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll,struct nvkm_device *device = subdev->device;u32 val, cfg;struct gk20a_pll old_pll; -u32 n_lo;/* get old coefficients */ gk20a_pllg_read_mnp (clk, &old_pll);
@@ -357,10 +363,7 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll,if (allow_slide && (cfg &GPCPLL_CFG_ENABLE )) {int ret; - n_lo =DIV_ROUND_UP (old_pll.m * clk->params->min_vco, - clk->parent_rate /KHZ ); - ret =gk20a_pllg_slide (clk, n_lo); - + ret =gk20a_pllg_slide (clk,gk20a_pllg_n_lo (clk, &old_pll));if (ret)return ret; }
@@ -391,8 +394,7 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll, old_pll = *pll;if (allow_slide) - old_pll.n =DIV_ROUND_UP (pll->m * clk->params->min_vco, - clk->parent_rate /KHZ ); + old_pll.n =gk20a_pllg_n_lo (clk, pll);gk20a_pllg_write_mnp (clk, &old_pll);gk20a_pllg_enable (clk);
@@ -628,8 +630,7 @@ gk20a_clk_fini(struct nvkm_clk *base)u32 n_lo;gk20a_pllg_read_mnp (clk, &pll); - n_lo =DIV_ROUND_UP (pll.m * clk->params->min_vco, - clk->parent_rate /KHZ ); + n_lo =gk20a_pllg_n_lo (clk, &pll);gk20a_pllg_slide (clk, n_lo); }
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 13/15 clk/gk20a: improve MNP programming
In reply to a message not in the archiveSplit the MNP programming function into two functions for the cases where we allow sliding or not, instead of making it take a parameter for this. This results in less conditionals in the code and makes it easier to read.
Also make the MNP programming functions take the PLL parameters as arguments, and move bits of code to more relevant places (previous programming tended to be just-in-time, which added more conditionnals in the code).
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 185 +++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 89 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +96 -89
@@ -72,6 +72,7 @@#define GPC2CLK_OUT_VCODIV_WIDTH 6#define GPC2CLK_OUT_VCODIV_SHIFT 8#define GPC2CLK_OUT_VCODIV1 0 +#define GPC2CLK_OUT_VCODIV2 2#define GPC2CLK_OUT_VCODIV_MASK (MASK(GPC2CLK_OUT_VCODIV_WIDTH) << \ GPC2CLK_OUT_VCODIV_SHIFT)#define GPC2CLK_OUT_BYPDIV_WIDTH 6
@@ -322,13 +323,42 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n)return ret; } -static void +static bool +gk20a_pllg_is_enabled (struct gk20a_clk *clk) +{ +struct nvkm_device *device = clk->base.subdev.device; +u32 val; + + val =nvkm_rd32 (device,GPCPLL_CFG ); +return val &GPCPLL_CFG_ENABLE ; +} + +static int gk20a_pllg_enable (struct gk20a_clk *clk) {struct nvkm_device *device = clk->base.subdev.device; +u32 val;nvkm_mask (device,GPCPLL_CFG ,GPCPLL_CFG_ENABLE ,GPCPLL_CFG_ENABLE );nvkm_rd32 (device,GPCPLL_CFG ); + +/* enable lock detection */ + val =nvkm_rd32 (device,GPCPLL_CFG ); +if (val &GPCPLL_CFG_LOCK_DET_OFF ) { + val &= ~GPCPLL_CFG_LOCK_DET_OFF ; +nvkm_wr32 (device,GPCPLL_CFG , val); + } + +/* wait for lock */ +if (nvkm_wait_usec (device,300 ,GPCPLL_CFG ,GPCPLL_CFG_LOCK , +GPCPLL_CFG_LOCK ) <0 ) +return -ETIMEDOUT ; + +/* switch to VCO mode */ +nvkm_mask (device,SEL_VCO ,BIT (SEL_VCO_GPC2CLK_OUT_SHIFT ), +BIT (SEL_VCO_GPC2CLK_OUT_SHIFT )); + +return 0 ; } static void
@@ -336,112 +366,81 @@ gk20a_pllg_disable(struct gk20a_clk *clk) {struct nvkm_device *device = clk->base.subdev.device; +/* put PLL in bypass before disabling it */ +nvkm_mask (device,SEL_VCO ,BIT (SEL_VCO_GPC2CLK_OUT_SHIFT ),0 ); +nvkm_mask (device,GPCPLL_CFG ,GPCPLL_CFG_ENABLE ,0 );nvkm_rd32 (device,GPCPLL_CFG ); }static int -_gk20a_pllg_program_mnp (struct gk20a_clk *clk,struct gk20a_pll *pll, -bool allow_slide) +gk20a_pllg_program_mnp (struct gk20a_clk *clk,const struct gk20a_pll *pll) {struct nvkm_subdev *subdev = &clk->base.subdev;struct nvkm_device *device = subdev->device; -u32 val, cfg; -struct gk20a_pll old_pll; - -/* get old coefficients */ -gk20a_pllg_read_mnp (clk, &old_pll); - -/* do NDIV slide if there is no change in M and PL */ - cfg =nvkm_rd32 (device,GPCPLL_CFG ); -if (allow_slide && pll->m == old_pll.m && - pll->pl == old_pll.pl && (cfg &GPCPLL_CFG_ENABLE )) { -return gk20a_pllg_slide (clk, pll->n); - } +struct gk20a_pll cur_pll; +int ret; -/* slide down to NDIV_LO */ -if (allow_slide && (cfg &GPCPLL_CFG_ENABLE )) { -int ret; +gk20a_pllg_read_mnp (clk, &cur_pll); - ret =gk20a_pllg_slide (clk,gk20a_pllg_n_lo (clk, &old_pll)); -if (ret) -return ret; - } - -/* split FO-to-bypass jump in halfs by setting out divider 1:2 */ +/* split VCO-to-bypass jump in half by setting out divider 1:2 */ nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_VCODIV_MASK , -0x2 <<GPC2CLK_OUT_VCODIV_SHIFT ); - -/* put PLL in bypass before programming it */ - val =nvkm_rd32 (device,SEL_VCO ); - val &= ~(BIT (SEL_VCO_GPC2CLK_OUT_SHIFT )); +GPC2CLK_OUT_VCODIV2 <<GPC2CLK_OUT_VCODIV_SHIFT ); +/* Intentional 2nd write to assure linear divider operation */ +nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_VCODIV_MASK , +GPC2CLK_OUT_VCODIV2 <<GPC2CLK_OUT_VCODIV_SHIFT ); +nvkm_rd32 (device,GPC2CLK_OUT );udelay (2 ); -nvkm_wr32 (device,SEL_VCO , val); - -/* get out from IDDQ */ - val =nvkm_rd32 (device,GPCPLL_CFG ); -if (val &GPCPLL_CFG_IDDQ ) { - val &= ~GPCPLL_CFG_IDDQ ; -nvkm_wr32 (device,GPCPLL_CFG , val); -nvkm_rd32 (device,GPCPLL_CFG ); -udelay (2 ); - }gk20a_pllg_disable (clk); -nvkm_debug (subdev,"%s: m=%d n=%d pl=%d\n" , __func__, - pll->m, pll->n, pll->pl); - - old_pll = *pll; -if (allow_slide) - old_pll.n =gk20a_pllg_n_lo (clk, pll); -gk20a_pllg_write_mnp (clk, &old_pll); +gk20a_pllg_write_mnp (clk, pll); -gk20a_pllg_enable (clk); - - val =nvkm_rd32 (device,GPCPLL_CFG ); -if (val &GPCPLL_CFG_LOCK_DET_OFF ) { - val &= ~GPCPLL_CFG_LOCK_DET_OFF ; -nvkm_wr32 (device,GPCPLL_CFG , val); - } - -if (nvkm_usec (device,300 , - if (nvkm_rd32(device, GPCPLL_CFG) & GPCPLL_CFG_LOCK) - break; - ) <0 ) -return -ETIMEDOUT ; - -/* switch to VCO mode */ -nvkm_mask (device,SEL_VCO ,BIT (SEL_VCO_GPC2CLK_OUT_SHIFT ), -BIT (SEL_VCO_GPC2CLK_OUT_SHIFT )); + ret =gk20a_pllg_enable (clk); +if (ret) +return ret;/* restore out divider 1:1 */ - val =nvkm_rd32 (device,GPC2CLK_OUT ); -if ((val &GPC2CLK_OUT_VCODIV_MASK ) != - (GPC2CLK_OUT_VCODIV1 <<GPC2CLK_OUT_VCODIV_SHIFT )) { - val &= ~GPC2CLK_OUT_VCODIV_MASK ; - val |=GPC2CLK_OUT_VCODIV1 <<GPC2CLK_OUT_VCODIV_SHIFT ; -udelay (2 ); -nvkm_wr32 (device,GPC2CLK_OUT , val); -/* Intentional 2nd write to assure linear divider operation */ -nvkm_wr32 (device,GPC2CLK_OUT , val); -nvkm_rd32 (device,GPC2CLK_OUT ); - } +udelay (2 ); +nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_VCODIV_MASK , +GPC2CLK_OUT_VCODIV1 <<GPC2CLK_OUT_VCODIV_SHIFT ); +/* Intentional 2nd write to assure linear divider operation */ +nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_VCODIV_MASK , +GPC2CLK_OUT_VCODIV1 <<GPC2CLK_OUT_VCODIV_SHIFT ); +nvkm_rd32 (device,GPC2CLK_OUT ); -/* slide up to new NDIV */ -return allow_slide ?gk20a_pllg_slide (clk, pll->n) :0 ; +return 0 ; }static int -gk20a_pllg_program_mnp (struct gk20a_clk *clk) +gk20a_pllg_program_mnp_slide (struct gk20a_clk *clk,const struct gk20a_pll *pll) { -int err; +struct gk20a_pll cur_pll; +int ret; + +if (gk20a_pllg_is_enabled (clk)) { +gk20a_pllg_read_mnp (clk, &cur_pll); - err =_gk20a_pllg_program_mnp (clk, &clk->pll, true); -if (err) - err =_gk20a_pllg_program_mnp (clk, &clk->pll, false); +/* just do NDIV slide if there is no change to M and PL */ +if (pll->m == cur_pll.m && pll->pl == cur_pll.pl) +return gk20a_pllg_slide (clk, pll->n); -return err; +/* slide down to current NDIV_LO */ + cur_pll.n =gk20a_pllg_n_lo (clk, &cur_pll); + ret =gk20a_pllg_slide (clk, cur_pll.n); +if (ret) +return ret; + } + +/* program MNP with the new clock parameters and new NDIV_LO */ + cur_pll = *pll; + cur_pll.n =gk20a_pllg_n_lo (clk, &cur_pll); + ret =gk20a_pllg_program_mnp (clk, &cur_pll); +if (ret) +return ret; + +/* slide up to new NDIV */ +return gk20a_pllg_slide (clk, pll->n); } static struct nvkm_pstate
@@ -571,8 +570,13 @@ int gk20a_clk_prog(struct nvkm_clk *base) {struct gk20a_clk *clk =gk20a_clk (base); +int ret; + + ret =gk20a_pllg_program_mnp_slide (clk, &clk->pll); +if (ret) + ret =gk20a_pllg_program_mnp (clk, &clk->pll); -return gk20a_pllg_program_mnp (clk); +return ret; }void
@@ -621,11 +625,9 @@ gk20a_clk_fini(struct nvkm_clk *base) {struct nvkm_device *device = base->subdev.device;struct gk20a_clk *clk =gk20a_clk (base); -u32 val;/* slide to VCO min */ - val =nvkm_rd32 (device,GPCPLL_CFG ); -if (val &GPCPLL_CFG_ENABLE ) { +if (gk20a_pllg_is_enabled (clk)) {struct gk20a_pll pll;u32 n_lo;
@@ -634,10 +636,10 @@ gk20a_clk_fini(struct nvkm_clk *base)gk20a_pllg_slide (clk, n_lo); } -/* put PLL in bypass before disabling it */ -nvkm_mask (device,SEL_VCO ,BIT (SEL_VCO_GPC2CLK_OUT_SHIFT ),0 ); -gk20a_pllg_disable (clk); + +/* set IDDQ */ +nvkm_mask (device,GPCPLL_CFG ,GPCPLL_CFG_IDDQ ,1 ); } static int
@@ -648,6 +650,11 @@ gk20a_clk_init(struct nvkm_clk *base)struct nvkm_device *device = subdev->device;int ret; +/* get out from IDDQ */ +nvkm_mask (device,GPCPLL_CFG ,GPCPLL_CFG_IDDQ ,0 ); +nvkm_rd32 (device,GPCPLL_CFG ); +udelay (5 ); +nvkm_mask (device,GPC2CLK_OUT ,GPC2CLK_OUT_INIT_MASK ,GPC2CLK_OUT_INIT_VAL );
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 14/15 clk/gk20a: rename constructor
In reply to a message not in the archiveStrip the _ prefix off the gk20a clock constructor.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 4 ++-- drm/nouveau/nvkm/subdev/clk/gk20a.h | 2 +- drm/nouveau/nvkm/subdev/clk/gm20b.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +2 -2
@@ -691,7 +691,7 @@ gk20a_clk = { };int -_gk20a_clk_ctor (struct nvkm_device *device,int index, +gk20a_clk_ctor (struct nvkm_device *device,int index,const struct nvkm_clk_func *func,const struct gk20a_clk_pllg_params *params,struct gk20a_clk *clk)
@@ -730,7 +730,7 @@ gk20a_clk_new(struct nvkm_device *device, int index, struct nvkm_clk **pclk)return -ENOMEM ; *pclk = &clk->base; - ret =_gk20a_clk_ctor (device, index, &gk20a_clk, &gk20a_pllg_params, + ret =gk20a_clk_ctor (device, index, &gk20a_clk, &gk20a_pllg_params, clk); clk->pl_to_div = pl_to_div;
drm/nouveau/nvkm/subdev/clk/gk20a.h +1 -1
@@ -54,7 +54,7 @@ struct gk20a_clk { };#define gk20a_clk (p) container_of((p), struct gk20a_clk, base) -int _gk20a_clk_ctor (struct nvkm_device *,int ,const struct nvkm_clk_func *, +int gk20a_clk_ctor (struct nvkm_device *,int ,const struct nvkm_clk_func *,const struct gk20a_clk_pllg_params *,struct gk20a_clk *);void gk20a_clk_fini (struct nvkm_clk *);int gk20a_clk_read (struct nvkm_clk *,enum nv_clk_src );
drm/nouveau/nvkm/subdev/clk/gm20b.c +2 -2
@@ -192,8 +192,8 @@ gm20b_clk_new(struct nvkm_device *device, int index, struct nvkm_clk **pclk)return -ENOMEM ; *pclk = &clk->base; - ret =_gk20a_clk_ctor (device, index, &gm20b_clk_speedo0, - &gm20b_pllg_params, clk); + ret =gk20a_clk_ctor (device, index, &gm20b_clk_speedo0, + &gm20b_pllg_params, clk); clk->pl_to_div = pl_to_div; clk->div_to_pl = div_to_pl;
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 15/15 clk/gm20b: add glitchless and DFS support
In reply to a message not in the archiveThis patch adds support for advanced features supported by the Noise-Aware PLL of Maxwell. Glitchless switch allows the PL field to be updated without disabling the PLL first if the SYNC_MODE bit of the CFG register is set.
More significantly, DFS allows the PLL to monitor the actual input voltage and to dynamically lower the output frequency accordingly. This allows the clock to be more tolerant of lower voltages.
These improvements are only supported for Tegra speedos >= 1.
Also add the voltage table that is suitable for GM20B's NAPLL. This change needs to be done atomically for the right voltages to be used by the clock driver.
--- drm/nouveau/nvkm/subdev/clk/gk20a.c | 89 +--- drm/nouveau/nvkm/subdev/clk/gk20a.h | 92 ++++ drm/nouveau/nvkm/subdev/clk/gm20b.c | 892 ++++++++++++++++++++++++++++++++++- drm/nouveau/nvkm/subdev/volt/gm20b.c | 25 +- 4 files changed, 1000 insertions(+), 98 deletions(-)
drm/nouveau/nvkm/subdev/clk/gk20a.c +4 -85
@@ -28,70 +28,6 @@#include <core/tegra.h> #include <subdev/timer.h> -#define KHZ (1000) -#define MHZ (KHZ * 1000) - -#define MASK (w) ((1 << (w)) - 1) - -#define GPCPLL_CFG (SYS_GPCPLL_CFG_BASE + 0) -#define GPCPLL_CFG_ENABLE BIT(0) -#define GPCPLL_CFG_IDDQ BIT(1) -#define GPCPLL_CFG_LOCK_DET_OFF BIT(4) -#define GPCPLL_CFG_LOCK BIT(17) - -#define GPCPLL_COEFF (SYS_GPCPLL_CFG_BASE + 4) -#define GPCPLL_COEFF_M_SHIFT 0 -#define GPCPLL_COEFF_M_WIDTH 8 -#define GPCPLL_COEFF_N_SHIFT 8 -#define GPCPLL_COEFF_N_WIDTH 8 -#define GPCPLL_COEFF_P_SHIFT 16 -#define GPCPLL_COEFF_P_WIDTH 6 - -#define GPCPLL_CFG2 (SYS_GPCPLL_CFG_BASE + 0xc) -#define GPCPLL_CFG2_SETUP2_SHIFT 16 -#define GPCPLL_CFG2_PLL_STEPA_SHIFT 24 - -#define GPCPLL_CFG3 (SYS_GPCPLL_CFG_BASE + 0x18) -#define GPCPLL_CFG3_PLL_STEPB_SHIFT 16 - -#define GPC_BCASE_GPCPLL_CFG_BASE 0x00132800 -#define GPCPLL_NDIV_SLOWDOWN (SYS_GPCPLL_CFG_BASE + 0x1c) -#define GPCPLL_NDIV_SLOWDOWN_NDIV_LO_SHIFT 0 -#define GPCPLL_NDIV_SLOWDOWN_NDIV_MID_SHIFT 8 -#define GPCPLL_NDIV_SLOWDOWN_STEP_SIZE_LO2MID_SHIFT 16 -#define GPCPLL_NDIV_SLOWDOWN_SLOWDOWN_USING_PLL_SHIFT 22 -#define GPCPLL_NDIV_SLOWDOWN_EN_DYNRAMP_SHIFT 31 - -#define SEL_VCO (SYS_GPCPLL_CFG_BASE + 0x100) -#define SEL_VCO_GPC2CLK_OUT_SHIFT 0 - -#define GPC2CLK_OUT (SYS_GPCPLL_CFG_BASE + 0x250) -#define GPC2CLK_OUT_SDIV14_INDIV4_WIDTH 1 -#define GPC2CLK_OUT_SDIV14_INDIV4_SHIFT 31 -#define GPC2CLK_OUT_SDIV14_INDIV4_MODE 1 -#define GPC2CLK_OUT_VCODIV_WIDTH 6 -#define GPC2CLK_OUT_VCODIV_SHIFT 8 -#define GPC2CLK_OUT_VCODIV1 0 -#define GPC2CLK_OUT_VCODIV2 2 -#define GPC2CLK_OUT_VCODIV_MASK (MASK(GPC2CLK_OUT_VCODIV_WIDTH) << \ - GPC2CLK_OUT_VCODIV_SHIFT) -#define GPC2CLK_OUT_BYPDIV_WIDTH 6 -#define GPC2CLK_OUT_BYPDIV_SHIFT 0 -#define GPC2CLK_OUT_BYPDIV31 0x3c -#define GPC2CLK_OUT_INIT_MASK ((MASK(GPC2CLK_OUT_SDIV14_INDIV4_WIDTH) << \ - GPC2CLK_OUT_SDIV14_INDIV4_SHIFT)\ - | (MASK(GPC2CLK_OUT_VCODIV_WIDTH) << GPC2CLK_OUT_VCODIV_SHIFT)\ - | (MASK(GPC2CLK_OUT_BYPDIV_WIDTH) << GPC2CLK_OUT_BYPDIV_SHIFT)) -#define GPC2CLK_OUT_INIT_VAL ((GPC2CLK_OUT_SDIV14_INDIV4_MODE << \ - GPC2CLK_OUT_SDIV14_INDIV4_SHIFT) \ - | (GPC2CLK_OUT_VCODIV1 << GPC2CLK_OUT_VCODIV_SHIFT) \ - | (GPC2CLK_OUT_BYPDIV31 << GPC2CLK_OUT_BYPDIV_SHIFT)) - -#define GPC_BCAST_NDIV_SLOWDOWN_DEBUG (GPC_BCASE_GPCPLL_CFG_BASE + 0xa0) -#define GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_SHIFT 24 -#define GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_MASK \ - (0x1 << GPC_BCAST_NDIV_SLOWDOWN_DEBUG_PLL_DYNRAMP_DONE_SYNCED_SHIFT) -static const u8 _pl_to_div[] = {/* PL: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 */ /* p: */ 1 ,2 ,3 ,4 ,5 ,6 ,8 ,10 ,12 ,16 ,12 ,16 ,20 ,24 ,32 ,
@@ -125,7 +61,7 @@ static const struct gk20a_clk_pllg_params gk20a_pllg_params = { .min_pl = 1, .max_pl = 32, }; -static void +void gk20a_pllg_read_mnp (struct gk20a_clk *clk,struct gk20a_pll *pll) {struct nvkm_device *device = clk->base.subdev.device;
@@ -137,7 +73,7 @@ gk20a_pllg_read_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll) pll->pl = (val >>GPCPLL_COEFF_P_SHIFT ) &MASK (GPCPLL_COEFF_P_WIDTH ); } -static void +void gk20a_pllg_write_mnp (struct gk20a_clk *clk,const struct gk20a_pll *pll) {struct nvkm_device *device = clk->base.subdev.device;
@@ -149,7 +85,7 @@ gk20a_pllg_write_mnp(struct gk20a_clk *clk, const struct gk20a_pll *pll)nvkm_wr32 (device,GPCPLL_COEFF , val); } -static u32 +u32 gk20a_pllg_calc_rate (struct gk20a_clk *clk,struct gk20a_pll *pll) {u32 rate;
@@ -161,14 +97,7 @@ gk20a_pllg_calc_rate(struct gk20a_clk *clk, struct gk20a_pll *pll)return rate / divider /2 ; } -static u32 -gk20a_pllg_n_lo (struct gk20a_clk *clk,struct gk20a_pll *pll) -{ -return DIV_ROUND_UP (pll->m * clk->params->min_vco, - clk->parent_rate /KHZ ); -} - -static int +int gk20a_pllg_calc_mnp (struct gk20a_clk *clk,unsigned long rate,struct gk20a_pll *pll) {
@@ -323,16 +252,6 @@ gk20a_pllg_slide(struct gk20a_clk *clk, u32 n)return ret; } -static bool -gk20a_pllg_is_enabled (struct gk20a_clk *clk) -{ -struct nvkm_device *device = clk->base.subdev.device; -u32 val; - - val =nvkm_rd32 (device,GPCPLL_CFG ); -return val &GPCPLL_CFG_ENABLE ; -} -static int gk20a_pllg_enable (struct gk20a_clk *clk) {
drm/nouveau/nvkm/subdev/clk/gk20a.h +92 -0
107 lines not on this page · raw message
drm/nouveau/nvkm/subdev/clk/gm20b.c +881 -11
952 lines not on this page · raw message
drm/nouveau/nvkm/subdev/volt/gm20b.c +23 -2
@@ -41,6 +41,23 @@ const struct cvb_coef gm20b_cvb_coef[] = { /* 921600 */ { 2647676, -106455, 1632 }, }; +static const struct cvb_coef gm20b_na_cvb_coef[] = { +/* KHz, c0, c1, c2, c3, c4, c5 */ +/* 76800 */ {814294 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 153600 */ {856185 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 230400 */ {898077 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 307200 */ {939968 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 384000 */ {981860 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 460800 */ {1023751 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 537600 */ {1065642 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 614400 */ {1107534 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 691200 */ {1149425 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 768000 */ {1191317 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 844800 */ {1233208 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 921600 */ {1275100 ,8144 ,-940 ,808 ,-21583 ,226 }, +/* 998400 */ {1316991 ,8144 ,-940 ,808 ,-21583 ,226 }, +}; +const u32 speedo_to_vmin[] = {/* 0, 1, 2, 3, 4, */ 950000, 840000, 818750, 840000, 810000,
@@ -66,6 +83,10 @@ gm20b_volt_new(struct nvkm_device *device, int index, struct nvkm_volt **pvolt) vmin = speedo_to_vmin[tdev->gpu_speedo_id]; -return gk20a_volt_ctor (device, index, gm20b_cvb_coef, -ARRAY_SIZE (gm20b_cvb_coef), vmin, volt); +if (tdev->gpu_speedo_id >=1 ) +return gk20a_volt_ctor (device, index, gm20b_na_cvb_coef, +ARRAY_SIZE (gm20b_na_cvb_coef), vmin, volt); +else +return gk20a_volt_ctor (device, index, gm20b_cvb_coef, +ARRAY_SIZE (gm20b_cvb_coef), vmin, volt); }
Signature · 6 lines
2.8.3 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau