Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Instantiate mmio-mapped RTC chips based on device tree information
0004  *
0005  * Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
0006  */
0007 #include <linux/kernel.h>
0008 #include <linux/of.h>
0009 #include <linux/init.h>
0010 #include <linux/of_address.h>
0011 #include <linux/of_platform.h>
0012 #include <linux/slab.h>
0013 
0014 #include <asm/prom.h>
0015 
0016 static __initdata struct {
0017     const char *compatible;
0018     char *plat_name;
0019 } of_rtc_table[] = {
0020     { "ds1743-nvram", "rtc-ds1742" },
0021 };
0022 
0023 void __init of_instantiate_rtc(void)
0024 {
0025     struct device_node *node;
0026     int err;
0027     int i;
0028 
0029     for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) {
0030         char *plat_name = of_rtc_table[i].plat_name;
0031 
0032         for_each_compatible_node(node, NULL,
0033                      of_rtc_table[i].compatible) {
0034             struct resource *res;
0035 
0036             res = kmalloc(sizeof(*res), GFP_KERNEL);
0037             if (!res) {
0038                 printk(KERN_ERR "OF RTC: Out of memory "
0039                        "allocating resource structure for %pOF\n",
0040                        node);
0041                 continue;
0042             }
0043 
0044             err = of_address_to_resource(node, 0, res);
0045             if (err) {
0046                 printk(KERN_ERR "OF RTC: Error "
0047                        "translating resources for %pOF\n",
0048                        node);
0049                 continue;
0050             }
0051 
0052             printk(KERN_INFO "OF_RTC: %pOF is a %s @ 0x%llx-0x%llx\n",
0053                    node, plat_name,
0054                    (unsigned long long)res->start,
0055                    (unsigned long long)res->end);
0056             platform_device_register_simple(plat_name, -1, res, 1);
0057         }
0058     }
0059 }