smu.c 30 KB

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