Skip to content

Commit bf95efd

Browse files
bigguinessDavid Woodhouse
authored and
David Woodhouse
committed
mtd: plat_nand: add platform probe/remove callbacks
Add optional probe and remove callbacks to the plat_nand driver. Some platforms may require additional setup, such as configuring the memory controller, before the nand device can be accessed. This patch provides an optional callback to handle this setup as well as a callback to teardown the setup. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Tested-by: Alexander Clouter <alex@digriz.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 4d96482 commit bf95efd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

drivers/mtd/nand/plat_nand.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
7272

7373
platform_set_drvdata(pdev, data);
7474

75+
/* Handle any platform specific setup */
76+
if (pdata->ctrl.probe) {
77+
res = pdata->ctrl.probe(pdev);
78+
if (res)
79+
goto out;
80+
}
81+
7582
/* Scan to find existance of the device */
7683
if (nand_scan(&data->mtd, 1)) {
7784
res = -ENXIO;
@@ -101,6 +108,8 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
101108

102109
nand_release(&data->mtd);
103110
out:
111+
if (pdata->ctrl.remove)
112+
pdata->ctrl.remove(pdev);
104113
platform_set_drvdata(pdev, NULL);
105114
iounmap(data->io_base);
106115
kfree(data);
@@ -113,15 +122,15 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
113122
static int __devexit plat_nand_remove(struct platform_device *pdev)
114123
{
115124
struct plat_nand_data *data = platform_get_drvdata(pdev);
116-
#ifdef CONFIG_MTD_PARTITIONS
117125
struct platform_nand_data *pdata = pdev->dev.platform_data;
118-
#endif
119126

120127
nand_release(&data->mtd);
121128
#ifdef CONFIG_MTD_PARTITIONS
122129
if (data->parts && data->parts != pdata->chip.partitions)
123130
kfree(data->parts);
124131
#endif
132+
if (pdata->ctrl.remove)
133+
pdata->ctrl.remove(pdev);
125134
iounmap(data->io_base);
126135
kfree(data);
127136

include/linux/mtd/nand.h

+7
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,13 @@ struct platform_nand_chip {
577577
void *priv;
578578
};
579579

580+
/* Keep gcc happy */
581+
struct platform_device;
582+
580583
/**
581584
* struct platform_nand_ctrl - controller level device structure
585+
* @probe: platform specific function to probe/setup hardware
586+
* @remove: platform specific function to remove/teardown hardware
582587
* @hwcontrol: platform specific hardware control structure
583588
* @dev_ready: platform specific function to read ready/busy pin
584589
* @select_chip: platform specific chip select function
@@ -591,6 +596,8 @@ struct platform_nand_chip {
591596
* All fields are optional and depend on the hardware driver requirements
592597
*/
593598
struct platform_nand_ctrl {
599+
int (*probe)(struct platform_device *pdev);
600+
void (*remove)(struct platform_device *pdev);
594601
void (*hwcontrol)(struct mtd_info *mtd, int cmd);
595602
int (*dev_ready)(struct mtd_info *mtd);
596603
void (*select_chip)(struct mtd_info *mtd, int chip);

0 commit comments

Comments
 (0)