Skip to content

Commit fe891a0

Browse files
dilingerSamuel Ortiz
authored andcommitted
mfd-core: Unconditionally add mfd_cell to every platform_device
Previously, one would set the mfd_cell's platform_data/data_size to point to the current mfd_cell in order to pass that information along to drivers. This causes the current mfd_cell to always be available to drivers. It also adds a wrapper function for fetching the mfd cell from a platform device, similar to what originally existed for mfd devices. Drivers who previously used platform_data for other purposes can still use it; the difference is that mfd_get_data() must be used to access it (and the pdata structure is no longer allocated in mfd_add_devices). Note that mfd_get_data is intentionally vague (in name) about where the data is stored; variable name changes can come later without having to touch brazillions of drivers. Signed-off-by: Andres Salomon <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 2798e22 commit fe891a0

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

drivers/mfd/mfd-core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ static int mfd_add_device(struct device *parent, int id,
3939
pdev->dev.parent = parent;
4040
platform_set_drvdata(pdev, cell->driver_data);
4141

42-
if (cell->data_size) {
43-
ret = platform_device_add_data(pdev,
44-
cell->platform_data, cell->data_size);
45-
if (ret)
46-
goto fail_res;
47-
}
42+
ret = platform_device_add_data(pdev, cell, sizeof(*cell));
43+
if (ret)
44+
goto fail_res;
4845

4946
for (r = 0; r < cell->num_resources; r++) {
5047
res[r].name = cell->resources[r].name;

include/linux/mfd/core.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ struct mfd_cell {
3333
/* driver-specific data for MFD-aware "cell" drivers */
3434
void *driver_data;
3535

36-
/* platform_data can be used to either pass data to "generic"
37-
driver or as a hook to mfd_cell for the "cell" drivers */
36+
/* platform_data can be used to pass data to "generic" drivers */
3837
void *platform_data;
38+
39+
/* unused */
3940
size_t data_size;
4041

4142
/*
@@ -55,6 +56,24 @@ struct mfd_cell {
5556
bool pm_runtime_no_callbacks;
5657
};
5758

59+
/*
60+
* Given a platform device that's been created by mfd_add_devices(), fetch
61+
* the mfd_cell that created it.
62+
*/
63+
static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
64+
{
65+
return pdev->dev.platform_data;
66+
}
67+
68+
/*
69+
* Given a platform device that's been created by mfd_add_devices(), fetch
70+
* the .platform_data entry from the mfd_cell that created it.
71+
*/
72+
static inline void *mfd_get_data(struct platform_device *pdev)
73+
{
74+
return mfd_get_cell(pdev)->platform_data;
75+
}
76+
5877
extern int mfd_add_devices(struct device *parent, int id,
5978
const struct mfd_cell *cells, int n_devs,
6079
struct resource *mem_base,

0 commit comments

Comments
 (0)