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