Signed-off-by: Peter Chen <peter.chen@xxxxxxxxxxxxx> --- drivers/usb/chipidea/usbmisc_imx.c | 71 +++++++++++++++++------------------- 1 files changed, 34 insertions(+), 37 deletions(-) diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index ac5a461..545efbf 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -15,6 +15,7 @@ #include <linux/err.h> #include <linux/io.h> #include <linux/delay.h> +#include <linux/regmap.h> #include "ci_hdrc_imx.h" @@ -34,10 +35,10 @@ struct imx_usbmisc { void __iomem *base; - spinlock_t lock; struct clk *clk; struct usbmisc_usb_device usbdev[USB_DEV_MAX]; const struct usbmisc_ops *ops; + struct regmap *regmap; }; static struct imx_usbmisc *usbmisc; @@ -66,21 +67,16 @@ static struct usbmisc_usb_device *get_usbdev(struct device *dev) static int usbmisc_imx25_post(struct device *dev) { struct usbmisc_usb_device *usbdev; - void __iomem *reg; - unsigned long flags; - u32 val; usbdev = get_usbdev(dev); if (IS_ERR(usbdev)) return PTR_ERR(usbdev); - reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET; - if (usbdev->evdo) { - spin_lock_irqsave(&usbmisc->lock, flags); - val = readl(reg); - writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg); - spin_unlock_irqrestore(&usbmisc->lock, flags); + regmap_update_bits(usbmisc->regmap, + MX25_USB_PHY_CTRL_OFFSET, + MX25_BM_EXTERNAL_VBUS_DIVIDER, + MX25_BM_EXTERNAL_VBUS_DIVIDER); usleep_range(5000, 10000); /* needed to stabilize voltage */ } @@ -90,37 +86,33 @@ static int usbmisc_imx25_post(struct device *dev) static int usbmisc_imx53_init(struct device *dev) { struct usbmisc_usb_device *usbdev; - void __iomem *reg = NULL; - unsigned long flags; - u32 val = 0; + unsigned int reg = 0, val = 0; usbdev = get_usbdev(dev); if (IS_ERR(usbdev)) return PTR_ERR(usbdev); if (usbdev->disable_oc) { - spin_lock_irqsave(&usbmisc->lock, flags); switch (usbdev->index) { case 0: - reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; - val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG; + reg = MX53_USB_OTG_PHY_CTRL_0_OFFSET; + val = MX53_BM_OVER_CUR_DIS_OTG; break; case 1: - reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; - val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1; + reg = MX53_USB_OTG_PHY_CTRL_0_OFFSET; + val = MX53_BM_OVER_CUR_DIS_H1; break; case 2: - reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET; - val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; + reg = MX53_USB_UH2_CTRL_OFFSET; + val = MX53_BM_OVER_CUR_DIS_UHx; break; case 3: - reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET; - val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; + reg = MX53_USB_UH3_CTRL_OFFSET; + val = MX53_BM_OVER_CUR_DIS_UHx; break; } - if (reg && val) - writel(val, reg); - spin_unlock_irqrestore(&usbmisc->lock, flags); + if (usbdev->index >= 0 && usbdev->index <= 3) + regmap_update_bits(usbmisc->regmap, reg, val, val); } return 0; @@ -128,22 +120,15 @@ static int usbmisc_imx53_init(struct device *dev) static int usbmisc_imx6q_init(struct device *dev) { - struct usbmisc_usb_device *usbdev; - unsigned long flags; - u32 reg; usbdev = get_usbdev(dev); if (IS_ERR(usbdev)) return PTR_ERR(usbdev); - if (usbdev->disable_oc) { - spin_lock_irqsave(&usbmisc->lock, flags); - reg = readl(usbmisc->base + usbdev->index * 4); - writel(reg | MX6_BM_OVER_CUR_DIS, - usbmisc->base + usbdev->index * 4); - spin_unlock_irqrestore(&usbmisc->lock, flags); - } + if (usbdev->disable_oc) + regmap_update_bits(usbmisc->regmap, usbdev->index * 4, + MX6_BM_OVER_CUR_DIS, MX6_BM_OVER_CUR_DIS); return 0; } @@ -177,6 +162,12 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); +static struct regmap_config usbmisc_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, +}; + static int usbmisc_imx_probe(struct platform_device *pdev) { struct resource *res; @@ -191,13 +182,19 @@ static int usbmisc_imx_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - spin_lock_init(&data->lock); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); data->base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(data->base)) return PTR_ERR(data->base); + usbmisc_regmap_config.max_register = res->end - res->start - 3; + data->regmap = devm_regmap_init_mmio(&pdev->dev, data->base, + &usbmisc_regmap_config); + if (IS_ERR(data->regmap)) { + dev_err(&pdev->dev, "regmap init failed\n"); + return PTR_ERR(data->regmap); + } + data->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(data->clk)) { dev_err(&pdev->dev, -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html