confused

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I am new to this linux world, I coded some kernel drivers now but I am still a very confused...

For example... in spi/spi.c this driver is for the spi bus driver right? but these functions that are here are not "connected" to the bus driver? i mean, they are not part of the bus properties they are just in spi.[c,h]? But who should call these, every device that is in the bus?

When should one use the platform way? I made some code but i did not use it, should i change it to that? Because I actually took some ideas from those things and created some mine_platform_data to initialize some data i later use to initialize the devices data...
but then this would only be the platform driver and my actual drivers i need would need to be added?

Why do some need for example pci_platform_register instead of platform_register, it's because they need more stuff that platform_driver does not provide?

Oh i forgot i was registering it by a char driver "way"...

but the spi/spidev.c is also registering as a char driver :S

How can i "convert" my module driver to be in the kernel? put the init in my setup.c?

For example, in at32_add_device_spi: platform_device_register(pdev);
is this what triggers the spi drivers loading? so the devices come before the driver?

But i did not find many occurrences of platform_device_register in the sourcedrivers...

Well this was a lot, many things that wanted to ask i was able to figure out just by writing here, it seems it made my mind think clearly :)

Sorry for this big thing but i would appreciate any explanation or pointers to some documents that might enlighten me, thanks all :)

Evil

Oh, one more thing! since i have a pin already configured to be used as pwm, how can i change it to to be controlled by the PIO controller? i had to put in my driver a *PIOA_PER |= ( 1U<<28 ); to make it so...

EDIT: hmm so drivers can use other char drivers to implement read/write, is that it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eviltelm wrote:
Hello, I am new to this linux world, I coded some kernel drivers now but I am still a very confused...
This post is a little old but hopefully my response still helps :)

It might help to start with terminology, Linux has the concept of 'Drivers', 'Devices' and 'Busses' (and others, but that'll do for now). A driver is written to handle a device connected to a bus. For example, if you write a driver for an spi device the driver will call spi_driver_register(). When you connect the device to the bus a call should be made to spi_device_register() (usually this will be in setup.c because SPI is not a hot-plug bus). The bus logic in spi.c takes care of gluing the two halves together.

Note that the 'platform bus' is a virtual bus for permanently connected bits such as internal peripherals in a SoC. This is where platform_device_register and friends come in, they're the same as SPI, PCI etc versions but for devices that aren't on a formal, explicit bus.

Some confusion might also be coming from the fact that the SPI host driver, atmel_spi.c is a platform driver that registers as an SPI host. This is because the logic is connected to the AT32 internal bus, part of the platform bus. SPI drivers, that is those registered with spi_driver_register, are drivers for things that live on the SPI bus, not the SPI host controllers.

Quote:
Oh i forgot i was registering it by a char driver "way"...

but the spi/spidev.c is also registering as a char driver :S

Whether the driver exposes a character interface, block interface, just a bunch of sysfs nodes or any other interface doesn't depend on what kind of bus it connects to. In fact if a driver exists solely to provide functionality to other kernel code (eg the crypto drivers) then there's no need for it to expose a userspace interface at all.
Quote:
How can i "convert" my module driver to be in the kernel? put the init in my setup.c?
Don't quite get you here. Maybe you can clarify this in light of what I said above
Quote:
For example, in at32_add_device_spi: platform_device_register(pdev);
is this what triggers the spi drivers loading? so the devices come before the driver?
The SPI host driver and the SPI device drivers can register in any order. Nothing really happens between these two until a device comes along claiming to be attached to the host and driven by the SPI driver. Even then the drivers don't necessarily need to be registered before the device, the kernel can invoke userspace helpers to search for the appropriate drivers in modules, load them and get on with the task of gluing it all together.
Quote:
Oh, one more thing! since i have a pin already configured to be used as pwm, how can i change it to to be controlled by the PIO controller? i had to put in my driver a *PIOA_PER |= ( 1U<<28 ); to make it so...
I think the function is called at32_select_periph but I don't have a source tree in front of me
Quote:
EDIT: hmm so drivers can use other char drivers to implement read/write, is that it?
Well they can but generally don't. An example where they (kind of) do is the GPIO infrastructure where each driver talks only to the GPIO framework and the framework takes care of creating the userspace interface and forwarding the data through.

-S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ooh I forgot about this for a while but very much appreciated :)

Yup i think i got, but i will have to check all this stuff again when i have time, let myself dive into the kernel sources again :P

About the "convert my module to be in kernel" i meant to say changing it so that it would be loaded automatically without having to do the insmod...

About the at32_select_periph, if I recall it correctly i couldn't use that function and maybe red somewhere that it shouldn't be used outside setup.c or something like that...

Ok but imagine i have a driver of my own, i must register the device as a char (or misc if only one device since it's straightforward) if i need to perform some read or ioctl right?
But if I have some kind of input 'thingie' I register it with the linux input. But it didn't work very well last time because qtopia didn't have the linux input driver plugin so I had to work around it...

I now need to use the ngw100 (hence me visiting the forum and noticing this) so I was in my laptop with 2.3 added other usart that i needed and everything was fine but now then i formatted and got the buildroot 3.0 and the world is upside down!
There is no project_avr32... i can find the kernel sources in output/build/linux-xxx and output/toolchain/linux-xxx... but of these two places where should i go and change setup.c?

Thanks a lot for the answer and sorry not to have checked it sooner.

Appreciate any help again ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eviltelm wrote:

I now need to use the ngw100 (hence me visiting the forum and noticing this) so I was in my laptop with 2.3 added other usart that i needed and everything was fine but now then i formatted and got the buildroot 3.0 and the world is upside down!
There is no project_avr32... i can find the kernel sources in output/build/linux-xxx and output/toolchain/linux-xxx... but of these two places where should i go and change setup.c?

Hey Eviltelm!

I have the exact same issue... If you learn anything, please let me know :)

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope unfortunately I've learned nothing :/
I just use the output/build/* i think but for no real reason...

Again, any hint here is very very welcome!