sec_of.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * COPYRIGHT(C) 2022 Samsung Electronics Co., Ltd. All Right Reserved.
  4. */
  5. #ifndef __SEC_OF_H__
  6. #define __SEC_OF_H__
  7. #include <linux/kernel.h>
  8. #include <linux/of.h>
  9. #ifdef CONFIG_OF
  10. static inline int sec_of_parse_reg_prop(struct device_node *np,
  11. phys_addr_t *base, phys_addr_t *size)
  12. {
  13. const __be32 *cell;
  14. int address_cells;
  15. int size_cells;
  16. cell = of_get_property(np, "reg", NULL);
  17. if (IS_ERR_OR_NULL(cell))
  18. return -EINVAL;
  19. /* NOTE: 'of_n_addr_cells' and 'of_n_size_cells' always
  20. * search from the parent node except 'root'.
  21. * To use '#address-cells' and '#size-cells' of the current node,
  22. * these 'if' statements are rquired.
  23. */
  24. if (of_property_read_u32(np, "#address-cells", &address_cells))
  25. address_cells = of_n_addr_cells(np);
  26. if (of_property_read_u32(np, "#size-cells", &size_cells))
  27. size_cells = of_n_size_cells(np);
  28. *base = (phys_addr_t)of_read_number(cell, address_cells);
  29. *size = (phys_addr_t)of_read_number(cell + address_cells, size_cells);
  30. return 0;
  31. }
  32. static inline int sec_of_test_debug_level(const struct device_node *np,
  33. const char *node_name, unsigned int sec_dbg_level)
  34. {
  35. int nr_dbg_level;
  36. int i;
  37. nr_dbg_level = (int)of_property_count_u32_elems(np, node_name);
  38. if (nr_dbg_level <= 0)
  39. return -ENOENT;
  40. for (i = 0; i < nr_dbg_level; i++) {
  41. u32 dbg_level;
  42. of_property_read_u32_index(np, node_name, i, &dbg_level);
  43. if (sec_dbg_level == (unsigned int)dbg_level)
  44. return 0;
  45. }
  46. return -EINVAL;
  47. }
  48. #else
  49. static inline int sec_of_parse_reg_prop(struct device_node *np, phys_addr_t *base, phys_addr_t *size) { return -ENODEV; }
  50. static inline int sec_of_test_debug_level(const struct device_node *np, const char *node_name, unsigned int sec_dbg_level) { return -ENODEV; };
  51. #endif
  52. #endif /* __SEC_OF_H__ */