/drivers/i2c/busses/i2c-acorn.c

http://github.com/mirrors/linux · C · 96 lines · 62 code · 19 blank · 15 comment · 4 complexity · e1861025dce14964e6670d6883bfb3a9 MD5 · raw file

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