// SPDX-License-Identifier: GPL-2.0-only /* * I2C Link Layer for ST NCI NFC controller familly based Driver * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
*/
/* * Writing a frame must not return the number of written bytes. * It must return either zero for success, or <0 for error. * In addition, it must not alter the skb
*/ staticint st_nci_i2c_write(void *phy_id, struct sk_buff *skb)
{ int r; struct st_nci_i2c_phy *phy = phy_id; struct i2c_client *client = phy->i2c_dev;
if (phy->ndlc->hard_fault != 0) return phy->ndlc->hard_fault;
r = i2c_master_send(client, skb->data, skb->len); if (r < 0) { /* Retry, chip was in standby */
usleep_range(1000, 4000);
r = i2c_master_send(client, skb->data, skb->len);
}
if (r >= 0) { if (r != skb->len)
r = -EREMOTEIO; else
r = 0;
}
return r;
}
/* * Reads an ndlc frame and returns it in a newly allocated sk_buff. * returns: * 0 : if received frame is complete * -EREMOTEIO : i2c read error (fatal) * -EBADMSG : frame was incorrect and discarded * -ENOMEM : cannot allocate skb, frame dropped
*/ staticint st_nci_i2c_read(struct st_nci_i2c_phy *phy, struct sk_buff **skb)
{ int r;
u8 len;
u8 buf[ST_NCI_I2C_MAX_SIZE]; struct i2c_client *client = phy->i2c_dev;
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE); if (r < 0) { /* Retry, chip was in standby */
usleep_range(1000, 4000);
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE);
}
if (r != ST_NCI_I2C_MIN_SIZE) return -EREMOTEIO;
len = be16_to_cpu(*(__be16 *) (buf + 2)); if (len > ST_NCI_I2C_MAX_SIZE) {
nfc_err(&client->dev, "invalid frame len\n"); return -EBADMSG;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.