cregit-Linux how code gets into the kernel

Release 4.7 drivers/gpio/gpio-da9055.c

Directory: drivers/gpio
/*
 * GPIO Driver for Dialog DA9055 PMICs.
 *
 * Copyright(c) 2012 Dialog Semiconductor Ltd.
 *
 * Author: David Dajun Chen <dchen@diasemi.com>
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License, or (at your
 *  option) any later version.
 *
 */
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>

#include <linux/mfd/da9055/core.h>
#include <linux/mfd/da9055/reg.h>
#include <linux/mfd/da9055/pdata.h>


#define DA9055_VDD_IO			0x0

#define DA9055_PUSH_PULL		0x3

#define DA9055_ACT_LOW			0x0

#define DA9055_GPI			0x1

#define DA9055_PORT_MASK		0x3

#define DA9055_PORT_SHIFT(offset)	(4 * (offset % 2))


#define DA9055_INPUT			DA9055_GPI

#define DA9055_OUTPUT			DA9055_PUSH_PULL

#define DA9055_IRQ_GPI0			3


struct da9055_gpio {
	
struct da9055 *da9055;
	
struct gpio_chip gp;
};


static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) { struct da9055_gpio *gpio = gpiochip_get_data(gc); int gpio_direction = 0; int ret; /* Get GPIO direction */ ret = da9055_reg_read(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1); if (ret < 0) return ret; gpio_direction = ret & (DA9055_PORT_MASK) << DA9055_PORT_SHIFT(offset); gpio_direction >>= DA9055_PORT_SHIFT(offset); switch (gpio_direction) { case DA9055_INPUT: ret = da9055_reg_read(gpio->da9055, DA9055_REG_STATUS_B); if (ret < 0) return ret; break; case DA9055_OUTPUT: ret = da9055_reg_read(gpio->da9055, DA9055_REG_GPIO_MODE0_2); if (ret < 0) return ret; } return ret & (1 << offset); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam14099.29%150.00%
linus walleijlinus walleij10.71%150.00%
Total141100.00%2100.00%


static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { struct da9055_gpio *gpio = gpiochip_get_data(gc); da9055_reg_update(gpio->da9055, DA9055_REG_GPIO_MODE0_2, 1 << offset, value << offset); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam4397.73%150.00%
linus walleijlinus walleij12.27%150.00%
Total44100.00%2100.00%


static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { struct da9055_gpio *gpio = gpiochip_get_data(gc); unsigned char reg_byte; reg_byte = (DA9055_ACT_LOW | DA9055_GPI) << DA9055_PORT_SHIFT(offset); return da9055_reg_update(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1, DA9055_PORT_MASK << DA9055_PORT_SHIFT(offset), reg_byte); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam6598.48%150.00%
linus walleijlinus walleij11.52%150.00%
Total66100.00%2100.00%


static int da9055_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { struct da9055_gpio *gpio = gpiochip_get_data(gc); unsigned char reg_byte; int ret; reg_byte = (DA9055_VDD_IO | DA9055_PUSH_PULL) << DA9055_PORT_SHIFT(offset); ret = da9055_reg_update(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1, DA9055_PORT_MASK << DA9055_PORT_SHIFT(offset), reg_byte); if (ret < 0) return ret; da9055_gpio_set(gc, offset, value); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam9398.94%150.00%
linus walleijlinus walleij11.06%150.00%
Total94100.00%2100.00%


static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset) { struct da9055_gpio *gpio = gpiochip_get_data(gc); struct da9055 *da9055 = gpio->da9055; return regmap_irq_get_virq(da9055->irq_data, DA9055_IRQ_GPI0 + offset); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam4497.78%150.00%
linus walleijlinus walleij12.22%150.00%
Total45100.00%2100.00%

static struct gpio_chip reference_gp = { .label = "da9055-gpio", .owner = THIS_MODULE, .get = da9055_gpio_get, .set = da9055_gpio_set, .direction_input = da9055_gpio_direction_input, .direction_output = da9055_gpio_direction_output, .to_irq = da9055_gpio_to_irq, .can_sleep = true, .ngpio = 3, .base = -1, };
static int da9055_gpio_probe(struct platform_device *pdev) { struct da9055_gpio *gpio; struct da9055_pdata *pdata; int ret; gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); if (!gpio) return -ENOMEM; gpio->da9055 = dev_get_drvdata(pdev->dev.parent); pdata = dev_get_platdata(gpio->da9055->dev); gpio->gp = reference_gp; if (pdata && pdata->gpio_base) gpio->gp.base = pdata->gpio_base; ret = devm_gpiochip_add_data(&pdev->dev, &gpio->gp, gpio); if (ret < 0) { dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); return ret; } platform_set_drvdata(pdev, gpio); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam13288.59%116.67%
laxman dewanganlaxman dewangan85.37%116.67%
jingoo hanjingoo han32.01%116.67%
abdoulaye bertheabdoulaye berthe32.01%116.67%
linus walleijlinus walleij21.34%116.67%
varka bhadramvarka bhadram10.67%116.67%
Total149100.00%6100.00%

static struct platform_driver da9055_gpio_driver = { .probe = da9055_gpio_probe, .driver = { .name = "da9055-gpio", }, };
static int __init da9055_gpio_init(void) { return platform_driver_register(&da9055_gpio_driver); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam16100.00%1100.00%
Total16100.00%1100.00%

subsys_initcall(da9055_gpio_init);
static void __exit da9055_gpio_exit(void) { platform_driver_unregister(&da9055_gpio_driver); }

Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam15100.00%1100.00%
Total15100.00%1100.00%

module_exit(da9055_gpio_exit); MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); MODULE_DESCRIPTION("DA9055 GPIO Device Driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:da9055-gpio");

Overall Contributors

PersonTokensPropCommitsCommitProp
ashish jangamashish jangam72996.94%114.29%
linus walleijlinus walleij81.06%228.57%
laxman dewanganlaxman dewangan81.06%114.29%
abdoulaye bertheabdoulaye berthe30.40%114.29%
jingoo hanjingoo han30.40%114.29%
varka bhadramvarka bhadram10.13%114.29%
greg kroah-hartmangreg kroah-hartman0.00%00.00%
Total752100.00%7100.00%
Directory: drivers/gpio
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}