xref: /openbmc/u-boot/include/syscon.h (revision c20ee0ed)
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 
11*c20ee0edSSimon Glass #include <fdtdec.h>
12*c20ee0edSSimon Glass 
1357251285SSimon Glass /**
1457251285SSimon Glass  * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS
1557251285SSimon Glass  *
1657251285SSimon Glass  * @regmap:	Register map for this controller
1757251285SSimon Glass  */
1857251285SSimon Glass struct syscon_uc_info {
1957251285SSimon Glass 	struct regmap *regmap;
2057251285SSimon Glass };
2157251285SSimon Glass 
2257251285SSimon Glass /* So far there are no ops so this is a placeholder */
2357251285SSimon Glass struct syscon_ops {
2457251285SSimon Glass };
2557251285SSimon Glass 
2657251285SSimon Glass #define syscon_get_ops(dev)        ((struct syscon_ops *)(dev)->driver->ops)
2757251285SSimon Glass 
2804ecf36bSSimon Glass #if CONFIG_IS_ENABLED(OF_PLATDATA)
2904ecf36bSSimon Glass /*
3004ecf36bSSimon Glass  * We don't support 64-bit machines. If they are so resource-contrained that
3104ecf36bSSimon Glass  * they need to use OF_PLATDATA, something is horribly wrong with the
3204ecf36bSSimon Glass  * education of our hardware engineers.
33*c20ee0edSSimon Glass  *
34*c20ee0edSSimon Glass  * Update: 64-bit is now supported and we have an education crisis.
3504ecf36bSSimon Glass  */
3604ecf36bSSimon Glass struct syscon_base_platdata {
37*c20ee0edSSimon Glass 	fdt_val_t reg[2];
3804ecf36bSSimon Glass };
3904ecf36bSSimon Glass #endif
4004ecf36bSSimon Glass 
4157251285SSimon Glass /**
4257251285SSimon Glass  * syscon_get_regmap() - Get access to a register map
4357251285SSimon Glass  *
4457251285SSimon Glass  * @dev:	Device to check (UCLASS_SCON)
4557251285SSimon Glass  * @info:	Returns regmap for the device
4657251285SSimon Glass  * @return 0 if OK, -ve on error
4757251285SSimon Glass  */
4857251285SSimon Glass struct regmap *syscon_get_regmap(struct udevice *dev);
4957251285SSimon Glass 
5057251285SSimon Glass /**
5157251285SSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
5257251285SSimon Glass  *
5357251285SSimon Glass  * Each system controller can be accessed by its driver data, which is
5457251285SSimon Glass  * assumed to be unique through the scope of all system controllers that
55ac94b7bcSSimon Glass  * are in use. This function looks up the controller given this driver data.
56ac94b7bcSSimon Glass  *
57ac94b7bcSSimon Glass  * @driver_data:	Driver data value to look up
58ac94b7bcSSimon Glass  * @devp:		Returns the controller correponding to @driver_data
59ac94b7bcSSimon Glass  * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
60ac94b7bcSSimon Glass  *	   code
61ac94b7bcSSimon Glass  */
62ac94b7bcSSimon Glass int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
63ac94b7bcSSimon Glass 
64ac94b7bcSSimon Glass /**
65ac94b7bcSSimon Glass  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
66ac94b7bcSSimon Glass  *
67ac94b7bcSSimon Glass  * Each system controller can be accessed by its driver data, which is
68ac94b7bcSSimon Glass  * assumed to be unique through the scope of all system controllers that
6957251285SSimon Glass  * are in use. This function looks up the regmap given this driver data.
7057251285SSimon Glass  *
7157251285SSimon Glass  * @driver_data:	Driver data value to look up
7257251285SSimon Glass  * @return register map correponding to @driver_data, or -ve error code
7357251285SSimon Glass  */
7457251285SSimon Glass struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
7557251285SSimon Glass 
7657251285SSimon Glass /**
7757251285SSimon Glass  * syscon_get_first_range() - get the first memory range from a syscon regmap
7857251285SSimon Glass  *
7957251285SSimon Glass  * @driver_data:	Driver data value to look up
8057251285SSimon Glass  * @return first region of register map correponding to @driver_data, or
8157251285SSimon Glass  *			-ve error code
8257251285SSimon Glass  */
8357251285SSimon Glass void *syscon_get_first_range(ulong driver_data);
8457251285SSimon Glass 
8557251285SSimon Glass #endif
86