i80321_i2c.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* $OpenBSD: i80321_i2c.c,v 1.3 2009/03/27 16:02:41 oga Exp $ */
  2. /* $NetBSD: i80321_i2c.c,v 1.2 2005/12/11 12:16:51 christos Exp $ */
  3. /*
  4. * Copyright (c) 2003 Wasabi Systems, Inc.
  5. * All rights reserved.
  6. *
  7. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed for the NetBSD Project by
  20. * Wasabi Systems, Inc.
  21. * 4. The name of Wasabi Systems, Inc. may not be used to endorse
  22. * or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
  29. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /*
  38. * Intel i80321 I/O Processor I2C Controller Unit support.
  39. */
  40. #include <sys/param.h>
  41. #include <sys/rwlock.h>
  42. #include <sys/systm.h>
  43. #include <sys/device.h>
  44. #include <sys/kernel.h>
  45. #include <machine/bus.h>
  46. #include <machine/intr.h>
  47. #include <arm/xscale/i80321reg.h>
  48. #include <arm/xscale/i80321var.h>
  49. #include <dev/i2c/i2cvar.h>
  50. #include <arm/xscale/iopi2creg.h>
  51. #include <arm/xscale/iopi2cvar.h>
  52. int i80321_i2c_match(struct device *parent, void *v, void *aux);
  53. void i80321_i2c_attach(struct device *parent, struct device *self, void *aux);
  54. struct cfattach i80321_i2c_ca = {
  55. sizeof(struct iopiic_softc), i80321_i2c_match, i80321_i2c_attach
  56. };
  57. int
  58. i80321_i2c_match(struct device *parent, void *v, void *aux)
  59. {
  60. struct cfdata *cf = v;
  61. struct iopxs_attach_args *ia = aux;
  62. /* XXX thecus will reboot if iopiic1 attaches */
  63. if (ia->ia_offset == VERDE_I2C_BASE1)
  64. return 0;
  65. if (strcmp(cf->cf_driver->cd_name, ia->ia_name) == 0)
  66. return (1);
  67. return (0);
  68. }
  69. void
  70. i80321_i2c_attach(struct device *parent, struct device *self, void *aux)
  71. {
  72. struct iopiic_softc *sc = (void *) self;
  73. struct iopxs_attach_args *ia = aux;
  74. int error;
  75. #ifdef LATER
  76. uint8_t gpio_bits;
  77. #endif
  78. printf(": I2C controller\n");
  79. sc->sc_st = ia->ia_st;
  80. if ((error = bus_space_subregion(sc->sc_st, ia->ia_sh,
  81. ia->ia_offset, ia->ia_size,
  82. &sc->sc_sh)) != 0) {
  83. printf("%s: unable to subregion registers, error = %d\n",
  84. sc->sc_dev.dv_xname, error);
  85. return;
  86. }
  87. #ifdef LATER
  88. gpio_bits = (ia->ia_offset == VERDE_I2C_BASE0) ?
  89. (1U << 7) | (1U << 6) : (1U << 5) | (1U << 4);
  90. i80321_gpio_set_val(gpio_bits, 0);
  91. i80321_gpio_set_direction(gpio_bits, 0);
  92. #endif
  93. /* XXX Reset the I2C unit? */
  94. rw_init(&sc->sc_buslock, "iopiiclk");
  95. /* XXX We don't currently use interrupts. Fix this some day. */
  96. #if 0
  97. sc->sc_ih = i80321_intr_establish((ia->ia_offset == VERDE_I2C_BASE0) ?
  98. ICU_INT_I2C0 : ICU_INT_I2C1, IPL_BIO, iopiic_intr, sc);
  99. if (sc->sc_ih == NULL) {
  100. aprint_error("%s: unable to establish interrupt handler\n",
  101. sc->sc_dev.dv_xname);
  102. return;
  103. }
  104. #endif
  105. /*
  106. * Enable the I2C unit as a master.
  107. * No, we do not support slave mode.
  108. */
  109. sc->sc_icr = IIC_ICR_GCD | IIC_ICR_UE | IIC_ICR_SCLE;
  110. bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ICR, 0);
  111. bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ISAR, 0);
  112. bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ICR, sc->sc_icr);
  113. iopiic_attach(sc);
  114. }