Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Philips UCB1400 GPIO driver |
| 3 | * |
| 4 | * Author: Marek Vasut <marek.vasut@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/ucb1400.h> |
| 14 | |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 15 | static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off) |
| 16 | { |
| 17 | struct ucb1400_gpio *gpio; |
Linus Walleij | 9af4f0a | 2015-12-07 15:01:14 +0100 | [diff] [blame] | 18 | gpio = gpiochip_get_data(gc); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 19 | ucb1400_gpio_set_direction(gpio->ac97, off, 0); |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val) |
| 24 | { |
| 25 | struct ucb1400_gpio *gpio; |
Linus Walleij | 9af4f0a | 2015-12-07 15:01:14 +0100 | [diff] [blame] | 26 | gpio = gpiochip_get_data(gc); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 27 | ucb1400_gpio_set_direction(gpio->ac97, off, 1); |
| 28 | ucb1400_gpio_set_value(gpio->ac97, off, val); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off) |
| 33 | { |
| 34 | struct ucb1400_gpio *gpio; |
Linus Walleij | 9af4f0a | 2015-12-07 15:01:14 +0100 | [diff] [blame] | 35 | |
| 36 | gpio = gpiochip_get_data(gc); |
Linus Walleij | c9d4ab0 | 2015-12-21 14:56:04 +0100 | [diff] [blame] | 37 | return !!ucb1400_gpio_get_value(gpio->ac97, off); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val) |
| 41 | { |
| 42 | struct ucb1400_gpio *gpio; |
Linus Walleij | 9af4f0a | 2015-12-07 15:01:14 +0100 | [diff] [blame] | 43 | gpio = gpiochip_get_data(gc); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 44 | ucb1400_gpio_set_value(gpio->ac97, off, val); |
| 45 | } |
| 46 | |
| 47 | static int ucb1400_gpio_probe(struct platform_device *dev) |
| 48 | { |
Jingoo Han | e56aee1 | 2013-07-30 17:08:05 +0900 | [diff] [blame] | 49 | struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 50 | int err = 0; |
| 51 | |
Marek Vasut | 360e64d | 2013-04-14 20:35:48 +0200 | [diff] [blame] | 52 | if (!(ucb && ucb->gpio_offset)) { |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 53 | err = -EINVAL; |
| 54 | goto err; |
| 55 | } |
| 56 | |
| 57 | platform_set_drvdata(dev, ucb); |
| 58 | |
| 59 | ucb->gc.label = "ucb1400_gpio"; |
Marek Vasut | 360e64d | 2013-04-14 20:35:48 +0200 | [diff] [blame] | 60 | ucb->gc.base = ucb->gpio_offset; |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 61 | ucb->gc.ngpio = 10; |
| 62 | ucb->gc.owner = THIS_MODULE; |
| 63 | |
| 64 | ucb->gc.direction_input = ucb1400_gpio_dir_in; |
| 65 | ucb->gc.direction_output = ucb1400_gpio_dir_out; |
| 66 | ucb->gc.get = ucb1400_gpio_get; |
| 67 | ucb->gc.set = ucb1400_gpio_set; |
Linus Walleij | 9fb1f39 | 2013-12-04 14:42:46 +0100 | [diff] [blame] | 68 | ucb->gc.can_sleep = true; |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 69 | |
Laxman Dewangan | 5d61a9e | 2016-02-22 17:43:28 +0530 | [diff] [blame] | 70 | err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 71 | if (err) |
| 72 | goto err; |
| 73 | |
Rickard Strandqvist | 31a3f9d | 2014-06-26 18:18:51 +0200 | [diff] [blame] | 74 | if (ucb->gpio_setup) |
Marek Vasut | 360e64d | 2013-04-14 20:35:48 +0200 | [diff] [blame] | 75 | err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 76 | |
| 77 | err: |
| 78 | return err; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | static int ucb1400_gpio_remove(struct platform_device *dev) |
| 83 | { |
| 84 | int err = 0; |
| 85 | struct ucb1400_gpio *ucb = platform_get_drvdata(dev); |
| 86 | |
Marek Vasut | 360e64d | 2013-04-14 20:35:48 +0200 | [diff] [blame] | 87 | if (ucb && ucb->gpio_teardown) { |
| 88 | err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 89 | if (err) |
| 90 | return err; |
| 91 | } |
| 92 | |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 93 | return err; |
| 94 | } |
| 95 | |
| 96 | static struct platform_driver ucb1400_gpio_driver = { |
| 97 | .probe = ucb1400_gpio_probe, |
| 98 | .remove = ucb1400_gpio_remove, |
| 99 | .driver = { |
| 100 | .name = "ucb1400_gpio" |
| 101 | }, |
| 102 | }; |
| 103 | |
Mark Brown | 6f61415 | 2011-12-08 00:24:00 +0800 | [diff] [blame] | 104 | module_platform_driver(ucb1400_gpio_driver); |
Marek Vasut | 4cf8e53 | 2009-09-22 16:46:35 -0700 | [diff] [blame] | 105 | |
| 106 | MODULE_DESCRIPTION("Philips UCB1400 GPIO driver"); |
| 107 | MODULE_LICENSE("GPL"); |
Axel Lin | 41ad730 | 2013-11-19 15:31:20 +0800 | [diff] [blame] | 108 | MODULE_ALIAS("platform:ucb1400_gpio"); |