dev_get_platdata understanding
So I see this type of code in platform driver inside kernel,
struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
or this,
struct aat2870_platform_data *pdata = dev_get_platdata(&client->dev);
So how dev_get_platdata is helping us.
In device.h the definition here is,
static inline void *dev_get_platdata(const struct device *dev)
{
return dev->platform_data;
}
So if I see from kernel it is always done for to get platform specific data.
Like Here is a definition of platform_device, in platform_device.h
struct platform_device {
const char *name;
int id;
bool id_auto;
struct device dev; <--------------------
u32 num_resources;
struct resource *resource;
const struct platform_device_id *id_entry;
char *driver_override; /* Driver name to force a match */
/* MFD cell pointer */
struct mfd_cell *mfd_cell;
/* arch specific additions */
struct pdev_archdata archdata;
};
further struct device is,
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
const struct device_type *type;
struct mutex mutex; /* mutex to synchronize calls to
* its driver.
*/
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
void *platform_data; /* Platform specific data, device <------
core doesn't touch it */
void *driver_data; /* Driver data, set and get with
dev_set/get_drvdata */
struct dev_pm_info power;
struct dev_pm_domain *pm_domain;
#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
struct irq_domain *msi_domain;
#endif
#ifdef CONFIG_PINCTRL
struct dev_pin_info *pins;
#endif
#ifdef CONFIG_GENERIC_MSI_IRQ
struct list_head msi_list;
#endif
#ifdef CONFIG_NUMA
int numa_node; /* NUMA node this device is close to */
#endif
u64 *dma_mask; /* dma mask (if dma'able device) */
u64 coherent_dma_mask;/* Like dma_mask, but for
alloc_coherent mappings as
not all hardware supports
64 bit addresses for consistent
allocations such descriptors. */
unsigned long dma_pfn_offset;
struct device_dma_parameters *dma_parms;
struct list_head dma_pools; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
#ifdef CONFIG_DMA_CMA
struct cma *cma_area; /* contiguous memory area for dma
allocations */
#endif
/* arch specific additions */
struct dev_archdata archdata;
struct device_node *of_node; /* associated device tree node */ <------
......
......
}
Or same way in an i2c device.
So we have a platform device and inside it is a structure struct device. Using these we can get device configuration data and use it in our platform driver to configure device.
In Simple sense this is what happens,
When a match occurs,the probe function of the driver is called, with a struct platform_device structure as the parameter, which contains a struct device dev field, in which there is a field struct device_node *of_node that corresponds that corresponds to the node associated to our device, so that one can use it to extract the device settings.
More info about of_node
https://stackoverflow.com/questions/22783154/whats-of-node-parameter-in-the-struct-device
of_node is related to Open Firmware it holds the information of a device tree.
struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
or this,
struct aat2870_platform_data *pdata = dev_get_platdata(&client->dev);
So how dev_get_platdata is helping us.
In device.h the definition here is,
static inline void *dev_get_platdata(const struct device *dev)
{
return dev->platform_data;
}
So if I see from kernel it is always done for to get platform specific data.
Like Here is a definition of platform_device, in platform_device.h
struct platform_device {
const char *name;
int id;
bool id_auto;
struct device dev; <--------------------
u32 num_resources;
struct resource *resource;
const struct platform_device_id *id_entry;
char *driver_override; /* Driver name to force a match */
/* MFD cell pointer */
struct mfd_cell *mfd_cell;
/* arch specific additions */
struct pdev_archdata archdata;
};
further struct device is,
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
const struct device_type *type;
struct mutex mutex; /* mutex to synchronize calls to
* its driver.
*/
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
void *platform_data; /* Platform specific data, device <------
core doesn't touch it */
void *driver_data; /* Driver data, set and get with
dev_set/get_drvdata */
struct dev_pm_info power;
struct dev_pm_domain *pm_domain;
#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
struct irq_domain *msi_domain;
#endif
#ifdef CONFIG_PINCTRL
struct dev_pin_info *pins;
#endif
#ifdef CONFIG_GENERIC_MSI_IRQ
struct list_head msi_list;
#endif
#ifdef CONFIG_NUMA
int numa_node; /* NUMA node this device is close to */
#endif
u64 *dma_mask; /* dma mask (if dma'able device) */
u64 coherent_dma_mask;/* Like dma_mask, but for
alloc_coherent mappings as
not all hardware supports
64 bit addresses for consistent
allocations such descriptors. */
unsigned long dma_pfn_offset;
struct device_dma_parameters *dma_parms;
struct list_head dma_pools; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
#ifdef CONFIG_DMA_CMA
struct cma *cma_area; /* contiguous memory area for dma
allocations */
#endif
/* arch specific additions */
struct dev_archdata archdata;
struct device_node *of_node; /* associated device tree node */ <------
......
......
}
Or same way in an i2c device.
So we have a platform device and inside it is a structure struct device. Using these we can get device configuration data and use it in our platform driver to configure device.
In Simple sense this is what happens,
When a match occurs,the probe function of the driver is called, with a struct platform_device structure as the parameter, which contains a struct device dev field, in which there is a field struct device_node *of_node that corresponds that corresponds to the node associated to our device, so that one can use it to extract the device settings.
More info about of_node
https://stackoverflow.com/questions/22783154/whats-of-node-parameter-in-the-struct-device
of_node is related to Open Firmware it holds the information of a device tree.
Comments
Post a Comment