i2c-acorn.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/init.h>
  16. #include <linux/i2c.h>
  17. #include <linux/i2c-algo-bit.h>
  18. #include <mach/hardware.h>
  19. #include <asm/io.h>
  20. #include <asm/hardware/ioc.h>
  21. #include <asm/system.h>
  22. #define FORCE_ONES 0xdc
  23. #define SCL 0x02
  24. #define SDA 0x01
  25. /*
  26. * We must preserve all non-i2c output bits in IOC_CONTROL.
  27. * Note also that we need to preserve the value of SCL and
  28. * SDA outputs as well (which may be different from the
  29. * values read back from IOC_CONTROL).
  30. */
  31. static u_int force_ones;
  32. static void ioc_setscl(void *data, int state)
  33. {
  34. u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
  35. u_int ones = force_ones;
  36. if (state)
  37. ones |= SCL;
  38. else
  39. ones &= ~SCL;
  40. force_ones = ones;
  41. ioc_writeb(ioc_control | ones, IOC_CONTROL);
  42. }
  43. static void ioc_setsda(void *data, int state)
  44. {
  45. u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
  46. u_int ones = force_ones;
  47. if (state)
  48. ones |= SDA;
  49. else
  50. ones &= ~SDA;
  51. force_ones = ones;
  52. ioc_writeb(ioc_control | ones, IOC_CONTROL);
  53. }
  54. static int ioc_getscl(void *data)
  55. {
  56. return (ioc_readb(IOC_CONTROL) & SCL) != 0;
  57. }
  58. static int ioc_getsda(void *data)
  59. {
  60. return (ioc_readb(IOC_CONTROL) & SDA) != 0;
  61. }
  62. static struct i2c_algo_bit_data ioc_data = {
  63. .setsda = ioc_setsda,
  64. .setscl = ioc_setscl,
  65. .getsda = ioc_getsda,
  66. .getscl = ioc_getscl,
  67. .udelay = 80,
  68. .timeout = 100
  69. };
  70. static struct i2c_adapter ioc_ops = {
  71. .id = I2C_HW_B_IOC,
  72. .algo_data = &ioc_data,
  73. };
  74. static int __init i2c_ioc_init(void)
  75. {
  76. force_ones = FORCE_ONES | SCL | SDA;
  77. return i2c_bit_add_bus(&ioc_ops);
  78. }
  79. module_init(i2c_ioc_init);