PageRenderTime 190ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 1ms

/arch/powerpc/platforms/chrp/nvram.c

https://bitbucket.org/cresqo/cm7-p500-kernel
C | 89 lines | 64 code | 14 blank | 11 comment | 16 complexity | 04c205874d332179843a47b83ae9984f MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*
  2. * c 2001 PPC 64 Team, IBM Corp
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * /dev/nvram driver for PPC
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/spinlock.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/prom.h>
  17. #include <asm/machdep.h>
  18. #include <asm/rtas.h>
  19. #include "chrp.h"
  20. static unsigned int nvram_size;
  21. static unsigned char nvram_buf[4];
  22. static DEFINE_SPINLOCK(nvram_lock);
  23. static unsigned char chrp_nvram_read(int addr)
  24. {
  25. unsigned int done;
  26. unsigned long flags;
  27. unsigned char ret;
  28. if (addr >= nvram_size) {
  29. printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
  30. current->comm, addr, nvram_size);
  31. return 0xff;
  32. }
  33. spin_lock_irqsave(&nvram_lock, flags);
  34. if ((rtas_call(rtas_token("nvram-fetch"), 3, 2, &done, addr,
  35. __pa(nvram_buf), 1) != 0) || 1 != done)
  36. ret = 0xff;
  37. else
  38. ret = nvram_buf[0];
  39. spin_unlock_irqrestore(&nvram_lock, flags);
  40. return ret;
  41. }
  42. static void chrp_nvram_write(int addr, unsigned char val)
  43. {
  44. unsigned int done;
  45. unsigned long flags;
  46. if (addr >= nvram_size) {
  47. printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",
  48. current->comm, addr, nvram_size);
  49. return;
  50. }
  51. spin_lock_irqsave(&nvram_lock, flags);
  52. nvram_buf[0] = val;
  53. if ((rtas_call(rtas_token("nvram-store"), 3, 2, &done, addr,
  54. __pa(nvram_buf), 1) != 0) || 1 != done)
  55. printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
  56. spin_unlock_irqrestore(&nvram_lock, flags);
  57. }
  58. void __init chrp_nvram_init(void)
  59. {
  60. struct device_node *nvram;
  61. const unsigned int *nbytes_p;
  62. unsigned int proplen;
  63. nvram = of_find_node_by_type(NULL, "nvram");
  64. if (nvram == NULL)
  65. return;
  66. nbytes_p = of_get_property(nvram, "#bytes", &proplen);
  67. if (nbytes_p == NULL || proplen != sizeof(unsigned int))
  68. return;
  69. nvram_size = *nbytes_p;
  70. printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
  71. of_node_put(nvram);
  72. ppc_md.nvram_read_val = chrp_nvram_read;
  73. ppc_md.nvram_write_val = chrp_nvram_write;
  74. return;
  75. }