Pull DMA mask updates from Russell King:
"This series cleans up the handling of DMA masks in a lot of drivers,
fixing some bugs as we go.
Some of the more serious errors include:
- drivers which only set their coherent DMA mask if the attempt to
set the streaming mask fails.
- drivers which test for a NULL dma mask pointer, and then set the
dma mask pointer to a location in their module .data section -
which will cause problems if the module is reloaded.
To counter these, I have introduced two helper functions:
- dma_set_mask_and_coherent() takes care of setting both the
streaming and coherent masks at the same time, with the correct
error handling as specified by the API.
- dma_coerce_mask_and_coherent() which resolves the problem of
drivers forcefully setting DMA masks. This is more a marker for
future work to further clean these locations up - the code which
creates the devices really should be initialising these, but to fix
that in one go along with this change could potentially be very
disruptive.
The last thing this series does is prise away some of Linux's addition
to "DMA addresses are physical addresses and RAM always starts at
zero". We have ARM LPAE systems where all system memory is above 4GB
physical, hence having DMA masks interpreted by (eg) the block layers
as describing physical addresses in the range 0..DMAMASK fails on
these platforms. Santosh Shilimkar addresses this in this series; the
patches were copied to the appropriate people multiple times but were
ignored.
Fixing this also gets rid of some ARM weirdness in the setup of the
max*pfn variables, and brings ARM into line with every other Linux
architecture as far as those go"
* 'for-linus-dma-masks' of git://git.linaro.org/people/rmk/linux-arm: (52 commits)
ARM: 7805/1: mm: change max*pfn to include the physical offset of memory
ARM: 7797/1: mmc: Use dma_max_pfn(dev) helper for bounce_limit calculations
ARM: 7796/1: scsi: Use dma_max_pfn(dev) helper for bounce_limit calculations
ARM: 7795/1: mm: dma-mapping: Add dma_max_pfn(dev) helper function
ARM: 7794/1: block: Rename parameter dma_mask to max_addr for blk_queue_bounce_limit()
ARM: DMA-API: better handing of DMA masks for coherent allocations
ARM: 7857/1: dma: imx-sdma: setup dma mask
DMA-API: firmware/google/gsmi.c: avoid direct access to DMA masks
DMA-API: dcdbas: update DMA mask handing
DMA-API: dma: edma.c: no need to explicitly initialize DMA masks
DMA-API: usb: musb: use platform_device_register_full() to avoid directly messing with dma masks
DMA-API: crypto: remove last references to 'static struct device *dev'
DMA-API: crypto: fix ixp4xx crypto platform device support
DMA-API: others: use dma_set_coherent_mask()
DMA-API: staging: use dma_set_coherent_mask()
DMA-API: usb: use new dma_coerce_mask_and_coherent()
DMA-API: usb: use dma_set_coherent_mask()
DMA-API: parport: parport_pc.c: use dma_coerce_mask_and_coherent()
DMA-API: net: octeon: use dma_coerce_mask_and_coherent()
DMA-API: net: nxp/lpc_eth: use dma_coerce_mask_and_coherent()
...
208 lines
4.9 KiB
C
208 lines
4.9 KiB
C
/*
|
|
* OHCI HCD (Host Controller Driver) for USB.
|
|
*
|
|
* Copyright (C) 2010 ST Microelectronics.
|
|
* Deepak Sikri<deepak.sikri@st.com>
|
|
*
|
|
* Based on various ohci-*.c drivers
|
|
*
|
|
* This file is licensed under the terms of the GNU General Public
|
|
* License version 2. This program is licensed "as is" without any
|
|
* warranty of any kind, whether express or implied.
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/io.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/signal.h>
|
|
#include <linux/usb.h>
|
|
#include <linux/usb/hcd.h>
|
|
|
|
#include "ohci.h"
|
|
|
|
#define DRIVER_DESC "OHCI SPEAr driver"
|
|
|
|
static const char hcd_name[] = "SPEAr-ohci";
|
|
struct spear_ohci {
|
|
struct clk *clk;
|
|
};
|
|
|
|
#define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv)
|
|
|
|
static struct hc_driver __read_mostly ohci_spear_hc_driver;
|
|
|
|
static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
|
|
{
|
|
const struct hc_driver *driver = &ohci_spear_hc_driver;
|
|
struct ohci_hcd *ohci;
|
|
struct usb_hcd *hcd = NULL;
|
|
struct clk *usbh_clk;
|
|
struct spear_ohci *sohci_p;
|
|
struct resource *res;
|
|
int retval, irq;
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
if (irq < 0) {
|
|
retval = irq;
|
|
goto fail;
|
|
}
|
|
|
|
/*
|
|
* Right now device-tree probed devices don't get dma_mask set.
|
|
* Since shared usb code relies on it, set it here for now.
|
|
* Once we have dma capability bindings this can go away.
|
|
*/
|
|
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
|
|
if (retval)
|
|
goto fail;
|
|
|
|
usbh_clk = devm_clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(usbh_clk)) {
|
|
dev_err(&pdev->dev, "Error getting interface clock\n");
|
|
retval = PTR_ERR(usbh_clk);
|
|
goto fail;
|
|
}
|
|
|
|
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
|
|
if (!hcd) {
|
|
retval = -ENOMEM;
|
|
goto fail;
|
|
}
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res) {
|
|
retval = -ENODEV;
|
|
goto err_put_hcd;
|
|
}
|
|
|
|
hcd->rsrc_start = pdev->resource[0].start;
|
|
hcd->rsrc_len = resource_size(res);
|
|
if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
|
|
hcd_name)) {
|
|
dev_dbg(&pdev->dev, "request_mem_region failed\n");
|
|
retval = -EBUSY;
|
|
goto err_put_hcd;
|
|
}
|
|
|
|
hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
|
|
if (!hcd->regs) {
|
|
dev_dbg(&pdev->dev, "ioremap failed\n");
|
|
retval = -ENOMEM;
|
|
goto err_put_hcd;
|
|
}
|
|
|
|
sohci_p = to_spear_ohci(hcd);
|
|
sohci_p->clk = usbh_clk;
|
|
|
|
clk_prepare_enable(sohci_p->clk);
|
|
|
|
ohci = hcd_to_ohci(hcd);
|
|
|
|
retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
|
|
if (retval == 0)
|
|
return retval;
|
|
|
|
clk_disable_unprepare(sohci_p->clk);
|
|
err_put_hcd:
|
|
usb_put_hcd(hcd);
|
|
fail:
|
|
dev_err(&pdev->dev, "init fail, %d\n", retval);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
|
|
{
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
struct spear_ohci *sohci_p = to_spear_ohci(hcd);
|
|
|
|
usb_remove_hcd(hcd);
|
|
if (sohci_p->clk)
|
|
clk_disable_unprepare(sohci_p->clk);
|
|
|
|
usb_put_hcd(hcd);
|
|
return 0;
|
|
}
|
|
|
|
#if defined(CONFIG_PM)
|
|
static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
|
|
pm_message_t message)
|
|
{
|
|
struct usb_hcd *hcd = platform_get_drvdata(dev);
|
|
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
|
|
struct spear_ohci *sohci_p = to_spear_ohci(hcd);
|
|
|
|
if (time_before(jiffies, ohci->next_statechange))
|
|
msleep(5);
|
|
ohci->next_statechange = jiffies;
|
|
|
|
clk_disable_unprepare(sohci_p->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
|
|
{
|
|
struct usb_hcd *hcd = platform_get_drvdata(dev);
|
|
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
|
|
struct spear_ohci *sohci_p = to_spear_ohci(hcd);
|
|
|
|
if (time_before(jiffies, ohci->next_statechange))
|
|
msleep(5);
|
|
ohci->next_statechange = jiffies;
|
|
|
|
clk_prepare_enable(sohci_p->clk);
|
|
ohci_resume(hcd, false);
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
static struct of_device_id spear_ohci_id_table[] = {
|
|
{ .compatible = "st,spear600-ohci", },
|
|
{ },
|
|
};
|
|
|
|
/* Driver definition to register with the platform bus */
|
|
static struct platform_driver spear_ohci_hcd_driver = {
|
|
.probe = spear_ohci_hcd_drv_probe,
|
|
.remove = spear_ohci_hcd_drv_remove,
|
|
#ifdef CONFIG_PM
|
|
.suspend = spear_ohci_hcd_drv_suspend,
|
|
.resume = spear_ohci_hcd_drv_resume,
|
|
#endif
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = "spear-ohci",
|
|
.of_match_table = spear_ohci_id_table,
|
|
},
|
|
};
|
|
|
|
static const struct ohci_driver_overrides spear_overrides __initconst = {
|
|
.extra_priv_size = sizeof(struct spear_ohci),
|
|
};
|
|
static int __init ohci_spear_init(void)
|
|
{
|
|
if (usb_disabled())
|
|
return -ENODEV;
|
|
|
|
pr_info("%s: " DRIVER_DESC "\n", hcd_name);
|
|
|
|
ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides);
|
|
return platform_driver_register(&spear_ohci_hcd_driver);
|
|
}
|
|
module_init(ohci_spear_init);
|
|
|
|
static void __exit ohci_spear_cleanup(void)
|
|
{
|
|
platform_driver_unregister(&spear_ohci_hcd_driver);
|
|
}
|
|
module_exit(ohci_spear_cleanup);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_AUTHOR("Deepak Sikri");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS("platform:spear-ohci");
|