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