gpio-ucb1400.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Philips UCB1400 GPIO driver
  4. *
  5. * Author: Marek Vasut <[email protected]>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/ucb1400.h>
  9. #include <linux/gpio/driver.h>
  10. static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
  11. {
  12. struct ucb1400_gpio *gpio;
  13. gpio = gpiochip_get_data(gc);
  14. ucb1400_gpio_set_direction(gpio->ac97, off, 0);
  15. return 0;
  16. }
  17. static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
  18. {
  19. struct ucb1400_gpio *gpio;
  20. gpio = gpiochip_get_data(gc);
  21. ucb1400_gpio_set_direction(gpio->ac97, off, 1);
  22. ucb1400_gpio_set_value(gpio->ac97, off, val);
  23. return 0;
  24. }
  25. static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
  26. {
  27. struct ucb1400_gpio *gpio;
  28. gpio = gpiochip_get_data(gc);
  29. return !!ucb1400_gpio_get_value(gpio->ac97, off);
  30. }
  31. static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
  32. {
  33. struct ucb1400_gpio *gpio;
  34. gpio = gpiochip_get_data(gc);
  35. ucb1400_gpio_set_value(gpio->ac97, off, val);
  36. }
  37. static int ucb1400_gpio_probe(struct platform_device *dev)
  38. {
  39. struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
  40. int err = 0;
  41. if (!(ucb && ucb->gpio_offset)) {
  42. err = -EINVAL;
  43. goto err;
  44. }
  45. platform_set_drvdata(dev, ucb);
  46. ucb->gc.label = "ucb1400_gpio";
  47. ucb->gc.base = ucb->gpio_offset;
  48. ucb->gc.ngpio = 10;
  49. ucb->gc.owner = THIS_MODULE;
  50. ucb->gc.direction_input = ucb1400_gpio_dir_in;
  51. ucb->gc.direction_output = ucb1400_gpio_dir_out;
  52. ucb->gc.get = ucb1400_gpio_get;
  53. ucb->gc.set = ucb1400_gpio_set;
  54. ucb->gc.can_sleep = true;
  55. err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
  56. err:
  57. return err;
  58. }
  59. static struct platform_driver ucb1400_gpio_driver = {
  60. .probe = ucb1400_gpio_probe,
  61. .driver = {
  62. .name = "ucb1400_gpio"
  63. },
  64. };
  65. module_platform_driver(ucb1400_gpio_driver);
  66. MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS("platform:ucb1400_gpio");