From: Shijie Zhang Date: Tue, 24 Apr 2012 17:09:23 +0000 (+0800) Subject: intel_scu_ipc: move osc clock code from SCU IPC core driver X-Git-Tag: 2.1b_release~880 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05c712ae9144cba8d71b61d41d4af11edff858fe;p=kernel%2Fkernel-mfld-blackbay.git intel_scu_ipc: move osc clock code from SCU IPC core driver 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 Reviewed-on: http://android.intel.com:8080/45901 Reviewed-by: Chen, Jie D Reviewed-by: Yang, Bin Reviewed-by: Du, Alek Reviewed-by: Wang, Zhifeng Tested-by: Wang, Zhifeng Reviewed-by: buildbot Tested-by: buildbot --- diff --git a/arch/x86/include/asm/intel_scu_ipc.h b/arch/x86/include/asm/intel_scu_ipc.h index c38e9b6..2f6ab7e 100644 --- a/arch/x86/include/asm/intel_scu_ipc.h +++ b/arch/x86/include/asm/intel_scu_ipc.h @@ -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 diff --git a/arch/x86/include/asm/intel_scu_ipcutil.h b/arch/x86/include/asm/intel_scu_ipcutil.h index 1bc963f..bc2b871 100644 --- a/arch/x86/include/asm/intel_scu_ipcutil.h +++ b/arch/x86/include/asm/intel_scu_ipcutil.h @@ -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); diff --git a/arch/x86/platform/intel-mid/device_libs/platform_mt9e013.c b/arch/x86/platform/intel-mid/device_libs/platform_mt9e013.c index 79ebf44..f626e9c 100644 --- a/arch/x86/platform/intel-mid/device_libs/platform_mt9e013.c +++ b/arch/x86/platform/intel-mid/device_libs/platform_mt9e013.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include "platform_camera.h" diff --git a/arch/x86/platform/intel-mid/device_libs/platform_mt9m114.c b/arch/x86/platform/intel-mid/device_libs/platform_mt9m114.c index 3aba03b..e9c188c 100644 --- a/arch/x86/platform/intel-mid/device_libs/platform_mt9m114.c +++ b/arch/x86/platform/intel-mid/device_libs/platform_mt9m114.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include "platform_camera.h" #include "platform_mt9m114.h" diff --git a/arch/x86/platform/intel-mid/device_libs/platform_ov8830.c b/arch/x86/platform/intel-mid/device_libs/platform_ov8830.c index 4561250..4149845 100644 --- a/arch/x86/platform/intel-mid/device_libs/platform_ov8830.c +++ b/arch/x86/platform/intel-mid/device_libs/platform_ov8830.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include "platform_camera.h" diff --git a/drivers/misc/a1026.c b/drivers/misc/a1026.c index 97dc91a..13dbf6a 100644 --- a/drivers/misc/a1026.c +++ b/drivers/misc/a1026.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index a2ea5ec..0ea8d69 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -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 #include #include @@ -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 diff --git a/drivers/platform/x86/intel_scu_ipcutil.c b/drivers/platform/x86/intel_scu_ipcutil.c index c33397b..f196ebb 100644 --- a/drivers/platform/x86/intel_scu_ipcutil.c +++ b/drivers/platform/x86/intel_scu_ipcutil.c @@ -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"); diff --git a/sound/soc/mid-x86/clv_machine.c b/sound/soc/mid-x86/clv_machine.c index efe0e85..42db1b4 100644 --- a/sound/soc/mid-x86/clv_machine.c +++ b/sound/soc/mid-x86/clv_machine.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/sound/soc/mid-x86/mfld_machine.c b/sound/soc/mid-x86/mfld_machine.c index d26265b..e974e86 100644 --- a/sound/soc/mid-x86/mfld_machine.c +++ b/sound/soc/mid-x86/mfld_machine.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sound/soc/mid-x86/mfld_machine_gi.c b/sound/soc/mid-x86/mfld_machine_gi.c index e24d445..8482c6a 100644 --- a/sound/soc/mid-x86/mfld_machine_gi.c +++ b/sound/soc/mid-x86/mfld_machine_gi.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include