i2c-acorn.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * linux/drivers/acorn/char/i2c.c
  3. *
  4. * Copyright (C) 2000 Russell King
  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. * ARM IOC/IOMD i2c driver.
  11. *
  12. * On Acorn machines, the following i2c devices are on the bus:
  13. * - PCF8583 real time clock & static RAM
  14. */
  15. #include <linux/module.h>
  16. #include <linux/i2c.h>
  17. #include <linux/i2c-algo-bit.h>
  18. #include <linux/io.h>
  19. #include <mach/hardware.h>
  20. #include <asm/hardware/ioc.h>
  21. #define FORCE_ONES 0xdc
  22. #define SCL 0x02
  23. #define SDA 0x01
  24. /*
  25. * We must preserve all non-i2c output bits in IOC_CONTROL.
  26. * Note also that we need to preserve the value of SCL and
  27. * SDA outputs as well (which may be different from the
  28. * values read back from IOC_CONTROL).
  29. */
  30. static u_int force_ones;
  31. static void ioc_setscl(void *data, int state)
  32. {
  33. u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
  34. u_int ones = force_ones;
  35. if (state)
  36. ones |= SCL;
  37. else
  38. ones &= ~SCL;
  39. force_ones = ones;
  40. ioc_writeb(ioc_control | ones, IOC_CONTROL);
  41. }
  42. static void ioc_setsda(void *data, int state)
  43. {
  44. u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
  45. u_int ones = force_ones;
  46. if (state)
  47. ones |= SDA;
  48. else
  49. ones &= ~SDA;
  50. force_ones = ones;
  51. ioc_writeb(ioc_control | ones, IOC_CONTROL);
  52. }
  53. static int ioc_getscl(void *data)
  54. {
  55. return (ioc_readb(IOC_CONTROL) & SCL) != 0;
  56. }
  57. static int ioc_getsda(void *data)
  58. {
  59. return (ioc_readb(IOC_CONTROL) & SDA) != 0;
  60. }
  61. static struct i2c_algo_bit_data ioc_data = {
  62. .setsda = ioc_setsda,
  63. .setscl = ioc_setscl,
  64. .getsda = ioc_getsda,
  65. .getscl = ioc_getscl,
  66. .udelay = 80,
  67. .timeout = HZ,
  68. };
  69. static struct i2c_adapter ioc_ops = {
  70. .nr = 0,
  71. .algo_data = &ioc_data,
  72. };
  73. static int __init i2c_ioc_init(void)
  74. {
  75. force_ones = FORCE_ONES | SCL | SDA;
  76. return i2c_bit_add_numbered_bus(&ioc_ops);
  77. }
  78. module_init(i2c_ioc_init);