intel_scu_ipc: move osc clock code from SCU IPC core driver
authorShijie Zhang <shijie.zhang@intel.com>
Tue, 24 Apr 2012 17:09:23 +0000 (01:09 +0800)
committerbuildbot <buildbot@intel.com>
Fri, 27 Apr 2012 02:55:08 +0000 (19:55 -0700)
BZ: 32907

Based on current drvier framework, it's not suitable to leave OSC CLK
related code inside the IPC core driver. Move it to intel_scu_ipcutil.

Change-Id: I02981dd1e8f9fea7b521f6d1d07feca0c6dd492e
Signed-off-by: Shijie Zhang <shijie.zhang@intel.com>
Reviewed-on: http://android.intel.com:8080/45901
Reviewed-by: Chen, Jie D <jie.d.chen@intel.com>
Reviewed-by: Yang, Bin <bin.yang@intel.com>
Reviewed-by: Du, Alek <alek.du@intel.com>
Reviewed-by: Wang, Zhifeng <zhifeng.wang@intel.com>
Tested-by: Wang, Zhifeng <zhifeng.wang@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
arch/x86/include/asm/intel_scu_ipc.h
arch/x86/include/asm/intel_scu_ipcutil.h
arch/x86/platform/intel-mid/device_libs/platform_mt9e013.c
arch/x86/platform/intel-mid/device_libs/platform_mt9m114.c
arch/x86/platform/intel-mid/device_libs/platform_ov8830.c
drivers/misc/a1026.c
drivers/platform/x86/intel_scu_ipc.c
drivers/platform/x86/intel_scu_ipcutil.c
sound/soc/mid-x86/clv_machine.c
sound/soc/mid-x86/mfld_machine.c
sound/soc/mid-x86/mfld_machine_gi.c

index c38e9b6..2f6ab7e 100644 (file)
@@ -53,24 +53,6 @@ int intel_scu_ipc_medfw_prepare(void __user *arg);
 int intel_scu_ipc_read_mip(u8 *data, int len, int offset, int issigned);
 int intel_scu_ipc_write_umip(u8 *data, int len, int offset);
 
-/* Penwell has 4 osc clocks */
-#define OSC_CLK_AUDIO  0       /* Audio */
-#define OSC_CLK_CAM0   1       /* Primary camera */
-#define OSC_CLK_CAM1   2       /* Secondary camera */
-#define OSC_CLK_DISP   3       /* Display buffer */
-
-int intel_scu_ipc_osc_clk(u8 clk, unsigned int khz);
-
-enum clk0_mode {
-       CLK0_AUDIENCE = 0x4,
-       CLK0_VIBRA1 = 0x8,
-       CLK0_VIBRA2 = 0x10,
-       CLK0_MSIC = 0x20,
-       CLK0_QUERY = 0x1000,
-};
-
-int intel_scu_ipc_set_osc_clk0(unsigned int enable, enum clk0_mode mode);
-
 extern struct blocking_notifier_head intel_scu_notifier;
 
 static inline void intel_scu_notifier_add(struct notifier_block *nb)
@@ -91,22 +73,4 @@ static inline int intel_scu_notifier_post(unsigned long v, void *p)
 #define                SCU_AVAILABLE           1
 #define                SCU_DOWN                2
 
-#define MSIC_VPROG1_CTRL       0xD6
-#define MSIC_VPROG2_CTRL       0xD7
-#define MSIC_VPROG_ON          0xFF
-#define MSIC_VPROG_OFF         0
-
-/* Helpers to turn on/off msic vprog1 and vprog2 */
-static inline int intel_scu_ipc_msic_vprog1(int on)
-{
-       return intel_scu_ipc_iowrite8(MSIC_VPROG1_CTRL,
-                       on ? MSIC_VPROG_ON : MSIC_VPROG_OFF);
-}
-
-static inline int intel_scu_ipc_msic_vprog2(int on)
-{
-       return intel_scu_ipc_iowrite8(MSIC_VPROG2_CTRL,
-                       on ? MSIC_VPROG_ON : MSIC_VPROG_OFF);
-}
-
 #endif
index 1bc963f..bc2b871 100644 (file)
@@ -1,5 +1,27 @@
 #ifndef _ASM_X86_INTEL_SCU_IPCUTIL_H_
-#define  _ASM_X86_INTEL_SCU_IPCUTIL_H_
+#define _ASM_X86_INTEL_SCU_IPCUTIL_H_
+
+/* Penwell has 4 osc clocks */
+#define OSC_CLK_AUDIO  0       /* Audio */
+#define OSC_CLK_CAM0   1       /* Primary camera */
+#define OSC_CLK_CAM1   2       /* Secondary camera */
+#define OSC_CLK_DISP   3       /* Display buffer */
+
+int intel_scu_ipc_osc_clk(u8 clk, unsigned int khz);
+
+enum clk0_mode {
+       CLK0_AUDIENCE = 0x4,
+       CLK0_VIBRA1 = 0x8,
+       CLK0_VIBRA2 = 0x10,
+       CLK0_MSIC = 0x20,
+       CLK0_QUERY = 0x1000,
+};
+
+int intel_scu_ipc_set_osc_clk0(unsigned int enable, enum clk0_mode mode);
+
+/* Helpers to turn on/off msic vprog1 and vprog2 */
+int intel_scu_ipc_msic_vprog1(int on);
+int intel_scu_ipc_msic_vprog2(int on);
 
 /* OSHOB-OS Handoff Buffer read */
 int intel_scu_ipc_read_oshob(u8 *data, int len, int offset);
index 79ebf44..f626e9c 100644 (file)
@@ -13,7 +13,7 @@
 #include <linux/gpio.h>
 #include <linux/delay.h>
 #include <linux/atomisp_platform.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <asm/intel-mid.h>
 #include <media/v4l2-subdev.h>
 #include "platform_camera.h"
index 3aba03b..e9c188c 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/delay.h>
 #include <linux/atomisp_platform.h>
 #include <asm/intel-mid.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <media/v4l2-subdev.h>
 #include "platform_camera.h"
 #include "platform_mt9m114.h"
index 4561250..4149845 100644 (file)
@@ -13,7 +13,7 @@
 #include <linux/gpio.h>
 #include <linux/delay.h>
 #include <linux/atomisp_platform.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <asm/intel-mid.h>
 #include <media/v4l2-subdev.h>
 #include "platform_camera.h"
index 97dc91a..13dbf6a 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/uaccess.h>
 #include <linux/delay.h>
 #include <linux/firmware.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <linux/a1026.h>
 #include <linux/i2c.h>
 
index a2ea5ec..0ea8d69 100644 (file)
@@ -3,7 +3,7 @@
  *
  * (C) Copyright 2008-2010 Intel Corporation
  * Author: Sreedhara DS (sreedhara.ds@intel.com)
- * (C) Copyright 2010 Intel Corporation
+ * (C) Copyright 2010-2012 Intel Corporation
  * Author: Sudha Krishnakumar (sudha.krishnakumar@intel.com)
  *
  * This program is free software; you can redistribute it and/or
@@ -18,6 +18,7 @@
  * IPC-1 Driver provides an API for power control unit registers (e.g. MSIC)
  * along with other APIs.
  */
+
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -148,10 +149,6 @@ static DEFINE_MUTEX(ipclock); /* lock used to prevent multiple call to SCU */
 /* PM Qos struct */
 static struct pm_qos_request_list *qos;
 
-/* Mode for Audio clock */
-static DEFINE_MUTEX(osc_clk0_lock);
-static unsigned int osc_clk0_mode;
-
 /*
  * Command Register (Write Only):
  * A write to this register results in an interrupt to the SCU core processor
@@ -1597,88 +1594,6 @@ static void intel_scu_sysfs_remove(struct pci_dev *dev)
        sysfs_remove_group(&dev->dev.kobj, &intel_scu_ipc_attr_group);
 }
 
-int intel_scu_ipc_osc_clk(u8 clk, unsigned int khz)
-{
-       /* SCU IPC COMMAND(osc clk on/off) definition:
-        * ipc_wbuf[0] = clock to act on {0, 1, 2, 3}
-        * ipc_wbuf[1] =
-        * bit 0 - 1:on  0:off
-        * bit 1 - if 1, read divider setting from bits 3:2 as follows:
-        * bit [3:2] - 00: clk/1, 01: clk/2, 10: clk/4, 11: reserved
-        */
-       unsigned int base_freq;
-       unsigned int div;
-       u8 ipc_wbuf[16];
-       int ipc_ret;
-
-       if (clk > 3)
-               return -EINVAL;
-
-       ipc_wbuf[0] = clk;
-       ipc_wbuf[1] = 0;
-       if (khz) {
-#ifdef CONFIG_CTP_CRYSTAL_38M4
-               base_freq = 38400;
-#else
-               base_freq = 19200;
-#endif
-               div = fls(base_freq / khz) - 1;
-               if (div >= 3 || (1 << div) * khz != base_freq)
-                       return -EINVAL; /* Allow only exact frequencies */
-               ipc_wbuf[1] = 0x03 | (div << 2);
-       }
-
-       ipc_ret = intel_scu_ipc_command(IPCMSG_OSC_CLK, 0,
-                                       (u32 *)ipc_wbuf, 2, NULL, 0);
-       if (ipc_ret != 0)
-               pr_err("%s: failed to set osc clk(%d) output\n", __func__, clk);
-
-       return ipc_ret;
-}
-EXPORT_SYMBOL_GPL(intel_scu_ipc_osc_clk);
-
-/*
- * OSC_CLK_AUDIO is connected to the MSIC as well as Audience, so it should be
- * turned on if any one of them requests it to be on and it should be turned off
- * only if no one needs it on.
- */
-int intel_scu_ipc_set_osc_clk0(unsigned int enable, enum clk0_mode mode)
-{
-       int ret = 0, clk_enable;
-       static const unsigned int clk_khz = 19200;
-
-       pr_debug("set_clk0 request %s for Mode 0x%x\n",
-                               enable ? "ON" : "OFF", mode);
-       mutex_lock(&osc_clk0_lock);
-       if (mode == CLK0_QUERY) {
-               ret = osc_clk0_mode;
-               goto out;
-       }
-       if (enable) {
-               /* if clock is already on, just add new user */
-               if (osc_clk0_mode) {
-                       osc_clk0_mode |= mode;
-                       goto out;
-               }
-               osc_clk0_mode |= mode;
-               pr_debug("set_clk0: enabling clk, mode 0x%x\n", osc_clk0_mode);
-               clk_enable = 1;
-       } else {
-               osc_clk0_mode &= ~mode;
-               pr_debug("set_clk0: disabling clk, mode 0x%x\n", osc_clk0_mode);
-               /* others using the clock, cannot turn it of */
-               if (osc_clk0_mode)
-                       goto out;
-               clk_enable = 0;
-       }
-       pr_debug("configuring OSC_CLK_AUDIO now\n");
-       ret = intel_scu_ipc_osc_clk(OSC_CLK_AUDIO, clk_enable ? clk_khz : 0);
-out:
-       mutex_unlock(&osc_clk0_lock);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(intel_scu_ipc_set_osc_clk0);
-
 /*
  * Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1
  * When ioc bit is set to 1, caller api must wait for interrupt handler called
index c33397b..f196ebb 100644 (file)
@@ -83,6 +83,111 @@ struct osc_clk_t {
        unsigned int khz; /* clock frequency */
 };
 
+/* Mode for Audio clock */
+static DEFINE_MUTEX(osc_clk0_lock);
+static unsigned int osc_clk0_mode;
+
+int intel_scu_ipc_osc_clk(u8 clk, unsigned int khz)
+{
+       /* SCU IPC COMMAND(osc clk on/off) definition:
+        * ipc_wbuf[0] = clock to act on {0, 1, 2, 3}
+        * ipc_wbuf[1] =
+        * bit 0 - 1:on  0:off
+        * bit 1 - if 1, read divider setting from bits 3:2 as follows:
+        * bit [3:2] - 00: clk/1, 01: clk/2, 10: clk/4, 11: reserved
+        */
+       unsigned int base_freq;
+       unsigned int div;
+       u8 ipc_wbuf[16];
+       int ipc_ret;
+
+       if (clk > 3)
+               return -EINVAL;
+
+       ipc_wbuf[0] = clk;
+       ipc_wbuf[1] = 0;
+       if (khz) {
+#ifdef CONFIG_CTP_CRYSTAL_38M4
+               base_freq = 38400;
+#else
+               base_freq = 19200;
+#endif
+               div = fls(base_freq / khz) - 1;
+               if (div >= 3 || (1 << div) * khz != base_freq)
+                       return -EINVAL; /* Allow only exact frequencies */
+               ipc_wbuf[1] = 0x03 | (div << 2);
+       }
+
+       ipc_ret = intel_scu_ipc_command(IPCMSG_OSC_CLK, 0,
+                                       (u32 *)ipc_wbuf, 2, NULL, 0);
+       if (ipc_ret != 0)
+               pr_err("%s: failed to set osc clk(%d) output\n", __func__, clk);
+
+       return ipc_ret;
+}
+EXPORT_SYMBOL_GPL(intel_scu_ipc_osc_clk);
+
+/*
+ * OSC_CLK_AUDIO is connected to the MSIC as well as Audience, so it should be
+ * turned on if any one of them requests it to be on and it should be turned off
+ * only if no one needs it on.
+ */
+int intel_scu_ipc_set_osc_clk0(unsigned int enable, enum clk0_mode mode)
+{
+       int ret = 0, clk_enable;
+       static const unsigned int clk_khz = 19200;
+
+       pr_debug("set_clk0 request %s for Mode 0x%x\n",
+                               enable ? "ON" : "OFF", mode);
+       mutex_lock(&osc_clk0_lock);
+       if (mode == CLK0_QUERY) {
+               ret = osc_clk0_mode;
+               goto out;
+       }
+       if (enable) {
+               /* if clock is already on, just add new user */
+               if (osc_clk0_mode) {
+                       osc_clk0_mode |= mode;
+                       goto out;
+               }
+               osc_clk0_mode |= mode;
+               pr_debug("set_clk0: enabling clk, mode 0x%x\n", osc_clk0_mode);
+               clk_enable = 1;
+       } else {
+               osc_clk0_mode &= ~mode;
+               pr_debug("set_clk0: disabling clk, mode 0x%x\n", osc_clk0_mode);
+               /* others using the clock, cannot turn it of */
+               if (osc_clk0_mode)
+                       goto out;
+               clk_enable = 0;
+       }
+       pr_debug("configuring OSC_CLK_AUDIO now\n");
+       ret = intel_scu_ipc_osc_clk(OSC_CLK_AUDIO, clk_enable ? clk_khz : 0);
+out:
+       mutex_unlock(&osc_clk0_lock);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(intel_scu_ipc_set_osc_clk0);
+
+#define MSIC_VPROG1_CTRL        0xD6
+#define MSIC_VPROG2_CTRL        0xD7
+#define MSIC_VPROG_ON           0xFF
+#define MSIC_VPROG_OFF          0
+
+int intel_scu_ipc_msic_vprog1(int on)
+{
+       return intel_scu_ipc_iowrite8(MSIC_VPROG1_CTRL,
+                       on ? MSIC_VPROG_ON : MSIC_VPROG_OFF);
+}
+EXPORT_SYMBOL_GPL(intel_scu_ipc_msic_vprog1);
+
+int intel_scu_ipc_msic_vprog2(int on)
+{
+       return intel_scu_ipc_iowrite8(MSIC_VPROG2_CTRL,
+                       on ? MSIC_VPROG_ON : MSIC_VPROG_OFF);
+}
+EXPORT_SYMBOL_GPL(intel_scu_ipc_msic_vprog2);
+
 /**
  *     scu_reg_access          -       implement register access ioctls
  *     @cmd: command we are doing (read/write/update)
@@ -467,7 +572,7 @@ static void __exit ipc_module_exit(void)
        misc_deregister(&scu_ipcutil);
 }
 
-module_init(ipc_module_init);
+rootfs_initcall(ipc_module_init);
 module_exit(ipc_module_exit);
 
 MODULE_LICENSE("GPL v2");
index efe0e85..42db1b4 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/delay.h>
 #include <linux/ipc_device.h>
 #include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
index d26265b..e974e86 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/gpio.h>
 #include <linux/ipc_device.h>
 #include <asm/intel-mid.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
index e24d445..8482c6a 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/gpio.h>
 #include <linux/ipc_device.h>
 #include <asm/intel-mid.h>
-#include <asm/intel_scu_ipc.h>
+#include <asm/intel_scu_ipcutil.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>