* [PATCH v2 1/2] mmc: atmel-mci: Incapsulate used to be a platform data into host structure
2024-04-25 17:08 [PATCH v2 0/2] mmc: atmel-mci: Get rid of leftovers and clean up Andy Shevchenko
@ 2024-04-25 17:08 ` Andy Shevchenko
2024-04-25 17:08 ` [PATCH v2 2/2] mmc: atmel-mci: Switch to use dev_err_probe() Andy Shevchenko
2024-04-26 4:52 ` [PATCH v2 0/2] mmc: atmel-mci: Get rid of leftovers and clean up Ulf Hansson
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-04-25 17:08 UTC (permalink / raw)
To: Andy Shevchenko, linux-mmc, linux-arm-kernel, linux-kernel
Cc: Aubin Constans, Ulf Hansson, Alexandre Belloni, Claudiu Beznea
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 <andriy.shevchenko@linux.intel.com>
---
drivers/mmc/host/atmel-mci.c | 61 ++++++++++++++----------------------
1 file changed, 24 insertions(+), 37 deletions(-)
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 3aed57c392fa..9ae3ce14db50 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -224,14 +224,6 @@ struct mci_slot_pdata {
bool non_removable;
};
-/**
- * struct mci_platform_data - board-specific MMC/SDcard configuration
- * @slot: Per-slot configuration data.
- */
-struct mci_platform_data {
- struct mci_slot_pdata slot[ATMCI_MAX_NR_SLOTS];
-};
-
struct atmel_mci_caps {
bool has_dma_conf_reg;
bool has_pdc;
@@ -297,6 +289,7 @@ struct atmel_mci_dma {
* @mapbase: Physical address of the MMIO registers.
* @mck: The peripheral bus clock hooked up to the MMC controller.
* @dev: Device associated with the MMC controller.
+ * @pdata: Per-slot configuration data.
* @slot: Slots sharing this MMC controller.
* @caps: MCI capabilities depending on MCI version.
* @prepare_data: function to setup MCI before data transfer which
@@ -375,6 +368,7 @@ struct atmel_mci {
struct clk *mck;
struct device *dev;
+ struct mci_slot_pdata pdata[ATMCI_MAX_NR_SLOTS];
struct atmel_mci_slot *slot[ATMCI_MAX_NR_SLOTS];
struct atmel_mci_caps caps;
@@ -630,11 +624,11 @@ static const struct of_device_id atmci_dt_ids[] = {
MODULE_DEVICE_TABLE(of, atmci_dt_ids);
-static struct mci_platform_data *atmci_of_init(struct device *dev)
+static int atmci_of_init(struct atmel_mci *host)
{
+ struct device *dev = host->dev;
struct device_node *np = dev->of_node;
struct device_node *cnp;
- struct mci_platform_data *pdata;
u32 slot_id;
int err;
@@ -643,10 +637,6 @@ static struct mci_platform_data *atmci_of_init(struct device *dev)
return ERR_PTR(-EINVAL);
}
- pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
- if (!pdata)
- return ERR_PTR(-ENOMEM);
-
for_each_child_of_node(np, cnp) {
if (of_property_read_u32(cnp, "reg", &slot_id)) {
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)
}
if (of_property_read_u32(cnp, "bus-width",
- &pdata->slot[slot_id].bus_width))
- pdata->slot[slot_id].bus_width = 1;
+ &host->pdata[slot_id].bus_width))
+ host->pdata[slot_id].bus_width = 1;
- pdata->slot[slot_id].detect_pin =
+ host->pdata[slot_id].detect_pin =
devm_fwnode_gpiod_get(dev, of_fwnode_handle(cnp),
"cd", GPIOD_IN, "cd-gpios");
- err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].detect_pin);
+ err = PTR_ERR_OR_ZERO(host->pdata[slot_id].detect_pin);
if (err) {
if (err != -ENOENT) {
of_node_put(cnp);
- return ERR_PTR(err);
+ return err;
}
- pdata->slot[slot_id].detect_pin = NULL;
+ host->pdata[slot_id].detect_pin = NULL;
}
- pdata->slot[slot_id].non_removable =
+ host->pdata[slot_id].non_removable =
of_property_read_bool(cnp, "non-removable");
- pdata->slot[slot_id].wp_pin =
+ host->pdata[slot_id].wp_pin =
devm_fwnode_gpiod_get(dev, of_fwnode_handle(cnp),
"wp", GPIOD_IN, "wp-gpios");
- err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].wp_pin);
+ err = PTR_ERR_OR_ZERO(host->pdata[slot_id].wp_pin);
if (err) {
if (err != -ENOENT) {
of_node_put(cnp);
- return ERR_PTR(err);
+ return err;
}
- pdata->slot[slot_id].wp_pin = NULL;
+ host->pdata[slot_id].wp_pin = NULL;
}
}
- return pdata;
+ return 0;
}
static inline unsigned int atmci_get_version(struct atmel_mci *host)
@@ -2456,7 +2446,6 @@ static void atmci_get_cap(struct atmel_mci *host)
static int atmci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct mci_platform_data *pdata;
struct atmel_mci *host;
struct resource *regs;
unsigned int nr_slots;
@@ -2467,12 +2456,6 @@ static int atmci_probe(struct platform_device *pdev)
if (!regs)
return -ENXIO;
- pdata = atmci_of_init(dev);
- if (IS_ERR(pdata)) {
- dev_err(dev, "platform data not available\n");
- return PTR_ERR(pdata);
- }
-
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
@@ -2485,6 +2468,10 @@ static int atmci_probe(struct platform_device *pdev)
spin_lock_init(&host->lock);
INIT_LIST_HEAD(&host->queue);
+ ret = atmci_of_init(host);
+ if (ret)
+ return dev_err_probe(dev, ret, "Slot information not available\n");
+
host->mck = devm_clk_get(dev, "mci_clk");
if (IS_ERR(host->mck))
return PTR_ERR(host->mck);
@@ -2544,16 +2531,16 @@ static int atmci_probe(struct platform_device *pdev)
/* We need at least one slot to succeed */
nr_slots = 0;
ret = -ENODEV;
- if (pdata->slot[0].bus_width) {
- ret = atmci_init_slot(host, &pdata->slot[0],
+ if (host->pdata[0].bus_width) {
+ ret = atmci_init_slot(host, &host->pdata[0],
0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA);
if (!ret) {
nr_slots++;
host->buf_size = host->slot[0]->mmc->max_req_size;
}
}
- if (pdata->slot[1].bus_width) {
- ret = atmci_init_slot(host, &pdata->slot[1],
+ if (host->pdata[1].bus_width) {
+ ret = atmci_init_slot(host, &host->pdata[1],
1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB);
if (!ret) {
nr_slots++;
--
2.43.0.rc1.1336.g36b5255a03ac
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] mmc: atmel-mci: Switch to use dev_err_probe()
2024-04-25 17:08 [PATCH v2 0/2] mmc: atmel-mci: Get rid of leftovers and clean up Andy Shevchenko
2024-04-25 17:08 ` [PATCH v2 1/2] mmc: atmel-mci: Incapsulate used to be a platform data into host structure Andy Shevchenko
@ 2024-04-25 17:08 ` Andy Shevchenko
2024-04-26 4:52 ` [PATCH v2 0/2] mmc: atmel-mci: Get rid of leftovers and clean up Ulf Hansson
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-04-25 17:08 UTC (permalink / raw)
To: Andy Shevchenko, linux-mmc, linux-arm-kernel, linux-kernel
Cc: Aubin Constans, Ulf Hansson, Alexandre Belloni, Claudiu Beznea
Switch to use dev_err_probe() to simplify the error path and
unify a message template.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/mmc/host/atmel-mci.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 9ae3ce14db50..8199d9620075 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -632,10 +632,8 @@ static int atmci_of_init(struct atmel_mci *host)
u32 slot_id;
int err;
- if (!np) {
- dev_err(dev, "device node not found\n");
- return ERR_PTR(-EINVAL);
- }
+ if (!np)
+ return dev_err_probe(dev, -EINVAL, "device node not found\n");
for_each_child_of_node(np, cnp) {
if (of_property_read_u32(cnp, "reg", &slot_id)) {
@@ -2551,7 +2549,7 @@ static int atmci_probe(struct platform_device *pdev)
}
if (!nr_slots) {
- dev_err(dev, "init failed: no slot defined\n");
+ dev_err_probe(dev, ret, "init failed: no slot defined\n");
goto err_init_slot;
}
@@ -2560,8 +2558,7 @@ static int atmci_probe(struct platform_device *pdev)
&host->buf_phys_addr,
GFP_KERNEL);
if (!host->buffer) {
- ret = -ENOMEM;
- dev_err(dev, "buffer allocation failed\n");
+ ret = dev_err_probe(dev, -ENOMEM, "buffer allocation failed\n");
goto err_dma_alloc;
}
}
--
2.43.0.rc1.1336.g36b5255a03ac
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread