smu.c 31 KB

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