157251285SSimon Glass /* 257251285SSimon Glass * Copyright (c) 2015 Google, Inc 357251285SSimon Glass * Written by Simon Glass <sjg@chromium.org> 457251285SSimon Glass * 557251285SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 657251285SSimon Glass */ 757251285SSimon Glass 857251285SSimon Glass #ifndef __SYSCON_H 957251285SSimon Glass #define __SYSCON_H 1057251285SSimon Glass 11a28bfcc3SSimon Glass #include <fdtdec.h> 12a28bfcc3SSimon Glass 1357251285SSimon Glass /** 1457251285SSimon Glass * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS 1557251285SSimon Glass * 1657251285SSimon Glass * @regmap: Register map for this controller 1757251285SSimon Glass */ 1857251285SSimon Glass struct syscon_uc_info { 1957251285SSimon Glass struct regmap *regmap; 2057251285SSimon Glass }; 2157251285SSimon Glass 2257251285SSimon Glass /* So far there are no ops so this is a placeholder */ 2357251285SSimon Glass struct syscon_ops { 2457251285SSimon Glass }; 2557251285SSimon Glass 2657251285SSimon Glass #define syscon_get_ops(dev) ((struct syscon_ops *)(dev)->driver->ops) 2757251285SSimon Glass 2804ecf36bSSimon Glass #if CONFIG_IS_ENABLED(OF_PLATDATA) 2904ecf36bSSimon Glass /* 3004ecf36bSSimon Glass * We don't support 64-bit machines. If they are so resource-contrained that 3104ecf36bSSimon Glass * they need to use OF_PLATDATA, something is horribly wrong with the 3204ecf36bSSimon Glass * education of our hardware engineers. 33a28bfcc3SSimon Glass * 34a28bfcc3SSimon Glass * Update: 64-bit is now supported and we have an education crisis. 3504ecf36bSSimon Glass */ 3604ecf36bSSimon Glass struct syscon_base_platdata { 37a28bfcc3SSimon Glass fdt_val_t reg[2]; 3804ecf36bSSimon Glass }; 3904ecf36bSSimon Glass #endif 4004ecf36bSSimon Glass 4157251285SSimon Glass /** 4257251285SSimon Glass * syscon_get_regmap() - Get access to a register map 4357251285SSimon Glass * 4457251285SSimon Glass * @dev: Device to check (UCLASS_SCON) 4557251285SSimon Glass * @info: Returns regmap for the device 4657251285SSimon Glass * @return 0 if OK, -ve on error 4757251285SSimon Glass */ 4857251285SSimon Glass struct regmap *syscon_get_regmap(struct udevice *dev); 4957251285SSimon Glass 5057251285SSimon Glass /** 5157251285SSimon Glass * syscon_get_regmap_by_driver_data() - Look up a controller by its ID 5257251285SSimon Glass * 5357251285SSimon Glass * Each system controller can be accessed by its driver data, which is 5457251285SSimon Glass * assumed to be unique through the scope of all system controllers that 55ac94b7bcSSimon Glass * are in use. This function looks up the controller given this driver data. 56ac94b7bcSSimon Glass * 57ac94b7bcSSimon Glass * @driver_data: Driver data value to look up 58ac94b7bcSSimon Glass * @devp: Returns the controller correponding to @driver_data 59ac94b7bcSSimon Glass * @return 0 on success, -ENODEV if the ID was not found, or other -ve error 60ac94b7bcSSimon Glass * code 61ac94b7bcSSimon Glass */ 62ac94b7bcSSimon Glass int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp); 63ac94b7bcSSimon Glass 64ac94b7bcSSimon Glass /** 65ac94b7bcSSimon Glass * syscon_get_regmap_by_driver_data() - Look up a controller by its ID 66ac94b7bcSSimon Glass * 67ac94b7bcSSimon Glass * Each system controller can be accessed by its driver data, which is 68ac94b7bcSSimon Glass * assumed to be unique through the scope of all system controllers that 6957251285SSimon Glass * are in use. This function looks up the regmap given this driver data. 7057251285SSimon Glass * 7157251285SSimon Glass * @driver_data: Driver data value to look up 7257251285SSimon Glass * @return register map correponding to @driver_data, or -ve error code 7357251285SSimon Glass */ 7457251285SSimon Glass struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data); 7557251285SSimon Glass 7657251285SSimon Glass /** 77*10427e2dSJean-Jacques Hiblot * syscon_regmap_lookup_by_phandle() - Look up a controller by a phandle 78*10427e2dSJean-Jacques Hiblot * 79*10427e2dSJean-Jacques Hiblot * This operates by looking up the given name in the device (device 80*10427e2dSJean-Jacques Hiblot * tree property) of the device using the system controller. 81*10427e2dSJean-Jacques Hiblot * 82*10427e2dSJean-Jacques Hiblot * @dev: Device using the system controller 83*10427e2dSJean-Jacques Hiblot * @name: Name of property referring to the system controller 84*10427e2dSJean-Jacques Hiblot * @return A pointer to the regmap if found, ERR_PTR(-ve) on error 85*10427e2dSJean-Jacques Hiblot */ 86*10427e2dSJean-Jacques Hiblot struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev, 87*10427e2dSJean-Jacques Hiblot const char *name); 88*10427e2dSJean-Jacques Hiblot 89*10427e2dSJean-Jacques Hiblot /** 9057251285SSimon Glass * syscon_get_first_range() - get the first memory range from a syscon regmap 9157251285SSimon Glass * 9257251285SSimon Glass * @driver_data: Driver data value to look up 9357251285SSimon Glass * @return first region of register map correponding to @driver_data, or 9457251285SSimon Glass * -ve error code 9557251285SSimon Glass */ 9657251285SSimon Glass void *syscon_get_first_range(ulong driver_data); 9757251285SSimon Glass 9857251285SSimon Glass #endif 99