gpio-ucb1400.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 = container_of(gc, struct ucb1400_gpio, 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 = container_of(gc, struct ucb1400_gpio, 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 = container_of(gc, struct ucb1400_gpio, 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 = container_of(gc, struct ucb1400_gpio, 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 = gpiochip_add(&ucb->gc);
  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. gpiochip_remove(&ucb->gc);
  76. return err;
  77. }
  78. static struct platform_driver ucb1400_gpio_driver = {
  79. .probe = ucb1400_gpio_probe,
  80. .remove = ucb1400_gpio_remove,
  81. .driver = {
  82. .name = "ucb1400_gpio"
  83. },
  84. };
  85. module_platform_driver(ucb1400_gpio_driver);
  86. MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
  87. MODULE_LICENSE("GPL");
  88. MODULE_ALIAS("platform:ucb1400_gpio");