intel_scu_ipc.c 18 KB

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