smu.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. /*
  2. * PowerMac G5 SMU driver
  3. *
  4. * Copyright 2004 J. Mayer <l_indien@magic.fr>
  5. * Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  6. *
  7. * Released under the term of the GNU GPL v2.
  8. */
  9. /*
  10. * TODO:
  11. * - maybe add timeout to commands ?
  12. * - blocking version of time functions
  13. * - polling version of i2c commands (including timer that works with
  14. * interrupts off)
  15. * - maybe avoid some data copies with i2c by directly using the smu cmd
  16. * buffer and a lower level internal interface
  17. * - understand SMU -> CPU events and implement reception of them via
  18. * the userland interface
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/device.h>
  23. #include <linux/dmapool.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/highmem.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/rtc.h>
  30. #include <linux/completion.h>
  31. #include <linux/miscdevice.h>
  32. #include <linux/delay.h>
  33. #include <linux/poll.h>
  34. #include <linux/mutex.h>
  35. #include <linux/of_device.h>
  36. #include <linux/of_irq.h>
  37. #include <linux/of_platform.h>
  38. #include <linux/slab.h>
  39. #include <asm/byteorder.h>
  40. #include <asm/io.h>
  41. #include <asm/prom.h>
  42. #include <asm/machdep.h>
  43. #include <asm/pmac_feature.h>
  44. #include <asm/smu.h>
  45. #include <asm/sections.h>
  46. #include <asm/uaccess.h>
  47. #define VERSION "0.7"
  48. #define AUTHOR "(c) 2005 Benjamin Herrenschmidt, IBM Corp."
  49. #undef DEBUG_SMU
  50. #ifdef DEBUG_SMU
  51. #define DPRINTK(fmt, args...) do { printk(KERN_DEBUG fmt , ##args); } while (0)
  52. #else
  53. #define DPRINTK(fmt, args...) do { } while (0)
  54. #endif
  55. /*
  56. * This is the command buffer passed to the SMU hardware
  57. */
  58. #define SMU_MAX_DATA 254
  59. struct smu_cmd_buf {
  60. u8 cmd;
  61. u8 length;
  62. u8 data[SMU_MAX_DATA];
  63. };
  64. struct smu_device {
  65. spinlock_t lock;
  66. struct device_node *of_node;
  67. struct platform_device *of_dev;
  68. int doorbell; /* doorbell gpio */
  69. u32 __iomem *db_buf; /* doorbell buffer */
  70. struct device_node *db_node;
  71. unsigned int db_irq;
  72. int msg;
  73. struct device_node *msg_node;
  74. unsigned int msg_irq;
  75. struct smu_cmd_buf *cmd_buf; /* command buffer virtual */
  76. u32 cmd_buf_abs; /* command buffer absolute */
  77. struct list_head cmd_list;
  78. struct smu_cmd *cmd_cur; /* pending command */
  79. int broken_nap;
  80. struct list_head cmd_i2c_list;
  81. struct smu_i2c_cmd *cmd_i2c_cur; /* pending i2c command */
  82. struct timer_list i2c_timer;
  83. };
  84. /*
  85. * I don't think there will ever be more than one SMU, so
  86. * for now, just hard code that
  87. */
  88. static DEFINE_MUTEX(smu_mutex);
  89. static struct smu_device *smu;
  90. static DEFINE_MUTEX(smu_part_access);
  91. static int smu_irq_inited;
  92. static void smu_i2c_retry(unsigned long data);
  93. /*
  94. * SMU driver low level stuff
  95. */
  96. static void smu_start_cmd(void)
  97. {
  98. unsigned long faddr, fend;
  99. struct smu_cmd *cmd;
  100. if (list_empty(&smu->cmd_list))
  101. return;
  102. /* Fetch first command in queue */
  103. cmd = list_entry(smu->cmd_list.next, struct smu_cmd, link);
  104. smu->cmd_cur = cmd;
  105. list_del(&cmd->link);
  106. DPRINTK("SMU: starting cmd %x, %d bytes data\n", cmd->cmd,
  107. cmd->data_len);
  108. DPRINTK("SMU: data buffer: %8ph\n", cmd->data_buf);
  109. /* Fill the SMU command buffer */
  110. smu->cmd_buf->cmd = cmd->cmd;
  111. smu->cmd_buf->length = cmd->data_len;
  112. memcpy(smu->cmd_buf->data, cmd->data_buf, cmd->data_len);
  113. /* Flush command and data to RAM */
  114. faddr = (unsigned long)smu->cmd_buf;
  115. fend = faddr + smu->cmd_buf->length + 2;
  116. flush_inval_dcache_range(faddr, fend);
  117. /* We also disable NAP mode for the duration of the command
  118. * on U3 based machines.
  119. * This is slightly racy as it can be written back to 1 by a sysctl
  120. * but that never happens in practice. There seem to be an issue with
  121. * U3 based machines such as the iMac G5 where napping for the
  122. * whole duration of the command prevents the SMU from fetching it
  123. * from memory. This might be related to the strange i2c based
  124. * mechanism the SMU uses to access memory.
  125. */
  126. if (smu->broken_nap)
  127. powersave_nap = 0;
  128. /* This isn't exactly a DMA mapping here, I suspect
  129. * the SMU is actually communicating with us via i2c to the
  130. * northbridge or the CPU to access RAM.
  131. */
  132. writel(smu->cmd_buf_abs, smu->db_buf);
  133. /* Ring the SMU doorbell */
  134. pmac_do_feature_call(PMAC_FTR_WRITE_GPIO, NULL, smu->doorbell, 4);
  135. }
  136. static irqreturn_t smu_db_intr(int irq, void *arg)
  137. {
  138. unsigned long flags;
  139. struct smu_cmd *cmd;
  140. void (*done)(struct smu_cmd *cmd, void *misc) = NULL;
  141. void *misc = NULL;
  142. u8 gpio;
  143. int rc = 0;
  144. /* SMU completed the command, well, we hope, let's make sure
  145. * of it
  146. */
  147. spin_lock_irqsave(&smu->lock, flags);
  148. gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell);
  149. if ((gpio & 7) != 7) {
  150. spin_unlock_irqrestore(&smu->lock, flags);
  151. return IRQ_HANDLED;
  152. }
  153. cmd = smu->cmd_cur;
  154. smu->cmd_cur = NULL;
  155. if (cmd == NULL)
  156. goto bail;
  157. if (rc == 0) {
  158. unsigned long faddr;
  159. int reply_len;
  160. u8 ack;
  161. /* CPU might have brought back the cache line, so we need
  162. * to flush again before peeking at the SMU response. We
  163. * flush the entire buffer for now as we haven't read the
  164. * reply length (it's only 2 cache lines anyway)
  165. */
  166. faddr = (unsigned long)smu->cmd_buf;
  167. flush_inval_dcache_range(faddr, faddr + 256);
  168. /* Now check ack */
  169. ack = (~cmd->cmd) & 0xff;
  170. if (ack != smu->cmd_buf->cmd) {
  171. DPRINTK("SMU: incorrect ack, want %x got %x\n",
  172. ack, smu->cmd_buf->cmd);
  173. rc = -EIO;
  174. }
  175. reply_len = rc == 0 ? smu->cmd_buf->length : 0;
  176. DPRINTK("SMU: reply len: %d\n", reply_len);
  177. if (reply_len > cmd->reply_len) {
  178. printk(KERN_WARNING "SMU: reply buffer too small,"
  179. "got %d bytes for a %d bytes buffer\n",
  180. reply_len, cmd->reply_len);
  181. reply_len = cmd->reply_len;
  182. }
  183. cmd->reply_len = reply_len;
  184. if (cmd->reply_buf && reply_len)
  185. memcpy(cmd->reply_buf, smu->cmd_buf->data, reply_len);
  186. }
  187. /* Now complete the command. Write status last in order as we lost
  188. * ownership of the command structure as soon as it's no longer -1
  189. */
  190. done = cmd->done;
  191. misc = cmd->misc;
  192. mb();
  193. cmd->status = rc;
  194. /* Re-enable NAP mode */
  195. if (smu->broken_nap)
  196. powersave_nap = 1;
  197. bail:
  198. /* Start next command if any */
  199. smu_start_cmd();
  200. spin_unlock_irqrestore(&smu->lock, flags);
  201. /* Call command completion handler if any */
  202. if (done)
  203. done(cmd, misc);
  204. /* It's an edge interrupt, nothing to do */
  205. return IRQ_HANDLED;
  206. }
  207. static irqreturn_t smu_msg_intr(int irq, void *arg)
  208. {
  209. /* I don't quite know what to do with this one, we seem to never
  210. * receive it, so I suspect we have to arm it someway in the SMU
  211. * to start getting events that way.
  212. */
  213. printk(KERN_INFO "SMU: message interrupt !\n");
  214. /* It's an edge interrupt, nothing to do */
  215. return IRQ_HANDLED;
  216. }
  217. /*
  218. * Queued command management.
  219. *
  220. */
  221. int smu_queue_cmd(struct smu_cmd *cmd)
  222. {
  223. unsigned long flags;
  224. if (smu == NULL)
  225. return -ENODEV;
  226. if (cmd->data_len > SMU_MAX_DATA ||
  227. cmd->reply_len > SMU_MAX_DATA)
  228. return -EINVAL;
  229. cmd->status = 1;
  230. spin_lock_irqsave(&smu->lock, flags);
  231. list_add_tail(&cmd->link, &smu->cmd_list);
  232. if (smu->cmd_cur == NULL)
  233. smu_start_cmd();
  234. spin_unlock_irqrestore(&smu->lock, flags);
  235. /* Workaround for early calls when irq isn't available */
  236. if (!smu_irq_inited || smu->db_irq == NO_IRQ)
  237. smu_spinwait_cmd(cmd);
  238. return 0;
  239. }
  240. EXPORT_SYMBOL(smu_queue_cmd);
  241. int smu_queue_simple(struct smu_simple_cmd *scmd, u8 command,
  242. unsigned int data_len,
  243. void (*done)(struct smu_cmd *cmd, void *misc),
  244. void *misc, ...)
  245. {
  246. struct smu_cmd *cmd = &scmd->cmd;
  247. va_list list;
  248. int i;
  249. if (data_len > sizeof(scmd->buffer))
  250. return -EINVAL;
  251. memset(scmd, 0, sizeof(*scmd));
  252. cmd->cmd = command;
  253. cmd->data_len = data_len;
  254. cmd->data_buf = scmd->buffer;
  255. cmd->reply_len = sizeof(scmd->buffer);
  256. cmd->reply_buf = scmd->buffer;
  257. cmd->done = done;
  258. cmd->misc = misc;
  259. va_start(list, misc);
  260. for (i = 0; i < data_len; ++i)
  261. scmd->buffer[i] = (u8)va_arg(list, int);
  262. va_end(list);
  263. return smu_queue_cmd(cmd);
  264. }
  265. EXPORT_SYMBOL(smu_queue_simple);
  266. void smu_poll(void)
  267. {
  268. u8 gpio;
  269. if (smu == NULL)
  270. return;
  271. gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell);
  272. if ((gpio & 7) == 7)
  273. smu_db_intr(smu->db_irq, smu);
  274. }
  275. EXPORT_SYMBOL(smu_poll);
  276. void smu_done_complete(struct smu_cmd *cmd, void *misc)
  277. {
  278. struct completion *comp = misc;
  279. complete(comp);
  280. }
  281. EXPORT_SYMBOL(smu_done_complete);
  282. void smu_spinwait_cmd(struct smu_cmd *cmd)
  283. {
  284. while(cmd->status == 1)
  285. smu_poll();
  286. }
  287. EXPORT_SYMBOL(smu_spinwait_cmd);
  288. /* RTC low level commands */
  289. static inline int bcd2hex (int n)
  290. {
  291. return (((n & 0xf0) >> 4) * 10) + (n & 0xf);
  292. }
  293. static inline int hex2bcd (int n)
  294. {
  295. return ((n / 10) << 4) + (n % 10);
  296. }
  297. static inline void smu_fill_set_rtc_cmd(struct smu_cmd_buf *cmd_buf,
  298. struct rtc_time *time)
  299. {
  300. cmd_buf->cmd = 0x8e;
  301. cmd_buf->length = 8;
  302. cmd_buf->data[0] = 0x80;
  303. cmd_buf->data[1] = hex2bcd(time->tm_sec);
  304. cmd_buf->data[2] = hex2bcd(time->tm_min);
  305. cmd_buf->data[3] = hex2bcd(time->tm_hour);
  306. cmd_buf->data[4] = time->tm_wday;
  307. cmd_buf->data[5] = hex2bcd(time->tm_mday);
  308. cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
  309. cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
  310. }
  311. int smu_get_rtc_time(struct rtc_time *time, int spinwait)
  312. {
  313. struct smu_simple_cmd cmd;
  314. int rc;
  315. if (smu == NULL)
  316. return -ENODEV;
  317. memset(time, 0, sizeof(struct rtc_time));
  318. rc = smu_queue_simple(&cmd, SMU_CMD_RTC_COMMAND, 1, NULL, NULL,
  319. SMU_CMD_RTC_GET_DATETIME);
  320. if (rc)
  321. return rc;
  322. smu_spinwait_simple(&cmd);
  323. time->tm_sec = bcd2hex(cmd.buffer[0]);
  324. time->tm_min = bcd2hex(cmd.buffer[1]);
  325. time->tm_hour = bcd2hex(cmd.buffer[2]);
  326. time->tm_wday = bcd2hex(cmd.buffer[3]);
  327. time->tm_mday = bcd2hex(cmd.buffer[4]);
  328. time->tm_mon = bcd2hex(cmd.buffer[5]) - 1;
  329. time->tm_year = bcd2hex(cmd.buffer[6]) + 100;
  330. return 0;
  331. }
  332. int smu_set_rtc_time(struct rtc_time *time, int spinwait)
  333. {
  334. struct smu_simple_cmd cmd;
  335. int rc;
  336. if (smu == NULL)
  337. return -ENODEV;
  338. rc = smu_queue_simple(&cmd, SMU_CMD_RTC_COMMAND, 8, NULL, NULL,
  339. SMU_CMD_RTC_SET_DATETIME,
  340. hex2bcd(time->tm_sec),
  341. hex2bcd(time->tm_min),
  342. hex2bcd(time->tm_hour),
  343. time->tm_wday,
  344. hex2bcd(time->tm_mday),
  345. hex2bcd(time->tm_mon) + 1,
  346. hex2bcd(time->tm_year - 100));
  347. if (rc)
  348. return rc;
  349. smu_spinwait_simple(&cmd);
  350. return 0;
  351. }
  352. void smu_shutdown(void)
  353. {
  354. struct smu_simple_cmd cmd;
  355. if (smu == NULL)
  356. return;
  357. if (smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 9, NULL, NULL,
  358. 'S', 'H', 'U', 'T', 'D', 'O', 'W', 'N', 0))
  359. return;
  360. smu_spinwait_simple(&cmd);
  361. for (;;)
  362. ;
  363. }
  364. void smu_restart(void)
  365. {
  366. struct smu_simple_cmd cmd;
  367. if (smu == NULL)
  368. return;
  369. if (smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 8, NULL, NULL,
  370. 'R', 'E', 'S', 'T', 'A', 'R', 'T', 0))
  371. return;
  372. smu_spinwait_simple(&cmd);
  373. for (;;)
  374. ;
  375. }
  376. int smu_present(void)
  377. {
  378. return smu != NULL;
  379. }
  380. EXPORT_SYMBOL(smu_present);
  381. int __init smu_init (void)
  382. {
  383. struct device_node *np;
  384. const u32 *data;
  385. int ret = 0;
  386. np = of_find_node_by_type(NULL, "smu");
  387. if (np == NULL)
  388. return -ENODEV;
  389. printk(KERN_INFO "SMU: Driver %s %s\n", VERSION, AUTHOR);
  390. if (smu_cmdbuf_abs == 0) {
  391. printk(KERN_ERR "SMU: Command buffer not allocated !\n");
  392. ret = -EINVAL;
  393. goto fail_np;
  394. }
  395. smu = alloc_bootmem(sizeof(struct smu_device));
  396. spin_lock_init(&smu->lock);
  397. INIT_LIST_HEAD(&smu->cmd_list);
  398. INIT_LIST_HEAD(&smu->cmd_i2c_list);
  399. smu->of_node = np;
  400. smu->db_irq = NO_IRQ;
  401. smu->msg_irq = NO_IRQ;
  402. /* smu_cmdbuf_abs is in the low 2G of RAM, can be converted to a
  403. * 32 bits value safely
  404. */
  405. smu->cmd_buf_abs = (u32)smu_cmdbuf_abs;
  406. smu->cmd_buf = __va(smu_cmdbuf_abs);
  407. smu->db_node = of_find_node_by_name(NULL, "smu-doorbell");
  408. if (smu->db_node == NULL) {
  409. printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n");
  410. ret = -ENXIO;
  411. goto fail_bootmem;
  412. }
  413. data = of_get_property(smu->db_node, "reg", NULL);
  414. if (data == NULL) {
  415. printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n");
  416. ret = -ENXIO;
  417. goto fail_db_node;
  418. }
  419. /* Current setup has one doorbell GPIO that does both doorbell
  420. * and ack. GPIOs are at 0x50, best would be to find that out
  421. * in the device-tree though.
  422. */
  423. smu->doorbell = *data;
  424. if (smu->doorbell < 0x50)
  425. smu->doorbell += 0x50;
  426. /* Now look for the smu-interrupt GPIO */
  427. do {
  428. smu->msg_node = of_find_node_by_name(NULL, "smu-interrupt");
  429. if (smu->msg_node == NULL)
  430. break;
  431. data = of_get_property(smu->msg_node, "reg", NULL);
  432. if (data == NULL) {
  433. of_node_put(smu->msg_node);
  434. smu->msg_node = NULL;
  435. break;
  436. }
  437. smu->msg = *data;
  438. if (smu->msg < 0x50)
  439. smu->msg += 0x50;
  440. } while(0);
  441. /* Doorbell buffer is currently hard-coded, I didn't find a proper
  442. * device-tree entry giving the address. Best would probably to use
  443. * an offset for K2 base though, but let's do it that way for now.
  444. */
  445. smu->db_buf = ioremap(0x8000860c, 0x1000);
  446. if (smu->db_buf == NULL) {
  447. printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n");
  448. ret = -ENXIO;
  449. goto fail_msg_node;
  450. }
  451. /* U3 has an issue with NAP mode when issuing SMU commands */
  452. smu->broken_nap = pmac_get_uninorth_variant() < 4;
  453. if (smu->broken_nap)
  454. printk(KERN_INFO "SMU: using NAP mode workaround\n");
  455. sys_ctrler = SYS_CTRLER_SMU;
  456. return 0;
  457. fail_msg_node:
  458. if (smu->msg_node)
  459. of_node_put(smu->msg_node);
  460. fail_db_node:
  461. of_node_put(smu->db_node);
  462. fail_bootmem:
  463. free_bootmem(__pa(smu), sizeof(struct smu_device));
  464. smu = NULL;
  465. fail_np:
  466. of_node_put(np);
  467. return ret;
  468. }
  469. static int smu_late_init(void)
  470. {
  471. if (!smu)
  472. return 0;
  473. init_timer(&smu->i2c_timer);
  474. smu->i2c_timer.function = smu_i2c_retry;
  475. smu->i2c_timer.data = (unsigned long)smu;
  476. if (smu->db_node) {
  477. smu->db_irq = irq_of_parse_and_map(smu->db_node, 0);
  478. if (smu->db_irq == NO_IRQ)
  479. printk(KERN_ERR "smu: failed to map irq for node %s\n",
  480. smu->db_node->full_name);
  481. }
  482. if (smu->msg_node) {
  483. smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0);
  484. if (smu->msg_irq == NO_IRQ)
  485. printk(KERN_ERR "smu: failed to map irq for node %s\n",
  486. smu->msg_node->full_name);
  487. }
  488. /*
  489. * Try to request the interrupts
  490. */
  491. if (smu->db_irq != NO_IRQ) {
  492. if (request_irq(smu->db_irq, smu_db_intr,
  493. IRQF_SHARED, "SMU doorbell", smu) < 0) {
  494. printk(KERN_WARNING "SMU: can't "
  495. "request interrupt %d\n",
  496. smu->db_irq);
  497. smu->db_irq = NO_IRQ;
  498. }
  499. }
  500. if (smu->msg_irq != NO_IRQ) {
  501. if (request_irq(smu->msg_irq, smu_msg_intr,
  502. IRQF_SHARED, "SMU message", smu) < 0) {
  503. printk(KERN_WARNING "SMU: can't "
  504. "request interrupt %d\n",
  505. smu->msg_irq);
  506. smu->msg_irq = NO_IRQ;
  507. }
  508. }
  509. smu_irq_inited = 1;
  510. return 0;
  511. }
  512. /* This has to be before arch_initcall as the low i2c stuff relies on the
  513. * above having been done before we reach arch_initcalls
  514. */
  515. core_initcall(smu_late_init);
  516. /*
  517. * sysfs visibility
  518. */
  519. static void smu_expose_childs(struct work_struct *unused)
  520. {
  521. struct device_node *np;
  522. for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;)
  523. if (of_device_is_compatible(np, "smu-sensors"))
  524. of_platform_device_create(np, "smu-sensors",
  525. &smu->of_dev->dev);
  526. }
  527. static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs);
  528. static int smu_platform_probe(struct platform_device* dev)
  529. {
  530. if (!smu)
  531. return -ENODEV;
  532. smu->of_dev = dev;
  533. /*
  534. * Ok, we are matched, now expose all i2c busses. We have to defer
  535. * that unfortunately or it would deadlock inside the device model
  536. */
  537. schedule_work(&smu_expose_childs_work);
  538. return 0;
  539. }
  540. static const struct of_device_id smu_platform_match[] =
  541. {
  542. {
  543. .type = "smu",
  544. },
  545. {},
  546. };
  547. static struct platform_driver smu_of_platform_driver =
  548. {
  549. .driver = {
  550. .name = "smu",
  551. .of_match_table = smu_platform_match,
  552. },
  553. .probe = smu_platform_probe,
  554. };
  555. static int __init smu_init_sysfs(void)
  556. {
  557. /*
  558. * For now, we don't power manage machines with an SMU chip,
  559. * I'm a bit too far from figuring out how that works with those
  560. * new chipsets, but that will come back and bite us
  561. */
  562. platform_driver_register(&smu_of_platform_driver);
  563. return 0;
  564. }
  565. device_initcall(smu_init_sysfs);
  566. struct platform_device *smu_get_ofdev(void)
  567. {
  568. if (!smu)
  569. return NULL;
  570. return smu->of_dev;
  571. }
  572. EXPORT_SYMBOL_GPL(smu_get_ofdev);
  573. /*
  574. * i2c interface
  575. */
  576. static void smu_i2c_complete_command(struct smu_i2c_cmd *cmd, int fail)
  577. {
  578. void (*done)(struct smu_i2c_cmd *cmd, void *misc) = cmd->done;
  579. void *misc = cmd->misc;
  580. unsigned long flags;
  581. /* Check for read case */
  582. if (!fail && cmd->read) {
  583. if (cmd->pdata[0] < 1)
  584. fail = 1;
  585. else
  586. memcpy(cmd->info.data, &cmd->pdata[1],
  587. cmd->info.datalen);
  588. }
  589. DPRINTK("SMU: completing, success: %d\n", !fail);
  590. /* Update status and mark no pending i2c command with lock
  591. * held so nobody comes in while we dequeue an eventual
  592. * pending next i2c command
  593. */
  594. spin_lock_irqsave(&smu->lock, flags);
  595. smu->cmd_i2c_cur = NULL;
  596. wmb();
  597. cmd->status = fail ? -EIO : 0;
  598. /* Is there another i2c command waiting ? */
  599. if (!list_empty(&smu->cmd_i2c_list)) {
  600. struct smu_i2c_cmd *newcmd;
  601. /* Fetch it, new current, remove from list */
  602. newcmd = list_entry(smu->cmd_i2c_list.next,
  603. struct smu_i2c_cmd, link);
  604. smu->cmd_i2c_cur = newcmd;
  605. list_del(&cmd->link);
  606. /* Queue with low level smu */
  607. list_add_tail(&cmd->scmd.link, &smu->cmd_list);
  608. if (smu->cmd_cur == NULL)
  609. smu_start_cmd();
  610. }
  611. spin_unlock_irqrestore(&smu->lock, flags);
  612. /* Call command completion handler if any */
  613. if (done)
  614. done(cmd, misc);
  615. }
  616. static void smu_i2c_retry(unsigned long data)
  617. {
  618. struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur;
  619. DPRINTK("SMU: i2c failure, requeuing...\n");
  620. /* requeue command simply by resetting reply_len */
  621. cmd->pdata[0] = 0xff;
  622. cmd->scmd.reply_len = sizeof(cmd->pdata);
  623. smu_queue_cmd(&cmd->scmd);
  624. }
  625. static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
  626. {
  627. struct smu_i2c_cmd *cmd = misc;
  628. int fail = 0;
  629. DPRINTK("SMU: i2c compl. stage=%d status=%x pdata[0]=%x rlen: %x\n",
  630. cmd->stage, scmd->status, cmd->pdata[0], scmd->reply_len);
  631. /* Check for possible status */
  632. if (scmd->status < 0)
  633. fail = 1;
  634. else if (cmd->read) {
  635. if (cmd->stage == 0)
  636. fail = cmd->pdata[0] != 0;
  637. else
  638. fail = cmd->pdata[0] >= 0x80;
  639. } else {
  640. fail = cmd->pdata[0] != 0;
  641. }
  642. /* Handle failures by requeuing command, after 5ms interval
  643. */
  644. if (fail && --cmd->retries > 0) {
  645. DPRINTK("SMU: i2c failure, starting timer...\n");
  646. BUG_ON(cmd != smu->cmd_i2c_cur);
  647. if (!smu_irq_inited) {
  648. mdelay(5);
  649. smu_i2c_retry(0);
  650. return;
  651. }
  652. mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5));
  653. return;
  654. }
  655. /* If failure or stage 1, command is complete */
  656. if (fail || cmd->stage != 0) {
  657. smu_i2c_complete_command(cmd, fail);
  658. return;
  659. }
  660. DPRINTK("SMU: going to stage 1\n");
  661. /* Ok, initial command complete, now poll status */
  662. scmd->reply_buf = cmd->pdata;
  663. scmd->reply_len = sizeof(cmd->pdata);
  664. scmd->data_buf = cmd->pdata;
  665. scmd->data_len = 1;
  666. cmd->pdata[0] = 0;
  667. cmd->stage = 1;
  668. cmd->retries = 20;
  669. smu_queue_cmd(scmd);
  670. }
  671. int smu_queue_i2c(struct smu_i2c_cmd *cmd)
  672. {
  673. unsigned long flags;
  674. if (smu == NULL)
  675. return -ENODEV;
  676. /* Fill most fields of scmd */
  677. cmd->scmd.cmd = SMU_CMD_I2C_COMMAND;
  678. cmd->scmd.done = smu_i2c_low_completion;
  679. cmd->scmd.misc = cmd;
  680. cmd->scmd.reply_buf = cmd->pdata;
  681. cmd->scmd.reply_len = sizeof(cmd->pdata);
  682. cmd->scmd.data_buf = (u8 *)(char *)&cmd->info;
  683. cmd->scmd.status = 1;
  684. cmd->stage = 0;
  685. cmd->pdata[0] = 0xff;
  686. cmd->retries = 20;
  687. cmd->status = 1;
  688. /* Check transfer type, sanitize some "info" fields
  689. * based on transfer type and do more checking
  690. */
  691. cmd->info.caddr = cmd->info.devaddr;
  692. cmd->read = cmd->info.devaddr & 0x01;
  693. switch(cmd->info.type) {
  694. case SMU_I2C_TRANSFER_SIMPLE:
  695. memset(&cmd->info.sublen, 0, 4);
  696. break;
  697. case SMU_I2C_TRANSFER_COMBINED:
  698. cmd->info.devaddr &= 0xfe;
  699. case SMU_I2C_TRANSFER_STDSUB:
  700. if (cmd->info.sublen > 3)
  701. return -EINVAL;
  702. break;
  703. default:
  704. return -EINVAL;
  705. }
  706. /* Finish setting up command based on transfer direction
  707. */
  708. if (cmd->read) {
  709. if (cmd->info.datalen > SMU_I2C_READ_MAX)
  710. return -EINVAL;
  711. memset(cmd->info.data, 0xff, cmd->info.datalen);
  712. cmd->scmd.data_len = 9;
  713. } else {
  714. if (cmd->info.datalen > SMU_I2C_WRITE_MAX)
  715. return -EINVAL;
  716. cmd->scmd.data_len = 9 + cmd->info.datalen;
  717. }
  718. DPRINTK("SMU: i2c enqueuing command\n");
  719. DPRINTK("SMU: %s, len=%d bus=%x addr=%x sub0=%x type=%x\n",
  720. cmd->read ? "read" : "write", cmd->info.datalen,
  721. cmd->info.bus, cmd->info.caddr,
  722. cmd->info.subaddr[0], cmd->info.type);
  723. /* Enqueue command in i2c list, and if empty, enqueue also in
  724. * main command list
  725. */
  726. spin_lock_irqsave(&smu->lock, flags);
  727. if (smu->cmd_i2c_cur == NULL) {
  728. smu->cmd_i2c_cur = cmd;
  729. list_add_tail(&cmd->scmd.link, &smu->cmd_list);
  730. if (smu->cmd_cur == NULL)
  731. smu_start_cmd();
  732. } else
  733. list_add_tail(&cmd->link, &smu->cmd_i2c_list);
  734. spin_unlock_irqrestore(&smu->lock, flags);
  735. return 0;
  736. }
  737. /*
  738. * Handling of "partitions"
  739. */
  740. static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len)
  741. {
  742. DECLARE_COMPLETION_ONSTACK(comp);
  743. unsigned int chunk;
  744. struct smu_cmd cmd;
  745. int rc;
  746. u8 params[8];
  747. /* We currently use a chunk size of 0xe. We could check the
  748. * SMU firmware version and use bigger sizes though
  749. */
  750. chunk = 0xe;
  751. while (len) {
  752. unsigned int clen = min(len, chunk);
  753. cmd.cmd = SMU_CMD_MISC_ee_COMMAND;
  754. cmd.data_len = 7;
  755. cmd.data_buf = params;
  756. cmd.reply_len = chunk;
  757. cmd.reply_buf = dest;
  758. cmd.done = smu_done_complete;
  759. cmd.misc = &comp;
  760. params[0] = SMU_CMD_MISC_ee_GET_DATABLOCK_REC;
  761. params[1] = 0x4;
  762. *((u32 *)&params[2]) = addr;
  763. params[6] = clen;
  764. rc = smu_queue_cmd(&cmd);
  765. if (rc)
  766. return rc;
  767. wait_for_completion(&comp);
  768. if (cmd.status != 0)
  769. return rc;
  770. if (cmd.reply_len != clen) {
  771. printk(KERN_DEBUG "SMU: short read in "
  772. "smu_read_datablock, got: %d, want: %d\n",
  773. cmd.reply_len, clen);
  774. return -EIO;
  775. }
  776. len -= clen;
  777. addr += clen;
  778. dest += clen;
  779. }
  780. return 0;
  781. }
  782. static struct smu_sdbp_header *smu_create_sdb_partition(int id)
  783. {
  784. DECLARE_COMPLETION_ONSTACK(comp);
  785. struct smu_simple_cmd cmd;
  786. unsigned int addr, len, tlen;
  787. struct smu_sdbp_header *hdr;
  788. struct property *prop;
  789. /* First query the partition info */
  790. DPRINTK("SMU: Query partition infos ... (irq=%d)\n", smu->db_irq);
  791. smu_queue_simple(&cmd, SMU_CMD_PARTITION_COMMAND, 2,
  792. smu_done_complete, &comp,
  793. SMU_CMD_PARTITION_LATEST, id);
  794. wait_for_completion(&comp);
  795. DPRINTK("SMU: done, status: %d, reply_len: %d\n",
  796. cmd.cmd.status, cmd.cmd.reply_len);
  797. /* Partition doesn't exist (or other error) */
  798. if (cmd.cmd.status != 0 || cmd.cmd.reply_len != 6)
  799. return NULL;
  800. /* Fetch address and length from reply */
  801. addr = *((u16 *)cmd.buffer);
  802. len = cmd.buffer[3] << 2;
  803. /* Calucluate total length to allocate, including the 17 bytes
  804. * for "sdb-partition-XX" that we append at the end of the buffer
  805. */
  806. tlen = sizeof(struct property) + len + 18;
  807. prop = kzalloc(tlen, GFP_KERNEL);
  808. if (prop == NULL)
  809. return NULL;
  810. hdr = (struct smu_sdbp_header *)(prop + 1);
  811. prop->name = ((char *)prop) + tlen - 18;
  812. sprintf(prop->name, "sdb-partition-%02x", id);
  813. prop->length = len;
  814. prop->value = hdr;
  815. prop->next = NULL;
  816. /* Read the datablock */
  817. if (smu_read_datablock((u8 *)hdr, addr, len)) {
  818. printk(KERN_DEBUG "SMU: datablock read failed while reading "
  819. "partition %02x !\n", id);
  820. goto failure;
  821. }
  822. /* Got it, check a few things and create the property */
  823. if (hdr->id != id) {
  824. printk(KERN_DEBUG "SMU: Reading partition %02x and got "
  825. "%02x !\n", id, hdr->id);
  826. goto failure;
  827. }
  828. if (of_add_property(smu->of_node, prop)) {
  829. printk(KERN_DEBUG "SMU: Failed creating sdb-partition-%02x "
  830. "property !\n", id);
  831. goto failure;
  832. }
  833. return hdr;
  834. failure:
  835. kfree(prop);
  836. return NULL;
  837. }
  838. /* Note: Only allowed to return error code in pointers (using ERR_PTR)
  839. * when interruptible is 1
  840. */
  841. const struct smu_sdbp_header *__smu_get_sdb_partition(int id,
  842. unsigned int *size, int interruptible)
  843. {
  844. char pname[32];
  845. const struct smu_sdbp_header *part;
  846. if (!smu)
  847. return NULL;
  848. sprintf(pname, "sdb-partition-%02x", id);
  849. DPRINTK("smu_get_sdb_partition(%02x)\n", id);
  850. if (interruptible) {
  851. int rc;
  852. rc = mutex_lock_interruptible(&smu_part_access);
  853. if (rc)
  854. return ERR_PTR(rc);
  855. } else
  856. mutex_lock(&smu_part_access);
  857. part = of_get_property(smu->of_node, pname, size);
  858. if (part == NULL) {
  859. DPRINTK("trying to extract from SMU ...\n");
  860. part = smu_create_sdb_partition(id);
  861. if (part != NULL && size)
  862. *size = part->len << 2;
  863. }
  864. mutex_unlock(&smu_part_access);
  865. return part;
  866. }
  867. const struct smu_sdbp_header *smu_get_sdb_partition(int id, unsigned int *size)
  868. {
  869. return __smu_get_sdb_partition(id, size, 0);
  870. }
  871. EXPORT_SYMBOL(smu_get_sdb_partition);
  872. /*
  873. * Userland driver interface
  874. */
  875. static LIST_HEAD(smu_clist);
  876. static DEFINE_SPINLOCK(smu_clist_lock);
  877. enum smu_file_mode {
  878. smu_file_commands,
  879. smu_file_events,
  880. smu_file_closing
  881. };
  882. struct smu_private
  883. {
  884. struct list_head list;
  885. enum smu_file_mode mode;
  886. int busy;
  887. struct smu_cmd cmd;
  888. spinlock_t lock;
  889. wait_queue_head_t wait;
  890. u8 buffer[SMU_MAX_DATA];
  891. };
  892. static int smu_open(struct inode *inode, struct file *file)
  893. {
  894. struct smu_private *pp;
  895. unsigned long flags;
  896. pp = kzalloc(sizeof(struct smu_private), GFP_KERNEL);
  897. if (pp == 0)
  898. return -ENOMEM;
  899. spin_lock_init(&pp->lock);
  900. pp->mode = smu_file_commands;
  901. init_waitqueue_head(&pp->wait);
  902. mutex_lock(&smu_mutex);
  903. spin_lock_irqsave(&smu_clist_lock, flags);
  904. list_add(&pp->list, &smu_clist);
  905. spin_unlock_irqrestore(&smu_clist_lock, flags);
  906. file->private_data = pp;
  907. mutex_unlock(&smu_mutex);
  908. return 0;
  909. }
  910. static void smu_user_cmd_done(struct smu_cmd *cmd, void *misc)
  911. {
  912. struct smu_private *pp = misc;
  913. wake_up_all(&pp->wait);
  914. }
  915. static ssize_t smu_write(struct file *file, const char __user *buf,
  916. size_t count, loff_t *ppos)
  917. {
  918. struct smu_private *pp = file->private_data;
  919. unsigned long flags;
  920. struct smu_user_cmd_hdr hdr;
  921. int rc = 0;
  922. if (pp->busy)
  923. return -EBUSY;
  924. else if (copy_from_user(&hdr, buf, sizeof(hdr)))
  925. return -EFAULT;
  926. else if (hdr.cmdtype == SMU_CMDTYPE_WANTS_EVENTS) {
  927. pp->mode = smu_file_events;
  928. return 0;
  929. } else if (hdr.cmdtype == SMU_CMDTYPE_GET_PARTITION) {
  930. const struct smu_sdbp_header *part;
  931. part = __smu_get_sdb_partition(hdr.cmd, NULL, 1);
  932. if (part == NULL)
  933. return -EINVAL;
  934. else if (IS_ERR(part))
  935. return PTR_ERR(part);
  936. return 0;
  937. } else if (hdr.cmdtype != SMU_CMDTYPE_SMU)
  938. return -EINVAL;
  939. else if (pp->mode != smu_file_commands)
  940. return -EBADFD;
  941. else if (hdr.data_len > SMU_MAX_DATA)
  942. return -EINVAL;
  943. spin_lock_irqsave(&pp->lock, flags);
  944. if (pp->busy) {
  945. spin_unlock_irqrestore(&pp->lock, flags);
  946. return -EBUSY;
  947. }
  948. pp->busy = 1;
  949. pp->cmd.status = 1;
  950. spin_unlock_irqrestore(&pp->lock, flags);
  951. if (copy_from_user(pp->buffer, buf + sizeof(hdr), hdr.data_len)) {
  952. pp->busy = 0;
  953. return -EFAULT;
  954. }
  955. pp->cmd.cmd = hdr.cmd;
  956. pp->cmd.data_len = hdr.data_len;
  957. pp->cmd.reply_len = SMU_MAX_DATA;
  958. pp->cmd.data_buf = pp->buffer;
  959. pp->cmd.reply_buf = pp->buffer;
  960. pp->cmd.done = smu_user_cmd_done;
  961. pp->cmd.misc = pp;
  962. rc = smu_queue_cmd(&pp->cmd);
  963. if (rc < 0)
  964. return rc;
  965. return count;
  966. }
  967. static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
  968. char __user *buf, size_t count)
  969. {
  970. DECLARE_WAITQUEUE(wait, current);
  971. struct smu_user_reply_hdr hdr;
  972. unsigned long flags;
  973. int size, rc = 0;
  974. if (!pp->busy)
  975. return 0;
  976. if (count < sizeof(struct smu_user_reply_hdr))
  977. return -EOVERFLOW;
  978. spin_lock_irqsave(&pp->lock, flags);
  979. if (pp->cmd.status == 1) {
  980. if (file->f_flags & O_NONBLOCK) {
  981. spin_unlock_irqrestore(&pp->lock, flags);
  982. return -EAGAIN;
  983. }
  984. add_wait_queue(&pp->wait, &wait);
  985. for (;;) {
  986. set_current_state(TASK_INTERRUPTIBLE);
  987. rc = 0;
  988. if (pp->cmd.status != 1)
  989. break;
  990. rc = -ERESTARTSYS;
  991. if (signal_pending(current))
  992. break;
  993. spin_unlock_irqrestore(&pp->lock, flags);
  994. schedule();
  995. spin_lock_irqsave(&pp->lock, flags);
  996. }
  997. set_current_state(TASK_RUNNING);
  998. remove_wait_queue(&pp->wait, &wait);
  999. }
  1000. spin_unlock_irqrestore(&pp->lock, flags);
  1001. if (rc)
  1002. return rc;
  1003. if (pp->cmd.status != 0)
  1004. pp->cmd.reply_len = 0;
  1005. size = sizeof(hdr) + pp->cmd.reply_len;
  1006. if (count < size)
  1007. size = count;
  1008. rc = size;
  1009. hdr.status = pp->cmd.status;
  1010. hdr.reply_len = pp->cmd.reply_len;
  1011. if (copy_to_user(buf, &hdr, sizeof(hdr)))
  1012. return -EFAULT;
  1013. size -= sizeof(hdr);
  1014. if (size && copy_to_user(buf + sizeof(hdr), pp->buffer, size))
  1015. return -EFAULT;
  1016. pp->busy = 0;
  1017. return rc;
  1018. }
  1019. static ssize_t smu_read_events(struct file *file, struct smu_private *pp,
  1020. char __user *buf, size_t count)
  1021. {
  1022. /* Not implemented */
  1023. msleep_interruptible(1000);
  1024. return 0;
  1025. }
  1026. static ssize_t smu_read(struct file *file, char __user *buf,
  1027. size_t count, loff_t *ppos)
  1028. {
  1029. struct smu_private *pp = file->private_data;
  1030. if (pp->mode == smu_file_commands)
  1031. return smu_read_command(file, pp, buf, count);
  1032. if (pp->mode == smu_file_events)
  1033. return smu_read_events(file, pp, buf, count);
  1034. return -EBADFD;
  1035. }
  1036. static unsigned int smu_fpoll(struct file *file, poll_table *wait)
  1037. {
  1038. struct smu_private *pp = file->private_data;
  1039. unsigned int mask = 0;
  1040. unsigned long flags;
  1041. if (pp == 0)
  1042. return 0;
  1043. if (pp->mode == smu_file_commands) {
  1044. poll_wait(file, &pp->wait, wait);
  1045. spin_lock_irqsave(&pp->lock, flags);
  1046. if (pp->busy && pp->cmd.status != 1)
  1047. mask |= POLLIN;
  1048. spin_unlock_irqrestore(&pp->lock, flags);
  1049. }
  1050. if (pp->mode == smu_file_events) {
  1051. /* Not yet implemented */
  1052. }
  1053. return mask;
  1054. }
  1055. static int smu_release(struct inode *inode, struct file *file)
  1056. {
  1057. struct smu_private *pp = file->private_data;
  1058. unsigned long flags;
  1059. unsigned int busy;
  1060. if (pp == 0)
  1061. return 0;
  1062. file->private_data = NULL;
  1063. /* Mark file as closing to avoid races with new request */
  1064. spin_lock_irqsave(&pp->lock, flags);
  1065. pp->mode = smu_file_closing;
  1066. busy = pp->busy;
  1067. /* Wait for any pending request to complete */
  1068. if (busy && pp->cmd.status == 1) {
  1069. DECLARE_WAITQUEUE(wait, current);
  1070. add_wait_queue(&pp->wait, &wait);
  1071. for (;;) {
  1072. set_current_state(TASK_UNINTERRUPTIBLE);
  1073. if (pp->cmd.status != 1)
  1074. break;
  1075. spin_unlock_irqrestore(&pp->lock, flags);
  1076. schedule();
  1077. spin_lock_irqsave(&pp->lock, flags);
  1078. }
  1079. set_current_state(TASK_RUNNING);
  1080. remove_wait_queue(&pp->wait, &wait);
  1081. }
  1082. spin_unlock_irqrestore(&pp->lock, flags);
  1083. spin_lock_irqsave(&smu_clist_lock, flags);
  1084. list_del(&pp->list);
  1085. spin_unlock_irqrestore(&smu_clist_lock, flags);
  1086. kfree(pp);
  1087. return 0;
  1088. }
  1089. static const struct file_operations smu_device_fops = {
  1090. .llseek = no_llseek,
  1091. .read = smu_read,
  1092. .write = smu_write,
  1093. .poll = smu_fpoll,
  1094. .open = smu_open,
  1095. .release = smu_release,
  1096. };
  1097. static struct miscdevice pmu_device = {
  1098. MISC_DYNAMIC_MINOR, "smu", &smu_device_fops
  1099. };
  1100. static int smu_device_init(void)
  1101. {
  1102. if (!smu)
  1103. return -ENODEV;
  1104. if (misc_register(&pmu_device) < 0)
  1105. printk(KERN_ERR "via-pmu: cannot register misc device.\n");
  1106. return 0;
  1107. }
  1108. device_initcall(smu_device_init);