Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mips: ar7: convert to CONFIG_COMMON_CLK

Perform a minimal conversion of the ar7 clock implementation to the common
clock framework. While the hardware can control the rates, this is left
unchanged, and all clocks are registered as fixed-rate or fixed-divider
clocks. Similarly, the clkdev lookup information is left unchanged but
moved from the table format into individual allocations.

There is a small increase in code size:

text data bss dec hex filename
4757116 596640 91328 5445084 5315dc vmlinux-before
4806159 602360 91344 5499863 53ebd7 vmlinux-after

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+30 -81
+1 -2
arch/mips/Kconfig
··· 201 201 config AR7 202 202 bool "Texas Instruments AR7" 203 203 select BOOT_ELF32 204 + select COMMON_CLK 204 205 select DMA_NONCOHERENT 205 206 select CEVT_R4K 206 207 select CSRC_R4K ··· 216 215 select SYS_SUPPORTS_ZBOOT_UART16550 217 216 select GPIOLIB 218 217 select VLYNQ 219 - select CLKDEV_LOOKUP 220 - select HAVE_LEGACY_CLK 221 218 help 222 219 Support for the Texas Instruments AR7 System-on-a-Chip 223 220 family: TNETD7100, 7200 and 7300.
+29 -75
arch/mips/ar7/clock.c
··· 15 15 #include <linux/err.h> 16 16 #include <linux/clkdev.h> 17 17 #include <linux/clk.h> 18 + #include <linux/clk-provider.h> 18 19 19 20 #include <asm/addrspace.h> 20 21 #include <asm/mach-ar7/ar7.h> ··· 86 85 struct tnetd7200_clock usb; 87 86 }; 88 87 89 - static struct clk bus_clk = { 88 + struct clk_rate { 89 + u32 rate; 90 + }; 91 + static struct clk_rate bus_clk = { 90 92 .rate = 125000000, 91 93 }; 92 94 93 - static struct clk cpu_clk = { 95 + static struct clk_rate cpu_clk = { 94 96 .rate = 150000000, 95 97 }; 96 - 97 - static struct clk dsp_clk; 98 - static struct clk vbus_clk; 99 98 100 99 static void approximate(int base, int target, int *prediv, 101 100 int *postdiv, int *mul) ··· 242 241 struct tnetd7300_clocks *clocks = 243 242 ioremap(UR8_REGS_CLOCKS, 244 243 sizeof(struct tnetd7300_clocks)); 244 + u32 dsp_clk; 245 + struct clk *clk; 245 246 246 247 bus_clk.rate = tnetd7300_get_clock(BUS_PLL_SOURCE_SHIFT, 247 248 &clocks->bus, bootcr, AR7_AFE_CLOCK); ··· 254 251 else 255 252 cpu_clk.rate = bus_clk.rate; 256 253 257 - if (dsp_clk.rate == 250000000) 254 + dsp_clk = tnetd7300_dsp_clock(); 255 + if (dsp_clk == 250000000) 258 256 tnetd7300_set_clock(DSP_PLL_SOURCE_SHIFT, &clocks->dsp, 259 - bootcr, dsp_clk.rate); 257 + bootcr, dsp_clk); 260 258 261 259 iounmap(clocks); 262 260 iounmap(bootcr); 261 + 262 + clk = clk_register_fixed_rate(NULL, "cpu", NULL, 0, cpu_clk.rate); 263 + clkdev_create(clk, "cpu", NULL); 264 + clk = clk_register_fixed_rate(NULL, "dsp", NULL, 0, dsp_clk); 265 + clkdev_create(clk, "dsp", NULL); 263 266 } 264 267 265 268 static void tnetd7200_set_clock(int base, struct tnetd7200_clock *clock, ··· 337 328 int cpu_base, cpu_mul, cpu_prediv, cpu_postdiv; 338 329 int dsp_base, dsp_mul, dsp_prediv, dsp_postdiv; 339 330 int usb_base, usb_mul, usb_prediv, usb_postdiv; 331 + struct clk *clk; 340 332 341 333 cpu_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_CPU, bootcr); 342 334 dsp_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_DSP, bootcr); ··· 406 396 usb_prediv, usb_postdiv, -1, usb_mul, 407 397 TNETD7200_DEF_USB_CLK); 408 398 409 - dsp_clk.rate = cpu_clk.rate; 410 - 411 399 iounmap(clocks); 412 400 iounmap(bootcr); 401 + 402 + clk = clk_register_fixed_rate(NULL, "cpu", NULL, 0, cpu_clk.rate); 403 + clkdev_create(clk, "cpu", NULL); 404 + clkdev_create(clk, "dsp", NULL); 413 405 } 414 - 415 - /* 416 - * Linux clock API 417 - */ 418 - int clk_enable(struct clk *clk) 419 - { 420 - return 0; 421 - } 422 - EXPORT_SYMBOL(clk_enable); 423 - 424 - void clk_disable(struct clk *clk) 425 - { 426 - } 427 - EXPORT_SYMBOL(clk_disable); 428 - 429 - unsigned long clk_get_rate(struct clk *clk) 430 - { 431 - if (!clk) 432 - return 0; 433 - 434 - return clk->rate; 435 - } 436 - EXPORT_SYMBOL(clk_get_rate); 437 - 438 - static struct clk_lookup ar7_clkdev_table[] = { 439 - CLKDEV_INIT(NULL, "bus", &bus_clk), 440 - /* cpmac and vbus share the same rate */ 441 - CLKDEV_INIT("cpmac.0", "cpmac", &vbus_clk), 442 - CLKDEV_INIT("cpmac.1", "cpmac", &vbus_clk), 443 - CLKDEV_INIT(NULL, "cpu", &cpu_clk), 444 - CLKDEV_INIT(NULL, "dsp", &dsp_clk), 445 - CLKDEV_INIT(NULL, "vbus", &vbus_clk), 446 - }; 447 406 448 407 void __init ar7_init_clocks(void) 449 408 { 409 + struct clk *clk; 410 + 450 411 switch (ar7_chip_id()) { 451 412 case AR7_CHIP_7100: 452 413 case AR7_CHIP_7200: 453 414 tnetd7200_init_clocks(); 454 415 break; 455 416 case AR7_CHIP_7300: 456 - dsp_clk.rate = tnetd7300_dsp_clock(); 457 417 tnetd7300_init_clocks(); 458 418 break; 459 419 default: 460 420 break; 461 421 } 422 + clk = clk_register_fixed_rate(NULL, "bus", NULL, 0, bus_clk.rate); 423 + clkdev_create(clk, "bus", NULL); 462 424 /* adjust vbus clock rate */ 463 - vbus_clk.rate = bus_clk.rate / 2; 464 - 465 - clkdev_add_table(ar7_clkdev_table, ARRAY_SIZE(ar7_clkdev_table)); 425 + clk = clk_register_fixed_factor(NULL, "vbus", "bus", 0, 1, 2); 426 + clkdev_create(clk, "vbus", NULL); 427 + clkdev_create(clk, "cpmac", "cpmac.1"); 428 + clkdev_create(clk, "cpmac", "cpmac.1"); 466 429 } 467 - 468 - /* dummy functions, should not be called */ 469 - long clk_round_rate(struct clk *clk, unsigned long rate) 470 - { 471 - WARN_ON(clk); 472 - return 0; 473 - } 474 - EXPORT_SYMBOL(clk_round_rate); 475 - 476 - int clk_set_rate(struct clk *clk, unsigned long rate) 477 - { 478 - WARN_ON(clk); 479 - return 0; 480 - } 481 - EXPORT_SYMBOL(clk_set_rate); 482 - 483 - int clk_set_parent(struct clk *clk, struct clk *parent) 484 - { 485 - WARN_ON(clk); 486 - return 0; 487 - } 488 - EXPORT_SYMBOL(clk_set_parent); 489 - 490 - struct clk *clk_get_parent(struct clk *clk) 491 - { 492 - WARN_ON(clk); 493 - return NULL; 494 - } 495 - EXPORT_SYMBOL(clk_get_parent);
-4
arch/mips/include/asm/mach-ar7/ar7.h
··· 131 131 0x14))) >> 16) & 0xff; 132 132 } 133 133 134 - struct clk { 135 - unsigned int rate; 136 - }; 137 - 138 134 static inline int ar7_has_high_cpmac(void) 139 135 { 140 136 u16 chip_id = ar7_chip_id();