0

What is the best option to write/read complete configuration to the chip, if I'm using a IIO driver? With 'complete configuration' I mean a file (e.g chip_config.cfg) where are the values of all registers of that chip in some specific format.

What options do I know now:

  1. Device attribute - can be created directly from IIO framework, however it should be used only for one value. Also can read only 4096 bytes of data.
  2. Open file from kernel - kernel_read_file() and similar functions, but strictly prohibited.
  3. Firmware framework - only write.
  4. debugfs - we do not want to use this.

Thank you for every suggestion.

Juraj
  • 96
  • 4
  • https://lore.kernel.org/patchwork/patch/1216690/ – 0andriy Aug 11 '20 at 22:26
  • I know about this option but debugs is not enabled and it won't be enabled. – Juraj Aug 12 '20 at 08:39
  • Then you have several options (all **NON-standard**): **a)** extend IOCTL interface to cover your case, **b)** create a custom sysfs node which will abuse it and do what you want to, **c)** use form of file to supply configuration to the chip (this perhaps only one way solution, i.e. to the chip and not from it). And note again the **STANDARD** option is to use debugfs as shown in example in my previous comment. – 0andriy Aug 12 '20 at 09:27

1 Answers1

0

this should be done in two parts: a user space one that reads and parses the file, and a driver that reads and writes to the chip.

You can't use the firmware framework you mentioned above, i.e. write only: because you usually need to read from the device registers; to check if certain bits are set; read back values from registers you've written to; and so on.

secret squirrel
  • 802
  • 9
  • 13
  • Yes, this is another possible solution. However, I don't want the user-space program only for parsing that configuration. To understand what I mean, I have a SPI driver that communicates with, for example, ADC chip. This driver registers the Industrial IO device to access voltage values from sysfs. This chip has also some registers and I want to r/w them in one operation, like "cat config.cfg > chip_configuration" for write and "cat chip_configuration" for read. The 'chip_configuration' file should be created by my driver in sysfs directory, where are all other files created by IIO. – Juraj Aug 10 '20 at 11:28
  • its not just for parsing, but to check and report back to the user about the success or failure of writing to the chip – secret squirrel Aug 10 '20 at 11:44
  • 1
    If you want to do it all in the kernel via sysfs, you should have a look at https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt Especially the part "Mixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice." – secret squirrel Aug 10 '20 at 12:21
  • Yes, I know, but this driver is just for us and we want this functionality, when you simply send the cfg file contents to device file, the driver parses it and set registry one by one. It would be easy with char device file in /dev/, but it is already "reserved" by IIO framework. That's why I'm asking if there is some standard procedure how to do it, because I can't find anything about it on the internet (maybe I have bad keywords). Thank you. – Juraj Aug 12 '20 at 08:35
  • I think cfg80211 - a wifi driver - takes a text file of radio band allocations which it keeps in the /lib/modules directory somewhere. The path to the file is supplied to the driver via a parameter in /sys/ somewhere, like /sys/module/cfg80211/parameters (thats just from memory, so dont quote me). If thats the model your after, look at the cfg80211 driver – secret squirrel Aug 12 '20 at 08:46