Skip to content

Commit

Permalink
usb: gadget: udc-xilinx: Add clock support
Browse files Browse the repository at this point in the history
Currently the driver depends on the  bootloader to enable the clocks.
Add support for clocking. The patch enables the clock at  probe and
disables them at remove.

Signed-off-by: Shubhrajyoti Datta <[email protected]>
Signed-off-by: Michal Simek <[email protected]>
  • Loading branch information
Shubhrajyoti Datta authored and Michal Simek committed Apr 23, 2018
1 parent 0c03e59 commit 732e12b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions drivers/usb/gadget/udc/udc-xilinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* later version.
*/

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
Expand Down Expand Up @@ -176,6 +177,7 @@ struct xusb_ep {
* @addr: the usb device base address
* @lock: instance of spinlock
* @dma_enabled: flag indicating whether the dma is included in the system
* @clk: pointer to struct clk
* @read_fn: function pointer to read device registers
* @write_fn: function pointer to write to device registers
*/
Expand All @@ -193,6 +195,7 @@ struct xusb_udc {
void __iomem *addr;
spinlock_t lock;
bool dma_enabled;
struct clk *clk;

unsigned int (*read_fn)(void __iomem *reg);
void (*write_fn)(void __iomem *, u32, u32);
Expand Down Expand Up @@ -2098,6 +2101,26 @@ static int xudc_probe(struct platform_device *pdev)
udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb;
udc->gadget.name = driver_name;

udc->clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
if (IS_ERR(udc->clk)) {
if (PTR_ERR(udc->clk) != -ENOENT) {
ret = PTR_ERR(udc->clk);
goto fail;
}

/*
* Clock framework support is optional, continue on,
* anyways if we don't find a matching clock
*/
udc->clk = NULL;
}

ret = clk_prepare_enable(udc->clk);
if (ret) {
dev_err(&pdev->dev, "Unable to enable clock.\n");
return ret;
}

spin_lock_init(&udc->lock);

/* Check for IP endianness */
Expand Down Expand Up @@ -2153,6 +2176,7 @@ static int xudc_remove(struct platform_device *pdev)
struct xusb_udc *udc = platform_get_drvdata(pdev);

usb_del_gadget_udc(&udc->gadget);
clk_disable_unprepare(udc->clk);

return 0;
}
Expand Down

0 comments on commit 732e12b

Please sign in to comment.