cregit-Linux how code gets into the kernel

Release 4.7 drivers/gpio/gpio-xgene.c

Directory: drivers/gpio
/*
 * AppliedMicro X-Gene SoC GPIO Driver
 *
 * Copyright (c) 2014, Applied Micro Circuits Corporation
 * Author: Feng Kan <fkan@apm.com>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/acpi.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/platform_device.h>
#include <linux/gpio/driver.h>
#include <linux/types.h>
#include <linux/bitops.h>


#define GPIO_SET_DR_OFFSET	0x0C

#define GPIO_DATA_OFFSET	0x14

#define GPIO_BANK_STRIDE	0x0C


#define XGENE_GPIOS_PER_BANK	16

#define XGENE_MAX_GPIO_BANKS	3

#define XGENE_MAX_GPIOS		(XGENE_GPIOS_PER_BANK * XGENE_MAX_GPIO_BANKS)


#define GPIO_BIT_OFFSET(x)	(x % XGENE_GPIOS_PER_BANK)

#define GPIO_BANK_OFFSET(x)	((x / XGENE_GPIOS_PER_BANK) * GPIO_BANK_STRIDE)


struct xgene_gpio {
	
struct gpio_chip	chip;
	
void __iomem		*base;
	
spinlock_t		lock;
#ifdef CONFIG_PM
	
u32			set_dr_val[XGENE_MAX_GPIO_BANKS];
#endif
};


static int xgene_gpio_get(struct gpio_chip *gc, unsigned int offset) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long bank_offset; u32 bit_offset; bank_offset = GPIO_DATA_OFFSET + GPIO_BANK_OFFSET(offset); bit_offset = GPIO_BIT_OFFSET(offset); return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset)); }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan6698.51%150.00%
linus walleijlinus walleij11.49%150.00%
Total67100.00%2100.00%


static void __xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long bank_offset; u32 setval, bit_offset; bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); bit_offset = GPIO_BIT_OFFSET(offset) + XGENE_GPIOS_PER_BANK; setval = ioread32(chip->base + bank_offset); if (val) setval |= BIT(bit_offset); else setval &= ~BIT(bit_offset); iowrite32(setval, chip->base + bank_offset); }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan9698.97%150.00%
linus walleijlinus walleij11.03%150.00%
Total97100.00%2100.00%


static void xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long flags; spin_lock_irqsave(&chip->lock, flags); __xgene_gpio_set(gc, offset, val); spin_unlock_irqrestore(&chip->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan6098.36%150.00%
linus walleijlinus walleij11.64%150.00%
Total61100.00%2100.00%


static int xgene_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long bank_offset, bit_offset; bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); bit_offset = GPIO_BIT_OFFSET(offset); return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset)); }

Contributors

PersonTokensPropCommitsCommitProp
linus walleijlinus walleij66100.00%1100.00%
Total66100.00%1100.00%


static int xgene_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long flags, bank_offset; u32 dirval, bit_offset; bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); bit_offset = GPIO_BIT_OFFSET(offset); spin_lock_irqsave(&chip->lock, flags); dirval = ioread32(chip->base + bank_offset); dirval |= BIT(bit_offset); iowrite32(dirval, chip->base + bank_offset); spin_unlock_irqrestore(&chip->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan10399.04%150.00%
linus walleijlinus walleij10.96%150.00%
Total104100.00%2100.00%


static int xgene_gpio_dir_out(struct gpio_chip *gc, unsigned int offset, int val) { struct xgene_gpio *chip = gpiochip_get_data(gc); unsigned long flags, bank_offset; u32 dirval, bit_offset; bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); bit_offset = GPIO_BIT_OFFSET(offset); spin_lock_irqsave(&chip->lock, flags); dirval = ioread32(chip->base + bank_offset); dirval &= ~BIT(bit_offset); iowrite32(dirval, chip->base + bank_offset); __xgene_gpio_set(gc, offset, val); spin_unlock_irqrestore(&chip->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan11699.15%150.00%
linus walleijlinus walleij10.85%150.00%
Total117100.00%2100.00%

#ifdef CONFIG_PM
static int xgene_gpio_suspend(struct device *dev) { struct xgene_gpio *gpio = dev_get_drvdata(dev); unsigned long bank_offset; unsigned int bank; for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) { bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE; gpio->set_dr_val[bank] = ioread32(gpio->base + bank_offset); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan71100.00%1100.00%
Total71100.00%1100.00%


static int xgene_gpio_resume(struct device *dev) { struct xgene_gpio *gpio = dev_get_drvdata(dev); unsigned long bank_offset; unsigned int bank; for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) { bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE; iowrite32(gpio->set_dr_val[bank], gpio->base + bank_offset); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan71100.00%1100.00%
Total71100.00%1100.00%

static SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume); #define XGENE_GPIO_PM_OPS (&xgene_gpio_pm) #else #define XGENE_GPIO_PM_OPS NULL #endif
static int xgene_gpio_probe(struct platform_device *pdev) { struct resource *res; struct xgene_gpio *gpio; int err = 0; gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); if (!gpio) { err = -ENOMEM; goto err; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { err = -EINVAL; goto err; } gpio->base = devm_ioremap_nocache(&pdev->dev, res->start, resource_size(res)); if (!gpio->base) { err = -ENOMEM; goto err; } gpio->chip.ngpio = XGENE_MAX_GPIOS; spin_lock_init(&gpio->lock); gpio->chip.parent = &pdev->dev; gpio->chip.get_direction = xgene_gpio_get_direction; gpio->chip.direction_input = xgene_gpio_dir_in; gpio->chip.direction_output = xgene_gpio_dir_out; gpio->chip.get = xgene_gpio_get; gpio->chip.set = xgene_gpio_set; gpio->chip.label = dev_name(&pdev->dev); gpio->chip.base = -1; platform_set_drvdata(pdev, gpio); err = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); if (err) { dev_err(&pdev->dev, "failed to register gpiochip.\n"); goto err; } dev_info(&pdev->dev, "X-Gene GPIO driver registered.\n"); return 0; err: dev_err(&pdev->dev, "X-Gene GPIO driver registration failed.\n"); return err; }

Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan24184.86%112.50%
axel linaxel lin238.10%225.00%
linus walleijlinus walleij113.87%337.50%
laxman dewanganlaxman dewangan62.11%112.50%
wei yongjunwei yongjun31.06%112.50%
Total284100.00%8100.00%

static const struct of_device_id xgene_gpio_of_match[] = { { .compatible = "apm,xgene-gpio", }, {}, }; #ifdef CONFIG_ACPI static const struct acpi_device_id xgene_gpio_acpi_match[] = { { "APMC0D14", 0 }, { }, }; #endif static struct platform_driver xgene_gpio_driver = { .driver = { .name = "xgene-gpio", .of_match_table = xgene_gpio_of_match, .acpi_match_table = ACPI_PTR(xgene_gpio_acpi_match), .pm = XGENE_GPIO_PM_OPS, }, .probe = xgene_gpio_probe, }; builtin_platform_driver(xgene_gpio_driver);

Overall Contributors

PersonTokensPropCommitsCommitProp
feng kanfeng kan99687.22%110.00%
linus walleijlinus walleij827.18%330.00%
duc dangduc dang312.71%110.00%
axel linaxel lin232.01%220.00%
laxman dewanganlaxman dewangan60.53%110.00%
wei yongjunwei yongjun30.26%110.00%
paul gortmakerpaul gortmaker10.09%110.00%
Total1142100.00%10100.00%
Directory: drivers/gpio
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}