Release 4.7 drivers/gpio/gpio-kempld.c
/*
* Kontron PLD GPIO driver
*
* Copyright (c) 2010-2013 Kontron Europe GmbH
* Author: Michael Brunner <michael.brunner@kontron.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License 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.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/mfd/kempld.h>
#define KEMPLD_GPIO_MAX_NUM 16
#define KEMPLD_GPIO_MASK(x) (BIT((x) % 8))
#define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x) / 8)
#define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x) / 8)
#define KEMPLD_GPIO_EVT_LVL_EDGE 0x46
#define KEMPLD_GPIO_IEN 0x4A
struct kempld_gpio_data {
struct gpio_chip chip;
struct kempld_device_data *pld;
};
/*
* Set or clear GPIO bit
* kempld_get_mutex must be called prior to calling this function.
*/
static void kempld_gpio_bitop(struct kempld_device_data *pld,
u8 reg, u8 bit, u8 val)
{
u8 status;
status = kempld_read8(pld, reg);
if (val)
status |= KEMPLD_GPIO_MASK(bit);
else
status &= ~KEMPLD_GPIO_MASK(bit);
kempld_write8(pld, reg, status);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 55 | 90.16% | 1 | 50.00% |
brunner michael | brunner michael | 6 | 9.84% | 1 | 50.00% |
| Total | 61 | 100.00% | 2 | 100.00% |
static int kempld_gpio_get_bit(struct kempld_device_data *pld, u8 reg, u8 bit)
{
u8 status;
kempld_get_mutex(pld);
status = kempld_read8(pld, reg);
kempld_release_mutex(pld);
return !!(status & KEMPLD_GPIO_MASK(bit));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 48 | 94.12% | 1 | 50.00% |
brunner michael | brunner michael | 3 | 5.88% | 1 | 50.00% |
| Total | 51 | 100.00% | 2 | 100.00% |
static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 45 | 93.75% | 1 | 33.33% |
linus walleij | linus walleij | 3 | 6.25% | 2 | 66.67% |
| Total | 48 | 100.00% | 3 | 100.00% |
static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld);
kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value);
kempld_release_mutex(pld);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 59 | 98.33% | 1 | 50.00% |
linus walleij | linus walleij | 1 | 1.67% | 1 | 50.00% |
| Total | 60 | 100.00% | 2 | 100.00% |
static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld);
kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 0);
kempld_release_mutex(pld);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 59 | 98.33% | 1 | 50.00% |
linus walleij | linus walleij | 1 | 1.67% | 1 | 50.00% |
| Total | 60 | 100.00% | 2 | 100.00% |
static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld);
kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value);
kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 1);
kempld_release_mutex(pld);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 76 | 98.70% | 1 | 50.00% |
linus walleij | linus walleij | 1 | 1.30% | 1 | 50.00% |
| Total | 77 | 100.00% | 2 | 100.00% |
static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 45 | 95.74% | 1 | 33.33% |
linus walleij | linus walleij | 1 | 2.13% | 1 | 33.33% |
michael brunner | michael brunner | 1 | 2.13% | 1 | 33.33% |
| Total | 47 | 100.00% | 3 | 100.00% |
static int kempld_gpio_pincount(struct kempld_device_data *pld)
{
u16 evt, evt_back;
kempld_get_mutex(pld);
/* Backup event register as it might be already initialized */
evt_back = kempld_read16(pld, KEMPLD_GPIO_EVT_LVL_EDGE);
/* Clear event register */
kempld_write16(pld, KEMPLD_GPIO_EVT_LVL_EDGE, 0x0000);
/* Read back event register */
evt = kempld_read16(pld, KEMPLD_GPIO_EVT_LVL_EDGE);
/* Restore event register */
kempld_write16(pld, KEMPLD_GPIO_EVT_LVL_EDGE, evt_back);
kempld_release_mutex(pld);
return evt ? __ffs(evt) : 16;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 76 | 100.00% | 1 | 100.00% |
| Total | 76 | 100.00% | 1 | 100.00% |
static int kempld_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct kempld_device_data *pld = dev_get_drvdata(dev->parent);
struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
struct kempld_gpio_data *gpio;
struct gpio_chip *chip;
int ret;
if (pld->info.spec_major < 2) {
dev_err(dev,
"Driver only supports GPIO devices compatible to PLD spec. rev. 2.0 or higher\n");
return -ENODEV;
}
gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
if (!gpio)
return -ENOMEM;
gpio->pld = pld;
platform_set_drvdata(pdev, gpio);
chip = &gpio->chip;
chip->label = "gpio-kempld";
chip->owner = THIS_MODULE;
chip->parent = dev;
chip->can_sleep = true;
if (pdata && pdata->gpio_base)
chip->base = pdata->gpio_base;
else
chip->base = -1;
chip->direction_input = kempld_gpio_direction_input;
chip->direction_output = kempld_gpio_direction_output;
chip->get_direction = kempld_gpio_get_direction;
chip->get = kempld_gpio_get;
chip->set = kempld_gpio_set;
chip->ngpio = kempld_gpio_pincount(pld);
if (chip->ngpio == 0) {
dev_err(dev, "No GPIO pins detected\n");
return -ENODEV;
}
ret = devm_gpiochip_add_data(dev, chip, gpio);
if (ret) {
dev_err(dev, "Could not register GPIO chip\n");
return ret;
}
dev_info(dev, "GPIO functionality initialized with %d pins\n",
chip->ngpio);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 263 | 95.99% | 1 | 14.29% |
linus walleij | linus walleij | 4 | 1.46% | 3 | 42.86% |
laxman dewangan | laxman dewangan | 3 | 1.09% | 1 | 14.29% |
jingoo han | jingoo han | 3 | 1.09% | 1 | 14.29% |
varka bhadram | varka bhadram | 1 | 0.36% | 1 | 14.29% |
| Total | 274 | 100.00% | 7 | 100.00% |
static struct platform_driver kempld_gpio_driver = {
.driver = {
.name = "kempld-gpio",
},
.probe = kempld_gpio_probe,
};
module_platform_driver(kempld_gpio_driver);
MODULE_DESCRIPTION("KEM PLD GPIO Driver");
MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:kempld-gpio");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guenter roeck | guenter roeck | 843 | 96.45% | 1 | 7.69% |
linus walleij | linus walleij | 11 | 1.26% | 4 | 30.77% |
brunner michael | brunner michael | 9 | 1.03% | 1 | 7.69% |
laxman dewangan | laxman dewangan | 3 | 0.34% | 1 | 7.69% |
jingoo han | jingoo han | 3 | 0.34% | 1 | 7.69% |
michael brunner | michael brunner | 2 | 0.23% | 2 | 15.38% |
axel lin | axel lin | 1 | 0.11% | 1 | 7.69% |
varka bhadram | varka bhadram | 1 | 0.11% | 1 | 7.69% |
javier martinez canillas | javier martinez canillas | 1 | 0.11% | 1 | 7.69% |
| Total | 874 | 100.00% | 13 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.