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