aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSreedhara DS <sreedhara.ds@intel.com>2010-10-22 10:43:55 -0400
committerMatthew Garrett <mjg@redhat.com>2011-01-07 17:03:40 -0500
commit5369c02d951afc72d68f5f85089160a63d31ca37 (patch)
tree0a07cc414001e9dbb27e704484f75a4a6bb61f89 /drivers
parent3e5b08cbbf78bedd316904ab0cf3b27119433ee5 (diff)
intel_scu_ipc: Utility driver for intel scu ipc
This driver implements ioctl and interfaces with intel scu ipc driver. It is used to access pmic/msic registers from user space and firmware update utility. Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> [Extensive clean up and debug] Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/platform/x86/Kconfig9
-rw-r--r--drivers/platform/x86/Makefile1
-rw-r--r--drivers/platform/x86/intel_scu_ipc.c4
-rw-r--r--drivers/platform/x86/intel_scu_ipcutil.c133
4 files changed, 145 insertions, 2 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index faec777b1ed..65ba62086ca 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -576,6 +576,15 @@ config INTEL_SCU_IPC
576 some embedded Intel x86 platforms. This is not needed for PC-type 576 some embedded Intel x86 platforms. This is not needed for PC-type
577 machines. 577 machines.
578 578
579config INTEL_SCU_IPC_UTIL
580 tristate "Intel SCU IPC utility driver"
581 depends on INTEL_SCU_IPC
582 default y
583 ---help---
584 The IPC Util driver provides an interface with the SCU enabling
585 low level access for debug work and updating the firmware. Say
586 N unless you will be doing this on an Intel MID platform.
587
579config GPIO_INTEL_PMIC 588config GPIO_INTEL_PMIC
580 bool "Intel PMIC GPIO support" 589 bool "Intel PMIC GPIO support"
581 depends on INTEL_SCU_IPC && GPIOLIB 590 depends on INTEL_SCU_IPC && GPIOLIB
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 9950ccc940b..4ec4ff8f918 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o
28obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 28obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
29obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o 29obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o
30obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o 30obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o
31obj-$(CONFIG_INTEL_SCU_IPC_UTIL)+= intel_scu_ipcutil.o
31obj-$(CONFIG_RAR_REGISTER) += intel_rar_register.o 32obj-$(CONFIG_RAR_REGISTER) += intel_rar_register.o
32obj-$(CONFIG_INTEL_IPS) += intel_ips.o 33obj-$(CONFIG_INTEL_IPS) += intel_ips.o
33obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o 34obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o
diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
index ca35b0ce944..1752ef006d2 100644
--- a/drivers/platform/x86/intel_scu_ipc.c
+++ b/drivers/platform/x86/intel_scu_ipc.c
@@ -497,7 +497,7 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)
497 "intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd); 497 "intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd);
498 498
499 mutex_unlock(&ipclock); 499 mutex_unlock(&ipclock);
500 return -1; 500 return -EIO;
501 } 501 }
502 mutex_unlock(&ipclock); 502 mutex_unlock(&ipclock);
503 return 0; 503 return 0;
@@ -642,7 +642,7 @@ update_end:
642 642
643 if (status == IPC_FW_UPDATE_SUCCESS) 643 if (status == IPC_FW_UPDATE_SUCCESS)
644 return 0; 644 return 0;
645 return -1; 645 return -EIO;
646} 646}
647EXPORT_SYMBOL(intel_scu_ipc_fw_update); 647EXPORT_SYMBOL(intel_scu_ipc_fw_update);
648 648
diff --git a/drivers/platform/x86/intel_scu_ipcutil.c b/drivers/platform/x86/intel_scu_ipcutil.c
new file mode 100644
index 00000000000..ba3231d0819
--- /dev/null
+++ b/drivers/platform/x86/intel_scu_ipcutil.c
@@ -0,0 +1,133 @@
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 * This driver provides ioctl interfaces to call intel scu ipc driver api
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/types.h>
19#include <linux/fs.h>
20#include <linux/fcntl.h>
21#include <linux/sched.h>
22#include <linux/uaccess.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <asm/intel_scu_ipc.h>
26
27static u32 major;
28
29#define MAX_FW_SIZE 264192
30
31/* ioctl commnds */
32#define INTE_SCU_IPC_REGISTER_READ 0
33#define INTE_SCU_IPC_REGISTER_WRITE 1
34#define INTE_SCU_IPC_REGISTER_UPDATE 2
35#define INTE_SCU_IPC_FW_UPDATE 0xA2
36
37struct scu_ipc_data {
38 u32 count; /* No. of registers */
39 u16 addr[5]; /* Register addresses */
40 u8 data[5]; /* Register data */
41 u8 mask; /* Valid for read-modify-write */
42};
43
44/**
45 * scu_reg_access - implement register access ioctls
46 * @cmd: command we are doing (read/write/update)
47 * @data: kernel copy of ioctl data
48 *
49 * Allow the user to perform register accesses on the SCU via the
50 * kernel interface
51 */
52
53static int scu_reg_access(u32 cmd, struct scu_ipc_data *data)
54{
55 int count = data->count;
56
57 if (count == 0 || count == 3 || count > 4)
58 return -EINVAL;
59
60 switch (cmd) {
61 case INTE_SCU_IPC_REGISTER_READ:
62 return intel_scu_ipc_readv(data->addr, data->data, count);
63 case INTE_SCU_IPC_REGISTER_WRITE:
64 return intel_scu_ipc_writev(data->addr, data->data, count);
65 case INTE_SCU_IPC_REGISTER_UPDATE:
66 return intel_scu_ipc_update_register(data->addr[0],
67 data->data[0], data->mask);
68 default:
69 return -ENOTTY;
70 }
71}
72
73/**
74 * scu_ipc_ioctl - control ioctls for the SCU
75 * @fp: file handle of the SCU device
76 * @cmd: ioctl coce
77 * @arg: pointer to user passed structure
78 *
79 * Support the I/O and firmware flashing interfaces of the SCU
80 */
81static long scu_ipc_ioctl(struct file *fp, unsigned int cmd,
82 unsigned long arg)
83{
84 int ret;
85 struct scu_ipc_data data;
86 void __user *argp = (void __user *)arg;
87
88 if (!capable(CAP_SYS_RAWIO))
89 return -EPERM;
90
91 if (cmd == INTE_SCU_IPC_FW_UPDATE) {
92 u8 *fwbuf = kmalloc(MAX_FW_SIZE, GFP_KERNEL);
93 if (fwbuf == NULL)
94 return -ENOMEM;
95 if (copy_from_user(fwbuf, (u8 *)arg, MAX_FW_SIZE)) {
96 kfree(fwbuf);
97 return -EFAULT;
98 }
99 ret = intel_scu_ipc_fw_update(fwbuf, MAX_FW_SIZE);
100 kfree(fwbuf);
101 return ret;
102 } else {
103 if (copy_from_user(&data, argp, sizeof(struct scu_ipc_data)))
104 return -EFAULT;
105 ret = scu_reg_access(cmd, &data);
106 if (ret < 0)
107 return ret;
108 if (copy_to_user(argp, &data, sizeof(struct scu_ipc_data)))
109 return -EFAULT;
110 return 0;
111 }
112}
113
114static const struct file_operations scu_ipc_fops = {
115 .unlocked_ioctl = scu_ipc_ioctl,
116};
117
118static int __init ipc_module_init(void)
119{
120 return register_chrdev(0, "intel_mid_scu", &scu_ipc_fops);
121}
122
123static void __exit ipc_module_exit(void)
124{
125 unregister_chrdev(major, "intel_mid_scu");
126}
127
128module_init(ipc_module_init);
129module_exit(ipc_module_exit);
130
131MODULE_LICENSE("GPL V2");
132MODULE_DESCRIPTION("Utility driver for intel scu ipc");
133MODULE_AUTHOR("Sreedhara <sreedhara.ds@intel.com>");