smu.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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 <linux/of_device.h>
  38. #include <linux/of_platform.h>
  39. #include <linux/slab.h>
  40. #include <asm/byteorder.h>
  41. #include <asm/io.h>
  42. #include <asm/prom.h>
  43. #include <asm/machdep.h>
  44. #include <asm/pmac_feature.h>
  45. #include <asm/smu.h>
  46. #include <asm/sections.h>
  47. #include <asm/abs_addr.h>
  48. #include <asm/uaccess.h>
  49. #define VERSION "0.7"
  50. #define AUTHOR "(c) 2005 Benjamin Herrenschmidt, IBM Corp."
  51. #undef DEBUG_SMU
  52. #ifdef DEBUG_SMU
  53. #define DPRINTK(fmt, args...) do { printk(KERN_DEBUG fmt , ##args); } while (0)
  54. #else
  55. #define DPRINTK(fmt, args...) do { } while (0)
  56. #endif
  57. /*
  58. * This is the command buffer passed to the SMU hardware
  59. */
  60. #define SMU_MAX_DATA 254
  61. struct smu_cmd_buf {
  62. u8 cmd;
  63. u8 length;
  64. u8 data[SMU_MAX_DATA];
  65. };
  66. struct smu_device {
  67. spinlock_t lock;
  68. struct device_node *of_node;
  69. struct of_device *of_dev;
  70. int doorbell; /* doorbell gpio */
  71. u32 __iomem *db_buf; /* doorbell buffer */
  72. struct device_node *db_node;
  73. unsigned int db_irq;
  74. int msg;
  75. struct device_node *msg_node;
  76. unsigned int msg_irq;
  77. struct smu_cmd_buf *cmd_buf; /* command buffer virtual */
  78. u32 cmd_buf_abs; /* command buffer absolute */
  79. struct list_head cmd_list;
  80. struct smu_cmd *cmd_cur; /* pending command */
  81. int broken_nap;
  82. struct list_head cmd_i2c_list;
  83. struct smu_i2c_cmd *cmd_i2c_cur; /* pending i2c command */
  84. struct timer_list i2c_timer;
  85. };
  86. /*
  87. * I don't think there will ever be more than one SMU, so
  88. * for now, just hard code that
  89. */
  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 of_device* dev,
  534. const struct of_device_id *match)
  535. {
  536. if (!smu)
  537. return -ENODEV;
  538. smu->of_dev = dev;
  539. /*
  540. * Ok, we are matched, now expose all i2c busses. We have to defer
  541. * that unfortunately or it would deadlock inside the device model
  542. */
  543. schedule_work(&smu_expose_childs_work);
  544. return 0;
  545. }
  546. static const struct of_device_id smu_platform_match[] =
  547. {
  548. {
  549. .type = "smu",
  550. },
  551. {},
  552. };
  553. static struct of_platform_driver smu_of_platform_driver =
  554. {
  555. .name = "smu",
  556. .match_table = smu_platform_match,
  557. .probe = smu_platform_probe,
  558. };
  559. static int __init smu_init_sysfs(void)
  560. {
  561. /*
  562. * Due to sysfs bogosity, a sysdev is not a real device, so
  563. * we should in fact create both if we want sysdev semantics
  564. * for power management.
  565. * For now, we don't power manage machines with an SMU chip,
  566. * I'm a bit too far from figuring out how that works with those
  567. * new chipsets, but that will come back and bite us
  568. */
  569. of_register_platform_driver(&smu_of_platform_driver);
  570. return 0;
  571. }
  572. device_initcall(smu_init_sysfs);
  573. struct of_device *smu_get_ofdev(void)
  574. {
  575. if (!smu)
  576. return NULL;
  577. return smu->of_dev;
  578. }
  579. EXPORT_SYMBOL_GPL(smu_get_ofdev);
  580. /*
  581. * i2c interface
  582. */
  583. static void smu_i2c_complete_command(struct smu_i2c_cmd *cmd, int fail)
  584. {
  585. void (*done)(struct smu_i2c_cmd *cmd, void *misc) = cmd->done;
  586. void *misc = cmd->misc;
  587. unsigned long flags;
  588. /* Check for read case */
  589. if (!fail && cmd->read) {
  590. if (cmd->pdata[0] < 1)
  591. fail = 1;
  592. else
  593. memcpy(cmd->info.data, &cmd->pdata[1],
  594. cmd->info.datalen);
  595. }
  596. DPRINTK("SMU: completing, success: %d\n", !fail);
  597. /* Update status and mark no pending i2c command with lock
  598. * held so nobody comes in while we dequeue an eventual
  599. * pending next i2c command
  600. */
  601. spin_lock_irqsave(&smu->lock, flags);
  602. smu->cmd_i2c_cur = NULL;
  603. wmb();
  604. cmd->status = fail ? -EIO : 0;
  605. /* Is there another i2c command waiting ? */
  606. if (!list_empty(&smu->cmd_i2c_list)) {
  607. struct smu_i2c_cmd *newcmd;
  608. /* Fetch it, new current, remove from list */
  609. newcmd = list_entry(smu->cmd_i2c_list.next,
  610. struct smu_i2c_cmd, link);
  611. smu->cmd_i2c_cur = newcmd;
  612. list_del(&cmd->link);
  613. /* Queue with low level smu */
  614. list_add_tail(&cmd->scmd.link, &smu->cmd_list);
  615. if (smu->cmd_cur == NULL)
  616. smu_start_cmd();
  617. }
  618. spin_unlock_irqrestore(&smu->lock, flags);
  619. /* Call command completion handler if any */
  620. if (done)
  621. done(cmd, misc);
  622. }
  623. static void smu_i2c_retry(unsigned long data)
  624. {
  625. struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur;
  626. DPRINTK("SMU: i2c failure, requeuing...\n");
  627. /* requeue command simply by resetting reply_len */
  628. cmd->pdata[0] = 0xff;
  629. cmd->scmd.reply_len = sizeof(cmd->pdata);
  630. smu_queue_cmd(&cmd->scmd);
  631. }
  632. static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
  633. {
  634. struct smu_i2c_cmd *cmd = misc;
  635. int fail = 0;
  636. DPRINTK("SMU: i2c compl. stage=%d status=%x pdata[0]=%x rlen: %x\n",
  637. cmd->stage, scmd->status, cmd->pdata[0], scmd->reply_len);
  638. /* Check for possible status */
  639. if (scmd->status < 0)
  640. fail = 1;
  641. else if (cmd->read) {
  642. if (cmd->stage == 0)
  643. fail = cmd->pdata[0] != 0;
  644. else
  645. fail = cmd->pdata[0] >= 0x80;
  646. } else {
  647. fail = cmd->pdata[0] != 0;
  648. }
  649. /* Handle failures by requeuing command, after 5ms interval
  650. */
  651. if (fail && --cmd->retries > 0) {
  652. DPRINTK("SMU: i2c failure, starting timer...\n");
  653. BUG_ON(cmd != smu->cmd_i2c_cur);
  654. if (!smu_irq_inited) {
  655. mdelay(5);
  656. smu_i2c_retry(0);
  657. return;
  658. }
  659. mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5));
  660. return;
  661. }
  662. /* If failure or stage 1, command is complete */
  663. if (fail || cmd->stage != 0) {
  664. smu_i2c_complete_command(cmd, fail);
  665. return;
  666. }
  667. DPRINTK("SMU: going to stage 1\n");
  668. /* Ok, initial command complete, now poll status */
  669. scmd->reply_buf = cmd->pdata;
  670. scmd->reply_len = sizeof(cmd->pdata);
  671. scmd->data_buf = cmd->pdata;
  672. scmd->data_len = 1;
  673. cmd->pdata[0] = 0;
  674. cmd->stage = 1;
  675. cmd->retries = 20;
  676. smu_queue_cmd(scmd);
  677. }
  678. int smu_queue_i2c(struct smu_i2c_cmd *cmd)
  679. {
  680. unsigned long flags;
  681. if (smu == NULL)
  682. return -ENODEV;
  683. /* Fill most fields of scmd */
  684. cmd->scmd.cmd = SMU_CMD_I2C_COMMAND;
  685. cmd->scmd.done = smu_i2c_low_completion;
  686. cmd->scmd.misc = cmd;
  687. cmd->scmd.reply_buf = cmd->pdata;
  688. cmd->scmd.reply_len = sizeof(cmd->pdata);
  689. cmd->scmd.data_buf = (u8 *)(char *)&cmd->info;
  690. cmd->scmd.status = 1;
  691. cmd->stage = 0;
  692. cmd->pdata[0] = 0xff;
  693. cmd->retries = 20;
  694. cmd->status = 1;
  695. /* Check transfer type, sanitize some "info" fields
  696. * based on transfer type and do more checking
  697. */
  698. cmd->info.caddr = cmd->info.devaddr;
  699. cmd->read = cmd->info.devaddr & 0x01;
  700. switch(cmd->info.type) {
  701. case SMU_I2C_TRANSFER_SIMPLE:
  702. memset(&cmd->info.sublen, 0, 4);
  703. break;
  704. case SMU_I2C_TRANSFER_COMBINED:
  705. cmd->info.devaddr &= 0xfe;
  706. case SMU_I2C_TRANSFER_STDSUB:
  707. if (cmd->info.sublen > 3)
  708. return -EINVAL;
  709. break;
  710. default:
  711. return -EINVAL;
  712. }
  713. /* Finish setting up command based on transfer direction
  714. */
  715. if (cmd->read) {
  716. if (cmd->info.datalen > SMU_I2C_READ_MAX)
  717. return -EINVAL;
  718. memset(cmd->info.data, 0xff, cmd->info.datalen);
  719. cmd->scmd.data_len = 9;
  720. } else {
  721. if (cmd->info.datalen > SMU_I2C_WRITE_MAX)
  722. return -EINVAL;
  723. cmd->scmd.data_len = 9 + cmd->info.datalen;
  724. }
  725. DPRINTK("SMU: i2c enqueuing command\n");
  726. DPRINTK("SMU: %s, len=%d bus=%x addr=%x sub0=%x type=%x\n",
  727. cmd->read ? "read" : "write", cmd->info.datalen,
  728. cmd->info.bus, cmd->info.caddr,
  729. cmd->info.subaddr[0], cmd->info.type);
  730. /* Enqueue command in i2c list, and if empty, enqueue also in
  731. * main command list
  732. */
  733. spin_lock_irqsave(&smu->lock, flags);
  734. if (smu->cmd_i2c_cur == NULL) {
  735. smu->cmd_i2c_cur = cmd;
  736. list_add_tail(&cmd->scmd.link, &smu->cmd_list);
  737. if (smu->cmd_cur == NULL)
  738. smu_start_cmd();
  739. } else
  740. list_add_tail(&cmd->link, &smu->cmd_i2c_list);
  741. spin_unlock_irqrestore(&smu->lock, flags);
  742. return 0;
  743. }
  744. /*
  745. * Handling of "partitions"
  746. */
  747. static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len)
  748. {
  749. DECLARE_COMPLETION_ONSTACK(comp);
  750. unsigned int chunk;
  751. struct smu_cmd cmd;
  752. int rc;
  753. u8 params[8];
  754. /* We currently use a chunk size of 0xe. We could check the
  755. * SMU firmware version and use bigger sizes though
  756. */
  757. chunk = 0xe;
  758. while (len) {
  759. unsigned int clen = min(len, chunk);
  760. cmd.cmd = SMU_CMD_MISC_ee_COMMAND;
  761. cmd.data_len = 7;
  762. cmd.data_buf = params;
  763. cmd.reply_len = chunk;
  764. cmd.reply_buf = dest;
  765. cmd.done = smu_done_complete;
  766. cmd.misc = &comp;
  767. params[0] = SMU_CMD_MISC_ee_GET_DATABLOCK_REC;
  768. params[1] = 0x4;
  769. *((u32 *)&params[2]) = addr;
  770. params[6] = clen;
  771. rc = smu_queue_cmd(&cmd);
  772. if (rc)
  773. return rc;
  774. wait_for_completion(&comp);
  775. if (cmd.status != 0)
  776. return rc;
  777. if (cmd.reply_len != clen) {
  778. printk(KERN_DEBUG "SMU: short read in "
  779. "smu_read_datablock, got: %d, want: %d\n",
  780. cmd.reply_len, clen);
  781. return -EIO;
  782. }
  783. len -= clen;
  784. addr += clen;
  785. dest += clen;
  786. }
  787. return 0;
  788. }
  789. static struct smu_sdbp_header *smu_create_sdb_partition(int id)
  790. {
  791. DECLARE_COMPLETION_ONSTACK(comp);
  792. struct smu_simple_cmd cmd;
  793. unsigned int addr, len, tlen;
  794. struct smu_sdbp_header *hdr;
  795. struct property *prop;
  796. /* First query the partition info */
  797. DPRINTK("SMU: Query partition infos ... (irq=%d)\n", smu->db_irq);
  798. smu_queue_simple(&cmd, SMU_CMD_PARTITION_COMMAND, 2,
  799. smu_done_complete, &comp,
  800. SMU_CMD_PARTITION_LATEST, id);
  801. wait_for_completion(&comp);
  802. DPRINTK("SMU: done, status: %d, reply_len: %d\n",
  803. cmd.cmd.status, cmd.cmd.reply_len);
  804. /* Partition doesn't exist (or other error) */
  805. if (cmd.cmd.status != 0 || cmd.cmd.reply_len != 6)
  806. return NULL;
  807. /* Fetch address and length from reply */
  808. addr = *((u16 *)cmd.buffer);
  809. len = cmd.buffer[3] << 2;
  810. /* Calucluate total length to allocate, including the 17 bytes
  811. * for "sdb-partition-XX" that we append at the end of the buffer
  812. */
  813. tlen = sizeof(struct property) + len + 18;
  814. prop = kzalloc(tlen, GFP_KERNEL);
  815. if (prop == NULL)
  816. return NULL;
  817. hdr = (struct smu_sdbp_header *)(prop + 1);
  818. prop->name = ((char *)prop) + tlen - 18;
  819. sprintf(prop->name, "sdb-partition-%02x", id);
  820. prop->length = len;
  821. prop->value = hdr;
  822. prop->next = NULL;
  823. /* Read the datablock */
  824. if (smu_read_datablock((u8 *)hdr, addr, len)) {
  825. printk(KERN_DEBUG "SMU: datablock read failed while reading "
  826. "partition %02x !\n", id);
  827. goto failure;
  828. }
  829. /* Got it, check a few things and create the property */
  830. if (hdr->id != id) {
  831. printk(KERN_DEBUG "SMU: Reading partition %02x and got "
  832. "%02x !\n", id, hdr->id);
  833. goto failure;
  834. }
  835. if (prom_add_property(smu->of_node, prop)) {
  836. printk(KERN_DEBUG "SMU: Failed creating sdb-partition-%02x "
  837. "property !\n", id);
  838. goto failure;
  839. }
  840. return hdr;
  841. failure:
  842. kfree(prop);
  843. return NULL;
  844. }
  845. /* Note: Only allowed to return error code in pointers (using ERR_PTR)
  846. * when interruptible is 1
  847. */
  848. const struct smu_sdbp_header *__smu_get_sdb_partition(int id,
  849. unsigned int *size, int interruptible)
  850. {
  851. char pname[32];
  852. const struct smu_sdbp_header *part;
  853. if (!smu)
  854. return NULL;
  855. sprintf(pname, "sdb-partition-%02x", id);
  856. DPRINTK("smu_get_sdb_partition(%02x)\n", id);
  857. if (interruptible) {
  858. int rc;
  859. rc = mutex_lock_interruptible(&smu_part_access);
  860. if (rc)
  861. return ERR_PTR(rc);
  862. } else
  863. mutex_lock(&smu_part_access);
  864. part = of_get_property(smu->of_node, pname, size);
  865. if (part == NULL) {
  866. DPRINTK("trying to extract from SMU ...\n");
  867. part = smu_create_sdb_partition(id);
  868. if (part != NULL && size)
  869. *size = part->len << 2;
  870. }
  871. mutex_unlock(&smu_part_access);
  872. return part;
  873. }
  874. const struct smu_sdbp_header *smu_get_sdb_partition(int id, unsigned int *size)
  875. {
  876. return __smu_get_sdb_partition(id, size, 0);
  877. }
  878. EXPORT_SYMBOL(smu_get_sdb_partition);
  879. /*
  880. * Userland driver interface
  881. */
  882. static LIST_HEAD(smu_clist);
  883. static DEFINE_SPINLOCK(smu_clist_lock);
  884. enum smu_file_mode {
  885. smu_file_commands,
  886. smu_file_events,
  887. smu_file_closing
  888. };
  889. struct smu_private
  890. {
  891. struct list_head list;
  892. enum smu_file_mode mode;
  893. int busy;
  894. struct smu_cmd cmd;
  895. spinlock_t lock;
  896. wait_queue_head_t wait;
  897. u8 buffer[SMU_MAX_DATA];
  898. };
  899. static int smu_open(struct inode *inode, struct file *file)
  900. {
  901. struct smu_private *pp;
  902. unsigned long flags;
  903. pp = kzalloc(sizeof(struct smu_private), GFP_KERNEL);
  904. if (pp == 0)
  905. return -ENOMEM;
  906. spin_lock_init(&pp->lock);
  907. pp->mode = smu_file_commands;
  908. init_waitqueue_head(&pp->wait);
  909. lock_kernel();
  910. spin_lock_irqsave(&smu_clist_lock, flags);
  911. list_add(&pp->list, &smu_clist);
  912. spin_unlock_irqrestore(&smu_clist_lock, flags);
  913. file->private_data = pp;
  914. unlock_kernel();
  915. return 0;
  916. }
  917. static void smu_user_cmd_done(struct smu_cmd *cmd, void *misc)
  918. {
  919. struct smu_private *pp = misc;
  920. wake_up_all(&pp->wait);
  921. }
  922. static ssize_t smu_write(struct file *file, const char __user *buf,
  923. size_t count, loff_t *ppos)
  924. {
  925. struct smu_private *pp = file->private_data;
  926. unsigned long flags;
  927. struct smu_user_cmd_hdr hdr;
  928. int rc = 0;
  929. if (pp->busy)
  930. return -EBUSY;
  931. else if (copy_from_user(&hdr, buf, sizeof(hdr)))
  932. return -EFAULT;
  933. else if (hdr.cmdtype == SMU_CMDTYPE_WANTS_EVENTS) {
  934. pp->mode = smu_file_events;
  935. return 0;
  936. } else if (hdr.cmdtype == SMU_CMDTYPE_GET_PARTITION) {
  937. const struct smu_sdbp_header *part;
  938. part = __smu_get_sdb_partition(hdr.cmd, NULL, 1);
  939. if (part == NULL)
  940. return -EINVAL;
  941. else if (IS_ERR(part))
  942. return PTR_ERR(part);
  943. return 0;
  944. } else if (hdr.cmdtype != SMU_CMDTYPE_SMU)
  945. return -EINVAL;
  946. else if (pp->mode != smu_file_commands)
  947. return -EBADFD;
  948. else if (hdr.data_len > SMU_MAX_DATA)
  949. return -EINVAL;
  950. spin_lock_irqsave(&pp->lock, flags);
  951. if (pp->busy) {
  952. spin_unlock_irqrestore(&pp->lock, flags);
  953. return -EBUSY;
  954. }
  955. pp->busy = 1;
  956. pp->cmd.status = 1;
  957. spin_unlock_irqrestore(&pp->lock, flags);
  958. if (copy_from_user(pp->buffer, buf + sizeof(hdr), hdr.data_len)) {
  959. pp->busy = 0;
  960. return -EFAULT;
  961. }
  962. pp->cmd.cmd = hdr.cmd;
  963. pp->cmd.data_len = hdr.data_len;
  964. pp->cmd.reply_len = SMU_MAX_DATA;
  965. pp->cmd.data_buf = pp->buffer;
  966. pp->cmd.reply_buf = pp->buffer;
  967. pp->cmd.done = smu_user_cmd_done;
  968. pp->cmd.misc = pp;
  969. rc = smu_queue_cmd(&pp->cmd);
  970. if (rc < 0)
  971. return rc;
  972. return count;
  973. }
  974. static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
  975. char __user *buf, size_t count)
  976. {
  977. DECLARE_WAITQUEUE(wait, current);
  978. struct smu_user_reply_hdr hdr;
  979. unsigned long flags;
  980. int size, rc = 0;
  981. if (!pp->busy)
  982. return 0;
  983. if (count < sizeof(struct smu_user_reply_hdr))
  984. return -EOVERFLOW;
  985. spin_lock_irqsave(&pp->lock, flags);
  986. if (pp->cmd.status == 1) {
  987. if (file->f_flags & O_NONBLOCK)
  988. return -EAGAIN;
  989. add_wait_queue(&pp->wait, &wait);
  990. for (;;) {
  991. set_current_state(TASK_INTERRUPTIBLE);
  992. rc = 0;
  993. if (pp->cmd.status != 1)
  994. break;
  995. rc = -ERESTARTSYS;
  996. if (signal_pending(current))
  997. break;
  998. spin_unlock_irqrestore(&pp->lock, flags);
  999. schedule();
  1000. spin_lock_irqsave(&pp->lock, flags);
  1001. }
  1002. set_current_state(TASK_RUNNING);
  1003. remove_wait_queue(&pp->wait, &wait);
  1004. }
  1005. spin_unlock_irqrestore(&pp->lock, flags);
  1006. if (rc)
  1007. return rc;
  1008. if (pp->cmd.status != 0)
  1009. pp->cmd.reply_len = 0;
  1010. size = sizeof(hdr) + pp->cmd.reply_len;
  1011. if (count < size)
  1012. size = count;
  1013. rc = size;
  1014. hdr.status = pp->cmd.status;
  1015. hdr.reply_len = pp->cmd.reply_len;
  1016. if (copy_to_user(buf, &hdr, sizeof(hdr)))
  1017. return -EFAULT;
  1018. size -= sizeof(hdr);
  1019. if (size && copy_to_user(buf + sizeof(hdr), pp->buffer, size))
  1020. return -EFAULT;
  1021. pp->busy = 0;
  1022. return rc;
  1023. }
  1024. static ssize_t smu_read_events(struct file *file, struct smu_private *pp,
  1025. char __user *buf, size_t count)
  1026. {
  1027. /* Not implemented */
  1028. msleep_interruptible(1000);
  1029. return 0;
  1030. }
  1031. static ssize_t smu_read(struct file *file, char __user *buf,
  1032. size_t count, loff_t *ppos)
  1033. {
  1034. struct smu_private *pp = file->private_data;
  1035. if (pp->mode == smu_file_commands)
  1036. return smu_read_command(file, pp, buf, count);
  1037. if (pp->mode == smu_file_events)
  1038. return smu_read_events(file, pp, buf, count);
  1039. return -EBADFD;
  1040. }
  1041. static unsigned int smu_fpoll(struct file *file, poll_table *wait)
  1042. {
  1043. struct smu_private *pp = file->private_data;
  1044. unsigned int mask = 0;
  1045. unsigned long flags;
  1046. if (pp == 0)
  1047. return 0;
  1048. if (pp->mode == smu_file_commands) {
  1049. poll_wait(file, &pp->wait, wait);
  1050. spin_lock_irqsave(&pp->lock, flags);
  1051. if (pp->busy && pp->cmd.status != 1)
  1052. mask |= POLLIN;
  1053. spin_unlock_irqrestore(&pp->lock, flags);
  1054. } if (pp->mode == smu_file_events) {
  1055. /* Not yet implemented */
  1056. }
  1057. return mask;
  1058. }
  1059. static int smu_release(struct inode *inode, struct file *file)
  1060. {
  1061. struct smu_private *pp = file->private_data;
  1062. unsigned long flags;
  1063. unsigned int busy;
  1064. if (pp == 0)
  1065. return 0;
  1066. file->private_data = NULL;
  1067. /* Mark file as closing to avoid races with new request */
  1068. spin_lock_irqsave(&pp->lock, flags);
  1069. pp->mode = smu_file_closing;
  1070. busy = pp->busy;
  1071. /* Wait for any pending request to complete */
  1072. if (busy && pp->cmd.status == 1) {
  1073. DECLARE_WAITQUEUE(wait, current);
  1074. add_wait_queue(&pp->wait, &wait);
  1075. for (;;) {
  1076. set_current_state(TASK_UNINTERRUPTIBLE);
  1077. if (pp->cmd.status != 1)
  1078. break;
  1079. spin_unlock_irqrestore(&pp->lock, flags);
  1080. schedule();
  1081. spin_lock_irqsave(&pp->lock, flags);
  1082. }
  1083. set_current_state(TASK_RUNNING);
  1084. remove_wait_queue(&pp->wait, &wait);
  1085. }
  1086. spin_unlock_irqrestore(&pp->lock, flags);
  1087. spin_lock_irqsave(&smu_clist_lock, flags);
  1088. list_del(&pp->list);
  1089. spin_unlock_irqrestore(&smu_clist_lock, flags);
  1090. kfree(pp);
  1091. return 0;
  1092. }
  1093. static const struct file_operations smu_device_fops = {
  1094. .llseek = no_llseek,
  1095. .read = smu_read,
  1096. .write = smu_write,
  1097. .poll = smu_fpoll,
  1098. .open = smu_open,
  1099. .release = smu_release,
  1100. };
  1101. static struct miscdevice pmu_device = {
  1102. MISC_DYNAMIC_MINOR, "smu", &smu_device_fops
  1103. };
  1104. static int smu_device_init(void)
  1105. {
  1106. if (!smu)
  1107. return -ENODEV;
  1108. if (misc_register(&pmu_device) < 0)
  1109. printk(KERN_ERR "via-pmu: cannot register misc device.\n");
  1110. return 0;
  1111. }
  1112. device_initcall(smu_device_init);