aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/cec/cec-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/cec/cec-core.c')
-rw-r--r--drivers/media/cec/cec-core.c72
1 files changed, 59 insertions, 13 deletions
diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index a9f9525db9ae..b0c87f9ea08f 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -1,20 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0-only
1/* 2/*
2 * cec-core.c - HDMI Consumer Electronics Control framework - Core 3 * cec-core.c - HDMI Consumer Electronics Control framework - Core
3 * 4 *
4 * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 5 * 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 */ 6 */
19 7
20#include <linux/errno.h> 8#include <linux/errno.h>
@@ -207,6 +195,55 @@ void cec_register_cec_notifier(struct cec_adapter *adap,
207EXPORT_SYMBOL_GPL(cec_register_cec_notifier); 195EXPORT_SYMBOL_GPL(cec_register_cec_notifier);
208#endif 196#endif
209 197
198#ifdef CONFIG_DEBUG_FS
199static ssize_t cec_error_inj_write(struct file *file,
200 const char __user *ubuf, size_t count, loff_t *ppos)
201{
202 struct seq_file *sf = file->private_data;
203 struct cec_adapter *adap = sf->private;
204 char *buf;
205 char *line;
206 char *p;
207
208 buf = memdup_user_nul(ubuf, min_t(size_t, PAGE_SIZE, count));
209 if (IS_ERR(buf))
210 return PTR_ERR(buf);
211 p = buf;
212 while (p && *p) {
213 p = skip_spaces(p);
214 line = strsep(&p, "\n");
215 if (!*line || *line == '#')
216 continue;
217 if (!adap->ops->error_inj_parse_line(adap, line)) {
218 kfree(buf);
219 return -EINVAL;
220 }
221 }
222 kfree(buf);
223 return count;
224}
225
226static int cec_error_inj_show(struct seq_file *sf, void *unused)
227{
228 struct cec_adapter *adap = sf->private;
229
230 return adap->ops->error_inj_show(adap, sf);
231}
232
233static int cec_error_inj_open(struct inode *inode, struct file *file)
234{
235 return single_open(file, cec_error_inj_show, inode->i_private);
236}
237
238static const struct file_operations cec_error_inj_fops = {
239 .open = cec_error_inj_open,
240 .write = cec_error_inj_write,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = single_release,
244};
245#endif
246
210struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, 247struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
211 void *priv, const char *name, u32 caps, 248 void *priv, const char *name, u32 caps,
212 u8 available_las) 249 u8 available_las)
@@ -346,7 +383,16 @@ int cec_register_adapter(struct cec_adapter *adap,
346 pr_warn("cec-%s: Failed to create status file\n", adap->name); 383 pr_warn("cec-%s: Failed to create status file\n", adap->name);
347 debugfs_remove_recursive(adap->cec_dir); 384 debugfs_remove_recursive(adap->cec_dir);
348 adap->cec_dir = NULL; 385 adap->cec_dir = NULL;
386 return 0;
349 } 387 }
388 if (!adap->ops->error_inj_show || !adap->ops->error_inj_parse_line)
389 return 0;
390 adap->error_inj_file = debugfs_create_file("error-inj", 0644,
391 adap->cec_dir, adap,
392 &cec_error_inj_fops);
393 if (IS_ERR_OR_NULL(adap->error_inj_file))
394 pr_warn("cec-%s: Failed to create error-inj file\n",
395 adap->name);
350#endif 396#endif
351 return 0; 397 return 0;
352} 398}