2

I have gone through some driver implementation in Linux Kernel Source and can see that these are the platform driver.

drivers/net/ethernet/smsc/smsc911x.c

  static struct platform_driver smc911x_driver = {
    .probe           = smc911x_drv_probe,
    .remove  = smc911x_drv_remove,
    .suspend         = smc911x_drv_suspend,
    .resume  = smc911x_drv_resume,
    .driver  = {
            .name    = CARDNAME,
            .owner  = THIS_MODULE,
    },
};

Above is a driver for platform device(smsc based Ethernet controller) and platform devices are devices which are not probed automatically during system boot-up unlike legacy devices sitting on the pci bus.

I guess this understanding of mine is OK here?

Now when I say it is the platform devices, is it mean these devices(Ethernet Controller) are sitting on Platform bus and on ARM architecture default platform bus is AMBA.

So when we solder the Ethernet controller on ARM based board it should be sit on or interfaced with AMBA bus?

How Do we decide that driver we're going to write is Platform driver or Normal driver?

Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199
  • 1
    See [this closed question](http://stackoverflow.com/questions/14972584/how-can-the-linux-kernel-determine-which-driver-a-device-is-going-to-use), where I answered this. You must add a `platform_register_device()` to your machine file. See: [platform driver documenation](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-model/platform.txt) for instance. If there is no bus that will *probe* the hardware, then you must use a platform device. – artless noise May 26 '14 at 02:01
  • OK, @artless have gone through closed question which you have answered and have some doubts after it.Platform devices are not associated with any bus but are associated with platform bus?What are the platform bus?Also when you say platform devices are integrated with CPU ,is it mean platform devices are on same black chip where cpu is and not on same green die? – Amit Singh Tomar May 26 '14 at 11:43
  • Read [driver model overview](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-model/overview.txt). A typical PC (Linux heritage) has a PCI bus; many Linux drivers are for PCI cards. – artless noise May 26 '14 at 16:00
  • *platform bus* is a synthetic bus; Ie, the Linux driver model wants each device to be connected to a bus. The *plaform bus* is for when there is no supported bus. From the documentation *What they usually have in common is direct addressing from a CPU bus.*, which is what your AMBA device is. Compare to a PCI, USB, SPI, I2C, etc bus where there is a common BUS that connect the chip to the CPU. Do you mean green **board**? You can't answer like that. An Ethernet MII is a BUS, but it is not a topology supported by Linux. Ie, you can have extra chips. You can't look at a board and tell. – artless noise May 26 '14 at 16:38
  • Thanks @artlessnoise,I think I got your point or may be not .Let me just place my understanding before you, platform devices are the one which directly connects to CPU chip without buses like PCI, USB,SPI,I2C and just like AMBA devices Platform devices have direct addressing from CPU bus(To be honest I didn't get this point).Is it like platform device's register are accessible over links like xio or MII? – Amit Singh Tomar May 26 '14 at 17:40
  • The AMBA BUS is no BUS to Linux. It is called a BUS by ARM. You are making the two the same, but they are not. Just like the MII is not a *Linux BUS*, but is a BUS. This is like the word *controller*; it is very generic and can be in many places. Read [driver model overview](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-model/overview.txt) again. A Linux BUS must have ways to `probe`. This first started with PCMCIA and the *CIS* (card information services). Now, a standard for *extensible buses* but not for silicon verilog components like amba – artless noise May 26 '14 at 18:28
  • I guess some one may argue [MCA](http://en.wikipedia.org/wiki/Micro_Channel_architecture) was first to have *plug-and-play* support for PCs. – artless noise May 26 '14 at 18:33
  • As tangr's answered, there are *prime cell* drivers; but they are [rather limited](http://lxr.free-electrons.com/ident?i=amba_driver) in number. Many systems use an AMBA/AXI bus, but they do not dynamically ID the devices. Typically they are setup by a machine file and/or device tree and are platform drivers. There are 100-1000s of ARM AMBA platform drivers. – artless noise May 26 '14 at 21:18
  • Thanks @artlessnoise.Could not ask better explanation than this but the only doubt have is how a platform device(Device sitting on i2c and spi can be platform device, so platform devices other than i2c and spi) is connected to CPU physically?Also would you let me know what it mean by direct addressing from a CPU BUS? – Amit Singh Tomar May 27 '14 at 14:25
  • I'm not sure how you got the idea that devices sitting on i2c and SPI are 'platform' devices. I'm sure you would write the driver as being on top those respective buses. – tangrs May 28 '14 at 01:07
  • For example, the driver `synaptics_i2c` driver uses `i2c_driver` and `i2c_device_id` structures instead of the platform drivers. – tangrs May 28 '14 at 01:10
  • @tangrs I followed this post on SO where it is mentioned that devices sitting on i2c and SPI are platform devices. http://stackoverflow.com/questions/15610570/what-is-the-difference-between-platform-driver-and-normal-device-driver – Amit Singh Tomar May 28 '14 at 04:08
  • @tangrs I think I got your point.Driver for i2c controller is based on platform driver(it could be AMBA bus based as well drivers/i2c/busses/i2c-nomadik.c) using platform_driver structure where as devices sitting on i2c buses will use i2c_driver structure. – Amit Singh Tomar May 28 '14 at 07:27
  • @AmitSinghTomar, that sounds right. The i2c controller is a platform device that provides a 'bridge' into a i2c bus. All i2c devices can run on top of the i2c bus which i2c controller driver provides. – tangrs May 28 '14 at 09:35

1 Answers1

2

From my limited experience in developing ARM platform drivers, AMBA devices typically have identification registers at the end of their memory mapped IO register interface.

Generally speaking, if you look at the reference manual for your ethernet controller and register summary specifies peripheral/component identification registers (usually at offsets 0xFE0-0xFEC and 0xFF0-0xFFC), you should write an AMBA bus driver. These drivers can be identified automatically by the bus driver.

Otherwise, if the register interface doesn't specify any ID registers at offsets 0xFE0-0xFEC and 0xFF0-0xFFC, you'll probably just want to write a platform driver. These devices cannot be automatically identified and you need to specifically attach a driver to the device.

tangrs
  • 9,709
  • 1
  • 38
  • 53
  • Thanks @tangrs for the answer.It would be great if you can provide some example where reference manual of any controller having identification registers and AMBA bus driver code. – Amit Singh Tomar May 26 '14 at 04:18
  • The [PL110](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0161e/index.html) is a good example. [Corresponding driver code](http://lxr.free-electrons.com/source/drivers/video/amba-clcd.c). Notice how the device is bound to the driver by IDs specified in `clcdfb_id_table` instead of a driver name. – tangrs May 26 '14 at 06:37
  • OK ,I see PL110 is AMBA bus driver code(PL110 is sitting on AMBA bus).For LAN91C111 ethernet controller(http://www.microchip.com/wwwproducts/Devices.aspx?product=LAN91C111),I couldn't find any ID register so do we need to write platform driver?Also on which bus LAN91C11 controller would sit? – Amit Singh Tomar May 26 '14 at 07:40
  • Also ,I have gone through one of the post here on SO where some one said ""All the Buses which do not have discoverable property like ID line will be based platform bus framework" eg. I2C has only clock and data so is based on platform bus".Are you agree to it? – Amit Singh Tomar May 26 '14 at 08:16
  • 1
    Sounds about right. The platform bus isn't really a real bus. It's basically a catch-all for devices on a SoC that aren't on the other buses. – tangrs May 26 '14 at 09:52
  • 1
    @AmitSinghTomar `i2c` has a generic command to list all attached ids. This is used by the bus controller to probe the devices online. Another alternative is a *map* of connected devices is sent as an argument to the controller; *spi* drivers use this mechanism. It is much like the *platform devices*. – artless noise May 26 '14 at 18:35
  • @tangrs, I am just looking at this Diagram and trying to map it to your answer ,In this Diagram UART device is sitting on AMBA bus and if this UART device has peripheral/component identification registers then we need to wrire AMBA driver other wise we need to write platform driver for uart device .Please confirm on this understanding. – Amit Singh Tomar May 27 '14 at 14:37
  • http://electronicdesign.com/site-files/electronicdesign.com/files/archive/electronicdesign.com/files/29/4165/figure_01.gif – Amit Singh Tomar May 27 '14 at 14:39
  • Yes, that sounds about right. Though, have a look in the Linux source code; it's likely a driver for your UART device already exists so you can see whether it's implemented as a platform driver or a AMBA driver. – tangrs May 28 '14 at 01:04
  • @tangrs One final thing would like to ask to get my understanding going.I have gone through the drivers/i2c/busses/i2c-nomadik.c code which is based on AMBA driver ,so as per your answer i2c controller should have peripheral/component identification registers but I couldn't find the same Identification register .In source code from line 30 to 93 there are many register provided but which one is the peripheral/component identification registers? – Amit Singh Tomar May 28 '14 at 10:10
  • The driver itself doesn't do anything with the identification registers since it's not in charge of probing devices on the bus. It does, however, specify which IDs the driver should be bound to on [lines 1134-1146](http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-nomadik.c#L1134). – tangrs May 28 '14 at 10:13
  • Ok @tangrs. It is i2c bus driver and i2c client driver would only do device probing.Are these ID's related to identification registers?Do I have to look into reference manual to find the component identification registers ? – Amit Singh Tomar May 28 '14 at 10:27
  • Which IDs do you mean? – tangrs May 28 '14 at 12:17
  • I mean the ID's you mentioned in your comment "specify which IDs the driver should be bound to on lines 1134-1146".My only confusion is i2c controller should have Identification register ,where do I find these in order to tell that it would AMBA bus driver. – Amit Singh Tomar May 28 '14 at 13:29
  • It should be in the documentation for your part. – tangrs May 29 '14 at 00:45