syscon.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  23. * syscon_get_regmap() - Get access to a register map
  24. *
  25. * @dev: Device to check (UCLASS_SCON)
  26. * @info: Returns regmap for the device
  27. * Return: 0 if OK, -ve on error
  28. */
  29. struct regmap *syscon_get_regmap(struct udevice *dev);
  30. /**
  31. * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  32. *
  33. * Each system controller can be accessed by its driver data, which is
  34. * assumed to be unique through the scope of all system controllers that
  35. * are in use. This function looks up the controller given this driver data.
  36. *
  37. * @driver_data: Driver data value to look up
  38. * @devp: Returns the controller correponding to @driver_data
  39. * Return: 0 on success, -ENODEV if the ID was not found, or other -ve error
  40. * code
  41. */
  42. int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
  43. /**
  44. * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  45. *
  46. * Each system controller can be accessed by its driver data, which is
  47. * assumed to be unique through the scope of all system controllers that
  48. * are in use. This function looks up the regmap given this driver data.
  49. *
  50. * @driver_data: Driver data value to look up
  51. * Return: register map correponding to @driver_data, or -ve error code
  52. */
  53. struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
  54. /**
  55. * syscon_regmap_lookup_by_phandle() - Look up a controller by a phandle
  56. *
  57. * This operates by looking up the given name in the device (device
  58. * tree property) of the device using the system controller.
  59. *
  60. * @dev: Device using the system controller
  61. * @name: Name of property referring to the system controller
  62. * Return: A pointer to the regmap if found, ERR_PTR(-ve) on error
  63. */
  64. struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev,
  65. const char *name);
  66. /**
  67. * syscon_get_first_range() - get the first memory range from a syscon regmap
  68. *
  69. * @driver_data: Driver data value to look up
  70. * Return: first region of register map correponding to @driver_data, or
  71. * -ve error code
  72. */
  73. void *syscon_get_first_range(ulong driver_data);
  74. /**
  75. * syscon_node_to_regmap - get regmap from syscon
  76. *
  77. * @node: Device node of syscon
  78. */
  79. struct regmap *syscon_node_to_regmap(ofnode node);
  80. #endif