equal
deleted
inserted
replaced
72 int ec_xmldev_init(ec_xmldev_t *xmldev, /**< EtherCAT XML device */ |
72 int ec_xmldev_init(ec_xmldev_t *xmldev, /**< EtherCAT XML device */ |
73 ec_master_t *master, /**< EtherCAT master */ |
73 ec_master_t *master, /**< EtherCAT master */ |
74 dev_t dev_num /**< device number */ |
74 dev_t dev_num /**< device number */ |
75 ) |
75 ) |
76 { |
76 { |
|
77 atomic_set(&xmldev->available, 1); |
77 cdev_init(&xmldev->cdev, &fops); |
78 cdev_init(&xmldev->cdev, &fops); |
78 xmldev->cdev.owner = THIS_MODULE; |
79 xmldev->cdev.owner = THIS_MODULE; |
79 if (cdev_add(&xmldev->cdev, |
80 if (cdev_add(&xmldev->cdev, |
80 MKDEV(MAJOR(dev_num), master->index), 1)) { |
81 MKDEV(MAJOR(dev_num), master->index), 1)) { |
81 EC_ERR("Failed to add character device!\n"); |
82 EC_ERR("Failed to add character device!\n"); |
95 cdev_del(&xmldev->cdev); |
96 cdev_del(&xmldev->cdev); |
96 } |
97 } |
97 |
98 |
98 /*****************************************************************************/ |
99 /*****************************************************************************/ |
99 |
100 |
|
101 int ec_xmldev_request(ec_xmldev_t *xmldev, |
|
102 uint32_t vendor_id, |
|
103 uint32_t product_code |
|
104 ) |
|
105 { |
|
106 return 1; |
|
107 } |
|
108 |
|
109 /****************************************************************************** |
|
110 * file_operations |
|
111 *****************************************************************************/ |
|
112 |
100 int ecxmldev_open(struct inode *inode, struct file *filp) |
113 int ecxmldev_open(struct inode *inode, struct file *filp) |
101 { |
114 { |
102 ec_xmldev_t *xmldev; |
115 ec_xmldev_t *xmldev; |
103 |
116 |
104 xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); |
117 xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); |
|
118 |
|
119 if (!atomic_dec_and_test(&xmldev->available)) { |
|
120 atomic_inc(&xmldev->available); |
|
121 return -EBUSY; |
|
122 } |
|
123 |
105 filp->private_data = xmldev; |
124 filp->private_data = xmldev; |
106 |
125 |
107 EC_DBG("File opened.\n"); |
126 EC_DBG("File opened.\n"); |
108 |
127 |
109 return 0; |
128 return 0; |
111 |
130 |
112 /*****************************************************************************/ |
131 /*****************************************************************************/ |
113 |
132 |
114 int ecxmldev_release(struct inode *inode, struct file *filp) |
133 int ecxmldev_release(struct inode *inode, struct file *filp) |
115 { |
134 { |
|
135 ec_xmldev_t *xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); |
|
136 atomic_inc(&xmldev->available); |
116 EC_DBG("File closed.\n"); |
137 EC_DBG("File closed.\n"); |
117 return 0; |
138 return 0; |
118 } |
139 } |
119 |
140 |
120 /*****************************************************************************/ |
141 /*****************************************************************************/ |