- 了解Linux MFD Driver
1.Multifunction Device Drivers
Multifunction devices embed several functions (e.g. GPIOs, touchscreens, keyboards, current regulators, power management chips, etc…) in one single integrated circuit. They usually talk to the main CPU through one or more IRQ lines and low speed data busses (SPI, I2C, etc…). They appear as one single device to the main system through the data bus and the MFD framework allows for sub devices (a.k.a. functions) to appear as discrete platform devices. MFDs are typically found on embedded platforms.
In Create a simple platform driver, we created simple platform device driver. If there is device which can provide multiple functionalities, its driver may not go in particular subsystems. For an example, lets say there is chip which can also work as codec & sensors, its full driver can neither go in sound/soc/codec or in sensors subsystem. In this case, MFD provides way to register multiple functionalities through MFD core.
1.1.What is a multi-function device ?
- An external peripheral or a hardware block exposing more than a single functionality
- Examples:
-
PMICs
- da9063: regulators, led controller, watchdog, rtc, temperature sensor, vibration motor driver, ON key
- max77843: regulators, charger, fuel gauge, haptic feedback, LED controller, micro USB interface controller
-
atmel-hlcdc: display controller and backlight pwm
-
- The main issue is to register those in different kernel subsystems. In particular the
external peripherals are represented by only one struct device (or the specialized i2c_client or spi_device)
1.2.MFD subsystem
- The MFD subsystem has been created to handle those devices
- Allows to register the same device in multiple subsystems
- The MFD driver has to multiplex access on the bus (mainly takes care of locking)
and handle IRQs - May handle clocks
- May also need to confgure the IP
- May do variant or functions detection
- Other beneft: allows driver reuse, multiple MFD can reuse drivers from other subsystems.
1.3.MFD APIs
For this, MFD provides way to divide functionalities into core and specific function drivers. Generic functionalities(e.g. register access, generic initialisation, common functionalities, etc), can go in mfd while device specific functionalities(e.g. codec specific functionalities) can go in their specific driver.
devm_mfd_add_devices() in core, registers MFD functionalities which populates individual function devices and invokes probe for those drivers.
Functional driver may use parent device data/DT properties if needed. MFD core can pass resources(memory or IRQ) to MFD devices while registering MFD devices.
- Defned in include/linux/mfd/core.h
- Implemented in drivers/mfd/mfd-core.c