Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 5725128 | 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 | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __SYSCON_H |
| 8 | #define __SYSCON_H |
| 9 | |
Masahiro Yamada | e151a1c | 2018-04-19 12:14:04 +0900 | [diff] [blame] | 10 | #include <dm/ofnode.h> |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 11 | #include <fdtdec.h> |
| 12 | |
Simon Glass | 5725128 | 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 | |
| 28 | /** |
| 29 | * syscon_get_regmap() - Get access to a register map |
| 30 | * |
| 31 | * @dev: Device to check (UCLASS_SCON) |
| 32 | * @info: Returns regmap for the device |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 33 | * Return: 0 if OK, -ve on error |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 34 | */ |
| 35 | struct regmap *syscon_get_regmap(struct udevice *dev); |
| 36 | |
| 37 | /** |
| 38 | * syscon_get_regmap_by_driver_data() - Look up a controller by its ID |
| 39 | * |
| 40 | * Each system controller can be accessed by its driver data, which is |
| 41 | * assumed to be unique through the scope of all system controllers that |
Simon Glass | ac94b7b | 2016-01-17 16:11:08 -0700 | [diff] [blame] | 42 | * are in use. This function looks up the controller given this driver data. |
| 43 | * |
| 44 | * @driver_data: Driver data value to look up |
| 45 | * @devp: Returns the controller correponding to @driver_data |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 46 | * Return: 0 on success, -ENODEV if the ID was not found, or other -ve error |
Simon Glass | ac94b7b | 2016-01-17 16:11:08 -0700 | [diff] [blame] | 47 | * code |
| 48 | */ |
| 49 | int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp); |
| 50 | |
| 51 | /** |
| 52 | * syscon_get_regmap_by_driver_data() - Look up a controller by its ID |
| 53 | * |
| 54 | * Each system controller can be accessed by its driver data, which is |
| 55 | * assumed to be unique through the scope of all system controllers that |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 56 | * are in use. This function looks up the regmap given this driver data. |
| 57 | * |
| 58 | * @driver_data: Driver data value to look up |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 59 | * Return: register map correponding to @driver_data, or -ve error code |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 60 | */ |
| 61 | struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data); |
| 62 | |
| 63 | /** |
Jean-Jacques Hiblot | 6c3af1f | 2018-11-29 10:57:37 +0100 | [diff] [blame] | 64 | * syscon_regmap_lookup_by_phandle() - Look up a controller by a phandle |
| 65 | * |
| 66 | * This operates by looking up the given name in the device (device |
| 67 | * tree property) of the device using the system controller. |
| 68 | * |
| 69 | * @dev: Device using the system controller |
| 70 | * @name: Name of property referring to the system controller |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 71 | * Return: A pointer to the regmap if found, ERR_PTR(-ve) on error |
Jean-Jacques Hiblot | 6c3af1f | 2018-11-29 10:57:37 +0100 | [diff] [blame] | 72 | */ |
| 73 | struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev, |
| 74 | const char *name); |
| 75 | |
| 76 | /** |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 77 | * syscon_get_first_range() - get the first memory range from a syscon regmap |
| 78 | * |
| 79 | * @driver_data: Driver data value to look up |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 80 | * Return: first region of register map correponding to @driver_data, or |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 81 | * -ve error code |
| 82 | */ |
| 83 | void *syscon_get_first_range(ulong driver_data); |
| 84 | |
Masahiro Yamada | e151a1c | 2018-04-19 12:14:04 +0900 | [diff] [blame] | 85 | /** |
| 86 | * syscon_node_to_regmap - get regmap from syscon |
| 87 | * |
| 88 | * @node: Device node of syscon |
| 89 | */ |
| 90 | struct regmap *syscon_node_to_regmap(ofnode node); |
| 91 | |
Simon Glass | 5725128 | 2015-06-23 15:38:43 -0600 | [diff] [blame] | 92 | #endif |