Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
43cdd1b
Documentation
arch
block
certs
crypto
drivers
accessibility
acpi
acpica
apei
arm64
dptf
nfit
pmic
x86
Kconfig
Makefile
ac.c
acpi_amba.c
acpi_apd.c
acpi_cmos_rtc.c
acpi_configfs.c
acpi_dbg.c
acpi_extlog.c
acpi_ipmi.c
acpi_lpat.c
acpi_lpit.c
acpi_lpss.c
acpi_memhotplug.c
acpi_pad.c
acpi_platform.c
acpi_pnp.c
acpi_processor.c
acpi_video.c
acpi_watchdog.c
battery.c
battery.h
bgrt.c
blacklist.c
bus.c
button.c
cm_sbs.c
container.c
cppc_acpi.c
custom_method.c
debugfs.c
device_pm.c
device_sysfs.c
dock.c
ec.c
ec_sys.c
event.c
evged.c
fan.c
glue.c
hed.c
internal.h
ioapic.c
irq.c
numa.c
nvs.c
osi.c
osl.c
pci_irq.c
pci_link.c
pci_mcfg.c
pci_root.c
pci_slot.c
power.c
proc.c
processor_core.c
processor_driver.c
processor_idle.c
processor_pdc.c
processor_perflib.c
processor_thermal.c
processor_throttling.c
property.c
reboot.c
resource.c
sbs.c
sbshc.c
sbshc.h
scan.c
sleep.c
sleep.h
spcr.c
sysfs.c
tables.c
thermal.c
utils.c
video_detect.c
wakeup.c
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fmc
fpga
fsi
gpio
gpu
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
ide
idle
iio
infiniband
input
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
sn
soc
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
uwb
vfio
vhost
video
virt
virtio
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
acpi
/
sbshc.c
Copy path
Blame
Blame
Latest commit
History
History
304 lines (261 loc) · 7.18 KB
Breadcrumbs
linux
/
drivers
/
acpi
/
sbshc.c
Top
File metadata and controls
Code
Blame
304 lines (261 loc) · 7.18 KB
Raw
/* * SMBus driver for ACPI Embedded Controller (v0.1) * * Copyright (c) 2007 Alexey Starikovskiy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 2. */ #include <linux/acpi.h> #include <linux/wait.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/interrupt.h> #include "sbshc.h" #define PREFIX "ACPI: " #define ACPI_SMB_HC_CLASS "smbus_host_ctl" #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC" struct acpi_smb_hc { struct acpi_ec *ec; struct mutex lock; wait_queue_head_t wait; u8 offset; u8 query_bit; smbus_alarm_callback callback; void *context; bool done; }; static int acpi_smbus_hc_add(struct acpi_device *device); static int acpi_smbus_hc_remove(struct acpi_device *device); static const struct acpi_device_id sbs_device_ids[] = { {"ACPI0001", 0}, {"ACPI0005", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, sbs_device_ids); static struct acpi_driver acpi_smb_hc_driver = { .name = "smbus_hc", .class = ACPI_SMB_HC_CLASS, .ids = sbs_device_ids, .ops = { .add = acpi_smbus_hc_add, .remove = acpi_smbus_hc_remove, }, }; union acpi_smb_status { u8 raw; struct { u8 status:5; u8 reserved:1; u8 alarm:1; u8 done:1; } fields; }; enum acpi_smb_status_codes { SMBUS_OK = 0, SMBUS_UNKNOWN_FAILURE = 0x07, SMBUS_DEVICE_ADDRESS_NACK = 0x10, SMBUS_DEVICE_ERROR = 0x11, SMBUS_DEVICE_COMMAND_ACCESS_DENIED = 0x12, SMBUS_UNKNOWN_ERROR = 0x13, SMBUS_DEVICE_ACCESS_DENIED = 0x17, SMBUS_TIMEOUT = 0x18, SMBUS_HOST_UNSUPPORTED_PROTOCOL = 0x19, SMBUS_BUSY = 0x1a, SMBUS_PEC_ERROR = 0x1f, }; enum acpi_smb_offset { ACPI_SMB_PROTOCOL = 0, /* protocol, PEC */ ACPI_SMB_STATUS = 1, /* status */ ACPI_SMB_ADDRESS = 2, /* address */ ACPI_SMB_COMMAND = 3, /* command */ ACPI_SMB_DATA = 4, /* 32 data registers */ ACPI_SMB_BLOCK_COUNT = 0x24, /* number of data bytes */ ACPI_SMB_ALARM_ADDRESS = 0x25, /* alarm address */ ACPI_SMB_ALARM_DATA = 0x26, /* 2 bytes alarm data */ }; static inline int smb_hc_read(struct acpi_smb_hc *hc, u8 address, u8 *data) { return ec_read(hc->offset + address, data); } static inline int smb_hc_write(struct acpi_smb_hc *hc, u8 address, u8 data) { return ec_write(hc->offset + address, data); } static int wait_transaction_complete(struct acpi_smb_hc *hc, int timeout) { if (wait_event_timeout(hc->wait, hc->done, msecs_to_jiffies(timeout))) return 0; return -ETIME; } static int acpi_smbus_transaction(struct acpi_smb_hc *hc, u8 protocol, u8 address, u8 command, u8 *data, u8 length) { int ret = -EFAULT, i; u8 temp, sz = 0; if (!hc) { printk(KERN_ERR PREFIX "host controller is not configured\n"); return ret; } mutex_lock(&hc->lock); hc->done = false; if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) goto end; if (temp) { ret = -EBUSY; goto end; } smb_hc_write(hc, ACPI_SMB_COMMAND, command); if (!(protocol & 0x01)) { smb_hc_write(hc, ACPI_SMB_BLOCK_COUNT, length); for (i = 0; i < length; ++i) smb_hc_write(hc, ACPI_SMB_DATA + i, data[i]); } smb_hc_write(hc, ACPI_SMB_ADDRESS, address << 1); smb_hc_write(hc, ACPI_SMB_PROTOCOL, protocol); /* * Wait for completion. Save the status code, data size, * and data into the return package (if required by the protocol). */ ret = wait_transaction_complete(hc, 1000); if (ret || !(protocol & 0x01)) goto end; switch (protocol) { case SMBUS_RECEIVE_BYTE: case SMBUS_READ_BYTE: sz = 1; break; case SMBUS_READ_WORD: sz = 2; break; case SMBUS_READ_BLOCK: if (smb_hc_read(hc, ACPI_SMB_BLOCK_COUNT, &sz)) { ret = -EFAULT; goto end; } sz &= 0x1f; break; } for (i = 0; i < sz; ++i) smb_hc_read(hc, ACPI_SMB_DATA + i, &data[i]); end: mutex_unlock(&hc->lock); return ret; } int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address, u8 command, u8 *data) { return acpi_smbus_transaction(hc, protocol, address, command, data, 0); } EXPORT_SYMBOL_GPL(acpi_smbus_read); int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 address, u8 command, u8 *data, u8 length) { return acpi_smbus_transaction(hc, protocol, address, command, data, length); } EXPORT_SYMBOL_GPL(acpi_smbus_write); int acpi_smbus_register_callback(struct acpi_smb_hc *hc, smbus_alarm_callback callback, void *context) { mutex_lock(&hc->lock); hc->callback = callback; hc->context = context; mutex_unlock(&hc->lock); return 0; } EXPORT_SYMBOL_GPL(acpi_smbus_register_callback); int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc) { mutex_lock(&hc->lock); hc->callback = NULL; hc->context = NULL; mutex_unlock(&hc->lock); return 0; } EXPORT_SYMBOL_GPL(acpi_smbus_unregister_callback); static inline void acpi_smbus_callback(void *context) { struct acpi_smb_hc *hc = context; if (hc->callback) hc->callback(hc->context); } static int smbus_alarm(void *context) { struct acpi_smb_hc *hc = context; union acpi_smb_status status; u8 address; if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw)) return 0; /* Check if it is only a completion notify */ if (status.fields.done && status.fields.status == SMBUS_OK) { hc->done = true; wake_up(&hc->wait); } if (!status.fields.alarm) return 0; mutex_lock(&hc->lock); smb_hc_read(hc, ACPI_SMB_ALARM_ADDRESS, &address); status.fields.alarm = 0; smb_hc_write(hc, ACPI_SMB_STATUS, status.raw); /* We are only interested in events coming from known devices */ switch (address >> 1) { case ACPI_SBS_CHARGER: case ACPI_SBS_MANAGER: case ACPI_SBS_BATTERY: acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_smbus_callback, hc); default:; } mutex_unlock(&hc->lock); return 0; } typedef int (*acpi_ec_query_func) (void *data); extern int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, acpi_handle handle, acpi_ec_query_func func, void *data); static int acpi_smbus_hc_add(struct acpi_device *device) { int status; unsigned long long val; struct acpi_smb_hc *hc; if (!device) return -EINVAL; status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val); if (ACPI_FAILURE(status)) { printk(KERN_ERR PREFIX "error obtaining _EC.\n"); return -EIO; } strcpy(acpi_device_name(device), ACPI_SMB_HC_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_SMB_HC_CLASS); hc = kzalloc(sizeof(struct acpi_smb_hc), GFP_KERNEL); if (!hc) return -ENOMEM; mutex_init(&hc->lock); init_waitqueue_head(&hc->wait); hc->ec = acpi_driver_data(device->parent); hc->offset = (val >> 8) & 0xff; hc->query_bit = val & 0xff; device->driver_data = hc; acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); dev_info(&device->dev, "SBS HC: offset = 0x%0x, query_bit = 0x%0x\n", hc->offset, hc->query_bit); return 0; } extern void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit); static int acpi_smbus_hc_remove(struct acpi_device *device) { struct acpi_smb_hc *hc; if (!device) return -EINVAL; hc = acpi_driver_data(device); acpi_ec_remove_query_handler(hc->ec, hc->query_bit); kfree(hc); device->driver_data = NULL; return 0; } module_acpi_driver(acpi_smb_hc_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Alexey Starikovskiy"); MODULE_DESCRIPTION("ACPI SMBus HC driver");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
You can’t perform that action at this time.