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