intel_scu_ipc.c 18 KB

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