But i'm not smart enough :pI didn't want to depend on the fixed layout of memory, but consider it+
+
+/* We read the entire key, using a look up table. Returned is only the
+ * requested byte. This is of course slower then it could be and uses 4 times
+ * more reads as needed but keeps code a little simpler.
+ */
+u8 sunxi_sid_read_byte(const int key)
+{
+ u32 sid_key;
+ u8 ret;
+
+ ret = 0;
+ if (likely((key <= SUNXI_SID_SIZE))) {
+ sid_key = ioread32(p->sid_base + keys_lut[key >> 2]);
+ switch (key % 4) {
+ case 0:
+ ret = (sid_key >> 24) & 0xff;
+ break;
+ case 1:
+ ret = (sid_key >> 16) & 0xff;
+ break;
+ case 2:
+ ret = (sid_key >> 8) & 0xff;
+ break;
+ case 3:
+ ret = sid_key & 0xff;
+ break;
+ }
+ }
Come on, you can do better. This lookup table is useless.
removed.
You had me confused and I was looking at this for a little while. Bit-ordering does not change, Byte endianness is a different story of course. As it is now, I decided to use Big endianess. So now a 32bit key looks like:Strangely enough, they have swapped the MSB and LSB bytes. I double
Also, why the first key is the one with the MSBs?
I'd expect that the key 0 is the one holding the LSBs.
checked it with u-boot and yep, swapped. Though in the end, if we write
stuff there and we read stuff from there, order doesn't matter? So what
do we prefer. Have it so that it makes sense and ignore how u-boot reads
it, or correct it and be consistent?