From patchwork Mon Jan 27 05:05:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240201 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 26 Jan 2020 22:05:55 -0700 Subject: [PATCH 048/108] x86: pinctrl: Add a way to get the pinctrl reg address In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-1-sjg@chromium.org> Message-ID: <20200126220508.48.I6d4adee5cfa6760f332c0a463658ab3167308689@changeid> At present we can query the offset of a pinctrl register within the p2sb. For ACPI we need to get the actual address of the register. Add a function to handle this and rename the old one to more accurately reflect its purpose. Signed-off-by: Simon Glass --- arch/x86/include/asm/intel_pinctrl.h | 16 ++++++++++++++-- drivers/gpio/intel_gpio.c | 15 +++++++++++---- drivers/misc/p2sb-uclass.c | 16 ++++++++-------- drivers/pinctrl/intel/pinctrl.c | 11 +++++++++-- include/p2sb.h | 9 +++++++++ 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/intel_pinctrl.h b/arch/x86/include/asm/intel_pinctrl.h index 72fd9246cb..ebdaa39265 100644 --- a/arch/x86/include/asm/intel_pinctrl.h +++ b/arch/x86/include/asm/intel_pinctrl.h @@ -262,11 +262,23 @@ int pinctrl_read_pads(struct udevice *dev, ofnode node, const char *prop, int pinctrl_count_pads(struct udevice *dev, u32 *pads, int size); /** - * intel_pinctrl_get_config_reg_addr() - Get address of the pin config registers + * intel_pinctrl_get_config_reg_offset() - Get offset of pin config registers * + * This works out the register offset of a pin within the p2sb region. + * + * @dev: Pinctrl device + * @offset: GPIO offset within this device + * @return register offset of first register within the GPIO p2sb region + */ +u32 intel_pinctrl_get_config_reg_offset(struct udevice *dev, uint offset); + +/** + * intel_pinctrl_get_config_reg_offset() - Get address of pin config registers + * + * This works out the absolute address of the registers for a pin * @dev: Pinctrl device * @offset: GPIO offset within this device - * @return register offset within the GPIO p2sb region + * @return register offset of first register within the GPIO p2sb region */ u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset); diff --git a/drivers/gpio/intel_gpio.c b/drivers/gpio/intel_gpio.c index 4bf1c9ddc4..c56b362c4e 100644 --- a/drivers/gpio/intel_gpio.c +++ b/drivers/gpio/intel_gpio.c @@ -23,7 +23,9 @@ static int intel_gpio_direction_input(struct udevice *dev, uint offset) { struct udevice *pinctrl = dev_get_parent(dev); - uint config_offset = intel_pinctrl_get_config_reg_addr(pinctrl, offset); + uint config_offset; + + config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset); pcr_clrsetbits32(pinctrl, config_offset, PAD_CFG0_MODE_MASK | PAD_CFG0_TX_STATE | @@ -37,7 +39,9 @@ static int intel_gpio_direction_output(struct udevice *dev, uint offset, int value) { struct udevice *pinctrl = dev_get_parent(dev); - uint config_offset = intel_pinctrl_get_config_reg_addr(pinctrl, offset); + uint config_offset; + + config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset); pcr_clrsetbits32(dev, config_offset, PAD_CFG0_MODE_MASK | PAD_CFG0_RX_STATE | @@ -67,10 +71,13 @@ static int intel_gpio_get_value(struct udevice *dev, uint offset) return 0; } -static int intel_gpio_set_value(struct udevice *dev, unsigned offset, int value) +static int intel_gpio_set_value(struct udevice *dev, unsigned int offset, + int value) { struct udevice *pinctrl = dev_get_parent(dev); - uint config_offset = intel_pinctrl_get_config_reg_addr(pinctrl, offset); + uint config_offset; + + config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset); pcr_clrsetbits32(dev, config_offset, PAD_CFG0_TX_STATE, value ? PAD_CFG0_TX_STATE : 0); diff --git a/drivers/misc/p2sb-uclass.c b/drivers/misc/p2sb-uclass.c index a198700b5f..1d00a73f2f 100644 --- a/drivers/misc/p2sb-uclass.c +++ b/drivers/misc/p2sb-uclass.c @@ -16,7 +16,7 @@ #define PCR_COMMON_IOSF_1_0 1 -static void *_pcr_reg_address(struct udevice *dev, uint offset) +void *pcr_reg_address(struct udevice *dev, uint offset) { struct p2sb_child_platdata *pplat = dev_get_parent_platdata(dev); struct udevice *p2sb = dev_get_parent(dev); @@ -53,7 +53,7 @@ uint pcr_read32(struct udevice *dev, uint offset) /* Ensure the PCR offset is correctly aligned */ assert(IS_ALIGNED(offset, sizeof(uint32_t))); - ptr = _pcr_reg_address(dev, offset); + ptr = pcr_reg_address(dev, offset); val = readl(ptr); unmap_sysmem(ptr); @@ -65,7 +65,7 @@ uint pcr_read16(struct udevice *dev, uint offset) /* Ensure the PCR offset is correctly aligned */ check_pcr_offset_align(offset, sizeof(uint16_t)); - return readw(_pcr_reg_address(dev, offset)); + return readw(pcr_reg_address(dev, offset)); } uint pcr_read8(struct udevice *dev, uint offset) @@ -73,7 +73,7 @@ uint pcr_read8(struct udevice *dev, uint offset) /* Ensure the PCR offset is correctly aligned */ check_pcr_offset_align(offset, sizeof(uint8_t)); - return readb(_pcr_reg_address(dev, offset)); + return readb(pcr_reg_address(dev, offset)); } /* @@ -84,7 +84,7 @@ uint pcr_read8(struct udevice *dev, uint offset) */ static void write_completion(struct udevice *dev, uint offset) { - readl(_pcr_reg_address(dev, ALIGN_DOWN(offset, sizeof(uint32_t)))); + readl(pcr_reg_address(dev, ALIGN_DOWN(offset, sizeof(uint32_t)))); } void pcr_write32(struct udevice *dev, uint offset, uint indata) @@ -92,7 +92,7 @@ void pcr_write32(struct udevice *dev, uint offset, uint indata) /* Ensure the PCR offset is correctly aligned */ assert(IS_ALIGNED(offset, sizeof(indata))); - writel(indata, _pcr_reg_address(dev, offset)); + writel(indata, pcr_reg_address(dev, offset)); /* Ensure the writes complete */ write_completion(dev, offset); } @@ -102,7 +102,7 @@ void pcr_write16(struct udevice *dev, uint offset, uint indata) /* Ensure the PCR offset is correctly aligned */ check_pcr_offset_align(offset, sizeof(uint16_t)); - writew(indata, _pcr_reg_address(dev, offset)); + writew(indata, pcr_reg_address(dev, offset)); /* Ensure the writes complete */ write_completion(dev, offset); } @@ -112,7 +112,7 @@ void pcr_write8(struct udevice *dev, uint offset, uint indata) /* Ensure the PCR offset is correctly aligned */ check_pcr_offset_align(offset, sizeof(uint8_t)); - writeb(indata, _pcr_reg_address(dev, offset)); + writeb(indata, pcr_reg_address(dev, offset)); /* Ensure the writes complete */ write_completion(dev, offset); } diff --git a/drivers/pinctrl/intel/pinctrl.c b/drivers/pinctrl/intel/pinctrl.c index bd58b85dd8..68955f66ed 100644 --- a/drivers/pinctrl/intel/pinctrl.c +++ b/drivers/pinctrl/intel/pinctrl.c @@ -391,7 +391,7 @@ static int pinctrl_configure_pad(struct udevice *dev, return 0; } -u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset) +u32 intel_pinctrl_get_config_reg_offset(struct udevice *dev, uint offset) { struct intel_pinctrl_priv *priv = dev_get_priv(dev); const struct pad_community *comm = priv->comm; @@ -404,9 +404,16 @@ u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset) return config_offset; } +u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset) +{ + uint config_offset = intel_pinctrl_get_config_reg_offset(dev, offset); + + return (u32)(ulong)pcr_reg_address(dev, config_offset); +} + u32 intel_pinctrl_get_config_reg(struct udevice *dev, uint offset) { - uint config_offset = intel_pinctrl_get_config_reg_addr(dev, offset); + uint config_offset = intel_pinctrl_get_config_reg_offset(dev, offset); return pcr_read32(dev, config_offset); } diff --git a/include/p2sb.h b/include/p2sb.h index 60c7f70773..74eb08b7ff 100644 --- a/include/p2sb.h +++ b/include/p2sb.h @@ -132,4 +132,13 @@ int p2sb_set_port_id(struct udevice *dev, int portid); */ int p2sb_get_port_id(struct udevice *dev); +/** + * pcr_reg_address() Convert an offset in p2sb space to an absolute address + * + * @dev: Child device (whose parent is UCLASS_P2SB) + * @offset: Offset within that child's address space + * @return pointer to that offset within the child's address space + */ +void *pcr_reg_address(struct udevice *dev, uint offset); + #endif