0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/ucb1400.h>
0010
0011 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
0012 {
0013 struct ucb1400_gpio *gpio;
0014 gpio = gpiochip_get_data(gc);
0015 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
0016 return 0;
0017 }
0018
0019 static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
0020 {
0021 struct ucb1400_gpio *gpio;
0022 gpio = gpiochip_get_data(gc);
0023 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
0024 ucb1400_gpio_set_value(gpio->ac97, off, val);
0025 return 0;
0026 }
0027
0028 static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
0029 {
0030 struct ucb1400_gpio *gpio;
0031
0032 gpio = gpiochip_get_data(gc);
0033 return !!ucb1400_gpio_get_value(gpio->ac97, off);
0034 }
0035
0036 static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
0037 {
0038 struct ucb1400_gpio *gpio;
0039 gpio = gpiochip_get_data(gc);
0040 ucb1400_gpio_set_value(gpio->ac97, off, val);
0041 }
0042
0043 static int ucb1400_gpio_probe(struct platform_device *dev)
0044 {
0045 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
0046 int err = 0;
0047
0048 if (!(ucb && ucb->gpio_offset)) {
0049 err = -EINVAL;
0050 goto err;
0051 }
0052
0053 platform_set_drvdata(dev, ucb);
0054
0055 ucb->gc.label = "ucb1400_gpio";
0056 ucb->gc.base = ucb->gpio_offset;
0057 ucb->gc.ngpio = 10;
0058 ucb->gc.owner = THIS_MODULE;
0059
0060 ucb->gc.direction_input = ucb1400_gpio_dir_in;
0061 ucb->gc.direction_output = ucb1400_gpio_dir_out;
0062 ucb->gc.get = ucb1400_gpio_get;
0063 ucb->gc.set = ucb1400_gpio_set;
0064 ucb->gc.can_sleep = true;
0065
0066 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
0067
0068 err:
0069 return err;
0070
0071 }
0072
0073 static struct platform_driver ucb1400_gpio_driver = {
0074 .probe = ucb1400_gpio_probe,
0075 .driver = {
0076 .name = "ucb1400_gpio"
0077 },
0078 };
0079
0080 module_platform_driver(ucb1400_gpio_driver);
0081
0082 MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
0083 MODULE_LICENSE("GPL");
0084 MODULE_ALIAS("platform:ucb1400_gpio");