Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752340AbbFAMfe (ORCPT ); Mon, 1 Jun 2015 08:35:34 -0400 Received: from mail-bn1on0053.outbound.protection.outlook.com ([157.56.110.53]:21056 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751596AbbFAMfZ (ORCPT ); Mon, 1 Jun 2015 08:35:25 -0400 X-Greylist: delayed 2090 seconds by postgrey-1.27 at vger.kernel.org; Mon, 01 Jun 2015 08:35:24 EDT Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; From: Anurag Kumar Vulisha To: , , , CC: , , , , , , Anurag Kumar Vulisha Subject: [patch] gpio: Added GPIO support to ZynqMP SoC Date: Mon, 1 Jun 2015 17:30:19 +0530 Message-ID: <1433160019-11157-1-git-send-email-anuragku@xilinx.com> X-Mailer: git-send-email 1.7.4 X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-21582.004 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD030;1:DSLBKYpzANvpoQrnES0N+xajUyWzoZB5FPKuUtZ3ovBgG/RDC5gSea5lMzCI8lhrW4vdGXYtjydfe6h6l/XVOzAfGT7O1K4RyDMROnimK3u6vsbdlSZuKuREmIjQzvPdOY85UidRAYbpDnM5k7hsyBujAeDrp/Ubm/ek1xTP9EBFnL0vaV5zOSaEISgCcLRQ5SSx4tEyUfbjgihq3FbeS/tW32oB4idhwU4ECozG8qFtv1RJn/chSkEivhFS6fblMALWfVWUwXbfy7J7vg5Kso31rkdrFiKxxWIosJSSv5b/lyoocSjtRC/dohVfypYE X-Forefront-Antispam-Report: CIP:149.199.60.100;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(438002)(199003)(189002)(37524003)(42186005)(2201001)(50226001)(6806004)(52956003)(47776003)(19580395003)(64706001)(87936001)(19580405001)(106466001)(45336002)(46386002)(50466002)(229853001)(46102003)(33646002)(48376002)(92566002)(5001830100001)(50986999)(4001540100001)(62966003)(77156002)(36756003)(63266004)(189998001)(107886002)(81156007)(5001960100002)(5001920100001)(5001770100001)(5001860100001)(86362001)(103686003)(36386004)(107986001)(4001450100001)(90966001)(5001870100001)(4001430100001);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2FFO11HUB041;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;PTR:unknown-60-100.xilinx.com,xapps1.xilinx.com;A:1;MX:1;LANG:; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11HUB041;2:XznjaKIZoe0fFLdM5kRvxpl8ahkmTiOJHJ44ljA/Og/I2nqMhtIuPEoETn1XsEa2;2:mMxtBGmF4hsyidtx+SoJoY7bRVPQXPKvJQb+xFge8wQrGxr+6AsNlWttjZTEkUnQrOQXG3fdK2UiIDS/zeqdNZDlt7JZK8jkGcfI6Jux8AT0SXnfr3kQq8JM2qBaW2NQPrcjKOPfkuYHTZx7cWWlfzNbLs///HTQHXonyidmtW6YDnc7SB+mvDA/JH/0sGo1C++XFbO6zcwg+onnIg00V9wuuDQ5u5JudG4rwvlPNtaOu6Il+ZO0QqVsnRT+hcVS;6:YQ1TCH4/SDweGsoEegy72AEuU9cRxw8kvHPgSwkWqvXOus50IJbxfeLsgl+Gl3UAwcJZdcXuJU9JyBUaR5zcWH/W1+PHl5hoO98Wzr60sjwSQlhN/IQi+ZZjSqypFA7kOJCYy4mQH3Xm3Fnme24McCIyLBBiCgdSE3b85byx8heYCUjFDfqYDcGP4pS39r6VeRgPkelZndZJHGPX3v0WgPQOAZFXvDQu9mhg4+ZUHjeAGMJAk1BwhBCxnCvqNEQf1vLQDO9U2RKY/lEsP/JznL9otq6uHmxB5qzyOnh3PtSTTb5Q7ltm8X8wqEHH8FAXOE0JzmwWVCCpyXjXb+TLwUMOdkc3VhclseVJ481sdf7R767bezQmuxS6dgFMtq8B9/66XSrnKz036aHT45M3n3IhJxnewxFI0hmAVcT+g0I0iZdXJxMj+gZTNpUx1ZkcRhce3kpXv3B/6a/Wsxx14NfxnpYHxz2JCWiIMNM3vD2wWl5WikyvjpURgXsNfLkj X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2FFO11HUB041; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(520003)(5005006)(3002001);SRVR:BY2FFO11HUB041;BCL:0;PCL:0;RULEID:;SRVR:BY2FFO11HUB041; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11HUB041;3:B3Mwc1aev18VT98zPKyG/+1Wi601jwaZhxECPIMRe5kzJYj0Y7rofgLTkuHjHNKXVOvvr8H0FLDfFTZujOUA7VsFNOPKcfo7C42GlUDajz0jKLFIii3HZPlnmta4vmJ5eDWnJNMEJ1uqV1tA+pbTIZvXpGAr6XtFUTbpXDb5KR/SFa3KjjJDygoa2CoydXtOqhxcDVLU/pbC/5ZiMYJqLm8KswcHXzWUDLKSRj26qWzOl83RW9Joox5Vm9JXCpYm0z4cQwF7f/kj4oFphe6+NlFJFJHb7qq6wqPBnPHJ/H0bDKhVGTH4pBtAVyChTi3J X-Forefront-PRVS: 05947791E4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2FFO11HUB041;9:pR4a8srndEcxzVFMpnSmshsKD+MIDaQHAQk22iVTL?= =?us-ascii?Q?HSLJmOHLwZVHpD1+dzeTEZErJYw5YvKfkNDUV+EZ7CHNxFZyzz2SNRGq98Nl?= =?us-ascii?Q?AytM3hf7hJes5mlWOBKrcHty6ScF5kAbirvABvf0D4kgCDZfZpWxFaPETrYu?= =?us-ascii?Q?+cJU1/1NWWGnC/x7VOSqz2b47Rflc/Y01TGySBnSpY1GLIRmcDc1QqqNHEf7?= =?us-ascii?Q?6UMGmQZIJGNpKUExa7590TTmAB7HRzbRE0IbLegjI4DYT6Mk52M99ZzhCCNQ?= =?us-ascii?Q?uuPxTuMkL4lX70LX9+14lFr9k3hz2gen0yw9uZo8rmHWV0o/Kgq+hpQ4NPLu?= =?us-ascii?Q?naWkaDNPZyW2KPwZPpOcKahjzFSgPMlTe0daQx319EzrQIfMHRZFUjvpNCie?= =?us-ascii?Q?oNVX/iuV9DMzrATyK9pH7NthSsO02vFBhWDo1BJiw0riiwh8bUDEvq+qB2jC?= =?us-ascii?Q?td5XdXALxdh0s45XRks2cEnHBbqpDQV250co9GdCePgjQtQp/z0HWMc0Rmte?= =?us-ascii?Q?9PWLpksSel7lHNji+dw2xXAPZAw4WCkqThSI3bR08VnGEAJtxIYGU23NTunm?= =?us-ascii?Q?bViEK+lbe6m2qBSCQK7SUMy2WDSCXllDsQ4nd+Wk+cLSfRI/IVG1XvSuT72p?= =?us-ascii?Q?RACGvThQ8yKaJmPvV+KbVHkUMyFffjh7rHymVhhamsKf+s/IZHESa3qciLvw?= =?us-ascii?Q?958TnOjP1yBk8BnSRvdgll1vhrMDJ4uFUjmPEFGx+VNYhHiiFft/Ihj4hQmA?= =?us-ascii?Q?aqDc/HU+04YQC1KH9+WVCe9By0t8sNH4sQANXcXOVXgB+4jPxyZ4rGC7+9hP?= =?us-ascii?Q?xSBiE2dnGVSZXCeYIIvK1Grys7SDQkqNvc8nYuI8s66Vkb9vWThPnGF2F5Ki?= =?us-ascii?Q?+Oizn4OGjFEYbHk/cVvz0peuM2QHBV11F6a3L55R1Hmao+OiWrVcwPOoqGdm?= =?us-ascii?Q?lAZiWBkLCoSLyuh5CF0stfXxJuqsOM0aOlluJr4GbpG3Fr2PLU6l69Tm4tnV?= =?us-ascii?Q?md1FwChqMs/osZK7v+2ZpmPYmM8xDCUFyPMoksm4dPv9+FIevCnpo2ZstgOC?= =?us-ascii?Q?RMi/ereTusCvVAVWxR0LCskzWDRECdzR191oytEVwDNlD7V8mQuxGREC/30J?= =?us-ascii?Q?83jySbIgknXnrcN+5yckkDz68spOseZBo1ZoeudDU14q90VMxyZc/cGLjI15?= =?us-ascii?Q?Fm1WSeJmwfLpdplhMghlzS6uNsNnkLF9Ul1BgmwFkEfDZsBhojzSLGvyA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11HUB041;3:Ue8CVDlOm0RnyWlyV/TsVvKsVChNgUMrF/lK/hlicqzujRO7+oPhM1WmSE7AUdKPuURU6iOWiNattNiGKinHiItuyCqgGjKv/4KtK7ox33rlOeVlAQRDfGVa5ONsqQZrwyF34zFo9Ip+1lbhSmrzsQ==;10:jONGKhTBxHlhwHONayFbWxBwjdeEYgH1HBlsB7S0IcOecFMAFWYwikJoi5LwQKAY+Z2+n6qtX6j1hTLq0RCcZDsNElXuxBElZQnkq/eEU/8= X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2015 12:00:24.3534 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2FFO11HUB041 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13987 Lines: 382 Added support to ZynqMP SoC on the existing zynq gpio driver. Signed-off-by: Anurag Kumar Vulisha --- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-zynq.c | 191 ++++++++++++++++++++++++++++++---------------- 2 files changed, 126 insertions(+), 67 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index caefe80..eef3a74 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -505,7 +505,7 @@ config GPIO_ZEVIO config GPIO_ZYNQ tristate "Xilinx Zynq GPIO support" - depends on ARCH_ZYNQ + depends on ARCH_ZYNQ || ARCH_ZYNQMP select GPIOLIB_IRQCHIP help Say yes here to support Xilinx Zynq GPIO controller. diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c index 184c4b1..d9d26aa 100644 --- a/drivers/gpio/gpio-zynq.c +++ b/drivers/gpio/gpio-zynq.c @@ -18,34 +18,47 @@ #include #include #include +#include #define DRIVER_NAME "zynq-gpio" /* Maximum banks */ #define ZYNQ_GPIO_MAX_BANK 4 +#define ZYNQMP_GPIO_MAX_BANK 6 #define ZYNQ_GPIO_BANK0_NGPIO 32 #define ZYNQ_GPIO_BANK1_NGPIO 22 #define ZYNQ_GPIO_BANK2_NGPIO 32 #define ZYNQ_GPIO_BANK3_NGPIO 32 -#define ZYNQ_GPIO_NR_GPIOS (ZYNQ_GPIO_BANK0_NGPIO + \ - ZYNQ_GPIO_BANK1_NGPIO + \ - ZYNQ_GPIO_BANK2_NGPIO + \ - ZYNQ_GPIO_BANK3_NGPIO) - -#define ZYNQ_GPIO_BANK0_PIN_MIN 0 -#define ZYNQ_GPIO_BANK0_PIN_MAX (ZYNQ_GPIO_BANK0_PIN_MIN + \ - ZYNQ_GPIO_BANK0_NGPIO - 1) -#define ZYNQ_GPIO_BANK1_PIN_MIN (ZYNQ_GPIO_BANK0_PIN_MAX + 1) -#define ZYNQ_GPIO_BANK1_PIN_MAX (ZYNQ_GPIO_BANK1_PIN_MIN + \ - ZYNQ_GPIO_BANK1_NGPIO - 1) -#define ZYNQ_GPIO_BANK2_PIN_MIN (ZYNQ_GPIO_BANK1_PIN_MAX + 1) -#define ZYNQ_GPIO_BANK2_PIN_MAX (ZYNQ_GPIO_BANK2_PIN_MIN + \ - ZYNQ_GPIO_BANK2_NGPIO - 1) -#define ZYNQ_GPIO_BANK3_PIN_MIN (ZYNQ_GPIO_BANK2_PIN_MAX + 1) -#define ZYNQ_GPIO_BANK3_PIN_MAX (ZYNQ_GPIO_BANK3_PIN_MIN + \ - ZYNQ_GPIO_BANK3_NGPIO - 1) +#define ZYNQMP_GPIO_BANK0_NGPIO 26 +#define ZYNQMP_GPIO_BANK1_NGPIO 26 +#define ZYNQMP_GPIO_BANK2_NGPIO 26 +#define ZYNQMP_GPIO_BANK3_NGPIO 32 +#define ZYNQMP_GPIO_BANK4_NGPIO 32 +#define ZYNQMP_GPIO_BANK5_NGPIO 32 + +#define ZYNQ_GPIO_NR_GPIOS 118 +#define ZYNQMP_GPIO_NR_GPIOS 174 + +#define ZYNQ_GPIO_BANK0_PIN_MIN(str) 0 +#define ZYNQ_GPIO_BANK0_PIN_MAX(str) (ZYNQ_GPIO_BANK0_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK0_NGPIO - 1) +#define ZYNQ_GPIO_BANK1_PIN_MIN(str) (ZYNQ_GPIO_BANK0_PIN_MAX(str) + 1) +#define ZYNQ_GPIO_BANK1_PIN_MAX(str) (ZYNQ_GPIO_BANK1_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK1_NGPIO - 1) +#define ZYNQ_GPIO_BANK2_PIN_MIN(str) (ZYNQ_GPIO_BANK1_PIN_MAX(str) + 1) +#define ZYNQ_GPIO_BANK2_PIN_MAX(str) (ZYNQ_GPIO_BANK2_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK2_NGPIO - 1) +#define ZYNQ_GPIO_BANK3_PIN_MIN(str) (ZYNQ_GPIO_BANK2_PIN_MAX(str) + 1) +#define ZYNQ_GPIO_BANK3_PIN_MAX(str) (ZYNQ_GPIO_BANK3_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK3_NGPIO - 1) +#define ZYNQ_GPIO_BANK4_PIN_MIN(str) (ZYNQ_GPIO_BANK3_PIN_MAX(str) + 1) +#define ZYNQ_GPIO_BANK4_PIN_MAX(str) (ZYNQ_GPIO_BANK4_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK4_NGPIO - 1) +#define ZYNQ_GPIO_BANK5_PIN_MIN(str) (ZYNQ_GPIO_BANK4_PIN_MAX(str) + 1) +#define ZYNQ_GPIO_BANK5_PIN_MAX(str) (ZYNQ_GPIO_BANK5_PIN_MIN(str) + \ + ZYNQ##str##_GPIO_BANK5_NGPIO - 1) /* Register offsets for the GPIO device */ @@ -89,12 +102,30 @@ * @base_addr: base address of the GPIO device * @clk: clock resource for this controller * @irq: interrupt for the GPIO device + * @p_data: pointer to platform data */ struct zynq_gpio { struct gpio_chip chip; void __iomem *base_addr; struct clk *clk; int irq; + const struct zynq_platform_data *p_data; +}; + +/** + * struct zynq_platform_data - zynq gpio platform data structure + * @label: string to store in gpio->label + * @ngpio: max number of gpio pins + * @max_bank: maximum number of gpio banks + * @bank_min: this array represents bank's min pin + * @bank_max: this array represents bank's max pin +*/ +struct zynq_platform_data { + const char *label; + u16 ngpio; + int max_bank; + int bank_min[ZYNQMP_GPIO_MAX_BANK]; + int bank_max[ZYNQMP_GPIO_MAX_BANK]; }; static struct irq_chip zynq_gpio_level_irqchip; @@ -112,39 +143,26 @@ static struct irq_chip zynq_gpio_edge_irqchip; */ static inline void zynq_gpio_get_bank_pin(unsigned int pin_num, unsigned int *bank_num, - unsigned int *bank_pin_num) + unsigned int *bank_pin_num, + struct zynq_gpio *gpio) { - switch (pin_num) { - case ZYNQ_GPIO_BANK0_PIN_MIN ... ZYNQ_GPIO_BANK0_PIN_MAX: - *bank_num = 0; - *bank_pin_num = pin_num; - break; - case ZYNQ_GPIO_BANK1_PIN_MIN ... ZYNQ_GPIO_BANK1_PIN_MAX: - *bank_num = 1; - *bank_pin_num = pin_num - ZYNQ_GPIO_BANK1_PIN_MIN; - break; - case ZYNQ_GPIO_BANK2_PIN_MIN ... ZYNQ_GPIO_BANK2_PIN_MAX: - *bank_num = 2; - *bank_pin_num = pin_num - ZYNQ_GPIO_BANK2_PIN_MIN; - break; - case ZYNQ_GPIO_BANK3_PIN_MIN ... ZYNQ_GPIO_BANK3_PIN_MAX: - *bank_num = 3; - *bank_pin_num = pin_num - ZYNQ_GPIO_BANK3_PIN_MIN; - break; - default: - WARN(true, "invalid GPIO pin number: %u", pin_num); - *bank_num = 0; - *bank_pin_num = 0; - break; + int bank; + + for (bank = 0; bank < gpio->p_data->max_bank; bank++) { + if ((pin_num >= gpio->p_data->bank_min[bank]) && + (pin_num <= gpio->p_data->bank_max[bank])) { + *bank_num = bank; + *bank_pin_num = pin_num - + gpio->p_data->bank_min[bank]; + return; + } } -} -static const unsigned int zynq_gpio_bank_offset[] = { - ZYNQ_GPIO_BANK0_PIN_MIN, - ZYNQ_GPIO_BANK1_PIN_MIN, - ZYNQ_GPIO_BANK2_PIN_MIN, - ZYNQ_GPIO_BANK3_PIN_MIN, -}; + /* default */ + WARN(true, "invalid GPIO pin number: %u", pin_num); + *bank_num = 0; + *bank_pin_num = 0; +} /** * zynq_gpio_get_value - Get the state of the specified pin of GPIO device @@ -161,7 +179,7 @@ static int zynq_gpio_get_value(struct gpio_chip *chip, unsigned int pin) unsigned int bank_num, bank_pin_num; struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); - zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); data = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); @@ -185,7 +203,7 @@ static void zynq_gpio_set_value(struct gpio_chip *chip, unsigned int pin, unsigned int reg_offset, bank_num, bank_pin_num; struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); - zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); if (bank_pin_num >= ZYNQ_GPIO_MID_PIN_NUM) { /* only 16 data bits in bit maskable reg */ @@ -222,7 +240,7 @@ static int zynq_gpio_dir_in(struct gpio_chip *chip, unsigned int pin) unsigned int bank_num, bank_pin_num; struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); - zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); /* bank 0 pins 7 and 8 are special and cannot be used as inputs */ if (bank_num == 0 && (bank_pin_num == 7 || bank_pin_num == 8)) @@ -255,7 +273,7 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, unsigned int bank_num, bank_pin_num; struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); - zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); /* set the GPIO pin as output */ reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); @@ -286,7 +304,7 @@ static void zynq_gpio_irq_mask(struct irq_data *irq_data) struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); device_pin_num = irq_data->hwirq; - zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); writel_relaxed(BIT(bank_pin_num), gpio->base_addr + ZYNQ_GPIO_INTDIS_OFFSET(bank_num)); } @@ -306,7 +324,7 @@ static void zynq_gpio_irq_unmask(struct irq_data *irq_data) struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); device_pin_num = irq_data->hwirq; - zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); writel_relaxed(BIT(bank_pin_num), gpio->base_addr + ZYNQ_GPIO_INTEN_OFFSET(bank_num)); } @@ -325,7 +343,7 @@ static void zynq_gpio_irq_ack(struct irq_data *irq_data) struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); device_pin_num = irq_data->hwirq; - zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); writel_relaxed(BIT(bank_pin_num), gpio->base_addr + ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); } @@ -375,7 +393,7 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type) struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); device_pin_num = irq_data->hwirq; - zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); int_type = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num)); @@ -470,7 +488,7 @@ static void zynq_gpio_handle_bank_irq(struct zynq_gpio *gpio, unsigned int bank_num, unsigned long pending) { - unsigned int bank_offset = zynq_gpio_bank_offset[bank_num]; + unsigned int bank_offset = gpio->p_data->bank_min[bank_num]; struct irq_domain *irqdomain = gpio->chip.irqdomain; int offset; @@ -505,7 +523,7 @@ static void zynq_gpio_irqhandler(unsigned int irq, struct irq_desc *desc) chained_irq_enter(irqchip, desc); - for (bank_num = 0; bank_num < ZYNQ_GPIO_MAX_BANK; bank_num++) { + for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++) { int_sts = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); int_enb = readl_relaxed(gpio->base_addr + @@ -582,6 +600,46 @@ static const struct dev_pm_ops zynq_gpio_dev_pm_ops = { zynq_gpio_runtime_resume, NULL) }; +static const struct zynq_platform_data zynqmp_gpio_def = { + .label = "zynqmp_gpio", + .ngpio = ZYNQMP_GPIO_NR_GPIOS, + .max_bank = ZYNQMP_GPIO_MAX_BANK, + .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(MP), + .bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(MP), + .bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(MP), + .bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(MP), + .bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(MP), + .bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(MP), + .bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(MP), + .bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(MP), + .bank_min[4] = ZYNQ_GPIO_BANK4_PIN_MIN(MP), + .bank_max[4] = ZYNQ_GPIO_BANK4_PIN_MAX(MP), + .bank_min[5] = ZYNQ_GPIO_BANK5_PIN_MIN(MP), + .bank_max[5] = ZYNQ_GPIO_BANK5_PIN_MAX(MP), +}; + +static const struct zynq_platform_data zynq_gpio_def = { + .label = "zynq_gpio", + .ngpio = ZYNQ_GPIO_NR_GPIOS, + .max_bank = ZYNQ_GPIO_MAX_BANK, + .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(), + .bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(), + .bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(), + .bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(), + .bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(), + .bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(), + .bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(), + .bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(), +}; + +static const struct of_device_id zynq_gpio_of_match[] = { + { .compatible = "xlnx,zynq-gpio-1.0", .data = (void *)&zynq_gpio_def }, + { .compatible = "xlnx,zynqmp-gpio-1.0", + .data = (void *)&zynqmp_gpio_def }, + { /* end of table */ } +}; +MODULE_DEVICE_TABLE(of, zynq_gpio_of_match); + /** * zynq_gpio_probe - Initialization method for a zynq_gpio device * @pdev: platform device instance @@ -599,11 +657,18 @@ static int zynq_gpio_probe(struct platform_device *pdev) struct zynq_gpio *gpio; struct gpio_chip *chip; struct resource *res; + const struct of_device_id *match; gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); if (!gpio) return -ENOMEM; + match = of_match_node(zynq_gpio_of_match, pdev->dev.of_node); + if (!match) { + dev_err(&pdev->dev, "of_match_node() failed\n"); + return -EINVAL; + } + gpio->p_data = match->data; platform_set_drvdata(pdev, gpio); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -619,7 +684,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) /* configure the gpio chip */ chip = &gpio->chip; - chip->label = "zynq_gpio"; + chip->label = gpio->p_data->label; chip->owner = THIS_MODULE; chip->dev = &pdev->dev; chip->get = zynq_gpio_get_value; @@ -629,7 +694,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) chip->direction_input = zynq_gpio_dir_in; chip->direction_output = zynq_gpio_dir_out; chip->base = -1; - chip->ngpio = ZYNQ_GPIO_NR_GPIOS; + chip->ngpio = gpio->p_data->ngpio; /* Enable GPIO clock */ gpio->clk = devm_clk_get(&pdev->dev, NULL); @@ -651,7 +716,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) } /* disable interrupts for all banks */ - for (bank_num = 0; bank_num < ZYNQ_GPIO_MAX_BANK; bank_num++) + for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++) writel_relaxed(ZYNQ_GPIO_IXR_DISABLE_ALL, gpio->base_addr + ZYNQ_GPIO_INTDIS_OFFSET(bank_num)); @@ -695,12 +760,6 @@ static int zynq_gpio_remove(struct platform_device *pdev) return 0; } -static struct of_device_id zynq_gpio_of_match[] = { - { .compatible = "xlnx,zynq-gpio-1.0", }, - { /* end of table */ } -}; -MODULE_DEVICE_TABLE(of, zynq_gpio_of_match); - static struct platform_driver zynq_gpio_driver = { .driver = { .name = DRIVER_NAME, -- 1.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/