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