···198198 return ret;
199199}
200200201201+int i2c_write_read_data(int bus_index, int bus_address,
202202+ const unsigned char* buf_write, int count_write,
203203+ unsigned char* buf_read, int count_read)
204204+{
205205+ int i;
206206+ int ret = 0;
207207+ const struct i2c_interface *iface = i2c_if[bus_index];
208208+209209+ i2c_start(iface);
210210+ if (!i2c_outb(iface, bus_address))
211211+ {
212212+ ret = -2;
213213+ goto end;
214214+ }
215215+216216+ for(i = 0;i < count_write;i++)
217217+ {
218218+ if (!i2c_outb(iface, buf_write[i]))
219219+ {
220220+ ret = -3;
221221+ goto end;
222222+ }
223223+ }
224224+225225+ for(i = 0;i < count_read-1;i++)
226226+ buf_read[i] = i2c_inb(iface, true);
227227+228228+ buf_read[i] = i2c_inb(iface, false);
229229+230230+end:
231231+ i2c_stop(iface);
232232+ return ret;
233233+}
234234+201235/* returns bus index which can be used as a handle, or <0 on error */
202236int i2c_add_node(const struct i2c_interface *iface)
203237{
+10
firmware/export/generic_i2c.h
···4949int i2c_read_data(int bus_index, int bus_address, int address,
5050 unsigned char* buf, int count);
51515252+/* Special function for devices that can appear on I2C bus but do not
5353+ * comply to I2C specification. Such devices include AT88SC6416C crypto
5454+ * memory. To read data from AT88SC6416C, a write I2C transaction starts,
5555+ * 3 bytes are written and then, in the middle of transaction, the device
5656+ * starts sending data.
5757+ */
5858+int i2c_write_read_data(int bus_index, int bus_address,
5959+ const unsigned char* buf_write, int count_write,
6060+ unsigned char* buf_read, int count_read);
6161+5262#endif /* _GEN_I2C_ */
5363
···11+/***************************************************************************
22+* __________ __ ___.
33+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+* \/ \/ \/ \/ \/
88+* $Id: $
99+*
1010+* Copyright (C) 2021 by Tomasz Moń
1111+*
1212+* This program is free software; you can redistribute it and/or
1313+* modify it under the terms of the GNU General Public License
1414+* as published by the Free Software Foundation; either version 2
1515+* of the License, or (at your option) any later version.
1616+*
1717+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818+* KIND, either express or implied.
1919+*
2020+****************************************************************************/
2121+2222+#ifndef _CRYPTOMEM_SANSACONNECT_H_
2323+#define _CRYPTOMEM_SANSACONNECT_H_
2424+2525+int cryptomem_read_deviceid(char deviceid[32]);
2626+2727+#endif /* _CRYPTOMEM_SANSACONNECT_H_ */