xref: /openbmc/u-boot/include/syscon.h (revision 83d290c5)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
257251285SSimon Glass /*
357251285SSimon Glass  * Copyright (c) 2015 Google, Inc
457251285SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
557251285SSimon Glass  */
657251285SSimon Glass 
757251285SSimon Glass #ifndef __SYSCON_H
857251285SSimon Glass #define __SYSCON_H
957251285SSimon Glass 
10c20ee0edSSimon Glass #include <fdtdec.h>
11c20ee0edSSimon Glass 
1257251285SSimon Glass /**
1357251285SSimon Glass  * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS
1457251285SSimon Glass  *
1557251285SSimon Glass  * @regmap:	Register map for this controller
1657251285SSimon Glass  */
1757251285SSimon Glass struct syscon_uc_info {
1857251285SSimon Glass 	struct regmap *regmap;
1957251285SSimon Glass };
2057251285SSimon Glass 
2157251285SSimon Glass /* So far there are no ops so this is a placeholder */
2257251285SSimon Glass struct syscon_ops {
2357251285SSimon Glass };
2457251285SSimon Glass 
2557251285SSimon Glass #define syscon_get_ops(dev)        ((struct syscon_ops *)(dev)->driver->ops)
2657251285SSimon Glass 
2704ecf36bSSimon Glass #if CONFIG_IS_ENABLED(OF_PLATDATA)
2804ecf36bSSimon Glass /*
2904ecf36bSSimon Glass  * We don't support 64-bit machines. If they are so resource-contrained that
3004ecf36bSSimon Glass  * they need to use OF_PLATDATA, something is horribly wrong with the
3104ecf36bSSimon Glass  * education of our hardware engineers.
32c20ee0edSSimon Glass  *
33c20ee0edSSimon Glass  * Update: 64-bit is now supported and we have an education crisis.
3404ecf36bSSimon Glass  */
3504ecf36bSSimon Glass struct syscon_base_platdata {
36c20ee0edSSimon Glass 	fdt_val_t reg[2];
3704ecf36bSSimon Glass };
3804ecf36bSSimon Glass #endif
3904ecf36bSSimon Glass 
4057251285SSimon Glass /**
4157251285SSimon Glass  * syscon_get_regmap() - Get access to a register map
4257251285SSimon Glass  *
4357251285SSimon Glass  * @dev:	Device to check (UCLASS_SCON)
4457251285SSimon Glass  * @info:	Returns regmap for the device
4557251285SSimon Glass  * @return 0 if OK, -ve on error
4657251285SSimon Glass  */
4757251285SSimon Glass struct regmap *syscon_get_regmap(struct udevice *dev);
4857251285SSimon Glass 
4957251285SSimon Glass /**
5057251285SSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
5157251285SSimon Glass  *
5257251285SSimon Glass  * Each system controller can be accessed by its driver data, which is
5357251285SSimon Glass  * assumed to be unique through the scope of all system controllers that
54ac94b7bcSSimon Glass  * are in use. This function looks up the controller given this driver data.
55ac94b7bcSSimon Glass  *
56ac94b7bcSSimon Glass  * @driver_data:	Driver data value to look up
57ac94b7bcSSimon Glass  * @devp:		Returns the controller correponding to @driver_data
58ac94b7bcSSimon Glass  * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
59ac94b7bcSSimon Glass  *	   code
60ac94b7bcSSimon Glass  */
61ac94b7bcSSimon Glass int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
62ac94b7bcSSimon Glass 
63ac94b7bcSSimon Glass /**
64ac94b7bcSSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
65ac94b7bcSSimon Glass  *
66ac94b7bcSSimon Glass  * Each system controller can be accessed by its driver data, which is
67ac94b7bcSSimon Glass  * assumed to be unique through the scope of all system controllers that
6857251285SSimon Glass  * are in use. This function looks up the regmap given this driver data.
6957251285SSimon Glass  *
7057251285SSimon Glass  * @driver_data:	Driver data value to look up
7157251285SSimon Glass  * @return register map correponding to @driver_data, or -ve error code
7257251285SSimon Glass  */
7357251285SSimon Glass struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
7457251285SSimon Glass 
7557251285SSimon Glass /**
7657251285SSimon Glass  * syscon_get_first_range() - get the first memory range from a syscon regmap
7757251285SSimon Glass  *
7857251285SSimon Glass  * @driver_data:	Driver data value to look up
7957251285SSimon Glass  * @return first region of register map correponding to @driver_data, or
8057251285SSimon Glass  *			-ve error code
8157251285SSimon Glass  */
8257251285SSimon Glass void *syscon_get_first_range(ulong driver_data);
8357251285SSimon Glass 
8457251285SSimon Glass #endif
85