gpio-ucb1400.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <linux/module.h>
  12. #include <linux/ucb1400.h>
  13. static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
  14. {
  15. struct ucb1400_gpio *gpio;
  16. gpio = gpiochip_get_data(gc);
  17. ucb1400_gpio_set_direction(gpio->ac97, off, 0);
  18. return 0;
  19. }
  20. static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
  21. {
  22. struct ucb1400_gpio *gpio;
  23. gpio = gpiochip_get_data(gc);
  24. ucb1400_gpio_set_direction(gpio->ac97, off, 1);
  25. ucb1400_gpio_set_value(gpio->ac97, off, val);
  26. return 0;
  27. }
  28. static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
  29. {
  30. struct ucb1400_gpio *gpio;
  31. gpio = gpiochip_get_data(gc);
  32. return !!ucb1400_gpio_get_value(gpio->ac97, off);
  33. }
  34. static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
  35. {
  36. struct ucb1400_gpio *gpio;
  37. gpio = gpiochip_get_data(gc);
  38. ucb1400_gpio_set_value(gpio->ac97, off, val);
  39. }
  40. static int ucb1400_gpio_probe(struct platform_device *dev)
  41. {
  42. struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
  43. int err = 0;
  44. if (!(ucb && ucb->gpio_offset)) {
  45. err = -EINVAL;
  46. goto err;
  47. }
  48. platform_set_drvdata(dev, ucb);
  49. ucb->gc.label = "ucb1400_gpio";
  50. ucb->gc.base = ucb->gpio_offset;
  51. ucb->gc.ngpio = 10;
  52. ucb->gc.owner = THIS_MODULE;
  53. ucb->gc.direction_input = ucb1400_gpio_dir_in;
  54. ucb->gc.direction_output = ucb1400_gpio_dir_out;
  55. ucb->gc.get = ucb1400_gpio_get;
  56. ucb->gc.set = ucb1400_gpio_set;
  57. ucb->gc.can_sleep = true;
  58. err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
  59. if (err)
  60. goto err;
  61. if (ucb->gpio_setup)
  62. err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
  63. err:
  64. return err;
  65. }
  66. static int ucb1400_gpio_remove(struct platform_device *dev)
  67. {
  68. int err = 0;
  69. struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
  70. if (ucb && ucb->gpio_teardown) {
  71. err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
  72. if (err)
  73. return err;
  74. }
  75. return err;
  76. }
  77. static struct platform_driver ucb1400_gpio_driver = {
  78. .probe = ucb1400_gpio_probe,
  79. .remove = ucb1400_gpio_remove,
  80. .driver = {
  81. .name = "ucb1400_gpio"
  82. },
  83. };
  84. module_platform_driver(ucb1400_gpio_driver);
  85. MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
  86. MODULE_LICENSE("GPL");
  87. MODULE_ALIAS("platform:ucb1400_gpio");