mirror of
https://github.com/CTCaer/hekate.git
synced 2024-11-26 19:52:11 +00:00
i2c: Update drivers
Adds support for 8 byte transfers needed by touch driver changes.
This commit is contained in:
parent
9697067466
commit
144d6fd3f6
4 changed files with 44 additions and 9 deletions
|
@ -19,7 +19,7 @@
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
|
|
||||||
static u32 i2c_addrs[] = {
|
static const u32 i2c_addrs[] = {
|
||||||
0x7000C000, 0x7000C400, 0x7000C500,
|
0x7000C000, 0x7000C400, 0x7000C500,
|
||||||
0x7000C700, 0x7000D000, 0x7000D100
|
0x7000C700, 0x7000D000, 0x7000D100
|
||||||
};
|
};
|
||||||
|
@ -121,6 +121,11 @@ int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size)
|
||||||
return _i2c_send_pkt(idx, x, tmp, size + 1);
|
return _i2c_send_pkt(idx, x, tmp, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i2c_recv_buf(u8 *buf, u32 size, u32 idx, u32 x)
|
||||||
|
{
|
||||||
|
return _i2c_recv_pkt(idx, buf, size, x);
|
||||||
|
}
|
||||||
|
|
||||||
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y)
|
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y)
|
||||||
{
|
{
|
||||||
int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1);
|
int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1);
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
void i2c_init(u32 idx);
|
void i2c_init(u32 idx);
|
||||||
int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size);
|
int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size);
|
||||||
|
int i2c_recv_buf(u8 *buf, u32 size, u32 idx, u32 x);
|
||||||
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y);
|
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y);
|
||||||
int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b);
|
int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b);
|
||||||
u8 i2c_recv_byte(u32 idx, u32 x, u32 y);
|
u8 i2c_recv_byte(u32 idx, u32 x, u32 y);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
|
|
||||||
static u32 i2c_addrs[] = {
|
static const u32 i2c_addrs[] = {
|
||||||
0x7000C000, 0x7000C400, 0x7000C500,
|
0x7000C000, 0x7000C400, 0x7000C500,
|
||||||
0x7000C700, 0x7000D000, 0x7000D100
|
0x7000C700, 0x7000D000, 0x7000D100
|
||||||
};
|
};
|
||||||
|
@ -37,21 +37,39 @@ static void _i2c_wait(vu32 *base)
|
||||||
|
|
||||||
static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size)
|
static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size)
|
||||||
{
|
{
|
||||||
if (size > 4)
|
if (size > 8)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u32 tmp = 0;
|
u32 tmp = 0;
|
||||||
memcpy(&tmp, buf, size);
|
|
||||||
|
|
||||||
vu32 *base = (vu32 *)i2c_addrs[idx];
|
vu32 *base = (vu32 *)i2c_addrs[idx];
|
||||||
base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode).
|
base[I2C_CMD_ADDR0] = x << 1; //Set x (send mode).
|
||||||
|
|
||||||
|
if (size > 4)
|
||||||
|
{
|
||||||
|
memcpy(&tmp, buf, 4);
|
||||||
base[I2C_CMD_DATA1] = tmp; //Set value.
|
base[I2C_CMD_DATA1] = tmp; //Set value.
|
||||||
|
tmp = 0;
|
||||||
|
memcpy(&tmp, buf + 4, size - 4);
|
||||||
|
base[I2C_CMD_DATA2] = tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(&tmp, buf, size);
|
||||||
|
base[I2C_CMD_DATA1] = tmp; //Set value.
|
||||||
|
}
|
||||||
|
|
||||||
base[I2C_CNFG] = ((size - 1) << 1) | 0x2800; //Set size and send mode.
|
base[I2C_CNFG] = ((size - 1) << 1) | 0x2800; //Set size and send mode.
|
||||||
_i2c_wait(base); //Kick transaction.
|
_i2c_wait(base); //Kick transaction.
|
||||||
|
|
||||||
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;
|
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;
|
||||||
|
|
||||||
|
u32 timeout = get_tmr_ms() + 1500;
|
||||||
while (base[I2C_STATUS] & 0x100)
|
while (base[I2C_STATUS] & 0x100)
|
||||||
;
|
{
|
||||||
|
if (get_tmr_ms() > timeout)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (base[I2C_STATUS] << 28)
|
if (base[I2C_STATUS] << 28)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -70,8 +88,13 @@ static int _i2c_recv_pkt(u32 idx, u8 *buf, u32 size, u32 x)
|
||||||
_i2c_wait(base); // Kick transaction.
|
_i2c_wait(base); // Kick transaction.
|
||||||
|
|
||||||
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;
|
base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFFDFF) | 0x200;
|
||||||
|
|
||||||
|
u32 timeout = get_tmr_ms() + 1500;
|
||||||
while (base[I2C_STATUS] & 0x100)
|
while (base[I2C_STATUS] & 0x100)
|
||||||
;
|
{
|
||||||
|
if (get_tmr_ms() > timeout)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (base[I2C_STATUS] << 28)
|
if (base[I2C_STATUS] << 28)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -112,7 +135,7 @@ int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size)
|
||||||
{
|
{
|
||||||
u8 tmp[4];
|
u8 tmp[4];
|
||||||
|
|
||||||
if (size > 3)
|
if (size > 7)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
tmp[0] = y;
|
tmp[0] = y;
|
||||||
|
@ -121,6 +144,11 @@ int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size)
|
||||||
return _i2c_send_pkt(idx, x, tmp, size + 1);
|
return _i2c_send_pkt(idx, x, tmp, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i2c_recv_buf(u8 *buf, u32 size, u32 idx, u32 x)
|
||||||
|
{
|
||||||
|
return _i2c_recv_pkt(idx, buf, size, x);
|
||||||
|
}
|
||||||
|
|
||||||
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y)
|
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y)
|
||||||
{
|
{
|
||||||
int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1);
|
int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1);
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
void i2c_init(u32 idx);
|
void i2c_init(u32 idx);
|
||||||
int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size);
|
int i2c_send_buf_small(u32 idx, u32 x, u32 y, u8 *buf, u32 size);
|
||||||
|
int i2c_recv_buf(u8 *buf, u32 size, u32 idx, u32 x);
|
||||||
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y);
|
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y);
|
||||||
int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b);
|
int i2c_send_byte(u32 idx, u32 x, u32 y, u8 b);
|
||||||
u8 i2c_recv_byte(u32 idx, u32 x, u32 y);
|
u8 i2c_recv_byte(u32 idx, u32 x, u32 y);
|
||||||
|
|
Loading…
Reference in a new issue