Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
| 7 | * Marek Vasut <marex@denx.de> |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | 6fe43a3 | 2017-05-18 20:08:59 -0600 | [diff] [blame] | 10 | #ifndef _DM_FDTADDR_H |
| 11 | #define _DM_FDTADDR_H |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 12 | |
| 13 | #include <fdtdec.h> |
| 14 | |
| 15 | struct udevice; |
| 16 | |
| 17 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 18 | * devfdt_get_addr() - Get the reg property of a device |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 19 | * |
| 20 | * @dev: Pointer to a device |
| 21 | * |
| 22 | * @return addr |
| 23 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 24 | fdt_addr_t devfdt_get_addr(struct udevice *dev); |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 25 | |
| 26 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 27 | * devfdt_get_addr_ptr() - Return pointer to the address of the reg property |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 28 | * of a device |
| 29 | * |
| 30 | * @dev: Pointer to a device |
| 31 | * |
| 32 | * @return Pointer to addr, or NULL if there is no such property |
| 33 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 34 | void *devfdt_get_addr_ptr(struct udevice *dev); |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 35 | |
| 36 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 37 | * devfdt_map_physmem() - Read device address from reg property of the |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 38 | * device node and map the address into CPU address |
| 39 | * space. |
| 40 | * |
| 41 | * @dev: Pointer to device |
| 42 | * @size: size of the memory to map |
| 43 | * |
| 44 | * @return mapped address, or NULL if the device does not have reg |
| 45 | * property. |
| 46 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 47 | void *devfdt_map_physmem(struct udevice *dev, unsigned long size); |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 48 | |
| 49 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 50 | * devfdt_get_addr_index() - Get the indexed reg property of a device |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 51 | * |
| 52 | * @dev: Pointer to a device |
| 53 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 54 | * and @index is used to select which one is required |
| 55 | * |
| 56 | * @return addr |
| 57 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 58 | fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index); |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 59 | |
| 60 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 61 | * devfdt_get_addr_size_index() - Get the indexed reg property of a device |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 62 | * |
| 63 | * Returns the address and size specified in the 'reg' property of a device. |
| 64 | * |
| 65 | * @dev: Pointer to a device |
| 66 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 67 | * and @index is used to select which one is required |
| 68 | * @size: Pointer to size varible - this function returns the size |
| 69 | * specified in the 'reg' property here |
| 70 | * |
| 71 | * @return addr |
| 72 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 73 | fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 74 | fdt_size_t *size); |
| 75 | |
| 76 | /** |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 77 | * devfdt_get_addr_name() - Get the reg property of a device, indexed by name |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 78 | * |
| 79 | * @dev: Pointer to a device |
| 80 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 81 | * 'reg-names' property providing named-based identification. @index |
| 82 | * indicates the value to search for in 'reg-names'. |
| 83 | * |
| 84 | * @return addr |
| 85 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 86 | fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name); |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * dm_set_translation_offset() - Set translation offset |
| 90 | * @offs: Translation offset |
| 91 | * |
| 92 | * Some platforms need a special address translation. Those |
| 93 | * platforms (e.g. mvebu in SPL) can configure a translation |
| 94 | * offset in the DM by calling this function. It will be |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 95 | * added to all addresses returned in devfdt_get_addr(). |
Simon Glass | aadfaf0 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 96 | */ |
| 97 | void dm_set_translation_offset(fdt_addr_t offs); |
| 98 | |
| 99 | /** |
| 100 | * dm_get_translation_offset() - Get translation offset |
| 101 | * |
| 102 | * This function returns the translation offset that can |
| 103 | * be configured by calling dm_set_translation_offset(). |
| 104 | * |
| 105 | * @return translation offset for the device address (0 as default). |
| 106 | */ |
| 107 | fdt_addr_t dm_get_translation_offset(void); |
| 108 | |
| 109 | #endif |