blob: 7a5ee3fa26b23b19eac0431601a615470dfe8f87 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass57251282015-06-23 15:38:43 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass57251282015-06-23 15:38:43 -06005 */
6
7#ifndef __SYSCON_H
8#define __SYSCON_H
9
Masahiro Yamadae151a1c2018-04-19 12:14:04 +090010#include <dm/ofnode.h>
Simon Glassc20ee0e2017-08-29 14:15:50 -060011#include <fdtdec.h>
12
Simon Glass57251282015-06-23 15:38:43 -060013/**
14 * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS
15 *
16 * @regmap: Register map for this controller
17 */
18struct syscon_uc_info {
19 struct regmap *regmap;
20};
21
22/* So far there are no ops so this is a placeholder */
23struct 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 Schuchardt185f8122022-01-19 18:05:50 +010033 * Return: 0 if OK, -ve on error
Simon Glass57251282015-06-23 15:38:43 -060034 */
35struct 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 Glassac94b7b2016-01-17 16:11:08 -070042 * 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 Schuchardt185f8122022-01-19 18:05:50 +010046 * Return: 0 on success, -ENODEV if the ID was not found, or other -ve error
Simon Glassac94b7b2016-01-17 16:11:08 -070047 * code
48 */
49int 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 Glass57251282015-06-23 15:38:43 -060056 * are in use. This function looks up the regmap given this driver data.
57 *
58 * @driver_data: Driver data value to look up
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010059 * Return: register map correponding to @driver_data, or -ve error code
Simon Glass57251282015-06-23 15:38:43 -060060 */
61struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
62
63/**
Jean-Jacques Hiblot6c3af1f2018-11-29 10:57:37 +010064 * 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 Schuchardt185f8122022-01-19 18:05:50 +010071 * Return: A pointer to the regmap if found, ERR_PTR(-ve) on error
Jean-Jacques Hiblot6c3af1f2018-11-29 10:57:37 +010072 */
73struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev,
74 const char *name);
75
76/**
Simon Glass57251282015-06-23 15:38:43 -060077 * syscon_get_first_range() - get the first memory range from a syscon regmap
78 *
79 * @driver_data: Driver data value to look up
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010080 * Return: first region of register map correponding to @driver_data, or
Simon Glass57251282015-06-23 15:38:43 -060081 * -ve error code
82 */
83void *syscon_get_first_range(ulong driver_data);
84
Masahiro Yamadae151a1c2018-04-19 12:14:04 +090085/**
86 * syscon_node_to_regmap - get regmap from syscon
87 *
88 * @node: Device node of syscon
89 */
90struct regmap *syscon_node_to_regmap(ofnode node);
91
Simon Glass57251282015-06-23 15:38:43 -060092#endif