122258fa4SDavid Gibson /* 222258fa4SDavid Gibson * Instantiate mmio-mapped RTC chips based on device tree information 322258fa4SDavid Gibson * 422258fa4SDavid Gibson * Copyright 2007 David Gibson <[email protected]>, IBM Corporation. 522258fa4SDavid Gibson * 622258fa4SDavid Gibson * This program is free software; you can redistribute it and/or modify it 722258fa4SDavid Gibson * under the terms of the GNU General Public License as published by the 822258fa4SDavid Gibson * Free Software Foundation; either version 2 of the License, or (at your 922258fa4SDavid Gibson * option) any later version. 1022258fa4SDavid Gibson */ 1122258fa4SDavid Gibson #include <linux/kernel.h> 1222258fa4SDavid Gibson #include <linux/of.h> 1322258fa4SDavid Gibson #include <linux/init.h> 14*26a2056eSRob Herring #include <linux/of_address.h> 1522258fa4SDavid Gibson #include <linux/of_platform.h> 165a0e3ad6STejun Heo #include <linux/slab.h> 1722258fa4SDavid Gibson 1822258fa4SDavid Gibson static __initdata struct { 1922258fa4SDavid Gibson const char *compatible; 2022258fa4SDavid Gibson char *plat_name; 2122258fa4SDavid Gibson } of_rtc_table[] = { 2222258fa4SDavid Gibson { "ds1743-nvram", "rtc-ds1742" }, 2322258fa4SDavid Gibson }; 2422258fa4SDavid Gibson 2522258fa4SDavid Gibson void __init of_instantiate_rtc(void) 2622258fa4SDavid Gibson { 2722258fa4SDavid Gibson struct device_node *node; 2822258fa4SDavid Gibson int err; 2922258fa4SDavid Gibson int i; 3022258fa4SDavid Gibson 3122258fa4SDavid Gibson for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) { 3222258fa4SDavid Gibson char *plat_name = of_rtc_table[i].plat_name; 3322258fa4SDavid Gibson 3422258fa4SDavid Gibson for_each_compatible_node(node, NULL, 3522258fa4SDavid Gibson of_rtc_table[i].compatible) { 3622258fa4SDavid Gibson struct resource *res; 3722258fa4SDavid Gibson 3822258fa4SDavid Gibson res = kmalloc(sizeof(*res), GFP_KERNEL); 3922258fa4SDavid Gibson if (!res) { 4022258fa4SDavid Gibson printk(KERN_ERR "OF RTC: Out of memory " 4122258fa4SDavid Gibson "allocating resource structure for %s\n", 4222258fa4SDavid Gibson node->full_name); 4322258fa4SDavid Gibson continue; 4422258fa4SDavid Gibson } 4522258fa4SDavid Gibson 4622258fa4SDavid Gibson err = of_address_to_resource(node, 0, res); 4722258fa4SDavid Gibson if (err) { 4822258fa4SDavid Gibson printk(KERN_ERR "OF RTC: Error " 4922258fa4SDavid Gibson "translating resources for %s\n", 5022258fa4SDavid Gibson node->full_name); 5122258fa4SDavid Gibson continue; 5222258fa4SDavid Gibson } 5322258fa4SDavid Gibson 5422258fa4SDavid Gibson printk(KERN_INFO "OF_RTC: %s is a %s @ 0x%llx-0x%llx\n", 5522258fa4SDavid Gibson node->full_name, plat_name, 5622258fa4SDavid Gibson (unsigned long long)res->start, 5722258fa4SDavid Gibson (unsigned long long)res->end); 5822258fa4SDavid Gibson platform_device_register_simple(plat_name, -1, res, 1); 5922258fa4SDavid Gibson } 6022258fa4SDavid Gibson } 6122258fa4SDavid Gibson } 62