syscon.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __SYSCON_H
  7. #define __SYSCON_H
  8. #include <dm/ofnode.h>
  9. #include <fdtdec.h>
  10. /**
  11. * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS
  12. *
  13. * @regmap: Register map for this controller
  14. */
  15. struct syscon_uc_info {
  16. struct regmap *regmap;
  17. };
  18. /* So far there are no ops so this is a placeholder */
  19. struct syscon_ops {
  20. };
  21. #define syscon_get_ops(dev) ((struct syscon_ops *)(dev)->driver->ops)
  22. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  23. /*
  24. * We don't support 64-bit machines. If they are so resource-contrained that
  25. * they need to use OF_PLATDATA, something is horribly wrong with the
  26. * education of our hardware engineers.
  27. *
  28. * Update: 64-bit is now supported and we have an education crisis.
  29. */
  30. struct syscon_base_platdata {
  31. fdt_val_t reg[2];
  32. };
  33. #endif
  34. /**
  35. * syscon_get_regmap() - Get access to a register map
  36. *
  37. * @dev: Device to check (UCLASS_SCON)
  38. * @info: Returns regmap for the device
  39. * @return 0 if OK, -ve on error
  40. */
  41. struct regmap *syscon_get_regmap(struct udevice *dev);
  42. /**
  43. * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  44. *
  45. * Each system controller can be accessed by its driver data, which is
  46. * assumed to be unique through the scope of all system controllers that
  47. * are in use. This function looks up the controller given this driver data.
  48. *
  49. * @driver_data: Driver data value to look up
  50. * @devp: Returns the controller correponding to @driver_data
  51. * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
  52. * code
  53. */
  54. int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
  55. /**
  56. * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  57. *
  58. * Each system controller can be accessed by its driver data, which is
  59. * assumed to be unique through the scope of all system controllers that
  60. * are in use. This function looks up the regmap given this driver data.
  61. *
  62. * @driver_data: Driver data value to look up
  63. * @return register map correponding to @driver_data, or -ve error code
  64. */
  65. struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
  66. /**
  67. * syscon_regmap_lookup_by_phandle() - Look up a controller by a phandle
  68. *
  69. * This operates by looking up the given name in the device (device
  70. * tree property) of the device using the system controller.
  71. *
  72. * @dev: Device using the system controller
  73. * @name: Name of property referring to the system controller
  74. * @return A pointer to the regmap if found, ERR_PTR(-ve) on error
  75. */
  76. struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev,
  77. const char *name);
  78. /**
  79. * syscon_get_first_range() - get the first memory range from a syscon regmap
  80. *
  81. * @driver_data: Driver data value to look up
  82. * @return first region of register map correponding to @driver_data, or
  83. * -ve error code
  84. */
  85. void *syscon_get_first_range(ulong driver_data);
  86. /**
  87. * syscon_node_to_regmap - get regmap from syscon
  88. *
  89. * @node: Device node of syscon
  90. */
  91. struct regmap *syscon_node_to_regmap(ofnode node);
  92. #endif