2015-01-20 22:55:57 +00:00
|
|
|
/*
|
|
|
|
* Driver for the NXP ISP1760 chip
|
|
|
|
*
|
|
|
|
* Copyright 2014 Laurent Pinchart
|
|
|
|
* Copyright 2007 Sebastian Siewior
|
|
|
|
*
|
|
|
|
* Contacts:
|
|
|
|
* Sebastian Siewior <bigeasy@linutronix.de>
|
|
|
|
* Laurent Pinchart <laurent.pinchart@ideasonboard.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2015-01-20 22:55:59 +00:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
2015-01-20 22:55:57 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
#include "isp1760-core.h"
|
|
|
|
#include "isp1760-hcd.h"
|
2015-01-20 22:55:59 +00:00
|
|
|
#include "isp1760-regs.h"
|
|
|
|
|
|
|
|
static void isp1760_init_core(struct isp1760_device *isp)
|
|
|
|
{
|
|
|
|
u32 hwmode;
|
|
|
|
|
|
|
|
/* Low-level chip reset */
|
|
|
|
if (isp->rst_gpio) {
|
|
|
|
gpiod_set_value_cansleep(isp->rst_gpio, 1);
|
|
|
|
mdelay(50);
|
|
|
|
gpiod_set_value_cansleep(isp->rst_gpio, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the host controller, including the CPU interface
|
|
|
|
* configuration.
|
|
|
|
*/
|
|
|
|
isp1760_write32(isp->regs, HC_RESET_REG, SW_RESET_RESET_ALL);
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
/* Setup HW Mode Control: This assumes a level active-low interrupt */
|
|
|
|
hwmode = HW_DATA_BUS_32BIT;
|
|
|
|
|
|
|
|
if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_16)
|
|
|
|
hwmode &= ~HW_DATA_BUS_32BIT;
|
|
|
|
if (isp->devflags & ISP1760_FLAG_ANALOG_OC)
|
|
|
|
hwmode |= HW_ANA_DIGI_OC;
|
|
|
|
if (isp->devflags & ISP1760_FLAG_DACK_POL_HIGH)
|
|
|
|
hwmode |= HW_DACK_POL_HIGH;
|
|
|
|
if (isp->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
|
|
|
|
hwmode |= HW_DREQ_POL_HIGH;
|
|
|
|
if (isp->devflags & ISP1760_FLAG_INTR_POL_HIGH)
|
|
|
|
hwmode |= HW_INTR_HIGH_ACT;
|
|
|
|
if (isp->devflags & ISP1760_FLAG_INTR_EDGE_TRIG)
|
|
|
|
hwmode |= HW_INTR_EDGE_TRIG;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to set this first in case we're in 16-bit mode.
|
|
|
|
* Write it twice to ensure correct upper bits if switching
|
|
|
|
* to 16-bit mode.
|
|
|
|
*/
|
|
|
|
isp1760_write32(isp->regs, HC_HW_MODE_CTRL, hwmode);
|
|
|
|
isp1760_write32(isp->regs, HC_HW_MODE_CTRL, hwmode);
|
|
|
|
|
|
|
|
dev_info(isp->dev, "bus width: %u, oc: %s\n",
|
|
|
|
isp->devflags & ISP1760_FLAG_BUS_WIDTH_16 ? 16 : 32,
|
|
|
|
isp->devflags & ISP1760_FLAG_ANALOG_OC ? "analog" : "digital");
|
|
|
|
}
|
2015-01-20 22:55:57 +00:00
|
|
|
|
|
|
|
int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
|
|
|
|
struct device *dev, unsigned int devflags)
|
|
|
|
{
|
|
|
|
struct isp1760_device *isp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (usb_disabled())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* prevent usb-core allocating DMA pages */
|
|
|
|
dev->dma_mask = NULL;
|
|
|
|
|
|
|
|
isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
|
|
|
|
if (!isp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-01-20 22:55:59 +00:00
|
|
|
isp->dev = dev;
|
|
|
|
isp->devflags = devflags;
|
|
|
|
|
|
|
|
isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(isp->rst_gpio))
|
|
|
|
return PTR_ERR(isp->rst_gpio);
|
|
|
|
|
2015-01-20 22:55:57 +00:00
|
|
|
isp->regs = devm_ioremap_resource(dev, mem);
|
|
|
|
if (IS_ERR(isp->regs))
|
|
|
|
return PTR_ERR(isp->regs);
|
|
|
|
|
2015-01-20 22:55:59 +00:00
|
|
|
isp1760_init_core(isp);
|
|
|
|
|
2015-01-20 22:55:58 +00:00
|
|
|
ret = isp1760_hcd_register(&isp->hcd, isp->regs, mem, irq,
|
2015-01-20 22:55:59 +00:00
|
|
|
irqflags | IRQF_SHARED, dev);
|
2015-01-20 22:55:57 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, isp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void isp1760_unregister(struct device *dev)
|
|
|
|
{
|
|
|
|
struct isp1760_device *isp = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
isp1760_hcd_unregister(&isp->hcd);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
|
|
|
|
MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|