The Pedigree Project  0.1
I2C.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _I2C_H
21 #define _I2C_H
22 
23 #include "pedigree/kernel/processor/MemoryRegion.h"
24 #include "pedigree/kernel/processor/types.h"
25 
26 class I2C
27 {
28  public:
29  I2C() : m_MmioBase("I2C")
30  {
31  }
32  virtual ~I2C()
33  {
34  }
35 
36  static I2C &instance(size_t n)
37  {
38  return m_Instance[n];
39  }
40 
41  void initialise(uintptr_t baseAddr);
42 
43  bool transmit(uint8_t addr, uintptr_t buffer, size_t len);
44  bool receive(uint8_t addr, uintptr_t buffer, size_t maxlen);
45 
46  bool write(uint8_t addr, uint8_t reg, uint8_t data);
47  uint8_t read(uint8_t addr, uint8_t reg);
48 
49  private:
50  static I2C m_Instance[3];
51 
52  MemoryRegion m_MmioBase;
53 
54  void waitForBus();
55 
56  enum Registers
57  {
58  I2C_REV = 0x00 / 2, // R
59  I2C_IE = 0x04 / 2, // RW
60  I2C_STAT = 0x08 / 2, // RW
61  I2C_WE = 0x0C / 2, // RW
62  I2C_SYSS = 0x10 / 2, // R
63  I2C_BUF = 0x14 / 2, // RW
64  I2C_CNT = 0x18 / 2, // RW
65  I2C_DATA = 0x1C / 2, // RW
66  I2C_SYSC = 0x20 / 2, // RW
67  I2C_CON = 0x24 / 2, // RW
68  I2C_OA0 = 0x28 / 2, // RW
69  I2C_SA = 0x2C / 2, // RW
70  I2C_PSC = 0x30 / 2, // RW
71  I2C_SCLL = 0x34 / 2, // RW
72  I2C_SCLH = 0x38 / 2, // RW
73  I2C_SYSTEST = 0x3C / 2, // RW
74  I2C_BUFSTAT = 0x40 / 2, // R
75  I2C_OA1 = 0x44 / 2, // RW
76  I2C_OA2 = 0x48 / 2, // RW
77  I2C_OA3 = 0x4C / 2, // RW
78  I2C_ACTOA = 0x50 / 2, // R
79  I2C_SBLOCK = 0x54 / 2, // RW
80  };
81 };
82 
83 #endif
Special memory entity in the kernel's virtual address space.
Definition: MemoryRegion.h:35
Definition: I2C.h:26