Skip to content

Commit 01dcc60

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
new helper to create platform devices with dma mask
compared to the most powerful and already existing helper (namely platform_device_register_resndata) this allows to specify a dma_mask. To make eventual extensions later more easy, a struct holding the used information is created instead of passing the information by function parameters. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent b7565fa commit 01dcc60

2 files changed

Lines changed: 78 additions & 22 deletions

File tree

‎drivers/base/platform.c‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -375,52 +375,64 @@ void platform_device_unregister(struct platform_device *pdev)
375375
EXPORT_SYMBOL_GPL(platform_device_unregister);
376376

377377
/**
378-
* platform_device_register_resndata - add a platform-level device with
378+
* platform_device_register_full - add a platform-level device with
379379
* resources and platform-specific data
380380
*
381-
* @parent: parent device for the device we're adding
382-
* @name: base name of the device we're adding
383-
* @id: instance id
384-
* @res: set of resources that needs to be allocated for the device
385-
* @num: number of resources
386-
* @data: platform specific data for this platform device
387-
* @size: size of platform specific data
381+
* @pdevinfo: data used to create device
388382
*
389383
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
390384
*/
391-
struct platform_device *platform_device_register_resndata(
392-
struct device *parent,
393-
const char *name, int id,
394-
const struct resource *res, unsigned int num,
395-
const void *data, size_t size)
385+
struct platform_device *platform_device_register_full(
386+
struct platform_device_info *pdevinfo)
396387
{
397388
int ret = -ENOMEM;
398389
struct platform_device *pdev;
399390

400-
pdev = platform_device_alloc(name, id);
391+
pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
401392
if (!pdev)
402-
goto err;
403-
404-
pdev->dev.parent = parent;
393+
goto err_alloc;
394+
395+
pdev->dev.parent = pdevinfo->parent;
396+
397+
if (pdevinfo->dma_mask) {
398+
/*
399+
* This memory isn't freed when the device is put,
400+
* I don't have a nice idea for that though. Conceptually
401+
* dma_mask in struct device should not be a pointer.
402+
* See http://thread.gmane.org/gmane.linux.kernel.pci/9081
403+
*/
404+
pdev->dev.dma_mask =
405+
kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
406+
if (!pdev->dev.dma_mask)
407+
goto err;
408+
409+
*pdev->dev.dma_mask = pdevinfo->dma_mask;
410+
pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
411+
}
405412

406-
ret = platform_device_add_resources(pdev, res, num);
413+
ret = platform_device_add_resources(pdev,
414+
pdevinfo->res, pdevinfo->num_res);
407415
if (ret)
408416
goto err;
409417

410-
ret = platform_device_add_data(pdev, data, size);
418+
ret = platform_device_add_data(pdev,
419+
pdevinfo->data, pdevinfo->size_data);
411420
if (ret)
412421
goto err;
413422

414423
ret = platform_device_add(pdev);
415424
if (ret) {
416425
err:
426+
kfree(pdev->dev.dma_mask);
427+
428+
err_alloc:
417429
platform_device_put(pdev);
418430
return ERR_PTR(ret);
419431
}
420432

421433
return pdev;
422434
}
423-
EXPORT_SYMBOL_GPL(platform_device_register_resndata);
435+
EXPORT_SYMBOL_GPL(platform_device_register_full);
424436

425437
static int platform_drv_probe(struct device *_dev)
426438
{

‎include/linux/platform_device.h‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,54 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
4949
extern int platform_get_irq_byname(struct platform_device *, const char *);
5050
extern int platform_add_devices(struct platform_device **, int);
5151

52-
extern struct platform_device *platform_device_register_resndata(
52+
struct platform_device_info {
53+
struct device *parent;
54+
55+
const char *name;
56+
int id;
57+
58+
const struct resource *res;
59+
unsigned int num_res;
60+
61+
const void *data;
62+
size_t size_data;
63+
u64 dma_mask;
64+
};
65+
extern struct platform_device *platform_device_register_full(
66+
struct platform_device_info *pdevinfo);
67+
68+
/**
69+
* platform_device_register_resndata - add a platform-level device with
70+
* resources and platform-specific data
71+
*
72+
* @parent: parent device for the device we're adding
73+
* @name: base name of the device we're adding
74+
* @id: instance id
75+
* @res: set of resources that needs to be allocated for the device
76+
* @num: number of resources
77+
* @data: platform specific data for this platform device
78+
* @size: size of platform specific data
79+
*
80+
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
81+
*/
82+
static inline struct platform_device *platform_device_register_resndata(
5383
struct device *parent, const char *name, int id,
5484
const struct resource *res, unsigned int num,
55-
const void *data, size_t size);
85+
const void *data, size_t size) {
86+
87+
struct platform_device_info pdevinfo = {
88+
.parent = parent,
89+
.name = name,
90+
.id = id,
91+
.res = res,
92+
.num_res = num,
93+
.data = data,
94+
.size_data = size,
95+
.dma_mask = 0,
96+
};
97+
98+
return platform_device_register_full(&pdevinfo);
99+
}
56100

57101
/**
58102
* platform_device_register_simple - add a platform-level device and its resources

0 commit comments

Comments
 (0)