gpio-ucb1400.c 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Philips UCB1400 GPIO driver
 *
 * Author: Marek Vasut <marek.vasut@gmail.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.
 *
 */

#include <linux/module.h>
#include <linux/ucb1400.h>

static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
{
	struct ucb1400_gpio *gpio;
18
	gpio = gpiochip_get_data(gc);
19 20 21 22 23 24 25
	ucb1400_gpio_set_direction(gpio->ac97, off, 0);
	return 0;
}

static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
{
	struct ucb1400_gpio *gpio;
26
	gpio = gpiochip_get_data(gc);
27 28 29 30 31 32 33 34
	ucb1400_gpio_set_direction(gpio->ac97, off, 1);
	ucb1400_gpio_set_value(gpio->ac97, off, val);
	return 0;
}

static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
{
	struct ucb1400_gpio *gpio;
35 36

	gpio = gpiochip_get_data(gc);
37
	return !!ucb1400_gpio_get_value(gpio->ac97, off);
38 39 40 41 42
}

static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
{
	struct ucb1400_gpio *gpio;
43
	gpio = gpiochip_get_data(gc);
44 45 46 47 48
	ucb1400_gpio_set_value(gpio->ac97, off, val);
}

static int ucb1400_gpio_probe(struct platform_device *dev)
{
J
Jingoo Han 已提交
49
	struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
50 51
	int err = 0;

52
	if (!(ucb && ucb->gpio_offset)) {
53 54 55 56 57 58 59
		err = -EINVAL;
		goto err;
	}

	platform_set_drvdata(dev, ucb);

	ucb->gc.label = "ucb1400_gpio";
60
	ucb->gc.base = ucb->gpio_offset;
61 62 63 64 65 66 67
	ucb->gc.ngpio = 10;
	ucb->gc.owner = THIS_MODULE;

	ucb->gc.direction_input = ucb1400_gpio_dir_in;
	ucb->gc.direction_output = ucb1400_gpio_dir_out;
	ucb->gc.get = ucb1400_gpio_get;
	ucb->gc.set = ucb1400_gpio_set;
68
	ucb->gc.can_sleep = true;
69

70
	err = gpiochip_add_data(&ucb->gc, ucb);
71 72 73
	if (err)
		goto err;

74
	if (ucb->gpio_setup)
75
		err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
76 77 78 79 80 81 82 83 84 85 86

err:
	return err;

}

static int ucb1400_gpio_remove(struct platform_device *dev)
{
	int err = 0;
	struct ucb1400_gpio *ucb = platform_get_drvdata(dev);

87 88
	if (ucb && ucb->gpio_teardown) {
		err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
89 90 91 92
		if (err)
			return err;
	}

93
	gpiochip_remove(&ucb->gc);
94 95 96 97 98 99 100 101 102 103 104
	return err;
}

static struct platform_driver ucb1400_gpio_driver = {
	.probe	= ucb1400_gpio_probe,
	.remove	= ucb1400_gpio_remove,
	.driver	= {
		.name	= "ucb1400_gpio"
	},
};

105
module_platform_driver(ucb1400_gpio_driver);
106 107 108

MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
MODULE_LICENSE("GPL");
A
Axel Lin 已提交
109
MODULE_ALIAS("platform:ucb1400_gpio");