intel_scu_ipc.c 18 KB

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