From eb4fc74ab6d0434aef59790badb85834f320ba74 Mon Sep 17 00:00:00 2001 From: Philippe Langlais Date: Thu, 20 Oct 2011 10:22:50 +0200 Subject: modem: add mloader and trace features Signed-off-by: Philippe Langlais --- include/linux/db8500-modem-trace.h | 24 ++++++++++++++++++++++++ include/linux/mloader.h | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 include/linux/db8500-modem-trace.h create mode 100644 include/linux/mloader.h (limited to 'include') diff --git a/include/linux/db8500-modem-trace.h b/include/linux/db8500-modem-trace.h new file mode 100644 index 00000000000..4863e1a0b03 --- /dev/null +++ b/include/linux/db8500-modem-trace.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * Authors: Michel JAOUEN + * Maxime COQUELIN + * for ST-Ericsson + * License terms: GNU General Public License (GPL), version 2 + */ +/* macro for requesting a trace read */ + +struct modem_trace_req { + __u32 phys_addr; + __u8 filler; + __u8 *buff; + __u32 size; +}; + +#define TM_IO_NUMBER 0xfc +#define TM_GET_DUMPINFO _IOR(TM_IO_NUMBER, 1, unsigned long) +#define TM_TRACE_REQ _IOWR(TM_IO_NUMBER, 2, unsigned long) + +struct db8500_trace_platform_data { + unsigned long ape_base; + unsigned long modem_base; +}; diff --git a/include/linux/mloader.h b/include/linux/mloader.h new file mode 100644 index 00000000000..ceca3245856 --- /dev/null +++ b/include/linux/mloader.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * Author: Ludovic Barre for ST-Ericsson. + * License terms: GNU General Public License (GPL), version 2 + */ + +#ifndef _MLOADER_H_ +#define _MLOADER_H_ + +/* not use in ioctl-number.txt */ +#define ML_IO_NUMBER 0xFE + +#define ML_UPLOAD _IO(ML_IO_NUMBER, 1) +#define ML_GET_NBIMAGES _IOR(ML_IO_NUMBER, 2, int) +#define ML_GET_DUMPINFO _IOR(ML_IO_NUMBER, 3, struct dump_image*) + +#define MAX_NAME 16 + +struct dump_image { + char name[MAX_NAME]; + unsigned int offset; + unsigned int size; +}; + +#endif /* _MLOADER_H_ */ -- cgit v1.2.3 From 2a418882e47a84ff7b8bcd0204e848db7035aefb Mon Sep 17 00:00:00 2001 From: Kumar Sanghvi Date: Mon, 16 May 2011 20:56:25 +0530 Subject: drivers: Add Modem Access Framework Adds Modem Access Framework, which allows for registering platform specific modem access mechanisms. The framework also exposes APIs for client drivers for getting and releasing access to modem, regardless of the underlying platform specific access mechanism. ST-Ericsson ID: CR329459 Change-Id: I643c56892e4423ec27467cbcfe8a22586c1e3f6a Signed-off-by: Kumar Sanghvi Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/23553 Reviewed-by: QATEST Reviewed-by: Srinidhi KASAGAR --- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/modem/Kconfig | 7 + drivers/modem/Makefile | 2 + drivers/modem/modem_access.c | 416 +++++++++++++++++++++++++++++++++++++ include/linux/modem/modem.h | 63 ++++++ include/linux/modem/modem_client.h | 53 +++++ 7 files changed, 544 insertions(+) create mode 100644 drivers/modem/Kconfig create mode 100644 drivers/modem/Makefile create mode 100644 drivers/modem/modem_access.c create mode 100644 include/linux/modem/modem.h create mode 100644 include/linux/modem/modem_client.h (limited to 'include') diff --git a/drivers/Kconfig b/drivers/Kconfig index d236aef7e59..ae18ca02e32 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -140,4 +140,6 @@ source "drivers/virt/Kconfig" source "drivers/devfreq/Kconfig" +source "drivers/modem/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index 95952c82bf1..831a5d43937 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -99,6 +99,7 @@ obj-$(CONFIG_CPU_FREQ) += cpufreq/ obj-$(CONFIG_CPU_IDLE) += cpuidle/ obj-y += mmc/ obj-$(CONFIG_MEMSTICK) += memstick/ +obj-$(CONFIG_MODEM) += modem/ obj-y += leds/ obj-$(CONFIG_INFINIBAND) += infiniband/ obj-$(CONFIG_SGI_SN) += sn/ diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig new file mode 100644 index 00000000000..000181cdb3d --- /dev/null +++ b/drivers/modem/Kconfig @@ -0,0 +1,7 @@ +config MODEM + bool "Modem Access Framework" + default n + help + Add support for Modem Access Framework. It allows different + platform specific drivers to register modem access mechanisms + and allows transparent access to modem to the client drivers. diff --git a/drivers/modem/Makefile b/drivers/modem/Makefile new file mode 100644 index 00000000000..0526714bebd --- /dev/null +++ b/drivers/modem/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_MODEM) := modem_access.o + diff --git a/drivers/modem/modem_access.c b/drivers/modem/modem_access.c new file mode 100644 index 00000000000..7337029c251 --- /dev/null +++ b/drivers/modem/modem_access.c @@ -0,0 +1,416 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * License Terms: GNU General Public License v2 + * Author: Kumar Sanghvi + * + * Heavily adapted from Regulator framework. + * Provides mechanisms for registering platform specific access + * mechanisms for modem. + * Also, exposes APIs for gettng/releasing the access and even + * query the access status, and the modem usage status. + */ +#include +#include +#include +#include + +static DEFINE_MUTEX(modem_list_mutex); +static LIST_HEAD(modem_list); + +struct modem { + struct device *dev; + struct list_head list; + char *modem_name; + struct device_attribute dev_attr; + struct modem_dev *mdev; + atomic_t use; +}; + +static const char *mdev_get_name(struct modem_dev *mdev) +{ + if (mdev->desc->name) + return mdev->desc->name; + else + return ""; +} + +static int _modem_is_requested(struct modem_dev *mdev) +{ + /* If we don't know then assume that the modem is always on */ + if (!mdev->desc->ops->is_requested) + return 0; + + return mdev->desc->ops->is_requested(mdev); +} + +/** + * modem_is_requested - check if modem access is requested + * @modem: modem device + * + * Checks whether modem is accessed or not by querying + * the underlying platform specific modem access + * implementation. + */ +int modem_is_requested(struct modem *modem) +{ + int ret; + + mutex_lock(&modem->mdev->mutex); + ret = _modem_is_requested(modem->mdev); + mutex_unlock(&modem->mdev->mutex); + + return ret; +} +EXPORT_SYMBOL(modem_is_requested); + +static int _modem_request(struct modem_dev *mdev) +{ + int ret; + + if (++mdev->use_count == 1) { + ret = _modem_is_requested(mdev); + if (ret == 0) + mdev->desc->ops->request(mdev); + } + + return 0; +} + +/** + * modem_request - Request access the modem + * @modem: modem device + * + * API to access the modem. It keeps a client + * specific check on whether the particular modem + * requested is accessed or not. + */ +void modem_request(struct modem *modem) +{ + struct modem_dev *mdev = modem->mdev; + int ret = 0; + + + mutex_lock(&mdev->mutex); + if (atomic_read(&modem->use) == 1) { + mutex_unlock(&mdev->mutex); + return; + } + ret = _modem_request(mdev); + if (ret == 0) + atomic_set(&modem->use, 1); + mutex_unlock(&mdev->mutex); +} +EXPORT_SYMBOL(modem_request); + +static int _modem_release(struct modem_dev *mdev) +{ + if (WARN(mdev->use_count <= 0, + "unbalanced releases for %s\n", + mdev_get_name(mdev))) + return -EIO; + + if (--mdev->use_count == 0) + mdev->desc->ops->release(mdev); + + return 0; +} + +/** + * modem_release - Release access to modem + * @modem: modem device + * + * Releases accesss to the modem. It keeps a client + * specific check on whether a particular modem + * is released or not. + */ +void modem_release(struct modem *modem) +{ + struct modem_dev *mdev = modem->mdev; + int ret = 0; + + mutex_lock(&mdev->mutex); + if (atomic_read(&modem->use) == 0) { + mutex_unlock(&mdev->mutex); + return; + } + ret = _modem_release(mdev); + if (ret == 0) + atomic_set(&modem->use, 0); + mutex_unlock(&mdev->mutex); +} +EXPORT_SYMBOL(modem_release); + +/** + * modem_get_usage - Check if particular client is using modem + * @modem: modem device + * + * Checks whether the particular client is using access to modem. + * This API could be used by client drivers in making their + * suspend decisions. + */ +int modem_get_usage(struct modem *modem) +{ + return atomic_read(&modem->use); +} +EXPORT_SYMBOL(modem_get_usage); + +static struct modem *create_modem(struct modem_dev *mdev, + struct device *dev, + const char *id) +{ + struct modem *modem; + + modem = kzalloc(sizeof(*modem), GFP_KERNEL); + if (modem == NULL) + return NULL; + + mutex_lock(&mdev->mutex); + modem->mdev = mdev; + modem->dev = dev; + list_add(&modem->list, &mdev->client_list); + + mutex_unlock(&mdev->mutex); + return modem; + +} + +static struct modem *_modem_get(struct device *dev, const char *id, + int exclusive) +{ + struct modem_dev *mdev_ptr; + struct modem *modem = ERR_PTR(-ENODEV); + int ret; + + if (id == NULL) { + pr_err("modem_get with no identifier\n"); + return modem; + } + + mutex_lock(&modem_list_mutex); + list_for_each_entry(mdev_ptr, &modem_list, modem_list) { + if (strcmp(mdev_get_name(mdev_ptr), id) == 0) + goto found; + } + + return ERR_PTR(-ENODEV); + +found: + if (!try_module_get(mdev_ptr->owner)) + goto out; + + modem = create_modem(mdev_ptr, dev, id); + if (modem == NULL) { + modem = ERR_PTR(-ENOMEM); + module_put(mdev_ptr->owner); + } + + mdev_ptr->open_count++; + ret = _modem_is_requested(mdev_ptr); + if (ret) + mdev_ptr->use_count = 1; + else + mdev_ptr->use_count = 0; + +out: + mutex_unlock(&modem_list_mutex); + return modem; + +} + +/** + * modem_get - Get reference to a particular platform specific modem + * @dev: device + * @id: modem device name + * + * Get reference to a particular modem device. + */ +struct modem *modem_get(struct device *dev, const char *id) +{ + return _modem_get(dev, id, 0); +} +EXPORT_SYMBOL(modem_get); + +/** + * modem_put - Release reference to a modem device + * @modem: modem device + * + * Release reference to a modem device. + */ +void modem_put(struct modem *modem) +{ + struct modem_dev *mdev; + + if (modem == NULL || IS_ERR(modem)) + return; + + mutex_lock(&modem_list_mutex); + mdev = modem->mdev; + + list_del(&modem->list); + kfree(modem); + + mdev->open_count--; + + module_put(mdev->owner); + mutex_unlock(&modem_list_mutex); +} +EXPORT_SYMBOL(modem_put); + +static ssize_t modem_print_state(char *buf, int state) +{ + if (state > 0) + return sprintf(buf, "accessed\n"); + else if (state == 0) + return sprintf(buf, "released\n"); + else + return sprintf(buf, "unknown\n"); +} + +static ssize_t modem_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct modem_dev *mdev = dev_get_drvdata(dev); + ssize_t ret; + + mutex_lock(&mdev->mutex); + ret = modem_print_state(buf, _modem_is_requested(mdev)); + mutex_unlock(&mdev->mutex); + + return ret; +} +static DEVICE_ATTR(state, 0444, modem_state_show, NULL); + +static ssize_t modem_use_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct modem_dev *mdev = dev_get_drvdata(dev); + struct modem *mod; + size_t size = 0; + + list_for_each_entry(mod, &mdev->client_list, list) { + if (mod->dev != NULL) + size += sprintf((buf + size), "%s (%d)\n", + dev_name(mod->dev), atomic_read(&mod->use)); + else + size += sprintf((buf + size), "unknown (%d)\n", + atomic_read(&mod->use)); + } + size += sprintf((buf + size), "\n"); + + return size; +} +static DEVICE_ATTR(use, 0444, modem_use_show, NULL); + +static ssize_t modem_name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct modem_dev *mdev = dev_get_drvdata(dev); + + return sprintf(buf, "%s\n", mdev_get_name(mdev)); +} +static DEVICE_ATTR(name, 0444, modem_name_show, NULL); + +static ssize_t modem_num_active_users_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct modem_dev *mdev = dev_get_drvdata(dev); + return sprintf(buf, "%d\n", mdev->use_count); +} +static DEVICE_ATTR(num_active_users, 0444, modem_num_active_users_show, NULL); + +static int add_modem_attributes(struct modem_dev *mdev) +{ + struct device *dev = &mdev->dev; + struct modem_ops *ops = mdev->desc->ops; + int status = 0; + + status = device_create_file(dev, &dev_attr_use); + if (status < 0) + return status; + + status = device_create_file(dev, &dev_attr_name); + if (status < 0) + return status; + + status = device_create_file(dev, &dev_attr_num_active_users); + if (status < 0) + return status; + + if (ops->is_requested) { + status = device_create_file(dev, &dev_attr_state); + if (status < 0) + return status; + } + + return 0; +} + +/** + * modem_register - register a modem + * @modem_desc: - description for modem + * @dev: - device + * @driver_data:- driver specific data + * + * Register a modem with the modem access framework, so that + * it could be used by client drivers for accessing the + * modem. + */ +struct modem_dev *modem_register(struct modem_desc *modem_desc, + struct device *dev, + void *driver_data) +{ + static atomic_t modem_no = ATOMIC_INIT(0); + struct modem_dev *mdev; + int ret; + + if (modem_desc == NULL) + return ERR_PTR(-EINVAL); + + if (modem_desc->name == NULL || modem_desc->ops == NULL) + return ERR_PTR(-EINVAL); + + mdev = kzalloc(sizeof(struct modem_dev), GFP_KERNEL); + if (mdev == NULL) + return ERR_PTR(-ENOMEM); + + mutex_lock(&modem_list_mutex); + + mutex_init(&mdev->mutex); + mdev->modem_data = driver_data; + mdev->owner = modem_desc->owner; + mdev->desc = modem_desc; + INIT_LIST_HEAD(&mdev->client_list); + INIT_LIST_HEAD(&mdev->modem_list); + BLOCKING_INIT_NOTIFIER_HEAD(&mdev->notifier); + + /* mdev->dev.class = &modem_class;*/ + mdev->dev.parent = dev; + dev_set_name(&mdev->dev, "modem.%d", atomic_inc_return(&modem_no) - 1); + ret = device_register(&mdev->dev); + if (ret != 0) + goto clean; + + dev_set_drvdata(&mdev->dev, mdev); + + ret = add_modem_attributes(mdev); + if (ret < 0) + goto backoff; + + list_add(&mdev->modem_list, &modem_list); + +out: + mutex_unlock(&modem_list_mutex); + return mdev; + +backoff: + device_unregister(&mdev->dev); + mdev = ERR_PTR(ret); + goto out; + +clean: + kfree(mdev); + mdev = ERR_PTR(ret); + goto out; +} +EXPORT_SYMBOL(modem_register); diff --git a/include/linux/modem/modem.h b/include/linux/modem/modem.h new file mode 100644 index 00000000000..c9614a9b061 --- /dev/null +++ b/include/linux/modem/modem.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * License Terms: GNU General Public License v2 + * Author: Kumar Sanghvi + * + * Heavily adapted from Regulator framework + */ +#ifndef __MODEM_H__ +#define __MODEM_H__ + +#include + +struct modem_dev; + +struct modem_ops { + void (*request)(struct modem_dev *); + void (*release)(struct modem_dev *); + int (*is_requested)(struct modem_dev *); +}; + +struct modem_desc { + const char *name; + int id; + struct modem_ops *ops; + struct module *owner; +}; + +struct modem_dev { + struct modem_desc *desc; + int use_count; + int open_count; + int exclusive; + + struct list_head modem_list; + + struct list_head client_list; + + struct blocking_notifier_head notifier; + struct mutex mutex; + struct module *owner; + struct device dev; + void *modem_data; +}; + +#ifdef CONFIG_MODEM +struct modem_dev *modem_register(struct modem_desc *modem_desc, + struct device *dev, + void *driver_data); +void modem_unregister(struct modem_dev *mdev); + +#else +static inline struct modem_dev *modem_register(struct modem_desc *modem_desc, + struct device *dev, void *driver_data) +{ + return NULL; +} + +static inline void modem_unregister(struct modem_dev *mdev) +{ +} +#endif +#endif /* __MODEM_H__ */ diff --git a/include/linux/modem/modem_client.h b/include/linux/modem/modem_client.h new file mode 100644 index 00000000000..21f04798490 --- /dev/null +++ b/include/linux/modem/modem_client.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * License Terms: GNU General Public License v2 + * Author: Kumar Sanghvi + * + * Heavily adapted from Regulator framework + */ +#ifndef __MODEM_CLIENT_H__ +#define __MODEM_CLIENT_H__ + +#include + +struct modem; + +#ifdef CONFIG_MODEM +struct modem *modem_get(struct device *dev, const char *id); +void modem_put(struct modem *modem); +void modem_request(struct modem *modem); +void modem_release(struct modem *modem); +int modem_is_requested(struct modem *modem); +int modem_get_usage(struct modem *modem); + +#else + +static inline struct modem *modem_get(struct device *dev, const char *id) +{ + return NULL; +} + +static inline void modem_put(struct modem *modem) +{ +} + +static inline void modem_request(struct modem *modem) +{ +} + +static inline void modem_release(struct modem *modem) +{ +} + +static inline int modem_is_requested(struct modem *modem) +{ + return 0; +} + +static inline int modem_get_usage(struct modem *modem) +{ + return 0; +} +#endif +#endif /* __MODEM_CLIENT_H__ */ -- cgit v1.2.3 From 3cea57241b2be162293c5ac43fa0dd6b99af0fe5 Mon Sep 17 00:00:00 2001 From: Kumar Sanghvi Date: Thu, 26 May 2011 14:38:19 +0530 Subject: u8500: shrm: Move shrm to drivers/modem Moves shrm specific files from arch/arm/mach-ux500/mach/include and drivers/misc to include/linux/modem/shrm and drivers/modem/shrm respectively ST-Ericsson ID: CR329459 Change-Id: I3a08f83e5302429d51eb865ee1c5e4e0ec73e31b Signed-off-by: Kumar Sanghvi Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/23980 Reviewed-by: QATEST Reviewed-by: Srinidhi KASAGAR --- Documentation/DocBook/shrm.tmpl | 10 +- arch/arm/mach-ux500/include/mach/shrm.h | 23 - arch/arm/mach-ux500/include/mach/shrm_config.h | 111 -- arch/arm/mach-ux500/include/mach/shrm_driver.h | 204 ---- arch/arm/mach-ux500/include/mach/shrm_net.h | 44 - arch/arm/mach-ux500/include/mach/shrm_private.h | 181 --- drivers/char/shrm_char.c | 8 +- drivers/misc/shrm/Kconfig | 43 - drivers/misc/shrm/Makefile | 11 - drivers/misc/shrm/modem_shrm_driver.c | 671 ----------- drivers/misc/shrm/shrm_driver.c | 1439 ----------------------- drivers/misc/shrm/shrm_fifo.c | 827 ------------- drivers/misc/shrm/shrm_protocol.c | 1191 ------------------- drivers/modem/Kconfig | 2 + drivers/modem/Makefile | 1 + drivers/modem/shrm/Kconfig | 43 + drivers/modem/shrm/Makefile | 11 + drivers/modem/shrm/modem_shrm_driver.c | 669 +++++++++++ drivers/modem/shrm/shrm_driver.c | 1439 +++++++++++++++++++++++ drivers/modem/shrm/shrm_fifo.c | 827 +++++++++++++ drivers/modem/shrm/shrm_protocol.c | 1191 +++++++++++++++++++ drivers/net/u8500_shrm.c | 10 +- include/linux/modem/shrm/shrm.h | 23 + include/linux/modem/shrm/shrm_config.h | 111 ++ include/linux/modem/shrm/shrm_driver.h | 202 ++++ include/linux/modem/shrm/shrm_net.h | 44 + include/linux/modem/shrm/shrm_private.h | 181 +++ 27 files changed, 4758 insertions(+), 4759 deletions(-) delete mode 100644 arch/arm/mach-ux500/include/mach/shrm.h delete mode 100644 arch/arm/mach-ux500/include/mach/shrm_config.h delete mode 100644 arch/arm/mach-ux500/include/mach/shrm_driver.h delete mode 100644 arch/arm/mach-ux500/include/mach/shrm_net.h delete mode 100644 arch/arm/mach-ux500/include/mach/shrm_private.h delete mode 100644 drivers/misc/shrm/Kconfig delete mode 100644 drivers/misc/shrm/Makefile delete mode 100644 drivers/misc/shrm/modem_shrm_driver.c delete mode 100644 drivers/misc/shrm/shrm_driver.c delete mode 100644 drivers/misc/shrm/shrm_fifo.c delete mode 100644 drivers/misc/shrm/shrm_protocol.c create mode 100644 drivers/modem/shrm/Kconfig create mode 100644 drivers/modem/shrm/Makefile create mode 100644 drivers/modem/shrm/modem_shrm_driver.c create mode 100644 drivers/modem/shrm/shrm_driver.c create mode 100644 drivers/modem/shrm/shrm_fifo.c create mode 100644 drivers/modem/shrm/shrm_protocol.c create mode 100644 include/linux/modem/shrm/shrm.h create mode 100644 include/linux/modem/shrm/shrm_config.h create mode 100644 include/linux/modem/shrm/shrm_driver.h create mode 100644 include/linux/modem/shrm/shrm_net.h create mode 100644 include/linux/modem/shrm/shrm_private.h (limited to 'include') diff --git a/Documentation/DocBook/shrm.tmpl b/Documentation/DocBook/shrm.tmpl index 7f21cd3f7dd..2773b821bf5 100644 --- a/Documentation/DocBook/shrm.tmpl +++ b/Documentation/DocBook/shrm.tmpl @@ -117,15 +117,15 @@ This Section lists the functions used internally by the SHRM driver to implement FIFO management. It physically reads/writes data to/from memory. -!Idrivers/misc/shrm/shrm_fifo.c +!Idrivers/modem/shrm/shrm_fifo.c This Section lists the functions used internally by the SHRM driver to implement the SHM protocol and handle all interrupt callback. -!Idrivers/misc/shrm/shrm_protocol.c +!Idrivers/modem/shrm/shrm_protocol.c This Section lists the functions used internally by the SHRM driver to implement Modem-Host communication L1 interface specifications. -!Idrivers/misc/shrm/modem_shrm_driver.c +!Idrivers/modem/shrm/modem_shrm_driver.c @@ -133,7 +133,7 @@ This Section lists some of the Data structure used by the SHRM driver. -!Iarch/arm/mach-ux500/include/mach/shrm_driver.h -!Iarch/arm/mach-ux500/include/mach/shrm_private.h +!Iinclude/linux/modem/shrm/shrm_driver.h +!Iinclude/linux/modem/shrm/shrm_private.h diff --git a/arch/arm/mach-ux500/include/mach/shrm.h b/arch/arm/mach-ux500/include/mach/shrm.h deleted file mode 100644 index 6deeeb16ba8..00000000000 --- a/arch/arm/mach-ux500/include/mach/shrm.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghavi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#ifndef __SHM_DRIVER_IF_H__ -#define __SHM_DRIVER_IF_H__ - -#include - -/* forward declaration */ -struct shrm_dev; - -typedef void (*rx_cb)(void *data, unsigned int length); -typedef void (*received_msg_handler)(unsigned char l2_header, - void *msg_ptr, unsigned int length, - struct shrm_dev *shrm); - -#endif diff --git a/arch/arm/mach-ux500/include/mach/shrm_config.h b/arch/arm/mach-ux500/include/mach/shrm_config.h deleted file mode 100644 index a82b35ef77b..00000000000 --- a/arch/arm/mach-ux500/include/mach/shrm_config.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghavi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#ifndef __SHRM_CONFIG_H -#define __SHRM_CONFIG_H - - -/* -Note: modem need to define IPC as a non-cacheable area. -In Cortex R4 MPU requires that base address of NC area is aligned on a -region-sized boundary.On modem side, only 1 NC area can be defined, hence -the whole IPC area must be defined as NC (at least). - -*/ - -/* cache line size = 32bytes*/ -#define SHM_CACHE_LINE 32 -#define SHM_PTR_SIZE 4 - -/* FIFO 0 address configuration */ -/* ---------------------------- */ -/* 128KB */ -#define SHM_FIFO_0_SIZE (128*1024) - - -/* == APE addresses == */ -#ifdef CONFIG_SHRM_V1_UPDATES_VERSION -#define SHM_IPC_BASE_AMCU 0x06F80000 -#else -#define SHM_IPC_BASE_AMCU 0x06000000 -#endif - -/* offset pointers */ -#define SHM_ACFIFO_0_WRITE_AMCU SHM_IPC_BASE_AMCU -#define SHM_ACFIFO_0_READ_AMCU (SHM_ACFIFO_0_WRITE_AMCU + SHM_PTR_SIZE) -#define SHM_CAFIFO_0_WRITE_AMCU (SHM_ACFIFO_0_WRITE_AMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_0_READ_AMCU (SHM_CAFIFO_0_WRITE_AMCU + SHM_PTR_SIZE) -/* FIFO start */ -#define SHM_ACFIFO_0_START_AMCU (SHM_CAFIFO_0_WRITE_AMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_0_START_AMCU (SHM_ACFIFO_0_START_AMCU + SHM_FIFO_0_SIZE) - - -/* == CMT addresses ==*/ -#define SHM_IPC_BASE_CMCU (SHM_IPC_BASE_AMCU+0x08000000) -/* offset pointers */ -#define SHM_ACFIFO_0_WRITE_CMCU SHM_IPC_BASE_CMCU -#define SHM_ACFIFO_0_READ_CMCU (SHM_ACFIFO_0_WRITE_CMCU + SHM_PTR_SIZE) -#define SHM_CAFIFO_0_WRITE_CMCU (SHM_ACFIFO_0_WRITE_CMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_0_READ_CMCU (SHM_CAFIFO_0_WRITE_CMCU + SHM_PTR_SIZE) -/* FIFO*/ -#define SHM_ACFIFO_0_START_CMCU (SHM_CAFIFO_0_WRITE_CMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_0_START_CMCU (SHM_ACFIFO_0_START_CMCU + SHM_FIFO_0_SIZE) - - -/* ADSP addresses*/ -#define SHM_ACFIFO_0_START_ADSP 0x0 -#define SHM_CAFIFO_0_START_ADSP 0x0 -#define SHM_ACFIFO_0_WRITE_ADSP 0x0 -#define SHM_ACFIFO_0_READ_ADSP 0x0 -#define SHM_CAFIFO_0_WRITE_ADSP 0x0 -#define SHM_CAFIFO_0_READ_ADSP 0x0 - -/* FIFO 1 address configuration */ -/* ---------------------------- */ - - -/* FIFO 1 - 4K */ -#define SHM_FIFO_1_SIZE (4*1024) - - -/* == APE addresses == */ -#define SHM_ACFIFO_1_WRITE_AMCU (SHM_CAFIFO_0_START_AMCU + SHM_FIFO_0_SIZE) -#define SHM_ACFIFO_1_READ_AMCU (SHM_ACFIFO_1_WRITE_AMCU + SHM_PTR_SIZE) -#define SHM_CAFIFO_1_WRITE_AMCU (SHM_ACFIFO_1_WRITE_AMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_1_READ_AMCU (SHM_CAFIFO_1_WRITE_AMCU + SHM_PTR_SIZE) -/* FIFO*/ -#define SHM_ACFIFO_1_START_AMCU (SHM_CAFIFO_1_WRITE_AMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_1_START_AMCU (SHM_ACFIFO_1_START_AMCU + SHM_FIFO_1_SIZE) - - -/* == CMT addresses ==*/ -#define SHM_ACFIFO_1_WRITE_CMCU (SHM_CAFIFO_0_START_CMCU + SHM_FIFO_0_SIZE) -#define SHM_ACFIFO_1_READ_CMCU (SHM_ACFIFO_1_WRITE_CMCU + SHM_PTR_SIZE) -#define SHM_CAFIFO_1_WRITE_CMCU (SHM_ACFIFO_1_WRITE_CMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_1_READ_CMCU (SHM_CAFIFO_1_WRITE_CMCU + SHM_PTR_SIZE) -/* FIFO1 start */ -#define SHM_ACFIFO_1_START_CMCU (SHM_CAFIFO_1_WRITE_CMCU + SHM_CACHE_LINE) -#define SHM_CAFIFO_1_START_CMCU (SHM_ACFIFO_1_START_CMCU + SHM_FIFO_1_SIZE) - - -/* ADSP addresses*/ -#define SHM_ACFIFO_1_START_ADSP 0x0 -#define SHM_CAFIFO_1_START_ADSP 0x0 -#define SHM_ACFIFO_1_WRITE_ADSP 0x0 -#define SHM_ACFIFO_1_READ_ADSP 0x0 -#define SHM_CAFIFO_1_WRITE_ADSP 0x0 -#define SHM_CAFIFO_1_READ_ADSP 0x0 - - -#define U8500_SHM_FIFO_APE_COMMON_BASE (SHM_ACFIFO_0_START_AMCU) -#define U8500_SHM_FIFO_CMT_COMMON_BASE (SHM_CAFIFO_0_START_AMCU) -#define U8500_SHM_FIFO_APE_AUDIO_BASE (SHM_ACFIFO_1_START_AMCU) -#define U8500_SHM_FIFO_CMT_AUDIO_BASE (SHM_CAFIFO_1_START_AMCU) - -#endif /* __SHRM_CONFIG_H */ diff --git a/arch/arm/mach-ux500/include/mach/shrm_driver.h b/arch/arm/mach-ux500/include/mach/shrm_driver.h deleted file mode 100644 index 71b3fbcf229..00000000000 --- a/arch/arm/mach-ux500/include/mach/shrm_driver.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghavi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#ifndef __SHRM_DRIVER_H__ -#define __SHRM_DRIVER_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#define ISA_DEVICES 6 - -#define BOOT_INIT (0) -#define BOOT_INFO_SYNC (1) -#define BOOT_DONE (2) -#define BOOT_UNKNOWN (3) - -/** - * struct shrm_dev - shrm device information - * @ca_wake_irq: CMT wake interrupt number - * @ac_read_notif_0_irq: ape-cmt common channel read notify interrupt - * @ac_read_notif_1_irq: ape-cmt audio channel read notify interrupt - * @ca_msg_pending_notif_0_irq: cmt-ape common channel msg pending interrupt - * @ca_msg_pending_notif_1_irq: cmt-ape audio channel msg pending interrupt - * @intr_base: interrupt base register address - * @ape_common_fifo_base: ape side common channel fifo base addr - * @ape_audio_fifo_base: ape side audio channel fifo base addr - * @cmt_common_fifo_base: cmt side common channel fifo base addr - * @cmt_audio_fifo_base: cmt side audio channel fifo base addr - * @ape_common_fifo_base_phy: physical addr of ape common fifo - * @ape_audio_fifo_base_phy: physical addr of ape audio fifo - * @cmt_common_fifo_base_phy: physical addr of cmt common fifo - * @cmt_audio_fifo_base_phy: physical addr of cmt audio fifo - * @ape_common_fifo_size: ape side common channel fifo size - * @ape_audio_fifo_size: ape side audio channel fifo size - * @cmt_common_fifo_size: cmt side common channel fifo size - * @cmt_audio_fifo_size: cmt side audio channel fifo size - * @netdev_flag_up: flag to indicate up/down of netwok device - * @msr_flag: flag to check on-going MSR sequence - * @ac_common_shared_wptr: ape-cmt common channel write pointer - * @ac_common_shared_rptr: ape-cmt common channel read pointer - * @ca_common_shared_wptr: cmt-ape common channel write pointer - * @ca_common_shared_rptr: cmt-ape common channel read pointer - * @ac_audio_shared_wptr: ape-cmt audio channel write pointer - * @ac_audio_shared_rptr: ape-cmt audio channel read pointer - * @ca_audio_shared_wptr: cmt-ape audio channel write pointer - * @ca_audio_shared_rptr: cmt-ape audio channel read pointer - * @dev: pointer to the driver device - * @ndev: pointer to the network device structure - * @isa_context: pointer to t_isa_driver_sontext dtructure - * @shm_common_ch_wr_wq: work queue for writing to common channel - * @shm_audio_ch_wr_wq: workqueue for writing to audio channel - * @shm_ac_wake_wq: workqueue for receiving ape-cmt wake requests - * @shm_ca_wake_wq: workqueue for receiving cmt-ape wake requests - * @shm_ac_sleep_wq: workqueue for recieving ape-cmt sleep requests - * @send_ac_msg_pend_notify_0: work for handling pending message on common - * channel - * @send_ac_msg_pend_notify_1: work for handling pending message on audio - * channel - * @shm_ac_wake_req: work to send ape-cmt wake request - * @shm_ca_wake_req: work to send cmt-ape wake request - * @shm_ca_sleep_req: work to send cmt-ape sleep request - * @shm_ac_sleep_req: work to send ape-cmt sleep request - */ -struct shrm_dev { - u8 ca_wake_irq; - u8 ac_read_notif_0_irq; - u8 ac_read_notif_1_irq; - u8 ca_msg_pending_notif_0_irq; - u8 ca_msg_pending_notif_1_irq; - void __iomem *intr_base; - void __iomem *ape_common_fifo_base; - void __iomem *ape_audio_fifo_base; - void __iomem *cmt_common_fifo_base; - void __iomem *cmt_audio_fifo_base; - - u32 *ape_common_fifo_base_phy; - u32 *ape_audio_fifo_base_phy; - u32 *cmt_common_fifo_base_phy; - u32 *cmt_audio_fifo_base_phy; - - int ape_common_fifo_size; - int ape_audio_fifo_size; - int cmt_common_fifo_size; - int cmt_audio_fifo_size; - int netdev_flag_up; - int msr_flag; - - void __iomem *ac_common_shared_wptr; - void __iomem *ac_common_shared_rptr; - void __iomem *ca_common_shared_wptr; - void __iomem *ca_common_shared_rptr; - - void __iomem *ac_audio_shared_wptr; - void __iomem *ac_audio_shared_rptr; - void __iomem *ca_audio_shared_wptr; - void __iomem *ca_audio_shared_rptr; - - struct device *dev; - struct net_device *ndev; - struct modem *modem; - struct isa_driver_context *isa_context; - struct workqueue_struct *shm_common_ch_wr_wq; - struct workqueue_struct *shm_audio_ch_wr_wq; - struct workqueue_struct *shm_ac_wake_wq; - struct workqueue_struct *shm_ca_wake_wq; - struct workqueue_struct *shm_ac_sleep_wq; - struct work_struct send_ac_msg_pend_notify_0; - struct work_struct send_ac_msg_pend_notify_1; - struct work_struct shm_ac_wake_req; - struct work_struct shm_ca_wake_req; - struct work_struct shm_ca_sleep_req; - struct work_struct shm_ac_sleep_req; -}; - -/** - * struct queue_element - information to add an element to queue - * @entry: list entry - * @offset: message offset - * @size: message size - * @no: total number of messages - */ -struct queue_element { - struct list_head entry; - u32 offset; - u32 size; - u32 no; -}; - -/** - * struct message_queue - ISI, RPC, AUDIO, SECURITY message queue information - * @fifo_base: pointer to the respective fifo base - * @size: size of the data to be read - * @readptr: fifo read pointer - * @writeptr: fifo write pointer - * @no: total number of messages - * @update_lock: spinlock for protecting the queue read operation - * @q_rp: queue write pointer - * @wq_readable: wait queue head - * @msg_list: message list - * @shrm: pointer to shrm device information structure - */ -struct message_queue { - u8 *fifo_base; - u32 size; - u32 readptr; - u32 writeptr; - u32 no; - spinlock_t update_lock; - atomic_t q_rp; - wait_queue_head_t wq_readable; - struct list_head msg_list; - struct shrm_dev *shrm; -}; - -/** - * struct isadev_context - shrm char interface context - * @dl_queue: structre to store the queue related info - * @device_id: message id(ISI, RPC, AUDIO, SECURITY) - * @addr: device addresses. - */ -struct isadev_context { - struct message_queue dl_queue; - u8 device_id; - void *addr; -}; - -/** - * struct isa_driver_context - shrm char interface device information - * @is_open: flag to check the usage of queue - * @isadev: pointer to struct t_isadev_context - * @common_tx: spinlock for protecting common channel - * @tx_audio_mutex: mutex for protecting audio channel - * @cdev: character device structre - * @shm_class: pointer to the class structure - */ -struct isa_driver_context { - atomic_t is_open[ISA_DEVICES]; - struct isadev_context *isadev; - spinlock_t common_tx; - struct mutex tx_audio_mutex; - struct cdev cdev; - struct class *shm_class; -}; - -#endif diff --git a/arch/arm/mach-ux500/include/mach/shrm_net.h b/arch/arm/mach-ux500/include/mach/shrm_net.h deleted file mode 100644 index a97b276ee15..00000000000 --- a/arch/arm/mach-ux500/include/mach/shrm_net.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2009 - * - * Author: Kumar Sanghvi for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#ifndef __SHRM_NET_H -#define __SHRM_NET_H - -#define SHRM_HLEN 1 -#define PHONET_ALEN 1 - -#define PN_PIPE 0xD9 -#define PN_DEV_HOST 0x00 -#define PN_LINK_ADDR 0x26 -#define PN_TX_QUEUE_LEN 3 - -#define RESOURCE_ID_INDEX 3 -#define SRC_OBJ_INDEX 7 -#define MSG_ID_INDEX 9 -#define PIPE_HDL_INDEX 10 -#define NETLINK_SHRM 20 - -/** - * struct shrm_net_iface_priv - shrm net interface device information - * @shrm_device: pointer to the shrm device information structure - * @iface_num: flag used to indicate the up/down of netdev - */ -struct shrm_net_iface_priv { - struct shrm_dev *shrm_device; - unsigned int iface_num; -}; - -int shrm_register_netdev(struct shrm_dev *shrm_dev_data); -int shrm_net_receive(struct net_device *dev); -int shrm_suspend_netdev(struct net_device *dev); -int shrm_resume_netdev(struct net_device *dev); -int shrm_stop_netdev(struct net_device *dev); -int shrm_restart_netdev(struct net_device *dev); -int shrm_start_netdev(struct net_device *dev); -void shrm_unregister_netdev(struct shrm_dev *shrm_dev_data); - -#endif /* __SHRM_NET_H */ diff --git a/arch/arm/mach-ux500/include/mach/shrm_private.h b/arch/arm/mach-ux500/include/mach/shrm_private.h deleted file mode 100644 index 1f09e7bef94..00000000000 --- a/arch/arm/mach-ux500/include/mach/shrm_private.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghavi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#ifndef __SHRM_PRIVATE_INCLUDED -#define __SHRM_PRIVATE_INCLUDED - -#include -#include -#include -#include - -#define GOP_OUTPUT_REGISTER_BASE (0x0) -#define GOP_SET_REGISTER_BASE (0x4) -#define GOP_CLEAR_REGISTER_BASE (0x8) -#define GOP_TOGGLE_REGISTER_BASE (0xc) - - -#define GOP_AUDIO_AC_READ_NOTIFICATION_BIT (0) -#define GOP_AUDIO_CA_MSG_PENDING_NOTIFICATION_BIT (1) -#define GOP_COMMON_AC_READ_NOTIFICATION_BIT (2) -#define GOP_COMMON_CA_MSG_PENDING_NOTIFICATION_BIT (3) -#define GOP_CA_WAKE_REQ_BIT (7) -#define GOP_AUDIO_CA_READ_NOTIFICATION_BIT (23) -#define GOP_AUDIO_AC_MSG_PENDING_NOTIFICATION_BIT (24) -#define GOP_COMMON_CA_READ_NOTIFICATION_BIT (25) -#define GOP_COMMON_AC_MSG_PENDING_NOTIFICATION_BIT (26) -#define GOP_CA_WAKE_ACK_BIT (27) - -#define L2_MSG_MAPID_OFFSET (24) -#define L1_MSG_MAPID_OFFSET (28) - -#define SHRM_SLEEP_STATE (0) -#define SHRM_PTR_FREE (1) -#define SHRM_PTR_BUSY (2) -#define SHRM_IDLE (3) - -#define ISI_MESSAGING (0) -#define RPC_MESSAGING (1) -#define AUDIO_MESSAGING (2) -#define SECURITY_MESSAGING (3) -#define COMMON_LOOPBACK_MESSAGING (0xC0) -#define AUDIO_LOOPBACK_MESSAGING (0x80) - -#define COMMON_CHANNEL 0 -#define AUDIO_CHANNEL 1 - -typedef void (*MSG_PENDING_NOTIF)(const u32 Wptr); - -/** - * struct fifo_write_params - parameters used for FIFO write operation. - * @writer_local_rptr: pointer to local read buffer - * @writer_local_wptr: pointer to local write buffer - * @shared_wptr: write pointer shared by cmt and ape - * @shared_rptr: read pointer shared by cmt and ape - * @availablesize: available memory in fifo - * @end_addr_fifo: fifo end addr - * @fifo_virtual_addr: fifo virtual addr - * @fifo_update_lock: spin lock to update fifo. - * - * On writting a message to FIFO the same has to be read by the modem before - * writing the next message to the FIFO. In oder to over come this a local - * write and read pointer is used for internal purpose. - */ -struct fifo_write_params { - u32 writer_local_rptr; - u32 writer_local_wptr; - u32 shared_wptr; - u32 shared_rptr; - u32 availablesize; - u32 end_addr_fifo; - u32 *fifo_virtual_addr; - spinlock_t fifo_update_lock; -} ; - -/** - * struct fifo_read_params - parameters used for FIFO read operation - * @reader_local_rptr: pointer to local read buffer - * @reader_local_wptr: pointer to local write buffer - * @shared_wptr: write pointer shared by cmt and ape - * @shared_rptr: read pointer shared by cmt and ape - * @availablesize: available memory in fifo - * @end_addr_fifo: fifo end add - * @fifo_virtual_addr: fifo virtual addr - */ -struct fifo_read_params{ - u32 reader_local_rptr; - u32 reader_local_wptr; - u32 shared_wptr; - u32 shared_rptr; - u32 availablesize; - u32 end_addr_fifo; - u32 *fifo_virtual_addr; - -} ; - -int shrm_protocol_init(struct shrm_dev *shrm, - received_msg_handler common_rx_handler, - received_msg_handler audio_rx_handler); -void shrm_protocol_deinit(struct shrm_dev *shrm); -void shm_fifo_init(struct shrm_dev *shrm); -int shm_write_msg_to_fifo(struct shrm_dev *shrm, u8 channel, - u8 l2header, void *addr, u32 length); -int shm_write_msg(struct shrm_dev *shrm, - u8 l2_header, void *addr, u32 length); - -u8 is_the_only_one_unread_message(struct shrm_dev *shrm, - u8 channel, u32 length); -u8 read_remaining_messages_common(void); -u8 read_remaining_messages_audio(void); -u8 read_one_l2msg_audio(struct shrm_dev *shrm, - u8 *p_l2_msg, u32 *p_len); -u8 read_one_l2msg_common(struct shrm_dev *shrm, - u8 *p_l2_msg, u32 *p_len); -void receive_messages_common(struct shrm_dev *shrm); -void receive_messages_audio(struct shrm_dev *shrm); - -void update_ac_common_local_rptr(struct shrm_dev *shrm); -void update_ac_audio_local_rptr(struct shrm_dev *shrm); -void update_ca_common_local_wptr(struct shrm_dev *shrm); -void update_ca_audio_local_wptr(struct shrm_dev *shrm); -void update_ac_common_shared_wptr(struct shrm_dev *shrm); -void update_ac_audio_shared_wptr(struct shrm_dev *shrm); -void update_ca_common_shared_rptr(struct shrm_dev *shrm); -void update_ca_audio_shared_rptr(struct shrm_dev *shrm); - - -void get_writer_pointers(u8 msg_type, u32 *WriterLocalRptr, \ - u32 *WriterLocalWptr, u32 *SharedWptr); -void get_reader_pointers(u8 msg_type, u32 *ReaderLocalRptr, \ - u32 *ReaderLocalWptr, u32 *SharedRptr); -u8 read_boot_info_req(struct shrm_dev *shrm, - u32 *pConfig, - u32 *pVersion); -void write_boot_info_resp(struct shrm_dev *shrm, u32 Config, - u32 Version); - -void send_ac_msg_pending_notification_0(struct shrm_dev *shrm); -void send_ac_msg_pending_notification_1(struct shrm_dev *shrm); -void ca_msg_read_notification_0(struct shrm_dev *shrm); -void ca_msg_read_notification_1(struct shrm_dev *shrm); - -void set_ca_msg_0_read_notif_send(u8 val); -u8 get_ca_msg_0_read_notif_send(void); -void set_ca_msg_1_read_notif_send(u8 val); -u8 get_ca_msg_1_read_notif_send(void); - -irqreturn_t ca_wake_irq_handler(int irq, void *ctrlr); -irqreturn_t ac_read_notif_0_irq_handler(int irq, void *ctrlr); -irqreturn_t ac_read_notif_1_irq_handler(int irq, void *ctrlr); -irqreturn_t ca_msg_pending_notif_0_irq_handler(int irq, void *ctrlr); -irqreturn_t ca_msg_pending_notif_1_irq_handler(int irq, void *ctrlr); - -void shm_ca_msgpending_0_tasklet(unsigned long); -void shm_ca_msgpending_1_tasklet(unsigned long); -void shm_ac_read_notif_0_tasklet(unsigned long); -void shm_ac_read_notif_1_tasklet(unsigned long); -void shm_ca_wake_req_tasklet(unsigned long); - -u8 get_boot_state(void); - -int get_ca_wake_req_state(void); - -/* shrm character interface */ -int isa_init(struct shrm_dev *shrm); -void isa_exit(struct shrm_dev *shrm); -int add_msg_to_queue(struct message_queue *q, u32 size); -ssize_t isa_read(struct file *filp, char __user *buf, size_t len, - loff_t *ppos); -int get_size_of_new_msg(struct message_queue *q); -int remove_msg_from_queue(struct message_queue *q); -void shrm_char_reset_queues(struct shrm_dev *shrm); -int shrm_get_cdev_index(u8 l2_header); -int shrm_get_cdev_l2header(u8 idx); - -#endif diff --git a/drivers/char/shrm_char.c b/drivers/char/shrm_char.c index 6375d7f1ea3..31f1fedd704 100644 --- a/drivers/char/shrm_char.c +++ b/drivers/char/shrm_char.c @@ -15,13 +15,13 @@ #include #include #include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #define NAME "IPC_ISA" diff --git a/drivers/misc/shrm/Kconfig b/drivers/misc/shrm/Kconfig deleted file mode 100644 index 6bafdeec5b9..00000000000 --- a/drivers/misc/shrm/Kconfig +++ /dev/null @@ -1,43 +0,0 @@ -# -# SHM HW kernel configuration -# -config U8500_SHRM - tristate "U8500 SHRM hardware driver" - depends on ARCH_U8500 && PHONET - default Y - ---help--- - If you say Y here, you will enable the STN8500 SHM hardware driver. - - If unsure, say N. -choice - prompt "Modem Image Version" - depends on U8500_SHRM - default SHRM_V1_UPDATES_VERSION - - config SHRM_V1_UPDATES_VERSION - depends on U8500_SHRM - bool "SHRM V1 UPDATES" - help - Modem Images with V1 Updates - -endchoice - -config U8500_SHRM_LOOP_BACK - tristate "U8500 SHRM loopback" - depends on U8500_SHRM - default n - ---help--- - If you say Y here, you will enable the shm loopback - - If unsure, say N. - -config U8500_SHRM_MODEM_SILENT_RESET - bool "U8500 SHRM Modem Silent Reset" - depends on U8500_SHRM - default n - ---help--- - If you say Y here, you will enable the modem silent reset feature - - If unsure, say N. - - diff --git a/drivers/misc/shrm/Makefile b/drivers/misc/shrm/Makefile deleted file mode 100644 index 8115c24920b..00000000000 --- a/drivers/misc/shrm/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# -# Makefile for SHRM drivers -# - -ifdef CONFIG_PHONET -u8500_shrm-objs := modem_shrm_driver.o shrm_fifo.o shrm_protocol.o -else -u8500_shrm-objs := shrm_driver.o shrm_fifo.o shrm_protocol.o -endif - -obj-$(CONFIG_U8500_SHRM) += u8500_shrm.o diff --git a/drivers/misc/shrm/modem_shrm_driver.c b/drivers/misc/shrm/modem_shrm_driver.c deleted file mode 100644 index a3c8d4bda1b..00000000000 --- a/drivers/misc/shrm/modem_shrm_driver.c +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghvi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#ifdef CONFIG_HIGH_RES_TIMERS -#include -static struct hrtimer timer; -#endif -#include -#include -#include - -/* debug functionality */ -#define ISA_DEBUG 0 - -#define PHONET_TASKLET -#define MAX_RCV_LEN 2048 - -void do_phonet_rcv_tasklet(unsigned long unused); -struct tasklet_struct phonet_rcv_tasklet; - -/** - * audio_receive() - Receive audio channel completion callback - * @shrm: pointer to shrm device information structure - * @data: message pointer - * @n_bytes: message size - * @l2_header: L2 header/device ID 2->audio, 5->audio_loopback - * - * This fucntion is called from the audio receive handler. Copies the audio - * message from the FIFO to the AUDIO queue. The message is later copied from - * this queue to the user buffer through the char or net interface read - * operation. - */ -static int audio_receive(struct shrm_dev *shrm, void *data, - u32 n_bytes, u8 l2_header) -{ - u32 size = 0; - int ret = 0; - int idx; - u8 *psrc; - struct message_queue *q; - struct isadev_context *audiodev; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - idx = shrm_get_cdev_index(l2_header); - if (idx < 0) { - dev_err(shrm->dev, "failed to get index\n"); - return idx; - } - audiodev = &shrm->isa_context->isadev[idx]; - q = &audiodev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - ret = add_msg_to_queue(q, n_bytes); - spin_unlock(&q->update_lock); - if (ret < 0) - dev_err(shrm->dev, "Adding a msg to message queue failed"); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * common_receive() - Receive common channel completion callback - * @shrm: pointer to the shrm device information structure - * @data: message pointer - * @n_bytes: message size - * @l2_header: L2 header / device ID - * - * This function is called from the receive handler to copy the respective - * ISI, RPC, SECURITY message to its respective queue. The message is then - * copied from queue to the user buffer on char net interface read operation. - */ -static int common_receive(struct shrm_dev *shrm, void *data, - u32 n_bytes, u8 l2_header) -{ - u32 size = 0; - int ret = 0; - int idx; - u8 *psrc; - struct message_queue *q; - struct isadev_context *isa_dev; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - idx = shrm_get_cdev_index(l2_header); - if (idx < 0) { - dev_err(shrm->dev, "failed to get index\n"); - return idx; - } - isa_dev = &shrm->isa_context->isadev[idx]; - q = &isa_dev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - dev_dbg(shrm->dev, "Inside Loop Back\n"); - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - ret = add_msg_to_queue(q, n_bytes); - spin_unlock(&q->update_lock); - if (ret < 0) { - dev_err(shrm->dev, "Adding a msg to message queue failed"); - return ret; - } - - - if (l2_header == ISI_MESSAGING) { - if (shrm->netdev_flag_up) { - dev_dbg(shrm->dev, - "scheduling the phonet tasklet from %s!\n", - __func__); - tasklet_schedule(&phonet_rcv_tasklet); - } - dev_dbg(shrm->dev, - "Out of phonet tasklet %s!!!\n", __func__); - } - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * rx_common_l2msg_handler() - common channel receive handler - * @l2_header: L2 header - * @msg: pointer to the receive buffer - * @length: length of the msg to read - * @shrm: pointer to shrm device information structure - * - * This function is called to receive the message from CaMsgPendingNotification - * interrupt handler. - */ -static void rx_common_l2msg_handler(u8 l2_header, - void *msg, u32 length, - struct shrm_dev *shrm) -{ - int ret = 0; - dev_dbg(shrm->dev, "%s IN\n", __func__); - - ret = common_receive(shrm, msg, length, l2_header); - if (ret < 0) - dev_err(shrm->dev, - "common receive with l2 header %d failed\n", l2_header); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -/** - * rx_audio_l2msg_handler() - audio channel receive handler - * @l2_header: L2 header - * @msg: pointer to the receive buffer - * @length: length of the msg to read - * @shrm: pointer to shrm device information structure - * - * This function is called to receive the message from CaMsgPendingNotification - * interrupt handler. - */ -static void rx_audio_l2msg_handler(u8 l2_header, - void *msg, u32 length, - struct shrm_dev *shrm) -{ - int ret = 0; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - ret = audio_receive(shrm, msg, length, l2_header); - if (ret < 0) - dev_err(shrm->dev, "audio receive failed\n"); - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -static int __init shm_initialise_irq(struct shrm_dev *shrm) -{ - int err = 0; - - err = shrm_protocol_init(shrm, - rx_common_l2msg_handler, rx_audio_l2msg_handler); - if (err < 0) { - dev_err(shrm->dev, "SHM Protocol Init Failure\n"); - return err; - } - - err = request_irq(shrm->ca_wake_irq, - ca_wake_irq_handler, IRQF_TRIGGER_RISING, - "ca_wake-up", shrm); - if (err < 0) { - dev_err(shrm->dev, - "Unable to allocate shm tx interrupt line\n"); - free_irq(shrm->ca_wake_irq, shrm); - return err; - } - - err = request_irq(shrm->ac_read_notif_0_irq, - ac_read_notif_0_irq_handler, 0, - "ac_read_notif_0", shrm); - - if (err < 0) { - dev_err(shrm->dev, - "error ac_read_notif_0_irq interrupt line\n"); - goto irq_err1; - } - - err = request_irq(shrm->ac_read_notif_1_irq, - ac_read_notif_1_irq_handler, 0, - "ac_read_notif_1", shrm); - - if (err < 0) { - dev_err(shrm->dev, - "error ac_read_notif_1_irq interrupt line\n"); - goto irq_err2; - } - - err = request_irq(shrm->ca_msg_pending_notif_0_irq, - ca_msg_pending_notif_0_irq_handler, 0, - "ca_msg_pending_notif_0", shrm); - - if (err < 0) { - dev_err(shrm->dev, - "error ca_msg_pending_notif_0_irq line\n"); - goto irq_err3; - } - - err = request_irq(shrm->ca_msg_pending_notif_1_irq, - ca_msg_pending_notif_1_irq_handler, 0, - "ca_msg_pending_notif_1", shrm); - - if (err < 0) { - dev_err(shrm->dev, - "error ca_msg_pending_notif_1_irq interrupt line\n"); - goto irq_err4; - } - return err; -irq_err4: - free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); -irq_err3: - free_irq(shrm->ac_read_notif_1_irq, shrm); -irq_err2: - free_irq(shrm->ac_read_notif_0_irq, shrm); -irq_err1: - free_irq(shrm->ca_wake_irq, shrm); - return err; -} - -static void free_shm_irq(struct shrm_dev *shrm) -{ - free_irq(shrm->ca_wake_irq, shrm); - free_irq(shrm->ac_read_notif_0_irq, shrm); - free_irq(shrm->ac_read_notif_1_irq, shrm); - free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); - free_irq(shrm->ca_msg_pending_notif_1_irq, shrm); -} - - - -#ifdef CONFIG_HIGH_RES_TIMERS -static enum hrtimer_restart callback(struct hrtimer *timer) -{ - return HRTIMER_NORESTART; -} -#endif - -void do_phonet_rcv_tasklet(unsigned long unused) -{ - ssize_t ret; - struct shrm_dev *shrm = (struct shrm_dev *)unused; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - for (;;) { - ret = shrm_net_receive(shrm->ndev); - if (ret == 0) { - dev_dbg(shrm->dev, "len is zero, queue empty\n"); - break; - } - if (ret < 0) { - dev_err(shrm->dev, "len < 0 !!! error!!!\n"); - break; - } - } - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -static int shrm_probe(struct platform_device *pdev) -{ - int err = 0; - struct resource *res; - struct shrm_dev *shrm = NULL; - - shrm = kzalloc(sizeof(struct shrm_dev), GFP_KERNEL); - if (shrm == NULL) { - dev_err(&pdev->dev, - "Could not allocate memory for struct shm_dev\n"); - return -ENOMEM; - } - - shrm->dev = &pdev->dev; - shrm->modem = modem_get(shrm->dev, "u8500-shrm-modem"); - if (shrm->modem == NULL) { - dev_err(shrm->dev, " Could not retrieve the modem.\n"); - return -ENODEV; - } - - /* initialise the SHM */ - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - dev_err(shrm->dev, - "Unable to map Ca Wake up interrupt\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_wake_irq = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); - - if (!res) { - dev_err(shrm->dev, - "Unable to map APE_Read_notif_common IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ac_read_notif_0_irq = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 2); - - if (!res) { - dev_err(shrm->dev, - "Unable to map APE_Read_notif_audio IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ac_read_notif_1_irq = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 3); - - if (!res) { - dev_err(shrm->dev, - "Unable to map Cmt_msg_pending_notif_common IRQbase\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_msg_pending_notif_0_irq = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 4); - - if (!res) { - dev_err(shrm->dev, - "Unable to map Cmt_msg_pending_notif_audio IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_msg_pending_notif_1_irq = res->start; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - - if (!res) { - dev_err(shrm->dev, - "Could not get SHM IO memory information\n"); - err = -ENODEV; - goto rollback_intr; - } - shrm->intr_base = (void __iomem *)ioremap_nocache(res->start, - res->end - res->start + 1); - if (!(shrm->intr_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ape_common_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_APE_COMMON_BASE; - shrm->ape_common_fifo_base = - (void __iomem *)ioremap_nocache( - U8500_SHM_FIFO_APE_COMMON_BASE, - SHM_FIFO_0_SIZE); - shrm->ape_common_fifo_size = (SHM_FIFO_0_SIZE)/4; - - if (!(shrm->ape_common_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ape_common_fifo_base; - } - shrm->cmt_common_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_CMT_COMMON_BASE; - shrm->cmt_common_fifo_base = - (void __iomem *)ioremap_nocache( - U8500_SHM_FIFO_CMT_COMMON_BASE, SHM_FIFO_0_SIZE); - shrm->cmt_common_fifo_size = (SHM_FIFO_0_SIZE)/4; - - if (!(shrm->cmt_common_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_cmt_common_fifo_base; - } - shrm->ape_audio_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_APE_AUDIO_BASE; - shrm->ape_audio_fifo_base = - (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_APE_AUDIO_BASE, - SHM_FIFO_1_SIZE); - shrm->ape_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; - - if (!(shrm->ape_audio_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ape_audio_fifo_base; - } - shrm->cmt_audio_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_CMT_AUDIO_BASE; - shrm->cmt_audio_fifo_base = - (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_CMT_AUDIO_BASE, - SHM_FIFO_1_SIZE); - shrm->cmt_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; - - if (!(shrm->cmt_audio_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_cmt_audio_fifo_base; - } - shrm->ac_common_shared_wptr = - (void __iomem *)ioremap(SHM_ACFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_common_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ac_common_shared_wptr; - } - shrm->ac_common_shared_rptr = - (void __iomem *)ioremap(SHM_ACFIFO_0_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_common_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ca_common_shared_wptr = - (void __iomem *)ioremap(SHM_CAFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_common_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ca_common_shared_rptr = - (void __iomem *)ioremap(SHM_CAFIFO_0_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_common_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ac_audio_shared_wptr = - (void __iomem *)ioremap(SHM_ACFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_audio_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ac_audio_shared_rptr = - (void __iomem *)ioremap(SHM_ACFIFO_1_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_audio_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ca_audio_shared_wptr = - (void __iomem *)ioremap(SHM_CAFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_audio_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - shrm->ca_audio_shared_rptr = - (void __iomem *)ioremap(SHM_CAFIFO_1_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_audio_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - if (isa_init(shrm) != 0) { - dev_err(shrm->dev, "Driver Initialization Error\n"); - err = -EBUSY; - } - /* install handlers and tasklets */ - if (shm_initialise_irq(shrm)) { - dev_err(shrm->dev, - "shm error in interrupt registration\n"); - goto rollback_irq; - } -#ifdef CONFIG_HIGH_RES_TIMERS - hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - timer.function = callback; - hrtimer_start(&timer, ktime_set(0, 2*NSEC_PER_MSEC), HRTIMER_MODE_REL); -#endif - err = shrm_register_netdev(shrm); - if (err < 0) - goto rollback_irq; - - tasklet_init(&phonet_rcv_tasklet, do_phonet_rcv_tasklet, 0); - phonet_rcv_tasklet.data = (unsigned long)shrm; - - platform_set_drvdata(pdev, shrm); - - return err; -rollback_irq: - free_shm_irq(shrm); -rollback_map: - iounmap(shrm->ac_common_shared_wptr); - iounmap(shrm->ac_common_shared_rptr); - iounmap(shrm->ca_common_shared_wptr); - iounmap(shrm->ca_common_shared_rptr); - iounmap(shrm->ac_audio_shared_wptr); - iounmap(shrm->ac_audio_shared_rptr); - iounmap(shrm->ca_audio_shared_wptr); - iounmap(shrm->ca_audio_shared_rptr); -rollback_ac_common_shared_wptr: - iounmap(shrm->cmt_audio_fifo_base); -rollback_cmt_audio_fifo_base: - iounmap(shrm->ape_audio_fifo_base); -rollback_ape_audio_fifo_base: - iounmap(shrm->cmt_common_fifo_base); -rollback_cmt_common_fifo_base: - iounmap(shrm->ape_common_fifo_base); -rollback_ape_common_fifo_base: - iounmap(shrm->intr_base); -rollback_intr: - kfree(shrm); - return err; -} - -static int __exit shrm_remove(struct platform_device *pdev) -{ - struct shrm_dev *shrm = platform_get_drvdata(pdev); - - free_shm_irq(shrm); - iounmap(shrm->intr_base); - iounmap(shrm->ape_common_fifo_base); - iounmap(shrm->cmt_common_fifo_base); - iounmap(shrm->ape_audio_fifo_base); - iounmap(shrm->cmt_audio_fifo_base); - iounmap(shrm->ac_common_shared_wptr); - iounmap(shrm->ac_common_shared_rptr); - iounmap(shrm->ca_common_shared_wptr); - iounmap(shrm->ca_common_shared_rptr); - iounmap(shrm->ac_audio_shared_wptr); - iounmap(shrm->ac_audio_shared_rptr); - iounmap(shrm->ca_audio_shared_wptr); - iounmap(shrm->ca_audio_shared_rptr); - shrm_unregister_netdev(shrm); - isa_exit(shrm); - kfree(shrm); - - return 0; -} - -#ifdef CONFIG_PM -/** - * u8500_shrm_suspend() - This routine puts the SHRM in to sustend state. - * @dev: pointer to device structure. - * - * This routine checks the current ongoing communication with Modem by - * examining the ca_wake state and prevents suspend if modem communication - * is on-going. - * If ca_wake = 1 (high), modem comm. is on-going; don't suspend - * If ca_wake = 0 (low), no comm. with modem on-going.Allow suspend - */ -int u8500_shrm_suspend(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct shrm_dev *shrm = platform_get_drvdata(pdev); - int err; - - dev_dbg(&pdev->dev, "%s called...\n", __func__); - dev_dbg(&pdev->dev, "ca_wake_req_state = %x\n", - get_ca_wake_req_state()); - - /* if ca_wake_req is high, prevent system suspend */ - if (!get_ca_wake_req_state()) { - err = shrm_suspend_netdev(shrm->ndev); - return err; - } else - return -EBUSY; -} - -/** - * u8500_shrm_resume() - This routine resumes the SHRM from suspend state. - * @dev: pointer to device structure - * - * This routine restore back the current state of the SHRM - */ -int u8500_shrm_resume(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct shrm_dev *shrm = platform_get_drvdata(pdev); - int err; - - dev_dbg(&pdev->dev, "%s called...\n", __func__); - err = shrm_resume_netdev(shrm->ndev); - - return err; -} - -static const struct dev_pm_ops shrm_dev_pm_ops = { - .suspend_noirq = u8500_shrm_suspend, - .resume_noirq = u8500_shrm_resume, -}; -#endif - -static struct platform_driver shrm_driver = { - .remove = __exit_p(shrm_remove), - .driver = { - .name = "u8500_shrm", - .owner = THIS_MODULE, -#ifdef CONFIG_PM - .pm = &shrm_dev_pm_ops, -#endif - }, -}; - -static int __init shrm_driver_init(void) -{ - return platform_driver_probe(&shrm_driver, shrm_probe); -} - -static void __exit shrm_driver_exit(void) -{ - platform_driver_unregister(&shrm_driver); -} - -module_init(shrm_driver_init); -module_exit(shrm_driver_exit); - -MODULE_AUTHOR("Biju Das, Kumar Sanghvi, Arun Murthy"); -MODULE_DESCRIPTION("Shared Memory Modem Driver Interface"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/misc/shrm/shrm_driver.c b/drivers/misc/shrm/shrm_driver.c deleted file mode 100644 index 6277794608a..00000000000 --- a/drivers/misc/shrm/shrm_driver.c +++ /dev/null @@ -1,1439 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghvi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#define DEBUG - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -#ifdef CONFIG_HIGH_RES_TIMERS -#include -static struct hrtimer timer; -#endif - - -#define NAME "IPC_ISA" -#define ISA_DEVICES 4 -/**debug functionality*/ -#define ISA_DEBUG 0 - -#define ISI_MESSAGING (0) -#define RPC_MESSAGING (1) -#define AUDIO_MESSAGING (2) -#define SECURITY_MESSAGING (3) - -#define SIZE_OF_FIFO (512*1024) - -static u8 message_fifo[4][SIZE_OF_FIFO]; - -static u8 wr_isi_msg[10*1024]; -static u8 wr_rpc_msg[10*1024]; -static u8 wr_sec_msg[10*1024]; -static u8 wr_audio_msg[10*1024]; - -/* global data */ -/* - * int major:This variable is exported to user as module_param to specify - * major number at load time - */ -static int major; -module_param(major, int, 0); -MODULE_PARM_DESC(major, "Major device number"); -/* global fops mutex */ -static DEFINE_MUTEX(isa_lock); -rx_cb common_rx; -rx_cb audio_rx; - - -static int isi_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); -static int rpc_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); -static int audio_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); -static int security_receive(struct shrm_dev *shrm, - void *data, u32 n_bytes); - -static void rx_common_l2msg_handler(u8 l2_header, - void *msg, u32 length, - struct shrm_dev *shrm) -{ - int ret = 0; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - u8 *pdata; -#endif - dev_dbg(shrm->dev, "%s IN\n", __func__); - - switch (l2_header) { - case ISI_MESSAGING: - ret = isi_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, "isi receive failed\n"); - break; - case RPC_MESSAGING: - ret = rpc_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, "rpc receive failed\n"); - break; - case SECURITY_MESSAGING: - ret = security_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, - "security receive failed\n"); - break; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - case COMMMON_LOOPBACK_MESSAGING: - pdata = (u8 *)msg; - if ((*pdata == 0x50) || (*pdata == 0xAF)) { - ret = isi_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, "isi receive failed\n"); - } else if ((*pdata == 0x0A) || (*pdata == 0xF5)) { - ret = rpc_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, "rpc receive failed\n"); - } else if ((*pdata == 0xFF) || (*pdata == 0x00)) { - ret = security_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, - "security receive failed\n"); - } - break; -#endif - default: - break; - } - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -static void rx_audio_l2msg_handler(u8 l2_header, - void *msg, u32 length, - struct shrm_dev *shrm) -{ - int ret = 0; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - audio_receive(shrm, msg, length); - if (ret < 0) - dev_err(shrm->dev, "audio receive failed\n"); - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -static int __init shm_initialise_irq(struct shrm_dev *shrm) -{ - int err = 0; - - shrm_protocol_init(shrm, - rx_common_l2msg_handler, rx_audio_l2msg_handler); - - err = request_irq(shrm->ca_wake_irq, - ca_wake_irq_handler, IRQF_TRIGGER_RISING, - "ca_wake-up", shrm); - if (err < 0) { - dev_err(shrm->dev, - "Unable to allocate shm tx interrupt line\n"); - return err; - } - - err = request_irq(shrm->ac_read_notif_0_irq, - ac_read_notif_0_irq_handler, 0, - "ac_read_notif_0", shrm); - if (err < 0) { - dev_err(shrm->dev, - "error ac_read_notif_0_irq interrupt line\n"); - goto irq_err1; - } - - err = request_irq(shrm->ac_read_notif_1_irq, - ac_read_notif_1_irq_handler, 0, - "ac_read_notif_1", shrm); - if (err < 0) { - dev_err(shrm->dev, - "error ac_read_notif_1_irq interrupt line\n"); - goto irq_err2; - } - - err = request_irq(shrm->ca_msg_pending_notif_0_irq, - ca_msg_pending_notif_0_irq_handler, 0, - "ca_msg_pending_notif_0", shrm); - if (err < 0) { - dev_err(shrm->dev, - "error ca_msg_pending_notif_0_irq line\n"); - goto irq_err3; - } - - err = request_irq(shrm->ca_msg_pending_notif_1_irq, - ca_msg_pending_notif_1_irq_handler, 0, - "ca_msg_pending_notif_1", shrm); - if (err < 0) { - dev_err(shrm->dev, - "error ca_msg_pending_notif_1_irq interrupt line\n"); - goto irq_err4; - } - - return err; - -irq_err4: - free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); -irq_err3: - free_irq(shrm->ac_read_notif_1_irq, shrm); -irq_err2: - free_irq(shrm->ac_read_notif_0_irq, shrm); -irq_err1: - free_irq(shrm->ca_wake_irq, shrm); - return err; -} - -static void free_shm_irq(struct shrm_dev *shrm) -{ - free_irq(shrm->ca_wake_irq, shrm); - free_irq(shrm->ac_read_notif_0_irq, shrm); - free_irq(shrm->ac_read_notif_1_irq, shrm); - free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); - free_irq(shrm->ca_msg_pending_notif_1_irq, shrm); -} - -/** - * create_queue() - To create FIFO for Tx and Rx message buffering. - * @q: message queue. - * @devicetype: device type 0-isi,1-rpc,2-audio,3-security. - * - * This function creates a FIFO buffer of n_bytes size using - * dma_alloc_coherent(). It also initializes all queue handling - * locks, queue management pointers. It also initializes message list - * which occupies this queue. - * - * It return -ENOMEM in case of no memory. - */ -static int create_queue(struct message_queue *q, u32 devicetype, - struct shrm_dev *shrm) -{ - q->fifo_base = (u8 *)&message_fifo[devicetype]; - q->size = SIZE_OF_FIFO; - q->readptr = 0; - q->writeptr = 0; - q->no = 0; - q->shrm = shrm; - spin_lock_init(&q->update_lock); - INIT_LIST_HEAD(&q->msg_list); - init_waitqueue_head(&q->wq_readable); - atomic_set(&q->q_rp, 0); - - return 0; -} -/** - * delete_queue() - To delete FIFO and assiciated memory. - * @q: message queue - * - * This function deletes FIFO created using create_queue() function. - * It resets queue management pointers. - */ -static void delete_queue(struct message_queue *q) -{ - q->size = 0; - q->readptr = 0; - q->writeptr = 0; -} - -/** - * add_msg_to_queue() - Add a message inside inside queue - * - * @q: message queue - * @size: size in bytes - * - * This function tries to allocate n_bytes of size in FIFO q. - * It returns negative number when no memory can be allocated - * currently. - */ -int add_msg_to_queue(struct message_queue *q, u32 size) -{ - struct queue_element *new_msg = NULL; - struct shrm_dev *shrm = q->shrm; - - dev_dbg(shrm->dev, "%s IN q->writeptr=%d\n", - __func__, q->writeptr); - new_msg = kmalloc(sizeof(struct queue_element), - GFP_KERNEL|GFP_ATOMIC); - - if (new_msg == NULL) { - dev_err(shrm->dev, "memory overflow inside while(1)\n"); - return -ENOMEM; - } - new_msg->offset = q->writeptr; - new_msg->size = size; - new_msg->no = q->no++; - - /* check for overflow condition */ - if (q->readptr <= q->writeptr) { - if (((q->writeptr-q->readptr) + size) >= q->size) { - dev_err(shrm->dev, "Buffer overflow !!\n"); - BUG_ON(((q->writeptr-q->readptr) + size) >= q->size); - } - } else { - if ((q->writeptr + size) >= q->readptr) { - dev_err(shrm->dev, "Buffer overflow !!\n"); - BUG_ON((q->writeptr + size) >= q->readptr); - } - } - q->writeptr = (q->writeptr + size) % q->size; - if (list_empty(&q->msg_list)) { - list_add_tail(&new_msg->entry, &q->msg_list); - /* There can be 2 blocking calls read and another select */ - - atomic_set(&q->q_rp, 1); - wake_up_interruptible(&q->wq_readable); - } else - list_add_tail(&new_msg->entry, &q->msg_list); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return 0; -} - -/** - * remove_msg_from_queue() - To remove a message from the msg queue. - * - * @q: message queue - * - * This function delets a message from the message list associated with message - * queue q and also updates read ptr. - * If the message list is empty, then, event is set to block the select and - * read calls of the paricular queue. - * - * The message list is FIFO style and message is always added to tail and - * removed from head. - */ - -int remove_msg_from_queue(struct message_queue *q) -{ - struct queue_element *old_msg = NULL; - struct shrm_dev *shrm = q->shrm; - struct list_head *msg; - - dev_dbg(shrm->dev, "%s IN q->readptr %d\n", - __func__, q->readptr); - - list_for_each(msg, &q->msg_list) { - old_msg = list_entry(msg, struct queue_element, entry); - if (old_msg == NULL) { - dev_err(shrm->dev, ":no message found\n"); - return -EFAULT; - } - break; - } - list_del(msg); - q->readptr = (q->readptr + old_msg->size) % q->size; - if (list_empty(&q->msg_list)) { - dev_dbg(shrm->dev, "List is empty setting RP= 0\n"); - atomic_set(&q->q_rp, 0); - } - kfree(old_msg); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return 0; -} - -/** - * get_size_of_new_msg() - retrieve new message from message list - * - * @q: message queue - * - * This function will retrieve most recent message from the corresponding - * queue list. New message is always retrieved from head side. - * It returns new message no, offset if FIFO and size. - */ -int get_size_of_new_msg(struct message_queue *q) -{ - struct queue_element *new_msg = NULL; - struct list_head *msg_list; - struct shrm_dev *shrm = q->shrm; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - spin_lock_bh(&q->update_lock); - list_for_each(msg_list, &q->msg_list) { - new_msg = list_entry(msg_list, struct queue_element, entry); - if (new_msg == NULL) { - spin_unlock_bh(&q->update_lock); - dev_err(shrm->dev, "no message found\n"); - return -1; - } - break; - } - spin_unlock_bh(&q->update_lock); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return new_msg->size; -} - -/** - * isi_receive() - Rx Completion callback - * - * @data:message pointer - * @n_bytes:message size - * - * This function is a callback to indicate ISI message reception is complete. - * It updates Writeptr of the Fifo - */ -static int isi_receive(struct shrm_dev *shrm, - void *data, u32 n_bytes) -{ - u32 size = 0; - int ret = 0; - u8 *psrc; - struct message_queue *q; - struct isadev_context *isidev = &shrm->isa_context->isadev[0]; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - q = &isidev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - dev_dbg(shrm->dev, "Inside Loop Back\n"); - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - ret = add_msg_to_queue(q, n_bytes); - if (ret < 0) - dev_err(shrm->dev, "Adding msg to message queue failed\n"); - spin_unlock(&q->update_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * rpc_receive() - Rx Completion callback - * - * @data:message pointer - * @n_bytes:message size - * - * This function is a callback to indicate RPC message reception is complete. - * It updates Writeptr of the Fifo - */ -static int rpc_receive(struct shrm_dev *shrm, - void *data, u32 n_bytes) -{ - u32 size = 0; - int ret = 0; - u8 *psrc; - struct message_queue *q; - struct isadev_context *rpcdev = &shrm->isa_context->isadev[1]; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - q = &rpcdev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - - ret = add_msg_to_queue(q, n_bytes); - if (ret < 0) - dev_err(shrm->dev, "Adding msg to message queue failed\n"); - spin_unlock(&q->update_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * audio_receive() - Rx Completion callback - * - * @data:message pointer - * @n_bytes:message size - * - * This function is a callback to indicate audio message reception is complete. - * It updates Writeptr of the Fifo - */ -static int audio_receive(struct shrm_dev *shrm, - void *data, u32 n_bytes) -{ - u32 size = 0; - int ret = 0; - u8 *psrc; - struct message_queue *q; - struct isadev_context *audiodev = &shrm->isa_context->isadev[2]; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - q = &audiodev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - ret = add_msg_to_queue(q, n_bytes); - if (ret < 0) - dev_err(shrm->dev, "Adding msg to message queue failed\n"); - spin_unlock(&q->update_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * security_receive() - Rx Completion callback - * - * @data:message pointer - * @n_bytes: message size - * - * This function is a callback to indicate security message reception - * is complete.It updates Writeptr of the Fifo - */ -static int security_receive(struct shrm_dev *shrm, - void *data, u32 n_bytes) -{ - u32 size = 0; - int ret = 0; - u8 *psrc; - struct message_queue *q; - struct isadev_context *secdev = &shrm->isa_context->isadev[3]; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - q = &secdev->dl_queue; - spin_lock(&q->update_lock); - /* Memcopy RX data first */ - if ((q->writeptr+n_bytes) >= q->size) { - psrc = (u8 *)data; - size = (q->size-q->writeptr); - /* Copy First Part of msg */ - memcpy((q->fifo_base+q->writeptr), psrc, size); - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - memcpy(q->fifo_base, psrc, (n_bytes-size)); - } else { - memcpy((q->fifo_base+q->writeptr), data, n_bytes); - } - ret = add_msg_to_queue(q, n_bytes); - if (ret < 0) - dev_err(shrm->dev, "Adding msg to message queue failed\n"); - spin_unlock(&q->update_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - - -/** - * isa_select() - Select Interface - * - * @filp:file descriptor pointer - * @wait:poll_table_struct pointer - * - * This function is used to perform non-blocking read operations. It allows - * a process to determine whether it can read from one or more open files - * without blocking. These calls can also block a process until any of a - * given set of file descriptors becomes available for reading. - * If a file is ready to read, POLLIN | POLLRDNORM bitmask is returned. - * The driver method is called whenever the user-space program performs a select - * system call involving a file descriptor associated with the driver. - */ -static u32 isa_select(struct file *filp, - struct poll_table_struct *wait) -{ - struct isadev_context *isadev = filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - struct message_queue *q; - u32 mask = 0; - u32 m = iminor(filp->f_path.dentry->d_inode); - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (isadev->device_id != m) - return -1; - q = &isadev->dl_queue; - poll_wait(filp, &q->wq_readable, wait); - if (atomic_read(&q->q_rp) == 1) - mask = POLLIN | POLLRDNORM; - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return mask; -} - -/** - * isa_read() - Read from device - * - * @filp:file descriptor - * @buf:user buffer pointer - * @len:size of requested data transfer - * @ppos:not used - * - * This function is called whenever user calls read() system call. - * It reads a oldest message from queue and copies it into user buffer and - * returns its size. - * If there is no message present in queue, then it blocks until new data is - * available. - */ -ssize_t isa_read(struct file *filp, char __user *buf, - size_t len, loff_t *ppos) -{ - struct isadev_context *isadev = (struct isadev_context *) - filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - struct message_queue *q; - char *psrc; - u32 msgsize; - u32 size = 0; - int ret = 0; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (len <= 0) - return -EFAULT; - q = &isadev->dl_queue; - - spin_lock_bh(&q->update_lock); - if (list_empty(&q->msg_list)) { - spin_unlock_bh(&q->update_lock); - if (wait_event_interruptible(q->wq_readable, - atomic_read(&q->q_rp) == 1)) { - return -ERESTARTSYS; - } - } else - spin_unlock_bh(&q->update_lock); - - msgsize = get_size_of_new_msg(q); - if ((q->readptr+msgsize) >= q->size) { - dev_dbg(shrm->dev, "Inside Loop Back\n"); - psrc = (char *)buf; - size = (q->size-q->readptr); - /* Copy First Part of msg */ - if (copy_to_user(psrc, - (u8 *)(q->fifo_base+q->readptr), - size)) { - dev_err(shrm->dev, "copy_to_user failed\n"); - return -EFAULT; - } - psrc += size; - /* Copy Second Part of msg at the top of fifo */ - if (copy_to_user(psrc, - (u8 *)(q->fifo_base), - (msgsize-size))) { - dev_err(shrm->dev, "copy_to_user failed\n"); - return -EFAULT; - } - } else { - if (copy_to_user(buf, - (u8 *)(q->fifo_base+q->readptr), - msgsize)) { - dev_err(shrm->dev, "copy_to_user failed\n"); - return -EFAULT; - } - } - - spin_lock_bh(&q->update_lock); - ret = remove_msg_from_queue(q); - if (ret < 0) { - dev_err(shrm->dev, - "Removing msg from message queue failed\n"); - msgsize = ret; - } - spin_unlock_bh(&q->update_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return msgsize; -} -/** - * isa_write() - Write to device - * - * @filp:file descriptor - * @buf:user buffer pointer - * @len:size of requested data transfer - * @ppos:not used - * - * This function is called whenever user calls write() system call. - * It checks if there is space available in queue, and copies the message - * inside queue. If there is no space, it blocks until space becomes available. - * It also schedules transfer thread to transmit the newly added message. - */ -static ssize_t isa_write(struct file *filp, const char __user *buf, - size_t len, loff_t *ppos) -{ - struct isadev_context *isadev = filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - struct message_queue *q; - int err, ret; - void *addr = 0; - u8 l2_header = 0; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - if (len <= 0) - return -EFAULT; - q = &isadev->dl_queue; - - switch (isadev->device_id) { - case ISI_MESSAGING: - dev_dbg(shrm->dev, "ISI\n"); - addr = (void *)wr_isi_msg; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - dev_dbg(shrm->dev, "Loopback\n"); - l2_header = COMMON_LOOPBACK_MESSAGING; -#else - l2_header = isadev->device_id; -#endif - break; - case RPC_MESSAGING: - dev_dbg(shrm->dev, "RPC\n"); - addr = (void *)wr_rpc_msg; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - l2_header = COMMON_LOOPBACK_MESSAGING; -#else - l2_header = isadev->device_id; -#endif - break; - case AUDIO_MESSAGING: - dev_dbg(shrm->dev, "Audio\n"); - addr = (void *)wr_audio_msg; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - l2_header = AUDIO_LOOPBACK_MESSAGING; -#else - l2_header = isadev->device_id; -#endif - - break; - case SECURITY_MESSAGING: - dev_dbg(shrm->dev, "Security\n"); - addr = (void *)wr_sec_msg; -#ifdef CONFIG_U8500_SHRM_LOOP_BACK - l2_header = COMMON_LOOPBACK_MESSAGING; -#else - l2_header = isadev->device_id; -#endif - break; - default: - dev_dbg(shrm->dev, "Wrong device\n"); - return -EFAULT; - } - - if (copy_from_user(addr, buf, len)) { - dev_err(shrm->dev, "copy_from_user failed\n"); - return -EFAULT; - } - - /* Write msg to Fifo */ - if (isadev->device_id == 2) { - mutex_lock(&shrm->isa_context->tx_audio_mutex); - err = shm_write_msg(shrm, l2_header, addr, len); - if (!err) - ret = len; - else - ret = err; - mutex_unlock(&shrm->isa_context->tx_audio_mutex); - } else { - spin_lock_bh(&shrm->isa_context->common_tx); - err = shm_write_msg(shrm, l2_header, addr, len); - if (!err) - ret = len; - else - ret = err; - spin_unlock_bh(&shrm->isa_context->common_tx); - } - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return ret; -} - -/** - * isa_ioctl() - To handle different ioctl commands supported by driver. - * - * @inode: structure is used by the kernel internally to represent files - * @filp:file descriptor pointer - * @cmd:ioctl command - * @arg:input param - * - * Following ioctls are supported by this driver. - * DLP_IOCTL_ALLOCATE_BUFFER - To allocate buffer for new uplink message. - * This ioctl is called with required message size. It returns offset for - * the allocates space in the queue. DLP_IOCTL_PUT_MESSAGE - To indicate - * new uplink message available in queuq for transmission. Message is copied - * from offset location returned by previous ioctl before calling this ioctl. - * DLP_IOCTL_GET_MESSAGE - To check if any downlink message is available in - * queue. It returns offset for new message inside queue. - * DLP_IOCTL_DEALLOCATE_BUFFER - To deallocate any buffer allocate for - * downlink message once the message is copied. Message is copied from offset - * location returned by previous ioctl before calling this ioctl. - */ -static int isa_ioctl(struct inode *inode, struct file *filp, - unsigned cmd, unsigned long arg) -{ - int err = 0; - struct isadev_context *isadev = filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - u32 m = iminor(inode); - - if (isadev->device_id != m) - return -1; - - switch (cmd) { - case DLP_IOC_ALLOCATE_BUFFER: - dev_dbg(shrm->dev, "DLP_IOC_ALLOCATE_BUFFER\n"); - break; - case DLP_IOC_PUT_MESSAGE: - dev_dbg(shrm->dev, "DLP_IOC_PUT_MESSAGE\n"); - break; - case DLP_IOC_GET_MESSAGE: - dev_dbg(shrm->dev, "DLP_IOC_GET_MESSAGE\n"); - break; - case DLP_IOC_DEALLOCATE_BUFFER: - dev_dbg(shrm->dev, "DLP_IOC_DEALLOCATE_BUFFER\n"); - break; - default: - dev_dbg(shrm->dev, "Unknown IOCTL\n"); - err = -1; - break; - } - return err; -} -/** - * isa_mmap() - Maps kernel queue memory to user space. - * - * @filp:file descriptor pointer - * @vma:virtual area memory structure. - * - * This function maps kernel FIFO into user space. This function - * shall be called twice to map both uplink and downlink buffers. - */ -static int isa_mmap(struct file *filp, struct vm_area_struct *vma) -{ - struct isadev_context *isadev = filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - - u32 m = iminor(filp->f_path.dentry->d_inode); - dev_dbg(shrm->dev, "%s %dIN\n", __func__, m); - - isadev = (struct isadev_context *)filp->private_data; - return 0; -} - -/** - * isa_close() - Close device file - * - * @inode:structure is used by the kernel internally to represent files - * @filp:device file descriptor - * - * This function deletes structues associated with this file, deletes - * queues, flushes and destroys workqueus and closes this file. - * It also unregisters itself from l2mux driver. - */ -static int isa_close(struct inode *inode, struct file *filp) -{ - struct isadev_context *isadev = filp->private_data; - struct shrm_dev *shrm = isadev->dl_queue.shrm; - struct isa_driver_context *isa_context = shrm->isa_context; - u8 m; - - mutex_lock(&isa_lock); - m = iminor(filp->f_path.dentry->d_inode); - dev_dbg(shrm->dev, "%s IN %d", __func__, m); - - if (atomic_dec_and_test(&isa_context->is_open[m])) { - atomic_inc(&isa_context->is_open[m]); - dev_err(shrm->dev, "Device not opened yet\n"); - mutex_unlock(&isa_lock); - return -ENODEV; - } - atomic_set(&isa_context->is_open[m], 1); - - dev_dbg(shrm->dev, "isadev->device_id %d", isadev->device_id); - dev_dbg(shrm->dev, "Closed %d device\n", m); - - if (m == ISI_MESSAGING) - dev_dbg(shrm->dev, "Closed ISI_MESSAGING Device\n"); - else if (m == RPC_MESSAGING) - dev_dbg(shrm->dev, "Closed RPC_MESSAGING Device\n"); - else if (m == AUDIO_MESSAGING) - dev_dbg(shrm->dev, "Closed AUDIO_MESSAGING Device\n"); - else if (m == SECURITY_MESSAGING) - dev_dbg(shrm->dev, "Closed SECURITY_MESSAGING Device\n"); - else - dev_dbg(shrm->dev, NAME ":No such device present\n"); - - mutex_unlock(&isa_lock); - return 0; -} -/** - * isa_open() - Open device file - * - * @inode: structure is used by the kernel internally to represent files - * @filp: device file descriptor - * - * This function performs initialization tasks needed to open SHM channel. - * Following tasks are performed. - * -return if device is already opened - * -create uplink FIFO - * -create downlink FIFO - * -init delayed workqueue thread - * -register to l2mux driver - */ -static int isa_open(struct inode *inode, struct file *filp) -{ - int err = 0; - u8 m; - struct isadev_context *isadev; - struct isa_driver_context *isa_context = container_of( - inode->i_cdev, - struct isa_driver_context, - cdev); - struct shrm_dev *shrm = isa_context->isadev->dl_queue.shrm; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (get_boot_state() != BOOT_DONE) { - dev_err(shrm->dev, "Boot is not done\n"); - return -EBUSY; - } - mutex_lock(&isa_lock); - m = iminor(inode); - - if ((m != ISI_MESSAGING) && (m != RPC_MESSAGING) && - (m != AUDIO_MESSAGING) && (m != SECURITY_MESSAGING)) { - dev_err(shrm->dev, "No such device present\n"); - mutex_unlock(&isa_lock); - return -ENODEV; - } - if (!atomic_dec_and_test(&isa_context->is_open[m])) { - atomic_inc(&isa_context->is_open[m]); - dev_err(shrm->dev, "Device already opened\n"); - mutex_unlock(&isa_lock); - return -EBUSY; - } - - if (m == ISI_MESSAGING) - dev_dbg(shrm->dev, "Open ISI_MESSAGING Device\n"); - else if (m == RPC_MESSAGING) - dev_dbg(shrm->dev, "Open RPC_MESSAGING Device\n"); - else if (m == AUDIO_MESSAGING) - dev_dbg(shrm->dev, "Open AUDIO_MESSAGING Device\n"); - else if (m == SECURITY_MESSAGING) - dev_dbg(shrm->dev, "Open SECURITY_MESSAGING Device\n"); - else - dev_dbg(shrm->dev, ":No such device present\n"); - - isadev = &isa_context->isadev[m]; - if (filp != NULL) - filp->private_data = isadev; - - mutex_unlock(&isa_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return err; -} - -const struct file_operations isa_fops = { - .owner = THIS_MODULE, - .open = isa_open, - .release = isa_close, - .ioctl = isa_ioctl, - .mmap = isa_mmap, - .read = isa_read, - .write = isa_write, - .poll = isa_select, -}; - -/** - * isa_init() - module insertion function - * - * This function registers module as a character driver using - * register_chrdev_region() or alloc_chrdev_region. It adds this - * driver to system using cdev_add() call. Major number is dynamically - * allocated using alloc_chrdev_region() by default or left to user to specify - * it during load time. For this variable major is used as module_param - * Nodes to be created using - * mknod /dev/isi c $major 0 - * mknod /dev/rpc c $major 1 - * mknod /dev/audio c $major 2 - * mknod /dev/sec c $major 3 - */ -int isa_init(struct shrm_dev *shrm) -{ - dev_t dev_id; - int retval, no_dev; - struct isadev_context *isadev; - struct isa_driver_context *isa_context; - - isa_context = kzalloc(sizeof(struct isa_driver_context), - GFP_KERNEL); - shrm->isa_context = isa_context; - if (isa_context == NULL) { - dev_err(shrm->dev, "Failed to alloc memory\n"); - return -ENOMEM; - } - - if (major) { - dev_id = MKDEV(major, 0); - retval = register_chrdev_region(dev_id, ISA_DEVICES, NAME); - } else { - retval = alloc_chrdev_region(&dev_id, 0, ISA_DEVICES, NAME); - major = MAJOR(dev_id); - } - - dev_dbg(shrm->dev, "major %d\n", major); - - cdev_init(&isa_context->cdev, &isa_fops); - isa_context->cdev.owner = THIS_MODULE; - retval = cdev_add(&isa_context->cdev, dev_id, ISA_DEVICES); - if (retval) { - dev_err(shrm->dev, "Failed to add char device\n"); - return retval; - } - - for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) - atomic_set(&isa_context->is_open[no_dev], 1); - - isa_context->isadev = kzalloc(sizeof - (struct isadev_context)*ISA_DEVICES, - GFP_KERNEL); - if (isa_context->isadev == NULL) { - dev_err(shrm->dev, "Failed to alloc memory\n"); - return -ENOMEM; - } - for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) { - isadev = &isa_context->isadev[no_dev]; - isadev->device_id = no_dev; - retval = create_queue(&isadev->dl_queue, - isadev->device_id, shrm); - if (retval < 0) { - dev_err(shrm->dev, "create dl_queue failed\n"); - delete_queue(&isadev->dl_queue); - kfree(isadev); - return retval; - } - } - mutex_init(&isa_context->tx_audio_mutex); - spin_lock_init(&isa_context->common_tx); - - dev_err(shrm->dev, "SHRM char driver added\n"); - - return retval; -} - -void isa_exit(struct shrm_dev *shrm) -{ - int no_dev; - struct isadev_context *isadev; - struct isa_driver_context *isa_context = shrm->isa_context; - dev_t dev_id = MKDEV(major, 0); - - for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) { - isadev = &isa_context->isadev[no_dev]; - delete_queue(&isadev->dl_queue); - kfree(isadev); - } - - cdev_del(&isa_context->cdev); - unregister_chrdev_region(dev_id, ISA_DEVICES); - kfree(isa_context); - - dev_err(shrm->dev, "SHRM char driver removed\n"); -} - -#ifdef CONFIG_HIGH_RES_TIMERS -static enum hrtimer_restart callback(struct hrtimer *timer) -{ - return HRTIMER_NORESTART; -} -#endif - - -static int __init shrm_probe(struct platform_device *pdev) -{ - int err = 0; - struct resource *res; - struct shrm_dev *shrm = NULL; - - if (pdev == NULL) { - dev_err(shrm->dev, - "No device/platform_data found on shm device\n"); - return -ENODEV; - } - - - shrm = kzalloc(sizeof(struct shrm_dev), GFP_KERNEL); - if (shrm == NULL) { - dev_err(shrm->dev, - "Could not allocate memory for struct shm_dev\n"); - return -ENOMEM; - } - shrm->dev = &pdev->dev; - - /* initialise the SHM */ - - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - dev_err(shrm->dev, "Unable to map Ca Wake up interrupt\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_wake_irq = res->start; - - res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); - if (!res) { - dev_err(shrm->dev, - "Unable to map APE_Read_notif_common IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ac_read_notif_0_irq = res->start; - - res = platform_get_resource(pdev, IORESOURCE_IRQ, 2); - if (!res) { - dev_err(shrm->dev, - "Unable to map APE_Read_notif_audio IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ac_read_notif_1_irq = res->start; - - res = platform_get_resource(pdev, IORESOURCE_IRQ, 3); - if (!res) { - dev_err(shrm->dev, - "Unable to map Cmt_msg_pending_notif_common IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_msg_pending_notif_0_irq = res->start; - - res = platform_get_resource(pdev, IORESOURCE_IRQ, 4); - if (!res) { - dev_err(shrm->dev, - "Unable to map Cmt_msg_pending_notif_audio IRQ base\n"); - err = -EBUSY; - goto rollback_intr; - } - shrm->ca_msg_pending_notif_1_irq = res->start; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(shrm->dev, - "Could not get SHM IO memory information\n"); - err = -ENODEV; - goto rollback_intr; - } - - shrm->intr_base = (void __iomem *)ioremap_nocache(res->start, - res->end - res->start + 1); - - if (!(shrm->intr_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_intr; - } - - shrm->ape_common_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_APE_COMMON_BASE; - shrm->ape_common_fifo_base = - (void __iomem *)ioremap_nocache( - U8500_SHM_FIFO_APE_COMMON_BASE, - SHM_FIFO_0_SIZE); - shrm->ape_common_fifo_size = (SHM_FIFO_0_SIZE)/4; - - if (!(shrm->ape_common_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ape_common_fifo_base; - } - - shrm->cmt_common_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_CMT_COMMON_BASE; - - shrm->cmt_common_fifo_base = - (void __iomem *)ioremap_nocache( - U8500_SHM_FIFO_CMT_COMMON_BASE, SHM_FIFO_0_SIZE); - shrm->cmt_common_fifo_size = (SHM_FIFO_0_SIZE)/4; - - if (!(shrm->cmt_common_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_cmt_common_fifo_base; - } - - shrm->ape_audio_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_APE_AUDIO_BASE; - shrm->ape_audio_fifo_base = - (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_APE_AUDIO_BASE, - SHM_FIFO_1_SIZE); - shrm->ape_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; - - if (!(shrm->ape_audio_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ape_audio_fifo_base; - } - - shrm->cmt_audio_fifo_base_phy = - (u32 *)U8500_SHM_FIFO_CMT_AUDIO_BASE; - shrm->cmt_audio_fifo_base = - (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_CMT_AUDIO_BASE, - SHM_FIFO_1_SIZE); - shrm->cmt_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; - - if (!(shrm->cmt_audio_fifo_base)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_cmt_audio_fifo_base; - } - - shrm->ac_common_shared_wptr = - (void __iomem *)ioremap(SHM_ACFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_common_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_ac_common_shared_wptr; - } - - shrm->ac_common_shared_rptr = - (void __iomem *)ioremap(SHM_ACFIFO_0_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_common_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - shrm->ca_common_shared_wptr = - (void __iomem *)ioremap(SHM_CAFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_common_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - shrm->ca_common_shared_rptr = - (void __iomem *)ioremap(SHM_CAFIFO_0_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_common_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - shrm->ac_audio_shared_wptr = - (void __iomem *)ioremap(SHM_ACFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_audio_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - shrm->ac_audio_shared_rptr = - (void __iomem *)ioremap(SHM_ACFIFO_1_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ac_audio_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - shrm->ca_audio_shared_wptr = - (void __iomem *)ioremap(SHM_CAFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_audio_shared_wptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - shrm->ca_audio_shared_rptr = - (void __iomem *)ioremap(SHM_CAFIFO_1_READ_AMCU, SHM_PTR_SIZE); - - if (!(shrm->ca_audio_shared_rptr)) { - dev_err(shrm->dev, "Unable to map register base\n"); - err = -EBUSY; - goto rollback_map; - } - - - if (isa_init(shrm) != 0) { - dev_err(shrm->dev, "Driver Initialization Error\n"); - err = -EBUSY; - } - /* install handlers and tasklets */ - if (shm_initialise_irq(shrm)) { - dev_err(shrm->dev, "shm error in interrupt registration\n"); - goto rollback_irq; - } - -#ifdef CONFIG_HIGH_RES_TIMERS - hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - timer.function = callback; - - hrtimer_start(&timer, ktime_set(0, 2*NSEC_PER_MSEC), HRTIMER_MODE_REL); -#endif - - return err; - -rollback_irq: - free_shm_irq(shrm); -rollback_map: - iounmap(shrm->ac_common_shared_wptr); - iounmap(shrm->ac_common_shared_rptr); - iounmap(shrm->ca_common_shared_wptr); - iounmap(shrm->ca_common_shared_rptr); - iounmap(shrm->ac_audio_shared_wptr); - iounmap(shrm->ac_audio_shared_rptr); - iounmap(shrm->ca_audio_shared_wptr); - iounmap(shrm->ca_audio_shared_rptr); -rollback_ac_common_shared_wptr: - iounmap(shrm->cmt_audio_fifo_base); -rollback_cmt_audio_fifo_base: - iounmap(shrm->ape_audio_fifo_base); -rollback_ape_audio_fifo_base: - iounmap(shrm->cmt_common_fifo_base); -rollback_cmt_common_fifo_base: - iounmap(shrm->ape_common_fifo_base); -rollback_ape_common_fifo_base: - iounmap(shrm->intr_base); -rollback_intr: - kfree(shrm); - return err; -} - -static int __exit shrm_remove(struct platform_device *pdev) -{ - struct shrm_dev *shrm = platform_get_drvdata(pdev); - - free_shm_irq(shrm); - iounmap(shrm->intr_base); - iounmap(shrm->ape_common_fifo_base); - iounmap(shrm->cmt_common_fifo_base); - iounmap(shrm->ape_audio_fifo_base); - iounmap(shrm->cmt_audio_fifo_base); - iounmap(shrm->ac_common_shared_wptr); - iounmap(shrm->ac_common_shared_rptr); - iounmap(shrm->ca_common_shared_wptr); - iounmap(shrm->ca_common_shared_rptr); - iounmap(shrm->ac_audio_shared_wptr); - iounmap(shrm->ac_audio_shared_rptr); - iounmap(shrm->ca_audio_shared_wptr); - iounmap(shrm->ca_audio_shared_rptr); - kfree(shrm); - isa_exit(shrm); - - return 0; -} -#ifdef CONFIG_PM - -/** - * u8500_shrm_suspend() - This routine puts the SHRM in to sustend state. - * @pdev: platform device. - * - * This routine checks the current ongoing communication with Modem by - * examining the ca_wake state and prevents suspend if modem communication - * is on-going. - * If ca_wake = 1 (high), modem comm. is on-going; don't suspend - * If ca_wake = 0 (low), no comm. with modem on-going.Allow suspend - */ -int u8500_shrm_suspend(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct shrm_dev *shrm = platform_get_drvdata(pdev); - - dev_dbg(shrm->dev, "%s called...\n", __func__); - dev_dbg(shrm->dev, "\n ca_wake_req_state = %x\n", - get_ca_wake_req_state()); - /* if ca_wake_req is high, prevent system suspend */ - if (get_ca_wake_req_state()) - return -EBUSY; - else - return 0; -} - -/** - * u8500_shrm_resume() - This routine resumes the SHRM from sustend state. - * @pdev: platform device. - * - * This routine restore back the current state of the SHRM - */ -int u8500_shrm_resume(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct shrm_dev *shrm = platform_get_drvdata(pdev); - - dev_dbg(shrm->dev, "%s called...\n", __func__); - /* TODO: - * As of now, no state save takes place in suspend. - * So, nothing to restore in resume. - * Simply return as of now. - * State saved in suspend should be restored here. - */ - - return 0; -} - -static const struct dev_pm_ops shrm_dev_pm_ops = { - .suspend = u8500_shrm_suspend, - .resume = u8500_shrm_resume, -}; -#endif - -static struct platform_driver shrm_driver = { - .remove = __exit_p(shrm_remove), - .driver = { - .name = "u8500_shrm", - .owner = THIS_MODULE, -#ifdef CONFIG_PM - .pm = &shrm_dev_pm_ops, -#endif - }, -}; - -static int __init shrm_driver_init(void) -{ - return platform_driver_probe(&shrm_driver, shrm_probe); -} - -static void __exit shrm_driver_exit(void) -{ - platform_driver_unregister(&shrm_driver); -} - -module_init(shrm_driver_init); -module_exit(shrm_driver_exit); - -MODULE_AUTHOR("Biju Das"); -MODULE_DESCRIPTION("Shared Memory Modem Driver Interface"); -MODULE_LICENSE("GPL"); diff --git a/drivers/misc/shrm/shrm_fifo.c b/drivers/misc/shrm/shrm_fifo.c deleted file mode 100644 index cbe0949a56d..00000000000 --- a/drivers/misc/shrm/shrm_fifo.c +++ /dev/null @@ -1,827 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghavi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#include -#include -#include -#include - -#define L1_BOOT_INFO_REQ 1 -#define L1_BOOT_INFO_RESP 2 -#define L1_NORMAL_MSG 3 -#define L1_HEADER_MASK 28 -#define L1_MAPID_MASK 0xF0000000 -#define CONFIG_OFFSET 8 -#define COUNTER_OFFSET 20 -#define L2_HEADER_SIZE 4 -#define L2_HEADER_OFFSET 24 -#define MASK_0_15_BIT 0xFF -#define MASK_16_31_BIT 0xFF00 -#define MASK_16_27_BIT 0xFFF0000 -#define MASK_0_39_BIT 0xFFFFF -#define MASK_40_55_BIT 0xFF00000 -#define MASK_8_16_BIT 0x0000FF00 -#define MSG_LEN_OFFSET 16 -#define SHRM_VER 2 -#define ca_ist_inactivity_timer 100 /*100ms */ -#define ca_csc_inactivity_timer 100 /*100ms */ - -static u8 msg_audio_counter; -static u8 msg_common_counter; - -struct fifo_write_params ape_shm_fifo_0; -struct fifo_write_params ape_shm_fifo_1; -struct fifo_read_params cmt_shm_fifo_0; -struct fifo_read_params cmt_shm_fifo_1; - - -static u8 cmt_read_notif_0_send; -static u8 cmt_read_notif_1_send; - -void shm_fifo_init(struct shrm_dev *shrm) -{ - ape_shm_fifo_0.writer_local_wptr = 0; - ape_shm_fifo_0.writer_local_rptr = 0; - *((u32 *)shrm->ac_common_shared_wptr) = 0; - *((u32 *)shrm->ac_common_shared_rptr) = 0; - ape_shm_fifo_0.shared_wptr = 0; - ape_shm_fifo_0.shared_rptr = 0; - ape_shm_fifo_0.availablesize = shrm->ape_common_fifo_size; - ape_shm_fifo_0.end_addr_fifo = shrm->ape_common_fifo_size; - ape_shm_fifo_0.fifo_virtual_addr = shrm->ape_common_fifo_base; - spin_lock_init(&ape_shm_fifo_0.fifo_update_lock); - - - cmt_shm_fifo_0.reader_local_rptr = 0; - cmt_shm_fifo_0.reader_local_wptr = 0; - cmt_shm_fifo_0.shared_wptr = - *((u32 *)shrm->ca_common_shared_wptr); - cmt_shm_fifo_0.shared_rptr = - *((u32 *)shrm->ca_common_shared_rptr); - cmt_shm_fifo_0.availablesize = shrm->cmt_common_fifo_size; - cmt_shm_fifo_0.end_addr_fifo = shrm->cmt_common_fifo_size; - cmt_shm_fifo_0.fifo_virtual_addr = shrm->cmt_common_fifo_base; - - ape_shm_fifo_1.writer_local_wptr = 0; - ape_shm_fifo_1.writer_local_rptr = 0; - ape_shm_fifo_1.shared_wptr = 0; - ape_shm_fifo_1.shared_rptr = 0; - *((u32 *)shrm->ac_audio_shared_wptr) = 0; - *((u32 *)shrm->ac_audio_shared_rptr) = 0; - ape_shm_fifo_1.availablesize = shrm->ape_audio_fifo_size; - ape_shm_fifo_1.end_addr_fifo = shrm->ape_audio_fifo_size; - ape_shm_fifo_1.fifo_virtual_addr = shrm->ape_audio_fifo_base; - spin_lock_init(&ape_shm_fifo_1.fifo_update_lock); - - cmt_shm_fifo_1.reader_local_rptr = 0; - cmt_shm_fifo_1.reader_local_wptr = 0; - cmt_shm_fifo_1.shared_wptr = - *((u32 *)shrm->ca_audio_shared_wptr); - cmt_shm_fifo_1.shared_rptr = - *((u32 *)shrm->ca_audio_shared_rptr); - cmt_shm_fifo_1.availablesize = shrm->cmt_audio_fifo_size; - cmt_shm_fifo_1.end_addr_fifo = shrm->cmt_audio_fifo_size; - cmt_shm_fifo_1.fifo_virtual_addr = shrm->cmt_audio_fifo_base; - msg_audio_counter = 0; - msg_common_counter = 0; -} - -u8 read_boot_info_req(struct shrm_dev *shrm, - u32 *config, - u32 *version) -{ - struct fifo_read_params *fifo = &cmt_shm_fifo_0; - u32 *msg; - u32 header = 0; - u8 msgtype; - - /* Read L1 header read content of reader_local_rptr */ - msg = (u32 *) - (fifo->reader_local_rptr + fifo->fifo_virtual_addr); - header = *msg; - msgtype = (header & L1_MAPID_MASK) >> L1_MSG_MAPID_OFFSET; - if (msgtype != L1_BOOT_INFO_REQ) { - dev_err(shrm->dev, "Read_Boot_Info_Req Fatal ERROR\n"); - BUG(); - } - *config = (header >> CONFIG_OFFSET) & MASK_0_15_BIT; - *version = header & MASK_0_15_BIT; - fifo->reader_local_rptr += 1; - - return 1; -} - -void write_boot_info_resp(struct shrm_dev *shrm, u32 config, - u32 version) -{ - struct fifo_write_params *fifo = &ape_shm_fifo_0; - u32 *msg; - u8 msg_length; - version = SHRM_VER; - - spin_lock_bh(&fifo->fifo_update_lock); - /* Read L1 header read content of reader_local_rptr */ - msg = (u32 *) - (fifo->writer_local_wptr+fifo->fifo_virtual_addr); - if (version < 1) { - *msg = ((L1_BOOT_INFO_RESP << L1_MSG_MAPID_OFFSET) | - ((config << CONFIG_OFFSET) & MASK_16_31_BIT) - | (version & MASK_0_15_BIT)); - msg_length = 1; - } else { - *msg = ((L1_BOOT_INFO_RESP << L1_MSG_MAPID_OFFSET) | - ((0x8 << MSG_LEN_OFFSET) & MASK_16_27_BIT) | - ((config << CONFIG_OFFSET) & MASK_8_16_BIT)| - version); - msg++; - *msg = ca_ist_inactivity_timer; - msg++; - *msg = ca_csc_inactivity_timer; - msg_length = L1_NORMAL_MSG; - } - fifo->writer_local_wptr += msg_length; - fifo->availablesize -= msg_length; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -/** - * shm_write_msg_to_fifo() - write message to FIFO - * @shrm: pointer to shrm device information structure - * @channel: audio or common channel - * @l2header: L2 header or device ID - * @addr: pointer to write buffer address - * @length: length of mst to write - * - * Function Which Writes the data into Fifo in IPC zone - * It is called from shm_write_msg. This function will copy the msg - * from the kernel buffer to FIFO. There are 4 kernel buffers from where - * the data is to copied to FIFO one for each of the messages ISI, RPC, - * AUDIO and SECURITY. ISI, RPC and SECURITY messages are pushed to FIFO - * in commmon channel and AUDIO message is pushed onto audio channel FIFO. - */ -int shm_write_msg_to_fifo(struct shrm_dev *shrm, u8 channel, - u8 l2header, void *addr, u32 length) -{ - struct fifo_write_params *fifo = NULL; - u32 l1_header = 0, l2_header = 0; - u32 requiredsize; - u32 size = 0; - u32 *msg; - u8 *src; - - if (channel == COMMON_CHANNEL) - fifo = &ape_shm_fifo_0; - else if (channel == AUDIO_CHANNEL) - fifo = &ape_shm_fifo_1; - else { - dev_err(shrm->dev, "invalid channel\n"); - return -EINVAL; - } - - /* L2 size in 32b */ - requiredsize = ((length + 3) / 4); - /* Add size of L1 & L2 header */ - requiredsize += 2; - - /* if availablesize = or < requiredsize then error */ - if (fifo->availablesize <= requiredsize) { - /* Fatal ERROR - should never happens */ - dev_dbg(shrm->dev, "wr_wptr= %x\n", - fifo->writer_local_wptr); - dev_dbg(shrm->dev, "wr_rptr= %x\n", - fifo->writer_local_rptr); - dev_dbg(shrm->dev, "shared_wptr= %x\n", - fifo->shared_wptr); - dev_dbg(shrm->dev, "shared_rptr= %x\n", - fifo->shared_rptr); - dev_dbg(shrm->dev, "availsize= %x\n", - fifo->availablesize); - dev_dbg(shrm->dev, "end__fifo= %x\n", - fifo->end_addr_fifo); - dev_warn(shrm->dev, "Modem is busy, please wait." - " c_cnt = %d; a_cnt = %d\n", msg_common_counter, - msg_audio_counter); - if (channel == COMMON_CHANNEL) { - dev_warn(shrm->dev, - "Modem is lagging behind in reading." - "Stopping n/w dev queue\n"); - shrm_stop_netdev(shrm->ndev); - } - - return -EAGAIN; - } - - if (channel == COMMON_CHANNEL) { - /* build L1 header */ - l1_header = ((L1_NORMAL_MSG << L1_MSG_MAPID_OFFSET) | - (((msg_common_counter++) << COUNTER_OFFSET) - & MASK_40_55_BIT) | - ((length + L2_HEADER_SIZE) & MASK_0_39_BIT)); - } else if (channel == AUDIO_CHANNEL) { - /* build L1 header */ - l1_header = ((L1_NORMAL_MSG << L1_MSG_MAPID_OFFSET) | - (((msg_audio_counter++) << COUNTER_OFFSET) - & MASK_40_55_BIT) | - ((length + L2_HEADER_SIZE) & MASK_0_39_BIT)); - } - - /* - * Need to take care race condition for fifo->availablesize - * & fifo->writer_local_rptr with Ac_Read_notification interrupt. - * One option could be use stack variable for LocalRptr and recompute - * fifo->availablesize,based on flag enabled in the - * Ac_read_notification - */ - l2_header = ((l2header << L2_HEADER_OFFSET) | - ((length) & MASK_0_39_BIT)); - spin_lock_bh(&fifo->fifo_update_lock); - /* Check Local Rptr is less than or equal to Local WPtr */ - if (fifo->writer_local_rptr <= fifo->writer_local_wptr) { - msg = (u32 *) - (fifo->fifo_virtual_addr+fifo->writer_local_wptr); - - /* check enough place bewteen writer_local_wptr & end of FIFO */ - if ((fifo->end_addr_fifo-fifo->writer_local_wptr) >= - requiredsize) { - /* Add L1 header and L2 header */ - *msg = l1_header; - msg++; - *msg = l2_header; - msg++; - - /* copy the l2 message in 1 memcpy */ - memcpy((void *)msg, addr, length); - /* UpdateWptr */ - fifo->writer_local_wptr += requiredsize; - fifo->availablesize -= requiredsize; - fifo->writer_local_wptr %= fifo->end_addr_fifo; - } else { - /* - * message is split between and of FIFO and beg of FIFO - * copy first part from writer_local_wptr to end of FIFO - */ - size = fifo->end_addr_fifo-fifo->writer_local_wptr; - - if (size == 1) { - /* Add L1 header */ - *msg = l1_header; - msg++; - /* UpdateWptr */ - fifo->writer_local_wptr = 0; - fifo->availablesize -= size; - /* - * copy second part from beg of FIFO - * with remaining part of msg - */ - msg = (u32 *) - fifo->fifo_virtual_addr; - *msg = l2_header; - msg++; - - /* copy the l3 message in 1 memcpy */ - memcpy((void *)msg, addr, length); - /* UpdateWptr */ - fifo->writer_local_wptr += - requiredsize-size; - fifo->availablesize -= - (requiredsize-size); - } else if (size == 2) { - /* Add L1 header and L2 header */ - *msg = l1_header; - msg++; - *msg = l2_header; - msg++; - - /* UpdateWptr */ - fifo->writer_local_wptr = 0; - fifo->availablesize -= size; - - /* - * copy second part from beg of FIFO - * with remaining part of msg - */ - msg = (u32 *) - fifo->fifo_virtual_addr; - /* copy the l3 message in 1 memcpy */ - memcpy((void *)msg, addr, length); - - /* UpdateWptr */ - fifo->writer_local_wptr += - requiredsize-size; - fifo->availablesize -= - (requiredsize-size); - } else { - /* Add L1 header and L2 header */ - *msg = l1_header; - msg++; - *msg = l2_header; - msg++; - - /* copy the l2 message in 1 memcpy */ - memcpy((void *)msg, addr, (size-2)*4); - - - /* UpdateWptr */ - fifo->writer_local_wptr = 0; - fifo->availablesize -= size; - - /* - * copy second part from beg of FIFO - * with remaining part of msg - */ - msg = (u32 *)fifo->fifo_virtual_addr; - src = (u8 *)addr+((size - 2) * 4); - memcpy((void *)msg, src, - (length-((size - 2) * 4))); - - /* UpdateWptr */ - fifo->writer_local_wptr += - requiredsize-size; - fifo->availablesize -= - (requiredsize-size); - } - - } - } else { - /* writer_local_rptr > writer_local_wptr */ - msg = (u32 *) - (fifo->fifo_virtual_addr+fifo->writer_local_wptr); - /* Add L1 header and L2 header */ - *msg = l1_header; - msg++; - *msg = l2_header; - msg++; - /* - * copy message possbile between writer_local_wptr up - * to writer_local_rptr copy the l3 message in 1 memcpy - */ - memcpy((void *)msg, addr, length); - - /* UpdateWptr */ - fifo->writer_local_wptr += requiredsize; - fifo->availablesize -= requiredsize; - - } - spin_unlock_bh(&fifo->fifo_update_lock); - return length; -} - -/** - * read_one_l2msg_common() - read message from common channel - * @shrm: pointer to shrm device information structure - * @l2_msg: pointer to the read L2 message buffer - * @len: message length - * - * This function read one message from the FIFO and returns l2 header type - */ -u8 read_one_l2msg_common(struct shrm_dev *shrm, - u8 *l2_msg, u32 *len) -{ - struct fifo_read_params *fifo = &cmt_shm_fifo_0; - - u32 *msg; - u32 l1_header = 0; - u32 l2_header = 0; - u32 length; - u8 msgtype; - u32 msg_size; - u32 size = 0; - - /* Read L1 header read content of reader_local_rptr */ - msg = (u32 *) - (fifo->reader_local_rptr+fifo->fifo_virtual_addr); - l1_header = *msg++; - msgtype = (l1_header & 0xF0000000) >> L1_HEADER_MASK; - - if (msgtype != L1_NORMAL_MSG) { - /* Fatal ERROR - should never happens */ - dev_dbg(shrm->dev, "wr_wptr= %x\n", - fifo->reader_local_wptr); - dev_dbg(shrm->dev, "wr_rptr= %x\n", - fifo->reader_local_rptr); - dev_dbg(shrm->dev, "shared_wptr= %x\n", - fifo->shared_wptr); - dev_dbg(shrm->dev, "shared_rptr= %x\n", - fifo->shared_rptr); - dev_dbg(shrm->dev, "availsize= %x\n", - fifo->availablesize); - dev_dbg(shrm->dev, "end_fifo= %x\n", - fifo->end_addr_fifo); - /* Fatal ERROR - should never happens */ - dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); - BUG(); - } - if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { - l2_header = (*((u32 *)fifo->fifo_virtual_addr)); - length = l2_header & MASK_0_39_BIT; - } else { - /* Read L2 header,Msg size & content of reader_local_rptr */ - l2_header = *msg; - length = l2_header & MASK_0_39_BIT; - } - - *len = length; - msg_size = ((length + 3) / 4); - msg_size += 2; - - if (fifo->reader_local_rptr + msg_size <= - fifo->end_addr_fifo) { - /* Skip L2 header */ - msg++; - - /* read msg between reader_local_rptr and end of FIFO */ - memcpy((void *)l2_msg, (void *)msg, length); - /* UpdateLocalRptr */ - fifo->reader_local_rptr += msg_size; - fifo->reader_local_rptr %= fifo->end_addr_fifo; - } else { - /* - * msg split between end of FIFO and beg copy first - * part of msg read msg between reader_local_rptr - * and end of FIFO - */ - size = fifo->end_addr_fifo-fifo->reader_local_rptr; - if (size == 1) { - msg = (u32 *)(fifo->fifo_virtual_addr); - /* Skip L2 header */ - msg++; - memcpy((void *)l2_msg, (void *)(msg), length); - } else if (size == 2) { - /* Skip L2 header */ - msg++; - msg = (u32 *)(fifo->fifo_virtual_addr); - memcpy((void *)l2_msg, - (void *)(msg), length); - } else { - /* Skip L2 header */ - msg++; - memcpy((void *)l2_msg, (void *)msg, ((size - 2) * 4)); - /* copy second part of msg */ - l2_msg += ((size - 2) * 4); - msg = (u32 *)(fifo->fifo_virtual_addr); - memcpy((void *)l2_msg, (void *)(msg), - (length-((size - 2) * 4))); - } - fifo->reader_local_rptr = - (fifo->reader_local_rptr+msg_size) % - fifo->end_addr_fifo; - } - return (l2_header>>L2_HEADER_OFFSET) & MASK_0_15_BIT; - } - -u8 read_remaining_messages_common() -{ - struct fifo_read_params *fifo = &cmt_shm_fifo_0; - /* - * There won't be any Race condition reader_local_rptr & - * fifo->reader_local_wptr with CaMsgpending Notification Interrupt - */ - return ((fifo->reader_local_rptr != fifo->reader_local_wptr) ? 1 : 0); -} - -u8 read_one_l2msg_audio(struct shrm_dev *shrm, - u8 *l2_msg, u32 *len) -{ - struct fifo_read_params *fifo = &cmt_shm_fifo_1; - - u32 *msg; - u32 l1_header = 0; - u32 l2_header = 0; - u32 length; - u8 msgtype; - u32 msg_size; - u32 size = 0; - - /* Read L1 header read content of reader_local_rptr */ - msg = (u32 *) - (fifo->reader_local_rptr+fifo->fifo_virtual_addr); - l1_header = *msg++; - msgtype = (l1_header & 0xF0000000) >> L1_HEADER_MASK; - - if (msgtype != L1_NORMAL_MSG) { - /* Fatal ERROR - should never happens */ - dev_dbg(shrm->dev, "wr_local_wptr= %x\n", - fifo->reader_local_wptr); - dev_dbg(shrm->dev, "wr_local_rptr= %x\n", - fifo->reader_local_rptr); - dev_dbg(shrm->dev, "shared_wptr= %x\n", - fifo->shared_wptr); - dev_dbg(shrm->dev, "shared_rptr= %x\n", - fifo->shared_rptr); - dev_dbg(shrm->dev, "availsize=%x\n", - fifo->availablesize); - dev_dbg(shrm->dev, "end_fifo= %x\n", - fifo->end_addr_fifo); - /* Fatal ERROR - should never happens */ - dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); - BUG(); - } - if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { - l2_header = (*((u32 *)fifo->fifo_virtual_addr)); - length = l2_header & MASK_0_39_BIT; - } else { - /* Read L2 header,Msg size & content of reader_local_rptr */ - l2_header = *msg; - length = l2_header & MASK_0_39_BIT; - } - - *len = length; - msg_size = ((length + 3) / 4); - msg_size += 2; - - if (fifo->reader_local_rptr + msg_size <= - fifo->end_addr_fifo) { - /* Skip L2 header */ - msg++; - /* read msg between reader_local_rptr and end of FIFO */ - memcpy((void *)l2_msg, (void *)msg, length); - /* UpdateLocalRptr */ - fifo->reader_local_rptr += msg_size; - fifo->reader_local_rptr %= fifo->end_addr_fifo; - } else { - - /* - * msg split between end of FIFO and beg - * copy first part of msg - * read msg between reader_local_rptr and end of FIFO - */ - size = fifo->end_addr_fifo-fifo->reader_local_rptr; - if (size == 1) { - msg = (u32 *)(fifo->fifo_virtual_addr); - /* Skip L2 header */ - msg++; - memcpy((void *)l2_msg, (void *)(msg), length); - } else if (size == 2) { - /* Skip L2 header */ - msg++; - msg = (u32 *)(fifo->fifo_virtual_addr); - memcpy((void *)l2_msg, (void *)(msg), length); - } else { - /* Skip L2 header */ - msg++; - memcpy((void *)l2_msg, (void *)msg, ((size - 2) * 4)); - /* copy second part of msg */ - l2_msg += ((size - 2) * 4); - msg = (u32 *)(fifo->fifo_virtual_addr); - memcpy((void *)l2_msg, (void *)(msg), - (length-((size - 2) * 4))); - } - fifo->reader_local_rptr = - (fifo->reader_local_rptr+msg_size) % - fifo->end_addr_fifo; - - } - return (l2_header>>L2_HEADER_OFFSET) & MASK_0_15_BIT; - } - -u8 read_remaining_messages_audio() -{ - struct fifo_read_params *fifo = &cmt_shm_fifo_1; - - return ((fifo->reader_local_rptr != fifo->reader_local_wptr) ? - 1 : 0); -} - -u8 is_the_only_one_unread_message(struct shrm_dev *shrm, - u8 channel, u32 length) -{ - struct fifo_write_params *fifo = NULL; - u32 messagesize = 0; - u8 is_only_one_unread_msg = 0; - - if (channel == COMMON_CHANNEL) - fifo = &ape_shm_fifo_0; - else /* channel = AUDIO_CHANNEL */ - fifo = &ape_shm_fifo_1; - - /* L3 size in 32b */ - messagesize = ((length + 3) / 4); - /* Add size of L1 & L2 header */ - messagesize += 2; - /* - * possibility of race condition with Ac Read notification interrupt. - * need to check ? - */ - if (fifo->writer_local_wptr > fifo->writer_local_rptr) - is_only_one_unread_msg = - ((fifo->writer_local_rptr + messagesize) == - fifo->writer_local_wptr) ? 1 : 0; - else - /* Msg split between end of fifo and starting of Fifo */ - is_only_one_unread_msg = - (((fifo->writer_local_rptr + messagesize) % - fifo->end_addr_fifo) == fifo->writer_local_wptr) ? - 1 : 0; - - return is_only_one_unread_msg; -} - -void update_ca_common_local_wptr(struct shrm_dev *shrm) -{ - /* - * update CA common reader local write pointer with the - * shared write pointer - */ - struct fifo_read_params *fifo = &cmt_shm_fifo_0; - - fifo->shared_wptr = - (*((u32 *)shrm->ca_common_shared_wptr)); - fifo->reader_local_wptr = fifo->shared_wptr; -} - -void update_ca_audio_local_wptr(struct shrm_dev *shrm) -{ - /* - * update CA audio reader local write pointer with the - * shared write pointer - */ - struct fifo_read_params *fifo = &cmt_shm_fifo_1; - - fifo->shared_wptr = - (*((u32 *)shrm->ca_audio_shared_wptr)); - fifo->reader_local_wptr = fifo->shared_wptr; -} - -void update_ac_common_local_rptr(struct shrm_dev *shrm) -{ - /* - * update AC common writer local read pointer with the - * shared read pointer - */ - struct fifo_write_params *fifo; - u32 free_space = 0; - - fifo = &ape_shm_fifo_0; - - spin_lock_bh(&fifo->fifo_update_lock); - fifo->shared_rptr = - (*((u32 *)shrm->ac_common_shared_rptr)); - - if (fifo->shared_rptr >= fifo->writer_local_rptr) - free_space = - (fifo->shared_rptr-fifo->writer_local_rptr); - else { - free_space = - (fifo->end_addr_fifo-fifo->writer_local_rptr); - free_space += fifo->shared_rptr; - } - - /* Chance of race condition of below variables with write_msg */ - fifo->availablesize += free_space; - fifo->writer_local_rptr = fifo->shared_rptr; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -void update_ac_audio_local_rptr(struct shrm_dev *shrm) -{ - /* - * update AC audio writer local read pointer with the - * shared read pointer - */ - struct fifo_write_params *fifo; - u32 free_space = 0; - - fifo = &ape_shm_fifo_1; - spin_lock_bh(&fifo->fifo_update_lock); - fifo->shared_rptr = - (*((u32 *)shrm->ac_audio_shared_rptr)); - - if (fifo->shared_rptr >= fifo->writer_local_rptr) - free_space = - (fifo->shared_rptr-fifo->writer_local_rptr); - else { - free_space = - (fifo->end_addr_fifo-fifo->writer_local_rptr); - free_space += fifo->shared_rptr; - } - - /* Chance of race condition of below variables with write_msg */ - fifo->availablesize += free_space; - fifo->writer_local_rptr = fifo->shared_rptr; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -void update_ac_common_shared_wptr(struct shrm_dev *shrm) -{ - /* - * update AC common shared write pointer with the - * local write pointer - */ - struct fifo_write_params *fifo; - - fifo = &ape_shm_fifo_0; - spin_lock_bh(&fifo->fifo_update_lock); - /* Update shared pointer fifo offset of the IPC zone */ - (*((u32 *)shrm->ac_common_shared_wptr)) = - fifo->writer_local_wptr; - - fifo->shared_wptr = fifo->writer_local_wptr; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -void update_ac_audio_shared_wptr(struct shrm_dev *shrm) -{ - /* - * update AC audio shared write pointer with the - * local write pointer - */ - struct fifo_write_params *fifo; - - fifo = &ape_shm_fifo_1; - spin_lock_bh(&fifo->fifo_update_lock); - /* Update shared pointer fifo offset of the IPC zone */ - (*((u32 *)shrm->ac_audio_shared_wptr)) = - fifo->writer_local_wptr; - fifo->shared_wptr = fifo->writer_local_wptr; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -void update_ca_common_shared_rptr(struct shrm_dev *shrm) -{ - /* - * update CA common shared read pointer with the - * local read pointer - */ - struct fifo_read_params *fifo; - - fifo = &cmt_shm_fifo_0; - - /* Update shared pointer fifo offset of the IPC zone */ - (*((u32 *)shrm->ca_common_shared_rptr)) = - fifo->reader_local_rptr; - fifo->shared_rptr = fifo->reader_local_rptr; -} - -void update_ca_audio_shared_rptr(struct shrm_dev *shrm) -{ - /* - * update CA audio shared read pointer with the - * local read pointer - */ - struct fifo_read_params *fifo; - - fifo = &cmt_shm_fifo_1; - - /* Update shared pointer fifo offset of the IPC zone */ - (*((u32 *)shrm->ca_audio_shared_rptr)) = - fifo->reader_local_rptr; - fifo->shared_rptr = fifo->reader_local_rptr; -} - -void get_reader_pointers(u8 channel_type, u32 *reader_local_rptr, - u32 *reader_local_wptr, u32 *shared_rptr) -{ - struct fifo_read_params *fifo = NULL; - - if (channel_type == COMMON_CHANNEL) - fifo = &cmt_shm_fifo_0; - else /* channel_type = AUDIO_CHANNEL */ - fifo = &cmt_shm_fifo_1; - - *reader_local_rptr = fifo->reader_local_rptr; - *reader_local_wptr = fifo->reader_local_wptr; - *shared_rptr = fifo->shared_rptr; -} - -void get_writer_pointers(u8 channel_type, u32 *writer_local_rptr, - u32 *writer_local_wptr, u32 *shared_wptr) -{ - struct fifo_write_params *fifo = NULL; - - if (channel_type == COMMON_CHANNEL) - fifo = &ape_shm_fifo_0; - else /* channel_type = AUDIO_CHANNEL */ - fifo = &ape_shm_fifo_1; - - spin_lock_bh(&fifo->fifo_update_lock); - *writer_local_rptr = fifo->writer_local_rptr; - *writer_local_wptr = fifo->writer_local_wptr; - *shared_wptr = fifo->shared_wptr; - spin_unlock_bh(&fifo->fifo_update_lock); -} - -void set_ca_msg_0_read_notif_send(u8 val) -{ - cmt_read_notif_0_send = val; -} - -u8 get_ca_msg_0_read_notif_send(void) -{ - return cmt_read_notif_0_send; -} - -void set_ca_msg_1_read_notif_send(u8 val) -{ - cmt_read_notif_1_send = val; -} - -u8 get_ca_msg_1_read_notif_send(void) -{ - return cmt_read_notif_1_send; -} diff --git a/drivers/misc/shrm/shrm_protocol.c b/drivers/misc/shrm/shrm_protocol.c deleted file mode 100644 index 686bebcb451..00000000000 --- a/drivers/misc/shrm/shrm_protocol.c +++ /dev/null @@ -1,1191 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2010 - * - * Author: Biju Das for ST-Ericsson - * Author: Kumar Sanghvi for ST-Ericsson - * Author: Arun Murthy for ST-Ericsson - * License terms: GNU General Public License (GPL) version 2 - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define L2_HEADER_ISI 0x0 -#define L2_HEADER_RPC 0x1 -#define L2_HEADER_AUDIO 0x2 -#define L2_HEADER_SECURITY 0x3 -#define L2_HEADER_COMMON_SIMPLE_LOOPBACK 0xC0 -#define L2_HEADER_COMMON_ADVANCED_LOOPBACK 0xC1 -#define L2_HEADER_AUDIO_SIMPLE_LOOPBACK 0x80 -#define L2_HEADER_AUDIO_ADVANCED_LOOPBACK 0x81 -#define MAX_PAYLOAD 1024 - -static u8 boot_state = BOOT_INIT; -static u8 recieve_common_msg[8*1024]; -static u8 recieve_audio_msg[8*1024]; -static received_msg_handler rx_common_handler; -static received_msg_handler rx_audio_handler; -static struct hrtimer timer; -struct sock *shrm_nl_sk; - -static char shrm_common_tx_state = SHRM_SLEEP_STATE; -static char shrm_common_rx_state = SHRM_SLEEP_STATE; -static char shrm_audio_tx_state = SHRM_SLEEP_STATE; -static char shrm_audio_rx_state = SHRM_SLEEP_STATE; - -static atomic_t ac_sleep_disable_count = ATOMIC_INIT(0); -static struct shrm_dev *shm_dev; - -/* Spin lock and tasklet declaration */ -DECLARE_TASKLET(shm_ca_0_tasklet, shm_ca_msgpending_0_tasklet, 0); -DECLARE_TASKLET(shm_ca_1_tasklet, shm_ca_msgpending_1_tasklet, 0); -DECLARE_TASKLET(shm_ac_read_0_tasklet, shm_ac_read_notif_0_tasklet, 0); -DECLARE_TASKLET(shm_ac_read_1_tasklet, shm_ac_read_notif_1_tasklet, 0); - -static DEFINE_MUTEX(ac_state_mutex); - -static DEFINE_SPINLOCK(ca_common_lock); -static DEFINE_SPINLOCK(ca_audio_lock); -static DEFINE_SPINLOCK(ca_wake_req_lock); -static DEFINE_SPINLOCK(boot_lock); - -enum shrm_nl { - SHRM_NL_MOD_RESET = 1, - SHRM_NL_MOD_QUERY_STATE, - SHRM_NL_USER_MOD_RESET, - SHRM_NL_STATUS_MOD_ONLINE, - SHRM_NL_STATUS_MOD_OFFLINE, -}; - -static void shm_ac_sleep_req_work(struct work_struct *work) -{ - mutex_lock(&ac_state_mutex); - if (atomic_read(&ac_sleep_disable_count) == 0) - modem_release(shm_dev->modem); - mutex_unlock(&ac_state_mutex); -} - -static void shm_ac_wake_req_work(struct work_struct *work) -{ - mutex_lock(&ac_state_mutex); - modem_request(shm_dev->modem); - mutex_unlock(&ac_state_mutex); -} - -static u32 get_host_accessport_val(void) -{ - u32 prcm_hostaccess; - - prcm_hostaccess = readl(PRCM_HOSTACCESS_REQ); - wmb(); - prcm_hostaccess = prcm_hostaccess & 0x01; - - return prcm_hostaccess; -} -static enum hrtimer_restart callback(struct hrtimer *timer) -{ - unsigned long flags; - - spin_lock_irqsave(&ca_wake_req_lock, flags); - if (((shrm_common_rx_state == SHRM_IDLE) || - (shrm_common_rx_state == SHRM_SLEEP_STATE)) - && ((shrm_common_tx_state == SHRM_IDLE) || - (shrm_common_tx_state == SHRM_SLEEP_STATE)) - && ((shrm_audio_rx_state == SHRM_IDLE) || - (shrm_audio_rx_state == SHRM_SLEEP_STATE)) - && ((shrm_audio_tx_state == SHRM_IDLE) || - (shrm_audio_tx_state == SHRM_SLEEP_STATE))) { - - shrm_common_rx_state = SHRM_SLEEP_STATE; - shrm_audio_rx_state = SHRM_SLEEP_STATE; - shrm_common_tx_state = SHRM_SLEEP_STATE; - shrm_audio_tx_state = SHRM_SLEEP_STATE; - - queue_work(shm_dev->shm_ac_sleep_wq, - &shm_dev->shm_ac_sleep_req); - - } - spin_unlock_irqrestore(&ca_wake_req_lock, flags); - - return HRTIMER_NORESTART; -} - -int nl_send_multicast_message(int msg, gfp_t gfp_mask) -{ - struct sk_buff *skb = NULL; - struct nlmsghdr *nlh = NULL; - int err; - - /* prepare netlink message */ - skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), gfp_mask); - if (!skb) { - dev_err(shm_dev->dev, "%s:alloc_skb failed\n", __func__); - err = -ENOMEM; - goto out; - } - - nlh = (struct nlmsghdr *)skb->data; - nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); - dev_dbg(shm_dev->dev, "nlh->nlmsg_len = %d\n", nlh->nlmsg_len); - - nlh->nlmsg_pid = 0; /* from kernel */ - nlh->nlmsg_flags = 0; - *(int *)NLMSG_DATA(nlh) = msg; - skb_put(skb, MAX_PAYLOAD); - /* sender is in group 1<<0 */ - NETLINK_CB(skb).pid = 0; /* from kernel */ - /* to mcast group 1<<0 */ - NETLINK_CB(skb).dst_group = 1; - - /*multicast the message to all listening processes*/ - err = netlink_broadcast(shrm_nl_sk, skb, 0, 1, gfp_mask); - dev_dbg(shm_dev->dev, "ret val from nl-multicast = %d\n", err); - -out: - return err; -} - -static void nl_send_unicast_message(int dst_pid) -{ - struct sk_buff *skb = NULL; - struct nlmsghdr *nlh = NULL; - int err; - int bt_state; - unsigned long flags; - - dev_info(shm_dev->dev, "Sending unicast message\n"); - - /* prepare the NL message for unicast */ - skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), GFP_KERNEL); - if (!skb) { - dev_err(shm_dev->dev, "%s:alloc_skb failed\n", __func__); - return; - } - - nlh = (struct nlmsghdr *)skb->data; - nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); - dev_dbg(shm_dev->dev, "nlh->nlmsg_len = %d\n", nlh->nlmsg_len); - - nlh->nlmsg_pid = 0; /* from kernel */ - nlh->nlmsg_flags = 0; - - spin_lock_irqsave(&boot_lock, flags); - bt_state = boot_state; - spin_unlock_irqrestore(&boot_lock, flags); - - if (bt_state == BOOT_DONE) - *(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_ONLINE; - else - *(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_OFFLINE; - - skb_put(skb, MAX_PAYLOAD); - /* sender is in group 1<<0 */ - NETLINK_CB(skb).pid = 0; /* from kernel */ - NETLINK_CB(skb).dst_group = 0; - - /*unicast the message to the querying processes*/ - err = netlink_unicast(shrm_nl_sk, skb, dst_pid, MSG_DONTWAIT); - dev_dbg(shm_dev->dev, "ret val from nl-unicast = %d\n", err); -} - - -static int check_modem_in_reset(void) -{ - u8 bt_state; - unsigned long flags; - - spin_lock_irqsave(&boot_lock, flags); - bt_state = boot_state; - spin_unlock_irqrestore(&boot_lock, flags); - -#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET - if (bt_state != BOOT_UNKNOWN) - return 0; - else - return -ENODEV; -#else - /* - * this check won't be applicable and won't work correctly - * if modem-silent-feature is not enabled - * so, simply return 0 - */ - return 0; -#endif -} - -void shm_ca_msgpending_0_tasklet(unsigned long tasklet_data) -{ - struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; - u32 reader_local_rptr; - u32 reader_local_wptr; - u32 shared_rptr; - u32 config = 0, version = 0; - unsigned long flags; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - /* Interprocess locking */ - spin_lock(&ca_common_lock); - - /* Update_reader_local_wptr with shared_wptr */ - update_ca_common_local_wptr(shrm); - get_reader_pointers(COMMON_CHANNEL, &reader_local_rptr, - &reader_local_wptr, &shared_rptr); - - set_ca_msg_0_read_notif_send(0); - - if (boot_state == BOOT_DONE) { - shrm_common_rx_state = SHRM_PTR_FREE; - - if (reader_local_rptr != shared_rptr) - ca_msg_read_notification_0(shrm); - if (reader_local_rptr != reader_local_wptr) - receive_messages_common(shrm); - get_reader_pointers(COMMON_CHANNEL, &reader_local_rptr, - &reader_local_wptr, &shared_rptr); - if (reader_local_rptr == reader_local_wptr) - shrm_common_rx_state = SHRM_IDLE; - } else { - /* BOOT phase.only a BOOT_RESP should be in FIFO */ - if (boot_state != BOOT_INFO_SYNC) { - if (!read_boot_info_req(shrm, &config, &version)) { - dev_err(shrm->dev, - "Unable to read boot state\n"); - BUG(); - } - /* SendReadNotification */ - ca_msg_read_notification_0(shrm); - /* - * Check the version number before - * sending Boot info response - */ - - /* send MsgPending notification */ - write_boot_info_resp(shrm, config, version); - spin_lock_irqsave(&boot_lock, flags); - boot_state = BOOT_INFO_SYNC; - spin_unlock_irqrestore(&boot_lock, flags); - dev_info(shrm->dev, "BOOT_INFO_SYNC\n"); - queue_work(shrm->shm_common_ch_wr_wq, - &shrm->send_ac_msg_pend_notify_0); - } else { - ca_msg_read_notification_0(shrm); - dev_info(shrm->dev, - "BOOT_INFO_SYNC\n"); - } - } - /* Interprocess locking */ - spin_unlock(&ca_common_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void shm_ca_msgpending_1_tasklet(unsigned long tasklet_data) -{ - struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; - u32 reader_local_rptr; - u32 reader_local_wptr; - u32 shared_rptr; - - /* - * This function is called when CaMsgPendingNotification Trigerred - * by CMU. It means that CMU has wrote a message into Ca Audio FIFO - */ - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown\n", - __func__); - return; - } - - /* Interprocess locking */ - spin_lock(&ca_audio_lock); - - /* Update_reader_local_wptr(with shared_wptr) */ - update_ca_audio_local_wptr(shrm); - get_reader_pointers(AUDIO_CHANNEL, &reader_local_rptr, - &reader_local_wptr, &shared_rptr); - - set_ca_msg_1_read_notif_send(0); - - if (boot_state != BOOT_DONE) { - dev_err(shrm->dev, "Boot Error\n"); - return; - } - shrm_audio_rx_state = SHRM_PTR_FREE; - /* Check we already read the message */ - if (reader_local_rptr != shared_rptr) - ca_msg_read_notification_1(shrm); - if (reader_local_rptr != reader_local_wptr) - receive_messages_audio(shrm); - - get_reader_pointers(AUDIO_CHANNEL, &reader_local_rptr, - &reader_local_wptr, &shared_rptr); - if (reader_local_rptr == reader_local_wptr) - shrm_audio_rx_state = SHRM_IDLE; - - /* Interprocess locking */ - spin_unlock(&ca_audio_lock); - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void shm_ac_read_notif_0_tasklet(unsigned long tasklet_data) -{ - struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; - u32 writer_local_rptr; - u32 writer_local_wptr; - u32 shared_wptr; - unsigned long flags; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - /* Update writer_local_rptrwith shared_rptr */ - update_ac_common_local_rptr(shrm); - get_writer_pointers(COMMON_CHANNEL, &writer_local_rptr, - &writer_local_wptr, &shared_wptr); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown\n", - __func__); - return; - } - - if (boot_state == BOOT_INFO_SYNC) { - /* BOOT_RESP sent by APE has been received by CMT */ - spin_lock_irqsave(&boot_lock, flags); - boot_state = BOOT_DONE; - spin_unlock_irqrestore(&boot_lock, flags); - dev_info(shrm->dev, "IPC_ISA BOOT_DONE\n"); - - if (shrm->msr_flag) { - shrm_start_netdev(shrm->ndev); - shrm->msr_flag = 0; - - /* multicast that modem is online */ - nl_send_multicast_message(SHRM_NL_STATUS_MOD_ONLINE, GFP_ATOMIC); - } - - } else if (boot_state == BOOT_DONE) { - if (writer_local_rptr != writer_local_wptr) { - shrm_common_tx_state = SHRM_PTR_FREE; - queue_work(shrm->shm_common_ch_wr_wq, - &shrm->send_ac_msg_pend_notify_0); - } else { - shrm_common_tx_state = SHRM_IDLE; - shrm_restart_netdev(shrm->ndev); - } - } else { - dev_err(shrm->dev, "Invalid boot state\n"); - } - /* start timer here */ - hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), - HRTIMER_MODE_REL); - atomic_dec(&ac_sleep_disable_count); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void shm_ac_read_notif_1_tasklet(unsigned long tasklet_data) -{ - struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; - u32 writer_local_rptr; - u32 writer_local_wptr; - u32 shared_wptr; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown\n", - __func__); - return; - } - - /* Update writer_local_rptr(with shared_rptr) */ - update_ac_audio_local_rptr(shrm); - get_writer_pointers(AUDIO_CHANNEL, &writer_local_rptr, - &writer_local_wptr, &shared_wptr); - if (boot_state != BOOT_DONE) { - dev_err(shrm->dev, "Error Case in boot state\n"); - return; - } - if (writer_local_rptr != writer_local_wptr) { - shrm_audio_tx_state = SHRM_PTR_FREE; - queue_work(shrm->shm_audio_ch_wr_wq, - &shrm->send_ac_msg_pend_notify_1); - } else { - shrm_audio_tx_state = SHRM_IDLE; - } - /* start timer here */ - hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), - HRTIMER_MODE_REL); - atomic_dec(&ac_sleep_disable_count); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void shm_ca_sleep_req_work(struct work_struct *work) -{ - dev_dbg(shm_dev->dev, "%s:IRQ_PRCMU_CA_SLEEP\n", __func__); - - shrm_common_rx_state = SHRM_IDLE; - shrm_audio_rx_state = SHRM_IDLE; - - writel((1<intr_base + GOP_SET_REGISTER_BASE); - - hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), - HRTIMER_MODE_REL); -#ifdef CONFIG_UX500_SUSPEND - suspend_unblock_sleep(); -#endif - atomic_dec(&ac_sleep_disable_count); -} - -void shm_ca_wake_req_work(struct work_struct *work) -{ - struct shrm_dev *shrm = container_of(work, - struct shrm_dev, shm_ca_wake_req); - - /* initialize the FIFO Variables */ - if (boot_state == BOOT_INIT) - shm_fifo_init(shrm); - - mutex_lock(&ac_state_mutex); - modem_request(shrm->modem); - mutex_unlock(&ac_state_mutex); - - /* send ca_wake_ack_interrupt to CMU */ - if (!get_host_accessport_val()) - BUG(); - writel((1<intr_base + GOP_SET_REGISTER_BASE); -} -#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET -static int shrm_modem_reset_sequence(void) -{ - int err; - unsigned long flags; - - /* - * disable irqs - * very much needed for user-space initiated - * modem-reset - */ - disable_irq_nosync(shm_dev->ac_read_notif_0_irq); - disable_irq_nosync(shm_dev->ac_read_notif_1_irq); - disable_irq_nosync(shm_dev->ca_msg_pending_notif_0_irq); - disable_irq_nosync(shm_dev->ca_msg_pending_notif_1_irq); - disable_irq_nosync(IRQ_PRCMU_CA_WAKE); - disable_irq_nosync(IRQ_PRCMU_CA_SLEEP); - - - /* update the boot_state */ - spin_lock_irqsave(&boot_lock, flags); - boot_state = BOOT_UNKNOWN; - - /* - * put a barrier over here to make sure boot_state is updated - * else, it is seen that some of already executing modem - * irqs or tasklets fail the protocol checks and will ultimately - * try to acces the modem causing system to hang. - * This is particularly seen with user-space initiated modem reset - */ - wmb(); - spin_unlock_irqrestore(&boot_lock, flags); - - hrtimer_cancel(&timer); - - /* - * keep the count to 0 so that we can bring down the line - * for normal ac-wake and ac-sleep logic - */ - atomic_set(&ac_sleep_disable_count, 0); - - /* workaround for MSR */ - queue_work(shm_dev->shm_ac_wake_wq, - &shm_dev->shm_ac_wake_req); - - /* stop network queue */ - shrm_stop_netdev(shm_dev->ndev); - - /* reset char device queues */ - shrm_char_reset_queues(shm_dev); - - /* reset protocol states */ - shrm_common_tx_state = SHRM_SLEEP_STATE; - shrm_common_rx_state = SHRM_SLEEP_STATE; - shrm_audio_tx_state = SHRM_SLEEP_STATE; - shrm_audio_rx_state = SHRM_SLEEP_STATE; - - /* set the msr flag */ - shm_dev->msr_flag = 1; - - /* multicast that modem is going to reset */ - err = nl_send_multicast_message(SHRM_NL_MOD_RESET, GFP_ATOMIC); - - /* reset the boot state */ - spin_lock_irqsave(&boot_lock, flags); - boot_state = BOOT_INIT; - spin_unlock_irqrestore(&boot_lock, flags); - - /* re-enable irqs */ - enable_irq(shm_dev->ac_read_notif_0_irq); - enable_irq(shm_dev->ac_read_notif_1_irq); - enable_irq(shm_dev->ca_msg_pending_notif_0_irq); - enable_irq(shm_dev->ca_msg_pending_notif_1_irq); - enable_irq(IRQ_PRCMU_CA_WAKE); - enable_irq(IRQ_PRCMU_CA_SLEEP); - - return err; -} -#endif - -static void shrm_modem_reset_callback(unsigned long irq) -{ - dev_err(shm_dev->dev, "Received mod_reset_req interrupt\n"); - -#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET - { - int err; - dev_info(shm_dev->dev, "Initiating Modem silent reset\n"); - - err = shrm_modem_reset_sequence(); - if (err) - dev_err(shm_dev->dev, - "Failed multicast of modem reset\n"); - } -#else - dev_info(shm_dev->dev, "Modem in reset loop, doing System reset\n"); - - /* Call the PRCMU reset API */ - prcmu_system_reset(SW_RESET_NO_ARGUMENT); -#endif -} - -DECLARE_TASKLET(shrm_sw_reset_callback, shrm_modem_reset_callback, - IRQ_PRCMU_MODEM_SW_RESET_REQ); - -static irqreturn_t shrm_prcmu_irq_handler(int irq, void *data) -{ - struct shrm_dev *shrm = data; - - switch (irq) { - case IRQ_PRCMU_CA_WAKE: -#ifdef CONFIG_UX500_SUSPEND - suspend_block_sleep(); -#endif - if (shrm->msr_flag) - atomic_set(&ac_sleep_disable_count, 0); - atomic_inc(&ac_sleep_disable_count); - queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_wake_req); - break; - case IRQ_PRCMU_CA_SLEEP: - queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_sleep_req); - break; - case IRQ_PRCMU_MODEM_SW_RESET_REQ: - tasklet_schedule(&shrm_sw_reset_callback); - break; - default: - dev_err(shrm->dev, "%s: => IRQ %d\n", __func__, irq); - return IRQ_NONE; - } - return IRQ_HANDLED; -} - -static void send_ac_msg_pend_notify_0_work(struct work_struct *work) -{ - struct shrm_dev *shrm = container_of(work, struct shrm_dev, - send_ac_msg_pend_notify_0); - - dev_dbg(shrm->dev, "%s IN\n", __func__); - update_ac_common_shared_wptr(shrm); - - mutex_lock(&ac_state_mutex); - atomic_inc(&ac_sleep_disable_count); - modem_request(shrm->modem); - mutex_unlock(&ac_state_mutex); - - if (!get_host_accessport_val()) - BUG(); - - /* Trigger AcMsgPendingNotification to CMU */ - writel((1<intr_base + GOP_SET_REGISTER_BASE); - - if (shrm_common_tx_state == SHRM_PTR_FREE) - shrm_common_tx_state = SHRM_PTR_BUSY; - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -static void send_ac_msg_pend_notify_1_work(struct work_struct *work) -{ - struct shrm_dev *shrm = container_of(work, struct shrm_dev, - send_ac_msg_pend_notify_1); - - dev_dbg(shrm->dev, "%s IN\n", __func__); - /* Update shared_wptr with writer_local_wptr) */ - update_ac_audio_shared_wptr(shrm); - - mutex_lock(&ac_state_mutex); - atomic_inc(&ac_sleep_disable_count); - modem_request(shrm->modem); - mutex_unlock(&ac_state_mutex); - - if (!get_host_accessport_val()) - BUG(); - - /* Trigger AcMsgPendingNotification to CMU */ - writel((1<intr_base + GOP_SET_REGISTER_BASE); - - if (shrm_audio_tx_state == SHRM_PTR_FREE) - shrm_audio_tx_state = SHRM_PTR_BUSY; - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void shm_nl_receive(struct sk_buff *skb) -{ - struct nlmsghdr *nlh = NULL; - int msg; - - dev_dbg(shm_dev->dev, "Received NL msg from user-space\n"); - - nlh = (struct nlmsghdr *)skb->data; - msg = *((int *)(NLMSG_DATA(nlh))); - switch (msg) { - case SHRM_NL_MOD_QUERY_STATE: - dev_info(shm_dev->dev, "mod-query-state from user-space\n"); - nl_send_unicast_message(nlh->nlmsg_pid); - break; - - case SHRM_NL_USER_MOD_RESET: - dev_info(shm_dev->dev, "user-space inited mod-reset-req\n"); - dev_info(shm_dev->dev, "PCRMU resets modem\n"); - prcmu_modem_reset(); - break; - - default: - dev_err(shm_dev->dev, "Invalid NL msg from user-space\n"); - break; - }; -} - -int shrm_protocol_init(struct shrm_dev *shrm, - received_msg_handler common_rx_handler, - received_msg_handler audio_rx_handler) -{ - int err; - - shm_dev = shrm; - boot_state = BOOT_INIT; - dev_info(shrm->dev, "IPC_ISA BOOT_INIT\n"); - rx_common_handler = common_rx_handler; - rx_audio_handler = audio_rx_handler; - atomic_set(&ac_sleep_disable_count, 0); - - hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - timer.function = callback; - - shrm->shm_common_ch_wr_wq = create_singlethread_workqueue - ("shm_common_channel_irq"); - if (!shrm->shm_common_ch_wr_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); - return -ENOMEM; - } - shrm->shm_audio_ch_wr_wq = create_singlethread_workqueue - ("shm_audio_channel_irq"); - if (!shrm->shm_audio_ch_wr_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); - err = -ENOMEM; - goto free_wq1; - } - shrm->shm_ac_wake_wq = create_singlethread_workqueue("shm_ac_wake_req"); - if (!shrm->shm_ac_wake_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); - err = -ENOMEM; - goto free_wq2; - } - shrm->shm_ca_wake_wq = create_singlethread_workqueue("shm_ca_wake_req"); - if (!shrm->shm_ac_wake_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); - err = -ENOMEM; - goto free_wq3; - } - shrm->shm_ac_sleep_wq = create_singlethread_workqueue - ("shm_ac_sleep_req"); - if (!shrm->shm_ac_sleep_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); - err = -ENOMEM; - goto free_wq4; - } - INIT_WORK(&shrm->send_ac_msg_pend_notify_0, - send_ac_msg_pend_notify_0_work); - INIT_WORK(&shrm->send_ac_msg_pend_notify_1, - send_ac_msg_pend_notify_1_work); - INIT_WORK(&shrm->shm_ca_wake_req, shm_ca_wake_req_work); - INIT_WORK(&shrm->shm_ca_sleep_req, shm_ca_sleep_req_work); - INIT_WORK(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); - INIT_WORK(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); - - /* set tasklet data */ - shm_ca_0_tasklet.data = (unsigned long)shrm; - shm_ca_1_tasklet.data = (unsigned long)shrm; - - err = request_irq(IRQ_PRCMU_CA_SLEEP, shrm_prcmu_irq_handler, - IRQF_NO_SUSPEND, "ca-sleep", shrm); - if (err < 0) { - dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_SLEEP.\n"); - goto free_wq5; - } - - err = request_irq(IRQ_PRCMU_CA_WAKE, shrm_prcmu_irq_handler, - IRQF_NO_SUSPEND, "ca-wake", shrm); - if (err < 0) { - dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_WAKE.\n"); - goto drop2; - } - - err = request_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, shrm_prcmu_irq_handler, - IRQF_NO_SUSPEND, "modem-sw-reset-req", shrm); - if (err < 0) { - dev_err(shm_dev->dev, - "Failed alloc IRQ_PRCMU_MODEM_SW_RESET_REQ.\n"); - goto drop1; - } - -#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET - /* init netlink socket for user-space communication */ - shrm_nl_sk = netlink_kernel_create(NULL, NETLINK_SHRM, 1, - shm_nl_receive, NULL, THIS_MODULE); - - if (!shrm_nl_sk) { - dev_err(shm_dev->dev, "netlink socket creation failed\n"); - goto drop; - } -#endif - return 0; - -#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET -drop: - free_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, NULL); -#endif -drop1: - free_irq(IRQ_PRCMU_CA_WAKE, NULL); -drop2: - free_irq(IRQ_PRCMU_CA_SLEEP, NULL); -free_wq5: - destroy_workqueue(shrm->shm_ac_sleep_wq); -free_wq4: - destroy_workqueue(shrm->shm_ca_wake_wq); -free_wq3: - destroy_workqueue(shrm->shm_ac_wake_wq); -free_wq2: - destroy_workqueue(shrm->shm_audio_ch_wr_wq); -free_wq1: - destroy_workqueue(shrm->shm_common_ch_wr_wq); - return err; -} - -void shrm_protocol_deinit(struct shrm_dev *shrm) -{ - free_irq(IRQ_PRCMU_CA_SLEEP, NULL); - free_irq(IRQ_PRCMU_CA_WAKE, NULL); - free_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, NULL); - flush_scheduled_work(); - destroy_workqueue(shrm->shm_common_ch_wr_wq); - destroy_workqueue(shrm->shm_audio_ch_wr_wq); - destroy_workqueue(shrm->shm_ac_wake_wq); - destroy_workqueue(shrm->shm_ca_wake_wq); - destroy_workqueue(shrm->shm_ac_sleep_wq); - modem_put(shrm->modem); -} - -int get_ca_wake_req_state(void) -{ - return ((atomic_read(&ac_sleep_disable_count) > 0) || - modem_get_usage(shm_dev->modem)); -} - -irqreturn_t ca_wake_irq_handler(int irq, void *ctrlr) -{ - struct shrm_dev *shrm = ctrlr; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - /* initialize the FIFO Variables */ - if (boot_state == BOOT_INIT) - shm_fifo_init(shrm); - - dev_dbg(shrm->dev, "Inside ca_wake_irq_handler\n"); - - /* Clear the interrupt */ - writel((1 << GOP_CA_WAKE_REQ_BIT), - shrm->intr_base + GOP_CLEAR_REGISTER_BASE); - - /* send ca_wake_ack_interrupt to CMU */ - writel((1 << GOP_CA_WAKE_ACK_BIT), - shrm->intr_base + GOP_SET_REGISTER_BASE); - - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return IRQ_HANDLED; -} - - -irqreturn_t ac_read_notif_0_irq_handler(int irq, void *ctrlr) -{ - struct shrm_dev *shrm = ctrlr; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - shm_ac_read_0_tasklet.data = (unsigned long)shrm; - tasklet_schedule(&shm_ac_read_0_tasklet); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - /* Clear the interrupt */ - writel((1 << GOP_COMMON_AC_READ_NOTIFICATION_BIT), - shrm->intr_base + GOP_CLEAR_REGISTER_BASE); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return IRQ_HANDLED; -} - -irqreturn_t ac_read_notif_1_irq_handler(int irq, void *ctrlr) -{ - struct shrm_dev *shrm = ctrlr; - - dev_dbg(shrm->dev, "%s IN+\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - shm_ac_read_1_tasklet.data = (unsigned long)shrm; - tasklet_schedule(&shm_ac_read_1_tasklet); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - /* Clear the interrupt */ - writel((1 << GOP_AUDIO_AC_READ_NOTIFICATION_BIT), - shrm->intr_base + GOP_CLEAR_REGISTER_BASE); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return IRQ_HANDLED; -} - -irqreturn_t ca_msg_pending_notif_0_irq_handler(int irq, void *ctrlr) -{ - struct shrm_dev *shrm = ctrlr; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - tasklet_schedule(&shm_ca_0_tasklet); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - /* Clear the interrupt */ - writel((1 << GOP_COMMON_CA_MSG_PENDING_NOTIFICATION_BIT), - shrm->intr_base + GOP_CLEAR_REGISTER_BASE); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return IRQ_HANDLED; -} - -irqreturn_t ca_msg_pending_notif_1_irq_handler(int irq, void *ctrlr) -{ - struct shrm_dev *shrm = ctrlr; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - tasklet_schedule(&shm_ca_1_tasklet); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return IRQ_HANDLED; - } - - /* Clear the interrupt */ - writel((1<intr_base+GOP_CLEAR_REGISTER_BASE); - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return IRQ_HANDLED; - -} - -/** - * shm_write_msg() - write message to shared memory - * @shrm: pointer to the shrm device information structure - * @l2_header: L2 header - * @addr: pointer to the message - * @length: length of the message to be written - * - * This function is called from net or char interface driver write operation. - * Prior to calling this function the message is copied from the user space - * buffer to the kernel buffer. This function based on the l2 header routes - * the message to the respective channel and FIFO. Then makes a call to the - * fifo write function where the message is written to the physical device. - */ -int shm_write_msg(struct shrm_dev *shrm, u8 l2_header, - void *addr, u32 length) -{ - u8 channel = 0; - int ret; - - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (boot_state != BOOT_DONE) { - dev_err(shrm->dev, - "error after boot done call this fn\n"); - ret = -ENODEV; - goto out; - } - - if ((l2_header == L2_HEADER_ISI) || - (l2_header == L2_HEADER_RPC) || - (l2_header == L2_HEADER_SECURITY) || - (l2_header == L2_HEADER_COMMON_SIMPLE_LOOPBACK) || - (l2_header == L2_HEADER_COMMON_ADVANCED_LOOPBACK)) { - channel = 0; - if (shrm_common_tx_state == SHRM_SLEEP_STATE) - shrm_common_tx_state = SHRM_PTR_FREE; - else if (shrm_common_tx_state == SHRM_IDLE) - shrm_common_tx_state = SHRM_PTR_FREE; - - } else if ((l2_header == L2_HEADER_AUDIO) || - (l2_header == L2_HEADER_AUDIO_SIMPLE_LOOPBACK) || - (l2_header == L2_HEADER_AUDIO_ADVANCED_LOOPBACK)) { - if (shrm_audio_tx_state == SHRM_SLEEP_STATE) - shrm_audio_tx_state = SHRM_PTR_FREE; - else if (shrm_audio_tx_state == SHRM_IDLE) - shrm_audio_tx_state = SHRM_PTR_FREE; - - channel = 1; - } else { - ret = -ENODEV; - goto out; - } - ret = shm_write_msg_to_fifo(shrm, channel, l2_header, addr, length); - if (ret < 0) { - dev_err(shrm->dev, "write message to fifo failed\n"); - return ret; - } - /* - * notify only if new msg copied is the only unread one - * otherwise it means that reading process is ongoing - */ - if (is_the_only_one_unread_message(shrm, channel, length)) { - - /* Send Message Pending Noitication to CMT */ - if (channel == 0) - queue_work(shrm->shm_common_ch_wr_wq, - &shrm->send_ac_msg_pend_notify_0); - else - queue_work(shrm->shm_audio_ch_wr_wq, - &shrm->send_ac_msg_pend_notify_1); - - } - - dev_dbg(shrm->dev, "%s OUT\n", __func__); - return 0; - -out: - return ret; -} - -void ca_msg_read_notification_0(struct shrm_dev *shrm) -{ - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (get_ca_msg_0_read_notif_send() == 0) { - update_ca_common_shared_rptr(shrm); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - /* Trigger CaMsgReadNotification to CMU */ - writel((1 << GOP_COMMON_CA_READ_NOTIFICATION_BIT), - shrm->intr_base + GOP_SET_REGISTER_BASE); - set_ca_msg_0_read_notif_send(1); - shrm_common_rx_state = SHRM_PTR_BUSY; - } - - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -void ca_msg_read_notification_1(struct shrm_dev *shrm) -{ - dev_dbg(shrm->dev, "%s IN\n", __func__); - - if (get_ca_msg_1_read_notif_send() == 0) { - update_ca_audio_shared_rptr(shrm); - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - /* Trigger CaMsgReadNotification to CMU */ - writel((1<intr_base+GOP_SET_REGISTER_BASE); - set_ca_msg_1_read_notif_send(1); - shrm_audio_rx_state = SHRM_PTR_BUSY; - } - dev_dbg(shrm->dev, "%s OUT\n", __func__); -} - -/** - * receive_messages_common - receive common channnel msg from - * CMT(Cellular Mobile Terminal) - * @shrm: pointer to shrm device information structure - * - * The messages sent from CMT to APE are written to the respective FIFO - * and an interrupt is triggered by the CMT. This ca message pending - * interrupt calls this function. This function sends a read notification - * acknowledgement to the CMT and calls the common channel receive handler - * where the messsage is copied to the respective(ISI, RPC, SECURIT) queue - * based on the message l2 header. - */ -void receive_messages_common(struct shrm_dev *shrm) -{ - u8 l2_header; - u32 len; - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - l2_header = read_one_l2msg_common(shrm, recieve_common_msg, &len); - /* Send Recieve_Call_back to Upper Layer */ - if (!rx_common_handler) { - dev_err(shrm->dev, "common_rx_handler is Null\n"); - BUG(); - } - (*rx_common_handler)(l2_header, &recieve_common_msg, len, - shrm); - /* SendReadNotification */ - ca_msg_read_notification_0(shrm); - - while (read_remaining_messages_common()) { - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - l2_header = read_one_l2msg_common(shrm, recieve_common_msg, - &len); - /* Send Recieve_Call_back to Upper Layer */ - (*rx_common_handler)(l2_header, - &recieve_common_msg, len, - shrm); - } -} - -/** - * receive_messages_audio() - receive audio message from CMT - * @shrm: pointer to shrm device information structure - * - * The messages sent from CMT to APE are written to the respective FIFO - * and an interrupt is triggered by the CMT. This ca message pending - * interrupt calls this function. This function sends a read notification - * acknowledgement to the CMT and calls the common channel receive handler - * where the messsage is copied to the audio queue. - */ -void receive_messages_audio(struct shrm_dev *shrm) -{ - u8 l2_header; - u32 len; - - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - l2_header = read_one_l2msg_audio(shrm, recieve_audio_msg, &len); - /* Send Recieve_Call_back to Upper Layer */ - - if (!rx_audio_handler) { - dev_crit(shrm->dev, "audio_rx_handler is Null\n"); - BUG(); - } - (*rx_audio_handler)(l2_header, &recieve_audio_msg, - len, shrm); - - /* SendReadNotification */ - ca_msg_read_notification_1(shrm); - while (read_remaining_messages_audio()) { - if (check_modem_in_reset()) { - dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", - __func__); - return; - } - - l2_header = read_one_l2msg_audio(shrm, - recieve_audio_msg, &len); - /* Send Recieve_Call_back to Upper Layer */ - (*rx_audio_handler)(l2_header, - &recieve_audio_msg, len, - shrm); - } -} - -u8 get_boot_state() -{ - return boot_state; -} diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig index a23b5c90e5e..95d4307775b 100644 --- a/drivers/modem/Kconfig +++ b/drivers/modem/Kconfig @@ -18,3 +18,5 @@ config MODEM_U8500 Application processor. If unsure, say N. + +source "drivers/modem/shrm/Kconfig" diff --git a/drivers/modem/Makefile b/drivers/modem/Makefile index 57b50916c79..e1b3f376cce 100644 --- a/drivers/modem/Makefile +++ b/drivers/modem/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_MODEM) := modem_access.o obj-$(CONFIG_MODEM_U8500) += modem_u8500.o +obj-$(CONFIG_U8500_SHRM) += shrm/ diff --git a/drivers/modem/shrm/Kconfig b/drivers/modem/shrm/Kconfig new file mode 100644 index 00000000000..465c8bb10a1 --- /dev/null +++ b/drivers/modem/shrm/Kconfig @@ -0,0 +1,43 @@ +# +# SHM HW kernel configuration +# +config U8500_SHRM + bool "U8500 SHRM hardware driver" + depends on ARCH_U8500 && PHONET && MODEM_U8500 + default Y + ---help--- + If you say Y here, you will enable the STN8500 SHM hardware driver. + + If unsure, say N. +choice + prompt "Modem Image Version" + depends on U8500_SHRM + default SHRM_V1_UPDATES_VERSION + + config SHRM_V1_UPDATES_VERSION + depends on U8500_SHRM + bool "SHRM V1 UPDATES" + help + Modem Images with V1 Updates + +endchoice + +config U8500_SHRM_LOOP_BACK + bool "U8500 SHRM loopback" + depends on U8500_SHRM + default n + ---help--- + If you say Y here, you will enable the shm loopback + + If unsure, say N. + +config U8500_SHRM_MODEM_SILENT_RESET + bool "U8500 SHRM Modem Silent Reset" + depends on U8500_SHRM + default n + ---help--- + If you say Y here, you will enable the modem silent reset feature + + If unsure, say N. + + diff --git a/drivers/modem/shrm/Makefile b/drivers/modem/shrm/Makefile new file mode 100644 index 00000000000..8115c24920b --- /dev/null +++ b/drivers/modem/shrm/Makefile @@ -0,0 +1,11 @@ +# +# Makefile for SHRM drivers +# + +ifdef CONFIG_PHONET +u8500_shrm-objs := modem_shrm_driver.o shrm_fifo.o shrm_protocol.o +else +u8500_shrm-objs := shrm_driver.o shrm_fifo.o shrm_protocol.o +endif + +obj-$(CONFIG_U8500_SHRM) += u8500_shrm.o diff --git a/drivers/modem/shrm/modem_shrm_driver.c b/drivers/modem/shrm/modem_shrm_driver.c new file mode 100644 index 00000000000..5e986ab9a2c --- /dev/null +++ b/drivers/modem/shrm/modem_shrm_driver.c @@ -0,0 +1,669 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghvi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_HIGH_RES_TIMERS +#include +static struct hrtimer timer; +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#include +/* debug functionality */ +#define ISA_DEBUG 0 + +#define PHONET_TASKLET +#define MAX_RCV_LEN 2048 + +static void do_phonet_rcv_tasklet(unsigned long unused); +struct tasklet_struct phonet_rcv_tasklet; + +/** + * audio_receive() - Receive audio channel completion callback + * @shrm: pointer to shrm device information structure + * @data: message pointer + * @n_bytes: message size + * @l2_header: L2 header/device ID 2->audio, 5->audio_loopback + * + * This fucntion is called from the audio receive handler. Copies the audio + * message from the FIFO to the AUDIO queue. The message is later copied from + * this queue to the user buffer through the char or net interface read + * operation. + */ +static int audio_receive(struct shrm_dev *shrm, void *data, + u32 n_bytes, u8 l2_header) +{ + u32 size = 0; + int ret = 0; + int idx; + u8 *psrc; + struct message_queue *q; + struct isadev_context *audiodev; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + idx = shrm_get_cdev_index(l2_header); + if (idx < 0) { + dev_err(shrm->dev, "failed to get index\n"); + return idx; + } + audiodev = &shrm->isa_context->isadev[idx]; + q = &audiodev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + ret = add_msg_to_queue(q, n_bytes); + spin_unlock(&q->update_lock); + if (ret < 0) + dev_err(shrm->dev, "Adding a msg to message queue failed"); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * common_receive() - Receive common channel completion callback + * @shrm: pointer to the shrm device information structure + * @data: message pointer + * @n_bytes: message size + * @l2_header: L2 header / device ID + * + * This function is called from the receive handler to copy the respective + * ISI, RPC, SECURITY message to its respective queue. The message is then + * copied from queue to the user buffer on char net interface read operation. + */ +static int common_receive(struct shrm_dev *shrm, void *data, + u32 n_bytes, u8 l2_header) +{ + u32 size = 0; + int ret = 0; + int idx; + u8 *psrc; + struct message_queue *q; + struct isadev_context *isa_dev; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + idx = shrm_get_cdev_index(l2_header); + if (idx < 0) { + dev_err(shrm->dev, "failed to get index\n"); + return idx; + } + isa_dev = &shrm->isa_context->isadev[idx]; + q = &isa_dev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + dev_dbg(shrm->dev, "Inside Loop Back\n"); + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + ret = add_msg_to_queue(q, n_bytes); + spin_unlock(&q->update_lock); + if (ret < 0) { + dev_err(shrm->dev, "Adding a msg to message queue failed"); + return ret; + } + + + if (l2_header == ISI_MESSAGING) { + if (shrm->netdev_flag_up) { + dev_dbg(shrm->dev, + "scheduling the phonet tasklet from %s!\n", + __func__); + tasklet_schedule(&phonet_rcv_tasklet); + } + dev_dbg(shrm->dev, + "Out of phonet tasklet %s!!!\n", __func__); + } + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * rx_common_l2msg_handler() - common channel receive handler + * @l2_header: L2 header + * @msg: pointer to the receive buffer + * @length: length of the msg to read + * @shrm: pointer to shrm device information structure + * + * This function is called to receive the message from CaMsgPendingNotification + * interrupt handler. + */ +static void rx_common_l2msg_handler(u8 l2_header, + void *msg, u32 length, + struct shrm_dev *shrm) +{ + int ret = 0; + dev_dbg(shrm->dev, "%s IN\n", __func__); + + ret = common_receive(shrm, msg, length, l2_header); + if (ret < 0) + dev_err(shrm->dev, + "common receive with l2 header %d failed\n", l2_header); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +/** + * rx_audio_l2msg_handler() - audio channel receive handler + * @l2_header: L2 header + * @msg: pointer to the receive buffer + * @length: length of the msg to read + * @shrm: pointer to shrm device information structure + * + * This function is called to receive the message from CaMsgPendingNotification + * interrupt handler. + */ +static void rx_audio_l2msg_handler(u8 l2_header, + void *msg, u32 length, + struct shrm_dev *shrm) +{ + int ret = 0; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + ret = audio_receive(shrm, msg, length, l2_header); + if (ret < 0) + dev_err(shrm->dev, "audio receive failed\n"); + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +static int __init shm_initialise_irq(struct shrm_dev *shrm) +{ + int err = 0; + + err = shrm_protocol_init(shrm, + rx_common_l2msg_handler, rx_audio_l2msg_handler); + if (err < 0) { + dev_err(shrm->dev, "SHM Protocol Init Failure\n"); + return err; + } + + err = request_irq(shrm->ca_wake_irq, + ca_wake_irq_handler, IRQF_TRIGGER_RISING, + "ca_wake-up", shrm); + if (err < 0) { + dev_err(shrm->dev, + "Unable to allocate shm tx interrupt line\n"); + free_irq(shrm->ca_wake_irq, shrm); + return err; + } + + err = request_irq(shrm->ac_read_notif_0_irq, + ac_read_notif_0_irq_handler, 0, + "ac_read_notif_0", shrm); + + if (err < 0) { + dev_err(shrm->dev, + "error ac_read_notif_0_irq interrupt line\n"); + goto irq_err1; + } + + err = request_irq(shrm->ac_read_notif_1_irq, + ac_read_notif_1_irq_handler, 0, + "ac_read_notif_1", shrm); + + if (err < 0) { + dev_err(shrm->dev, + "error ac_read_notif_1_irq interrupt line\n"); + goto irq_err2; + } + + err = request_irq(shrm->ca_msg_pending_notif_0_irq, + ca_msg_pending_notif_0_irq_handler, 0, + "ca_msg_pending_notif_0", shrm); + + if (err < 0) { + dev_err(shrm->dev, + "error ca_msg_pending_notif_0_irq line\n"); + goto irq_err3; + } + + err = request_irq(shrm->ca_msg_pending_notif_1_irq, + ca_msg_pending_notif_1_irq_handler, 0, + "ca_msg_pending_notif_1", shrm); + + if (err < 0) { + dev_err(shrm->dev, + "error ca_msg_pending_notif_1_irq interrupt line\n"); + goto irq_err4; + } + return err; +irq_err4: + free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); +irq_err3: + free_irq(shrm->ac_read_notif_1_irq, shrm); +irq_err2: + free_irq(shrm->ac_read_notif_0_irq, shrm); +irq_err1: + free_irq(shrm->ca_wake_irq, shrm); + return err; +} + +static void free_shm_irq(struct shrm_dev *shrm) +{ + free_irq(shrm->ca_wake_irq, shrm); + free_irq(shrm->ac_read_notif_0_irq, shrm); + free_irq(shrm->ac_read_notif_1_irq, shrm); + free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); + free_irq(shrm->ca_msg_pending_notif_1_irq, shrm); +} + + + +#ifdef CONFIG_HIGH_RES_TIMERS +static enum hrtimer_restart callback(struct hrtimer *timer) +{ + return HRTIMER_NORESTART; +} +#endif + +void do_phonet_rcv_tasklet(unsigned long unused) +{ + ssize_t ret; + struct shrm_dev *shrm = (struct shrm_dev *)unused; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + for (;;) { + ret = shrm_net_receive(shrm->ndev); + if (ret == 0) { + dev_dbg(shrm->dev, "len is zero, queue empty\n"); + break; + } + if (ret < 0) { + dev_err(shrm->dev, "len < 0 !!! error!!!\n"); + break; + } + } + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +static int shrm_probe(struct platform_device *pdev) +{ + int err = 0; + struct resource *res; + struct shrm_dev *shrm = NULL; + + shrm = kzalloc(sizeof(struct shrm_dev), GFP_KERNEL); + if (shrm == NULL) { + dev_err(&pdev->dev, + "Could not allocate memory for struct shm_dev\n"); + return -ENOMEM; + } + + shrm->dev = &pdev->dev; + shrm->modem = modem_get(shrm->dev, "u8500-shrm-modem"); + if (shrm->modem == NULL) { + dev_err(shrm->dev, " Could not retrieve the modem.\n"); + return -ENODEV; + } + + /* initialise the SHM */ + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) { + dev_err(shrm->dev, + "Unable to map Ca Wake up interrupt\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_wake_irq = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); + + if (!res) { + dev_err(shrm->dev, + "Unable to map APE_Read_notif_common IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ac_read_notif_0_irq = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 2); + + if (!res) { + dev_err(shrm->dev, + "Unable to map APE_Read_notif_audio IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ac_read_notif_1_irq = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 3); + + if (!res) { + dev_err(shrm->dev, + "Unable to map Cmt_msg_pending_notif_common IRQbase\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_msg_pending_notif_0_irq = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 4); + + if (!res) { + dev_err(shrm->dev, + "Unable to map Cmt_msg_pending_notif_audio IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_msg_pending_notif_1_irq = res->start; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + if (!res) { + dev_err(shrm->dev, + "Could not get SHM IO memory information\n"); + err = -ENODEV; + goto rollback_intr; + } + shrm->intr_base = (void __iomem *)ioremap_nocache(res->start, + res->end - res->start + 1); + if (!(shrm->intr_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ape_common_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_APE_COMMON_BASE; + shrm->ape_common_fifo_base = + (void __iomem *)ioremap_nocache( + U8500_SHM_FIFO_APE_COMMON_BASE, + SHM_FIFO_0_SIZE); + shrm->ape_common_fifo_size = (SHM_FIFO_0_SIZE)/4; + + if (!(shrm->ape_common_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ape_common_fifo_base; + } + shrm->cmt_common_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_CMT_COMMON_BASE; + shrm->cmt_common_fifo_base = + (void __iomem *)ioremap_nocache( + U8500_SHM_FIFO_CMT_COMMON_BASE, SHM_FIFO_0_SIZE); + shrm->cmt_common_fifo_size = (SHM_FIFO_0_SIZE)/4; + + if (!(shrm->cmt_common_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_cmt_common_fifo_base; + } + shrm->ape_audio_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_APE_AUDIO_BASE; + shrm->ape_audio_fifo_base = + (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_APE_AUDIO_BASE, + SHM_FIFO_1_SIZE); + shrm->ape_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; + + if (!(shrm->ape_audio_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ape_audio_fifo_base; + } + shrm->cmt_audio_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_CMT_AUDIO_BASE; + shrm->cmt_audio_fifo_base = + (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_CMT_AUDIO_BASE, + SHM_FIFO_1_SIZE); + shrm->cmt_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; + + if (!(shrm->cmt_audio_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_cmt_audio_fifo_base; + } + shrm->ac_common_shared_wptr = + (void __iomem *)ioremap(SHM_ACFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_common_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ac_common_shared_wptr; + } + shrm->ac_common_shared_rptr = + (void __iomem *)ioremap(SHM_ACFIFO_0_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_common_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ca_common_shared_wptr = + (void __iomem *)ioremap(SHM_CAFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_common_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ca_common_shared_rptr = + (void __iomem *)ioremap(SHM_CAFIFO_0_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_common_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ac_audio_shared_wptr = + (void __iomem *)ioremap(SHM_ACFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_audio_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ac_audio_shared_rptr = + (void __iomem *)ioremap(SHM_ACFIFO_1_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_audio_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ca_audio_shared_wptr = + (void __iomem *)ioremap(SHM_CAFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_audio_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + shrm->ca_audio_shared_rptr = + (void __iomem *)ioremap(SHM_CAFIFO_1_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_audio_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + if (isa_init(shrm) != 0) { + dev_err(shrm->dev, "Driver Initialization Error\n"); + err = -EBUSY; + } + /* install handlers and tasklets */ + if (shm_initialise_irq(shrm)) { + dev_err(shrm->dev, + "shm error in interrupt registration\n"); + goto rollback_irq; + } +#ifdef CONFIG_HIGH_RES_TIMERS + hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + timer.function = callback; + hrtimer_start(&timer, ktime_set(0, 2*NSEC_PER_MSEC), HRTIMER_MODE_REL); +#endif + err = shrm_register_netdev(shrm); + if (err < 0) + goto rollback_irq; + + tasklet_init(&phonet_rcv_tasklet, do_phonet_rcv_tasklet, 0); + phonet_rcv_tasklet.data = (unsigned long)shrm; + + platform_set_drvdata(pdev, shrm); + + return err; +rollback_irq: + free_shm_irq(shrm); +rollback_map: + iounmap(shrm->ac_common_shared_wptr); + iounmap(shrm->ac_common_shared_rptr); + iounmap(shrm->ca_common_shared_wptr); + iounmap(shrm->ca_common_shared_rptr); + iounmap(shrm->ac_audio_shared_wptr); + iounmap(shrm->ac_audio_shared_rptr); + iounmap(shrm->ca_audio_shared_wptr); + iounmap(shrm->ca_audio_shared_rptr); +rollback_ac_common_shared_wptr: + iounmap(shrm->cmt_audio_fifo_base); +rollback_cmt_audio_fifo_base: + iounmap(shrm->ape_audio_fifo_base); +rollback_ape_audio_fifo_base: + iounmap(shrm->cmt_common_fifo_base); +rollback_cmt_common_fifo_base: + iounmap(shrm->ape_common_fifo_base); +rollback_ape_common_fifo_base: + iounmap(shrm->intr_base); +rollback_intr: + kfree(shrm); + return err; +} + +static int __exit shrm_remove(struct platform_device *pdev) +{ + struct shrm_dev *shrm = platform_get_drvdata(pdev); + + free_shm_irq(shrm); + iounmap(shrm->intr_base); + iounmap(shrm->ape_common_fifo_base); + iounmap(shrm->cmt_common_fifo_base); + iounmap(shrm->ape_audio_fifo_base); + iounmap(shrm->cmt_audio_fifo_base); + iounmap(shrm->ac_common_shared_wptr); + iounmap(shrm->ac_common_shared_rptr); + iounmap(shrm->ca_common_shared_wptr); + iounmap(shrm->ca_common_shared_rptr); + iounmap(shrm->ac_audio_shared_wptr); + iounmap(shrm->ac_audio_shared_rptr); + iounmap(shrm->ca_audio_shared_wptr); + iounmap(shrm->ca_audio_shared_rptr); + shrm_unregister_netdev(shrm); + isa_exit(shrm); + kfree(shrm); + + return 0; +} + +#ifdef CONFIG_PM +/** + * u8500_shrm_suspend() - This routine puts the SHRM in to sustend state. + * @dev: pointer to device structure. + * + * This routine checks the current ongoing communication with Modem by + * examining the ca_wake state and prevents suspend if modem communication + * is on-going. + * If ca_wake = 1 (high), modem comm. is on-going; don't suspend + * If ca_wake = 0 (low), no comm. with modem on-going.Allow suspend + */ +int u8500_shrm_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct shrm_dev *shrm = platform_get_drvdata(pdev); + int err; + + dev_dbg(&pdev->dev, "%s called...\n", __func__); + dev_dbg(&pdev->dev, "ca_wake_req_state = %x\n", + get_ca_wake_req_state()); + + /* if ca_wake_req is high, prevent system suspend */ + if (!get_ca_wake_req_state()) { + err = shrm_suspend_netdev(shrm->ndev); + return err; + } else + return -EBUSY; +} + +/** + * u8500_shrm_resume() - This routine resumes the SHRM from suspend state. + * @dev: pointer to device structure + * + * This routine restore back the current state of the SHRM + */ +int u8500_shrm_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct shrm_dev *shrm = platform_get_drvdata(pdev); + int err; + + dev_dbg(&pdev->dev, "%s called...\n", __func__); + err = shrm_resume_netdev(shrm->ndev); + + return err; +} + +static const struct dev_pm_ops shrm_dev_pm_ops = { + .suspend_noirq = u8500_shrm_suspend, + .resume_noirq = u8500_shrm_resume, +}; +#endif + +static struct platform_driver shrm_driver = { + .remove = __exit_p(shrm_remove), + .driver = { + .name = "u8500_shrm", + .owner = THIS_MODULE, +#ifdef CONFIG_PM + .pm = &shrm_dev_pm_ops, +#endif + }, +}; + +static int __init shrm_driver_init(void) +{ + return platform_driver_probe(&shrm_driver, shrm_probe); +} + +static void __exit shrm_driver_exit(void) +{ + platform_driver_unregister(&shrm_driver); +} + +module_init(shrm_driver_init); +module_exit(shrm_driver_exit); + +MODULE_AUTHOR("Biju Das, Kumar Sanghvi, Arun Murthy"); +MODULE_DESCRIPTION("Shared Memory Modem Driver Interface"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/modem/shrm/shrm_driver.c b/drivers/modem/shrm/shrm_driver.c new file mode 100644 index 00000000000..11540831f95 --- /dev/null +++ b/drivers/modem/shrm/shrm_driver.c @@ -0,0 +1,1439 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghvi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#define DEBUG + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#ifdef CONFIG_HIGH_RES_TIMERS +#include +static struct hrtimer timer; +#endif + + +#define NAME "IPC_ISA" +#define ISA_DEVICES 4 +/**debug functionality*/ +#define ISA_DEBUG 0 + +#define ISI_MESSAGING (0) +#define RPC_MESSAGING (1) +#define AUDIO_MESSAGING (2) +#define SECURITY_MESSAGING (3) + +#define SIZE_OF_FIFO (512*1024) + +static u8 message_fifo[4][SIZE_OF_FIFO]; + +static u8 wr_isi_msg[10*1024]; +static u8 wr_rpc_msg[10*1024]; +static u8 wr_sec_msg[10*1024]; +static u8 wr_audio_msg[10*1024]; + +/* global data */ +/* + * int major:This variable is exported to user as module_param to specify + * major number at load time + */ +static int major; +module_param(major, int, 0); +MODULE_PARM_DESC(major, "Major device number"); +/* global fops mutex */ +static DEFINE_MUTEX(isa_lock); +rx_cb common_rx; +rx_cb audio_rx; + + +static int isi_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); +static int rpc_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); +static int audio_receive(struct shrm_dev *shrm, void *data, u32 n_bytes); +static int security_receive(struct shrm_dev *shrm, + void *data, u32 n_bytes); + +static void rx_common_l2msg_handler(u8 l2_header, + void *msg, u32 length, + struct shrm_dev *shrm) +{ + int ret = 0; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + u8 *pdata; +#endif + dev_dbg(shrm->dev, "%s IN\n", __func__); + + switch (l2_header) { + case ISI_MESSAGING: + ret = isi_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, "isi receive failed\n"); + break; + case RPC_MESSAGING: + ret = rpc_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, "rpc receive failed\n"); + break; + case SECURITY_MESSAGING: + ret = security_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, + "security receive failed\n"); + break; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + case COMMMON_LOOPBACK_MESSAGING: + pdata = (u8 *)msg; + if ((*pdata == 0x50) || (*pdata == 0xAF)) { + ret = isi_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, "isi receive failed\n"); + } else if ((*pdata == 0x0A) || (*pdata == 0xF5)) { + ret = rpc_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, "rpc receive failed\n"); + } else if ((*pdata == 0xFF) || (*pdata == 0x00)) { + ret = security_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, + "security receive failed\n"); + } + break; +#endif + default: + break; + } + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +static void rx_audio_l2msg_handler(u8 l2_header, + void *msg, u32 length, + struct shrm_dev *shrm) +{ + int ret = 0; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + audio_receive(shrm, msg, length); + if (ret < 0) + dev_err(shrm->dev, "audio receive failed\n"); + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +static int __init shm_initialise_irq(struct shrm_dev *shrm) +{ + int err = 0; + + shrm_protocol_init(shrm, + rx_common_l2msg_handler, rx_audio_l2msg_handler); + + err = request_irq(shrm->ca_wake_irq, + ca_wake_irq_handler, IRQF_TRIGGER_RISING, + "ca_wake-up", shrm); + if (err < 0) { + dev_err(shrm->dev, + "Unable to allocate shm tx interrupt line\n"); + return err; + } + + err = request_irq(shrm->ac_read_notif_0_irq, + ac_read_notif_0_irq_handler, 0, + "ac_read_notif_0", shrm); + if (err < 0) { + dev_err(shrm->dev, + "error ac_read_notif_0_irq interrupt line\n"); + goto irq_err1; + } + + err = request_irq(shrm->ac_read_notif_1_irq, + ac_read_notif_1_irq_handler, 0, + "ac_read_notif_1", shrm); + if (err < 0) { + dev_err(shrm->dev, + "error ac_read_notif_1_irq interrupt line\n"); + goto irq_err2; + } + + err = request_irq(shrm->ca_msg_pending_notif_0_irq, + ca_msg_pending_notif_0_irq_handler, 0, + "ca_msg_pending_notif_0", shrm); + if (err < 0) { + dev_err(shrm->dev, + "error ca_msg_pending_notif_0_irq line\n"); + goto irq_err3; + } + + err = request_irq(shrm->ca_msg_pending_notif_1_irq, + ca_msg_pending_notif_1_irq_handler, 0, + "ca_msg_pending_notif_1", shrm); + if (err < 0) { + dev_err(shrm->dev, + "error ca_msg_pending_notif_1_irq interrupt line\n"); + goto irq_err4; + } + + return err; + +irq_err4: + free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); +irq_err3: + free_irq(shrm->ac_read_notif_1_irq, shrm); +irq_err2: + free_irq(shrm->ac_read_notif_0_irq, shrm); +irq_err1: + free_irq(shrm->ca_wake_irq, shrm); + return err; +} + +static void free_shm_irq(struct shrm_dev *shrm) +{ + free_irq(shrm->ca_wake_irq, shrm); + free_irq(shrm->ac_read_notif_0_irq, shrm); + free_irq(shrm->ac_read_notif_1_irq, shrm); + free_irq(shrm->ca_msg_pending_notif_0_irq, shrm); + free_irq(shrm->ca_msg_pending_notif_1_irq, shrm); +} + +/** + * create_queue() - To create FIFO for Tx and Rx message buffering. + * @q: message queue. + * @devicetype: device type 0-isi,1-rpc,2-audio,3-security. + * + * This function creates a FIFO buffer of n_bytes size using + * dma_alloc_coherent(). It also initializes all queue handling + * locks, queue management pointers. It also initializes message list + * which occupies this queue. + * + * It return -ENOMEM in case of no memory. + */ +static int create_queue(struct message_queue *q, u32 devicetype, + struct shrm_dev *shrm) +{ + q->fifo_base = (u8 *)&message_fifo[devicetype]; + q->size = SIZE_OF_FIFO; + q->readptr = 0; + q->writeptr = 0; + q->no = 0; + q->shrm = shrm; + spin_lock_init(&q->update_lock); + INIT_LIST_HEAD(&q->msg_list); + init_waitqueue_head(&q->wq_readable); + atomic_set(&q->q_rp, 0); + + return 0; +} +/** + * delete_queue() - To delete FIFO and assiciated memory. + * @q: message queue + * + * This function deletes FIFO created using create_queue() function. + * It resets queue management pointers. + */ +static void delete_queue(struct message_queue *q) +{ + q->size = 0; + q->readptr = 0; + q->writeptr = 0; +} + +/** + * add_msg_to_queue() - Add a message inside inside queue + * + * @q: message queue + * @size: size in bytes + * + * This function tries to allocate n_bytes of size in FIFO q. + * It returns negative number when no memory can be allocated + * currently. + */ +int add_msg_to_queue(struct message_queue *q, u32 size) +{ + struct queue_element *new_msg = NULL; + struct shrm_dev *shrm = q->shrm; + + dev_dbg(shrm->dev, "%s IN q->writeptr=%d\n", + __func__, q->writeptr); + new_msg = kmalloc(sizeof(struct queue_element), + GFP_KERNEL|GFP_ATOMIC); + + if (new_msg == NULL) { + dev_err(shrm->dev, "memory overflow inside while(1)\n"); + return -ENOMEM; + } + new_msg->offset = q->writeptr; + new_msg->size = size; + new_msg->no = q->no++; + + /* check for overflow condition */ + if (q->readptr <= q->writeptr) { + if (((q->writeptr-q->readptr) + size) >= q->size) { + dev_err(shrm->dev, "Buffer overflow !!\n"); + BUG_ON(((q->writeptr-q->readptr) + size) >= q->size); + } + } else { + if ((q->writeptr + size) >= q->readptr) { + dev_err(shrm->dev, "Buffer overflow !!\n"); + BUG_ON((q->writeptr + size) >= q->readptr); + } + } + q->writeptr = (q->writeptr + size) % q->size; + if (list_empty(&q->msg_list)) { + list_add_tail(&new_msg->entry, &q->msg_list); + /* There can be 2 blocking calls read and another select */ + + atomic_set(&q->q_rp, 1); + wake_up_interruptible(&q->wq_readable); + } else + list_add_tail(&new_msg->entry, &q->msg_list); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return 0; +} + +/** + * remove_msg_from_queue() - To remove a message from the msg queue. + * + * @q: message queue + * + * This function delets a message from the message list associated with message + * queue q and also updates read ptr. + * If the message list is empty, then, event is set to block the select and + * read calls of the paricular queue. + * + * The message list is FIFO style and message is always added to tail and + * removed from head. + */ + +int remove_msg_from_queue(struct message_queue *q) +{ + struct queue_element *old_msg = NULL; + struct shrm_dev *shrm = q->shrm; + struct list_head *msg; + + dev_dbg(shrm->dev, "%s IN q->readptr %d\n", + __func__, q->readptr); + + list_for_each(msg, &q->msg_list) { + old_msg = list_entry(msg, struct queue_element, entry); + if (old_msg == NULL) { + dev_err(shrm->dev, ":no message found\n"); + return -EFAULT; + } + break; + } + list_del(msg); + q->readptr = (q->readptr + old_msg->size) % q->size; + if (list_empty(&q->msg_list)) { + dev_dbg(shrm->dev, "List is empty setting RP= 0\n"); + atomic_set(&q->q_rp, 0); + } + kfree(old_msg); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return 0; +} + +/** + * get_size_of_new_msg() - retrieve new message from message list + * + * @q: message queue + * + * This function will retrieve most recent message from the corresponding + * queue list. New message is always retrieved from head side. + * It returns new message no, offset if FIFO and size. + */ +int get_size_of_new_msg(struct message_queue *q) +{ + struct queue_element *new_msg = NULL; + struct list_head *msg_list; + struct shrm_dev *shrm = q->shrm; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + spin_lock_bh(&q->update_lock); + list_for_each(msg_list, &q->msg_list) { + new_msg = list_entry(msg_list, struct queue_element, entry); + if (new_msg == NULL) { + spin_unlock_bh(&q->update_lock); + dev_err(shrm->dev, "no message found\n"); + return -1; + } + break; + } + spin_unlock_bh(&q->update_lock); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return new_msg->size; +} + +/** + * isi_receive() - Rx Completion callback + * + * @data:message pointer + * @n_bytes:message size + * + * This function is a callback to indicate ISI message reception is complete. + * It updates Writeptr of the Fifo + */ +static int isi_receive(struct shrm_dev *shrm, + void *data, u32 n_bytes) +{ + u32 size = 0; + int ret = 0; + u8 *psrc; + struct message_queue *q; + struct isadev_context *isidev = &shrm->isa_context->isadev[0]; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + q = &isidev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + dev_dbg(shrm->dev, "Inside Loop Back\n"); + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + ret = add_msg_to_queue(q, n_bytes); + if (ret < 0) + dev_err(shrm->dev, "Adding msg to message queue failed\n"); + spin_unlock(&q->update_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * rpc_receive() - Rx Completion callback + * + * @data:message pointer + * @n_bytes:message size + * + * This function is a callback to indicate RPC message reception is complete. + * It updates Writeptr of the Fifo + */ +static int rpc_receive(struct shrm_dev *shrm, + void *data, u32 n_bytes) +{ + u32 size = 0; + int ret = 0; + u8 *psrc; + struct message_queue *q; + struct isadev_context *rpcdev = &shrm->isa_context->isadev[1]; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + q = &rpcdev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + + ret = add_msg_to_queue(q, n_bytes); + if (ret < 0) + dev_err(shrm->dev, "Adding msg to message queue failed\n"); + spin_unlock(&q->update_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * audio_receive() - Rx Completion callback + * + * @data:message pointer + * @n_bytes:message size + * + * This function is a callback to indicate audio message reception is complete. + * It updates Writeptr of the Fifo + */ +static int audio_receive(struct shrm_dev *shrm, + void *data, u32 n_bytes) +{ + u32 size = 0; + int ret = 0; + u8 *psrc; + struct message_queue *q; + struct isadev_context *audiodev = &shrm->isa_context->isadev[2]; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + q = &audiodev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + ret = add_msg_to_queue(q, n_bytes); + if (ret < 0) + dev_err(shrm->dev, "Adding msg to message queue failed\n"); + spin_unlock(&q->update_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * security_receive() - Rx Completion callback + * + * @data:message pointer + * @n_bytes: message size + * + * This function is a callback to indicate security message reception + * is complete.It updates Writeptr of the Fifo + */ +static int security_receive(struct shrm_dev *shrm, + void *data, u32 n_bytes) +{ + u32 size = 0; + int ret = 0; + u8 *psrc; + struct message_queue *q; + struct isadev_context *secdev = &shrm->isa_context->isadev[3]; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + q = &secdev->dl_queue; + spin_lock(&q->update_lock); + /* Memcopy RX data first */ + if ((q->writeptr+n_bytes) >= q->size) { + psrc = (u8 *)data; + size = (q->size-q->writeptr); + /* Copy First Part of msg */ + memcpy((q->fifo_base+q->writeptr), psrc, size); + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (n_bytes-size)); + } else { + memcpy((q->fifo_base+q->writeptr), data, n_bytes); + } + ret = add_msg_to_queue(q, n_bytes); + if (ret < 0) + dev_err(shrm->dev, "Adding msg to message queue failed\n"); + spin_unlock(&q->update_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + + +/** + * isa_select() - Select Interface + * + * @filp:file descriptor pointer + * @wait:poll_table_struct pointer + * + * This function is used to perform non-blocking read operations. It allows + * a process to determine whether it can read from one or more open files + * without blocking. These calls can also block a process until any of a + * given set of file descriptors becomes available for reading. + * If a file is ready to read, POLLIN | POLLRDNORM bitmask is returned. + * The driver method is called whenever the user-space program performs a select + * system call involving a file descriptor associated with the driver. + */ +static u32 isa_select(struct file *filp, + struct poll_table_struct *wait) +{ + struct isadev_context *isadev = filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + struct message_queue *q; + u32 mask = 0; + u32 m = iminor(filp->f_path.dentry->d_inode); + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (isadev->device_id != m) + return -1; + q = &isadev->dl_queue; + poll_wait(filp, &q->wq_readable, wait); + if (atomic_read(&q->q_rp) == 1) + mask = POLLIN | POLLRDNORM; + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return mask; +} + +/** + * isa_read() - Read from device + * + * @filp:file descriptor + * @buf:user buffer pointer + * @len:size of requested data transfer + * @ppos:not used + * + * This function is called whenever user calls read() system call. + * It reads a oldest message from queue and copies it into user buffer and + * returns its size. + * If there is no message present in queue, then it blocks until new data is + * available. + */ +ssize_t isa_read(struct file *filp, char __user *buf, + size_t len, loff_t *ppos) +{ + struct isadev_context *isadev = (struct isadev_context *) + filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + struct message_queue *q; + char *psrc; + u32 msgsize; + u32 size = 0; + int ret = 0; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (len <= 0) + return -EFAULT; + q = &isadev->dl_queue; + + spin_lock_bh(&q->update_lock); + if (list_empty(&q->msg_list)) { + spin_unlock_bh(&q->update_lock); + if (wait_event_interruptible(q->wq_readable, + atomic_read(&q->q_rp) == 1)) { + return -ERESTARTSYS; + } + } else + spin_unlock_bh(&q->update_lock); + + msgsize = get_size_of_new_msg(q); + if ((q->readptr+msgsize) >= q->size) { + dev_dbg(shrm->dev, "Inside Loop Back\n"); + psrc = (char *)buf; + size = (q->size-q->readptr); + /* Copy First Part of msg */ + if (copy_to_user(psrc, + (u8 *)(q->fifo_base+q->readptr), + size)) { + dev_err(shrm->dev, "copy_to_user failed\n"); + return -EFAULT; + } + psrc += size; + /* Copy Second Part of msg at the top of fifo */ + if (copy_to_user(psrc, + (u8 *)(q->fifo_base), + (msgsize-size))) { + dev_err(shrm->dev, "copy_to_user failed\n"); + return -EFAULT; + } + } else { + if (copy_to_user(buf, + (u8 *)(q->fifo_base+q->readptr), + msgsize)) { + dev_err(shrm->dev, "copy_to_user failed\n"); + return -EFAULT; + } + } + + spin_lock_bh(&q->update_lock); + ret = remove_msg_from_queue(q); + if (ret < 0) { + dev_err(shrm->dev, + "Removing msg from message queue failed\n"); + msgsize = ret; + } + spin_unlock_bh(&q->update_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return msgsize; +} +/** + * isa_write() - Write to device + * + * @filp:file descriptor + * @buf:user buffer pointer + * @len:size of requested data transfer + * @ppos:not used + * + * This function is called whenever user calls write() system call. + * It checks if there is space available in queue, and copies the message + * inside queue. If there is no space, it blocks until space becomes available. + * It also schedules transfer thread to transmit the newly added message. + */ +static ssize_t isa_write(struct file *filp, const char __user *buf, + size_t len, loff_t *ppos) +{ + struct isadev_context *isadev = filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + struct message_queue *q; + int err, ret; + void *addr = 0; + u8 l2_header = 0; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + if (len <= 0) + return -EFAULT; + q = &isadev->dl_queue; + + switch (isadev->device_id) { + case ISI_MESSAGING: + dev_dbg(shrm->dev, "ISI\n"); + addr = (void *)wr_isi_msg; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + dev_dbg(shrm->dev, "Loopback\n"); + l2_header = COMMON_LOOPBACK_MESSAGING; +#else + l2_header = isadev->device_id; +#endif + break; + case RPC_MESSAGING: + dev_dbg(shrm->dev, "RPC\n"); + addr = (void *)wr_rpc_msg; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + l2_header = COMMON_LOOPBACK_MESSAGING; +#else + l2_header = isadev->device_id; +#endif + break; + case AUDIO_MESSAGING: + dev_dbg(shrm->dev, "Audio\n"); + addr = (void *)wr_audio_msg; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + l2_header = AUDIO_LOOPBACK_MESSAGING; +#else + l2_header = isadev->device_id; +#endif + + break; + case SECURITY_MESSAGING: + dev_dbg(shrm->dev, "Security\n"); + addr = (void *)wr_sec_msg; +#ifdef CONFIG_U8500_SHRM_LOOP_BACK + l2_header = COMMON_LOOPBACK_MESSAGING; +#else + l2_header = isadev->device_id; +#endif + break; + default: + dev_dbg(shrm->dev, "Wrong device\n"); + return -EFAULT; + } + + if (copy_from_user(addr, buf, len)) { + dev_err(shrm->dev, "copy_from_user failed\n"); + return -EFAULT; + } + + /* Write msg to Fifo */ + if (isadev->device_id == 2) { + mutex_lock(&shrm->isa_context->tx_audio_mutex); + err = shm_write_msg(shrm, l2_header, addr, len); + if (!err) + ret = len; + else + ret = err; + mutex_unlock(&shrm->isa_context->tx_audio_mutex); + } else { + spin_lock_bh(&shrm->isa_context->common_tx); + err = shm_write_msg(shrm, l2_header, addr, len); + if (!err) + ret = len; + else + ret = err; + spin_unlock_bh(&shrm->isa_context->common_tx); + } + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return ret; +} + +/** + * isa_ioctl() - To handle different ioctl commands supported by driver. + * + * @inode: structure is used by the kernel internally to represent files + * @filp:file descriptor pointer + * @cmd:ioctl command + * @arg:input param + * + * Following ioctls are supported by this driver. + * DLP_IOCTL_ALLOCATE_BUFFER - To allocate buffer for new uplink message. + * This ioctl is called with required message size. It returns offset for + * the allocates space in the queue. DLP_IOCTL_PUT_MESSAGE - To indicate + * new uplink message available in queuq for transmission. Message is copied + * from offset location returned by previous ioctl before calling this ioctl. + * DLP_IOCTL_GET_MESSAGE - To check if any downlink message is available in + * queue. It returns offset for new message inside queue. + * DLP_IOCTL_DEALLOCATE_BUFFER - To deallocate any buffer allocate for + * downlink message once the message is copied. Message is copied from offset + * location returned by previous ioctl before calling this ioctl. + */ +static int isa_ioctl(struct inode *inode, struct file *filp, + unsigned cmd, unsigned long arg) +{ + int err = 0; + struct isadev_context *isadev = filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + u32 m = iminor(inode); + + if (isadev->device_id != m) + return -1; + + switch (cmd) { + case DLP_IOC_ALLOCATE_BUFFER: + dev_dbg(shrm->dev, "DLP_IOC_ALLOCATE_BUFFER\n"); + break; + case DLP_IOC_PUT_MESSAGE: + dev_dbg(shrm->dev, "DLP_IOC_PUT_MESSAGE\n"); + break; + case DLP_IOC_GET_MESSAGE: + dev_dbg(shrm->dev, "DLP_IOC_GET_MESSAGE\n"); + break; + case DLP_IOC_DEALLOCATE_BUFFER: + dev_dbg(shrm->dev, "DLP_IOC_DEALLOCATE_BUFFER\n"); + break; + default: + dev_dbg(shrm->dev, "Unknown IOCTL\n"); + err = -1; + break; + } + return err; +} +/** + * isa_mmap() - Maps kernel queue memory to user space. + * + * @filp:file descriptor pointer + * @vma:virtual area memory structure. + * + * This function maps kernel FIFO into user space. This function + * shall be called twice to map both uplink and downlink buffers. + */ +static int isa_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct isadev_context *isadev = filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + + u32 m = iminor(filp->f_path.dentry->d_inode); + dev_dbg(shrm->dev, "%s %dIN\n", __func__, m); + + isadev = (struct isadev_context *)filp->private_data; + return 0; +} + +/** + * isa_close() - Close device file + * + * @inode:structure is used by the kernel internally to represent files + * @filp:device file descriptor + * + * This function deletes structues associated with this file, deletes + * queues, flushes and destroys workqueus and closes this file. + * It also unregisters itself from l2mux driver. + */ +static int isa_close(struct inode *inode, struct file *filp) +{ + struct isadev_context *isadev = filp->private_data; + struct shrm_dev *shrm = isadev->dl_queue.shrm; + struct isa_driver_context *isa_context = shrm->isa_context; + u8 m; + + mutex_lock(&isa_lock); + m = iminor(filp->f_path.dentry->d_inode); + dev_dbg(shrm->dev, "%s IN %d", __func__, m); + + if (atomic_dec_and_test(&isa_context->is_open[m])) { + atomic_inc(&isa_context->is_open[m]); + dev_err(shrm->dev, "Device not opened yet\n"); + mutex_unlock(&isa_lock); + return -ENODEV; + } + atomic_set(&isa_context->is_open[m], 1); + + dev_dbg(shrm->dev, "isadev->device_id %d", isadev->device_id); + dev_dbg(shrm->dev, "Closed %d device\n", m); + + if (m == ISI_MESSAGING) + dev_dbg(shrm->dev, "Closed ISI_MESSAGING Device\n"); + else if (m == RPC_MESSAGING) + dev_dbg(shrm->dev, "Closed RPC_MESSAGING Device\n"); + else if (m == AUDIO_MESSAGING) + dev_dbg(shrm->dev, "Closed AUDIO_MESSAGING Device\n"); + else if (m == SECURITY_MESSAGING) + dev_dbg(shrm->dev, "Closed SECURITY_MESSAGING Device\n"); + else + dev_dbg(shrm->dev, NAME ":No such device present\n"); + + mutex_unlock(&isa_lock); + return 0; +} +/** + * isa_open() - Open device file + * + * @inode: structure is used by the kernel internally to represent files + * @filp: device file descriptor + * + * This function performs initialization tasks needed to open SHM channel. + * Following tasks are performed. + * -return if device is already opened + * -create uplink FIFO + * -create downlink FIFO + * -init delayed workqueue thread + * -register to l2mux driver + */ +static int isa_open(struct inode *inode, struct file *filp) +{ + int err = 0; + u8 m; + struct isadev_context *isadev; + struct isa_driver_context *isa_context = container_of( + inode->i_cdev, + struct isa_driver_context, + cdev); + struct shrm_dev *shrm = isa_context->isadev->dl_queue.shrm; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (get_boot_state() != BOOT_DONE) { + dev_err(shrm->dev, "Boot is not done\n"); + return -EBUSY; + } + mutex_lock(&isa_lock); + m = iminor(inode); + + if ((m != ISI_MESSAGING) && (m != RPC_MESSAGING) && + (m != AUDIO_MESSAGING) && (m != SECURITY_MESSAGING)) { + dev_err(shrm->dev, "No such device present\n"); + mutex_unlock(&isa_lock); + return -ENODEV; + } + if (!atomic_dec_and_test(&isa_context->is_open[m])) { + atomic_inc(&isa_context->is_open[m]); + dev_err(shrm->dev, "Device already opened\n"); + mutex_unlock(&isa_lock); + return -EBUSY; + } + + if (m == ISI_MESSAGING) + dev_dbg(shrm->dev, "Open ISI_MESSAGING Device\n"); + else if (m == RPC_MESSAGING) + dev_dbg(shrm->dev, "Open RPC_MESSAGING Device\n"); + else if (m == AUDIO_MESSAGING) + dev_dbg(shrm->dev, "Open AUDIO_MESSAGING Device\n"); + else if (m == SECURITY_MESSAGING) + dev_dbg(shrm->dev, "Open SECURITY_MESSAGING Device\n"); + else + dev_dbg(shrm->dev, ":No such device present\n"); + + isadev = &isa_context->isadev[m]; + if (filp != NULL) + filp->private_data = isadev; + + mutex_unlock(&isa_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return err; +} + +const struct file_operations isa_fops = { + .owner = THIS_MODULE, + .open = isa_open, + .release = isa_close, + .ioctl = isa_ioctl, + .mmap = isa_mmap, + .read = isa_read, + .write = isa_write, + .poll = isa_select, +}; + +/** + * isa_init() - module insertion function + * + * This function registers module as a character driver using + * register_chrdev_region() or alloc_chrdev_region. It adds this + * driver to system using cdev_add() call. Major number is dynamically + * allocated using alloc_chrdev_region() by default or left to user to specify + * it during load time. For this variable major is used as module_param + * Nodes to be created using + * mknod /dev/isi c $major 0 + * mknod /dev/rpc c $major 1 + * mknod /dev/audio c $major 2 + * mknod /dev/sec c $major 3 + */ +int isa_init(struct shrm_dev *shrm) +{ + dev_t dev_id; + int retval, no_dev; + struct isadev_context *isadev; + struct isa_driver_context *isa_context; + + isa_context = kzalloc(sizeof(struct isa_driver_context), + GFP_KERNEL); + shrm->isa_context = isa_context; + if (isa_context == NULL) { + dev_err(shrm->dev, "Failed to alloc memory\n"); + return -ENOMEM; + } + + if (major) { + dev_id = MKDEV(major, 0); + retval = register_chrdev_region(dev_id, ISA_DEVICES, NAME); + } else { + retval = alloc_chrdev_region(&dev_id, 0, ISA_DEVICES, NAME); + major = MAJOR(dev_id); + } + + dev_dbg(shrm->dev, "major %d\n", major); + + cdev_init(&isa_context->cdev, &isa_fops); + isa_context->cdev.owner = THIS_MODULE; + retval = cdev_add(&isa_context->cdev, dev_id, ISA_DEVICES); + if (retval) { + dev_err(shrm->dev, "Failed to add char device\n"); + return retval; + } + + for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) + atomic_set(&isa_context->is_open[no_dev], 1); + + isa_context->isadev = kzalloc(sizeof + (struct isadev_context)*ISA_DEVICES, + GFP_KERNEL); + if (isa_context->isadev == NULL) { + dev_err(shrm->dev, "Failed to alloc memory\n"); + return -ENOMEM; + } + for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) { + isadev = &isa_context->isadev[no_dev]; + isadev->device_id = no_dev; + retval = create_queue(&isadev->dl_queue, + isadev->device_id, shrm); + if (retval < 0) { + dev_err(shrm->dev, "create dl_queue failed\n"); + delete_queue(&isadev->dl_queue); + kfree(isadev); + return retval; + } + } + mutex_init(&isa_context->tx_audio_mutex); + spin_lock_init(&isa_context->common_tx); + + dev_err(shrm->dev, "SHRM char driver added\n"); + + return retval; +} + +void isa_exit(struct shrm_dev *shrm) +{ + int no_dev; + struct isadev_context *isadev; + struct isa_driver_context *isa_context = shrm->isa_context; + dev_t dev_id = MKDEV(major, 0); + + for (no_dev = 0; no_dev < ISA_DEVICES; no_dev++) { + isadev = &isa_context->isadev[no_dev]; + delete_queue(&isadev->dl_queue); + kfree(isadev); + } + + cdev_del(&isa_context->cdev); + unregister_chrdev_region(dev_id, ISA_DEVICES); + kfree(isa_context); + + dev_err(shrm->dev, "SHRM char driver removed\n"); +} + +#ifdef CONFIG_HIGH_RES_TIMERS +static enum hrtimer_restart callback(struct hrtimer *timer) +{ + return HRTIMER_NORESTART; +} +#endif + + +static int __init shrm_probe(struct platform_device *pdev) +{ + int err = 0; + struct resource *res; + struct shrm_dev *shrm = NULL; + + if (pdev == NULL) { + dev_err(shrm->dev, + "No device/platform_data found on shm device\n"); + return -ENODEV; + } + + + shrm = kzalloc(sizeof(struct shrm_dev), GFP_KERNEL); + if (shrm == NULL) { + dev_err(shrm->dev, + "Could not allocate memory for struct shm_dev\n"); + return -ENOMEM; + } + shrm->dev = &pdev->dev; + + /* initialise the SHM */ + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) { + dev_err(shrm->dev, "Unable to map Ca Wake up interrupt\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_wake_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); + if (!res) { + dev_err(shrm->dev, + "Unable to map APE_Read_notif_common IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ac_read_notif_0_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 2); + if (!res) { + dev_err(shrm->dev, + "Unable to map APE_Read_notif_audio IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ac_read_notif_1_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 3); + if (!res) { + dev_err(shrm->dev, + "Unable to map Cmt_msg_pending_notif_common IRQbase\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_msg_pending_notif_0_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 4); + if (!res) { + dev_err(shrm->dev, + "Unable to map Cmt_msg_pending_notif_audio IRQ base\n"); + err = -EBUSY; + goto rollback_intr; + } + shrm->ca_msg_pending_notif_1_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(shrm->dev, + "Could not get SHM IO memory information\n"); + err = -ENODEV; + goto rollback_intr; + } + + shrm->intr_base = (void __iomem *)ioremap_nocache(res->start, + res->end - res->start + 1); + + if (!(shrm->intr_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_intr; + } + + shrm->ape_common_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_APE_COMMON_BASE; + shrm->ape_common_fifo_base = + (void __iomem *)ioremap_nocache( + U8500_SHM_FIFO_APE_COMMON_BASE, + SHM_FIFO_0_SIZE); + shrm->ape_common_fifo_size = (SHM_FIFO_0_SIZE)/4; + + if (!(shrm->ape_common_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ape_common_fifo_base; + } + + shrm->cmt_common_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_CMT_COMMON_BASE; + + shrm->cmt_common_fifo_base = + (void __iomem *)ioremap_nocache( + U8500_SHM_FIFO_CMT_COMMON_BASE, SHM_FIFO_0_SIZE); + shrm->cmt_common_fifo_size = (SHM_FIFO_0_SIZE)/4; + + if (!(shrm->cmt_common_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_cmt_common_fifo_base; + } + + shrm->ape_audio_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_APE_AUDIO_BASE; + shrm->ape_audio_fifo_base = + (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_APE_AUDIO_BASE, + SHM_FIFO_1_SIZE); + shrm->ape_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; + + if (!(shrm->ape_audio_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ape_audio_fifo_base; + } + + shrm->cmt_audio_fifo_base_phy = + (u32 *)U8500_SHM_FIFO_CMT_AUDIO_BASE; + shrm->cmt_audio_fifo_base = + (void __iomem *)ioremap_nocache(U8500_SHM_FIFO_CMT_AUDIO_BASE, + SHM_FIFO_1_SIZE); + shrm->cmt_audio_fifo_size = (SHM_FIFO_1_SIZE)/4; + + if (!(shrm->cmt_audio_fifo_base)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_cmt_audio_fifo_base; + } + + shrm->ac_common_shared_wptr = + (void __iomem *)ioremap(SHM_ACFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_common_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_ac_common_shared_wptr; + } + + shrm->ac_common_shared_rptr = + (void __iomem *)ioremap(SHM_ACFIFO_0_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_common_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + shrm->ca_common_shared_wptr = + (void __iomem *)ioremap(SHM_CAFIFO_0_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_common_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + shrm->ca_common_shared_rptr = + (void __iomem *)ioremap(SHM_CAFIFO_0_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_common_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + shrm->ac_audio_shared_wptr = + (void __iomem *)ioremap(SHM_ACFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_audio_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + shrm->ac_audio_shared_rptr = + (void __iomem *)ioremap(SHM_ACFIFO_1_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ac_audio_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + shrm->ca_audio_shared_wptr = + (void __iomem *)ioremap(SHM_CAFIFO_1_WRITE_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_audio_shared_wptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + shrm->ca_audio_shared_rptr = + (void __iomem *)ioremap(SHM_CAFIFO_1_READ_AMCU, SHM_PTR_SIZE); + + if (!(shrm->ca_audio_shared_rptr)) { + dev_err(shrm->dev, "Unable to map register base\n"); + err = -EBUSY; + goto rollback_map; + } + + + if (isa_init(shrm) != 0) { + dev_err(shrm->dev, "Driver Initialization Error\n"); + err = -EBUSY; + } + /* install handlers and tasklets */ + if (shm_initialise_irq(shrm)) { + dev_err(shrm->dev, "shm error in interrupt registration\n"); + goto rollback_irq; + } + +#ifdef CONFIG_HIGH_RES_TIMERS + hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + timer.function = callback; + + hrtimer_start(&timer, ktime_set(0, 2*NSEC_PER_MSEC), HRTIMER_MODE_REL); +#endif + + return err; + +rollback_irq: + free_shm_irq(shrm); +rollback_map: + iounmap(shrm->ac_common_shared_wptr); + iounmap(shrm->ac_common_shared_rptr); + iounmap(shrm->ca_common_shared_wptr); + iounmap(shrm->ca_common_shared_rptr); + iounmap(shrm->ac_audio_shared_wptr); + iounmap(shrm->ac_audio_shared_rptr); + iounmap(shrm->ca_audio_shared_wptr); + iounmap(shrm->ca_audio_shared_rptr); +rollback_ac_common_shared_wptr: + iounmap(shrm->cmt_audio_fifo_base); +rollback_cmt_audio_fifo_base: + iounmap(shrm->ape_audio_fifo_base); +rollback_ape_audio_fifo_base: + iounmap(shrm->cmt_common_fifo_base); +rollback_cmt_common_fifo_base: + iounmap(shrm->ape_common_fifo_base); +rollback_ape_common_fifo_base: + iounmap(shrm->intr_base); +rollback_intr: + kfree(shrm); + return err; +} + +static int __exit shrm_remove(struct platform_device *pdev) +{ + struct shrm_dev *shrm = platform_get_drvdata(pdev); + + free_shm_irq(shrm); + iounmap(shrm->intr_base); + iounmap(shrm->ape_common_fifo_base); + iounmap(shrm->cmt_common_fifo_base); + iounmap(shrm->ape_audio_fifo_base); + iounmap(shrm->cmt_audio_fifo_base); + iounmap(shrm->ac_common_shared_wptr); + iounmap(shrm->ac_common_shared_rptr); + iounmap(shrm->ca_common_shared_wptr); + iounmap(shrm->ca_common_shared_rptr); + iounmap(shrm->ac_audio_shared_wptr); + iounmap(shrm->ac_audio_shared_rptr); + iounmap(shrm->ca_audio_shared_wptr); + iounmap(shrm->ca_audio_shared_rptr); + kfree(shrm); + isa_exit(shrm); + + return 0; +} +#ifdef CONFIG_PM + +/** + * u8500_shrm_suspend() - This routine puts the SHRM in to sustend state. + * @pdev: platform device. + * + * This routine checks the current ongoing communication with Modem by + * examining the ca_wake state and prevents suspend if modem communication + * is on-going. + * If ca_wake = 1 (high), modem comm. is on-going; don't suspend + * If ca_wake = 0 (low), no comm. with modem on-going.Allow suspend + */ +int u8500_shrm_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct shrm_dev *shrm = platform_get_drvdata(pdev); + + dev_dbg(shrm->dev, "%s called...\n", __func__); + dev_dbg(shrm->dev, "\n ca_wake_req_state = %x\n", + get_ca_wake_req_state()); + /* if ca_wake_req is high, prevent system suspend */ + if (get_ca_wake_req_state()) + return -EBUSY; + else + return 0; +} + +/** + * u8500_shrm_resume() - This routine resumes the SHRM from sustend state. + * @pdev: platform device. + * + * This routine restore back the current state of the SHRM + */ +int u8500_shrm_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct shrm_dev *shrm = platform_get_drvdata(pdev); + + dev_dbg(shrm->dev, "%s called...\n", __func__); + /* TODO: + * As of now, no state save takes place in suspend. + * So, nothing to restore in resume. + * Simply return as of now. + * State saved in suspend should be restored here. + */ + + return 0; +} + +static const struct dev_pm_ops shrm_dev_pm_ops = { + .suspend = u8500_shrm_suspend, + .resume = u8500_shrm_resume, +}; +#endif + +static struct platform_driver shrm_driver = { + .remove = __exit_p(shrm_remove), + .driver = { + .name = "u8500_shrm", + .owner = THIS_MODULE, +#ifdef CONFIG_PM + .pm = &shrm_dev_pm_ops, +#endif + }, +}; + +static int __init shrm_driver_init(void) +{ + return platform_driver_probe(&shrm_driver, shrm_probe); +} + +static void __exit shrm_driver_exit(void) +{ + platform_driver_unregister(&shrm_driver); +} + +module_init(shrm_driver_init); +module_exit(shrm_driver_exit); + +MODULE_AUTHOR("Biju Das"); +MODULE_DESCRIPTION("Shared Memory Modem Driver Interface"); +MODULE_LICENSE("GPL"); diff --git a/drivers/modem/shrm/shrm_fifo.c b/drivers/modem/shrm/shrm_fifo.c new file mode 100644 index 00000000000..883966d4ab5 --- /dev/null +++ b/drivers/modem/shrm/shrm_fifo.c @@ -0,0 +1,827 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghavi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#include +#include +#include +#include + +#define L1_BOOT_INFO_REQ 1 +#define L1_BOOT_INFO_RESP 2 +#define L1_NORMAL_MSG 3 +#define L1_HEADER_MASK 28 +#define L1_MAPID_MASK 0xF0000000 +#define CONFIG_OFFSET 8 +#define COUNTER_OFFSET 20 +#define L2_HEADER_SIZE 4 +#define L2_HEADER_OFFSET 24 +#define MASK_0_15_BIT 0xFF +#define MASK_16_31_BIT 0xFF00 +#define MASK_16_27_BIT 0xFFF0000 +#define MASK_0_39_BIT 0xFFFFF +#define MASK_40_55_BIT 0xFF00000 +#define MASK_8_16_BIT 0x0000FF00 +#define MSG_LEN_OFFSET 16 +#define SHRM_VER 2 +#define ca_ist_inactivity_timer 100 /*100ms */ +#define ca_csc_inactivity_timer 100 /*100ms */ + +static u8 msg_audio_counter; +static u8 msg_common_counter; + +struct fifo_write_params ape_shm_fifo_0; +struct fifo_write_params ape_shm_fifo_1; +struct fifo_read_params cmt_shm_fifo_0; +struct fifo_read_params cmt_shm_fifo_1; + + +static u8 cmt_read_notif_0_send; +static u8 cmt_read_notif_1_send; + +void shm_fifo_init(struct shrm_dev *shrm) +{ + ape_shm_fifo_0.writer_local_wptr = 0; + ape_shm_fifo_0.writer_local_rptr = 0; + *((u32 *)shrm->ac_common_shared_wptr) = 0; + *((u32 *)shrm->ac_common_shared_rptr) = 0; + ape_shm_fifo_0.shared_wptr = 0; + ape_shm_fifo_0.shared_rptr = 0; + ape_shm_fifo_0.availablesize = shrm->ape_common_fifo_size; + ape_shm_fifo_0.end_addr_fifo = shrm->ape_common_fifo_size; + ape_shm_fifo_0.fifo_virtual_addr = shrm->ape_common_fifo_base; + spin_lock_init(&ape_shm_fifo_0.fifo_update_lock); + + + cmt_shm_fifo_0.reader_local_rptr = 0; + cmt_shm_fifo_0.reader_local_wptr = 0; + cmt_shm_fifo_0.shared_wptr = + *((u32 *)shrm->ca_common_shared_wptr); + cmt_shm_fifo_0.shared_rptr = + *((u32 *)shrm->ca_common_shared_rptr); + cmt_shm_fifo_0.availablesize = shrm->cmt_common_fifo_size; + cmt_shm_fifo_0.end_addr_fifo = shrm->cmt_common_fifo_size; + cmt_shm_fifo_0.fifo_virtual_addr = shrm->cmt_common_fifo_base; + + ape_shm_fifo_1.writer_local_wptr = 0; + ape_shm_fifo_1.writer_local_rptr = 0; + ape_shm_fifo_1.shared_wptr = 0; + ape_shm_fifo_1.shared_rptr = 0; + *((u32 *)shrm->ac_audio_shared_wptr) = 0; + *((u32 *)shrm->ac_audio_shared_rptr) = 0; + ape_shm_fifo_1.availablesize = shrm->ape_audio_fifo_size; + ape_shm_fifo_1.end_addr_fifo = shrm->ape_audio_fifo_size; + ape_shm_fifo_1.fifo_virtual_addr = shrm->ape_audio_fifo_base; + spin_lock_init(&ape_shm_fifo_1.fifo_update_lock); + + cmt_shm_fifo_1.reader_local_rptr = 0; + cmt_shm_fifo_1.reader_local_wptr = 0; + cmt_shm_fifo_1.shared_wptr = + *((u32 *)shrm->ca_audio_shared_wptr); + cmt_shm_fifo_1.shared_rptr = + *((u32 *)shrm->ca_audio_shared_rptr); + cmt_shm_fifo_1.availablesize = shrm->cmt_audio_fifo_size; + cmt_shm_fifo_1.end_addr_fifo = shrm->cmt_audio_fifo_size; + cmt_shm_fifo_1.fifo_virtual_addr = shrm->cmt_audio_fifo_base; + msg_audio_counter = 0; + msg_common_counter = 0; +} + +u8 read_boot_info_req(struct shrm_dev *shrm, + u32 *config, + u32 *version) +{ + struct fifo_read_params *fifo = &cmt_shm_fifo_0; + u32 *msg; + u32 header = 0; + u8 msgtype; + + /* Read L1 header read content of reader_local_rptr */ + msg = (u32 *) + (fifo->reader_local_rptr + fifo->fifo_virtual_addr); + header = *msg; + msgtype = (header & L1_MAPID_MASK) >> L1_MSG_MAPID_OFFSET; + if (msgtype != L1_BOOT_INFO_REQ) { + dev_err(shrm->dev, "Read_Boot_Info_Req Fatal ERROR\n"); + BUG(); + } + *config = (header >> CONFIG_OFFSET) & MASK_0_15_BIT; + *version = header & MASK_0_15_BIT; + fifo->reader_local_rptr += 1; + + return 1; +} + +void write_boot_info_resp(struct shrm_dev *shrm, u32 config, + u32 version) +{ + struct fifo_write_params *fifo = &ape_shm_fifo_0; + u32 *msg; + u8 msg_length; + version = SHRM_VER; + + spin_lock_bh(&fifo->fifo_update_lock); + /* Read L1 header read content of reader_local_rptr */ + msg = (u32 *) + (fifo->writer_local_wptr+fifo->fifo_virtual_addr); + if (version < 1) { + *msg = ((L1_BOOT_INFO_RESP << L1_MSG_MAPID_OFFSET) | + ((config << CONFIG_OFFSET) & MASK_16_31_BIT) + | (version & MASK_0_15_BIT)); + msg_length = 1; + } else { + *msg = ((L1_BOOT_INFO_RESP << L1_MSG_MAPID_OFFSET) | + ((0x8 << MSG_LEN_OFFSET) & MASK_16_27_BIT) | + ((config << CONFIG_OFFSET) & MASK_8_16_BIT)| + version); + msg++; + *msg = ca_ist_inactivity_timer; + msg++; + *msg = ca_csc_inactivity_timer; + msg_length = L1_NORMAL_MSG; + } + fifo->writer_local_wptr += msg_length; + fifo->availablesize -= msg_length; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +/** + * shm_write_msg_to_fifo() - write message to FIFO + * @shrm: pointer to shrm device information structure + * @channel: audio or common channel + * @l2header: L2 header or device ID + * @addr: pointer to write buffer address + * @length: length of mst to write + * + * Function Which Writes the data into Fifo in IPC zone + * It is called from shm_write_msg. This function will copy the msg + * from the kernel buffer to FIFO. There are 4 kernel buffers from where + * the data is to copied to FIFO one for each of the messages ISI, RPC, + * AUDIO and SECURITY. ISI, RPC and SECURITY messages are pushed to FIFO + * in commmon channel and AUDIO message is pushed onto audio channel FIFO. + */ +int shm_write_msg_to_fifo(struct shrm_dev *shrm, u8 channel, + u8 l2header, void *addr, u32 length) +{ + struct fifo_write_params *fifo = NULL; + u32 l1_header = 0, l2_header = 0; + u32 requiredsize; + u32 size = 0; + u32 *msg; + u8 *src; + + if (channel == COMMON_CHANNEL) + fifo = &ape_shm_fifo_0; + else if (channel == AUDIO_CHANNEL) + fifo = &ape_shm_fifo_1; + else { + dev_err(shrm->dev, "invalid channel\n"); + return -EINVAL; + } + + /* L2 size in 32b */ + requiredsize = ((length + 3) / 4); + /* Add size of L1 & L2 header */ + requiredsize += 2; + + /* if availablesize = or < requiredsize then error */ + if (fifo->availablesize <= requiredsize) { + /* Fatal ERROR - should never happens */ + dev_dbg(shrm->dev, "wr_wptr= %x\n", + fifo->writer_local_wptr); + dev_dbg(shrm->dev, "wr_rptr= %x\n", + fifo->writer_local_rptr); + dev_dbg(shrm->dev, "shared_wptr= %x\n", + fifo->shared_wptr); + dev_dbg(shrm->dev, "shared_rptr= %x\n", + fifo->shared_rptr); + dev_dbg(shrm->dev, "availsize= %x\n", + fifo->availablesize); + dev_dbg(shrm->dev, "end__fifo= %x\n", + fifo->end_addr_fifo); + dev_warn(shrm->dev, "Modem is busy, please wait." + " c_cnt = %d; a_cnt = %d\n", msg_common_counter, + msg_audio_counter); + if (channel == COMMON_CHANNEL) { + dev_warn(shrm->dev, + "Modem is lagging behind in reading." + "Stopping n/w dev queue\n"); + shrm_stop_netdev(shrm->ndev); + } + + return -EAGAIN; + } + + if (channel == COMMON_CHANNEL) { + /* build L1 header */ + l1_header = ((L1_NORMAL_MSG << L1_MSG_MAPID_OFFSET) | + (((msg_common_counter++) << COUNTER_OFFSET) + & MASK_40_55_BIT) | + ((length + L2_HEADER_SIZE) & MASK_0_39_BIT)); + } else if (channel == AUDIO_CHANNEL) { + /* build L1 header */ + l1_header = ((L1_NORMAL_MSG << L1_MSG_MAPID_OFFSET) | + (((msg_audio_counter++) << COUNTER_OFFSET) + & MASK_40_55_BIT) | + ((length + L2_HEADER_SIZE) & MASK_0_39_BIT)); + } + + /* + * Need to take care race condition for fifo->availablesize + * & fifo->writer_local_rptr with Ac_Read_notification interrupt. + * One option could be use stack variable for LocalRptr and recompute + * fifo->availablesize,based on flag enabled in the + * Ac_read_notification + */ + l2_header = ((l2header << L2_HEADER_OFFSET) | + ((length) & MASK_0_39_BIT)); + spin_lock_bh(&fifo->fifo_update_lock); + /* Check Local Rptr is less than or equal to Local WPtr */ + if (fifo->writer_local_rptr <= fifo->writer_local_wptr) { + msg = (u32 *) + (fifo->fifo_virtual_addr+fifo->writer_local_wptr); + + /* check enough place bewteen writer_local_wptr & end of FIFO */ + if ((fifo->end_addr_fifo-fifo->writer_local_wptr) >= + requiredsize) { + /* Add L1 header and L2 header */ + *msg = l1_header; + msg++; + *msg = l2_header; + msg++; + + /* copy the l2 message in 1 memcpy */ + memcpy((void *)msg, addr, length); + /* UpdateWptr */ + fifo->writer_local_wptr += requiredsize; + fifo->availablesize -= requiredsize; + fifo->writer_local_wptr %= fifo->end_addr_fifo; + } else { + /* + * message is split between and of FIFO and beg of FIFO + * copy first part from writer_local_wptr to end of FIFO + */ + size = fifo->end_addr_fifo-fifo->writer_local_wptr; + + if (size == 1) { + /* Add L1 header */ + *msg = l1_header; + msg++; + /* UpdateWptr */ + fifo->writer_local_wptr = 0; + fifo->availablesize -= size; + /* + * copy second part from beg of FIFO + * with remaining part of msg + */ + msg = (u32 *) + fifo->fifo_virtual_addr; + *msg = l2_header; + msg++; + + /* copy the l3 message in 1 memcpy */ + memcpy((void *)msg, addr, length); + /* UpdateWptr */ + fifo->writer_local_wptr += + requiredsize-size; + fifo->availablesize -= + (requiredsize-size); + } else if (size == 2) { + /* Add L1 header and L2 header */ + *msg = l1_header; + msg++; + *msg = l2_header; + msg++; + + /* UpdateWptr */ + fifo->writer_local_wptr = 0; + fifo->availablesize -= size; + + /* + * copy second part from beg of FIFO + * with remaining part of msg + */ + msg = (u32 *) + fifo->fifo_virtual_addr; + /* copy the l3 message in 1 memcpy */ + memcpy((void *)msg, addr, length); + + /* UpdateWptr */ + fifo->writer_local_wptr += + requiredsize-size; + fifo->availablesize -= + (requiredsize-size); + } else { + /* Add L1 header and L2 header */ + *msg = l1_header; + msg++; + *msg = l2_header; + msg++; + + /* copy the l2 message in 1 memcpy */ + memcpy((void *)msg, addr, (size-2)*4); + + + /* UpdateWptr */ + fifo->writer_local_wptr = 0; + fifo->availablesize -= size; + + /* + * copy second part from beg of FIFO + * with remaining part of msg + */ + msg = (u32 *)fifo->fifo_virtual_addr; + src = (u8 *)addr+((size - 2) * 4); + memcpy((void *)msg, src, + (length-((size - 2) * 4))); + + /* UpdateWptr */ + fifo->writer_local_wptr += + requiredsize-size; + fifo->availablesize -= + (requiredsize-size); + } + + } + } else { + /* writer_local_rptr > writer_local_wptr */ + msg = (u32 *) + (fifo->fifo_virtual_addr+fifo->writer_local_wptr); + /* Add L1 header and L2 header */ + *msg = l1_header; + msg++; + *msg = l2_header; + msg++; + /* + * copy message possbile between writer_local_wptr up + * to writer_local_rptr copy the l3 message in 1 memcpy + */ + memcpy((void *)msg, addr, length); + + /* UpdateWptr */ + fifo->writer_local_wptr += requiredsize; + fifo->availablesize -= requiredsize; + + } + spin_unlock_bh(&fifo->fifo_update_lock); + return length; +} + +/** + * read_one_l2msg_common() - read message from common channel + * @shrm: pointer to shrm device information structure + * @l2_msg: pointer to the read L2 message buffer + * @len: message length + * + * This function read one message from the FIFO and returns l2 header type + */ +u8 read_one_l2msg_common(struct shrm_dev *shrm, + u8 *l2_msg, u32 *len) +{ + struct fifo_read_params *fifo = &cmt_shm_fifo_0; + + u32 *msg; + u32 l1_header = 0; + u32 l2_header = 0; + u32 length; + u8 msgtype; + u32 msg_size; + u32 size = 0; + + /* Read L1 header read content of reader_local_rptr */ + msg = (u32 *) + (fifo->reader_local_rptr+fifo->fifo_virtual_addr); + l1_header = *msg++; + msgtype = (l1_header & 0xF0000000) >> L1_HEADER_MASK; + + if (msgtype != L1_NORMAL_MSG) { + /* Fatal ERROR - should never happens */ + dev_dbg(shrm->dev, "wr_wptr= %x\n", + fifo->reader_local_wptr); + dev_dbg(shrm->dev, "wr_rptr= %x\n", + fifo->reader_local_rptr); + dev_dbg(shrm->dev, "shared_wptr= %x\n", + fifo->shared_wptr); + dev_dbg(shrm->dev, "shared_rptr= %x\n", + fifo->shared_rptr); + dev_dbg(shrm->dev, "availsize= %x\n", + fifo->availablesize); + dev_dbg(shrm->dev, "end_fifo= %x\n", + fifo->end_addr_fifo); + /* Fatal ERROR - should never happens */ + dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); + BUG(); + } + if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { + l2_header = (*((u32 *)fifo->fifo_virtual_addr)); + length = l2_header & MASK_0_39_BIT; + } else { + /* Read L2 header,Msg size & content of reader_local_rptr */ + l2_header = *msg; + length = l2_header & MASK_0_39_BIT; + } + + *len = length; + msg_size = ((length + 3) / 4); + msg_size += 2; + + if (fifo->reader_local_rptr + msg_size <= + fifo->end_addr_fifo) { + /* Skip L2 header */ + msg++; + + /* read msg between reader_local_rptr and end of FIFO */ + memcpy((void *)l2_msg, (void *)msg, length); + /* UpdateLocalRptr */ + fifo->reader_local_rptr += msg_size; + fifo->reader_local_rptr %= fifo->end_addr_fifo; + } else { + /* + * msg split between end of FIFO and beg copy first + * part of msg read msg between reader_local_rptr + * and end of FIFO + */ + size = fifo->end_addr_fifo-fifo->reader_local_rptr; + if (size == 1) { + msg = (u32 *)(fifo->fifo_virtual_addr); + /* Skip L2 header */ + msg++; + memcpy((void *)l2_msg, (void *)(msg), length); + } else if (size == 2) { + /* Skip L2 header */ + msg++; + msg = (u32 *)(fifo->fifo_virtual_addr); + memcpy((void *)l2_msg, + (void *)(msg), length); + } else { + /* Skip L2 header */ + msg++; + memcpy((void *)l2_msg, (void *)msg, ((size - 2) * 4)); + /* copy second part of msg */ + l2_msg += ((size - 2) * 4); + msg = (u32 *)(fifo->fifo_virtual_addr); + memcpy((void *)l2_msg, (void *)(msg), + (length-((size - 2) * 4))); + } + fifo->reader_local_rptr = + (fifo->reader_local_rptr+msg_size) % + fifo->end_addr_fifo; + } + return (l2_header>>L2_HEADER_OFFSET) & MASK_0_15_BIT; + } + +u8 read_remaining_messages_common() +{ + struct fifo_read_params *fifo = &cmt_shm_fifo_0; + /* + * There won't be any Race condition reader_local_rptr & + * fifo->reader_local_wptr with CaMsgpending Notification Interrupt + */ + return ((fifo->reader_local_rptr != fifo->reader_local_wptr) ? 1 : 0); +} + +u8 read_one_l2msg_audio(struct shrm_dev *shrm, + u8 *l2_msg, u32 *len) +{ + struct fifo_read_params *fifo = &cmt_shm_fifo_1; + + u32 *msg; + u32 l1_header = 0; + u32 l2_header = 0; + u32 length; + u8 msgtype; + u32 msg_size; + u32 size = 0; + + /* Read L1 header read content of reader_local_rptr */ + msg = (u32 *) + (fifo->reader_local_rptr+fifo->fifo_virtual_addr); + l1_header = *msg++; + msgtype = (l1_header & 0xF0000000) >> L1_HEADER_MASK; + + if (msgtype != L1_NORMAL_MSG) { + /* Fatal ERROR - should never happens */ + dev_dbg(shrm->dev, "wr_local_wptr= %x\n", + fifo->reader_local_wptr); + dev_dbg(shrm->dev, "wr_local_rptr= %x\n", + fifo->reader_local_rptr); + dev_dbg(shrm->dev, "shared_wptr= %x\n", + fifo->shared_wptr); + dev_dbg(shrm->dev, "shared_rptr= %x\n", + fifo->shared_rptr); + dev_dbg(shrm->dev, "availsize=%x\n", + fifo->availablesize); + dev_dbg(shrm->dev, "end_fifo= %x\n", + fifo->end_addr_fifo); + /* Fatal ERROR - should never happens */ + dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); + BUG(); + } + if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { + l2_header = (*((u32 *)fifo->fifo_virtual_addr)); + length = l2_header & MASK_0_39_BIT; + } else { + /* Read L2 header,Msg size & content of reader_local_rptr */ + l2_header = *msg; + length = l2_header & MASK_0_39_BIT; + } + + *len = length; + msg_size = ((length + 3) / 4); + msg_size += 2; + + if (fifo->reader_local_rptr + msg_size <= + fifo->end_addr_fifo) { + /* Skip L2 header */ + msg++; + /* read msg between reader_local_rptr and end of FIFO */ + memcpy((void *)l2_msg, (void *)msg, length); + /* UpdateLocalRptr */ + fifo->reader_local_rptr += msg_size; + fifo->reader_local_rptr %= fifo->end_addr_fifo; + } else { + + /* + * msg split between end of FIFO and beg + * copy first part of msg + * read msg between reader_local_rptr and end of FIFO + */ + size = fifo->end_addr_fifo-fifo->reader_local_rptr; + if (size == 1) { + msg = (u32 *)(fifo->fifo_virtual_addr); + /* Skip L2 header */ + msg++; + memcpy((void *)l2_msg, (void *)(msg), length); + } else if (size == 2) { + /* Skip L2 header */ + msg++; + msg = (u32 *)(fifo->fifo_virtual_addr); + memcpy((void *)l2_msg, (void *)(msg), length); + } else { + /* Skip L2 header */ + msg++; + memcpy((void *)l2_msg, (void *)msg, ((size - 2) * 4)); + /* copy second part of msg */ + l2_msg += ((size - 2) * 4); + msg = (u32 *)(fifo->fifo_virtual_addr); + memcpy((void *)l2_msg, (void *)(msg), + (length-((size - 2) * 4))); + } + fifo->reader_local_rptr = + (fifo->reader_local_rptr+msg_size) % + fifo->end_addr_fifo; + + } + return (l2_header>>L2_HEADER_OFFSET) & MASK_0_15_BIT; + } + +u8 read_remaining_messages_audio() +{ + struct fifo_read_params *fifo = &cmt_shm_fifo_1; + + return ((fifo->reader_local_rptr != fifo->reader_local_wptr) ? + 1 : 0); +} + +u8 is_the_only_one_unread_message(struct shrm_dev *shrm, + u8 channel, u32 length) +{ + struct fifo_write_params *fifo = NULL; + u32 messagesize = 0; + u8 is_only_one_unread_msg = 0; + + if (channel == COMMON_CHANNEL) + fifo = &ape_shm_fifo_0; + else /* channel = AUDIO_CHANNEL */ + fifo = &ape_shm_fifo_1; + + /* L3 size in 32b */ + messagesize = ((length + 3) / 4); + /* Add size of L1 & L2 header */ + messagesize += 2; + /* + * possibility of race condition with Ac Read notification interrupt. + * need to check ? + */ + if (fifo->writer_local_wptr > fifo->writer_local_rptr) + is_only_one_unread_msg = + ((fifo->writer_local_rptr + messagesize) == + fifo->writer_local_wptr) ? 1 : 0; + else + /* Msg split between end of fifo and starting of Fifo */ + is_only_one_unread_msg = + (((fifo->writer_local_rptr + messagesize) % + fifo->end_addr_fifo) == fifo->writer_local_wptr) ? + 1 : 0; + + return is_only_one_unread_msg; +} + +void update_ca_common_local_wptr(struct shrm_dev *shrm) +{ + /* + * update CA common reader local write pointer with the + * shared write pointer + */ + struct fifo_read_params *fifo = &cmt_shm_fifo_0; + + fifo->shared_wptr = + (*((u32 *)shrm->ca_common_shared_wptr)); + fifo->reader_local_wptr = fifo->shared_wptr; +} + +void update_ca_audio_local_wptr(struct shrm_dev *shrm) +{ + /* + * update CA audio reader local write pointer with the + * shared write pointer + */ + struct fifo_read_params *fifo = &cmt_shm_fifo_1; + + fifo->shared_wptr = + (*((u32 *)shrm->ca_audio_shared_wptr)); + fifo->reader_local_wptr = fifo->shared_wptr; +} + +void update_ac_common_local_rptr(struct shrm_dev *shrm) +{ + /* + * update AC common writer local read pointer with the + * shared read pointer + */ + struct fifo_write_params *fifo; + u32 free_space = 0; + + fifo = &ape_shm_fifo_0; + + spin_lock_bh(&fifo->fifo_update_lock); + fifo->shared_rptr = + (*((u32 *)shrm->ac_common_shared_rptr)); + + if (fifo->shared_rptr >= fifo->writer_local_rptr) + free_space = + (fifo->shared_rptr-fifo->writer_local_rptr); + else { + free_space = + (fifo->end_addr_fifo-fifo->writer_local_rptr); + free_space += fifo->shared_rptr; + } + + /* Chance of race condition of below variables with write_msg */ + fifo->availablesize += free_space; + fifo->writer_local_rptr = fifo->shared_rptr; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +void update_ac_audio_local_rptr(struct shrm_dev *shrm) +{ + /* + * update AC audio writer local read pointer with the + * shared read pointer + */ + struct fifo_write_params *fifo; + u32 free_space = 0; + + fifo = &ape_shm_fifo_1; + spin_lock_bh(&fifo->fifo_update_lock); + fifo->shared_rptr = + (*((u32 *)shrm->ac_audio_shared_rptr)); + + if (fifo->shared_rptr >= fifo->writer_local_rptr) + free_space = + (fifo->shared_rptr-fifo->writer_local_rptr); + else { + free_space = + (fifo->end_addr_fifo-fifo->writer_local_rptr); + free_space += fifo->shared_rptr; + } + + /* Chance of race condition of below variables with write_msg */ + fifo->availablesize += free_space; + fifo->writer_local_rptr = fifo->shared_rptr; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +void update_ac_common_shared_wptr(struct shrm_dev *shrm) +{ + /* + * update AC common shared write pointer with the + * local write pointer + */ + struct fifo_write_params *fifo; + + fifo = &ape_shm_fifo_0; + spin_lock_bh(&fifo->fifo_update_lock); + /* Update shared pointer fifo offset of the IPC zone */ + (*((u32 *)shrm->ac_common_shared_wptr)) = + fifo->writer_local_wptr; + + fifo->shared_wptr = fifo->writer_local_wptr; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +void update_ac_audio_shared_wptr(struct shrm_dev *shrm) +{ + /* + * update AC audio shared write pointer with the + * local write pointer + */ + struct fifo_write_params *fifo; + + fifo = &ape_shm_fifo_1; + spin_lock_bh(&fifo->fifo_update_lock); + /* Update shared pointer fifo offset of the IPC zone */ + (*((u32 *)shrm->ac_audio_shared_wptr)) = + fifo->writer_local_wptr; + fifo->shared_wptr = fifo->writer_local_wptr; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +void update_ca_common_shared_rptr(struct shrm_dev *shrm) +{ + /* + * update CA common shared read pointer with the + * local read pointer + */ + struct fifo_read_params *fifo; + + fifo = &cmt_shm_fifo_0; + + /* Update shared pointer fifo offset of the IPC zone */ + (*((u32 *)shrm->ca_common_shared_rptr)) = + fifo->reader_local_rptr; + fifo->shared_rptr = fifo->reader_local_rptr; +} + +void update_ca_audio_shared_rptr(struct shrm_dev *shrm) +{ + /* + * update CA audio shared read pointer with the + * local read pointer + */ + struct fifo_read_params *fifo; + + fifo = &cmt_shm_fifo_1; + + /* Update shared pointer fifo offset of the IPC zone */ + (*((u32 *)shrm->ca_audio_shared_rptr)) = + fifo->reader_local_rptr; + fifo->shared_rptr = fifo->reader_local_rptr; +} + +void get_reader_pointers(u8 channel_type, u32 *reader_local_rptr, + u32 *reader_local_wptr, u32 *shared_rptr) +{ + struct fifo_read_params *fifo = NULL; + + if (channel_type == COMMON_CHANNEL) + fifo = &cmt_shm_fifo_0; + else /* channel_type = AUDIO_CHANNEL */ + fifo = &cmt_shm_fifo_1; + + *reader_local_rptr = fifo->reader_local_rptr; + *reader_local_wptr = fifo->reader_local_wptr; + *shared_rptr = fifo->shared_rptr; +} + +void get_writer_pointers(u8 channel_type, u32 *writer_local_rptr, + u32 *writer_local_wptr, u32 *shared_wptr) +{ + struct fifo_write_params *fifo = NULL; + + if (channel_type == COMMON_CHANNEL) + fifo = &ape_shm_fifo_0; + else /* channel_type = AUDIO_CHANNEL */ + fifo = &ape_shm_fifo_1; + + spin_lock_bh(&fifo->fifo_update_lock); + *writer_local_rptr = fifo->writer_local_rptr; + *writer_local_wptr = fifo->writer_local_wptr; + *shared_wptr = fifo->shared_wptr; + spin_unlock_bh(&fifo->fifo_update_lock); +} + +void set_ca_msg_0_read_notif_send(u8 val) +{ + cmt_read_notif_0_send = val; +} + +u8 get_ca_msg_0_read_notif_send(void) +{ + return cmt_read_notif_0_send; +} + +void set_ca_msg_1_read_notif_send(u8 val) +{ + cmt_read_notif_1_send = val; +} + +u8 get_ca_msg_1_read_notif_send(void) +{ + return cmt_read_notif_1_send; +} diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c new file mode 100644 index 00000000000..99a58aa6f71 --- /dev/null +++ b/drivers/modem/shrm/shrm_protocol.c @@ -0,0 +1,1191 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghvi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define L2_HEADER_ISI 0x0 +#define L2_HEADER_RPC 0x1 +#define L2_HEADER_AUDIO 0x2 +#define L2_HEADER_SECURITY 0x3 +#define L2_HEADER_COMMON_SIMPLE_LOOPBACK 0xC0 +#define L2_HEADER_COMMON_ADVANCED_LOOPBACK 0xC1 +#define L2_HEADER_AUDIO_SIMPLE_LOOPBACK 0x80 +#define L2_HEADER_AUDIO_ADVANCED_LOOPBACK 0x81 +#define MAX_PAYLOAD 1024 + +static u8 boot_state = BOOT_INIT; +static u8 recieve_common_msg[8*1024]; +static u8 recieve_audio_msg[8*1024]; +static received_msg_handler rx_common_handler; +static received_msg_handler rx_audio_handler; +static struct hrtimer timer; +struct sock *shrm_nl_sk; + +static char shrm_common_tx_state = SHRM_SLEEP_STATE; +static char shrm_common_rx_state = SHRM_SLEEP_STATE; +static char shrm_audio_tx_state = SHRM_SLEEP_STATE; +static char shrm_audio_rx_state = SHRM_SLEEP_STATE; + +static atomic_t ac_sleep_disable_count = ATOMIC_INIT(0); +static struct shrm_dev *shm_dev; + +/* Spin lock and tasklet declaration */ +DECLARE_TASKLET(shm_ca_0_tasklet, shm_ca_msgpending_0_tasklet, 0); +DECLARE_TASKLET(shm_ca_1_tasklet, shm_ca_msgpending_1_tasklet, 0); +DECLARE_TASKLET(shm_ac_read_0_tasklet, shm_ac_read_notif_0_tasklet, 0); +DECLARE_TASKLET(shm_ac_read_1_tasklet, shm_ac_read_notif_1_tasklet, 0); + +static DEFINE_MUTEX(ac_state_mutex); + +static DEFINE_SPINLOCK(ca_common_lock); +static DEFINE_SPINLOCK(ca_audio_lock); +static DEFINE_SPINLOCK(ca_wake_req_lock); +static DEFINE_SPINLOCK(boot_lock); + +enum shrm_nl { + SHRM_NL_MOD_RESET = 1, + SHRM_NL_MOD_QUERY_STATE, + SHRM_NL_USER_MOD_RESET, + SHRM_NL_STATUS_MOD_ONLINE, + SHRM_NL_STATUS_MOD_OFFLINE, +}; + +static void shm_ac_sleep_req_work(struct work_struct *work) +{ + mutex_lock(&ac_state_mutex); + if (atomic_read(&ac_sleep_disable_count) == 0) + modem_release(shm_dev->modem); + mutex_unlock(&ac_state_mutex); +} + +static void shm_ac_wake_req_work(struct work_struct *work) +{ + mutex_lock(&ac_state_mutex); + modem_request(shm_dev->modem); + mutex_unlock(&ac_state_mutex); +} + +static u32 get_host_accessport_val(void) +{ + u32 prcm_hostaccess; + + prcm_hostaccess = readl(PRCM_HOSTACCESS_REQ); + wmb(); + prcm_hostaccess = prcm_hostaccess & 0x01; + + return prcm_hostaccess; +} +static enum hrtimer_restart callback(struct hrtimer *timer) +{ + unsigned long flags; + + spin_lock_irqsave(&ca_wake_req_lock, flags); + if (((shrm_common_rx_state == SHRM_IDLE) || + (shrm_common_rx_state == SHRM_SLEEP_STATE)) + && ((shrm_common_tx_state == SHRM_IDLE) || + (shrm_common_tx_state == SHRM_SLEEP_STATE)) + && ((shrm_audio_rx_state == SHRM_IDLE) || + (shrm_audio_rx_state == SHRM_SLEEP_STATE)) + && ((shrm_audio_tx_state == SHRM_IDLE) || + (shrm_audio_tx_state == SHRM_SLEEP_STATE))) { + + shrm_common_rx_state = SHRM_SLEEP_STATE; + shrm_audio_rx_state = SHRM_SLEEP_STATE; + shrm_common_tx_state = SHRM_SLEEP_STATE; + shrm_audio_tx_state = SHRM_SLEEP_STATE; + + queue_work(shm_dev->shm_ac_sleep_wq, + &shm_dev->shm_ac_sleep_req); + + } + spin_unlock_irqrestore(&ca_wake_req_lock, flags); + + return HRTIMER_NORESTART; +} + +int nl_send_multicast_message(int msg, gfp_t gfp_mask) +{ + struct sk_buff *skb = NULL; + struct nlmsghdr *nlh = NULL; + int err; + + /* prepare netlink message */ + skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), gfp_mask); + if (!skb) { + dev_err(shm_dev->dev, "%s:alloc_skb failed\n", __func__); + err = -ENOMEM; + goto out; + } + + nlh = (struct nlmsghdr *)skb->data; + nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); + dev_dbg(shm_dev->dev, "nlh->nlmsg_len = %d\n", nlh->nlmsg_len); + + nlh->nlmsg_pid = 0; /* from kernel */ + nlh->nlmsg_flags = 0; + *(int *)NLMSG_DATA(nlh) = msg; + skb_put(skb, MAX_PAYLOAD); + /* sender is in group 1<<0 */ + NETLINK_CB(skb).pid = 0; /* from kernel */ + /* to mcast group 1<<0 */ + NETLINK_CB(skb).dst_group = 1; + + /*multicast the message to all listening processes*/ + err = netlink_broadcast(shrm_nl_sk, skb, 0, 1, gfp_mask); + dev_dbg(shm_dev->dev, "ret val from nl-multicast = %d\n", err); + +out: + return err; +} + +static void nl_send_unicast_message(int dst_pid) +{ + struct sk_buff *skb = NULL; + struct nlmsghdr *nlh = NULL; + int err; + int bt_state; + unsigned long flags; + + dev_info(shm_dev->dev, "Sending unicast message\n"); + + /* prepare the NL message for unicast */ + skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), GFP_KERNEL); + if (!skb) { + dev_err(shm_dev->dev, "%s:alloc_skb failed\n", __func__); + return; + } + + nlh = (struct nlmsghdr *)skb->data; + nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); + dev_dbg(shm_dev->dev, "nlh->nlmsg_len = %d\n", nlh->nlmsg_len); + + nlh->nlmsg_pid = 0; /* from kernel */ + nlh->nlmsg_flags = 0; + + spin_lock_irqsave(&boot_lock, flags); + bt_state = boot_state; + spin_unlock_irqrestore(&boot_lock, flags); + + if (bt_state == BOOT_DONE) + *(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_ONLINE; + else + *(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_OFFLINE; + + skb_put(skb, MAX_PAYLOAD); + /* sender is in group 1<<0 */ + NETLINK_CB(skb).pid = 0; /* from kernel */ + NETLINK_CB(skb).dst_group = 0; + + /*unicast the message to the querying processes*/ + err = netlink_unicast(shrm_nl_sk, skb, dst_pid, MSG_DONTWAIT); + dev_dbg(shm_dev->dev, "ret val from nl-unicast = %d\n", err); +} + + +static int check_modem_in_reset(void) +{ + u8 bt_state; + unsigned long flags; + + spin_lock_irqsave(&boot_lock, flags); + bt_state = boot_state; + spin_unlock_irqrestore(&boot_lock, flags); + +#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET + if (bt_state != BOOT_UNKNOWN) + return 0; + else + return -ENODEV; +#else + /* + * this check won't be applicable and won't work correctly + * if modem-silent-feature is not enabled + * so, simply return 0 + */ + return 0; +#endif +} + +void shm_ca_msgpending_0_tasklet(unsigned long tasklet_data) +{ + struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; + u32 reader_local_rptr; + u32 reader_local_wptr; + u32 shared_rptr; + u32 config = 0, version = 0; + unsigned long flags; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + /* Interprocess locking */ + spin_lock(&ca_common_lock); + + /* Update_reader_local_wptr with shared_wptr */ + update_ca_common_local_wptr(shrm); + get_reader_pointers(COMMON_CHANNEL, &reader_local_rptr, + &reader_local_wptr, &shared_rptr); + + set_ca_msg_0_read_notif_send(0); + + if (boot_state == BOOT_DONE) { + shrm_common_rx_state = SHRM_PTR_FREE; + + if (reader_local_rptr != shared_rptr) + ca_msg_read_notification_0(shrm); + if (reader_local_rptr != reader_local_wptr) + receive_messages_common(shrm); + get_reader_pointers(COMMON_CHANNEL, &reader_local_rptr, + &reader_local_wptr, &shared_rptr); + if (reader_local_rptr == reader_local_wptr) + shrm_common_rx_state = SHRM_IDLE; + } else { + /* BOOT phase.only a BOOT_RESP should be in FIFO */ + if (boot_state != BOOT_INFO_SYNC) { + if (!read_boot_info_req(shrm, &config, &version)) { + dev_err(shrm->dev, + "Unable to read boot state\n"); + BUG(); + } + /* SendReadNotification */ + ca_msg_read_notification_0(shrm); + /* + * Check the version number before + * sending Boot info response + */ + + /* send MsgPending notification */ + write_boot_info_resp(shrm, config, version); + spin_lock_irqsave(&boot_lock, flags); + boot_state = BOOT_INFO_SYNC; + spin_unlock_irqrestore(&boot_lock, flags); + dev_info(shrm->dev, "BOOT_INFO_SYNC\n"); + queue_work(shrm->shm_common_ch_wr_wq, + &shrm->send_ac_msg_pend_notify_0); + } else { + ca_msg_read_notification_0(shrm); + dev_info(shrm->dev, + "BOOT_INFO_SYNC\n"); + } + } + /* Interprocess locking */ + spin_unlock(&ca_common_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void shm_ca_msgpending_1_tasklet(unsigned long tasklet_data) +{ + struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; + u32 reader_local_rptr; + u32 reader_local_wptr; + u32 shared_rptr; + + /* + * This function is called when CaMsgPendingNotification Trigerred + * by CMU. It means that CMU has wrote a message into Ca Audio FIFO + */ + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown\n", + __func__); + return; + } + + /* Interprocess locking */ + spin_lock(&ca_audio_lock); + + /* Update_reader_local_wptr(with shared_wptr) */ + update_ca_audio_local_wptr(shrm); + get_reader_pointers(AUDIO_CHANNEL, &reader_local_rptr, + &reader_local_wptr, &shared_rptr); + + set_ca_msg_1_read_notif_send(0); + + if (boot_state != BOOT_DONE) { + dev_err(shrm->dev, "Boot Error\n"); + return; + } + shrm_audio_rx_state = SHRM_PTR_FREE; + /* Check we already read the message */ + if (reader_local_rptr != shared_rptr) + ca_msg_read_notification_1(shrm); + if (reader_local_rptr != reader_local_wptr) + receive_messages_audio(shrm); + + get_reader_pointers(AUDIO_CHANNEL, &reader_local_rptr, + &reader_local_wptr, &shared_rptr); + if (reader_local_rptr == reader_local_wptr) + shrm_audio_rx_state = SHRM_IDLE; + + /* Interprocess locking */ + spin_unlock(&ca_audio_lock); + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void shm_ac_read_notif_0_tasklet(unsigned long tasklet_data) +{ + struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; + u32 writer_local_rptr; + u32 writer_local_wptr; + u32 shared_wptr; + unsigned long flags; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + /* Update writer_local_rptrwith shared_rptr */ + update_ac_common_local_rptr(shrm); + get_writer_pointers(COMMON_CHANNEL, &writer_local_rptr, + &writer_local_wptr, &shared_wptr); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown\n", + __func__); + return; + } + + if (boot_state == BOOT_INFO_SYNC) { + /* BOOT_RESP sent by APE has been received by CMT */ + spin_lock_irqsave(&boot_lock, flags); + boot_state = BOOT_DONE; + spin_unlock_irqrestore(&boot_lock, flags); + dev_info(shrm->dev, "IPC_ISA BOOT_DONE\n"); + + if (shrm->msr_flag) { + shrm_start_netdev(shrm->ndev); + shrm->msr_flag = 0; + + /* multicast that modem is online */ + nl_send_multicast_message(SHRM_NL_STATUS_MOD_ONLINE, + GFP_ATOMIC); + } + + } else if (boot_state == BOOT_DONE) { + if (writer_local_rptr != writer_local_wptr) { + shrm_common_tx_state = SHRM_PTR_FREE; + queue_work(shrm->shm_common_ch_wr_wq, + &shrm->send_ac_msg_pend_notify_0); + } else { + shrm_common_tx_state = SHRM_IDLE; + shrm_restart_netdev(shrm->ndev); + } + } else { + dev_err(shrm->dev, "Invalid boot state\n"); + } + /* start timer here */ + hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), + HRTIMER_MODE_REL); + atomic_dec(&ac_sleep_disable_count); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void shm_ac_read_notif_1_tasklet(unsigned long tasklet_data) +{ + struct shrm_dev *shrm = (struct shrm_dev *)tasklet_data; + u32 writer_local_rptr; + u32 writer_local_wptr; + u32 shared_wptr; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown\n", + __func__); + return; + } + + /* Update writer_local_rptr(with shared_rptr) */ + update_ac_audio_local_rptr(shrm); + get_writer_pointers(AUDIO_CHANNEL, &writer_local_rptr, + &writer_local_wptr, &shared_wptr); + if (boot_state != BOOT_DONE) { + dev_err(shrm->dev, "Error Case in boot state\n"); + return; + } + if (writer_local_rptr != writer_local_wptr) { + shrm_audio_tx_state = SHRM_PTR_FREE; + queue_work(shrm->shm_audio_ch_wr_wq, + &shrm->send_ac_msg_pend_notify_1); + } else { + shrm_audio_tx_state = SHRM_IDLE; + } + /* start timer here */ + hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), + HRTIMER_MODE_REL); + atomic_dec(&ac_sleep_disable_count); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void shm_ca_sleep_req_work(struct work_struct *work) +{ + dev_dbg(shm_dev->dev, "%s:IRQ_PRCMU_CA_SLEEP\n", __func__); + + shrm_common_rx_state = SHRM_IDLE; + shrm_audio_rx_state = SHRM_IDLE; + + writel((1<intr_base + GOP_SET_REGISTER_BASE); + + hrtimer_start(&timer, ktime_set(0, 10*NSEC_PER_MSEC), + HRTIMER_MODE_REL); +#ifdef CONFIG_UX500_SUSPEND + suspend_unblock_sleep(); +#endif + atomic_dec(&ac_sleep_disable_count); +} + +void shm_ca_wake_req_work(struct work_struct *work) +{ + struct shrm_dev *shrm = container_of(work, + struct shrm_dev, shm_ca_wake_req); + + /* initialize the FIFO Variables */ + if (boot_state == BOOT_INIT) + shm_fifo_init(shrm); + + mutex_lock(&ac_state_mutex); + modem_request(shrm->modem); + mutex_unlock(&ac_state_mutex); + + /* send ca_wake_ack_interrupt to CMU */ + if (!get_host_accessport_val()) + BUG(); + writel((1<intr_base + GOP_SET_REGISTER_BASE); +} +#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET +static int shrm_modem_reset_sequence(void) +{ + int err; + unsigned long flags; + + /* + * disable irqs + * very much needed for user-space initiated + * modem-reset + */ + disable_irq_nosync(shm_dev->ac_read_notif_0_irq); + disable_irq_nosync(shm_dev->ac_read_notif_1_irq); + disable_irq_nosync(shm_dev->ca_msg_pending_notif_0_irq); + disable_irq_nosync(shm_dev->ca_msg_pending_notif_1_irq); + disable_irq_nosync(IRQ_PRCMU_CA_WAKE); + disable_irq_nosync(IRQ_PRCMU_CA_SLEEP); + + + /* update the boot_state */ + spin_lock_irqsave(&boot_lock, flags); + boot_state = BOOT_UNKNOWN; + + /* + * put a barrier over here to make sure boot_state is updated + * else, it is seen that some of already executing modem + * irqs or tasklets fail the protocol checks and will ultimately + * try to acces the modem causing system to hang. + * This is particularly seen with user-space initiated modem reset + */ + wmb(); + spin_unlock_irqrestore(&boot_lock, flags); + + hrtimer_cancel(&timer); + + /* + * keep the count to 0 so that we can bring down the line + * for normal ac-wake and ac-sleep logic + */ + atomic_set(&ac_sleep_disable_count, 0); + + /* workaround for MSR */ + queue_work(shm_dev->shm_ac_wake_wq, + &shm_dev->shm_ac_wake_req); + + /* stop network queue */ + shrm_stop_netdev(shm_dev->ndev); + + /* reset char device queues */ + shrm_char_reset_queues(shm_dev); + + /* reset protocol states */ + shrm_common_tx_state = SHRM_SLEEP_STATE; + shrm_common_rx_state = SHRM_SLEEP_STATE; + shrm_audio_tx_state = SHRM_SLEEP_STATE; + shrm_audio_rx_state = SHRM_SLEEP_STATE; + + /* set the msr flag */ + shm_dev->msr_flag = 1; + + /* multicast that modem is going to reset */ + err = nl_send_multicast_message(SHRM_NL_MOD_RESET, GFP_ATOMIC); + + /* reset the boot state */ + spin_lock_irqsave(&boot_lock, flags); + boot_state = BOOT_INIT; + spin_unlock_irqrestore(&boot_lock, flags); + + /* re-enable irqs */ + enable_irq(shm_dev->ac_read_notif_0_irq); + enable_irq(shm_dev->ac_read_notif_1_irq); + enable_irq(shm_dev->ca_msg_pending_notif_0_irq); + enable_irq(shm_dev->ca_msg_pending_notif_1_irq); + enable_irq(IRQ_PRCMU_CA_WAKE); + enable_irq(IRQ_PRCMU_CA_SLEEP); + + return err; +} +#endif + +static void shrm_modem_reset_callback(unsigned long irq) +{ + dev_err(shm_dev->dev, "Received mod_reset_req interrupt\n"); + +#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET + { + int err; + dev_info(shm_dev->dev, "Initiating Modem silent reset\n"); + + err = shrm_modem_reset_sequence(); + if (err) + dev_err(shm_dev->dev, + "Failed multicast of modem reset\n"); + } +#else + dev_info(shm_dev->dev, "Modem in reset loop, doing System reset\n"); + + /* Call the PRCMU reset API */ + prcmu_system_reset(SW_RESET_NO_ARGUMENT); +#endif +} + +DECLARE_TASKLET(shrm_sw_reset_callback, shrm_modem_reset_callback, + IRQ_PRCMU_MODEM_SW_RESET_REQ); + +static irqreturn_t shrm_prcmu_irq_handler(int irq, void *data) +{ + struct shrm_dev *shrm = data; + + switch (irq) { + case IRQ_PRCMU_CA_WAKE: +#ifdef CONFIG_UX500_SUSPEND + suspend_block_sleep(); +#endif + if (shrm->msr_flag) + atomic_set(&ac_sleep_disable_count, 0); + atomic_inc(&ac_sleep_disable_count); + queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_wake_req); + break; + case IRQ_PRCMU_CA_SLEEP: + queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_sleep_req); + break; + case IRQ_PRCMU_MODEM_SW_RESET_REQ: + tasklet_schedule(&shrm_sw_reset_callback); + break; + default: + dev_err(shrm->dev, "%s: => IRQ %d\n", __func__, irq); + return IRQ_NONE; + } + return IRQ_HANDLED; +} + +static void send_ac_msg_pend_notify_0_work(struct work_struct *work) +{ + struct shrm_dev *shrm = container_of(work, struct shrm_dev, + send_ac_msg_pend_notify_0); + + dev_dbg(shrm->dev, "%s IN\n", __func__); + update_ac_common_shared_wptr(shrm); + + mutex_lock(&ac_state_mutex); + atomic_inc(&ac_sleep_disable_count); + modem_request(shrm->modem); + mutex_unlock(&ac_state_mutex); + + if (!get_host_accessport_val()) + BUG(); + + /* Trigger AcMsgPendingNotification to CMU */ + writel((1<intr_base + GOP_SET_REGISTER_BASE); + + if (shrm_common_tx_state == SHRM_PTR_FREE) + shrm_common_tx_state = SHRM_PTR_BUSY; + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +static void send_ac_msg_pend_notify_1_work(struct work_struct *work) +{ + struct shrm_dev *shrm = container_of(work, struct shrm_dev, + send_ac_msg_pend_notify_1); + + dev_dbg(shrm->dev, "%s IN\n", __func__); + /* Update shared_wptr with writer_local_wptr) */ + update_ac_audio_shared_wptr(shrm); + + mutex_lock(&ac_state_mutex); + atomic_inc(&ac_sleep_disable_count); + modem_request(shrm->modem); + mutex_unlock(&ac_state_mutex); + + if (!get_host_accessport_val()) + BUG(); + + /* Trigger AcMsgPendingNotification to CMU */ + writel((1<intr_base + GOP_SET_REGISTER_BASE); + + if (shrm_audio_tx_state == SHRM_PTR_FREE) + shrm_audio_tx_state = SHRM_PTR_BUSY; + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void shm_nl_receive(struct sk_buff *skb) +{ + struct nlmsghdr *nlh = NULL; + int msg; + + dev_dbg(shm_dev->dev, "Received NL msg from user-space\n"); + + nlh = (struct nlmsghdr *)skb->data; + msg = *((int *)(NLMSG_DATA(nlh))); + switch (msg) { + case SHRM_NL_MOD_QUERY_STATE: + dev_info(shm_dev->dev, "mod-query-state from user-space\n"); + nl_send_unicast_message(nlh->nlmsg_pid); + break; + + case SHRM_NL_USER_MOD_RESET: + dev_info(shm_dev->dev, "user-space inited mod-reset-req\n"); + dev_info(shm_dev->dev, "PCRMU resets modem\n"); + prcmu_modem_reset(); + break; + + default: + dev_err(shm_dev->dev, "Invalid NL msg from user-space\n"); + break; + }; +} + +int shrm_protocol_init(struct shrm_dev *shrm, + received_msg_handler common_rx_handler, + received_msg_handler audio_rx_handler) +{ + int err; + + shm_dev = shrm; + boot_state = BOOT_INIT; + dev_info(shrm->dev, "IPC_ISA BOOT_INIT\n"); + rx_common_handler = common_rx_handler; + rx_audio_handler = audio_rx_handler; + atomic_set(&ac_sleep_disable_count, 0); + + hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + timer.function = callback; + + shrm->shm_common_ch_wr_wq = create_singlethread_workqueue + ("shm_common_channel_irq"); + if (!shrm->shm_common_ch_wr_wq) { + dev_err(shrm->dev, "failed to create work queue\n"); + return -ENOMEM; + } + shrm->shm_audio_ch_wr_wq = create_singlethread_workqueue + ("shm_audio_channel_irq"); + if (!shrm->shm_audio_ch_wr_wq) { + dev_err(shrm->dev, "failed to create work queue\n"); + err = -ENOMEM; + goto free_wq1; + } + shrm->shm_ac_wake_wq = create_singlethread_workqueue("shm_ac_wake_req"); + if (!shrm->shm_ac_wake_wq) { + dev_err(shrm->dev, "failed to create work queue\n"); + err = -ENOMEM; + goto free_wq2; + } + shrm->shm_ca_wake_wq = create_singlethread_workqueue("shm_ca_wake_req"); + if (!shrm->shm_ac_wake_wq) { + dev_err(shrm->dev, "failed to create work queue\n"); + err = -ENOMEM; + goto free_wq3; + } + shrm->shm_ac_sleep_wq = create_singlethread_workqueue + ("shm_ac_sleep_req"); + if (!shrm->shm_ac_sleep_wq) { + dev_err(shrm->dev, "failed to create work queue\n"); + err = -ENOMEM; + goto free_wq4; + } + INIT_WORK(&shrm->send_ac_msg_pend_notify_0, + send_ac_msg_pend_notify_0_work); + INIT_WORK(&shrm->send_ac_msg_pend_notify_1, + send_ac_msg_pend_notify_1_work); + INIT_WORK(&shrm->shm_ca_wake_req, shm_ca_wake_req_work); + INIT_WORK(&shrm->shm_ca_sleep_req, shm_ca_sleep_req_work); + INIT_WORK(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); + INIT_WORK(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); + + /* set tasklet data */ + shm_ca_0_tasklet.data = (unsigned long)shrm; + shm_ca_1_tasklet.data = (unsigned long)shrm; + + err = request_irq(IRQ_PRCMU_CA_SLEEP, shrm_prcmu_irq_handler, + IRQF_NO_SUSPEND, "ca-sleep", shrm); + if (err < 0) { + dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_SLEEP.\n"); + goto free_wq5; + } + + err = request_irq(IRQ_PRCMU_CA_WAKE, shrm_prcmu_irq_handler, + IRQF_NO_SUSPEND, "ca-wake", shrm); + if (err < 0) { + dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_WAKE.\n"); + goto drop2; + } + + err = request_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, shrm_prcmu_irq_handler, + IRQF_NO_SUSPEND, "modem-sw-reset-req", shrm); + if (err < 0) { + dev_err(shm_dev->dev, + "Failed alloc IRQ_PRCMU_MODEM_SW_RESET_REQ.\n"); + goto drop1; + } + +#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET + /* init netlink socket for user-space communication */ + shrm_nl_sk = netlink_kernel_create(NULL, NETLINK_SHRM, 1, + shm_nl_receive, NULL, THIS_MODULE); + + if (!shrm_nl_sk) { + dev_err(shm_dev->dev, "netlink socket creation failed\n"); + goto drop; + } +#endif + return 0; + +#ifdef CONFIG_U8500_SHRM_MODEM_SILENT_RESET +drop: + free_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, NULL); +#endif +drop1: + free_irq(IRQ_PRCMU_CA_WAKE, NULL); +drop2: + free_irq(IRQ_PRCMU_CA_SLEEP, NULL); +free_wq5: + destroy_workqueue(shrm->shm_ac_sleep_wq); +free_wq4: + destroy_workqueue(shrm->shm_ca_wake_wq); +free_wq3: + destroy_workqueue(shrm->shm_ac_wake_wq); +free_wq2: + destroy_workqueue(shrm->shm_audio_ch_wr_wq); +free_wq1: + destroy_workqueue(shrm->shm_common_ch_wr_wq); + return err; +} + +void shrm_protocol_deinit(struct shrm_dev *shrm) +{ + free_irq(IRQ_PRCMU_CA_SLEEP, NULL); + free_irq(IRQ_PRCMU_CA_WAKE, NULL); + free_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, NULL); + flush_scheduled_work(); + destroy_workqueue(shrm->shm_common_ch_wr_wq); + destroy_workqueue(shrm->shm_audio_ch_wr_wq); + destroy_workqueue(shrm->shm_ac_wake_wq); + destroy_workqueue(shrm->shm_ca_wake_wq); + destroy_workqueue(shrm->shm_ac_sleep_wq); + modem_put(shrm->modem); +} + +int get_ca_wake_req_state(void) +{ + return ((atomic_read(&ac_sleep_disable_count) > 0) || + modem_get_usage(shm_dev->modem)); +} + +irqreturn_t ca_wake_irq_handler(int irq, void *ctrlr) +{ + struct shrm_dev *shrm = ctrlr; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + /* initialize the FIFO Variables */ + if (boot_state == BOOT_INIT) + shm_fifo_init(shrm); + + dev_dbg(shrm->dev, "Inside ca_wake_irq_handler\n"); + + /* Clear the interrupt */ + writel((1 << GOP_CA_WAKE_REQ_BIT), + shrm->intr_base + GOP_CLEAR_REGISTER_BASE); + + /* send ca_wake_ack_interrupt to CMU */ + writel((1 << GOP_CA_WAKE_ACK_BIT), + shrm->intr_base + GOP_SET_REGISTER_BASE); + + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return IRQ_HANDLED; +} + + +irqreturn_t ac_read_notif_0_irq_handler(int irq, void *ctrlr) +{ + struct shrm_dev *shrm = ctrlr; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + shm_ac_read_0_tasklet.data = (unsigned long)shrm; + tasklet_schedule(&shm_ac_read_0_tasklet); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + /* Clear the interrupt */ + writel((1 << GOP_COMMON_AC_READ_NOTIFICATION_BIT), + shrm->intr_base + GOP_CLEAR_REGISTER_BASE); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return IRQ_HANDLED; +} + +irqreturn_t ac_read_notif_1_irq_handler(int irq, void *ctrlr) +{ + struct shrm_dev *shrm = ctrlr; + + dev_dbg(shrm->dev, "%s IN+\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + shm_ac_read_1_tasklet.data = (unsigned long)shrm; + tasklet_schedule(&shm_ac_read_1_tasklet); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + /* Clear the interrupt */ + writel((1 << GOP_AUDIO_AC_READ_NOTIFICATION_BIT), + shrm->intr_base + GOP_CLEAR_REGISTER_BASE); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return IRQ_HANDLED; +} + +irqreturn_t ca_msg_pending_notif_0_irq_handler(int irq, void *ctrlr) +{ + struct shrm_dev *shrm = ctrlr; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + tasklet_schedule(&shm_ca_0_tasklet); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + /* Clear the interrupt */ + writel((1 << GOP_COMMON_CA_MSG_PENDING_NOTIFICATION_BIT), + shrm->intr_base + GOP_CLEAR_REGISTER_BASE); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return IRQ_HANDLED; +} + +irqreturn_t ca_msg_pending_notif_1_irq_handler(int irq, void *ctrlr) +{ + struct shrm_dev *shrm = ctrlr; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + tasklet_schedule(&shm_ca_1_tasklet); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return IRQ_HANDLED; + } + + /* Clear the interrupt */ + writel((1<intr_base+GOP_CLEAR_REGISTER_BASE); + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return IRQ_HANDLED; + +} + +/** + * shm_write_msg() - write message to shared memory + * @shrm: pointer to the shrm device information structure + * @l2_header: L2 header + * @addr: pointer to the message + * @length: length of the message to be written + * + * This function is called from net or char interface driver write operation. + * Prior to calling this function the message is copied from the user space + * buffer to the kernel buffer. This function based on the l2 header routes + * the message to the respective channel and FIFO. Then makes a call to the + * fifo write function where the message is written to the physical device. + */ +int shm_write_msg(struct shrm_dev *shrm, u8 l2_header, + void *addr, u32 length) +{ + u8 channel = 0; + int ret; + + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (boot_state != BOOT_DONE) { + dev_err(shrm->dev, + "error after boot done call this fn\n"); + ret = -ENODEV; + goto out; + } + + if ((l2_header == L2_HEADER_ISI) || + (l2_header == L2_HEADER_RPC) || + (l2_header == L2_HEADER_SECURITY) || + (l2_header == L2_HEADER_COMMON_SIMPLE_LOOPBACK) || + (l2_header == L2_HEADER_COMMON_ADVANCED_LOOPBACK)) { + channel = 0; + if (shrm_common_tx_state == SHRM_SLEEP_STATE) + shrm_common_tx_state = SHRM_PTR_FREE; + else if (shrm_common_tx_state == SHRM_IDLE) + shrm_common_tx_state = SHRM_PTR_FREE; + + } else if ((l2_header == L2_HEADER_AUDIO) || + (l2_header == L2_HEADER_AUDIO_SIMPLE_LOOPBACK) || + (l2_header == L2_HEADER_AUDIO_ADVANCED_LOOPBACK)) { + if (shrm_audio_tx_state == SHRM_SLEEP_STATE) + shrm_audio_tx_state = SHRM_PTR_FREE; + else if (shrm_audio_tx_state == SHRM_IDLE) + shrm_audio_tx_state = SHRM_PTR_FREE; + + channel = 1; + } else { + ret = -ENODEV; + goto out; + } + ret = shm_write_msg_to_fifo(shrm, channel, l2_header, addr, length); + if (ret < 0) { + dev_err(shrm->dev, "write message to fifo failed\n"); + return ret; + } + /* + * notify only if new msg copied is the only unread one + * otherwise it means that reading process is ongoing + */ + if (is_the_only_one_unread_message(shrm, channel, length)) { + + /* Send Message Pending Noitication to CMT */ + if (channel == 0) + queue_work(shrm->shm_common_ch_wr_wq, + &shrm->send_ac_msg_pend_notify_0); + else + queue_work(shrm->shm_audio_ch_wr_wq, + &shrm->send_ac_msg_pend_notify_1); + + } + + dev_dbg(shrm->dev, "%s OUT\n", __func__); + return 0; + +out: + return ret; +} + +void ca_msg_read_notification_0(struct shrm_dev *shrm) +{ + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (get_ca_msg_0_read_notif_send() == 0) { + update_ca_common_shared_rptr(shrm); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + /* Trigger CaMsgReadNotification to CMU */ + writel((1 << GOP_COMMON_CA_READ_NOTIFICATION_BIT), + shrm->intr_base + GOP_SET_REGISTER_BASE); + set_ca_msg_0_read_notif_send(1); + shrm_common_rx_state = SHRM_PTR_BUSY; + } + + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +void ca_msg_read_notification_1(struct shrm_dev *shrm) +{ + dev_dbg(shrm->dev, "%s IN\n", __func__); + + if (get_ca_msg_1_read_notif_send() == 0) { + update_ca_audio_shared_rptr(shrm); + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + /* Trigger CaMsgReadNotification to CMU */ + writel((1<intr_base+GOP_SET_REGISTER_BASE); + set_ca_msg_1_read_notif_send(1); + shrm_audio_rx_state = SHRM_PTR_BUSY; + } + dev_dbg(shrm->dev, "%s OUT\n", __func__); +} + +/** + * receive_messages_common - receive common channnel msg from + * CMT(Cellular Mobile Terminal) + * @shrm: pointer to shrm device information structure + * + * The messages sent from CMT to APE are written to the respective FIFO + * and an interrupt is triggered by the CMT. This ca message pending + * interrupt calls this function. This function sends a read notification + * acknowledgement to the CMT and calls the common channel receive handler + * where the messsage is copied to the respective(ISI, RPC, SECURIT) queue + * based on the message l2 header. + */ +void receive_messages_common(struct shrm_dev *shrm) +{ + u8 l2_header; + u32 len; + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + l2_header = read_one_l2msg_common(shrm, recieve_common_msg, &len); + /* Send Recieve_Call_back to Upper Layer */ + if (!rx_common_handler) { + dev_err(shrm->dev, "common_rx_handler is Null\n"); + BUG(); + } + (*rx_common_handler)(l2_header, &recieve_common_msg, len, + shrm); + /* SendReadNotification */ + ca_msg_read_notification_0(shrm); + + while (read_remaining_messages_common()) { + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + l2_header = read_one_l2msg_common(shrm, recieve_common_msg, + &len); + /* Send Recieve_Call_back to Upper Layer */ + (*rx_common_handler)(l2_header, + &recieve_common_msg, len, + shrm); + } +} + +/** + * receive_messages_audio() - receive audio message from CMT + * @shrm: pointer to shrm device information structure + * + * The messages sent from CMT to APE are written to the respective FIFO + * and an interrupt is triggered by the CMT. This ca message pending + * interrupt calls this function. This function sends a read notification + * acknowledgement to the CMT and calls the common channel receive handler + * where the messsage is copied to the audio queue. + */ +void receive_messages_audio(struct shrm_dev *shrm) +{ + u8 l2_header; + u32 len; + + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + l2_header = read_one_l2msg_audio(shrm, recieve_audio_msg, &len); + /* Send Recieve_Call_back to Upper Layer */ + + if (!rx_audio_handler) { + dev_crit(shrm->dev, "audio_rx_handler is Null\n"); + BUG(); + } + (*rx_audio_handler)(l2_header, &recieve_audio_msg, + len, shrm); + + /* SendReadNotification */ + ca_msg_read_notification_1(shrm); + while (read_remaining_messages_audio()) { + if (check_modem_in_reset()) { + dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", + __func__); + return; + } + + l2_header = read_one_l2msg_audio(shrm, + recieve_audio_msg, &len); + /* Send Recieve_Call_back to Upper Layer */ + (*rx_audio_handler)(l2_header, + &recieve_audio_msg, len, + shrm); + } +} + +u8 get_boot_state() +{ + return boot_state; +} diff --git a/drivers/net/u8500_shrm.c b/drivers/net/u8500_shrm.c index 488f96f2c04..0e813bbb3cc 100644 --- a/drivers/net/u8500_shrm.c +++ b/drivers/net/u8500_shrm.c @@ -12,15 +12,15 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include /** * shrm_net_receive() - receive data and copy to user space buffer diff --git a/include/linux/modem/shrm/shrm.h b/include/linux/modem/shrm/shrm.h new file mode 100644 index 00000000000..6deeeb16ba8 --- /dev/null +++ b/include/linux/modem/shrm/shrm.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghavi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#ifndef __SHM_DRIVER_IF_H__ +#define __SHM_DRIVER_IF_H__ + +#include + +/* forward declaration */ +struct shrm_dev; + +typedef void (*rx_cb)(void *data, unsigned int length); +typedef void (*received_msg_handler)(unsigned char l2_header, + void *msg_ptr, unsigned int length, + struct shrm_dev *shrm); + +#endif diff --git a/include/linux/modem/shrm/shrm_config.h b/include/linux/modem/shrm/shrm_config.h new file mode 100644 index 00000000000..a82b35ef77b --- /dev/null +++ b/include/linux/modem/shrm/shrm_config.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghavi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#ifndef __SHRM_CONFIG_H +#define __SHRM_CONFIG_H + + +/* +Note: modem need to define IPC as a non-cacheable area. +In Cortex R4 MPU requires that base address of NC area is aligned on a +region-sized boundary.On modem side, only 1 NC area can be defined, hence +the whole IPC area must be defined as NC (at least). + +*/ + +/* cache line size = 32bytes*/ +#define SHM_CACHE_LINE 32 +#define SHM_PTR_SIZE 4 + +/* FIFO 0 address configuration */ +/* ---------------------------- */ +/* 128KB */ +#define SHM_FIFO_0_SIZE (128*1024) + + +/* == APE addresses == */ +#ifdef CONFIG_SHRM_V1_UPDATES_VERSION +#define SHM_IPC_BASE_AMCU 0x06F80000 +#else +#define SHM_IPC_BASE_AMCU 0x06000000 +#endif + +/* offset pointers */ +#define SHM_ACFIFO_0_WRITE_AMCU SHM_IPC_BASE_AMCU +#define SHM_ACFIFO_0_READ_AMCU (SHM_ACFIFO_0_WRITE_AMCU + SHM_PTR_SIZE) +#define SHM_CAFIFO_0_WRITE_AMCU (SHM_ACFIFO_0_WRITE_AMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_0_READ_AMCU (SHM_CAFIFO_0_WRITE_AMCU + SHM_PTR_SIZE) +/* FIFO start */ +#define SHM_ACFIFO_0_START_AMCU (SHM_CAFIFO_0_WRITE_AMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_0_START_AMCU (SHM_ACFIFO_0_START_AMCU + SHM_FIFO_0_SIZE) + + +/* == CMT addresses ==*/ +#define SHM_IPC_BASE_CMCU (SHM_IPC_BASE_AMCU+0x08000000) +/* offset pointers */ +#define SHM_ACFIFO_0_WRITE_CMCU SHM_IPC_BASE_CMCU +#define SHM_ACFIFO_0_READ_CMCU (SHM_ACFIFO_0_WRITE_CMCU + SHM_PTR_SIZE) +#define SHM_CAFIFO_0_WRITE_CMCU (SHM_ACFIFO_0_WRITE_CMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_0_READ_CMCU (SHM_CAFIFO_0_WRITE_CMCU + SHM_PTR_SIZE) +/* FIFO*/ +#define SHM_ACFIFO_0_START_CMCU (SHM_CAFIFO_0_WRITE_CMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_0_START_CMCU (SHM_ACFIFO_0_START_CMCU + SHM_FIFO_0_SIZE) + + +/* ADSP addresses*/ +#define SHM_ACFIFO_0_START_ADSP 0x0 +#define SHM_CAFIFO_0_START_ADSP 0x0 +#define SHM_ACFIFO_0_WRITE_ADSP 0x0 +#define SHM_ACFIFO_0_READ_ADSP 0x0 +#define SHM_CAFIFO_0_WRITE_ADSP 0x0 +#define SHM_CAFIFO_0_READ_ADSP 0x0 + +/* FIFO 1 address configuration */ +/* ---------------------------- */ + + +/* FIFO 1 - 4K */ +#define SHM_FIFO_1_SIZE (4*1024) + + +/* == APE addresses == */ +#define SHM_ACFIFO_1_WRITE_AMCU (SHM_CAFIFO_0_START_AMCU + SHM_FIFO_0_SIZE) +#define SHM_ACFIFO_1_READ_AMCU (SHM_ACFIFO_1_WRITE_AMCU + SHM_PTR_SIZE) +#define SHM_CAFIFO_1_WRITE_AMCU (SHM_ACFIFO_1_WRITE_AMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_1_READ_AMCU (SHM_CAFIFO_1_WRITE_AMCU + SHM_PTR_SIZE) +/* FIFO*/ +#define SHM_ACFIFO_1_START_AMCU (SHM_CAFIFO_1_WRITE_AMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_1_START_AMCU (SHM_ACFIFO_1_START_AMCU + SHM_FIFO_1_SIZE) + + +/* == CMT addresses ==*/ +#define SHM_ACFIFO_1_WRITE_CMCU (SHM_CAFIFO_0_START_CMCU + SHM_FIFO_0_SIZE) +#define SHM_ACFIFO_1_READ_CMCU (SHM_ACFIFO_1_WRITE_CMCU + SHM_PTR_SIZE) +#define SHM_CAFIFO_1_WRITE_CMCU (SHM_ACFIFO_1_WRITE_CMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_1_READ_CMCU (SHM_CAFIFO_1_WRITE_CMCU + SHM_PTR_SIZE) +/* FIFO1 start */ +#define SHM_ACFIFO_1_START_CMCU (SHM_CAFIFO_1_WRITE_CMCU + SHM_CACHE_LINE) +#define SHM_CAFIFO_1_START_CMCU (SHM_ACFIFO_1_START_CMCU + SHM_FIFO_1_SIZE) + + +/* ADSP addresses*/ +#define SHM_ACFIFO_1_START_ADSP 0x0 +#define SHM_CAFIFO_1_START_ADSP 0x0 +#define SHM_ACFIFO_1_WRITE_ADSP 0x0 +#define SHM_ACFIFO_1_READ_ADSP 0x0 +#define SHM_CAFIFO_1_WRITE_ADSP 0x0 +#define SHM_CAFIFO_1_READ_ADSP 0x0 + + +#define U8500_SHM_FIFO_APE_COMMON_BASE (SHM_ACFIFO_0_START_AMCU) +#define U8500_SHM_FIFO_CMT_COMMON_BASE (SHM_CAFIFO_0_START_AMCU) +#define U8500_SHM_FIFO_APE_AUDIO_BASE (SHM_ACFIFO_1_START_AMCU) +#define U8500_SHM_FIFO_CMT_AUDIO_BASE (SHM_CAFIFO_1_START_AMCU) + +#endif /* __SHRM_CONFIG_H */ diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h new file mode 100644 index 00000000000..f662a0c4533 --- /dev/null +++ b/include/linux/modem/shrm/shrm_driver.h @@ -0,0 +1,202 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghavi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#ifndef __SHRM_DRIVER_H__ +#define __SHRM_DRIVER_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ISA_DEVICES 6 + +#define BOOT_INIT (0) +#define BOOT_INFO_SYNC (1) +#define BOOT_DONE (2) +#define BOOT_UNKNOWN (3) + +/** + * struct shrm_dev - shrm device information + * @ca_wake_irq: CMT wake interrupt number + * @ac_read_notif_0_irq: ape-cmt common channel read notify interrupt + * @ac_read_notif_1_irq: ape-cmt audio channel read notify interrupt + * @ca_msg_pending_notif_0_irq: cmt-ape common channel msg pending interrupt + * @ca_msg_pending_notif_1_irq: cmt-ape audio channel msg pending interrupt + * @intr_base: interrupt base register address + * @ape_common_fifo_base: ape side common channel fifo base addr + * @ape_audio_fifo_base: ape side audio channel fifo base addr + * @cmt_common_fifo_base: cmt side common channel fifo base addr + * @cmt_audio_fifo_base: cmt side audio channel fifo base addr + * @ape_common_fifo_base_phy: physical addr of ape common fifo + * @ape_audio_fifo_base_phy: physical addr of ape audio fifo + * @cmt_common_fifo_base_phy: physical addr of cmt common fifo + * @cmt_audio_fifo_base_phy: physical addr of cmt audio fifo + * @ape_common_fifo_size: ape side common channel fifo size + * @ape_audio_fifo_size: ape side audio channel fifo size + * @cmt_common_fifo_size: cmt side common channel fifo size + * @cmt_audio_fifo_size: cmt side audio channel fifo size + * @netdev_flag_up: flag to indicate up/down of netwok device + * @msr_flag: flag to check on-going MSR sequence + * @ac_common_shared_wptr: ape-cmt common channel write pointer + * @ac_common_shared_rptr: ape-cmt common channel read pointer + * @ca_common_shared_wptr: cmt-ape common channel write pointer + * @ca_common_shared_rptr: cmt-ape common channel read pointer + * @ac_audio_shared_wptr: ape-cmt audio channel write pointer + * @ac_audio_shared_rptr: ape-cmt audio channel read pointer + * @ca_audio_shared_wptr: cmt-ape audio channel write pointer + * @ca_audio_shared_rptr: cmt-ape audio channel read pointer + * @dev: pointer to the driver device + * @ndev: pointer to the network device structure + * @isa_context: pointer to t_isa_driver_sontext dtructure + * @shm_common_ch_wr_wq: work queue for writing to common channel + * @shm_audio_ch_wr_wq: workqueue for writing to audio channel + * @shm_ac_wake_wq: workqueue for receiving ape-cmt wake requests + * @shm_ca_wake_wq: workqueue for receiving cmt-ape wake requests + * @shm_ac_sleep_wq: workqueue for recieving ape-cmt sleep requests + * @send_ac_msg_pend_notify_0: work for handling pending message on common + * channel + * @send_ac_msg_pend_notify_1: work for handling pending message on audio + * channel + * @shm_ac_wake_req: work to send ape-cmt wake request + * @shm_ca_wake_req: work to send cmt-ape wake request + * @shm_ca_sleep_req: work to send cmt-ape sleep request + * @shm_ac_sleep_req: work to send ape-cmt sleep request + */ +struct shrm_dev { + u8 ca_wake_irq; + u8 ac_read_notif_0_irq; + u8 ac_read_notif_1_irq; + u8 ca_msg_pending_notif_0_irq; + u8 ca_msg_pending_notif_1_irq; + void __iomem *intr_base; + void __iomem *ape_common_fifo_base; + void __iomem *ape_audio_fifo_base; + void __iomem *cmt_common_fifo_base; + void __iomem *cmt_audio_fifo_base; + + u32 *ape_common_fifo_base_phy; + u32 *ape_audio_fifo_base_phy; + u32 *cmt_common_fifo_base_phy; + u32 *cmt_audio_fifo_base_phy; + + int ape_common_fifo_size; + int ape_audio_fifo_size; + int cmt_common_fifo_size; + int cmt_audio_fifo_size; + int netdev_flag_up; + int msr_flag; + + void __iomem *ac_common_shared_wptr; + void __iomem *ac_common_shared_rptr; + void __iomem *ca_common_shared_wptr; + void __iomem *ca_common_shared_rptr; + + void __iomem *ac_audio_shared_wptr; + void __iomem *ac_audio_shared_rptr; + void __iomem *ca_audio_shared_wptr; + void __iomem *ca_audio_shared_rptr; + + struct device *dev; + struct net_device *ndev; + struct modem *modem; + struct isa_driver_context *isa_context; + struct workqueue_struct *shm_common_ch_wr_wq; + struct workqueue_struct *shm_audio_ch_wr_wq; + struct workqueue_struct *shm_ac_wake_wq; + struct workqueue_struct *shm_ca_wake_wq; + struct workqueue_struct *shm_ac_sleep_wq; + struct work_struct send_ac_msg_pend_notify_0; + struct work_struct send_ac_msg_pend_notify_1; + struct work_struct shm_ac_wake_req; + struct work_struct shm_ca_wake_req; + struct work_struct shm_ca_sleep_req; + struct work_struct shm_ac_sleep_req; +}; + +/** + * struct queue_element - information to add an element to queue + * @entry: list entry + * @offset: message offset + * @size: message size + * @no: total number of messages + */ +struct queue_element { + struct list_head entry; + u32 offset; + u32 size; + u32 no; +}; + +/** + * struct message_queue - ISI, RPC, AUDIO, SECURITY message queue information + * @fifo_base: pointer to the respective fifo base + * @size: size of the data to be read + * @readptr: fifo read pointer + * @writeptr: fifo write pointer + * @no: total number of messages + * @update_lock: spinlock for protecting the queue read operation + * @q_rp: queue write pointer + * @wq_readable: wait queue head + * @msg_list: message list + * @shrm: pointer to shrm device information structure + */ +struct message_queue { + u8 *fifo_base; + u32 size; + u32 readptr; + u32 writeptr; + u32 no; + spinlock_t update_lock; + atomic_t q_rp; + wait_queue_head_t wq_readable; + struct list_head msg_list; + struct shrm_dev *shrm; +}; + +/** + * struct isadev_context - shrm char interface context + * @dl_queue: structre to store the queue related info + * @device_id: message id(ISI, RPC, AUDIO, SECURITY) + * @addr: device addresses. + */ +struct isadev_context { + struct message_queue dl_queue; + u8 device_id; + void *addr; +}; + +/** + * struct isa_driver_context - shrm char interface device information + * @is_open: flag to check the usage of queue + * @isadev: pointer to struct t_isadev_context + * @common_tx: spinlock for protecting common channel + * @tx_audio_mutex: mutex for protecting audio channel + * @cdev: character device structre + * @shm_class: pointer to the class structure + */ +struct isa_driver_context { + atomic_t is_open[ISA_DEVICES]; + struct isadev_context *isadev; + spinlock_t common_tx; + struct mutex tx_audio_mutex; + struct cdev cdev; + struct class *shm_class; +}; + +#endif diff --git a/include/linux/modem/shrm/shrm_net.h b/include/linux/modem/shrm/shrm_net.h new file mode 100644 index 00000000000..a97b276ee15 --- /dev/null +++ b/include/linux/modem/shrm/shrm_net.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) ST-Ericsson SA 2009 + * + * Author: Kumar Sanghvi for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#ifndef __SHRM_NET_H +#define __SHRM_NET_H + +#define SHRM_HLEN 1 +#define PHONET_ALEN 1 + +#define PN_PIPE 0xD9 +#define PN_DEV_HOST 0x00 +#define PN_LINK_ADDR 0x26 +#define PN_TX_QUEUE_LEN 3 + +#define RESOURCE_ID_INDEX 3 +#define SRC_OBJ_INDEX 7 +#define MSG_ID_INDEX 9 +#define PIPE_HDL_INDEX 10 +#define NETLINK_SHRM 20 + +/** + * struct shrm_net_iface_priv - shrm net interface device information + * @shrm_device: pointer to the shrm device information structure + * @iface_num: flag used to indicate the up/down of netdev + */ +struct shrm_net_iface_priv { + struct shrm_dev *shrm_device; + unsigned int iface_num; +}; + +int shrm_register_netdev(struct shrm_dev *shrm_dev_data); +int shrm_net_receive(struct net_device *dev); +int shrm_suspend_netdev(struct net_device *dev); +int shrm_resume_netdev(struct net_device *dev); +int shrm_stop_netdev(struct net_device *dev); +int shrm_restart_netdev(struct net_device *dev); +int shrm_start_netdev(struct net_device *dev); +void shrm_unregister_netdev(struct shrm_dev *shrm_dev_data); + +#endif /* __SHRM_NET_H */ diff --git a/include/linux/modem/shrm/shrm_private.h b/include/linux/modem/shrm/shrm_private.h new file mode 100644 index 00000000000..2063f6d6e8e --- /dev/null +++ b/include/linux/modem/shrm/shrm_private.h @@ -0,0 +1,181 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Biju Das for ST-Ericsson + * Author: Kumar Sanghavi for ST-Ericsson + * Author: Arun Murthy for ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + */ + +#ifndef __SHRM_PRIVATE_INCLUDED +#define __SHRM_PRIVATE_INCLUDED + +#include +#include +#include +#include + +#define GOP_OUTPUT_REGISTER_BASE (0x0) +#define GOP_SET_REGISTER_BASE (0x4) +#define GOP_CLEAR_REGISTER_BASE (0x8) +#define GOP_TOGGLE_REGISTER_BASE (0xc) + + +#define GOP_AUDIO_AC_READ_NOTIFICATION_BIT (0) +#define GOP_AUDIO_CA_MSG_PENDING_NOTIFICATION_BIT (1) +#define GOP_COMMON_AC_READ_NOTIFICATION_BIT (2) +#define GOP_COMMON_CA_MSG_PENDING_NOTIFICATION_BIT (3) +#define GOP_CA_WAKE_REQ_BIT (7) +#define GOP_AUDIO_CA_READ_NOTIFICATION_BIT (23) +#define GOP_AUDIO_AC_MSG_PENDING_NOTIFICATION_BIT (24) +#define GOP_COMMON_CA_READ_NOTIFICATION_BIT (25) +#define GOP_COMMON_AC_MSG_PENDING_NOTIFICATION_BIT (26) +#define GOP_CA_WAKE_ACK_BIT (27) + +#define L2_MSG_MAPID_OFFSET (24) +#define L1_MSG_MAPID_OFFSET (28) + +#define SHRM_SLEEP_STATE (0) +#define SHRM_PTR_FREE (1) +#define SHRM_PTR_BUSY (2) +#define SHRM_IDLE (3) + +#define ISI_MESSAGING (0) +#define RPC_MESSAGING (1) +#define AUDIO_MESSAGING (2) +#define SECURITY_MESSAGING (3) +#define COMMON_LOOPBACK_MESSAGING (0xC0) +#define AUDIO_LOOPBACK_MESSAGING (0x80) + +#define COMMON_CHANNEL 0 +#define AUDIO_CHANNEL 1 + +typedef void (*MSG_PENDING_NOTIF)(const u32 Wptr); + +/** + * struct fifo_write_params - parameters used for FIFO write operation. + * @writer_local_rptr: pointer to local read buffer + * @writer_local_wptr: pointer to local write buffer + * @shared_wptr: write pointer shared by cmt and ape + * @shared_rptr: read pointer shared by cmt and ape + * @availablesize: available memory in fifo + * @end_addr_fifo: fifo end addr + * @fifo_virtual_addr: fifo virtual addr + * @fifo_update_lock: spin lock to update fifo. + * + * On writting a message to FIFO the same has to be read by the modem before + * writing the next message to the FIFO. In oder to over come this a local + * write and read pointer is used for internal purpose. + */ +struct fifo_write_params { + u32 writer_local_rptr; + u32 writer_local_wptr; + u32 shared_wptr; + u32 shared_rptr; + u32 availablesize; + u32 end_addr_fifo; + u32 *fifo_virtual_addr; + spinlock_t fifo_update_lock; +} ; + +/** + * struct fifo_read_params - parameters used for FIFO read operation + * @reader_local_rptr: pointer to local read buffer + * @reader_local_wptr: pointer to local write buffer + * @shared_wptr: write pointer shared by cmt and ape + * @shared_rptr: read pointer shared by cmt and ape + * @availablesize: available memory in fifo + * @end_addr_fifo: fifo end add + * @fifo_virtual_addr: fifo virtual addr + */ +struct fifo_read_params{ + u32 reader_local_rptr; + u32 reader_local_wptr; + u32 shared_wptr; + u32 shared_rptr; + u32 availablesize; + u32 end_addr_fifo; + u32 *fifo_virtual_addr; + +} ; + +int shrm_protocol_init(struct shrm_dev *shrm, + received_msg_handler common_rx_handler, + received_msg_handler audio_rx_handler); +void shrm_protocol_deinit(struct shrm_dev *shrm); +void shm_fifo_init(struct shrm_dev *shrm); +int shm_write_msg_to_fifo(struct shrm_dev *shrm, u8 channel, + u8 l2header, void *addr, u32 length); +int shm_write_msg(struct shrm_dev *shrm, + u8 l2_header, void *addr, u32 length); + +u8 is_the_only_one_unread_message(struct shrm_dev *shrm, + u8 channel, u32 length); +u8 read_remaining_messages_common(void); +u8 read_remaining_messages_audio(void); +u8 read_one_l2msg_audio(struct shrm_dev *shrm, + u8 *p_l2_msg, u32 *p_len); +u8 read_one_l2msg_common(struct shrm_dev *shrm, + u8 *p_l2_msg, u32 *p_len); +void receive_messages_common(struct shrm_dev *shrm); +void receive_messages_audio(struct shrm_dev *shrm); + +void update_ac_common_local_rptr(struct shrm_dev *shrm); +void update_ac_audio_local_rptr(struct shrm_dev *shrm); +void update_ca_common_local_wptr(struct shrm_dev *shrm); +void update_ca_audio_local_wptr(struct shrm_dev *shrm); +void update_ac_common_shared_wptr(struct shrm_dev *shrm); +void update_ac_audio_shared_wptr(struct shrm_dev *shrm); +void update_ca_common_shared_rptr(struct shrm_dev *shrm); +void update_ca_audio_shared_rptr(struct shrm_dev *shrm); + + +void get_writer_pointers(u8 msg_type, u32 *WriterLocalRptr, \ + u32 *WriterLocalWptr, u32 *SharedWptr); +void get_reader_pointers(u8 msg_type, u32 *ReaderLocalRptr, \ + u32 *ReaderLocalWptr, u32 *SharedRptr); +u8 read_boot_info_req(struct shrm_dev *shrm, + u32 *pConfig, + u32 *pVersion); +void write_boot_info_resp(struct shrm_dev *shrm, u32 Config, + u32 Version); + +void send_ac_msg_pending_notification_0(struct shrm_dev *shrm); +void send_ac_msg_pending_notification_1(struct shrm_dev *shrm); +void ca_msg_read_notification_0(struct shrm_dev *shrm); +void ca_msg_read_notification_1(struct shrm_dev *shrm); + +void set_ca_msg_0_read_notif_send(u8 val); +u8 get_ca_msg_0_read_notif_send(void); +void set_ca_msg_1_read_notif_send(u8 val); +u8 get_ca_msg_1_read_notif_send(void); + +irqreturn_t ca_wake_irq_handler(int irq, void *ctrlr); +irqreturn_t ac_read_notif_0_irq_handler(int irq, void *ctrlr); +irqreturn_t ac_read_notif_1_irq_handler(int irq, void *ctrlr); +irqreturn_t ca_msg_pending_notif_0_irq_handler(int irq, void *ctrlr); +irqreturn_t ca_msg_pending_notif_1_irq_handler(int irq, void *ctrlr); + +void shm_ca_msgpending_0_tasklet(unsigned long); +void shm_ca_msgpending_1_tasklet(unsigned long); +void shm_ac_read_notif_0_tasklet(unsigned long); +void shm_ac_read_notif_1_tasklet(unsigned long); +void shm_ca_wake_req_tasklet(unsigned long); + +u8 get_boot_state(void); + +int get_ca_wake_req_state(void); + +/* shrm character interface */ +int isa_init(struct shrm_dev *shrm); +void isa_exit(struct shrm_dev *shrm); +int add_msg_to_queue(struct message_queue *q, u32 size); +ssize_t isa_read(struct file *filp, char __user *buf, size_t len, + loff_t *ppos); +int get_size_of_new_msg(struct message_queue *q); +int remove_msg_from_queue(struct message_queue *q); +void shrm_char_reset_queues(struct shrm_dev *shrm); +int shrm_get_cdev_index(u8 l2_header); +int shrm_get_cdev_l2header(u8 idx); + +#endif -- cgit v1.2.3 From 509e35ab0d844f024c32fc7fe2f510d2407d98ab Mon Sep 17 00:00:00 2001 From: Kumar Sanghvi Date: Thu, 19 May 2011 14:14:52 +0530 Subject: u8500: shrm: Add support for CIQ L2Mux channel Adds support for the CIQ L2Mux channel ST-Ericsson ID: CR334399 Change-Id: Ib189a1090c11b3537fafd6f3b9bc8becf1c63c2f Signed-off-by: Kumar Sanghvi Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/23373 Reviewed-by: QATEST Tested-by: Sean SANDOVAL Reviewed-by: Srinidhi KASAGAR --- drivers/char/shrm_char.c | 24 +++++++++++++++++++++--- drivers/modem/shrm/shrm_protocol.c | 4 +++- include/linux/modem/shrm/shrm_driver.h | 2 +- include/linux/modem/shrm/shrm_private.h | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/drivers/char/shrm_char.c b/drivers/char/shrm_char.c index 31f1fedd704..fa44b469b98 100644 --- a/drivers/char/shrm_char.c +++ b/drivers/char/shrm_char.c @@ -25,8 +25,8 @@ #define NAME "IPC_ISA" -/* L2 header for common loopback device is 0xc0 and hence 0xc0+1 = 193*/ -#define MAX_L2_HEADERS 193 +/* L2 header for ciq device is 0xc3 and hence 0xc3+1 = 196*/ +#define MAX_L2_HEADERS 196 #define SIZE_OF_FIFO (512*1024) @@ -49,6 +49,7 @@ static struct map_device map_dev[] = { {SECURITY_MESSAGING, 3, "sec"}, {COMMON_LOOPBACK_MESSAGING, 4, "common_loopback"}, {AUDIO_LOOPBACK_MESSAGING, 5, "audio_loopback"}, + {CIQ_MESSAGING, 6, "ciq"}, }; /* @@ -483,6 +484,10 @@ ssize_t isa_write(struct file *filp, const char __user *buf, dev_dbg(shrm->dev, "Audio loopback\n"); addr = isadev->addr; break; + case CIQ_MESSAGING: + dev_dbg(shrm->dev, "CIQ\n"); + addr = isadev->addr; + break; default: dev_dbg(shrm->dev, "Wrong device\n"); return -EFAULT; @@ -637,6 +642,10 @@ static int isa_close(struct inode *inode, struct file *filp) kfree(isadev->addr); dev_info(shrm->dev, "Close AUDIO_LOOPBACK_MESSAGING Device\n"); break; + case CIQ_MESSAGING: + kfree(isadev->addr); + dev_info(shrm->dev, "Close CIQ_MESSAGING Device\n"); + break; default: dev_info(shrm->dev, "No such device present\n"); mutex_unlock(&isa_lock); @@ -683,7 +692,8 @@ static int isa_open(struct inode *inode, struct file *filp) (m != AUDIO_LOOPBACK_MESSAGING) && (m != COMMON_LOOPBACK_MESSAGING) && (m != AUDIO_MESSAGING) && - (m != SECURITY_MESSAGING)) { + (m != SECURITY_MESSAGING) && + (m != CIQ_MESSAGING)) { dev_err(shrm->dev, "No such device present\n"); mutex_unlock(&isa_lock); return -ENODEV; @@ -729,6 +739,14 @@ static int isa_open(struct inode *inode, struct file *filp) } dev_info(shrm->dev, "Open AUDIO_LOOPBACK_MESSAGING Device\n"); break; + case CIQ_MESSAGING: + isadev->addr = kzalloc(10 * 1024, GFP_KERNEL); + if (!isadev->addr) { + mutex_unlock(&isa_lock); + return -ENOMEM; + } + dev_info(shrm->dev, "Open CIQ_MESSAGING Device\n"); + break; }; mutex_unlock(&isa_lock); diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index 99a58aa6f71..14fe28ca267 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -29,6 +29,7 @@ #define L2_HEADER_COMMON_ADVANCED_LOOPBACK 0xC1 #define L2_HEADER_AUDIO_SIMPLE_LOOPBACK 0x80 #define L2_HEADER_AUDIO_ADVANCED_LOOPBACK 0x81 +#define L2_HEADER_CIQ 0xC3 #define MAX_PAYLOAD 1024 static u8 boot_state = BOOT_INIT; @@ -993,7 +994,8 @@ int shm_write_msg(struct shrm_dev *shrm, u8 l2_header, (l2_header == L2_HEADER_RPC) || (l2_header == L2_HEADER_SECURITY) || (l2_header == L2_HEADER_COMMON_SIMPLE_LOOPBACK) || - (l2_header == L2_HEADER_COMMON_ADVANCED_LOOPBACK)) { + (l2_header == L2_HEADER_COMMON_ADVANCED_LOOPBACK) || + (l2_header == L2_HEADER_CIQ)) { channel = 0; if (shrm_common_tx_state == SHRM_SLEEP_STATE) shrm_common_tx_state = SHRM_PTR_FREE; diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index f662a0c4533..e7b87005565 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -24,7 +24,7 @@ #include #include -#define ISA_DEVICES 6 +#define ISA_DEVICES 7 #define BOOT_INIT (0) #define BOOT_INFO_SYNC (1) diff --git a/include/linux/modem/shrm/shrm_private.h b/include/linux/modem/shrm/shrm_private.h index 2063f6d6e8e..888a7c200fd 100644 --- a/include/linux/modem/shrm/shrm_private.h +++ b/include/linux/modem/shrm/shrm_private.h @@ -46,6 +46,7 @@ #define SECURITY_MESSAGING (3) #define COMMON_LOOPBACK_MESSAGING (0xC0) #define AUDIO_LOOPBACK_MESSAGING (0x80) +#define CIQ_MESSAGING (0xC3) #define COMMON_CHANNEL 0 #define AUDIO_CHANNEL 1 -- cgit v1.2.3 From 74d2fc32aa4b51a735764414e04eaaef56746a1a Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Mon, 10 Oct 2011 14:55:06 +0530 Subject: u8500-shrm: Initiate MSR in case of serious bug During APE-Modem communication, for some reasson if software or hardware fails, instead of calling kernel function BUG() and halting the system making it no more useful until reboot, initiate a MSR. ST-Ericsson Linux next: NA ST-Ericsson ID: 366150 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I59e93b338c3242b506be7775487be065421022b8 Signed-off-by: Arun Murthy Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/33416 Reviewed-by: Bibek BASU Reviewed-by: QABUILD Reviewed-by: Magnus TEMPLING Reviewed-by: Rickard EVERTSSON Reviewed-by: Srinidhi KASAGAR --- drivers/modem/shrm/shrm_fifo.c | 14 +++++++++++--- drivers/modem/shrm/shrm_protocol.c | 29 ++++++++++++++++++++++------- include/linux/modem/shrm/shrm_driver.h | 2 ++ 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/drivers/modem/shrm/shrm_fifo.c b/drivers/modem/shrm/shrm_fifo.c index 1f0f9202e51..57da56f4905 100644 --- a/drivers/modem/shrm/shrm_fifo.c +++ b/drivers/modem/shrm/shrm_fifo.c @@ -11,6 +11,7 @@ #include #include #include +#include #define L1_BOOT_INFO_REQ 1 #define L1_BOOT_INFO_RESP 2 @@ -109,7 +110,10 @@ u8 read_boot_info_req(struct shrm_dev *shrm, if (msgtype != L1_BOOT_INFO_REQ) { dev_err(shrm->dev, "Read_Boot_Info_Req Fatal ERROR\n"); dev_err(shrm->dev, "Received msgtype is %d\n", msgtype); - BUG(); + dev_info(shrm->dev, "Initiating a modem reset\n"); + queue_work(shrm->shm_ac_wake_wq, + &shrm->shm_mod_reset_req); + return 0; } *config = (header >> CONFIG_OFFSET) & MASK_0_15_BIT; *version = header & MASK_0_15_BIT; @@ -416,7 +420,9 @@ u8 read_one_l2msg_common(struct shrm_dev *shrm, fifo->end_addr_fifo); /* Fatal ERROR - should never happens */ dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); - BUG(); + dev_info(shrm->dev, "Initiating a modem reset\n"); + queue_work(shrm->shm_ac_wake_wq, + &shrm->shm_mod_reset_req); } if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { l2_header = (*((u32 *)fifo->fifo_virtual_addr)); @@ -522,7 +528,9 @@ u8 read_one_l2msg_audio(struct shrm_dev *shrm, dev_info(shrm->dev, "Received msgtype is %d\n", msgtype); /* Fatal ERROR - should never happens */ dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); - BUG(); + dev_info(shrm->dev, "Initiating a modem reset\n"); + queue_work(shrm->shm_ac_wake_wq, + &shrm->shm_mod_reset_req); } if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { l2_header = (*((u32 *)fifo->fifo_virtual_addr)); diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index 50443e4803a..e34a88676be 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -70,6 +70,11 @@ enum shrm_nl { SHRM_NL_STATUS_MOD_OFFLINE, }; +void shm_mod_reset_req_work(struct work_struct *work) +{ + prcmu_modem_reset(); +} + static void shm_ac_sleep_req_work(struct work_struct *work) { mutex_lock(&ac_state_mutex); @@ -264,7 +269,7 @@ void shm_ca_msgpending_0_tasklet(unsigned long tasklet_data) if (!read_boot_info_req(shrm, &config, &version)) { dev_err(shrm->dev, "Unable to read boot state\n"); - BUG(); + return; } /* SendReadNotification */ ca_msg_read_notification_0(shrm); @@ -468,8 +473,11 @@ void shm_ca_wake_req_work(struct work_struct *work) mutex_unlock(&ac_state_mutex); /* send ca_wake_ack_interrupt to CMU */ - if (!get_host_accessport_val()) - BUG(); + if (!get_host_accessport_val()) { + dev_crit(shrm->dev, "get_host_accessport failed\n"); + dev_info(shrm->dev, "Initiating a modem reset\n"); + prcmu_modem_reset(); + } writel((1<intr_base + GOP_SET_REGISTER_BASE); } @@ -611,8 +619,11 @@ static void send_ac_msg_pend_notify_0_work(struct work_struct *work) modem_request(shrm->modem); mutex_unlock(&ac_state_mutex); - if (!get_host_accessport_val()) - BUG(); + if (!get_host_accessport_val()) { + dev_crit(shrm->dev, "get_host_accessport failed\n"); + dev_info(shrm->dev, "Initiating a modem reset\n"); + prcmu_modem_reset(); + } /* Trigger AcMsgPendingNotification to CMU */ writel((1<modem); mutex_unlock(&ac_state_mutex); - if (!get_host_accessport_val()) - BUG(); + if (!get_host_accessport_val()) { + dev_crit(shrm->dev, "get_host_accessport failed\n"); + dev_info(shrm->dev, "Initiating a modem reset\n"); + prcmu_modem_reset(); + } /* Trigger AcMsgPendingNotification to CMU */ writel((1<shm_ca_sleep_req, shm_ca_sleep_req_work); INIT_WORK(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); INIT_WORK(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); + INIT_WORK(&shrm->shm_mod_reset_req, shm_mod_reset_req_work); /* set tasklet data */ shm_ca_0_tasklet.data = (unsigned long)shrm; diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index e7b87005565..8fa215571eb 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -77,6 +77,7 @@ * @shm_ca_wake_req: work to send cmt-ape wake request * @shm_ca_sleep_req: work to send cmt-ape sleep request * @shm_ac_sleep_req: work to send ape-cmt sleep request + * @shm_mod_reset_req: work to send a reset request to modem */ struct shrm_dev { u8 ca_wake_irq; @@ -127,6 +128,7 @@ struct shrm_dev { struct work_struct shm_ca_wake_req; struct work_struct shm_ca_sleep_req; struct work_struct shm_ac_sleep_req; + struct work_struct shm_mod_reset_req; }; /** -- cgit v1.2.3 From 3c5a53db080203d69be59b756106f4a573ad775c Mon Sep 17 00:00:00 2001 From: Thierry STRUDEL Date: Thu, 27 Oct 2011 18:47:58 +0200 Subject: shrm: use kthread_worker instead of workqueue Workqueue updates no longer guarantee fixed workqueue to worker kthread association, so giving RT priority to the irq worker won't work. Use kthread_worker which guarantees specific kthread association instead. This also makes setting the priority cleaner. ST-Ericsson ID: 361756 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: Id54eafae1391ef8b09e93a4815efa1b674d3d90d Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36062 Reviewed-by: Srinidhi KASAGAR Reviewed-by: QABUILD Tested-by: Christoffer LONNERFORS Reviewed-by: Arun MURTHY --- drivers/modem/shrm/shrm_fifo.c | 6 +- drivers/modem/shrm/shrm_protocol.c | 160 +++++++++++++++++++-------------- include/linux/modem/shrm/shrm_driver.h | 45 ++++++---- 3 files changed, 124 insertions(+), 87 deletions(-) (limited to 'include') diff --git a/drivers/modem/shrm/shrm_fifo.c b/drivers/modem/shrm/shrm_fifo.c index 57da56f4905..1804c1be69e 100644 --- a/drivers/modem/shrm/shrm_fifo.c +++ b/drivers/modem/shrm/shrm_fifo.c @@ -111,7 +111,7 @@ u8 read_boot_info_req(struct shrm_dev *shrm, dev_err(shrm->dev, "Read_Boot_Info_Req Fatal ERROR\n"); dev_err(shrm->dev, "Received msgtype is %d\n", msgtype); dev_info(shrm->dev, "Initiating a modem reset\n"); - queue_work(shrm->shm_ac_wake_wq, + queue_kthread_work(&shrm->shm_ac_wake_kw, &shrm->shm_mod_reset_req); return 0; } @@ -421,7 +421,7 @@ u8 read_one_l2msg_common(struct shrm_dev *shrm, /* Fatal ERROR - should never happens */ dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); dev_info(shrm->dev, "Initiating a modem reset\n"); - queue_work(shrm->shm_ac_wake_wq, + queue_kthread_work(&shrm->shm_ac_wake_kw, &shrm->shm_mod_reset_req); } if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { @@ -529,7 +529,7 @@ u8 read_one_l2msg_audio(struct shrm_dev *shrm, /* Fatal ERROR - should never happens */ dev_crit(shrm->dev, "Fatal ERROR - should never happen\n"); dev_info(shrm->dev, "Initiating a modem reset\n"); - queue_work(shrm->shm_ac_wake_wq, + queue_kthread_work(&shrm->shm_ac_wake_kw, &shrm->shm_mod_reset_req); } if (fifo->reader_local_rptr == (fifo->end_addr_fifo-1)) { diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index 78dc4be0754..c13f05d50e8 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -70,12 +70,12 @@ enum shrm_nl { SHRM_NL_STATUS_MOD_OFFLINE, }; -void shm_mod_reset_req_work(struct work_struct *work) +void shm_mod_reset_req_work(struct kthread_work *work) { prcmu_modem_reset(); } -static void shm_ac_sleep_req_work(struct work_struct *work) +static void shm_ac_sleep_req_work(struct kthread_work *work) { mutex_lock(&ac_state_mutex); if (atomic_read(&ac_sleep_disable_count) == 0) @@ -83,7 +83,7 @@ static void shm_ac_sleep_req_work(struct work_struct *work) mutex_unlock(&ac_state_mutex); } -static void shm_ac_wake_req_work(struct work_struct *work) +static void shm_ac_wake_req_work(struct kthread_work *work) { mutex_lock(&ac_state_mutex); modem_request(shm_dev->modem); @@ -119,7 +119,7 @@ static enum hrtimer_restart callback(struct hrtimer *timer) shrm_common_tx_state = SHRM_SLEEP_STATE; shrm_audio_tx_state = SHRM_SLEEP_STATE; - queue_work(shm_dev->shm_ac_sleep_wq, + queue_kthread_work(&shm_dev->shm_ac_sleep_kw, &shm_dev->shm_ac_sleep_req); } @@ -284,7 +284,7 @@ void shm_ca_msgpending_0_tasklet(unsigned long tasklet_data) boot_state = BOOT_INFO_SYNC; spin_unlock_irqrestore(&boot_lock, flags); dev_info(shrm->dev, "BOOT_INFO_SYNC\n"); - queue_work(shrm->shm_common_ch_wr_wq, + queue_kthread_work(&shrm->shm_common_ch_wr_kw, &shrm->send_ac_msg_pend_notify_0); } else { ca_msg_read_notification_0(shrm); @@ -388,7 +388,7 @@ void shm_ac_read_notif_0_tasklet(unsigned long tasklet_data) } else if (boot_state == BOOT_DONE) { if (writer_local_rptr != writer_local_wptr) { shrm_common_tx_state = SHRM_PTR_FREE; - queue_work(shrm->shm_common_ch_wr_wq, + queue_kthread_work(&shrm->shm_common_ch_wr_kw, &shrm->send_ac_msg_pend_notify_0); } else { shrm_common_tx_state = SHRM_IDLE; @@ -430,7 +430,7 @@ void shm_ac_read_notif_1_tasklet(unsigned long tasklet_data) } if (writer_local_rptr != writer_local_wptr) { shrm_audio_tx_state = SHRM_PTR_FREE; - queue_work(shrm->shm_audio_ch_wr_wq, + queue_kthread_work(&shrm->shm_audio_ch_wr_kw, &shrm->send_ac_msg_pend_notify_1); } else { shrm_audio_tx_state = SHRM_IDLE; @@ -443,7 +443,7 @@ void shm_ac_read_notif_1_tasklet(unsigned long tasklet_data) dev_dbg(shrm->dev, "%s OUT\n", __func__); } -void shm_ca_sleep_req_work(struct work_struct *work) +void shm_ca_sleep_req_work(struct kthread_work *work) { dev_dbg(shm_dev->dev, "%s:IRQ_PRCMU_CA_SLEEP\n", __func__); @@ -459,7 +459,7 @@ void shm_ca_sleep_req_work(struct work_struct *work) atomic_dec(&ac_sleep_disable_count); } -void shm_ca_wake_req_work(struct work_struct *work) +void shm_ca_wake_req_work(struct kthread_work *work) { struct shrm_dev *shrm = container_of(work, struct shrm_dev, shm_ca_wake_req); @@ -496,7 +496,7 @@ static int shrm_modem_reset_sequence(void) atomic_set(&ac_sleep_disable_count, 0); /* workaround for MSR */ - queue_work(shm_dev->shm_ac_wake_wq, + queue_kthread_work(&shm_dev->shm_ac_wake_kw, &shm_dev->shm_ac_wake_req); /* stop network queue */ @@ -570,10 +570,10 @@ static irqreturn_t shrm_prcmu_irq_handler(int irq, void *data) if (shrm->msr_flag) atomic_set(&ac_sleep_disable_count, 0); atomic_inc(&ac_sleep_disable_count); - queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_wake_req); + queue_kthread_work(&shrm->shm_ca_wake_kw, &shrm->shm_ca_wake_req); break; case IRQ_PRCMU_CA_SLEEP: - queue_work(shrm->shm_ca_wake_wq, &shrm->shm_ca_sleep_req); + queue_kthread_work(&shrm->shm_ca_wake_kw, &shrm->shm_ca_sleep_req); break; case IRQ_PRCMU_MODEM_SW_RESET_REQ: /* update the boot_state */ @@ -606,7 +606,7 @@ static irqreturn_t shrm_prcmu_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static void send_ac_msg_pend_notify_0_work(struct work_struct *work) +static void send_ac_msg_pend_notify_0_work(struct kthread_work *work) { struct shrm_dev *shrm = container_of(work, struct shrm_dev, send_ac_msg_pend_notify_0); @@ -635,7 +635,7 @@ static void send_ac_msg_pend_notify_0_work(struct work_struct *work) dev_dbg(shrm->dev, "%s OUT\n", __func__); } -static void send_ac_msg_pend_notify_1_work(struct work_struct *work) +static void send_ac_msg_pend_notify_1_work(struct kthread_work *work) { struct shrm_dev *shrm = container_of(work, struct shrm_dev, send_ac_msg_pend_notify_1); @@ -697,6 +697,7 @@ int shrm_protocol_init(struct shrm_dev *shrm, received_msg_handler audio_rx_handler) { int err; + struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; shm_dev = shrm; boot_state = BOOT_INIT; @@ -708,49 +709,70 @@ int shrm_protocol_init(struct shrm_dev *shrm, hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); timer.function = callback; - shrm->shm_common_ch_wr_wq = create_singlethread_workqueue - ("shm_common_channel_irq"); - if (!shrm->shm_common_ch_wr_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); + init_kthread_worker(&shrm->shm_common_ch_wr_kw); + shrm->shm_common_ch_wr_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_common_ch_wr_kw, + "shm_common_channel_irq"); + if (IS_ERR(shrm->shm_common_ch_wr_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); return -ENOMEM; } - shrm->shm_audio_ch_wr_wq = alloc_workqueue("shm_audio_channel_irq", - WQ_UNBOUND | WQ_MEM_RECLAIM, 1); - if (!shrm->shm_audio_ch_wr_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); + + init_kthread_worker(&shrm->shm_audio_ch_wr_kw); + shrm->shm_audio_ch_wr_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_audio_ch_wr_kw, + "shm_audio_channel_irq"); + if (IS_ERR(shrm->shm_audio_ch_wr_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); err = -ENOMEM; - goto free_wq1; + goto free_kw1; } - shrm->shm_ac_wake_wq = alloc_workqueue("shm_ac_wake_req", - WQ_UNBOUND | WQ_MEM_RECLAIM, 1); - if (!shrm->shm_ac_wake_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); + /* must use the FIFO scheduler as it is realtime sensitive */ + sched_setscheduler(shrm->shm_audio_ch_wr_kw_task, SCHED_FIFO, ¶m); + + init_kthread_worker(&shrm->shm_ac_wake_kw); + shrm->shm_ac_wake_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_ac_wake_kw, + "shm_ac_wake_req"); + if (IS_ERR(shrm->shm_ac_wake_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); err = -ENOMEM; - goto free_wq2; + goto free_kw2; } - shrm->shm_ca_wake_wq = alloc_workqueue("shm_ca_wake_req", - WQ_UNBOUND | WQ_MEM_RECLAIM, 1); - if (!shrm->shm_ca_wake_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); + /* must use the FIFO scheduler as it is realtime sensitive */ + sched_setscheduler(shrm->shm_ac_wake_kw_task, SCHED_FIFO, ¶m); + + init_kthread_worker(&shrm->shm_ca_wake_kw); + shrm->shm_ca_wake_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_ca_wake_kw, + "shm_ca_wake_req"); + if (IS_ERR(shrm->shm_ca_wake_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); err = -ENOMEM; - goto free_wq3; + goto free_kw3; } - shrm->shm_ac_sleep_wq = create_singlethread_workqueue - ("shm_ac_sleep_req"); - if (!shrm->shm_ac_sleep_wq) { - dev_err(shrm->dev, "failed to create work queue\n"); + /* must use the FIFO scheduler as it is realtime sensitive */ + sched_setscheduler(shrm->shm_ca_wake_kw_task, SCHED_FIFO, ¶m); + + init_kthread_worker(&shrm->shm_ac_sleep_kw); + shrm->shm_ac_sleep_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_ac_sleep_kw, + "shm_ac_sleep_req"); + if (IS_ERR(shrm->shm_ac_sleep_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); err = -ENOMEM; - goto free_wq4; + goto free_kw4; } - INIT_WORK(&shrm->send_ac_msg_pend_notify_0, - send_ac_msg_pend_notify_0_work); - INIT_WORK(&shrm->send_ac_msg_pend_notify_1, - send_ac_msg_pend_notify_1_work); - INIT_WORK(&shrm->shm_ca_wake_req, shm_ca_wake_req_work); - INIT_WORK(&shrm->shm_ca_sleep_req, shm_ca_sleep_req_work); - INIT_WORK(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); - INIT_WORK(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); - INIT_WORK(&shrm->shm_mod_reset_req, shm_mod_reset_req_work); + + init_kthread_work(&shrm->send_ac_msg_pend_notify_0, + send_ac_msg_pend_notify_0_work); + init_kthread_work(&shrm->send_ac_msg_pend_notify_1, + send_ac_msg_pend_notify_1_work); + init_kthread_work(&shrm->shm_ca_wake_req, shm_ca_wake_req_work); + init_kthread_work(&shrm->shm_ca_sleep_req, shm_ca_sleep_req_work); + init_kthread_work(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); + init_kthread_work(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); + init_kthread_work(&shrm->shm_mod_reset_req, shm_mod_reset_req_work); /* set tasklet data */ shm_ca_0_tasklet.data = (unsigned long)shrm; @@ -760,7 +782,7 @@ int shrm_protocol_init(struct shrm_dev *shrm, IRQF_NO_SUSPEND, "ca-sleep", shrm); if (err < 0) { dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_SLEEP.\n"); - goto free_wq5; + goto free_kw5; } err = request_irq(IRQ_PRCMU_CA_WAKE, shrm_prcmu_irq_handler, @@ -798,16 +820,16 @@ drop1: free_irq(IRQ_PRCMU_CA_WAKE, NULL); drop2: free_irq(IRQ_PRCMU_CA_SLEEP, NULL); -free_wq5: - destroy_workqueue(shrm->shm_ac_sleep_wq); -free_wq4: - destroy_workqueue(shrm->shm_ca_wake_wq); -free_wq3: - destroy_workqueue(shrm->shm_ac_wake_wq); -free_wq2: - destroy_workqueue(shrm->shm_audio_ch_wr_wq); -free_wq1: - destroy_workqueue(shrm->shm_common_ch_wr_wq); +free_kw5: + kthread_stop(shrm->shm_ac_sleep_kw_task); +free_kw4: + kthread_stop(shrm->shm_ca_wake_kw_task); +free_kw3: + kthread_stop(shrm->shm_ac_wake_kw_task); +free_kw2: + kthread_stop(shrm->shm_audio_ch_wr_kw_task); +free_kw1: + kthread_stop(shrm->shm_common_ch_wr_kw_task); return err; } @@ -816,12 +838,16 @@ void shrm_protocol_deinit(struct shrm_dev *shrm) free_irq(IRQ_PRCMU_CA_SLEEP, NULL); free_irq(IRQ_PRCMU_CA_WAKE, NULL); free_irq(IRQ_PRCMU_MODEM_SW_RESET_REQ, NULL); - flush_scheduled_work(); - destroy_workqueue(shrm->shm_common_ch_wr_wq); - destroy_workqueue(shrm->shm_audio_ch_wr_wq); - destroy_workqueue(shrm->shm_ac_wake_wq); - destroy_workqueue(shrm->shm_ca_wake_wq); - destroy_workqueue(shrm->shm_ac_sleep_wq); + flush_kthread_worker(&shrm->shm_common_ch_wr_kw); + flush_kthread_worker(&shrm->shm_audio_ch_wr_kw); + flush_kthread_worker(&shrm->shm_ac_wake_kw); + flush_kthread_worker(&shrm->shm_ca_wake_kw); + flush_kthread_worker(&shrm->shm_ac_sleep_kw); + kthread_stop(shrm->shm_common_ch_wr_kw_task); + kthread_stop(shrm->shm_audio_ch_wr_kw_task); + kthread_stop(shrm->shm_ac_wake_kw_task); + kthread_stop(shrm->shm_ca_wake_kw_task); + kthread_stop(shrm->shm_ac_sleep_kw_task); modem_put(shrm->modem); } @@ -1038,10 +1064,10 @@ int shm_write_msg(struct shrm_dev *shrm, u8 l2_header, /* Send Message Pending Noitication to CMT */ if (channel == 0) - queue_work(shrm->shm_common_ch_wr_wq, + queue_kthread_work(&shrm->shm_common_ch_wr_kw, &shrm->send_ac_msg_pend_notify_0); else - queue_work(shrm->shm_audio_ch_wr_wq, + queue_kthread_work(&shrm->shm_audio_ch_wr_kw, &shrm->send_ac_msg_pend_notify_1); } diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index 8fa215571eb..689ce207df5 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -23,6 +23,7 @@ #include #include #include +#include #define ISA_DEVICES 7 @@ -64,11 +65,16 @@ * @dev: pointer to the driver device * @ndev: pointer to the network device structure * @isa_context: pointer to t_isa_driver_sontext dtructure - * @shm_common_ch_wr_wq: work queue for writing to common channel - * @shm_audio_ch_wr_wq: workqueue for writing to audio channel - * @shm_ac_wake_wq: workqueue for receiving ape-cmt wake requests - * @shm_ca_wake_wq: workqueue for receiving cmt-ape wake requests - * @shm_ac_sleep_wq: workqueue for recieving ape-cmt sleep requests + * @shm_common_ch_wr_wk: kthread worker for writing to common channel + * @shm_common_ch_wr_wk_task: task for writing to common channel + * @shm_audio_ch_wr_wk: kthread worker for writing to audio channel + * @shm_audio_ch_wr_wk_task: task for writing to audio channel + * @shm_ac_wake_wk: kthread worker for receiving ape-cmt wake requests + * @shm_ac_wake_wk_task: task for receiving ape-cmt wake requests + * @shm_ca_wake_wk: kthread worker for receiving cmt-ape wake requests + * @shm_ca_wake_wk_task: task for receiving cmt-ape wake requests + * @shm_ac_sleep_wk: kthread worker for recieving ape-cmt sleep requests + * @shm_ac_sleep_wk_task: task for recieving ape-cmt sleep requests * @send_ac_msg_pend_notify_0: work for handling pending message on common * channel * @send_ac_msg_pend_notify_1: work for handling pending message on audio @@ -117,18 +123,23 @@ struct shrm_dev { struct net_device *ndev; struct modem *modem; struct isa_driver_context *isa_context; - struct workqueue_struct *shm_common_ch_wr_wq; - struct workqueue_struct *shm_audio_ch_wr_wq; - struct workqueue_struct *shm_ac_wake_wq; - struct workqueue_struct *shm_ca_wake_wq; - struct workqueue_struct *shm_ac_sleep_wq; - struct work_struct send_ac_msg_pend_notify_0; - struct work_struct send_ac_msg_pend_notify_1; - struct work_struct shm_ac_wake_req; - struct work_struct shm_ca_wake_req; - struct work_struct shm_ca_sleep_req; - struct work_struct shm_ac_sleep_req; - struct work_struct shm_mod_reset_req; + struct kthread_worker shm_common_ch_wr_kw; + struct task_struct *shm_common_ch_wr_kw_task; + struct kthread_worker shm_audio_ch_wr_kw; + struct task_struct *shm_audio_ch_wr_kw_task; + struct kthread_worker shm_ac_wake_kw; + struct task_struct *shm_ac_wake_kw_task; + struct kthread_worker shm_ca_wake_kw; + struct task_struct *shm_ca_wake_kw_task; + struct kthread_worker shm_ac_sleep_kw; + struct task_struct *shm_ac_sleep_kw_task; + struct kthread_work send_ac_msg_pend_notify_0; + struct kthread_work send_ac_msg_pend_notify_1; + struct kthread_work shm_ac_wake_req; + struct kthread_work shm_ca_wake_req; + struct kthread_work shm_ca_sleep_req; + struct kthread_work shm_ac_sleep_req; + struct kthread_work shm_mod_reset_req; }; /** -- cgit v1.2.3 From 205a30eb9c473d8fdf2c4a3d484d2ab70ebd3790 Mon Sep 17 00:00:00 2001 From: Chris Blair Date: Mon, 7 Nov 2011 14:34:38 +0000 Subject: modem: Add M6718 modem SPI IPC driver framework Adds support for the M6718 modem IPC SPI driver. This patch adds the spi driver under which the protocol will be added. ST-Ericsson ID: 369397 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12224 ST-Ericsson Linux next: NA Change-Id: Ifa60efa9cb6a9d30b02b88b563624a293bc0930c Signed-off-by: Chris Blair Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36433 Reviewed-by: Jonas ABERG --- drivers/modem/Kconfig | 2 + drivers/modem/Makefile | 1 + drivers/modem/m6718_spi/Kconfig | 83 ++++++++++++++++ drivers/modem/m6718_spi/Makefile | 10 ++ drivers/modem/m6718_spi/modem_driver.c | 134 ++++++++++++++++++++++++++ include/linux/modem/m6718_spi/modem_driver.h | 135 +++++++++++++++++++++++++++ 6 files changed, 365 insertions(+) create mode 100644 drivers/modem/m6718_spi/Kconfig create mode 100644 drivers/modem/m6718_spi/Makefile create mode 100644 drivers/modem/m6718_spi/modem_driver.c create mode 100644 include/linux/modem/m6718_spi/modem_driver.h (limited to 'include') diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig index 9ecbe00fd61..323ef88af18 100644 --- a/drivers/modem/Kconfig +++ b/drivers/modem/Kconfig @@ -29,3 +29,5 @@ config MODEM_M6718 Add support for the modem access driver for the M6718 modem. If unsure, say N. + +source "drivers/modem/m6718_spi/Kconfig" diff --git a/drivers/modem/Makefile b/drivers/modem/Makefile index c0df71e65a1..a7c1df50074 100644 --- a/drivers/modem/Makefile +++ b/drivers/modem/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_MODEM) := modem_access.o obj-$(CONFIG_MODEM_U8500) += modem_u8500.o obj-$(CONFIG_U8500_SHRM) += shrm/ obj-$(CONFIG_MODEM_M6718) += modem_m6718.o +obj-$(CONFIG_MODEM_M6718_SPI) += m6718_spi/ diff --git a/drivers/modem/m6718_spi/Kconfig b/drivers/modem/m6718_spi/Kconfig new file mode 100644 index 00000000000..f945d24a094 --- /dev/null +++ b/drivers/modem/m6718_spi/Kconfig @@ -0,0 +1,83 @@ +# +# M6718 modem SPI IPC driver kernel configuration +# +config MODEM_M6718_SPI + tristate "M6718 modem IPC SPI driver" + depends on MODEM_M6718 + default y + ---help--- + If you say Y here, you will enable the M6718 modem IPC SPI driver. + + If unsure, say Y. + +config MODEM_M6718_SPI_DEBUG + boolean "Modem driver debug" + depends on MODEM_M6718_SPI + default N + ---help--- + If you say Y here, you will enable full debug trace from the M6718 + modem driver. This should not be enabled by default. + + If unsure, say N. + +config MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE + boolean "M6718 modem state driver integration" + depends on MODEM_M6718_SPI + default y + ---help--- + Enables integration of the IPC driver with the modem state driver. + This allows the IPC driver to be notified of changes in modem state + (on, off, reset) and allows the IPC driver to cause modem state + changes if needed. + + By default this should be enabled. + +config MODEM_M6718_SPI_ENABLE_FEATURE_FRAME_DUMP + boolean "IPC SPI L1 frame dump" + depends on MODEM_M6718_SPI + default n + ---help--- + If you say Y here, you will enable dumping of the raw TX and RX frames + by the IPC driver L1. + + If unsure, say N. + +config MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK + boolean "Modem IPC loopback support" + depends on MODEM_M6718_SPI + default y + ---help--- + If you say Y here, you will enable the IPC loopback channels/devices. + + If unsure, say Y. + + +config MODEM_M6718_SPI_ENABLE_FEATURE_VERIFY_FRAMES + boolean "Verify loopback frames" + depends on MODEM_M6718_SPI + default n + ---help--- + This will enabling checking of loopback frames to verify that the data + received is identical to the data sent. + + If unsure, say N. + +config MODEM_M6718_SPI_ENABLE_FEATURE_THROUGHPUT_MEASUREMENT + boolean "Modem IPC throughput measurement" + depends on MODEM_M6718_SPI + default n + ---help--- + If you say Y here, you will enable the IPC link throughput + measurement and reporting. + + If unsure, say N. + +config MODEM_M6718_SPI_SET_THROUGHPUT_FREQUENCY + int "Sample rate for throughput measurements (seconds)" + default "5" + depends on MODEM_M6718_SPI_ENABLE_FEATURE_THROUGHPUT_MEASUREMENT + help + The sample frequency for taking IPC SPI link throughput measurements. + Increasing the rate (reducing the time) will increase the accuracy of + the measurements, but will also increase the impact on link and system + performance. diff --git a/drivers/modem/m6718_spi/Makefile b/drivers/modem/m6718_spi/Makefile new file mode 100644 index 00000000000..96bf481e986 --- /dev/null +++ b/drivers/modem/m6718_spi/Makefile @@ -0,0 +1,10 @@ +# +# Makefile for M6718 SPI driver +# +ifeq ($(CONFIG_MODEM_M6718_SPI_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif + +m6718_modem_spi-objs := modem_driver.o + +obj-$(CONFIG_MODEM_M6718_SPI) += m6718_modem_spi.o diff --git a/drivers/modem/m6718_spi/modem_driver.c b/drivers/modem/m6718_spi/modem_driver.c new file mode 100644 index 00000000000..7d0efa6e395 --- /dev/null +++ b/drivers/modem/m6718_spi/modem_driver.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on modem_shrm_driver.c + * + * License terms: GNU General Public License (GPL) version 2 + * + * SPI driver implementing the M6718 inter-processor communication protocol. + */ +#include +#include +#include +#include +#include + +static struct modem_spi_dev modem_driver_data = { + .dev = NULL, + .ndev = NULL, + .modem = NULL, + .isa_context = NULL, + .netdev_flag_up = 0 +}; + +/** + * modem_m6718_spi_receive() - Receive a frame from L1 physical layer + * @sdev: pointer to spi device structure + * @channel: L2 mux channel id + * @len: frame data length + * @data: pointer to frame data + * + * This function is called from the driver L1 physical transport layer. It + * copied the frame data to the receive queue for the channel on which the data + * was received. + * + * Special handling is given to slave-loopback channels where the data is simply + * sent back to the modem on the same channel. + * + * Special handling is given to the ISI channel when PHONET is enabled - the + * phonet tasklet is scheduled in order to pump the received data through the + * net device interface. + */ +int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, + u32 len, void *data) +{ + return -ENODEV; +} +EXPORT_SYMBOL_GPL(modem_m6718_spi_receive); + +static int spi_probe(struct spi_device *sdev) +{ + int result = 0; + + spi_set_drvdata(sdev, &modem_driver_data); + + /* + * Since we can have multiple spi links for the same modem, only + * initialise the modem data and char/net interfaces once. + */ + if (modem_driver_data.dev == NULL) { + modem_driver_data.dev = &sdev->dev; + modem_driver_data.modem = + modem_get(modem_driver_data.dev, "m6718"); + if (modem_driver_data.modem == NULL) { + dev_err(&sdev->dev, + "failed to retrieve modem description\n"); + result = -ENODEV; + } + } + return result; +} + +static int __exit spi_remove(struct spi_device *sdev) +{ + return 0; +} + +#ifdef CONFIG_PM +/** + * spi_suspend() - This routine puts the IPC driver in to suspend state. + * @sdev: pointer to spi device structure. + * @mesg: pm operation + * + * This routine checks the current ongoing communication with modem + * and prevents suspend if modem communication is on-going. + */ +static int spi_suspend(struct spi_device *sdev, pm_message_t mesg) +{ + dev_dbg(&sdev->dev, "suspend called\n"); + return 0; +} + +/** + * spi_resume() - This routine resumes the IPC driver from suspend state. + * @sdev: pointer to spi device structure + */ +static int spi_resume(struct spi_device *sdev) +{ + dev_dbg(&sdev->dev, "resume called\n"); + return 0; +} +#endif /* CONFIG_PM */ + +static struct spi_driver spi_driver = { + .driver = { + .name = "spimodem", + .bus = &spi_bus_type, + .owner = THIS_MODULE + }, + .probe = spi_probe, + .remove = __exit_p(spi_remove), +#ifdef CONFIG_PM + .suspend = spi_suspend, + .resume = spi_resume, +#endif +}; + +static int __init m6718_spi_driver_init(void) +{ + pr_info("M6718 modem driver initialising\n"); + return spi_register_driver(&spi_driver); +} +module_init(m6718_spi_driver_init); + +static void __exit m6718_spi_driver_exit(void) +{ + pr_debug("M6718 modem SPI IPC driver exit\n"); + spi_unregister_driver(&spi_driver); +} +module_exit(m6718_spi_driver_exit); + +MODULE_AUTHOR("Chris Blair "); +MODULE_DESCRIPTION("M6718 modem IPC SPI driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/modem/m6718_spi/modem_driver.h b/include/linux/modem/m6718_spi/modem_driver.h new file mode 100644 index 00000000000..8c5209c228c --- /dev/null +++ b/include/linux/modem/m6718_spi/modem_driver.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_driver.h + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC driver interface header. + */ +#ifndef _MODEM_DRIVER_H_ +#define _MODEM_DRIVER_H_ + +#include +#include +#include +#include + + +/* driver L2 mux channels */ +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK +#define MODEM_M6718_SPI_MAX_CHANNELS (9) +#else +#define MODEM_M6718_SPI_MAX_CHANNELS (3) +#endif + +#define MODEM_M6718_SPI_CHN_ISI (0) +/*#define MODEM_M6718_SPI_CHN_RPC (1) not supported */ +#define MODEM_M6718_SPI_CHN_AUDIO (2) +/*#define MODEM_M6718_SPI_CHN_SECURITY (3) not supported */ +/* (4) not supported */ +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK +#define MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0 (5) +#define MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0 (6) +#define MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1 (7) +#define MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1 (8) +#endif + +/** + * struct queue_element - information to add an element to queue + * @entry: list entry + * @offset: message offset + * @size: message size + * @no: total number of messages + */ +struct queue_element { + struct list_head entry; + u32 offset; + u32 size; + u32 no; +}; + +/** + * struct message_queue - ISI, RPC, AUDIO, SECURITY message queue information + * @channel: L2 mux channel served by this queue + * @fifo_base: pointer to the respective fifo base + * @size: size of the data to be read + * @free: free space in the queue + * @readptr: fifo read pointer + * @writeptr: fifo write pointer + * @no: total number of messages + * @update_lock: spinlock for protecting the queue read operation + * @q_rp: queue read pointer is valid + * @wq_readable: wait queue head + * @msg_list: message list + * @modem_spi_dev: pointer to modem device information structure + */ +struct message_queue { + u8 channel; + u8 *fifo_base; + u32 size; + u32 free; + u32 readptr; + u32 writeptr; + u32 no; + spinlock_t update_lock; + atomic_t q_rp; + wait_queue_head_t wq_readable; + struct list_head msg_list; + struct modem_spi_dev *modem_spi_dev; +}; + +/** + * struct isa_device_context - modem char interface device information + * @dl_queue: structre to store the queue related info + * @device_id: channel id (ISI, AUDIO, RPC, ...) + * @addr: device address + */ +struct isa_device_context { + struct message_queue dl_queue; + u8 device_id; + void *addr; +}; + +/** + * struct isa_driver_context - modem char interface driver information + * @is_open: flag to check the usage of queue + * @isadev: pointer to struct t_isadev_context + * @common_tx_lock: spinlock for protecting common channel + * @audio_tx_mutex: mutex for protecting audio channel + * @cdev: character device structre + * @modem_class: pointer to the class structure + */ +struct isa_driver_context { + atomic_t is_open[MODEM_M6718_SPI_MAX_CHANNELS]; + struct isa_device_context *isadev; + spinlock_t common_tx_lock; + struct mutex audio_tx_mutex; + struct cdev cdev; + struct class *modem_class; +}; + +/** + * struct modem_spi_dev - modem device information + * @dev pointer to device + * @ndev pointer to net_device interface + * @modem pointer to registered modem structure + * @isa_context pointer to char device interface + * @netdev_flag_up: flag to indicate up/down of network device + * @msr_flag: flag to indicate modem-silent-reset is in progress + */ +struct modem_spi_dev { + struct device *dev; + struct net_device *ndev; + struct modem *modem; + struct isa_driver_context *isa_context; + int netdev_flag_up; + bool msr_flag; +}; + +/* function exported for L1 to call with received frames */ +int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, + u32 len, void *data); + +#endif /* _MODEM_DRIVER_H_ */ -- cgit v1.2.3 From 726fba97127de03f8b4ca6f7ec29e66b1d1b76e3 Mon Sep 17 00:00:00 2001 From: Chris Blair Date: Fri, 4 Nov 2011 09:29:42 +0000 Subject: modem: Port M6718 modem state driver Adds the modem state driver to the M6718 modem IPC interface. ST-Ericsson ID: 369397 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12224 ST-Ericsson Linux next: NA Change-Id: I5566277b950aa0be954f4350bdc1ed38c7afd7d8 Signed-off-by: Chris Blair Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36434 Reviewed-by: Derek MORTON Reviewed-by: QATOOLS Reviewed-by: Andrew LYNN Reviewed-by: QABUILD Reviewed-by: Jonas ABERG --- drivers/modem/m6718_spi/Makefile | 4 + drivers/modem/m6718_spi/modem_state.c | 1300 +++++++++++++++++++++++++++ include/linux/modem/m6718_spi/modem_state.h | 36 + 3 files changed, 1340 insertions(+) create mode 100644 drivers/modem/m6718_spi/modem_state.c create mode 100644 include/linux/modem/m6718_spi/modem_state.h (limited to 'include') diff --git a/drivers/modem/m6718_spi/Makefile b/drivers/modem/m6718_spi/Makefile index 96bf481e986..492995bc753 100644 --- a/drivers/modem/m6718_spi/Makefile +++ b/drivers/modem/m6718_spi/Makefile @@ -7,4 +7,8 @@ endif m6718_modem_spi-objs := modem_driver.o +ifeq ($(CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE),y) +m6718_modem_spi-objs += modem_state.o +endif + obj-$(CONFIG_MODEM_M6718_SPI) += m6718_modem_spi.o diff --git a/drivers/modem/m6718_spi/modem_state.c b/drivers/modem/m6718_spi/modem_state.c new file mode 100644 index 00000000000..266f75a7a71 --- /dev/null +++ b/drivers/modem/m6718_spi/modem_state.c @@ -0,0 +1,1300 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Derek Morton + * + * License terms: GNU General Public License (GPL) version 2 + * + * Power state driver for M6718 MODEM + */ + +/* define DEBUG to enable debug logging */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * To enable this driver add a struct platform_device in the board + * configuration file (e.g. board-*.c) with name="modemstate" + * optionally specify dev.initname="m6718" to define the driver + * name as it will appear in the file system. + * e.g. + * static struct platform_device modem_state_device = + * { + * .name = "modemstate", + * .dev = + * { + * .init_name = "m6718" // Name that will appear in FS + * }, + * .num_resources = ARRAY_SIZE(modem_state_resources), + * .resource = modem_state_resources + * }; + * + * This driver uses gpio pins which should be specified as resources * + * e.g. + * static struct resource modem_state_resources[] = ....... + * Output pins are specified as IORESOURCE_IO + * Currently supported Output pins are: + * onkey_pin + * reset_pin + * vbat_pin + * Input pins are specified as IORESOURCE_IRQ + * Currently supported input pins are: + * rsthc_pin + * rstext_pin + * crash_pin + * Currently only the start value is used as the gpio pin number but + * end should also be specified as the gpio pin number in case gpio ranges + * are used in the future. + * e.g. if gpio 161 is used as the onkey pin + * { + * .start = 161, + * .end = 161, + * .name = "onkey_pin", + * .flags = IORESOURCE_IO, + * }, + */ + +struct modem_state_dev { + int onkey_pin; + int rsthc_pin; + int rstext_pin; + int crash_pin; + int reset_pin; + int vbat_pin; + int power_state; + int irq_state; + int busy; + struct timer_list onkey_timer; + struct timer_list reset_timer; + struct timer_list onkey_debounce_timer; + struct timer_list vbat_off_timer; + struct timer_list busy_timer; + spinlock_t lock; + struct device *dev; + struct workqueue_struct *workqueue; + struct work_struct wq_rsthc; + struct work_struct wq_rstext; + struct work_struct wq_crash; +#ifdef CONFIG_DEBUG_FS + struct dentry *debugfsdir; + struct dentry *debugfs_debug; +#endif +}; + +struct callback_list { + struct list_head node; + int (*callback) (unsigned long); + unsigned long data; +}; +LIST_HEAD(callback_list); + +static char *modem_state_str[] = { + "off", + "reset", + "crash", + "on", + /* + * Add new states before error and update enum modem_states + * in modem_state.h + */ + "error" +}; + +static struct modem_state_dev *modem_state; + +static void set_on_config(struct modem_state_dev *msdev) +{ + if (msdev->crash_pin) + nmk_config_pin(PIN_CFG(msdev->crash_pin, GPIO) | + PIN_INPUT_PULLDOWN, false); + if (msdev->rstext_pin) + nmk_config_pin(PIN_CFG(msdev->rstext_pin, GPIO) | + PIN_INPUT_PULLDOWN, false); + if (msdev->rsthc_pin) + nmk_config_pin(PIN_CFG(msdev->rsthc_pin, GPIO) | + PIN_INPUT_PULLDOWN, false); + if (msdev->reset_pin) + nmk_config_pin(PIN_CFG(msdev->reset_pin, GPIO) | + PIN_OUTPUT_HIGH, false); +} + +static void set_off_config(struct modem_state_dev *msdev) +{ + if (msdev->crash_pin) + nmk_config_pin(PIN_CFG(msdev->crash_pin, GPIO) | + PIN_INPUT_PULLDOWN, false); + if (msdev->rstext_pin) + nmk_config_pin(PIN_CFG(msdev->rstext_pin, GPIO) | + PIN_OUTPUT_LOW, false); + if (msdev->rsthc_pin) + nmk_config_pin(PIN_CFG(msdev->rsthc_pin, GPIO) | PIN_OUTPUT_LOW, + false); + if (msdev->reset_pin) + nmk_config_pin(PIN_CFG(msdev->reset_pin, GPIO) | + PIN_OUTPUT_HIGH, false); +} + +static void enable_irq_all(struct modem_state_dev *msdev) +{ + if (msdev->rsthc_pin) { + enable_irq(GPIO_TO_IRQ(msdev->rsthc_pin)); + if ((0 > enable_irq_wake(GPIO_TO_IRQ(msdev->rsthc_pin)))) + dev_err(msdev->dev, + "Request for wake on pin %d failed\n", + msdev->rsthc_pin); + } + if (msdev->rstext_pin) { + enable_irq(GPIO_TO_IRQ(msdev->rstext_pin)); + if ((0 > enable_irq_wake(GPIO_TO_IRQ(msdev->rstext_pin)))) + dev_err(msdev->dev, + "Request for wake on pin %d failed\n", + msdev->rstext_pin); + } + if (msdev->crash_pin) { + enable_irq(GPIO_TO_IRQ(msdev->crash_pin)); + if ((0 > enable_irq_wake(GPIO_TO_IRQ(msdev->crash_pin)))) + dev_err(msdev->dev, + "Request for wake on pin %d failed\n", + msdev->crash_pin); + } +} + +static void disable_irq_all(struct modem_state_dev *msdev) +{ + if (msdev->rsthc_pin) { + disable_irq_wake(GPIO_TO_IRQ(msdev->rsthc_pin)); + disable_irq(GPIO_TO_IRQ(msdev->rsthc_pin)); + } + if (msdev->rstext_pin) { + disable_irq_wake(GPIO_TO_IRQ(msdev->rstext_pin)); + disable_irq(GPIO_TO_IRQ(msdev->rstext_pin)); + } + if (msdev->crash_pin) { + disable_irq_wake(GPIO_TO_IRQ(msdev->crash_pin)); + disable_irq(GPIO_TO_IRQ(msdev->crash_pin)); + } +} + +/* + * These functions which access GPIO must only be called + * with spinlock enabled. + */ + +/* + * Toggle ONKEY pin high then low to turn modem on or off. Modem expects + * ONKEY line to be pulled low then high. GPIO needs to be driven high then + * low as logic is inverted through a transistor. + */ +static void toggle_modem_power(struct modem_state_dev *msdev) +{ + dev_info(msdev->dev, "Modem power toggle\n"); + msdev->busy = 1; + gpio_set_value(msdev->onkey_pin, 1); + msdev->onkey_timer.data = (unsigned long)msdev; + /* Timeout of at least 1 second */ + mod_timer(&msdev->onkey_timer, jiffies + (1 * HZ) + 1); +} + +/* Modem is forced into reset when its reset line is pulled low */ +/* Drive GPIO low then high to reset modem */ +static void modem_reset(struct modem_state_dev *msdev) +{ + dev_info(msdev->dev, "Modem reset\n"); + msdev->busy = 1; + gpio_set_value(msdev->reset_pin, 0); + msdev->reset_timer.data = (unsigned long)msdev; + /* Wait a couple of Jiffies */ + mod_timer(&msdev->reset_timer, jiffies + 2); +} + +static void modem_vbat_set_value(struct modem_state_dev *msdev, int vbat_val) +{ + switch (vbat_val) { + case 0: + msdev->power_state = 0; + dev_info(msdev->dev, "Modem vbat off\n"); + gpio_set_value(msdev->vbat_pin, vbat_val); + if (1 == msdev->irq_state) { + msdev->irq_state = 0; + disable_irq_all(msdev); + set_off_config(msdev); + } + break; + case 1: + dev_info(msdev->dev, "Modem vbat on\n"); + if (0 == msdev->irq_state) { + msdev->irq_state = 1; + set_on_config(msdev); + enable_irq_all(msdev); + } + gpio_set_value(msdev->vbat_pin, vbat_val); + break; + default: + return; + break; + } +} + +static void modem_power_on(struct modem_state_dev *msdev) +{ + int rsthc = gpio_get_value(msdev->rsthc_pin); + msdev->power_state = 1; + del_timer(&msdev->vbat_off_timer); + if (rsthc == 0) { + modem_vbat_set_value(msdev, 1); + toggle_modem_power(msdev); + } +} + +static void modem_power_off(struct modem_state_dev *msdev) +{ + int rsthc = gpio_get_value(msdev->rsthc_pin); + + msdev->power_state = 0; + if (rsthc == 1) { + toggle_modem_power(msdev); + /* Cut power to modem after 10 seconds */ + msdev->vbat_off_timer.data = (unsigned long)msdev; + mod_timer(&msdev->vbat_off_timer, jiffies + (10 * HZ)); + } +} +/* End of functions requiring spinlock */ + +static void call_callbacks(void) +{ + struct callback_list *item; + + list_for_each_entry(item, &callback_list, node) + item->callback(item->data); +} + +static int get_modem_state(struct modem_state_dev *msdev) +{ + int state; + unsigned long flags; + + spin_lock_irqsave(&msdev->lock, flags); + if (0 == gpio_get_value(msdev->rsthc_pin)) + state = MODEM_STATE_OFF; + else if (0 == gpio_get_value(msdev->rstext_pin)) + state = MODEM_STATE_RESET; + else if (1 == gpio_get_value(msdev->crash_pin)) + state = MODEM_STATE_CRASH; + else + state = MODEM_STATE_ON; + spin_unlock_irqrestore(&msdev->lock, flags); + + return state; +} + +/* modempower read handler */ +static ssize_t modem_state_power_get(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int rsthc; + int power_state; + unsigned long flags; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + spin_lock_irqsave(&msdev->lock, flags); + rsthc = gpio_get_value(msdev->rsthc_pin); + power_state = msdev->power_state; + spin_unlock_irqrestore(&msdev->lock, flags); + + return sprintf(buf, "state=%d, expected=%d\n", rsthc, power_state); +} + +/* + * modempower write handler + * Write '0' to /sys/devices/platform/modemstate/modempower to turn modem off + * Write '1' to /sys/devices/platform/modemstate/modempower to turn modem on + */ +static ssize_t modem_state_power_set(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long flags; + int ret = count; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + ret = -EAGAIN; + } else if (count > 0) { + switch (buf[0]) { + case '0': + modem_power_off(msdev); + break; + case '1': + modem_power_on(msdev); + break; + default: + break; + } + } + spin_unlock_irqrestore(&msdev->lock, flags); + return ret; +} + +/* reset read handler */ +static ssize_t modem_state_reset_get(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int rstext; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + /* No need for spinlocks here as there is only 1 value */ + rstext = gpio_get_value(msdev->rstext_pin); + + return sprintf(buf, "state=%d\n", rstext); +} + +/* reset write handler */ +/* Write '1' to /sys/devices/platform/modemstate/reset to reset modem */ +static ssize_t modem_state_reset_set(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long flags; + int ret = count; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + ret = -EAGAIN; + } else if (count > 0) { + if (buf[0] == '1') + modem_reset(msdev); + } + spin_unlock_irqrestore(&msdev->lock, flags); + + return ret; +} + +/* crash read handler */ +static ssize_t modem_state_crash_get(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int crash; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + /* No need for spinlocks here as there is only 1 value */ + crash = gpio_get_value(msdev->crash_pin); + + return sprintf(buf, "state=%d\n", crash); +} + +/* state read handler */ +static ssize_t modem_state_state_get(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int state; + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + state = get_modem_state(msdev); + if (state > MODEM_STATE_END_MARKER) + state = MODEM_STATE_END_MARKER; + + return sprintf(buf, "%s\n", modem_state_str[state]); +} + +#ifdef CONFIG_DEBUG_FS +static int modem_state_debug_get(struct seq_file *s, void *data) +{ + int onkey; + int rsthc; + int rstext; + int reset; + int crash; + int vbat; + unsigned long flags; + struct modem_state_dev *msdev = s->private; + + spin_lock_irqsave(&msdev->lock, flags); + onkey = gpio_get_value(msdev->onkey_pin); + rsthc = gpio_get_value(msdev->rsthc_pin); + rstext = gpio_get_value(msdev->rstext_pin); + reset = gpio_get_value(msdev->reset_pin); + crash = gpio_get_value(msdev->crash_pin); + vbat = gpio_get_value(msdev->vbat_pin); + spin_unlock_irqrestore(&msdev->lock, flags); + + seq_printf(s, "onkey=%d, rsthc=%d, rstext=%d, " + "reset=%d, crash=%d, vbat=%d\n", + onkey, rsthc, rstext, reset, crash, vbat); + return 0; +} + +/* + * debug write handler + * Write o['0'|'1'] to /sys/devices/platform/modemstate/debug to set + * onkey line low or high. + * Write r['0'|'1'] to /sys/devices/platform/modemstate/debug to set + * reset line low or high. + * Write v['0'|'1'] to /sys/devices/platform/modemstate/debug to set + * vbat line low or high. + */ +static ssize_t modem_state_debug_set(struct file *file, + const char __user *user_buf, + size_t count, + loff_t *ppos) +{ + unsigned long flags; + int bufsize; + char buf[128]; + + bufsize = min(count, sizeof(buf) - 1); + if (copy_from_user(buf, user_buf, bufsize)) + return -EFAULT; + buf[bufsize] = 0; + + spin_lock_irqsave(&modem_state->lock, flags); + if (modem_state->busy) { + return -EAGAIN; + } else if (count > 1) { + switch (buf[1]) { + case '0': /* fallthrough */ + case '1': + switch (buf[0]) { + case 'o': + gpio_set_value(modem_state->onkey_pin, + buf[1] - '0'); + break; + case 'r': + gpio_set_value(modem_state->reset_pin, + buf[1] - '0'); + break; + case 'v': + gpio_set_value(modem_state->vbat_pin, + buf[1] - '0'); + break; + default: + break; + } + break; + default: + break; + } + } + spin_unlock_irqrestore(&modem_state->lock, flags); + + return bufsize; +} + +static int modem_state_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, modem_state_debug_get, inode->i_private); +} +#endif /* CONFIG_DEBUG_FS */ + +static DEVICE_ATTR(modempower, S_IRUSR | S_IWUSR, + modem_state_power_get, modem_state_power_set); +static DEVICE_ATTR(reset, S_IRUSR | S_IWUSR, + modem_state_reset_get, modem_state_reset_set); +static DEVICE_ATTR(crash, S_IRUSR, modem_state_crash_get, NULL); +static DEVICE_ATTR(state, S_IRUSR, modem_state_state_get, NULL); + +static struct attribute *modemstate_attributes[] = { + &dev_attr_modempower.attr, + &dev_attr_reset.attr, + &dev_attr_crash.attr, + &dev_attr_state.attr, + NULL +}; + +static struct attribute_group modemstate_attr_group = { + .attrs = modemstate_attributes, + .name = "modemstate" +}; + +#ifdef CONFIG_DEBUG_FS +static const struct file_operations debugfs_debug_fops = { + .open = modem_state_debug_open, + .read = seq_read, + .write = modem_state_debug_set, + .llseek = seq_lseek, + .release = single_release +}; +#endif + +static void sysfs_notify_rsthc(struct modem_state_dev *msdev) +{ + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_modempower.attr.name); + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_state.attr.name); +} + +static void sysfs_notify_rstext(struct modem_state_dev *msdev) +{ + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_reset.attr.name); + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_state.attr.name); +} + +static void sysfs_notify_crash(struct modem_state_dev *msdev) +{ + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_crash.attr.name); + sysfs_notify(&msdev->dev->kobj, NULL, dev_attr_state.attr.name); +} + +static void wq_rsthc(struct work_struct *work) +{ + unsigned long flags; + int rsthc; + struct modem_state_dev *msdev = + container_of(work, struct modem_state_dev, wq_rsthc); + + spin_lock_irqsave(&msdev->lock, flags); + rsthc = gpio_get_value(msdev->rsthc_pin); + dev_dbg(msdev->dev, "RSTHC interrupt detected, rsthc=%d\n", rsthc); + if (msdev->power_state == rsthc) { + if (!rsthc) { + /* Modem has turned off, and we were expecting it to. + turn vbat to the modem off now */ + del_timer(&msdev->vbat_off_timer); + modem_vbat_set_value(msdev, 0); + } + } else { + dev_dbg(msdev->dev, + "Modem power state is %d, expected %d\n", rsthc, + msdev->power_state); + dev_dbg(msdev->dev, + "Attempting to change modem power state " + "in 2 seconds\n"); + + msdev->onkey_debounce_timer.data = (unsigned long)msdev; + /* Wait > 2048ms due to debounce timer */ + mod_timer(&msdev->onkey_debounce_timer, + jiffies + ((2050 * HZ) / 1000)); + } + spin_unlock_irqrestore(&msdev->lock, flags); + + call_callbacks(); + sysfs_notify_rsthc(msdev); +} + +static void wq_rstext(struct work_struct *work) +{ + struct modem_state_dev *msdev = + container_of(work, struct modem_state_dev, wq_rstext); + + dev_dbg(msdev->dev, "RSTEXT interrupt detected, rstext=%d\n", + gpio_get_value(msdev->rstext_pin)); + + call_callbacks(); + sysfs_notify_rstext(msdev); +} + +static void wq_crash(struct work_struct *work) +{ + struct modem_state_dev *msdev = + container_of(work, struct modem_state_dev, wq_rstext); + + dev_dbg(msdev->dev, "modem crash interrupt detected. crash=%d\n", + gpio_get_value(msdev->crash_pin)); + + call_callbacks(); + sysfs_notify_crash(msdev); +} + +/* Populate device structure used by the driver */ +static int modem_state_dev_init(struct platform_device *pdev, + struct modem_state_dev *msdev) +{ + int err = 0; + struct resource *r; + + r = platform_get_resource_byname(pdev, IORESOURCE_IO, "onkey_pin"); + if (r == NULL) { + err = -ENXIO; + dev_err(&pdev->dev, + "Could not get GPIO number for onkey pin\n"); + goto err_resource; + } + msdev->onkey_pin = r->start; + + r = platform_get_resource_byname(pdev, IORESOURCE_IO, "reset_pin"); + if (r == NULL) { + err = -ENXIO; + dev_err(&pdev->dev, + "Could not get GPIO number for reset pin\n"); + goto err_resource; + } + msdev->reset_pin = r->start; + + r = platform_get_resource_byname(pdev, IORESOURCE_IO, "vbat_pin"); + if (r == NULL) { + err = -ENXIO; + dev_err(&pdev->dev, "Could not get GPIO number for vbat pin\n"); + goto err_resource; + } + msdev->vbat_pin = r->start; + + msdev->rsthc_pin = platform_get_irq_byname(pdev, "rsthc_pin"); + if (msdev->rsthc_pin < 0) { + err = msdev->rsthc_pin; + dev_err(&pdev->dev, + "Could not get GPIO number for rsthc pin\n"); + goto err_resource; + } + + msdev->rstext_pin = platform_get_irq_byname(pdev, "rstext_pin"); + if (msdev->rstext_pin < 0) { + err = msdev->rstext_pin; + dev_err(&pdev->dev, + "Could not get GPIO number for retext pin\n"); + goto err_resource; + } + + msdev->crash_pin = platform_get_irq_byname(pdev, "crash_pin"); + if (msdev->crash_pin < 0) { + err = msdev->crash_pin; + dev_err(&pdev->dev, + "Could not get GPIO number for crash pin\n"); + goto err_resource; + } +err_resource: + return err; +} + +/* IRQ handlers */ + +/* Handlers for rsthc (modem power off indication) IRQ */ +static irqreturn_t rsthc_irq(int irq, void *dev) +{ + struct modem_state_dev *msdev = (struct modem_state_dev *)dev; + + /* check it's our interrupt */ + if (irq != GPIO_TO_IRQ(msdev->rsthc_pin)) { + dev_err(msdev->dev, "Spurious RSTHC irq\n"); + return IRQ_NONE; + } + + queue_work(msdev->workqueue, &msdev->wq_rsthc); + return IRQ_HANDLED; +} + +/* Handlers for rstext (modem reset indication) IRQ */ +static irqreturn_t rstext_irq(int irq, void *dev) +{ + struct modem_state_dev *msdev = (struct modem_state_dev *)dev; + + /* check it's our interrupt */ + if (irq != GPIO_TO_IRQ(msdev->rstext_pin)) { + dev_err(msdev->dev, "Spurious RSTEXT irq\n"); + return IRQ_NONE; + } + + queue_work(msdev->workqueue, &msdev->wq_rstext); + return IRQ_HANDLED; +} + +/* Handlers for modem crash indication IRQ */ +static irqreturn_t crash_irq(int irq, void *dev) +{ + struct modem_state_dev *msdev = (struct modem_state_dev *)dev; + + /* check it's our interrupt */ + if (irq != GPIO_TO_IRQ(msdev->crash_pin)) { + dev_err(msdev->dev, "Spurious modem crash irq\n"); + return IRQ_NONE; + } + + queue_work(msdev->workqueue, &msdev->wq_crash); + return IRQ_HANDLED; +} + +static int request_irq_pin(int pin, irq_handler_t handler, unsigned long flags, + struct modem_state_dev *msdev) +{ + int err = 0; + if (pin) { + err = request_irq(GPIO_TO_IRQ(pin), handler, flags, + dev_name(msdev->dev), msdev); + if (err == 0) { + err = enable_irq_wake(GPIO_TO_IRQ(pin)); + if (err < 0) { + dev_err(msdev->dev, + "Request for wake on pin %d failed\n", + pin); + free_irq(GPIO_TO_IRQ(pin), NULL); + } + } else { + dev_err(msdev->dev, + "Request for irq on pin %d failed\n", pin); + } + } + return err; +} + +static void free_irq_pin(int pin) +{ + disable_irq_wake(GPIO_TO_IRQ(pin)); + free_irq(GPIO_TO_IRQ(pin), NULL); +} + +static int request_irq_all(struct modem_state_dev *msdev) +{ + int err; + + err = request_irq_pin(msdev->rsthc_pin, rsthc_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_NO_SUSPEND, msdev); + if (err < 0) + goto err_rsthc_irq_req; + + err = request_irq_pin(msdev->rstext_pin, rstext_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_NO_SUSPEND, msdev); + if (err < 0) + goto err_rstext_irq_req; + + err = request_irq_pin(msdev->crash_pin, crash_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_NO_SUSPEND, msdev); + if (err < 0) + goto err_crash_irq_req; + + return 0; + +err_crash_irq_req: + free_irq_pin(msdev->rstext_pin); +err_rstext_irq_req: + free_irq_pin(msdev->rsthc_pin); +err_rsthc_irq_req: + return err; +} + +/* Configure GPIO used by the driver */ +static int modem_state_gpio_init(struct platform_device *pdev, + struct modem_state_dev *msdev) +{ + int err = 0; + + /* Reserve gpio pins */ + if (msdev->onkey_pin != 0) { + err = gpio_request(msdev->onkey_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for onkey pin failed\n"); + goto err_onkey_req; + } + } + if (msdev->reset_pin != 0) { + err = gpio_request(msdev->reset_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for reset pin failed\n"); + goto err_reset_req; + } + } + if (msdev->rsthc_pin != 0) { + err = gpio_request(msdev->rsthc_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for rsthc pin failed\n"); + goto err_rsthc_req; + } + } + if (msdev->rstext_pin != 0) { + err = gpio_request(msdev->rstext_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for rstext pin failed\n"); + goto err_rstext_req; + } + } + if (msdev->crash_pin != 0) { + err = gpio_request(msdev->crash_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for crash pin failed\n"); + goto err_crash_req; + } + } + if (msdev->vbat_pin != 0) { + err = gpio_request(msdev->vbat_pin, dev_name(msdev->dev)); + if (err < 0) { + dev_err(&pdev->dev, "Request for vbat pin failed\n"); + goto err_vbat_req; + } + } + + /* Set initial pin config */ + set_on_config(msdev); + if (msdev->onkey_pin) + nmk_config_pin(PIN_CFG(msdev->onkey_pin, GPIO) | + PIN_OUTPUT_LOW, false); + if (msdev->vbat_pin) + nmk_config_pin(PIN_CFG(msdev->vbat_pin, GPIO) | PIN_OUTPUT_HIGH, + false); + + /* Configure IRQs for GPIO pins */ + err = request_irq_all(msdev); + if (err < 0) { + dev_err(&pdev->dev, "Request for irqs failed, err = %d\n", err); + goto err_irq_req; + } + msdev->irq_state = 1; + + /* Save current modem state */ + msdev->power_state = gpio_get_value(msdev->rsthc_pin); + + return 0; + +err_irq_req: + gpio_free(msdev->vbat_pin); +err_vbat_req: + gpio_free(msdev->crash_pin); +err_crash_req: + gpio_free(msdev->rstext_pin); +err_rstext_req: + gpio_free(msdev->rsthc_pin); +err_rsthc_req: + gpio_free(msdev->reset_pin); +err_reset_req: + gpio_free(msdev->onkey_pin); +err_onkey_req: + return err; +} + +/* Timer handlers */ + +static void modem_power_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) + msdev->busy = 0; + else + dev_err(msdev->dev, + "onkey timer expired and busy flag not set\n"); + + gpio_set_value(msdev->onkey_pin, 0); + spin_unlock_irqrestore(&msdev->lock, flags); +} + +static void modem_reset_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&modem_state->lock, flags); + if (msdev->busy) + msdev->busy = 0; + else + dev_err(msdev->dev, + "reset timer expired and busy flag not set\n"); + + gpio_set_value(msdev->reset_pin, 1); + spin_unlock_irqrestore(&modem_state->lock, flags); +} + +static void modem_onkey_debounce_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + dev_info(msdev->dev, + "Delayed onkey change aborted. " + "Another action in progress\n"); + } else { + if (gpio_get_value(msdev->rsthc_pin) != msdev->power_state) { + if (0 == msdev->power_state) + modem_power_off(msdev); + else + modem_power_on(msdev); + } + } + spin_unlock_irqrestore(&msdev->lock, flags); +} + +static void modem_vbat_off_timeout(unsigned long data) +{ + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + unsigned long flags; + spin_lock_irqsave(&msdev->lock, flags); + if (0 == msdev->power_state) + modem_vbat_set_value(msdev, 0); + spin_unlock_irqrestore(&msdev->lock, flags); +} + +static void modem_busy_on_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + mod_timer(&msdev->busy_timer, jiffies + 1); + } else { + msdev->busy_timer.function = NULL; + modem_power_on(msdev); + } + spin_unlock_irqrestore(&msdev->lock, flags); +} + +static void modem_busy_off_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + mod_timer(&msdev->busy_timer, jiffies + 1); + } else { + msdev->busy_timer.function = NULL; + modem_power_off(msdev); + } + spin_unlock_irqrestore(&msdev->lock, flags); +} + +static void modem_busy_reset_timeout(unsigned long data) +{ + unsigned long flags; + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + + spin_lock_irqsave(&msdev->lock, flags); + if (msdev->busy) { + mod_timer(&msdev->busy_timer, jiffies + 1); + } else { + msdev->busy_timer.function = NULL; + modem_reset(msdev); + } + spin_unlock_irqrestore(&msdev->lock, flags); +} + +#ifdef DEBUG +static int callback_test(unsigned long data) +{ + struct modem_state_dev *msdev = (struct modem_state_dev *)data; + dev_info(msdev->dev, "Test callback. Modem state is %s\n", + modem_state_to_str(modem_state_get_state())); + return 0; +} +#endif + +/* Exported functions */ + +void modem_state_power_on(void) +{ + unsigned long flags; + spin_lock_irqsave(&modem_state->lock, flags); + if (modem_state->busy) { + /* + * Ignore on request if turning off is queued, + * cancel any queued reset request + */ + if (modem_busy_reset_timeout == + modem_state->busy_timer.function) { + del_timer_sync(&modem_state->busy_timer); + modem_state->busy_timer.function = NULL; + } + if (NULL == modem_state->busy_timer.function) { + modem_state->busy_timer.function = + modem_busy_on_timeout; + modem_state->busy_timer.data = + (unsigned long)modem_state; + mod_timer(&modem_state->busy_timer, jiffies + 1); + } + } else { + modem_power_on(modem_state); + } + spin_unlock_irqrestore(&modem_state->lock, flags); +} + +void modem_state_power_off(void) +{ + unsigned long flags; + spin_lock_irqsave(&modem_state->lock, flags); + if (modem_state->busy) { + /* + * Prioritize off request if others are queued. + * Must turn modem off if system is shutting down + */ + if (NULL != modem_state->busy_timer.function) + del_timer_sync(&modem_state->busy_timer); + + modem_state->busy_timer.function = modem_busy_off_timeout; + modem_state->busy_timer.data = (unsigned long)modem_state; + mod_timer(&modem_state->busy_timer, jiffies + 1); + } else { + modem_power_off(modem_state); + } + spin_unlock_irqrestore(&modem_state->lock, flags); +} + +void modem_state_force_reset(void) +{ + unsigned long flags; + spin_lock_irqsave(&modem_state->lock, flags); + if (modem_state->busy) { + /* Ignore reset request if turning on or off is queued */ + if (NULL == modem_state->busy_timer.function) { + modem_state->busy_timer.function = + modem_busy_reset_timeout; + modem_state->busy_timer.data = + (unsigned long)modem_state; + mod_timer(&modem_state->busy_timer, jiffies + 1); + } + } else { + modem_reset(modem_state); + } + spin_unlock_irqrestore(&modem_state->lock, flags); +} + +int modem_state_get_state(void) +{ + return get_modem_state(modem_state); +} + +char *modem_state_to_str(int state) +{ + if (state > MODEM_STATE_END_MARKER) + state = MODEM_STATE_END_MARKER; + + return modem_state_str[state]; +} + +int modem_state_register_callback(int (*callback) (unsigned long), + unsigned long data) +{ + struct callback_list *item; + unsigned long flags; + + if (NULL == modem_state) + return -EAGAIN; + + if (NULL == callback) + return -EINVAL; + + item = kzalloc(sizeof(*item), GFP_KERNEL); + if (NULL == item) { + dev_err(modem_state->dev, + "Could not allocate memory for struct callback_list\n"); + return -ENOMEM; + } + item->callback = callback; + item->data = data; + + spin_lock_irqsave(&modem_state->lock, flags); + list_add_tail(&item->node, &callback_list); + spin_unlock_irqrestore(&modem_state->lock, flags); + + return 0; +} + +int modem_state_remove_callback(int (*callback) (unsigned long)) +{ + struct callback_list *iterator; + struct callback_list *item; + unsigned long flags; + int ret = -ENXIO; + + if (NULL == callback) + return -EINVAL; + + spin_lock_irqsave(&modem_state->lock, flags); + list_for_each_entry_safe(iterator, item, &callback_list, node) { + if (callback == item->callback) { + list_del(&item->node); + kfree(item); + ret = 0; + break; + } + } + spin_unlock_irqrestore(&modem_state->lock, flags); + + return ret; +} + +#ifdef CONFIG_PM +int modem_state_suspend(struct device *dev) +{ + struct modem_state_dev *msdev = + platform_get_drvdata(to_platform_device(dev)); + + if (msdev->busy) { + dev_info(dev, "Driver is busy\n"); + return -EBUSY; + } else { + return 0; + } +} + +int modem_state_resume(struct device *dev) +{ + return 0; +} +#endif + +static int __devinit modem_state_probe(struct platform_device *pdev) +{ + int err = 0; + + dev_info(&pdev->dev, "Starting probe\n"); + + modem_state = kzalloc(sizeof(struct modem_state_dev), GFP_KERNEL); + if (NULL == modem_state) { + dev_err(&pdev->dev, + "Could not allocate memory for modem_state_dev\n"); + return -ENOMEM; + } + modem_state->dev = &pdev->dev; + + spin_lock_init(&modem_state->lock); + + INIT_WORK(&modem_state->wq_rsthc, wq_rsthc); + INIT_WORK(&modem_state->wq_rstext, wq_rstext); + INIT_WORK(&modem_state->wq_crash, wq_crash); + modem_state->workqueue = + create_singlethread_workqueue(dev_name(&pdev->dev)); + if (modem_state->workqueue == NULL) { + dev_err(&pdev->dev, "Failed to create workqueue\n"); + goto err_queue; + } + + err = modem_state_dev_init(pdev, modem_state); + if (err != 0) { + dev_err(&pdev->dev, "Could not initialize device structure\n"); + goto err_dev; + } + + init_timer(&modem_state->onkey_timer); + init_timer(&modem_state->reset_timer); + init_timer(&modem_state->onkey_debounce_timer); + init_timer(&modem_state->vbat_off_timer); + init_timer(&modem_state->busy_timer); + modem_state->onkey_timer.function = modem_power_timeout; + modem_state->reset_timer.function = modem_reset_timeout; + modem_state->onkey_debounce_timer.function = + modem_onkey_debounce_timeout; + modem_state->vbat_off_timer.function = modem_vbat_off_timeout; + modem_state->busy_timer.function = NULL; + + platform_set_drvdata(pdev, modem_state); + + err = modem_state_gpio_init(pdev, modem_state); + if (err != 0) { + dev_err(&pdev->dev, "Could not initialize GPIO\n"); + goto err_gpio; + } + + if (sysfs_create_group(&pdev->dev.kobj, &modemstate_attr_group) < 0) { + dev_err(&pdev->dev, "failed to create sysfs nodes\n"); + goto err_sysfs; + } + +#ifdef CONFIG_DEBUG_FS + modem_state->debugfsdir = debugfs_create_dir("modemstate", NULL); + modem_state->debugfs_debug = debugfs_create_file("debug", + S_IRUGO | S_IWUGO, + modem_state->debugfsdir, + modem_state, + &debugfs_debug_fops); +#endif + +#ifdef DEBUG + modem_state_register_callback(callback_test, + (unsigned long)modem_state); +#endif + return 0; + +err_sysfs: +err_gpio: +err_dev: + destroy_workqueue(modem_state->workqueue); +err_queue: + kfree(modem_state); + return err; +} + +static int __devexit modem_state_remove(struct platform_device *pdev) +{ + struct modem_state_dev *msdev = platform_get_drvdata(pdev); + + sysfs_remove_group(&pdev->dev.kobj, &modemstate_attr_group); + destroy_workqueue(msdev->workqueue); + kfree(msdev); + return 0; +} + +static void modem_state_shutdown(struct platform_device *pdev) +{ + /* + * Trigger software shutdown of the modem and then wait until + * modem-off state is detected. If the modem does not power off + * when requested power will be removed and we will detect the + * modem-off state that way. + */ + modem_state_power_off(); + if (MODEM_STATE_OFF != modem_state_get_state()) + dev_alert(&pdev->dev, "Waiting for modem to power down\n"); + while (MODEM_STATE_OFF != modem_state_get_state()) + cond_resched(); +} + +#ifdef CONFIG_PM +static const struct dev_pm_ops modem_state_dev_pm_ops = { + .suspend_noirq = modem_state_suspend, + .resume_noirq = modem_state_resume, +}; +#endif + +static struct platform_driver modem_state_driver = { + .probe = modem_state_probe, + .remove = __devexit_p(modem_state_remove), + .shutdown = modem_state_shutdown, + .driver = { + .name = "modemstate", + .owner = THIS_MODULE, +#ifdef CONFIG_PM + .pm = &modem_state_dev_pm_ops, +#endif + }, +}; + +static int __init modem_state_init(void) +{ +#ifdef DEBUG + printk(KERN_ALERT "Modem state driver init\n"); +#endif + return platform_driver_probe(&modem_state_driver, modem_state_probe); +} + +static void __exit modem_state_exit(void) +{ + platform_driver_unregister(&modem_state_driver); +} + +module_init(modem_state_init); +module_exit(modem_state_exit); + +MODULE_AUTHOR("Derek Morton"); +MODULE_DESCRIPTION("M6718 modem power state driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/modem/m6718_spi/modem_state.h b/include/linux/modem/m6718_spi/modem_state.h new file mode 100644 index 00000000000..a2f1d9fbe3e --- /dev/null +++ b/include/linux/modem/m6718_spi/modem_state.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Derek Morton + * + * License terms: GNU General Public License (GPL) version 2 + * + * Power state driver for M6718 MODEM + */ +#ifndef MODEM_STATE_H +#define MODEM_STATE_H + +enum modem_states { + MODEM_STATE_OFF, + MODEM_STATE_RESET, + MODEM_STATE_CRASH, + MODEM_STATE_ON, + /* + * Add new states before end marker and update modem_state_str[] + * in modem_state.c + */ + MODEM_STATE_END_MARKER +}; + +void modem_state_power_on(void); +void modem_state_power_off(void); +void modem_state_force_reset(void); +int modem_state_get_state(void); +char *modem_state_to_str(int state); + +/* Callbacks will be running in tasklet context */ +int modem_state_register_callback(int (*callback) (unsigned long), + unsigned long data); +int modem_state_remove_callback(int (*callback) (unsigned long)); + +#endif -- cgit v1.2.3 From 56972bcf391f80737671ff89badd69fd9101f2c5 Mon Sep 17 00:00:00 2001 From: Chris Blair Date: Fri, 4 Nov 2011 11:03:27 +0000 Subject: modem: Add M6718 IPC SPI driver protocol framework Adds the M6718 modem IPC SPI driver procotol framework and types. Placeholders remain where future parts of the protocol will be called. ST-Ericsson ID: 369397 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12224 ST-Ericsson Linux next: NA Change-Id: Id4cd5a7fa730c06838c9dd5b1a1cc0045135fdd4 Signed-off-by: Chris Blair Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36466 Reviewed-by: QATOOLS Reviewed-by: QABUILD Reviewed-by: Jonas ABERG --- drivers/modem/m6718_spi/Makefile | 2 +- drivers/modem/m6718_spi/modem_driver.c | 26 ++- drivers/modem/m6718_spi/modem_private.h | 103 ++++++++++ drivers/modem/m6718_spi/modem_protocol.h | 22 ++ drivers/modem/m6718_spi/modem_state.c | 2 +- drivers/modem/m6718_spi/modem_state.h | 36 ++++ drivers/modem/m6718_spi/modem_statemachine.h | 74 +++++++ drivers/modem/m6718_spi/protocol.c | 287 +++++++++++++++++++++++++++ include/linux/modem/m6718_spi/modem_driver.h | 32 ++- include/linux/modem/m6718_spi/modem_state.h | 36 ---- 10 files changed, 579 insertions(+), 41 deletions(-) create mode 100644 drivers/modem/m6718_spi/modem_private.h create mode 100644 drivers/modem/m6718_spi/modem_protocol.h create mode 100644 drivers/modem/m6718_spi/modem_state.h create mode 100644 drivers/modem/m6718_spi/modem_statemachine.h create mode 100644 drivers/modem/m6718_spi/protocol.c delete mode 100644 include/linux/modem/m6718_spi/modem_state.h (limited to 'include') diff --git a/drivers/modem/m6718_spi/Makefile b/drivers/modem/m6718_spi/Makefile index 492995bc753..66bad09c0dd 100644 --- a/drivers/modem/m6718_spi/Makefile +++ b/drivers/modem/m6718_spi/Makefile @@ -5,7 +5,7 @@ ifeq ($(CONFIG_MODEM_M6718_SPI_DEBUG),y) EXTRA_CFLAGS += -DDEBUG endif -m6718_modem_spi-objs := modem_driver.o +m6718_modem_spi-objs := modem_driver.o protocol.o ifeq ($(CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE),y) m6718_modem_spi-objs += modem_state.o diff --git a/drivers/modem/m6718_spi/modem_driver.c b/drivers/modem/m6718_spi/modem_driver.c index 7d0efa6e395..13d4a3e28b2 100644 --- a/drivers/modem/m6718_spi/modem_driver.c +++ b/drivers/modem/m6718_spi/modem_driver.c @@ -13,6 +13,7 @@ #include #include #include +#include "modem_protocol.h" static struct modem_spi_dev modem_driver_data = { .dev = NULL, @@ -53,6 +54,13 @@ static int spi_probe(struct spi_device *sdev) spi_set_drvdata(sdev, &modem_driver_data); + if (modem_protocol_probe(sdev) != 0) { + dev_err(&sdev->dev, + "failed to initialise link protocol\n"); + result = -ENODEV; + goto rollback; + } + /* * Since we can have multiple spi links for the same modem, only * initialise the modem data and char/net interfaces once. @@ -65,13 +73,20 @@ static int spi_probe(struct spi_device *sdev) dev_err(&sdev->dev, "failed to retrieve modem description\n"); result = -ENODEV; + goto rollback_protocol_init; } } return result; + +rollback_protocol_init: + modem_protocol_exit(); +rollback: + return result; } static int __exit spi_remove(struct spi_device *sdev) { + modem_protocol_exit(); return 0; } @@ -86,8 +101,14 @@ static int __exit spi_remove(struct spi_device *sdev) */ static int spi_suspend(struct spi_device *sdev, pm_message_t mesg) { - dev_dbg(&sdev->dev, "suspend called\n"); - return 0; + bool busy; + + busy = modem_protocol_is_busy(sdev); + dev_dbg(&sdev->dev, "suspend called, protocol busy:%d\n", busy); + if (!busy) + return 0; + else + return -EBUSY; } /** @@ -118,6 +139,7 @@ static struct spi_driver spi_driver = { static int __init m6718_spi_driver_init(void) { pr_info("M6718 modem driver initialising\n"); + modem_protocol_init(); return spi_register_driver(&spi_driver); } module_init(m6718_spi_driver_init); diff --git a/drivers/modem/m6718_spi/modem_private.h b/drivers/modem/m6718_spi/modem_private.h new file mode 100644 index 00000000000..383699f1f3e --- /dev/null +++ b/drivers/modem/m6718_spi/modem_private.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_driver.h + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC driver protocol interface header: + * private data + */ +#ifndef _MODEM_PRIVATE_H_ +#define _MODEM_PRIVATE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "modem_protocol.h" +#include "modem_statemachine.h" + +#define IPC_DRIVER_VERSION (0x03) /* APE protocol version */ +#define IPC_DRIVER_MODEM_MIN_VER (0x03) /* version required from modem */ + +#define IPC_NBR_SUPPORTED_SPI_LINKS (2) +#define IPC_LINK_COMMON (0) +#define IPC_LINK_AUDIO (1) + +#define IPC_TX_QUEUE_MAX_SIZE (1024*1024) + +#define IPC_L1_HDR_SIZE (4) +#define IPC_L2_HDR_SIZE (4) + +/* tx queue item (frame) */ +struct ipc_tx_queue { + struct list_head node; + int actual_len; + int len; + void *data; + int counter; +}; + +/* context structure for an spi link */ +struct ipc_link_context { + struct modem_m6718_spi_link_platform_data *link; + struct spi_device *sdev; + atomic_t gpio_configured; + atomic_t state_int; + spinlock_t sm_lock; + spinlock_t tx_q_update_lock; + atomic_t tx_q_count; + int tx_q_free; + struct list_head tx_q; + int tx_frame_counter; + const struct ipc_sm_state *state; + u32 cmd; + struct ipc_tx_queue *frame; + struct spi_message spi_message; + struct spi_transfer spi_transfer; + struct timer_list comms_timer; + struct timer_list slave_stable_timer; +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_VERIFY_FRAMES + struct ipc_tx_queue *last_frame; +#endif +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_THROUGHPUT_MEASUREMENT + u32 tx_bytes; + u32 rx_bytes; + unsigned long idl_measured_at; + unsigned long idl_idle_enter; + unsigned long idl_idle_total; +#endif +#ifdef CONFIG_DEBUG_FS + struct dentry *debugfsfile; + u8 lastevent; + u8 lastignored; + enum ipc_sm_state_id lastignored_in; + bool lastignored_inthis; + int tx_q_min; + unsigned long statesince; +#endif +}; + +/* context structure for the spi driver */ +struct ipc_l1_context { + bool init_done; + atomic_t boot_sync_done; + struct ipc_link_context device_context[IPC_NBR_SUPPORTED_SPI_LINKS]; +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_THROUGHPUT_MEASUREMENT + struct timer_list tp_timer; +#endif +#ifdef CONFIG_DEBUG_FS + struct dentry *debugfsdir; + struct dentry *debugfs_silentreset; + bool msr_disable; +#endif +}; + +#endif /* _MODEM_PRIVATE_H_ */ diff --git a/drivers/modem/m6718_spi/modem_protocol.h b/drivers/modem/m6718_spi/modem_protocol.h new file mode 100644 index 00000000000..69511945cb5 --- /dev/null +++ b/drivers/modem/m6718_spi/modem_protocol.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_driver.h + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC driver protocol interface header. + */ +#ifndef _MODEM_PROTOCOL_H_ +#define _MODEM_PROTOCOL_H_ + +#include + +void modem_protocol_init(void); +int modem_protocol_probe(struct spi_device *sdev); +void modem_protocol_exit(void); +bool modem_protocol_is_busy(struct spi_device *sdev); +bool modem_protocol_channel_is_open(u8 channel); + +#endif /* _MODEM_PROTOCOL_H_ */ diff --git a/drivers/modem/m6718_spi/modem_state.c b/drivers/modem/m6718_spi/modem_state.c index 266f75a7a71..47376934bcb 100644 --- a/drivers/modem/m6718_spi/modem_state.c +++ b/drivers/modem/m6718_spi/modem_state.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include "modem_state.h" /* * To enable this driver add a struct platform_device in the board diff --git a/drivers/modem/m6718_spi/modem_state.h b/drivers/modem/m6718_spi/modem_state.h new file mode 100644 index 00000000000..a2f1d9fbe3e --- /dev/null +++ b/drivers/modem/m6718_spi/modem_state.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Derek Morton + * + * License terms: GNU General Public License (GPL) version 2 + * + * Power state driver for M6718 MODEM + */ +#ifndef MODEM_STATE_H +#define MODEM_STATE_H + +enum modem_states { + MODEM_STATE_OFF, + MODEM_STATE_RESET, + MODEM_STATE_CRASH, + MODEM_STATE_ON, + /* + * Add new states before end marker and update modem_state_str[] + * in modem_state.c + */ + MODEM_STATE_END_MARKER +}; + +void modem_state_power_on(void); +void modem_state_power_off(void); +void modem_state_force_reset(void); +int modem_state_get_state(void); +char *modem_state_to_str(int state); + +/* Callbacks will be running in tasklet context */ +int modem_state_register_callback(int (*callback) (unsigned long), + unsigned long data); +int modem_state_remove_callback(int (*callback) (unsigned long)); + +#endif diff --git a/drivers/modem/m6718_spi/modem_statemachine.h b/drivers/modem/m6718_spi/modem_statemachine.h new file mode 100644 index 00000000000..bc737dbb7e8 --- /dev/null +++ b/drivers/modem/m6718_spi/modem_statemachine.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC driver protocol interface header: + * statemachine functionality. + */ +#ifndef _MODEM_STATEMACHINE_H_ +#define _MODEM_STATEMACHINE_H_ + +#include + +/* valid states for the driver state machine */ +enum ipc_sm_state_id { + /* common link and shared states below */ + IPC_SM_INIT, + IPC_SM_HALT, + IPC_SM_RESET, + IPC_SM_WAIT_SLAVE_STABLE, + IPC_SM_WAIT_HANDSHAKE_INACTIVE, + IPC_SM_SLW_TX_BOOTREQ, + IPC_SM_ACT_TX_BOOTREQ, + IPC_SM_SLW_RX_BOOTRESP, + IPC_SM_ACT_RX_BOOTRESP, + IPC_SM_IDL, + IPC_SM_SLW_TX_WR_CMD, + IPC_SM_ACT_TX_WR_CMD, + IPC_SM_SLW_TX_WR_DAT, + IPC_SM_ACT_TX_WR_DAT, + IPC_SM_SLW_TX_RD_CMD, + IPC_SM_ACT_TX_RD_CMD, + IPC_SM_SLW_RX_WR_CMD, + IPC_SM_ACT_RX_WR_CMD, + IPC_SM_ACT_RX_WR_DAT, + /* audio link states below */ + IPC_SM_INIT_AUD, + IPC_SM_HALT_AUD, + IPC_SM_RESET_AUD, + IPC_SM_IDL_AUD, + IPC_SM_SLW_TX_WR_DAT_AUD, + IPC_SM_ACT_TX_WR_DAT_AUD, + IPC_SM_SLW_RX_WR_DAT_AUD, + IPC_SM_ACT_RX_WR_DAT_AUD, + IPC_SM_STATE_ID_NBR +}; + +/* state machine trigger causes events */ +#define IPC_SM_RUN_NONE (0x00) +#define IPC_SM_RUN_SLAVE_IRQ (0x01) +#define IPC_SM_RUN_TFR_COMPLETE (0x02) +#define IPC_SM_RUN_TX_REQ (0x04) +#define IPC_SM_RUN_INIT (0x08) +#define IPC_SM_RUN_ABORT (0x10) +#define IPC_SM_RUN_COMMS_TMO (0x20) +#define IPC_SM_RUN_STABLE_TMO (0x40) +#define IPC_SM_RUN_RESET (0x80) + +struct ipc_link_context; /* forward declaration */ + +typedef u8 (*ipc_sm_enter_func)(u8 event, struct ipc_link_context *context); +typedef const struct ipc_sm_state *(*ipc_sm_exit_func)(u8 event, + struct ipc_link_context *context); + +struct ipc_sm_state { + enum ipc_sm_state_id id; + ipc_sm_enter_func enter; + ipc_sm_exit_func exit; + u8 events; +}; + +#endif /* _MODEM_STATEMACHINE_H_ */ diff --git a/drivers/modem/m6718_spi/protocol.c b/drivers/modem/m6718_spi/protocol.c new file mode 100644 index 00000000000..5f03167d024 --- /dev/null +++ b/drivers/modem/m6718_spi/protocol.c @@ -0,0 +1,287 @@ +/* + * Copyright (C) ST-Ericsson SA 2010,2011 + * + * Author: Chris Blair for ST-Ericsson + * + * License terms: GNU General Public License (GPL) version 2 + * + * U9500 <-> M6718 IPC protocol implementation using SPI. + */ +#include +#include "modem_protocol.h" +#include "modem_private.h" + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE +#include +#include "modem_state.h" + +#define MODEM_STATE_REGISTER_TMO_MS (500) +#endif + +#ifdef WORKAROUND_DUPLICATED_IRQ +#include +#endif + +struct l2mux_channel { + u8 open:1; + u8 link:7; +}; + +/* valid open L2 mux channels */ +static const struct l2mux_channel channels[255] = { + [MODEM_M6718_SPI_CHN_ISI] = { + .open = true, + .link = IPC_LINK_COMMON + }, + [MODEM_M6718_SPI_CHN_AUDIO] = { + .open = true, + .link = IPC_LINK_AUDIO + }, + [MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0] = { + .open = true, + .link = IPC_LINK_COMMON + }, + [MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0] = { + .open = true, + .link = IPC_LINK_COMMON + }, + [MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1] = { + .open = true, + .link = IPC_LINK_AUDIO + }, + [MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1] = { + .open = true, + .link = IPC_LINK_AUDIO + } +}; + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE +static void modem_state_reg_wq(struct work_struct *work); +static DECLARE_DELAYED_WORK(modem_state_reg_work, modem_state_reg_wq); +#endif + +/* the spi driver context */ +struct ipc_l1_context l1_context = { +#ifdef CONFIG_DEBUG_FS + .msr_disable = false, +#endif + .init_done = false +}; + +bool modem_protocol_channel_is_open(u8 channel) +{ + return channels[channel].open; +} + +void modem_comms_timeout(unsigned long data) +{ + /* TODO: statemachine will be kicked here */ +} + +void slave_stable_timeout(unsigned long data) +{ + /* TODO: statemachine will be kicked here */ +} + +/** + * modem_protocol_init() - initialise the IPC protocol + * + * Initialises the IPC protocol in preparation for use. After this is called + * the protocol is ready to be probed for each link to be supported. + */ +void modem_protocol_init(void) +{ + pr_info("M6718 IPC protocol initialising version %02x\n", + IPC_DRIVER_VERSION); + + atomic_set(&l1_context.boot_sync_done, 0); + l1_context.init_done = true; +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE + schedule_delayed_work(&modem_state_reg_work, 0); +#endif +} + +/** + * modem_m6718_spi_send() - send a frame using the IPC protocol + * @modem_spi_dev: pointer to modem driver information structure + * @channel: L2 channel to send on + * @len: length of data to send + * @data: pointer to buffer containing data + * + * Check that the requested channel is supported and open, queue a frame + * containing the data on the appropriate link and ensure the state machine + * is running to start the transfer. + */ +int modem_m6718_spi_send(struct modem_spi_dev *modem_spi_dev, u8 channel, + u32 len, void *data) +{ + struct ipc_link_context *context; + + if (!channels[channel].open) { + dev_err(modem_spi_dev->dev, + "error: invalid channel (%d), discarding frame\n", + channel); + return -EINVAL; + } + + context = &l1_context.device_context[channels[channel].link]; + if (context->state == NULL || context->state->id == IPC_SM_HALT) { + static unsigned long linkfail_warn_time; + if (printk_timed_ratelimit(&linkfail_warn_time, 60 * 1000)) + dev_err(modem_spi_dev->dev, + "error: link %d for ch %d is not available, " + "discarding frames\n", + channels[channel].link, channel); + return -ENODEV; + } + + /* TODO: statemachine will be kicked here */ + return 0; +} +EXPORT_SYMBOL_GPL(modem_m6718_spi_send); + +/** + * modem_m6718_spi_is_boot_done() - check if boot handshake with modem is done + */ +bool modem_m6718_spi_is_boot_done(void) +{ + return atomic_read(&l1_context.boot_sync_done); +} +EXPORT_SYMBOL_GPL(modem_m6718_spi_is_boot_done); + +/** + * modem_protocol_is_busy() - check if the protocol is currently active + * @sdev: pointer to spi_device for link to check + * + * Checks each of the IPC links to see if they are inactive: this means they + * can be in either IDLE or INIT states. If any of the links are not idle then + * true is returned to indicate that the protocol is busy. + */ +bool modem_protocol_is_busy(struct spi_device *sdev) +{ + int i; + + for (i = 0; i < IPC_NBR_SUPPORTED_SPI_LINKS; i++) + switch (l1_context.device_context[i].state->id) { + case IPC_SM_IDL: + case IPC_SM_IDL_AUD: + case IPC_SM_INIT: + case IPC_SM_INIT_AUD: + case IPC_SM_WAIT_SLAVE_STABLE: + /* not busy; continue checking */ + break; + default: + dev_info(&sdev->dev, "link %d is busy\n", i); + return true; + } + return false; +} + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_MODEM_STATE +static int modem_state_callback(unsigned long unused) +{ + int modem_state = modem_state_get_state(); + + pr_info("M6718 IPC protocol modemstate reports modem is %s\n", + modem_state_to_str(modem_state)); + + switch (modem_state) { + case MODEM_STATE_ON: + /* TODO: statemachine will be kicked here */ + break; + case MODEM_STATE_OFF: + case MODEM_STATE_RESET: + case MODEM_STATE_CRASH: + /* TODO: statemachine will be kicked here */ + break; + default: + break; + } + return 0; +} + +static void modem_state_reg_wq(struct work_struct *work) +{ + if (modem_state_register_callback(modem_state_callback, 0) == -EAGAIN) { + pr_info("M6718 IPC protocol failed to register with " + "modemstate, will retry\n"); + schedule_delayed_work(&modem_state_reg_work, + (MODEM_STATE_REGISTER_TMO_MS * HZ) / 1000); + } else { + pr_info("M6718 IPC protocol registered with modemstate\n"); + } +} +#endif + +int modem_protocol_probe(struct spi_device *sdev) +{ + struct modem_m6718_spi_link_platform_data *link = + sdev->dev.platform_data; + struct ipc_link_context *context; + int link_id; + + if (link == NULL) { + /* platform data missing in board config? */ + dev_err(&sdev->dev, "error: no platform data for link!\n"); + return -ENODEV; + } + + link_id = link->id; + context = &l1_context.device_context[link_id]; + + if (link_id >= IPC_NBR_SUPPORTED_SPI_LINKS) { + dev_err(&sdev->dev, + "link %d error: too many links! (max %d)\n", + link->id, IPC_NBR_SUPPORTED_SPI_LINKS); + return -ENODEV; + } + + dev_info(&sdev->dev, + "link %d: registering SPI link bus:%d cs:%d\n", + link->id, sdev->master->bus_num, sdev->chip_select); + + /* update spi device with correct word size for our device */ + sdev->bits_per_word = 16; + spi_setup(sdev); + + /* init link context */ + context->link = link; + context->sdev = sdev; + atomic_set(&context->gpio_configured, 0); + spin_lock_init(&context->sm_lock); + init_timer(&context->comms_timer); + context->comms_timer.function = modem_comms_timeout; + context->comms_timer.data = (unsigned long)context; + init_timer(&context->slave_stable_timer); + context->slave_stable_timer.function = slave_stable_timeout; + context->slave_stable_timer.data = (unsigned long)context; + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_VERIFY_FRAMES + context->last_frame = NULL; +#endif + + /* + * For link0 (the handshake link) we force a state transition now so + * that it prepares for boot sync. + */ + /* TODO: statemachine will be kicked here */ + + /* + * unlikely but possible: for links other than 0, check if handshake is + * already complete by the time this link is probed - if so we force a + * state transition since the one issued by the handshake exit actions + * will have been ignored. + */ + if (link->id > 0 && atomic_read(&l1_context.boot_sync_done)) { + dev_dbg(&sdev->dev, + "link %d: boot sync is done, kicking state machine\n", + link->id); + /* TODO: statemachine will be kicked here */ + } + return 0; +} + +void modem_protocol_exit(void) +{ + pr_info("M6718 IPC protocol exit\n"); +} diff --git a/include/linux/modem/m6718_spi/modem_driver.h b/include/linux/modem/m6718_spi/modem_driver.h index 8c5209c228c..f3aae4a7116 100644 --- a/include/linux/modem/m6718_spi/modem_driver.h +++ b/include/linux/modem/m6718_spi/modem_driver.h @@ -128,8 +128,38 @@ struct modem_spi_dev { bool msr_flag; }; -/* function exported for L1 to call with received frames */ +/** + * struct modem_m6718_spi_link_gpio - gpio configuration for an IPC link + * @ss_pin: pins to use for slave-select + * @ss_active: active level for slave-select pin + * @int_pin: pin to use for slave-int (ready) + * @int_active: active level for slave-int + */ +struct modem_m6718_spi_link_gpio { + int ss_pin; + int ss_active; + int int_pin; + int int_active; +}; + +/** + * struct modem_m6718_spi_link_platform_data - IPC link data + * @id: link id + * @gpio: link gpio configuration + * @name: link name (to appear in debugfs) + */ +struct modem_m6718_spi_link_platform_data { + int id; + struct modem_m6718_spi_link_gpio gpio; +#ifdef CONFIG_DEBUG_FS + const char *name; +#endif +}; + int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, u32 len, void *data); +int modem_m6718_spi_send(struct modem_spi_dev *modem_spi_dev, u8 channel, + u32 len, void *data); +bool modem_m6718_spi_is_boot_done(void); #endif /* _MODEM_DRIVER_H_ */ diff --git a/include/linux/modem/m6718_spi/modem_state.h b/include/linux/modem/m6718_spi/modem_state.h deleted file mode 100644 index a2f1d9fbe3e..00000000000 --- a/include/linux/modem/m6718_spi/modem_state.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) ST-Ericsson SA 2011 - * - * Author: Derek Morton - * - * License terms: GNU General Public License (GPL) version 2 - * - * Power state driver for M6718 MODEM - */ -#ifndef MODEM_STATE_H -#define MODEM_STATE_H - -enum modem_states { - MODEM_STATE_OFF, - MODEM_STATE_RESET, - MODEM_STATE_CRASH, - MODEM_STATE_ON, - /* - * Add new states before end marker and update modem_state_str[] - * in modem_state.c - */ - MODEM_STATE_END_MARKER -}; - -void modem_state_power_on(void); -void modem_state_power_off(void); -void modem_state_force_reset(void); -int modem_state_get_state(void); -char *modem_state_to_str(int state); - -/* Callbacks will be running in tasklet context */ -int modem_state_register_callback(int (*callback) (unsigned long), - unsigned long data); -int modem_state_remove_callback(int (*callback) (unsigned long)); - -#endif -- cgit v1.2.3 From c5648a9b856b3c59d7229a50304e0e976735a4ad Mon Sep 17 00:00:00 2001 From: Chris Blair Date: Sat, 19 Nov 2011 08:29:32 +0000 Subject: modem: Add M6718 IPC SPI driver char interface Adds the char device interface from the modem to userspace. ST-Ericsson ID: 369397 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12224 ST-Ericsson Linux next: NA Change-Id: Ia0a5e8a8e95f28ee4a812795db91dc872b39f560 Signed-off-by: Chris Blair Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36491 Reviewed-by: QATOOLS Reviewed-by: QABUILD Reviewed-by: Jonas ABERG --- drivers/char/Makefile | 1 + drivers/char/m6718_modem_char.c | 722 +++++++++++++++++++++++++++++ drivers/modem/m6718_spi/modem_driver.c | 73 ++- include/linux/modem/m6718_spi/modem_char.h | 26 ++ 4 files changed, 816 insertions(+), 6 deletions(-) create mode 100644 drivers/char/m6718_modem_char.c create mode 100644 include/linux/modem/m6718_spi/modem_char.h (limited to 'include') diff --git a/drivers/char/Makefile b/drivers/char/Makefile index bd155f091c4..a73e2c197cd 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_TELCLOCK) += tlclk.o ifdef CONFIG_PHONET obj-$(CONFIG_U8500_SHRM) += shrm_char.o +obj-$(CONFIG_MODEM_M6718_SPI) += m6718_modem_char.o endif obj-$(CONFIG_MWAVE) += mwave/ diff --git a/drivers/char/m6718_modem_char.c b/drivers/char/m6718_modem_char.c new file mode 100644 index 00000000000..34bfe98aa57 --- /dev/null +++ b/drivers/char/m6718_modem_char.c @@ -0,0 +1,722 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_char.c + * + * License terms: GNU General Public License (GPL) version 2 + * + * M6718 modem char device interface. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NAME "IPC_ISA" + +#define MAX_PDU_SIZE (2000) /* largest frame we need to send */ +#define MAX_RX_FIFO_ENTRIES (10) +#define SIZE_OF_RX_FIFO (MAX_PDU_SIZE * MAX_RX_FIFO_ENTRIES) +#define SIZE_OF_TX_COPY_BUFFER (MAX_PDU_SIZE) /* only need 1 at a time */ + +static u8 message_fifo[MODEM_M6718_SPI_MAX_CHANNELS][SIZE_OF_RX_FIFO]; + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK +static u8 wr_mlb_msg[SIZE_OF_TX_COPY_BUFFER]; +#endif +static u8 wr_audio_msg[SIZE_OF_TX_COPY_BUFFER]; + +struct map_device { + u8 l2_header; + u8 idx; + char *name; +}; + +static struct map_device map_dev[] = { + {MODEM_M6718_SPI_CHN_ISI, 0, "isi"}, + {MODEM_M6718_SPI_CHN_AUDIO, 1, "modemaudio"}, +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK + {MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0, 2, "master_loopback0"}, + {MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0, 3, "slave_loopback0"}, + {MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1, 4, "master_loopback1"}, + {MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1, 5, "slave_loopback1"}, +#endif +}; + +/* + * major - variable exported as module_param to specify major node number + */ +static int major; +module_param(major, int, 0); +MODULE_PARM_DESC(major, "Major device number"); + +/* global fops mutex */ +static DEFINE_MUTEX(isa_lock); + +/** + * modem_get_cdev_index() - return the index mapped to l2 header + * @l2_header: L2 header + * + * struct map_device maps the index(count) with the device L2 header. + * This function returns the index for the provided L2 header in case + * of success else -ve value. + */ +int modem_get_cdev_index(u8 l2_header) +{ + u8 cnt; + for (cnt = 0; cnt < ARRAY_SIZE(map_dev); cnt++) { + if (map_dev[cnt].l2_header == l2_header) + return map_dev[cnt].idx; + } + return -EINVAL; +} +EXPORT_SYMBOL_GPL(modem_get_cdev_index); + +/** + * modem_get_cdev_l2header() - return l2_header mapped to the index + * @idx: index + * + * struct map_device maps the index(count) with the device L2 header. + * This function returns the L2 header for the given index in case + * of success else -ve value. + */ +int modem_get_cdev_l2header(u8 idx) +{ + u8 cnt; + for (cnt = 0; cnt < ARRAY_SIZE(map_dev); cnt++) { + if (map_dev[cnt].idx == idx) + return map_dev[cnt].l2_header; + } + return -EINVAL; +} +EXPORT_SYMBOL_GPL(modem_get_cdev_l2header); + +/** + * modem_isa_reset() - reset device interfaces + * @modem_spi_dev: pointer to modem driver information structure + * + * Emptys the queue for each L2 mux channel. + */ +void modem_isa_reset(struct modem_spi_dev *modem_spi_dev) +{ + struct isa_device_context *isadev; + struct isa_driver_context *isa_context; + struct queue_element *cur_msg = NULL; + struct list_head *cur_msg_ptr = NULL; + struct list_head *msg_ptr; + struct message_queue *q; + int devidx; + + dev_info(modem_spi_dev->dev, "resetting char device queues\n"); + + isa_context = modem_spi_dev->isa_context; + for (devidx = 0; devidx < ARRAY_SIZE(map_dev); devidx++) { + isadev = &isa_context->isadev[devidx]; + q = &isadev->dl_queue; + + spin_lock_bh(&q->update_lock); + /* empty out the msg queue */ + list_for_each_safe(cur_msg_ptr, msg_ptr, &q->msg_list) { + cur_msg = list_entry(cur_msg_ptr, + struct queue_element, entry); + list_del(cur_msg_ptr); + kfree(cur_msg); + } + + /* reset the msg queue pointers */ + q->size = SIZE_OF_RX_FIFO; + q->readptr = 0; + q->writeptr = 0; + q->no = 0; + + /* wake up the blocking read/select */ + atomic_set(&q->q_rp, 1); + wake_up_interruptible(&q->wq_readable); + spin_unlock_bh(&q->update_lock); + } +} +EXPORT_SYMBOL_GPL(modem_isa_reset); + +static void create_queue(struct message_queue *q, u8 channel, + struct modem_spi_dev *modem_spi_dev) +{ + q->channel = channel; + q->fifo_base = (u8 *)&message_fifo[channel]; + q->size = SIZE_OF_RX_FIFO; + q->free = q->size; + q->readptr = 0; + q->writeptr = 0; + q->no = 0; + spin_lock_init(&q->update_lock); + atomic_set(&q->q_rp, 0); + init_waitqueue_head(&q->wq_readable); + INIT_LIST_HEAD(&q->msg_list); + q->modem_spi_dev = modem_spi_dev; +} + +static void delete_queue(struct message_queue *q) +{ + q->size = 0; + q->readptr = 0; + q->writeptr = 0; +} + +/** + * modem_isa_queue_msg() - Add a message to a queue queue + * @q: message queue + * @size: size in bytes + * + * This function tries to allocate size bytes in FIFO q. + * It returns negative number when no memory can be allocated + * currently. + */ +int modem_isa_queue_msg(struct message_queue *q, u32 size) +{ + struct queue_element *new_msg = NULL; + struct modem_spi_dev *modem_spi_dev = q->modem_spi_dev; + + new_msg = kmalloc(sizeof(struct queue_element), GFP_ATOMIC); + if (new_msg == NULL) { + dev_err(modem_spi_dev->dev, + "failed to allocate memory for queue item\n"); + return -ENOMEM; + } + new_msg->offset = q->writeptr; + new_msg->size = size; + new_msg->no = q->no++; + + /* check for overflow condition */ + if (q->readptr <= q->writeptr) { + if (((q->writeptr - q->readptr) + size) >= q->size) { + dev_err(modem_spi_dev->dev, "rx q++ ch %d %d (%d)\n", + q->channel, size, q->free); + dev_err(modem_spi_dev->dev, + "ch%d buffer overflow, frame discarded\n", + q->channel); + return -ENOMEM; + } + } else { + if ((q->writeptr + size) >= q->readptr) { + dev_err(modem_spi_dev->dev, "rx q++ ch %d %d (%d)\n", + q->channel, size, q->free); + dev_err(modem_spi_dev->dev, + "ch%d buffer overflow, frame discarded\n", + q->channel); + return -ENOMEM; + } + } + q->free -= size; + q->writeptr = (q->writeptr + size) % q->size; + if (list_empty(&q->msg_list)) { + list_add_tail(&new_msg->entry, &q->msg_list); + /* There can be 2 blocking calls: read and another select */ + atomic_set(&q->q_rp, 1); + wake_up_interruptible(&q->wq_readable); + } else { + list_add_tail(&new_msg->entry, &q->msg_list); + } + return 0; +} +EXPORT_SYMBOL_GPL(modem_isa_queue_msg); + +/** + * modem_isa_unqueue_msg() - remove a message from the msg queue + * @q: message queue + * + * Deletes a message from the message list associated with message + * queue q and also updates read ptr. If the message list is empty + * then a flag is set to block the select and read calls of the paricular queue. + * + * The message list is FIFO style and message is always added to tail and + * removed from head. + */ +int modem_isa_unqueue_msg(struct message_queue *q) +{ + struct queue_element *old_msg = NULL; + struct list_head *msg_ptr = NULL; + struct list_head *old_msg_ptr = NULL; + + list_for_each_safe(old_msg_ptr, msg_ptr, &q->msg_list) { + old_msg = list_entry(old_msg_ptr, struct queue_element, entry); + if (old_msg == NULL) + return -EFAULT; + list_del(old_msg_ptr); + q->readptr = (q->readptr + old_msg->size) % q->size; + q->free += old_msg->size; + kfree(old_msg); + break; + } + if (list_empty(&q->msg_list)) + atomic_set(&q->q_rp, 0); + return 0; +} +EXPORT_SYMBOL_GPL(modem_isa_unqueue_msg); + +/** + * modem_isa_msg_size() - retrieve the size of the most recent message + * @q: message queue + */ +int modem_isa_msg_size(struct message_queue *q) +{ + struct queue_element *new_msg = NULL; + struct list_head *msg_list; + unsigned long flags; + int size = 0; + + spin_lock_irqsave(&q->update_lock, flags); + list_for_each(msg_list, &q->msg_list) { + new_msg = list_entry(msg_list, struct queue_element, entry); + if (new_msg == NULL) { + spin_unlock_irqrestore(&q->update_lock, flags); + return -EFAULT; + } + size = new_msg->size; + break; + } + spin_unlock_irqrestore(&q->update_lock, flags); + return size; +} +EXPORT_SYMBOL_GPL(modem_isa_msg_size); + +static u32 isa_select(struct file *filp, struct poll_table_struct *wait) +{ + struct isa_device_context *isadev = filp->private_data; + struct modem_spi_dev *modem_spi_dev = isadev->dl_queue.modem_spi_dev; + struct message_queue *q; + u32 m = iminor(filp->f_path.dentry->d_inode); + u8 idx = modem_get_cdev_index(m); + + if (modem_spi_dev->msr_flag) + return -ENODEV; + if (isadev->device_id != idx) + return -1; + + q = &isadev->dl_queue; + poll_wait(filp, &q->wq_readable, wait); + if (atomic_read(&q->q_rp) == 1) + return POLLIN | POLLRDNORM; + return 0; +} + +static ssize_t isa_read(struct file *filp, char __user *buf, + size_t len, loff_t *ppos) +{ + u32 size = 0; + int ret; + char *psrc; + struct isa_device_context *isadev = + (struct isa_device_context *)filp->private_data; + struct message_queue *q = &isadev->dl_queue; + struct modem_spi_dev *modem_spi_dev = q->modem_spi_dev; + u32 msgsize; + unsigned long flags; + + if (len <= 0) + return -EFAULT; + + if (modem_spi_dev->msr_flag) { + atomic_set(&q->q_rp, 0); + return -ENODEV; + } + + spin_lock_irqsave(&q->update_lock, flags); + if (list_empty(&q->msg_list)) { + spin_unlock_irqrestore(&q->update_lock, flags); + dev_dbg(modem_spi_dev->dev, "waiting for data on device %d\n", + isadev->device_id); + if (wait_event_interruptible(q->wq_readable, + atomic_read(&q->q_rp) == 1)) + return -ERESTARTSYS; + } else { + spin_unlock_irqrestore(&q->update_lock, flags); + } + + if (modem_spi_dev->msr_flag) { + atomic_set(&q->q_rp, 0); + return -ENODEV; + } + + msgsize = modem_isa_msg_size(q); + if (len < msgsize) + return -EINVAL; + + if ((q->readptr + msgsize) >= q->size) { + psrc = (char *)buf; + size = (q->size - q->readptr); + /* copy first part of msg */ + if (copy_to_user(psrc, (u8 *)(q->fifo_base + q->readptr), + size)) + return -EFAULT; + + psrc += size; + /* copy second part of msg at the top of fifo */ + if (copy_to_user(psrc, (u8 *)(q->fifo_base), + (msgsize - size))) + return -EFAULT; + } else { + if (copy_to_user(buf, (u8 *)(q->fifo_base + q->readptr), + msgsize)) + return -EFAULT; + } + + spin_lock_irqsave(&q->update_lock, flags); + ret = modem_isa_unqueue_msg(q); + if (ret < 0) + msgsize = ret; + spin_unlock_irqrestore(&q->update_lock, flags); + return msgsize; +} + +static ssize_t isa_write(struct file *filp, const char __user *buf, + size_t len, loff_t *ppos) +{ + struct isa_device_context *isadev = filp->private_data; + struct message_queue *q = &isadev->dl_queue; + struct modem_spi_dev *modem_spi_dev = q->modem_spi_dev; + struct isa_driver_context *isa_context = modem_spi_dev->isa_context; + void *addr = 0; + int err; + int l2_header; + int ret = 0; + unsigned long flags; + + if (len <= 0 || buf == NULL) + return -EFAULT; + + if (len > SIZE_OF_TX_COPY_BUFFER) { + dev_err(modem_spi_dev->dev, + "invalid message size %d! max is %d bytes\n", + len, SIZE_OF_TX_COPY_BUFFER); + return -EFAULT; + } + + l2_header = modem_get_cdev_l2header(isadev->device_id); + if (l2_header < 0) { + dev_err(modem_spi_dev->dev, "invalid L2 channel!\n"); + return l2_header; + } + + switch (l2_header) { + case MODEM_M6718_SPI_CHN_AUDIO: + addr = (void *)wr_audio_msg; + break; + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0: + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0: + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1: + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1: + addr = (void *)wr_mlb_msg; + break; + default: + dev_dbg(modem_spi_dev->dev, "invalid device!\n"); + return -EFAULT; + } + + if (copy_from_user(addr, buf, len)) + return -EFAULT; + + /* + * Special handling for audio channel: + * uses a mutext instead of a spinlock + */ + if (l2_header == MODEM_M6718_SPI_CHN_AUDIO || + l2_header == MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1) { + mutex_lock(&isa_context->audio_tx_mutex); + err = modem_m6718_spi_send(modem_spi_dev, l2_header, len, addr); + if (!err) + ret = len; + else + ret = err; + mutex_unlock(&modem_spi_dev->isa_context->audio_tx_mutex); + } else { + spin_lock_irqsave(&isa_context->common_tx_lock, flags); + err = modem_m6718_spi_send(modem_spi_dev, l2_header, len, addr); + if (!err) + ret = len; + else + ret = err; + spin_unlock_irqrestore(&isa_context->common_tx_lock, flags); + } + return ret; +} + +static long isa_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + return -EINVAL; +} + +static int isa_mmap(struct file *filp, struct vm_area_struct *vma) +{ + return -EINVAL; +} + +static int isa_close(struct inode *inode, struct file *filp) +{ + struct isa_device_context *isadev = filp->private_data; + struct modem_spi_dev *modem_spi_dev = isadev->dl_queue.modem_spi_dev; + struct isa_driver_context *isa_context = modem_spi_dev->isa_context; + u8 m; + int idx; + + mutex_lock(&isa_lock); + m = iminor(filp->f_path.dentry->d_inode); + idx = modem_get_cdev_index(m); + if (idx < 0) { + dev_err(modem_spi_dev->dev, "invalid L2 channel!\n"); + return idx; + } + + if (atomic_dec_and_test(&isa_context->is_open[idx])) { + atomic_inc(&isa_context->is_open[idx]); + dev_err(modem_spi_dev->dev, "device is not open yet!\n"); + mutex_unlock(&isa_lock); + return -ENODEV; + } + atomic_set(&isa_context->is_open[idx], 1); + + switch (m) { + case MODEM_M6718_SPI_CHN_AUDIO: + dev_dbg(modem_spi_dev->dev, "close channel AUDIO\n"); + break; +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0: + dev_dbg(modem_spi_dev->dev, "close channel MASTER_LOOPBACK0\n"); + break; + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0: + dev_dbg(modem_spi_dev->dev, "close channel SLAVE_LOOPBACK0\n"); + break; + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1: + dev_dbg(modem_spi_dev->dev, "close channel MASTER_LOOPBACK1\n"); + break; + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1: + dev_dbg(modem_spi_dev->dev, "close channel SLAVE_LOOPBACK1\n"); + break; +#endif + default: + dev_dbg(modem_spi_dev->dev, "invalid device\n"); + mutex_unlock(&isa_lock); + return -ENODEV; + } + mutex_unlock(&isa_lock); + return 0; +} + +static int isa_open(struct inode *inode, struct file *filp) +{ + int err = 0; + u8 m; + int idx; + struct isa_device_context *isadev; + struct isa_driver_context *isa_context = + container_of(inode->i_cdev, struct isa_driver_context, cdev); + struct modem_spi_dev *modem_spi_dev = + isa_context->isadev->dl_queue.modem_spi_dev; + + if (!modem_m6718_spi_is_boot_done()) { + dev_dbg(modem_spi_dev->dev, + "failed to open device, boot is not complete\n"); + err = -EBUSY; + goto out; + } + + mutex_lock(&isa_lock); + m = iminor(inode); + idx = modem_get_cdev_index(m); + if (idx < 0) { + dev_err(modem_spi_dev->dev, "invalid device\n"); + err = -ENODEV; + goto cleanup; + } + + if (!atomic_dec_and_test(&isa_context->is_open[idx])) { + atomic_inc(&isa_context->is_open[idx]); + dev_err(modem_spi_dev->dev, "device is already open\n"); + err = -EBUSY; + goto cleanup; + } + + isadev = &isa_context->isadev[idx]; + if (filp != NULL) + filp->private_data = isadev; + + switch (m) { + case MODEM_M6718_SPI_CHN_AUDIO: + dev_dbg(modem_spi_dev->dev, "open channel AUDIO\n"); + break; +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK0: + dev_dbg(modem_spi_dev->dev, "open channel MASTER_LOOPBACK0\n"); + break; + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0: + dev_dbg(modem_spi_dev->dev, "open channel SLAVE_LOOPBACK0\n"); + break; + case MODEM_M6718_SPI_CHN_MASTER_LOOPBACK1: + dev_dbg(modem_spi_dev->dev, "open channel MASTER_LOOPBACK1\n"); + break; + case MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1: + dev_dbg(modem_spi_dev->dev, "open channel SLAVE_LOOPBACK1\n"); + break; +#endif + } + +cleanup: + mutex_unlock(&isa_lock); +out: + return err; +} + +const struct file_operations isa_fops = { + .owner = THIS_MODULE, + .open = isa_open, + .release = isa_close, + .unlocked_ioctl = isa_ioctl, + .mmap = isa_mmap, + .read = isa_read, + .write = isa_write, + .poll = isa_select, +}; + +/** + * modem_isa_init() - initialise the modem char device interfaces + * @modem_spi_dev: pointer to the modem driver information structure + * + * This function registers registers as a char device driver and creates the + * char device nodes supported by the modem. + */ +int modem_isa_init(struct modem_spi_dev *modem_spi_dev) +{ + dev_t dev_id; + int retval; + int devidx; + struct isa_device_context *isadev; + struct isa_driver_context *isa_context; + + dev_dbg(modem_spi_dev->dev, "registering char device interfaces\n"); + + isa_context = kzalloc(sizeof(struct isa_driver_context), GFP_KERNEL); + if (isa_context == NULL) { + dev_err(modem_spi_dev->dev, "failed to allocate context\n"); + retval = -ENOMEM; + goto rollback; + } + + modem_spi_dev->isa_context = isa_context; + if (major) { + /* major node specified at module load */ + dev_id = MKDEV(major, 0); + retval = register_chrdev_region(dev_id, + MODEM_M6718_SPI_MAX_CHANNELS, NAME); + } else { + retval = alloc_chrdev_region(&dev_id, 0, + MODEM_M6718_SPI_MAX_CHANNELS, NAME); + major = MAJOR(dev_id); + } + + dev_dbg(modem_spi_dev->dev, "device major is %d\n", major); + + cdev_init(&isa_context->cdev, &isa_fops); + isa_context->cdev.owner = THIS_MODULE; + retval = cdev_add(&isa_context->cdev, dev_id, + MODEM_M6718_SPI_MAX_CHANNELS); + if (retval) { + dev_err(modem_spi_dev->dev, "failed to add char device\n"); + goto rollback_register; + } + + isa_context->modem_class = class_create(THIS_MODULE, NAME); + if (IS_ERR(isa_context->modem_class)) { + dev_err(modem_spi_dev->dev, "failed to create modem class\n"); + retval = PTR_ERR(isa_context->modem_class); + goto rollback_add_dev; + } + isa_context->isadev = kzalloc(sizeof(struct isa_device_context) * + MODEM_M6718_SPI_MAX_CHANNELS, GFP_KERNEL); + if (isa_context->isadev == NULL) { + dev_err(modem_spi_dev->dev, + "failed to allocate device context\n"); + goto rollback_create_dev; + } + + for (devidx = 0; devidx < ARRAY_SIZE(map_dev); devidx++) { + atomic_set(&isa_context->is_open[devidx], 1); + device_create(isa_context->modem_class, + NULL, + MKDEV(MAJOR(dev_id), map_dev[devidx].l2_header), + NULL, + map_dev[devidx].name); + + isadev = &isa_context->isadev[devidx]; + isadev->device_id = devidx; + create_queue(&isadev->dl_queue, + isadev->device_id, modem_spi_dev); + + dev_dbg(modem_spi_dev->dev, "created device %d (%s) (%d.%d)\n", + devidx, map_dev[devidx].name, major, + map_dev[devidx].l2_header); + } + + mutex_init(&isa_context->audio_tx_mutex); + spin_lock_init(&isa_context->common_tx_lock); + + dev_dbg(modem_spi_dev->dev, "registered modem char devices\n"); + return 0; + +rollback_create_dev: + for (devidx = 0; devidx < ARRAY_SIZE(map_dev); devidx++) { + device_destroy(isa_context->modem_class, + MKDEV(MAJOR(dev_id), map_dev[devidx].l2_header)); + } + class_destroy(isa_context->modem_class); +rollback_add_dev: + cdev_del(&isa_context->cdev); +rollback_register: + unregister_chrdev_region(dev_id, MODEM_M6718_SPI_MAX_CHANNELS); + kfree(isa_context); + modem_spi_dev->isa_context = NULL; +rollback: + return retval; +} +EXPORT_SYMBOL_GPL(modem_isa_init); + +/** + * modem_isa_exit() - remove the char device interfaces and clean up + * @modem_spi_dev: pointer to the modem driver information structure + */ +void modem_isa_exit(struct modem_spi_dev *modem_spi_dev) +{ + int devidx; + struct isa_device_context *isadev; + struct isa_driver_context *isa_context = modem_spi_dev->isa_context; + dev_t dev_id = MKDEV(major, 0); + + if (!modem_spi_dev || !modem_spi_dev->isa_context) + return; + + for (devidx = 0; devidx < ARRAY_SIZE(map_dev); devidx++) + device_destroy(isa_context->modem_class, + MKDEV(MAJOR(dev_id), + map_dev[devidx].l2_header)); + for (devidx = 0; devidx < MODEM_M6718_SPI_MAX_CHANNELS; devidx++) { + isadev = &isa_context->isadev[devidx]; + delete_queue(&isadev->dl_queue); + kfree(isadev); + } + class_destroy(isa_context->modem_class); + cdev_del(&isa_context->cdev); + unregister_chrdev_region(dev_id, MODEM_M6718_SPI_MAX_CHANNELS); + kfree(isa_context); + modem_spi_dev->isa_context = NULL; + dev_dbg(modem_spi_dev->dev, "removed modem char devices\n"); +} +EXPORT_SYMBOL_GPL(modem_isa_exit); + +MODULE_AUTHOR("Chris Blair "); +MODULE_DESCRIPTION("M6718 modem IPC char device interface"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/modem/m6718_spi/modem_driver.c b/drivers/modem/m6718_spi/modem_driver.c index 13d4a3e28b2..d85e6943c23 100644 --- a/drivers/modem/m6718_spi/modem_driver.c +++ b/drivers/modem/m6718_spi/modem_driver.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "modem_protocol.h" static struct modem_spi_dev modem_driver_data = { @@ -31,20 +32,70 @@ static struct modem_spi_dev modem_driver_data = { * @data: pointer to frame data * * This function is called from the driver L1 physical transport layer. It - * copied the frame data to the receive queue for the channel on which the data + * copies the frame data to the receive queue for the channel on which the data * was received. * * Special handling is given to slave-loopback channels where the data is simply * sent back to the modem on the same channel. - * - * Special handling is given to the ISI channel when PHONET is enabled - the - * phonet tasklet is scheduled in order to pump the received data through the - * net device interface. */ int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, u32 len, void *data) { - return -ENODEV; + u32 size = 0; + int ret = 0; + int idx; + u8 *psrc; + u32 writeptr; + struct message_queue *q; + struct isa_device_context *isadev; + + dev_dbg(&sdev->dev, "L2 received frame from L1: channel %d len %d\n", + channel, len); + +#ifdef CONFIG_MODEM_M6718_SPI_ENABLE_FEATURE_LOOPBACK + if (channel == MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK0 || + channel == MODEM_M6718_SPI_CHN_SLAVE_LOOPBACK1) { + /* data received on slave loopback channel - loop it back */ + modem_m6718_spi_send(&modem_driver_data, channel, len, data); + return 0; + } +#endif + + /* find the isa device index for this L2 channel */ + idx = modem_get_cdev_index(channel); + if (idx < 0) { + dev_err(&sdev->dev, "failed to get isa device index\n"); + return idx; + } + isadev = &modem_driver_data.isa_context->isadev[idx]; + q = &isadev->dl_queue; + + spin_lock(&q->update_lock); + + /* verify message can be contained in buffer */ + writeptr = q->writeptr; + ret = modem_isa_queue_msg(q, len); + if (ret >= 0) { + /* memcopy RX data */ + if ((writeptr + len) >= q->size) { + psrc = (u8 *)data; + size = q->size - writeptr; + /* copy first part of msg */ + memcpy((q->fifo_base + writeptr), psrc, size); + psrc += size; + /* copy second part of msg at the top of fifo */ + memcpy(q->fifo_base, psrc, (len - size)); + } else { + memcpy((q->fifo_base + writeptr), data, len); + } + } + spin_unlock(&q->update_lock); + + if (ret < 0) { + dev_err(&sdev->dev, "failed to queue frame!"); + return ret; + } + return ret; } EXPORT_SYMBOL_GPL(modem_m6718_spi_receive); @@ -75,9 +126,18 @@ static int spi_probe(struct spi_device *sdev) result = -ENODEV; goto rollback_protocol_init; } + + result = modem_isa_init(&modem_driver_data); + if (result < 0) { + dev_err(&sdev->dev, + "failed to initialise char interface\n"); + goto rollback_modem_get; + } } return result; +rollback_modem_get: + modem_put(modem_driver_data.modem); rollback_protocol_init: modem_protocol_exit(); rollback: @@ -87,6 +147,7 @@ rollback: static int __exit spi_remove(struct spi_device *sdev) { modem_protocol_exit(); + modem_isa_exit(&modem_driver_data); return 0; } diff --git a/include/linux/modem/m6718_spi/modem_char.h b/include/linux/modem/m6718_spi/modem_char.h new file mode 100644 index 00000000000..04d82eaa03c --- /dev/null +++ b/include/linux/modem/m6718_spi/modem_char.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_driver.h + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC driver char interface header. + */ +#ifndef _MODEM_CHAR_H_ +#define _MODEM_CHAR_H_ + +#include + +int modem_isa_init(struct modem_spi_dev *modem_spi_dev); +void modem_isa_exit(struct modem_spi_dev *modem_spi_dev); + +int modem_isa_queue_msg(struct message_queue *q, u32 size); +int modem_isa_msg_size(struct message_queue *q); +int modem_isa_unqueue_msg(struct message_queue *q); +void modem_isa_reset(struct modem_spi_dev *modem_spi_dev); +int modem_get_cdev_index(u8 l2_header); +int modem_get_cdev_l2header(u8 idx); + +#endif /* _MODEM_CHAR_H_ */ -- cgit v1.2.3 From d15cba295cd8b01d7f44a62e636f3e95a51ec497 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Mon, 5 Dec 2011 17:00:02 +0530 Subject: u8500-shrm: DocBook: Remove warnings in shrm driver ST-Ericsson Linux next: NA ST-Ericsson ID: 354484 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I9b086aae5dc697c1b0fccc0913b170c3ef32ea97 Signed-off-by: Arun Murthy Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/41014 Reviewed-by: QABUILD Reviewed-by: Bibek BASU Reviewed-by: Srinidhi KASAGAR --- include/linux/modem/shrm/shrm_driver.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index 689ce207df5..081dfd111e4 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -64,17 +64,18 @@ * @ca_audio_shared_rptr: cmt-ape audio channel read pointer * @dev: pointer to the driver device * @ndev: pointer to the network device structure + * @modem: poiner to struct modem * @isa_context: pointer to t_isa_driver_sontext dtructure - * @shm_common_ch_wr_wk: kthread worker for writing to common channel - * @shm_common_ch_wr_wk_task: task for writing to common channel - * @shm_audio_ch_wr_wk: kthread worker for writing to audio channel - * @shm_audio_ch_wr_wk_task: task for writing to audio channel - * @shm_ac_wake_wk: kthread worker for receiving ape-cmt wake requests - * @shm_ac_wake_wk_task: task for receiving ape-cmt wake requests - * @shm_ca_wake_wk: kthread worker for receiving cmt-ape wake requests - * @shm_ca_wake_wk_task: task for receiving cmt-ape wake requests - * @shm_ac_sleep_wk: kthread worker for recieving ape-cmt sleep requests - * @shm_ac_sleep_wk_task: task for recieving ape-cmt sleep requests + * @shm_common_ch_wr_kw: kthread worker for writing to common channel + * @shm_common_ch_wr_kw_task: task for writing to common channel + * @shm_audio_ch_wr_kw: kthread worker for writing to audio channel + * @shm_audio_ch_wr_kw_task: task for writing to audio channel + * @shm_ac_wake_kw: kthread worker for receiving ape-cmt wake requests + * @shm_ac_wake_kw_task: task for receiving ape-cmt wake requests + * @shm_ca_wake_kw: kthread worker for receiving cmt-ape wake requests + * @shm_ca_wake_kw_task: task for receiving cmt-ape wake requests + * @shm_ac_sleep_kw: kthread worker for recieving ape-cmt sleep requests + * @shm_ac_sleep_kw_task: task for recieving ape-cmt sleep requests * @send_ac_msg_pend_notify_0: work for handling pending message on common * channel * @send_ac_msg_pend_notify_1: work for handling pending message on audio -- cgit v1.2.3 From e6676501bbf6fc77ba3185025a09f3cace501f70 Mon Sep 17 00:00:00 2001 From: Mark Godfrey Date: Fri, 4 Nov 2011 09:39:47 +0000 Subject: u8500: shrm: Add support for RTC Calib messages A new shared-mem IPC logical channel (mapID=200) allows APE to send and receive messages to the modem in support of the calibration of the RealTimeClock. The modem can measure the 32KHz clock drift (against network clock) and report the drift to the APE. This new logical channel supports this reporting and can be accessed via a new /dev/rtc_calibration device. ST-Ericsson ID: 362204 ST-Ericsson Linux next: NA ST-Ericsson FOSS-OUT ID: Trivial Change-Id: Ic0ed097c1bbd8b3a6816642840c258e598b79715 Signed-off-by: Mark Godfrey Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36440 Reviewed-by: QATOOLS Reviewed-by: QABUILD Reviewed-by: Jonas ABERG --- drivers/char/shrm_char.c | 21 ++++++++++++++++++--- drivers/modem/shrm/shrm_protocol.c | 4 +++- include/linux/modem/shrm/shrm_driver.h | 2 +- include/linux/modem/shrm/shrm_private.h | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/drivers/char/shrm_char.c b/drivers/char/shrm_char.c index fa44b469b98..e8f350e5da8 100644 --- a/drivers/char/shrm_char.c +++ b/drivers/char/shrm_char.c @@ -25,8 +25,8 @@ #define NAME "IPC_ISA" -/* L2 header for ciq device is 0xc3 and hence 0xc3+1 = 196*/ -#define MAX_L2_HEADERS 196 +/* L2 header for rtc_calibration device is 0xC8 and hence 0xC8 + 1 = 201 */ +#define MAX_L2_HEADERS 201 #define SIZE_OF_FIFO (512*1024) @@ -35,6 +35,7 @@ static u8 message_fifo[ISA_DEVICES][SIZE_OF_FIFO]; static u8 wr_rpc_msg[10*1024]; static u8 wr_sec_msg[10*1024]; static u8 wr_audio_msg[10*1024]; +static u8 wr_rtc_cal_msg[100]; struct map_device { u8 l2_header; @@ -50,6 +51,7 @@ static struct map_device map_dev[] = { {COMMON_LOOPBACK_MESSAGING, 4, "common_loopback"}, {AUDIO_LOOPBACK_MESSAGING, 5, "audio_loopback"}, {CIQ_MESSAGING, 6, "ciq"}, + {RTC_CAL_MESSAGING, 7, "rtc_calibration"}, }; /* @@ -488,6 +490,10 @@ ssize_t isa_write(struct file *filp, const char __user *buf, dev_dbg(shrm->dev, "CIQ\n"); addr = isadev->addr; break; + case RTC_CAL_MESSAGING: + dev_dbg(shrm->dev, "isa_write(): RTC Calibration\n"); + addr = (void *)wr_rtc_cal_msg; + break; default: dev_dbg(shrm->dev, "Wrong device\n"); return -EFAULT; @@ -612,6 +618,7 @@ static int isa_close(struct inode *inode, struct file *filp) idx = shrm_get_cdev_index(m); if (idx < 0) { dev_err(shrm->dev, "failed to get index\n"); + mutex_unlock(&isa_lock); return idx; } dev_dbg(shrm->dev, "isa_close %d", m); @@ -646,6 +653,9 @@ static int isa_close(struct inode *inode, struct file *filp) kfree(isadev->addr); dev_info(shrm->dev, "Close CIQ_MESSAGING Device\n"); break; + case RTC_CAL_MESSAGING: + dev_info(shrm->dev, "Close RTC_CAL_MESSAGING Device\n"); + break; default: dev_info(shrm->dev, "No such device present\n"); mutex_unlock(&isa_lock); @@ -693,7 +703,8 @@ static int isa_open(struct inode *inode, struct file *filp) (m != COMMON_LOOPBACK_MESSAGING) && (m != AUDIO_MESSAGING) && (m != SECURITY_MESSAGING) && - (m != CIQ_MESSAGING)) { + (m != CIQ_MESSAGING) && + (m != RTC_CAL_MESSAGING)) { dev_err(shrm->dev, "No such device present\n"); mutex_unlock(&isa_lock); return -ENODEV; @@ -701,6 +712,7 @@ static int isa_open(struct inode *inode, struct file *filp) idx = shrm_get_cdev_index(m); if (idx < 0) { dev_err(shrm->dev, "failed to get index\n"); + mutex_unlock(&isa_lock); return idx; } if (!atomic_dec_and_test(&isa_context->is_open[idx])) { @@ -747,6 +759,9 @@ static int isa_open(struct inode *inode, struct file *filp) } dev_info(shrm->dev, "Open CIQ_MESSAGING Device\n"); break; + case RTC_CAL_MESSAGING: + dev_info(shrm->dev, "Open RTC_CAL_MESSAGING Device\n"); + break; }; mutex_unlock(&isa_lock); diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index 7f168ae278f..6cc6e347188 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -29,6 +29,7 @@ #define L2_HEADER_AUDIO_SIMPLE_LOOPBACK 0x80 #define L2_HEADER_AUDIO_ADVANCED_LOOPBACK 0x81 #define L2_HEADER_CIQ 0xC3 +#define L2_HEADER_RTC_CALIBRATION 0xC8 #define MAX_PAYLOAD 1024 #define PRCM_HOSTACCESS_REQ 0x334 @@ -1056,7 +1057,8 @@ int shm_write_msg(struct shrm_dev *shrm, u8 l2_header, (l2_header == L2_HEADER_SECURITY) || (l2_header == L2_HEADER_COMMON_SIMPLE_LOOPBACK) || (l2_header == L2_HEADER_COMMON_ADVANCED_LOOPBACK) || - (l2_header == L2_HEADER_CIQ)) { + (l2_header == L2_HEADER_CIQ) || + (l2_header == L2_HEADER_RTC_CALIBRATION)) { channel = 0; if (shrm_common_tx_state == SHRM_SLEEP_STATE) shrm_common_tx_state = SHRM_PTR_FREE; diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index 081dfd111e4..96b5c594d34 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -25,7 +25,7 @@ #include #include -#define ISA_DEVICES 7 +#define ISA_DEVICES 8 #define BOOT_INIT (0) #define BOOT_INFO_SYNC (1) diff --git a/include/linux/modem/shrm/shrm_private.h b/include/linux/modem/shrm/shrm_private.h index 888a7c200fd..23caabf5a06 100644 --- a/include/linux/modem/shrm/shrm_private.h +++ b/include/linux/modem/shrm/shrm_private.h @@ -47,6 +47,7 @@ #define COMMON_LOOPBACK_MESSAGING (0xC0) #define AUDIO_LOOPBACK_MESSAGING (0x80) #define CIQ_MESSAGING (0xC3) +#define RTC_CAL_MESSAGING (0xC8) #define COMMON_CHANNEL 0 #define AUDIO_CHANNEL 1 -- cgit v1.2.3 From 3cbfa821cdbf2c298fa4b76ea71211e8573b5cb8 Mon Sep 17 00:00:00 2001 From: Chris Blair Date: Fri, 4 Nov 2011 13:51:25 +0000 Subject: modem: Add M6718 IPC SPI driver net interface Adds the net device interface from the modem to userspace. ST-Ericsson ID: 369397 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12224 ST-Ericsson Linux next: NA Change-Id: Ib1cafdc1558305d808870b0fdafa8e7029ec5a6b Signed-off-by: Chris Blair Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/36494 Reviewed-by: QATOOLS Reviewed-by: QABUILD Reviewed-by: Jonas ABERG --- drivers/modem/m6718_spi/modem_driver.c | 55 ++++- drivers/net/Makefile | 1 + drivers/net/m6718_modem_net.c | 333 ++++++++++++++++++++++++++++++ include/linux/modem/m6718_spi/modem_net.h | 50 +++++ 4 files changed, 437 insertions(+), 2 deletions(-) create mode 100644 drivers/net/m6718_modem_net.c create mode 100644 include/linux/modem/m6718_spi/modem_net.h (limited to 'include') diff --git a/drivers/modem/m6718_spi/modem_driver.c b/drivers/modem/m6718_spi/modem_driver.c index d85e6943c23..623a9191d27 100644 --- a/drivers/modem/m6718_spi/modem_driver.c +++ b/drivers/modem/m6718_spi/modem_driver.c @@ -13,9 +13,15 @@ #include #include #include +#include #include #include "modem_protocol.h" +#ifdef CONFIG_PHONET +static void phonet_rcv_tasklet_func(unsigned long); +static struct tasklet_struct phonet_rcv_tasklet; +#endif + static struct modem_spi_dev modem_driver_data = { .dev = NULL, .ndev = NULL, @@ -37,6 +43,10 @@ static struct modem_spi_dev modem_driver_data = { * * Special handling is given to slave-loopback channels where the data is simply * sent back to the modem on the same channel. + * + * Special handling is given to the ISI channel when PHONET is enabled - the + * phonet tasklet is scheduled in order to pump the received data through the + * net device interface. */ int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, u32 len, void *data) @@ -95,10 +105,37 @@ int modem_m6718_spi_receive(struct spi_device *sdev, u8 channel, dev_err(&sdev->dev, "failed to queue frame!"); return ret; } + +#ifdef CONFIG_PHONET + if (channel == MODEM_M6718_SPI_CHN_ISI && + modem_driver_data.netdev_flag_up) + tasklet_schedule(&phonet_rcv_tasklet); +#endif return ret; } EXPORT_SYMBOL_GPL(modem_m6718_spi_receive); +static void phonet_rcv_tasklet_func(unsigned long unused) +{ + ssize_t result; + + dev_dbg(modem_driver_data.dev, "receiving frames for phonet\n"); + /* continue receiving while there are frames in the queue */ + for (;;) { + result = modem_net_receive(modem_driver_data.ndev); + if (result == 0) { + dev_dbg(modem_driver_data.dev, + "queue is empty, finished receiving\n"); + break; + } + if (result < 0) { + dev_err(modem_driver_data.dev, + "failed to receive frame from queue!\n"); + break; + } + } +} + static int spi_probe(struct spi_device *sdev) { int result = 0; @@ -133,9 +170,22 @@ static int spi_probe(struct spi_device *sdev) "failed to initialise char interface\n"); goto rollback_modem_get; } + + result = modem_net_init(&modem_driver_data); + if (result < 0) { + dev_err(&sdev->dev, + "failed to initialse net interface\n"); + goto rollback_isa_init; + } + +#ifdef CONFIG_PHONET + tasklet_init(&phonet_rcv_tasklet, phonet_rcv_tasklet_func, 0); +#endif } return result; +rollback_isa_init: + modem_isa_exit(&modem_driver_data); rollback_modem_get: modem_put(modem_driver_data.modem); rollback_protocol_init: @@ -147,6 +197,7 @@ rollback: static int __exit spi_remove(struct spi_device *sdev) { modem_protocol_exit(); + modem_net_exit(&modem_driver_data); modem_isa_exit(&modem_driver_data); return 0; } @@ -167,7 +218,7 @@ static int spi_suspend(struct spi_device *sdev, pm_message_t mesg) busy = modem_protocol_is_busy(sdev); dev_dbg(&sdev->dev, "suspend called, protocol busy:%d\n", busy); if (!busy) - return 0; + return modem_net_suspend(modem_driver_data.ndev); else return -EBUSY; } @@ -179,7 +230,7 @@ static int spi_suspend(struct spi_device *sdev, pm_message_t mesg) static int spi_resume(struct spi_device *sdev) { dev_dbg(&sdev->dev, "resume called\n"); - return 0; + return modem_net_resume(modem_driver_data.ndev); } #endif /* CONFIG_PM */ diff --git a/drivers/net/Makefile b/drivers/net/Makefile index c1d8099a34e..a0f2484368b 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -73,4 +73,5 @@ obj-$(CONFIG_HYPERV_NET) += hyperv/ ifdef CONFIG_PHONET obj-$(CONFIG_U8500_SHRM) += u8500_shrm.o +obj-$(CONFIG_MODEM_M6718_SPI) += m6718_modem_net.o endif diff --git a/drivers/net/m6718_modem_net.c b/drivers/net/m6718_modem_net.c new file mode 100644 index 00000000000..f64a775560b --- /dev/null +++ b/drivers/net/m6718_modem_net.c @@ -0,0 +1,333 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on u8500_shrm.c + * + * License terms: GNU General Public License (GPL) version 2 + * + * M6718 modem net device interface. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/** + * modem_net_receive() - receive data and copy to user space buffer + * @dev: pointer to the network device structure + * + * Copy data from ISI queue to the user space buffer. + */ +int modem_net_receive(struct net_device *dev) +{ + struct sk_buff *skb; + struct isa_device_context *isadev; + struct message_queue *q; + u32 msgsize; + u32 size = 0; + struct modem_spi_net_dev *net_iface_priv = + (struct modem_spi_net_dev *)netdev_priv(dev); + struct modem_spi_dev *modem_spi_dev = net_iface_priv->modem_spi_dev; + + isadev = &modem_spi_dev->isa_context->isadev[MODEM_M6718_SPI_CHN_ISI]; + q = &isadev->dl_queue; + + spin_lock_bh(&q->update_lock); + if (list_empty(&q->msg_list)) { + spin_unlock_bh(&q->update_lock); + dev_dbg(modem_spi_dev->dev, "empty queue!\n"); + return 0; + } + spin_unlock_bh(&q->update_lock); + + msgsize = modem_isa_msg_size(q); + if (msgsize <= 0) + return msgsize; + + /* + * The packet has been retrieved from the transmission + * medium. Build an skb around it, so upper layers can handle it + */ + skb = dev_alloc_skb(msgsize); + if (!skb) { + pr_notice_ratelimited("isa rx: low on mem - packet dropped\n"); + dev->stats.rx_dropped++; + return -ENOMEM; + } + + if ((q->readptr + msgsize) >= q->size) { + size = (q->size - q->readptr); + /* copy first part of msg */ + skb_copy_to_linear_data(skb, + (u8 *)(q->fifo_base + q->readptr), size); + skb_put(skb, size); + + /* copy second part of msg at the top of fifo */ + skb_copy_to_linear_data_offset(skb, size, + (u8 *)(q->fifo_base), (msgsize - size)); + skb_put(skb, msgsize - size); + + } else { + skb_copy_to_linear_data(skb, + (u8 *)(q->fifo_base + q->readptr), msgsize); + skb_put(skb, msgsize); + } + + spin_lock_bh(&q->update_lock); + modem_isa_unqueue_msg(q); + spin_unlock_bh(&q->update_lock); + + skb_reset_mac_header(skb); + __skb_pull(skb, dev->hard_header_len); + /* write metadata and then pass to the receive level */ + skb->dev = dev; + skb->protocol = htons(ETH_P_PHONET); + skb->priority = 0; + skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */ + if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) { + dev->stats.rx_packets++; + dev->stats.rx_bytes += msgsize; + } else { + dev->stats.rx_dropped++; + } + + return msgsize; +} +EXPORT_SYMBOL_GPL(modem_net_receive); + +static int netdev_isa_open(struct net_device *dev) +{ + struct modem_spi_net_dev *net_iface_priv = + (struct modem_spi_net_dev *)netdev_priv(dev); + struct modem_spi_dev *modem_spi_dev = net_iface_priv->modem_spi_dev; + + modem_spi_dev->netdev_flag_up = 1; + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + netif_wake_queue(dev); + return 0; +} + +static int netdev_isa_close(struct net_device *dev) +{ + struct modem_spi_net_dev *net_iface_priv = + (struct modem_spi_net_dev *)netdev_priv(dev); + struct modem_spi_dev *modem_spi_dev = net_iface_priv->modem_spi_dev; + + modem_spi_dev->netdev_flag_up = 0; + netif_stop_queue(dev); + netif_carrier_off(dev); + return 0; +} + +static int netdev_isa_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + struct if_phonet_req *req = (struct if_phonet_req *)ifr; + + switch (cmd) { + case SIOCPNGAUTOCONF: + req->ifr_phonet_autoconf.device = PN_DEV_HOST; + return 0; + } + return -ENOIOCTLCMD; +} + +static struct net_device_stats *netdev_isa_stats(struct net_device *dev) +{ + return &dev->stats; +} + +/** + * netdev_isa_write() - write through the net interface + * @skb: pointer to the socket buffer + * @dev: pointer to the network device structure + * + * Copies data(ISI message) from the user buffer to the kernel buffer and + * schedule transfer thread to transmit the message to the modem via FIFO. + */ +static netdev_tx_t netdev_isa_write(struct sk_buff *skb, struct net_device *dev) +{ + int err; + int retval = 0; + struct modem_spi_net_dev *net_iface_priv = + (struct modem_spi_net_dev *)netdev_priv(dev); + struct modem_spi_dev *modem_spi_dev = net_iface_priv->modem_spi_dev; + + /* + * FIXME: + * U8500 modem requires that Pipe created/enabled Indication should + * be sent from the port corresponding to GPRS socket. + * Also, the U8500 modem does not implement Pipe controller + * which takes care of port manipulations for GPRS traffic. + * + * Now, APE has GPRS socket and the socket for sending + * Indication msgs bound to different ports. + * Phonet stack does not allow an indication msg to be sent + * from GPRS socket, since Phonet stack assumes the presence + * of Pipe controller in modem. + * + * So, due to lack of Pipe controller implementation in the + * U8500 modem, carry out the port manipulation related to + * GPRS traffic here. + * Ideally, it should be done either by Pipe controller in + * modem OR some implementation of Pipe controller on APE side + */ + if (skb->data[RESOURCE_ID_INDEX] == PN_PIPE) { + if ((skb->data[MSG_ID_INDEX] == PNS_PIPE_CREATED_IND) || + (skb->data[MSG_ID_INDEX] == PNS_PIPE_ENABLED_IND) || + (skb->data[MSG_ID_INDEX] == PNS_PIPE_DISABLED_IND)) + skb->data[SRC_OBJ_INDEX] = skb->data[PIPE_HDL_INDEX]; + } + + spin_lock_bh(&modem_spi_dev->isa_context->common_tx_lock); + err = modem_m6718_spi_send(modem_spi_dev, MODEM_M6718_SPI_CHN_ISI, + skb->len, skb->data); + if (!err) { + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; + retval = NETDEV_TX_OK; + dev_kfree_skb(skb); + } else { + dev->stats.tx_dropped++; + retval = NETDEV_TX_BUSY; + } + spin_unlock_bh(&modem_spi_dev->isa_context->common_tx_lock); + + return retval; +} + +static const struct net_device_ops modem_netdev_ops = { + .ndo_open = netdev_isa_open, + .ndo_stop = netdev_isa_close, + .ndo_do_ioctl = netdev_isa_ioctl, + .ndo_start_xmit = netdev_isa_write, + .ndo_get_stats = netdev_isa_stats, +}; + +static void net_device_init(struct net_device *dev) +{ + struct modem_spi_net_dev *net_iface_priv; + + dev->netdev_ops = &modem_netdev_ops; + dev->header_ops = &phonet_header_ops; + dev->type = ARPHRD_PHONET; + dev->flags = IFF_POINTOPOINT | IFF_NOARP; + dev->mtu = PHONET_MAX_MTU; + dev->hard_header_len = MODEM_HLEN; + dev->addr_len = PHONET_ALEN; + dev->tx_queue_len = PN_TX_QUEUE_LEN; + dev->destructor = free_netdev; + dev->dev_addr[0] = PN_LINK_ADDR; + net_iface_priv = netdev_priv(dev); + memset(net_iface_priv, 0 , sizeof(struct modem_spi_net_dev)); +} + +int modem_net_init(struct modem_spi_dev *modem_spi_dev) +{ + struct net_device *nw_device; + struct modem_spi_net_dev *net_iface_priv; + int err; + /* + * keep the same net device name as U8500 to allow userspace clients + * to remain unchanged and use the same interfaces + */ + char *devname = "shrm%d"; + + /* allocate the net device */ + nw_device = modem_spi_dev->ndev = + alloc_netdev(sizeof(struct modem_spi_net_dev), + devname, net_device_init); + if (nw_device == NULL) { + dev_err(modem_spi_dev->dev, + "failed to allocate modem net device\n"); + return -ENOMEM; + } + err = register_netdev(modem_spi_dev->ndev); + if (err) { + dev_err(modem_spi_dev->dev, + "failed to register modem net device: error %d\n", err); + free_netdev(modem_spi_dev->ndev); + return -ENODEV; + } + dev_dbg(modem_spi_dev->dev, "registered modem net device\n"); + + net_iface_priv = (struct modem_spi_net_dev *)netdev_priv(nw_device); + net_iface_priv->modem_spi_dev = modem_spi_dev; + net_iface_priv->iface_num = 0; + return err; +} +EXPORT_SYMBOL_GPL(modem_net_init); + +int modem_net_stop(struct net_device *dev) +{ + netif_stop_queue(dev); + return 0; +} + +int modem_net_restart(struct net_device *dev) +{ + if (netif_queue_stopped(dev)) + netif_wake_queue(dev); + return 0; +} +EXPORT_SYMBOL_GPL(modem_net_restart); + +int modem_net_start(struct net_device *dev) +{ + struct modem_spi_net_dev *net_iface_priv = + (struct modem_spi_net_dev *)netdev_priv(dev); + struct modem_spi_dev *modem_spi_dev = net_iface_priv->modem_spi_dev; + + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + netif_start_queue(dev); + modem_spi_dev->netdev_flag_up = 1; + return 0; +} +EXPORT_SYMBOL_GPL(modem_net_start); + +int modem_net_suspend(struct net_device *dev) +{ + if (netif_running(dev)) { + netif_stop_queue(dev); + netif_carrier_off(dev); + } + netif_device_detach(dev); + return 0; +} +EXPORT_SYMBOL_GPL(modem_net_suspend); + +int modem_net_resume(struct net_device *dev) +{ + netif_device_attach(dev); + if (netif_running(dev)) { + netif_carrier_on(dev); + netif_wake_queue(dev); + } + return 0; +} +EXPORT_SYMBOL_GPL(modem_net_resume); + +void modem_net_exit(struct modem_spi_dev *modem_spi_dev) +{ + if (modem_spi_dev && modem_spi_dev->ndev) { + unregister_netdev(modem_spi_dev->ndev); + modem_spi_dev->ndev = NULL; + dev_dbg(modem_spi_dev->dev, "removed modem net device\n"); + } +} +EXPORT_SYMBOL_GPL(modem_net_exit); + +MODULE_AUTHOR("Chris Blair "); +MODULE_DESCRIPTION("M6718 modem IPC net device interface"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/modem/m6718_spi/modem_net.h b/include/linux/modem/m6718_spi/modem_net.h new file mode 100644 index 00000000000..521103bf006 --- /dev/null +++ b/include/linux/modem/m6718_spi/modem_net.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) ST-Ericsson SA 2011 + * + * Author: Chris Blair for ST-Ericsson + * based on shrm_net.h + * + * License terms: GNU General Public License (GPL) version 2 + * + * Modem IPC net device interface header. + */ +#ifndef _MODEM_NET_H_ +#define _MODEM_NET_H_ + +#include + +#define MODEM_HLEN (1) +#define PHONET_ALEN (1) + +#define PN_PIPE (0xD9) +#define PN_DEV_HOST (0x00) +#define PN_LINK_ADDR (0x26) +#define PN_TX_QUEUE_LEN (3) + +#define RESOURCE_ID_INDEX (3) +#define SRC_OBJ_INDEX (7) +#define MSG_ID_INDEX (9) +#define PIPE_HDL_INDEX (10) +#define NETLINK_MODEM (20) + +/** + * struct modem_spi_net_dev - modem net interface device information + * @modem_spi_dev: pointer to the modem spi device information structure + * @iface_num: flag used to indicate the up/down of netdev + */ +struct modem_spi_net_dev { + struct modem_spi_dev *modem_spi_dev; + unsigned int iface_num; +}; + +int modem_net_init(struct modem_spi_dev *modem_spi_dev); +void modem_net_exit(struct modem_spi_dev *modem_spi_dev); + +int modem_net_receive(struct net_device *dev); +int modem_net_suspend(struct net_device *dev); +int modem_net_resume(struct net_device *dev); +int modem_net_start(struct net_device *dev); +int modem_net_restart(struct net_device *dev); +int modem_net_stop(struct net_device *dev); + +#endif /* _MODEM_NET_H_ */ -- cgit v1.2.3 From aedb9867d5f6f65d908c3e5e130b37ceddcbeb03 Mon Sep 17 00:00:00 2001 From: Rikard Olsson Date: Wed, 11 Jan 2012 15:55:40 +0100 Subject: ARM: ux500: adds additional dump areas Adds additional dump area information which contains information of fuses in db8500. ST-Ericsson Linux next: - ST-Ericsson ID: 404278 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: If2aea9493c0942700acc676c40dc9b6e344ef891 Signed-off-by: Rikard Olsson Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/45155 Reviewed-by: Srinidhi KASAGAR --- arch/arm/mach-ux500/mloader-db8500.c | 12 +++++++++++- drivers/misc/dbx500-mloader.c | 19 +++++++++++++++++++ include/linux/mloader.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/arch/arm/mach-ux500/mloader-db8500.c b/arch/arm/mach-ux500/mloader-db8500.c index b13652f55cb..8f08e6af969 100644 --- a/arch/arm/mach-ux500/mloader-db8500.c +++ b/arch/arm/mach-ux500/mloader-db8500.c @@ -12,6 +12,7 @@ #include #include +#include static struct dbx500_ml_area modem_areas[] = { { .name = "modem_trace", .start = 0x6000000, .size = 0xf00000 }, @@ -31,13 +32,22 @@ static struct dbx500_mloader_pdata mloader_fw_data = { .nr_areas = ARRAY_SIZE(modem_areas), }; +static struct resource mloader_fw_rsrc[] = { + { + .start = (U8500_BACKUPRAM1_BASE + 0xF70), + .end = (U8500_BACKUPRAM1_BASE + 0xF7C), + .flags = IORESOURCE_MEM + } +}; + struct platform_device mloader_fw_device = { .name = "dbx500_mloader_fw", .id = -1, .dev = { .platform_data = &mloader_fw_data, }, - .num_resources = 0, + .resource = mloader_fw_rsrc, + .num_resources = ARRAY_SIZE(mloader_fw_rsrc) }; /* Default areas can be overloaded in cmdline */ diff --git a/drivers/misc/dbx500-mloader.c b/drivers/misc/dbx500-mloader.c index c3ec8b67983..408d1a1a29e 100644 --- a/drivers/misc/dbx500-mloader.c +++ b/drivers/misc/dbx500-mloader.c @@ -22,6 +22,7 @@ #include #include +#include #define DEVICE_NAME "dbx500_mloader_fw" @@ -30,6 +31,8 @@ struct mloader_priv { struct dbx500_mloader_pdata *pdata; struct miscdevice misc_dev; u32 aeras_size; + void __iomem *uid_base; + u8 size; }; static struct mloader_priv *mloader_priv; @@ -165,6 +168,11 @@ static long mloader_fw_ioctl(struct file *filp, unsigned int cmd, kfree(dump_images); break; } + case ML_GET_FUSEINFO: { + ret = copy_to_user(argp, (void *) mloader_priv->uid_base, + mloader_priv->size) ? -EFAULT : 0; + break; + } default: ret = -EPERM; break; @@ -183,6 +191,7 @@ static int __devinit mloader_fw_probe(struct platform_device *pdev) { int ret = 0; int i; + struct resource *res = NULL; mloader_priv = kzalloc(sizeof(*mloader_priv), GFP_ATOMIC); if (!mloader_priv) { @@ -196,6 +205,16 @@ static int __devinit mloader_fw_probe(struct platform_device *pdev) mloader_priv->misc_dev.minor = MISC_DYNAMIC_MINOR; mloader_priv->misc_dev.name = DEVICE_NAME; mloader_priv->misc_dev.fops = &modem_fw_fops; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mloader_priv->size = resource_size(res); + mloader_priv->uid_base = ioremap(res->start, mloader_priv->size); + + if (!mloader_priv->uid_base) { + ret = -ENOMEM; + goto err_free_priv; + } + ret = misc_register(&mloader_priv->misc_dev); if (ret < 0) { dev_err(&pdev->dev, "can't misc_register\n"); diff --git a/include/linux/mloader.h b/include/linux/mloader.h index ceca3245856..c339a7f7a36 100644 --- a/include/linux/mloader.h +++ b/include/linux/mloader.h @@ -13,6 +13,7 @@ #define ML_UPLOAD _IO(ML_IO_NUMBER, 1) #define ML_GET_NBIMAGES _IOR(ML_IO_NUMBER, 2, int) #define ML_GET_DUMPINFO _IOR(ML_IO_NUMBER, 3, struct dump_image*) +#define ML_GET_FUSEINFO _IOR(ML_IO_NUMBER, 4, char*) #define MAX_NAME 16 -- cgit v1.2.3 From 90f2a2c4152a251b0bfad40d7fdc512f543cd5ce Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Tue, 24 Jan 2012 15:57:26 +0530 Subject: u8500-shrm: add timer to check if modem has stuck or hang On APE sending msg_pend notification, the only way when APE gets to know that modem is not responsive, is when it ends up with a FIFO full. In order to get this FIFO full on common channel it might take 30min. Hence add a timer and start the timer on msg_pend_notification and cancel the timer at read_noti. If timer expires within this time then its for sure that modem is not responsive. Initiate MSR in that case. The current timer value is 6sec. Since there are two timers and on expiry of either of the timer, modem_reset is called, have added flag so as to ensure that modem_rest is not called simultaneously on exit of both the timer in short span of time. ST-Ericsson Linux next: NA ST-Ericsson ID: 407459 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: If3e7b61ee57ea4b1d386a50c8c4b99c2cd701e13 Signed-off-by: Arun Murthy Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/46337 Reviewed-by: Ashok G X Tested-by: Ashok G X Reviewed-by: Srinidhi KASAGAR --- drivers/modem/shrm/shrm_protocol.c | 68 +++++++++++++++++++++++++++++++++- include/linux/modem/shrm/shrm_driver.h | 4 ++ 2 files changed, 70 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index dfb8f14f0e2..5997c35297b 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -31,6 +31,7 @@ #define L2_HEADER_CIQ 0xC3 #define L2_HEADER_RTC_CALIBRATION 0xC8 #define MAX_PAYLOAD 1024 +#define MOD_STUCK_TIMEOUT 6 #define PRCM_HOSTACCESS_REQ 0x334 @@ -40,6 +41,8 @@ static u8 recieve_audio_msg[8*1024]; static received_msg_handler rx_common_handler; static received_msg_handler rx_audio_handler; static struct hrtimer timer; +static struct hrtimer mod_stuck_timer_0; +static struct hrtimer mod_stuck_timer_1; struct sock *shrm_nl_sk; static char shrm_common_tx_state = SHRM_SLEEP_STATE; @@ -49,6 +52,7 @@ static char shrm_audio_rx_state = SHRM_SLEEP_STATE; static atomic_t ac_sleep_disable_count = ATOMIC_INIT(0); static atomic_t ac_msg_pend_1 = ATOMIC_INIT(0); +static atomic_t mod_stuck = ATOMIC_INIT(0); static struct shrm_dev *shm_dev; /* Spin lock and tasklet declaration */ @@ -63,6 +67,7 @@ static DEFINE_SPINLOCK(ca_common_lock); static DEFINE_SPINLOCK(ca_audio_lock); static DEFINE_SPINLOCK(ca_wake_req_lock); static DEFINE_SPINLOCK(boot_lock); +static DEFINE_SPINLOCK(mod_stuck_lock); enum shrm_nl { SHRM_NL_MOD_RESET = 1, @@ -102,6 +107,28 @@ static u32 get_host_accessport_val(void) return prcm_hostaccess; } + +static enum hrtimer_restart shm_mod_stuck_timeout(struct hrtimer *timer) +{ + unsigned long flags; + + spin_lock_irqsave(&mod_stuck_lock, flags); + /* Check MSR is already in progress */ + if (shm_dev->msr_flag || boot_state == BOOT_UNKNOWN || + atomic_read(&mod_stuck)) { + spin_unlock_irqrestore(&mod_stuck_lock, flags); + return HRTIMER_NORESTART; + } + atomic_set(&mod_stuck, 1); + spin_unlock_irqrestore(&mod_stuck_lock, flags); + dev_err(shm_dev->dev, "No response from modem, timeout %dsec\n", + MOD_STUCK_TIMEOUT); + dev_err(shm_dev->dev, "APE initiating MSR\n"); + queue_kthread_work(&shm_dev->shm_mod_stuck_kw, + &shm_dev->shm_mod_reset_req); + return HRTIMER_NORESTART; +} + static enum hrtimer_restart callback(struct hrtimer *timer) { unsigned long flags; @@ -510,6 +537,9 @@ static int shrm_modem_reset_sequence(void) unsigned long flags; hrtimer_cancel(&timer); + hrtimer_cancel(&mod_stuck_timer_0); + hrtimer_cancel(&mod_stuck_timer_1); + atomic_set(&mod_stuck, 0); tasklet_disable_nosync(&shm_ac_read_0_tasklet); tasklet_disable_nosync(&shm_ac_read_1_tasklet); tasklet_disable_nosync(&shm_ca_0_tasklet); @@ -666,6 +696,9 @@ static void send_ac_msg_pend_notify_0_work(struct kthread_work *work) writel((1<intr_base + GOP_SET_REGISTER_BASE); + /* timer to detect modem stuck or hang */ + hrtimer_start(&mod_stuck_timer_0, ktime_set(MOD_STUCK_TIMEOUT, 0), + HRTIMER_MODE_REL); if (shrm_common_tx_state == SHRM_PTR_FREE) shrm_common_tx_state = SHRM_PTR_BUSY; @@ -705,6 +738,9 @@ static void send_ac_msg_pend_notify_1_work(struct kthread_work *work) writel((1<intr_base + GOP_SET_REGISTER_BASE); + /* timer to detect modem stuck or hang */ + hrtimer_start(&mod_stuck_timer_1, ktime_set(MOD_STUCK_TIMEOUT, 0), + HRTIMER_MODE_REL); if (shrm_audio_tx_state == SHRM_PTR_FREE) shrm_audio_tx_state = SHRM_PTR_BUSY; @@ -729,7 +765,14 @@ void shm_nl_receive(struct sk_buff *skb) case SHRM_NL_USER_MOD_RESET: dev_info(shm_dev->dev, "user-space inited mod-reset-req\n"); dev_info(shm_dev->dev, "PCRMU resets modem\n"); - prcmu_modem_reset(); + if (atomic_read(&mod_stuck)) { + dev_info(shm_dev->dev, + "Modem reset already in progress\n"); + break; + } + atomic_set(&mod_stuck, 1); + queue_kthread_work(&shm_dev->shm_mod_stuck_kw, + &shm_dev->shm_mod_reset_req); break; default: @@ -754,6 +797,10 @@ int shrm_protocol_init(struct shrm_dev *shrm, hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); timer.function = callback; + hrtimer_init(&mod_stuck_timer_0, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + mod_stuck_timer_0.function = shm_mod_stuck_timeout; + hrtimer_init(&mod_stuck_timer_1, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + mod_stuck_timer_1.function = shm_mod_stuck_timeout; init_kthread_worker(&shrm->shm_common_ch_wr_kw); shrm->shm_common_ch_wr_kw_task = kthread_run(kthread_worker_fn, @@ -809,6 +856,15 @@ int shrm_protocol_init(struct shrm_dev *shrm, err = -ENOMEM; goto free_kw4; } + init_kthread_worker(&shrm->shm_mod_stuck_kw); + shrm->shm_mod_stuck_kw_task = kthread_run(kthread_worker_fn, + &shrm->shm_mod_stuck_kw, + "shm_mod_reset_req"); + if (IS_ERR(shrm->shm_mod_stuck_kw_task)) { + dev_err(shrm->dev, "failed to create work task\n"); + return -ENOMEM; + goto free_kw5; + } init_kthread_work(&shrm->send_ac_msg_pend_notify_0, send_ac_msg_pend_notify_0_work); @@ -828,7 +884,7 @@ int shrm_protocol_init(struct shrm_dev *shrm, IRQF_NO_SUSPEND, "ca-sleep", shrm); if (err < 0) { dev_err(shm_dev->dev, "Failed alloc IRQ_PRCMU_CA_SLEEP.\n"); - goto free_kw5; + goto free_kw6; } err = request_irq(IRQ_PRCMU_CA_WAKE, shrm_prcmu_irq_handler, @@ -866,6 +922,8 @@ drop1: free_irq(IRQ_PRCMU_CA_WAKE, NULL); drop2: free_irq(IRQ_PRCMU_CA_SLEEP, NULL); +free_kw6: + kthread_stop(shrm->shm_mod_stuck_kw_task); free_kw5: kthread_stop(shrm->shm_ac_sleep_kw_task); free_kw4: @@ -889,11 +947,13 @@ void shrm_protocol_deinit(struct shrm_dev *shrm) flush_kthread_worker(&shrm->shm_ac_wake_kw); flush_kthread_worker(&shrm->shm_ca_wake_kw); flush_kthread_worker(&shrm->shm_ac_sleep_kw); + flush_kthread_worker(&shrm->shm_mod_stuck_kw); kthread_stop(shrm->shm_common_ch_wr_kw_task); kthread_stop(shrm->shm_audio_ch_wr_kw_task); kthread_stop(shrm->shm_ac_wake_kw_task); kthread_stop(shrm->shm_ca_wake_kw_task); kthread_stop(shrm->shm_ac_sleep_kw_task); + kthread_stop(shrm->shm_mod_stuck_kw_task); modem_put(shrm->modem); } @@ -933,6 +993,8 @@ irqreturn_t ac_read_notif_0_irq_handler(int irq, void *ctrlr) struct shrm_dev *shrm = ctrlr; dev_dbg(shrm->dev, "%s IN\n", __func__); + /* Cancel the modem stuck timer */ + hrtimer_cancel(&mod_stuck_timer_0); if (check_modem_in_reset()) { dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", @@ -962,6 +1024,8 @@ irqreturn_t ac_read_notif_1_irq_handler(int irq, void *ctrlr) struct shrm_dev *shrm = ctrlr; dev_dbg(shrm->dev, "%s IN+\n", __func__); + /* Cancel the modem stuck timer */ + hrtimer_cancel(&mod_stuck_timer_1); if (check_modem_in_reset()) { dev_err(shrm->dev, "%s:Modem state reset or unknown.\n", diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index 96b5c594d34..072a232d53d 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -76,6 +76,8 @@ * @shm_ca_wake_kw_task: task for receiving cmt-ape wake requests * @shm_ac_sleep_kw: kthread worker for recieving ape-cmt sleep requests * @shm_ac_sleep_kw_task: task for recieving ape-cmt sleep requests + * @shm_mod_stuck_kw: kthread worker to reset the modem + * &shm_mod_stuck_kw_task: task for sending modem reset request * @send_ac_msg_pend_notify_0: work for handling pending message on common * channel * @send_ac_msg_pend_notify_1: work for handling pending message on audio @@ -134,6 +136,8 @@ struct shrm_dev { struct task_struct *shm_ca_wake_kw_task; struct kthread_worker shm_ac_sleep_kw; struct task_struct *shm_ac_sleep_kw_task; + struct kthread_worker shm_mod_stuck_kw; + struct task_struct *shm_mod_stuck_kw_task; struct kthread_work send_ac_msg_pend_notify_0; struct kthread_work send_ac_msg_pend_notify_1; struct kthread_work shm_ac_wake_req; -- cgit v1.2.3 From 2cb12e7c40790435d1ced4f711c164e7fb30f85a Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Wed, 25 Jan 2012 19:14:52 +0530 Subject: u8500-shrm: fix html docs build error /local/scratch/hudson_prod/sandbox/build-roots/u8500-lbp-dev/kernel/ Documentation/DocBook/shrm.xml:2153: parser error : EntityRef: expecting ';' &shm_mod_stuck_kw_task ^ unable to parse /local/scratch/hudson_prod/sandbox/build-roots/u8500-lbp-dev/ kernel/Documentation/DocBook/shrm.xml /bin/cp: cannot stat `*.*htm*': No such file or directory make[4]: *** [Documentation/DocBook/shrm.html] Error 1 make[4]: *** Waiting for unfinished jobs.... ST-Ericsson Linux next: NA ST-Ericsson ID: 407459 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I916a0aace48eb04b9707c3d2f3f6b4c47ce08b30 Signed-off-by: Arun Murthy Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/46539 Reviewed-by: Maria STURESSON Reviewed-by: QATEST Reviewed-by: Henrik CARLING --- include/linux/modem/shrm/shrm_driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index 072a232d53d..e8905e68778 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -77,7 +77,7 @@ * @shm_ac_sleep_kw: kthread worker for recieving ape-cmt sleep requests * @shm_ac_sleep_kw_task: task for recieving ape-cmt sleep requests * @shm_mod_stuck_kw: kthread worker to reset the modem - * &shm_mod_stuck_kw_task: task for sending modem reset request + * @shm_mod_stuck_kw_task: task for sending modem reset request * @send_ac_msg_pend_notify_0: work for handling pending message on common * channel * @send_ac_msg_pend_notify_1: work for handling pending message on audio -- cgit v1.2.3 From 83765c8325ac699f3236e8f428f6df0a7efff4b2 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Fri, 27 Jan 2012 20:38:10 +0530 Subject: modem: u8500-shrm: print prcmu and abb regs on stuck timeout ST-Ericsson Linux next: - ST-Ericsson ID: 402239 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: Ia08165f58c0d55db7ed97a0c74cd4b493cf14495 Signed-off-by: Arun Murthy Signed-off-by: Mian Yousaf Kaukab Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/47128 Reviewed-by: QABUILD Reviewed-by: QATEST Reviewed-by: Jonas ABERG --- drivers/modem/shrm/shrm_protocol.c | 14 ++++++++++++++ include/linux/modem/shrm/shrm_driver.h | 2 ++ 2 files changed, 16 insertions(+) (limited to 'include') diff --git a/drivers/modem/shrm/shrm_protocol.c b/drivers/modem/shrm/shrm_protocol.c index b9613f544e5..40e77993613 100644 --- a/drivers/modem/shrm/shrm_protocol.c +++ b/drivers/modem/shrm/shrm_protocol.c @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #define L2_HEADER_ISI 0x0 #define L2_HEADER_RPC 0x1 @@ -80,6 +82,13 @@ enum shrm_nl { SHRM_NL_STATUS_MOD_OFFLINE, }; +void shm_print_dbg_info_work(struct kthread_work *work) +{ + abx500_dump_all_banks(); + prcmu_debug_dump_regs(); + prcmu_debug_dump_data_mem(); +} + void shm_mod_reset_req_work(struct kthread_work *work) { prcmu_modem_reset(); @@ -115,6 +124,8 @@ static enum hrtimer_restart shm_fifo_full_timeout(struct hrtimer *timer) { queue_kthread_work(&shm_dev->shm_mod_stuck_kw, &shm_dev->shm_mod_reset_req); + queue_kthread_work(&shm_dev->shm_mod_stuck_kw, + &shm_dev->shm_print_dbg_info); return HRTIMER_NORESTART; } @@ -136,6 +147,8 @@ static enum hrtimer_restart shm_mod_stuck_timeout(struct hrtimer *timer) dev_err(shm_dev->dev, "APE initiating MSR\n"); queue_kthread_work(&shm_dev->shm_mod_stuck_kw, &shm_dev->shm_mod_reset_req); + queue_kthread_work(&shm_dev->shm_mod_stuck_kw, + &shm_dev->shm_print_dbg_info); return HRTIMER_NORESTART; } @@ -889,6 +902,7 @@ int shrm_protocol_init(struct shrm_dev *shrm, init_kthread_work(&shrm->shm_ac_sleep_req, shm_ac_sleep_req_work); init_kthread_work(&shrm->shm_ac_wake_req, shm_ac_wake_req_work); init_kthread_work(&shrm->shm_mod_reset_req, shm_mod_reset_req_work); + init_kthread_work(&shrm->shm_print_dbg_info, shm_print_dbg_info_work); /* set tasklet data */ shm_ca_0_tasklet.data = (unsigned long)shrm; diff --git a/include/linux/modem/shrm/shrm_driver.h b/include/linux/modem/shrm/shrm_driver.h index e8905e68778..b6e5c354db5 100644 --- a/include/linux/modem/shrm/shrm_driver.h +++ b/include/linux/modem/shrm/shrm_driver.h @@ -87,6 +87,7 @@ * @shm_ca_sleep_req: work to send cmt-ape sleep request * @shm_ac_sleep_req: work to send ape-cmt sleep request * @shm_mod_reset_req: work to send a reset request to modem + * @shm_print_dbg_info: work function to print all prcmu/abb registers */ struct shrm_dev { u8 ca_wake_irq; @@ -145,6 +146,7 @@ struct shrm_dev { struct kthread_work shm_ca_sleep_req; struct kthread_work shm_ac_sleep_req; struct kthread_work shm_mod_reset_req; + struct kthread_work shm_print_dbg_info; }; /** -- cgit v1.2.3