25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/kernel.h>
29 #include <linux/module.h>
50 #define RTL_ADDR_TYPE_IO 1
51 #define RTL_ADDR_TYPE_MMIO 2
53 #define RTL_CMD_ENTER_PRTM 1
54 #define RTL_CMD_EXIT_PRTM 2
72 #define RTL_SIGNATURE 0x0000005f4c54525fULL
73 #define RTL_MASK 0x000000ffffffffffULL
75 #define RTL_DEBUG(fmt, ...) \
78 pr_info(fmt, ##__VA_ARGS__); \
84 static void __iomem *rtl_cmd_addr;
85 static u8 rtl_cmd_type;
86 static u8 rtl_cmd_width;
95 static void rtl_port_unmap(
void __iomem *addr)
103 static int ibm_rtl_write(
u8 value)
106 static u32 cmd_port_val;
117 switch (rtl_cmd_width) {
120 RTL_DEBUG(
"cmd_port_val = %u\n", cmd_port_val);
125 RTL_DEBUG(
"cmd_port_val = %u\n", cmd_port_val);
130 RTL_DEBUG(
"cmd_port_val = %u\n", cmd_port_val);
138 pr_err(
"Hardware not responding to "
139 "mode switch request\n");
147 RTL_DEBUG(
"command_status reports failed command\n");
177 if (count < 1 || count > 2)
182 ret = ibm_rtl_write(0);
185 ret = ibm_rtl_write(1);
196 static struct bus_type rtl_subsys = {
198 .dev_name =
"ibm_rtl",
211 static int rtl_setup_sysfs(
void) {
216 for (i = 0; rtl_attributes[
i]; i ++)
222 static void rtl_teardown_sysfs(
void) {
224 for (i = 0; rtl_attributes[
i]; i ++)
239 static int __init ibm_rtl_init(
void) {
240 unsigned long ebda_addr, ebda_size;
241 unsigned int ebda_kb;
245 pr_warn(
"module loaded by force\n");
251 ebda_addr = get_bios_ebda();
257 ebda_map =
ioremap(ebda_addr, 4);
269 ebda_size = ebda_kb*1024;
272 ebda_map =
ioremap(ebda_addr, ebda_size);
277 for (i = 0 ; i < ebda_size/
sizeof(
unsigned int); i++) {
283 RTL_DEBUG(
"found RTL_SIGNATURE at %p\n", tmp);
289 RTL_DEBUG(
"rtl_cmd_width = %u, rtl_cmd_type = %u\n",
290 rtl_cmd_width, rtl_cmd_type);
292 RTL_DEBUG(
"addr = %#llx\n", (
unsigned long long)addr);
293 plen = rtl_cmd_width/
sizeof(
char);
294 rtl_cmd_addr = rtl_port_map(addr, plen);
295 RTL_DEBUG(
"rtl_cmd_addr = %p\n", rtl_cmd_addr);
300 ret = rtl_setup_sysfs();
308 rtl_port_unmap(rtl_cmd_addr);
314 static void __exit ibm_rtl_exit(
void)
321 rtl_teardown_sysfs();
323 rtl_port_unmap(rtl_cmd_addr);