i2c.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Freescale I2C Controller
  3. *
  4. * This software may be used and distributed according to the
  5. * terms of the GNU Public License, Version 2, incorporated
  6. * herein by reference.
  7. *
  8. * Copyright 2004 Freescale Semiconductor.
  9. * (C) Copyright 2003, Motorola, Inc.
  10. * author: Eran Liberty (liberty@freescale.com)
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #ifndef _ASM_I2C_H_
  28. #define _ASM_I2C_H_
  29. #include <asm/types.h>
  30. typedef struct i2c
  31. {
  32. u8 adr; /**< I2C slave address */
  33. #define I2C_ADR 0xFE
  34. #define I2C_ADR_SHIFT 1
  35. #define I2C_ADR_RES ~(I2C_ADR)
  36. u8 res0[3];
  37. u8 fdr; /**< I2C frequency divider register */
  38. #define IC2_FDR 0x3F
  39. #define IC2_FDR_SHIFT 0
  40. #define IC2_FDR_RES ~(IC2_FDR)
  41. u8 res1[3];
  42. u8 cr; /**< I2C control redister */
  43. #define I2C_CR_MEN 0x80
  44. #define I2C_CR_MIEN 0x40
  45. #define I2C_CR_MSTA 0x20
  46. #define I2C_CR_MTX 0x10
  47. #define I2C_CR_TXAK 0x08
  48. #define I2C_CR_RSTA 0x04
  49. #define I2C_CR_BCST 0x01
  50. u8 res2[3];
  51. u8 sr; /**< I2C status register */
  52. #define I2C_SR_MCF 0x80
  53. #define I2C_SR_MAAS 0x40
  54. #define I2C_SR_MBB 0x20
  55. #define I2C_SR_MAL 0x10
  56. #define I2C_SR_BCSTM 0x08
  57. #define I2C_SR_SRW 0x04
  58. #define I2C_SR_MIF 0x02
  59. #define I2C_SR_RXAK 0x01
  60. u8 res3[3];
  61. u8 dr; /**< I2C data register */
  62. #define I2C_DR 0xFF
  63. #define I2C_DR_SHIFT 0
  64. #define I2C_DR_RES ~(I2C_DR)
  65. u8 res4[3];
  66. u8 dfsrr; /**< I2C digital filter sampling rate register */
  67. #define I2C_DFSRR 0x3F
  68. #define I2C_DFSRR_SHIFT 0
  69. #define I2C_DFSRR_RES ~(I2C_DR)
  70. u8 res5[3];
  71. u8 res6[0xE8];
  72. } i2c_t;
  73. #ifndef CFG_HZ
  74. #error CFG_HZ is not defined in /include/configs/${BOARD}.h
  75. #endif
  76. #define I2C_TIMEOUT (CFG_HZ/4)
  77. #ifndef CFG_IMMRBAR
  78. #error CFG_IMMRBAR is not defined in /include/configs/${BOARD}.h
  79. #endif
  80. #ifndef CFG_I2C_OFFSET
  81. #error CFG_I2C_OFFSET is not defined in /include/configs/${BOARD}.h
  82. #endif
  83. #ifdef CONFIG_MPC8349ADS
  84. /*
  85. * MPC8349 have two i2c bus
  86. */
  87. extern i2c_t * mpc8349_i2c;
  88. #define I2C mpc8349_i2c
  89. #else
  90. #define I2C ((i2c_t*)(CFG_IMMRBAR + CFG_I2C_OFFSET))
  91. #endif
  92. #define I2C_READ 1
  93. #define I2C_WRITE 0
  94. #endif /* _ASM_I2C_H_ */