Wednesday, July 25, 2012

Android | Linux "Sysfs" interface in kernel [Xperia X10]

Before reading this, make sure you have read this post and this one.
Sysfs is a virtual file system provided by the linux kernel. It is exports information about devices and drivers, and is also used for configuration. We used this in previous post to set scaling_governor and scaling_max_freq. All those files are part of Sysfs interface. This post will outline on creating a new file in the same old cpufreq folder to display all possible frequencies that the cpu can run on. This was done on Xperia X10, and I have good reasons to believe that The interface files are created from the source in /drivers folder of the /kernel. This particular one we are searching for must be in /cpufreq. Inside the folder we find the source files. Open up cpufreq.c. 



Go to that part of the code that says sysfs interface. And find suitable place to create our file. As you can see I found mine.



Now that you have added a function to display the frequencies. Its time to create the file in the interface that would display them


They can be created by adding a line to the descriptors that create a file. Just add

define_one_ro(scaling_available_frequencies);


We need to add a line to the attributes structure also. Add

&scaling_available_frequencies.attr,


to the lines.


Now the driver file is ready. But if you have observed, we have made use of an external function by name


acpuclock_get_available_frequencies_str


This is not defined in acpuclock file. So we need to head over to the file


../kernel/arch/arm/mach-msm/acpuclock-8x50.c


and add this function to output the value of frequencies as a string buffer.


The function plainly alters the string in *buf to hold the values of the frequencies. This completes the work. Now compile the kernel and load it to the phone, and discover your own new interface that shows all the possible frequency values.


No comments:

Post a Comment