PageRenderTime 218ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/media/video/bt8xx/bttv-gpio.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 187 lines | 119 code | 30 blank | 38 comment | 7 complexity | 4202b56eb13702460070f337a6855725 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. bttv-gpio.c -- gpio sub drivers
  3. sysfs-based sub driver interface for bttv
  4. mainly intended for gpio access
  5. Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
  6. & Marcus Metzler (mocm@thp.uni-koeln.de)
  7. (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/device.h>
  24. #include <linux/slab.h>
  25. #include <asm/io.h>
  26. #include "bttvp.h"
  27. /* ----------------------------------------------------------------------- */
  28. /* internal: the bttv "bus" */
  29. static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv)
  30. {
  31. struct bttv_sub_driver *sub = to_bttv_sub_drv(drv);
  32. int len = strlen(sub->wanted);
  33. if (0 == strncmp(dev_name(dev), sub->wanted, len))
  34. return 1;
  35. return 0;
  36. }
  37. static int bttv_sub_probe(struct device *dev)
  38. {
  39. struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
  40. struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
  41. return sub->probe ? sub->probe(sdev) : -ENODEV;
  42. }
  43. static int bttv_sub_remove(struct device *dev)
  44. {
  45. struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
  46. struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
  47. if (sub->remove)
  48. sub->remove(sdev);
  49. return 0;
  50. }
  51. struct bus_type bttv_sub_bus_type = {
  52. .name = "bttv-sub",
  53. .match = &bttv_sub_bus_match,
  54. .probe = bttv_sub_probe,
  55. .remove = bttv_sub_remove,
  56. };
  57. static void release_sub_device(struct device *dev)
  58. {
  59. struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
  60. kfree(sub);
  61. }
  62. int bttv_sub_add_device(struct bttv_core *core, char *name)
  63. {
  64. struct bttv_sub_device *sub;
  65. int err;
  66. sub = kzalloc(sizeof(*sub),GFP_KERNEL);
  67. if (NULL == sub)
  68. return -ENOMEM;
  69. sub->core = core;
  70. sub->dev.parent = &core->pci->dev;
  71. sub->dev.bus = &bttv_sub_bus_type;
  72. sub->dev.release = release_sub_device;
  73. dev_set_name(&sub->dev, "%s%d", name, core->nr);
  74. err = device_register(&sub->dev);
  75. if (0 != err) {
  76. kfree(sub);
  77. return err;
  78. }
  79. printk("bttv%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev));
  80. list_add_tail(&sub->list,&core->subs);
  81. return 0;
  82. }
  83. int bttv_sub_del_devices(struct bttv_core *core)
  84. {
  85. struct bttv_sub_device *sub, *save;
  86. list_for_each_entry_safe(sub, save, &core->subs, list) {
  87. list_del(&sub->list);
  88. device_unregister(&sub->dev);
  89. }
  90. return 0;
  91. }
  92. /* ----------------------------------------------------------------------- */
  93. /* external: sub-driver register/unregister */
  94. int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted)
  95. {
  96. sub->drv.bus = &bttv_sub_bus_type;
  97. snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted);
  98. return driver_register(&sub->drv);
  99. }
  100. EXPORT_SYMBOL(bttv_sub_register);
  101. int bttv_sub_unregister(struct bttv_sub_driver *sub)
  102. {
  103. driver_unregister(&sub->drv);
  104. return 0;
  105. }
  106. EXPORT_SYMBOL(bttv_sub_unregister);
  107. /* ----------------------------------------------------------------------- */
  108. /* external: gpio access functions */
  109. void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits)
  110. {
  111. struct bttv *btv = container_of(core, struct bttv, c);
  112. unsigned long flags;
  113. u32 data;
  114. spin_lock_irqsave(&btv->gpio_lock,flags);
  115. data = btread(BT848_GPIO_OUT_EN);
  116. data = data & ~mask;
  117. data = data | (mask & outbits);
  118. btwrite(data,BT848_GPIO_OUT_EN);
  119. spin_unlock_irqrestore(&btv->gpio_lock,flags);
  120. }
  121. u32 bttv_gpio_read(struct bttv_core *core)
  122. {
  123. struct bttv *btv = container_of(core, struct bttv, c);
  124. u32 value;
  125. value = btread(BT848_GPIO_DATA);
  126. return value;
  127. }
  128. void bttv_gpio_write(struct bttv_core *core, u32 value)
  129. {
  130. struct bttv *btv = container_of(core, struct bttv, c);
  131. btwrite(value,BT848_GPIO_DATA);
  132. }
  133. void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
  134. {
  135. struct bttv *btv = container_of(core, struct bttv, c);
  136. unsigned long flags;
  137. u32 data;
  138. spin_lock_irqsave(&btv->gpio_lock,flags);
  139. data = btread(BT848_GPIO_DATA);
  140. data = data & ~mask;
  141. data = data | (mask & bits);
  142. btwrite(data,BT848_GPIO_DATA);
  143. spin_unlock_irqrestore(&btv->gpio_lock,flags);
  144. }
  145. /*
  146. * Local variables:
  147. * c-basic-offset: 8
  148. * End:
  149. */