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
wl1271_sysfs_show_bt_coex_state(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
wl1271_sysfs_store_bt_coex_state(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_get_sync(wl
->dev
);
61 pm_runtime_put_noidle(wl
->dev
);
65 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
66 pm_runtime_mark_last_busy(wl
->dev
);
67 pm_runtime_put_autosuspend(wl
->dev
);
70 mutex_unlock(&wl
->mutex
);
74 static DEVICE_ATTR(bt_coex_state
, 0644,
75 wl1271_sysfs_show_bt_coex_state
,
76 wl1271_sysfs_store_bt_coex_state
);
78 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
79 struct device_attribute
*attr
,
82 struct wl1271
*wl
= dev_get_drvdata(dev
);
87 mutex_lock(&wl
->mutex
);
88 if (wl
->hw_pg_ver
>= 0)
89 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
91 len
= snprintf(buf
, len
, "n/a\n");
92 mutex_unlock(&wl
->mutex
);
97 static DEVICE_ATTR(hw_pg_ver
, 0444, wl1271_sysfs_show_hw_pg_ver
, NULL
);
99 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
100 struct bin_attribute
*bin_attr
,
101 char *buffer
, loff_t pos
, size_t count
)
103 struct device
*dev
= kobj_to_dev(kobj
);
104 struct wl1271
*wl
= dev_get_drvdata(dev
);
108 ret
= mutex_lock_interruptible(&wl
->mutex
);
112 /* Check if the fwlog is still valid */
113 if (wl
->fwlog_size
< 0) {
114 mutex_unlock(&wl
->mutex
);
118 /* Seeking is not supported - old logs are not kept. Disregard pos. */
119 len
= min_t(size_t, count
, wl
->fwlog_size
);
120 wl
->fwlog_size
-= len
;
121 memcpy(buffer
, wl
->fwlog
, len
);
123 /* Make room for new messages */
124 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
126 mutex_unlock(&wl
->mutex
);
131 static const struct bin_attribute fwlog_attr
= {
132 .attr
= { .name
= "fwlog", .mode
= 0400 },
133 .read
= wl1271_sysfs_read_fwlog
,
136 int wlcore_sysfs_init(struct wl1271
*wl
)
140 /* Create sysfs file to control bt coex state */
141 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
143 wl1271_error("failed to create sysfs file bt_coex_state");
147 /* Create sysfs file to get HW PG version */
148 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
150 wl1271_error("failed to create sysfs file hw_pg_ver");
151 goto out_bt_coex_state
;
154 /* Create sysfs file for the FW log */
155 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
157 wl1271_error("failed to create sysfs file fwlog");
164 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
167 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
173 void wlcore_sysfs_free(struct wl1271
*wl
)
175 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
177 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
179 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);