equal
deleted
inserted
replaced
54 /*****************************************************************************/ |
54 /*****************************************************************************/ |
55 |
55 |
56 static int ec_master_count = 1; /**< parameter value, number of masters */ |
56 static int ec_master_count = 1; /**< parameter value, number of masters */ |
57 static int ec_eoeif_count = 0; /**< parameter value, number of EoE interf. */ |
57 static int ec_eoeif_count = 0; /**< parameter value, number of EoE interf. */ |
58 static struct list_head ec_masters; /**< list of masters */ |
58 static struct list_head ec_masters; /**< list of masters */ |
|
59 static dev_t device_number; |
59 |
60 |
60 /*****************************************************************************/ |
61 /*****************************************************************************/ |
61 |
62 |
62 /** \cond */ |
63 /** \cond */ |
63 |
64 |
87 ec_master_t *master, *next; |
88 ec_master_t *master, *next; |
88 |
89 |
89 EC_INFO("Master driver, %s\n", EC_COMPILE_INFO); |
90 EC_INFO("Master driver, %s\n", EC_COMPILE_INFO); |
90 |
91 |
91 if (ec_master_count < 1) { |
92 if (ec_master_count < 1) { |
92 EC_ERR("Error - Invalid ec_master_count: %i\n", ec_master_count); |
93 EC_ERR("Invalid ec_master_count: %i\n", ec_master_count); |
|
94 goto out_return; |
|
95 } |
|
96 |
|
97 if (alloc_chrdev_region(&device_number, 0, ec_master_count, "EtherCAT")) { |
|
98 EC_ERR("Failed to allocate device number!\n"); |
93 goto out_return; |
99 goto out_return; |
94 } |
100 } |
95 |
101 |
96 EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count); |
102 EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count); |
97 |
103 |
102 (ec_master_t *) kmalloc(sizeof(ec_master_t), GFP_KERNEL))) { |
108 (ec_master_t *) kmalloc(sizeof(ec_master_t), GFP_KERNEL))) { |
103 EC_ERR("Failed to allocate memory for EtherCAT master %i.\n", i); |
109 EC_ERR("Failed to allocate memory for EtherCAT master %i.\n", i); |
104 goto out_free; |
110 goto out_free; |
105 } |
111 } |
106 |
112 |
107 if (ec_master_init(master, i, ec_eoeif_count)) |
113 if (ec_master_init(master, i, ec_eoeif_count, device_number)) |
108 goto out_free; |
114 goto out_free; |
109 |
115 |
110 if (kobject_add(&master->kobj)) { |
116 if (kobject_add(&master->kobj)) { |
111 EC_ERR("Failed to add kobj.\n"); |
117 EC_ERR("Failed to add kobj.\n"); |
112 kobject_put(&master->kobj); // free master |
118 kobject_put(&master->kobj); // free master |
145 list_for_each_entry_safe(master, next, &ec_masters, list) { |
151 list_for_each_entry_safe(master, next, &ec_masters, list) { |
146 list_del(&master->list); |
152 list_del(&master->list); |
147 kobject_del(&master->kobj); |
153 kobject_del(&master->kobj); |
148 kobject_put(&master->kobj); // free master |
154 kobject_put(&master->kobj); // free master |
149 } |
155 } |
|
156 |
|
157 unregister_chrdev_region(device_number, ec_master_count); |
150 |
158 |
151 EC_INFO("Master driver cleaned up.\n"); |
159 EC_INFO("Master driver cleaned up.\n"); |
152 } |
160 } |
153 |
161 |
154 /*****************************************************************************/ |
162 /*****************************************************************************/ |