Skip to content

Commit 0a454e9

Browse files
andy-shevstorulf
authored andcommitted
mmc: atmel-mci: Incapsulate used to be a platform data into host structure
After platform data is gone, we always allocate memory for the slot information. Incapsulate the array of the latter into the host structure, so we allocate memory only once. This makes code simpler. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 0b7b565 commit 0a454e9

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

drivers/mmc/host/atmel-mci.c

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ struct mci_slot_pdata {
224224
bool non_removable;
225225
};
226226

227-
/**
228-
* struct mci_platform_data - board-specific MMC/SDcard configuration
229-
* @slot: Per-slot configuration data.
230-
*/
231-
struct mci_platform_data {
232-
struct mci_slot_pdata slot[ATMCI_MAX_NR_SLOTS];
233-
};
234-
235227
struct atmel_mci_caps {
236228
bool has_dma_conf_reg;
237229
bool has_pdc;
@@ -297,6 +289,7 @@ struct atmel_mci_dma {
297289
* @mapbase: Physical address of the MMIO registers.
298290
* @mck: The peripheral bus clock hooked up to the MMC controller.
299291
* @dev: Device associated with the MMC controller.
292+
* @pdata: Per-slot configuration data.
300293
* @slot: Slots sharing this MMC controller.
301294
* @caps: MCI capabilities depending on MCI version.
302295
* @prepare_data: function to setup MCI before data transfer which
@@ -375,6 +368,7 @@ struct atmel_mci {
375368
struct clk *mck;
376369
struct device *dev;
377370

371+
struct mci_slot_pdata pdata[ATMCI_MAX_NR_SLOTS];
378372
struct atmel_mci_slot *slot[ATMCI_MAX_NR_SLOTS];
379373

380374
struct atmel_mci_caps caps;
@@ -630,11 +624,11 @@ static const struct of_device_id atmci_dt_ids[] = {
630624

631625
MODULE_DEVICE_TABLE(of, atmci_dt_ids);
632626

633-
static struct mci_platform_data *atmci_of_init(struct device *dev)
627+
static int atmci_of_init(struct atmel_mci *host)
634628
{
629+
struct device *dev = host->dev;
635630
struct device_node *np = dev->of_node;
636631
struct device_node *cnp;
637-
struct mci_platform_data *pdata;
638632
u32 slot_id;
639633
int err;
640634

@@ -643,10 +637,6 @@ static struct mci_platform_data *atmci_of_init(struct device *dev)
643637
return ERR_PTR(-EINVAL);
644638
}
645639

646-
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
647-
if (!pdata)
648-
return ERR_PTR(-ENOMEM);
649-
650640
for_each_child_of_node(np, cnp) {
651641
if (of_property_read_u32(cnp, "reg", &slot_id)) {
652642
dev_warn(dev, "reg property is missing for %pOF\n", cnp);
@@ -661,38 +651,38 @@ static struct mci_platform_data *atmci_of_init(struct device *dev)
661651
}
662652

663653
if (of_property_read_u32(cnp, "bus-width",
664-
&pdata->slot[slot_id].bus_width))
665-
pdata->slot[slot_id].bus_width = 1;
654+
&host->pdata[slot_id].bus_width))
655+
host->pdata[slot_id].bus_width = 1;
666656

667-
pdata->slot[slot_id].detect_pin =
657+
host->pdata[slot_id].detect_pin =
668658
devm_fwnode_gpiod_get(dev, of_fwnode_handle(cnp),
669659
"cd", GPIOD_IN, "cd-gpios");
670-
err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].detect_pin);
660+
err = PTR_ERR_OR_ZERO(host->pdata[slot_id].detect_pin);
671661
if (err) {
672662
if (err != -ENOENT) {
673663
of_node_put(cnp);
674-
return ERR_PTR(err);
664+
return err;
675665
}
676-
pdata->slot[slot_id].detect_pin = NULL;
666+
host->pdata[slot_id].detect_pin = NULL;
677667
}
678668

679-
pdata->slot[slot_id].non_removable =
669+
host->pdata[slot_id].non_removable =
680670
of_property_read_bool(cnp, "non-removable");
681671

682-
pdata->slot[slot_id].wp_pin =
672+
host->pdata[slot_id].wp_pin =
683673
devm_fwnode_gpiod_get(dev, of_fwnode_handle(cnp),
684674
"wp", GPIOD_IN, "wp-gpios");
685-
err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].wp_pin);
675+
err = PTR_ERR_OR_ZERO(host->pdata[slot_id].wp_pin);
686676
if (err) {
687677
if (err != -ENOENT) {
688678
of_node_put(cnp);
689-
return ERR_PTR(err);
679+
return err;
690680
}
691-
pdata->slot[slot_id].wp_pin = NULL;
681+
host->pdata[slot_id].wp_pin = NULL;
692682
}
693683
}
694684

695-
return pdata;
685+
return 0;
696686
}
697687

698688
static inline unsigned int atmci_get_version(struct atmel_mci *host)
@@ -2456,7 +2446,6 @@ static void atmci_get_cap(struct atmel_mci *host)
24562446
static int atmci_probe(struct platform_device *pdev)
24572447
{
24582448
struct device *dev = &pdev->dev;
2459-
struct mci_platform_data *pdata;
24602449
struct atmel_mci *host;
24612450
struct resource *regs;
24622451
unsigned int nr_slots;
@@ -2467,12 +2456,6 @@ static int atmci_probe(struct platform_device *pdev)
24672456
if (!regs)
24682457
return -ENXIO;
24692458

2470-
pdata = atmci_of_init(dev);
2471-
if (IS_ERR(pdata)) {
2472-
dev_err(dev, "platform data not available\n");
2473-
return PTR_ERR(pdata);
2474-
}
2475-
24762459
irq = platform_get_irq(pdev, 0);
24772460
if (irq < 0)
24782461
return irq;
@@ -2485,6 +2468,10 @@ static int atmci_probe(struct platform_device *pdev)
24852468
spin_lock_init(&host->lock);
24862469
INIT_LIST_HEAD(&host->queue);
24872470

2471+
ret = atmci_of_init(host);
2472+
if (ret)
2473+
return dev_err_probe(dev, ret, "Slot information not available\n");
2474+
24882475
host->mck = devm_clk_get(dev, "mci_clk");
24892476
if (IS_ERR(host->mck))
24902477
return PTR_ERR(host->mck);
@@ -2544,16 +2531,16 @@ static int atmci_probe(struct platform_device *pdev)
25442531
/* We need at least one slot to succeed */
25452532
nr_slots = 0;
25462533
ret = -ENODEV;
2547-
if (pdata->slot[0].bus_width) {
2548-
ret = atmci_init_slot(host, &pdata->slot[0],
2534+
if (host->pdata[0].bus_width) {
2535+
ret = atmci_init_slot(host, &host->pdata[0],
25492536
0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA);
25502537
if (!ret) {
25512538
nr_slots++;
25522539
host->buf_size = host->slot[0]->mmc->max_req_size;
25532540
}
25542541
}
2555-
if (pdata->slot[1].bus_width) {
2556-
ret = atmci_init_slot(host, &pdata->slot[1],
2542+
if (host->pdata[1].bus_width) {
2543+
ret = atmci_init_slot(host, &host->pdata[1],
25572544
1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB);
25582545
if (!ret) {
25592546
nr_slots++;

0 commit comments

Comments
 (0)