@@ -69,18 +69,19 @@ index ba56485cbe8c..e86723b44c2e 100644
6969 obj-$(CONFIG_MLXREG_LC) += mlxreg-lc.o
7070diff --git a/drivers/platform/mellanox/mlxreg-dpu.c b/drivers/platform/mellanox/mlxreg-dpu.c
7171new file mode 100644
72- index 000000000000..f831d6dd5ece
72+ index 000000000..c6cfbee55
7373--- /dev/null
7474+++ b/drivers/platform/mellanox/mlxreg-dpu.c
75- @@ -0,0 +1,625 @@
75+ @@ -0,0 +1,626 @@
7676+ // SPDX-License-Identifier: GPL-2.0+
7777+ /*
7878+ * Nvidia Data Processor Unit platform driver
7979+ *
80- + * Copyright (C) 2024 Nvidia Technologies Ltd.
80+ + * Copyright (C) 2025 Nvidia Technologies Ltd.
8181+ */
8282+
8383+ #include <linux/device.h>
84+ + #include <linux/dev_printk.h>
8485+ #include <linux/i2c.h>
8586+ #include <linux/module.h>
8687+ #include <linux/platform_data/mlxcpld.h>
@@ -389,13 +390,14 @@ index 000000000000..f831d6dd5ece
389390+ .mask = MLXREG_DPU_AGGR_MASK,
390391+ };
391392+
392- + /* mlxreg_dpu - device private data
393- + * @dev: platform device;
394- + * @data: pltaform core data;
395- + * @io_data: register access platform data;
396- + * @io_regs: register access device;
397- + * @hotplug_data: hotplug platform data;
398- + * @hotplug: hotplug device;
393+ + /**
394+ + * struct mlxreg_dpu - device private data
395+ + * @dev: platform device
396+ + * @data: platform core data
397+ + * @io_data: register access platform data
398+ + * @io_regs: register access device
399+ + * @hotplug_data: hotplug platform data
400+ + * @hotplug: hotplug device
399401+ */
400402+ struct mlxreg_dpu {
401403+ struct device *dev;
@@ -478,6 +480,11 @@ index 000000000000..f831d6dd5ece
478480+ return false;
479481+ }
480482+
483+ + static const struct reg_default mlxreg_dpu_regmap_default[] = {
484+ + { MLXREG_DPU_REG_PG_EVENT_OFFSET, 0x00 },
485+ + { MLXREG_DPU_REG_HEALTH_EVENT_OFFSET, 0x00 },
486+ + };
487+ +
481488+ /* Configuration for the register map of a device with 2 bytes address space. */
482489+ static const struct regmap_config mlxreg_dpu_regmap_conf = {
483490+ .reg_bits = 16,
@@ -487,10 +494,13 @@ index 000000000000..f831d6dd5ece
487494+ .writeable_reg = mlxreg_dpu_writeable_reg,
488495+ .readable_reg = mlxreg_dpu_readable_reg,
489496+ .volatile_reg = mlxreg_dpu_volatile_reg,
497+ + .reg_defaults = mlxreg_dpu_regmap_default,
498+ + .num_reg_defaults = ARRAY_SIZE(mlxreg_dpu_regmap_default),
490499+ };
491500+
492- + static int mlxreg_dpu_copy_hotplug_data(struct device *dev, struct mlxreg_dpu *mlxreg_dpu,
493- + struct mlxreg_core_hotplug_platform_data *hotplug_data)
501+ + static int
502+ + mlxreg_dpu_copy_hotplug_data(struct device *dev, struct mlxreg_dpu *mlxreg_dpu,
503+ + const struct mlxreg_core_hotplug_platform_data *hotplug_data)
494504+ {
495505+ struct mlxreg_core_item *item;
496506+ int i;
@@ -502,18 +512,15 @@ index 000000000000..f831d6dd5ece
502512+
503513+ mlxreg_dpu->hotplug_data->items = devm_kmemdup(dev, hotplug_data->items,
504514+ mlxreg_dpu->hotplug_data->counter *
505- + sizeof(*hotplug_data->items),
515+ + sizeof(*mlxreg_dpu-> hotplug_data->items),
506516+ GFP_KERNEL);
507517+ if (!mlxreg_dpu->hotplug_data->items)
508518+ return -ENOMEM;
509519+
510520+ item = mlxreg_dpu->hotplug_data->items;
511- + for (i = 0; i < mlxreg_dpu->hotplug_data->counter; i++, item++) {
512- + item = devm_kmemdup(dev, &hotplug_data->items[i], sizeof(*item), GFP_KERNEL);
513- + if (!item)
514- + return -ENOMEM;
521+ + for (i = 0; i < hotplug_data->counter; i++, item++) {
515522+ item->data = devm_kmemdup(dev, hotplug_data->items[i].data,
516- + hotplug_data->items[i].count * sizeof(item->data),
523+ + hotplug_data->items[i].count * sizeof(* item->data),
517524+ GFP_KERNEL);
518525+ if (!item->data)
519526+ return -ENOMEM;
@@ -533,6 +540,7 @@ index 000000000000..f831d6dd5ece
533540+ err = regmap_read(regmap, MLXREG_DPU_REG_CONFIG3_OFFSET, ®val);
534541+ if (err)
535542+ return err;
543+ +
536544+ switch (regval) {
537545+ case MLXREG_DPU_BF3:
538546+ /* Copy platform specific hotplug data. */
@@ -552,15 +560,15 @@ index 000000000000..f831d6dd5ece
552560+ if (mlxreg_dpu->io_data) {
553561+ mlxreg_dpu->io_data->regmap = regmap;
554562+ mlxreg_dpu->io_regs =
555- + platform_device_register_resndata(dev, "mlxreg-io", data->slot, NULL, 0,
556- + mlxreg_dpu->io_data,
557- + sizeof(*mlxreg_dpu->io_data));
563+ + platform_device_register_resndata(dev, "mlxreg-io",
564+ + data->slot, NULL, 0,
565+ + mlxreg_dpu->io_data,
566+ + sizeof(*mlxreg_dpu->io_data));
558567+ if (IS_ERR(mlxreg_dpu->io_regs)) {
559568+ dev_err(dev, "Failed to create regio for client %s at bus %d at addr 0x%02x\n",
560569+ data->hpdev.brdinfo->type, data->hpdev.nr,
561570+ data->hpdev.brdinfo->addr);
562- + err = PTR_ERR(mlxreg_dpu->io_regs);
563- + goto fail_register_io;
571+ + return PTR_ERR(mlxreg_dpu->io_regs);
564572+ }
565573+ }
566574+
@@ -569,9 +577,10 @@ index 000000000000..f831d6dd5ece
569577+ mlxreg_dpu->hotplug_data->regmap = regmap;
570578+ mlxreg_dpu->hotplug_data->irq = irq;
571579+ mlxreg_dpu->hotplug =
572- + platform_device_register_resndata(dev, "mlxreg-hotplug", data->slot, NULL, 0,
573- + mlxreg_dpu->hotplug_data,
574- + sizeof(*mlxreg_dpu->hotplug_data));
580+ + platform_device_register_resndata(dev, "mlxreg-hotplug",
581+ + data->slot, NULL, 0,
582+ + mlxreg_dpu->hotplug_data,
583+ + sizeof(*mlxreg_dpu->hotplug_data));
575584+ if (IS_ERR(mlxreg_dpu->hotplug)) {
576585+ err = PTR_ERR(mlxreg_dpu->hotplug);
577586+ goto fail_register_hotplug;
@@ -582,16 +591,13 @@ index 000000000000..f831d6dd5ece
582591+
583592+ fail_register_hotplug:
584593+ platform_device_unregister(mlxreg_dpu->io_regs);
585- + fail_register_io:
586594+
587595+ return err;
588596+ }
589597+
590598+ static void mlxreg_dpu_config_exit(struct mlxreg_dpu *mlxreg_dpu)
591599+ {
592- + /* Unregister hotplug driver. */
593600+ platform_device_unregister(mlxreg_dpu->hotplug);
594- + /* Unregister IO access driver. */
595601+ platform_device_unregister(mlxreg_dpu->io_regs);
596602+ }
597603+
@@ -606,14 +612,14 @@ index 000000000000..f831d6dd5ece
606612+ if (!data || !data->hpdev.brdinfo)
607613+ return -EINVAL;
608614+
609- + mlxreg_dpu = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_dpu), GFP_KERNEL);
610- + if (!mlxreg_dpu)
611- + return -ENOMEM;
612- +
613615+ data->hpdev.adapter = i2c_get_adapter(data->hpdev.nr);
614616+ if (!data->hpdev.adapter)
615617+ return -EPROBE_DEFER;
616618+
619+ + mlxreg_dpu = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_dpu), GFP_KERNEL);
620+ + if (!mlxreg_dpu)
621+ + return -ENOMEM;
622+ +
617623+ /* Create device at the top of DPU I2C tree.*/
618624+ data->hpdev.client = i2c_new_client_device(data->hpdev.adapter,
619625+ data->hpdev.brdinfo);
@@ -624,8 +630,7 @@ index 000000000000..f831d6dd5ece
624630+ goto i2c_new_device_fail;
625631+ }
626632+
627- + regmap = devm_regmap_init_i2c(data->hpdev.client,
628- + &mlxreg_dpu_regmap_conf);
633+ + regmap = devm_regmap_init_i2c(data->hpdev.client, &mlxreg_dpu_regmap_conf);
629634+ if (IS_ERR(regmap)) {
630635+ dev_err(&pdev->dev, "Failed to create regmap for client %s at bus %d at addr 0x%02x\n",
631636+ data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr);
@@ -647,13 +652,10 @@ index 000000000000..f831d6dd5ece
647652+ mlxreg_dpu->dev = &pdev->dev;
648653+ platform_set_drvdata(pdev, mlxreg_dpu);
649654+
650- + /* Configure DPU. */
651655+ err = mlxreg_dpu_config_init(mlxreg_dpu, regmap, data, data->hpdev.brdinfo->irq);
652656+ if (err)
653657+ goto mlxreg_dpu_config_init_fail;
654658+
655- + return err;
656- +
657659+ mlxreg_dpu_config_init_fail:
658660+ regcache_sync_fail:
659661+ devm_regmap_init_i2c_fail:
@@ -697,7 +699,6 @@ index 000000000000..f831d6dd5ece
697699+ MODULE_DESCRIPTION("Nvidia Data Processor Unit platform driver");
698700+ MODULE_LICENSE("Dual BSD/GPL");
699701+ MODULE_ALIAS("platform:mlxreg-dpu");
700- +
701702- -
702- 2.34.1
703+ 2.44.0
703704
0 commit comments