Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: AMD G-Series PCH gpio driver

GPIO platform driver for the AMD G-series PCH (eg. on GX-412TC)

This driver doesn't registers itself automatically, as it needs to
be provided with platform specific configuration, provided by some
board driver setup code.

Didn't implement oftree probing yet, as it's rarely found on x86.

Cc: linux-gpio@vger.kernel.org
Cc: linus.walleij@linaro.org
Cc: bgolaszewski@baylibre.com
Cc: dvhart@infradead.org
Cc: platform-driver-x86@vger.kernel.org
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Enrico Weigelt, metux IT consult and committed by
Linus Walleij
e09d168f 837ccda3

+248
+7
MAINTAINERS
··· 766 766 F: Documentation/hwmon/fam15h_power 767 767 F: drivers/hwmon/fam15h_power.c 768 768 769 + AMD FCH GPIO DRIVER 770 + M: Enrico Weigelt, metux IT consult <info@metux.net> 771 + L: linux-gpio@vger.kernel.org 772 + S: Maintained 773 + F: drivers/gpio/gpio-amd-fch.c 774 + F: include/linux/platform_data/gpio/gpio-amd-fch.h 775 + 769 776 AMD GEODE CS5536 USB DEVICE CONTROLLER DRIVER 770 777 L: linux-geode@lists.infradead.org (moderated for non-subscribers) 771 778 S: Orphan
+9
drivers/gpio/Kconfig
··· 655 655 help 656 656 Say Y or M here to support GPIO on Loongson1 SoCs. 657 657 658 + config GPIO_AMD_FCH 659 + tristate "GPIO support for AMD Fusion Controller Hub (G-series SOCs)" 660 + help 661 + This option enables driver for GPIO on AMDs Fusion Controller Hub, 662 + as found on G-series SOCs (eg. GX-412TC) 663 + 664 + Note: This driver doesn't registers itself automatically, as it 665 + needs to be provided with platform specific configuration. 666 + (See eg. CONFIG_PCENGINES_APU2.) 658 667 endmenu 659 668 660 669 menu "Port-mapped I/O GPIO drivers"
+1
drivers/gpio/Makefile
··· 27 27 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 28 28 obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o 29 29 obj-$(CONFIG_GPIO_ALTERA_A10SR) += gpio-altera-a10sr.o 30 + obj-$(CONFIG_GPIO_AMD_FCH) += gpio-amd-fch.o 30 31 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o 31 32 obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o 32 33 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
+185
drivers/gpio/gpio-amd-fch.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + 3 + /* 4 + * GPIO driver for the AMD G series FCH (eg. GX-412TC) 5 + * 6 + * Copyright (C) 2018 metux IT consult 7 + * Author: Enrico Weigelt, metux IT consult <info@metux.net> 8 + * 9 + */ 10 + 11 + #include <linux/err.h> 12 + #include <linux/io.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/gpio/driver.h> 17 + #include <linux/platform_data/gpio/gpio-amd-fch.h> 18 + #include <linux/spinlock.h> 19 + 20 + #define AMD_FCH_MMIO_BASE 0xFED80000 21 + #define AMD_FCH_GPIO_BANK0_BASE 0x1500 22 + #define AMD_FCH_GPIO_SIZE 0x0300 23 + 24 + #define AMD_FCH_GPIO_FLAG_DIRECTION BIT(23) 25 + #define AMD_FCH_GPIO_FLAG_WRITE BIT(22) 26 + #define AMD_FCH_GPIO_FLAG_READ BIT(16) 27 + 28 + static const struct resource amd_fch_gpio_iores = 29 + DEFINE_RES_MEM_NAMED( 30 + AMD_FCH_MMIO_BASE + AMD_FCH_GPIO_BANK0_BASE, 31 + AMD_FCH_GPIO_SIZE, 32 + "amd-fch-gpio-iomem"); 33 + 34 + struct amd_fch_gpio_priv { 35 + struct platform_device *pdev; 36 + struct gpio_chip gc; 37 + void __iomem *base; 38 + struct amd_fch_gpio_pdata *pdata; 39 + spinlock_t lock; 40 + }; 41 + 42 + static void *amd_fch_gpio_addr(struct amd_fch_gpio_priv *priv, 43 + unsigned int gpio) 44 + { 45 + return priv->base + priv->pdata->gpio_reg[gpio]*sizeof(u32); 46 + } 47 + 48 + static int amd_fch_gpio_direction_input(struct gpio_chip *gc, 49 + unsigned int offset) 50 + { 51 + unsigned long flags; 52 + struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc); 53 + void *ptr = amd_fch_gpio_addr(priv, offset); 54 + 55 + spin_lock_irqsave(&priv->lock, flags); 56 + writel_relaxed(readl_relaxed(ptr) & ~AMD_FCH_GPIO_FLAG_DIRECTION, ptr); 57 + spin_unlock_irqrestore(&priv->lock, flags); 58 + 59 + return 0; 60 + } 61 + 62 + static int amd_fch_gpio_direction_output(struct gpio_chip *gc, 63 + unsigned int gpio, int value) 64 + { 65 + unsigned long flags; 66 + struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc); 67 + void *ptr = amd_fch_gpio_addr(priv, gpio); 68 + 69 + spin_lock_irqsave(&priv->lock, flags); 70 + writel_relaxed(readl_relaxed(ptr) | AMD_FCH_GPIO_FLAG_DIRECTION, ptr); 71 + spin_unlock_irqrestore(&priv->lock, flags); 72 + 73 + return 0; 74 + } 75 + 76 + static int amd_fch_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio) 77 + { 78 + int ret; 79 + unsigned long flags; 80 + struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc); 81 + void *ptr = amd_fch_gpio_addr(priv, gpio); 82 + 83 + spin_lock_irqsave(&priv->lock, flags); 84 + ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_DIRECTION); 85 + spin_unlock_irqrestore(&priv->lock, flags); 86 + 87 + return ret; 88 + } 89 + 90 + static void amd_fch_gpio_set(struct gpio_chip *gc, 91 + unsigned int gpio, int value) 92 + { 93 + unsigned long flags; 94 + struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc); 95 + void *ptr = amd_fch_gpio_addr(priv, gpio); 96 + u32 mask; 97 + 98 + spin_lock_irqsave(&priv->lock, flags); 99 + 100 + mask = readl_relaxed(ptr); 101 + if (value) 102 + mask |= AMD_FCH_GPIO_FLAG_WRITE; 103 + else 104 + mask &= ~AMD_FCH_GPIO_FLAG_WRITE; 105 + writel_relaxed(mask, ptr); 106 + 107 + spin_unlock_irqrestore(&priv->lock, flags); 108 + } 109 + 110 + static int amd_fch_gpio_get(struct gpio_chip *gc, 111 + unsigned int offset) 112 + { 113 + unsigned long flags; 114 + int ret; 115 + struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc); 116 + void *ptr = amd_fch_gpio_addr(priv, offset); 117 + 118 + spin_lock_irqsave(&priv->lock, flags); 119 + ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_READ); 120 + spin_unlock_irqrestore(&priv->lock, flags); 121 + 122 + return ret; 123 + } 124 + 125 + static int amd_fch_gpio_request(struct gpio_chip *chip, 126 + unsigned int gpio_pin) 127 + { 128 + return 0; 129 + } 130 + 131 + static int amd_fch_gpio_probe(struct platform_device *pdev) 132 + { 133 + struct amd_fch_gpio_priv *priv; 134 + struct amd_fch_gpio_pdata *pdata; 135 + 136 + pdata = dev_get_platdata(&pdev->dev); 137 + if (!pdata) { 138 + dev_err(&pdev->dev, "no platform_data\n"); 139 + return -ENOENT; 140 + } 141 + 142 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 143 + if (!priv) 144 + return -ENOMEM; 145 + 146 + priv->pdata = pdata; 147 + priv->pdev = pdev; 148 + 149 + priv->gc.owner = THIS_MODULE; 150 + priv->gc.parent = &pdev->dev; 151 + priv->gc.label = dev_name(&pdev->dev); 152 + priv->gc.ngpio = priv->pdata->gpio_num; 153 + priv->gc.names = priv->pdata->gpio_names; 154 + priv->gc.base = -1; 155 + priv->gc.request = amd_fch_gpio_request; 156 + priv->gc.direction_input = amd_fch_gpio_direction_input; 157 + priv->gc.direction_output = amd_fch_gpio_direction_output; 158 + priv->gc.get_direction = amd_fch_gpio_get_direction; 159 + priv->gc.get = amd_fch_gpio_get; 160 + priv->gc.set = amd_fch_gpio_set; 161 + 162 + spin_lock_init(&priv->lock); 163 + 164 + priv->base = devm_ioremap_resource(&pdev->dev, &amd_fch_gpio_iores); 165 + if (IS_ERR(priv->base)) 166 + return PTR_ERR(priv->base); 167 + 168 + platform_set_drvdata(pdev, priv); 169 + 170 + return devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv); 171 + } 172 + 173 + static struct platform_driver amd_fch_gpio_driver = { 174 + .driver = { 175 + .name = AMD_FCH_GPIO_DRIVER_NAME, 176 + }, 177 + .probe = amd_fch_gpio_probe, 178 + }; 179 + 180 + module_platform_driver(amd_fch_gpio_driver); 181 + 182 + MODULE_AUTHOR("Enrico Weigelt, metux IT consult <info@metux.net>"); 183 + MODULE_DESCRIPTION("AMD G-series FCH GPIO driver"); 184 + MODULE_LICENSE("GPL"); 185 + MODULE_ALIAS("platform:" AMD_FCH_GPIO_DRIVER_NAME);
+46
include/linux/platform_data/gpio/gpio-amd-fch.h
··· 1 + /* SPDX-License-Identifier: GPL+ */ 2 + 3 + /* 4 + * AMD FCH gpio driver platform-data 5 + * 6 + * Copyright (C) 2018 metux IT consult 7 + * Author: Enrico Weigelt <info@metux.net> 8 + * 9 + */ 10 + 11 + #ifndef __LINUX_PLATFORM_DATA_GPIO_AMD_FCH_H 12 + #define __LINUX_PLATFORM_DATA_GPIO_AMD_FCH_H 13 + 14 + #define AMD_FCH_GPIO_DRIVER_NAME "gpio_amd_fch" 15 + 16 + /* 17 + * gpio register index definitions 18 + */ 19 + #define AMD_FCH_GPIO_REG_GPIO49 0x40 20 + #define AMD_FCH_GPIO_REG_GPIO50 0x41 21 + #define AMD_FCH_GPIO_REG_GPIO51 0x42 22 + #define AMD_FCH_GPIO_REG_GPIO59_DEVSLP0 0x43 23 + #define AMD_FCH_GPIO_REG_GPIO57 0x44 24 + #define AMD_FCH_GPIO_REG_GPIO58 0x45 25 + #define AMD_FCH_GPIO_REG_GPIO59_DEVSLP1 0x46 26 + #define AMD_FCH_GPIO_REG_GPIO64 0x47 27 + #define AMD_FCH_GPIO_REG_GPIO68 0x48 28 + #define AMD_FCH_GPIO_REG_GPIO66_SPKR 0x5B 29 + #define AMD_FCH_GPIO_REG_GPIO71 0x4D 30 + #define AMD_FCH_GPIO_REG_GPIO32_GE1 0x59 31 + #define AMD_FCH_GPIO_REG_GPIO33_GE2 0x5A 32 + #define AMT_FCH_GPIO_REG_GEVT22 0x09 33 + 34 + /* 35 + * struct amd_fch_gpio_pdata - GPIO chip platform data 36 + * @gpio_num: number of entries 37 + * @gpio_reg: array of gpio registers 38 + * @gpio_names: array of gpio names 39 + */ 40 + struct amd_fch_gpio_pdata { 41 + int gpio_num; 42 + int *gpio_reg; 43 + const char * const *gpio_names; 44 + }; 45 + 46 + #endif /* __LINUX_PLATFORM_DATA_GPIO_AMD_FCH_H */