Rui Miguel Silva | 08ee377 | 2022-06-29 11:06:15 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Driver for the NXP ISP1760 chip |
| 4 | * |
| 5 | * Copyright 2021 Linaro, Rui Miguel Silva <rui.silva@linaro.org> |
| 6 | * |
| 7 | */ |
| 8 | |
Rui Miguel Silva | 08ee377 | 2022-06-29 11:06:15 +0100 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <dm/device-internal.h> |
| 11 | #include <dm/device_compat.h> |
| 12 | #include <dm/devres.h> |
| 13 | #include <dm/lists.h> |
| 14 | #include <linux/bug.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/usb/otg.h> |
| 18 | #include <linux/usb/usb_urb_compat.h> |
| 19 | #include <log.h> |
| 20 | #include <usb.h> |
| 21 | |
| 22 | #include "isp1760-core.h" |
| 23 | #include "isp1760-hcd.h" |
| 24 | #include "isp1760-regs.h" |
| 25 | #include "isp1760-uboot.h" |
| 26 | |
| 27 | static int isp1760_msg_submit_control(struct udevice *dev, |
| 28 | struct usb_device *udev, |
| 29 | unsigned long pipe, void *buffer, |
| 30 | int length, struct devrequest *setup) |
| 31 | { |
| 32 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 33 | |
| 34 | return usb_urb_submit_control(&host->hcd, &host->urb, &host->hep, udev, |
| 35 | pipe, buffer, length, setup, 0, |
| 36 | host->host_speed); |
| 37 | } |
| 38 | |
| 39 | static int isp1760_msg_submit_bulk(struct udevice *dev, struct usb_device *udev, |
| 40 | unsigned long pipe, void *buffer, int length) |
| 41 | { |
| 42 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 43 | |
| 44 | return usb_urb_submit_bulk(&host->hcd, &host->urb, &host->hep, udev, |
| 45 | pipe, buffer, length); |
| 46 | } |
| 47 | |
| 48 | static int isp1760_msg_submit_irq(struct udevice *dev, struct usb_device *udev, |
| 49 | unsigned long pipe, void *buffer, int length, |
| 50 | int interval, bool nonblock) |
| 51 | { |
| 52 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 53 | |
| 54 | return usb_urb_submit_irq(&host->hcd, &host->urb, &host->hep, udev, |
| 55 | pipe, buffer, length, interval); |
| 56 | } |
| 57 | |
| 58 | static int isp1760_get_max_xfer_size(struct udevice *dev, size_t *size) |
| 59 | { |
| 60 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 61 | struct isp1760_hcd *priv = host->hcd.hcd_priv; |
| 62 | const struct isp1760_memory_layout *mem = priv->memory_layout; |
| 63 | |
| 64 | *size = mem->blocks_size[ISP176x_BLOCK_NUM - 1]; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | struct dm_usb_ops isp1760_usb_ops = { |
| 70 | .control = isp1760_msg_submit_control, |
| 71 | .bulk = isp1760_msg_submit_bulk, |
| 72 | .interrupt = isp1760_msg_submit_irq, |
| 73 | .get_max_xfer_size = isp1760_get_max_xfer_size, |
| 74 | }; |