smu.c 31 KB

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