[SPARC]: Convert clock drivers to of_driver framework.

Signed-off-by: David S. Miller <davem@davemloft.net>

authored by David S. Miller and committed by David S. Miller ee5caf0e 36a59bd8

+103 -274
+40 -69
arch/sparc/kernel/time.c
··· 42 42 #include <asm/sun4paddr.h> 43 43 #include <asm/page.h> 44 44 #include <asm/pcic.h> 45 + #include <asm/of_device.h> 45 46 46 47 extern unsigned long wall_jiffies; 47 48 ··· 274 273 #endif 275 274 } 276 275 277 - /* Probe for the mostek real time clock chip. */ 278 - static __inline__ void clock_probe(void) 276 + static int __devinit clock_probe(struct of_device *op, const struct of_device_id *match) 279 277 { 280 - struct linux_prom_registers clk_reg[2]; 281 - char model[128]; 282 - register int node, cpuunit, bootbus; 283 - struct resource r; 278 + struct device_node *dp = op->node; 279 + char *model = of_get_property(dp, "model", NULL); 284 280 285 - cpuunit = bootbus = 0; 286 - memset(&r, 0, sizeof(r)); 281 + if (!model) 282 + return -ENODEV; 287 283 288 - /* Determine the correct starting PROM node for the probe. */ 289 - node = prom_getchild(prom_root_node); 290 - switch (sparc_cpu_model) { 291 - case sun4c: 292 - break; 293 - case sun4m: 294 - node = prom_getchild(prom_searchsiblings(node, "obio")); 295 - break; 296 - case sun4d: 297 - node = prom_getchild(bootbus = prom_searchsiblings(prom_getchild(cpuunit = prom_searchsiblings(node, "cpu-unit")), "bootbus")); 298 - break; 299 - default: 300 - prom_printf("CLOCK: Unsupported architecture!\n"); 301 - prom_halt(); 302 - } 303 - 304 - /* Find the PROM node describing the real time clock. */ 305 - sp_clock_typ = MSTK_INVALID; 306 - node = prom_searchsiblings(node,"eeprom"); 307 - if (!node) { 308 - prom_printf("CLOCK: No clock found!\n"); 309 - prom_halt(); 310 - } 311 - 312 - /* Get the model name and setup everything up. */ 313 - model[0] = '\0'; 314 - prom_getstring(node, "model", model, sizeof(model)); 315 - if (strcmp(model, "mk48t02") == 0) { 284 + if (!strcmp(model, "mk48t02")) { 316 285 sp_clock_typ = MSTK48T02; 317 - if (prom_getproperty(node, "reg", (char *) clk_reg, sizeof(clk_reg)) == -1) { 318 - prom_printf("clock_probe: FAILED!\n"); 319 - prom_halt(); 320 - } 321 - if (sparc_cpu_model == sun4d) 322 - prom_apply_generic_ranges (bootbus, cpuunit, clk_reg, 1); 323 - else 324 - prom_apply_obio_ranges(clk_reg, 1); 286 + 325 287 /* Map the clock register io area read-only */ 326 - r.flags = clk_reg[0].which_io; 327 - r.start = clk_reg[0].phys_addr; 328 - mstk48t02_regs = sbus_ioremap(&r, 0, 329 - sizeof(struct mostek48t02), "mk48t02"); 288 + mstk48t02_regs = of_ioremap(&op->resource[0], 0, 289 + sizeof(struct mostek48t02), 290 + "mk48t02"); 330 291 mstk48t08_regs = NULL; /* To catch weirdness */ 331 - } else if (strcmp(model, "mk48t08") == 0) { 292 + } else if (!strcmp(model, "mk48t08")) { 332 293 sp_clock_typ = MSTK48T08; 333 - if(prom_getproperty(node, "reg", (char *) clk_reg, 334 - sizeof(clk_reg)) == -1) { 335 - prom_printf("clock_probe: FAILED!\n"); 336 - prom_halt(); 337 - } 338 - if (sparc_cpu_model == sun4d) 339 - prom_apply_generic_ranges (bootbus, cpuunit, clk_reg, 1); 340 - else 341 - prom_apply_obio_ranges(clk_reg, 1); 342 - /* Map the clock register io area read-only */ 343 - /* XXX r/o attribute is somewhere in r.flags */ 344 - r.flags = clk_reg[0].which_io; 345 - r.start = clk_reg[0].phys_addr; 346 - mstk48t08_regs = sbus_ioremap(&r, 0, 347 - sizeof(struct mostek48t08), "mk48t08"); 294 + mstk48t08_regs = of_ioremap(&op->resource[0], 0, 295 + sizeof(struct mostek48t08), 296 + "mk48t08"); 348 297 349 298 mstk48t02_regs = &mstk48t08_regs->regs; 350 - } else { 351 - prom_printf("CLOCK: Unknown model name '%s'\n",model); 352 - prom_halt(); 353 - } 299 + } else 300 + return -ENODEV; 354 301 355 302 /* Report a low battery voltage condition. */ 356 303 if (has_low_battery()) ··· 307 358 /* Kick start the clock if it is completely stopped. */ 308 359 if (mostek_read(mstk48t02_regs + MOSTEK_SEC) & MSTK_STOP) 309 360 kick_start_clock(); 361 + 362 + return 0; 363 + } 364 + 365 + static struct of_device_id clock_match[] = { 366 + { 367 + .name = "eeprom", 368 + }, 369 + {}, 370 + }; 371 + 372 + static struct of_platform_driver clock_driver = { 373 + .name = "clock", 374 + .match_table = clock_match, 375 + .probe = clock_probe, 376 + }; 377 + 378 + 379 + /* Probe for the mostek real time clock chip. */ 380 + static void clock_init(void) 381 + { 382 + of_register_driver(&clock_driver, &of_bus_type); 310 383 } 311 384 312 385 void __init sbus_time_init(void) ··· 347 376 if (ARCH_SUN4) 348 377 sun4_clock_probe(); 349 378 else 350 - clock_probe(); 379 + clock_init(); 351 380 352 381 sparc_init_timers(timer_interrupt); 353 382
-2
arch/sparc64/kernel/pci.c
··· 307 307 p->scan_bus(p); 308 308 } 309 309 310 - extern void clock_probe(void); 311 310 extern void power_init(void); 312 311 313 312 static int __init pcibios_init(void) ··· 319 320 320 321 isa_init(); 321 322 ebus_init(); 322 - clock_probe(); 323 323 power_init(); 324 324 325 325 return 0;
-2
arch/sparc64/kernel/sbus.c
··· 1267 1267 void __init sbus_arch_postinit(void) 1268 1268 { 1269 1269 extern void firetruck_init(void); 1270 - extern void clock_probe(void); 1271 1270 1272 1271 firetruck_init(); 1273 - clock_probe(); 1274 1272 }
+63 -201
arch/sparc64/kernel/time.c
··· 770 770 return 1; 771 771 } 772 772 773 - static void __init __clock_assign_common(void __iomem *addr, char *model) 773 + static int __devinit clock_probe(struct of_device *op, const struct of_device_id *match) 774 774 { 775 - if (model[5] == '0' && model[6] == '2') { 776 - mstk48t02_regs = addr; 777 - } else if(model[5] == '0' && model[6] == '8') { 778 - mstk48t08_regs = addr; 779 - mstk48t02_regs = mstk48t08_regs + MOSTEK_48T08_48T02; 780 - } else { 781 - mstk48t59_regs = addr; 782 - mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02; 783 - } 784 - } 775 + struct device_node *dp = op->node; 776 + char *model = of_get_property(dp, "model", NULL); 777 + unsigned long size, flags; 778 + void __iomem *regs; 785 779 786 - static void __init clock_assign_clk_reg(struct linux_prom_registers *clk_reg, 787 - char *model) 788 - { 789 - unsigned long addr; 780 + if (!model || !clock_model_matches(model)) 781 + return -ENODEV; 790 782 791 - addr = ((unsigned long) clk_reg[0].phys_addr | 792 - (((unsigned long) clk_reg[0].which_io) << 32UL)); 783 + size = (op->resource[0].end - op->resource[0].start) + 1; 784 + regs = of_ioremap(&op->resource[0], 0, size, "clock"); 785 + if (!regs) 786 + return -ENOMEM; 793 787 794 - __clock_assign_common((void __iomem *) addr, model); 795 - } 796 - 797 - static int __init clock_probe_central(void) 798 - { 799 - struct linux_prom_registers clk_reg[2], *pr; 800 - struct device_node *dp; 801 - char *model; 802 - 803 - if (!central_bus) 804 - return 0; 805 - 806 - /* Get Central FHC's prom node. */ 807 - dp = central_bus->child->prom_node; 808 - 809 - /* Then get the first child device below it. */ 810 - dp = dp->child; 811 - 812 - while (dp) { 813 - model = of_get_property(dp, "model", NULL); 814 - if (!model || !clock_model_matches(model)) 815 - goto next_sibling; 816 - 817 - pr = of_get_property(dp, "reg", NULL); 818 - memcpy(clk_reg, pr, sizeof(clk_reg)); 819 - 820 - apply_fhc_ranges(central_bus->child, clk_reg, 1); 821 - apply_central_ranges(central_bus, clk_reg, 1); 822 - 823 - clock_assign_clk_reg(clk_reg, model); 824 - return 1; 825 - 826 - next_sibling: 827 - dp = dp->sibling; 828 - } 829 - 830 - return 0; 831 - } 832 - 833 - #ifdef CONFIG_PCI 834 - static void __init clock_isa_ebus_assign_regs(struct resource *res, char *model) 835 - { 836 788 if (!strcmp(model, "ds1287") || 837 789 !strcmp(model, "m5819") || 838 790 !strcmp(model, "m5819p") || 839 791 !strcmp(model, "m5823")) { 840 - ds1287_regs = res->start; 792 + ds1287_regs = (unsigned long) regs; 793 + } else if (model[5] == '0' && model[6] == '2') { 794 + mstk48t02_regs = regs; 795 + } else if(model[5] == '0' && model[6] == '8') { 796 + mstk48t08_regs = regs; 797 + mstk48t02_regs = mstk48t08_regs + MOSTEK_48T08_48T02; 841 798 } else { 842 - mstk48t59_regs = (void __iomem *) res->start; 799 + mstk48t59_regs = regs; 843 800 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02; 844 801 } 845 - } 846 802 847 - static int __init clock_probe_one_ebus_dev(struct linux_ebus_device *edev) 848 - { 849 - struct device_node *dp = edev->prom_node; 850 - char *model; 851 - 852 - model = of_get_property(dp, "model", NULL); 853 - if (!clock_model_matches(model)) 854 - return 0; 855 - 856 - clock_isa_ebus_assign_regs(&edev->resource[0], model); 857 - 858 - return 1; 859 - } 860 - 861 - static int __init clock_probe_ebus(void) 862 - { 863 - struct linux_ebus *ebus; 864 - 865 - for_each_ebus(ebus) { 866 - struct linux_ebus_device *edev; 867 - 868 - for_each_ebusdev(edev, ebus) { 869 - if (clock_probe_one_ebus_dev(edev)) 870 - return 1; 871 - } 872 - } 873 - 874 - return 0; 875 - } 876 - 877 - static int __init clock_probe_one_isa_dev(struct sparc_isa_device *idev) 878 - { 879 - struct device_node *dp = idev->prom_node; 880 - char *model; 881 - 882 - model = of_get_property(dp, "model", NULL); 883 - if (!clock_model_matches(model)) 884 - return 0; 885 - 886 - clock_isa_ebus_assign_regs(&idev->resource, model); 887 - 888 - return 1; 889 - } 890 - 891 - static int __init clock_probe_isa(void) 892 - { 893 - struct sparc_isa_bridge *isa_br; 894 - 895 - for_each_isa(isa_br) { 896 - struct sparc_isa_device *isa_dev; 897 - 898 - for_each_isadev(isa_dev, isa_br) { 899 - if (clock_probe_one_isa_dev(isa_dev)) 900 - return 1; 901 - } 902 - } 903 - 904 - return 0; 905 - } 906 - #endif /* CONFIG_PCI */ 907 - 908 - #ifdef CONFIG_SBUS 909 - static int __init clock_probe_one_sbus_dev(struct sbus_bus *sbus, struct sbus_dev *sdev) 910 - { 911 - struct resource *res; 912 - char model[64]; 913 - void __iomem *addr; 914 - 915 - prom_getstring(sdev->prom_node, "model", model, sizeof(model)); 916 - if (!clock_model_matches(model)) 917 - return 0; 918 - 919 - res = &sdev->resource[0]; 920 - addr = sbus_ioremap(res, 0, 0x800UL, "eeprom"); 921 - 922 - __clock_assign_common(addr, model); 923 - 924 - return 1; 925 - } 926 - 927 - static int __init clock_probe_sbus(void) 928 - { 929 - struct sbus_bus *sbus; 930 - 931 - for_each_sbus(sbus) { 932 - struct sbus_dev *sdev; 933 - 934 - for_each_sbusdev(sdev, sbus) { 935 - if (clock_probe_one_sbus_dev(sbus, sdev)) 936 - return 1; 937 - } 938 - } 939 - 940 - return 0; 941 - } 942 - #endif 943 - 944 - void __init clock_probe(void) 945 - { 946 - static int invoked; 947 - unsigned long flags; 948 - 949 - if (invoked) 950 - return; 951 - invoked = 1; 952 - 953 - if (this_is_starfire) { 954 - xtime.tv_sec = starfire_get_time(); 955 - xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); 956 - set_normalized_timespec(&wall_to_monotonic, 957 - -xtime.tv_sec, -xtime.tv_nsec); 958 - return; 959 - } 960 - if (tlb_type == hypervisor) { 961 - xtime.tv_sec = hypervisor_get_time(); 962 - xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); 963 - set_normalized_timespec(&wall_to_monotonic, 964 - -xtime.tv_sec, -xtime.tv_nsec); 965 - return; 966 - } 967 - 968 - /* Check FHC Central then EBUSs then ISA bridges then SBUSs. 969 - * That way we handle the presence of multiple properly. 970 - * 971 - * As a special case, machines with Central must provide the 972 - * timer chip there. 973 - */ 974 - if (!clock_probe_central() && 975 - #ifdef CONFIG_PCI 976 - !clock_probe_ebus() && 977 - !clock_probe_isa() && 978 - #endif 979 - #ifdef CONFIG_SBUS 980 - !clock_probe_sbus() 981 - #endif 982 - ) { 983 - printk(KERN_WARNING "No clock chip found.\n"); 984 - return; 985 - } 803 + printk(KERN_INFO "%s: Clock regs at %p\n", dp->full_name, regs); 986 804 987 805 local_irq_save(flags); 988 806 ··· 817 999 set_system_time(); 818 1000 819 1001 local_irq_restore(flags); 1002 + 1003 + return 0; 820 1004 } 1005 + 1006 + static struct of_device_id clock_match[] = { 1007 + { 1008 + .name = "eeprom", 1009 + }, 1010 + { 1011 + .name = "rtc", 1012 + }, 1013 + {}, 1014 + }; 1015 + 1016 + static struct of_platform_driver clock_driver = { 1017 + .name = "clock", 1018 + .match_table = clock_match, 1019 + .probe = clock_probe, 1020 + }; 1021 + 1022 + static int __init clock_init(void) 1023 + { 1024 + if (this_is_starfire) { 1025 + xtime.tv_sec = starfire_get_time(); 1026 + xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); 1027 + set_normalized_timespec(&wall_to_monotonic, 1028 + -xtime.tv_sec, -xtime.tv_nsec); 1029 + return 0; 1030 + } 1031 + if (tlb_type == hypervisor) { 1032 + xtime.tv_sec = hypervisor_get_time(); 1033 + xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); 1034 + set_normalized_timespec(&wall_to_monotonic, 1035 + -xtime.tv_sec, -xtime.tv_nsec); 1036 + return 0; 1037 + } 1038 + 1039 + return of_register_driver(&clock_driver, &of_bus_type); 1040 + } 1041 + 1042 + /* Must be after subsys_initcall() so that busses are probed. Must 1043 + * be before device_initcall() because things like the RTC driver 1044 + * need to see the clock registers. 1045 + */ 1046 + fs_initcall(clock_init); 821 1047 822 1048 /* This is gets the master TICK_INT timer going. */ 823 1049 static unsigned long sparc64_init_timers(void)