intel_scu_ipc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * intel_scu_ipc.c: Driver for the Intel SCU IPC mechanism
  3. *
  4. * (C) Copyright 2008-2010 Intel Corporation
  5. * Author: Sreedhara DS (sreedhara.ds@intel.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. *
  12. * SCU running in ARC processor communicates with other entity running in IA
  13. * core through IPC mechanism which in turn messaging between IA core ad SCU.
  14. * SCU has two IPC mechanism IPC-1 and IPC-2. IPC-1 is used between IA32 and
  15. * SCU where IPC-2 is used between P-Unit and SCU. This driver delas with
  16. * IPC-1 Driver provides an API for power control unit registers (e.g. MSIC)
  17. * along with other APIs.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/device.h>
  23. #include <linux/pm.h>
  24. #include <linux/pci.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/sfi.h>
  27. #include <linux/module.h>
  28. #include <asm/intel-mid.h>
  29. #include <asm/intel_scu_ipc.h>
  30. /* IPC defines the following message types */
  31. #define IPCMSG_WATCHDOG_TIMER 0xF8 /* Set Kernel Watchdog Threshold */
  32. #define IPCMSG_BATTERY 0xEF /* Coulomb Counter Accumulator */
  33. #define IPCMSG_FW_UPDATE 0xFE /* Firmware update */
  34. #define IPCMSG_PCNTRL 0xFF /* Power controller unit read/write */
  35. #define IPCMSG_FW_REVISION 0xF4 /* Get firmware revision */
  36. /* Command id associated with message IPCMSG_PCNTRL */
  37. #define IPC_CMD_PCNTRL_W 0 /* Register write */
  38. #define IPC_CMD_PCNTRL_R 1 /* Register read */
  39. #define IPC_CMD_PCNTRL_M 2 /* Register read-modify-write */
  40. /*
  41. * IPC register summary
  42. *
  43. * IPC register blocks are memory mapped at fixed address of 0xFF11C000
  44. * To read or write information to the SCU, driver writes to IPC-1 memory
  45. * mapped registers (base address 0xFF11C000). The following is the IPC
  46. * mechanism
  47. *
  48. * 1. IA core cDMI interface claims this transaction and converts it to a
  49. * Transaction Layer Packet (TLP) message which is sent across the cDMI.
  50. *
  51. * 2. South Complex cDMI block receives this message and writes it to
  52. * the IPC-1 register block, causing an interrupt to the SCU
  53. *
  54. * 3. SCU firmware decodes this interrupt and IPC message and the appropriate
  55. * message handler is called within firmware.
  56. */
  57. #define IPC_WWBUF_SIZE 20 /* IPC Write buffer Size */
  58. #define IPC_RWBUF_SIZE 20 /* IPC Read buffer Size */
  59. #define IPC_IOC 0x100 /* IPC command register IOC bit */
  60. enum {
  61. SCU_IPC_LINCROFT,
  62. SCU_IPC_PENWELL,
  63. SCU_IPC_CLOVERVIEW,
  64. SCU_IPC_TANGIER,
  65. };
  66. /* intel scu ipc driver data*/
  67. struct intel_scu_ipc_pdata_t {
  68. u32 ipc_base;
  69. u32 i2c_base;
  70. u32 ipc_len;
  71. u32 i2c_len;
  72. u8 irq_mode;
  73. };
  74. static struct intel_scu_ipc_pdata_t intel_scu_ipc_pdata[] = {
  75. [SCU_IPC_LINCROFT] = {
  76. .ipc_base = 0xff11c000,
  77. .i2c_base = 0xff12b000,
  78. .ipc_len = 0x100,
  79. .i2c_len = 0x10,
  80. .irq_mode = 0,
  81. },
  82. [SCU_IPC_PENWELL] = {
  83. .ipc_base = 0xff11c000,
  84. .i2c_base = 0xff12b000,
  85. .ipc_len = 0x100,
  86. .i2c_len = 0x10,
  87. .irq_mode = 1,
  88. },
  89. [SCU_IPC_CLOVERVIEW] = {
  90. .ipc_base = 0xff11c000,
  91. .i2c_base = 0xff12b000,
  92. .ipc_len = 0x100,
  93. .i2c_len = 0x10,
  94. .irq_mode = 1,
  95. },
  96. [SCU_IPC_TANGIER] = {
  97. .ipc_base = 0xff009000,
  98. .i2c_base = 0xff00d000,
  99. .ipc_len = 0x100,
  100. .i2c_len = 0x10,
  101. .irq_mode = 0,
  102. },
  103. };
  104. static int ipc_probe(struct pci_dev *dev, const struct pci_device_id *id);
  105. static void ipc_remove(struct pci_dev *pdev);
  106. struct intel_scu_ipc_dev {
  107. struct pci_dev *pdev;
  108. void __iomem *ipc_base;
  109. void __iomem *i2c_base;
  110. struct completion cmd_complete;
  111. u8 irq_mode;
  112. };
  113. static struct intel_scu_ipc_dev ipcdev; /* Only one for now */
  114. static int platform; /* Platform type */
  115. /*
  116. * IPC Read Buffer (Read Only):
  117. * 16 byte buffer for receiving data from SCU, if IPC command
  118. * processing results in response data
  119. */
  120. #define IPC_READ_BUFFER 0x90
  121. #define IPC_I2C_CNTRL_ADDR 0
  122. #define I2C_DATA_ADDR 0x04
  123. static DEFINE_MUTEX(ipclock); /* lock used to prevent multiple call to SCU */
  124. /*
  125. * Command Register (Write Only):
  126. * A write to this register results in an interrupt to the SCU core processor
  127. * Format:
  128. * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
  129. */
  130. static inline void ipc_command(u32 cmd) /* Send ipc command */
  131. {
  132. if (ipcdev.irq_mode) {
  133. reinit_completion(&ipcdev.cmd_complete);
  134. writel(cmd | IPC_IOC, ipcdev.ipc_base);
  135. }
  136. writel(cmd, ipcdev.ipc_base);
  137. }
  138. /*
  139. * IPC Write Buffer (Write Only):
  140. * 16-byte buffer for sending data associated with IPC command to
  141. * SCU. Size of the data is specified in the IPC_COMMAND_REG register
  142. */
  143. static inline void ipc_data_writel(u32 data, u32 offset) /* Write ipc data */
  144. {
  145. writel(data, ipcdev.ipc_base + 0x80 + offset);
  146. }
  147. /*
  148. * Status Register (Read Only):
  149. * Driver will read this register to get the ready/busy status of the IPC
  150. * block and error status of the IPC command that was just processed by SCU
  151. * Format:
  152. * |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)|
  153. */
  154. static inline u8 ipc_read_status(void)
  155. {
  156. return __raw_readl(ipcdev.ipc_base + 0x04);
  157. }
  158. static inline u8 ipc_data_readb(u32 offset) /* Read ipc byte data */
  159. {
  160. return readb(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
  161. }
  162. static inline u32 ipc_data_readl(u32 offset) /* Read ipc u32 data */
  163. {
  164. return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
  165. }
  166. static inline int busy_loop(void) /* Wait till scu status is busy */
  167. {
  168. u32 status = 0;
  169. u32 loop_count = 0;
  170. status = ipc_read_status();
  171. while (status & 1) {
  172. udelay(1); /* scu processing time is in few u secods */
  173. status = ipc_read_status();
  174. loop_count++;
  175. /* break if scu doesn't reset busy bit after huge retry */
  176. if (loop_count > 100000) {
  177. dev_err(&ipcdev.pdev->dev, "IPC timed out");
  178. return -ETIMEDOUT;
  179. }
  180. }
  181. if ((status >> 1) & 1)
  182. return -EIO;
  183. return 0;
  184. }
  185. /* Wait till ipc ioc interrupt is received or timeout in 3 HZ */
  186. static inline int ipc_wait_for_interrupt(void)
  187. {
  188. int status;
  189. if (!wait_for_completion_timeout(&ipcdev.cmd_complete, 3 * HZ)) {
  190. struct device *dev = &ipcdev.pdev->dev;
  191. dev_err(dev, "IPC timed out\n");
  192. return -ETIMEDOUT;
  193. }
  194. status = ipc_read_status();
  195. if ((status >> 1) & 1)
  196. return -EIO;
  197. return 0;
  198. }
  199. int intel_scu_ipc_check_status(void)
  200. {
  201. return ipcdev.irq_mode ? ipc_wait_for_interrupt() : busy_loop();
  202. }
  203. /* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */
  204. static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id)
  205. {
  206. int nc;
  207. u32 offset = 0;
  208. int err;
  209. u8 cbuf[IPC_WWBUF_SIZE] = { };
  210. u32 *wbuf = (u32 *)&cbuf;
  211. mutex_lock(&ipclock);
  212. memset(cbuf, 0, sizeof(cbuf));
  213. if (ipcdev.pdev == NULL) {
  214. mutex_unlock(&ipclock);
  215. return -ENODEV;
  216. }
  217. for (nc = 0; nc < count; nc++, offset += 2) {
  218. cbuf[offset] = addr[nc];
  219. cbuf[offset + 1] = addr[nc] >> 8;
  220. }
  221. if (id == IPC_CMD_PCNTRL_R) {
  222. for (nc = 0, offset = 0; nc < count; nc++, offset += 4)
  223. ipc_data_writel(wbuf[nc], offset);
  224. ipc_command((count*2) << 16 | id << 12 | 0 << 8 | op);
  225. } else if (id == IPC_CMD_PCNTRL_W) {
  226. for (nc = 0; nc < count; nc++, offset += 1)
  227. cbuf[offset] = data[nc];
  228. for (nc = 0, offset = 0; nc < count; nc++, offset += 4)
  229. ipc_data_writel(wbuf[nc], offset);
  230. ipc_command((count*3) << 16 | id << 12 | 0 << 8 | op);
  231. } else if (id == IPC_CMD_PCNTRL_M) {
  232. cbuf[offset] = data[0];
  233. cbuf[offset + 1] = data[1];
  234. ipc_data_writel(wbuf[0], 0); /* Write wbuff */
  235. ipc_command(4 << 16 | id << 12 | 0 << 8 | op);
  236. }
  237. err = intel_scu_ipc_check_status();
  238. if (!err && id == IPC_CMD_PCNTRL_R) { /* Read rbuf */
  239. /* Workaround: values are read as 0 without memcpy_fromio */
  240. memcpy_fromio(cbuf, ipcdev.ipc_base + 0x90, 16);
  241. for (nc = 0; nc < count; nc++)
  242. data[nc] = ipc_data_readb(nc);
  243. }
  244. mutex_unlock(&ipclock);
  245. return err;
  246. }
  247. /**
  248. * intel_scu_ipc_ioread8 - read a word via the SCU
  249. * @addr: register on SCU
  250. * @data: return pointer for read byte
  251. *
  252. * Read a single register. Returns 0 on success or an error code. All
  253. * locking between SCU accesses is handled for the caller.
  254. *
  255. * This function may sleep.
  256. */
  257. int intel_scu_ipc_ioread8(u16 addr, u8 *data)
  258. {
  259. return pwr_reg_rdwr(&addr, data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
  260. }
  261. EXPORT_SYMBOL(intel_scu_ipc_ioread8);
  262. /**
  263. * intel_scu_ipc_ioread16 - read a word via the SCU
  264. * @addr: register on SCU
  265. * @data: return pointer for read word
  266. *
  267. * Read a register pair. Returns 0 on success or an error code. All
  268. * locking between SCU accesses is handled for the caller.
  269. *
  270. * This function may sleep.
  271. */
  272. int intel_scu_ipc_ioread16(u16 addr, u16 *data)
  273. {
  274. u16 x[2] = {addr, addr + 1 };
  275. return pwr_reg_rdwr(x, (u8 *)data, 2, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
  276. }
  277. EXPORT_SYMBOL(intel_scu_ipc_ioread16);
  278. /**
  279. * intel_scu_ipc_ioread32 - read a dword via the SCU
  280. * @addr: register on SCU
  281. * @data: return pointer for read dword
  282. *
  283. * Read four registers. Returns 0 on success or an error code. All
  284. * locking between SCU accesses is handled for the caller.
  285. *
  286. * This function may sleep.
  287. */
  288. int intel_scu_ipc_ioread32(u16 addr, u32 *data)
  289. {
  290. u16 x[4] = {addr, addr + 1, addr + 2, addr + 3};
  291. return pwr_reg_rdwr(x, (u8 *)data, 4, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
  292. }
  293. EXPORT_SYMBOL(intel_scu_ipc_ioread32);
  294. /**
  295. * intel_scu_ipc_iowrite8 - write a byte via the SCU
  296. * @addr: register on SCU
  297. * @data: byte to write
  298. *
  299. * Write a single register. Returns 0 on success or an error code. All
  300. * locking between SCU accesses is handled for the caller.
  301. *
  302. * This function may sleep.
  303. */
  304. int intel_scu_ipc_iowrite8(u16 addr, u8 data)
  305. {
  306. return pwr_reg_rdwr(&addr, &data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
  307. }
  308. EXPORT_SYMBOL(intel_scu_ipc_iowrite8);
  309. /**
  310. * intel_scu_ipc_iowrite16 - write a word via the SCU
  311. * @addr: register on SCU
  312. * @data: word to write
  313. *
  314. * Write two registers. Returns 0 on success or an error code. All
  315. * locking between SCU accesses is handled for the caller.
  316. *
  317. * This function may sleep.
  318. */
  319. int intel_scu_ipc_iowrite16(u16 addr, u16 data)
  320. {
  321. u16 x[2] = {addr, addr + 1 };
  322. return pwr_reg_rdwr(x, (u8 *)&data, 2, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
  323. }
  324. EXPORT_SYMBOL(intel_scu_ipc_iowrite16);
  325. /**
  326. * intel_scu_ipc_iowrite32 - write a dword via the SCU
  327. * @addr: register on SCU
  328. * @data: dword to write
  329. *
  330. * Write four registers. Returns 0 on success or an error code. All
  331. * locking between SCU accesses is handled for the caller.
  332. *
  333. * This function may sleep.
  334. */
  335. int intel_scu_ipc_iowrite32(u16 addr, u32 data)
  336. {
  337. u16 x[4] = {addr, addr + 1, addr + 2, addr + 3};
  338. return pwr_reg_rdwr(x, (u8 *)&data, 4, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
  339. }
  340. EXPORT_SYMBOL(intel_scu_ipc_iowrite32);
  341. /**
  342. * intel_scu_ipc_readvv - read a set of registers
  343. * @addr: register list
  344. * @data: bytes to return
  345. * @len: length of array
  346. *
  347. * Read registers. Returns 0 on success or an error code. All
  348. * locking between SCU accesses is handled for the caller.
  349. *
  350. * The largest array length permitted by the hardware is 5 items.
  351. *
  352. * This function may sleep.
  353. */
  354. int intel_scu_ipc_readv(u16 *addr, u8 *data, int len)
  355. {
  356. return pwr_reg_rdwr(addr, data, len, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
  357. }
  358. EXPORT_SYMBOL(intel_scu_ipc_readv);
  359. /**
  360. * intel_scu_ipc_writev - write a set of registers
  361. * @addr: register list
  362. * @data: bytes to write
  363. * @len: length of array
  364. *
  365. * Write registers. Returns 0 on success or an error code. All
  366. * locking between SCU accesses is handled for the caller.
  367. *
  368. * The largest array length permitted by the hardware is 5 items.
  369. *
  370. * This function may sleep.
  371. *
  372. */
  373. int intel_scu_ipc_writev(u16 *addr, u8 *data, int len)
  374. {
  375. return pwr_reg_rdwr(addr, data, len, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
  376. }
  377. EXPORT_SYMBOL(intel_scu_ipc_writev);
  378. /**
  379. * intel_scu_ipc_update_register - r/m/w a register
  380. * @addr: register address
  381. * @bits: bits to update
  382. * @mask: mask of bits to update
  383. *
  384. * Read-modify-write power control unit register. The first data argument
  385. * must be register value and second is mask value
  386. * mask is a bitmap that indicates which bits to update.
  387. * 0 = masked. Don't modify this bit, 1 = modify this bit.
  388. * returns 0 on success or an error code.
  389. *
  390. * This function may sleep. Locking between SCU accesses is handled
  391. * for the caller.
  392. */
  393. int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask)
  394. {
  395. u8 data[2] = { bits, mask };
  396. return pwr_reg_rdwr(&addr, data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_M);
  397. }
  398. EXPORT_SYMBOL(intel_scu_ipc_update_register);
  399. /**
  400. * intel_scu_ipc_simple_command - send a simple command
  401. * @cmd: command
  402. * @sub: sub type
  403. *
  404. * Issue a simple command to the SCU. Do not use this interface if
  405. * you must then access data as any data values may be overwritten
  406. * by another SCU access by the time this function returns.
  407. *
  408. * This function may sleep. Locking for SCU accesses is handled for
  409. * the caller.
  410. */
  411. int intel_scu_ipc_simple_command(int cmd, int sub)
  412. {
  413. int err;
  414. mutex_lock(&ipclock);
  415. if (ipcdev.pdev == NULL) {
  416. mutex_unlock(&ipclock);
  417. return -ENODEV;
  418. }
  419. ipc_command(sub << 12 | cmd);
  420. err = intel_scu_ipc_check_status();
  421. mutex_unlock(&ipclock);
  422. return err;
  423. }
  424. EXPORT_SYMBOL(intel_scu_ipc_simple_command);
  425. /**
  426. * intel_scu_ipc_command - command with data
  427. * @cmd: command
  428. * @sub: sub type
  429. * @in: input data
  430. * @inlen: input length in dwords
  431. * @out: output data
  432. * @outlein: output length in dwords
  433. *
  434. * Issue a command to the SCU which involves data transfers. Do the
  435. * data copies under the lock but leave it for the caller to interpret
  436. */
  437. int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen,
  438. u32 *out, int outlen)
  439. {
  440. int i, err;
  441. mutex_lock(&ipclock);
  442. if (ipcdev.pdev == NULL) {
  443. mutex_unlock(&ipclock);
  444. return -ENODEV;
  445. }
  446. for (i = 0; i < inlen; i++)
  447. ipc_data_writel(*in++, 4 * i);
  448. ipc_command((inlen << 16) | (sub << 12) | cmd);
  449. err = intel_scu_ipc_check_status();
  450. if (!err) {
  451. for (i = 0; i < outlen; i++)
  452. *out++ = ipc_data_readl(4 * i);
  453. }
  454. mutex_unlock(&ipclock);
  455. return err;
  456. }
  457. EXPORT_SYMBOL(intel_scu_ipc_command);
  458. /*I2C commands */
  459. #define IPC_I2C_WRITE 1 /* I2C Write command */
  460. #define IPC_I2C_READ 2 /* I2C Read command */
  461. /**
  462. * intel_scu_ipc_i2c_cntrl - I2C read/write operations
  463. * @addr: I2C address + command bits
  464. * @data: data to read/write
  465. *
  466. * Perform an an I2C read/write operation via the SCU. All locking is
  467. * handled for the caller. This function may sleep.
  468. *
  469. * Returns an error code or 0 on success.
  470. *
  471. * This has to be in the IPC driver for the locking.
  472. */
  473. int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
  474. {
  475. u32 cmd = 0;
  476. mutex_lock(&ipclock);
  477. if (ipcdev.pdev == NULL) {
  478. mutex_unlock(&ipclock);
  479. return -ENODEV;
  480. }
  481. cmd = (addr >> 24) & 0xFF;
  482. if (cmd == IPC_I2C_READ) {
  483. writel(addr, ipcdev.i2c_base + IPC_I2C_CNTRL_ADDR);
  484. /* Write not getting updated without delay */
  485. mdelay(1);
  486. *data = readl(ipcdev.i2c_base + I2C_DATA_ADDR);
  487. } else if (cmd == IPC_I2C_WRITE) {
  488. writel(*data, ipcdev.i2c_base + I2C_DATA_ADDR);
  489. mdelay(1);
  490. writel(addr, ipcdev.i2c_base + IPC_I2C_CNTRL_ADDR);
  491. } else {
  492. dev_err(&ipcdev.pdev->dev,
  493. "intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd);
  494. mutex_unlock(&ipclock);
  495. return -EIO;
  496. }
  497. mutex_unlock(&ipclock);
  498. return 0;
  499. }
  500. EXPORT_SYMBOL(intel_scu_ipc_i2c_cntrl);
  501. /*
  502. * Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1
  503. * When ioc bit is set to 1, caller api must wait for interrupt handler called
  504. * which in turn unlocks the caller api. Currently this is not used
  505. *
  506. * This is edge triggered so we need take no action to clear anything
  507. */
  508. static irqreturn_t ioc(int irq, void *dev_id)
  509. {
  510. if (ipcdev.irq_mode)
  511. complete(&ipcdev.cmd_complete);
  512. return IRQ_HANDLED;
  513. }
  514. /**
  515. * ipc_probe - probe an Intel SCU IPC
  516. * @dev: the PCI device matching
  517. * @id: entry in the match table
  518. *
  519. * Enable and install an intel SCU IPC. This appears in the PCI space
  520. * but uses some hard coded addresses as well.
  521. */
  522. static int ipc_probe(struct pci_dev *dev, const struct pci_device_id *id)
  523. {
  524. int err, pid;
  525. struct intel_scu_ipc_pdata_t *pdata;
  526. resource_size_t pci_resource;
  527. if (ipcdev.pdev) /* We support only one SCU */
  528. return -EBUSY;
  529. pid = id->driver_data;
  530. pdata = &intel_scu_ipc_pdata[pid];
  531. ipcdev.pdev = pci_dev_get(dev);
  532. ipcdev.irq_mode = pdata->irq_mode;
  533. err = pci_enable_device(dev);
  534. if (err)
  535. return err;
  536. err = pci_request_regions(dev, "intel_scu_ipc");
  537. if (err)
  538. return err;
  539. pci_resource = pci_resource_start(dev, 0);
  540. if (!pci_resource)
  541. return -ENOMEM;
  542. init_completion(&ipcdev.cmd_complete);
  543. if (request_irq(dev->irq, ioc, 0, "intel_scu_ipc", &ipcdev))
  544. return -EBUSY;
  545. ipcdev.ipc_base = ioremap_nocache(pdata->ipc_base, pdata->ipc_len);
  546. if (!ipcdev.ipc_base)
  547. return -ENOMEM;
  548. ipcdev.i2c_base = ioremap_nocache(pdata->i2c_base, pdata->i2c_len);
  549. if (!ipcdev.i2c_base) {
  550. iounmap(ipcdev.ipc_base);
  551. return -ENOMEM;
  552. }
  553. intel_scu_devices_create();
  554. return 0;
  555. }
  556. /**
  557. * ipc_remove - remove a bound IPC device
  558. * @pdev: PCI device
  559. *
  560. * In practice the SCU is not removable but this function is also
  561. * called for each device on a module unload or cleanup which is the
  562. * path that will get used.
  563. *
  564. * Free up the mappings and release the PCI resources
  565. */
  566. static void ipc_remove(struct pci_dev *pdev)
  567. {
  568. free_irq(pdev->irq, &ipcdev);
  569. pci_release_regions(pdev);
  570. pci_dev_put(ipcdev.pdev);
  571. iounmap(ipcdev.ipc_base);
  572. iounmap(ipcdev.i2c_base);
  573. ipcdev.pdev = NULL;
  574. intel_scu_devices_destroy();
  575. }
  576. static DEFINE_PCI_DEVICE_TABLE(pci_ids) = {
  577. {PCI_VDEVICE(INTEL, 0x082a), SCU_IPC_LINCROFT},
  578. {PCI_VDEVICE(INTEL, 0x080e), SCU_IPC_PENWELL},
  579. {PCI_VDEVICE(INTEL, 0x08ea), SCU_IPC_CLOVERVIEW},
  580. {PCI_VDEVICE(INTEL, 0x11a0), SCU_IPC_TANGIER},
  581. { 0,}
  582. };
  583. MODULE_DEVICE_TABLE(pci, pci_ids);
  584. static struct pci_driver ipc_driver = {
  585. .name = "intel_scu_ipc",
  586. .id_table = pci_ids,
  587. .probe = ipc_probe,
  588. .remove = ipc_remove,
  589. };
  590. static int __init intel_scu_ipc_init(void)
  591. {
  592. platform = intel_mid_identify_cpu();
  593. if (platform == 0)
  594. return -ENODEV;
  595. return pci_register_driver(&ipc_driver);
  596. }
  597. static void __exit intel_scu_ipc_exit(void)
  598. {
  599. pci_unregister_driver(&ipc_driver);
  600. }
  601. MODULE_AUTHOR("Sreedhara DS <sreedhara.ds@intel.com>");
  602. MODULE_DESCRIPTION("Intel SCU IPC driver");
  603. MODULE_LICENSE("GPL");
  604. module_init(intel_scu_ipc_init);
  605. module_exit(intel_scu_ipc_exit);