xref: /openbmc/u-boot/include/syscon.h (revision 04ecf36b)
157251285SSimon Glass /*
257251285SSimon Glass  * Copyright (c) 2015 Google, Inc
357251285SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
457251285SSimon Glass  *
557251285SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
657251285SSimon Glass  */
757251285SSimon Glass 
857251285SSimon Glass #ifndef __SYSCON_H
957251285SSimon Glass #define __SYSCON_H
1057251285SSimon Glass 
1157251285SSimon Glass /**
1257251285SSimon Glass  * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS
1357251285SSimon Glass  *
1457251285SSimon Glass  * @regmap:	Register map for this controller
1557251285SSimon Glass  */
1657251285SSimon Glass struct syscon_uc_info {
1757251285SSimon Glass 	struct regmap *regmap;
1857251285SSimon Glass };
1957251285SSimon Glass 
2057251285SSimon Glass /* So far there are no ops so this is a placeholder */
2157251285SSimon Glass struct syscon_ops {
2257251285SSimon Glass };
2357251285SSimon Glass 
2457251285SSimon Glass #define syscon_get_ops(dev)        ((struct syscon_ops *)(dev)->driver->ops)
2557251285SSimon Glass 
26*04ecf36bSSimon Glass #if CONFIG_IS_ENABLED(OF_PLATDATA)
27*04ecf36bSSimon Glass /*
28*04ecf36bSSimon Glass  * We don't support 64-bit machines. If they are so resource-contrained that
29*04ecf36bSSimon Glass  * they need to use OF_PLATDATA, something is horribly wrong with the
30*04ecf36bSSimon Glass  * education of our hardware engineers.
31*04ecf36bSSimon Glass  */
32*04ecf36bSSimon Glass struct syscon_base_platdata {
33*04ecf36bSSimon Glass 	u32 reg[2];
34*04ecf36bSSimon Glass };
35*04ecf36bSSimon Glass #endif
36*04ecf36bSSimon Glass 
3757251285SSimon Glass /**
3857251285SSimon Glass  * syscon_get_regmap() - Get access to a register map
3957251285SSimon Glass  *
4057251285SSimon Glass  * @dev:	Device to check (UCLASS_SCON)
4157251285SSimon Glass  * @info:	Returns regmap for the device
4257251285SSimon Glass  * @return 0 if OK, -ve on error
4357251285SSimon Glass  */
4457251285SSimon Glass struct regmap *syscon_get_regmap(struct udevice *dev);
4557251285SSimon Glass 
4657251285SSimon Glass /**
4757251285SSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
4857251285SSimon Glass  *
4957251285SSimon Glass  * Each system controller can be accessed by its driver data, which is
5057251285SSimon Glass  * assumed to be unique through the scope of all system controllers that
51ac94b7bcSSimon Glass  * are in use. This function looks up the controller given this driver data.
52ac94b7bcSSimon Glass  *
53ac94b7bcSSimon Glass  * @driver_data:	Driver data value to look up
54ac94b7bcSSimon Glass  * @devp:		Returns the controller correponding to @driver_data
55ac94b7bcSSimon Glass  * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
56ac94b7bcSSimon Glass  *	   code
57ac94b7bcSSimon Glass  */
58ac94b7bcSSimon Glass int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
59ac94b7bcSSimon Glass 
60ac94b7bcSSimon Glass /**
61ac94b7bcSSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
62ac94b7bcSSimon Glass  *
63ac94b7bcSSimon Glass  * Each system controller can be accessed by its driver data, which is
64ac94b7bcSSimon Glass  * assumed to be unique through the scope of all system controllers that
6557251285SSimon Glass  * are in use. This function looks up the regmap given this driver data.
6657251285SSimon Glass  *
6757251285SSimon Glass  * @driver_data:	Driver data value to look up
6857251285SSimon Glass  * @return register map correponding to @driver_data, or -ve error code
6957251285SSimon Glass  */
7057251285SSimon Glass struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
7157251285SSimon Glass 
7257251285SSimon Glass /**
7357251285SSimon Glass  * syscon_get_first_range() - get the first memory range from a syscon regmap
7457251285SSimon Glass  *
7557251285SSimon Glass  * @driver_data:	Driver data value to look up
7657251285SSimon Glass  * @return first region of register map correponding to @driver_data, or
7757251285SSimon Glass  *			-ve error code
7857251285SSimon Glass  */
7957251285SSimon Glass void *syscon_get_first_range(ulong driver_data);
8057251285SSimon Glass 
8157251285SSimon Glass #endif
82