2 * arch/ppc/syslib/ppc_sys.c
4 * PPC System library functions
6 * Maintainer: Kumar Gala <kumar.gala@freescale.com>
8 * Copyright 2005 Freescale Semiconductor Inc.
9 * Copyright 2005 MontaVista, Inc. by Vitaly Bordug <vbordug@ru.mvista.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <asm/ppc_sys.h>
19 int (*ppc_sys_device_fixup) (struct platform_device * pdev);
21 static int ppc_sys_inited;
23 void __init identify_ppc_sys_by_id(u32 id)
27 if ((ppc_sys_specs[i].mask & id) == ppc_sys_specs[i].value)
32 cur_ppc_sys_spec = &ppc_sys_specs[i];
37 void __init identify_ppc_sys_by_name(char *name)
40 while (ppc_sys_specs[i].ppc_sys_name[0])
42 if (!strcmp(ppc_sys_specs[i].ppc_sys_name, name))
46 cur_ppc_sys_spec = &ppc_sys_specs[i];
50 static int __init count_sys_specs(void)
53 while (ppc_sys_specs[i].ppc_sys_name[0])
58 static int __init find_chip_by_name_and_id(char *name, u32 id)
63 unsigned int dups = 0;
65 unsigned char matched[count_sys_specs()];
67 while (ppc_sys_specs[i].ppc_sys_name[0]) {
68 if (!strcmp(ppc_sys_specs[i].ppc_sys_name, name))
76 for (i = 0; i < j; i++) {
77 if ((ppc_sys_specs[matched[i]].mask & id) ==
78 ppc_sys_specs[matched[i]].value) {
83 ret = (dups == 1) ? ret : (-1 * dups);
88 void __init identify_ppc_sys_by_name_and_id(char *name, u32 id)
90 int i = find_chip_by_name_and_id(name, id);
92 cur_ppc_sys_spec = &ppc_sys_specs[i];
95 /* Update all memory resources by paddr, call before platform_device_register */
97 ppc_sys_fixup_mem_resource(struct platform_device *pdev, phys_addr_t paddr)
100 for (i = 0; i < pdev->num_resources; i++) {
101 struct resource *r = &pdev->resource[i];
102 if ((r->flags & IORESOURCE_MEM) == IORESOURCE_MEM) {
109 /* Get platform_data pointer out of platform device, call before platform_device_register */
110 void *__init ppc_sys_get_pdata(enum ppc_sys_devices dev)
112 return ppc_sys_platform_devices[dev].dev.platform_data;
115 void ppc_sys_device_remove(enum ppc_sys_devices dev)
119 if (ppc_sys_inited) {
120 platform_device_unregister(&ppc_sys_platform_devices[dev]);
122 if (cur_ppc_sys_spec == NULL)
124 for (i = 0; i < cur_ppc_sys_spec->num_devices; i++)
125 if (cur_ppc_sys_spec->device_list[i] == dev)
126 cur_ppc_sys_spec->device_list[i] = -1;
130 static int __init ppc_sys_init(void)
132 unsigned int i, dev_id, ret = 0;
134 BUG_ON(cur_ppc_sys_spec == NULL);
136 for (i = 0; i < cur_ppc_sys_spec->num_devices; i++) {
137 dev_id = cur_ppc_sys_spec->device_list[i];
139 if (ppc_sys_device_fixup != NULL)
140 ppc_sys_device_fixup(&ppc_sys_platform_devices
142 if (platform_device_register
143 (&ppc_sys_platform_devices[dev_id])) {
146 "unable to register device %d\n",
156 subsys_initcall(ppc_sys_init);