12

I am looking at some pointers for understanding how the Linux kernel implements the setting up of various hardware clocks. This basically relates to working with setting up the various clocks that hardware features like the LCD, UART etc will use. For example when Linux boots how does it handle setting up the clocks for UART or USB. Maybe something like a Clock manager or something.

I am basically trying to implement something similar for a different OS on a new hardware that i am working on. Any help would be really appreciated.

[Edit]
Thanks for the replies and the links. So here is what i have implemented up until now. This should give you an idea of where I'm headed.

I looked up the Hardware Reference Manual for the particular system I'm targeting and wrote some code to monitor/modify the signals/pins of the peripherals I am interested in i.e. turning them ON/OFF from the command line.Now a collection of these clocks/signals together control a peripheral.The HRM would say that if you want to turn on the UART or something then turn on such and such signals/pins. And @BjoernD yes I am using something like a mmap() function to talk to the peripherals.

The meat of my question is that I want to understand the design and implementation of a Clock/Peripheral Manager which uses the utility that I have already written. This Clock/Peripheral Manager would give me the control of enabling/disabling the peripherals I want.Basically this Manager would enable me to make changes in the init code that is right now running. Also during run time processes can call this Manager to turn ON/OFF the devices so that power consumption is optimized. It might not have made perfect sense but I'm myself trying to wrap my head around this.

Now I'm sure something like this would have been implemented in Linux or for that matter any OS for performance issues (nobody would want to waste power by turning on all peripherals at boot time). I want to understand the Software Architecture of it. Reference from any OS would do as of now to atleast get a headstart. Also I am not writing my own OS, there is an OS in place but Im looking more at a board level software aka BSP to work on. But thanks for the OS link anyways, they are really good. Appreciate it.

Thanks!

The Stig
  • 581
  • 2
  • 5
  • 15

2 Answers2

6

What you want to achieve is highly specific to a) the platform you are using and b) the device you want to use. For instance, on x86 there are 3 ways to communicate with a device:

  1. Interrupts allow the device to signal the CPU. The OS usually provides mechanisms to register interrupt handlers - functions that are called upon occurrence of an interrupt. In Linux see request_irq() and friends in linux/include/interrupt.h
  2. Memory-mapped I/O is physical memory of the device that the platform's BIOS makes available in the same way you also access plain physical memory - simply by writing to a memory address. What exactly is behind such memory (e.g., network interface config registers or an LCD frame buffer) depends on the device and is usually specified in the device's data sheet.
  3. I/O ports are accessed through a special address space and special instructions (INB/OUTB & co.). Other than that they work similar to I/O memory.

There's a multitude of ways to find out what resources a device provies and where the BIOS mapped them. Some platforms use ACPI tables (google yourself for the 1,000k page spec), PCI provides info on devices in a standardized way through the PCI config space, USB has similar ways of discovering devices attached to the bus, and some devices, e.g., UARTS, are simply specified to be available at a pre-configured I/O range that is fixed for your platform.

As a start for understanding Linux, I'd recommend "Understanding the Linux kernel". For specifics on how Linux handles devices and what is there to write drivers, have a look at Linux Device Drivers. Furthermore, you will need to have a look at the peculiarities of your platform and the device you want to drive.

If you want to start an own OS, a UART is certainly something that will be veeery helpful to print debug output, so you might want to go for this first.

Now that I wrote down all this, it seems that your actual question is: How to get started with Operating System design. This question should be highly valuable for you: What are some resources for getting started in operating system development?

Community
  • 1
  • 1
BjoernD
  • 4,720
  • 27
  • 32
  • So what I am basically trying to do is have some kind of system in place so that i can appropriately turn on the required signals/clocks for the respective h/w. – The Stig Jul 01 '11 at 21:14
  • Contd (Return key supposedly pastes the comment) So for example during boot maybe only UART might be turned on but the rest maybe off to save power.Later when LCD needs to start it can send a request to a utility/manager to turn on certain signals (these would be known from the h/w specs).So the utility will take appropriate action by setting the required bits in the control register for LCD "HIGH". – The Stig Jul 01 '11 at 21:22
  • I am sure that this has been dealt with in an organized way in the Linux kernel,its just that i don't know where to look. – The Stig Jul 01 '11 at 21:29
  • Ok, got it. This is really hardware- and device-specific. Editing my response. – BjoernD Jul 02 '11 at 01:29
  • I edited my question to add more details and answer some of the things you posted. – The Stig Jul 03 '11 at 02:36
0

The two big power users in most computers are the CPU and the disks. Both of these have capabilities for power saving in Linux. The CPU clock can be slowed down when the system is not busy, and the disk motors can be stopped when no I/O is happening. For a UART, even if you save all of the power that it uses by turning off its clock, it is still tiny compared to the others because a UART doesn't have much logic in it.

Best ways to save power are 1) more efficient power supply 2) replace rotating disk with SSD 3) Slow down the CPU and memory bus

Steve C
  • 647
  • 3
  • 6
  • And how is your answer related to the question? – BjoernD Jul 11 '11 at 15:49
  • Steve - I appreciate you mentioning the ways to save power but i am looking at more of a way to manage my peripherals efficiently to save power as I have detailed in my question. I know that dynamic CPU frequency scaling is a good option but I am not working on it as of now. And I am not just talking about UART, rather more of a manager for handling all peripherals including LCD, USB etc which i suppose you'd agree consume a lot of power. – The Stig Jul 11 '11 at 19:25