| /* Copyright (c) 2011, Code Aurora Forum. 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/module.h> |
| #include <linux/slab.h> |
| #include <linux/err.h> |
| #include <linux/platform_device.h> |
| #include <linux/firmware.h> |
| #include <linux/parser.h> |
| #include <linux/wcnss_wlan.h> |
| #include <linux/platform_data/qcom_wcnss_device.h> |
| #include <linux/workqueue.h> |
| #include <linux/jiffies.h> |
| #include <linux/gpio.h> |
| #include <mach/peripheral-loader.h> |
| #include "wcnss_riva.h" |
| |
| #define DEVICE "wcnss_wlan" |
| #define VERSION "1.01" |
| #define WCNSS_PIL_DEVICE "wcnss" |
| #define WCNSS_NV_NAME "wlan/prima/WCNSS_qcom_cfg.ini" |
| |
| /* module params */ |
| #define WCNSS_CONFIG_UNSPECIFIED (-1) |
| static int has_48mhz_xo = WCNSS_CONFIG_UNSPECIFIED; |
| module_param(has_48mhz_xo, int, S_IRUGO); |
| MODULE_PARM_DESC(has_48mhz_xo, "Is an external 48 MHz XO present"); |
| |
| static struct { |
| struct platform_device *pdev; |
| void *pil; |
| struct resource *mmio_res; |
| struct resource *tx_irq_res; |
| struct resource *rx_irq_res; |
| struct resource *gpios_5wire; |
| const struct dev_pm_ops *pm_ops; |
| int smd_channel_ready; |
| struct wcnss_wlan_config wlan_config; |
| struct delayed_work wcnss_work; |
| } *penv = NULL; |
| |
| static void wcnss_post_bootup(struct work_struct *work) |
| { |
| pr_info("%s: Cancel APPS vote for Iris & Riva\n", __func__); |
| |
| /* Since Riva is up, cancel any APPS vote for Iris & Riva VREGs */ |
| wcnss_wlan_power(&penv->pdev->dev, &penv->wlan_config, |
| WCNSS_WLAN_SWITCH_OFF); |
| } |
| |
| static int |
| wcnss_gpios_config(struct resource *gpios_5wire, bool enable) |
| { |
| int i, j; |
| int rc = 0; |
| |
| for (i = gpios_5wire->start; i <= gpios_5wire->end; i++) { |
| if (enable) { |
| rc = gpio_request(i, gpios_5wire->name); |
| if (rc) { |
| pr_err("WCNSS gpio_request %d err %d\n", i, rc); |
| goto fail; |
| } |
| } else |
| gpio_free(i); |
| } |
| |
| return rc; |
| |
| fail: |
| for (j = i-1; j >= gpios_5wire->start; j--) |
| gpio_free(j); |
| return rc; |
| } |
| |
| static int __devinit |
| wcnss_wlan_ctrl_probe(struct platform_device *pdev) |
| { |
| if (!penv) |
| return -ENODEV; |
| |
| penv->smd_channel_ready = 1; |
| |
| pr_info("%s: SMD ctrl channel up\n", __func__); |
| |
| /* Schedule a work to do any post boot up activity */ |
| INIT_DELAYED_WORK(&penv->wcnss_work, wcnss_post_bootup); |
| schedule_delayed_work(&penv->wcnss_work, msecs_to_jiffies(10000)); |
| |
| return 0; |
| } |
| |
| static int __devexit |
| wcnss_wlan_ctrl_remove(struct platform_device *pdev) |
| { |
| if (penv) |
| penv->smd_channel_ready = 0; |
| |
| pr_info("%s: SMD ctrl channel down\n", __func__); |
| |
| return 0; |
| } |
| |
| |
| static struct platform_driver wcnss_wlan_ctrl_driver = { |
| .driver = { |
| .name = "WLAN_CTRL", |
| .owner = THIS_MODULE, |
| }, |
| .probe = wcnss_wlan_ctrl_probe, |
| .remove = __devexit_p(wcnss_wlan_ctrl_remove), |
| }; |
| |
| struct device *wcnss_wlan_get_device(void) |
| { |
| if (penv && penv->pdev && penv->smd_channel_ready) |
| return &penv->pdev->dev; |
| return NULL; |
| } |
| EXPORT_SYMBOL(wcnss_wlan_get_device); |
| |
| struct resource *wcnss_wlan_get_memory_map(struct device *dev) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && penv->smd_channel_ready) |
| return penv->mmio_res; |
| return NULL; |
| } |
| EXPORT_SYMBOL(wcnss_wlan_get_memory_map); |
| |
| int wcnss_wlan_get_dxe_tx_irq(struct device *dev) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && |
| penv->tx_irq_res && penv->smd_channel_ready) |
| return penv->tx_irq_res->start; |
| return WCNSS_WLAN_IRQ_INVALID; |
| } |
| EXPORT_SYMBOL(wcnss_wlan_get_dxe_tx_irq); |
| |
| int wcnss_wlan_get_dxe_rx_irq(struct device *dev) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && |
| penv->rx_irq_res && penv->smd_channel_ready) |
| return penv->rx_irq_res->start; |
| return WCNSS_WLAN_IRQ_INVALID; |
| } |
| EXPORT_SYMBOL(wcnss_wlan_get_dxe_rx_irq); |
| |
| void wcnss_wlan_register_pm_ops(struct device *dev, |
| const struct dev_pm_ops *pm_ops) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && pm_ops) |
| penv->pm_ops = pm_ops; |
| } |
| EXPORT_SYMBOL(wcnss_wlan_register_pm_ops); |
| |
| void wcnss_wlan_unregister_pm_ops(struct device *dev, |
| const struct dev_pm_ops *pm_ops) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && pm_ops) { |
| if (pm_ops->suspend != penv->pm_ops->suspend || |
| pm_ops->resume != penv->pm_ops->resume) |
| pr_err("PM APIs dont match with registered APIs\n"); |
| penv->pm_ops = NULL; |
| } |
| } |
| EXPORT_SYMBOL(wcnss_wlan_unregister_pm_ops); |
| |
| static int wcnss_wlan_suspend(struct device *dev) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && |
| penv->smd_channel_ready && |
| penv->pm_ops && penv->pm_ops->suspend) |
| return penv->pm_ops->suspend(dev); |
| return 0; |
| } |
| |
| static int wcnss_wlan_resume(struct device *dev) |
| { |
| if (penv && dev && (dev == &penv->pdev->dev) && |
| penv->smd_channel_ready && |
| penv->pm_ops && penv->pm_ops->resume) |
| return penv->pm_ops->resume(dev); |
| return 0; |
| } |
| |
| static int __devinit |
| wcnss_wlan_probe(struct platform_device *pdev) |
| { |
| int ret; |
| struct qcom_wcnss_opts *pdata; |
| |
| /* verify we haven't been called more than once */ |
| if (penv) { |
| dev_err(&pdev->dev, "cannot handle multiple devices.\n"); |
| return -ENODEV; |
| } |
| |
| /* create an environment to track the device */ |
| penv = kzalloc(sizeof(*penv), GFP_KERNEL); |
| if (!penv) { |
| dev_err(&pdev->dev, "cannot allocate device memory.\n"); |
| return -ENOMEM; |
| } |
| penv->pdev = pdev; |
| |
| /* initialize the WCNSS device configuration */ |
| pdata = pdev->dev.platform_data; |
| if (WCNSS_CONFIG_UNSPECIFIED == has_48mhz_xo) |
| has_48mhz_xo = pdata->has_48mhz_xo; |
| penv->wlan_config.use_48mhz_xo = has_48mhz_xo; |
| |
| penv->gpios_5wire = platform_get_resource_byname(pdev, IORESOURCE_IO, |
| "wcnss_gpios_5wire"); |
| |
| /* allocate 5-wire GPIO resources */ |
| if (!penv->gpios_5wire) { |
| dev_err(&pdev->dev, "insufficient IO resources\n"); |
| ret = -ENOENT; |
| goto fail_gpio_res; |
| } |
| |
| /* Configure 5 wire GPIOs */ |
| ret = wcnss_gpios_config(penv->gpios_5wire, true); |
| if (ret) { |
| dev_err(&pdev->dev, "WCNSS gpios config failed.\n"); |
| goto fail_gpio_res; |
| } |
| |
| /* power up the WCNSS */ |
| ret = wcnss_wlan_power(&pdev->dev, &penv->wlan_config, |
| WCNSS_WLAN_SWITCH_ON); |
| if (ret) { |
| dev_err(&pdev->dev, "WCNSS Power-up failed.\n"); |
| goto fail_power; |
| } |
| |
| /* trigger initialization of the WCNSS */ |
| penv->pil = pil_get(WCNSS_PIL_DEVICE); |
| if (IS_ERR(penv->pil)) { |
| dev_err(&pdev->dev, "Peripheral Loader failed on WCNSS.\n"); |
| ret = PTR_ERR(penv->pil); |
| penv->pil = NULL; |
| goto fail_pil; |
| } |
| |
| /* allocate resources */ |
| penv->mmio_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| "wcnss_mmio"); |
| penv->tx_irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| "wcnss_wlantx_irq"); |
| penv->rx_irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| "wcnss_wlanrx_irq"); |
| |
| if (!(penv->mmio_res && penv->tx_irq_res && penv->rx_irq_res)) { |
| dev_err(&pdev->dev, "insufficient resources\n"); |
| ret = -ENOENT; |
| goto fail_res; |
| } |
| |
| return 0; |
| |
| fail_res: |
| if (penv->pil) |
| pil_put(penv->pil); |
| fail_pil: |
| wcnss_wlan_power(&pdev->dev, &penv->wlan_config, |
| WCNSS_WLAN_SWITCH_OFF); |
| fail_power: |
| wcnss_gpios_config(penv->gpios_5wire, false); |
| fail_gpio_res: |
| kfree(penv); |
| penv = NULL; |
| return ret; |
| } |
| |
| static int __devexit |
| wcnss_wlan_remove(struct platform_device *pdev) |
| { |
| return 0; |
| } |
| |
| |
| static const struct dev_pm_ops wcnss_wlan_pm_ops = { |
| .suspend = wcnss_wlan_suspend, |
| .resume = wcnss_wlan_resume, |
| }; |
| |
| static struct platform_driver wcnss_wlan_driver = { |
| .driver = { |
| .name = DEVICE, |
| .owner = THIS_MODULE, |
| .pm = &wcnss_wlan_pm_ops, |
| }, |
| .probe = wcnss_wlan_probe, |
| .remove = __devexit_p(wcnss_wlan_remove), |
| }; |
| |
| static int __init wcnss_wlan_init(void) |
| { |
| platform_driver_register(&wcnss_wlan_driver); |
| platform_driver_register(&wcnss_wlan_ctrl_driver); |
| |
| return 0; |
| } |
| |
| static void __exit wcnss_wlan_exit(void) |
| { |
| if (penv) { |
| if (penv->pil) |
| pil_put(penv->pil); |
| |
| |
| kfree(penv); |
| penv = NULL; |
| } |
| |
| platform_driver_unregister(&wcnss_wlan_ctrl_driver); |
| platform_driver_unregister(&wcnss_wlan_driver); |
| } |
| |
| module_init(wcnss_wlan_init); |
| module_exit(wcnss_wlan_exit); |
| |
| MODULE_LICENSE("GPL v2"); |
| MODULE_VERSION(VERSION); |
| MODULE_DESCRIPTION(DEVICE "Driver"); |