Skip to content

Commit

Permalink
Merge branch 'ir-support-v0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfvak committed Apr 14, 2021
2 parents c1e4bec + 07348f4 commit c37bb79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
9 changes: 8 additions & 1 deletion arch/arm/boot/dts/nintendo3ds.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
sc16is750: infrared@4d {
compatible = "nxp,sc16is750";
reg = <0x4d>;
clock-frequency = <18432000>;
clocks = <&irclk>;

interrupts-extended = <&gpio3 1 IRQ_TYPE_EDGE_FALLING>;

Expand Down Expand Up @@ -361,6 +361,13 @@
clock-output-names = "3ds:refclk134mhz";
};

irclk: xtal18mhz {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <18432000>;
clock-output-names = "3ds:xtal18mhz";
};

sdclk: refclk67mhz {
compatible = "fixed-factor-clock";
clocks = <&refclk>;
Expand Down
26 changes: 9 additions & 17 deletions drivers/platform/nintendo3ds/ctr_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,28 @@ static int ctr_i2c_recv(struct ctr_i2c *i2c, u8 *byte, unsigned flags)
return err;
}

static int ctr_i2c_stop(struct ctr_i2c *i2c)
{
u8 data;
return ctr_i2c_recv(i2c, &data, I2C_CNT_LAST);
}

static int ctr_i2c_select_device(struct ctr_i2c *i2c, struct i2c_msg *msg)
{
return ctr_i2c_send(i2c, i2c_8bit_addr_from_msg(msg), I2C_CNT_START);
}

static int ctr_i2c_msg_read(struct ctr_i2c *i2c, u8 *buf, int len)
static int ctr_i2c_msg_read(struct ctr_i2c *i2c, u8 *buf, int len, bool last)
{
int i;
for (i = 0; i < len; i++) {
if (ctr_i2c_recv(i2c, &buf[i], I2C_CNT_ERRACK))
unsigned flag = (last && (i==(len-1))) ? I2C_CNT_LAST : I2C_CNT_ERRACK;
if (ctr_i2c_recv(i2c, &buf[i], flag))
return i;
}

return len;
}

static int ctr_i2c_msg_write(struct ctr_i2c *i2c, u8 *buf, int len)
static int ctr_i2c_msg_write(struct ctr_i2c *i2c, u8 *buf, int len, bool last)
{
int i;

for (i = 0; i < len; i++) {
if (ctr_i2c_send(i2c, buf[i], 0))
unsigned flag = (last && (i==(len-1))) ? I2C_CNT_LAST : 0;
if (ctr_i2c_send(i2c, buf[i], flag))
return i;

if (!(ctr_i2c_read_cnt(i2c) & I2C_CNT_ERRACK)) {
Expand All @@ -130,7 +124,6 @@ static int ctr_i2c_msg_write(struct ctr_i2c *i2c, u8 *buf, int len)
return i;
}
}

return len;
}

Expand All @@ -151,10 +144,11 @@ static int ctr_i2c_master_xfer(struct i2c_adapter *adap,
ctr_i2c_select_device(i2c, msg);

if (msg->len != 0) {
bool last = i == (num-1);
if (msg->flags & I2C_M_RD) {
plen = ctr_i2c_msg_read(i2c, msg->buf, msg->len);
plen = ctr_i2c_msg_read(i2c, msg->buf, msg->len, last);
} else {
plen = ctr_i2c_msg_write(i2c, msg->buf, msg->len);
plen = ctr_i2c_msg_write(i2c, msg->buf, msg->len, last);
}

if (plen != msg->len)
Expand All @@ -164,8 +158,6 @@ static int ctr_i2c_master_xfer(struct i2c_adapter *adap,
msg++;
}

ctr_i2c_stop(i2c);

return i;
}

Expand Down

0 comments on commit c37bb79

Please sign in to comment.