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