| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * pinctrl pads, groups, functions for CSR SiRFatlasVII |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2011 - 2014 Cambridge Silicon Radio Limited, a CSR plc group |
|---|
| 5 | 6 | * company. |
|---|
| 6 | | - * |
|---|
| 7 | | - * Licensed under GPLv2 or later. |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 19 | 18 | #include <linux/of_device.h> |
|---|
| 20 | 19 | #include <linux/of_platform.h> |
|---|
| 21 | 20 | #include <linux/of_irq.h> |
|---|
| 22 | | -#include <linux/of_gpio.h> |
|---|
| 23 | 21 | #include <linux/pinctrl/machine.h> |
|---|
| 24 | 22 | #include <linux/pinctrl/pinconf.h> |
|---|
| 25 | 23 | #include <linux/pinctrl/pinctrl.h> |
|---|
| 26 | 24 | #include <linux/pinctrl/pinmux.h> |
|---|
| 27 | 25 | #include <linux/pinctrl/consumer.h> |
|---|
| 28 | 26 | #include <linux/pinctrl/pinconf-generic.h> |
|---|
| 29 | | -#include <linux/gpio.h> |
|---|
| 27 | +#include <linux/gpio/driver.h> |
|---|
| 30 | 28 | |
|---|
| 31 | 29 | /* Definition of Pad&Mux Properties */ |
|---|
| 32 | 30 | #define N 0 |
|---|
| .. | .. |
|---|
| 171 | 169 | |
|---|
| 172 | 170 | /** |
|---|
| 173 | 171 | * struct atlas7_pad_conf - Atlas7 Pad Configuration |
|---|
| 174 | | - * @id The ID of this Pad. |
|---|
| 172 | + * @id: The ID of this Pad. |
|---|
| 175 | 173 | * @type: The type of this Pad. |
|---|
| 176 | 174 | * @mux_reg: The mux register offset. |
|---|
| 177 | 175 | * This register contains the mux. |
|---|
| .. | .. |
|---|
| 212 | 210 | .ad_ctrl_bit = adb, \ |
|---|
| 213 | 211 | } |
|---|
| 214 | 212 | |
|---|
| 215 | | -/** |
|---|
| 213 | +/* |
|---|
| 216 | 214 | * struct atlas7_pad_status - Atlas7 Pad status |
|---|
| 217 | 215 | */ |
|---|
| 218 | 216 | struct atlas7_pad_status { |
|---|
| .. | .. |
|---|
| 354 | 352 | int nbank; |
|---|
| 355 | 353 | raw_spinlock_t lock; |
|---|
| 356 | 354 | struct gpio_chip chip; |
|---|
| 357 | | - struct atlas7_gpio_bank banks[0]; |
|---|
| 355 | + struct atlas7_gpio_bank banks[]; |
|---|
| 358 | 356 | }; |
|---|
| 359 | 357 | |
|---|
| 360 | | -/** |
|---|
| 361 | | - * @dev: a pointer back to containing device |
|---|
| 362 | | - * @virtbase: the offset to the controller in virtual memory |
|---|
| 363 | | - */ |
|---|
| 364 | 358 | struct atlas7_pmx { |
|---|
| 365 | 359 | struct device *dev; |
|---|
| 366 | 360 | struct pinctrl_dev *pctl; |
|---|
| .. | .. |
|---|
| 378 | 372 | * refer to A7DA IO Summary - CS-314158-DD-4E.xls |
|---|
| 379 | 373 | */ |
|---|
| 380 | 374 | |
|---|
| 381 | | -/*Pads in IOC RTC & TOP */ |
|---|
| 375 | +/* Pads in IOC RTC & TOP */ |
|---|
| 382 | 376 | static const struct pinctrl_pin_desc atlas7_ioc_pads[] = { |
|---|
| 383 | 377 | /* RTC PADs */ |
|---|
| 384 | 378 | PINCTRL_PIN(0, "rtc_gpio_0"), |
|---|
| .. | .. |
|---|
| 4783 | 4777 | |
|---|
| 4784 | 4778 | /** |
|---|
| 4785 | 4779 | * struct atlas7_pull_info - Atlas7 Pad pull info |
|---|
| 4786 | | - * @type:The type of this Pad. |
|---|
| 4787 | | - * @mask:The mas value of this pin's pull bits. |
|---|
| 4788 | | - * @v2s: The map of pull register value to pull status. |
|---|
| 4789 | | - * @s2v: The map of pull status to pull register value. |
|---|
| 4780 | + * @pad_type: The type of this Pad. |
|---|
| 4781 | + * @mask: The mas value of this pin's pull bits. |
|---|
| 4782 | + * @v2s: The map of pull register value to pull status. |
|---|
| 4783 | + * @s2v: The map of pull status to pull register value. |
|---|
| 4790 | 4784 | */ |
|---|
| 4791 | 4785 | struct atlas7_pull_info { |
|---|
| 4792 | 4786 | u8 pad_type; |
|---|
| .. | .. |
|---|
| 4910 | 4904 | * @type: The type of this Pad. |
|---|
| 4911 | 4905 | * @mask: The mask value of this pin's pull bits. |
|---|
| 4912 | 4906 | * @imval: The immediate value of drives trength register. |
|---|
| 4907 | + * @reserved: Reserved space |
|---|
| 4913 | 4908 | */ |
|---|
| 4914 | 4909 | struct atlas7_ds_info { |
|---|
| 4915 | 4910 | u8 type; |
|---|
| .. | .. |
|---|
| 5540 | 5535 | { |
|---|
| 5541 | 5536 | struct atlas7_pmx *pmx = dev_get_drvdata(dev); |
|---|
| 5542 | 5537 | struct atlas7_pad_status *status; |
|---|
| 5543 | | - struct atlas7_pad_config *conf; |
|---|
| 5544 | 5538 | int idx; |
|---|
| 5545 | | - u32 bank; |
|---|
| 5546 | 5539 | |
|---|
| 5547 | 5540 | for (idx = 0; idx < pmx->pctl_desc.npins; idx++) { |
|---|
| 5548 | 5541 | /* Get this Pad's descriptor from PINCTRL */ |
|---|
| 5549 | | - conf = &pmx->pctl_data->confs[idx]; |
|---|
| 5550 | | - bank = atlas7_pin_to_bank(idx); |
|---|
| 5551 | 5542 | status = &pmx->sleep_data[idx]; |
|---|
| 5552 | 5543 | |
|---|
| 5553 | 5544 | /* Restore Function selector */ |
|---|
| .. | .. |
|---|
| 5615 | 5606 | arch_initcall(atlas7_pinmux_init); |
|---|
| 5616 | 5607 | |
|---|
| 5617 | 5608 | |
|---|
| 5618 | | -/** |
|---|
| 5609 | +/* |
|---|
| 5619 | 5610 | * The Following is GPIO Code |
|---|
| 5620 | 5611 | */ |
|---|
| 5621 | 5612 | static inline struct |
|---|
| .. | .. |
|---|
| 6002 | 5993 | struct gpio_chip *chip; |
|---|
| 6003 | 5994 | u32 nbank; |
|---|
| 6004 | 5995 | int ret, idx; |
|---|
| 5996 | + struct gpio_irq_chip *girq; |
|---|
| 6005 | 5997 | |
|---|
| 6006 | 5998 | ret = of_property_read_u32(np, "gpio-banks", &nbank); |
|---|
| 6007 | 5999 | if (ret) { |
|---|
| .. | .. |
|---|
| 6012 | 6004 | } |
|---|
| 6013 | 6005 | |
|---|
| 6014 | 6006 | /* retrieve gpio descriptor data */ |
|---|
| 6015 | | - a7gc = devm_kzalloc(&pdev->dev, sizeof(*a7gc) + |
|---|
| 6016 | | - sizeof(struct atlas7_gpio_bank) * nbank, GFP_KERNEL); |
|---|
| 6007 | + a7gc = devm_kzalloc(&pdev->dev, struct_size(a7gc, banks, nbank), |
|---|
| 6008 | + GFP_KERNEL); |
|---|
| 6017 | 6009 | if (!a7gc) |
|---|
| 6018 | 6010 | return -ENOMEM; |
|---|
| 6019 | 6011 | |
|---|
| .. | .. |
|---|
| 6054 | 6046 | chip->of_gpio_n_cells = 2; |
|---|
| 6055 | 6047 | chip->parent = &pdev->dev; |
|---|
| 6056 | 6048 | |
|---|
| 6057 | | - /* Add gpio chip to system */ |
|---|
| 6058 | | - ret = gpiochip_add_data(chip, a7gc); |
|---|
| 6059 | | - if (ret) { |
|---|
| 6060 | | - dev_err(&pdev->dev, |
|---|
| 6061 | | - "%s: error in probe function with status %d\n", |
|---|
| 6062 | | - np->name, ret); |
|---|
| 6063 | | - goto failed; |
|---|
| 6064 | | - } |
|---|
| 6065 | | - |
|---|
| 6066 | | - /* Add gpio chip to irq subsystem */ |
|---|
| 6067 | | - ret = gpiochip_irqchip_add(chip, &atlas7_gpio_irq_chip, |
|---|
| 6068 | | - 0, handle_level_irq, IRQ_TYPE_NONE); |
|---|
| 6069 | | - if (ret) { |
|---|
| 6070 | | - dev_err(&pdev->dev, |
|---|
| 6071 | | - "could not connect irqchip to gpiochip\n"); |
|---|
| 6072 | | - goto failed; |
|---|
| 6073 | | - } |
|---|
| 6074 | | - |
|---|
| 6049 | + girq = &chip->irq; |
|---|
| 6050 | + girq->chip = &atlas7_gpio_irq_chip; |
|---|
| 6051 | + girq->parent_handler = atlas7_gpio_handle_irq; |
|---|
| 6052 | + girq->num_parents = nbank; |
|---|
| 6053 | + girq->parents = devm_kcalloc(&pdev->dev, nbank, |
|---|
| 6054 | + sizeof(*girq->parents), |
|---|
| 6055 | + GFP_KERNEL); |
|---|
| 6056 | + if (!girq->parents) |
|---|
| 6057 | + return -ENOMEM; |
|---|
| 6075 | 6058 | for (idx = 0; idx < nbank; idx++) { |
|---|
| 6076 | 6059 | struct atlas7_gpio_bank *bank; |
|---|
| 6077 | 6060 | |
|---|
| .. | .. |
|---|
| 6090 | 6073 | goto failed; |
|---|
| 6091 | 6074 | } |
|---|
| 6092 | 6075 | bank->irq = ret; |
|---|
| 6076 | + girq->parents[idx] = ret; |
|---|
| 6077 | + } |
|---|
| 6078 | + girq->default_type = IRQ_TYPE_NONE; |
|---|
| 6079 | + girq->handler = handle_level_irq; |
|---|
| 6093 | 6080 | |
|---|
| 6094 | | - gpiochip_set_chained_irqchip(chip, &atlas7_gpio_irq_chip, |
|---|
| 6095 | | - bank->irq, atlas7_gpio_handle_irq); |
|---|
| 6081 | + /* Add gpio chip to system */ |
|---|
| 6082 | + ret = gpiochip_add_data(chip, a7gc); |
|---|
| 6083 | + if (ret) { |
|---|
| 6084 | + dev_err(&pdev->dev, |
|---|
| 6085 | + "%pOF: error in probe function with status %d\n", |
|---|
| 6086 | + np, ret); |
|---|
| 6087 | + goto failed; |
|---|
| 6096 | 6088 | } |
|---|
| 6097 | 6089 | |
|---|
| 6098 | 6090 | platform_set_drvdata(pdev, a7gc); |
|---|