This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc / syslib / ppc_sys.c
1 /*
2  * arch/ppc/syslib/ppc_sys.c
3  *
4  * PPC System library functions
5  *
6  * Maintainer: Kumar Gala <kumar.gala@freescale.com>
7  *
8  * Copyright 2005 Freescale Semiconductor Inc.
9  *
10  * This program is free software; you can redistribute  it and/or modify it
11  * under  the terms of  the GNU General  Public License as published by the
12  * Free Software Foundation;  either version 2 of the  License, or (at your
13  * option) any later version.
14  */
15
16 #include <asm/ppc_sys.h>
17
18 int (*ppc_sys_device_fixup) (struct platform_device * pdev);
19
20 static int ppc_sys_inited;
21
22 void __init identify_ppc_sys_by_id(u32 id)
23 {
24         unsigned int i = 0;
25         while (1) {
26                 if ((ppc_sys_specs[i].mask & id) == ppc_sys_specs[i].value)
27                         break;
28                 i++;
29         }
30
31         cur_ppc_sys_spec = &ppc_sys_specs[i];
32
33         return;
34 }
35
36 void __init identify_ppc_sys_by_name(char *name)
37 {
38         /* TODO */
39         return;
40 }
41
42 /* Update all memory resources by paddr, call before platform_device_register */
43 void __init
44 ppc_sys_fixup_mem_resource(struct platform_device *pdev, phys_addr_t paddr)
45 {
46         int i;
47         for (i = 0; i < pdev->num_resources; i++) {
48                 struct resource *r = &pdev->resource[i];
49                 if ((r->flags & IORESOURCE_MEM) == IORESOURCE_MEM) {
50                         r->start += paddr;
51                         r->end += paddr;
52                 }
53         }
54 }
55
56 /* Get platform_data pointer out of platform device, call before platform_device_register */
57 void *__init ppc_sys_get_pdata(enum ppc_sys_devices dev)
58 {
59         return ppc_sys_platform_devices[dev].dev.platform_data;
60 }
61
62 void ppc_sys_device_remove(enum ppc_sys_devices dev)
63 {
64         unsigned int i;
65
66         if (ppc_sys_inited) {
67                 platform_device_unregister(&ppc_sys_platform_devices[dev]);
68         } else {
69                 if (cur_ppc_sys_spec == NULL)
70                         return;
71                 for (i = 0; i < cur_ppc_sys_spec->num_devices; i++)
72                         if (cur_ppc_sys_spec->device_list[i] == dev)
73                                 cur_ppc_sys_spec->device_list[i] = -1;
74         }
75 }
76
77 static int __init ppc_sys_init(void)
78 {
79         unsigned int i, dev_id, ret = 0;
80
81         BUG_ON(cur_ppc_sys_spec == NULL);
82
83         for (i = 0; i < cur_ppc_sys_spec->num_devices; i++) {
84                 dev_id = cur_ppc_sys_spec->device_list[i];
85                 if (dev_id != -1) {
86                         if (ppc_sys_device_fixup != NULL)
87                                 ppc_sys_device_fixup(&ppc_sys_platform_devices
88                                                      [dev_id]);
89                         if (platform_device_register
90                             (&ppc_sys_platform_devices[dev_id])) {
91                                 ret = 1;
92                                 printk(KERN_ERR
93                                        "unable to register device %d\n",
94                                        dev_id);
95                         }
96                 }
97         }
98
99         ppc_sys_inited = 1;
100         return ret;
101 }
102
103 subsys_initcall(ppc_sys_init);