2 * This file is part of wlcore
4 * Copyright (C) 2013 Texas Instruments Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
28 struct device_attribute
*attr
,
31 struct wl1271
*wl
= dev_get_drvdata(dev
);
36 mutex_lock(&wl
->mutex
);
37 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
39 mutex_unlock(&wl
->mutex
);
45 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
46 struct device_attribute
*attr
,
47 const char *buf
, size_t count
)
49 struct wl1271
*wl
= dev_get_drvdata(dev
);
53 ret
= kstrtoul(buf
, 10, &res
);
55 wl1271_warning("incorrect value written to bt_coex_mode");
59 mutex_lock(&wl
->mutex
);
63 if (res
== wl
->sg_enabled
)
68 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
71 ret
= wl1271_ps_elp_wakeup(wl
);
75 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
76 wl1271_ps_elp_sleep(wl
);
79 mutex_unlock(&wl
->mutex
);
83 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
84 wl1271_sysfs_show_bt_coex_state
,
85 wl1271_sysfs_store_bt_coex_state
);
87 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
88 struct device_attribute
*attr
,
91 struct wl1271
*wl
= dev_get_drvdata(dev
);
96 mutex_lock(&wl
->mutex
);
97 if (wl
->hw_pg_ver
>= 0)
98 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
100 len
= snprintf(buf
, len
, "n/a\n");
101 mutex_unlock(&wl
->mutex
);
106 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
107 wl1271_sysfs_show_hw_pg_ver
, NULL
);
109 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
110 struct bin_attribute
*bin_attr
,
111 char *buffer
, loff_t pos
, size_t count
)
113 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
114 struct wl1271
*wl
= dev_get_drvdata(dev
);
118 ret
= mutex_lock_interruptible(&wl
->mutex
);
122 /* Let only one thread read the log at a time, blocking others */
123 while (wl
->fwlog_size
== 0) {
126 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
130 if (wl
->fwlog_size
!= 0) {
131 finish_wait(&wl
->fwlog_waitq
, &wait
);
135 mutex_unlock(&wl
->mutex
);
138 finish_wait(&wl
->fwlog_waitq
, &wait
);
140 if (signal_pending(current
))
143 ret
= mutex_lock_interruptible(&wl
->mutex
);
148 /* Check if the fwlog is still valid */
149 if (wl
->fwlog_size
< 0) {
150 mutex_unlock(&wl
->mutex
);
154 /* Seeking is not supported - old logs are not kept. Disregard pos. */
155 len
= min(count
, (size_t)wl
->fwlog_size
);
156 wl
->fwlog_size
-= len
;
157 memcpy(buffer
, wl
->fwlog
, len
);
159 /* Make room for new messages */
160 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
162 mutex_unlock(&wl
->mutex
);
167 static struct bin_attribute fwlog_attr
= {
168 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
169 .read
= wl1271_sysfs_read_fwlog
,
172 int wlcore_sysfs_init(struct wl1271
*wl
)
176 /* Create sysfs file to control bt coex state */
177 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
179 wl1271_error("failed to create sysfs file bt_coex_state");
183 /* Create sysfs file to get HW PG version */
184 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
186 wl1271_error("failed to create sysfs file hw_pg_ver");
187 goto out_bt_coex_state
;
190 /* Create sysfs file for the FW log */
191 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
193 wl1271_error("failed to create sysfs file fwlog");
200 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
203 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
209 void wlcore_sysfs_free(struct wl1271
*wl
)
211 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
213 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
215 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);