Skip to content

Instantly share code, notes, and snippets.

@neheb
Created October 31, 2022 02:13
Show Gist options
  • Save neheb/e3876aee464312b2481b5be46c97d59c to your computer and use it in GitHub Desktop.
Save neheb/e3876aee464312b2481b5be46c97d59c to your computer and use it in GitHub Desktop.
--- a/drivers/clk/ralink/clk-mt7621.c
+++ b/drivers/clk/ralink/clk-mt7621.c
@@ -269,6 +269,10 @@ static unsigned long mt7621_cpu_recalc_rate(struct clk_hw *hw,
break;
case 1:
regmap_read(memc, MEMC_REG_CPU_PLL, &pll);
+ pll &= ~(0x7ff);
+ pll |= (0x362);
+ regmap_write(memc, MEMC_REG_CPU_PLL, pll);
+ for(int i = 0; i < 1024; i++);
fbdiv = FIELD_GET(CPU_PLL_FBDIV_MASK, pll);
prediv = FIELD_GET(CPU_PLL_PREDIV_MASK, pll);
cpu_clk = ((fbdiv + 1) * xtal_clk) >> prediv_tbl[prediv];
@neheb
Copy link
Author

neheb commented Oct 31, 2022

@paraka this looks fishy...

@paraka
Copy link

paraka commented Oct 31, 2022

@neheb Where is that code comming from? What is the added code for? The original driver code and the one I wrote and mainlined does not have that at all..
See current kernel last code:
https://elixir.bootlin.com/linux/v6.1-rc3/source/drivers/clk/ralink/clk-mt7621.c

@neheb
Copy link
Author

neheb commented Oct 31, 2022

It's an attempt to port gw826943555/openwrt@e1856e8 to 5.15. I'm not sure how to use the regmap API to do this properly.

@paraka
Copy link

paraka commented Oct 31, 2022

regmap read and write look good but you should use FIELD_GET and FIELD_PREP (from bitfield header)[0] to get and set values to already read pll. Also, the waiting for loop looks hacky. Maybe you can use accurate kernel sleep function for doing this?

[0]: https://elixir.bootlin.com/linux/v6.1-rc3/source/include/linux/bitfield.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment