1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/fs.h>
21#include <linux/proc_fs.h>
22#include <linux/uaccess.h>
23
24#include "smd_private.h"
25
26static void *radio_log_base;
27static size_t radio_log_size;
28
29extern void *smem_item(unsigned id, unsigned *size);
30
31static ssize_t last_radio_log_read(struct file *file, char __user *buf,
32 size_t len, loff_t *offset)
33{
34 loff_t pos = *offset;
35 ssize_t count;
36
37 if (pos >= radio_log_size)
38 return 0;
39
40 count = min(len, (size_t)(radio_log_size - pos));
41 if (copy_to_user(buf, radio_log_base + pos, count)) {
42 pr_err("%s: copy to user failed\n", __func__);
43 return -EFAULT;
44 }
45
46 *offset += count;
47 return count;
48}
49
50static struct file_operations last_radio_log_fops = {
51 .read = last_radio_log_read,
52 .llseek = default_llseek,
53};
54
55void msm_init_last_radio_log(struct module *owner)
56{
57 struct proc_dir_entry *entry;
58
59 if (last_radio_log_fops.owner) {
60 pr_err("%s: already claimed\n", __func__);
61 return;
62 }
63
64 radio_log_base = smem_item(SMEM_CLKREGIM_BSP, &radio_log_size);
65 if (!radio_log_base) {
66 pr_err("%s: could not retrieve SMEM_CLKREGIM_BSP\n", __func__);
67 return;
68 }
69
70 entry = create_proc_entry("last_radio_log", S_IFREG | S_IRUGO, NULL);
71 if (!entry) {
72 pr_err("%s: could not create proc entry for radio log\n",
73 __func__);
74 return;
75 }
76
77 pr_err("%s: last radio log is %d bytes long\n", __func__,
78 radio_log_size);
79 last_radio_log_fops.owner = owner;
80 entry->proc_fops = &last_radio_log_fops;
81 entry->size = radio_log_size;
82}
83EXPORT_SYMBOL(msm_init_last_radio_log);
84