Skip to contentSkip to conversation

chris: struct device - replace bus_id with dev_name(), dev_set_name()

PATCH Kay Sievers 3 participants 4 messages Nov 7, 2008 – Nov 18, 2008

lore
Share & tools
lore
#0 lore raw

(I did not compile or test it, please let me know, or help fixing
it, if something is wrong with the conversion)

This patch is part of a larger patch series which will remove the "char bus_id[20]" name string from struct device. The device name is managed in the kobject anyway, and without any size limitation, and just needlessly copied into "struct device".

To set and read the device name dev_name(dev) and dev_set_name(dev) must be used. If your code uses static kobjects, which it shouldn't do, "const char *init_name" can be used to statically provide the name the registered device should have. At registration time, the init_name field is cleared, to enforce the use of dev_name(dev) to access the device name at a later time.

We need to get rid of all occurrences of bus_id in the entire tree to be able to enable the new interface. Please apply this patch, and possibly convert any remaining remaining occurrences of bus_id.

We want to submit a patch to -next, which will remove bus_id from "struct device", to find the remaining pieces to convert, and finally switch over to the new api, which will remove the 20 bytes array and does no longer have a size limitation.

Thanks,
Kay

From: Kay Sievers <[email protected]>
Subject: chris: struct device - replace bus_id with dev_name(), dev_set_name()

---
 arch/cris/arch-v32/drivers/iop_fw_load.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/cris/arch-v32/drivers/iop_fw_load.c +3 -3
@@ -24,12 +24,12 @@
 #error "Please contact <[email protected]> for details on how to fix it properly."
 
 static struct device iop_spu_device[2] = {
-	{ .bus_id =     "iop-spu0", },
-	{ .bus_id =     "iop-spu1", },
+	{ .init_name =     "iop-spu0", },
+	{ .init_name =     "iop-spu1", },
 };
 
 static struct device iop_mpu_device = {
-	.bus_id =       "iop-mpu",
+	.init_name =       "iop-mpu",
 };
 
 static int wait_mpu_idle(void)
#1 lore raw
Quoted 4 lines · Kay Sievers

This patch is part of a larger patch series which will remove the "char bus_id[20]" name string from struct device. The device name is managed in the kobject anyway, and without any size limitation, and just needlessly copied into "struct device".

Thanks, but I think that since this driver has been broken a long time it is high time to fix it, and I think the fix removes the need for your patch.

Greg, could you please look this patch over?

[CRISv32] Fix IOP fw-loader to use platform_device.

Change IOP fw-loader to use platform_device instead of raw device, which should be more correct usage.

---

 iop_fw_load.c |   69 ++++++++++++++++++++++++----------------------------------
 1 file changed, 29 insertions(+), 40 deletions(-)
arch/cris/arch-v32/drivers/iop_fw_load.c +29 -40
index 3b3857e..7376012 100644
@@ -1,13 +1,14 @@
 /*
  * Firmware loader for ETRAX FS IO-Processor
  *
- * Copyright (C) 2004  Axis Communications AB
+ * Copyright (C) 2004-2008  Axis Communications AB
  */
 
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/firmware.h>
 
 #include <hwregs/reg_rdwr.h>
@@ -20,16 +21,17 @@
 
 #define IOP_TIMEOUT 100
 
-#error "This driver is broken with regard to its driver core usage."
-#error "Please contact <[email protected]> for details on how to fix it properly."
+int iop_fw_load_spu(const unsigned char *fw_name, unsigned int spu_inst);
+int iop_fw_load_mpu(unsigned char *fw_name);
+int iop_start_mpu(unsigned int start_addr);
 
-static struct device iop_spu_device[2] = {
-	{ .bus_id =     "iop-spu0", },
-	{ .bus_id =     "iop-spu1", },
+static struct platform_device iop_spu_device[2] = {
+	{ .name =     "iop-spu0", },
+	{ .name =     "iop-spu1", },
 };
 
-static struct device iop_mpu_device = {
-	.bus_id =       "iop-mpu",
+static struct platform_device iop_mpu_device = {
+	.name =       "iop-mpu",
 };
 
 static int wait_mpu_idle(void)
@@ -61,7 +63,7 @@ int iop_fw_load_spu(const unsigned char *fw_name, unsigned int spu_inst)
 		.fsm =            regk_iop_spu_no,
 	};
 	reg_iop_sw_cpu_r_mc_stat mc_stat;
-        const struct firmware *fw_entry;
+	const struct firmware *fw_entry;
 	u32 *data;
 	unsigned int timeout;
 	int retval, i;
@@ -72,9 +74,8 @@ int iop_fw_load_spu(const unsigned char *fw_name, unsigned int spu_inst)
 	/* get firmware */
 	retval = request_firmware(&fw_entry,
 				  fw_name,
-				  &iop_spu_device[spu_inst]);
-	if (retval != 0)
-	{
+				  &iop_spu_device[spu_inst].dev);
+	if (retval != 0) {
 		printk(KERN_ERR
 		       "iop_load_spu: Failed to load firmware \"%s\"\n",
 		       fw_name);
@@ -121,29 +122,29 @@ int iop_fw_load_spu(const unsigned char *fw_name, unsigned int spu_inst)
 	/* release ownership of memory controller */
 	(void) REG_RD(iop_sw_cpu, regi_iop_sw_cpu, rs_mc_data);
 
- out:
+out:
 	release_firmware(fw_entry);
 	return retval;
 }
+EXPORT_SYMBOL(iop_fw_load_spu);
 
 int iop_fw_load_mpu(unsigned char *fw_name)
 {
 	const unsigned int start_addr = 0;
 	reg_iop_mpu_rw_ctrl mpu_ctrl;
-        const struct firmware *fw_entry;
+	const struct firmware *fw_entry;
 	u32 *data;
 	int retval, i;
 
 	/* get firmware */
-	retval = request_firmware(&fw_entry, fw_name, &iop_mpu_device);
-	if (retval != 0)
-	{
+	retval = request_firmware(&fw_entry, fw_name, &iop_mpu_device.dev);
+	if (retval != 0) {
 		printk(KERN_ERR
 		       "iop_load_spu: Failed to load firmware \"%s\"\n",
 		       fw_name);
 		return retval;
 	}
-	data = (u32 *) fw_entry->data;
+	data = (u32 *)fw_entry->data;
 
 	/* disable MPU */
 	mpu_ctrl.en = regk_iop_mpu_no;
@@ -161,10 +162,11 @@ int iop_fw_load_mpu(unsigned char *fw_name)
 		data++;
 	}
 
- out:
+out:
 	release_firmware(fw_entry);
 	return retval;
 }
+EXPORT_SYMBOL(iop_fw_load_mpu);
 
 int iop_start_mpu(unsigned int start_addr)
 {
@@ -189,34 +191,24 @@ int iop_start_mpu(unsigned int start_addr)
 		goto out;
 	/* enable MPU */
 	REG_WR(iop_mpu, regi_iop_mpu, rw_ctrl, mpu_ctrl);
- out:
+out:
 	return retval;
 }
+EXPORT_SYMBOL(iop_start_mpu);
 
 static int __init iop_fw_load_init(void)
 {
-#if 0
-	/*
-	 * static struct devices can not be added directly to sysfs by ignoring
-	 * the driver model infrastructure.  To fix this properly, please use
-	 * the platform_bus to register these devices to be able to properly
-	 * use the firmware infrastructure.
-	 */
-	device_initialize(&iop_spu_device[0]);
-	kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0");
-	kobject_add(&iop_spu_device[0].kobj);
-	device_initialize(&iop_spu_device[1]);
-	kobject_set_name(&iop_spu_device[1].kobj, "iop-spu1");
-	kobject_add(&iop_spu_device[1].kobj);
-	device_initialize(&iop_mpu_device);
-	kobject_set_name(&iop_mpu_device.kobj, "iop-mpu");
-	kobject_add(&iop_mpu_device.kobj);
-#endif
+	platform_device_register(&iop_mpu_device);
+	platform_device_register(&iop_spu_device[0]);
+	platform_device_register(&iop_spu_device[1]);
 	return 0;
 }
 
 static void __exit iop_fw_load_exit(void)
 {
+	platform_device_unregister(&iop_mpu_device);
+	platform_device_unregister(&iop_spu_device[0]);
+	platform_device_unregister(&iop_spu_device[1]);
 }
 
 module_init(iop_fw_load_init);
@@ -225,6 +217,3 @@ module_exit(iop_fw_load_exit);
 MODULE_DESCRIPTION("ETRAX FS IO-Processor Firmware Loader");
 MODULE_LICENSE("GPL");
 
-EXPORT_SYMBOL(iop_fw_load_spu);
-EXPORT_SYMBOL(iop_fw_load_mpu);
-EXPORT_SYMBOL(iop_start_mpu);

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
#2 lore raw
Quoted 12 lines · Jesper Nilsson
Quoted 4 lines · Kay Sievers

This patch is part of a larger patch series which will remove the "char bus_id[20]" name string from struct device. The device name is managed in the kobject anyway, and without any size limitation, and just needlessly copied into "struct device".

Thanks, but I think that since this driver has been broken a long time it is high time to fix it, and I think the fix removes the need for your patch.

Greg, could you please look this patch over?

Quoted 7 lines

[CRISv32] Fix IOP fw-loader to use platform_device.

Change IOP fw-loader to use platform_device instead of raw device, which should be more correct usage.

Looks sane to me. Want me to take it through my tree, or will you be submitting it?

thanks,

greg k-h

#3 lore raw
Quoted 15 lines · Greg KH
Quoted 14 lines · Jesper Nilsson
Quoted 4 lines · Kay Sievers

This patch is part of a larger patch series which will remove the "char bus_id[20]" name string from struct device. The device name is managed in the kobject anyway, and without any size limitation, and just needlessly copied into "struct device".

Thanks, but I think that since this driver has been broken a long time it is high time to fix it, and I think the fix removes the need for your patch.

Greg, could you please look this patch over?

[CRISv32] Fix IOP fw-loader to use platform_device.

Quoted 8 lines
Quoted 5 lines

Change IOP fw-loader to use platform_device instead of raw device, which should be more correct usage.

Looks sane to me. Want me to take it through my tree, or will you be submitting it?

Thanks, good to hear, I'll take it into the CRIS-tree.

Quoted 3 lines

thanks,

greg k-h

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]