wcnss: new SMD control channel with WCNSS

A new SMD control channel is opened with WCNSS, currently only the
version information is exchanged thru this channel. WCNSS version is
exposed thru /sys interface.

Conflicts:

	drivers/net/wireless/wcnss/wcnss_wlan.c

Change-Id: I45638bdd992846fa6087b6131180684d30805002
Signed-off-by: Sameer Thalappil <sameert@codeaurora.org>
This commit is contained in:
Sameer Thalappil 2012-08-10 17:17:09 -07:00 committed by Iliyan Malchev
parent 99461008bf
commit a892c2da60

View file

@ -23,7 +23,9 @@
#include <linux/jiffies.h>
#include <linux/gpio.h>
#include <linux/wakelock.h>
#include <linux/delay.h>
#include <mach/peripheral-loader.h>
#include <mach/msm_smd.h>
#define DEVICE "wcnss_wlan"
#define VERSION "1.01"
@ -43,6 +45,31 @@ static DEFINE_SPINLOCK(reg_spinlock);
#define RIVA_SSR_BIT BIT(23)
#define RIVA_SUSPEND_BIT BIT(24)
#define WCNSS_CTRL_CHANNEL "WCNSS_CTRL"
#define WCNSS_MAX_FRAME_SIZE 500
#define WCNSS_VERSION_LEN 30
/* message types */
#define WCNSS_CTRL_MSG_START 0x01000000
#define WCNSS_VERSION_REQ (WCNSS_CTRL_MSG_START + 0)
#define WCNSS_VERSION_RSP (WCNSS_CTRL_MSG_START + 1)
#define VALID_VERSION(version) \
((strncmp(version, "INVALID", WCNSS_VERSION_LEN)) ? 1 : 0)
struct smd_msg_hdr {
unsigned int type;
unsigned int len;
};
struct wcnss_version {
struct smd_msg_hdr hdr;
unsigned char major;
unsigned char minor;
unsigned char version;
unsigned char revision;
};
static struct {
struct platform_device *pdev;
void *pil;
@ -53,11 +80,15 @@ static struct {
const struct dev_pm_ops *pm_ops;
int triggered;
int smd_channel_ready;
smd_channel_t *smd_ch;
unsigned char wcnss_version[WCNSS_VERSION_LEN];
unsigned int serial_number;
int thermal_mitigation;
void (*tm_notify)(struct device *, int);
struct wcnss_wlan_config wlan_config;
struct delayed_work wcnss_work;
struct work_struct wcnssctrl_version_work;
struct work_struct wcnssctrl_rx_work;
struct wake_lock wcnss_wake_lock;
void __iomem *msm_wcnss_base;
} *penv = NULL;
@ -118,6 +149,19 @@ static ssize_t wcnss_thermal_mitigation_store(struct device *dev,
static DEVICE_ATTR(thermal_mitigation, S_IRUSR | S_IWUSR,
wcnss_thermal_mitigation_show, wcnss_thermal_mitigation_store);
static ssize_t wcnss_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
if (!penv)
return -ENODEV;
return scnprintf(buf, PAGE_SIZE, "%s", penv->wcnss_version);
}
static DEVICE_ATTR(wcnss_version, S_IRUSR,
wcnss_version_show, NULL);
static int wcnss_create_sysfs(struct device *dev)
{
int ret;
@ -130,11 +174,21 @@ static int wcnss_create_sysfs(struct device *dev)
return ret;
ret = device_create_file(dev, &dev_attr_thermal_mitigation);
if (ret) {
device_remove_file(dev, &dev_attr_serial_number);
return ret;
}
if (ret)
goto remove_serial;
ret = device_create_file(dev, &dev_attr_wcnss_version);
if (ret)
goto remove_thermal;
return 0;
remove_thermal:
device_remove_file(dev, &dev_attr_thermal_mitigation);
remove_serial:
device_remove_file(dev, &dev_attr_serial_number);
return ret;
}
static void wcnss_remove_sysfs(struct device *dev)
@ -142,6 +196,39 @@ static void wcnss_remove_sysfs(struct device *dev)
if (dev) {
device_remove_file(dev, &dev_attr_serial_number);
device_remove_file(dev, &dev_attr_thermal_mitigation);
device_remove_file(dev, &dev_attr_wcnss_version);
}
}
static void wcnss_smd_notify_event(void *data, unsigned int event)
{
int len = 0;
if (penv != data) {
pr_err("wcnss: invalid env pointer in smd callback\n");
return;
}
switch (event) {
case SMD_EVENT_DATA:
len = smd_read_avail(penv->smd_ch);
if (len < 0)
pr_err("wcnss: failed to read from smd %d\n", len);
schedule_work(&penv->wcnssctrl_rx_work);
break;
case SMD_EVENT_OPEN:
pr_debug("wcnss: opening WCNSS SMD channel :%s",
WCNSS_CTRL_CHANNEL);
if (!VALID_VERSION(penv->wcnss_version))
schedule_work(&penv->wcnssctrl_version_work);
break;
case SMD_EVENT_CLOSE:
pr_debug("wcnss: closing WCNSS SMD channel :%s",
WCNSS_CTRL_CHANNEL);
break;
default:
break;
}
}
@ -223,6 +310,45 @@ static struct platform_driver wcnss_wlan_ctrl_driver = {
.remove = __devexit_p(wcnss_wlan_ctrl_remove),
};
static int __devexit
wcnss_ctrl_remove(struct platform_device *pdev)
{
if (penv && penv->smd_ch)
smd_close(penv->smd_ch);
return 0;
}
static int __devinit
wcnss_ctrl_probe(struct platform_device *pdev)
{
int ret = 0;
if (!penv)
return -ENODEV;
ret = smd_named_open_on_edge(WCNSS_CTRL_CHANNEL, SMD_APPS_WCNSS,
&penv->smd_ch, penv, wcnss_smd_notify_event);
if (ret < 0) {
pr_err("wcnss: cannot open the smd command channel %s: %d\n",
WCNSS_CTRL_CHANNEL, ret);
return -ENODEV;
}
smd_disable_read_intr(penv->smd_ch);
return 0;
}
/* platform device for WCNSS_CTRL SMD channel */
static struct platform_driver wcnss_ctrl_driver = {
.driver = {
.name = "WCNSS_CTRL",
.owner = THIS_MODULE,
},
.probe = wcnss_ctrl_probe,
.remove = __devexit_p(wcnss_ctrl_remove),
};
struct device *wcnss_wlan_get_device(void)
{
if (penv && penv->pdev && penv->smd_channel_ready)
@ -430,6 +556,83 @@ void wcnss_allow_suspend()
}
EXPORT_SYMBOL(wcnss_allow_suspend);
static int wcnss_smd_tx(void *data, int len)
{
int ret = 0;
ret = smd_write_avail(penv->smd_ch);
if (ret < len) {
pr_err("wcnss: no space available for smd frame\n");
ret = -ENOSPC;
}
ret = smd_write(penv->smd_ch, data, len);
if (ret < len) {
pr_err("wcnss: failed to write Command %d", len);
ret = -ENODEV;
}
return ret;
}
static void wcnssctrl_rx_handler(struct work_struct *worker)
{
int len = 0;
int rc = 0;
unsigned char buf[WCNSS_MAX_FRAME_SIZE];
struct smd_msg_hdr *phdr;
struct wcnss_version *pversion;
len = smd_read_avail(penv->smd_ch);
if (len > WCNSS_MAX_FRAME_SIZE) {
pr_err("wcnss: frame larger than the allowed size\n");
smd_read(penv->smd_ch, NULL, len);
return;
}
if (len <= 0)
return;
rc = smd_read(penv->smd_ch, buf, len);
if (rc < len) {
pr_err("wcnss: incomplete data read from smd\n");
return;
}
phdr = (struct smd_msg_hdr *)buf;
switch (phdr->type) {
case WCNSS_VERSION_RSP:
pversion = (struct wcnss_version *)buf;
if (len != sizeof(struct wcnss_version)) {
pr_err("wcnss: invalid version data from wcnss %d\n",
len);
return;
}
snprintf(penv->wcnss_version, WCNSS_VERSION_LEN,
"%02x%02x%02x%02x", pversion->major, pversion->minor,
pversion->version, pversion->revision);
pr_info("wcnss: version %s\n", penv->wcnss_version);
break;
default:
pr_err("wcnss: invalid message type %d\n", phdr->type);
}
return;
}
static void wcnss_send_version_req(struct work_struct *worker)
{
struct smd_msg_hdr smd_msg;
int ret = 0;
smd_msg.type = WCNSS_VERSION_REQ;
smd_msg.len = sizeof(smd_msg);
ret = wcnss_smd_tx(&smd_msg, smd_msg.len);
if (ret < 0)
pr_err("wcnss: smd tx failed\n");
return;
}
static int
wcnss_trigger_config(struct platform_device *pdev)
{
@ -448,6 +651,7 @@ wcnss_trigger_config(struct platform_device *pdev)
penv->wlan_config.use_48mhz_xo = has_48mhz_xo;
penv->thermal_mitigation = 0;
strlcpy(penv->wcnss_version, "INVALID", WCNSS_VERSION_LEN);
penv->gpios_5wire = platform_get_resource_byname(pdev, IORESOURCE_IO,
"wcnss_gpios_5wire");
@ -497,10 +701,8 @@ wcnss_trigger_config(struct platform_device *pdev)
goto fail_res;
}
/* register sysfs entries */
ret = wcnss_create_sysfs(&pdev->dev);
if (ret)
goto fail_sysfs;
INIT_WORK(&penv->wcnssctrl_rx_work, wcnssctrl_rx_handler);
INIT_WORK(&penv->wcnssctrl_version_work, wcnss_send_version_req);
wake_lock_init(&penv->wcnss_wake_lock, WAKE_LOCK_SUSPEND, "wcnss");
@ -515,7 +717,6 @@ wcnss_trigger_config(struct platform_device *pdev)
fail_wake:
wake_lock_destroy(&penv->wcnss_wake_lock);
fail_sysfs:
fail_res:
if (penv->pil)
pil_put(penv->pil);
@ -557,6 +758,8 @@ static struct miscdevice wcnss_misc = {
static int __devinit
wcnss_wlan_probe(struct platform_device *pdev)
{
int ret = 0;
/* verify we haven't been called more than once */
if (penv) {
dev_err(&pdev->dev, "cannot handle multiple devices.\n");
@ -571,6 +774,12 @@ wcnss_wlan_probe(struct platform_device *pdev)
}
penv->pdev = pdev;
/* register sysfs entries */
ret = wcnss_create_sysfs(&pdev->dev);
if (ret)
return -ENOENT;
#ifdef MODULE
/*
@ -626,6 +835,7 @@ static int __init wcnss_wlan_init(void)
{
platform_driver_register(&wcnss_wlan_driver);
platform_driver_register(&wcnss_wlan_ctrl_driver);
platform_driver_register(&wcnss_ctrl_driver);
return 0;
}
@ -641,6 +851,7 @@ static void __exit wcnss_wlan_exit(void)
penv = NULL;
}
platform_driver_unregister(&wcnss_ctrl_driver);
platform_driver_unregister(&wcnss_wlan_ctrl_driver);
platform_driver_unregister(&wcnss_wlan_driver);
}