blob: 39ff57bdf18f1154a4a2152b9bf3d967201fa76f [file] [log] [blame]
Sreedhara DS9a58a332010-04-26 18:13:05 +01001/*
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 *
Lucas De Marchic8440332011-03-17 17:18:22 -030012 * SCU running in ARC processor communicates with other entity running in IA
Sreedhara DS9a58a332010-04-26 18:13:05 +010013 * 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>
Kay Sieversedbaa602011-12-21 16:26:03 -080022#include <linux/device.h>
Sreedhara DS9a58a332010-04-26 18:13:05 +010023#include <linux/pm.h>
24#include <linux/pci.h>
25#include <linux/interrupt.h>
Alan Cox209009b2010-09-13 15:55:05 +010026#include <linux/sfi.h>
Paul Gortmaker7c52d552011-05-27 12:33:10 -040027#include <linux/module.h>
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -070028#include <asm/intel-mid.h>
Sreedhara DS9a58a332010-04-26 18:13:05 +010029#include <asm/intel_scu_ipc.h>
30
31/* IPC defines the following message types */
32#define IPCMSG_WATCHDOG_TIMER 0xF8 /* Set Kernel Watchdog Threshold */
33#define IPCMSG_BATTERY 0xEF /* Coulomb Counter Accumulator */
34#define IPCMSG_FW_UPDATE 0xFE /* Firmware update */
35#define IPCMSG_PCNTRL 0xFF /* Power controller unit read/write */
36#define IPCMSG_FW_REVISION 0xF4 /* Get firmware revision */
37
38/* Command id associated with message IPCMSG_PCNTRL */
39#define IPC_CMD_PCNTRL_W 0 /* Register write */
40#define IPC_CMD_PCNTRL_R 1 /* Register read */
41#define IPC_CMD_PCNTRL_M 2 /* Register read-modify-write */
42
Sreedhara DS9a58a332010-04-26 18:13:05 +010043/*
44 * IPC register summary
45 *
46 * IPC register blocks are memory mapped at fixed address of 0xFF11C000
47 * To read or write information to the SCU, driver writes to IPC-1 memory
48 * mapped registers (base address 0xFF11C000). The following is the IPC
49 * mechanism
50 *
51 * 1. IA core cDMI interface claims this transaction and converts it to a
52 * Transaction Layer Packet (TLP) message which is sent across the cDMI.
53 *
54 * 2. South Complex cDMI block receives this message and writes it to
55 * the IPC-1 register block, causing an interrupt to the SCU
56 *
57 * 3. SCU firmware decodes this interrupt and IPC message and the appropriate
58 * message handler is called within firmware.
59 */
60
Arjan van de Ven51cd5252010-07-26 10:04:24 +010061#define IPC_WWBUF_SIZE 20 /* IPC Write buffer Size */
62#define IPC_RWBUF_SIZE 20 /* IPC Read buffer Size */
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -080063
64enum {
65 SCU_IPC_LINCROFT,
66};
67
68/* intel scu ipc driver data*/
69struct intel_scu_ipc_pdata_t {
70 u32 ipc_base;
71 u32 i2c_base;
72 u32 ipc_len;
73 u32 i2c_len;
74};
75
76static struct intel_scu_ipc_pdata_t intel_scu_ipc_pdata[] = {
77 [SCU_IPC_LINCROFT] = {
78 .ipc_base = 0xff11c000,
79 .i2c_base = 0xff12b000,
80 .ipc_len = 0x100,
81 .i2c_len = 0x10,
82 },
83};
Sreedhara DS9a58a332010-04-26 18:13:05 +010084
85static int ipc_probe(struct pci_dev *dev, const struct pci_device_id *id);
86static void ipc_remove(struct pci_dev *pdev);
87
88struct intel_scu_ipc_dev {
89 struct pci_dev *pdev;
90 void __iomem *ipc_base;
91 void __iomem *i2c_base;
92};
93
94static struct intel_scu_ipc_dev ipcdev; /* Only one for now */
95
Sreedhara DS14d10f02010-07-26 10:02:25 +010096static int platform; /* Platform type */
Sreedhara DS9a58a332010-04-26 18:13:05 +010097
98/*
99 * IPC Read Buffer (Read Only):
100 * 16 byte buffer for receiving data from SCU, if IPC command
101 * processing results in response data
102 */
103#define IPC_READ_BUFFER 0x90
104
105#define IPC_I2C_CNTRL_ADDR 0
106#define I2C_DATA_ADDR 0x04
107
108static DEFINE_MUTEX(ipclock); /* lock used to prevent multiple call to SCU */
109
110/*
111 * Command Register (Write Only):
112 * A write to this register results in an interrupt to the SCU core processor
113 * Format:
114 * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
115 */
116static inline void ipc_command(u32 cmd) /* Send ipc command */
117{
118 writel(cmd, ipcdev.ipc_base);
119}
120
121/*
122 * IPC Write Buffer (Write Only):
123 * 16-byte buffer for sending data associated with IPC command to
124 * SCU. Size of the data is specified in the IPC_COMMAND_REG register
125 */
126static inline void ipc_data_writel(u32 data, u32 offset) /* Write ipc data */
127{
128 writel(data, ipcdev.ipc_base + 0x80 + offset);
129}
130
131/*
Sreedhara DS9a58a332010-04-26 18:13:05 +0100132 * Status Register (Read Only):
133 * Driver will read this register to get the ready/busy status of the IPC
134 * block and error status of the IPC command that was just processed by SCU
135 * Format:
136 * |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)|
137 */
138
139static inline u8 ipc_read_status(void)
140{
141 return __raw_readl(ipcdev.ipc_base + 0x04);
142}
143
144static inline u8 ipc_data_readb(u32 offset) /* Read ipc byte data */
145{
146 return readb(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
147}
148
Sreedhara DSe3359fd2010-07-26 10:02:46 +0100149static inline u32 ipc_data_readl(u32 offset) /* Read ipc u32 data */
Sreedhara DS9a58a332010-04-26 18:13:05 +0100150{
151 return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
152}
153
154static inline int busy_loop(void) /* Wait till scu status is busy */
155{
156 u32 status = 0;
157 u32 loop_count = 0;
158
159 status = ipc_read_status();
160 while (status & 1) {
161 udelay(1); /* scu processing time is in few u secods */
162 status = ipc_read_status();
163 loop_count++;
164 /* break if scu doesn't reset busy bit after huge retry */
165 if (loop_count > 100000) {
166 dev_err(&ipcdev.pdev->dev, "IPC timed out");
167 return -ETIMEDOUT;
168 }
169 }
Hong Liu77e01d62010-07-26 10:06:12 +0100170 if ((status >> 1) & 1)
171 return -EIO;
172
173 return 0;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100174}
175
176/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */
177static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id)
178{
Alan Cox47073752012-03-05 15:01:02 -0800179 int nc;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100180 u32 offset = 0;
Axel Linecb56462011-01-25 14:12:12 +0000181 int err;
Sreedhara DSe3359fd2010-07-26 10:02:46 +0100182 u8 cbuf[IPC_WWBUF_SIZE] = { };
Sreedhara DS9a58a332010-04-26 18:13:05 +0100183 u32 *wbuf = (u32 *)&cbuf;
184
185 mutex_lock(&ipclock);
Sreedhara DSe3359fd2010-07-26 10:02:46 +0100186
Arjan van de Vened6f2b42010-07-26 10:04:37 +0100187 memset(cbuf, 0, sizeof(cbuf));
188
Sreedhara DS9a58a332010-04-26 18:13:05 +0100189 if (ipcdev.pdev == NULL) {
190 mutex_unlock(&ipclock);
191 return -ENODEV;
192 }
193
Alan Cox47073752012-03-05 15:01:02 -0800194 for (nc = 0; nc < count; nc++, offset += 2) {
195 cbuf[offset] = addr[nc];
196 cbuf[offset + 1] = addr[nc] >> 8;
197 }
Sreedhara DSe3359fd2010-07-26 10:02:46 +0100198
Alan Cox47073752012-03-05 15:01:02 -0800199 if (id == IPC_CMD_PCNTRL_R) {
200 for (nc = 0, offset = 0; nc < count; nc++, offset += 4)
201 ipc_data_writel(wbuf[nc], offset);
202 ipc_command((count*2) << 16 | id << 12 | 0 << 8 | op);
203 } else if (id == IPC_CMD_PCNTRL_W) {
204 for (nc = 0; nc < count; nc++, offset += 1)
205 cbuf[offset] = data[nc];
206 for (nc = 0, offset = 0; nc < count; nc++, offset += 4)
207 ipc_data_writel(wbuf[nc], offset);
208 ipc_command((count*3) << 16 | id << 12 | 0 << 8 | op);
209 } else if (id == IPC_CMD_PCNTRL_M) {
210 cbuf[offset] = data[0];
211 cbuf[offset + 1] = data[1];
212 ipc_data_writel(wbuf[0], 0); /* Write wbuff */
213 ipc_command(4 << 16 | id << 12 | 0 << 8 | op);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100214 }
215
Sreedhara DS9a58a332010-04-26 18:13:05 +0100216 err = busy_loop();
Sreedhara DS9a58a332010-04-26 18:13:05 +0100217 if (id == IPC_CMD_PCNTRL_R) { /* Read rbuf */
218 /* Workaround: values are read as 0 without memcpy_fromio */
Sreedhara DSe3359fd2010-07-26 10:02:46 +0100219 memcpy_fromio(cbuf, ipcdev.ipc_base + 0x90, 16);
Alan Cox47073752012-03-05 15:01:02 -0800220 for (nc = 0; nc < count; nc++)
221 data[nc] = ipc_data_readb(nc);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100222 }
223 mutex_unlock(&ipclock);
224 return err;
225}
226
227/**
228 * intel_scu_ipc_ioread8 - read a word via the SCU
229 * @addr: register on SCU
230 * @data: return pointer for read byte
231 *
232 * Read a single register. Returns 0 on success or an error code. All
233 * locking between SCU accesses is handled for the caller.
234 *
235 * This function may sleep.
236 */
237int intel_scu_ipc_ioread8(u16 addr, u8 *data)
238{
239 return pwr_reg_rdwr(&addr, data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
240}
241EXPORT_SYMBOL(intel_scu_ipc_ioread8);
242
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 */
253int 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}
258EXPORT_SYMBOL(intel_scu_ipc_ioread16);
259
260/**
261 * intel_scu_ipc_ioread32 - read a dword via the SCU
262 * @addr: register on SCU
263 * @data: return pointer for read dword
264 *
265 * Read four registers. 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 */
270int intel_scu_ipc_ioread32(u16 addr, u32 *data)
271{
272 u16 x[4] = {addr, addr + 1, addr + 2, addr + 3};
273 return pwr_reg_rdwr(x, (u8 *)data, 4, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
274}
275EXPORT_SYMBOL(intel_scu_ipc_ioread32);
276
277/**
278 * intel_scu_ipc_iowrite8 - write a byte via the SCU
279 * @addr: register on SCU
280 * @data: byte to write
281 *
282 * Write a single register. Returns 0 on success or an error code. All
283 * locking between SCU accesses is handled for the caller.
284 *
285 * This function may sleep.
286 */
287int intel_scu_ipc_iowrite8(u16 addr, u8 data)
288{
289 return pwr_reg_rdwr(&addr, &data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
290}
291EXPORT_SYMBOL(intel_scu_ipc_iowrite8);
292
293/**
294 * intel_scu_ipc_iowrite16 - write a word via the SCU
295 * @addr: register on SCU
296 * @data: word to write
297 *
298 * Write two 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 */
303int intel_scu_ipc_iowrite16(u16 addr, u16 data)
304{
305 u16 x[2] = {addr, addr + 1 };
306 return pwr_reg_rdwr(x, (u8 *)&data, 2, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
307}
308EXPORT_SYMBOL(intel_scu_ipc_iowrite16);
309
310/**
311 * intel_scu_ipc_iowrite32 - write a dword via the SCU
312 * @addr: register on SCU
313 * @data: dword to write
314 *
315 * Write four registers. 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 */
320int intel_scu_ipc_iowrite32(u16 addr, u32 data)
321{
322 u16 x[4] = {addr, addr + 1, addr + 2, addr + 3};
323 return pwr_reg_rdwr(x, (u8 *)&data, 4, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
324}
325EXPORT_SYMBOL(intel_scu_ipc_iowrite32);
326
327/**
328 * intel_scu_ipc_readvv - read a set of registers
329 * @addr: register list
330 * @data: bytes to return
331 * @len: length of array
332 *
333 * Read registers. Returns 0 on success or an error code. All
334 * locking between SCU accesses is handled for the caller.
335 *
336 * The largest array length permitted by the hardware is 5 items.
337 *
338 * This function may sleep.
339 */
340int intel_scu_ipc_readv(u16 *addr, u8 *data, int len)
341{
342 return pwr_reg_rdwr(addr, data, len, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_R);
343}
344EXPORT_SYMBOL(intel_scu_ipc_readv);
345
346/**
347 * intel_scu_ipc_writev - write a set of registers
348 * @addr: register list
349 * @data: bytes to write
350 * @len: length of array
351 *
352 * Write registers. Returns 0 on success or an error code. All
353 * locking between SCU accesses is handled for the caller.
354 *
355 * The largest array length permitted by the hardware is 5 items.
356 *
357 * This function may sleep.
358 *
359 */
360int intel_scu_ipc_writev(u16 *addr, u8 *data, int len)
361{
362 return pwr_reg_rdwr(addr, data, len, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_W);
363}
364EXPORT_SYMBOL(intel_scu_ipc_writev);
365
366
367/**
368 * intel_scu_ipc_update_register - r/m/w a register
369 * @addr: register address
370 * @bits: bits to update
371 * @mask: mask of bits to update
372 *
373 * Read-modify-write power control unit register. The first data argument
374 * must be register value and second is mask value
375 * mask is a bitmap that indicates which bits to update.
376 * 0 = masked. Don't modify this bit, 1 = modify this bit.
377 * returns 0 on success or an error code.
378 *
379 * This function may sleep. Locking between SCU accesses is handled
380 * for the caller.
381 */
382int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask)
383{
384 u8 data[2] = { bits, mask };
385 return pwr_reg_rdwr(&addr, data, 1, IPCMSG_PCNTRL, IPC_CMD_PCNTRL_M);
386}
387EXPORT_SYMBOL(intel_scu_ipc_update_register);
388
389/**
Sreedhara DS9a58a332010-04-26 18:13:05 +0100390 * 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 */
401int intel_scu_ipc_simple_command(int cmd, int sub)
402{
Axel Linecb56462011-01-25 14:12:12 +0000403 int err;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100404
405 mutex_lock(&ipclock);
406 if (ipcdev.pdev == NULL) {
407 mutex_unlock(&ipclock);
408 return -ENODEV;
409 }
Sreedhara DSb4fd4f82010-07-19 09:37:42 +0100410 ipc_command(sub << 12 | cmd);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100411 err = busy_loop();
412 mutex_unlock(&ipclock);
413 return err;
414}
415EXPORT_SYMBOL(intel_scu_ipc_simple_command);
416
417/**
418 * intel_scu_ipc_command - command with data
419 * @cmd: command
420 * @sub: sub type
421 * @in: input data
Sreedhara DSb4fd4f82010-07-19 09:37:42 +0100422 * @inlen: input length in dwords
Sreedhara DS9a58a332010-04-26 18:13:05 +0100423 * @out: output data
Sreedhara DSb4fd4f82010-07-19 09:37:42 +0100424 * @outlein: output length in dwords
Sreedhara DS9a58a332010-04-26 18:13:05 +0100425 *
426 * Issue a command to the SCU which involves data transfers. Do the
427 * data copies under the lock but leave it for the caller to interpret
428 */
429
430int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen,
431 u32 *out, int outlen)
432{
Axel Linecb56462011-01-25 14:12:12 +0000433 int i, err;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100434
435 mutex_lock(&ipclock);
436 if (ipcdev.pdev == NULL) {
437 mutex_unlock(&ipclock);
438 return -ENODEV;
439 }
440
441 for (i = 0; i < inlen; i++)
442 ipc_data_writel(*in++, 4 * i);
443
Hong Liu5aa06932010-07-26 10:06:31 +0100444 ipc_command((inlen << 16) | (sub << 12) | cmd);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100445 err = busy_loop();
446
447 for (i = 0; i < outlen; i++)
448 *out++ = ipc_data_readl(4 * i);
449
450 mutex_unlock(&ipclock);
451 return err;
452}
453EXPORT_SYMBOL(intel_scu_ipc_command);
454
455/*I2C commands */
456#define IPC_I2C_WRITE 1 /* I2C Write command */
457#define IPC_I2C_READ 2 /* I2C Read command */
458
459/**
460 * intel_scu_ipc_i2c_cntrl - I2C read/write operations
461 * @addr: I2C address + command bits
462 * @data: data to read/write
463 *
464 * Perform an an I2C read/write operation via the SCU. All locking is
465 * handled for the caller. This function may sleep.
466 *
467 * Returns an error code or 0 on success.
468 *
469 * This has to be in the IPC driver for the locking.
470 */
471int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
472{
473 u32 cmd = 0;
474
475 mutex_lock(&ipclock);
Sreedhara DSb4fd4f82010-07-19 09:37:42 +0100476 if (ipcdev.pdev == NULL) {
477 mutex_unlock(&ipclock);
478 return -ENODEV;
479 }
Sreedhara DS9a58a332010-04-26 18:13:05 +0100480 cmd = (addr >> 24) & 0xFF;
481 if (cmd == IPC_I2C_READ) {
482 writel(addr, ipcdev.i2c_base + IPC_I2C_CNTRL_ADDR);
483 /* Write not getting updated without delay */
484 mdelay(1);
485 *data = readl(ipcdev.i2c_base + I2C_DATA_ADDR);
486 } else if (cmd == IPC_I2C_WRITE) {
Jianwei Yang32e2f632010-08-24 14:32:38 +0100487 writel(*data, ipcdev.i2c_base + I2C_DATA_ADDR);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100488 mdelay(1);
489 writel(addr, ipcdev.i2c_base + IPC_I2C_CNTRL_ADDR);
490 } else {
491 dev_err(&ipcdev.pdev->dev,
492 "intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd);
493
494 mutex_unlock(&ipclock);
Sreedhara DS5369c02d2010-10-22 15:43:55 +0100495 return -EIO;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100496 }
497 mutex_unlock(&ipclock);
498 return 0;
499}
500EXPORT_SYMBOL(intel_scu_ipc_i2c_cntrl);
501
Sreedhara DS9a58a332010-04-26 18:13:05 +0100502/*
503 * Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1
504 * When ioc bit is set to 1, caller api must wait for interrupt handler called
505 * which in turn unlocks the caller api. Currently this is not used
506 *
507 * This is edge triggered so we need take no action to clear anything
508 */
509static irqreturn_t ioc(int irq, void *dev_id)
510{
511 return IRQ_HANDLED;
512}
513
514/**
515 * ipc_probe - probe an Intel SCU IPC
516 * @dev: the PCI device matching
517 * @id: entry in the match table
518 *
519 * Enable and install an intel SCU IPC. This appears in the PCI space
520 * but uses some hard coded addresses as well.
521 */
522static int ipc_probe(struct pci_dev *dev, const struct pci_device_id *id)
523{
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -0800524 int err, pid;
525 struct intel_scu_ipc_pdata_t *pdata;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100526 resource_size_t pci_resource;
527
528 if (ipcdev.pdev) /* We support only one SCU */
529 return -EBUSY;
530
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -0800531 pid = id->driver_data;
532 pdata = &intel_scu_ipc_pdata[pid];
533
Sreedhara DS9a58a332010-04-26 18:13:05 +0100534 ipcdev.pdev = pci_dev_get(dev);
535
536 err = pci_enable_device(dev);
537 if (err)
538 return err;
539
540 err = pci_request_regions(dev, "intel_scu_ipc");
541 if (err)
542 return err;
543
544 pci_resource = pci_resource_start(dev, 0);
545 if (!pci_resource)
546 return -ENOMEM;
547
548 if (request_irq(dev->irq, ioc, 0, "intel_scu_ipc", &ipcdev))
549 return -EBUSY;
550
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -0800551 ipcdev.ipc_base = ioremap_nocache(pdata->ipc_base, pdata->ipc_len);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100552 if (!ipcdev.ipc_base)
553 return -ENOMEM;
554
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -0800555 ipcdev.i2c_base = ioremap_nocache(pdata->i2c_base, pdata->i2c_len);
Sreedhara DS9a58a332010-04-26 18:13:05 +0100556 if (!ipcdev.i2c_base) {
557 iounmap(ipcdev.ipc_base);
558 return -ENOMEM;
559 }
Feng Tang1da4b1c2010-11-09 11:22:58 +0000560
561 intel_scu_devices_create();
562
Sreedhara DS9a58a332010-04-26 18:13:05 +0100563 return 0;
564}
565
566/**
567 * ipc_remove - remove a bound IPC device
568 * @pdev: PCI device
569 *
570 * In practice the SCU is not removable but this function is also
571 * called for each device on a module unload or cleanup which is the
572 * path that will get used.
573 *
574 * Free up the mappings and release the PCI resources
575 */
576static void ipc_remove(struct pci_dev *pdev)
577{
578 free_irq(pdev->irq, &ipcdev);
579 pci_release_regions(pdev);
580 pci_dev_put(ipcdev.pdev);
581 iounmap(ipcdev.ipc_base);
582 iounmap(ipcdev.i2c_base);
583 ipcdev.pdev = NULL;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000584 intel_scu_devices_destroy();
Sreedhara DS9a58a332010-04-26 18:13:05 +0100585}
586
Axel Lindaa77692011-07-07 10:22:46 +0800587static DEFINE_PCI_DEVICE_TABLE(pci_ids) = {
Kuppuswamy Sathyanarayanane97a1c92013-11-14 14:15:04 -0800588 {PCI_VDEVICE(INTEL, 0x082a), SCU_IPC_LINCROFT},
Sreedhara DS9a58a332010-04-26 18:13:05 +0100589 { 0,}
590};
591MODULE_DEVICE_TABLE(pci, pci_ids);
592
593static struct pci_driver ipc_driver = {
594 .name = "intel_scu_ipc",
595 .id_table = pci_ids,
596 .probe = ipc_probe,
597 .remove = ipc_remove,
598};
599
600
601static int __init intel_scu_ipc_init(void)
602{
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700603 platform = intel_mid_identify_cpu();
Alan Cox9dd3ade2010-07-26 10:03:58 +0100604 if (platform == 0)
605 return -ENODEV;
Sreedhara DS9a58a332010-04-26 18:13:05 +0100606 return pci_register_driver(&ipc_driver);
607}
608
609static void __exit intel_scu_ipc_exit(void)
610{
611 pci_unregister_driver(&ipc_driver);
612}
613
614MODULE_AUTHOR("Sreedhara DS <sreedhara.ds@intel.com>");
615MODULE_DESCRIPTION("Intel SCU IPC driver");
616MODULE_LICENSE("GPL");
617
618module_init(intel_scu_ipc_init);
619module_exit(intel_scu_ipc_exit);