ppc_sys.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <asm/ppc_sys.h>
  16. int (*ppc_sys_device_fixup) (struct platform_device * pdev);
  17. static int ppc_sys_inited;
  18. void __init identify_ppc_sys_by_id(u32 id)
  19. {
  20. unsigned int i = 0;
  21. while (1) {
  22. if ((ppc_sys_specs[i].mask & id) == ppc_sys_specs[i].value)
  23. break;
  24. i++;
  25. }
  26. cur_ppc_sys_spec = &ppc_sys_specs[i];
  27. return;
  28. }
  29. void __init identify_ppc_sys_by_name(char *name)
  30. {
  31. /* TODO */
  32. return;
  33. }
  34. /* Update all memory resources by paddr, call before platform_device_register */
  35. void __init
  36. ppc_sys_fixup_mem_resource(struct platform_device *pdev, phys_addr_t paddr)
  37. {
  38. int i;
  39. for (i = 0; i < pdev->num_resources; i++) {
  40. struct resource *r = &pdev->resource[i];
  41. if ((r->flags & IORESOURCE_MEM) == IORESOURCE_MEM) {
  42. r->start += paddr;
  43. r->end += paddr;
  44. }
  45. }
  46. }
  47. /* Get platform_data pointer out of platform device, call before platform_device_register */
  48. void *__init ppc_sys_get_pdata(enum ppc_sys_devices dev)
  49. {
  50. return ppc_sys_platform_devices[dev].dev.platform_data;
  51. }
  52. void ppc_sys_device_remove(enum ppc_sys_devices dev)
  53. {
  54. unsigned int i;
  55. if (ppc_sys_inited) {
  56. platform_device_unregister(&ppc_sys_platform_devices[dev]);
  57. } else {
  58. if (cur_ppc_sys_spec == NULL)
  59. return;
  60. for (i = 0; i < cur_ppc_sys_spec->num_devices; i++)
  61. if (cur_ppc_sys_spec->device_list[i] == dev)
  62. cur_ppc_sys_spec->device_list[i] = -1;
  63. }
  64. }
  65. static int __init ppc_sys_init(void)
  66. {
  67. unsigned int i, dev_id, ret = 0;
  68. BUG_ON(cur_ppc_sys_spec == NULL);
  69. for (i = 0; i < cur_ppc_sys_spec->num_devices; i++) {
  70. dev_id = cur_ppc_sys_spec->device_list[i];
  71. if (dev_id != -1) {
  72. if (ppc_sys_device_fixup != NULL)
  73. ppc_sys_device_fixup(&ppc_sys_platform_devices
  74. [dev_id]);
  75. if (platform_device_register
  76. (&ppc_sys_platform_devices[dev_id])) {
  77. ret = 1;
  78. printk(KERN_ERR
  79. "unable to register device %d\n",
  80. dev_id);
  81. }
  82. }
  83. }
  84. ppc_sys_inited = 1;
  85. return ret;
  86. }
  87. subsys_initcall(ppc_sys_init);