l3.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * L3 code
  3. *
  4. * Copyright (C) 2008, Christian Pellegrin <chripell@evolware.org>
  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. * based on:
  12. *
  13. * L3 bus algorithm module.
  14. *
  15. * Copyright (C) 2001 Russell King, All Rights Reserved.
  16. *
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <sound/l3.h>
  23. /*
  24. * Send one byte of data to the chip. Data is latched into the chip on
  25. * the rising edge of the clock.
  26. */
  27. static void sendbyte(struct l3_pins *adap, unsigned int byte)
  28. {
  29. int i;
  30. for (i = 0; i < 8; i++) {
  31. adap->setclk(0);
  32. udelay(adap->data_hold);
  33. adap->setdat(byte & 1);
  34. udelay(adap->data_setup);
  35. adap->setclk(1);
  36. udelay(adap->clock_high);
  37. byte >>= 1;
  38. }
  39. }
  40. /*
  41. * Send a set of bytes to the chip. We need to pulse the MODE line
  42. * between each byte, but never at the start nor at the end of the
  43. * transfer.
  44. */
  45. static void sendbytes(struct l3_pins *adap, const u8 *buf,
  46. int len)
  47. {
  48. int i;
  49. for (i = 0; i < len; i++) {
  50. if (i) {
  51. udelay(adap->mode_hold);
  52. adap->setmode(0);
  53. udelay(adap->mode);
  54. }
  55. adap->setmode(1);
  56. udelay(adap->mode_setup);
  57. sendbyte(adap, buf[i]);
  58. }
  59. }
  60. int l3_write(struct l3_pins *adap, u8 addr, u8 *data, int len)
  61. {
  62. adap->setclk(1);
  63. adap->setdat(1);
  64. adap->setmode(1);
  65. udelay(adap->mode);
  66. adap->setmode(0);
  67. udelay(adap->mode_setup);
  68. sendbyte(adap, addr);
  69. udelay(adap->mode_hold);
  70. sendbytes(adap, data, len);
  71. adap->setclk(1);
  72. adap->setdat(1);
  73. adap->setmode(0);
  74. return len;
  75. }
  76. EXPORT_SYMBOL_GPL(l3_write);
  77. MODULE_DESCRIPTION("L3 bit-banging driver");
  78. MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>");
  79. MODULE_LICENSE("GPL");