ucb1400_gpio.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. struct ucb1400_gpio_data *ucbdata;
  14. static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
  15. {
  16. struct ucb1400_gpio *gpio;
  17. gpio = container_of(gc, struct ucb1400_gpio, gc);
  18. ucb1400_gpio_set_direction(gpio->ac97, off, 0);
  19. return 0;
  20. }
  21. static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
  22. {
  23. struct ucb1400_gpio *gpio;
  24. gpio = container_of(gc, struct ucb1400_gpio, gc);
  25. ucb1400_gpio_set_direction(gpio->ac97, off, 1);
  26. ucb1400_gpio_set_value(gpio->ac97, off, val);
  27. return 0;
  28. }
  29. static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
  30. {
  31. struct ucb1400_gpio *gpio;
  32. gpio = container_of(gc, struct ucb1400_gpio, gc);
  33. return ucb1400_gpio_get_value(gpio->ac97, off);
  34. }
  35. static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
  36. {
  37. struct ucb1400_gpio *gpio;
  38. gpio = container_of(gc, struct ucb1400_gpio, gc);
  39. ucb1400_gpio_set_value(gpio->ac97, off, val);
  40. }
  41. static int ucb1400_gpio_probe(struct platform_device *dev)
  42. {
  43. struct ucb1400_gpio *ucb = dev->dev.platform_data;
  44. int err = 0;
  45. if (!(ucbdata && ucbdata->gpio_offset)) {
  46. err = -EINVAL;
  47. goto err;
  48. }
  49. platform_set_drvdata(dev, ucb);
  50. ucb->gc.label = "ucb1400_gpio";
  51. ucb->gc.base = ucbdata->gpio_offset;
  52. ucb->gc.ngpio = 10;
  53. ucb->gc.owner = THIS_MODULE;
  54. ucb->gc.direction_input = ucb1400_gpio_dir_in;
  55. ucb->gc.direction_output = ucb1400_gpio_dir_out;
  56. ucb->gc.get = ucb1400_gpio_get;
  57. ucb->gc.set = ucb1400_gpio_set;
  58. ucb->gc.can_sleep = 1;
  59. err = gpiochip_add(&ucb->gc);
  60. if (err)
  61. goto err;
  62. if (ucbdata && ucbdata->gpio_setup)
  63. err = ucbdata->gpio_setup(&dev->dev, ucb->gc.ngpio);
  64. err:
  65. return err;
  66. }
  67. static int ucb1400_gpio_remove(struct platform_device *dev)
  68. {
  69. int err = 0;
  70. struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
  71. if (ucbdata && ucbdata->gpio_teardown) {
  72. err = ucbdata->gpio_teardown(&dev->dev, ucb->gc.ngpio);
  73. if (err)
  74. return err;
  75. }
  76. err = gpiochip_remove(&ucb->gc);
  77. return err;
  78. }
  79. static struct platform_driver ucb1400_gpio_driver = {
  80. .probe = ucb1400_gpio_probe,
  81. .remove = ucb1400_gpio_remove,
  82. .driver = {
  83. .name = "ucb1400_gpio"
  84. },
  85. };
  86. static int __init ucb1400_gpio_init(void)
  87. {
  88. return platform_driver_register(&ucb1400_gpio_driver);
  89. }
  90. static void __exit ucb1400_gpio_exit(void)
  91. {
  92. platform_driver_unregister(&ucb1400_gpio_driver);
  93. }
  94. void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data)
  95. {
  96. ucbdata = data;
  97. }
  98. module_init(ucb1400_gpio_init);
  99. module_exit(ucb1400_gpio_exit);
  100. MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
  101. MODULE_LICENSE("GPL");