Create class device with device_number information in sysfs.
This commit is contained in:
parent
1553af9375
commit
25ffc9f638
|
|
@ -76,7 +76,8 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
||||||
unsigned int index, /**< master index */
|
unsigned int index, /**< master index */
|
||||||
const uint8_t *main_mac, /**< MAC address of main device */
|
const uint8_t *main_mac, /**< MAC address of main device */
|
||||||
const uint8_t *backup_mac, /**< MAC address of backup device */
|
const uint8_t *backup_mac, /**< MAC address of backup device */
|
||||||
dev_t device_number /**< Character device number. */
|
dev_t device_number, /**< Character device number. */
|
||||||
|
struct class *class /**< Device class. */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
@ -171,8 +172,18 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
||||||
if (ec_cdev_init(&master->cdev, master, device_number))
|
if (ec_cdev_init(&master->cdev, master, device_number))
|
||||||
goto out_clear_fsm;
|
goto out_clear_fsm;
|
||||||
|
|
||||||
|
master->class_device = class_device_create(class,
|
||||||
|
MKDEV(MAJOR(device_number), master->index),
|
||||||
|
NULL, "EtherCAT%u", master->index);
|
||||||
|
if (IS_ERR(master->class_device)) {
|
||||||
|
EC_ERR("Failed to create class device!\n");
|
||||||
|
goto out_clear_cdev;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_clear_cdev:
|
||||||
|
ec_cdev_clear(&master->cdev);
|
||||||
out_clear_fsm:
|
out_clear_fsm:
|
||||||
ec_fsm_master_clear(&master->fsm);
|
ec_fsm_master_clear(&master->fsm);
|
||||||
ec_datagram_clear(&master->fsm_datagram);
|
ec_datagram_clear(&master->fsm_datagram);
|
||||||
|
|
@ -192,6 +203,7 @@ void ec_master_clear(
|
||||||
ec_master_t *master /**< EtherCAT master */
|
ec_master_t *master /**< EtherCAT master */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
class_device_unregister(master->class_device);
|
||||||
ec_cdev_clear(&master->cdev);
|
ec_cdev_clear(&master->cdev);
|
||||||
#ifdef EC_EOE
|
#ifdef EC_EOE
|
||||||
ec_master_clear_eoe_handlers(master);
|
ec_master_clear_eoe_handlers(master);
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ struct ec_master {
|
||||||
unsigned int reserved; /**< non-zero, if the master is reserved for RT */
|
unsigned int reserved; /**< non-zero, if the master is reserved for RT */
|
||||||
|
|
||||||
ec_cdev_t cdev; /**< Master character device. */
|
ec_cdev_t cdev; /**< Master character device. */
|
||||||
|
struct class_device *class_device; /**< Master class device. */
|
||||||
|
|
||||||
ec_device_t main_device; /**< EtherCAT device */
|
ec_device_t main_device; /**< EtherCAT device */
|
||||||
const uint8_t *main_mac; /**< MAC address of main device */
|
const uint8_t *main_mac; /**< MAC address of main device */
|
||||||
|
|
@ -167,7 +168,7 @@ struct ec_master {
|
||||||
|
|
||||||
// master creation/deletion
|
// master creation/deletion
|
||||||
int ec_master_init(ec_master_t *, unsigned int, const uint8_t *,
|
int ec_master_init(ec_master_t *, unsigned int, const uint8_t *,
|
||||||
const uint8_t *, dev_t);
|
const uint8_t *, dev_t, struct class *);
|
||||||
void ec_master_clear(ec_master_t *);
|
void ec_master_clear(ec_master_t *);
|
||||||
|
|
||||||
// mode transitions
|
// mode transitions
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ int __init ec_init_module(void)
|
||||||
|
|
||||||
for (i = 0; i < master_count; i++) {
|
for (i = 0; i < master_count; i++) {
|
||||||
if (ec_master_init(&masters[i], i, macs[i][0], macs[i][1],
|
if (ec_master_init(&masters[i], i, macs[i][0], macs[i][1],
|
||||||
device_number)) {
|
device_number, class)) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out_free_masters;
|
goto out_free_masters;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue