blob: 1e6c1f6e667760b6c6d6414448a5884ca8a24dce [file] [log] [blame]
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/delay.h>
#include <mach/scm.h>
#include <mach/subsystem_restart.h>
#include <mach/subsystem_notif.h>
#include "smd_private.h"
#include "ramdump.h"
#include "sysmon.h"
#include "peripheral-loader.h"
#include "pil-q6v4.h"
#include "scm-pas.h"
struct lpass_q6v4 {
struct q6v4_data q6;
void *riva_notif_hdle;
void *modem_notif_hdle;
struct subsys_device *subsys;
struct subsys_desc subsys_desc;
int crash_shutdown;
void *ramdump_dev;
struct work_struct work;
int loadable;
};
static int pil_q6v4_lpass_boot(struct pil_desc *pil)
{
struct q6v4_data *drv = pil_to_q6v4_data(pil);
int err;
err = pil_q6v4_power_up(drv);
if (err)
return err;
return pil_q6v4_boot(pil);
}
static int pil_q6v4_lpass_shutdown(struct pil_desc *pil)
{
struct q6v4_data *drv = pil_to_q6v4_data(pil);
int ret;
ret = pil_q6v4_shutdown(pil);
if (ret)
return ret;
pil_q6v4_power_down(drv);
return 0;
}
static struct pil_reset_ops pil_q6v4_lpass_ops = {
.auth_and_reset = pil_q6v4_lpass_boot,
.shutdown = pil_q6v4_lpass_shutdown,
.proxy_vote = pil_q6v4_make_proxy_votes,
.proxy_unvote = pil_q6v4_remove_proxy_votes,
};
static struct pil_reset_ops pil_q6v4_lpass_ops_trusted = {
.init_image = pil_q6v4_init_image_trusted,
.auth_and_reset = pil_q6v4_boot_trusted,
.shutdown = pil_q6v4_shutdown_trusted,
.proxy_vote = pil_q6v4_make_proxy_votes,
.proxy_unvote = pil_q6v4_remove_proxy_votes,
};
static int riva_notifier_cb(struct notifier_block *this, unsigned long code,
void *ss_handle)
{
int ret;
switch (code) {
case SUBSYS_BEFORE_SHUTDOWN:
pr_debug("%s: R-Notify: Shutdown started\n", __func__);
ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss",
SUBSYS_BEFORE_SHUTDOWN);
if (ret < 0)
pr_err("%s: sysmon_send_event error %d", __func__, ret);
break;
}
return NOTIFY_DONE;
}
static struct notifier_block rnb = {
.notifier_call = riva_notifier_cb,
};
static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
void *ss_handle)
{
int ret;
switch (code) {
case SUBSYS_BEFORE_SHUTDOWN:
pr_debug("%s: M-Notify: Shutdown started\n", __func__);
ret = sysmon_send_event(SYSMON_SS_LPASS, "modem",
SUBSYS_BEFORE_SHUTDOWN);
if (ret < 0)
pr_err("%s: sysmon_send_event error %d", __func__, ret);
break;
}
return NOTIFY_DONE;
}
static struct notifier_block mnb = {
.notifier_call = modem_notifier_cb,
};
static void lpass_log_failure_reason(void)
{
char *reason;
char buffer[81];
unsigned size;
reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size);
if (!reason) {
pr_err("LPASS subsystem failure reason: (unknown, smem_get_entry failed).");
return;
}
if (reason[0] == '\0') {
pr_err("LPASS subsystem failure reason: (unknown, init value found)");
return;
}
size = min(size, sizeof(buffer) - 1);
memcpy(buffer, reason, size);
buffer[size] = '\0';
pr_err("LPASS subsystem failure reason: %s", buffer);
memset((void *)reason, 0x0, size);
wmb();
}
static void lpass_fatal_fn(struct work_struct *work)
{
pr_err("Watchdog bite received from lpass Q6!\n");
lpass_log_failure_reason();
panic("Q6 Resetting the SoC");
}
static void lpass_smsm_state_cb(void *data, uint32_t old_state,
uint32_t new_state)
{
struct lpass_q6v4 *drv = data;
/* Ignore if we're the one that set SMSM_RESET */
if (drv->crash_shutdown)
return;
if (new_state & SMSM_RESET) {
pr_err("%s: LPASS SMSM state changed to SMSM_RESET, new_state = %#x, old_state = %#x\n",
__func__, new_state, old_state);
lpass_log_failure_reason();
panic("Q6 Resetting the SoC");
}
}
#define SCM_Q6_NMI_CMD 0x1
static void send_q6_nmi(void)
{
/* Send NMI to QDSP6 via an SCM call. */
uint32_t cmd = 0x1;
scm_call(SCM_SVC_UTIL, SCM_Q6_NMI_CMD,
&cmd, sizeof(cmd), NULL, 0);
/* Q6 requires worstcase 100ms to dump caches etc.*/
mdelay(100);
pr_debug("%s: Q6 NMI was sent.\n", __func__);
}
#define subsys_to_lpass(d) container_of(d, struct lpass_q6v4, subsys_desc)
static int lpass_start(const struct subsys_desc *desc)
{
struct lpass_q6v4 *drv = subsys_to_lpass(desc);
if (drv->loadable)
return pil_boot(&drv->q6.desc);
return 0;
}
static void lpass_stop(const struct subsys_desc *desc)
{
struct lpass_q6v4 *drv = subsys_to_lpass(desc);
if (drv->loadable)
pil_shutdown(&drv->q6.desc);
}
static int lpass_shutdown(const struct subsys_desc *subsys)
{
struct lpass_q6v4 *drv = subsys_to_lpass(subsys);
send_q6_nmi();
if (drv->loadable)
pil_shutdown(&drv->q6.desc);
disable_irq_nosync(drv->q6.wdog_irq);
return 0;
}
static int lpass_powerup(const struct subsys_desc *subsys)
{
struct lpass_q6v4 *drv = subsys_to_lpass(subsys);
int ret = 0;
if (drv->loadable)
ret = pil_boot(&drv->q6.desc);
enable_irq(drv->q6.wdog_irq);
return ret;
}
static struct ramdump_segment segments[] = {
{0x8da00000, 0x8f200000 - 0x8da00000},
{0x28400000, 0x20000}
};
static int lpass_ramdump(int enable, const struct subsys_desc *subsys)
{
struct lpass_q6v4 *drv = subsys_to_lpass(subsys);
if (!enable)
return 0;
return do_ramdump(drv->ramdump_dev, segments, ARRAY_SIZE(segments));
}
static void lpass_crash_shutdown(const struct subsys_desc *subsys)
{
struct lpass_q6v4 *drv = subsys_to_lpass(subsys);
drv->crash_shutdown = 1;
send_q6_nmi();
}
static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id)
{
struct lpass_q6v4 *drv = dev_id;
disable_irq_nosync(drv->q6.wdog_irq);
schedule_work(&drv->work);
return IRQ_HANDLED;
}
static int __devinit pil_q6v4_lpass_driver_probe(struct platform_device *pdev)
{
const struct pil_q6v4_pdata *pdata = pdev->dev.platform_data;
struct lpass_q6v4 *drv;
struct q6v4_data *q6;
struct pil_desc *desc;
struct resource *res;
int ret;
drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
platform_set_drvdata(pdev, drv);
q6 = &drv->q6;
desc = &q6->desc;
q6->wdog_irq = platform_get_irq(pdev, 0);
if (q6->wdog_irq < 0)
return q6->wdog_irq;
drv->loadable = !!pdata; /* No pdata = don't use PIL */
if (drv->loadable) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
q6->base = devm_request_and_ioremap(&pdev->dev, res);
if (!q6->base)
return -ENOMEM;
q6->vreg = devm_regulator_get(&pdev->dev, "core_vdd");
if (IS_ERR(q6->vreg))
return PTR_ERR(q6->vreg);
q6->xo = devm_clk_get(&pdev->dev, "xo");
if (IS_ERR(q6->xo))
return PTR_ERR(q6->xo);
desc->name = pdata->name;
desc->dev = &pdev->dev;
desc->owner = THIS_MODULE;
desc->proxy_timeout = 10000;
pil_q6v4_init(q6, pdata);
if (pas_supported(pdata->pas_id) > 0) {
desc->ops = &pil_q6v4_lpass_ops_trusted;
dev_info(&pdev->dev, "using secure boot\n");
} else {
desc->ops = &pil_q6v4_lpass_ops;
dev_info(&pdev->dev, "using non-secure boot\n");
}
ret = pil_desc_init(desc);
if (ret)
return ret;
}
drv->subsys_desc.name = "adsp";
drv->subsys_desc.dev = &pdev->dev;
drv->subsys_desc.owner = THIS_MODULE;
drv->subsys_desc.start = lpass_start;
drv->subsys_desc.stop = lpass_stop;
drv->subsys_desc.shutdown = lpass_shutdown;
drv->subsys_desc.powerup = lpass_powerup;
drv->subsys_desc.ramdump = lpass_ramdump;
drv->subsys_desc.crash_shutdown = lpass_crash_shutdown;
INIT_WORK(&drv->work, lpass_fatal_fn);
drv->ramdump_dev = create_ramdump_device("lpass", &pdev->dev);
if (!drv->ramdump_dev) {
ret = -ENOMEM;
goto err_ramdump;
}
drv->subsys = subsys_register(&drv->subsys_desc);
if (IS_ERR(drv->subsys)) {
ret = PTR_ERR(drv->subsys);
goto err_subsys;
}
if (!drv->loadable)
subsys_default_online(drv->subsys);
ret = devm_request_irq(&pdev->dev, q6->wdog_irq, lpass_wdog_bite_irq,
IRQF_TRIGGER_RISING, dev_name(&pdev->dev), drv);
if (ret)
goto err_irq;
ret = smsm_state_cb_register(SMSM_Q6_STATE, SMSM_RESET,
lpass_smsm_state_cb, drv);
if (ret < 0)
goto err_smsm;
drv->riva_notif_hdle = subsys_notif_register_notifier("riva", &rnb);
if (IS_ERR(drv->riva_notif_hdle)) {
ret = PTR_ERR(drv->riva_notif_hdle);
goto err_notif_riva;
}
drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb);
if (IS_ERR(drv->modem_notif_hdle)) {
ret = PTR_ERR(drv->modem_notif_hdle);
goto err_notif_modem;
}
return 0;
err_notif_modem:
subsys_notif_unregister_notifier(drv->riva_notif_hdle, &rnb);
err_notif_riva:
smsm_state_cb_deregister(SMSM_Q6_STATE, SMSM_RESET,
lpass_smsm_state_cb, drv);
err_smsm:
err_irq:
subsys_unregister(drv->subsys);
err_subsys:
destroy_ramdump_device(drv->ramdump_dev);
err_ramdump:
if (drv->loadable)
pil_desc_release(desc);
return ret;
}
static int __devexit pil_q6v4_lpass_driver_exit(struct platform_device *pdev)
{
struct lpass_q6v4 *drv = platform_get_drvdata(pdev);
subsys_notif_unregister_notifier(drv->riva_notif_hdle, &rnb);
subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb);
smsm_state_cb_deregister(SMSM_Q6_STATE, SMSM_RESET,
lpass_smsm_state_cb, drv);
subsys_unregister(drv->subsys);
destroy_ramdump_device(drv->ramdump_dev);
if (drv->loadable)
pil_desc_release(&drv->q6.desc);
return 0;
}
static struct platform_driver pil_q6v4_lpass_driver = {
.probe = pil_q6v4_lpass_driver_probe,
.remove = __devexit_p(pil_q6v4_lpass_driver_exit),
.driver = {
.name = "pil-q6v4-lpass",
.owner = THIS_MODULE,
},
};
static int __init pil_q6v4_lpass_init(void)
{
return platform_driver_register(&pil_q6v4_lpass_driver);
}
module_init(pil_q6v4_lpass_init);
static void __exit pil_q6v4_lpass_exit(void)
{
platform_driver_unregister(&pil_q6v4_lpass_driver);
}
module_exit(pil_q6v4_lpass_exit);
MODULE_DESCRIPTION("Support for booting QDSP6v4 (Hexagon) processors");
MODULE_LICENSE("GPL v2");