s5p-dev-mfc.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2010-2011 Samsung Electronics Co.Ltd
  3. *
  4. * Base S5P MFC resource and device definitions
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/memblock.h>
  15. #include <linux/ioport.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/of.h>
  18. static struct platform_device s5p_device_mfc_l;
  19. static struct platform_device s5p_device_mfc_r;
  20. struct s5p_mfc_dt_meminfo {
  21. unsigned long loff;
  22. unsigned long lsize;
  23. unsigned long roff;
  24. unsigned long rsize;
  25. char *compatible;
  26. };
  27. struct s5p_mfc_reserved_mem {
  28. phys_addr_t base;
  29. unsigned long size;
  30. struct device *dev;
  31. };
  32. static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
  33. static void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
  34. phys_addr_t lbase, unsigned int lsize)
  35. {
  36. int i;
  37. s5p_mfc_mem[0].dev = &s5p_device_mfc_r.dev;
  38. s5p_mfc_mem[0].base = rbase;
  39. s5p_mfc_mem[0].size = rsize;
  40. s5p_mfc_mem[1].dev = &s5p_device_mfc_l.dev;
  41. s5p_mfc_mem[1].base = lbase;
  42. s5p_mfc_mem[1].size = lsize;
  43. for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
  44. struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
  45. if (memblock_remove(area->base, area->size)) {
  46. printk(KERN_ERR "Failed to reserve memory for MFC device (%ld bytes at 0x%08lx)\n",
  47. area->size, (unsigned long) area->base);
  48. area->base = 0;
  49. }
  50. }
  51. }
  52. int __init s5p_fdt_alloc_mfc_mem(unsigned long node, const char *uname,
  53. int depth, void *data)
  54. {
  55. const __be32 *prop;
  56. int len;
  57. struct s5p_mfc_dt_meminfo mfc_mem;
  58. if (!data)
  59. return 0;
  60. if (!of_flat_dt_is_compatible(node, data))
  61. return 0;
  62. prop = of_get_flat_dt_prop(node, "samsung,mfc-l", &len);
  63. if (!prop || (len != 2 * sizeof(unsigned long)))
  64. return 0;
  65. mfc_mem.loff = be32_to_cpu(prop[0]);
  66. mfc_mem.lsize = be32_to_cpu(prop[1]);
  67. prop = of_get_flat_dt_prop(node, "samsung,mfc-r", &len);
  68. if (!prop || (len != 2 * sizeof(unsigned long)))
  69. return 0;
  70. mfc_mem.roff = be32_to_cpu(prop[0]);
  71. mfc_mem.rsize = be32_to_cpu(prop[1]);
  72. s5p_mfc_reserve_mem(mfc_mem.roff, mfc_mem.rsize,
  73. mfc_mem.loff, mfc_mem.lsize);
  74. return 1;
  75. }