简体   繁体   中英

platform device/driver vs i2c device/driver

As i am new to embedded field i am facing difficulties in understanding the clear difference between i2c device/driver and platform device/driver.

i have read this link:

What is the difference between Platform driver and normal device driver..?

which say platform devices/driver are use for not discoverable device like devices connected at i2c bus and Platform devices are bound to drivers by matching names.

I have gone through a board file, in which audio codec(non discoverable device) connected at i2c bus is registered using i2c API (i2c_register_board_info, omap_i2c_add_bus etc.), so my questions are

  1. What is difference between i2c device/driver and platform device/driver ?
  2. When to use i2c related API and when to use platform related API(platform_driver_register,platform_device_register) for registration of device/driver in kernel. or if we can use i2c related API for non discoverable device(connected on i2c) registration then where we need platform device registration.

Every SOC(Silicon on Chip) or microcontroller will have a I2C controller, which provides a way to connect and communicate to I2C devices like camera sensors, PMIC, temperature sensor etc. The driver used for configuring and using this I2C controller is called platform driver. This I2C controller is called platform device. Mostly platform devices will be part of the SOC. The registers of the I2C controller are programmed using platform driver. These registers are in say ARM memory mapped and will be available on TRM of the SOC.

Now all the I2C devices that can be connected to the SOC or microcontroller via I2C controller like Camera sensors, PMIC, temperature sensor etc need a driver to control them. This driver is called device driver. The registers of these devices are not part of memory map of SOC. Need the datasheet of the I2C device like OV5640 Camera Sensor to program the registers. I2C data are sent out to program the registers and access data.

The official link for platform drivers can be found here LWN .

Platform devices are inherently not discoverable, ie the hardware cannot say "Hey! I'm present!" to the software. Typical examples are i2c devices, kernel/Documentation/i2c/instantiating-devicesstates:Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level (at run time). Instead, the software must know (at compile time) which devices are connected on each I2C bus segment. So USB and PCI are not platform devices.

  1. Platform devices are bound to drivers by matching names,
  2. Platform devices should be registered very early during system boot. Because they are often critical to the rest of the system (platform) and its drivers.

So basically, the question "is it a platform device or a standard device?" is more a question of which bus it uses. To work with a particular platform device, you have to:

  1. register a platform driver that will manage this device. It should define a unique name,
  2. register your platform device, defining the same name as the driver.

Are platform drivers for those devices that are on chip? Not true (in theory, but true in practice). i2c devices are not onChip, but are platform devices because they are not discoverable. Also we can think of onChip devices which are normal devices. Example: an integrated PCI GPU chip on a modern x86 processor. It is discoverable, thus not a platform device.

Are normal device drivers for those that are interfaced to the processor chip? Before coming across one i2c driver ?? Not true. Many normal devices are interfaced to the processor, but not through an i2c bus. Example: a USB mouse.

  1. What is difference between i2c device/driver and platform device/driver ?
  • i2c device driver API is used to control the i2c peripheral from the i2c client driver like audio-codec

  • platform device driver API are used by non-discoverable devices say audio-codec to get the hardware related configuration via device tree or board file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM