^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * R8A66597 HCD (Host Controller Driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006-2007 Renesas Solutions Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Portions Copyright (C) 2004-2005 David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Portions Copyright (C) 1999 Roman Weissgaerber
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "r8a66597.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) MODULE_AUTHOR("Yoshihiro Shimoda");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) MODULE_ALIAS("platform:r8a66597_hcd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DRIVER_VERSION "2009-05-26"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static const char hcd_name[] = "r8a66597_hcd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void packet_write(struct r8a66597 *r8a66597, u16 pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int r8a66597_get_frame(struct usb_hcd *hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned long reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) tmp = r8a66597_read(r8a66597, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) r8a66597_bset(r8a66597, 1 << pipenum, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) r8a66597_write(r8a66597, tmp, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned long reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) tmp = r8a66597_read(r8a66597, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) r8a66597_bclr(r8a66597, 1 << pipenum, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) r8a66597_write(r8a66597, tmp, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u16 usbspd, u8 upphub, u8 hubport, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned long devadd_reg = get_devadd_addr(r8a66597_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) r8a66597_write(r8a66597, val, devadd_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (r8a66597->pdata->on_chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) clk_prepare_enable(r8a66597->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) r8a66597_write(r8a66597, SCKE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) tmp = r8a66597_read(r8a66597, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (i++ > 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) printk(KERN_ERR "r8a66597: reg access fail.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } while ((tmp & SCKE) != SCKE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) r8a66597_write(r8a66597, 0x04, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) r8a66597_write(r8a66597, USBE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) tmp = r8a66597_read(r8a66597, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (i++ > 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) printk(KERN_ERR "r8a66597: reg access fail.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) } while ((tmp & USBE) != USBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) r8a66597_bclr(r8a66597, USBE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) XTAL, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) r8a66597_bset(r8a66597, XCKE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) tmp = r8a66597_read(r8a66597, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (i++ > 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) printk(KERN_ERR "r8a66597: reg access fail.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) } while ((tmp & SCKE) != SCKE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (r8a66597->pdata->on_chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) clk_disable_unprepare(r8a66597->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) r8a66597_bclr(r8a66597, USBE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) val = port ? DRPD : DCFM | DRPD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u16 val, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) r8a66597_write(r8a66597, 0, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) r8a66597_write(r8a66597, 0, get_intsts_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) r8a66597_port_power(r8a66597, port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) udelay(640);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) } while (tmp == EDGESTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) val = port ? DRPD : DCFM | DRPD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int enable_controller(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int ret, port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u16 vif = r8a66597->pdata->vif ? LDRV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) u16 endian = r8a66597->pdata->endian ? BIGEND : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = r8a66597_clock_enable(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) r8a66597_bset(r8a66597, USBE, SYSCFG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) r8a66597_bset(r8a66597, BRDY0, BRDYENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) r8a66597_bset(r8a66597, BEMP0, BEMPENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (port = 0; port < r8a66597->max_root_hub; port++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) r8a66597_enable_port(r8a66597, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static void disable_controller(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* disable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) r8a66597_write(r8a66597, 0, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) r8a66597_write(r8a66597, 0, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) r8a66597_write(r8a66597, 0, BRDYENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) r8a66597_write(r8a66597, 0, BEMPENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) r8a66597_write(r8a66597, 0, NRDYENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* clear status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) r8a66597_write(r8a66597, 0, BRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) r8a66597_write(r8a66597, 0, NRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) r8a66597_write(r8a66597, 0, BEMPSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) for (port = 0; port < r8a66597->max_root_hub; port++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) r8a66597_disable_port(r8a66597, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) r8a66597_clock_disable(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int get_parent_r8a66597_address(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (udev->parent && udev->parent->devnum != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) udev = udev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) dev = dev_get_drvdata(&udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return dev->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int is_child_device(char *devpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return (devpath[2] ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int is_hub_limit(char *devpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return ((strlen(devpath) >= 4) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void get_port_number(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) char *devpath, u16 *root_port, u16 *hub_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (root_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *root_port = (devpath[0] & 0x0F) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (*root_port >= r8a66597->max_root_hub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) printk(KERN_ERR "r8a66597: Illegal root port number.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (hub_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *hub_port = devpath[2] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static u16 get_r8a66597_usb_speed(enum usb_device_speed speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) u16 usbspd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) switch (speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) case USB_SPEED_LOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) usbspd = LSMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case USB_SPEED_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) usbspd = FSMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case USB_SPEED_HIGH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) usbspd = HSMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) printk(KERN_ERR "r8a66597: unknown speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return usbspd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void set_child_connect_map(struct r8a66597 *r8a66597, int address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) idx = address / 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) r8a66597->child_connect_map[idx] |= 1 << (address % 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static void put_child_connect_map(struct r8a66597 *r8a66597, int address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) idx = address / 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) r8a66597->child_connect_map[idx] &= ~(1 << (address % 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) u16 pipenum = pipe->info.pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dma_ch = R8A66597_PIPE_NO_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) pipe->fifoaddr = fifoaddr[dma_ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) pipe->fifosel = fifosel[dma_ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) pipe->fifoctr = fifoctr[dma_ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (pipenum == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pipe->pipectr = DCPCTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) pipe->pipectr = get_pipectr_addr(pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (check_bulk_or_isoc(pipenum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pipe->pipetre = get_pipetre_addr(pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pipe->pipetrn = get_pipetrn_addr(pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) pipe->pipetre = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) pipe->pipetrn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct r8a66597_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (usb_pipedevice(urb->pipe) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return &r8a66597->device0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return dev_get_drvdata(&urb->dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int make_r8a66597_device(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct urb *urb, u8 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dev_set_drvdata(&urb->dev->dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) dev->udev = urb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) dev->address = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) dev->usb_address = usb_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dev->state = USB_STATE_ADDRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) dev->ep_in_toggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) dev->ep_out_toggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) INIT_LIST_HEAD(&dev->device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) list_add_tail(&dev->device_list, &r8a66597->child_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) get_port_number(r8a66597, urb->dev->devpath,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) &dev->root_port, &dev->hub_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!is_child_device(urb->dev->devpath))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) r8a66597->root_hub[dev->root_port].dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) set_devadd_reg(r8a66597, dev->address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) get_r8a66597_usb_speed(urb->dev->speed),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) get_parent_r8a66597_address(r8a66597, urb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dev->hub_port, dev->root_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) u8 addr; /* R8A66597's address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (is_hub_limit(urb->dev->devpath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) dev_err(&urb->dev->dev, "External hub limit reached.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (dev && dev->state >= USB_STATE_ADDRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return dev->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (r8a66597->address_map & (1 << addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) dev_dbg(&urb->dev->dev, "alloc_address: r8a66597_addr=%d\n", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) r8a66597->address_map |= 1 << addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (make_r8a66597_device(r8a66597, urb, addr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) dev_err(&urb->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) "cannot communicate with a USB device more than 10.(%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) r8a66597->address_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static void free_usb_address(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct r8a66597_device *dev, int reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) dev_dbg(&dev->udev->dev, "free_addr: addr=%d\n", dev->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) dev->state = USB_STATE_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) r8a66597->address_map &= ~(1 << dev->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) dev->address = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * Only when resetting USB, it is necessary to erase drvdata. When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * a usb device with usb hub is disconnect, "dev->udev" is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * freed on usb_desconnect(). So we cannot access the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) dev_set_drvdata(&dev->udev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) list_del(&dev->device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) for (port = 0; port < r8a66597->max_root_hub; port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (r8a66597->root_hub[port].dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) r8a66597->root_hub[port].dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) u16 mask, u16 loop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) tmp = r8a66597_read(r8a66597, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (i++ > 1000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) printk(KERN_ERR "r8a66597: register%lx, loop %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) "is timeout\n", reg, loop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) ndelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) } while ((tmp & mask) != loop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static void clear_all_buffer(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct r8a66597_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (!pipe || pipe->info.pipenum == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) pipe_stop(r8a66597, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) r8a66597_bset(r8a66597, ACLRM, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) r8a66597_read(r8a66597, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) r8a66597_read(r8a66597, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) r8a66597_read(r8a66597, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct r8a66597_pipe *pipe, int toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) r8a66597_bset(r8a66597, SQSET, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) r8a66597_bset(r8a66597, SQCLR, pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static inline unsigned short mbw_value(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (r8a66597->pdata->on_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return MBW_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return MBW_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) unsigned short mbw = mbw_value(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) r8a66597_mdfy(r8a66597, mbw | pipenum, mbw | CURPIPE, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct r8a66597_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) unsigned short mbw = mbw_value(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) cfifo_change(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D0FIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D1FIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum, mbw | CURPIPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) pipe->fifosel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct r8a66597_pipe *pipe = hep->hcpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (usb_pipeendpoint(urb->pipe) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return pipe->info.pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static unsigned short *get_toggle_pointer(struct r8a66597_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) int urb_pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static void pipe_toggle_set(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct r8a66597_pipe *pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct urb *urb, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned char endpoint = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (!toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) *toggle |= 1 << endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) *toggle &= ~(1 << endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static void pipe_toggle_save(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct r8a66597_pipe *pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) pipe_toggle_set(r8a66597, pipe, urb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) pipe_toggle_set(r8a66597, pipe, urb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static void pipe_toggle_restore(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct r8a66597_pipe *pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) unsigned char endpoint = usb_pipeendpoint(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static void pipe_buffer_setting(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct r8a66597_pipe_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) u16 val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (info->pipenum == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) r8a66597_write(r8a66597, info->pipenum, PIPESEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (!info->dir_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) val |= R8A66597_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (info->type == R8A66597_BULK && info->dir_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) val |= R8A66597_DBLB | R8A66597_SHTNAK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) val |= info->type | info->epnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) r8a66597_write(r8a66597, val, PIPECFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) PIPEBUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) PIPEMAXP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) r8a66597_write(r8a66597, info->interval, PIPEPERI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct r8a66597_pipe_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) struct urb *urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (td->pipenum > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) info = &td->pipe->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) cfifo_change(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) pipe_buffer_setting(r8a66597, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) usb_pipeout(urb->pipe)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) !usb_pipecontrol(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) r8a66597_pipe_toggle(r8a66597, td->pipe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) pipe_toggle_set(r8a66597, td->pipe, urb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) clear_all_buffer(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) usb_pipeout(urb->pipe), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) pipe_toggle_restore(r8a66597, td->pipe, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct usb_endpoint_descriptor *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) memset(array, 0, sizeof(array));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) switch (usb_endpoint_type(ep)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) case USB_ENDPOINT_XFER_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (usb_endpoint_dir_in(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) array[i++] = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) array[i++] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) array[i++] = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) case USB_ENDPOINT_XFER_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (usb_endpoint_dir_in(ep)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) array[i++] = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) array[i++] = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) array[i++] = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) array[i++] = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) case USB_ENDPOINT_XFER_ISOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (usb_endpoint_dir_in(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) array[i++] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) array[i++] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) printk(KERN_ERR "r8a66597: Illegal type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) min = array[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) while (array[i] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) min = array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static u16 get_r8a66597_type(__u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) u16 r8a66597_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) case USB_ENDPOINT_XFER_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) r8a66597_type = R8A66597_BULK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) case USB_ENDPOINT_XFER_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) r8a66597_type = R8A66597_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) case USB_ENDPOINT_XFER_ISOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) r8a66597_type = R8A66597_ISO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) printk(KERN_ERR "r8a66597: Illegal type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) r8a66597_type = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return r8a66597_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static u16 get_bufnum(u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) u16 bufnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (pipenum == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) bufnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) else if (check_bulk_or_isoc(pipenum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) else if (check_interrupt(pipenum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) bufnum = 4 + (pipenum - 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return bufnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) static u16 get_buf_bsize(u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) u16 buf_bsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (pipenum == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) buf_bsize = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) else if (check_bulk_or_isoc(pipenum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) buf_bsize = R8A66597_BUF_BSIZE - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) else if (check_interrupt(pipenum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) buf_bsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return buf_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) struct r8a66597_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) struct r8a66597_pipe *pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) struct r8a66597_pipe_info *info = &pipe->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) unsigned short mbw = mbw_value(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) /* pipe dma is only for external controlles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (r8a66597->pdata->on_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if ((r8a66597->dma_map & (1 << i)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) dev_info(&dev->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) "address %d, EndpointAddress 0x%02x use "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) "DMA FIFO\n", usb_pipedevice(urb->pipe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) info->dir_in ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) USB_ENDPOINT_DIR_MASK + info->epnum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) : info->epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) r8a66597->dma_map |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) dev->dma_map |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) set_pipe_reg_addr(pipe, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) cfifo_change(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) mbw | CURPIPE, pipe->fifosel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) pipe->info.pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) r8a66597_bset(r8a66597, BCLR, pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct usb_host_endpoint *hep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) struct r8a66597_pipe_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct r8a66597_pipe *pipe = hep->hcpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dev_dbg(&dev->udev->dev, "enable_pipe:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) pipe->info = *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) r8a66597->pipe_cnt[pipe->info.pipenum]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) dev->pipe_cnt[pipe->info.pipenum]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static void r8a66597_urb_done(struct r8a66597 *r8a66597, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) __releases(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) __acquires(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) void *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) for (ptr = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) ptr < urb->transfer_buffer + urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) ptr += PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) flush_dcache_page(virt_to_page(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) spin_unlock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) spin_lock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct r8a66597_td *td, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct list_head *list = &r8a66597->pipe_queue[pipenum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (list_empty(list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) list_for_each_entry_safe(td, next, list, queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (td->address != address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) list_del(&td->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) r8a66597_urb_done(r8a66597, urb, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct r8a66597_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) int check_ep0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (!dev->pipe_cnt[pipenum])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if (!check_ep0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) check_ep0 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) force_dequeue(r8a66597, 0, dev->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) dev->pipe_cnt[pipenum] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) force_dequeue(r8a66597, pipenum, dev->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) dev_dbg(&dev->udev->dev, "disable_pipe\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) r8a66597->dma_map &= ~(dev->dma_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) dev->dma_map = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static u16 get_interval(struct urb *urb, __u8 interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) u16 time = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (urb->dev->speed == USB_SPEED_HIGH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (interval > IITV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) time = IITV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) time = interval ? interval - 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (interval > 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) time = IITV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) /* calculate the nearest value for PIPEPERI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) for (i = 0; i < 7; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if ((1 << i) < interval &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) (1 << (i + 1) > interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) time = 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) __u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) unsigned long time = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (usb_pipeisoc(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) for (i = 0; i < (interval - 1); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) time *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) time = time * 125 / 1000; /* uSOF -> msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) time = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct usb_host_endpoint *hep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct usb_endpoint_descriptor *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct r8a66597_pipe_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) info.pipenum = get_empty_pipenum(r8a66597, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) info.epnum = usb_endpoint_num(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) info.maxpacket = usb_endpoint_maxp(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) info.type = get_r8a66597_type(usb_endpoint_type(ep));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) info.bufnum = get_bufnum(info.pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) info.buf_bsize = get_buf_bsize(info.pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (info.type == R8A66597_BULK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) info.interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) info.timer_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) info.interval = get_interval(urb, ep->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) info.timer_interval = get_timer_interval(urb, ep->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (usb_endpoint_dir_in(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) info.dir_in = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) info.dir_in = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) enable_r8a66597_pipe(r8a66597, urb, hep, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) dev->state = USB_STATE_CONFIGURED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (pipenum == 0 && usb_pipeout(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) enable_irq_empty(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) enable_irq_ready(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (!usb_pipeisoc(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) enable_irq_nrdy(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) disable_irq_ready(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) disable_irq_nrdy(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) mod_timer(&r8a66597->rh_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) int connect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) rh->scount = R8A66597_MAX_SAMPLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) if (connect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) rh->port |= USB_PORT_STAT_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) rh->port &= ~USB_PORT_STAT_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) rh->port |= USB_PORT_STAT_C_CONNECTION << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) r8a66597_root_hub_start_polling(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) u16 syssts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) __releases(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) __acquires(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (syssts == SE0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (syssts == FS_JSTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) else if (syssts == LS_JSTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) if (r8a66597->bus_suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) spin_unlock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) usb_hcd_poll_rh_status(r8a66597_to_hcd(r8a66597));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) spin_lock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) u16 speed = get_rh_usb_speed(r8a66597, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) rh->port &= ~(USB_PORT_STAT_HIGH_SPEED | USB_PORT_STAT_LOW_SPEED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (speed == HSMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) rh->port |= USB_PORT_STAT_HIGH_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) else if (speed == LSMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) rh->port |= USB_PORT_STAT_LOW_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) rh->port &= ~USB_PORT_STAT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) rh->port |= USB_PORT_STAT_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) struct r8a66597_device *dev = r8a66597->root_hub[port].dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) disable_r8a66597_pipe_all(r8a66597, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) free_usb_address(r8a66597, dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) start_root_hub_sampling(r8a66597, port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) static void prepare_setup_packet(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) __le16 *p = (__le16 *)td->urb->setup_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) unsigned long setup_addr = USBREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) DCPMAXP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) setup_addr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) r8a66597_write(r8a66597, SUREQ, DCPCTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) static void prepare_packet_read(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) struct urb *urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (usb_pipecontrol(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (urb->actual_length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) r8a66597_write(r8a66597, BCLR, CFIFOCTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) pipe_irq_disable(r8a66597, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) pipe_start(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) pipe_irq_enable(r8a66597, urb, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (urb->actual_length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) pipe_irq_disable(r8a66597, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) pipe_setting(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) if (td->pipe->pipetre) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) r8a66597_write(r8a66597, TRCLR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) td->pipe->pipetre);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) r8a66597_write(r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) DIV_ROUND_UP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) (urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) td->maxpacket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) td->pipe->pipetrn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) r8a66597_bset(r8a66597, TRENB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) td->pipe->pipetre);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) pipe_start(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) pipe_irq_enable(r8a66597, urb, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static void prepare_packet_write(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct urb *urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (usb_pipecontrol(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (urb->actual_length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) r8a66597_write(r8a66597, BCLR, CFIFOCTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if (urb->actual_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) pipe_setting(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (td->pipe->pipetre)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) fifo_change_from_pipe(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) if (unlikely((tmp & FRDY) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) pipe_irq_enable(r8a66597, urb, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) packet_write(r8a66597, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) pipe_start(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static void prepare_status_packet(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) struct urb *urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) enable_irq_empty(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) r8a66597_write(r8a66597, BCLR, CFIFOCTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) enable_irq_ready(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) enable_irq_nrdy(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) pipe_start(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static int is_set_address(unsigned char *setup_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) setup_packet[1] == USB_REQ_SET_ADDRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) BUG_ON(!td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) switch (td->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) case USB_PID_SETUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (is_set_address(td->urb->setup_packet)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) td->set_address = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) td->urb->setup_packet[2] = alloc_usb_address(r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) td->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (td->urb->setup_packet[2] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) prepare_setup_packet(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) case USB_PID_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) prepare_packet_read(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) case USB_PID_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) prepare_packet_write(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) case USB_PID_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) prepare_status_packet(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) printk(KERN_ERR "r8a66597: invalid type.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (usb_pipeisoc(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (urb->number_of_packets == td->iso_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) /* control or bulk or interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if ((urb->transfer_buffer_length <= urb->actual_length) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) (td->short_packet) || (td->zero_packet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) unsigned long time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) BUG_ON(!td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) r8a66597->timeout_map |= 1 << td->pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) switch (usb_pipetype(td->urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) case PIPE_INTERRUPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) case PIPE_ISOCHRONOUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) time = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) time = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) mod_timer(&r8a66597->timers[td->pipenum].td,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) jiffies + msecs_to_jiffies(time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) u16 pipenum, struct urb *urb, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) __releases(r8a66597->lock) __acquires(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) int restart = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) r8a66597->timeout_map &= ~(1 << pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (likely(td)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if (td->set_address && (status != 0 || urb->unlinked))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) r8a66597->address_map &= ~(1 << urb->setup_packet[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) pipe_toggle_save(r8a66597, td->pipe, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) list_del(&td->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (!list_empty(&r8a66597->pipe_queue[pipenum]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) restart = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (likely(urb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (usb_pipeisoc(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) urb->start_frame = r8a66597_get_frame(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) r8a66597_urb_done(r8a66597, urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (restart) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) start_transfer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) set_td_timer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) int rcv_len, bufsize, urb_len, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) u16 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) int finish = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) fifo_change_from_pipe(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) if (unlikely((tmp & FRDY) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) printk(KERN_ERR "r8a66597: in fifo not ready (%d)\n", pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) finish_request(r8a66597, td, pipenum, td->urb, -EPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) /* prepare parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) rcv_len = tmp & DTLN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (usb_pipeisoc(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) buf = (u16 *)(urb->transfer_buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) urb->iso_frame_desc[td->iso_cnt].offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) urb_len = urb->iso_frame_desc[td->iso_cnt].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) buf = (void *)urb->transfer_buffer + urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) urb_len = urb->transfer_buffer_length - urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) bufsize = min(urb_len, (int) td->maxpacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (rcv_len <= bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) size = rcv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) size = bufsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) status = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) finish = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) /* update parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) urb->actual_length += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (rcv_len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) td->zero_packet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (rcv_len < bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) td->short_packet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) if (usb_pipeisoc(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) urb->iso_frame_desc[td->iso_cnt].actual_length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) urb->iso_frame_desc[td->iso_cnt].status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) td->iso_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) finish = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) /* check transfer finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (finish || check_transfer_finish(td, urb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) finish = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) /* read fifo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) if (urb->transfer_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (finish && pipenum != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) finish_request(r8a66597, td, pipenum, urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) int bufsize, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) u16 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) fifo_change_from_pipe(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if (unlikely((tmp & FRDY) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) printk(KERN_ERR "r8a66597: out fifo not ready (%d)\n", pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) finish_request(r8a66597, td, pipenum, urb, -EPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) /* prepare parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) bufsize = td->maxpacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (usb_pipeisoc(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) buf = (u16 *)(urb->transfer_buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) urb->iso_frame_desc[td->iso_cnt].offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) size = min(bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) (int)urb->iso_frame_desc[td->iso_cnt].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) buf = (u16 *)(urb->transfer_buffer + urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) size = min_t(u32, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) urb->transfer_buffer_length - urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) /* write fifo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (pipenum > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (urb->transfer_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) r8a66597_write_fifo(r8a66597, td->pipe, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) /* update parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) urb->actual_length += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (usb_pipeisoc(urb->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) urb->iso_frame_desc[td->iso_cnt].actual_length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) urb->iso_frame_desc[td->iso_cnt].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) td->iso_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /* check transfer finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (check_transfer_finish(td, urb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) disable_irq_ready(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) enable_irq_empty(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (!usb_pipeisoc(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) enable_irq_nrdy(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) pipe_irq_enable(r8a66597, urb, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) static void check_next_phase(struct r8a66597 *r8a66597, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) u8 finish = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) switch (td->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) case USB_PID_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) case USB_PID_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) if (check_transfer_finish(td, urb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) td->type = USB_PID_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) case USB_PID_SETUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (urb->transfer_buffer_length == urb->actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) td->type = USB_PID_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) else if (usb_pipeout(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) td->type = USB_PID_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) td->type = USB_PID_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) case USB_PID_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) finish = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (finish || status != 0 || urb->unlinked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) finish_request(r8a66597, td, 0, urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) start_transfer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) if (pid == PID_NAK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) return -ECONNRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) static void irq_pipe_ready(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) u16 check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) u16 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) mask = r8a66597_read(r8a66597, BRDYSTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) & r8a66597_read(r8a66597, BRDYENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) r8a66597_write(r8a66597, ~mask, BRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) if (mask & BRDY0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) td = r8a66597_get_td(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) if (td && td->type == USB_PID_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) packet_read(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) pipe_irq_disable(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) check_next_phase(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) check = 1 << pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (mask & check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if (td->type == USB_PID_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) packet_read(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) else if (td->type == USB_PID_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) packet_write(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) static void irq_pipe_empty(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) u16 check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) u16 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) mask = r8a66597_read(r8a66597, BEMPSTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) & r8a66597_read(r8a66597, BEMPENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) r8a66597_write(r8a66597, ~mask, BEMPSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (mask & BEMP0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) cfifo_change(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) td = r8a66597_get_td(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) if (td && td->type != USB_PID_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) disable_irq_empty(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) check_next_phase(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) check = 1 << pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (mask & check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) tmp = r8a66597_read(r8a66597, td->pipe->pipectr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) if ((tmp & INBUFM) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) disable_irq_empty(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) finish_request(r8a66597, td, pipenum, td->urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) u16 check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) u16 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) mask = r8a66597_read(r8a66597, NRDYSTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) & r8a66597_read(r8a66597, NRDYENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) r8a66597_write(r8a66597, ~mask, NRDYSTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) if (mask & NRDY0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) cfifo_change(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) status = get_urb_error(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) pipe_irq_disable(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) check_next_phase(r8a66597, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) check = 1 << pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (mask & check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (unlikely(!td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) status = get_urb_error(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) finish_request(r8a66597, td, pipenum, td->urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) u16 intsts0, intsts1, intsts2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) u16 intenb0, intenb1, intenb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) u16 mask0, mask1, mask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) spin_lock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) intsts0 = r8a66597_read(r8a66597, INTSTS0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) intsts1 = r8a66597_read(r8a66597, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) intsts2 = r8a66597_read(r8a66597, INTSTS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) intenb0 = r8a66597_read(r8a66597, INTENB0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) intenb1 = r8a66597_read(r8a66597, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) intenb2 = r8a66597_read(r8a66597, INTENB2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) mask2 = intsts2 & intenb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) mask1 = intsts1 & intenb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) if (mask2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) if (mask2 & ATTCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) /* start usb bus sampling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) start_root_hub_sampling(r8a66597, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (mask2 & DTCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) r8a66597_write(r8a66597, ~DTCH, INTSTS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) r8a66597_bclr(r8a66597, DTCHE, INTENB2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) r8a66597_usb_disconnect(r8a66597, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) if (mask2 & BCHG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) r8a66597_write(r8a66597, ~BCHG, INTSTS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) r8a66597_bclr(r8a66597, BCHGE, INTENB2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) if (mask1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (mask1 & ATTCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* start usb bus sampling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) start_root_hub_sampling(r8a66597, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) if (mask1 & DTCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) r8a66597_write(r8a66597, ~DTCH, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) r8a66597_bclr(r8a66597, DTCHE, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) r8a66597_usb_disconnect(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (mask1 & BCHG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) r8a66597_write(r8a66597, ~BCHG, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) r8a66597_bclr(r8a66597, BCHGE, INTENB1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) if (mask1 & SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) r8a66597_write(r8a66597, ~SIGN, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) status = get_urb_error(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) check_next_phase(r8a66597, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) if (mask1 & SACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) r8a66597_write(r8a66597, ~SACK, INTSTS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) check_next_phase(r8a66597, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) if (mask0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) if (mask0 & BRDY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) irq_pipe_ready(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if (mask0 & BEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) irq_pipe_empty(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) if (mask0 & NRDY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) irq_pipe_nrdy(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) spin_unlock(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) if (rh->port & USB_PORT_STAT_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) unsigned long dvstctr_reg = get_dvstctr_reg(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) tmp = r8a66597_read(r8a66597, dvstctr_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) if ((tmp & USBRST) == USBRST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) r8a66597_mdfy(r8a66597, UACT, USBRST | UACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) dvstctr_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) r8a66597_root_hub_start_polling(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) r8a66597_usb_connect(r8a66597, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (!(rh->port & USB_PORT_STAT_CONNECTION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) if (rh->scount > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) if (tmp == rh->old_syssts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) rh->scount--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (rh->scount == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) r8a66597_check_syssts(r8a66597, port, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) r8a66597_root_hub_start_polling(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) rh->scount = R8A66597_MAX_SAMPLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) rh->old_syssts = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) r8a66597_root_hub_start_polling(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) static void r8a66597_interval_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct r8a66597_timers *timers = from_timer(timers, t, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) struct r8a66597 *r8a66597 = timers->r8a66597;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) if (!(r8a66597->interval_map & (1 << pipenum)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) if (timer_pending(&r8a66597->timers[pipenum].interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) start_transfer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) static void r8a66597_td_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) struct r8a66597_timers *timers = from_timer(timers, t, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) struct r8a66597 *r8a66597 = timers->r8a66597;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) struct r8a66597_td *td, *new_td = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) struct r8a66597_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) if (!(r8a66597->timeout_map & (1 << pipenum)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) if (timer_pending(&r8a66597->timers[pipenum].td))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) if (!td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) r8a66597->timeout_map &= ~(1 << pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if (td->urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) set_td_timer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) pipe = td->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) pipe_stop(r8a66597, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) /* Select a different address or endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) new_td = td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) list_move_tail(&new_td->queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) &r8a66597->pipe_queue[pipenum]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) new_td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) if (!new_td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) new_td = td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) } while (td != new_td && td->address == new_td->address &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) td->pipe->info.epnum == new_td->pipe->info.epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) start_transfer(r8a66597, new_td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) if (td == new_td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) r8a66597->timeout_map &= ~(1 << pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) set_td_timer(r8a66597, new_td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) static void r8a66597_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) struct r8a66597 *r8a66597 = from_timer(r8a66597, t, rh_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) for (port = 0; port < r8a66597->max_root_hub; port++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) r8a66597_root_hub_control(r8a66597, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (dev && dev->address && dev->state != USB_STATE_CONFIGURED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) (urb->dev->state == USB_STATE_CONFIGURED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static int r8a66597_start(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) hcd->state = HC_STATE_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) return enable_controller(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) static void r8a66597_stop(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) disable_controller(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) unsigned int usb_address = usb_pipedevice(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) u16 root_port, hub_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) if (usb_address == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) get_port_number(r8a66597, urb->dev->devpath,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) &root_port, &hub_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) set_devadd_reg(r8a66597, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) get_r8a66597_usb_speed(urb->dev->speed),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) get_parent_r8a66597_address(r8a66597, urb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) hub_port, root_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) struct usb_host_endpoint *hep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) if (td == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) pipenum = r8a66597_get_pipenum(urb, hep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) td->pipenum = pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) td->pipe = hep->hcpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) td->urb = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) td->address = get_urb_to_r8a66597_addr(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) td->maxpacket = usb_maxpacket(urb->dev, urb->pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) !usb_pipein(urb->pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) if (usb_pipecontrol(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) td->type = USB_PID_SETUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) else if (usb_pipein(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) td->type = USB_PID_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) td->type = USB_PID_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) INIT_LIST_HEAD(&td->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) return td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) gfp_t mem_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) struct usb_host_endpoint *hep = urb->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) struct r8a66597_td *td = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) int ret, request = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) goto error_not_linked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) ret = usb_hcd_link_urb_to_ep(hcd, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) goto error_not_linked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) if (!hep->hcpriv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (!hep->hcpriv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) if (usb_pipeendpoint(urb->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) init_pipe_info(r8a66597, urb, hep, &hep->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) if (unlikely(check_pipe_config(r8a66597, urb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) init_pipe_config(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) set_address_zero(r8a66597, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) td = r8a66597_make_td(r8a66597, urb, hep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) if (td == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) request = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) urb->hcpriv = td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) if (request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (td->pipe->info.timer_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) r8a66597->interval_map |= 1 << td->pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) mod_timer(&r8a66597->timers[td->pipenum].interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) jiffies + msecs_to_jiffies(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) td->pipe->info.timer_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) ret = start_transfer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) list_del(&td->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) set_td_timer(r8a66597, td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) usb_hcd_unlink_urb_from_ep(hcd, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) error_not_linked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) rc = usb_hcd_check_unlink_urb(hcd, urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) if (urb->hcpriv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) td = urb->hcpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) pipe_stop(r8a66597, td->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) pipe_irq_disable(r8a66597, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) disable_irq_empty(r8a66597, td->pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) finish_request(r8a66597, td, td->pipenum, urb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) struct usb_host_endpoint *hep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) __acquires(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) __releases(r8a66597->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) struct r8a66597_td *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) struct urb *urb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) u16 pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) if (pipe == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) pipenum = pipe->info.pipenum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) if (pipenum == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) kfree(hep->hcpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) hep->hcpriv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) pipe_stop(r8a66597, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) pipe_irq_disable(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) disable_irq_empty(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) td = r8a66597_get_td(r8a66597, pipenum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) if (td)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) urb = td->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) kfree(hep->hcpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) hep->hcpriv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) static int r8a66597_get_frame(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) int chix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) struct usb_device *childdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (udev->state == USB_STATE_CONFIGURED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) udev->parent && udev->parent->devnum > 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) map[udev->devnum/32] |= (1 << (udev->devnum % 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) usb_hub_for_each_child(udev, chix, childdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) collect_usb_address_map(childdev, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) /* this function must be called with interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) int addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) struct list_head *list = &r8a66597->child_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) list_for_each_entry(dev, list, device_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (dev->usb_address != addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) printk(KERN_ERR "r8a66597: get_r8a66597_device fail.(%d)\n", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) static void update_usb_address_map(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) struct usb_device *root_hub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) unsigned long *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) int i, j, addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) unsigned long diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) diff = r8a66597->child_connect_map[i] ^ map[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) if (!diff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) for (j = 0; j < 32; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) if (!(diff & (1 << j)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) addr = i * 32 + j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) if (map[i] & (1 << j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) set_child_connect_map(r8a66597, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) struct r8a66597_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) dev = get_r8a66597_device(r8a66597, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) disable_r8a66597_pipe_all(r8a66597, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) free_usb_address(r8a66597, dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) put_child_connect_map(r8a66597, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) static void r8a66597_check_detect_child(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) struct usb_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) unsigned long now_map[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) memset(now_map, 0, sizeof(now_map));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) mutex_lock(&usb_bus_idr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) bus = idr_find(&usb_bus_idr, hcd->self.busnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) if (bus && bus->root_hub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) collect_usb_address_map(bus->root_hub, now_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) update_usb_address_map(r8a66597, bus->root_hub, now_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) mutex_unlock(&usb_bus_idr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) r8a66597_check_detect_child(r8a66597, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) *buf = 0; /* initialize (no change) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) for (i = 0; i < r8a66597->max_root_hub; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) if (r8a66597->root_hub[i].port & 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) *buf |= 1 << (i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return (*buf != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) struct usb_hub_descriptor *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) desc->bDescriptorType = USB_DT_HUB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) desc->bHubContrCurrent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) desc->bNbrPorts = r8a66597->max_root_hub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) desc->bDescLength = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) desc->bPwrOn2PwrGood = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) desc->wHubCharacteristics =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_NO_OCPM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) desc->u.hs.DeviceRemovable[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) ((1 << r8a66597->max_root_hub) - 1) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) desc->u.hs.DeviceRemovable[1] = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) u16 wIndex, char *buf, u16 wLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) int port = (wIndex & 0x00FF) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) spin_lock_irqsave(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) switch (typeReq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) case ClearHubFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) case SetHubFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) case C_HUB_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) case C_HUB_LOCAL_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) case ClearPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) if (wIndex > r8a66597->max_root_hub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) if (wLength != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) case USB_PORT_FEAT_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) rh->port &= ~USB_PORT_STAT_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) r8a66597_port_power(r8a66597, port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) case USB_PORT_FEAT_C_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) case USB_PORT_FEAT_C_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) case USB_PORT_FEAT_C_CONNECTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) case USB_PORT_FEAT_C_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) case USB_PORT_FEAT_C_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) rh->port &= ~(1 << wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) case GetHubDescriptor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) r8a66597_hub_descriptor(r8a66597,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) (struct usb_hub_descriptor *)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) case GetHubStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) *buf = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) case GetPortStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (wIndex > r8a66597->max_root_hub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) *(__le32 *)buf = cpu_to_le32(rh->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) case SetPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) if (wIndex > r8a66597->max_root_hub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) if (wLength != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) r8a66597_port_power(r8a66597, port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) rh->port |= USB_PORT_STAT_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) case USB_PORT_FEAT_RESET: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) struct r8a66597_device *dev = rh->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) rh->port |= USB_PORT_STAT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) disable_r8a66597_pipe_all(r8a66597, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) free_usb_address(r8a66597, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) get_dvstctr_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) mod_timer(&r8a66597->rh_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) jiffies + msecs_to_jiffies(50));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) rh->port |= 1 << wValue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) ret = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) spin_unlock_irqrestore(&r8a66597->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) #if defined(CONFIG_PM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) static int r8a66597_bus_suspend(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) dev_dbg(&r8a66597->device0.udev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) for (port = 0; port < r8a66597->max_root_hub; port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) unsigned long dvstctr_reg = get_dvstctr_reg(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) if (!(rh->port & USB_PORT_STAT_ENABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) dev_dbg(&rh->dev->udev->dev, "suspend port = %d\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) rh->port |= USB_PORT_STAT_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) if (rh->dev->udev->do_remote_wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) msleep(3); /* waiting last SOF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) r8a66597_bset(r8a66597, RWUPE, dvstctr_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) r8a66597_write(r8a66597, ~BCHG, get_intsts_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) r8a66597_bset(r8a66597, BCHGE, get_intenb_reg(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) r8a66597->bus_suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) static int r8a66597_bus_resume(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) dev_dbg(&r8a66597->device0.udev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) for (port = 0; port < r8a66597->max_root_hub; port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) unsigned long dvstctr_reg = get_dvstctr_reg(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) if (!(rh->port & USB_PORT_STAT_SUSPEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) dev_dbg(&rh->dev->udev->dev, "resume port = %d\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) rh->port &= ~USB_PORT_STAT_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) rh->port |= USB_PORT_STAT_C_SUSPEND << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) msleep(USB_RESUME_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) #define r8a66597_bus_suspend NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) #define r8a66597_bus_resume NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) static const struct hc_driver r8a66597_hc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) .description = hcd_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) .hcd_priv_size = sizeof(struct r8a66597),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) .irq = r8a66597_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) * generic hardware linkage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) .flags = HCD_USB2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) .start = r8a66597_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) .stop = r8a66597_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * managing i/o requests and associated device resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) .urb_enqueue = r8a66597_urb_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) .urb_dequeue = r8a66597_urb_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) .endpoint_disable = r8a66597_endpoint_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) * periodic schedule support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) .get_frame_number = r8a66597_get_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) * root hub support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) .hub_status_data = r8a66597_hub_status_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) .hub_control = r8a66597_hub_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) .bus_suspend = r8a66597_bus_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) .bus_resume = r8a66597_bus_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) #if defined(CONFIG_PM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) static int r8a66597_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) struct r8a66597 *r8a66597 = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) disable_controller(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) for (port = 0; port < r8a66597->max_root_hub; port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) rh->port = 0x00000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) static int r8a66597_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) struct r8a66597 *r8a66597 = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) enable_controller(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) usb_root_hub_lost_power(hcd->self.root_hub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) static const struct dev_pm_ops r8a66597_dev_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) .suspend = r8a66597_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) .resume = r8a66597_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) .poweroff = r8a66597_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) .restore = r8a66597_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) #define R8A66597_DEV_PM_OPS (&r8a66597_dev_pm_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) #else /* if defined(CONFIG_PM) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) #define R8A66597_DEV_PM_OPS NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) static int r8a66597_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) struct r8a66597 *r8a66597 = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) del_timer_sync(&r8a66597->rh_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) iounmap(r8a66597->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) if (r8a66597->pdata->on_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) clk_put(r8a66597->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) static int r8a66597_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) char clk_name[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) struct resource *res = NULL, *ires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) int irq = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) void __iomem *reg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) struct usb_hcd *hcd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) struct r8a66597 *r8a66597;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) unsigned long irq_trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) dev_err(&pdev->dev, "platform_get_resource error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) if (!ires) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) "platform_get_resource IORESOURCE_IRQ error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) irq = ires->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) reg = ioremap(res->start, resource_size(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (reg == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) dev_err(&pdev->dev, "ioremap error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) if (pdev->dev.platform_data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) dev_err(&pdev->dev, "no platform data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) /* initialize hcd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) if (!hcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) dev_err(&pdev->dev, "Failed to create hcd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) goto clean_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) r8a66597 = hcd_to_r8a66597(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) memset(r8a66597, 0, sizeof(struct r8a66597));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) platform_set_drvdata(pdev, r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) r8a66597->pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) if (r8a66597->pdata->on_chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) r8a66597->clk = clk_get(&pdev->dev, clk_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (IS_ERR(r8a66597->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) clk_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) ret = PTR_ERR(r8a66597->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) goto clean_up2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) r8a66597->max_root_hub = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) r8a66597->max_root_hub = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) spin_lock_init(&r8a66597->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) timer_setup(&r8a66597->rh_timer, r8a66597_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) r8a66597->reg = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) /* make sure no interrupts are pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) ret = r8a66597_clock_enable(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) goto clean_up3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) disable_controller(r8a66597);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) INIT_LIST_HEAD(&r8a66597->pipe_queue[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) r8a66597->timers[i].r8a66597 = r8a66597;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) timer_setup(&r8a66597->timers[i].td, r8a66597_td_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) timer_setup(&r8a66597->timers[i].interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) r8a66597_interval_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) INIT_LIST_HEAD(&r8a66597->child_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) hcd->rsrc_start = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) hcd->has_tt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) ret = usb_add_hcd(hcd, irq, irq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) dev_err(&pdev->dev, "Failed to add hcd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) goto clean_up3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) clean_up3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) if (r8a66597->pdata->on_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) clk_put(r8a66597->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) clean_up2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) clean_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) if (reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) iounmap(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) static struct platform_driver r8a66597_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) .probe = r8a66597_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) .remove = r8a66597_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) .name = hcd_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) .pm = R8A66597_DEV_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) module_platform_driver(r8a66597_driver);