Rui Miguel Silva | 88861a2 | 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 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <dm/device-internal.h> |
| 12 | #include <dm/device_compat.h> |
| 13 | #include <dm/devres.h> |
| 14 | #include <dm/lists.h> |
| 15 | #include <linux/bug.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/usb/otg.h> |
| 19 | #include <linux/usb/usb_urb_compat.h> |
| 20 | #include <log.h> |
| 21 | #include <usb.h> |
| 22 | |
| 23 | #include "isp1760-core.h" |
| 24 | #include "isp1760-hcd.h" |
| 25 | #include "isp1760-regs.h" |
| 26 | #include "isp1760-uboot.h" |
| 27 | |
| 28 | static int isp1760_msg_submit_control(struct udevice *dev, |
| 29 | struct usb_device *udev, |
| 30 | unsigned long pipe, void *buffer, |
| 31 | int length, struct devrequest *setup) |
| 32 | { |
| 33 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 34 | |
| 35 | return usb_urb_submit_control(&host->hcd, &host->urb, &host->hep, udev, |
| 36 | pipe, buffer, length, setup, 0, |
| 37 | host->host_speed); |
| 38 | } |
| 39 | |
| 40 | static int isp1760_msg_submit_bulk(struct udevice *dev, struct usb_device *udev, |
| 41 | unsigned long pipe, void *buffer, int length) |
| 42 | { |
| 43 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 44 | |
| 45 | return usb_urb_submit_bulk(&host->hcd, &host->urb, &host->hep, udev, |
| 46 | pipe, buffer, length); |
| 47 | } |
| 48 | |
| 49 | static int isp1760_msg_submit_irq(struct udevice *dev, struct usb_device *udev, |
| 50 | unsigned long pipe, void *buffer, int length, |
| 51 | int interval, bool nonblock) |
| 52 | { |
| 53 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 54 | |
| 55 | return usb_urb_submit_irq(&host->hcd, &host->urb, &host->hep, udev, |
| 56 | pipe, buffer, length, interval); |
| 57 | } |
| 58 | |
| 59 | static int isp1760_get_max_xfer_size(struct udevice *dev, size_t *size) |
| 60 | { |
| 61 | struct isp1760_host_data *host = dev_get_priv(dev); |
| 62 | struct isp1760_hcd *priv = host->hcd.hcd_priv; |
| 63 | const struct isp1760_memory_layout *mem = priv->memory_layout; |
| 64 | |
| 65 | *size = mem->blocks_size[ISP176x_BLOCK_NUM - 1]; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | struct dm_usb_ops isp1760_usb_ops = { |
| 71 | .control = isp1760_msg_submit_control, |
| 72 | .bulk = isp1760_msg_submit_bulk, |
| 73 | .interrupt = isp1760_msg_submit_irq, |
| 74 | .get_max_xfer_size = isp1760_get_max_xfer_size, |
| 75 | }; |