Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cec-core.c - HDMI Consumer Electronics Control framework - Core |
| 3 | * |
| 4 | * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you may redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 11 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 12 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 13 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 14 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 16 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 17 | * SOFTWARE. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/kmod.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/string.h> |
| 28 | #include <linux/types.h> |
| 29 | |
| 30 | #include "cec-priv.h" |
| 31 | |
| 32 | #define CEC_NUM_DEVICES 256 |
| 33 | #define CEC_NAME "cec" |
| 34 | |
| 35 | int cec_debug; |
| 36 | module_param_named(debug, cec_debug, int, 0644); |
| 37 | MODULE_PARM_DESC(debug, "debug level (0-2)"); |
| 38 | |
| 39 | static dev_t cec_dev_t; |
| 40 | |
| 41 | /* Active devices */ |
| 42 | static DEFINE_MUTEX(cec_devnode_lock); |
| 43 | static DECLARE_BITMAP(cec_devnode_nums, CEC_NUM_DEVICES); |
| 44 | |
| 45 | static struct dentry *top_cec_dir; |
| 46 | |
| 47 | /* dev to cec_devnode */ |
| 48 | #define to_cec_devnode(cd) container_of(cd, struct cec_devnode, dev) |
| 49 | |
| 50 | int cec_get_device(struct cec_devnode *devnode) |
| 51 | { |
| 52 | /* |
| 53 | * Check if the cec device is available. This needs to be done with |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 54 | * the devnode->lock held to prevent an open/unregister race: |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 55 | * without the lock, the device could be unregistered and freed between |
| 56 | * the devnode->registered check and get_device() calls, leading to |
| 57 | * a crash. |
| 58 | */ |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 59 | mutex_lock(&devnode->lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 60 | /* |
| 61 | * return ENXIO if the cec device has been removed |
| 62 | * already or if it is not registered anymore. |
| 63 | */ |
| 64 | if (!devnode->registered) { |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 65 | mutex_unlock(&devnode->lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 66 | return -ENXIO; |
| 67 | } |
| 68 | /* and increase the device refcount */ |
| 69 | get_device(&devnode->dev); |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 70 | mutex_unlock(&devnode->lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | void cec_put_device(struct cec_devnode *devnode) |
| 75 | { |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 76 | put_device(&devnode->dev); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* Called when the last user of the cec device exits. */ |
| 80 | static void cec_devnode_release(struct device *cd) |
| 81 | { |
| 82 | struct cec_devnode *devnode = to_cec_devnode(cd); |
| 83 | |
| 84 | mutex_lock(&cec_devnode_lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 85 | /* Mark device node number as free */ |
| 86 | clear_bit(devnode->minor, cec_devnode_nums); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 87 | mutex_unlock(&cec_devnode_lock); |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 88 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 89 | cec_delete_adapter(to_cec_adapter(devnode)); |
| 90 | } |
| 91 | |
| 92 | static struct bus_type cec_bus_type = { |
| 93 | .name = CEC_NAME, |
| 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * Register a cec device node |
| 98 | * |
| 99 | * The registration code assigns minor numbers and registers the new device node |
| 100 | * with the kernel. An error is returned if no free minor number can be found, |
| 101 | * or if the registration of the device node fails. |
| 102 | * |
| 103 | * Zero is returned on success. |
| 104 | * |
| 105 | * Note that if the cec_devnode_register call fails, the release() callback of |
| 106 | * the cec_devnode structure is *not* called, so the caller is responsible for |
| 107 | * freeing any data. |
| 108 | */ |
| 109 | static int __must_check cec_devnode_register(struct cec_devnode *devnode, |
| 110 | struct module *owner) |
| 111 | { |
| 112 | int minor; |
| 113 | int ret; |
| 114 | |
| 115 | /* Initialization */ |
| 116 | INIT_LIST_HEAD(&devnode->fhs); |
Hans Verkuil | 62148f0 | 2016-08-02 08:11:00 -0300 | [diff] [blame] | 117 | mutex_init(&devnode->lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 118 | |
| 119 | /* Part 1: Find a free minor number */ |
| 120 | mutex_lock(&cec_devnode_lock); |
| 121 | minor = find_next_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES, 0); |
| 122 | if (minor == CEC_NUM_DEVICES) { |
| 123 | mutex_unlock(&cec_devnode_lock); |
| 124 | pr_err("could not get a free minor\n"); |
| 125 | return -ENFILE; |
| 126 | } |
| 127 | |
| 128 | set_bit(minor, cec_devnode_nums); |
| 129 | mutex_unlock(&cec_devnode_lock); |
| 130 | |
| 131 | devnode->minor = minor; |
| 132 | devnode->dev.bus = &cec_bus_type; |
| 133 | devnode->dev.devt = MKDEV(MAJOR(cec_dev_t), minor); |
| 134 | devnode->dev.release = cec_devnode_release; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 135 | dev_set_name(&devnode->dev, "cec%d", devnode->minor); |
| 136 | device_initialize(&devnode->dev); |
| 137 | |
| 138 | /* Part 2: Initialize and register the character device */ |
| 139 | cdev_init(&devnode->cdev, &cec_devnode_fops); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 140 | devnode->cdev.owner = owner; |
| 141 | |
Logan Gunthorpe | 857313e | 2017-03-17 12:48:18 -0600 | [diff] [blame] | 142 | ret = cdev_device_add(&devnode->cdev, &devnode->dev); |
| 143 | if (ret) { |
| 144 | pr_err("%s: cdev_device_add failed\n", __func__); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 145 | goto clr_bit; |
| 146 | } |
| 147 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 148 | devnode->registered = true; |
| 149 | return 0; |
| 150 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 151 | clr_bit: |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 152 | mutex_lock(&cec_devnode_lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 153 | clear_bit(devnode->minor, cec_devnode_nums); |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 154 | mutex_unlock(&cec_devnode_lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Unregister a cec device node |
| 160 | * |
| 161 | * This unregisters the passed device. Future open calls will be met with |
| 162 | * errors. |
| 163 | * |
| 164 | * This function can safely be called if the device node has never been |
| 165 | * registered or has already been unregistered. |
| 166 | */ |
| 167 | static void cec_devnode_unregister(struct cec_devnode *devnode) |
| 168 | { |
| 169 | struct cec_fh *fh; |
| 170 | |
Hans Verkuil | 62148f0 | 2016-08-02 08:11:00 -0300 | [diff] [blame] | 171 | mutex_lock(&devnode->lock); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 172 | |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 173 | /* Check if devnode was never registered or already unregistered */ |
| 174 | if (!devnode->registered || devnode->unregistered) { |
| 175 | mutex_unlock(&devnode->lock); |
| 176 | return; |
| 177 | } |
| 178 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 179 | list_for_each_entry(fh, &devnode->fhs, list) |
| 180 | wake_up_interruptible(&fh->wait); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 181 | |
| 182 | devnode->registered = false; |
| 183 | devnode->unregistered = true; |
Hans Verkuil | 2ab25d3 | 2016-08-02 08:13:57 -0300 | [diff] [blame] | 184 | mutex_unlock(&devnode->lock); |
| 185 | |
Logan Gunthorpe | 857313e | 2017-03-17 12:48:18 -0600 | [diff] [blame] | 186 | cdev_device_del(&devnode->cdev, &devnode->dev); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 187 | put_device(&devnode->dev); |
| 188 | } |
| 189 | |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 190 | #ifdef CONFIG_CEC_NOTIFIER |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 191 | static void cec_cec_notify(struct cec_adapter *adap, u16 pa) |
| 192 | { |
| 193 | cec_s_phys_addr(adap, pa, false); |
| 194 | } |
| 195 | |
| 196 | void cec_register_cec_notifier(struct cec_adapter *adap, |
| 197 | struct cec_notifier *notifier) |
| 198 | { |
| 199 | if (WARN_ON(!adap->devnode.registered)) |
| 200 | return; |
| 201 | |
| 202 | adap->notifier = notifier; |
| 203 | cec_notifier_register(adap->notifier, adap, cec_cec_notify); |
| 204 | } |
| 205 | EXPORT_SYMBOL_GPL(cec_register_cec_notifier); |
| 206 | #endif |
| 207 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 208 | struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, |
| 209 | void *priv, const char *name, u32 caps, |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 210 | u8 available_las) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 211 | { |
| 212 | struct cec_adapter *adap; |
| 213 | int res; |
| 214 | |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 215 | #ifndef CONFIG_MEDIA_CEC_RC |
Hans Verkuil | ee044f5 | 2017-04-04 13:43:33 -0300 | [diff] [blame] | 216 | caps &= ~CEC_CAP_RC; |
| 217 | #endif |
| 218 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 219 | if (WARN_ON(!caps)) |
| 220 | return ERR_PTR(-EINVAL); |
| 221 | if (WARN_ON(!ops)) |
| 222 | return ERR_PTR(-EINVAL); |
| 223 | if (WARN_ON(!available_las || available_las > CEC_MAX_LOG_ADDRS)) |
| 224 | return ERR_PTR(-EINVAL); |
| 225 | adap = kzalloc(sizeof(*adap), GFP_KERNEL); |
| 226 | if (!adap) |
| 227 | return ERR_PTR(-ENOMEM); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 228 | strlcpy(adap->name, name, sizeof(adap->name)); |
| 229 | adap->phys_addr = CEC_PHYS_ADDR_INVALID; |
| 230 | adap->log_addrs.cec_version = CEC_OP_CEC_VERSION_2_0; |
| 231 | adap->log_addrs.vendor_id = CEC_VENDOR_ID_NONE; |
| 232 | adap->capabilities = caps; |
Hans Verkuil | f902c1e | 2017-06-07 11:46:12 -0300 | [diff] [blame] | 233 | adap->needs_hpd = caps & CEC_CAP_NEEDS_HPD; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 234 | adap->available_log_addrs = available_las; |
| 235 | adap->sequence = 0; |
| 236 | adap->ops = ops; |
| 237 | adap->priv = priv; |
| 238 | memset(adap->phys_addrs, 0xff, sizeof(adap->phys_addrs)); |
| 239 | mutex_init(&adap->lock); |
| 240 | INIT_LIST_HEAD(&adap->transmit_queue); |
| 241 | INIT_LIST_HEAD(&adap->wait_queue); |
| 242 | init_waitqueue_head(&adap->kthread_waitq); |
| 243 | |
| 244 | adap->kthread = kthread_run(cec_thread_func, adap, "cec-%s", name); |
| 245 | if (IS_ERR(adap->kthread)) { |
| 246 | pr_err("cec-%s: kernel_thread() failed\n", name); |
| 247 | res = PTR_ERR(adap->kthread); |
| 248 | kfree(adap); |
| 249 | return ERR_PTR(res); |
| 250 | } |
| 251 | |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 252 | #ifdef CONFIG_MEDIA_CEC_RC |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 253 | if (!(caps & CEC_CAP_RC)) |
| 254 | return adap; |
| 255 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 256 | /* Prepare the RC input device */ |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 257 | adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 258 | if (!adap->rc) { |
| 259 | pr_err("cec-%s: failed to allocate memory for rc_dev\n", |
| 260 | name); |
| 261 | kthread_stop(adap->kthread); |
| 262 | kfree(adap); |
| 263 | return ERR_PTR(-ENOMEM); |
| 264 | } |
| 265 | |
| 266 | snprintf(adap->input_name, sizeof(adap->input_name), |
| 267 | "RC for %s", name); |
| 268 | snprintf(adap->input_phys, sizeof(adap->input_phys), |
| 269 | "%s/input0", name); |
| 270 | |
| 271 | adap->rc->input_name = adap->input_name; |
| 272 | adap->rc->input_phys = adap->input_phys; |
| 273 | adap->rc->input_id.bustype = BUS_CEC; |
| 274 | adap->rc->input_id.vendor = 0; |
| 275 | adap->rc->input_id.product = 0; |
| 276 | adap->rc->input_id.version = 1; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 277 | adap->rc->driver_name = CEC_NAME; |
| 278 | adap->rc->allowed_protocols = RC_BIT_CEC; |
| 279 | adap->rc->priv = adap; |
| 280 | adap->rc->map_name = RC_MAP_CEC; |
| 281 | adap->rc->timeout = MS_TO_NS(100); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 282 | #endif |
| 283 | return adap; |
| 284 | } |
| 285 | EXPORT_SYMBOL_GPL(cec_allocate_adapter); |
| 286 | |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 287 | int cec_register_adapter(struct cec_adapter *adap, |
| 288 | struct device *parent) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 289 | { |
| 290 | int res; |
| 291 | |
| 292 | if (IS_ERR_OR_NULL(adap)) |
| 293 | return 0; |
| 294 | |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 295 | if (WARN_ON(!parent)) |
| 296 | return -EINVAL; |
| 297 | |
| 298 | adap->owner = parent->driver->owner; |
| 299 | adap->devnode.dev.parent = parent; |
| 300 | |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 301 | #ifdef CONFIG_MEDIA_CEC_RC |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 302 | if (adap->capabilities & CEC_CAP_RC) { |
Lee Jones | 43c0c03 | 2017-04-04 09:32:19 -0300 | [diff] [blame] | 303 | adap->rc->dev.parent = parent; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 304 | res = rc_register_device(adap->rc); |
| 305 | |
| 306 | if (res) { |
| 307 | pr_err("cec-%s: failed to prepare input device\n", |
| 308 | adap->name); |
| 309 | rc_free_device(adap->rc); |
| 310 | adap->rc = NULL; |
| 311 | return res; |
| 312 | } |
| 313 | } |
| 314 | #endif |
| 315 | |
| 316 | res = cec_devnode_register(&adap->devnode, adap->owner); |
| 317 | if (res) { |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 318 | #ifdef CONFIG_MEDIA_CEC_RC |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 319 | /* Note: rc_unregister also calls rc_free */ |
| 320 | rc_unregister_device(adap->rc); |
| 321 | adap->rc = NULL; |
| 322 | #endif |
| 323 | return res; |
| 324 | } |
| 325 | |
| 326 | dev_set_drvdata(&adap->devnode.dev, adap); |
Hans Verkuil | 20249f8 | 2017-05-28 05:52:16 -0300 | [diff] [blame] | 327 | #ifdef CONFIG_DEBUG_FS |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 328 | if (!top_cec_dir) |
| 329 | return 0; |
| 330 | |
| 331 | adap->cec_dir = debugfs_create_dir(dev_name(&adap->devnode.dev), top_cec_dir); |
| 332 | if (IS_ERR_OR_NULL(adap->cec_dir)) { |
| 333 | pr_warn("cec-%s: Failed to create debugfs dir\n", adap->name); |
| 334 | return 0; |
| 335 | } |
| 336 | adap->status_file = debugfs_create_devm_seqfile(&adap->devnode.dev, |
| 337 | "status", adap->cec_dir, cec_adap_status); |
| 338 | if (IS_ERR_OR_NULL(adap->status_file)) { |
| 339 | pr_warn("cec-%s: Failed to create status file\n", adap->name); |
| 340 | debugfs_remove_recursive(adap->cec_dir); |
| 341 | adap->cec_dir = NULL; |
| 342 | } |
| 343 | #endif |
| 344 | return 0; |
| 345 | } |
| 346 | EXPORT_SYMBOL_GPL(cec_register_adapter); |
| 347 | |
| 348 | void cec_unregister_adapter(struct cec_adapter *adap) |
| 349 | { |
| 350 | if (IS_ERR_OR_NULL(adap)) |
| 351 | return; |
| 352 | |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 353 | #ifdef CONFIG_MEDIA_CEC_RC |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 354 | /* Note: rc_unregister also calls rc_free */ |
| 355 | rc_unregister_device(adap->rc); |
| 356 | adap->rc = NULL; |
| 357 | #endif |
| 358 | debugfs_remove_recursive(adap->cec_dir); |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 359 | #ifdef CONFIG_CEC_NOTIFIER |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 360 | if (adap->notifier) |
| 361 | cec_notifier_unregister(adap->notifier); |
| 362 | #endif |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 363 | cec_devnode_unregister(&adap->devnode); |
| 364 | } |
| 365 | EXPORT_SYMBOL_GPL(cec_unregister_adapter); |
| 366 | |
| 367 | void cec_delete_adapter(struct cec_adapter *adap) |
| 368 | { |
| 369 | if (IS_ERR_OR_NULL(adap)) |
| 370 | return; |
| 371 | mutex_lock(&adap->lock); |
| 372 | __cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); |
| 373 | mutex_unlock(&adap->lock); |
| 374 | kthread_stop(adap->kthread); |
| 375 | if (adap->kthread_config) |
| 376 | kthread_stop(adap->kthread_config); |
Hans Verkuil | 5f2c467 | 2017-04-17 08:05:10 -0300 | [diff] [blame] | 377 | #ifdef CONFIG_MEDIA_CEC_RC |
Markus Elfring | d8eddb1 | 2016-07-17 17:52:49 -0300 | [diff] [blame] | 378 | rc_free_device(adap->rc); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 379 | #endif |
| 380 | kfree(adap); |
| 381 | } |
| 382 | EXPORT_SYMBOL_GPL(cec_delete_adapter); |
| 383 | |
| 384 | /* |
| 385 | * Initialise cec for linux |
| 386 | */ |
| 387 | static int __init cec_devnode_init(void) |
| 388 | { |
| 389 | int ret; |
| 390 | |
| 391 | pr_info("Linux cec interface: v0.10\n"); |
| 392 | ret = alloc_chrdev_region(&cec_dev_t, 0, CEC_NUM_DEVICES, |
| 393 | CEC_NAME); |
| 394 | if (ret < 0) { |
| 395 | pr_warn("cec: unable to allocate major\n"); |
| 396 | return ret; |
| 397 | } |
| 398 | |
Hans Verkuil | 20249f8 | 2017-05-28 05:52:16 -0300 | [diff] [blame] | 399 | #ifdef CONFIG_DEBUG_FS |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 400 | top_cec_dir = debugfs_create_dir("cec", NULL); |
| 401 | if (IS_ERR_OR_NULL(top_cec_dir)) { |
| 402 | pr_warn("cec: Failed to create debugfs cec dir\n"); |
| 403 | top_cec_dir = NULL; |
| 404 | } |
| 405 | #endif |
| 406 | |
| 407 | ret = bus_register(&cec_bus_type); |
| 408 | if (ret < 0) { |
| 409 | unregister_chrdev_region(cec_dev_t, CEC_NUM_DEVICES); |
| 410 | pr_warn("cec: bus_register failed\n"); |
| 411 | return -EIO; |
| 412 | } |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static void __exit cec_devnode_exit(void) |
| 418 | { |
| 419 | debugfs_remove_recursive(top_cec_dir); |
| 420 | bus_unregister(&cec_bus_type); |
| 421 | unregister_chrdev_region(cec_dev_t, CEC_NUM_DEVICES); |
| 422 | } |
| 423 | |
| 424 | subsys_initcall(cec_devnode_init); |
| 425 | module_exit(cec_devnode_exit) |
| 426 | |
| 427 | MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>"); |
| 428 | MODULE_DESCRIPTION("Device node registration for cec drivers"); |
| 429 | MODULE_LICENSE("GPL"); |