gpio.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
  3. * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/fs.h>
  21. #include <asm/uaccess.h>
  22. #include "solo6x10.h"
  23. static void solo_gpio_mode(struct solo_dev *solo_dev,
  24. unsigned int port_mask, unsigned int mode)
  25. {
  26. int port;
  27. unsigned int ret;
  28. ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_0);
  29. /* To set gpio */
  30. for (port = 0; port < 16; port++) {
  31. if (!((1 << port) & port_mask))
  32. continue;
  33. ret &= (~(3 << (port << 1)));
  34. ret |= ((mode & 3) << (port << 1));
  35. }
  36. solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_0, ret);
  37. /* To set extended gpio - sensor */
  38. ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_1);
  39. for (port = 0; port < 16; port++) {
  40. if (!((1 << (port + 16)) & port_mask))
  41. continue;
  42. if (!mode)
  43. ret &= ~(1 << port);
  44. else
  45. ret |= 1 << port;
  46. }
  47. solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_1, ret);
  48. }
  49. static void solo_gpio_set(struct solo_dev *solo_dev, unsigned int value)
  50. {
  51. solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
  52. solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) | value);
  53. }
  54. static void solo_gpio_clear(struct solo_dev *solo_dev, unsigned int value)
  55. {
  56. solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
  57. solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) & ~value);
  58. }
  59. static void solo_gpio_config(struct solo_dev *solo_dev)
  60. {
  61. /* Video reset */
  62. solo_gpio_mode(solo_dev, 0x30, 1);
  63. solo_gpio_clear(solo_dev, 0x30);
  64. udelay(100);
  65. solo_gpio_set(solo_dev, 0x30);
  66. udelay(100);
  67. /* Warning: Don't touch the next line unless you're sure of what
  68. * you're doing: first four gpio [0-3] are used for video. */
  69. solo_gpio_mode(solo_dev, 0x0f, 2);
  70. /* We use bit 8-15 of SOLO_GPIO_CONFIG_0 for relay purposes */
  71. solo_gpio_mode(solo_dev, 0xff00, 1);
  72. /* Initially set relay status to 0 */
  73. solo_gpio_clear(solo_dev, 0xff00);
  74. }
  75. int solo_gpio_init(struct solo_dev *solo_dev)
  76. {
  77. solo_gpio_config(solo_dev);
  78. return 0;
  79. }
  80. void solo_gpio_exit(struct solo_dev *solo_dev)
  81. {
  82. solo_gpio_clear(solo_dev, 0x30);
  83. solo_gpio_config(solo_dev);
  84. }