Blame view

drivers/gpio/gpio-ucb1400.c 2.24 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
2
3
4
5
  /*
   * Philips UCB1400 GPIO driver
   *
   * Author: Marek Vasut <marek.vasut@gmail.com>
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
6
7
8
9
   */
  
  #include <linux/module.h>
  #include <linux/ucb1400.h>
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
10
11
12
  static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
  {
  	struct ucb1400_gpio *gpio;
9af4f0ab8   Linus Walleij   gpio: ucb1400: us...
13
  	gpio = gpiochip_get_data(gc);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
14
15
16
17
18
19
20
  	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;
9af4f0ab8   Linus Walleij   gpio: ucb1400: us...
21
  	gpio = gpiochip_get_data(gc);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
22
23
24
25
26
27
28
29
  	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;
9af4f0ab8   Linus Walleij   gpio: ucb1400: us...
30
31
  
  	gpio = gpiochip_get_data(gc);
c9d4ab030   Linus Walleij   gpio: ucb1400: Be...
32
  	return !!ucb1400_gpio_get_value(gpio->ac97, off);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
33
34
35
36
37
  }
  
  static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
  {
  	struct ucb1400_gpio *gpio;
9af4f0ab8   Linus Walleij   gpio: ucb1400: us...
38
  	gpio = gpiochip_get_data(gc);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
39
40
41
42
43
  	ucb1400_gpio_set_value(gpio->ac97, off, val);
  }
  
  static int ucb1400_gpio_probe(struct platform_device *dev)
  {
e56aee189   Jingoo Han   gpio: use dev_get...
44
  	struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
45
  	int err = 0;
360e64d8b   Marek Vasut   mfd: ucb1400: Pas...
46
  	if (!(ucb && ucb->gpio_offset)) {
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
47
48
49
50
51
52
53
  		err = -EINVAL;
  		goto err;
  	}
  
  	platform_set_drvdata(dev, ucb);
  
  	ucb->gc.label = "ucb1400_gpio";
360e64d8b   Marek Vasut   mfd: ucb1400: Pas...
54
  	ucb->gc.base = ucb->gpio_offset;
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
55
56
57
58
59
60
61
  	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;
9fb1f39eb   Linus Walleij   gpio/pinctrl: mak...
62
  	ucb->gc.can_sleep = true;
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
63

5d61a9e0a   Laxman Dewangan   gpio: ucb1400: Us...
64
  	err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
65
66
  	if (err)
  		goto err;
31a3f9da4   Rickard Strandqvist   gpio: gpio-ucb140...
67
  	if (ucb->gpio_setup)
360e64d8b   Marek Vasut   mfd: ucb1400: Pas...
68
  		err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
69
70
71
72
73
74
75
76
77
78
  
  err:
  	return err;
  
  }
  
  static int ucb1400_gpio_remove(struct platform_device *dev)
  {
  	int err = 0;
  	struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
360e64d8b   Marek Vasut   mfd: ucb1400: Pas...
79
80
  	if (ucb && ucb->gpio_teardown) {
  		err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
81
82
83
  		if (err)
  			return err;
  	}
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
84
85
86
87
88
89
90
91
92
93
  	return err;
  }
  
  static struct platform_driver ucb1400_gpio_driver = {
  	.probe	= ucb1400_gpio_probe,
  	.remove	= ucb1400_gpio_remove,
  	.driver	= {
  		.name	= "ucb1400_gpio"
  	},
  };
6f61415e9   Mark Brown   gpio: Convert GPI...
94
  module_platform_driver(ucb1400_gpio_driver);
4cf8e53b3   Marek Vasut   mfd/gpio: add a G...
95
96
97
  
  MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
  MODULE_LICENSE("GPL");
41ad730e5   Axel Lin   gpio: ucb1400: Ad...
98
  MODULE_ALIAS("platform:ucb1400_gpio");