Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753203AbbFDM0J (ORCPT ); Thu, 4 Jun 2015 08:26:09 -0400 Received: from mail-bn1on0096.outbound.protection.outlook.com ([157.56.110.96]:10992 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752463AbbFDM0F (ORCPT ); Thu, 4 Jun 2015 08:26:05 -0400 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 v2] gpio: Added GPIO support to Zynq Ultrascale+ MPSoC Date: Thu, 4 Jun 2015 17:40:32 +0530 Message-ID: <1433419832-40678-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-21590.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD056;1:32mAS6n9Mdx4MaFkfM2wwKpgQNHHug2K4QOp0oZfrAVDViqYcKQDBIHO1H9pYV5+uAwHUtTOH7Mi23z4A/N05bQwkP/i3OzCtRhbpQc9/7LttUqAWOHMFg+HKGp2OZ4ua3GhF+SqkBwdTtAp+gAv7jW1IjYswFRXohvihaHpuGTaiP+3qyVMbGh3D7Ca/xfVzYKM5yno59u5C62kVa3mqduJbb4yyv4uAIAVcIzRC8Djgw8pvz45GTUT9wuObI6UmJa9vdcpv95HznPzbnllscb8uxf+kZJX9jkQ0Xz76o9qy1AlJZ94DqOqdCyfHUSow+Sv7FCThEx/IkkmDQl95w== X-Forefront-Antispam-Report: CIP:149.199.60.100;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(438002)(199003)(189002)(37524003)(46102003)(46386002)(45336002)(50466002)(19580395003)(19580405001)(63266004)(189998001)(47776003)(33646002)(5001860100001)(107886002)(48376002)(5001960100002)(86362001)(103686003)(106466001)(6806004)(64706001)(50986999)(36756003)(77156002)(4001540100001)(5001770100001)(62966003)(5001830100001)(2201001)(229853001)(52956003)(87936001)(81156007)(42186005)(50226001)(92566002)(36386004)(2621003)(107986001)(90966001)(4001430100001)(4001450100001)(5001870100001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN1AFFO11HUB025;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;PTR:unknown-60-100.xilinx.com,xapps1.xilinx.com;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11HUB025;2:+98HUCHGmTdj2yagm6EVSlc8JCJUPXL9PtrSHBDsEPkFVEk7p2J/cY34MvyG9MwE;2:JKA050B7S4+V3JkvCMPylFGhzKj9gWr6xQlnrvgulNW0GGbSXqMu+vrewukyOFo5zy6K3Nso/M1oCD2ZlJrbxnj+dEv9SrgE3/0hqUqAa9vHgFFFOxP2PgMyXMivwG7v8J1Et1YYAvz5btQSUoSAwpdPyBVhbxTa2wgB6cn8mqH6RYo7qfoxdWqVIxQ6GoRrmiPQgZVxigtx8W63QqWCPjk8I4ipsC74hmloQK3ofd/ieP2LrfuUBYYZC3D4W1vC;6:E/8N+bRbgk9unlNqd2vFg3BUeQtokKJMNtd1f6eKZ7JPWJ6zit8Ub+7HTysBhbFYTeBc5Y+ExhA0VMKPh73eJI0MZQ5Yr1jS7ssk9fH/5s6Q9JrqEmfb+Pk+zw0I6NVLq9PiApAYfAUlVobVZWBRtrKk7/mCpbI9F7unnpxyuPNrjsRYqfIDh7gZaxuhyPMc8sG+F9f+yN21tcP1xoh4rfPqTL/Fn6z6DkAtpghjqQ0JWH1aGFLWNk+XOonZCn4rqpwGndAbJ7H5zXY7uGSM/jIFwWKEXfUgR5pQDjIYzTBI61WfyRp6aYsCuxFsNIwaWzkUOiDSQzIJJXj6DL5p0ZEAuTr7vlLXY5YncZIPK8ynF/uihCEhTrlRpvjnl1Bt4lfv0I6FEOjSY2YEYOXHUSow5zeqYRkD9AV5M/FZCE/ZAKt+iIowvvXYZu5fZJw7ZEcbD+LmsS76SxgOq9uAMSWgJV5V2yYNx06mu8uO/D3yKBU/D2e2Kzb9agO4rRjq X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1AFFO11HUB025;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1AFFO11HUB004; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BN1AFFO11HUB025;BCL:0;PCL:0;RULEID:;SRVR:BN1AFFO11HUB025; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11HUB025;3:WzyUPs0Vted/aAb6nyENjQRmhVZRruidTjknp0Ld+t2eORbwzV52TEpGLdNY2Gb1nh0UJVjU2IjBvqUU+nf1rzP4RYLo2GEeF38qcMsHVb00dkmJHFXcyUpQd1TEyE1gIFqW/t7LgkM+TXX8vxhnmpeZtsXwR7LIT1Zq/5z4DMapOm9OZzoZ1rz5RfWUTSK2amZSeY31runTUlf7AVuCJUnb77+byAosRrjOY0QB7s1GBCR2G2NUvq12pElwNgSRhdmLGc/pyOFtmt/Gugdo13fDexGF0D2zelx9J3ApaXU89NPAIbxP+rnMkZ5HYJ+H X-Forefront-PRVS: 0597911EE1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN1AFFO11HUB025;9:LMSGDWQxCC/EVds3nRcqY692Tw9FWNhRVQ5GI/1v?= =?us-ascii?Q?GSfPxYdtJYYAtVW7iOO1WP5KZIDfCVFWNhmEiAT/kGcxHt9oP8M60qzItM+G?= =?us-ascii?Q?EWHDkU8GgftqO0QWt5WlPAXIcvvfnupeucAHnTck/cVnSV5cgMU6BoET5ay0?= =?us-ascii?Q?nbNVVfPu7MJJtHP/SB/4sq1zvXuBnTSvlJFHs4cUzFhxa48hcnYgcKdBycUh?= =?us-ascii?Q?y53JJ092JaornWfT1bC5WS4Du0QQ3ja/7x+KwdqIJ+IVLeW/7WxBKvzkleak?= =?us-ascii?Q?wR2I0iMQSyaGQyxasa8/0hO7zUYDEmYxxru26/sXXJ7gRhAXxSK4IfZyn0P6?= =?us-ascii?Q?GbMIz7OWEozrMpjnMNjnCbnV+LzI7LkddD0nEnva8YLz3PkQXckWz3OM3iAc?= =?us-ascii?Q?xizeOq9y6u6PbvS3owxLwD4SNBy+rReEwUIR4ROLSga4I+JEtXrPcnGDmvKf?= =?us-ascii?Q?MCEC23zSzPv17gaFqQXxiKQXZBIWdF35UgT/pfiFLZavB55LPllshmVKR2Av?= =?us-ascii?Q?+jbsEaU5CKXe/uc7Zwhc7D+SHSgAFeCjFItvpmFUUS4V317iR9QVGTEQO+dH?= =?us-ascii?Q?v18NvYIQ72BgnQk7+pQmVralqr1NMZd45v6h0A6IwEv6Amy44agKENXYLqPd?= =?us-ascii?Q?CQD14ZHxSCRdox3u37Ig3HEuxdjL8HO6//xTn9Im6U4HA3JB+UlliLHB2QV5?= =?us-ascii?Q?2uLtJZ0SA9DlUTyeuAzQS7BOc8p9gTxTaNAlqwJgGbL2h2j4rbGUbFZB/CwM?= =?us-ascii?Q?jij38wioQvvArGOBuz+9npaQJS0SdiRKnMFPn9CB9K4Xjs2kJ4460Upeh1Ob?= =?us-ascii?Q?BSOjwGv8bCRTJ3BTPgTFOKTm+r+l3Eq7QqdIPngI7X8sLhkmPhKnU5D5h3gy?= =?us-ascii?Q?AddyW5nH/rrM1tIRQmU5B8D17pLqpsjgD16BbBSvNZp24fQvYBGJPIjGZzwv?= =?us-ascii?Q?GvA7zni6zyMMHM6PzSpvFQV8RsWtm3amlSTNATmR5IZawruW0vV0OpxA2ntA?= =?us-ascii?Q?O1ynDOWv+FHUealTTKJ/tkrW+wPPsluVhtq5PefymRTSgezS42TGLbdWDQAg?= =?us-ascii?Q?IqqJyoVSdubwa+Mj4y6GmVTZ0NDs2B4WuJ3CUrcbETBAuOvfw/dEGs1//F8D?= =?us-ascii?Q?PjmkTM7BtahylXqBXZz2GewdNXjorx2R/8Oa3v7B/S7yXNsy6A841RkHsr1G?= =?us-ascii?Q?vbwxavtlFLrA9Vxm4r6ZJpEMV52R9SV0JCvJ?= X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11HUB025;3:5xPuNjdjkMs7SqlouhE41xGEJTFpjzo+mr0+L8rJYwWThrIOQ63mbe7pfsHmoT0MWwjS8dtTVrx+Xp0ZRgYz1fwG9gcTHbyF8bJk3nvET/9hm+WCawuIAy7zPgqLwCSsfiSsvIKoLzSK/uq32kBuNw==;10:toNEcZlRczfQC/3U20/Qs3qfmamzFOiDUly42VVckpRqiQq5ZtIyKIHDgBDpgSiB4Uh1cf2U6HDcIFVsG4vu9Cr09m0SvVUzak4wnkJ6mms= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2015 12:10:39.9722 (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: BN1AFFO11HUB025 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11HUB004;2:z63jRfEf9l66aArPKxOPm650W+YhCCpVA460FgAxJo4Bg1bjERT3W20IUtbMNO6v;2:4KfRqZ8xvaoBvhkbu87LfSY6W+ZgMDEZVL6d6sLiECIJaLzNBRRJ01eQGpnPEvl1BVK84U+E11dC+8mRQg7XyTHwbgj5shBq7nxRwNp/nP/UAuAOqSlxvbE96IotmTVvAKl65wKdq0oyBZJAZvZpLzUJPvyK4Dn7CzPJUoegNlYPUNB1FbaAzyOwuOA3ZiGfWc5XFLJKOXwz/N3K51+CVL9QmmQsmfakr+/4asuDOmjY9E7MxLN1WqvKikQtGpAS;9:mpaX8f0tRLOcTr6tuXnJtIS+jLaKl3KaRXOU1Me35/Yiqea0Xsc0rmK14lP76L20ZYEV8qJpTpHMWVCDjlaouWrs2cOPTTHsgaahml3qdcOw4TyjBgaLbB5iJT7dlmoJ3oMRgO9dCNbKOGBlezn9SA== X-OriginatorOrg: xilinx.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 14986 Lines: 401 Added support to Zynq Ultrascale+ MPSoC on the existing zynq gpio driver. Signed-off-by: Anurag Kumar Vulisha --- Chnages in v2: 1.Added device tree bingings for Zynq Ultrascale+ MPSoC 2.Changed the commit message and subject from ZynqMP to Zynq Ultrascale+ MPSoC --- .../devicetree/bindings/gpio/gpio-zynq.txt | 2 +- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-zynq.c | 191 +++++++++++++------- 3 files changed, 127 insertions(+), 68 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/gpio-zynq.txt b/Documentation/devicetree/bindings/gpio/gpio-zynq.txt index 986371a..db4c6a6 100644 --- a/Documentation/devicetree/bindings/gpio/gpio-zynq.txt +++ b/Documentation/devicetree/bindings/gpio/gpio-zynq.txt @@ -6,7 +6,7 @@ Required properties: - First cell is the GPIO line number - Second cell is used to specify optional parameters (unused) -- compatible : Should be "xlnx,zynq-gpio-1.0" +- compatible : Should be "xlnx,zynq-gpio-1.0" or "xlnx,zynqmp-gpio-1.0" - clocks : Clock specifier (see clock bindings for details) - gpio-controller : Marks the device node as a GPIO controller. - interrupts : Interrupt specifier (see interrupt bindings for 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/