1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wlcore
5 * Copyright (C) 2013 Texas Instruments Inc.
8 #include <linux/pm_runtime.h>
15 static ssize_t bt_coex_state_show(struct device *dev,
16 struct device_attribute *attr,
19 struct wl1271 *wl = dev_get_drvdata(dev);
24 mutex_lock(&wl->mutex);
25 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
27 mutex_unlock(&wl->mutex);
33 static ssize_t bt_coex_state_store(struct device *dev,
34 struct device_attribute *attr,
35 const char *buf, size_t count)
37 struct wl1271 *wl = dev_get_drvdata(dev);
41 ret = kstrtoul(buf, 10, &res);
43 wl1271_warning("incorrect value written to bt_coex_mode");
47 mutex_lock(&wl->mutex);
51 if (res == wl->sg_enabled)
56 if (unlikely(wl->state != WLCORE_STATE_ON))
59 ret = pm_runtime_resume_and_get(wl->dev);
63 wl1271_acx_sg_enable(wl, wl->sg_enabled);
64 pm_runtime_mark_last_busy(wl->dev);
65 pm_runtime_put_autosuspend(wl->dev);
68 mutex_unlock(&wl->mutex);
72 static DEVICE_ATTR_RW(bt_coex_state);
74 static ssize_t hw_pg_ver_show(struct device *dev,
75 struct device_attribute *attr,
78 struct wl1271 *wl = dev_get_drvdata(dev);
83 mutex_lock(&wl->mutex);
84 if (wl->hw_pg_ver >= 0)
85 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
87 len = snprintf(buf, len, "n/a\n");
88 mutex_unlock(&wl->mutex);
93 static DEVICE_ATTR_RO(hw_pg_ver);
95 static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
96 struct bin_attribute *bin_attr,
97 char *buffer, loff_t pos, size_t count)
99 struct device *dev = kobj_to_dev(kobj);
100 struct wl1271 *wl = dev_get_drvdata(dev);
104 ret = mutex_lock_interruptible(&wl->mutex);
108 /* Check if the fwlog is still valid */
109 if (wl->fwlog_size < 0) {
110 mutex_unlock(&wl->mutex);
114 /* Seeking is not supported - old logs are not kept. Disregard pos. */
115 len = min_t(size_t, count, wl->fwlog_size);
116 wl->fwlog_size -= len;
117 memcpy(buffer, wl->fwlog, len);
119 /* Make room for new messages */
120 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
122 mutex_unlock(&wl->mutex);
127 static const struct bin_attribute fwlog_attr = {
128 .attr = { .name = "fwlog", .mode = 0400 },
129 .read = wl1271_sysfs_read_fwlog,
132 int wlcore_sysfs_init(struct wl1271 *wl)
136 /* Create sysfs file to control bt coex state */
137 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
139 wl1271_error("failed to create sysfs file bt_coex_state");
143 /* Create sysfs file to get HW PG version */
144 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
146 wl1271_error("failed to create sysfs file hw_pg_ver");
147 goto out_bt_coex_state;
150 /* Create sysfs file for the FW log */
151 ret = device_create_bin_file(wl->dev, &fwlog_attr);
153 wl1271_error("failed to create sysfs file fwlog");
160 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
163 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
169 void wlcore_sysfs_free(struct wl1271 *wl)
171 device_remove_bin_file(wl->dev, &fwlog_attr);
173 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
175 device_remove_file(wl->dev, &dev_attr_bt_coex_state);