repo_name
string
path
string
copies
string
size
string
content
string
license
string
zparallax/amplitude_kernel_tw_exynos
drivers/tty/serial/sc26xx.c
2105
16843
/* * SC268xx.c: Serial driver for Philiphs SC2681/SC2692 devices. * * Copyright (C) 2006,2007 Thomas Bogendörfer (tsbogend@alpha.franken.de) */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/major.h> #include <linux/circ_buf.h> #include <linux/serial.h> #include <linux/sysrq.h> #include <linux/console.h> #include <linux/spinlock.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/irq.h> #include <linux/io.h> #warning "Please try migrate to use new driver SCCNXP and report the status" \ "in the linux-serial mailing list." #if defined(CONFIG_MAGIC_SYSRQ) #define SUPPORT_SYSRQ #endif #include <linux/serial_core.h> #define SC26XX_MAJOR 204 #define SC26XX_MINOR_START 205 #define SC26XX_NR 2 struct uart_sc26xx_port { struct uart_port port[2]; u8 dsr_mask[2]; u8 cts_mask[2]; u8 dcd_mask[2]; u8 ri_mask[2]; u8 dtr_mask[2]; u8 rts_mask[2]; u8 imr; }; /* register common to both ports */ #define RD_ISR 0x14 #define RD_IPR 0x34 #define WR_ACR 0x10 #define WR_IMR 0x14 #define WR_OPCR 0x34 #define WR_OPR_SET 0x38 #define WR_OPR_CLR 0x3C /* access common register */ #define READ_SC(p, r) readb((p)->membase + RD_##r) #define WRITE_SC(p, r, v) writeb((v), (p)->membase + WR_##r) /* register per port */ #define RD_PORT_MRx 0x00 #define RD_PORT_SR 0x04 #define RD_PORT_RHR 0x0c #define WR_PORT_MRx 0x00 #define WR_PORT_CSR 0x04 #define WR_PORT_CR 0x08 #define WR_PORT_THR 0x0c /* SR bits */ #define SR_BREAK (1 << 7) #define SR_FRAME (1 << 6) #define SR_PARITY (1 << 5) #define SR_OVERRUN (1 << 4) #define SR_TXRDY (1 << 2) #define SR_RXRDY (1 << 0) #define CR_RES_MR (1 << 4) #define CR_RES_RX (2 << 4) #define CR_RES_TX (3 << 4) #define CR_STRT_BRK (6 << 4) #define CR_STOP_BRK (7 << 4) #define CR_DIS_TX (1 << 3) #define CR_ENA_TX (1 << 2) #define CR_DIS_RX (1 << 1) #define CR_ENA_RX (1 << 0) /* ISR bits */ #define ISR_RXRDYB (1 << 5) #define ISR_TXRDYB (1 << 4) #define ISR_RXRDYA (1 << 1) #define ISR_TXRDYA (1 << 0) /* IMR bits */ #define IMR_RXRDY (1 << 1) #define IMR_TXRDY (1 << 0) /* access port register */ static inline u8 read_sc_port(struct uart_port *p, u8 reg) { return readb(p->membase + p->line * 0x20 + reg); } static inline void write_sc_port(struct uart_port *p, u8 reg, u8 val) { writeb(val, p->membase + p->line * 0x20 + reg); } #define READ_SC_PORT(p, r) read_sc_port(p, RD_PORT_##r) #define WRITE_SC_PORT(p, r, v) write_sc_port(p, WR_PORT_##r, v) static void sc26xx_enable_irq(struct uart_port *port, int mask) { struct uart_sc26xx_port *up; int line = port->line; port -= line; up = container_of(port, struct uart_sc26xx_port, port[0]); up->imr |= mask << (line * 4); WRITE_SC(port, IMR, up->imr); } static void sc26xx_disable_irq(struct uart_port *port, int mask) { struct uart_sc26xx_port *up; int line = port->line; port -= line; up = container_of(port, struct uart_sc26xx_port, port[0]); up->imr &= ~(mask << (line * 4)); WRITE_SC(port, IMR, up->imr); } static bool receive_chars(struct uart_port *port) { struct tty_port *tport = NULL; int limit = 10000; unsigned char ch; char flag; u8 status; /* FIXME what is this trying to achieve? */ if (port->state != NULL) /* Unopened serial console */ tport = &port->state->port; while (limit-- > 0) { status = READ_SC_PORT(port, SR); if (!(status & SR_RXRDY)) break; ch = READ_SC_PORT(port, RHR); flag = TTY_NORMAL; port->icount.rx++; if (unlikely(status & (SR_BREAK | SR_FRAME | SR_PARITY | SR_OVERRUN))) { if (status & SR_BREAK) { status &= ~(SR_PARITY | SR_FRAME); port->icount.brk++; if (uart_handle_break(port)) continue; } else if (status & SR_PARITY) port->icount.parity++; else if (status & SR_FRAME) port->icount.frame++; if (status & SR_OVERRUN) port->icount.overrun++; status &= port->read_status_mask; if (status & SR_BREAK) flag = TTY_BREAK; else if (status & SR_PARITY) flag = TTY_PARITY; else if (status & SR_FRAME) flag = TTY_FRAME; } if (uart_handle_sysrq_char(port, ch)) continue; if (status & port->ignore_status_mask) continue; tty_insert_flip_char(tport, ch, flag); } return !!tport; } static void transmit_chars(struct uart_port *port) { struct circ_buf *xmit; if (!port->state) return; xmit = &port->state->xmit; if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { sc26xx_disable_irq(port, IMR_TXRDY); return; } while (!uart_circ_empty(xmit)) { if (!(READ_SC_PORT(port, SR) & SR_TXRDY)) break; WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); port->icount.tx++; } if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(port); } static irqreturn_t sc26xx_interrupt(int irq, void *dev_id) { struct uart_sc26xx_port *up = dev_id; unsigned long flags; bool push; u8 isr; spin_lock_irqsave(&up->port[0].lock, flags); push = false; isr = READ_SC(&up->port[0], ISR); if (isr & ISR_TXRDYA) transmit_chars(&up->port[0]); if (isr & ISR_RXRDYA) push = receive_chars(&up->port[0]); spin_unlock(&up->port[0].lock); if (push) tty_flip_buffer_push(&up->port[0].state->port); spin_lock(&up->port[1].lock); push = false; if (isr & ISR_TXRDYB) transmit_chars(&up->port[1]); if (isr & ISR_RXRDYB) push = receive_chars(&up->port[1]); spin_unlock_irqrestore(&up->port[1].lock, flags); if (push) tty_flip_buffer_push(&up->port[1].state->port); return IRQ_HANDLED; } /* port->lock is not held. */ static unsigned int sc26xx_tx_empty(struct uart_port *port) { return (READ_SC_PORT(port, SR) & SR_TXRDY) ? TIOCSER_TEMT : 0; } /* port->lock held by caller. */ static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl) { struct uart_sc26xx_port *up; int line = port->line; port -= line; up = container_of(port, struct uart_sc26xx_port, port[0]); if (up->dtr_mask[line]) { if (mctrl & TIOCM_DTR) WRITE_SC(port, OPR_SET, up->dtr_mask[line]); else WRITE_SC(port, OPR_CLR, up->dtr_mask[line]); } if (up->rts_mask[line]) { if (mctrl & TIOCM_RTS) WRITE_SC(port, OPR_SET, up->rts_mask[line]); else WRITE_SC(port, OPR_CLR, up->rts_mask[line]); } } /* port->lock is held by caller and interrupts are disabled. */ static unsigned int sc26xx_get_mctrl(struct uart_port *port) { struct uart_sc26xx_port *up; int line = port->line; unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR; u8 ipr; port -= line; up = container_of(port, struct uart_sc26xx_port, port[0]); ipr = READ_SC(port, IPR) ^ 0xff; if (up->dsr_mask[line]) { mctrl &= ~TIOCM_DSR; mctrl |= ipr & up->dsr_mask[line] ? TIOCM_DSR : 0; } if (up->cts_mask[line]) { mctrl &= ~TIOCM_CTS; mctrl |= ipr & up->cts_mask[line] ? TIOCM_CTS : 0; } if (up->dcd_mask[line]) { mctrl &= ~TIOCM_CAR; mctrl |= ipr & up->dcd_mask[line] ? TIOCM_CAR : 0; } if (up->ri_mask[line]) { mctrl &= ~TIOCM_RNG; mctrl |= ipr & up->ri_mask[line] ? TIOCM_RNG : 0; } return mctrl; } /* port->lock held by caller. */ static void sc26xx_stop_tx(struct uart_port *port) { return; } /* port->lock held by caller. */ static void sc26xx_start_tx(struct uart_port *port) { struct circ_buf *xmit = &port->state->xmit; while (!uart_circ_empty(xmit)) { if (!(READ_SC_PORT(port, SR) & SR_TXRDY)) { sc26xx_enable_irq(port, IMR_TXRDY); break; } WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); port->icount.tx++; } } /* port->lock held by caller. */ static void sc26xx_stop_rx(struct uart_port *port) { } /* port->lock held by caller. */ static void sc26xx_enable_ms(struct uart_port *port) { } /* port->lock is not held. */ static void sc26xx_break_ctl(struct uart_port *port, int break_state) { if (break_state == -1) WRITE_SC_PORT(port, CR, CR_STRT_BRK); else WRITE_SC_PORT(port, CR, CR_STOP_BRK); } /* port->lock is not held. */ static int sc26xx_startup(struct uart_port *port) { sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY); WRITE_SC(port, OPCR, 0); /* reset tx and rx */ WRITE_SC_PORT(port, CR, CR_RES_RX); WRITE_SC_PORT(port, CR, CR_RES_TX); /* start rx/tx */ WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX); /* enable irqs */ sc26xx_enable_irq(port, IMR_RXRDY); return 0; } /* port->lock is not held. */ static void sc26xx_shutdown(struct uart_port *port) { /* disable interrupst */ sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY); /* stop tx/rx */ WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX); } /* port->lock is not held. */ static void sc26xx_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000); unsigned int quot = uart_get_divisor(port, baud); unsigned int iflag, cflag; unsigned long flags; u8 mr1, mr2, csr; spin_lock_irqsave(&port->lock, flags); while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc) udelay(2); WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX); iflag = termios->c_iflag; cflag = termios->c_cflag; port->read_status_mask = SR_OVERRUN; if (iflag & INPCK) port->read_status_mask |= SR_PARITY | SR_FRAME; if (iflag & (BRKINT | PARMRK)) port->read_status_mask |= SR_BREAK; port->ignore_status_mask = 0; if (iflag & IGNBRK) port->ignore_status_mask |= SR_BREAK; if ((cflag & CREAD) == 0) port->ignore_status_mask |= SR_BREAK | SR_FRAME | SR_PARITY | SR_OVERRUN; switch (cflag & CSIZE) { case CS5: mr1 = 0x00; break; case CS6: mr1 = 0x01; break; case CS7: mr1 = 0x02; break; default: case CS8: mr1 = 0x03; break; } mr2 = 0x07; if (cflag & CSTOPB) mr2 = 0x0f; if (cflag & PARENB) { if (cflag & PARODD) mr1 |= (1 << 2); } else mr1 |= (2 << 3); switch (baud) { case 50: csr = 0x00; break; case 110: csr = 0x11; break; case 134: csr = 0x22; break; case 200: csr = 0x33; break; case 300: csr = 0x44; break; case 600: csr = 0x55; break; case 1200: csr = 0x66; break; case 2400: csr = 0x88; break; case 4800: csr = 0x99; break; default: case 9600: csr = 0xbb; break; case 19200: csr = 0xcc; break; } WRITE_SC_PORT(port, CR, CR_RES_MR); WRITE_SC_PORT(port, MRx, mr1); WRITE_SC_PORT(port, MRx, mr2); WRITE_SC(port, ACR, 0x80); WRITE_SC_PORT(port, CSR, csr); /* reset tx and rx */ WRITE_SC_PORT(port, CR, CR_RES_RX); WRITE_SC_PORT(port, CR, CR_RES_TX); WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX); while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc) udelay(2); /* XXX */ uart_update_timeout(port, cflag, (port->uartclk / (16 * quot))); spin_unlock_irqrestore(&port->lock, flags); } static const char *sc26xx_type(struct uart_port *port) { return "SC26XX"; } static void sc26xx_release_port(struct uart_port *port) { } static int sc26xx_request_port(struct uart_port *port) { return 0; } static void sc26xx_config_port(struct uart_port *port, int flags) { } static int sc26xx_verify_port(struct uart_port *port, struct serial_struct *ser) { return -EINVAL; } static struct uart_ops sc26xx_ops = { .tx_empty = sc26xx_tx_empty, .set_mctrl = sc26xx_set_mctrl, .get_mctrl = sc26xx_get_mctrl, .stop_tx = sc26xx_stop_tx, .start_tx = sc26xx_start_tx, .stop_rx = sc26xx_stop_rx, .enable_ms = sc26xx_enable_ms, .break_ctl = sc26xx_break_ctl, .startup = sc26xx_startup, .shutdown = sc26xx_shutdown, .set_termios = sc26xx_set_termios, .type = sc26xx_type, .release_port = sc26xx_release_port, .request_port = sc26xx_request_port, .config_port = sc26xx_config_port, .verify_port = sc26xx_verify_port, }; static struct uart_port *sc26xx_port; #ifdef CONFIG_SERIAL_SC26XX_CONSOLE static void sc26xx_console_putchar(struct uart_port *port, char c) { unsigned long flags; int limit = 1000000; spin_lock_irqsave(&port->lock, flags); while (limit-- > 0) { if (READ_SC_PORT(port, SR) & SR_TXRDY) { WRITE_SC_PORT(port, THR, c); break; } udelay(2); } spin_unlock_irqrestore(&port->lock, flags); } static void sc26xx_console_write(struct console *con, const char *s, unsigned n) { struct uart_port *port = sc26xx_port; int i; for (i = 0; i < n; i++) { if (*s == '\n') sc26xx_console_putchar(port, '\r'); sc26xx_console_putchar(port, *s++); } } static int __init sc26xx_console_setup(struct console *con, char *options) { struct uart_port *port = sc26xx_port; int baud = 9600; int bits = 8; int parity = 'n'; int flow = 'n'; if (port->type != PORT_SC26XX) return -1; printk(KERN_INFO "Console: ttySC%d (SC26XX)\n", con->index); if (options) uart_parse_options(options, &baud, &parity, &bits, &flow); return uart_set_options(port, con, baud, parity, bits, flow); } static struct uart_driver sc26xx_reg; static struct console sc26xx_console = { .name = "ttySC", .write = sc26xx_console_write, .device = uart_console_device, .setup = sc26xx_console_setup, .flags = CON_PRINTBUFFER, .index = -1, .data = &sc26xx_reg, }; #define SC26XX_CONSOLE &sc26xx_console #else #define SC26XX_CONSOLE NULL #endif static struct uart_driver sc26xx_reg = { .owner = THIS_MODULE, .driver_name = "SC26xx", .dev_name = "ttySC", .major = SC26XX_MAJOR, .minor = SC26XX_MINOR_START, .nr = SC26XX_NR, .cons = SC26XX_CONSOLE, }; static u8 sc26xx_flags2mask(unsigned int flags, unsigned int bitpos) { unsigned int bit = (flags >> bitpos) & 15; return bit ? (1 << (bit - 1)) : 0; } static void sc26xx_init_masks(struct uart_sc26xx_port *up, int line, unsigned int data) { up->dtr_mask[line] = sc26xx_flags2mask(data, 0); up->rts_mask[line] = sc26xx_flags2mask(data, 4); up->dsr_mask[line] = sc26xx_flags2mask(data, 8); up->cts_mask[line] = sc26xx_flags2mask(data, 12); up->dcd_mask[line] = sc26xx_flags2mask(data, 16); up->ri_mask[line] = sc26xx_flags2mask(data, 20); } static int sc26xx_probe(struct platform_device *dev) { struct resource *res; struct uart_sc26xx_port *up; unsigned int *sc26xx_data = dev->dev.platform_data; int err; res = platform_get_resource(dev, IORESOURCE_MEM, 0); if (!res) return -ENODEV; up = kzalloc(sizeof *up, GFP_KERNEL); if (unlikely(!up)) return -ENOMEM; up->port[0].line = 0; up->port[0].ops = &sc26xx_ops; up->port[0].type = PORT_SC26XX; up->port[0].uartclk = (29491200 / 16); /* arbitrary */ up->port[0].mapbase = res->start; up->port[0].membase = ioremap_nocache(up->port[0].mapbase, 0x40); up->port[0].iotype = UPIO_MEM; up->port[0].irq = platform_get_irq(dev, 0); up->port[0].dev = &dev->dev; sc26xx_init_masks(up, 0, sc26xx_data[0]); sc26xx_port = &up->port[0]; up->port[1].line = 1; up->port[1].ops = &sc26xx_ops; up->port[1].type = PORT_SC26XX; up->port[1].uartclk = (29491200 / 16); /* arbitrary */ up->port[1].mapbase = up->port[0].mapbase; up->port[1].membase = up->port[0].membase; up->port[1].iotype = UPIO_MEM; up->port[1].irq = up->port[0].irq; up->port[1].dev = &dev->dev; sc26xx_init_masks(up, 1, sc26xx_data[1]); err = uart_register_driver(&sc26xx_reg); if (err) goto out_free_port; sc26xx_reg.tty_driver->name_base = sc26xx_reg.minor; err = uart_add_one_port(&sc26xx_reg, &up->port[0]); if (err) goto out_unregister_driver; err = uart_add_one_port(&sc26xx_reg, &up->port[1]); if (err) goto out_remove_port0; err = request_irq(up->port[0].irq, sc26xx_interrupt, 0, "sc26xx", up); if (err) goto out_remove_ports; dev_set_drvdata(&dev->dev, up); return 0; out_remove_ports: uart_remove_one_port(&sc26xx_reg, &up->port[1]); out_remove_port0: uart_remove_one_port(&sc26xx_reg, &up->port[0]); out_unregister_driver: uart_unregister_driver(&sc26xx_reg); out_free_port: kfree(up); sc26xx_port = NULL; return err; } static int __exit sc26xx_driver_remove(struct platform_device *dev) { struct uart_sc26xx_port *up = dev_get_drvdata(&dev->dev); free_irq(up->port[0].irq, up); uart_remove_one_port(&sc26xx_reg, &up->port[0]); uart_remove_one_port(&sc26xx_reg, &up->port[1]); uart_unregister_driver(&sc26xx_reg); kfree(up); sc26xx_port = NULL; dev_set_drvdata(&dev->dev, NULL); return 0; } static struct platform_driver sc26xx_driver = { .probe = sc26xx_probe, .remove = sc26xx_driver_remove, .driver = { .name = "SC26xx", .owner = THIS_MODULE, }, }; module_platform_driver(sc26xx_driver); MODULE_AUTHOR("Thomas Bogendörfer"); MODULE_DESCRIPTION("SC681/SC2692 serial driver"); MODULE_VERSION("1.0"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:SC26xx");
gpl-2.0
mdeejay/android_kernel_grouper
drivers/net/wireless/iwmc3200wifi/main.c
3897
21402
/* * Intel Wireless Multicomm 3200 WiFi driver * * Copyright (C) 2009 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * Intel Corporation <ilw@linux.intel.com> * Samuel Ortiz <samuel.ortiz@intel.com> * Zhu Yi <yi.zhu@intel.com> * */ #include <linux/kernel.h> #include <linux/netdevice.h> #include <linux/sched.h> #include <linux/ieee80211.h> #include <linux/wireless.h> #include <linux/slab.h> #include "iwm.h" #include "debug.h" #include "bus.h" #include "umac.h" #include "commands.h" #include "hal.h" #include "fw.h" #include "rx.h" static struct iwm_conf def_iwm_conf = { .sdio_ior_timeout = 5000, .calib_map = BIT(CALIB_CFG_DC_IDX) | BIT(CALIB_CFG_LO_IDX) | BIT(CALIB_CFG_TX_IQ_IDX) | BIT(CALIB_CFG_RX_IQ_IDX) | BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD), .expected_calib_map = BIT(PHY_CALIBRATE_DC_CMD) | BIT(PHY_CALIBRATE_LO_CMD) | BIT(PHY_CALIBRATE_TX_IQ_CMD) | BIT(PHY_CALIBRATE_RX_IQ_CMD) | BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD), .ct_kill_entry = 110, .ct_kill_exit = 110, .reset_on_fatal_err = 1, .auto_connect = 1, .enable_qos = 1, .mode = UMAC_MODE_BSS, /* UMAC configuration */ .power_index = 0, .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD, .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD, .cts_to_self = 0, .assoc_timeout = 2, .roam_timeout = 10, .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G | WIRELESS_MODE_11N, /* IBSS */ .ibss_band = UMAC_BAND_2GHZ, .ibss_channel = 1, .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03}, }; static int modparam_reset; module_param_named(reset, modparam_reset, bool, 0644); MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])"); static int modparam_wimax_enable = 1; module_param_named(wimax_enable, modparam_wimax_enable, bool, 0644); MODULE_PARM_DESC(wimax_enable, "Enable wimax core (default 1 [wimax enabled])"); int iwm_mode_to_nl80211_iftype(int mode) { switch (mode) { case UMAC_MODE_BSS: return NL80211_IFTYPE_STATION; case UMAC_MODE_IBSS: return NL80211_IFTYPE_ADHOC; default: return NL80211_IFTYPE_UNSPECIFIED; } return 0; } static void iwm_statistics_request(struct work_struct *work) { struct iwm_priv *iwm = container_of(work, struct iwm_priv, stats_request.work); iwm_send_umac_stats_req(iwm, 0); } static void iwm_disconnect_work(struct work_struct *work) { struct iwm_priv *iwm = container_of(work, struct iwm_priv, disconnect.work); if (iwm->umac_profile_active) iwm_invalidate_mlme_profile(iwm); clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status); iwm->umac_profile_active = 0; memset(iwm->bssid, 0, ETH_ALEN); iwm->channel = 0; iwm_link_off(iwm); wake_up_interruptible(&iwm->mlme_queue); cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL); } static void iwm_ct_kill_work(struct work_struct *work) { struct iwm_priv *iwm = container_of(work, struct iwm_priv, ct_kill_delay.work); struct wiphy *wiphy = iwm_to_wiphy(iwm); IWM_INFO(iwm, "CT kill delay timeout\n"); wiphy_rfkill_set_hw_state(wiphy, false); } static int __iwm_up(struct iwm_priv *iwm); static int __iwm_down(struct iwm_priv *iwm); static void iwm_reset_worker(struct work_struct *work) { struct iwm_priv *iwm; struct iwm_umac_profile *profile = NULL; int uninitialized_var(ret), retry = 0; iwm = container_of(work, struct iwm_priv, reset_worker); /* * XXX: The iwm->mutex is introduced purely for this reset work, * because the other users for iwm_up and iwm_down are only netdev * ndo_open and ndo_stop which are already protected by rtnl. * Please remove iwm->mutex together if iwm_reset_worker() is not * required in the future. */ if (!mutex_trylock(&iwm->mutex)) { IWM_WARN(iwm, "We are in the middle of interface bringing " "UP/DOWN. Skip driver resetting.\n"); return; } if (iwm->umac_profile_active) { profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL); if (profile) memcpy(profile, iwm->umac_profile, sizeof(*profile)); else IWM_ERR(iwm, "Couldn't alloc memory for profile\n"); } __iwm_down(iwm); while (retry++ < 3) { ret = __iwm_up(iwm); if (!ret) break; schedule_timeout_uninterruptible(10 * HZ); } if (ret) { IWM_WARN(iwm, "iwm_up() failed: %d\n", ret); kfree(profile); goto out; } if (profile) { IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n"); memcpy(iwm->umac_profile, profile, sizeof(*profile)); iwm_send_mlme_profile(iwm); kfree(profile); } else clear_bit(IWM_STATUS_RESETTING, &iwm->status); out: mutex_unlock(&iwm->mutex); } static void iwm_auth_retry_worker(struct work_struct *work) { struct iwm_priv *iwm; int i, ret; iwm = container_of(work, struct iwm_priv, auth_retry_worker); if (iwm->umac_profile_active) { ret = iwm_invalidate_mlme_profile(iwm); if (ret < 0) return; } iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK; ret = iwm_send_mlme_profile(iwm); if (ret < 0) return; for (i = 0; i < IWM_NUM_KEYS; i++) if (iwm->keys[i].key_len) iwm_set_key(iwm, 0, &iwm->keys[i]); iwm_set_tx_key(iwm, iwm->default_key); } static void iwm_watchdog(unsigned long data) { struct iwm_priv *iwm = (struct iwm_priv *)data; IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n"); if (modparam_reset) iwm_resetting(iwm); } int iwm_priv_init(struct iwm_priv *iwm) { int i, j; char name[32]; iwm->status = 0; INIT_LIST_HEAD(&iwm->pending_notif); init_waitqueue_head(&iwm->notif_queue); init_waitqueue_head(&iwm->nonwifi_queue); init_waitqueue_head(&iwm->wifi_ntfy_queue); init_waitqueue_head(&iwm->mlme_queue); memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf)); spin_lock_init(&iwm->tx_credit.lock); INIT_LIST_HEAD(&iwm->wifi_pending_cmd); INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd); iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE; iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE; spin_lock_init(&iwm->cmd_lock); iwm->scan_id = 1; INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request); INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work); INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work); INIT_WORK(&iwm->reset_worker, iwm_reset_worker); INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker); INIT_LIST_HEAD(&iwm->bss_list); skb_queue_head_init(&iwm->rx_list); INIT_LIST_HEAD(&iwm->rx_tickets); spin_lock_init(&iwm->ticket_lock); for (i = 0; i < IWM_RX_ID_HASH; i++) { INIT_LIST_HEAD(&iwm->rx_packets[i]); spin_lock_init(&iwm->packet_lock[i]); } INIT_WORK(&iwm->rx_worker, iwm_rx_worker); iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx"); if (!iwm->rx_wq) return -EAGAIN; for (i = 0; i < IWM_TX_QUEUES; i++) { INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker); snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i); iwm->txq[i].id = i; iwm->txq[i].wq = create_singlethread_workqueue(name); if (!iwm->txq[i].wq) return -EAGAIN; skb_queue_head_init(&iwm->txq[i].queue); skb_queue_head_init(&iwm->txq[i].stopped_queue); spin_lock_init(&iwm->txq[i].lock); } for (i = 0; i < IWM_NUM_KEYS; i++) memset(&iwm->keys[i], 0, sizeof(struct iwm_key)); iwm->default_key = -1; for (i = 0; i < IWM_STA_TABLE_NUM; i++) for (j = 0; j < IWM_UMAC_TID_NR; j++) { mutex_init(&iwm->sta_table[i].tid_info[j].mutex); iwm->sta_table[i].tid_info[j].stopped = false; } init_timer(&iwm->watchdog); iwm->watchdog.function = iwm_watchdog; iwm->watchdog.data = (unsigned long)iwm; mutex_init(&iwm->mutex); iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr), GFP_KERNEL); if (iwm->last_fw_err == NULL) return -ENOMEM; return 0; } void iwm_priv_deinit(struct iwm_priv *iwm) { int i; for (i = 0; i < IWM_TX_QUEUES; i++) destroy_workqueue(iwm->txq[i].wq); destroy_workqueue(iwm->rx_wq); kfree(iwm->last_fw_err); } /* * We reset all the structures, and we reset the UMAC. * After calling this routine, you're expected to reload * the firmware. */ void iwm_reset(struct iwm_priv *iwm) { struct iwm_notif *notif, *next; if (test_bit(IWM_STATUS_READY, &iwm->status)) iwm_target_reset(iwm); if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) { iwm->status = 0; set_bit(IWM_STATUS_RESETTING, &iwm->status); } else iwm->status = 0; iwm->scan_id = 1; list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) { list_del(&notif->pending); kfree(notif->buf); kfree(notif); } iwm_cmd_flush(iwm); flush_workqueue(iwm->rx_wq); iwm_link_off(iwm); } void iwm_resetting(struct iwm_priv *iwm) { set_bit(IWM_STATUS_RESETTING, &iwm->status); schedule_work(&iwm->reset_worker); } /* * Notification code: * * We're faced with the following issue: Any host command can * have an answer or not, and if there's an answer to expect, * it can be treated synchronously or asynchronously. * To work around the synchronous answer case, we implemented * our notification mechanism. * When a code path needs to wait for a command response * synchronously, it calls notif_handle(), which waits for the * right notification to show up, and then process it. Before * starting to wait, it registered as a waiter for this specific * answer (by toggling a bit in on of the handler_map), so that * the rx code knows that it needs to send a notification to the * waiting processes. It does so by calling iwm_notif_send(), * which adds the notification to the pending notifications list, * and then wakes the waiting processes up. */ int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd, u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size) { struct iwm_notif *notif; notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL); if (!notif) { IWM_ERR(iwm, "Couldn't alloc memory for notification\n"); return -ENOMEM; } INIT_LIST_HEAD(&notif->pending); notif->cmd = cmd; notif->cmd_id = cmd_id; notif->src = source; notif->buf = kzalloc(buf_size, GFP_KERNEL); if (!notif->buf) { IWM_ERR(iwm, "Couldn't alloc notification buffer\n"); kfree(notif); return -ENOMEM; } notif->buf_size = buf_size; memcpy(notif->buf, buf, buf_size); list_add_tail(&notif->pending, &iwm->pending_notif); wake_up_interruptible(&iwm->notif_queue); return 0; } static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd, u8 source) { struct iwm_notif *notif; list_for_each_entry(notif, &iwm->pending_notif, pending) { if ((notif->cmd_id == cmd) && (notif->src == source)) { list_del(&notif->pending); return notif; } } return NULL; } static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout) { int ret; struct iwm_notif *notif; unsigned long *map = NULL; switch (source) { case IWM_SRC_LMAC: map = &iwm->lmac_handler_map[0]; break; case IWM_SRC_UMAC: map = &iwm->umac_handler_map[0]; break; case IWM_SRC_UDMA: map = &iwm->udma_handler_map[0]; break; } set_bit(cmd, map); ret = wait_event_interruptible_timeout(iwm->notif_queue, ((notif = iwm_notif_find(iwm, cmd, source)) != NULL), timeout); clear_bit(cmd, map); if (!ret) return NULL; return notif; } int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout) { int ret; struct iwm_notif *notif; notif = iwm_notif_wait(iwm, cmd, source, timeout); if (!notif) return -ETIME; ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd); kfree(notif->buf); kfree(notif); return ret; } static int iwm_config_boot_params(struct iwm_priv *iwm) { struct iwm_udma_nonwifi_cmd target_cmd; int ret; /* check Wimax is off and config debug monitor */ if (!modparam_wimax_enable) { u32 data1 = 0x1f; u32 addr1 = 0x606BE258; u32 data2_set = 0x0; u32 data2_clr = 0x1; u32 addr2 = 0x606BE100; u32 data3 = 0x1; u32 addr3 = 0x606BEC00; target_cmd.resp = 0; target_cmd.handle_by_hw = 0; target_cmd.eop = 1; target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE; target_cmd.addr = cpu_to_le32(addr1); target_cmd.op1_sz = cpu_to_le32(sizeof(u32)); target_cmd.op2 = 0; ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1); if (ret < 0) { IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); return ret; } target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE; target_cmd.addr = cpu_to_le32(addr2); target_cmd.op1_sz = cpu_to_le32(data2_set); target_cmd.op2 = cpu_to_le32(data2_clr); ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1); if (ret < 0) { IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); return ret; } target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE; target_cmd.addr = cpu_to_le32(addr3); target_cmd.op1_sz = cpu_to_le32(sizeof(u32)); target_cmd.op2 = 0; ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3); if (ret < 0) { IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); return ret; } } return 0; } void iwm_init_default_profile(struct iwm_priv *iwm, struct iwm_umac_profile *profile) { memset(profile, 0, sizeof(struct iwm_umac_profile)); profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN; profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE; profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE; profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE; if (iwm->conf.enable_qos) profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED); profile->wireless_mode = iwm->conf.wireless_mode; profile->mode = cpu_to_le32(iwm->conf.mode); profile->ibss.atim = 0; profile->ibss.beacon_interval = 100; profile->ibss.join_only = 0; profile->ibss.band = iwm->conf.ibss_band; profile->ibss.channel = iwm->conf.ibss_channel; } void iwm_link_on(struct iwm_priv *iwm) { netif_carrier_on(iwm_to_ndev(iwm)); netif_tx_wake_all_queues(iwm_to_ndev(iwm)); iwm_send_umac_stats_req(iwm, 0); } void iwm_link_off(struct iwm_priv *iwm) { struct iw_statistics *wstats = &iwm->wstats; int i; netif_tx_stop_all_queues(iwm_to_ndev(iwm)); netif_carrier_off(iwm_to_ndev(iwm)); for (i = 0; i < IWM_TX_QUEUES; i++) { skb_queue_purge(&iwm->txq[i].queue); skb_queue_purge(&iwm->txq[i].stopped_queue); iwm->txq[i].concat_count = 0; iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf; flush_workqueue(iwm->txq[i].wq); } iwm_rx_free(iwm); cancel_delayed_work_sync(&iwm->stats_request); memset(wstats, 0, sizeof(struct iw_statistics)); wstats->qual.updated = IW_QUAL_ALL_INVALID; kfree(iwm->req_ie); iwm->req_ie = NULL; iwm->req_ie_len = 0; kfree(iwm->resp_ie); iwm->resp_ie = NULL; iwm->resp_ie_len = 0; del_timer_sync(&iwm->watchdog); } static void iwm_bss_list_clean(struct iwm_priv *iwm) { struct iwm_bss_info *bss, *next; list_for_each_entry_safe(bss, next, &iwm->bss_list, node) { list_del(&bss->node); kfree(bss->bss); kfree(bss); } } static int iwm_channels_init(struct iwm_priv *iwm) { int ret; ret = iwm_send_umac_channel_list(iwm); if (ret) { IWM_ERR(iwm, "Send channel list failed\n"); return ret; } ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST, IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); if (ret) { IWM_ERR(iwm, "Didn't get a channel list notification\n"); return ret; } return 0; } static int __iwm_up(struct iwm_priv *iwm) { int ret; struct iwm_notif *notif_reboot, *notif_ack = NULL; struct wiphy *wiphy = iwm_to_wiphy(iwm); u32 wireless_mode; ret = iwm_bus_enable(iwm); if (ret) { IWM_ERR(iwm, "Couldn't enable function\n"); return ret; } iwm_rx_setup_handlers(iwm); /* Wait for initial BARKER_REBOOT from hardware */ notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION, IWM_SRC_UDMA, 2 * HZ); if (!notif_reboot) { IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n"); goto err_disable; } /* We send the barker back */ ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16); if (ret) { IWM_ERR(iwm, "REBOOT barker response failed\n"); kfree(notif_reboot); goto err_disable; } kfree(notif_reboot->buf); kfree(notif_reboot); /* Wait for ACK_BARKER from hardware */ notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION, IWM_SRC_UDMA, 2 * HZ); if (!notif_ack) { IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n"); goto err_disable; } kfree(notif_ack->buf); kfree(notif_ack); /* We start to config static boot parameters */ ret = iwm_config_boot_params(iwm); if (ret) { IWM_ERR(iwm, "Config boot parameters failed\n"); goto err_disable; } ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr); if (ret) { IWM_ERR(iwm, "MAC reading failed\n"); goto err_disable; } memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr, ETH_ALEN); /* We can load the FWs */ ret = iwm_load_fw(iwm); if (ret) { IWM_ERR(iwm, "FW loading failed\n"); goto err_disable; } ret = iwm_eeprom_fat_channels(iwm); if (ret) { IWM_ERR(iwm, "Couldnt read HT channels EEPROM entries\n"); goto err_fw; } /* * Read our SKU capabilities. * If it's valid, we AND the configured wireless mode with the * device EEPROM value as the current profile wireless mode. */ wireless_mode = iwm_eeprom_wireless_mode(iwm); if (wireless_mode) { iwm->conf.wireless_mode &= wireless_mode; if (iwm->umac_profile) iwm->umac_profile->wireless_mode = iwm->conf.wireless_mode; } else IWM_ERR(iwm, "Wrong SKU capabilities: 0x%x\n", *((u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_SKU_CAP))); snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s", iwm->lmac_version, iwm->umac_version); /* We configure the UMAC and enable the wifi module */ ret = iwm_send_umac_config(iwm, cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) | cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) | cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN)); if (ret) { IWM_ERR(iwm, "UMAC config failed\n"); goto err_fw; } ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS, IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); if (ret) { IWM_ERR(iwm, "Didn't get a wifi core status notification\n"); goto err_fw; } if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN | UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) { IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n", iwm->core_enabled); ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS, IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); if (ret) { IWM_ERR(iwm, "Didn't get a core status notification\n"); goto err_fw; } if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN | UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) { IWM_ERR(iwm, "Not all cores enabled: 0x%x\n", iwm->core_enabled); goto err_fw; } else { IWM_INFO(iwm, "All cores enabled\n"); } } ret = iwm_channels_init(iwm); if (ret < 0) { IWM_ERR(iwm, "Couldn't init channels\n"); goto err_fw; } /* Set the READY bit to indicate interface is brought up successfully */ set_bit(IWM_STATUS_READY, &iwm->status); return 0; err_fw: iwm_eeprom_exit(iwm); err_disable: ret = iwm_bus_disable(iwm); if (ret < 0) IWM_ERR(iwm, "Couldn't disable function\n"); return -EIO; } int iwm_up(struct iwm_priv *iwm) { int ret; mutex_lock(&iwm->mutex); ret = __iwm_up(iwm); mutex_unlock(&iwm->mutex); return ret; } static int __iwm_down(struct iwm_priv *iwm) { int ret; /* The interface is already down */ if (!test_bit(IWM_STATUS_READY, &iwm->status)) return 0; if (iwm->scan_request) { cfg80211_scan_done(iwm->scan_request, true); iwm->scan_request = NULL; } clear_bit(IWM_STATUS_READY, &iwm->status); iwm_eeprom_exit(iwm); iwm_bss_list_clean(iwm); iwm_init_default_profile(iwm, iwm->umac_profile); iwm->umac_profile_active = false; iwm->default_key = -1; iwm->core_enabled = 0; ret = iwm_bus_disable(iwm); if (ret < 0) { IWM_ERR(iwm, "Couldn't disable function\n"); return ret; } return 0; } int iwm_down(struct iwm_priv *iwm) { int ret; mutex_lock(&iwm->mutex); ret = __iwm_down(iwm); mutex_unlock(&iwm->mutex); return ret; }
gpl-2.0
dewadg/mako-kernel
sound/atmel/ac97c.c
4665
31561
/* * Driver for Atmel AC97C * * Copyright (C) 2005-2009 Atmel Corporation * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */ #include <linux/clk.h> #include <linux/delay.h> #include <linux/bitmap.h> #include <linux/device.h> #include <linux/dmaengine.h> #include <linux/dma-mapping.h> #include <linux/atmel_pdc.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/mutex.h> #include <linux/gpio.h> #include <linux/types.h> #include <linux/io.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/ac97_codec.h> #include <sound/atmel-ac97c.h> #include <sound/memalloc.h> #include <linux/dw_dmac.h> #include <mach/cpu.h> #include <mach/gpio.h> #ifdef CONFIG_ARCH_AT91 #include <mach/hardware.h> #endif #include "ac97c.h" enum { DMA_TX_READY = 0, DMA_RX_READY, DMA_TX_CHAN_PRESENT, DMA_RX_CHAN_PRESENT, }; /* Serialize access to opened variable */ static DEFINE_MUTEX(opened_mutex); struct atmel_ac97c_dma { struct dma_chan *rx_chan; struct dma_chan *tx_chan; }; struct atmel_ac97c { struct clk *pclk; struct platform_device *pdev; struct atmel_ac97c_dma dma; struct snd_pcm_substream *playback_substream; struct snd_pcm_substream *capture_substream; struct snd_card *card; struct snd_pcm *pcm; struct snd_ac97 *ac97; struct snd_ac97_bus *ac97_bus; u64 cur_format; unsigned int cur_rate; unsigned long flags; int playback_period, capture_period; /* Serialize access to opened variable */ spinlock_t lock; void __iomem *regs; int irq; int opened; int reset_pin; }; #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data) #define ac97c_writel(chip, reg, val) \ __raw_writel((val), (chip)->regs + AC97C_##reg) #define ac97c_readl(chip, reg) \ __raw_readl((chip)->regs + AC97C_##reg) /* This function is called by the DMA driver. */ static void atmel_ac97c_dma_playback_period_done(void *arg) { struct atmel_ac97c *chip = arg; snd_pcm_period_elapsed(chip->playback_substream); } static void atmel_ac97c_dma_capture_period_done(void *arg) { struct atmel_ac97c *chip = arg; snd_pcm_period_elapsed(chip->capture_substream); } static int atmel_ac97c_prepare_dma(struct atmel_ac97c *chip, struct snd_pcm_substream *substream, enum dma_transfer_direction direction) { struct dma_chan *chan; struct dw_cyclic_desc *cdesc; struct snd_pcm_runtime *runtime = substream->runtime; unsigned long buffer_len, period_len; /* * We don't do DMA on "complex" transfers, i.e. with * non-halfword-aligned buffers or lengths. */ if (runtime->dma_addr & 1 || runtime->buffer_size & 1) { dev_dbg(&chip->pdev->dev, "too complex transfer\n"); return -EINVAL; } if (direction == DMA_MEM_TO_DEV) chan = chip->dma.tx_chan; else chan = chip->dma.rx_chan; buffer_len = frames_to_bytes(runtime, runtime->buffer_size); period_len = frames_to_bytes(runtime, runtime->period_size); cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len, period_len, direction); if (IS_ERR(cdesc)) { dev_dbg(&chip->pdev->dev, "could not prepare cyclic DMA\n"); return PTR_ERR(cdesc); } if (direction == DMA_MEM_TO_DEV) { cdesc->period_callback = atmel_ac97c_dma_playback_period_done; set_bit(DMA_TX_READY, &chip->flags); } else { cdesc->period_callback = atmel_ac97c_dma_capture_period_done; set_bit(DMA_RX_READY, &chip->flags); } cdesc->period_callback_param = chip; return 0; } static struct snd_pcm_hardware atmel_ac97c_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_JOINT_DUPLEX | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_PAUSE), .formats = (SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_LE), .rates = (SNDRV_PCM_RATE_CONTINUOUS), .rate_min = 4000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = 2 * 2 * 64 * 2048, .period_bytes_min = 4096, .period_bytes_max = 4096, .periods_min = 6, .periods_max = 64, }; static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; mutex_lock(&opened_mutex); chip->opened++; runtime->hw = atmel_ac97c_hw; if (chip->cur_rate) { runtime->hw.rate_min = chip->cur_rate; runtime->hw.rate_max = chip->cur_rate; } if (chip->cur_format) runtime->hw.formats = (1ULL << chip->cur_format); mutex_unlock(&opened_mutex); chip->playback_substream = substream; return 0; } static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; mutex_lock(&opened_mutex); chip->opened++; runtime->hw = atmel_ac97c_hw; if (chip->cur_rate) { runtime->hw.rate_min = chip->cur_rate; runtime->hw.rate_max = chip->cur_rate; } if (chip->cur_format) runtime->hw.formats = (1ULL << chip->cur_format); mutex_unlock(&opened_mutex); chip->capture_substream = substream; return 0; } static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); mutex_lock(&opened_mutex); chip->opened--; if (!chip->opened) { chip->cur_rate = 0; chip->cur_format = 0; } mutex_unlock(&opened_mutex); chip->playback_substream = NULL; return 0; } static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); mutex_lock(&opened_mutex); chip->opened--; if (!chip->opened) { chip->cur_rate = 0; chip->cur_format = 0; } mutex_unlock(&opened_mutex); chip->capture_substream = NULL; return 0; } static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); int retval; retval = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (retval < 0) return retval; /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */ if (cpu_is_at32ap7000()) { /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */ if (retval == 1) if (test_and_clear_bit(DMA_TX_READY, &chip->flags)) dw_dma_cyclic_free(chip->dma.tx_chan); } /* Set restrictions to params. */ mutex_lock(&opened_mutex); chip->cur_rate = params_rate(hw_params); chip->cur_format = params_format(hw_params); mutex_unlock(&opened_mutex); return retval; } static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); int retval; retval = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (retval < 0) return retval; /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */ if (cpu_is_at32ap7000()) { if (retval < 0) return retval; /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */ if (retval == 1) if (test_and_clear_bit(DMA_RX_READY, &chip->flags)) dw_dma_cyclic_free(chip->dma.rx_chan); } /* Set restrictions to params. */ mutex_lock(&opened_mutex); chip->cur_rate = params_rate(hw_params); chip->cur_format = params_format(hw_params); mutex_unlock(&opened_mutex); return retval; } static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); if (cpu_is_at32ap7000()) { if (test_and_clear_bit(DMA_TX_READY, &chip->flags)) dw_dma_cyclic_free(chip->dma.tx_chan); } return snd_pcm_lib_free_pages(substream); } static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); if (cpu_is_at32ap7000()) { if (test_and_clear_bit(DMA_RX_READY, &chip->flags)) dw_dma_cyclic_free(chip->dma.rx_chan); } return snd_pcm_lib_free_pages(substream); } static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int block_size = frames_to_bytes(runtime, runtime->period_size); unsigned long word = ac97c_readl(chip, OCA); int retval; chip->playback_period = 0; word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT)); /* assign channels to AC97C channel A */ switch (runtime->channels) { case 1: word |= AC97C_CH_ASSIGN(PCM_LEFT, A); break; case 2: word |= AC97C_CH_ASSIGN(PCM_LEFT, A) | AC97C_CH_ASSIGN(PCM_RIGHT, A); break; default: /* TODO: support more than two channels */ return -EINVAL; } ac97c_writel(chip, OCA, word); /* configure sample format and size */ word = ac97c_readl(chip, CAMR); if (chip->opened <= 1) word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16; else word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16; switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: if (cpu_is_at32ap7000()) word |= AC97C_CMR_CEM_LITTLE; break; case SNDRV_PCM_FORMAT_S16_BE: /* fall through */ word &= ~(AC97C_CMR_CEM_LITTLE); break; default: word = ac97c_readl(chip, OCA); word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT)); ac97c_writel(chip, OCA, word); return -EINVAL; } /* Enable underrun interrupt on channel A */ word |= AC97C_CSR_UNRUN; ac97c_writel(chip, CAMR, word); /* Enable channel A event interrupt */ word = ac97c_readl(chip, IMR); word |= AC97C_SR_CAEVT; ac97c_writel(chip, IER, word); /* set variable rate if needed */ if (runtime->rate != 48000) { word = ac97c_readl(chip, MR); word |= AC97C_MR_VRA; ac97c_writel(chip, MR, word); } else { word = ac97c_readl(chip, MR); word &= ~(AC97C_MR_VRA); ac97c_writel(chip, MR, word); } retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); if (retval) dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", runtime->rate); if (cpu_is_at32ap7000()) { if (!test_bit(DMA_TX_READY, &chip->flags)) retval = atmel_ac97c_prepare_dma(chip, substream, DMA_MEM_TO_DEV); } else { /* Initialize and start the PDC */ writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR); writel(block_size / 2, chip->regs + ATMEL_PDC_TCR); writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR); writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR); } return retval; } static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int block_size = frames_to_bytes(runtime, runtime->period_size); unsigned long word = ac97c_readl(chip, ICA); int retval; chip->capture_period = 0; word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT)); /* assign channels to AC97C channel A */ switch (runtime->channels) { case 1: word |= AC97C_CH_ASSIGN(PCM_LEFT, A); break; case 2: word |= AC97C_CH_ASSIGN(PCM_LEFT, A) | AC97C_CH_ASSIGN(PCM_RIGHT, A); break; default: /* TODO: support more than two channels */ return -EINVAL; } ac97c_writel(chip, ICA, word); /* configure sample format and size */ word = ac97c_readl(chip, CAMR); if (chip->opened <= 1) word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16; else word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16; switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: if (cpu_is_at32ap7000()) word |= AC97C_CMR_CEM_LITTLE; break; case SNDRV_PCM_FORMAT_S16_BE: /* fall through */ word &= ~(AC97C_CMR_CEM_LITTLE); break; default: word = ac97c_readl(chip, ICA); word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT)); ac97c_writel(chip, ICA, word); return -EINVAL; } /* Enable overrun interrupt on channel A */ word |= AC97C_CSR_OVRUN; ac97c_writel(chip, CAMR, word); /* Enable channel A event interrupt */ word = ac97c_readl(chip, IMR); word |= AC97C_SR_CAEVT; ac97c_writel(chip, IER, word); /* set variable rate if needed */ if (runtime->rate != 48000) { word = ac97c_readl(chip, MR); word |= AC97C_MR_VRA; ac97c_writel(chip, MR, word); } else { word = ac97c_readl(chip, MR); word &= ~(AC97C_MR_VRA); ac97c_writel(chip, MR, word); } retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); if (retval) dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", runtime->rate); if (cpu_is_at32ap7000()) { if (!test_bit(DMA_RX_READY, &chip->flags)) retval = atmel_ac97c_prepare_dma(chip, substream, DMA_DEV_TO_MEM); } else { /* Initialize and start the PDC */ writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR); writel(block_size / 2, chip->regs + ATMEL_PDC_RCR); writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR); writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR); } return retval; } static int atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); unsigned long camr, ptcr = 0; int retval = 0; camr = ac97c_readl(chip, CAMR); switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */ case SNDRV_PCM_TRIGGER_RESUME: /* fall through */ case SNDRV_PCM_TRIGGER_START: if (cpu_is_at32ap7000()) { retval = dw_dma_cyclic_start(chip->dma.tx_chan); if (retval) goto out; } else { ptcr = ATMEL_PDC_TXTEN; } camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */ case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */ case SNDRV_PCM_TRIGGER_STOP: if (cpu_is_at32ap7000()) dw_dma_cyclic_stop(chip->dma.tx_chan); else ptcr |= ATMEL_PDC_TXTDIS; if (chip->opened <= 1) camr &= ~AC97C_CMR_CENA; break; default: retval = -EINVAL; goto out; } ac97c_writel(chip, CAMR, camr); if (!cpu_is_at32ap7000()) writel(ptcr, chip->regs + ATMEL_PDC_PTCR); out: return retval; } static int atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); unsigned long camr, ptcr = 0; int retval = 0; camr = ac97c_readl(chip, CAMR); ptcr = readl(chip->regs + ATMEL_PDC_PTSR); switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */ case SNDRV_PCM_TRIGGER_RESUME: /* fall through */ case SNDRV_PCM_TRIGGER_START: if (cpu_is_at32ap7000()) { retval = dw_dma_cyclic_start(chip->dma.rx_chan); if (retval) goto out; } else { ptcr = ATMEL_PDC_RXTEN; } camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */ case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */ case SNDRV_PCM_TRIGGER_STOP: if (cpu_is_at32ap7000()) dw_dma_cyclic_stop(chip->dma.rx_chan); else ptcr |= (ATMEL_PDC_RXTDIS); if (chip->opened <= 1) camr &= ~AC97C_CMR_CENA; break; default: retval = -EINVAL; break; } ac97c_writel(chip, CAMR, camr); if (!cpu_is_at32ap7000()) writel(ptcr, chip->regs + ATMEL_PDC_PTCR); out: return retval; } static snd_pcm_uframes_t atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t frames; unsigned long bytes; if (cpu_is_at32ap7000()) bytes = dw_dma_get_src_addr(chip->dma.tx_chan); else bytes = readl(chip->regs + ATMEL_PDC_TPR); bytes -= runtime->dma_addr; frames = bytes_to_frames(runtime, bytes); if (frames >= runtime->buffer_size) frames -= runtime->buffer_size; return frames; } static snd_pcm_uframes_t atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream) { struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t frames; unsigned long bytes; if (cpu_is_at32ap7000()) bytes = dw_dma_get_dst_addr(chip->dma.rx_chan); else bytes = readl(chip->regs + ATMEL_PDC_RPR); bytes -= runtime->dma_addr; frames = bytes_to_frames(runtime, bytes); if (frames >= runtime->buffer_size) frames -= runtime->buffer_size; return frames; } static struct snd_pcm_ops atmel_ac97_playback_ops = { .open = atmel_ac97c_playback_open, .close = atmel_ac97c_playback_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = atmel_ac97c_playback_hw_params, .hw_free = atmel_ac97c_playback_hw_free, .prepare = atmel_ac97c_playback_prepare, .trigger = atmel_ac97c_playback_trigger, .pointer = atmel_ac97c_playback_pointer, }; static struct snd_pcm_ops atmel_ac97_capture_ops = { .open = atmel_ac97c_capture_open, .close = atmel_ac97c_capture_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = atmel_ac97c_capture_hw_params, .hw_free = atmel_ac97c_capture_hw_free, .prepare = atmel_ac97c_capture_prepare, .trigger = atmel_ac97c_capture_trigger, .pointer = atmel_ac97c_capture_pointer, }; static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev) { struct atmel_ac97c *chip = (struct atmel_ac97c *)dev; irqreturn_t retval = IRQ_NONE; u32 sr = ac97c_readl(chip, SR); u32 casr = ac97c_readl(chip, CASR); u32 cosr = ac97c_readl(chip, COSR); u32 camr = ac97c_readl(chip, CAMR); if (sr & AC97C_SR_CAEVT) { struct snd_pcm_runtime *runtime; int offset, next_period, block_size; dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n", casr & AC97C_CSR_OVRUN ? " OVRUN" : "", casr & AC97C_CSR_RXRDY ? " RXRDY" : "", casr & AC97C_CSR_UNRUN ? " UNRUN" : "", casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "", casr & AC97C_CSR_TXRDY ? " TXRDY" : "", !casr ? " NONE" : ""); if (!cpu_is_at32ap7000()) { if ((casr & camr) & AC97C_CSR_ENDTX) { runtime = chip->playback_substream->runtime; block_size = frames_to_bytes(runtime, runtime->period_size); chip->playback_period++; if (chip->playback_period == runtime->periods) chip->playback_period = 0; next_period = chip->playback_period + 1; if (next_period == runtime->periods) next_period = 0; offset = block_size * next_period; writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR); writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR); snd_pcm_period_elapsed( chip->playback_substream); } if ((casr & camr) & AC97C_CSR_ENDRX) { runtime = chip->capture_substream->runtime; block_size = frames_to_bytes(runtime, runtime->period_size); chip->capture_period++; if (chip->capture_period == runtime->periods) chip->capture_period = 0; next_period = chip->capture_period + 1; if (next_period == runtime->periods) next_period = 0; offset = block_size * next_period; writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR); writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR); snd_pcm_period_elapsed(chip->capture_substream); } } retval = IRQ_HANDLED; } if (sr & AC97C_SR_COEVT) { dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n", cosr & AC97C_CSR_OVRUN ? " OVRUN" : "", cosr & AC97C_CSR_RXRDY ? " RXRDY" : "", cosr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "", cosr & AC97C_CSR_TXRDY ? " TXRDY" : "", !cosr ? " NONE" : ""); retval = IRQ_HANDLED; } if (retval == IRQ_NONE) { dev_err(&chip->pdev->dev, "spurious interrupt sr 0x%08x " "casr 0x%08x cosr 0x%08x\n", sr, casr, cosr); } return retval; } static struct ac97_pcm at91_ac97_pcm_defs[] __devinitdata = { /* Playback */ { .exclusive = 1, .r = { { .slots = ((1 << AC97_SLOT_PCM_LEFT) | (1 << AC97_SLOT_PCM_RIGHT)), } }, }, /* PCM in */ { .stream = 1, .exclusive = 1, .r = { { .slots = ((1 << AC97_SLOT_PCM_LEFT) | (1 << AC97_SLOT_PCM_RIGHT)), } } }, /* Mic in */ { .stream = 1, .exclusive = 1, .r = { { .slots = (1<<AC97_SLOT_MIC), } } }, }; static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip) { struct snd_pcm *pcm; struct snd_pcm_hardware hw = atmel_ac97c_hw; int capture, playback, retval, err; capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags); playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags); if (!cpu_is_at32ap7000()) { err = snd_ac97_pcm_assign(chip->ac97_bus, ARRAY_SIZE(at91_ac97_pcm_defs), at91_ac97_pcm_defs); if (err) return err; } retval = snd_pcm_new(chip->card, chip->card->shortname, chip->pdev->id, playback, capture, &pcm); if (retval) return retval; if (capture) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &atmel_ac97_capture_ops); if (playback) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_ac97_playback_ops); retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pdev->dev, hw.periods_min * hw.period_bytes_min, hw.buffer_bytes_max); if (retval) return retval; pcm->private_data = chip; pcm->info_flags = 0; strcpy(pcm->name, chip->card->shortname); chip->pcm = pcm; return 0; } static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip) { struct snd_ac97_template template; memset(&template, 0, sizeof(template)); template.private_data = chip; return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97); } static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { struct atmel_ac97c *chip = get_chip(ac97); unsigned long word; int timeout = 40; word = (reg & 0x7f) << 16 | val; do { if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) { ac97c_writel(chip, COTHR, word); return; } udelay(1); } while (--timeout); dev_dbg(&chip->pdev->dev, "codec write timeout\n"); } static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97, unsigned short reg) { struct atmel_ac97c *chip = get_chip(ac97); unsigned long word; int timeout = 40; int write = 10; word = (0x80 | (reg & 0x7f)) << 16; if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) ac97c_readl(chip, CORHR); retry_write: timeout = 40; do { if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) { ac97c_writel(chip, COTHR, word); goto read_reg; } udelay(10); } while (--timeout); if (!--write) goto timed_out; goto retry_write; read_reg: do { if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) { unsigned short val = ac97c_readl(chip, CORHR); return val; } udelay(10); } while (--timeout); if (!--write) goto timed_out; goto retry_write; timed_out: dev_dbg(&chip->pdev->dev, "codec read timeout\n"); return 0xffff; } static bool filter(struct dma_chan *chan, void *slave) { struct dw_dma_slave *dws = slave; if (dws->dma_dev == chan->device->dev) { chan->private = dws; return true; } else return false; } static void atmel_ac97c_reset(struct atmel_ac97c *chip) { ac97c_writel(chip, MR, 0); ac97c_writel(chip, MR, AC97C_MR_ENA); ac97c_writel(chip, CAMR, 0); ac97c_writel(chip, COMR, 0); if (gpio_is_valid(chip->reset_pin)) { gpio_set_value(chip->reset_pin, 0); /* AC97 v2.2 specifications says minimum 1 us. */ udelay(2); gpio_set_value(chip->reset_pin, 1); } else { ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA); udelay(2); ac97c_writel(chip, MR, AC97C_MR_ENA); } } static int __devinit atmel_ac97c_probe(struct platform_device *pdev) { struct snd_card *card; struct atmel_ac97c *chip; struct resource *regs; struct ac97c_platform_data *pdata; struct clk *pclk; static struct snd_ac97_bus_ops ops = { .write = atmel_ac97c_write, .read = atmel_ac97c_read, }; int retval; int irq; regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!regs) { dev_dbg(&pdev->dev, "no memory resource\n"); return -ENXIO; } pdata = pdev->dev.platform_data; if (!pdata) { dev_dbg(&pdev->dev, "no platform data\n"); return -ENXIO; } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_dbg(&pdev->dev, "could not get irq\n"); return -ENXIO; } if (cpu_is_at32ap7000()) { pclk = clk_get(&pdev->dev, "pclk"); } else { pclk = clk_get(&pdev->dev, "ac97_clk"); } if (IS_ERR(pclk)) { dev_dbg(&pdev->dev, "no peripheral clock\n"); return PTR_ERR(pclk); } clk_enable(pclk); retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, THIS_MODULE, sizeof(struct atmel_ac97c), &card); if (retval) { dev_dbg(&pdev->dev, "could not create sound card device\n"); goto err_snd_card_new; } chip = get_chip(card); retval = request_irq(irq, atmel_ac97c_interrupt, 0, "AC97C", chip); if (retval) { dev_dbg(&pdev->dev, "unable to request irq %d\n", irq); goto err_request_irq; } chip->irq = irq; spin_lock_init(&chip->lock); strcpy(card->driver, "Atmel AC97C"); strcpy(card->shortname, "Atmel AC97C"); sprintf(card->longname, "Atmel AC97 controller"); chip->card = card; chip->pclk = pclk; chip->pdev = pdev; chip->regs = ioremap(regs->start, resource_size(regs)); if (!chip->regs) { dev_dbg(&pdev->dev, "could not remap register memory\n"); goto err_ioremap; } if (gpio_is_valid(pdata->reset_pin)) { if (gpio_request(pdata->reset_pin, "reset_pin")) { dev_dbg(&pdev->dev, "reset pin not available\n"); chip->reset_pin = -ENODEV; } else { gpio_direction_output(pdata->reset_pin, 1); chip->reset_pin = pdata->reset_pin; } } snd_card_set_dev(card, &pdev->dev); atmel_ac97c_reset(chip); /* Enable overrun interrupt from codec channel */ ac97c_writel(chip, COMR, AC97C_CSR_OVRUN); ac97c_writel(chip, IER, ac97c_readl(chip, IMR) | AC97C_SR_COEVT); retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus); if (retval) { dev_dbg(&pdev->dev, "could not register on ac97 bus\n"); goto err_ac97_bus; } retval = atmel_ac97c_mixer_new(chip); if (retval) { dev_dbg(&pdev->dev, "could not register ac97 mixer\n"); goto err_ac97_bus; } if (cpu_is_at32ap7000()) { if (pdata->rx_dws.dma_dev) { dma_cap_mask_t mask; dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); chip->dma.rx_chan = dma_request_channel(mask, filter, &pdata->rx_dws); if (chip->dma.rx_chan) { struct dma_slave_config dma_conf = { .src_addr = regs->start + AC97C_CARHR + 2, .src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, .src_maxburst = 1, .dst_maxburst = 1, .direction = DMA_DEV_TO_MEM, .device_fc = false, }; dmaengine_slave_config(chip->dma.rx_chan, &dma_conf); } dev_info(&chip->pdev->dev, "using %s for DMA RX\n", dev_name(&chip->dma.rx_chan->dev->device)); set_bit(DMA_RX_CHAN_PRESENT, &chip->flags); } if (pdata->tx_dws.dma_dev) { dma_cap_mask_t mask; dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); chip->dma.tx_chan = dma_request_channel(mask, filter, &pdata->tx_dws); if (chip->dma.tx_chan) { struct dma_slave_config dma_conf = { .dst_addr = regs->start + AC97C_CATHR + 2, .dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, .src_maxburst = 1, .dst_maxburst = 1, .direction = DMA_MEM_TO_DEV, .device_fc = false, }; dmaengine_slave_config(chip->dma.tx_chan, &dma_conf); } dev_info(&chip->pdev->dev, "using %s for DMA TX\n", dev_name(&chip->dma.tx_chan->dev->device)); set_bit(DMA_TX_CHAN_PRESENT, &chip->flags); } if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) && !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) { dev_dbg(&pdev->dev, "DMA not available\n"); retval = -ENODEV; goto err_dma; } } else { /* Just pretend that we have DMA channel(for at91 i is actually * the PDC) */ set_bit(DMA_RX_CHAN_PRESENT, &chip->flags); set_bit(DMA_TX_CHAN_PRESENT, &chip->flags); } retval = atmel_ac97c_pcm_new(chip); if (retval) { dev_dbg(&pdev->dev, "could not register ac97 pcm device\n"); goto err_dma; } retval = snd_card_register(card); if (retval) { dev_dbg(&pdev->dev, "could not register sound card\n"); goto err_dma; } platform_set_drvdata(pdev, card); dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n", chip->regs, irq); return 0; err_dma: if (cpu_is_at32ap7000()) { if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags)) dma_release_channel(chip->dma.rx_chan); if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) dma_release_channel(chip->dma.tx_chan); clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags); clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags); chip->dma.rx_chan = NULL; chip->dma.tx_chan = NULL; } err_ac97_bus: snd_card_set_dev(card, NULL); if (gpio_is_valid(chip->reset_pin)) gpio_free(chip->reset_pin); iounmap(chip->regs); err_ioremap: free_irq(irq, chip); err_request_irq: snd_card_free(card); err_snd_card_new: clk_disable(pclk); clk_put(pclk); return retval; } #ifdef CONFIG_PM static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg) { struct snd_card *card = platform_get_drvdata(pdev); struct atmel_ac97c *chip = card->private_data; if (cpu_is_at32ap7000()) { if (test_bit(DMA_RX_READY, &chip->flags)) dw_dma_cyclic_stop(chip->dma.rx_chan); if (test_bit(DMA_TX_READY, &chip->flags)) dw_dma_cyclic_stop(chip->dma.tx_chan); } clk_disable(chip->pclk); return 0; } static int atmel_ac97c_resume(struct platform_device *pdev) { struct snd_card *card = platform_get_drvdata(pdev); struct atmel_ac97c *chip = card->private_data; clk_enable(chip->pclk); if (cpu_is_at32ap7000()) { if (test_bit(DMA_RX_READY, &chip->flags)) dw_dma_cyclic_start(chip->dma.rx_chan); if (test_bit(DMA_TX_READY, &chip->flags)) dw_dma_cyclic_start(chip->dma.tx_chan); } return 0; } #else #define atmel_ac97c_suspend NULL #define atmel_ac97c_resume NULL #endif static int __devexit atmel_ac97c_remove(struct platform_device *pdev) { struct snd_card *card = platform_get_drvdata(pdev); struct atmel_ac97c *chip = get_chip(card); if (gpio_is_valid(chip->reset_pin)) gpio_free(chip->reset_pin); ac97c_writel(chip, CAMR, 0); ac97c_writel(chip, COMR, 0); ac97c_writel(chip, MR, 0); clk_disable(chip->pclk); clk_put(chip->pclk); iounmap(chip->regs); free_irq(chip->irq, chip); if (cpu_is_at32ap7000()) { if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags)) dma_release_channel(chip->dma.rx_chan); if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) dma_release_channel(chip->dma.tx_chan); clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags); clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags); chip->dma.rx_chan = NULL; chip->dma.tx_chan = NULL; } snd_card_set_dev(card, NULL); snd_card_free(card); platform_set_drvdata(pdev, NULL); return 0; } static struct platform_driver atmel_ac97c_driver = { .remove = __devexit_p(atmel_ac97c_remove), .driver = { .name = "atmel_ac97c", }, .suspend = atmel_ac97c_suspend, .resume = atmel_ac97c_resume, }; static int __init atmel_ac97c_init(void) { return platform_driver_probe(&atmel_ac97c_driver, atmel_ac97c_probe); } module_init(atmel_ac97c_init); static void __exit atmel_ac97c_exit(void) { platform_driver_unregister(&atmel_ac97c_driver); } module_exit(atmel_ac97c_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Driver for Atmel AC97 controller"); MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
gpl-2.0
rutvik95/android_kernel_frostbite
arch/um/drivers/chan_user.c
4665
7101
/* * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <sched.h> #include <signal.h> #include <termios.h> #include <sys/ioctl.h> #include "chan_user.h" #include "kern_constants.h" #include "os.h" #include "um_malloc.h" #include "user.h" void generic_close(int fd, void *unused) { close(fd); } int generic_read(int fd, char *c_out, void *unused) { int n; n = read(fd, c_out, sizeof(*c_out)); if (n > 0) return n; else if (errno == EAGAIN) return 0; else if (n == 0) return -EIO; return -errno; } /* XXX Trivial wrapper around write */ int generic_write(int fd, const char *buf, int n, void *unused) { int err; err = write(fd, buf, n); if (err > 0) return err; else if (errno == EAGAIN) return 0; else if (err == 0) return -EIO; return -errno; } int generic_window_size(int fd, void *unused, unsigned short *rows_out, unsigned short *cols_out) { struct winsize size; int ret; if (ioctl(fd, TIOCGWINSZ, &size) < 0) return -errno; ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col)); *rows_out = size.ws_row; *cols_out = size.ws_col; return ret; } void generic_free(void *data) { kfree(data); } int generic_console_write(int fd, const char *buf, int n) { sigset_t old, no_sigio; struct termios save, new; int err; if (isatty(fd)) { sigemptyset(&no_sigio); sigaddset(&no_sigio, SIGIO); if (sigprocmask(SIG_BLOCK, &no_sigio, &old)) goto error; CATCH_EINTR(err = tcgetattr(fd, &save)); if (err) goto error; new = save; /* * The terminal becomes a bit less raw, to handle \n also as * "Carriage Return", not only as "New Line". Otherwise, the new * line won't start at the first column. */ new.c_oflag |= OPOST; CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new)); if (err) goto error; } err = generic_write(fd, buf, n, NULL); /* * Restore raw mode, in any case; we *must* ignore any error apart * EINTR, except for debug. */ if (isatty(fd)) { CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); sigprocmask(SIG_SETMASK, &old, NULL); } return err; error: return -errno; } /* * UML SIGWINCH handling * * The point of this is to handle SIGWINCH on consoles which have host * ttys and relay them inside UML to whatever might be running on the * console and cares about the window size (since SIGWINCH notifies * about terminal size changes). * * So, we have a separate thread for each host tty attached to a UML * device (side-issue - I'm annoyed that one thread can't have * multiple controlling ttys for the purpose of handling SIGWINCH, but * I imagine there are other reasons that doesn't make any sense). * * SIGWINCH can't be received synchronously, so you have to set up to * receive it as a signal. That being the case, if you are going to * wait for it, it is convenient to sit in sigsuspend() and wait for * the signal to bounce you out of it (see below for how we make sure * to exit only on SIGWINCH). */ static void winch_handler(int sig) { } struct winch_data { int pty_fd; int pipe_fd; }; static int winch_thread(void *arg) { struct winch_data *data = arg; sigset_t sigs; int pty_fd, pipe_fd; int count; char c = 1; pty_fd = data->pty_fd; pipe_fd = data->pipe_fd; count = write(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : failed to write " "synchronization byte, err = %d\n", -count); /* * We are not using SIG_IGN on purpose, so don't fix it as I thought to * do! If using SIG_IGN, the sigsuspend() call below would not stop on * SIGWINCH. */ signal(SIGWINCH, winch_handler); sigfillset(&sigs); /* Block all signals possible. */ if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) { printk(UM_KERN_ERR "winch_thread : sigprocmask failed, " "errno = %d\n", errno); exit(1); } /* In sigsuspend(), block anything else than SIGWINCH. */ sigdelset(&sigs, SIGWINCH); if (setsid() < 0) { printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n", errno); exit(1); } if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) { printk(UM_KERN_ERR "winch_thread : TIOCSCTTY failed on " "fd %d err = %d\n", pty_fd, errno); exit(1); } if (tcsetpgrp(pty_fd, os_getpid()) < 0) { printk(UM_KERN_ERR "winch_thread : tcsetpgrp failed on " "fd %d err = %d\n", pty_fd, errno); exit(1); } /* * These are synchronization calls between various UML threads on the * host - since they are not different kernel threads, we cannot use * kernel semaphores. We don't use SysV semaphores because they are * persistent. */ count = read(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : failed to read " "synchronization byte, err = %d\n", errno); while(1) { /* * This will be interrupted by SIGWINCH only, since * other signals are blocked. */ sigsuspend(&sigs); count = write(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : write failed, " "err = %d\n", errno); } } static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out, unsigned long *stack_out) { struct winch_data data; int fds[2], n, err; char c; err = os_pipe(fds, 1, 1); if (err < 0) { printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n", -err); goto out; } data = ((struct winch_data) { .pty_fd = fd, .pipe_fd = fds[1] } ); /* * CLONE_FILES so this thread doesn't hold open files which are open * now, but later closed in a different thread. This is a * problem with /dev/net/tun, which if held open by this * thread, prevents the TUN/TAP device from being reused. */ err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out); if (err < 0) { printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n", -err); goto out_close; } *fd_out = fds[0]; n = read(fds[0], &c, sizeof(c)); if (n != sizeof(c)) { printk(UM_KERN_ERR "winch_tramp : failed to read " "synchronization byte\n"); printk(UM_KERN_ERR "read failed, err = %d\n", errno); printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd); err = -EINVAL; goto out_close; } if (os_set_fd_block(*fd_out, 0)) { printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd " "non-blocking.\n"); goto out_close; } return err; out_close: close(fds[1]); close(fds[0]); out: return err; } void register_winch(int fd, struct tty_struct *tty) { unsigned long stack; int pid, thread, count, thread_fd = -1; char c = 1; if (!isatty(fd)) return; pid = tcgetpgrp(fd); if (!is_skas_winch(pid, fd, tty) && (pid == -1)) { thread = winch_tramp(fd, tty, &thread_fd, &stack); if (thread < 0) return; register_winch_irq(thread_fd, fd, thread, tty, stack); count = write(thread_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "register_winch : failed to write " "synchronization byte, err = %d\n", errno); } }
gpl-2.0
Jetson-TX1-AndroidTV/android_kernel_shield_tv_video4linux
drivers/scsi/libfc/fc_frame.c
4921
2423
/* * Copyright(c) 2007 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * * Maintained at www.Open-FCoE.org */ /* * Frame allocation. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/skbuff.h> #include <linux/crc32.h> #include <linux/gfp.h> #include <scsi/fc_frame.h> /* * Check the CRC in a frame. */ u32 fc_frame_crc_check(struct fc_frame *fp) { u32 crc; u32 error; const u8 *bp; unsigned int len; WARN_ON(!fc_frame_is_linear(fp)); fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; len = (fr_len(fp) + 3) & ~3; /* round up length to include fill */ bp = (const u8 *) fr_hdr(fp); crc = ~crc32(~0, bp, len); error = crc ^ fr_crc(fp); return error; } EXPORT_SYMBOL(fc_frame_crc_check); /* * Allocate a frame intended to be sent. * Get an sk_buff for the frame and set the length. */ struct fc_frame *_fc_frame_alloc(size_t len) { struct fc_frame *fp; struct sk_buff *skb; WARN_ON((len % sizeof(u32)) != 0); len += sizeof(struct fc_frame_header); skb = alloc_skb_fclone(len + FC_FRAME_HEADROOM + FC_FRAME_TAILROOM + NET_SKB_PAD, GFP_ATOMIC); if (!skb) return NULL; skb_reserve(skb, NET_SKB_PAD + FC_FRAME_HEADROOM); fp = (struct fc_frame *) skb; fc_frame_init(fp); skb_put(skb, len); return fp; } EXPORT_SYMBOL(_fc_frame_alloc); struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len) { struct fc_frame *fp; size_t fill; fill = payload_len % 4; if (fill != 0) fill = 4 - fill; fp = _fc_frame_alloc(payload_len + fill); if (fp) { memset((char *) fr_hdr(fp) + payload_len, 0, fill); /* trim is OK, we just allocated it so there are no fragments */ skb_trim(fp_skb(fp), payload_len + sizeof(struct fc_frame_header)); } return fp; } EXPORT_SYMBOL(fc_frame_alloc_fill);
gpl-2.0
glenlee75/linux-at91
arch/x86/kernel/irq_64.c
7225
2858
/* * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar * * This file contains the lowest level x86_64-specific interrupt * entry and irq statistics code. All the remaining irq logic is * done by the generic kernel/irq/ code and in the * x86_64-specific irq controller code. (e.g. i8259.c and * io_apic.c.) */ #include <linux/kernel_stat.h> #include <linux/interrupt.h> #include <linux/seq_file.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/ftrace.h> #include <linux/uaccess.h> #include <linux/smp.h> #include <asm/io_apic.h> #include <asm/idle.h> #include <asm/apic.h> DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat); EXPORT_PER_CPU_SYMBOL(irq_stat); DEFINE_PER_CPU(struct pt_regs *, irq_regs); EXPORT_PER_CPU_SYMBOL(irq_regs); int sysctl_panic_on_stackoverflow; /* * Probabilistic stack overflow check: * * Only check the stack in process context, because everything else * runs on the big interrupt stacks. Checking reliably is too expensive, * so we just check from interrupts. */ static inline void stack_overflow_check(struct pt_regs *regs) { #ifdef CONFIG_DEBUG_STACKOVERFLOW #define STACK_TOP_MARGIN 128 struct orig_ist *oist; u64 irq_stack_top, irq_stack_bottom; u64 estack_top, estack_bottom; u64 curbase = (u64)task_stack_page(current); if (user_mode_vm(regs)) return; if (regs->sp >= curbase + sizeof(struct thread_info) + sizeof(struct pt_regs) + STACK_TOP_MARGIN && regs->sp <= curbase + THREAD_SIZE) return; irq_stack_top = (u64)__get_cpu_var(irq_stack_union.irq_stack) + STACK_TOP_MARGIN; irq_stack_bottom = (u64)__get_cpu_var(irq_stack_ptr); if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom) return; oist = &__get_cpu_var(orig_ist); estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN; estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1]; if (regs->sp >= estack_top && regs->sp <= estack_bottom) return; WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx,irq stk top-bottom:%Lx-%Lx,exception stk top-bottom:%Lx-%Lx)\n", current->comm, curbase, regs->sp, irq_stack_top, irq_stack_bottom, estack_top, estack_bottom); if (sysctl_panic_on_stackoverflow) panic("low stack detected by irq handler - check messages\n"); #endif } bool handle_irq(unsigned irq, struct pt_regs *regs) { struct irq_desc *desc; stack_overflow_check(regs); desc = irq_to_desc(irq); if (unlikely(!desc)) return false; generic_handle_irq_desc(irq, desc); return true; } extern void call_softirq(void); asmlinkage void do_softirq(void) { __u32 pending; unsigned long flags; if (in_interrupt()) return; local_irq_save(flags); pending = local_softirq_pending(); /* Switch to interrupt stack */ if (pending) { call_softirq(); WARN_ON_ONCE(softirq_count()); } local_irq_restore(flags); }
gpl-2.0
espenfjo/android_kernel_samsung_n8000
crypto/pcbc.c
12345
7852
/* * PCBC: Propagating Cipher Block Chaining mode * * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * Derived from cbc.c * - Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * */ #include <crypto/algapi.h> #include <linux/err.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/scatterlist.h> #include <linux/slab.h> struct crypto_pcbc_ctx { struct crypto_cipher *child; }; static int crypto_pcbc_setkey(struct crypto_tfm *parent, const u8 *key, unsigned int keylen) { struct crypto_pcbc_ctx *ctx = crypto_tfm_ctx(parent); struct crypto_cipher *child = ctx->child; int err; crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) & CRYPTO_TFM_REQ_MASK); err = crypto_cipher_setkey(child, key, keylen); crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) & CRYPTO_TFM_RES_MASK); return err; } static int crypto_pcbc_encrypt_segment(struct blkcipher_desc *desc, struct blkcipher_walk *walk, struct crypto_cipher *tfm) { void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = crypto_cipher_alg(tfm)->cia_encrypt; int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; u8 *iv = walk->iv; do { crypto_xor(iv, src, bsize); fn(crypto_cipher_tfm(tfm), dst, iv); memcpy(iv, dst, bsize); crypto_xor(iv, src, bsize); src += bsize; dst += bsize; } while ((nbytes -= bsize) >= bsize); return nbytes; } static int crypto_pcbc_encrypt_inplace(struct blkcipher_desc *desc, struct blkcipher_walk *walk, struct crypto_cipher *tfm) { void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = crypto_cipher_alg(tfm)->cia_encrypt; int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; u8 tmpbuf[bsize]; do { memcpy(tmpbuf, src, bsize); crypto_xor(iv, src, bsize); fn(crypto_cipher_tfm(tfm), src, iv); memcpy(iv, tmpbuf, bsize); crypto_xor(iv, src, bsize); src += bsize; } while ((nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); return nbytes; } static int crypto_pcbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct blkcipher_walk walk; struct crypto_blkcipher *tfm = desc->tfm; struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm); struct crypto_cipher *child = ctx->child; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt(desc, &walk); while ((nbytes = walk.nbytes)) { if (walk.src.virt.addr == walk.dst.virt.addr) nbytes = crypto_pcbc_encrypt_inplace(desc, &walk, child); else nbytes = crypto_pcbc_encrypt_segment(desc, &walk, child); err = blkcipher_walk_done(desc, &walk, nbytes); } return err; } static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc, struct blkcipher_walk *walk, struct crypto_cipher *tfm) { void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = crypto_cipher_alg(tfm)->cia_decrypt; int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; u8 *iv = walk->iv; do { fn(crypto_cipher_tfm(tfm), dst, src); crypto_xor(dst, iv, bsize); memcpy(iv, src, bsize); crypto_xor(iv, dst, bsize); src += bsize; dst += bsize; } while ((nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); return nbytes; } static int crypto_pcbc_decrypt_inplace(struct blkcipher_desc *desc, struct blkcipher_walk *walk, struct crypto_cipher *tfm) { void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = crypto_cipher_alg(tfm)->cia_decrypt; int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; u8 tmpbuf[bsize]; do { memcpy(tmpbuf, src, bsize); fn(crypto_cipher_tfm(tfm), src, src); crypto_xor(src, iv, bsize); memcpy(iv, tmpbuf, bsize); crypto_xor(iv, src, bsize); src += bsize; } while ((nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); return nbytes; } static int crypto_pcbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct blkcipher_walk walk; struct crypto_blkcipher *tfm = desc->tfm; struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm); struct crypto_cipher *child = ctx->child; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt(desc, &walk); while ((nbytes = walk.nbytes)) { if (walk.src.virt.addr == walk.dst.virt.addr) nbytes = crypto_pcbc_decrypt_inplace(desc, &walk, child); else nbytes = crypto_pcbc_decrypt_segment(desc, &walk, child); err = blkcipher_walk_done(desc, &walk, nbytes); } return err; } static int crypto_pcbc_init_tfm(struct crypto_tfm *tfm) { struct crypto_instance *inst = (void *)tfm->__crt_alg; struct crypto_spawn *spawn = crypto_instance_ctx(inst); struct crypto_pcbc_ctx *ctx = crypto_tfm_ctx(tfm); struct crypto_cipher *cipher; cipher = crypto_spawn_cipher(spawn); if (IS_ERR(cipher)) return PTR_ERR(cipher); ctx->child = cipher; return 0; } static void crypto_pcbc_exit_tfm(struct crypto_tfm *tfm) { struct crypto_pcbc_ctx *ctx = crypto_tfm_ctx(tfm); crypto_free_cipher(ctx->child); } static struct crypto_instance *crypto_pcbc_alloc(struct rtattr **tb) { struct crypto_instance *inst; struct crypto_alg *alg; int err; err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER); if (err) return ERR_PTR(err); alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, CRYPTO_ALG_TYPE_MASK); if (IS_ERR(alg)) return ERR_CAST(alg); inst = crypto_alloc_instance("pcbc", alg); if (IS_ERR(inst)) goto out_put_alg; inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER; inst->alg.cra_priority = alg->cra_priority; inst->alg.cra_blocksize = alg->cra_blocksize; inst->alg.cra_alignmask = alg->cra_alignmask; inst->alg.cra_type = &crypto_blkcipher_type; /* We access the data as u32s when xoring. */ inst->alg.cra_alignmask |= __alignof__(u32) - 1; inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize; inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize; inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize; inst->alg.cra_ctxsize = sizeof(struct crypto_pcbc_ctx); inst->alg.cra_init = crypto_pcbc_init_tfm; inst->alg.cra_exit = crypto_pcbc_exit_tfm; inst->alg.cra_blkcipher.setkey = crypto_pcbc_setkey; inst->alg.cra_blkcipher.encrypt = crypto_pcbc_encrypt; inst->alg.cra_blkcipher.decrypt = crypto_pcbc_decrypt; out_put_alg: crypto_mod_put(alg); return inst; } static void crypto_pcbc_free(struct crypto_instance *inst) { crypto_drop_spawn(crypto_instance_ctx(inst)); kfree(inst); } static struct crypto_template crypto_pcbc_tmpl = { .name = "pcbc", .alloc = crypto_pcbc_alloc, .free = crypto_pcbc_free, .module = THIS_MODULE, }; static int __init crypto_pcbc_module_init(void) { return crypto_register_template(&crypto_pcbc_tmpl); } static void __exit crypto_pcbc_module_exit(void) { crypto_unregister_template(&crypto_pcbc_tmpl); } module_init(crypto_pcbc_module_init); module_exit(crypto_pcbc_module_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("PCBC block cipher algorithm");
gpl-2.0
somesnow/AK-OnePone
net/sched/sch_blackhole.c
14137
1240
/* * net/sched/sch_blackhole.c Black hole queue * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Authors: Thomas Graf <tgraf@suug.ch> * * Note: Quantum tunneling is not supported. */ #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/skbuff.h> #include <net/pkt_sched.h> static int blackhole_enqueue(struct sk_buff *skb, struct Qdisc *sch) { qdisc_drop(skb, sch); return NET_XMIT_SUCCESS; } static struct sk_buff *blackhole_dequeue(struct Qdisc *sch) { return NULL; } static struct Qdisc_ops blackhole_qdisc_ops __read_mostly = { .id = "blackhole", .priv_size = 0, .enqueue = blackhole_enqueue, .dequeue = blackhole_dequeue, .peek = blackhole_dequeue, .owner = THIS_MODULE, }; static int __init blackhole_module_init(void) { return register_qdisc(&blackhole_qdisc_ops); } static void __exit blackhole_module_exit(void) { unregister_qdisc(&blackhole_qdisc_ops); } module_init(blackhole_module_init) module_exit(blackhole_module_exit) MODULE_LICENSE("GPL");
gpl-2.0
mrjaydee82/SinLessKerne1-m8-GPE
drivers/thermal/qpnp-adc-tm.c
58
55289
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #define pr_fmt(fmt) "%s: " fmt, __func__ #include <linux/kernel.h> #include <linux/of.h> #include <linux/err.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/mutex.h> #include <linux/types.h> #include <linux/hwmon.h> #include <linux/module.h> #include <linux/debugfs.h> #include <linux/spmi.h> #include <linux/of_irq.h> #include <linux/wakelock.h> #include <linux/interrupt.h> #include <linux/completion.h> #include <linux/hwmon-sysfs.h> #include <linux/qpnp/qpnp-adc.h> #include <linux/thermal.h> #include <linux/platform_device.h> #define QPNP_REVISION3 0x2 #define QPNP_PERPH_SUBTYPE 0x5 #define QPNP_PERPH_TYPE2 0x2 #define QPNP_REVISION_EIGHT_CHANNEL_SUPPORT 2 #define QPNP_STATUS1 0x8 #define QPNP_STATUS1_OP_MODE 4 #define QPNP_STATUS1_MEAS_INTERVAL_EN_STS BIT(2) #define QPNP_STATUS1_REQ_STS BIT(1) #define QPNP_STATUS1_EOC BIT(0) #define QPNP_STATUS2 0x9 #define QPNP_STATUS2_CONV_SEQ_STATE 6 #define QPNP_STATUS2_FIFO_NOT_EMPTY_FLAG BIT(1) #define QPNP_STATUS2_CONV_SEQ_TIMEOUT_STS BIT(0) #define QPNP_CONV_TIMEOUT_ERR 2 #define QPNP_MODE_CTL 0x40 #define QPNP_OP_MODE_SHIFT 3 #define QPNP_VREF_XO_THM_FORCE BIT(2) #define QPNP_AMUX_TRIM_EN BIT(1) #define QPNP_ADC_TRIM_EN BIT(0) #define QPNP_EN_CTL1 0x46 #define QPNP_ADC_TM_EN BIT(7) #define QPNP_ADC_CH_SEL_CTL 0x48 #define QPNP_ADC_DIG_PARAM 0x50 #define QPNP_ADC_DIG_DEC_RATIO_SEL_SHIFT 3 #define QPNP_HW_SETTLE_DELAY 0x51 #define QPNP_CONV_REQ 0x52 #define QPNP_CONV_REQ_SET BIT(7) #define QPNP_CONV_SEQ_CTL 0x54 #define QPNP_CONV_SEQ_HOLDOFF_SHIFT 4 #define QPNP_CONV_SEQ_TRIG_CTL 0x55 #define QPNP_ADC_TM_MEAS_INTERVAL_CTL 0x57 #define QPNP_ADC_TM_MEAS_INTERVAL_TIME_SHIFT 0x3 #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2 0x58 #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2_SHIFT 0x4 #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2_MASK 0xf0 #define QPNP_ADC_TM_MEAS_INTERVAL_CTL3_MASK 0xf #define QPNP_ADC_MEAS_INTERVAL_OP_CTL 0x59 #define QPNP_ADC_MEAS_INTERVAL_OP BIT(7) #define QPNP_FAST_AVG_CTL 0x5a #define QPNP_FAST_AVG_EN 0x5b #define QPNP_M0_LOW_THR_LSB 0x5c #define QPNP_M0_LOW_THR_MSB 0x5d #define QPNP_M0_HIGH_THR_LSB 0x5e #define QPNP_M0_HIGH_THR_MSB 0x5f #define QPNP_M1_ADC_CH_SEL_CTL 0x68 #define QPNP_M1_LOW_THR_LSB 0x69 #define QPNP_M1_LOW_THR_MSB 0x6a #define QPNP_M1_HIGH_THR_LSB 0x6b #define QPNP_M1_HIGH_THR_MSB 0x6c #define QPNP_M2_ADC_CH_SEL_CTL 0x70 #define QPNP_M2_LOW_THR_LSB 0x71 #define QPNP_M2_LOW_THR_MSB 0x72 #define QPNP_M2_HIGH_THR_LSB 0x73 #define QPNP_M2_HIGH_THR_MSB 0x74 #define QPNP_M3_ADC_CH_SEL_CTL 0x78 #define QPNP_M3_LOW_THR_LSB 0x79 #define QPNP_M3_LOW_THR_MSB 0x7a #define QPNP_M3_HIGH_THR_LSB 0x7b #define QPNP_M3_HIGH_THR_MSB 0x7c #define QPNP_M4_ADC_CH_SEL_CTL 0x80 #define QPNP_M4_LOW_THR_LSB 0x81 #define QPNP_M4_LOW_THR_MSB 0x82 #define QPNP_M4_HIGH_THR_LSB 0x83 #define QPNP_M4_HIGH_THR_MSB 0x84 #define QPNP_M5_ADC_CH_SEL_CTL 0x88 #define QPNP_M5_LOW_THR_LSB 0x89 #define QPNP_M5_LOW_THR_MSB 0x8a #define QPNP_M5_HIGH_THR_LSB 0x8b #define QPNP_M5_HIGH_THR_MSB 0x8c #define QPNP_M6_ADC_CH_SEL_CTL 0x90 #define QPNP_M6_LOW_THR_LSB 0x91 #define QPNP_M6_LOW_THR_MSB 0x92 #define QPNP_M6_HIGH_THR_LSB 0x93 #define QPNP_M6_HIGH_THR_MSB 0x94 #define QPNP_M7_ADC_CH_SEL_CTL 0x98 #define QPNP_M7_LOW_THR_LSB 0x99 #define QPNP_M7_LOW_THR_MSB 0x9a #define QPNP_M7_HIGH_THR_LSB 0x9b #define QPNP_M7_HIGH_THR_MSB 0x9c #define QPNP_ADC_TM_MULTI_MEAS_EN 0x41 #define QPNP_ADC_TM_MULTI_MEAS_EN_M0 BIT(0) #define QPNP_ADC_TM_MULTI_MEAS_EN_M1 BIT(1) #define QPNP_ADC_TM_MULTI_MEAS_EN_M2 BIT(2) #define QPNP_ADC_TM_MULTI_MEAS_EN_M3 BIT(3) #define QPNP_ADC_TM_MULTI_MEAS_EN_M4 BIT(4) #define QPNP_ADC_TM_MULTI_MEAS_EN_M5 BIT(5) #define QPNP_ADC_TM_MULTI_MEAS_EN_M6 BIT(6) #define QPNP_ADC_TM_MULTI_MEAS_EN_M7 BIT(7) #define QPNP_ADC_TM_LOW_THR_INT_EN 0x42 #define QPNP_ADC_TM_LOW_THR_INT_EN_M0 BIT(0) #define QPNP_ADC_TM_LOW_THR_INT_EN_M1 BIT(1) #define QPNP_ADC_TM_LOW_THR_INT_EN_M2 BIT(2) #define QPNP_ADC_TM_LOW_THR_INT_EN_M3 BIT(3) #define QPNP_ADC_TM_LOW_THR_INT_EN_M4 BIT(4) #define QPNP_ADC_TM_LOW_THR_INT_EN_M5 BIT(5) #define QPNP_ADC_TM_LOW_THR_INT_EN_M6 BIT(6) #define QPNP_ADC_TM_LOW_THR_INT_EN_M7 BIT(7) #define QPNP_ADC_TM_HIGH_THR_INT_EN 0x43 #define QPNP_ADC_TM_HIGH_THR_INT_EN_M0 BIT(0) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M1 BIT(1) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M2 BIT(2) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M3 BIT(3) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M4 BIT(4) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M5 BIT(5) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M6 BIT(6) #define QPNP_ADC_TM_HIGH_THR_INT_EN_M7 BIT(7) #define QPNP_ADC_TM_M0_MEAS_INTERVAL_CTL 0x59 #define QPNP_ADC_TM_M1_MEAS_INTERVAL_CTL 0x6d #define QPNP_ADC_TM_M2_MEAS_INTERVAL_CTL 0x75 #define QPNP_ADC_TM_M3_MEAS_INTERVAL_CTL 0x7d #define QPNP_ADC_TM_M4_MEAS_INTERVAL_CTL 0x85 #define QPNP_ADC_TM_M5_MEAS_INTERVAL_CTL 0x8d #define QPNP_ADC_TM_M6_MEAS_INTERVAL_CTL 0x95 #define QPNP_ADC_TM_M7_MEAS_INTERVAL_CTL 0x9d #define QPNP_ADC_TM_STATUS1 0x8 #define QPNP_ADC_TM_STATUS_LOW 0xa #define QPNP_ADC_TM_STATUS_HIGH 0xb #define QPNP_ADC_TM_M0_LOW_THR 0x5d5c #define QPNP_ADC_TM_M0_HIGH_THR 0x5f5e #define QPNP_ADC_TM_MEAS_INTERVAL 0x0 #define QPNP_ADC_TM_THR_LSB_MASK(val) (val & 0xff) #define QPNP_ADC_TM_THR_MSB_MASK(val) ((val & 0xff00) >> 8) #define QPNP_MIN_TIME 2000 #define QPNP_MAX_TIME 2100 struct qpnp_adc_thr_client_info { struct list_head list; struct qpnp_adc_tm_btm_param *btm_param; int32_t low_thr_requested; int32_t high_thr_requested; enum qpnp_state_request state_requested; enum qpnp_state_request state_req_copy; bool low_thr_set; bool high_thr_set; bool notify_low_thr; bool notify_high_thr; }; struct qpnp_adc_tm_sensor { struct thermal_zone_device *tz_dev; struct qpnp_adc_tm_chip *chip; enum thermal_device_mode mode; uint32_t sensor_num; enum qpnp_adc_meas_timer_select timer_select; uint32_t meas_interval; uint32_t low_thr; uint32_t high_thr; uint32_t btm_channel_num; uint32_t vadc_channel_num; struct work_struct work; bool thermal_node; uint32_t scale_type; struct list_head thr_list; }; struct qpnp_adc_tm_chip { struct device *dev; struct qpnp_adc_drv *adc; struct list_head list; bool adc_tm_initialized; int max_channels_available; struct qpnp_vadc_chip *vadc_dev; struct work_struct trigger_high_thr_work; struct work_struct trigger_low_thr_work; struct qpnp_adc_tm_sensor sensor[0]; }; LIST_HEAD(qpnp_adc_tm_device_list); struct qpnp_adc_tm_trip_reg_type { enum qpnp_adc_tm_channel_select btm_amux_chan; uint16_t low_thr_lsb_addr; uint16_t low_thr_msb_addr; uint16_t high_thr_lsb_addr; uint16_t high_thr_msb_addr; u8 multi_meas_en; u8 low_thr_int_chan_en; u8 high_thr_int_chan_en; u8 meas_interval_ctl; }; static struct qpnp_adc_tm_trip_reg_type adc_tm_data[] = { [QPNP_ADC_TM_CHAN0] = {QPNP_ADC_TM_M0_ADC_CH_SEL_CTL, QPNP_M0_LOW_THR_LSB, QPNP_M0_LOW_THR_MSB, QPNP_M0_HIGH_THR_LSB, QPNP_M0_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M0, QPNP_ADC_TM_LOW_THR_INT_EN_M0, QPNP_ADC_TM_HIGH_THR_INT_EN_M0, QPNP_ADC_TM_M0_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN1] = {QPNP_ADC_TM_M1_ADC_CH_SEL_CTL, QPNP_M1_LOW_THR_LSB, QPNP_M1_LOW_THR_MSB, QPNP_M1_HIGH_THR_LSB, QPNP_M1_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M1, QPNP_ADC_TM_LOW_THR_INT_EN_M1, QPNP_ADC_TM_HIGH_THR_INT_EN_M1, QPNP_ADC_TM_M1_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN2] = {QPNP_ADC_TM_M2_ADC_CH_SEL_CTL, QPNP_M2_LOW_THR_LSB, QPNP_M2_LOW_THR_MSB, QPNP_M2_HIGH_THR_LSB, QPNP_M2_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M2, QPNP_ADC_TM_LOW_THR_INT_EN_M2, QPNP_ADC_TM_HIGH_THR_INT_EN_M2, QPNP_ADC_TM_M2_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN3] = {QPNP_ADC_TM_M3_ADC_CH_SEL_CTL, QPNP_M3_LOW_THR_LSB, QPNP_M3_LOW_THR_MSB, QPNP_M3_HIGH_THR_LSB, QPNP_M3_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M3, QPNP_ADC_TM_LOW_THR_INT_EN_M3, QPNP_ADC_TM_HIGH_THR_INT_EN_M3, QPNP_ADC_TM_M3_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN4] = {QPNP_ADC_TM_M4_ADC_CH_SEL_CTL, QPNP_M4_LOW_THR_LSB, QPNP_M4_LOW_THR_MSB, QPNP_M4_HIGH_THR_LSB, QPNP_M4_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M4, QPNP_ADC_TM_LOW_THR_INT_EN_M4, QPNP_ADC_TM_HIGH_THR_INT_EN_M4, QPNP_ADC_TM_M4_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN5] = {QPNP_ADC_TM_M5_ADC_CH_SEL_CTL, QPNP_M5_LOW_THR_LSB, QPNP_M5_LOW_THR_MSB, QPNP_M5_HIGH_THR_LSB, QPNP_M5_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M5, QPNP_ADC_TM_LOW_THR_INT_EN_M5, QPNP_ADC_TM_HIGH_THR_INT_EN_M5, QPNP_ADC_TM_M5_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN6] = {QPNP_ADC_TM_M6_ADC_CH_SEL_CTL, QPNP_M6_LOW_THR_LSB, QPNP_M6_LOW_THR_MSB, QPNP_M6_HIGH_THR_LSB, QPNP_M6_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M6, QPNP_ADC_TM_LOW_THR_INT_EN_M6, QPNP_ADC_TM_HIGH_THR_INT_EN_M6, QPNP_ADC_TM_M6_MEAS_INTERVAL_CTL}, [QPNP_ADC_TM_CHAN7] = {QPNP_ADC_TM_M7_ADC_CH_SEL_CTL, QPNP_M7_LOW_THR_LSB, QPNP_M7_LOW_THR_MSB, QPNP_M7_HIGH_THR_LSB, QPNP_M7_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M7, QPNP_ADC_TM_LOW_THR_INT_EN_M7, QPNP_ADC_TM_HIGH_THR_INT_EN_M7, QPNP_ADC_TM_M7_MEAS_INTERVAL_CTL}, }; static struct qpnp_adc_tm_reverse_scale_fn adc_tm_rscale_fn[] = { [SCALE_R_VBATT] = {qpnp_adc_vbatt_rscaler}, [SCALE_RBATT_THERM] = {qpnp_adc_btm_scaler}, [SCALE_R_USB_ID] = {qpnp_adc_usb_scaler}, [SCALE_RPMIC_THERM] = {qpnp_adc_scale_millidegc_pmic_voltage_thr}, }; static int32_t qpnp_adc_tm_read_reg(struct qpnp_adc_tm_chip *chip, int16_t reg, u8 *data) { int rc = 0; rc = spmi_ext_register_readl(chip->adc->spmi->ctrl, chip->adc->slave, (chip->adc->offset + reg), data, 1); if (rc < 0) pr_err("adc-tm read reg %d failed with %d\n", reg, rc); return rc; } static int32_t qpnp_adc_tm_write_reg(struct qpnp_adc_tm_chip *chip, int16_t reg, u8 data) { int rc = 0; u8 *buf; buf = &data; rc = spmi_ext_register_writel(chip->adc->spmi->ctrl, chip->adc->slave, (chip->adc->offset + reg), buf, 1); if (rc < 0) pr_err("adc-tm write reg %d failed with %d\n", reg, rc); return rc; } static int32_t qpnp_adc_tm_enable(struct qpnp_adc_tm_chip *chip) { int rc = 0; u8 data = 0; data = QPNP_ADC_TM_EN; rc = qpnp_adc_tm_write_reg(chip, QPNP_EN_CTL1, data); if (rc < 0) pr_err("adc-tm enable failed\n"); return rc; } static int32_t qpnp_adc_tm_disable(struct qpnp_adc_tm_chip *chip) { u8 data = 0; int rc = 0; rc = qpnp_adc_tm_write_reg(chip, QPNP_EN_CTL1, data); if (rc < 0) pr_err("adc-tm disable failed\n"); return rc; } static int qpnp_adc_tm_is_valid(struct qpnp_adc_tm_chip *chip) { struct qpnp_adc_tm_chip *adc_tm_chip = NULL; list_for_each_entry(adc_tm_chip, &qpnp_adc_tm_device_list, list) if (chip == adc_tm_chip) return 0; return -EINVAL; } static int32_t qpnp_adc_tm_enable_if_channel_meas( struct qpnp_adc_tm_chip *chip) { u8 adc_tm_meas_en = 0; int rc = 0; rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN, &adc_tm_meas_en); if (rc) { pr_err("adc-tm-tm read status high failed with %d\n", rc); return rc; } if (adc_tm_meas_en) { qpnp_adc_tm_enable(chip); rc = qpnp_adc_tm_write_reg(chip, QPNP_CONV_REQ, QPNP_CONV_REQ_SET); if (rc < 0) { pr_err("adc-tm request conversion failed\n"); return rc; } } return rc; } static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) { u8 status1; int rc, count = 0; rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc) { pr_err("adc-tm read status1 failed\n"); return rc; } while ((status1 & QPNP_STATUS1_REQ_STS) && (count < 5)) { rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc < 0) pr_err("adc-tm disable failed\n"); usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME); count++; } return rc; } static int32_t qpnp_adc_tm_get_btm_idx(uint32_t btm_chan, uint32_t *btm_chan_idx) { int rc = 0, i; bool chan_found = false; for (i = 0; i < QPNP_ADC_TM_CHAN_NONE; i++) { if (adc_tm_data[i].btm_amux_chan == btm_chan) { *btm_chan_idx = i; chan_found = true; } } if (!chan_found) return -EINVAL; return rc; } static int32_t qpnp_adc_tm_check_revision(struct qpnp_adc_tm_chip *chip, uint32_t btm_chan_num) { u8 rev, perph_subtype; int rc = 0; rc = qpnp_adc_tm_read_reg(chip, QPNP_REVISION3, &rev); if (rc) { pr_err("adc-tm revision read failed\n"); return rc; } rc = qpnp_adc_tm_read_reg(chip, QPNP_PERPH_SUBTYPE, &perph_subtype); if (rc) { pr_err("adc-tm perph_subtype read failed\n"); return rc; } if (perph_subtype == QPNP_PERPH_TYPE2) { if ((rev < QPNP_REVISION_EIGHT_CHANNEL_SUPPORT) && (btm_chan_num > QPNP_ADC_TM_M4_ADC_CH_SEL_CTL)) { pr_debug("Version does not support more than 5 channels\n"); return -EINVAL; } } return rc; } static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip, u8 mode_ctl) { int rc; mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN); rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl); if (rc < 0) pr_err("adc-tm write mode selection err\n"); return rc; } static int32_t qpnp_adc_tm_timer_interval_select( struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, struct qpnp_vadc_chan_properties *chan_prop) { int rc, chan_idx = 0, i = 0; bool chan_found = false; u8 meas_interval_timer2 = 0, timer_interval_store = 0; uint32_t btm_chan_idx = 0; while (i < chip->max_channels_available) { if (chip->sensor[i].btm_channel_num == btm_chan) { chan_idx = i; chan_found = true; i++; } else i++; } if (!chan_found) { pr_err("Channel not found\n"); return -EINVAL; } switch (chip->sensor[chan_idx].timer_select) { case ADC_MEAS_TIMER_SELECT1: rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_MEAS_INTERVAL_CTL, chip->sensor[chan_idx].meas_interval); if (rc < 0) { pr_err("timer1 configure failed\n"); return rc; } break; case ADC_MEAS_TIMER_SELECT2: rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MEAS_INTERVAL_CTL2, &meas_interval_timer2); if (rc < 0) { pr_err("timer2 configure read failed\n"); return rc; } timer_interval_store = chip->sensor[chan_idx].meas_interval; timer_interval_store <<= QPNP_ADC_TM_MEAS_INTERVAL_CTL2_SHIFT; timer_interval_store &= QPNP_ADC_TM_MEAS_INTERVAL_CTL2_MASK; meas_interval_timer2 |= timer_interval_store; rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_MEAS_INTERVAL_CTL2, meas_interval_timer2); if (rc < 0) { pr_err("timer2 configure failed\n"); return rc; } break; case ADC_MEAS_TIMER_SELECT3: rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MEAS_INTERVAL_CTL2, &meas_interval_timer2); if (rc < 0) { pr_err("timer3 read failed\n"); return rc; } timer_interval_store = chip->sensor[chan_idx].meas_interval; timer_interval_store &= QPNP_ADC_TM_MEAS_INTERVAL_CTL3_MASK; meas_interval_timer2 |= timer_interval_store; rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_MEAS_INTERVAL_CTL2, meas_interval_timer2); if (rc < 0) { pr_err("timer3 configure failed\n"); return rc; } break; default: pr_err("Invalid timer selection\n"); return -EINVAL; } rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx); if (rc < 0) { pr_err("Invalid btm channel idx\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, adc_tm_data[btm_chan_idx].meas_interval_ctl, chip->sensor[chan_idx].timer_select); if (rc < 0) { pr_err("TM channel timer configure failed\n"); return rc; } pr_debug("timer select:%d, timer_value_within_select:%d, channel:%x\n", chip->sensor[chan_idx].timer_select, chip->sensor[chan_idx].meas_interval, btm_chan); return rc; } static int32_t qpnp_adc_tm_add_to_list(struct qpnp_adc_tm_chip *chip, uint32_t dt_index, struct qpnp_adc_tm_btm_param *param, struct qpnp_vadc_chan_properties *chan_prop) { struct qpnp_adc_thr_client_info *client_info = NULL; bool client_info_exists = false; list_for_each_entry(client_info, &chip->sensor[dt_index].thr_list, list) { if (client_info->btm_param == param) { client_info->low_thr_requested = chan_prop->low_thr; client_info->high_thr_requested = chan_prop->high_thr; client_info->state_requested = param->state_request; client_info->state_req_copy = param->state_request; client_info->notify_low_thr = false; client_info->notify_high_thr = false; client_info_exists = true; pr_debug("client found\n"); } } if (!client_info_exists) { client_info = devm_kzalloc(chip->dev, sizeof(struct qpnp_adc_thr_client_info), GFP_KERNEL); if (!client_info) { pr_err("%s: kzalloc() failed.\n", __func__); return -ENOMEM; } pr_debug("new client\n"); client_info->btm_param = param; client_info->low_thr_requested = chan_prop->low_thr; client_info->high_thr_requested = chan_prop->high_thr; client_info->state_requested = param->state_request; client_info->state_req_copy = param->state_request; list_add_tail(&client_info->list, &chip->sensor[dt_index].thr_list); } return 0; } static int32_t qpnp_adc_tm_reg_update(struct qpnp_adc_tm_chip *chip, uint16_t addr, u8 mask, bool state) { u8 reg_value = 0; int rc = 0; rc = qpnp_adc_tm_read_reg(chip, addr, &reg_value); if (rc < 0) { pr_err("read failed for addr:0x%x\n", addr); return rc; } reg_value = reg_value & ~mask; if (state) reg_value |= mask; pr_debug("state:%d, reg:0x%x with bits:0x%x and mask:0x%x\n", state, addr, reg_value, ~mask); rc = qpnp_adc_tm_write_reg(chip, addr, reg_value); if (rc < 0) { pr_err("write failed for addr:%x\n", addr); return rc; } return rc; } static int32_t qpnp_adc_tm_thr_update(struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, int32_t high_thr, int32_t low_thr) { int rc = 0; uint32_t btm_chan_idx = 0; rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx); if (rc < 0) { pr_err("Invalid btm channel idx\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, adc_tm_data[btm_chan_idx].low_thr_lsb_addr, QPNP_ADC_TM_THR_LSB_MASK(low_thr)); if (rc < 0) { pr_err("low threshold lsb setting failed\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, adc_tm_data[btm_chan_idx].low_thr_msb_addr, QPNP_ADC_TM_THR_MSB_MASK(low_thr)); if (rc < 0) { pr_err("low threshold msb setting failed\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, adc_tm_data[btm_chan_idx].high_thr_lsb_addr, QPNP_ADC_TM_THR_LSB_MASK(high_thr)); if (rc < 0) { pr_err("high threshold lsb setting failed\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, adc_tm_data[btm_chan_idx].high_thr_msb_addr, QPNP_ADC_TM_THR_MSB_MASK(high_thr)); if (rc < 0) pr_err("high threshold msb setting failed\n"); pr_debug("client requested high:%d and low:%d\n", high_thr, low_thr); return rc; } static int32_t qpnp_adc_tm_manage_thresholds(struct qpnp_adc_tm_chip *chip, uint32_t dt_index, uint32_t btm_chan) { struct qpnp_adc_thr_client_info *client_info = NULL; struct list_head *thr_list; int high_thr = 0, low_thr = 0, rc = 0; list_for_each(thr_list, &chip->sensor[dt_index].thr_list) { client_info = list_entry(thr_list, struct qpnp_adc_thr_client_info, list); high_thr = client_info->high_thr_requested; low_thr = client_info->low_thr_requested; client_info->high_thr_set = false; client_info->low_thr_set = false; } pr_debug("init threshold is high:%d and low:%d\n", high_thr, low_thr); list_for_each(thr_list, &chip->sensor[dt_index].thr_list) { client_info = list_entry(thr_list, struct qpnp_adc_thr_client_info, list); if ((client_info->state_req_copy == ADC_TM_HIGH_THR_ENABLE) || (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE)) if (client_info->high_thr_requested < high_thr) high_thr = client_info->high_thr_requested; if ((client_info->state_req_copy == ADC_TM_LOW_THR_ENABLE) || (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE)) if (client_info->low_thr_requested > low_thr) low_thr = client_info->low_thr_requested; pr_debug("threshold compared is high:%d and low:%d\n", client_info->high_thr_requested, client_info->low_thr_requested); pr_debug("current threshold is high:%d and low:%d\n", high_thr, low_thr); } list_for_each(thr_list, &chip->sensor[dt_index].thr_list) { client_info = list_entry(thr_list, struct qpnp_adc_thr_client_info, list); if ((client_info->state_req_copy == ADC_TM_HIGH_THR_ENABLE) || (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE)) if (high_thr == client_info->high_thr_requested) client_info->high_thr_set = true; if ((client_info->state_req_copy == ADC_TM_LOW_THR_ENABLE) || (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE)) if (low_thr == client_info->low_thr_requested) client_info->low_thr_set = true; } rc = qpnp_adc_tm_thr_update(chip, btm_chan, high_thr, low_thr); if (rc < 0) pr_err("setting chan:%d threshold failed\n", btm_chan); pr_debug("threshold written is high:%d and low:%d\n", high_thr, low_thr); return 0; } static int32_t qpnp_adc_tm_channel_configure(struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, struct qpnp_vadc_chan_properties *chan_prop, uint32_t amux_channel) { int rc = 0, i = 0, chan_idx = 0; bool chan_found = false, high_thr_set = false, low_thr_set = false; u8 sensor_mask = 0; struct qpnp_adc_thr_client_info *client_info = NULL; while (i < chip->max_channels_available) { if (chip->sensor[i].btm_channel_num == btm_chan) { chan_idx = i; chan_found = true; i++; } else i++; } if (!chan_found) { pr_err("Channel not found\n"); return -EINVAL; } sensor_mask = 1 << chan_idx; if (!chip->sensor[chan_idx].thermal_node) { rc = qpnp_adc_tm_manage_thresholds(chip, chan_idx, btm_chan); if (rc < 0) { pr_err("setting chan:%d threshold failed\n", btm_chan); return rc; } list_for_each_entry(client_info, &chip->sensor[chan_idx].thr_list, list) { if (client_info->high_thr_set == true) high_thr_set = true; if (client_info->low_thr_set == true) low_thr_set = true; } if (low_thr_set) { pr_debug("low sensor mask:%x with state:%d\n", sensor_mask, chan_prop->state_request); rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN, sensor_mask, true); if (rc < 0) { pr_err("low thr enable err:%d\n", btm_chan); return rc; } } if (high_thr_set) { pr_debug("high sensor mask:%x\n", sensor_mask); rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, sensor_mask, true); if (rc < 0) { pr_err("high thr enable err:%d\n", btm_chan); return rc; } } } rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, true); if (rc < 0) { pr_err("multi measurement en failed\n"); return rc; } return rc; } static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_amux_properties *chan_prop) { u8 decimation = 0, op_cntrl = 0; int rc = 0; uint32_t btm_chan = 0; rc = qpnp_adc_tm_disable(chip); if (rc) return rc; rc = qpnp_adc_tm_req_sts_check(chip); if (rc < 0) { pr_err("adc-tm req_sts check failed\n"); return rc; } rc = qpnp_adc_tm_mode_select(chip, chan_prop->mode_sel); if (rc < 0) { pr_err("adc-tm mode select failed\n"); return rc; } btm_chan = chan_prop->chan_prop->tm_channel_select; rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel); if (rc < 0) { pr_err("adc-tm channel selection err\n"); return rc; } decimation |= chan_prop->decimation << QPNP_ADC_DIG_DEC_RATIO_SEL_SHIFT; rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_DIG_PARAM, decimation); if (rc < 0) { pr_err("adc-tm digital parameter setup err\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, QPNP_HW_SETTLE_DELAY, chan_prop->hw_settle_time); if (rc < 0) { pr_err("adc-tm hw settling time setup err\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, QPNP_FAST_AVG_CTL, chan_prop->fast_avg_setup); if (rc < 0) { pr_err("adc-tm fast-avg setup err\n"); return rc; } rc = qpnp_adc_tm_timer_interval_select(chip, btm_chan, chan_prop->chan_prop); if (rc < 0) { pr_err("adc-tm timer select failed\n"); return rc; } rc = qpnp_adc_tm_channel_configure(chip, btm_chan, chan_prop->chan_prop, chan_prop->amux_channel); if (rc < 0) { pr_err("adc-tm channel configure failed\n"); return rc; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_MEAS_INTERVAL_OP_CTL, &op_cntrl); op_cntrl |= QPNP_ADC_MEAS_INTERVAL_OP; rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_MEAS_INTERVAL_OP_CTL, op_cntrl, true); if (rc < 0) { pr_err("adc-tm meas interval op configure failed\n"); return rc; } rc = qpnp_adc_tm_enable(chip); if (rc) return rc; rc = qpnp_adc_tm_write_reg(chip, QPNP_CONV_REQ, QPNP_CONV_REQ_SET); if (rc < 0) { pr_err("adc-tm request conversion failed\n"); return rc; } return 0; } static int qpnp_adc_tm_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; if ((IS_ERR(adc_tm)) || qpnp_adc_tm_check_revision( adc_tm->chip, adc_tm->btm_channel_num)) return -EINVAL; *mode = adc_tm->mode; return 0; } static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; int rc = 0, channel; u8 sensor_mask = 0; if (qpnp_adc_tm_is_valid(chip)) { pr_err("invalid device\n"); return -ENODEV; } if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num)) return -EINVAL; if (mode == THERMAL_DEVICE_ENABLED) { chip->adc->amux_prop->amux_channel = adc_tm->vadc_channel_num; channel = adc_tm->sensor_num; chip->adc->amux_prop->decimation = chip->adc->adc_channels[channel].adc_decimation; chip->adc->amux_prop->hw_settle_time = chip->adc->adc_channels[channel].hw_settle_time; chip->adc->amux_prop->fast_avg_setup = chip->adc->adc_channels[channel].fast_avg_setup; chip->adc->amux_prop->mode_sel = ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT; chip->adc->amux_prop->chan_prop->low_thr = adc_tm->low_thr; chip->adc->amux_prop->chan_prop->high_thr = adc_tm->high_thr; chip->adc->amux_prop->chan_prop->tm_channel_select = adc_tm->btm_channel_num; rc = qpnp_adc_tm_configure(chip, chip->adc->amux_prop); if (rc) { pr_err("adc-tm tm configure failed with %d\n", rc); return -EINVAL; } } else if (mode == THERMAL_DEVICE_DISABLED) { sensor_mask = 1 << adc_tm->sensor_num; rc = qpnp_adc_tm_disable(chip); if (rc < 0) { pr_err("adc-tm disable failed\n"); return rc; } rc = qpnp_adc_tm_req_sts_check(chip); if (rc < 0) { pr_err("adc-tm req_sts check failed\n"); return rc; } rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, false); if (rc < 0) { pr_err("multi measurement update failed\n"); return rc; } rc = qpnp_adc_tm_enable_if_channel_meas(chip); if (rc < 0) { pr_err("re-enabling measurement failed\n"); return rc; } } adc_tm->mode = mode; return 0; } static int qpnp_adc_tm_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num)) return -EINVAL; switch (trip) { case ADC_TM_TRIP_HIGH_WARM: *type = THERMAL_TRIP_CONFIGURABLE_HI; break; case ADC_TM_TRIP_LOW_COOL: *type = THERMAL_TRIP_CONFIGURABLE_LOW; break; default: return -EINVAL; } return 0; } static int qpnp_adc_tm_get_trip_temp(struct thermal_zone_device *thermal, int trip, long *temp) { struct qpnp_adc_tm_sensor *adc_tm_sensor = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm_sensor->chip; int64_t result = 0; u8 trip_cool_thr0, trip_cool_thr1, trip_warm_thr0, trip_warm_thr1; unsigned int reg; int rc = 0; uint16_t reg_low_thr_lsb, reg_low_thr_msb; uint16_t reg_high_thr_lsb, reg_high_thr_msb; uint32_t btm_chan_idx = 0, btm_chan = 0; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; if (qpnp_adc_tm_check_revision(chip, adc_tm_sensor->btm_channel_num)) return -EINVAL; btm_chan = adc_tm_sensor->btm_channel_num; rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx); if (rc < 0) { pr_err("Invalid btm channel idx\n"); return rc; } reg_low_thr_lsb = adc_tm_data[btm_chan_idx].low_thr_lsb_addr; reg_low_thr_msb = adc_tm_data[btm_chan_idx].low_thr_msb_addr; reg_high_thr_lsb = adc_tm_data[btm_chan_idx].high_thr_lsb_addr; reg_high_thr_msb = adc_tm_data[btm_chan_idx].high_thr_msb_addr; switch (trip) { case ADC_TM_TRIP_HIGH_WARM: rc = qpnp_adc_tm_read_reg(chip, reg_low_thr_lsb, &trip_warm_thr0); if (rc) { pr_err("adc-tm low_thr_lsb err\n"); return rc; } rc = qpnp_adc_tm_read_reg(chip, reg_low_thr_msb, &trip_warm_thr1); if (rc) { pr_err("adc-tm low_thr_msb err\n"); return rc; } reg = (trip_warm_thr1 << 8) | trip_warm_thr0; break; case ADC_TM_TRIP_LOW_COOL: rc = qpnp_adc_tm_read_reg(chip, reg_high_thr_lsb, &trip_cool_thr0); if (rc) { pr_err("adc-tm_tm high_thr_lsb err\n"); return rc; } rc = qpnp_adc_tm_read_reg(chip, reg_high_thr_msb, &trip_cool_thr1); if (rc) { pr_err("adc-tm_tm high_thr_lsb err\n"); return rc; } reg = (trip_cool_thr1 << 8) | trip_cool_thr0; break; default: return -EINVAL; } rc = qpnp_adc_tm_scale_voltage_therm_pu2(chip->vadc_dev, reg, &result); if (rc < 0) { pr_err("Failed to lookup the therm thresholds\n"); return rc; } *temp = result; return 0; } static int qpnp_adc_tm_set_trip_temp(struct thermal_zone_device *thermal, int trip, long temp) { struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; struct qpnp_adc_tm_config tm_config; u8 trip_cool_thr0, trip_cool_thr1, trip_warm_thr0, trip_warm_thr1; uint16_t reg_low_thr_lsb, reg_low_thr_msb; uint16_t reg_high_thr_lsb, reg_high_thr_msb; int rc = 0; uint32_t btm_chan = 0, btm_chan_idx = 0; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num)) return -EINVAL; memset(&tm_config, 0, sizeof(struct qpnp_adc_tm_config)); tm_config.channel = adc_tm->vadc_channel_num; switch (trip) { case ADC_TM_TRIP_HIGH_WARM: tm_config.high_thr_temp = temp; break; case ADC_TM_TRIP_LOW_COOL: tm_config.low_thr_temp = temp; break; default: return -EINVAL; } pr_debug("requested a high - %d and low - %d with trip - %d\n", tm_config.high_thr_temp, tm_config.low_thr_temp, trip); rc = qpnp_adc_tm_scale_therm_voltage_pu2(chip->vadc_dev, &tm_config); if (rc < 0) { pr_err("Failed to lookup the adc-tm thresholds\n"); return rc; } trip_warm_thr0 = ((tm_config.low_thr_voltage << 24) >> 24); trip_warm_thr1 = ((tm_config.low_thr_voltage << 16) >> 24); trip_cool_thr0 = ((tm_config.high_thr_voltage << 24) >> 24); trip_cool_thr1 = ((tm_config.high_thr_voltage << 16) >> 24); btm_chan = adc_tm->btm_channel_num; rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx); if (rc < 0) { pr_err("Invalid btm channel idx\n"); return rc; } reg_low_thr_lsb = adc_tm_data[btm_chan_idx].low_thr_lsb_addr; reg_low_thr_msb = adc_tm_data[btm_chan_idx].low_thr_msb_addr; reg_high_thr_lsb = adc_tm_data[btm_chan_idx].high_thr_lsb_addr; reg_high_thr_msb = adc_tm_data[btm_chan_idx].high_thr_msb_addr; switch (trip) { case ADC_TM_TRIP_HIGH_WARM: rc = qpnp_adc_tm_write_reg(chip, reg_low_thr_lsb, trip_cool_thr0); if (rc) { pr_err("adc-tm_tm read threshold err\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, reg_low_thr_msb, trip_cool_thr1); if (rc) { pr_err("adc-tm_tm read threshold err\n"); return rc; } adc_tm->low_thr = tm_config.high_thr_voltage; break; case ADC_TM_TRIP_LOW_COOL: rc = qpnp_adc_tm_write_reg(chip, reg_high_thr_lsb, trip_warm_thr0); if (rc) { pr_err("adc-tm_tm read threshold err\n"); return rc; } rc = qpnp_adc_tm_write_reg(chip, reg_high_thr_msb, trip_warm_thr1); if (rc) { pr_err("adc-tm_tm read threshold err\n"); return rc; } adc_tm->high_thr = tm_config.low_thr_voltage; break; default: return -EINVAL; } return 0; } static void notify_battery_therm(struct qpnp_adc_tm_sensor *adc_tm) { struct qpnp_adc_thr_client_info *client_info = NULL; list_for_each_entry(client_info, &adc_tm->thr_list, list) { if (client_info->notify_low_thr) { client_info->btm_param->threshold_notification( ADC_TM_WARM_STATE, client_info->btm_param->btm_ctx); client_info->notify_low_thr = false; } if (client_info->notify_high_thr) { client_info->btm_param->threshold_notification( ADC_TM_COOL_STATE, client_info->btm_param->btm_ctx); client_info->notify_high_thr = false; } } return; } static void notify_clients(struct qpnp_adc_tm_sensor *adc_tm) { struct qpnp_adc_thr_client_info *client_info = NULL; list_for_each_entry(client_info, &adc_tm->thr_list, list) { if (client_info->notify_low_thr) { if (client_info->btm_param->threshold_notification != NULL) { pr_debug("notify kernel with low state\n"); client_info->btm_param->threshold_notification( ADC_TM_LOW_STATE, client_info->btm_param->btm_ctx); client_info->notify_low_thr = false; } } if (client_info->notify_high_thr) { if (client_info->btm_param->threshold_notification != NULL) { pr_debug("notify kernel with high state\n"); client_info->btm_param->threshold_notification( ADC_TM_HIGH_STATE, client_info->btm_param->btm_ctx); client_info->notify_high_thr = false; } } } return; } static void notify_adc_tm_fn(struct work_struct *work) { struct qpnp_adc_tm_sensor *adc_tm = container_of(work, struct qpnp_adc_tm_sensor, work); if (adc_tm->thermal_node) { sysfs_notify(&adc_tm->tz_dev->device.kobj, NULL, "btm"); pr_debug("notifying uspace client\n"); } else { if (adc_tm->scale_type == SCALE_RBATT_THERM) notify_battery_therm(adc_tm); else notify_clients(adc_tm); } return; } static int qpnp_adc_tm_activate_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_activation_mode mode) { struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; int rc = 0, sensor_mask = 0; u8 thr_int_en = 0; bool state = false; uint32_t btm_chan_idx = 0, btm_chan = 0; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num)) return -EINVAL; if (mode == THERMAL_TRIP_ACTIVATION_ENABLED) state = true; sensor_mask = 1 << adc_tm->sensor_num; pr_debug("Sensor number:%x with state:%d\n", adc_tm->sensor_num, state); btm_chan = adc_tm->btm_channel_num; rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx); if (rc < 0) { pr_err("Invalid btm channel idx\n"); return rc; } switch (trip) { case ADC_TM_TRIP_HIGH_WARM: thr_int_en = adc_tm_data[btm_chan_idx].low_thr_int_chan_en; rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN, sensor_mask, state); if (rc) pr_err("channel:%x failed\n", btm_chan); break; case ADC_TM_TRIP_LOW_COOL: thr_int_en = adc_tm_data[btm_chan_idx].high_thr_int_chan_en; rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, sensor_mask, state); if (rc) pr_err("channel:%x failed\n", btm_chan); break; default: return -EINVAL; } return rc; } static int qpnp_adc_tm_read_status(struct qpnp_adc_tm_chip *chip) { u8 status_low = 0, status_high = 0, qpnp_adc_tm_meas_en = 0; u8 adc_tm_low_enable = 0, adc_tm_high_enable = 0; u8 sensor_mask = 0, adc_tm_low_thr_set = 0, adc_tm_high_thr_set = 0; int rc = 0, sensor_notify_num = 0, i = 0, sensor_num = 0; uint32_t btm_chan_num = 0; struct qpnp_adc_thr_client_info *client_info = NULL; struct list_head *thr_list; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; mutex_lock(&chip->adc->adc_lock); rc = qpnp_adc_tm_req_sts_check(chip); if (rc) { pr_err("adc-tm-tm req sts check failed with %d\n", rc); goto fail; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS_LOW, &status_low); if (rc) { pr_err("adc-tm-tm read status low failed with %d\n", rc); goto fail; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS_HIGH, &status_high); if (rc) { pr_err("adc-tm-tm read status high failed with %d\n", rc); goto fail; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_LOW_THR_INT_EN, &adc_tm_low_thr_set); if (rc) { pr_err("adc-tm-tm read low thr failed with %d\n", rc); goto fail; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, &adc_tm_high_thr_set); if (rc) { pr_err("adc-tm-tm read high thr failed with %d\n", rc); goto fail; } rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN, &qpnp_adc_tm_meas_en); if (rc) { pr_err("adc-tm-tm read status high failed with %d\n", rc); goto fail; } adc_tm_low_enable = qpnp_adc_tm_meas_en & status_low; adc_tm_low_enable &= adc_tm_low_thr_set; adc_tm_high_enable = qpnp_adc_tm_meas_en & status_high; adc_tm_high_enable &= adc_tm_high_thr_set; if (adc_tm_high_enable) { sensor_notify_num = adc_tm_high_enable; while (i < chip->max_channels_available) { if ((sensor_notify_num & 0x1) == 1) sensor_num = i; sensor_notify_num >>= 1; i++; } btm_chan_num = chip->sensor[sensor_num].btm_channel_num; pr_debug("high:sen:%d, hs:0x%x, ls:0x%x, meas_en:0x%x\n", sensor_num, adc_tm_high_enable, adc_tm_low_enable, qpnp_adc_tm_meas_en); if (!chip->sensor[sensor_num].thermal_node) { sensor_mask = 1 << sensor_num; pr_debug("non thermal node - mask:%x\n", sensor_mask); rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, sensor_mask, false); if (rc < 0) { pr_err("high threshold int read failed\n"); goto fail; } } else { pr_debug("thermal node with mask:%x\n", sensor_mask); rc = qpnp_adc_tm_activate_trip_type( chip->sensor[sensor_num].tz_dev, ADC_TM_TRIP_LOW_COOL, THERMAL_TRIP_ACTIVATION_DISABLED); if (rc < 0) { pr_err("notify error:%d\n", sensor_num); goto fail; } } list_for_each(thr_list, &chip->sensor[sensor_num].thr_list) { client_info = list_entry(thr_list, struct qpnp_adc_thr_client_info, list); if (client_info->high_thr_set) { client_info->high_thr_set = false; client_info->notify_high_thr = true; if (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE) client_info->state_req_copy = ADC_TM_LOW_THR_ENABLE; else client_info->state_req_copy = ADC_TM_HIGH_THR_DISABLE; } } } if (adc_tm_low_enable) { sensor_notify_num = adc_tm_low_enable; i = 0; while (i < chip->max_channels_available) { if ((sensor_notify_num & 0x1) == 1) sensor_num = i; sensor_notify_num >>= 1; i++; } btm_chan_num = chip->sensor[sensor_num].btm_channel_num; pr_debug("low:sen:%d, hs:0x%x, ls:0x%x, meas_en:0x%x\n", sensor_num, adc_tm_high_enable, adc_tm_low_enable, qpnp_adc_tm_meas_en); if (!chip->sensor[sensor_num].thermal_node) { pr_debug("non thermal node - mask:%x\n", sensor_mask); sensor_mask = 1 << sensor_num; rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN, sensor_mask, false); if (rc < 0) { pr_err("low threshold int read failed\n"); goto fail; } } else { pr_debug("thermal node with mask:%x\n", sensor_mask); rc = qpnp_adc_tm_activate_trip_type( chip->sensor[sensor_num].tz_dev, ADC_TM_TRIP_HIGH_WARM, THERMAL_TRIP_ACTIVATION_DISABLED); if (rc < 0) { pr_err("notify error:%d\n", sensor_num); goto fail; } } list_for_each(thr_list, &chip->sensor[sensor_num].thr_list) { client_info = list_entry(thr_list, struct qpnp_adc_thr_client_info, list); if (client_info->low_thr_set) { client_info->low_thr_set = false; client_info->notify_low_thr = true; if (client_info->state_req_copy == ADC_TM_HIGH_LOW_THR_ENABLE) client_info->state_req_copy = ADC_TM_HIGH_THR_ENABLE; else client_info->state_req_copy = ADC_TM_LOW_THR_DISABLE; } } } qpnp_adc_tm_manage_thresholds(chip, sensor_num, btm_chan_num); if (adc_tm_high_enable || adc_tm_low_enable) { rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, false); if (rc < 0) { pr_err("multi meas disable for channel failed\n"); goto fail; } rc = qpnp_adc_tm_enable_if_channel_meas(chip); if (rc < 0) { pr_err("re-enabling measurement failed\n"); return rc; } } else pr_debug("No threshold status enable %d for high/low??\n", sensor_mask); fail: mutex_unlock(&chip->adc->adc_lock); if (adc_tm_high_enable || adc_tm_low_enable) schedule_work(&chip->sensor[sensor_num].work); return rc; } static void qpnp_adc_tm_high_thr_work(struct work_struct *work) { struct qpnp_adc_tm_chip *chip = container_of(work, struct qpnp_adc_tm_chip, trigger_high_thr_work); int rc; rc = qpnp_adc_tm_read_status(chip); if (rc < 0) pr_err("adc-tm high thr work failed\n"); return; } static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data) { struct qpnp_adc_tm_chip *chip = data; qpnp_adc_tm_disable(chip); schedule_work(&chip->trigger_high_thr_work); return IRQ_HANDLED; } static void qpnp_adc_tm_low_thr_work(struct work_struct *work) { struct qpnp_adc_tm_chip *chip = container_of(work, struct qpnp_adc_tm_chip, trigger_low_thr_work); int rc; rc = qpnp_adc_tm_read_status(chip); if (rc < 0) pr_err("adc-tm low thr work failed\n"); return; } static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data) { struct qpnp_adc_tm_chip *chip = data; qpnp_adc_tm_disable(chip); schedule_work(&chip->trigger_low_thr_work); return IRQ_HANDLED; } static int qpnp_adc_read_temp(struct thermal_zone_device *thermal, long *temp) { struct qpnp_adc_tm_sensor *adc_tm_sensor = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm_sensor->chip; struct qpnp_vadc_result result; int rc = 0; rc = qpnp_vadc_read(chip->vadc_dev, adc_tm_sensor->vadc_channel_num, &result); if (rc) return rc; *temp = result.physical; return rc; } static struct thermal_zone_device_ops qpnp_adc_tm_thermal_ops = { .get_temp = qpnp_adc_read_temp, .get_mode = qpnp_adc_tm_get_mode, .set_mode = qpnp_adc_tm_set_mode, .get_trip_type = qpnp_adc_tm_get_trip_type, .activate_trip_type = qpnp_adc_tm_activate_trip_type, .get_trip_temp = qpnp_adc_tm_get_trip_temp, .set_trip_temp = qpnp_adc_tm_set_trip_temp, }; int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_tm_btm_param *param) { uint32_t channel, dt_index = 0, scale_type = 0; int rc = 0, i = 0; bool chan_found = false; if (qpnp_adc_tm_is_valid(chip)) { pr_err("chip not valid\n"); return -ENODEV; } if (param->threshold_notification == NULL) { pr_debug("No notification for high/low temp??\n"); return -EINVAL; } mutex_lock(&chip->adc->adc_lock); channel = param->channel; while (i < chip->max_channels_available) { if (chip->adc->adc_channels[i].channel_num == channel) { dt_index = i; chan_found = true; i++; } else i++; } if (!chan_found) { pr_err("not a valid ADC_TM channel\n"); rc = -EINVAL; goto fail_unlock; } rc = qpnp_adc_tm_check_revision(chip, chip->sensor[dt_index].btm_channel_num); if (rc < 0) goto fail_unlock; scale_type = chip->adc->adc_channels[dt_index].adc_scale_fn; if (scale_type >= SCALE_RSCALE_NONE) { rc = -EBADF; goto fail_unlock; } pr_debug("channel:%d, scale_type:%d, dt_idx:%d", channel, scale_type, dt_index); chip->adc->amux_prop->amux_channel = channel; chip->adc->amux_prop->decimation = chip->adc->adc_channels[dt_index].adc_decimation; chip->adc->amux_prop->hw_settle_time = chip->adc->adc_channels[dt_index].hw_settle_time; chip->adc->amux_prop->fast_avg_setup = chip->adc->adc_channels[dt_index].fast_avg_setup; chip->adc->amux_prop->mode_sel = ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT; adc_tm_rscale_fn[scale_type].chan(chip->vadc_dev, param, &chip->adc->amux_prop->chan_prop->low_thr, &chip->adc->amux_prop->chan_prop->high_thr); qpnp_adc_tm_add_to_list(chip, dt_index, param, chip->adc->amux_prop->chan_prop); chip->adc->amux_prop->chan_prop->tm_channel_select = chip->sensor[dt_index].btm_channel_num; chip->adc->amux_prop->chan_prop->state_request = param->state_request; rc = qpnp_adc_tm_configure(chip, chip->adc->amux_prop); if (rc) { pr_err("adc-tm configure failed with %d\n", rc); goto fail_unlock; } chip->sensor[dt_index].scale_type = scale_type; fail_unlock: mutex_unlock(&chip->adc->adc_lock); return rc; } EXPORT_SYMBOL(qpnp_adc_tm_channel_measure); int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_tm_btm_param *param) { uint32_t channel, dt_index = 0, btm_chan_num; u8 sensor_mask = 0; int rc = 0; if (qpnp_adc_tm_is_valid(chip)) return -ENODEV; mutex_lock(&chip->adc->adc_lock); rc = qpnp_adc_tm_disable(chip); if (rc < 0) { pr_err("adc-tm disable failed\n"); goto fail; } rc = qpnp_adc_tm_req_sts_check(chip); if (rc < 0) { pr_err("adc-tm req_sts check failed\n"); goto fail; } channel = param->channel; while ((chip->adc->adc_channels[dt_index].channel_num != channel) && (dt_index < chip->max_channels_available)) dt_index++; if (dt_index >= chip->max_channels_available) { pr_err("not a valid ADC_TMN channel\n"); rc = -EINVAL; goto fail; } btm_chan_num = chip->sensor[dt_index].btm_channel_num; sensor_mask = 1 << chip->sensor[dt_index].sensor_num; rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN, sensor_mask, false); if (rc < 0) { pr_err("low threshold int write failed\n"); goto fail; } rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, sensor_mask, false); if (rc < 0) { pr_err("high threshold int enable failed\n"); goto fail; } rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, false); if (rc < 0) { pr_err("multi measurement en failed\n"); goto fail; } rc = qpnp_adc_tm_enable_if_channel_meas(chip); if (rc < 0) pr_err("re-enabling measurement failed\n"); fail: mutex_unlock(&chip->adc->adc_lock); return rc; } EXPORT_SYMBOL(qpnp_adc_tm_disable_chan_meas); int32_t qpnp_adc_tm_usbid_configure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_tm_btm_param *param) { param->channel = LR_MUX10_PU2_AMUX_USB_ID_LV; return qpnp_adc_tm_channel_measure(chip, param); } EXPORT_SYMBOL(qpnp_adc_tm_usbid_configure); int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip) { struct qpnp_adc_tm_btm_param param; return qpnp_adc_tm_disable_chan_meas(chip, &param); } EXPORT_SYMBOL(qpnp_adc_tm_usbid_end); struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, const char *name) { struct qpnp_adc_tm_chip *chip; struct device_node *node = NULL; char prop_name[QPNP_MAX_PROP_NAME_LEN]; snprintf(prop_name, QPNP_MAX_PROP_NAME_LEN, "qcom,%s-adc_tm", name); node = of_parse_phandle(dev->of_node, prop_name, 0); if (node == NULL) return ERR_PTR(-ENODEV); list_for_each_entry(chip, &qpnp_adc_tm_device_list, list) if (chip->adc->spmi->dev.of_node == node) return chip; return ERR_PTR(-EPROBE_DEFER); } EXPORT_SYMBOL(qpnp_get_adc_tm); static int __devinit qpnp_adc_tm_probe(struct spmi_device *spmi) { struct device_node *node = spmi->dev.of_node, *child; struct qpnp_adc_tm_chip *chip; struct qpnp_adc_drv *adc_qpnp; int32_t count_adc_channel_list = 0, rc, sen_idx = 0, i = 0; u8 thr_init = 0; bool thermal_node = false; for_each_child_of_node(node, child) count_adc_channel_list++; if (!count_adc_channel_list) { pr_err("No channel listing\n"); return -EINVAL; } chip = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_adc_tm_chip) + (count_adc_channel_list * sizeof(struct qpnp_adc_tm_sensor)), GFP_KERNEL); if (!chip) { dev_err(&spmi->dev, "Unable to allocate memory\n"); return -ENOMEM; } adc_qpnp = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_adc_drv), GFP_KERNEL); if (!adc_qpnp) { dev_err(&spmi->dev, "Unable to allocate memory\n"); rc = -ENOMEM; goto fail; } chip->dev = &(spmi->dev); chip->adc = adc_qpnp; rc = qpnp_adc_get_devicetree_data(spmi, chip->adc); if (rc) { dev_err(&spmi->dev, "failed to read device tree\n"); goto fail; } mutex_init(&chip->adc->adc_lock); chip->adc->adc_high_thr_irq = spmi_get_irq_byname(spmi, NULL, "high-thr-en-set"); if (chip->adc->adc_high_thr_irq < 0) { pr_err("Invalid irq\n"); rc = -ENXIO; goto fail; } chip->adc->adc_low_thr_irq = spmi_get_irq_byname(spmi, NULL, "low-thr-en-set"); if (chip->adc->adc_low_thr_irq < 0) { pr_err("Invalid irq\n"); rc = -ENXIO; goto fail; } chip->vadc_dev = qpnp_get_vadc(&spmi->dev, "adc_tm"); if (IS_ERR(chip->vadc_dev)) { rc = PTR_ERR(chip->vadc_dev); if (rc != -EPROBE_DEFER) pr_err("vadc property missing, rc=%d\n", rc); goto fail; } for_each_child_of_node(node, child) { char name[25]; int btm_channel_num, timer_select = 0; rc = of_property_read_u32(child, "qcom,btm-channel-number", &btm_channel_num); if (rc) { pr_err("Invalid btm channel number\n"); goto fail; } rc = of_property_read_u32(child, "qcom,meas-interval-timer-idx", &timer_select); if (rc) { pr_debug("Default to timer1 with interval of 1 sec\n"); chip->sensor[sen_idx].timer_select = ADC_MEAS_TIMER_SELECT1; chip->sensor[sen_idx].meas_interval = ADC_MEAS1_INTERVAL_1S; } else { if (timer_select >= ADC_MEAS_TIMER_NUM) { pr_err("Invalid timer selection number\n"); goto fail; } chip->sensor[sen_idx].timer_select = timer_select; if (timer_select == ADC_MEAS_TIMER_SELECT2) chip->sensor[sen_idx].meas_interval = ADC_MEAS2_INTERVAL_500MS; if (timer_select == ADC_MEAS_TIMER_SELECT3) chip->sensor[sen_idx].meas_interval = ADC_MEAS3_INTERVAL_4S; } chip->sensor[sen_idx].btm_channel_num = btm_channel_num; chip->sensor[sen_idx].vadc_channel_num = chip->adc->adc_channels[sen_idx].channel_num; chip->sensor[sen_idx].sensor_num = sen_idx; chip->sensor[sen_idx].chip = chip; pr_debug("btm_chan:%x, vadc_chan:%x\n", btm_channel_num, chip->adc->adc_channels[sen_idx].channel_num); thermal_node = of_property_read_bool(child, "qcom,thermal-node"); if (thermal_node) { pr_debug("thermal node%x\n", btm_channel_num); chip->sensor[sen_idx].mode = THERMAL_DEVICE_DISABLED; chip->sensor[sen_idx].thermal_node = true; snprintf(name, sizeof(name), "%s", chip->adc->adc_channels[sen_idx].name); chip->sensor[sen_idx].meas_interval = QPNP_ADC_TM_MEAS_INTERVAL; chip->sensor[sen_idx].low_thr = QPNP_ADC_TM_M0_LOW_THR; chip->sensor[sen_idx].high_thr = QPNP_ADC_TM_M0_HIGH_THR; chip->sensor[sen_idx].tz_dev = thermal_zone_device_register(name, ADC_TM_TRIP_NUM, &chip->sensor[sen_idx], &qpnp_adc_tm_thermal_ops, 0, 0, 0, 0); if (IS_ERR(chip->sensor[sen_idx].tz_dev)) pr_err("thermal device register failed.\n"); } INIT_WORK(&chip->sensor[sen_idx].work, notify_adc_tm_fn); INIT_LIST_HEAD(&chip->sensor[sen_idx].thr_list); sen_idx++; } chip->max_channels_available = count_adc_channel_list; INIT_WORK(&chip->trigger_high_thr_work, qpnp_adc_tm_high_thr_work); INIT_WORK(&chip->trigger_low_thr_work, qpnp_adc_tm_low_thr_work); rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_HIGH_THR_INT_EN, thr_init); if (rc < 0) { pr_err("high thr init failed\n"); goto fail; } rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_LOW_THR_INT_EN, thr_init); if (rc < 0) { pr_err("low thr init failed\n"); goto fail; } rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN, thr_init); if (rc < 0) { pr_err("multi meas en failed\n"); goto fail; } rc = devm_request_irq(&spmi->dev, chip->adc->adc_high_thr_irq, qpnp_adc_tm_high_thr_isr, IRQF_TRIGGER_RISING, "qpnp_adc_tm_high_interrupt", chip); if (rc) { dev_err(&spmi->dev, "failed to request adc irq\n"); goto fail; } else { enable_irq_wake(chip->adc->adc_high_thr_irq); } rc = devm_request_irq(&spmi->dev, chip->adc->adc_low_thr_irq, qpnp_adc_tm_low_thr_isr, IRQF_TRIGGER_RISING, "qpnp_adc_tm_low_interrupt", chip); if (rc) { dev_err(&spmi->dev, "failed to request adc irq\n"); goto fail; } else { enable_irq_wake(chip->adc->adc_low_thr_irq); } dev_set_drvdata(&spmi->dev, chip); list_add(&chip->list, &qpnp_adc_tm_device_list); pr_debug("OK\n"); return 0; fail: for_each_child_of_node(node, child) { thermal_node = of_property_read_bool(child, "qcom,thermal-node"); if (thermal_node) thermal_zone_device_unregister(chip->sensor[i].tz_dev); i++; } dev_set_drvdata(&spmi->dev, NULL); return rc; } static int __devexit qpnp_adc_tm_remove(struct spmi_device *spmi) { struct qpnp_adc_tm_chip *chip = dev_get_drvdata(&spmi->dev); struct device_node *node = spmi->dev.of_node, *child; bool thermal_node = false; int i = 0; for_each_child_of_node(node, child) { thermal_node = of_property_read_bool(child, "qcom,thermal-node"); if (thermal_node) thermal_zone_device_unregister(chip->sensor[i].tz_dev); i++; } dev_set_drvdata(&spmi->dev, NULL); return 0; } static const struct of_device_id qpnp_adc_tm_match_table[] = { { .compatible = "qcom,qpnp-adc-tm" }, {} }; static struct spmi_driver qpnp_adc_tm_driver = { .driver = { .name = "qcom,qpnp-adc-tm", .of_match_table = qpnp_adc_tm_match_table, }, .probe = qpnp_adc_tm_probe, .remove = qpnp_adc_tm_remove, }; static int __init qpnp_adc_tm_init(void) { return spmi_driver_register(&qpnp_adc_tm_driver); } module_init(qpnp_adc_tm_init); static void __exit qpnp_adc_tm_exit(void) { spmi_driver_unregister(&qpnp_adc_tm_driver); } module_exit(qpnp_adc_tm_exit); MODULE_DESCRIPTION("QPNP PMIC ADC Threshold Monitoring driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
showp1984/bricked-endeavoru
net/sctp/sm_statetable.c
314
34363
/* SCTP kernel implementation * (C) Copyright IBM Corp. 2001, 2004 * Copyright (c) 1999-2000 Cisco, Inc. * Copyright (c) 1999-2001 Motorola, Inc. * Copyright (c) 2001 Intel Corp. * Copyright (c) 2001 Nokia, Inc. * * This file is part of the SCTP kernel implementation * * These are the state tables for the SCTP state machine. * * This SCTP implementation is free software; * you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This SCTP implementation is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied * ************************ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU CC; see the file COPYING. If not, write to * the Free Software Foundation, 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Please send any bug reports or fixes you make to the * email address(es): * lksctp developers <lksctp-developers@lists.sourceforge.net> * * Or submit a bug report through the following website: * http://www.sf.net/projects/lksctp * * Written or modified by: * La Monte H.P. Yarroll <piggy@acm.org> * Karl Knutson <karl@athena.chicago.il.us> * Jon Grimm <jgrimm@us.ibm.com> * Hui Huang <hui.huang@nokia.com> * Daisy Chang <daisyc@us.ibm.com> * Ardelle Fan <ardelle.fan@intel.com> * Sridhar Samudrala <sri@us.ibm.com> * * Any bugs reported given to us we will try to fix... any fixes shared will * be incorporated into the next SCTP release. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/skbuff.h> #include <net/sctp/sctp.h> #include <net/sctp/sm.h> static const sctp_sm_table_entry_t primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES]; static const sctp_sm_table_entry_t other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES]; static const sctp_sm_table_entry_t timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES]; static const sctp_sm_table_entry_t *sctp_chunk_event_lookup(sctp_cid_t cid, sctp_state_t state); static const sctp_sm_table_entry_t bug = { .fn = sctp_sf_bug, .name = "sctp_sf_bug" }; #define DO_LOOKUP(_max, _type, _table) \ ({ \ const sctp_sm_table_entry_t *rtn; \ \ if ((event_subtype._type > (_max))) { \ pr_warn("table %p possible attack: event %d exceeds max %d\n", \ _table, event_subtype._type, _max); \ rtn = &bug; \ } else \ rtn = &_table[event_subtype._type][(int)state]; \ \ rtn; \ }) const sctp_sm_table_entry_t *sctp_sm_lookup_event(sctp_event_t event_type, sctp_state_t state, sctp_subtype_t event_subtype) { switch (event_type) { case SCTP_EVENT_T_CHUNK: return sctp_chunk_event_lookup(event_subtype.chunk, state); case SCTP_EVENT_T_TIMEOUT: return DO_LOOKUP(SCTP_EVENT_TIMEOUT_MAX, timeout, timeout_event_table); case SCTP_EVENT_T_OTHER: return DO_LOOKUP(SCTP_EVENT_OTHER_MAX, other, other_event_table); case SCTP_EVENT_T_PRIMITIVE: return DO_LOOKUP(SCTP_EVENT_PRIMITIVE_MAX, primitive, primitive_event_table); default: /* Yikes! We got an illegal event type. */ return &bug; } } #define TYPE_SCTP_FUNC(func) {.fn = func, .name = #func} #define TYPE_SCTP_DATA { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_eat_data_fast_4_4), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_DATA */ #define TYPE_SCTP_INIT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_1B_init), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_reshutack), \ } /* TYPE_SCTP_INIT */ #define TYPE_SCTP_INIT_ACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_3_initack), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_1C_ack), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_INIT_ACK */ #define TYPE_SCTP_SACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_SACK */ #define TYPE_SCTP_HEARTBEAT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ /* This should not happen, but we are nice. */ \ TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \ } /* TYPE_SCTP_HEARTBEAT */ #define TYPE_SCTP_HEARTBEAT_ACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_violation), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_HEARTBEAT_ACK */ #define TYPE_SCTP_ABORT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_pdiscard), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_wait_abort), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_abort), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_abort), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_abort), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_abort), \ } /* TYPE_SCTP_ABORT */ #define TYPE_SCTP_SHUTDOWN { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_shut_ctsn), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_SHUTDOWN */ #define TYPE_SCTP_SHUTDOWN_ACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_violation), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_violation), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_violation), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \ } /* TYPE_SCTP_SHUTDOWN_ACK */ #define TYPE_SCTP_ERROR { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_err), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_operr_notify), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_operr_notify), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_operr_notify), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_ERROR */ #define TYPE_SCTP_COOKIE_ECHO { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_1D_ce), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \ } /* TYPE_SCTP_COOKIE_ECHO */ #define TYPE_SCTP_COOKIE_ACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_5_1E_ca), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_COOKIE_ACK */ #define TYPE_SCTP_ECN_ECNE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecne), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecne), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecne), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecne), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecne), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_ECN_ECNE */ #define TYPE_SCTP_ECN_CWR { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_ECN_CWR */ #define TYPE_SCTP_SHUTDOWN_COMPLETE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_4_C), \ } /* TYPE_SCTP_SHUTDOWN_COMPLETE */ /* The primary index for this table is the chunk type. * The secondary index for this table is the state. * * For base protocol (RFC 2960). */ static const sctp_sm_table_entry_t chunk_event_table[SCTP_NUM_BASE_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_DATA, TYPE_SCTP_INIT, TYPE_SCTP_INIT_ACK, TYPE_SCTP_SACK, TYPE_SCTP_HEARTBEAT, TYPE_SCTP_HEARTBEAT_ACK, TYPE_SCTP_ABORT, TYPE_SCTP_SHUTDOWN, TYPE_SCTP_SHUTDOWN_ACK, TYPE_SCTP_ERROR, TYPE_SCTP_COOKIE_ECHO, TYPE_SCTP_COOKIE_ACK, TYPE_SCTP_ECN_ECNE, TYPE_SCTP_ECN_CWR, TYPE_SCTP_SHUTDOWN_COMPLETE, }; /* state_fn_t chunk_event_table[][] */ #define TYPE_SCTP_ASCONF { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_ASCONF */ #define TYPE_SCTP_ASCONF_ACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_ASCONF_ACK */ /* The primary index for this table is the chunk type. * The secondary index for this table is the state. */ static const sctp_sm_table_entry_t addip_chunk_event_table[SCTP_NUM_ADDIP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_ASCONF, TYPE_SCTP_ASCONF_ACK, }; /*state_fn_t addip_chunk_event_table[][] */ #define TYPE_SCTP_FWD_TSN { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn_fast), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ } /* TYPE_SCTP_FWD_TSN */ /* The primary index for this table is the chunk type. * The secondary index for this table is the state. */ static const sctp_sm_table_entry_t prsctp_chunk_event_table[SCTP_NUM_PRSCTP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_FWD_TSN, }; /*state_fn_t prsctp_chunk_event_table[][] */ #define TYPE_SCTP_AUTH { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ootb), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_eat_auth), \ } /* TYPE_SCTP_AUTH */ /* The primary index for this table is the chunk type. * The secondary index for this table is the state. */ static const sctp_sm_table_entry_t auth_chunk_event_table[SCTP_NUM_AUTH_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_AUTH, }; /*state_fn_t auth_chunk_event_table[][] */ static const sctp_sm_table_entry_t chunk_event_table_unknown[SCTP_STATE_NUM_STATES] = { /* SCTP_STATE_EMPTY */ TYPE_SCTP_FUNC(sctp_sf_ootb), /* SCTP_STATE_CLOSED */ TYPE_SCTP_FUNC(sctp_sf_ootb), /* SCTP_STATE_COOKIE_WAIT */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_COOKIE_ECHOED */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_ESTABLISHED */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_SHUTDOWN_PENDING */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_SHUTDOWN_SENT */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_SHUTDOWN_RECEIVED */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), /* SCTP_STATE_SHUTDOWN_ACK_SENT */ TYPE_SCTP_FUNC(sctp_sf_unk_chunk), }; /* chunk unknown */ #define TYPE_SCTP_PRIMITIVE_ASSOCIATE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_asoc), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_not_impl), \ } /* TYPE_SCTP_PRIMITIVE_ASSOCIATE */ #define TYPE_SCTP_PRIMITIVE_SHUTDOWN { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_shutdown), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_shutdown),\ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_prm_shutdown), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \ } /* TYPE_SCTP_PRIMITIVE_SHUTDOWN */ #define TYPE_SCTP_PRIMITIVE_ABORT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_abort), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_abort), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_prm_abort), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_prm_abort), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_prm_abort), \ } /* TYPE_SCTP_PRIMITIVE_ABORT */ #define TYPE_SCTP_PRIMITIVE_SEND { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \ } /* TYPE_SCTP_PRIMITIVE_SEND */ #define TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \ } /* TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT */ #define TYPE_SCTP_PRIMITIVE_ASCONF { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_error_closed), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \ } /* TYPE_SCTP_PRIMITIVE_ASCONF */ /* The primary index for this table is the primitive type. * The secondary index for this table is the state. */ static const sctp_sm_table_entry_t primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_PRIMITIVE_ASSOCIATE, TYPE_SCTP_PRIMITIVE_SHUTDOWN, TYPE_SCTP_PRIMITIVE_ABORT, TYPE_SCTP_PRIMITIVE_SEND, TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT, TYPE_SCTP_PRIMITIVE_ASCONF, }; #define TYPE_SCTP_OTHER_NO_PENDING_TSN { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_start_shutdown), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ } #define TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_cookie_wait_icmp_abort), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_ignore_other), \ } static const sctp_sm_table_entry_t other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_OTHER_NO_PENDING_TSN, TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH, }; #define TYPE_SCTP_EVENT_TIMEOUT_NONE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_t1_cookie_timer_expire), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T1_INIT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_t1_init_timer_expire), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T3_RTX { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T4_RTO { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_t4_timer_expire), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_t5_timer_expire), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_SACK { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_bug), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } #define TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE { \ /* SCTP_STATE_EMPTY */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_CLOSED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_WAIT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_COOKIE_ECHOED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_ESTABLISHED */ \ TYPE_SCTP_FUNC(sctp_sf_autoclose_timer_expire), \ /* SCTP_STATE_SHUTDOWN_PENDING */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_RECEIVED */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ /* SCTP_STATE_SHUTDOWN_ACK_SENT */ \ TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \ } static const sctp_sm_table_entry_t timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES] = { TYPE_SCTP_EVENT_TIMEOUT_NONE, TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE, TYPE_SCTP_EVENT_TIMEOUT_T1_INIT, TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN, TYPE_SCTP_EVENT_TIMEOUT_T3_RTX, TYPE_SCTP_EVENT_TIMEOUT_T4_RTO, TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD, TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT, TYPE_SCTP_EVENT_TIMEOUT_SACK, TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE, }; static const sctp_sm_table_entry_t *sctp_chunk_event_lookup(sctp_cid_t cid, sctp_state_t state) { if (state > SCTP_STATE_MAX) return &bug; if (cid <= SCTP_CID_BASE_MAX) return &chunk_event_table[cid][state]; if (sctp_prsctp_enable) { if (cid == SCTP_CID_FWD_TSN) return &prsctp_chunk_event_table[0][state]; } if (sctp_addip_enable) { if (cid == SCTP_CID_ASCONF) return &addip_chunk_event_table[0][state]; if (cid == SCTP_CID_ASCONF_ACK) return &addip_chunk_event_table[1][state]; } if (sctp_auth_enable) { if (cid == SCTP_CID_AUTH) return &auth_chunk_event_table[0][state]; } return &chunk_event_table_unknown[state]; }
gpl-2.0
pknithis/linux
arch/mips/kernel/proc.c
826
5100
/* * Copyright (C) 1995, 1996, 2001 Ralf Baechle * Copyright (C) 2001, 2004 MIPS Technologies, Inc. * Copyright (C) 2004 Maciej W. Rozycki */ #include <linux/delay.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/seq_file.h> #include <asm/bootinfo.h> #include <asm/cpu.h> #include <asm/cpu-features.h> #include <asm/idle.h> #include <asm/mipsregs.h> #include <asm/processor.h> #include <asm/prom.h> unsigned int vced_count, vcei_count; /* * * No lock; only written during early bootup by CPU 0. * */ static RAW_NOTIFIER_HEAD(proc_cpuinfo_chain); int __ref register_proc_cpuinfo_notifier(struct notifier_block *nb) { return raw_notifier_chain_register(&proc_cpuinfo_chain, nb); } int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v) { return raw_notifier_call_chain(&proc_cpuinfo_chain, val, v); } static int show_cpuinfo(struct seq_file *m, void *v) { struct proc_cpuinfo_notifier_args proc_cpuinfo_notifier_args; unsigned long n = (unsigned long) v - 1; unsigned int version = cpu_data[n].processor_id; unsigned int fp_vers = cpu_data[n].fpu_id; char fmt [64]; int i; #ifdef CONFIG_SMP if (!cpu_online(n)) return 0; #endif /* * For the first processor also print the system type */ if (n == 0) { seq_printf(m, "system type\t\t: %s\n", get_system_type()); if (mips_get_machine_name()) seq_printf(m, "machine\t\t\t: %s\n", mips_get_machine_name()); } seq_printf(m, "processor\t\t: %ld\n", n); sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n", cpu_data[n].options & MIPS_CPU_FPU ? " FPU V%d.%d" : ""); seq_printf(m, fmt, __cpu_name[n], (version >> 4) & 0x0f, version & 0x0f, (fp_vers >> 4) & 0x0f, fp_vers & 0x0f); seq_printf(m, "BogoMIPS\t\t: %u.%02u\n", cpu_data[n].udelay_val / (500000/HZ), (cpu_data[n].udelay_val / (5000/HZ)) % 100); seq_printf(m, "wait instruction\t: %s\n", cpu_wait ? "yes" : "no"); seq_printf(m, "microsecond timers\t: %s\n", cpu_has_counter ? "yes" : "no"); seq_printf(m, "tlb_entries\t\t: %d\n", cpu_data[n].tlbsize); seq_printf(m, "extra interrupt vector\t: %s\n", cpu_has_divec ? "yes" : "no"); seq_printf(m, "hardware watchpoint\t: %s", cpu_has_watch ? "yes, " : "no\n"); if (cpu_has_watch) { seq_printf(m, "count: %d, address/irw mask: [", cpu_data[n].watch_reg_count); for (i = 0; i < cpu_data[n].watch_reg_count; i++) seq_printf(m, "%s0x%04x", i ? ", " : "" , cpu_data[n].watch_reg_masks[i]); seq_printf(m, "]\n"); } seq_printf(m, "isa\t\t\t:"); if (cpu_has_mips_r1) seq_printf(m, " mips1"); if (cpu_has_mips_2) seq_printf(m, "%s", " mips2"); if (cpu_has_mips_3) seq_printf(m, "%s", " mips3"); if (cpu_has_mips_4) seq_printf(m, "%s", " mips4"); if (cpu_has_mips_5) seq_printf(m, "%s", " mips5"); if (cpu_has_mips32r1) seq_printf(m, "%s", " mips32r1"); if (cpu_has_mips32r2) seq_printf(m, "%s", " mips32r2"); if (cpu_has_mips32r6) seq_printf(m, "%s", " mips32r6"); if (cpu_has_mips64r1) seq_printf(m, "%s", " mips64r1"); if (cpu_has_mips64r2) seq_printf(m, "%s", " mips64r2"); if (cpu_has_mips64r6) seq_printf(m, "%s", " mips64r6"); seq_printf(m, "\n"); seq_printf(m, "ASEs implemented\t:"); if (cpu_has_mips16) seq_printf(m, "%s", " mips16"); if (cpu_has_mdmx) seq_printf(m, "%s", " mdmx"); if (cpu_has_mips3d) seq_printf(m, "%s", " mips3d"); if (cpu_has_smartmips) seq_printf(m, "%s", " smartmips"); if (cpu_has_dsp) seq_printf(m, "%s", " dsp"); if (cpu_has_dsp2) seq_printf(m, "%s", " dsp2"); if (cpu_has_mipsmt) seq_printf(m, "%s", " mt"); if (cpu_has_mmips) seq_printf(m, "%s", " micromips"); if (cpu_has_vz) seq_printf(m, "%s", " vz"); if (cpu_has_msa) seq_printf(m, "%s", " msa"); if (cpu_has_eva) seq_printf(m, "%s", " eva"); if (cpu_has_htw) seq_printf(m, "%s", " htw"); if (cpu_has_xpa) seq_printf(m, "%s", " xpa"); seq_printf(m, "\n"); if (cpu_has_mmips) { seq_printf(m, "micromips kernel\t: %s\n", (read_c0_config3() & MIPS_CONF3_ISA_OE) ? "yes" : "no"); } seq_printf(m, "shadow register sets\t: %d\n", cpu_data[n].srsets); seq_printf(m, "kscratch registers\t: %d\n", hweight8(cpu_data[n].kscratch_mask)); seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package); seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core); sprintf(fmt, "VCE%%c exceptions\t\t: %s\n", cpu_has_vce ? "%u" : "not available"); seq_printf(m, fmt, 'D', vced_count); seq_printf(m, fmt, 'I', vcei_count); proc_cpuinfo_notifier_args.m = m; proc_cpuinfo_notifier_args.n = n; raw_notifier_call_chain(&proc_cpuinfo_chain, 0, &proc_cpuinfo_notifier_args); seq_printf(m, "\n"); return 0; } static void *c_start(struct seq_file *m, loff_t *pos) { unsigned long i = *pos; return i < NR_CPUS ? (void *) (i + 1) : NULL; } static void *c_next(struct seq_file *m, void *v, loff_t *pos) { ++*pos; return c_start(m, pos); } static void c_stop(struct seq_file *m, void *v) { } const struct seq_operations cpuinfo_op = { .start = c_start, .next = c_next, .stop = c_stop, .show = show_cpuinfo, };
gpl-2.0
PennPanda/linux
drivers/gpu/drm/gma500/psb_irq.c
1338
18032
/************************************************************************** * Copyright (c) 2007, Intel Corporation. * All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to * develop this driver. * **************************************************************************/ /* */ #include <drm/drmP.h> #include "psb_drv.h" #include "psb_reg.h" #include "psb_intel_reg.h" #include "power.h" #include "psb_irq.h" #include "mdfld_output.h" /* * inline functions */ static inline u32 psb_pipestat(int pipe) { if (pipe == 0) return PIPEASTAT; if (pipe == 1) return PIPEBSTAT; if (pipe == 2) return PIPECSTAT; BUG(); } static inline u32 mid_pipe_event(int pipe) { if (pipe == 0) return _PSB_PIPEA_EVENT_FLAG; if (pipe == 1) return _MDFLD_PIPEB_EVENT_FLAG; if (pipe == 2) return _MDFLD_PIPEC_EVENT_FLAG; BUG(); } static inline u32 mid_pipe_vsync(int pipe) { if (pipe == 0) return _PSB_VSYNC_PIPEA_FLAG; if (pipe == 1) return _PSB_VSYNC_PIPEB_FLAG; if (pipe == 2) return _MDFLD_PIPEC_VBLANK_FLAG; BUG(); } static inline u32 mid_pipeconf(int pipe) { if (pipe == 0) return PIPEACONF; if (pipe == 1) return PIPEBCONF; if (pipe == 2) return PIPECCONF; BUG(); } void psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask) { if ((dev_priv->pipestat[pipe] & mask) != mask) { u32 reg = psb_pipestat(pipe); dev_priv->pipestat[pipe] |= mask; /* Enable the interrupt, clear any pending status */ if (gma_power_begin(dev_priv->dev, false)) { u32 writeVal = PSB_RVDC32(reg); writeVal |= (mask | (mask >> 16)); PSB_WVDC32(writeVal, reg); (void) PSB_RVDC32(reg); gma_power_end(dev_priv->dev); } } } void psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask) { if ((dev_priv->pipestat[pipe] & mask) != 0) { u32 reg = psb_pipestat(pipe); dev_priv->pipestat[pipe] &= ~mask; if (gma_power_begin(dev_priv->dev, false)) { u32 writeVal = PSB_RVDC32(reg); writeVal &= ~mask; PSB_WVDC32(writeVal, reg); (void) PSB_RVDC32(reg); gma_power_end(dev_priv->dev); } } } static void mid_enable_pipe_event(struct drm_psb_private *dev_priv, int pipe) { if (gma_power_begin(dev_priv->dev, false)) { u32 pipe_event = mid_pipe_event(pipe); dev_priv->vdc_irq_mask |= pipe_event; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); gma_power_end(dev_priv->dev); } } static void mid_disable_pipe_event(struct drm_psb_private *dev_priv, int pipe) { if (dev_priv->pipestat[pipe] == 0) { if (gma_power_begin(dev_priv->dev, false)) { u32 pipe_event = mid_pipe_event(pipe); dev_priv->vdc_irq_mask &= ~pipe_event; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); gma_power_end(dev_priv->dev); } } } /** * Display controller interrupt handler for pipe event. * */ static void mid_pipe_event_handler(struct drm_device *dev, int pipe) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; uint32_t pipe_stat_val = 0; uint32_t pipe_stat_reg = psb_pipestat(pipe); uint32_t pipe_enable = dev_priv->pipestat[pipe]; uint32_t pipe_status = dev_priv->pipestat[pipe] >> 16; uint32_t pipe_clear; uint32_t i = 0; spin_lock(&dev_priv->irqmask_lock); pipe_stat_val = PSB_RVDC32(pipe_stat_reg); pipe_stat_val &= pipe_enable | pipe_status; pipe_stat_val &= pipe_stat_val >> 16; spin_unlock(&dev_priv->irqmask_lock); /* Clear the 2nd level interrupt status bits * Sometimes the bits are very sticky so we repeat until they unstick */ for (i = 0; i < 0xffff; i++) { PSB_WVDC32(PSB_RVDC32(pipe_stat_reg), pipe_stat_reg); pipe_clear = PSB_RVDC32(pipe_stat_reg) & pipe_status; if (pipe_clear == 0) break; } if (pipe_clear) dev_err(dev->dev, "%s, can't clear status bits for pipe %d, its value = 0x%x.\n", __func__, pipe, PSB_RVDC32(pipe_stat_reg)); if (pipe_stat_val & PIPE_VBLANK_STATUS) drm_handle_vblank(dev, pipe); if (pipe_stat_val & PIPE_TE_STATUS) drm_handle_vblank(dev, pipe); } /* * Display controller interrupt handler. */ static void psb_vdc_interrupt(struct drm_device *dev, uint32_t vdc_stat) { if (vdc_stat & _PSB_IRQ_ASLE) psb_intel_opregion_asle_intr(dev); if (vdc_stat & _PSB_VSYNC_PIPEA_FLAG) mid_pipe_event_handler(dev, 0); if (vdc_stat & _PSB_VSYNC_PIPEB_FLAG) mid_pipe_event_handler(dev, 1); } /* * SGX interrupt handler */ static void psb_sgx_interrupt(struct drm_device *dev, u32 stat_1, u32 stat_2) { struct drm_psb_private *dev_priv = dev->dev_private; u32 val, addr; int error = false; if (stat_1 & _PSB_CE_TWOD_COMPLETE) val = PSB_RSGX32(PSB_CR_2D_BLIT_STATUS); if (stat_2 & _PSB_CE2_BIF_REQUESTER_FAULT) { val = PSB_RSGX32(PSB_CR_BIF_INT_STAT); addr = PSB_RSGX32(PSB_CR_BIF_FAULT); if (val) { if (val & _PSB_CBI_STAT_PF_N_RW) DRM_ERROR("SGX MMU page fault:"); else DRM_ERROR("SGX MMU read / write protection fault:"); if (val & _PSB_CBI_STAT_FAULT_CACHE) DRM_ERROR("\tCache requestor"); if (val & _PSB_CBI_STAT_FAULT_TA) DRM_ERROR("\tTA requestor"); if (val & _PSB_CBI_STAT_FAULT_VDM) DRM_ERROR("\tVDM requestor"); if (val & _PSB_CBI_STAT_FAULT_2D) DRM_ERROR("\t2D requestor"); if (val & _PSB_CBI_STAT_FAULT_PBE) DRM_ERROR("\tPBE requestor"); if (val & _PSB_CBI_STAT_FAULT_TSP) DRM_ERROR("\tTSP requestor"); if (val & _PSB_CBI_STAT_FAULT_ISP) DRM_ERROR("\tISP requestor"); if (val & _PSB_CBI_STAT_FAULT_USSEPDS) DRM_ERROR("\tUSSEPDS requestor"); if (val & _PSB_CBI_STAT_FAULT_HOST) DRM_ERROR("\tHost requestor"); DRM_ERROR("\tMMU failing address is 0x%08x.\n", (unsigned int)addr); error = true; } } /* Clear bits */ PSB_WSGX32(stat_1, PSB_CR_EVENT_HOST_CLEAR); PSB_WSGX32(stat_2, PSB_CR_EVENT_HOST_CLEAR2); PSB_RSGX32(PSB_CR_EVENT_HOST_CLEAR2); } irqreturn_t psb_irq_handler(int irq, void *arg) { struct drm_device *dev = arg; struct drm_psb_private *dev_priv = dev->dev_private; uint32_t vdc_stat, dsp_int = 0, sgx_int = 0, hotplug_int = 0; u32 sgx_stat_1, sgx_stat_2; int handled = 0; spin_lock(&dev_priv->irqmask_lock); vdc_stat = PSB_RVDC32(PSB_INT_IDENTITY_R); if (vdc_stat & (_PSB_PIPE_EVENT_FLAG|_PSB_IRQ_ASLE)) dsp_int = 1; /* FIXME: Handle Medfield if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG) dsp_int = 1; */ if (vdc_stat & _PSB_IRQ_SGX_FLAG) sgx_int = 1; if (vdc_stat & _PSB_IRQ_DISP_HOTSYNC) hotplug_int = 1; vdc_stat &= dev_priv->vdc_irq_mask; spin_unlock(&dev_priv->irqmask_lock); if (dsp_int && gma_power_is_on(dev)) { psb_vdc_interrupt(dev, vdc_stat); handled = 1; } if (sgx_int) { sgx_stat_1 = PSB_RSGX32(PSB_CR_EVENT_STATUS); sgx_stat_2 = PSB_RSGX32(PSB_CR_EVENT_STATUS2); psb_sgx_interrupt(dev, sgx_stat_1, sgx_stat_2); handled = 1; } /* Note: this bit has other meanings on some devices, so we will need to address that later if it ever matters */ if (hotplug_int && dev_priv->ops->hotplug) { handled = dev_priv->ops->hotplug(dev); REG_WRITE(PORT_HOTPLUG_STAT, REG_READ(PORT_HOTPLUG_STAT)); } PSB_WVDC32(vdc_stat, PSB_INT_IDENTITY_R); (void) PSB_RVDC32(PSB_INT_IDENTITY_R); rmb(); if (!handled) return IRQ_NONE; return IRQ_HANDLED; } void psb_irq_preinstall(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); if (gma_power_is_on(dev)) { PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); PSB_WVDC32(0x00000000, PSB_INT_MASK_R); PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); PSB_WSGX32(0x00000000, PSB_CR_EVENT_HOST_ENABLE); PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE); } if (dev->vblank[0].enabled) dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG; if (dev->vblank[1].enabled) dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG; /* FIXME: Handle Medfield irq mask if (dev->vblank[1].enabled) dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG; if (dev->vblank[2].enabled) dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG; */ /* Revisit this area - want per device masks ? */ if (dev_priv->ops->hotplug) dev_priv->vdc_irq_mask |= _PSB_IRQ_DISP_HOTSYNC; dev_priv->vdc_irq_mask |= _PSB_IRQ_ASLE | _PSB_IRQ_SGX_FLAG; /* This register is safe even if display island is off */ PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } int psb_irq_postinstall(struct drm_device *dev) { struct drm_psb_private *dev_priv = dev->dev_private; unsigned long irqflags; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); /* Enable 2D and MMU fault interrupts */ PSB_WSGX32(_PSB_CE2_BIF_REQUESTER_FAULT, PSB_CR_EVENT_HOST_ENABLE2); PSB_WSGX32(_PSB_CE_TWOD_COMPLETE, PSB_CR_EVENT_HOST_ENABLE); PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE); /* Post */ /* This register is safe even if display island is off */ PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); if (dev->vblank[0].enabled) psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); else psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); if (dev->vblank[1].enabled) psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); else psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); if (dev->vblank[2].enabled) psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); else psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); if (dev_priv->ops->hotplug_enable) dev_priv->ops->hotplug_enable(dev, true); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); return 0; } void psb_irq_uninstall(struct drm_device *dev) { struct drm_psb_private *dev_priv = dev->dev_private; unsigned long irqflags; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); if (dev_priv->ops->hotplug_enable) dev_priv->ops->hotplug_enable(dev, false); PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); if (dev->vblank[0].enabled) psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); if (dev->vblank[1].enabled) psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); if (dev->vblank[2].enabled) psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG | _PSB_IRQ_MSVDX_FLAG | _LNC_IRQ_TOPAZ_FLAG; /* These two registers are safe even if display island is off */ PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); wmb(); /* This register is safe even if display island is off */ PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } void psb_irq_turn_on_dpst(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; u32 hist_reg; u32 pwm_reg; if (gma_power_begin(dev, false)) { PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL); hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL); PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL); hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL); PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); PSB_WVDC32(pwm_reg | PWM_PHASEIN_ENABLE | PWM_PHASEIN_INT_ENABLE, PWM_CONTROL_LOGIC); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); psb_enable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE); hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL); PSB_WVDC32(hist_reg | HISTOGRAM_INT_CTRL_CLEAR, HISTOGRAM_INT_CONTROL); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE, PWM_CONTROL_LOGIC); gma_power_end(dev); } } int psb_irq_enable_dpst(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); /* enable DPST */ mid_enable_pipe_event(dev_priv, 0); psb_irq_turn_on_dpst(dev); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); return 0; } void psb_irq_turn_off_dpst(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; u32 hist_reg; u32 pwm_reg; if (gma_power_begin(dev, false)) { PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL); hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL); psb_disable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); PSB_WVDC32(pwm_reg & ~PWM_PHASEIN_INT_ENABLE, PWM_CONTROL_LOGIC); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); gma_power_end(dev); } } int psb_irq_disable_dpst(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); mid_disable_pipe_event(dev_priv, 0); psb_irq_turn_off_dpst(dev); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); return 0; } /* * It is used to enable VBLANK interrupt */ int psb_enable_vblank(struct drm_device *dev, int pipe) { struct drm_psb_private *dev_priv = dev->dev_private; unsigned long irqflags; uint32_t reg_val = 0; uint32_t pipeconf_reg = mid_pipeconf(pipe); /* Medfield is different - we should perhaps extract out vblank and blacklight etc ops */ if (IS_MFLD(dev)) return mdfld_enable_te(dev, pipe); if (gma_power_begin(dev, false)) { reg_val = REG_READ(pipeconf_reg); gma_power_end(dev); } if (!(reg_val & PIPEACONF_ENABLE)) return -EINVAL; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); if (pipe == 0) dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG; else if (pipe == 1) dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); return 0; } /* * It is used to disable VBLANK interrupt */ void psb_disable_vblank(struct drm_device *dev, int pipe) { struct drm_psb_private *dev_priv = dev->dev_private; unsigned long irqflags; if (IS_MFLD(dev)) mdfld_disable_te(dev, pipe); spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); if (pipe == 0) dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG; else if (pipe == 1) dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } /* * It is used to enable TE interrupt */ int mdfld_enable_te(struct drm_device *dev, int pipe) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; uint32_t reg_val = 0; uint32_t pipeconf_reg = mid_pipeconf(pipe); if (gma_power_begin(dev, false)) { reg_val = REG_READ(pipeconf_reg); gma_power_end(dev); } if (!(reg_val & PIPEACONF_ENABLE)) return -EINVAL; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); mid_enable_pipe_event(dev_priv, pipe); psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); return 0; } /* * It is used to disable TE interrupt */ void mdfld_disable_te(struct drm_device *dev, int pipe) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; if (!dev_priv->dsr_enable) return; spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); mid_disable_pipe_event(dev_priv, pipe); psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE); spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } /* Called from drm generic code, passed a 'crtc', which * we use as a pipe index */ u32 psb_get_vblank_counter(struct drm_device *dev, int pipe) { uint32_t high_frame = PIPEAFRAMEHIGH; uint32_t low_frame = PIPEAFRAMEPIXEL; uint32_t pipeconf_reg = PIPEACONF; uint32_t reg_val = 0; uint32_t high1 = 0, high2 = 0, low = 0, count = 0; switch (pipe) { case 0: break; case 1: high_frame = PIPEBFRAMEHIGH; low_frame = PIPEBFRAMEPIXEL; pipeconf_reg = PIPEBCONF; break; case 2: high_frame = PIPECFRAMEHIGH; low_frame = PIPECFRAMEPIXEL; pipeconf_reg = PIPECCONF; break; default: dev_err(dev->dev, "%s, invalid pipe.\n", __func__); return 0; } if (!gma_power_begin(dev, false)) return 0; reg_val = REG_READ(pipeconf_reg); if (!(reg_val & PIPEACONF_ENABLE)) { dev_err(dev->dev, "trying to get vblank count for disabled pipe %d\n", pipe); goto psb_get_vblank_counter_exit; } /* * High & low register fields aren't synchronized, so make sure * we get a low value that's stable across two reads of the high * register. */ do { high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> PIPE_FRAME_HIGH_SHIFT); low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >> PIPE_FRAME_LOW_SHIFT); high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> PIPE_FRAME_HIGH_SHIFT); } while (high1 != high2); count = (high1 << 8) | low; psb_get_vblank_counter_exit: gma_power_end(dev); return count; }
gpl-2.0
CyanogenMod/android_kernel_motorola_apq8084
arch/arm/mach-orion5x/mv2120-setup.c
2106
5951
/* * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org> * Copyright (C) 2008 Martin Michlmayr <tbm@cyrius.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. */ #include <linux/gpio.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/irq.h> #include <linux/mtd/physmap.h> #include <linux/mv643xx_eth.h> #include <linux/leds.h> #include <linux/gpio_keys.h> #include <linux/input.h> #include <linux/i2c.h> #include <linux/ata_platform.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <mach/orion5x.h> #include "common.h" #include "mpp.h" #define MV2120_NOR_BOOT_BASE 0xf4000000 #define MV2120_NOR_BOOT_SIZE SZ_512K #define MV2120_GPIO_RTC_IRQ 3 #define MV2120_GPIO_KEY_RESET 17 #define MV2120_GPIO_KEY_POWER 18 #define MV2120_GPIO_POWER_OFF 19 /***************************************************************************** * Ethernet ****************************************************************************/ static struct mv643xx_eth_platform_data mv2120_eth_data = { .phy_addr = MV643XX_ETH_PHY_ADDR(8), }; static struct mv_sata_platform_data mv2120_sata_data = { .n_ports = 2, }; static struct mtd_partition mv2120_partitions[] = { { .name = "firmware", .size = 0x00080000, .offset = 0, }, }; static struct physmap_flash_data mv2120_nor_flash_data = { .width = 1, .parts = mv2120_partitions, .nr_parts = ARRAY_SIZE(mv2120_partitions) }; static struct resource mv2120_nor_flash_resource = { .flags = IORESOURCE_MEM, .start = MV2120_NOR_BOOT_BASE, .end = MV2120_NOR_BOOT_BASE + MV2120_NOR_BOOT_SIZE - 1, }; static struct platform_device mv2120_nor_flash = { .name = "physmap-flash", .id = 0, .dev = { .platform_data = &mv2120_nor_flash_data, }, .resource = &mv2120_nor_flash_resource, .num_resources = 1, }; static struct gpio_keys_button mv2120_buttons[] = { { .code = KEY_RESTART, .gpio = MV2120_GPIO_KEY_RESET, .desc = "reset", .active_low = 1, }, { .code = KEY_POWER, .gpio = MV2120_GPIO_KEY_POWER, .desc = "power", .active_low = 1, }, }; static struct gpio_keys_platform_data mv2120_button_data = { .buttons = mv2120_buttons, .nbuttons = ARRAY_SIZE(mv2120_buttons), }; static struct platform_device mv2120_button_device = { .name = "gpio-keys", .id = -1, .num_resources = 0, .dev = { .platform_data = &mv2120_button_data, }, }; /**************************************************************************** * General Setup ****************************************************************************/ static unsigned int mv2120_mpp_modes[] __initdata = { MPP0_GPIO, /* Sys status LED */ MPP1_GPIO, /* Sys error LED */ MPP2_GPIO, /* OverTemp interrupt */ MPP3_GPIO, /* RTC interrupt */ MPP4_GPIO, /* V_LED 5V */ MPP5_GPIO, /* V_LED 3.3V */ MPP6_UNUSED, MPP7_UNUSED, MPP8_GPIO, /* SATA 0 fail LED */ MPP9_GPIO, /* SATA 1 fail LED */ MPP10_UNUSED, MPP11_UNUSED, MPP12_SATA_LED, /* SATA 0 presence */ MPP13_SATA_LED, /* SATA 1 presence */ MPP14_SATA_LED, /* SATA 0 active */ MPP15_SATA_LED, /* SATA 1 active */ MPP16_UNUSED, MPP17_GPIO, /* Reset button */ MPP18_GPIO, /* Power button */ MPP19_GPIO, /* Power off */ 0, }; static struct i2c_board_info __initdata mv2120_i2c_rtc = { I2C_BOARD_INFO("pcf8563", 0x51), .irq = 0, }; static struct gpio_led mv2120_led_pins[] = { { .name = "mv2120:blue:health", .gpio = 0, }, { .name = "mv2120:red:health", .gpio = 1, }, { .name = "mv2120:led:bright", .gpio = 4, .default_trigger = "default-on", }, { .name = "mv2120:led:dimmed", .gpio = 5, }, { .name = "mv2120:red:sata0", .gpio = 8, .active_low = 1, }, { .name = "mv2120:red:sata1", .gpio = 9, .active_low = 1, }, }; static struct gpio_led_platform_data mv2120_led_data = { .leds = mv2120_led_pins, .num_leds = ARRAY_SIZE(mv2120_led_pins), }; static struct platform_device mv2120_leds = { .name = "leds-gpio", .id = -1, .dev = { .platform_data = &mv2120_led_data, } }; static void mv2120_power_off(void) { pr_info("%s: triggering power-off...\n", __func__); gpio_set_value(MV2120_GPIO_POWER_OFF, 0); } static void __init mv2120_init(void) { /* Setup basic Orion functions. Need to be called early. */ orion5x_init(); orion5x_mpp_conf(mv2120_mpp_modes); /* * Configure peripherals. */ orion5x_ehci0_init(); orion5x_ehci1_init(); orion5x_eth_init(&mv2120_eth_data); orion5x_i2c_init(); orion5x_sata_init(&mv2120_sata_data); orion5x_uart0_init(); orion5x_xor_init(); mvebu_mbus_add_window("devbus-boot", MV2120_NOR_BOOT_BASE, MV2120_NOR_BOOT_SIZE); platform_device_register(&mv2120_nor_flash); platform_device_register(&mv2120_button_device); if (gpio_request(MV2120_GPIO_RTC_IRQ, "rtc") == 0) { if (gpio_direction_input(MV2120_GPIO_RTC_IRQ) == 0) mv2120_i2c_rtc.irq = gpio_to_irq(MV2120_GPIO_RTC_IRQ); else gpio_free(MV2120_GPIO_RTC_IRQ); } i2c_register_board_info(0, &mv2120_i2c_rtc, 1); platform_device_register(&mv2120_leds); /* register mv2120 specific power-off method */ if (gpio_request(MV2120_GPIO_POWER_OFF, "POWEROFF") != 0 || gpio_direction_output(MV2120_GPIO_POWER_OFF, 1) != 0) pr_err("mv2120: failed to setup power-off GPIO\n"); pm_power_off = mv2120_power_off; } /* Warning: HP uses a wrong mach-type (=526) in their bootloader */ MACHINE_START(MV2120, "HP Media Vault mv2120") /* Maintainer: Martin Michlmayr <tbm@cyrius.com> */ .atag_offset = 0x100, .init_machine = mv2120_init, .map_io = orion5x_map_io, .init_early = orion5x_init_early, .init_irq = orion5x_init_irq, .init_time = orion5x_timer_init, .fixup = tag_fixup_mem32, .restart = orion5x_restart, MACHINE_END
gpl-2.0
Emotroid-Team/emotion_tw_caf_kernel
drivers/watchdog/bcm47xx_wdt.c
2618
6364
/* * Watchdog driver for Broadcom BCM47XX * * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs> * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr> * Copyright (C) 2012-2013 Hauke Mehrtens <hauke@hauke-m.de> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/bcm47xx_wdt.h> #include <linux/bitops.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/platform_device.h> #include <linux/reboot.h> #include <linux/types.h> #include <linux/watchdog.h> #include <linux/timer.h> #include <linux/jiffies.h> #define DRV_NAME "bcm47xx_wdt" #define WDT_DEFAULT_TIME 30 /* seconds */ #define WDT_SOFTTIMER_MAX 255 /* seconds */ #define WDT_SOFTTIMER_THRESHOLD 60 /* seconds */ static int timeout = WDT_DEFAULT_TIME; static bool nowayout = WATCHDOG_NOWAYOUT; module_param(timeout, int, 0); MODULE_PARM_DESC(timeout, "Watchdog time in seconds. (default=" __MODULE_STRING(WDT_DEFAULT_TIME) ")"); module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); static inline struct bcm47xx_wdt *bcm47xx_wdt_get(struct watchdog_device *wdd) { return container_of(wdd, struct bcm47xx_wdt, wdd); } static int bcm47xx_wdt_hard_keepalive(struct watchdog_device *wdd) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); wdt->timer_set_ms(wdt, wdd->timeout * 1000); return 0; } static int bcm47xx_wdt_hard_start(struct watchdog_device *wdd) { return 0; } static int bcm47xx_wdt_hard_stop(struct watchdog_device *wdd) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); wdt->timer_set(wdt, 0); return 0; } static int bcm47xx_wdt_hard_set_timeout(struct watchdog_device *wdd, unsigned int new_time) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); u32 max_timer = wdt->max_timer_ms; if (new_time < 1 || new_time > max_timer / 1000) { pr_warn("timeout value must be 1<=x<=%d, using %d\n", max_timer / 1000, new_time); return -EINVAL; } wdd->timeout = new_time; return 0; } static struct watchdog_ops bcm47xx_wdt_hard_ops = { .owner = THIS_MODULE, .start = bcm47xx_wdt_hard_start, .stop = bcm47xx_wdt_hard_stop, .ping = bcm47xx_wdt_hard_keepalive, .set_timeout = bcm47xx_wdt_hard_set_timeout, }; static void bcm47xx_wdt_soft_timer_tick(unsigned long data) { struct bcm47xx_wdt *wdt = (struct bcm47xx_wdt *)data; u32 next_tick = min(wdt->wdd.timeout * 1000, wdt->max_timer_ms); if (!atomic_dec_and_test(&wdt->soft_ticks)) { wdt->timer_set_ms(wdt, next_tick); mod_timer(&wdt->soft_timer, jiffies + HZ); } else { pr_crit("Watchdog will fire soon!!!\n"); } } static int bcm47xx_wdt_soft_keepalive(struct watchdog_device *wdd) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); atomic_set(&wdt->soft_ticks, wdd->timeout); return 0; } static int bcm47xx_wdt_soft_start(struct watchdog_device *wdd) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); bcm47xx_wdt_soft_keepalive(wdd); bcm47xx_wdt_soft_timer_tick((unsigned long)wdt); return 0; } static int bcm47xx_wdt_soft_stop(struct watchdog_device *wdd) { struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); del_timer_sync(&wdt->soft_timer); wdt->timer_set(wdt, 0); return 0; } static int bcm47xx_wdt_soft_set_timeout(struct watchdog_device *wdd, unsigned int new_time) { if (new_time < 1 || new_time > WDT_SOFTTIMER_MAX) { pr_warn("timeout value must be 1<=x<=%d, using %d\n", WDT_SOFTTIMER_MAX, new_time); return -EINVAL; } wdd->timeout = new_time; return 0; } static const struct watchdog_info bcm47xx_wdt_info = { .identity = DRV_NAME, .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, }; static int bcm47xx_wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { struct bcm47xx_wdt *wdt; wdt = container_of(this, struct bcm47xx_wdt, notifier); if (code == SYS_DOWN || code == SYS_HALT) wdt->wdd.ops->stop(&wdt->wdd); return NOTIFY_DONE; } static struct watchdog_ops bcm47xx_wdt_soft_ops = { .owner = THIS_MODULE, .start = bcm47xx_wdt_soft_start, .stop = bcm47xx_wdt_soft_stop, .ping = bcm47xx_wdt_soft_keepalive, .set_timeout = bcm47xx_wdt_soft_set_timeout, }; static int bcm47xx_wdt_probe(struct platform_device *pdev) { int ret; bool soft; struct bcm47xx_wdt *wdt = dev_get_platdata(&pdev->dev); if (!wdt) return -ENXIO; soft = wdt->max_timer_ms < WDT_SOFTTIMER_THRESHOLD * 1000; if (soft) { wdt->wdd.ops = &bcm47xx_wdt_soft_ops; setup_timer(&wdt->soft_timer, bcm47xx_wdt_soft_timer_tick, (long unsigned int)wdt); } else { wdt->wdd.ops = &bcm47xx_wdt_hard_ops; } wdt->wdd.info = &bcm47xx_wdt_info; wdt->wdd.timeout = WDT_DEFAULT_TIME; ret = wdt->wdd.ops->set_timeout(&wdt->wdd, timeout); if (ret) goto err_timer; watchdog_set_nowayout(&wdt->wdd, nowayout); wdt->notifier.notifier_call = &bcm47xx_wdt_notify_sys; ret = register_reboot_notifier(&wdt->notifier); if (ret) goto err_timer; ret = watchdog_register_device(&wdt->wdd); if (ret) goto err_notifier; dev_info(&pdev->dev, "BCM47xx Watchdog Timer enabled (%d seconds%s%s)\n", timeout, nowayout ? ", nowayout" : "", soft ? ", Software Timer" : ""); return 0; err_notifier: unregister_reboot_notifier(&wdt->notifier); err_timer: if (soft) del_timer_sync(&wdt->soft_timer); return ret; } static int bcm47xx_wdt_remove(struct platform_device *pdev) { struct bcm47xx_wdt *wdt = dev_get_platdata(&pdev->dev); if (!wdt) return -ENXIO; watchdog_unregister_device(&wdt->wdd); unregister_reboot_notifier(&wdt->notifier); return 0; } static struct platform_driver bcm47xx_wdt_driver = { .driver = { .owner = THIS_MODULE, .name = "bcm47xx-wdt", }, .probe = bcm47xx_wdt_probe, .remove = bcm47xx_wdt_remove, }; module_platform_driver(bcm47xx_wdt_driver); MODULE_AUTHOR("Aleksandar Radovanovic"); MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>"); MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx"); MODULE_LICENSE("GPL");
gpl-2.0
PRJosh/kernel.org
drivers/staging/iio/Documentation/generic_buffer.c
2874
8350
/* Industrialio buffer test code. * * Copyright (c) 2008 Jonathan Cameron * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. * * This program is primarily intended as an example application. * Reads the current buffer setup from sysfs and starts a short capture * from the specified device, pretty printing the result after appropriate * conversion. * * Command line parameters * generic_buffer -n <device_name> -t <trigger_name> * If trigger name is not specified the program assumes you want a dataready * trigger associated with the device and goes looking for it. * */ #define _GNU_SOURCE #include <unistd.h> #include <dirent.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <sys/stat.h> #include <sys/dir.h> #include <linux/types.h> #include <string.h> #include <poll.h> #include <endian.h> #include <getopt.h> #include <inttypes.h> #include "iio_utils.h" /** * size_from_channelarray() - calculate the storage size of a scan * @channels: the channel info array * @num_channels: number of channels * * Has the side effect of filling the channels[i].location values used * in processing the buffer output. **/ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) { int bytes = 0; int i = 0; while (i < num_channels) { if (bytes % channels[i].bytes == 0) channels[i].location = bytes; else channels[i].location = bytes - bytes%channels[i].bytes + channels[i].bytes; bytes = channels[i].location + channels[i].bytes; i++; } return bytes; } void print2byte(int input, struct iio_channel_info *info) { /* First swap if incorrect endian */ if (info->be) input = be16toh((uint16_t)input); else input = le16toh((uint16_t)input); /* * Shift before conversion to avoid sign extension * of left aligned data */ input = input >> info->shift; if (info->is_signed) { int16_t val = input; val &= (1 << info->bits_used) - 1; val = (int16_t)(val << (16 - info->bits_used)) >> (16 - info->bits_used); printf("%05f ", ((float)val + info->offset)*info->scale); } else { uint16_t val = input; val &= (1 << info->bits_used) - 1; printf("%05f ", ((float)val + info->offset)*info->scale); } } /** * process_scan() - print out the values in SI units * @data: pointer to the start of the scan * @channels: information about the channels. Note * size_from_channelarray must have been called first to fill the * location offsets. * @num_channels: number of channels **/ void process_scan(char *data, struct iio_channel_info *channels, int num_channels) { int k; for (k = 0; k < num_channels; k++) switch (channels[k].bytes) { /* only a few cases implemented so far */ case 2: print2byte(*(uint16_t *)(data + channels[k].location), &channels[k]); break; case 4: if (!channels[k].is_signed) { uint32_t val = *(uint32_t *) (data + channels[k].location); printf("%05f ", ((float)val + channels[k].offset)* channels[k].scale); } break; case 8: if (channels[k].is_signed) { int64_t val = *(int64_t *) (data + channels[k].location); if ((val >> channels[k].bits_used) & 1) val = (val & channels[k].mask) | ~channels[k].mask; /* special case for timestamp */ if (channels[k].scale == 1.0f && channels[k].offset == 0.0f) printf("%" PRId64 " ", val); else printf("%05f ", ((float)val + channels[k].offset)* channels[k].scale); } break; default: break; } printf("\n"); } int main(int argc, char **argv) { unsigned long num_loops = 2; unsigned long timedelay = 1000000; unsigned long buf_len = 128; int ret, c, i, j, toread; int fp; int num_channels; char *trigger_name = NULL, *device_name = NULL; char *dev_dir_name, *buf_dir_name; int datardytrigger = 1; char *data; ssize_t read_size; int dev_num, trig_num; char *buffer_access; int scan_size; int noevents = 0; char *dummy; struct iio_channel_info *channels; while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) { switch (c) { case 'n': device_name = optarg; break; case 't': trigger_name = optarg; datardytrigger = 0; break; case 'e': noevents = 1; break; case 'c': num_loops = strtoul(optarg, &dummy, 10); break; case 'w': timedelay = strtoul(optarg, &dummy, 10); break; case 'l': buf_len = strtoul(optarg, &dummy, 10); break; case '?': return -1; } } if (device_name == NULL) return -1; /* Find the device requested */ dev_num = find_type_by_name(device_name, "iio:device"); if (dev_num < 0) { printf("Failed to find the %s\n", device_name); ret = -ENODEV; goto error_ret; } printf("iio device number being used is %d\n", dev_num); asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); if (trigger_name == NULL) { /* * Build the trigger name. If it is device associated its * name is <device_name>_dev[n] where n matches the device * number found above */ ret = asprintf(&trigger_name, "%s-dev%d", device_name, dev_num); if (ret < 0) { ret = -ENOMEM; goto error_ret; } } /* Verify the trigger exists */ trig_num = find_type_by_name(trigger_name, "trigger"); if (trig_num < 0) { printf("Failed to find the trigger %s\n", trigger_name); ret = -ENODEV; goto error_free_triggername; } printf("iio trigger number being used is %d\n", trig_num); /* * Parse the files in scan_elements to identify what channels are * present */ ret = build_channel_array(dev_dir_name, &channels, &num_channels); if (ret) { printf("Problem reading scan element information\n"); printf("diag %s\n", dev_dir_name); goto error_free_triggername; } /* * Construct the directory name for the associated buffer. * As we know that the lis3l02dq has only one buffer this may * be built rather than found. */ ret = asprintf(&buf_dir_name, "%siio:device%d/buffer", iio_dir, dev_num); if (ret < 0) { ret = -ENOMEM; goto error_free_triggername; } printf("%s %s\n", dev_dir_name, trigger_name); /* Set the device trigger to be the data ready trigger found above */ ret = write_sysfs_string_and_verify("trigger/current_trigger", dev_dir_name, trigger_name); if (ret < 0) { printf("Failed to write current_trigger file\n"); goto error_free_buf_dir_name; } /* Setup ring buffer parameters */ ret = write_sysfs_int("length", buf_dir_name, buf_len); if (ret < 0) goto error_free_buf_dir_name; /* Enable the buffer */ ret = write_sysfs_int("enable", buf_dir_name, 1); if (ret < 0) goto error_free_buf_dir_name; scan_size = size_from_channelarray(channels, num_channels); data = malloc(scan_size*buf_len); if (!data) { ret = -ENOMEM; goto error_free_buf_dir_name; } ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); if (ret < 0) { ret = -ENOMEM; goto error_free_data; } /* Attempt to open non blocking the access dev */ fp = open(buffer_access, O_RDONLY | O_NONBLOCK); if (fp == -1) { /* If it isn't there make the node */ printf("Failed to open %s\n", buffer_access); ret = -errno; goto error_free_buffer_access; } /* Wait for events 10 times */ for (j = 0; j < num_loops; j++) { if (!noevents) { struct pollfd pfd = { .fd = fp, .events = POLLIN, }; poll(&pfd, 1, -1); toread = buf_len; } else { usleep(timedelay); toread = 64; } read_size = read(fp, data, toread*scan_size); if (read_size == -EAGAIN) { printf("nothing available\n"); continue; } for (i = 0; i < read_size/scan_size; i++) process_scan(data + scan_size*i, channels, num_channels); } /* Stop the buffer */ ret = write_sysfs_int("enable", buf_dir_name, 0); if (ret < 0) goto error_close_buffer_access; /* Disconnect the trigger - just write a dummy name. */ write_sysfs_string("trigger/current_trigger", dev_dir_name, "NULL"); error_close_buffer_access: close(fp); error_free_data: free(data); error_free_buffer_access: free(buffer_access); error_free_buf_dir_name: free(buf_dir_name); error_free_triggername: if (datardytrigger) free(trigger_name); error_ret: return ret; }
gpl-2.0
SM-G920P/Hacker_Kernel_SM-G920P
arch/x86/kernel/cpu/mtrr/cleanup.c
3386
25307
/* * MTRR (Memory Type Range Register) cleanup * * Copyright (C) 2009 Yinghai Lu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/module.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/smp.h> #include <linux/cpu.h> #include <linux/mutex.h> #include <linux/uaccess.h> #include <linux/kvm_para.h> #include <linux/range.h> #include <asm/processor.h> #include <asm/e820.h> #include <asm/mtrr.h> #include <asm/msr.h> #include "mtrr.h" struct var_mtrr_range_state { unsigned long base_pfn; unsigned long size_pfn; mtrr_type type; }; struct var_mtrr_state { unsigned long range_startk; unsigned long range_sizek; unsigned long chunk_sizek; unsigned long gran_sizek; unsigned int reg; }; /* Should be related to MTRR_VAR_RANGES nums */ #define RANGE_NUM 256 static struct range __initdata range[RANGE_NUM]; static int __initdata nr_range; static struct var_mtrr_range_state __initdata range_state[RANGE_NUM]; static int __initdata debug_print; #define Dprintk(x...) do { if (debug_print) printk(KERN_DEBUG x); } while (0) #define BIOS_BUG_MSG KERN_WARNING \ "WARNING: BIOS bug: VAR MTRR %d contains strange UC entry under 1M, check with your system vendor!\n" static int __init x86_get_mtrr_mem_range(struct range *range, int nr_range, unsigned long extra_remove_base, unsigned long extra_remove_size) { unsigned long base, size; mtrr_type type; int i; for (i = 0; i < num_var_ranges; i++) { type = range_state[i].type; if (type != MTRR_TYPE_WRBACK) continue; base = range_state[i].base_pfn; size = range_state[i].size_pfn; nr_range = add_range_with_merge(range, RANGE_NUM, nr_range, base, base + size); } if (debug_print) { printk(KERN_DEBUG "After WB checking\n"); for (i = 0; i < nr_range; i++) printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", range[i].start, range[i].end); } /* Take out UC ranges: */ for (i = 0; i < num_var_ranges; i++) { type = range_state[i].type; if (type != MTRR_TYPE_UNCACHABLE && type != MTRR_TYPE_WRPROT) continue; size = range_state[i].size_pfn; if (!size) continue; base = range_state[i].base_pfn; if (base < (1<<(20-PAGE_SHIFT)) && mtrr_state.have_fixed && (mtrr_state.enabled & 1)) { /* Var MTRR contains UC entry below 1M? Skip it: */ printk(BIOS_BUG_MSG, i); if (base + size <= (1<<(20-PAGE_SHIFT))) continue; size -= (1<<(20-PAGE_SHIFT)) - base; base = 1<<(20-PAGE_SHIFT); } subtract_range(range, RANGE_NUM, base, base + size); } if (extra_remove_size) subtract_range(range, RANGE_NUM, extra_remove_base, extra_remove_base + extra_remove_size); if (debug_print) { printk(KERN_DEBUG "After UC checking\n"); for (i = 0; i < RANGE_NUM; i++) { if (!range[i].end) continue; printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", range[i].start, range[i].end); } } /* sort the ranges */ nr_range = clean_sort_range(range, RANGE_NUM); if (debug_print) { printk(KERN_DEBUG "After sorting\n"); for (i = 0; i < nr_range; i++) printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", range[i].start, range[i].end); } return nr_range; } #ifdef CONFIG_MTRR_SANITIZER static unsigned long __init sum_ranges(struct range *range, int nr_range) { unsigned long sum = 0; int i; for (i = 0; i < nr_range; i++) sum += range[i].end - range[i].start; return sum; } static int enable_mtrr_cleanup __initdata = CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT; static int __init disable_mtrr_cleanup_setup(char *str) { enable_mtrr_cleanup = 0; return 0; } early_param("disable_mtrr_cleanup", disable_mtrr_cleanup_setup); static int __init enable_mtrr_cleanup_setup(char *str) { enable_mtrr_cleanup = 1; return 0; } early_param("enable_mtrr_cleanup", enable_mtrr_cleanup_setup); static int __init mtrr_cleanup_debug_setup(char *str) { debug_print = 1; return 0; } early_param("mtrr_cleanup_debug", mtrr_cleanup_debug_setup); static void __init set_var_mtrr(unsigned int reg, unsigned long basek, unsigned long sizek, unsigned char type, unsigned int address_bits) { u32 base_lo, base_hi, mask_lo, mask_hi; u64 base, mask; if (!sizek) { fill_mtrr_var_range(reg, 0, 0, 0, 0); return; } mask = (1ULL << address_bits) - 1; mask &= ~((((u64)sizek) << 10) - 1); base = ((u64)basek) << 10; base |= type; mask |= 0x800; base_lo = base & ((1ULL<<32) - 1); base_hi = base >> 32; mask_lo = mask & ((1ULL<<32) - 1); mask_hi = mask >> 32; fill_mtrr_var_range(reg, base_lo, base_hi, mask_lo, mask_hi); } static void __init save_var_mtrr(unsigned int reg, unsigned long basek, unsigned long sizek, unsigned char type) { range_state[reg].base_pfn = basek >> (PAGE_SHIFT - 10); range_state[reg].size_pfn = sizek >> (PAGE_SHIFT - 10); range_state[reg].type = type; } static void __init set_var_mtrr_all(unsigned int address_bits) { unsigned long basek, sizek; unsigned char type; unsigned int reg; for (reg = 0; reg < num_var_ranges; reg++) { basek = range_state[reg].base_pfn << (PAGE_SHIFT - 10); sizek = range_state[reg].size_pfn << (PAGE_SHIFT - 10); type = range_state[reg].type; set_var_mtrr(reg, basek, sizek, type, address_bits); } } static unsigned long to_size_factor(unsigned long sizek, char *factorp) { unsigned long base = sizek; char factor; if (base & ((1<<10) - 1)) { /* Not MB-aligned: */ factor = 'K'; } else if (base & ((1<<20) - 1)) { factor = 'M'; base >>= 10; } else { factor = 'G'; base >>= 20; } *factorp = factor; return base; } static unsigned int __init range_to_mtrr(unsigned int reg, unsigned long range_startk, unsigned long range_sizek, unsigned char type) { if (!range_sizek || (reg >= num_var_ranges)) return reg; while (range_sizek) { unsigned long max_align, align; unsigned long sizek; /* Compute the maximum size with which we can make a range: */ if (range_startk) max_align = __ffs(range_startk); else max_align = BITS_PER_LONG - 1; align = __fls(range_sizek); if (align > max_align) align = max_align; sizek = 1UL << align; if (debug_print) { char start_factor = 'K', size_factor = 'K'; unsigned long start_base, size_base; start_base = to_size_factor(range_startk, &start_factor); size_base = to_size_factor(sizek, &size_factor); Dprintk("Setting variable MTRR %d, " "base: %ld%cB, range: %ld%cB, type %s\n", reg, start_base, start_factor, size_base, size_factor, (type == MTRR_TYPE_UNCACHABLE) ? "UC" : ((type == MTRR_TYPE_WRBACK) ? "WB" : "Other") ); } save_var_mtrr(reg++, range_startk, sizek, type); range_startk += sizek; range_sizek -= sizek; if (reg >= num_var_ranges) break; } return reg; } static unsigned __init range_to_mtrr_with_hole(struct var_mtrr_state *state, unsigned long basek, unsigned long sizek) { unsigned long hole_basek, hole_sizek; unsigned long second_basek, second_sizek; unsigned long range0_basek, range0_sizek; unsigned long range_basek, range_sizek; unsigned long chunk_sizek; unsigned long gran_sizek; hole_basek = 0; hole_sizek = 0; second_basek = 0; second_sizek = 0; chunk_sizek = state->chunk_sizek; gran_sizek = state->gran_sizek; /* Align with gran size, prevent small block used up MTRRs: */ range_basek = ALIGN(state->range_startk, gran_sizek); if ((range_basek > basek) && basek) return second_sizek; state->range_sizek -= (range_basek - state->range_startk); range_sizek = ALIGN(state->range_sizek, gran_sizek); while (range_sizek > state->range_sizek) { range_sizek -= gran_sizek; if (!range_sizek) return 0; } state->range_sizek = range_sizek; /* Try to append some small hole: */ range0_basek = state->range_startk; range0_sizek = ALIGN(state->range_sizek, chunk_sizek); /* No increase: */ if (range0_sizek == state->range_sizek) { Dprintk("rangeX: %016lx - %016lx\n", range0_basek<<10, (range0_basek + state->range_sizek)<<10); state->reg = range_to_mtrr(state->reg, range0_basek, state->range_sizek, MTRR_TYPE_WRBACK); return 0; } /* Only cut back when it is not the last: */ if (sizek) { while (range0_basek + range0_sizek > (basek + sizek)) { if (range0_sizek >= chunk_sizek) range0_sizek -= chunk_sizek; else range0_sizek = 0; if (!range0_sizek) break; } } second_try: range_basek = range0_basek + range0_sizek; /* One hole in the middle: */ if (range_basek > basek && range_basek <= (basek + sizek)) second_sizek = range_basek - basek; if (range0_sizek > state->range_sizek) { /* One hole in middle or at the end: */ hole_sizek = range0_sizek - state->range_sizek - second_sizek; /* Hole size should be less than half of range0 size: */ if (hole_sizek >= (range0_sizek >> 1) && range0_sizek >= chunk_sizek) { range0_sizek -= chunk_sizek; second_sizek = 0; hole_sizek = 0; goto second_try; } } if (range0_sizek) { Dprintk("range0: %016lx - %016lx\n", range0_basek<<10, (range0_basek + range0_sizek)<<10); state->reg = range_to_mtrr(state->reg, range0_basek, range0_sizek, MTRR_TYPE_WRBACK); } if (range0_sizek < state->range_sizek) { /* Need to handle left over range: */ range_sizek = state->range_sizek - range0_sizek; Dprintk("range: %016lx - %016lx\n", range_basek<<10, (range_basek + range_sizek)<<10); state->reg = range_to_mtrr(state->reg, range_basek, range_sizek, MTRR_TYPE_WRBACK); } if (hole_sizek) { hole_basek = range_basek - hole_sizek - second_sizek; Dprintk("hole: %016lx - %016lx\n", hole_basek<<10, (hole_basek + hole_sizek)<<10); state->reg = range_to_mtrr(state->reg, hole_basek, hole_sizek, MTRR_TYPE_UNCACHABLE); } return second_sizek; } static void __init set_var_mtrr_range(struct var_mtrr_state *state, unsigned long base_pfn, unsigned long size_pfn) { unsigned long basek, sizek; unsigned long second_sizek = 0; if (state->reg >= num_var_ranges) return; basek = base_pfn << (PAGE_SHIFT - 10); sizek = size_pfn << (PAGE_SHIFT - 10); /* See if I can merge with the last range: */ if ((basek <= 1024) || (state->range_startk + state->range_sizek == basek)) { unsigned long endk = basek + sizek; state->range_sizek = endk - state->range_startk; return; } /* Write the range mtrrs: */ if (state->range_sizek != 0) second_sizek = range_to_mtrr_with_hole(state, basek, sizek); /* Allocate an msr: */ state->range_startk = basek + second_sizek; state->range_sizek = sizek - second_sizek; } /* Mininum size of mtrr block that can take hole: */ static u64 mtrr_chunk_size __initdata = (256ULL<<20); static int __init parse_mtrr_chunk_size_opt(char *p) { if (!p) return -EINVAL; mtrr_chunk_size = memparse(p, &p); return 0; } early_param("mtrr_chunk_size", parse_mtrr_chunk_size_opt); /* Granularity of mtrr of block: */ static u64 mtrr_gran_size __initdata; static int __init parse_mtrr_gran_size_opt(char *p) { if (!p) return -EINVAL; mtrr_gran_size = memparse(p, &p); return 0; } early_param("mtrr_gran_size", parse_mtrr_gran_size_opt); static unsigned long nr_mtrr_spare_reg __initdata = CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT; static int __init parse_mtrr_spare_reg(char *arg) { if (arg) nr_mtrr_spare_reg = simple_strtoul(arg, NULL, 0); return 0; } early_param("mtrr_spare_reg_nr", parse_mtrr_spare_reg); static int __init x86_setup_var_mtrrs(struct range *range, int nr_range, u64 chunk_size, u64 gran_size) { struct var_mtrr_state var_state; int num_reg; int i; var_state.range_startk = 0; var_state.range_sizek = 0; var_state.reg = 0; var_state.chunk_sizek = chunk_size >> 10; var_state.gran_sizek = gran_size >> 10; memset(range_state, 0, sizeof(range_state)); /* Write the range: */ for (i = 0; i < nr_range; i++) { set_var_mtrr_range(&var_state, range[i].start, range[i].end - range[i].start); } /* Write the last range: */ if (var_state.range_sizek != 0) range_to_mtrr_with_hole(&var_state, 0, 0); num_reg = var_state.reg; /* Clear out the extra MTRR's: */ while (var_state.reg < num_var_ranges) { save_var_mtrr(var_state.reg, 0, 0, 0); var_state.reg++; } return num_reg; } struct mtrr_cleanup_result { unsigned long gran_sizek; unsigned long chunk_sizek; unsigned long lose_cover_sizek; unsigned int num_reg; int bad; }; /* * gran_size: 64K, 128K, 256K, 512K, 1M, 2M, ..., 2G * chunk size: gran_size, ..., 2G * so we need (1+16)*8 */ #define NUM_RESULT 136 #define PSHIFT (PAGE_SHIFT - 10) static struct mtrr_cleanup_result __initdata result[NUM_RESULT]; static unsigned long __initdata min_loss_pfn[RANGE_NUM]; static void __init print_out_mtrr_range_state(void) { char start_factor = 'K', size_factor = 'K'; unsigned long start_base, size_base; mtrr_type type; int i; for (i = 0; i < num_var_ranges; i++) { size_base = range_state[i].size_pfn << (PAGE_SHIFT - 10); if (!size_base) continue; size_base = to_size_factor(size_base, &size_factor), start_base = range_state[i].base_pfn << (PAGE_SHIFT - 10); start_base = to_size_factor(start_base, &start_factor), type = range_state[i].type; printk(KERN_DEBUG "reg %d, base: %ld%cB, range: %ld%cB, type %s\n", i, start_base, start_factor, size_base, size_factor, (type == MTRR_TYPE_UNCACHABLE) ? "UC" : ((type == MTRR_TYPE_WRPROT) ? "WP" : ((type == MTRR_TYPE_WRBACK) ? "WB" : "Other")) ); } } static int __init mtrr_need_cleanup(void) { int i; mtrr_type type; unsigned long size; /* Extra one for all 0: */ int num[MTRR_NUM_TYPES + 1]; /* Check entries number: */ memset(num, 0, sizeof(num)); for (i = 0; i < num_var_ranges; i++) { type = range_state[i].type; size = range_state[i].size_pfn; if (type >= MTRR_NUM_TYPES) continue; if (!size) type = MTRR_NUM_TYPES; num[type]++; } /* Check if we got UC entries: */ if (!num[MTRR_TYPE_UNCACHABLE]) return 0; /* Check if we only had WB and UC */ if (num[MTRR_TYPE_WRBACK] + num[MTRR_TYPE_UNCACHABLE] != num_var_ranges - num[MTRR_NUM_TYPES]) return 0; return 1; } static unsigned long __initdata range_sums; static void __init mtrr_calc_range_state(u64 chunk_size, u64 gran_size, unsigned long x_remove_base, unsigned long x_remove_size, int i) { static struct range range_new[RANGE_NUM]; unsigned long range_sums_new; static int nr_range_new; int num_reg; /* Convert ranges to var ranges state: */ num_reg = x86_setup_var_mtrrs(range, nr_range, chunk_size, gran_size); /* We got new setting in range_state, check it: */ memset(range_new, 0, sizeof(range_new)); nr_range_new = x86_get_mtrr_mem_range(range_new, 0, x_remove_base, x_remove_size); range_sums_new = sum_ranges(range_new, nr_range_new); result[i].chunk_sizek = chunk_size >> 10; result[i].gran_sizek = gran_size >> 10; result[i].num_reg = num_reg; if (range_sums < range_sums_new) { result[i].lose_cover_sizek = (range_sums_new - range_sums) << PSHIFT; result[i].bad = 1; } else { result[i].lose_cover_sizek = (range_sums - range_sums_new) << PSHIFT; } /* Double check it: */ if (!result[i].bad && !result[i].lose_cover_sizek) { if (nr_range_new != nr_range || memcmp(range, range_new, sizeof(range))) result[i].bad = 1; } if (!result[i].bad && (range_sums - range_sums_new < min_loss_pfn[num_reg])) min_loss_pfn[num_reg] = range_sums - range_sums_new; } static void __init mtrr_print_out_one_result(int i) { unsigned long gran_base, chunk_base, lose_base; char gran_factor, chunk_factor, lose_factor; gran_base = to_size_factor(result[i].gran_sizek, &gran_factor); chunk_base = to_size_factor(result[i].chunk_sizek, &chunk_factor); lose_base = to_size_factor(result[i].lose_cover_sizek, &lose_factor); pr_info("%sgran_size: %ld%c \tchunk_size: %ld%c \t", result[i].bad ? "*BAD*" : " ", gran_base, gran_factor, chunk_base, chunk_factor); pr_cont("num_reg: %d \tlose cover RAM: %s%ld%c\n", result[i].num_reg, result[i].bad ? "-" : "", lose_base, lose_factor); } static int __init mtrr_search_optimal_index(void) { int num_reg_good; int index_good; int i; if (nr_mtrr_spare_reg >= num_var_ranges) nr_mtrr_spare_reg = num_var_ranges - 1; num_reg_good = -1; for (i = num_var_ranges - nr_mtrr_spare_reg; i > 0; i--) { if (!min_loss_pfn[i]) num_reg_good = i; } index_good = -1; if (num_reg_good != -1) { for (i = 0; i < NUM_RESULT; i++) { if (!result[i].bad && result[i].num_reg == num_reg_good && !result[i].lose_cover_sizek) { index_good = i; break; } } } return index_good; } int __init mtrr_cleanup(unsigned address_bits) { unsigned long x_remove_base, x_remove_size; unsigned long base, size, def, dummy; u64 chunk_size, gran_size; mtrr_type type; int index_good; int i; if (!is_cpu(INTEL) || enable_mtrr_cleanup < 1) return 0; rdmsr(MSR_MTRRdefType, def, dummy); def &= 0xff; if (def != MTRR_TYPE_UNCACHABLE) return 0; /* Get it and store it aside: */ memset(range_state, 0, sizeof(range_state)); for (i = 0; i < num_var_ranges; i++) { mtrr_if->get(i, &base, &size, &type); range_state[i].base_pfn = base; range_state[i].size_pfn = size; range_state[i].type = type; } /* Check if we need handle it and can handle it: */ if (!mtrr_need_cleanup()) return 0; /* Print original var MTRRs at first, for debugging: */ printk(KERN_DEBUG "original variable MTRRs\n"); print_out_mtrr_range_state(); memset(range, 0, sizeof(range)); x_remove_size = 0; x_remove_base = 1 << (32 - PAGE_SHIFT); if (mtrr_tom2) x_remove_size = (mtrr_tom2 >> PAGE_SHIFT) - x_remove_base; /* * [0, 1M) should always be covered by var mtrr with WB * and fixed mtrrs should take effect before var mtrr for it: */ nr_range = add_range_with_merge(range, RANGE_NUM, 0, 0, 1ULL<<(20 - PAGE_SHIFT)); /* add from var mtrr at last */ nr_range = x86_get_mtrr_mem_range(range, nr_range, x_remove_base, x_remove_size); range_sums = sum_ranges(range, nr_range); printk(KERN_INFO "total RAM covered: %ldM\n", range_sums >> (20 - PAGE_SHIFT)); if (mtrr_chunk_size && mtrr_gran_size) { i = 0; mtrr_calc_range_state(mtrr_chunk_size, mtrr_gran_size, x_remove_base, x_remove_size, i); mtrr_print_out_one_result(i); if (!result[i].bad) { set_var_mtrr_all(address_bits); printk(KERN_DEBUG "New variable MTRRs\n"); print_out_mtrr_range_state(); return 1; } printk(KERN_INFO "invalid mtrr_gran_size or mtrr_chunk_size, " "will find optimal one\n"); } i = 0; memset(min_loss_pfn, 0xff, sizeof(min_loss_pfn)); memset(result, 0, sizeof(result)); for (gran_size = (1ULL<<16); gran_size < (1ULL<<32); gran_size <<= 1) { for (chunk_size = gran_size; chunk_size < (1ULL<<32); chunk_size <<= 1) { if (i >= NUM_RESULT) continue; mtrr_calc_range_state(chunk_size, gran_size, x_remove_base, x_remove_size, i); if (debug_print) { mtrr_print_out_one_result(i); printk(KERN_INFO "\n"); } i++; } } /* Try to find the optimal index: */ index_good = mtrr_search_optimal_index(); if (index_good != -1) { printk(KERN_INFO "Found optimal setting for mtrr clean up\n"); i = index_good; mtrr_print_out_one_result(i); /* Convert ranges to var ranges state: */ chunk_size = result[i].chunk_sizek; chunk_size <<= 10; gran_size = result[i].gran_sizek; gran_size <<= 10; x86_setup_var_mtrrs(range, nr_range, chunk_size, gran_size); set_var_mtrr_all(address_bits); printk(KERN_DEBUG "New variable MTRRs\n"); print_out_mtrr_range_state(); return 1; } else { /* print out all */ for (i = 0; i < NUM_RESULT; i++) mtrr_print_out_one_result(i); } printk(KERN_INFO "mtrr_cleanup: can not find optimal value\n"); printk(KERN_INFO "please specify mtrr_gran_size/mtrr_chunk_size\n"); return 0; } #else int __init mtrr_cleanup(unsigned address_bits) { return 0; } #endif static int disable_mtrr_trim; static int __init disable_mtrr_trim_setup(char *str) { disable_mtrr_trim = 1; return 0; } early_param("disable_mtrr_trim", disable_mtrr_trim_setup); /* * Newer AMD K8s and later CPUs have a special magic MSR way to force WB * for memory >4GB. Check for that here. * Note this won't check if the MTRRs < 4GB where the magic bit doesn't * apply to are wrong, but so far we don't know of any such case in the wild. */ #define Tom2Enabled (1U << 21) #define Tom2ForceMemTypeWB (1U << 22) int __init amd_special_default_mtrr(void) { u32 l, h; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) return 0; if (boot_cpu_data.x86 < 0xf) return 0; /* In case some hypervisor doesn't pass SYSCFG through: */ if (rdmsr_safe(MSR_K8_SYSCFG, &l, &h) < 0) return 0; /* * Memory between 4GB and top of mem is forced WB by this magic bit. * Reserved before K8RevF, but should be zero there. */ if ((l & (Tom2Enabled | Tom2ForceMemTypeWB)) == (Tom2Enabled | Tom2ForceMemTypeWB)) return 1; return 0; } static u64 __init real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn) { u64 trim_start, trim_size; trim_start = start_pfn; trim_start <<= PAGE_SHIFT; trim_size = limit_pfn; trim_size <<= PAGE_SHIFT; trim_size -= trim_start; return e820_update_range(trim_start, trim_size, E820_RAM, E820_RESERVED); } /** * mtrr_trim_uncached_memory - trim RAM not covered by MTRRs * @end_pfn: ending page frame number * * Some buggy BIOSes don't setup the MTRRs properly for systems with certain * memory configurations. This routine checks that the highest MTRR matches * the end of memory, to make sure the MTRRs having a write back type cover * all of the memory the kernel is intending to use. If not, it'll trim any * memory off the end by adjusting end_pfn, removing it from the kernel's * allocation pools, warning the user with an obnoxious message. */ int __init mtrr_trim_uncached_memory(unsigned long end_pfn) { unsigned long i, base, size, highest_pfn = 0, def, dummy; mtrr_type type; u64 total_trim_size; /* extra one for all 0 */ int num[MTRR_NUM_TYPES + 1]; /* * Make sure we only trim uncachable memory on machines that * support the Intel MTRR architecture: */ if (!is_cpu(INTEL) || disable_mtrr_trim) return 0; rdmsr(MSR_MTRRdefType, def, dummy); def &= 0xff; if (def != MTRR_TYPE_UNCACHABLE) return 0; /* Get it and store it aside: */ memset(range_state, 0, sizeof(range_state)); for (i = 0; i < num_var_ranges; i++) { mtrr_if->get(i, &base, &size, &type); range_state[i].base_pfn = base; range_state[i].size_pfn = size; range_state[i].type = type; } /* Find highest cached pfn: */ for (i = 0; i < num_var_ranges; i++) { type = range_state[i].type; if (type != MTRR_TYPE_WRBACK) continue; base = range_state[i].base_pfn; size = range_state[i].size_pfn; if (highest_pfn < base + size) highest_pfn = base + size; } /* kvm/qemu doesn't have mtrr set right, don't trim them all: */ if (!highest_pfn) { printk(KERN_INFO "CPU MTRRs all blank - virtualized system.\n"); return 0; } /* Check entries number: */ memset(num, 0, sizeof(num)); for (i = 0; i < num_var_ranges; i++) { type = range_state[i].type; if (type >= MTRR_NUM_TYPES) continue; size = range_state[i].size_pfn; if (!size) type = MTRR_NUM_TYPES; num[type]++; } /* No entry for WB? */ if (!num[MTRR_TYPE_WRBACK]) return 0; /* Check if we only had WB and UC: */ if (num[MTRR_TYPE_WRBACK] + num[MTRR_TYPE_UNCACHABLE] != num_var_ranges - num[MTRR_NUM_TYPES]) return 0; memset(range, 0, sizeof(range)); nr_range = 0; if (mtrr_tom2) { range[nr_range].start = (1ULL<<(32 - PAGE_SHIFT)); range[nr_range].end = mtrr_tom2 >> PAGE_SHIFT; if (highest_pfn < range[nr_range].end) highest_pfn = range[nr_range].end; nr_range++; } nr_range = x86_get_mtrr_mem_range(range, nr_range, 0, 0); /* Check the head: */ total_trim_size = 0; if (range[0].start) total_trim_size += real_trim_memory(0, range[0].start); /* Check the holes: */ for (i = 0; i < nr_range - 1; i++) { if (range[i].end < range[i+1].start) total_trim_size += real_trim_memory(range[i].end, range[i+1].start); } /* Check the top: */ i = nr_range - 1; if (range[i].end < end_pfn) total_trim_size += real_trim_memory(range[i].end, end_pfn); if (total_trim_size) { pr_warning("WARNING: BIOS bug: CPU MTRRs don't cover all of memory, losing %lluMB of RAM.\n", total_trim_size >> 20); if (!changed_by_mtrr_cleanup) WARN_ON(1); pr_info("update e820 for mtrr\n"); update_e820(); return 1; } return 0; }
gpl-2.0
hroark13/Z750C_2_WARP
arch/powerpc/platforms/powermac/cpufreq_32.c
4410
18732
/* * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org> * Copyright (C) 2004 John Steele Scott <toojays@toojays.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * TODO: Need a big cleanup here. Basically, we need to have different * cpufreq_driver structures for the different type of HW instead of the * current mess. We also need to better deal with the detection of the * type of machine. * */ #include <linux/module.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/delay.h> #include <linux/sched.h> #include <linux/adb.h> #include <linux/pmu.h> #include <linux/cpufreq.h> #include <linux/init.h> #include <linux/device.h> #include <linux/hardirq.h> #include <asm/prom.h> #include <asm/machdep.h> #include <asm/irq.h> #include <asm/pmac_feature.h> #include <asm/mmu_context.h> #include <asm/sections.h> #include <asm/cputable.h> #include <asm/time.h> #include <asm/mpic.h> #include <asm/keylargo.h> #include <asm/switch_to.h> /* WARNING !!! This will cause calibrate_delay() to be called, * but this is an __init function ! So you MUST go edit * init/main.c to make it non-init before enabling DEBUG_FREQ */ #undef DEBUG_FREQ extern void low_choose_7447a_dfs(int dfs); extern void low_choose_750fx_pll(int pll); extern void low_sleep_handler(void); /* * Currently, PowerMac cpufreq supports only high & low frequencies * that are set by the firmware */ static unsigned int low_freq; static unsigned int hi_freq; static unsigned int cur_freq; static unsigned int sleep_freq; /* * Different models uses different mechanisms to switch the frequency */ static int (*set_speed_proc)(int low_speed); static unsigned int (*get_speed_proc)(void); /* * Some definitions used by the various speedprocs */ static u32 voltage_gpio; static u32 frequency_gpio; static u32 slew_done_gpio; static int no_schedule; static int has_cpu_l2lve; static int is_pmu_based; /* There are only two frequency states for each processor. Values * are in kHz for the time being. */ #define CPUFREQ_HIGH 0 #define CPUFREQ_LOW 1 static struct cpufreq_frequency_table pmac_cpu_freqs[] = { {CPUFREQ_HIGH, 0}, {CPUFREQ_LOW, 0}, {0, CPUFREQ_TABLE_END}, }; static struct freq_attr* pmac_cpu_freqs_attr[] = { &cpufreq_freq_attr_scaling_available_freqs, NULL, }; static inline void local_delay(unsigned long ms) { if (no_schedule) mdelay(ms); else msleep(ms); } #ifdef DEBUG_FREQ static inline void debug_calc_bogomips(void) { /* This will cause a recalc of bogomips and display the * result. We backup/restore the value to avoid affecting the * core cpufreq framework's own calculation. */ unsigned long save_lpj = loops_per_jiffy; calibrate_delay(); loops_per_jiffy = save_lpj; } #endif /* DEBUG_FREQ */ /* Switch CPU speed under 750FX CPU control */ static int cpu_750fx_cpu_speed(int low_speed) { u32 hid2; if (low_speed == 0) { /* ramping up, set voltage first */ pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05); /* Make sure we sleep for at least 1ms */ local_delay(10); /* tweak L2 for high voltage */ if (has_cpu_l2lve) { hid2 = mfspr(SPRN_HID2); hid2 &= ~0x2000; mtspr(SPRN_HID2, hid2); } } #ifdef CONFIG_6xx low_choose_750fx_pll(low_speed); #endif if (low_speed == 1) { /* tweak L2 for low voltage */ if (has_cpu_l2lve) { hid2 = mfspr(SPRN_HID2); hid2 |= 0x2000; mtspr(SPRN_HID2, hid2); } /* ramping down, set voltage last */ pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04); local_delay(10); } return 0; } static unsigned int cpu_750fx_get_cpu_speed(void) { if (mfspr(SPRN_HID1) & HID1_PS) return low_freq; else return hi_freq; } /* Switch CPU speed using DFS */ static int dfs_set_cpu_speed(int low_speed) { if (low_speed == 0) { /* ramping up, set voltage first */ pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05); /* Make sure we sleep for at least 1ms */ local_delay(1); } /* set frequency */ #ifdef CONFIG_6xx low_choose_7447a_dfs(low_speed); #endif udelay(100); if (low_speed == 1) { /* ramping down, set voltage last */ pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04); local_delay(1); } return 0; } static unsigned int dfs_get_cpu_speed(void) { if (mfspr(SPRN_HID1) & HID1_DFS) return low_freq; else return hi_freq; } /* Switch CPU speed using slewing GPIOs */ static int gpios_set_cpu_speed(int low_speed) { int gpio, timeout = 0; /* If ramping up, set voltage first */ if (low_speed == 0) { pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05); /* Delay is way too big but it's ok, we schedule */ local_delay(10); } /* Set frequency */ gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0); if (low_speed == ((gpio & 0x01) == 0)) goto skip; pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, frequency_gpio, low_speed ? 0x04 : 0x05); udelay(200); do { if (++timeout > 100) break; local_delay(1); gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, slew_done_gpio, 0); } while((gpio & 0x02) == 0); skip: /* If ramping down, set voltage last */ if (low_speed == 1) { pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04); /* Delay is way too big but it's ok, we schedule */ local_delay(10); } #ifdef DEBUG_FREQ debug_calc_bogomips(); #endif return 0; } /* Switch CPU speed under PMU control */ static int pmu_set_cpu_speed(int low_speed) { struct adb_request req; unsigned long save_l2cr; unsigned long save_l3cr; unsigned int pic_prio; unsigned long flags; preempt_disable(); #ifdef DEBUG_FREQ printk(KERN_DEBUG "HID1, before: %x\n", mfspr(SPRN_HID1)); #endif pmu_suspend(); /* Disable all interrupt sources on openpic */ pic_prio = mpic_cpu_get_priority(); mpic_cpu_set_priority(0xf); /* Make sure the decrementer won't interrupt us */ asm volatile("mtdec %0" : : "r" (0x7fffffff)); /* Make sure any pending DEC interrupt occurring while we did * the above didn't re-enable the DEC */ mb(); asm volatile("mtdec %0" : : "r" (0x7fffffff)); /* We can now disable MSR_EE */ local_irq_save(flags); /* Giveup the FPU & vec */ enable_kernel_fp(); #ifdef CONFIG_ALTIVEC if (cpu_has_feature(CPU_FTR_ALTIVEC)) enable_kernel_altivec(); #endif /* CONFIG_ALTIVEC */ /* Save & disable L2 and L3 caches */ save_l3cr = _get_L3CR(); /* (returns -1 if not available) */ save_l2cr = _get_L2CR(); /* (returns -1 if not available) */ /* Send the new speed command. My assumption is that this command * will cause PLL_CFG[0..3] to be changed next time CPU goes to sleep */ pmu_request(&req, NULL, 6, PMU_CPU_SPEED, 'W', 'O', 'O', 'F', low_speed); while (!req.complete) pmu_poll(); /* Prepare the northbridge for the speed transition */ pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,1); /* Call low level code to backup CPU state and recover from * hardware reset */ low_sleep_handler(); /* Restore the northbridge */ pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,0); /* Restore L2 cache */ if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0) _set_L2CR(save_l2cr); /* Restore L3 cache */ if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0) _set_L3CR(save_l3cr); /* Restore userland MMU context */ switch_mmu_context(NULL, current->active_mm); #ifdef DEBUG_FREQ printk(KERN_DEBUG "HID1, after: %x\n", mfspr(SPRN_HID1)); #endif /* Restore low level PMU operations */ pmu_unlock(); /* * Restore decrementer; we'll take a decrementer interrupt * as soon as interrupts are re-enabled and the generic * clockevents code will reprogram it with the right value. */ set_dec(1); /* Restore interrupts */ mpic_cpu_set_priority(pic_prio); /* Let interrupts flow again ... */ local_irq_restore(flags); #ifdef DEBUG_FREQ debug_calc_bogomips(); #endif pmu_resume(); preempt_enable(); return 0; } static int do_set_cpu_speed(int speed_mode, int notify) { struct cpufreq_freqs freqs; unsigned long l3cr; static unsigned long prev_l3cr; freqs.old = cur_freq; freqs.new = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq; freqs.cpu = smp_processor_id(); if (freqs.old == freqs.new) return 0; if (notify) cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); if (speed_mode == CPUFREQ_LOW && cpu_has_feature(CPU_FTR_L3CR)) { l3cr = _get_L3CR(); if (l3cr & L3CR_L3E) { prev_l3cr = l3cr; _set_L3CR(0); } } set_speed_proc(speed_mode == CPUFREQ_LOW); if (speed_mode == CPUFREQ_HIGH && cpu_has_feature(CPU_FTR_L3CR)) { l3cr = _get_L3CR(); if ((prev_l3cr & L3CR_L3E) && l3cr != prev_l3cr) _set_L3CR(prev_l3cr); } if (notify) cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); cur_freq = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq; return 0; } static unsigned int pmac_cpufreq_get_speed(unsigned int cpu) { return cur_freq; } static int pmac_cpufreq_verify(struct cpufreq_policy *policy) { return cpufreq_frequency_table_verify(policy, pmac_cpu_freqs); } static int pmac_cpufreq_target( struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) { unsigned int newstate = 0; int rc; if (cpufreq_frequency_table_target(policy, pmac_cpu_freqs, target_freq, relation, &newstate)) return -EINVAL; rc = do_set_cpu_speed(newstate, 1); ppc_proc_freq = cur_freq * 1000ul; return rc; } static int pmac_cpufreq_cpu_init(struct cpufreq_policy *policy) { if (policy->cpu != 0) return -ENODEV; policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; policy->cur = cur_freq; cpufreq_frequency_table_get_attr(pmac_cpu_freqs, policy->cpu); return cpufreq_frequency_table_cpuinfo(policy, pmac_cpu_freqs); } static u32 read_gpio(struct device_node *np) { const u32 *reg = of_get_property(np, "reg", NULL); u32 offset; if (reg == NULL) return 0; /* That works for all keylargos but shall be fixed properly * some day... The problem is that it seems we can't rely * on the "reg" property of the GPIO nodes, they are either * relative to the base of KeyLargo or to the base of the * GPIO space, and the device-tree doesn't help. */ offset = *reg; if (offset < KEYLARGO_GPIO_LEVELS0) offset += KEYLARGO_GPIO_LEVELS0; return offset; } static int pmac_cpufreq_suspend(struct cpufreq_policy *policy) { /* Ok, this could be made a bit smarter, but let's be robust for now. We * always force a speed change to high speed before sleep, to make sure * we have appropriate voltage and/or bus speed for the wakeup process, * and to make sure our loops_per_jiffies are "good enough", that is will * not cause too short delays if we sleep in low speed and wake in high * speed.. */ no_schedule = 1; sleep_freq = cur_freq; if (cur_freq == low_freq && !is_pmu_based) do_set_cpu_speed(CPUFREQ_HIGH, 0); return 0; } static int pmac_cpufreq_resume(struct cpufreq_policy *policy) { /* If we resume, first check if we have a get() function */ if (get_speed_proc) cur_freq = get_speed_proc(); else cur_freq = 0; /* We don't, hrm... we don't really know our speed here, best * is that we force a switch to whatever it was, which is * probably high speed due to our suspend() routine */ do_set_cpu_speed(sleep_freq == low_freq ? CPUFREQ_LOW : CPUFREQ_HIGH, 0); ppc_proc_freq = cur_freq * 1000ul; no_schedule = 0; return 0; } static struct cpufreq_driver pmac_cpufreq_driver = { .verify = pmac_cpufreq_verify, .target = pmac_cpufreq_target, .get = pmac_cpufreq_get_speed, .init = pmac_cpufreq_cpu_init, .suspend = pmac_cpufreq_suspend, .resume = pmac_cpufreq_resume, .flags = CPUFREQ_PM_NO_WARN, .attr = pmac_cpu_freqs_attr, .name = "powermac", .owner = THIS_MODULE, }; static int pmac_cpufreq_init_MacRISC3(struct device_node *cpunode) { struct device_node *volt_gpio_np = of_find_node_by_name(NULL, "voltage-gpio"); struct device_node *freq_gpio_np = of_find_node_by_name(NULL, "frequency-gpio"); struct device_node *slew_done_gpio_np = of_find_node_by_name(NULL, "slewing-done"); const u32 *value; /* * Check to see if it's GPIO driven or PMU only * * The way we extract the GPIO address is slightly hackish, but it * works well enough for now. We need to abstract the whole GPIO * stuff sooner or later anyway */ if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); if (freq_gpio_np) frequency_gpio = read_gpio(freq_gpio_np); if (slew_done_gpio_np) slew_done_gpio = read_gpio(slew_done_gpio_np); /* If we use the frequency GPIOs, calculate the min/max speeds based * on the bus frequencies */ if (frequency_gpio && slew_done_gpio) { int lenp, rc; const u32 *freqs, *ratio; freqs = of_get_property(cpunode, "bus-frequencies", &lenp); lenp /= sizeof(u32); if (freqs == NULL || lenp != 2) { printk(KERN_ERR "cpufreq: bus-frequencies incorrect or missing\n"); return 1; } ratio = of_get_property(cpunode, "processor-to-bus-ratio*2", NULL); if (ratio == NULL) { printk(KERN_ERR "cpufreq: processor-to-bus-ratio*2 missing\n"); return 1; } /* Get the min/max bus frequencies */ low_freq = min(freqs[0], freqs[1]); hi_freq = max(freqs[0], freqs[1]); /* Grrrr.. It _seems_ that the device-tree is lying on the low bus * frequency, it claims it to be around 84Mhz on some models while * it appears to be approx. 101Mhz on all. Let's hack around here... * fortunately, we don't need to be too precise */ if (low_freq < 98000000) low_freq = 101000000; /* Convert those to CPU core clocks */ low_freq = (low_freq * (*ratio)) / 2000; hi_freq = (hi_freq * (*ratio)) / 2000; /* Now we get the frequencies, we read the GPIO to see what is out current * speed */ rc = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0); cur_freq = (rc & 0x01) ? hi_freq : low_freq; set_speed_proc = gpios_set_cpu_speed; return 1; } /* If we use the PMU, look for the min & max frequencies in the * device-tree */ value = of_get_property(cpunode, "min-clock-frequency", NULL); if (!value) return 1; low_freq = (*value) / 1000; /* The PowerBook G4 12" (PowerBook6,1) has an error in the device-tree * here */ if (low_freq < 100000) low_freq *= 10; value = of_get_property(cpunode, "max-clock-frequency", NULL); if (!value) return 1; hi_freq = (*value) / 1000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; return 0; } static int pmac_cpufreq_init_7447A(struct device_node *cpunode) { struct device_node *volt_gpio_np; if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL) return 1; volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select"); if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); if (!voltage_gpio){ printk(KERN_ERR "cpufreq: missing cpu-vcore-select gpio\n"); return 1; } /* OF only reports the high frequency */ hi_freq = cur_freq; low_freq = cur_freq/2; /* Read actual frequency from CPU */ cur_freq = dfs_get_cpu_speed(); set_speed_proc = dfs_set_cpu_speed; get_speed_proc = dfs_get_cpu_speed; return 0; } static int pmac_cpufreq_init_750FX(struct device_node *cpunode) { struct device_node *volt_gpio_np; u32 pvr; const u32 *value; if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL) return 1; hi_freq = cur_freq; value = of_get_property(cpunode, "reduced-clock-frequency", NULL); if (!value) return 1; low_freq = (*value) / 1000; volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select"); if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); pvr = mfspr(SPRN_PVR); has_cpu_l2lve = !((pvr & 0xf00) == 0x100); set_speed_proc = cpu_750fx_cpu_speed; get_speed_proc = cpu_750fx_get_cpu_speed; cur_freq = cpu_750fx_get_cpu_speed(); return 0; } /* Currently, we support the following machines: * * - Titanium PowerBook 1Ghz (PMU based, 667Mhz & 1Ghz) * - Titanium PowerBook 800 (PMU based, 667Mhz & 800Mhz) * - Titanium PowerBook 400 (PMU based, 300Mhz & 400Mhz) * - Titanium PowerBook 500 (PMU based, 300Mhz & 500Mhz) * - iBook2 500/600 (PMU based, 400Mhz & 500/600Mhz) * - iBook2 700 (CPU based, 400Mhz & 700Mhz, support low voltage) * - Recent MacRISC3 laptops * - All new machines with 7447A CPUs */ static int __init pmac_cpufreq_setup(void) { struct device_node *cpunode; const u32 *value; if (strstr(cmd_line, "nocpufreq")) return 0; /* Assume only one CPU */ cpunode = of_find_node_by_type(NULL, "cpu"); if (!cpunode) goto out; /* Get current cpu clock freq */ value = of_get_property(cpunode, "clock-frequency", NULL); if (!value) goto out; cur_freq = (*value) / 1000; /* Check for 7447A based MacRISC3 */ if (of_machine_is_compatible("MacRISC3") && of_get_property(cpunode, "dynamic-power-step", NULL) && PVR_VER(mfspr(SPRN_PVR)) == 0x8003) { pmac_cpufreq_init_7447A(cpunode); /* Check for other MacRISC3 machines */ } else if (of_machine_is_compatible("PowerBook3,4") || of_machine_is_compatible("PowerBook3,5") || of_machine_is_compatible("MacRISC3")) { pmac_cpufreq_init_MacRISC3(cpunode); /* Else check for iBook2 500/600 */ } else if (of_machine_is_compatible("PowerBook4,1")) { hi_freq = cur_freq; low_freq = 400000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for TiPb 550 */ else if (of_machine_is_compatible("PowerBook3,3") && cur_freq == 550000) { hi_freq = cur_freq; low_freq = 500000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for TiPb 400 & 500 */ else if (of_machine_is_compatible("PowerBook3,2")) { /* We only know about the 400 MHz and the 500Mhz model * they both have 300 MHz as low frequency */ if (cur_freq < 350000 || cur_freq > 550000) goto out; hi_freq = cur_freq; low_freq = 300000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for 750FX */ else if (PVR_VER(mfspr(SPRN_PVR)) == 0x7000) pmac_cpufreq_init_750FX(cpunode); out: of_node_put(cpunode); if (set_speed_proc == NULL) return -ENODEV; pmac_cpu_freqs[CPUFREQ_LOW].frequency = low_freq; pmac_cpu_freqs[CPUFREQ_HIGH].frequency = hi_freq; ppc_proc_freq = cur_freq * 1000ul; printk(KERN_INFO "Registering PowerMac CPU frequency driver\n"); printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Boot: %d Mhz\n", low_freq/1000, hi_freq/1000, cur_freq/1000); return cpufreq_register_driver(&pmac_cpufreq_driver); } module_init(pmac_cpufreq_setup);
gpl-2.0
bigbiff/android_kernel_samsung_n900
arch/tile/kernel/proc.c
4410
3586
/* * Copyright 2010 Tilera Corporation. All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, version 2. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for * more details. */ #include <linux/smp.h> #include <linux/seq_file.h> #include <linux/threads.h> #include <linux/cpumask.h> #include <linux/timex.h> #include <linux/delay.h> #include <linux/fs.h> #include <linux/proc_fs.h> #include <linux/sysctl.h> #include <linux/hardirq.h> #include <linux/mman.h> #include <asm/unaligned.h> #include <asm/pgtable.h> #include <asm/processor.h> #include <asm/sections.h> #include <asm/homecache.h> #include <asm/hardwall.h> #include <arch/chip.h> /* * Support /proc/cpuinfo */ #define cpu_to_ptr(n) ((void *)((long)(n)+1)) #define ptr_to_cpu(p) ((long)(p) - 1) static int show_cpuinfo(struct seq_file *m, void *v) { int n = ptr_to_cpu(v); if (n == 0) { char buf[NR_CPUS*5]; cpulist_scnprintf(buf, sizeof(buf), cpu_online_mask); seq_printf(m, "cpu count\t: %d\n", num_online_cpus()); seq_printf(m, "cpu list\t: %s\n", buf); seq_printf(m, "model name\t: %s\n", chip_model); seq_printf(m, "flags\t\t:\n"); /* nothing for now */ seq_printf(m, "cpu MHz\t\t: %llu.%06llu\n", get_clock_rate() / 1000000, (get_clock_rate() % 1000000)); seq_printf(m, "bogomips\t: %lu.%02lu\n\n", loops_per_jiffy/(500000/HZ), (loops_per_jiffy/(5000/HZ)) % 100); } #ifdef CONFIG_SMP if (!cpu_online(n)) return 0; #endif seq_printf(m, "processor\t: %d\n", n); /* Print only num_online_cpus() blank lines total. */ if (cpumask_next(n, cpu_online_mask) < nr_cpu_ids) seq_printf(m, "\n"); return 0; } static void *c_start(struct seq_file *m, loff_t *pos) { return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL; } static void *c_next(struct seq_file *m, void *v, loff_t *pos) { ++*pos; return c_start(m, pos); } static void c_stop(struct seq_file *m, void *v) { } const struct seq_operations cpuinfo_op = { .start = c_start, .next = c_next, .stop = c_stop, .show = show_cpuinfo, }; /* * Support /proc/tile directory */ static int __init proc_tile_init(void) { struct proc_dir_entry *root = proc_mkdir("tile", NULL); if (root == NULL) return 0; proc_tile_hardwall_init(root); return 0; } arch_initcall(proc_tile_init); /* * Support /proc/sys/tile directory */ #ifndef __tilegx__ /* FIXME: GX: no support for unaligned access yet */ static ctl_table unaligned_subtable[] = { { .procname = "enabled", .data = &unaligned_fixup, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec }, { .procname = "printk", .data = &unaligned_printk, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec }, { .procname = "count", .data = &unaligned_fixup_count, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec }, {} }; static ctl_table unaligned_table[] = { { .procname = "unaligned_fixup", .mode = 0555, .child = unaligned_subtable }, {} }; static struct ctl_path tile_path[] = { { .procname = "tile" }, { } }; static int __init proc_sys_tile_init(void) { register_sysctl_paths(tile_path, unaligned_table); return 0; } arch_initcall(proc_sys_tile_init); #endif
gpl-2.0
kyleterry/linux
drivers/char/hw_random/nomadik-rng.c
7226
2508
/* * Nomadik RNG support * Copyright 2009 Alessandro Rubini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/device.h> #include <linux/amba/bus.h> #include <linux/hw_random.h> #include <linux/io.h> #include <linux/clk.h> #include <linux/err.h> static struct clk *rng_clk; static int nmk_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { void __iomem *base = (void __iomem *)rng->priv; /* * The register is 32 bits and gives 16 random bits (low half). * A subsequent read will delay the core for 400ns, so we just read * once and accept the very unlikely very small delay, even if wait==0. */ *(u16 *)data = __raw_readl(base + 8) & 0xffff; return 2; } /* we have at most one RNG per machine, granted */ static struct hwrng nmk_rng = { .name = "nomadik", .read = nmk_rng_read, }; static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id) { void __iomem *base; int ret; rng_clk = clk_get(&dev->dev, NULL); if (IS_ERR(rng_clk)) { dev_err(&dev->dev, "could not get rng clock\n"); ret = PTR_ERR(rng_clk); return ret; } clk_enable(rng_clk); ret = amba_request_regions(dev, dev->dev.init_name); if (ret) goto out_clk; ret = -ENOMEM; base = ioremap(dev->res.start, resource_size(&dev->res)); if (!base) goto out_release; nmk_rng.priv = (unsigned long)base; ret = hwrng_register(&nmk_rng); if (ret) goto out_unmap; return 0; out_unmap: iounmap(base); out_release: amba_release_regions(dev); out_clk: clk_disable(rng_clk); clk_put(rng_clk); return ret; } static int nmk_rng_remove(struct amba_device *dev) { void __iomem *base = (void __iomem *)nmk_rng.priv; hwrng_unregister(&nmk_rng); iounmap(base); amba_release_regions(dev); clk_disable(rng_clk); clk_put(rng_clk); return 0; } static struct amba_id nmk_rng_ids[] = { { .id = 0x000805e1, .mask = 0x000fffff, /* top bits are rev and cfg: accept all */ }, {0, 0}, }; MODULE_DEVICE_TABLE(amba, nmk_rng_ids); static struct amba_driver nmk_rng_driver = { .drv = { .owner = THIS_MODULE, .name = "rng", }, .probe = nmk_rng_probe, .remove = nmk_rng_remove, .id_table = nmk_rng_ids, }; module_amba_driver(nmk_rng_driver); MODULE_LICENSE("GPL");
gpl-2.0
namko/MID-Kernel-3.0
arch/arm/mach-omap2/clkt2xxx_dpll.c
7994
1448
/* * OMAP2-specific DPLL control functions * * Copyright (C) 2011 Nokia Corporation * Paul Walmsley * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/clk.h> #include <linux/io.h> #include <plat/clock.h> #include "clock.h" #include "cm2xxx_3xxx.h" #include "cm-regbits-24xx.h" /* Private functions */ /** * _allow_idle - enable DPLL autoidle bits * @clk: struct clk * of the DPLL to operate on * * Enable DPLL automatic idle control. The DPLL will enter low-power * stop when its downstream clocks are gated. No return value. * REVISIT: DPLL can optionally enter low-power bypass by writing 0x1 * instead. Add some mechanism to optionally enter this mode. */ static void _allow_idle(struct clk *clk) { if (!clk || !clk->dpll_data) return; omap2xxx_cm_set_dpll_auto_low_power_stop(); } /** * _deny_idle - prevent DPLL from automatically idling * @clk: struct clk * of the DPLL to operate on * * Disable DPLL automatic idle control. No return value. */ static void _deny_idle(struct clk *clk) { if (!clk || !clk->dpll_data) return; omap2xxx_cm_set_dpll_disable_autoidle(); } /* Public data */ const struct clkops clkops_omap2xxx_dpll_ops = { .allow_idle = _allow_idle, .deny_idle = _deny_idle, };
gpl-2.0
gauravdatir/linux
security/tomoyo/group.c
9786
5761
/* * security/tomoyo/group.c * * Copyright (C) 2005-2011 NTT DATA CORPORATION */ #include <linux/slab.h> #include "common.h" /** * tomoyo_same_path_group - Check for duplicated "struct tomoyo_path_group" entry. * * @a: Pointer to "struct tomoyo_acl_head". * @b: Pointer to "struct tomoyo_acl_head". * * Returns true if @a == @b, false otherwise. */ static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a, const struct tomoyo_acl_head *b) { return container_of(a, struct tomoyo_path_group, head)->member_name == container_of(b, struct tomoyo_path_group, head)->member_name; } /** * tomoyo_same_number_group - Check for duplicated "struct tomoyo_number_group" entry. * * @a: Pointer to "struct tomoyo_acl_head". * @b: Pointer to "struct tomoyo_acl_head". * * Returns true if @a == @b, false otherwise. */ static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a, const struct tomoyo_acl_head *b) { return !memcmp(&container_of(a, struct tomoyo_number_group, head) ->number, &container_of(b, struct tomoyo_number_group, head) ->number, sizeof(container_of(a, struct tomoyo_number_group, head) ->number)); } /** * tomoyo_same_address_group - Check for duplicated "struct tomoyo_address_group" entry. * * @a: Pointer to "struct tomoyo_acl_head". * @b: Pointer to "struct tomoyo_acl_head". * * Returns true if @a == @b, false otherwise. */ static bool tomoyo_same_address_group(const struct tomoyo_acl_head *a, const struct tomoyo_acl_head *b) { const struct tomoyo_address_group *p1 = container_of(a, typeof(*p1), head); const struct tomoyo_address_group *p2 = container_of(b, typeof(*p2), head); return tomoyo_same_ipaddr_union(&p1->address, &p2->address); } /** * tomoyo_write_group - Write "struct tomoyo_path_group"/"struct tomoyo_number_group"/"struct tomoyo_address_group" list. * * @param: Pointer to "struct tomoyo_acl_param". * @type: Type of this group. * * Returns 0 on success, negative value otherwise. */ int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type) { struct tomoyo_group *group = tomoyo_get_group(param, type); int error = -EINVAL; if (!group) return -ENOMEM; param->list = &group->member_list; if (type == TOMOYO_PATH_GROUP) { struct tomoyo_path_group e = { }; e.member_name = tomoyo_get_name(tomoyo_read_token(param)); if (!e.member_name) { error = -ENOMEM; goto out; } error = tomoyo_update_policy(&e.head, sizeof(e), param, tomoyo_same_path_group); tomoyo_put_name(e.member_name); } else if (type == TOMOYO_NUMBER_GROUP) { struct tomoyo_number_group e = { }; if (param->data[0] == '@' || !tomoyo_parse_number_union(param, &e.number)) goto out; error = tomoyo_update_policy(&e.head, sizeof(e), param, tomoyo_same_number_group); /* * tomoyo_put_number_union() is not needed because * param->data[0] != '@'. */ } else { struct tomoyo_address_group e = { }; if (param->data[0] == '@' || !tomoyo_parse_ipaddr_union(param, &e.address)) goto out; error = tomoyo_update_policy(&e.head, sizeof(e), param, tomoyo_same_address_group); } out: tomoyo_put_group(group); return error; } /** * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group. * * @pathname: The name of pathname. * @group: Pointer to "struct tomoyo_path_group". * * Returns matched member's pathname if @pathname matches pathnames in @group, * NULL otherwise. * * Caller holds tomoyo_read_lock(). */ const struct tomoyo_path_info * tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, const struct tomoyo_group *group) { struct tomoyo_path_group *member; list_for_each_entry_rcu(member, &group->member_list, head.list) { if (member->head.is_deleted) continue; if (!tomoyo_path_matches_pattern(pathname, member->member_name)) continue; return member->member_name; } return NULL; } /** * tomoyo_number_matches_group - Check whether the given number matches members of the given number group. * * @min: Min number. * @max: Max number. * @group: Pointer to "struct tomoyo_number_group". * * Returns true if @min and @max partially overlaps @group, false otherwise. * * Caller holds tomoyo_read_lock(). */ bool tomoyo_number_matches_group(const unsigned long min, const unsigned long max, const struct tomoyo_group *group) { struct tomoyo_number_group *member; bool matched = false; list_for_each_entry_rcu(member, &group->member_list, head.list) { if (member->head.is_deleted) continue; if (min > member->number.values[1] || max < member->number.values[0]) continue; matched = true; break; } return matched; } /** * tomoyo_address_matches_group - Check whether the given address matches members of the given address group. * * @is_ipv6: True if @address is an IPv6 address. * @address: An IPv4 or IPv6 address. * @group: Pointer to "struct tomoyo_address_group". * * Returns true if @address matches addresses in @group group, false otherwise. * * Caller holds tomoyo_read_lock(). */ bool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address, const struct tomoyo_group *group) { struct tomoyo_address_group *member; bool matched = false; const u8 size = is_ipv6 ? 16 : 4; list_for_each_entry_rcu(member, &group->member_list, head.list) { if (member->head.is_deleted) continue; if (member->address.is_ipv6 != is_ipv6) continue; if (memcmp(&member->address.ip[0], address, size) > 0 || memcmp(address, &member->address.ip[1], size) > 0) continue; matched = true; break; } return matched; }
gpl-2.0
thicklizard/HTC-one-android-kernel
sound/isa/cs423x/cs4236_lib.c
12602
38406
/* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * Routines for control of CS4235/4236B/4237B/4238B/4239 chips * * Note: * ----- * * Bugs: * ----- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * Indirect control registers (CS4236B+) * * C0 * D8: WSS reset (all chips) * * C1 (all chips except CS4236) * D7-D5: version * D4-D0: chip id * 11101 - CS4235 * 01011 - CS4236B * 01000 - CS4237B * 01001 - CS4238B * 11110 - CS4239 * * C2 * D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239) * D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B) * * C3 * D7: 3D Enable (CS4237B) * D6: 3D Mono Enable (CS4237B) * D5: 3D Serial Output (CS4237B,CS4238B) * D4: 3D Enable (CS4235,CS4238B,CS4239) * * C4 * D7: consumer serial port enable (CS4237B,CS4238B) * D6: channels status block reset (CS4237B,CS4238B) * D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B) * D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B) * * C5 lower channel status (digital serial data description) (CS4237B,CS4238B) * D7-D6: first two bits of category code * D5: lock * D4-D3: pre-emphasis (0 = none, 1 = 50/15us) * D2: copy/copyright (0 = copy inhibited) * D1: 0 = digital audio / 1 = non-digital audio * * C6 upper channel status (digital serial data description) (CS4237B,CS4238B) * D7-D6: sample frequency (0 = 44.1kHz) * D5: generation status (0 = no indication, 1 = original/commercially precaptureed data) * D4-D0: category code (upper bits) * * C7 reserved (must write 0) * * C8 wavetable control * D7: volume control interrupt enable (CS4235,CS4239) * D6: hardware volume control format (CS4235,CS4239) * D3: wavetable serial port enable (all chips) * D2: DSP serial port switch (all chips) * D1: disable MCLK (all chips) * D0: force BRESET low (all chips) * */ #include <asm/io.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/time.h> #include <linux/wait.h> #include <sound/core.h> #include <sound/wss.h> #include <sound/asoundef.h> #include <sound/initval.h> #include <sound/tlv.h> /* * */ static unsigned char snd_cs4236_ext_map[18] = { /* CS4236_LEFT_LINE */ 0xff, /* CS4236_RIGHT_LINE */ 0xff, /* CS4236_LEFT_MIC */ 0xdf, /* CS4236_RIGHT_MIC */ 0xdf, /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18, /* CS4236_RIGHT_MIX_CTRL */ 0xe0, /* CS4236_LEFT_FM */ 0xbf, /* CS4236_RIGHT_FM */ 0xbf, /* CS4236_LEFT_DSP */ 0xbf, /* CS4236_RIGHT_DSP */ 0xbf, /* CS4236_RIGHT_LOOPBACK */ 0xbf, /* CS4236_DAC_MUTE */ 0xe0, /* CS4236_ADC_RATE */ 0x01, /* 48kHz */ /* CS4236_DAC_RATE */ 0x01, /* 48kHz */ /* CS4236_LEFT_MASTER */ 0xbf, /* CS4236_RIGHT_MASTER */ 0xbf, /* CS4236_LEFT_WAVE */ 0xbf, /* CS4236_RIGHT_WAVE */ 0xbf }; /* * */ static void snd_cs4236_ctrl_out(struct snd_wss *chip, unsigned char reg, unsigned char val) { outb(reg, chip->cport + 3); outb(chip->cimage[reg] = val, chip->cport + 4); } static unsigned char snd_cs4236_ctrl_in(struct snd_wss *chip, unsigned char reg) { outb(reg, chip->cport + 3); return inb(chip->cport + 4); } /* * PCM */ #define CLOCKS 8 static struct snd_ratnum clocks[CLOCKS] = { { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 }, { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 }, { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 }, { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 }, { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 }, { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 }, { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 }, { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 } }; static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { .nrats = CLOCKS, .rats = clocks, }; static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime) { return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_clocks); } static unsigned char divisor_to_rate_register(unsigned int divisor) { switch (divisor) { case 353: return 1; case 529: return 2; case 617: return 3; case 1058: return 4; case 1764: return 5; case 2117: return 6; case 2558: return 7; default: if (divisor < 21 || divisor > 192) { snd_BUG(); return 192; } return divisor; } } static void snd_cs4236_playback_format(struct snd_wss *chip, struct snd_pcm_hw_params *params, unsigned char pdfr) { unsigned long flags; unsigned char rate = divisor_to_rate_register(params->rate_den); spin_lock_irqsave(&chip->reg_lock, flags); /* set fast playback format change and clean playback FIFO */ snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10); snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0); snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x10); snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate); spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs4236_capture_format(struct snd_wss *chip, struct snd_pcm_hw_params *params, unsigned char cdfr) { unsigned long flags; unsigned char rate = divisor_to_rate_register(params->rate_den); spin_lock_irqsave(&chip->reg_lock, flags); /* set fast capture format change and clean capture FIFO */ snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20); snd_wss_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0); snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x20); snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate); spin_unlock_irqrestore(&chip->reg_lock, flags); } #ifdef CONFIG_PM static void snd_cs4236_suspend(struct snd_wss *chip) { int reg; unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); for (reg = 0; reg < 32; reg++) chip->image[reg] = snd_wss_in(chip, reg); for (reg = 0; reg < 18; reg++) chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg)); for (reg = 2; reg < 9; reg++) chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg); spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs4236_resume(struct snd_wss *chip) { int reg; unsigned long flags; snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); for (reg = 0; reg < 32; reg++) { switch (reg) { case CS4236_EXT_REG: case CS4231_VERSION: case 27: /* why? CS4235 - master left */ case 29: /* why? CS4235 - master right */ break; default: snd_wss_out(chip, reg, chip->image[reg]); break; } } for (reg = 0; reg < 18; reg++) snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]); for (reg = 2; reg < 9; reg++) { switch (reg) { case 7: break; default: snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]); } } spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); } #endif /* CONFIG_PM */ /* * This function does no fail if the chip is not CS4236B or compatible. * It just an equivalent to the snd_wss_create() then. */ int snd_cs4236_create(struct snd_card *card, unsigned long port, unsigned long cport, int irq, int dma1, int dma2, unsigned short hardware, unsigned short hwshare, struct snd_wss **rchip) { struct snd_wss *chip; unsigned char ver1, ver2; unsigned int reg; int err; *rchip = NULL; if (hardware == WSS_HW_DETECT) hardware = WSS_HW_DETECT3; err = snd_wss_create(card, port, cport, irq, dma1, dma2, hardware, hwshare, &chip); if (err < 0) return err; if ((chip->hardware & WSS_HW_CS4236B_MASK) == 0) { snd_printd("chip is not CS4236+, hardware=0x%x\n", chip->hardware); *rchip = chip; return 0; } #if 0 { int idx; for (idx = 0; idx < 8; idx++) snd_printk(KERN_DEBUG "CD%i = 0x%x\n", idx, inb(chip->cport + idx)); for (idx = 0; idx < 9; idx++) snd_printk(KERN_DEBUG "C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx)); } #endif if (cport < 0x100 || cport == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR "please, specify control port " "for CS4236+ chips\n"); snd_device_free(card, chip); return -ENODEV; } ver1 = snd_cs4236_ctrl_in(chip, 1); ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); if (ver1 != ver2) { snd_printk(KERN_ERR "CS4236+ chip detected, but " "control port 0x%lx is not valid\n", cport); snd_device_free(card, chip); return -ENODEV; } snd_cs4236_ctrl_out(chip, 0, 0x00); snd_cs4236_ctrl_out(chip, 2, 0xff); snd_cs4236_ctrl_out(chip, 3, 0x00); snd_cs4236_ctrl_out(chip, 4, 0x80); reg = ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE; snd_cs4236_ctrl_out(chip, 5, reg); snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2); snd_cs4236_ctrl_out(chip, 7, 0x00); /* * 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 * output is working with this setup, other hardware should * have different signal paths and this value should be * selectable in the future */ snd_cs4236_ctrl_out(chip, 8, 0x8c); chip->rate_constraint = snd_cs4236_xrate; chip->set_playback_format = snd_cs4236_playback_format; chip->set_capture_format = snd_cs4236_capture_format; #ifdef CONFIG_PM chip->suspend = snd_cs4236_suspend; chip->resume = snd_cs4236_resume; #endif /* initialize extended registers */ for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++) snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]); /* initialize compatible but more featured registers */ snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40); snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40); snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff); snd_wss_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff); snd_wss_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf); snd_wss_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf); snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); snd_wss_out(chip, CS4231_LEFT_LINE_IN, 0xff); snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); switch (chip->hardware) { case WSS_HW_CS4235: case WSS_HW_CS4239: snd_wss_out(chip, CS4235_LEFT_MASTER, 0xff); snd_wss_out(chip, CS4235_RIGHT_MASTER, 0xff); break; } *rchip = chip; return 0; } int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm) { struct snd_pcm *pcm; int err; err = snd_wss_pcm(chip, device, &pcm); if (err < 0) return err; pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX; if (rpcm) *rpcm = pcm; return 0; } /* * MIXER */ #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } #define CS4236_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 16) & 0xff; uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = mask; return 0; } static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; return 0; } static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; int change; unsigned short val; val = (ucontrol->value.integer.value[0] & mask); if (invert) val = mask - val; val <<= shift; spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val; change = val != chip->eimage[CS4236_REG(reg)]; snd_cs4236_ext_out(chip, reg, val); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; return 0; } static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; int change; unsigned short val; val = (ucontrol->value.integer.value[0] & mask); if (invert) val = mask - val; val <<= shift; spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->cimage[reg] & ~(mask << shift)) | val; change = val != chip->cimage[reg]; snd_cs4236_ctrl_out(chip, reg, val); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } #define CS4236_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \ (shift_right << 19) | (mask << 24) | (invert << 22), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 24) & 0xff; uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = mask; return 0; } static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask; ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) { ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; } return 0; } static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; int change; unsigned short val1, val2; val1 = ucontrol->value.integer.value[0] & mask; val2 = ucontrol->value.integer.value[1] & mask; if (invert) { val1 = mask - val1; val2 = mask - val2; } val1 <<= shift_left; val2 <<= shift_right; spin_lock_irqsave(&chip->reg_lock, flags); if (left_reg != right_reg) { val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1; val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)]; snd_cs4236_ext_out(chip, left_reg, val1); snd_cs4236_ext_out(chip, right_reg, val2); } else { val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; change = val1 != chip->eimage[CS4236_REG(left_reg)]; snd_cs4236_ext_out(chip, left_reg, val1); } spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } #define CS4236_DOUBLE1_TLV(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \ (shift_right << 19) | (mask << 24) | (invert << 22), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) { ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; } return 0; } static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; int change; unsigned short val1, val2; val1 = ucontrol->value.integer.value[0] & mask; val2 = ucontrol->value.integer.value[1] & mask; if (invert) { val1 = mask - val1; val2 = mask - val2; } val1 <<= shift_left; val2 <<= shift_right; spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)]; snd_wss_out(chip, left_reg, val1); snd_cs4236_ext_out(chip, right_reg, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_MASTER_DIGITAL(xname, xindex, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \ .private_value = 71 << 24, \ .tlv = { .p = (xtlv) } } static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol) { return (vol < 64) ? 63 - vol : 64 + (71 - vol); } static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f); ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short val1, val2; val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f); val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f); spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1; val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2; change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)]; snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1); snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4235_OUTPUT_ACCU(xname, xindex, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \ .private_value = 3 << 24, \ .tlv = { .p = (xtlv) } } static inline int snd_cs4235_mixer_output_accu_get_volume(int vol) { switch ((vol >> 5) & 3) { case 0: return 1; case 1: return 3; case 2: return 2; case 3: return 0; } return 3; } static inline int snd_cs4235_mixer_output_accu_set_volume(int vol) { switch (vol & 3) { case 0: return 3 << 5; case 1: return 0 << 5; case 2: return 2 << 5; case 3: return 1 << 5; } return 1 << 5; } static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]); ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short val1, val2; val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]); val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]); spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1; val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2; change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER]; snd_wss_out(chip, CS4235_LEFT_MASTER, val1); snd_wss_out(chip, CS4235_RIGHT_MASTER, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -9450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_6bit_12db_max, -8250, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_5bit_22db_max, -2400, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0); static const DECLARE_TLV_DB_SCALE(db_scale_2bit, -1800, 600, 0); static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); static struct snd_kcontrol_new snd_cs4236_controls[] = { CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), CS4236_MASTER_DIGITAL("Master Digital Volume", 0, db_scale_7bit), CS4236_DOUBLE_TLV("Capture Boost Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1, db_scale_2bit), WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("DSP Playback Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), CS4236_DOUBLE_TLV("DSP Playback Volume", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("FM Playback Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), CS4236_DOUBLE_TLV("FM Playback Volume", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("Wavetable Playback Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), CS4236_DOUBLE_TLV("Wavetable Playback Volume", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1, db_scale_6bit_12db_max), WSS_DOUBLE("Synth Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), WSS_DOUBLE_TLV("Synth Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("Synth Capture Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), WSS_DOUBLE("Synth Capture Bypass", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1), CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), CS4236_DOUBLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1, db_scale_5bit_22db_max), CS4236_DOUBLE("Mic Playback Boost (+20dB)", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0), WSS_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE("Line Capture Bypass", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1), WSS_DOUBLE("CD Playback Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("CD Volume", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("CD Capture Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), CS4236_DOUBLE1("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), CS4236_DOUBLE1("Beep Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), WSS_SINGLE_TLV("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1, db_scale_4bit), WSS_SINGLE("Beep Bypass Playback Switch", 0, CS4231_MONO_CTRL, 5, 1, 0), WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0, db_scale_rec_gain), WSS_DOUBLE("Analog Loopback Capture Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), WSS_SINGLE("Loopback Digital Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0), CS4236_DOUBLE1_TLV("Loopback Digital Playback Volume", 0, CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1, db_scale_6bit), }; static const DECLARE_TLV_DB_SCALE(db_scale_5bit_6db_max, -5600, 200, 0); static const DECLARE_TLV_DB_SCALE(db_scale_2bit_16db_max, -2400, 800, 0); static struct snd_kcontrol_new snd_cs4235_controls[] = { WSS_DOUBLE("Master Playback Switch", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1), WSS_DOUBLE_TLV("Master Playback Volume", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1, db_scale_5bit_6db_max), CS4235_OUTPUT_ACCU("Playback Volume", 0, db_scale_2bit_16db_max), WSS_DOUBLE("Synth Playback Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), WSS_DOUBLE("Synth Capture Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), WSS_DOUBLE_TLV("Synth Volume", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1, db_scale_5bit_12db_max), CS4236_DOUBLE_TLV("Capture Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1, db_scale_2bit), WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), WSS_DOUBLE("PCM Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), WSS_DOUBLE_TLV("PCM Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), CS4236_DOUBLE("Wavetable Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), CS4236_SINGLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1, db_scale_5bit_22db_max), CS4236_SINGLE("Mic Boost (+20dB)", 0, CS4236_LEFT_MIC, 5, 1, 0), WSS_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE_TLV("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("CD Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE("CD Capture Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE_TLV("CD Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), CS4236_DOUBLE1("Beep Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), WSS_SINGLE("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), WSS_DOUBLE("Analog Loopback Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), }; #define CS4236_IEC958_ENABLE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \ .private_value = 1 << 16 } static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0; #if 0 printk(KERN_DEBUG "get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", snd_wss_in(chip, CS4231_ALT_FEATURE_1), snd_cs4236_ctrl_in(chip, 3), snd_cs4236_ctrl_in(chip, 4), snd_cs4236_ctrl_in(chip, 5), snd_cs4236_ctrl_in(chip, 6), snd_cs4236_ctrl_in(chip, 8)); #endif spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short enable, val; enable = ucontrol->value.integer.value[0] & 1; mutex_lock(&chip->mce_mutex); snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1); change = val != chip->image[CS4231_ALT_FEATURE_1]; snd_wss_out(chip, CS4231_ALT_FEATURE_1, val); val = snd_cs4236_ctrl_in(chip, 4) | 0xc0; snd_cs4236_ctrl_out(chip, 4, val); udelay(100); val &= ~0x40; snd_cs4236_ctrl_out(chip, 4, val); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); mutex_unlock(&chip->mce_mutex); #if 0 printk(KERN_DEBUG "set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", snd_wss_in(chip, CS4231_ALT_FEATURE_1), snd_cs4236_ctrl_in(chip, 3), snd_cs4236_ctrl_in(chip, 4), snd_cs4236_ctrl_in(chip, 5), snd_cs4236_ctrl_in(chip, 6), snd_cs4236_ctrl_in(chip, 8)); #endif return change; } static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = { CS4236_IEC958_ENABLE("IEC958 Output Enable", 0), CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0), CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0), CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0), CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0), CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1), CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0), CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1), CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) }; int snd_cs4236_mixer(struct snd_wss *chip) { struct snd_card *card; unsigned int idx, count; int err; struct snd_kcontrol_new *kcontrol; if (snd_BUG_ON(!chip || !chip->card)) return -EINVAL; card = chip->card; strcpy(card->mixername, snd_wss_chip_id(chip)); if (chip->hardware == WSS_HW_CS4235 || chip->hardware == WSS_HW_CS4239) { for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0) return err; } } else { for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0) return err; } } switch (chip->hardware) { case WSS_HW_CS4235: case WSS_HW_CS4239: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235); kcontrol = snd_cs4236_3d_controls_cs4235; break; case WSS_HW_CS4237B: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237); kcontrol = snd_cs4236_3d_controls_cs4237; break; case WSS_HW_CS4238B: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238); kcontrol = snd_cs4236_3d_controls_cs4238; break; default: count = 0; kcontrol = NULL; } for (idx = 0; idx < count; idx++, kcontrol++) { if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0) return err; } if (chip->hardware == WSS_HW_CS4237B || chip->hardware == WSS_HW_CS4238B) { for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0) return err; } } return 0; }
gpl-2.0
yinquan529/pandaboard
sound/isa/cs423x/cs4236_lib.c
12602
38406
/* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * Routines for control of CS4235/4236B/4237B/4238B/4239 chips * * Note: * ----- * * Bugs: * ----- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * Indirect control registers (CS4236B+) * * C0 * D8: WSS reset (all chips) * * C1 (all chips except CS4236) * D7-D5: version * D4-D0: chip id * 11101 - CS4235 * 01011 - CS4236B * 01000 - CS4237B * 01001 - CS4238B * 11110 - CS4239 * * C2 * D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239) * D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B) * * C3 * D7: 3D Enable (CS4237B) * D6: 3D Mono Enable (CS4237B) * D5: 3D Serial Output (CS4237B,CS4238B) * D4: 3D Enable (CS4235,CS4238B,CS4239) * * C4 * D7: consumer serial port enable (CS4237B,CS4238B) * D6: channels status block reset (CS4237B,CS4238B) * D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B) * D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B) * * C5 lower channel status (digital serial data description) (CS4237B,CS4238B) * D7-D6: first two bits of category code * D5: lock * D4-D3: pre-emphasis (0 = none, 1 = 50/15us) * D2: copy/copyright (0 = copy inhibited) * D1: 0 = digital audio / 1 = non-digital audio * * C6 upper channel status (digital serial data description) (CS4237B,CS4238B) * D7-D6: sample frequency (0 = 44.1kHz) * D5: generation status (0 = no indication, 1 = original/commercially precaptureed data) * D4-D0: category code (upper bits) * * C7 reserved (must write 0) * * C8 wavetable control * D7: volume control interrupt enable (CS4235,CS4239) * D6: hardware volume control format (CS4235,CS4239) * D3: wavetable serial port enable (all chips) * D2: DSP serial port switch (all chips) * D1: disable MCLK (all chips) * D0: force BRESET low (all chips) * */ #include <asm/io.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/time.h> #include <linux/wait.h> #include <sound/core.h> #include <sound/wss.h> #include <sound/asoundef.h> #include <sound/initval.h> #include <sound/tlv.h> /* * */ static unsigned char snd_cs4236_ext_map[18] = { /* CS4236_LEFT_LINE */ 0xff, /* CS4236_RIGHT_LINE */ 0xff, /* CS4236_LEFT_MIC */ 0xdf, /* CS4236_RIGHT_MIC */ 0xdf, /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18, /* CS4236_RIGHT_MIX_CTRL */ 0xe0, /* CS4236_LEFT_FM */ 0xbf, /* CS4236_RIGHT_FM */ 0xbf, /* CS4236_LEFT_DSP */ 0xbf, /* CS4236_RIGHT_DSP */ 0xbf, /* CS4236_RIGHT_LOOPBACK */ 0xbf, /* CS4236_DAC_MUTE */ 0xe0, /* CS4236_ADC_RATE */ 0x01, /* 48kHz */ /* CS4236_DAC_RATE */ 0x01, /* 48kHz */ /* CS4236_LEFT_MASTER */ 0xbf, /* CS4236_RIGHT_MASTER */ 0xbf, /* CS4236_LEFT_WAVE */ 0xbf, /* CS4236_RIGHT_WAVE */ 0xbf }; /* * */ static void snd_cs4236_ctrl_out(struct snd_wss *chip, unsigned char reg, unsigned char val) { outb(reg, chip->cport + 3); outb(chip->cimage[reg] = val, chip->cport + 4); } static unsigned char snd_cs4236_ctrl_in(struct snd_wss *chip, unsigned char reg) { outb(reg, chip->cport + 3); return inb(chip->cport + 4); } /* * PCM */ #define CLOCKS 8 static struct snd_ratnum clocks[CLOCKS] = { { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 }, { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 }, { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 }, { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 }, { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 }, { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 }, { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 }, { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 } }; static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { .nrats = CLOCKS, .rats = clocks, }; static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime) { return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_clocks); } static unsigned char divisor_to_rate_register(unsigned int divisor) { switch (divisor) { case 353: return 1; case 529: return 2; case 617: return 3; case 1058: return 4; case 1764: return 5; case 2117: return 6; case 2558: return 7; default: if (divisor < 21 || divisor > 192) { snd_BUG(); return 192; } return divisor; } } static void snd_cs4236_playback_format(struct snd_wss *chip, struct snd_pcm_hw_params *params, unsigned char pdfr) { unsigned long flags; unsigned char rate = divisor_to_rate_register(params->rate_den); spin_lock_irqsave(&chip->reg_lock, flags); /* set fast playback format change and clean playback FIFO */ snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10); snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0); snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x10); snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate); spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs4236_capture_format(struct snd_wss *chip, struct snd_pcm_hw_params *params, unsigned char cdfr) { unsigned long flags; unsigned char rate = divisor_to_rate_register(params->rate_den); spin_lock_irqsave(&chip->reg_lock, flags); /* set fast capture format change and clean capture FIFO */ snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20); snd_wss_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0); snd_wss_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x20); snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate); spin_unlock_irqrestore(&chip->reg_lock, flags); } #ifdef CONFIG_PM static void snd_cs4236_suspend(struct snd_wss *chip) { int reg; unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); for (reg = 0; reg < 32; reg++) chip->image[reg] = snd_wss_in(chip, reg); for (reg = 0; reg < 18; reg++) chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg)); for (reg = 2; reg < 9; reg++) chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg); spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs4236_resume(struct snd_wss *chip) { int reg; unsigned long flags; snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); for (reg = 0; reg < 32; reg++) { switch (reg) { case CS4236_EXT_REG: case CS4231_VERSION: case 27: /* why? CS4235 - master left */ case 29: /* why? CS4235 - master right */ break; default: snd_wss_out(chip, reg, chip->image[reg]); break; } } for (reg = 0; reg < 18; reg++) snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]); for (reg = 2; reg < 9; reg++) { switch (reg) { case 7: break; default: snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]); } } spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); } #endif /* CONFIG_PM */ /* * This function does no fail if the chip is not CS4236B or compatible. * It just an equivalent to the snd_wss_create() then. */ int snd_cs4236_create(struct snd_card *card, unsigned long port, unsigned long cport, int irq, int dma1, int dma2, unsigned short hardware, unsigned short hwshare, struct snd_wss **rchip) { struct snd_wss *chip; unsigned char ver1, ver2; unsigned int reg; int err; *rchip = NULL; if (hardware == WSS_HW_DETECT) hardware = WSS_HW_DETECT3; err = snd_wss_create(card, port, cport, irq, dma1, dma2, hardware, hwshare, &chip); if (err < 0) return err; if ((chip->hardware & WSS_HW_CS4236B_MASK) == 0) { snd_printd("chip is not CS4236+, hardware=0x%x\n", chip->hardware); *rchip = chip; return 0; } #if 0 { int idx; for (idx = 0; idx < 8; idx++) snd_printk(KERN_DEBUG "CD%i = 0x%x\n", idx, inb(chip->cport + idx)); for (idx = 0; idx < 9; idx++) snd_printk(KERN_DEBUG "C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx)); } #endif if (cport < 0x100 || cport == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR "please, specify control port " "for CS4236+ chips\n"); snd_device_free(card, chip); return -ENODEV; } ver1 = snd_cs4236_ctrl_in(chip, 1); ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); if (ver1 != ver2) { snd_printk(KERN_ERR "CS4236+ chip detected, but " "control port 0x%lx is not valid\n", cport); snd_device_free(card, chip); return -ENODEV; } snd_cs4236_ctrl_out(chip, 0, 0x00); snd_cs4236_ctrl_out(chip, 2, 0xff); snd_cs4236_ctrl_out(chip, 3, 0x00); snd_cs4236_ctrl_out(chip, 4, 0x80); reg = ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE; snd_cs4236_ctrl_out(chip, 5, reg); snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2); snd_cs4236_ctrl_out(chip, 7, 0x00); /* * 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 * output is working with this setup, other hardware should * have different signal paths and this value should be * selectable in the future */ snd_cs4236_ctrl_out(chip, 8, 0x8c); chip->rate_constraint = snd_cs4236_xrate; chip->set_playback_format = snd_cs4236_playback_format; chip->set_capture_format = snd_cs4236_capture_format; #ifdef CONFIG_PM chip->suspend = snd_cs4236_suspend; chip->resume = snd_cs4236_resume; #endif /* initialize extended registers */ for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++) snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]); /* initialize compatible but more featured registers */ snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40); snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40); snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff); snd_wss_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff); snd_wss_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf); snd_wss_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf); snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); snd_wss_out(chip, CS4231_LEFT_LINE_IN, 0xff); snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff); switch (chip->hardware) { case WSS_HW_CS4235: case WSS_HW_CS4239: snd_wss_out(chip, CS4235_LEFT_MASTER, 0xff); snd_wss_out(chip, CS4235_RIGHT_MASTER, 0xff); break; } *rchip = chip; return 0; } int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm) { struct snd_pcm *pcm; int err; err = snd_wss_pcm(chip, device, &pcm); if (err < 0) return err; pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX; if (rpcm) *rpcm = pcm; return 0; } /* * MIXER */ #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } #define CS4236_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 16) & 0xff; uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = mask; return 0; } static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; return 0; } static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; int change; unsigned short val; val = (ucontrol->value.integer.value[0] & mask); if (invert) val = mask - val; val <<= shift; spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val; change = val != chip->eimage[CS4236_REG(reg)]; snd_cs4236_ext_out(chip, reg, val); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; return 0; } static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; int change; unsigned short val; val = (ucontrol->value.integer.value[0] & mask); if (invert) val = mask - val; val <<= shift; spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->cimage[reg] & ~(mask << shift)) | val; change = val != chip->cimage[reg]; snd_cs4236_ctrl_out(chip, reg, val); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } #define CS4236_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \ (shift_right << 19) | (mask << 24) | (invert << 22), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 24) & 0xff; uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = mask; return 0; } static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask; ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) { ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; } return 0; } static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; int change; unsigned short val1, val2; val1 = ucontrol->value.integer.value[0] & mask; val2 = ucontrol->value.integer.value[1] & mask; if (invert) { val1 = mask - val1; val2 = mask - val2; } val1 <<= shift_left; val2 <<= shift_right; spin_lock_irqsave(&chip->reg_lock, flags); if (left_reg != right_reg) { val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1; val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)]; snd_cs4236_ext_out(chip, left_reg, val1); snd_cs4236_ext_out(chip, right_reg, val2); } else { val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; change = val1 != chip->eimage[CS4236_REG(left_reg)]; snd_cs4236_ext_out(chip, left_reg, val1); } spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } #define CS4236_DOUBLE1_TLV(xname, xindex, left_reg, right_reg, shift_left, \ shift_right, mask, invert, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \ (shift_right << 19) | (mask << 24) | (invert << 22), \ .tlv = { .p = (xtlv) } } static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask; spin_unlock_irqrestore(&chip->reg_lock, flags); if (invert) { ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; } return 0; } static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; int shift_right = (kcontrol->private_value >> 19) & 0x07; int mask = (kcontrol->private_value >> 24) & 0xff; int invert = (kcontrol->private_value >> 22) & 1; int change; unsigned short val1, val2; val1 = ucontrol->value.integer.value[0] & mask; val2 = ucontrol->value.integer.value[1] & mask; if (invert) { val1 = mask - val1; val2 = mask - val2; } val1 <<= shift_left; val2 <<= shift_right; spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2; change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)]; snd_wss_out(chip, left_reg, val1); snd_cs4236_ext_out(chip, right_reg, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4236_MASTER_DIGITAL(xname, xindex, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \ .private_value = 71 << 24, \ .tlv = { .p = (xtlv) } } static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol) { return (vol < 64) ? 63 - vol : 64 + (71 - vol); } static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f); ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short val1, val2; val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f); val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f); spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1; val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2; change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)]; snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1); snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } #define CS4235_OUTPUT_ACCU(xname, xindex, xtlv) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_cs4236_info_double, \ .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \ .private_value = 3 << 24, \ .tlv = { .p = (xtlv) } } static inline int snd_cs4235_mixer_output_accu_get_volume(int vol) { switch ((vol >> 5) & 3) { case 0: return 1; case 1: return 3; case 2: return 2; case 3: return 0; } return 3; } static inline int snd_cs4235_mixer_output_accu_set_volume(int vol) { switch (vol & 3) { case 0: return 3 << 5; case 1: return 0 << 5; case 2: return 2 << 5; case 3: return 1 << 5; } return 1 << 5; } static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]); ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short val1, val2; val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]); val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]); spin_lock_irqsave(&chip->reg_lock, flags); val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1; val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2; change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER]; snd_wss_out(chip, CS4235_LEFT_MASTER, val1); snd_wss_out(chip, CS4235_RIGHT_MASTER, val2); spin_unlock_irqrestore(&chip->reg_lock, flags); return change; } static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -9450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_6bit_12db_max, -8250, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_5bit_22db_max, -2400, 150, 0); static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0); static const DECLARE_TLV_DB_SCALE(db_scale_2bit, -1800, 600, 0); static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); static struct snd_kcontrol_new snd_cs4236_controls[] = { CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), CS4236_MASTER_DIGITAL("Master Digital Volume", 0, db_scale_7bit), CS4236_DOUBLE_TLV("Capture Boost Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1, db_scale_2bit), WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("DSP Playback Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), CS4236_DOUBLE_TLV("DSP Playback Volume", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("FM Playback Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), CS4236_DOUBLE_TLV("FM Playback Volume", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("Wavetable Playback Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), CS4236_DOUBLE_TLV("Wavetable Playback Volume", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1, db_scale_6bit_12db_max), WSS_DOUBLE("Synth Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), WSS_DOUBLE_TLV("Synth Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("Synth Capture Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), WSS_DOUBLE("Synth Capture Bypass", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1), CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), CS4236_DOUBLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1, db_scale_5bit_22db_max), CS4236_DOUBLE("Mic Playback Boost (+20dB)", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0), WSS_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE("Line Capture Bypass", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1), WSS_DOUBLE("CD Playback Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE_TLV("CD Volume", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("CD Capture Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), CS4236_DOUBLE1("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), CS4236_DOUBLE1("Beep Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), WSS_SINGLE_TLV("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1, db_scale_4bit), WSS_SINGLE("Beep Bypass Playback Switch", 0, CS4231_MONO_CTRL, 5, 1, 0), WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0, db_scale_rec_gain), WSS_DOUBLE("Analog Loopback Capture Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), WSS_SINGLE("Loopback Digital Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0), CS4236_DOUBLE1_TLV("Loopback Digital Playback Volume", 0, CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1, db_scale_6bit), }; static const DECLARE_TLV_DB_SCALE(db_scale_5bit_6db_max, -5600, 200, 0); static const DECLARE_TLV_DB_SCALE(db_scale_2bit_16db_max, -2400, 800, 0); static struct snd_kcontrol_new snd_cs4235_controls[] = { WSS_DOUBLE("Master Playback Switch", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1), WSS_DOUBLE_TLV("Master Playback Volume", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1, db_scale_5bit_6db_max), CS4235_OUTPUT_ACCU("Playback Volume", 0, db_scale_2bit_16db_max), WSS_DOUBLE("Synth Playback Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), WSS_DOUBLE("Synth Capture Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), WSS_DOUBLE_TLV("Synth Volume", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1, db_scale_5bit_12db_max), CS4236_DOUBLE_TLV("Capture Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1, db_scale_2bit), WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), WSS_DOUBLE("PCM Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), WSS_DOUBLE_TLV("PCM Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, db_scale_6bit), CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), CS4236_DOUBLE("Wavetable Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), CS4236_SINGLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1, db_scale_5bit_22db_max), CS4236_SINGLE("Mic Boost (+20dB)", 0, CS4236_LEFT_MIC, 5, 1, 0), WSS_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE_TLV("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), WSS_DOUBLE("CD Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), WSS_DOUBLE("CD Capture Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), WSS_DOUBLE_TLV("CD Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, db_scale_5bit_12db_max), CS4236_DOUBLE1("Beep Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), WSS_SINGLE("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), WSS_DOUBLE("Analog Loopback Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), }; #define CS4236_IEC958_ENABLE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_cs4236_info_single, \ .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \ .private_value = 1 << 16 } static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0; #if 0 printk(KERN_DEBUG "get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", snd_wss_in(chip, CS4231_ALT_FEATURE_1), snd_cs4236_ctrl_in(chip, 3), snd_cs4236_ctrl_in(chip, 4), snd_cs4236_ctrl_in(chip, 5), snd_cs4236_ctrl_in(chip, 6), snd_cs4236_ctrl_in(chip, 8)); #endif spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_wss *chip = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned short enable, val; enable = ucontrol->value.integer.value[0] & 1; mutex_lock(&chip->mce_mutex); snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1); change = val != chip->image[CS4231_ALT_FEATURE_1]; snd_wss_out(chip, CS4231_ALT_FEATURE_1, val); val = snd_cs4236_ctrl_in(chip, 4) | 0xc0; snd_cs4236_ctrl_out(chip, 4, val); udelay(100); val &= ~0x40; snd_cs4236_ctrl_out(chip, 4, val); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); mutex_unlock(&chip->mce_mutex); #if 0 printk(KERN_DEBUG "set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, " "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", snd_wss_in(chip, CS4231_ALT_FEATURE_1), snd_cs4236_ctrl_in(chip, 3), snd_cs4236_ctrl_in(chip, 4), snd_cs4236_ctrl_in(chip, 5), snd_cs4236_ctrl_in(chip, 6), snd_cs4236_ctrl_in(chip, 8)); #endif return change; } static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = { CS4236_IEC958_ENABLE("IEC958 Output Enable", 0), CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0), CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0), CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0), CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0), CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1), CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0), CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) }; static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = { CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0), CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1), CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1), CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0) }; int snd_cs4236_mixer(struct snd_wss *chip) { struct snd_card *card; unsigned int idx, count; int err; struct snd_kcontrol_new *kcontrol; if (snd_BUG_ON(!chip || !chip->card)) return -EINVAL; card = chip->card; strcpy(card->mixername, snd_wss_chip_id(chip)); if (chip->hardware == WSS_HW_CS4235 || chip->hardware == WSS_HW_CS4239) { for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0) return err; } } else { for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0) return err; } } switch (chip->hardware) { case WSS_HW_CS4235: case WSS_HW_CS4239: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235); kcontrol = snd_cs4236_3d_controls_cs4235; break; case WSS_HW_CS4237B: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237); kcontrol = snd_cs4236_3d_controls_cs4237; break; case WSS_HW_CS4238B: count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238); kcontrol = snd_cs4236_3d_controls_cs4238; break; default: count = 0; kcontrol = NULL; } for (idx = 0; idx < count; idx++, kcontrol++) { if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0) return err; } if (chip->hardware == WSS_HW_CS4237B || chip->hardware == WSS_HW_CS4238B) { for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0) return err; } } return 0; }
gpl-2.0
mwhudson/qemu
target-ppc/mem_helper.c
59
9090
/* * PowerPC memory access emulation helpers for QEMU. * * Copyright (c) 2003-2007 Jocelyn Mayer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "cpu.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" #include "helper_regs.h" #include "exec/cpu_ldst.h" //#define DEBUG_OP static inline bool needs_byteswap(const CPUPPCState *env) { #if defined(TARGET_WORDS_BIGENDIAN) return msr_le; #else return !msr_le; #endif } /*****************************************************************************/ /* Memory load and stores */ static inline target_ulong addr_add(CPUPPCState *env, target_ulong addr, target_long arg) { #if defined(TARGET_PPC64) if (!msr_is_64bit(env, env->msr)) { return (uint32_t)(addr + arg); } else #endif { return addr + arg; } } void helper_lmw(CPUPPCState *env, target_ulong addr, uint32_t reg) { for (; reg < 32; reg++) { if (needs_byteswap(env)) { env->gpr[reg] = bswap32(cpu_ldl_data(env, addr)); } else { env->gpr[reg] = cpu_ldl_data(env, addr); } addr = addr_add(env, addr, 4); } } void helper_stmw(CPUPPCState *env, target_ulong addr, uint32_t reg) { for (; reg < 32; reg++) { if (needs_byteswap(env)) { cpu_stl_data(env, addr, bswap32((uint32_t)env->gpr[reg])); } else { cpu_stl_data(env, addr, (uint32_t)env->gpr[reg]); } addr = addr_add(env, addr, 4); } } void helper_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb, uint32_t reg) { int sh; for (; nb > 3; nb -= 4) { env->gpr[reg] = cpu_ldl_data(env, addr); reg = (reg + 1) % 32; addr = addr_add(env, addr, 4); } if (unlikely(nb > 0)) { env->gpr[reg] = 0; for (sh = 24; nb > 0; nb--, sh -= 8) { env->gpr[reg] |= cpu_ldub_data(env, addr) << sh; addr = addr_add(env, addr, 1); } } } /* PPC32 specification says we must generate an exception if * rA is in the range of registers to be loaded. * In an other hand, IBM says this is valid, but rA won't be loaded. * For now, I'll follow the spec... */ void helper_lswx(CPUPPCState *env, target_ulong addr, uint32_t reg, uint32_t ra, uint32_t rb) { if (likely(xer_bc != 0)) { if (unlikely((ra != 0 && reg < ra && (reg + xer_bc) > ra) || (reg < rb && (reg + xer_bc) > rb))) { helper_raise_exception_err(env, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX); } else { helper_lsw(env, addr, xer_bc, reg); } } } void helper_stsw(CPUPPCState *env, target_ulong addr, uint32_t nb, uint32_t reg) { int sh; for (; nb > 3; nb -= 4) { cpu_stl_data(env, addr, env->gpr[reg]); reg = (reg + 1) % 32; addr = addr_add(env, addr, 4); } if (unlikely(nb > 0)) { for (sh = 24; nb > 0; nb--, sh -= 8) { cpu_stb_data(env, addr, (env->gpr[reg] >> sh) & 0xFF); addr = addr_add(env, addr, 1); } } } static void do_dcbz(CPUPPCState *env, target_ulong addr, int dcache_line_size) { int i; addr &= ~(dcache_line_size - 1); for (i = 0; i < dcache_line_size; i += 4) { cpu_stl_data(env, addr + i, 0); } if (env->reserve_addr == addr) { env->reserve_addr = (target_ulong)-1ULL; } } void helper_dcbz(CPUPPCState *env, target_ulong addr, uint32_t is_dcbzl) { int dcbz_size = env->dcache_line_size; #if defined(TARGET_PPC64) if (!is_dcbzl && (env->excp_model == POWERPC_EXCP_970) && ((env->spr[SPR_970_HID5] >> 7) & 0x3) == 1) { dcbz_size = 32; } #endif /* XXX add e500mc support */ do_dcbz(env, addr, dcbz_size); } void helper_icbi(CPUPPCState *env, target_ulong addr) { addr &= ~(env->dcache_line_size - 1); /* Invalidate one cache line : * PowerPC specification says this is to be treated like a load * (not a fetch) by the MMU. To be sure it will be so, * do the load "by hand". */ cpu_ldl_data(env, addr); } /* XXX: to be tested */ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg, uint32_t ra, uint32_t rb) { int i, c, d; d = 24; for (i = 0; i < xer_bc; i++) { c = cpu_ldub_data(env, addr); addr = addr_add(env, addr, 1); /* ra (if not 0) and rb are never modified */ if (likely(reg != rb && (ra == 0 || reg != ra))) { env->gpr[reg] = (env->gpr[reg] & ~(0xFF << d)) | (c << d); } if (unlikely(c == xer_cmp)) { break; } if (likely(d != 0)) { d -= 8; } else { d = 24; reg++; reg = reg & 0x1F; } } return i; } /*****************************************************************************/ /* Altivec extension helpers */ #if defined(HOST_WORDS_BIGENDIAN) #define HI_IDX 0 #define LO_IDX 1 #else #define HI_IDX 1 #define LO_IDX 0 #endif /* We use msr_le to determine index ordering in a vector. However, byteswapping is not simply controlled by msr_le. We also need to take into account endianness of the target. This is done for the little-endian PPC64 user-mode target. */ #define LVE(name, access, swap, element) \ void helper_##name(CPUPPCState *env, ppc_avr_t *r, \ target_ulong addr) \ { \ size_t n_elems = ARRAY_SIZE(r->element); \ int adjust = HI_IDX*(n_elems - 1); \ int sh = sizeof(r->element[0]) >> 1; \ int index = (addr & 0xf) >> sh; \ if (msr_le) { \ index = n_elems - index - 1; \ } \ \ if (needs_byteswap(env)) { \ r->element[LO_IDX ? index : (adjust - index)] = \ swap(access(env, addr)); \ } else { \ r->element[LO_IDX ? index : (adjust - index)] = \ access(env, addr); \ } \ } #define I(x) (x) LVE(lvebx, cpu_ldub_data, I, u8) LVE(lvehx, cpu_lduw_data, bswap16, u16) LVE(lvewx, cpu_ldl_data, bswap32, u32) #undef I #undef LVE #define STVE(name, access, swap, element) \ void helper_##name(CPUPPCState *env, ppc_avr_t *r, \ target_ulong addr) \ { \ size_t n_elems = ARRAY_SIZE(r->element); \ int adjust = HI_IDX * (n_elems - 1); \ int sh = sizeof(r->element[0]) >> 1; \ int index = (addr & 0xf) >> sh; \ if (msr_le) { \ index = n_elems - index - 1; \ } \ \ if (needs_byteswap(env)) { \ access(env, addr, swap(r->element[LO_IDX ? index : \ (adjust - index)])); \ } else { \ access(env, addr, r->element[LO_IDX ? index : \ (adjust - index)]); \ } \ } #define I(x) (x) STVE(stvebx, cpu_stb_data, I, u8) STVE(stvehx, cpu_stw_data, bswap16, u16) STVE(stvewx, cpu_stl_data, bswap32, u32) #undef I #undef LVE #undef HI_IDX #undef LO_IDX
gpl-2.0
zabereer/qmk_firmware
keyboards/handwired/jtallbean/split_65/keymaps/default/keymap.c
59
3398
/* Copyright 2020 jtallbean * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include QMK_KEYBOARD_H // Defines names for use in layer keycodes and the keymap enum layer_names { _BASE, _DN, _UP }; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Base */ [_BASE] = LAYOUT_all( KC_NO, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_GRV, KC_BSPC, KC_INS, KC_PGUP, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_PGDN, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_HOME, MO(_UP), KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END, MO(_DN), KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT ), /* Down */ [_DN] = LAYOUT_all( _______, KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, KC_MUTE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLU, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), /* Up */ [_UP] = LAYOUT_all( _______, _______, _______, _______, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, _______, _______, _______, _______, _______, KC_MPLY, _______, _______, _______, _______, _______, _______, _______, _______, KC_P4, KC_P5, KC_P6, _______, _______, _______, _______, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, KC_P1, KC_P2, KC_P3, _______, _______, _______, KC_MPRV, _______, _______, _______, _______, _______, _______, _______, _______, KC_P0, _______, _______, _______, _______, _______, KC_MSTP, _______, _______, _______, _______, _______, KC_P0, _______, _______, _______, _______, _______, _______ ), };
gpl-2.0
clemsyn/Clemsyn-OC-kernel
security/commoncap.c
315
28745
/* Common capabilities, needed by capability.o and root_plug.o * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ #include <linux/capability.h> #include <linux/audit.h> #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/security.h> #include <linux/file.h> #include <linux/mm.h> #include <linux/mman.h> #include <linux/pagemap.h> #include <linux/swap.h> #include <linux/skbuff.h> #include <linux/netlink.h> #include <linux/ptrace.h> #include <linux/xattr.h> #include <linux/hugetlb.h> #include <linux/mount.h> #include <linux/sched.h> #include <linux/prctl.h> #include <linux/securebits.h> #ifdef CONFIG_ANDROID_PARANOID_NETWORK #include <linux/android_aid.h> #endif /* * If a non-root user executes a setuid-root binary in * !secure(SECURE_NOROOT) mode, then we raise capabilities. * However if fE is also set, then the intent is for only * the file capabilities to be applied, and the setuid-root * bit is left on either to change the uid (plausible) or * to get full privilege on a kernel without file capabilities * support. So in that case we do not raise capabilities. * * Warn if that happens, once per boot. */ static void warn_setuid_and_fcaps_mixed(char *fname) { static int warned; if (!warned) { printk(KERN_INFO "warning: `%s' has both setuid-root and" " effective capabilities. Therefore not raising all" " capabilities.\n", fname); warned = 1; } } int cap_netlink_send(struct sock *sk, struct sk_buff *skb) { NETLINK_CB(skb).eff_cap = current_cap(); return 0; } int cap_netlink_recv(struct sk_buff *skb, int cap) { if (!cap_raised(NETLINK_CB(skb).eff_cap, cap)) return -EPERM; return 0; } EXPORT_SYMBOL(cap_netlink_recv); /** * cap_capable - Determine whether a task has a particular effective capability * @tsk: The task to query * @cred: The credentials to use * @cap: The capability to check for * @audit: Whether to write an audit message or not * * Determine whether the nominated task has the specified capability amongst * its effective set, returning 0 if it does, -ve if it does not. * * NOTE WELL: cap_has_capability() cannot be used like the kernel's capable() * and has_capability() functions. That is, it has the reverse semantics: * cap_has_capability() returns 0 when a task has a capability, but the * kernel's capable() and has_capability() returns 1 for this case. */ int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap, int audit) { #ifdef CONFIG_ANDROID_PARANOID_NETWORK if (cap == CAP_NET_RAW && in_egroup_p(AID_NET_RAW)) return 0; if (cap == CAP_NET_ADMIN && in_egroup_p(AID_NET_ADMIN)) return 0; #endif return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM; } /** * cap_settime - Determine whether the current process may set the system clock * @ts: The time to set * @tz: The timezone to set * * Determine whether the current process may set the system clock and timezone * information, returning 0 if permission granted, -ve if denied. */ int cap_settime(struct timespec *ts, struct timezone *tz) { if (!capable(CAP_SYS_TIME)) return -EPERM; return 0; } /** * cap_ptrace_access_check - Determine whether the current process may access * another * @child: The process to be accessed * @mode: The mode of attachment. * * Determine whether a process may access another, returning 0 if permission * granted, -ve if denied. */ int cap_ptrace_access_check(struct task_struct *child, unsigned int mode) { int ret = 0; rcu_read_lock(); if (!cap_issubset(__task_cred(child)->cap_permitted, current_cred()->cap_permitted) && !capable(CAP_SYS_PTRACE)) ret = -EPERM; rcu_read_unlock(); return ret; } /** * cap_ptrace_traceme - Determine whether another process may trace the current * @parent: The task proposed to be the tracer * * Determine whether the nominated task is permitted to trace the current * process, returning 0 if permission is granted, -ve if denied. */ int cap_ptrace_traceme(struct task_struct *parent) { int ret = 0; rcu_read_lock(); if (!cap_issubset(current_cred()->cap_permitted, __task_cred(parent)->cap_permitted) && !has_capability(parent, CAP_SYS_PTRACE)) ret = -EPERM; rcu_read_unlock(); return ret; } /** * cap_capget - Retrieve a task's capability sets * @target: The task from which to retrieve the capability sets * @effective: The place to record the effective set * @inheritable: The place to record the inheritable set * @permitted: The place to record the permitted set * * This function retrieves the capabilities of the nominated task and returns * them to the caller. */ int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) { const struct cred *cred; /* Derived from kernel/capability.c:sys_capget. */ rcu_read_lock(); cred = __task_cred(target); *effective = cred->cap_effective; *inheritable = cred->cap_inheritable; *permitted = cred->cap_permitted; rcu_read_unlock(); return 0; } /* * Determine whether the inheritable capabilities are limited to the old * permitted set. Returns 1 if they are limited, 0 if they are not. */ static inline int cap_inh_is_capped(void) { #ifdef CONFIG_SECURITY_FILE_CAPABILITIES /* they are so limited unless the current task has the CAP_SETPCAP * capability */ if (cap_capable(current, current_cred(), CAP_SETPCAP, SECURITY_CAP_AUDIT) == 0) return 0; #endif return 1; } /** * cap_capset - Validate and apply proposed changes to current's capabilities * @new: The proposed new credentials; alterations should be made here * @old: The current task's current credentials * @effective: A pointer to the proposed new effective capabilities set * @inheritable: A pointer to the proposed new inheritable capabilities set * @permitted: A pointer to the proposed new permitted capabilities set * * This function validates and applies a proposed mass change to the current * process's capability sets. The changes are made to the proposed new * credentials, and assuming no error, will be committed by the caller of LSM. */ int cap_capset(struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable, const kernel_cap_t *permitted) { if (cap_inh_is_capped() && !cap_issubset(*inheritable, cap_combine(old->cap_inheritable, old->cap_permitted))) /* incapable of using this inheritable set */ return -EPERM; if (!cap_issubset(*inheritable, cap_combine(old->cap_inheritable, old->cap_bset))) /* no new pI capabilities outside bounding set */ return -EPERM; /* verify restrictions on target's new Permitted set */ if (!cap_issubset(*permitted, old->cap_permitted)) return -EPERM; /* verify the _new_Effective_ is a subset of the _new_Permitted_ */ if (!cap_issubset(*effective, *permitted)) return -EPERM; new->cap_effective = *effective; new->cap_inheritable = *inheritable; new->cap_permitted = *permitted; return 0; } /* * Clear proposed capability sets for execve(). */ static inline void bprm_clear_caps(struct linux_binprm *bprm) { cap_clear(bprm->cred->cap_permitted); bprm->cap_effective = false; } #ifdef CONFIG_SECURITY_FILE_CAPABILITIES /** * cap_inode_need_killpriv - Determine if inode change affects privileges * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV * * Determine if an inode having a change applied that's marked ATTR_KILL_PRIV * affects the security markings on that inode, and if it is, should * inode_killpriv() be invoked or the change rejected? * * Returns 0 if granted; +ve if granted, but inode_killpriv() is required; and * -ve to deny the change. */ int cap_inode_need_killpriv(struct dentry *dentry) { struct inode *inode = dentry->d_inode; int error; if (!inode->i_op->getxattr) return 0; error = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, NULL, 0); if (error <= 0) return 0; return 1; } /** * cap_inode_killpriv - Erase the security markings on an inode * @dentry: The inode/dentry to alter * * Erase the privilege-enhancing security markings on an inode. * * Returns 0 if successful, -ve on error. */ int cap_inode_killpriv(struct dentry *dentry) { struct inode *inode = dentry->d_inode; if (!inode->i_op->removexattr) return 0; return inode->i_op->removexattr(dentry, XATTR_NAME_CAPS); } /* * Calculate the new process capability sets from the capability sets attached * to a file. */ static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps, struct linux_binprm *bprm, bool *effective) { struct cred *new = bprm->cred; unsigned i; int ret = 0; if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE) *effective = true; CAP_FOR_EACH_U32(i) { __u32 permitted = caps->permitted.cap[i]; __u32 inheritable = caps->inheritable.cap[i]; /* * pP' = (X & fP) | (pI & fI) */ new->cap_permitted.cap[i] = (new->cap_bset.cap[i] & permitted) | (new->cap_inheritable.cap[i] & inheritable); if (permitted & ~new->cap_permitted.cap[i]) /* insufficient to execute correctly */ ret = -EPERM; } /* * For legacy apps, with no internal support for recognizing they * do not have enough capabilities, we return an error if they are * missing some "forced" (aka file-permitted) capabilities. */ return *effective ? ret : 0; } /* * Extract the on-exec-apply capability sets for an executable file. */ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps) { struct inode *inode = dentry->d_inode; __u32 magic_etc; unsigned tocopy, i; int size; struct vfs_cap_data caps; memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data)); if (!inode || !inode->i_op->getxattr) return -ENODATA; size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &caps, XATTR_CAPS_SZ); if (size == -ENODATA || size == -EOPNOTSUPP) /* no data, that's ok */ return -ENODATA; if (size < 0) return size; if (size < sizeof(magic_etc)) return -EINVAL; cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps.magic_etc); switch (magic_etc & VFS_CAP_REVISION_MASK) { case VFS_CAP_REVISION_1: if (size != XATTR_CAPS_SZ_1) return -EINVAL; tocopy = VFS_CAP_U32_1; break; case VFS_CAP_REVISION_2: if (size != XATTR_CAPS_SZ_2) return -EINVAL; tocopy = VFS_CAP_U32_2; break; default: return -EINVAL; } CAP_FOR_EACH_U32(i) { if (i >= tocopy) break; cpu_caps->permitted.cap[i] = le32_to_cpu(caps.data[i].permitted); cpu_caps->inheritable.cap[i] = le32_to_cpu(caps.data[i].inheritable); } return 0; } /* * Attempt to get the on-exec apply capability sets for an executable file from * its xattrs and, if present, apply them to the proposed credentials being * constructed by execve(). */ static int get_file_caps(struct linux_binprm *bprm, bool *effective) { struct dentry *dentry; int rc = 0; struct cpu_vfs_cap_data vcaps; bprm_clear_caps(bprm); if (!file_caps_enabled) return 0; if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) return 0; dentry = dget(bprm->file->f_dentry); rc = get_vfs_caps_from_disk(dentry, &vcaps); if (rc < 0) { if (rc == -EINVAL) printk(KERN_NOTICE "%s: get_vfs_caps_from_disk returned %d for %s\n", __func__, rc, bprm->filename); else if (rc == -ENODATA) rc = 0; goto out; } rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective); if (rc == -EINVAL) printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n", __func__, rc, bprm->filename); out: dput(dentry); if (rc) bprm_clear_caps(bprm); return rc; } #else int cap_inode_need_killpriv(struct dentry *dentry) { return 0; } int cap_inode_killpriv(struct dentry *dentry) { return 0; } int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps) { memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data)); return -ENODATA; } static inline int get_file_caps(struct linux_binprm *bprm, bool *effective) { bprm_clear_caps(bprm); return 0; } #endif /* * Determine whether a exec'ing process's new permitted capabilities should be * limited to just what it already has. * * This prevents processes that are being ptraced from gaining access to * CAP_SETPCAP, unless the process they're tracing already has it, and the * binary they're executing has filecaps that elevate it. * * Returns 1 if they should be limited, 0 if they are not. */ static inline int cap_limit_ptraced_target(void) { #ifndef CONFIG_SECURITY_FILE_CAPABILITIES if (capable(CAP_SETPCAP)) return 0; #endif return 1; } /** * cap_bprm_set_creds - Set up the proposed credentials for execve(). * @bprm: The execution parameters, including the proposed creds * * Set up the proposed credentials for a new execution context being * constructed by execve(). The proposed creds in @bprm->cred is altered, * which won't take effect immediately. Returns 0 if successful, -ve on error. */ int cap_bprm_set_creds(struct linux_binprm *bprm) { const struct cred *old = current_cred(); struct cred *new = bprm->cred; bool effective; int ret; effective = false; ret = get_file_caps(bprm, &effective); if (ret < 0) return ret; if (!issecure(SECURE_NOROOT)) { /* * If the legacy file capability is set, then don't set privs * for a setuid root binary run by a non-root user. Do set it * for a root user just to cause least surprise to an admin. */ if (effective && new->uid != 0 && new->euid == 0) { warn_setuid_and_fcaps_mixed(bprm->filename); goto skip; } /* * To support inheritance of root-permissions and suid-root * executables under compatibility mode, we override the * capability sets for the file. * * If only the real uid is 0, we do not set the effective bit. */ if (new->euid == 0 || new->uid == 0) { /* pP' = (cap_bset & ~0) | (pI & ~0) */ new->cap_permitted = cap_combine(old->cap_bset, old->cap_inheritable); } if (new->euid == 0) effective = true; } skip: /* Don't let someone trace a set[ug]id/setpcap binary with the revised * credentials unless they have the appropriate permit */ if ((new->euid != old->uid || new->egid != old->gid || !cap_issubset(new->cap_permitted, old->cap_permitted)) && bprm->unsafe & ~LSM_UNSAFE_PTRACE_CAP) { /* downgrade; they get no more than they had, and maybe less */ if (!capable(CAP_SETUID)) { new->euid = new->uid; new->egid = new->gid; } if (cap_limit_ptraced_target()) new->cap_permitted = cap_intersect(new->cap_permitted, old->cap_permitted); } new->suid = new->fsuid = new->euid; new->sgid = new->fsgid = new->egid; /* For init, we want to retain the capabilities set in the initial * task. Thus we skip the usual capability rules */ if (!is_global_init(current)) { if (effective) new->cap_effective = new->cap_permitted; else cap_clear(new->cap_effective); } bprm->cap_effective = effective; /* * Audit candidate if current->cap_effective is set * * We do not bother to audit if 3 things are true: * 1) cap_effective has all caps * 2) we are root * 3) root is supposed to have all caps (SECURE_NOROOT) * Since this is just a normal root execing a process. * * Number 1 above might fail if you don't have a full bset, but I think * that is interesting information to audit. */ if (!cap_isclear(new->cap_effective)) { if (!cap_issubset(CAP_FULL_SET, new->cap_effective) || new->euid != 0 || new->uid != 0 || issecure(SECURE_NOROOT)) { ret = audit_log_bprm_fcaps(bprm, new, old); if (ret < 0) return ret; } } new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS); return 0; } /** * cap_bprm_secureexec - Determine whether a secure execution is required * @bprm: The execution parameters * * Determine whether a secure execution is required, return 1 if it is, and 0 * if it is not. * * The credentials have been committed by this point, and so are no longer * available through @bprm->cred. */ int cap_bprm_secureexec(struct linux_binprm *bprm) { const struct cred *cred = current_cred(); if (cred->uid != 0) { if (bprm->cap_effective) return 1; if (!cap_isclear(cred->cap_permitted)) return 1; } return (cred->euid != cred->uid || cred->egid != cred->gid); } /** * cap_inode_setxattr - Determine whether an xattr may be altered * @dentry: The inode/dentry being altered * @name: The name of the xattr to be changed * @value: The value that the xattr will be changed to * @size: The size of value * @flags: The replacement flag * * Determine whether an xattr may be altered or set on an inode, returning 0 if * permission is granted, -ve if denied. * * This is used to make sure security xattrs don't get updated or set by those * who aren't privileged to do so. */ int cap_inode_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) { if (!strcmp(name, XATTR_NAME_CAPS)) { if (!capable(CAP_SETFCAP)) return -EPERM; return 0; } if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) && !capable(CAP_SYS_ADMIN)) return -EPERM; return 0; } /** * cap_inode_removexattr - Determine whether an xattr may be removed * @dentry: The inode/dentry being altered * @name: The name of the xattr to be changed * * Determine whether an xattr may be removed from an inode, returning 0 if * permission is granted, -ve if denied. * * This is used to make sure security xattrs don't get removed by those who * aren't privileged to remove them. */ int cap_inode_removexattr(struct dentry *dentry, const char *name) { if (!strcmp(name, XATTR_NAME_CAPS)) { if (!capable(CAP_SETFCAP)) return -EPERM; return 0; } if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) && !capable(CAP_SYS_ADMIN)) return -EPERM; return 0; } /* * cap_emulate_setxuid() fixes the effective / permitted capabilities of * a process after a call to setuid, setreuid, or setresuid. * * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of * {r,e,s}uid != 0, the permitted and effective capabilities are * cleared. * * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective * capabilities of the process are cleared. * * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective * capabilities are set to the permitted capabilities. * * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should * never happen. * * -astor * * cevans - New behaviour, Oct '99 * A process may, via prctl(), elect to keep its capabilities when it * calls setuid() and switches away from uid==0. Both permitted and * effective sets will be retained. * Without this change, it was impossible for a daemon to drop only some * of its privilege. The call to setuid(!=0) would drop all privileges! * Keeping uid 0 is not an option because uid 0 owns too many vital * files.. * Thanks to Olaf Kirch and Peter Benie for spotting this. */ static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old) { if ((old->uid == 0 || old->euid == 0 || old->suid == 0) && (new->uid != 0 && new->euid != 0 && new->suid != 0) && !issecure(SECURE_KEEP_CAPS)) { cap_clear(new->cap_permitted); cap_clear(new->cap_effective); } if (old->euid == 0 && new->euid != 0) cap_clear(new->cap_effective); if (old->euid != 0 && new->euid == 0) new->cap_effective = new->cap_permitted; } /** * cap_task_fix_setuid - Fix up the results of setuid() call * @new: The proposed credentials * @old: The current task's current credentials * @flags: Indications of what has changed * * Fix up the results of setuid() call before the credential changes are * actually applied, returning 0 to grant the changes, -ve to deny them. */ int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags) { switch (flags) { case LSM_SETID_RE: case LSM_SETID_ID: case LSM_SETID_RES: /* juggle the capabilities to follow [RES]UID changes unless * otherwise suppressed */ if (!issecure(SECURE_NO_SETUID_FIXUP)) cap_emulate_setxuid(new, old); break; case LSM_SETID_FS: /* juggle the capabilties to follow FSUID changes, unless * otherwise suppressed * * FIXME - is fsuser used for all CAP_FS_MASK capabilities? * if not, we might be a bit too harsh here. */ if (!issecure(SECURE_NO_SETUID_FIXUP)) { if (old->fsuid == 0 && new->fsuid != 0) new->cap_effective = cap_drop_fs_set(new->cap_effective); if (old->fsuid != 0 && new->fsuid == 0) new->cap_effective = cap_raise_fs_set(new->cap_effective, new->cap_permitted); } break; default: return -EINVAL; } return 0; } #ifdef CONFIG_SECURITY_FILE_CAPABILITIES /* * Rationale: code calling task_setscheduler, task_setioprio, and * task_setnice, assumes that * . if capable(cap_sys_nice), then those actions should be allowed * . if not capable(cap_sys_nice), but acting on your own processes, * then those actions should be allowed * This is insufficient now since you can call code without suid, but * yet with increased caps. * So we check for increased caps on the target process. */ static int cap_safe_nice(struct task_struct *p) { int is_subset; rcu_read_lock(); is_subset = cap_issubset(__task_cred(p)->cap_permitted, current_cred()->cap_permitted); rcu_read_unlock(); if (!is_subset && !capable(CAP_SYS_NICE)) return -EPERM; return 0; } /** * cap_task_setscheduler - Detemine if scheduler policy change is permitted * @p: The task to affect * @policy: The policy to effect * @lp: The parameters to the scheduling policy * * Detemine if the requested scheduler policy change is permitted for the * specified task, returning 0 if permission is granted, -ve if denied. */ int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp) { return cap_safe_nice(p); } /** * cap_task_ioprio - Detemine if I/O priority change is permitted * @p: The task to affect * @ioprio: The I/O priority to set * * Detemine if the requested I/O priority change is permitted for the specified * task, returning 0 if permission is granted, -ve if denied. */ int cap_task_setioprio(struct task_struct *p, int ioprio) { return cap_safe_nice(p); } /** * cap_task_ioprio - Detemine if task priority change is permitted * @p: The task to affect * @nice: The nice value to set * * Detemine if the requested task priority change is permitted for the * specified task, returning 0 if permission is granted, -ve if denied. */ int cap_task_setnice(struct task_struct *p, int nice) { return cap_safe_nice(p); } /* * Implement PR_CAPBSET_DROP. Attempt to remove the specified capability from * the current task's bounding set. Returns 0 on success, -ve on error. */ static long cap_prctl_drop(struct cred *new, unsigned long cap) { if (!capable(CAP_SETPCAP)) return -EPERM; if (!cap_valid(cap)) return -EINVAL; cap_lower(new->cap_bset, cap); return 0; } #else int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp) { return 0; } int cap_task_setioprio (struct task_struct *p, int ioprio) { return 0; } int cap_task_setnice (struct task_struct *p, int nice) { return 0; } #endif /** * cap_task_prctl - Implement process control functions for this security module * @option: The process control function requested * @arg2, @arg3, @arg4, @arg5: The argument data for this function * * Allow process control functions (sys_prctl()) to alter capabilities; may * also deny access to other functions not otherwise implemented here. * * Returns 0 or +ve on success, -ENOSYS if this function is not implemented * here, other -ve on error. If -ENOSYS is returned, sys_prctl() and other LSM * modules will consider performing the function. */ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) { struct cred *new; long error = 0; new = prepare_creds(); if (!new) return -ENOMEM; switch (option) { case PR_CAPBSET_READ: error = -EINVAL; if (!cap_valid(arg2)) goto error; error = !!cap_raised(new->cap_bset, arg2); goto no_change; #ifdef CONFIG_SECURITY_FILE_CAPABILITIES case PR_CAPBSET_DROP: error = cap_prctl_drop(new, arg2); if (error < 0) goto error; goto changed; /* * The next four prctl's remain to assist with transitioning a * system from legacy UID=0 based privilege (when filesystem * capabilities are not in use) to a system using filesystem * capabilities only - as the POSIX.1e draft intended. * * Note: * * PR_SET_SECUREBITS = * issecure_mask(SECURE_KEEP_CAPS_LOCKED) * | issecure_mask(SECURE_NOROOT) * | issecure_mask(SECURE_NOROOT_LOCKED) * | issecure_mask(SECURE_NO_SETUID_FIXUP) * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED) * * will ensure that the current process and all of its * children will be locked into a pure * capability-based-privilege environment. */ case PR_SET_SECUREBITS: error = -EPERM; if ((((new->securebits & SECURE_ALL_LOCKS) >> 1) & (new->securebits ^ arg2)) /*[1]*/ || ((new->securebits & SECURE_ALL_LOCKS & ~arg2)) /*[2]*/ || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/ || (cap_capable(current, current_cred(), CAP_SETPCAP, SECURITY_CAP_AUDIT) != 0) /*[4]*/ /* * [1] no changing of bits that are locked * [2] no unlocking of locks * [3] no setting of unsupported bits * [4] doing anything requires privilege (go read about * the "sendmail capabilities bug") */ ) /* cannot change a locked bit */ goto error; new->securebits = arg2; goto changed; case PR_GET_SECUREBITS: error = new->securebits; goto no_change; #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */ case PR_GET_KEEPCAPS: if (issecure(SECURE_KEEP_CAPS)) error = 1; goto no_change; case PR_SET_KEEPCAPS: error = -EINVAL; if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */ goto error; error = -EPERM; if (issecure(SECURE_KEEP_CAPS_LOCKED)) goto error; if (arg2) new->securebits |= issecure_mask(SECURE_KEEP_CAPS); else new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS); goto changed; default: /* No functionality available - continue with default */ error = -ENOSYS; goto error; } /* Functionality provided */ changed: return commit_creds(new); no_change: error: abort_creds(new); return error; } /** * cap_syslog - Determine whether syslog function is permitted * @type: Function requested * * Determine whether the current process is permitted to use a particular * syslog function, returning 0 if permission is granted, -ve if not. */ int cap_syslog(int type) { if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN)) return -EPERM; return 0; } /** * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted * @mm: The VM space in which the new mapping is to be made * @pages: The size of the mapping * * Determine whether the allocation of a new virtual mapping by the current * task is permitted, returning 0 if permission is granted, -ve if not. */ int cap_vm_enough_memory(struct mm_struct *mm, long pages) { int cap_sys_admin = 0; if (cap_capable(current, current_cred(), CAP_SYS_ADMIN, SECURITY_CAP_NOAUDIT) == 0) cap_sys_admin = 1; return __vm_enough_memory(mm, pages, cap_sys_admin); } /* * cap_file_mmap - check if able to map given addr * @file: unused * @reqprot: unused * @prot: unused * @flags: unused * @addr: address attempting to be mapped * @addr_only: unused * * If the process is attempting to map memory below mmap_min_addr they need * CAP_SYS_RAWIO. The other parameters to this function are unused by the * capability security module. Returns 0 if this mapping should be allowed * -EPERM if not. */ int cap_file_mmap(struct file *file, unsigned long reqprot, unsigned long prot, unsigned long flags, unsigned long addr, unsigned long addr_only) { int ret = 0; if (addr < dac_mmap_min_addr) { ret = cap_capable(current, current_cred(), CAP_SYS_RAWIO, SECURITY_CAP_AUDIT); /* set PF_SUPERPRIV if it turns out we allow the low mmap */ if (ret == 0) current->flags |= PF_SUPERPRIV; } return ret; }
gpl-2.0
waleedq/samsung-kernel-latona
drivers/gpu/drm/i915/intel_sdvo.c
571
89301
/* * Copyright 2006 Dave Airlie <airlied@linux.ie> * Copyright © 2006-2007 Intel Corporation * Jesse Barnes <jesse.barnes@intel.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Authors: * Eric Anholt <eric@anholt.net> */ #include <linux/i2c.h> #include <linux/slab.h> #include <linux/delay.h> #include "drmP.h" #include "drm.h" #include "drm_crtc.h" #include "intel_drv.h" #include "drm_edid.h" #include "i915_drm.h" #include "i915_drv.h" #include "intel_sdvo_regs.h" #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1) #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1) #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1) #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0) #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\ SDVO_TV_MASK) #define IS_TV(c) (c->output_flag & SDVO_TV_MASK) #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) static char *tv_format_names[] = { "NTSC_M" , "NTSC_J" , "NTSC_443", "PAL_B" , "PAL_D" , "PAL_G" , "PAL_H" , "PAL_I" , "PAL_M" , "PAL_N" , "PAL_NC" , "PAL_60" , "SECAM_B" , "SECAM_D" , "SECAM_G" , "SECAM_K" , "SECAM_K1", "SECAM_L" , "SECAM_60" }; #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names)) struct intel_sdvo_priv { u8 slave_addr; /* Register for the SDVO device: SDVOB or SDVOC */ int sdvo_reg; /* Active outputs controlled by this SDVO output */ uint16_t controlled_output; /* * Capabilities of the SDVO device returned by * i830_sdvo_get_capabilities() */ struct intel_sdvo_caps caps; /* Pixel clock limitations reported by the SDVO device, in kHz */ int pixel_clock_min, pixel_clock_max; /* * For multiple function SDVO device, * this is for current attached outputs. */ uint16_t attached_output; /** * This is set if we're going to treat the device as TV-out. * * While we have these nice friendly flags for output types that ought * to decide this for us, the S-Video output on our HDMI+S-Video card * shows up as RGB1 (VGA). */ bool is_tv; /* This is for current tv format name */ char *tv_format_name; /** * This is set if we treat the device as HDMI, instead of DVI. */ bool is_hdmi; /** * This is set if we detect output of sdvo device as LVDS. */ bool is_lvds; /** * This is sdvo flags for input timing. */ uint8_t sdvo_flags; /** * This is sdvo fixed pannel mode pointer */ struct drm_display_mode *sdvo_lvds_fixed_mode; /* * supported encoding mode, used to determine whether HDMI is * supported */ struct intel_sdvo_encode encode; /* DDC bus used by this SDVO encoder */ uint8_t ddc_bus; /* Mac mini hack -- use the same DDC as the analog connector */ struct i2c_adapter *analog_ddc_bus; }; struct intel_sdvo_connector { /* Mark the type of connector */ uint16_t output_flag; /* This contains all current supported TV format */ char *tv_format_supported[TV_FORMAT_NUM]; int format_supported_num; struct drm_property *tv_format_property; struct drm_property *tv_format_name_property[TV_FORMAT_NUM]; /** * Returned SDTV resolutions allowed for the current format, if the * device reported it. */ struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions; /* add the property for the SDVO-TV */ struct drm_property *left_property; struct drm_property *right_property; struct drm_property *top_property; struct drm_property *bottom_property; struct drm_property *hpos_property; struct drm_property *vpos_property; /* add the property for the SDVO-TV/LVDS */ struct drm_property *brightness_property; struct drm_property *contrast_property; struct drm_property *saturation_property; struct drm_property *hue_property; /* Add variable to record current setting for the above property */ u32 left_margin, right_margin, top_margin, bottom_margin; /* this is to get the range of margin.*/ u32 max_hscan, max_vscan; u32 max_hpos, cur_hpos; u32 max_vpos, cur_vpos; u32 cur_brightness, max_brightness; u32 cur_contrast, max_contrast; u32 cur_saturation, max_saturation; u32 cur_hue, max_hue; }; static bool intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags); static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type); static void intel_sdvo_create_enhance_property(struct drm_connector *connector); /** * Writes the SDVOB or SDVOC with the given value, but always writes both * SDVOB and SDVOC to work around apparent hardware issues (according to * comments in the BIOS). */ static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val) { struct drm_device *dev = intel_encoder->enc.dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u32 bval = val, cval = val; int i; if (sdvo_priv->sdvo_reg == PCH_SDVOB) { I915_WRITE(sdvo_priv->sdvo_reg, val); I915_READ(sdvo_priv->sdvo_reg); return; } if (sdvo_priv->sdvo_reg == SDVOB) { cval = I915_READ(SDVOC); } else { bval = I915_READ(SDVOB); } /* * Write the registers twice for luck. Sometimes, * writing them only once doesn't appear to 'stick'. * The BIOS does this too. Yay, magic */ for (i = 0; i < 2; i++) { I915_WRITE(SDVOB, bval); I915_READ(SDVOB); I915_WRITE(SDVOC, cval); I915_READ(SDVOC); } } static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr, u8 *ch) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u8 out_buf[2]; u8 buf[2]; int ret; struct i2c_msg msgs[] = { { .addr = sdvo_priv->slave_addr >> 1, .flags = 0, .len = 1, .buf = out_buf, }, { .addr = sdvo_priv->slave_addr >> 1, .flags = I2C_M_RD, .len = 1, .buf = buf, } }; out_buf[0] = addr; out_buf[1] = 0; if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2) { *ch = buf[0]; return true; } DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); return false; } static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr, u8 ch) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u8 out_buf[2]; struct i2c_msg msgs[] = { { .addr = sdvo_priv->slave_addr >> 1, .flags = 0, .len = 2, .buf = out_buf, } }; out_buf[0] = addr; out_buf[1] = ch; if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1) { return true; } return false; } #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} /** Mapping of command numbers to names, for debug output */ static const struct _sdvo_cmd_name { u8 cmd; char *name; } sdvo_cmd_names[] = { SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2), SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS), /* Add the op code for SDVO enhancements */ SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V), /* HDMI op code */ SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE), SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA), SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA), }; #define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB) #define SDVO_NAME(dev_priv) (IS_SDVOB((dev_priv)->sdvo_reg) ? "SDVOB" : "SDVOC") #define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv) static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd, void *args, int args_len) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; int i; DRM_DEBUG_KMS("%s: W: %02X ", SDVO_NAME(sdvo_priv), cmd); for (i = 0; i < args_len; i++) DRM_LOG_KMS("%02X ", ((u8 *)args)[i]); for (; i < 8; i++) DRM_LOG_KMS(" "); for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) { if (cmd == sdvo_cmd_names[i].cmd) { DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name); break; } } if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0])) DRM_LOG_KMS("(%02X)", cmd); DRM_LOG_KMS("\n"); } static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd, void *args, int args_len) { int i; intel_sdvo_debug_write(intel_encoder, cmd, args, args_len); for (i = 0; i < args_len; i++) { intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i, ((u8*)args)[i]); } intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd); } static const char *cmd_status_names[] = { "Power on", "Success", "Not supported", "Invalid arg", "Pending", "Target not specified", "Scaling not supported" }; static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder, void *response, int response_len, u8 status) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; int i; DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv)); for (i = 0; i < response_len; i++) DRM_LOG_KMS("%02X ", ((u8 *)response)[i]); for (; i < 8; i++) DRM_LOG_KMS(" "); if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) DRM_LOG_KMS("(%s)", cmd_status_names[status]); else DRM_LOG_KMS("(??? %d)", status); DRM_LOG_KMS("\n"); } static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder, void *response, int response_len) { int i; u8 status; u8 retry = 50; while (retry--) { /* Read the command response */ for (i = 0; i < response_len; i++) { intel_sdvo_read_byte(intel_encoder, SDVO_I2C_RETURN_0 + i, &((u8 *)response)[i]); } /* read the return status */ intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS, &status); intel_sdvo_debug_response(intel_encoder, response, response_len, status); if (status != SDVO_CMD_STATUS_PENDING) return status; mdelay(50); } return status; } static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) { if (mode->clock >= 100000) return 1; else if (mode->clock >= 50000) return 2; else return 4; } /** * Try to read the response after issuie the DDC switch command. But it * is noted that we must do the action of reading response and issuing DDC * switch command in one I2C transaction. Otherwise when we try to start * another I2C transaction after issuing the DDC bus switch, it will be * switched to the internal SDVO register. */ static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder, u8 target) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u8 out_buf[2], cmd_buf[2], ret_value[2], ret; struct i2c_msg msgs[] = { { .addr = sdvo_priv->slave_addr >> 1, .flags = 0, .len = 2, .buf = out_buf, }, /* the following two are to read the response */ { .addr = sdvo_priv->slave_addr >> 1, .flags = 0, .len = 1, .buf = cmd_buf, }, { .addr = sdvo_priv->slave_addr >> 1, .flags = I2C_M_RD, .len = 1, .buf = ret_value, }, }; intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH, &target, 1); /* write the DDC switch command argument */ intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target); out_buf[0] = SDVO_I2C_OPCODE; out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH; cmd_buf[0] = SDVO_I2C_CMD_STATUS; cmd_buf[1] = 0; ret_value[0] = 0; ret_value[1] = 0; ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3); if (ret != 3) { /* failure in I2C transfer */ DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); return; } if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("DDC switch command returns response %d\n", ret_value[0]); return; } return; } static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1) { struct intel_sdvo_set_target_input_args targets = {0}; u8 status; if (target_0 && target_1) return SDVO_CMD_STATUS_NOTSUPP; if (target_1) targets.target_1 = 1; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets, sizeof(targets)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } /** * Return whether each input is trained. * * This function is making an assumption about the layout of the response, * which should be checked against the docs. */ static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2) { struct intel_sdvo_get_trained_inputs_response response; u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response)); if (status != SDVO_CMD_STATUS_SUCCESS) return false; *input_1 = response.input0_trained; *input_2 = response.input1_trained; return true; } static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder, u16 outputs) { u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs, sizeof(outputs)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder, int mode) { u8 status, state = SDVO_ENCODER_STATE_ON; switch (mode) { case DRM_MODE_DPMS_ON: state = SDVO_ENCODER_STATE_ON; break; case DRM_MODE_DPMS_STANDBY: state = SDVO_ENCODER_STATE_STANDBY; break; case DRM_MODE_DPMS_SUSPEND: state = SDVO_ENCODER_STATE_SUSPEND; break; case DRM_MODE_DPMS_OFF: state = SDVO_ENCODER_STATE_OFF; break; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder, int *clock_min, int *clock_max) { struct intel_sdvo_pixel_clock_range clocks; u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks)); if (status != SDVO_CMD_STATUS_SUCCESS) return false; /* Convert the values from units of 10 kHz to kHz. */ *clock_min = clocks.min * 10; *clock_max = clocks.max * 10; return true; } static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder, u16 outputs) { u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs, sizeof(outputs)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd, struct intel_sdvo_dtd *dtd) { u8 status; intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) return false; intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return true; } static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder, struct intel_sdvo_dtd *dtd) { return intel_sdvo_set_timing(intel_encoder, SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd); } static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder, struct intel_sdvo_dtd *dtd) { return intel_sdvo_set_timing(intel_encoder, SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd); } static bool intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder, uint16_t clock, uint16_t width, uint16_t height) { struct intel_sdvo_preferred_input_timing_args args; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; uint8_t status; memset(&args, 0, sizeof(args)); args.clock = clock; args.width = width; args.height = height; args.interlace = 0; if (sdvo_priv->is_lvds && (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width || sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height)) args.scaled = 1; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, &args, sizeof(args)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return true; } static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder, struct intel_sdvo_dtd *dtd) { bool status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &dtd->part1, sizeof(dtd->part1)); if (status != SDVO_CMD_STATUS_SUCCESS) return false; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &dtd->part2, sizeof(dtd->part2)); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return false; } static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val) { u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return true; } static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd, struct drm_display_mode *mode) { uint16_t width, height; uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len; uint16_t h_sync_offset, v_sync_offset; width = mode->crtc_hdisplay; height = mode->crtc_vdisplay; /* do some mode translations */ h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start; h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start; v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start; v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start; dtd->part1.clock = mode->clock / 10; dtd->part1.h_active = width & 0xff; dtd->part1.h_blank = h_blank_len & 0xff; dtd->part1.h_high = (((width >> 8) & 0xf) << 4) | ((h_blank_len >> 8) & 0xf); dtd->part1.v_active = height & 0xff; dtd->part1.v_blank = v_blank_len & 0xff; dtd->part1.v_high = (((height >> 8) & 0xf) << 4) | ((v_blank_len >> 8) & 0xf); dtd->part2.h_sync_off = h_sync_offset & 0xff; dtd->part2.h_sync_width = h_sync_len & 0xff; dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 | (v_sync_len & 0xf); dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) | ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) | ((v_sync_len & 0x30) >> 4); dtd->part2.dtd_flags = 0x18; if (mode->flags & DRM_MODE_FLAG_PHSYNC) dtd->part2.dtd_flags |= 0x2; if (mode->flags & DRM_MODE_FLAG_PVSYNC) dtd->part2.dtd_flags |= 0x4; dtd->part2.sdvo_flags = 0; dtd->part2.v_sync_off_high = v_sync_offset & 0xc0; dtd->part2.reserved = 0; } static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, struct intel_sdvo_dtd *dtd) { mode->hdisplay = dtd->part1.h_active; mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8; mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off; mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2; mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width; mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4; mode->htotal = mode->hdisplay + dtd->part1.h_blank; mode->htotal += (dtd->part1.h_high & 0xf) << 8; mode->vdisplay = dtd->part1.v_active; mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8; mode->vsync_start = mode->vdisplay; mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf; mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2; mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0; mode->vsync_end = mode->vsync_start + (dtd->part2.v_sync_off_width & 0xf); mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4; mode->vtotal = mode->vdisplay + dtd->part1.v_blank; mode->vtotal += (dtd->part1.v_high & 0xf) << 8; mode->clock = dtd->part1.clock * 10; mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); if (dtd->part2.dtd_flags & 0x2) mode->flags |= DRM_MODE_FLAG_PHSYNC; if (dtd->part2.dtd_flags & 0x4) mode->flags |= DRM_MODE_FLAG_PVSYNC; } static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder, struct intel_sdvo_encode *encode) { uint8_t status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0); status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode)); if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */ memset(encode, 0, sizeof(*encode)); return false; } return true; } static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder, uint8_t mode) { uint8_t status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder, uint8_t mode) { uint8_t status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1); status = intel_sdvo_read_response(intel_encoder, NULL, 0); return (status == SDVO_CMD_STATUS_SUCCESS); } #if 0 static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder) { int i, j; uint8_t set_buf_index[2]; uint8_t av_split; uint8_t buf_size; uint8_t buf[48]; uint8_t *pos; intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0); intel_sdvo_read_response(encoder, &av_split, 1); for (i = 0; i <= av_split; i++) { set_buf_index[0] = i; set_buf_index[1] = 0; intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2); intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0); intel_sdvo_read_response(encoder, &buf_size, 1); pos = buf; for (j = 0; j <= buf_size; j += 8) { intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA, NULL, 0); intel_sdvo_read_response(encoder, pos, 8); pos += 8; } } } #endif static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder, int index, uint8_t *data, int8_t size, uint8_t tx_rate) { uint8_t set_buf_index[2]; set_buf_index[0] = index; set_buf_index[1] = 0; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2); for (; size > 0; size -= 8) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8); data += 8; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); } static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size) { uint8_t csum = 0; int i; for (i = 0; i < size; i++) csum += data[i]; return 0x100 - csum; } #define DIP_TYPE_AVI 0x82 #define DIP_VERSION_AVI 0x2 #define DIP_LEN_AVI 13 struct dip_infoframe { uint8_t type; uint8_t version; uint8_t len; uint8_t checksum; union { struct { /* Packet Byte #1 */ uint8_t S:2; uint8_t B:2; uint8_t A:1; uint8_t Y:2; uint8_t rsvd1:1; /* Packet Byte #2 */ uint8_t R:4; uint8_t M:2; uint8_t C:2; /* Packet Byte #3 */ uint8_t SC:2; uint8_t Q:2; uint8_t EC:3; uint8_t ITC:1; /* Packet Byte #4 */ uint8_t VIC:7; uint8_t rsvd2:1; /* Packet Byte #5 */ uint8_t PR:4; uint8_t rsvd3:4; /* Packet Byte #6~13 */ uint16_t top_bar_end; uint16_t bottom_bar_start; uint16_t left_bar_end; uint16_t right_bar_start; } avi; struct { /* Packet Byte #1 */ uint8_t channel_count:3; uint8_t rsvd1:1; uint8_t coding_type:4; /* Packet Byte #2 */ uint8_t sample_size:2; /* SS0, SS1 */ uint8_t sample_frequency:3; uint8_t rsvd2:3; /* Packet Byte #3 */ uint8_t coding_type_private:5; uint8_t rsvd3:3; /* Packet Byte #4 */ uint8_t channel_allocation; /* Packet Byte #5 */ uint8_t rsvd4:3; uint8_t level_shift:4; uint8_t downmix_inhibit:1; } audio; uint8_t payload[28]; } __attribute__ ((packed)) u; } __attribute__((packed)); static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder, struct drm_display_mode * mode) { struct dip_infoframe avi_if = { .type = DIP_TYPE_AVI, .version = DIP_VERSION_AVI, .len = DIP_LEN_AVI, }; avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if, 4 + avi_if.len); intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if, 4 + avi_if.len, SDVO_HBUF_TX_VSYNC); } static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder) { struct intel_sdvo_tv_format format; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; uint32_t format_map, i; uint8_t status; for (i = 0; i < TV_FORMAT_NUM; i++) if (tv_format_names[i] == sdvo_priv->tv_format_name) break; format_map = 1 << i; memset(&format, 0, sizeof(format)); memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ? sizeof(format) : sizeof(format_map)); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format, sizeof(format)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) DRM_DEBUG_KMS("%s: Failed to set TV format\n", SDVO_NAME(sdvo_priv)); } static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv; if (dev_priv->is_tv) { struct intel_sdvo_dtd output_dtd; bool success; /* We need to construct preferred input timings based on our * output timings. To do that, we have to set the output * timings, even though this isn't really the right place in * the sequence to do it. Oh well. */ /* Set output timings */ intel_sdvo_get_dtd_from_mode(&output_dtd, mode); intel_sdvo_set_target_output(intel_encoder, dev_priv->attached_output); intel_sdvo_set_output_timing(intel_encoder, &output_dtd); /* Set the input timing to the screen. Assume always input 0. */ intel_sdvo_set_target_input(intel_encoder, true, false); success = intel_sdvo_create_preferred_input_timing(intel_encoder, mode->clock / 10, mode->hdisplay, mode->vdisplay); if (success) { struct intel_sdvo_dtd input_dtd; intel_sdvo_get_preferred_input_timing(intel_encoder, &input_dtd); intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; drm_mode_set_crtcinfo(adjusted_mode, 0); mode->clock = adjusted_mode->clock; adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); } else { return false; } } else if (dev_priv->is_lvds) { struct intel_sdvo_dtd output_dtd; bool success; drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0); /* Set output timings */ intel_sdvo_get_dtd_from_mode(&output_dtd, dev_priv->sdvo_lvds_fixed_mode); intel_sdvo_set_target_output(intel_encoder, dev_priv->attached_output); intel_sdvo_set_output_timing(intel_encoder, &output_dtd); /* Set the input timing to the screen. Assume always input 0. */ intel_sdvo_set_target_input(intel_encoder, true, false); success = intel_sdvo_create_preferred_input_timing( intel_encoder, mode->clock / 10, mode->hdisplay, mode->vdisplay); if (success) { struct intel_sdvo_dtd input_dtd; intel_sdvo_get_preferred_input_timing(intel_encoder, &input_dtd); intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; drm_mode_set_crtcinfo(adjusted_mode, 0); mode->clock = adjusted_mode->clock; adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); } else { return false; } } else { /* Make the CRTC code factor in the SDVO pixel multiplier. The * SDVO device will be told of the multiplier during mode_set. */ adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); } return true; } static void intel_sdvo_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { struct drm_device *dev = encoder->dev; struct drm_i915_private *dev_priv = dev->dev_private; struct drm_crtc *crtc = encoder->crtc; struct intel_crtc *intel_crtc = to_intel_crtc(crtc); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u32 sdvox = 0; int sdvo_pixel_multiply; struct intel_sdvo_in_out_map in_out; struct intel_sdvo_dtd input_dtd; u8 status; if (!mode) return; /* First, set the input mapping for the first input to our controlled * output. This is only correct if we're a single-input device, in * which case the first input is the output from the appropriate SDVO * channel on the motherboard. In a two-input device, the first input * will be SDVOB and the second SDVOC. */ in_out.in0 = sdvo_priv->attached_output; in_out.in1 = 0; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP, &in_out, sizeof(in_out)); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (sdvo_priv->is_hdmi) { intel_sdvo_set_avi_infoframe(intel_encoder, mode); sdvox |= SDVO_AUDIO_ENABLE; } /* We have tried to get input timing in mode_fixup, and filled into adjusted_mode */ if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags; } else intel_sdvo_get_dtd_from_mode(&input_dtd, mode); /* If it's a TV, we already set the output timing in mode_fixup. * Otherwise, the output timing is equal to the input timing. */ if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) { /* Set the output timing to the screen */ intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output); intel_sdvo_set_output_timing(intel_encoder, &input_dtd); } /* Set the input timing to the screen. Assume always input 0. */ intel_sdvo_set_target_input(intel_encoder, true, false); if (sdvo_priv->is_tv) intel_sdvo_set_tv_format(intel_encoder); /* We would like to use intel_sdvo_create_preferred_input_timing() to * provide the device with a timing it can support, if it supports that * feature. However, presumably we would need to adjust the CRTC to * output the preferred timing, and we don't support that currently. */ #if 0 success = intel_sdvo_create_preferred_input_timing(encoder, clock, width, height); if (success) { struct intel_sdvo_dtd *input_dtd; intel_sdvo_get_preferred_input_timing(encoder, &input_dtd); intel_sdvo_set_input_timing(encoder, &input_dtd); } #else intel_sdvo_set_input_timing(intel_encoder, &input_dtd); #endif switch (intel_sdvo_get_pixel_multiplier(mode)) { case 1: intel_sdvo_set_clock_rate_mult(intel_encoder, SDVO_CLOCK_RATE_MULT_1X); break; case 2: intel_sdvo_set_clock_rate_mult(intel_encoder, SDVO_CLOCK_RATE_MULT_2X); break; case 4: intel_sdvo_set_clock_rate_mult(intel_encoder, SDVO_CLOCK_RATE_MULT_4X); break; } /* Set the SDVO control regs. */ if (IS_I965G(dev)) { sdvox |= SDVO_BORDER_ENABLE | SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH; } else { sdvox |= I915_READ(sdvo_priv->sdvo_reg); switch (sdvo_priv->sdvo_reg) { case SDVOB: sdvox &= SDVOB_PRESERVE_MASK; break; case SDVOC: sdvox &= SDVOC_PRESERVE_MASK; break; } sdvox |= (9 << 19) | SDVO_BORDER_ENABLE; } if (intel_crtc->pipe == 1) sdvox |= SDVO_PIPE_B_SELECT; sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode); if (IS_I965G(dev)) { /* done in crtc_mode_set as the dpll_md reg must be written early */ } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { /* done in crtc_mode_set as it lives inside the dpll register */ } else { sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; } if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL) sdvox |= SDVO_STALL_SELECT; intel_sdvo_write_sdvox(intel_encoder, sdvox); } static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) { struct drm_device *dev = encoder->dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; u32 temp; if (mode != DRM_MODE_DPMS_ON) { intel_sdvo_set_active_outputs(intel_encoder, 0); if (0) intel_sdvo_set_encoder_power_state(intel_encoder, mode); if (mode == DRM_MODE_DPMS_OFF) { temp = I915_READ(sdvo_priv->sdvo_reg); if ((temp & SDVO_ENABLE) != 0) { intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE); } } } else { bool input1, input2; int i; u8 status; temp = I915_READ(sdvo_priv->sdvo_reg); if ((temp & SDVO_ENABLE) == 0) intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE); for (i = 0; i < 2; i++) intel_wait_for_vblank(dev); status = intel_sdvo_get_trained_inputs(intel_encoder, &input1, &input2); /* Warn if the device reported failure to sync. * A lot of SDVO devices fail to notify of sync, but it's * a given it the status is a success, we succeeded. */ if (status == SDVO_CMD_STATUS_SUCCESS && !input1) { DRM_DEBUG_KMS("First %s output reported failure to " "sync\n", SDVO_NAME(sdvo_priv)); } if (0) intel_sdvo_set_encoder_power_state(intel_encoder, mode); intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output); } return; } static int intel_sdvo_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; if (mode->flags & DRM_MODE_FLAG_DBLSCAN) return MODE_NO_DBLESCAN; if (sdvo_priv->pixel_clock_min > mode->clock) return MODE_CLOCK_LOW; if (sdvo_priv->pixel_clock_max < mode->clock) return MODE_CLOCK_HIGH; if (sdvo_priv->is_lvds == true) { if (sdvo_priv->sdvo_lvds_fixed_mode == NULL) return MODE_PANEL; if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay) return MODE_PANEL; if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay) return MODE_PANEL; } return MODE_OK; } static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps) { u8 status; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps)); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return true; } /* No use! */ #if 0 struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB) { struct drm_connector *connector = NULL; struct intel_encoder *iout = NULL; struct intel_sdvo_priv *sdvo; /* find the sdvo connector */ list_for_each_entry(connector, &dev->mode_config.connector_list, head) { iout = to_intel_encoder(connector); if (iout->type != INTEL_OUTPUT_SDVO) continue; sdvo = iout->dev_priv; if (sdvo->sdvo_reg == SDVOB && sdvoB) return connector; if (sdvo->sdvo_reg == SDVOC && !sdvoB) return connector; } return NULL; } int intel_sdvo_supports_hotplug(struct drm_connector *connector) { u8 response[2]; u8 status; struct intel_encoder *intel_encoder; DRM_DEBUG_KMS("\n"); if (!connector) return 0; intel_encoder = to_intel_encoder(connector); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (response[0] !=0) return 1; return 0; } void intel_sdvo_set_hotplug(struct drm_connector *connector, int on) { u8 response[2]; u8 status; struct intel_encoder *intel_encoder = to_intel_encoder(connector); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); intel_sdvo_read_response(intel_encoder, &response, 2); if (on) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); } else { response[0] = 0; response[1] = 0; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); intel_sdvo_read_response(intel_encoder, &response, 2); } #endif static bool intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; int caps = 0; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1)) caps++; if (sdvo_priv->caps.output_flags & (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)) caps++; return (caps > 1); } static struct drm_connector * intel_find_analog_connector(struct drm_device *dev) { struct drm_connector *connector; struct drm_encoder *encoder; struct intel_encoder *intel_encoder; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { intel_encoder = enc_to_intel_encoder(encoder); if (intel_encoder->type == INTEL_OUTPUT_ANALOG) { list_for_each_entry(connector, &dev->mode_config.connector_list, head) { if (encoder == intel_attached_encoder(connector)) return connector; } } } return NULL; } static int intel_analog_is_connected(struct drm_device *dev) { struct drm_connector *analog_connector; analog_connector = intel_find_analog_connector(dev); if (!analog_connector) return false; if (analog_connector->funcs->detect(analog_connector) == connector_status_disconnected) return false; return true; } enum drm_connector_status intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; enum drm_connector_status status = connector_status_connected; struct edid *edid = NULL; edid = drm_get_edid(connector, intel_encoder->ddc_bus); /* This is only applied to SDVO cards with multiple outputs */ if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) { uint8_t saved_ddc, temp_ddc; saved_ddc = sdvo_priv->ddc_bus; temp_ddc = sdvo_priv->ddc_bus >> 1; /* * Don't use the 1 as the argument of DDC bus switch to get * the EDID. It is used for SDVO SPD ROM. */ while(temp_ddc > 1) { sdvo_priv->ddc_bus = temp_ddc; edid = drm_get_edid(connector, intel_encoder->ddc_bus); if (edid) { /* * When we can get the EDID, maybe it is the * correct DDC bus. Update it. */ sdvo_priv->ddc_bus = temp_ddc; break; } temp_ddc >>= 1; } if (edid == NULL) sdvo_priv->ddc_bus = saved_ddc; } /* when there is no edid and no monitor is connected with VGA * port, try to use the CRT ddc to read the EDID for DVI-connector */ if (edid == NULL && sdvo_priv->analog_ddc_bus && !intel_analog_is_connected(connector->dev)) edid = drm_get_edid(connector, sdvo_priv->analog_ddc_bus); if (edid != NULL) { bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); bool need_digital = !!(sdvo_connector->output_flag & SDVO_TMDS_MASK); /* DDC bus is shared, match EDID to connector type */ if (is_digital && need_digital) sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid); else if (is_digital != need_digital) status = connector_status_disconnected; connector->display_info.raw_edid = NULL; } else status = connector_status_disconnected; kfree(edid); return status; } static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector) { uint16_t response; u8 status; struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; enum drm_connector_status ret; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0); if (sdvo_priv->is_tv) { /* add 30ms delay when the output type is SDVO-TV */ mdelay(30); } status = intel_sdvo_read_response(intel_encoder, &response, 2); DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); if (status != SDVO_CMD_STATUS_SUCCESS) return connector_status_unknown; if (response == 0) return connector_status_disconnected; sdvo_priv->attached_output = response; if ((sdvo_connector->output_flag & response) == 0) ret = connector_status_disconnected; else if (response & SDVO_TMDS_MASK) ret = intel_sdvo_hdmi_sink_detect(connector); else ret = connector_status_connected; /* May update encoder flag for like clock for SDVO TV, etc.*/ if (ret == connector_status_connected) { sdvo_priv->is_tv = false; sdvo_priv->is_lvds = false; intel_encoder->needs_tv_clock = false; if (response & SDVO_TV_MASK) { sdvo_priv->is_tv = true; intel_encoder->needs_tv_clock = true; } if (response & SDVO_LVDS_MASK) sdvo_priv->is_lvds = true; } return ret; } static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; int num_modes; /* set the bus switch and get the modes */ num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); /* * Mac mini hack. On this device, the DVI-I connector shares one DDC * link between analog and digital outputs. So, if the regular SDVO * DDC fails, check to see if the analog output is disconnected, in * which case we'll look there for the digital DDC data. */ if (num_modes == 0 && sdvo_priv->analog_ddc_bus && !intel_analog_is_connected(connector->dev)) { /* Switch to the analog ddc bus and try that */ (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus); } } /* * Set of SDVO TV modes. * Note! This is in reply order (see loop in get_tv_modes). * XXX: all 60Hz refresh? */ struct drm_display_mode sdvo_tv_modes[] = { { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384, 416, 0, 200, 201, 232, 233, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384, 416, 0, 240, 241, 272, 273, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464, 496, 0, 300, 301, 332, 333, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704, 736, 0, 350, 351, 382, 383, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704, 736, 0, 400, 401, 432, 433, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704, 736, 0, 480, 481, 512, 513, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768, 800, 0, 480, 481, 512, 513, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768, 800, 0, 576, 577, 608, 609, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784, 816, 0, 350, 351, 382, 383, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784, 816, 0, 400, 401, 432, 433, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784, 816, 0, 480, 481, 512, 513, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784, 816, 0, 540, 541, 572, 573, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784, 816, 0, 576, 577, 608, 609, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832, 864, 0, 576, 577, 608, 609, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864, 896, 0, 600, 601, 632, 633, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896, 928, 0, 624, 625, 656, 657, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984, 1016, 0, 766, 767, 798, 799, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088, 1120, 0, 768, 769, 800, 801, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344, 1376, 0, 1024, 1025, 1056, 1057, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, }; static void intel_sdvo_get_tv_modes(struct drm_connector *connector) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct intel_sdvo_sdtv_resolution_request tv_res; uint32_t reply = 0, format_map = 0; int i; uint8_t status; /* Read the list of supported input resolutions for the selected TV * format. */ for (i = 0; i < TV_FORMAT_NUM; i++) if (tv_format_names[i] == sdvo_priv->tv_format_name) break; format_map = (1 << i); memcpy(&tv_res, &format_map, sizeof(struct intel_sdvo_sdtv_resolution_request) > sizeof(format_map) ? sizeof(format_map) : sizeof(struct intel_sdvo_sdtv_resolution_request)); intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, &tv_res, sizeof(tv_res)); status = intel_sdvo_read_response(intel_encoder, &reply, 3); if (status != SDVO_CMD_STATUS_SUCCESS) return; for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) if (reply & (1 << i)) { struct drm_display_mode *nmode; nmode = drm_mode_duplicate(connector->dev, &sdvo_tv_modes[i]); if (nmode) drm_mode_probed_add(connector, nmode); } } static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct drm_i915_private *dev_priv = connector->dev->dev_private; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct drm_display_mode *newmode; /* * Attempt to get the mode list from DDC. * Assume that the preferred modes are * arranged in priority order. */ intel_ddc_get_modes(connector, intel_encoder->ddc_bus); if (list_empty(&connector->probed_modes) == false) goto end; /* Fetch modes from VBT */ if (dev_priv->sdvo_lvds_vbt_mode != NULL) { newmode = drm_mode_duplicate(connector->dev, dev_priv->sdvo_lvds_vbt_mode); if (newmode != NULL) { /* Guarantee the mode is preferred */ newmode->type = (DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER); drm_mode_probed_add(connector, newmode); } } end: list_for_each_entry(newmode, &connector->probed_modes, head) { if (newmode->type & DRM_MODE_TYPE_PREFERRED) { sdvo_priv->sdvo_lvds_fixed_mode = drm_mode_duplicate(connector->dev, newmode); break; } } } static int intel_sdvo_get_modes(struct drm_connector *connector) { struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; if (IS_TV(sdvo_connector)) intel_sdvo_get_tv_modes(connector); else if (IS_LVDS(sdvo_connector)) intel_sdvo_get_lvds_modes(connector); else intel_sdvo_get_ddc_modes(connector); if (list_empty(&connector->probed_modes)) return 0; return 1; } static void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) { struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv; struct drm_device *dev = connector->dev; if (IS_TV(sdvo_priv)) { if (sdvo_priv->left_property) drm_property_destroy(dev, sdvo_priv->left_property); if (sdvo_priv->right_property) drm_property_destroy(dev, sdvo_priv->right_property); if (sdvo_priv->top_property) drm_property_destroy(dev, sdvo_priv->top_property); if (sdvo_priv->bottom_property) drm_property_destroy(dev, sdvo_priv->bottom_property); if (sdvo_priv->hpos_property) drm_property_destroy(dev, sdvo_priv->hpos_property); if (sdvo_priv->vpos_property) drm_property_destroy(dev, sdvo_priv->vpos_property); if (sdvo_priv->saturation_property) drm_property_destroy(dev, sdvo_priv->saturation_property); if (sdvo_priv->contrast_property) drm_property_destroy(dev, sdvo_priv->contrast_property); if (sdvo_priv->hue_property) drm_property_destroy(dev, sdvo_priv->hue_property); } if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { if (sdvo_priv->brightness_property) drm_property_destroy(dev, sdvo_priv->brightness_property); } return; } static void intel_sdvo_destroy(struct drm_connector *connector) { struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; if (sdvo_connector->tv_format_property) drm_property_destroy(connector->dev, sdvo_connector->tv_format_property); intel_sdvo_destroy_enhance_property(connector); drm_sysfs_connector_remove(connector); drm_connector_cleanup(connector); kfree(connector); } static int intel_sdvo_set_property(struct drm_connector *connector, struct drm_property *property, uint64_t val) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; struct drm_crtc *crtc = encoder->crtc; int ret = 0; bool changed = false; uint8_t cmd, status; uint16_t temp_value; ret = drm_connector_property_set_value(connector, property, val); if (ret < 0) goto out; if (property == sdvo_connector->tv_format_property) { if (val >= TV_FORMAT_NUM) { ret = -EINVAL; goto out; } if (sdvo_priv->tv_format_name == sdvo_connector->tv_format_supported[val]) goto out; sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val]; changed = true; } if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) { cmd = 0; temp_value = val; if (sdvo_connector->left_property == property) { drm_connector_property_set_value(connector, sdvo_connector->right_property, val); if (sdvo_connector->left_margin == temp_value) goto out; sdvo_connector->left_margin = temp_value; sdvo_connector->right_margin = temp_value; temp_value = sdvo_connector->max_hscan - sdvo_connector->left_margin; cmd = SDVO_CMD_SET_OVERSCAN_H; } else if (sdvo_connector->right_property == property) { drm_connector_property_set_value(connector, sdvo_connector->left_property, val); if (sdvo_connector->right_margin == temp_value) goto out; sdvo_connector->left_margin = temp_value; sdvo_connector->right_margin = temp_value; temp_value = sdvo_connector->max_hscan - sdvo_connector->left_margin; cmd = SDVO_CMD_SET_OVERSCAN_H; } else if (sdvo_connector->top_property == property) { drm_connector_property_set_value(connector, sdvo_connector->bottom_property, val); if (sdvo_connector->top_margin == temp_value) goto out; sdvo_connector->top_margin = temp_value; sdvo_connector->bottom_margin = temp_value; temp_value = sdvo_connector->max_vscan - sdvo_connector->top_margin; cmd = SDVO_CMD_SET_OVERSCAN_V; } else if (sdvo_connector->bottom_property == property) { drm_connector_property_set_value(connector, sdvo_connector->top_property, val); if (sdvo_connector->bottom_margin == temp_value) goto out; sdvo_connector->top_margin = temp_value; sdvo_connector->bottom_margin = temp_value; temp_value = sdvo_connector->max_vscan - sdvo_connector->top_margin; cmd = SDVO_CMD_SET_OVERSCAN_V; } else if (sdvo_connector->hpos_property == property) { if (sdvo_connector->cur_hpos == temp_value) goto out; cmd = SDVO_CMD_SET_POSITION_H; sdvo_connector->cur_hpos = temp_value; } else if (sdvo_connector->vpos_property == property) { if (sdvo_connector->cur_vpos == temp_value) goto out; cmd = SDVO_CMD_SET_POSITION_V; sdvo_connector->cur_vpos = temp_value; } else if (sdvo_connector->saturation_property == property) { if (sdvo_connector->cur_saturation == temp_value) goto out; cmd = SDVO_CMD_SET_SATURATION; sdvo_connector->cur_saturation = temp_value; } else if (sdvo_connector->contrast_property == property) { if (sdvo_connector->cur_contrast == temp_value) goto out; cmd = SDVO_CMD_SET_CONTRAST; sdvo_connector->cur_contrast = temp_value; } else if (sdvo_connector->hue_property == property) { if (sdvo_connector->cur_hue == temp_value) goto out; cmd = SDVO_CMD_SET_HUE; sdvo_connector->cur_hue = temp_value; } else if (sdvo_connector->brightness_property == property) { if (sdvo_connector->cur_brightness == temp_value) goto out; cmd = SDVO_CMD_SET_BRIGHTNESS; sdvo_connector->cur_brightness = temp_value; } if (cmd) { intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2); status = intel_sdvo_read_response(intel_encoder, NULL, 0); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO command \n"); return -EINVAL; } changed = true; } } if (changed && crtc) drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb); out: return ret; } static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { .dpms = intel_sdvo_dpms, .mode_fixup = intel_sdvo_mode_fixup, .prepare = intel_encoder_prepare, .mode_set = intel_sdvo_mode_set, .commit = intel_encoder_commit, }; static const struct drm_connector_funcs intel_sdvo_connector_funcs = { .dpms = drm_helper_connector_dpms, .detect = intel_sdvo_detect, .fill_modes = drm_helper_probe_single_connector_modes, .set_property = intel_sdvo_set_property, .destroy = intel_sdvo_destroy, }; static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { .get_modes = intel_sdvo_get_modes, .mode_valid = intel_sdvo_mode_valid, .best_encoder = intel_attached_encoder, }; static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) { struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; if (intel_encoder->i2c_bus) intel_i2c_destroy(intel_encoder->i2c_bus); if (intel_encoder->ddc_bus) intel_i2c_destroy(intel_encoder->ddc_bus); if (sdvo_priv->analog_ddc_bus) intel_i2c_destroy(sdvo_priv->analog_ddc_bus); if (sdvo_priv->sdvo_lvds_fixed_mode != NULL) drm_mode_destroy(encoder->dev, sdvo_priv->sdvo_lvds_fixed_mode); drm_encoder_cleanup(encoder); kfree(intel_encoder); } static const struct drm_encoder_funcs intel_sdvo_enc_funcs = { .destroy = intel_sdvo_enc_destroy, }; /** * Choose the appropriate DDC bus for control bus switch command for this * SDVO output based on the controlled output. * * DDC bus number assignment is in a priority order of RGB outputs, then TMDS * outputs, then LVDS outputs. */ static void intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv, struct intel_sdvo_priv *sdvo, u32 reg) { struct sdvo_device_mapping *mapping; if (IS_SDVOB(reg)) mapping = &(dev_priv->sdvo_mappings[0]); else mapping = &(dev_priv->sdvo_mappings[1]); sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4); } static bool intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device) { struct intel_sdvo_priv *sdvo_priv = output->dev_priv; uint8_t status; if (device == 0) intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0); else intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1); intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0); status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1); if (status != SDVO_CMD_STATUS_SUCCESS) return false; return true; } static struct intel_encoder * intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan) { struct drm_device *dev = chan->drm_dev; struct drm_encoder *encoder; struct intel_encoder *intel_encoder = NULL; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { intel_encoder = enc_to_intel_encoder(encoder); if (intel_encoder->ddc_bus == &chan->adapter) break; } return intel_encoder; } static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) { struct intel_encoder *intel_encoder; struct intel_sdvo_priv *sdvo_priv; struct i2c_algo_bit_data *algo_data; const struct i2c_algorithm *algo; algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; intel_encoder = intel_sdvo_chan_to_intel_encoder( (struct intel_i2c_chan *)(algo_data->data)); if (intel_encoder == NULL) return -EINVAL; sdvo_priv = intel_encoder->dev_priv; algo = intel_encoder->i2c_bus->algo; intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus); return algo->master_xfer(i2c_adap, msgs, num); } static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { .master_xfer = intel_sdvo_master_xfer, }; static u8 intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) { struct drm_i915_private *dev_priv = dev->dev_private; struct sdvo_device_mapping *my_mapping, *other_mapping; if (IS_SDVOB(sdvo_reg)) { my_mapping = &dev_priv->sdvo_mappings[0]; other_mapping = &dev_priv->sdvo_mappings[1]; } else { my_mapping = &dev_priv->sdvo_mappings[1]; other_mapping = &dev_priv->sdvo_mappings[0]; } /* If the BIOS described our SDVO device, take advantage of it. */ if (my_mapping->slave_addr) return my_mapping->slave_addr; /* If the BIOS only described a different SDVO device, use the * address that it isn't using. */ if (other_mapping->slave_addr) { if (other_mapping->slave_addr == 0x70) return 0x72; else return 0x70; } /* No SDVO device info is found for another DVO port, * so use mapping assumption we had before BIOS parsing. */ if (IS_SDVOB(sdvo_reg)) return 0x70; else return 0x72; } static bool intel_sdvo_connector_alloc (struct intel_connector **ret) { struct intel_connector *intel_connector; struct intel_sdvo_connector *sdvo_connector; *ret = kzalloc(sizeof(*intel_connector) + sizeof(*sdvo_connector), GFP_KERNEL); if (!*ret) return false; intel_connector = *ret; sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1); intel_connector->dev_priv = sdvo_connector; return true; } static void intel_sdvo_connector_create (struct drm_encoder *encoder, struct drm_connector *connector) { drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs, connector->connector_type); drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); connector->interlace_allowed = 0; connector->doublescan_allowed = 0; connector->display_info.subpixel_order = SubPixelHorizontalRGB; drm_mode_connector_attach_encoder(connector, encoder); drm_sysfs_connector_add(connector); } static bool intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device) { struct drm_encoder *encoder = &intel_encoder->enc; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct drm_connector *connector; struct intel_connector *intel_connector; struct intel_sdvo_connector *sdvo_connector; if (!intel_sdvo_connector_alloc(&intel_connector)) return false; sdvo_connector = intel_connector->dev_priv; if (device == 0) { sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0; sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0; } else if (device == 1) { sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1; sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1; } connector = &intel_connector->base; connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; encoder->encoder_type = DRM_MODE_ENCODER_TMDS; connector->connector_type = DRM_MODE_CONNECTOR_DVID; if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode) && intel_sdvo_get_digital_encoding_mode(intel_encoder, device) && sdvo_priv->is_hdmi) { /* enable hdmi encoding mode if supported */ intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI); intel_sdvo_set_colorimetry(intel_encoder, SDVO_COLORIMETRY_RGB256); connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; } intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | (1 << INTEL_ANALOG_CLONE_BIT); intel_sdvo_connector_create(encoder, connector); return true; } static bool intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type) { struct drm_encoder *encoder = &intel_encoder->enc; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct drm_connector *connector; struct intel_connector *intel_connector; struct intel_sdvo_connector *sdvo_connector; if (!intel_sdvo_connector_alloc(&intel_connector)) return false; connector = &intel_connector->base; encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; sdvo_connector = intel_connector->dev_priv; sdvo_priv->controlled_output |= type; sdvo_connector->output_flag = type; sdvo_priv->is_tv = true; intel_encoder->needs_tv_clock = true; intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; intel_sdvo_connector_create(encoder, connector); intel_sdvo_tv_create_property(connector, type); intel_sdvo_create_enhance_property(connector); return true; } static bool intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device) { struct drm_encoder *encoder = &intel_encoder->enc; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct drm_connector *connector; struct intel_connector *intel_connector; struct intel_sdvo_connector *sdvo_connector; if (!intel_sdvo_connector_alloc(&intel_connector)) return false; connector = &intel_connector->base; connector->polled = DRM_CONNECTOR_POLL_CONNECT; encoder->encoder_type = DRM_MODE_ENCODER_DAC; connector->connector_type = DRM_MODE_CONNECTOR_VGA; sdvo_connector = intel_connector->dev_priv; if (device == 0) { sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0; sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; } else if (device == 1) { sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1; sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; } intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | (1 << INTEL_ANALOG_CLONE_BIT); intel_sdvo_connector_create(encoder, connector); return true; } static bool intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device) { struct drm_encoder *encoder = &intel_encoder->enc; struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct drm_connector *connector; struct intel_connector *intel_connector; struct intel_sdvo_connector *sdvo_connector; if (!intel_sdvo_connector_alloc(&intel_connector)) return false; connector = &intel_connector->base; encoder->encoder_type = DRM_MODE_ENCODER_LVDS; connector->connector_type = DRM_MODE_CONNECTOR_LVDS; sdvo_connector = intel_connector->dev_priv; sdvo_priv->is_lvds = true; if (device == 0) { sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0; sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; } else if (device == 1) { sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1; sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; } intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | (1 << INTEL_SDVO_LVDS_CLONE_BIT); intel_sdvo_connector_create(encoder, connector); intel_sdvo_create_enhance_property(connector); return true; } static bool intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags) { struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; sdvo_priv->is_tv = false; intel_encoder->needs_tv_clock = false; sdvo_priv->is_lvds = false; /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/ if (flags & SDVO_OUTPUT_TMDS0) if (!intel_sdvo_dvi_init(intel_encoder, 0)) return false; if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK) if (!intel_sdvo_dvi_init(intel_encoder, 1)) return false; /* TV has no XXX1 function block */ if (flags & SDVO_OUTPUT_SVID0) if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0)) return false; if (flags & SDVO_OUTPUT_CVBS0) if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0)) return false; if (flags & SDVO_OUTPUT_RGB0) if (!intel_sdvo_analog_init(intel_encoder, 0)) return false; if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK) if (!intel_sdvo_analog_init(intel_encoder, 1)) return false; if (flags & SDVO_OUTPUT_LVDS0) if (!intel_sdvo_lvds_init(intel_encoder, 0)) return false; if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK) if (!intel_sdvo_lvds_init(intel_encoder, 1)) return false; if ((flags & SDVO_OUTPUT_MASK) == 0) { unsigned char bytes[2]; sdvo_priv->controlled_output = 0; memcpy(bytes, &sdvo_priv->caps.output_flags, 2); DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", SDVO_NAME(sdvo_priv), bytes[0], bytes[1]); return false; } intel_encoder->crtc_mask = (1 << 0) | (1 << 1); return true; } static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; struct intel_sdvo_tv_format format; uint32_t format_map, i; uint8_t status; intel_sdvo_set_target_output(intel_encoder, type); intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &format, sizeof(format)); if (status != SDVO_CMD_STATUS_SUCCESS) return; memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ? sizeof(format_map) : sizeof(format)); if (format_map == 0) return; sdvo_connector->format_supported_num = 0; for (i = 0 ; i < TV_FORMAT_NUM; i++) if (format_map & (1 << i)) { sdvo_connector->tv_format_supported [sdvo_connector->format_supported_num++] = tv_format_names[i]; } sdvo_connector->tv_format_property = drm_property_create( connector->dev, DRM_MODE_PROP_ENUM, "mode", sdvo_connector->format_supported_num); for (i = 0; i < sdvo_connector->format_supported_num; i++) drm_property_add_enum( sdvo_connector->tv_format_property, i, i, sdvo_connector->tv_format_supported[i]); sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0]; drm_connector_attach_property( connector, sdvo_connector->tv_format_property, 0); } static void intel_sdvo_create_enhance_property(struct drm_connector *connector) { struct drm_encoder *encoder = intel_attached_encoder(connector); struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); struct intel_connector *intel_connector = to_intel_connector(connector); struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv; struct intel_sdvo_enhancements_reply sdvo_data; struct drm_device *dev = connector->dev; uint8_t status; uint16_t response, data_value[2]; intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &sdvo_data, sizeof(sdvo_data)); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS(" incorrect response is returned\n"); return; } response = *((uint16_t *)&sdvo_data); if (!response) { DRM_DEBUG_KMS("No enhancement is supported\n"); return; } if (IS_TV(sdvo_priv)) { /* when horizontal overscan is supported, Add the left/right * property */ if (sdvo_data.overscan_h) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO max " "h_overscan\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_OVERSCAN_H, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n"); return; } sdvo_priv->max_hscan = data_value[0]; sdvo_priv->left_margin = data_value[0] - response; sdvo_priv->right_margin = sdvo_priv->left_margin; sdvo_priv->left_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "left_margin", 2); sdvo_priv->left_property->values[0] = 0; sdvo_priv->left_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->left_property, sdvo_priv->left_margin); sdvo_priv->right_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "right_margin", 2); sdvo_priv->right_property->values[0] = 0; sdvo_priv->right_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->right_property, sdvo_priv->right_margin); DRM_DEBUG_KMS("h_overscan: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.overscan_v) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO max " "v_overscan\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_OVERSCAN_V, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n"); return; } sdvo_priv->max_vscan = data_value[0]; sdvo_priv->top_margin = data_value[0] - response; sdvo_priv->bottom_margin = sdvo_priv->top_margin; sdvo_priv->top_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "top_margin", 2); sdvo_priv->top_property->values[0] = 0; sdvo_priv->top_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->top_property, sdvo_priv->top_margin); sdvo_priv->bottom_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "bottom_margin", 2); sdvo_priv->bottom_property->values[0] = 0; sdvo_priv->bottom_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->bottom_property, sdvo_priv->bottom_margin); DRM_DEBUG_KMS("v_overscan: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.position_h) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_POSITION_H, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_POSITION_H, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n"); return; } sdvo_priv->max_hpos = data_value[0]; sdvo_priv->cur_hpos = response; sdvo_priv->hpos_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "hpos", 2); sdvo_priv->hpos_property->values[0] = 0; sdvo_priv->hpos_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->hpos_property, sdvo_priv->cur_hpos); DRM_DEBUG_KMS("h_position: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.position_v) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_POSITION_V, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_POSITION_V, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n"); return; } sdvo_priv->max_vpos = data_value[0]; sdvo_priv->cur_vpos = response; sdvo_priv->vpos_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "vpos", 2); sdvo_priv->vpos_property->values[0] = 0; sdvo_priv->vpos_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->vpos_property, sdvo_priv->cur_vpos); DRM_DEBUG_KMS("v_position: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.saturation) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_SATURATION, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max sat\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SATURATION, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get sat\n"); return; } sdvo_priv->max_saturation = data_value[0]; sdvo_priv->cur_saturation = response; sdvo_priv->saturation_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "saturation", 2); sdvo_priv->saturation_property->values[0] = 0; sdvo_priv->saturation_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->saturation_property, sdvo_priv->cur_saturation); DRM_DEBUG_KMS("saturation: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.contrast) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_CONTRAST, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_CONTRAST, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get contrast\n"); return; } sdvo_priv->max_contrast = data_value[0]; sdvo_priv->cur_contrast = response; sdvo_priv->contrast_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "contrast", 2); sdvo_priv->contrast_property->values[0] = 0; sdvo_priv->contrast_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->contrast_property, sdvo_priv->cur_contrast); DRM_DEBUG_KMS("contrast: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } if (sdvo_data.hue) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_HUE, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max hue\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HUE, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get hue\n"); return; } sdvo_priv->max_hue = data_value[0]; sdvo_priv->cur_hue = response; sdvo_priv->hue_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "hue", 2); sdvo_priv->hue_property->values[0] = 0; sdvo_priv->hue_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->hue_property, sdvo_priv->cur_hue); DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n", data_value[0], data_value[1], response); } } if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { if (sdvo_data.brightness) { intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &data_value, 4); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO Max bright\n"); return; } intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_BRIGHTNESS, NULL, 0); status = intel_sdvo_read_response(intel_encoder, &response, 2); if (status != SDVO_CMD_STATUS_SUCCESS) { DRM_DEBUG_KMS("Incorrect SDVO get brigh\n"); return; } sdvo_priv->max_brightness = data_value[0]; sdvo_priv->cur_brightness = response; sdvo_priv->brightness_property = drm_property_create(dev, DRM_MODE_PROP_RANGE, "brightness", 2); sdvo_priv->brightness_property->values[0] = 0; sdvo_priv->brightness_property->values[1] = data_value[0]; drm_connector_attach_property(connector, sdvo_priv->brightness_property, sdvo_priv->cur_brightness); DRM_DEBUG_KMS("brightness: max %d, " "default %d, current %d\n", data_value[0], data_value[1], response); } } return; } bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) { struct drm_i915_private *dev_priv = dev->dev_private; struct intel_encoder *intel_encoder; struct intel_sdvo_priv *sdvo_priv; u8 ch[0x40]; int i; u32 i2c_reg, ddc_reg, analog_ddc_reg; intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); if (!intel_encoder) { return false; } sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1); sdvo_priv->sdvo_reg = sdvo_reg; intel_encoder->dev_priv = sdvo_priv; intel_encoder->type = INTEL_OUTPUT_SDVO; if (HAS_PCH_SPLIT(dev)) { i2c_reg = PCH_GPIOE; ddc_reg = PCH_GPIOE; analog_ddc_reg = PCH_GPIOA; } else { i2c_reg = GPIOE; ddc_reg = GPIOE; analog_ddc_reg = GPIOA; } /* setup the DDC bus. */ if (IS_SDVOB(sdvo_reg)) intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB"); else intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC"); if (!intel_encoder->i2c_bus) goto err_inteloutput; sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); /* Save the bit-banging i2c functionality for use by the DDC wrapper */ intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; /* Read the regs to test if we can talk to the device */ for (i = 0; i < 0x40; i++) { if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) { DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", IS_SDVOB(sdvo_reg) ? 'B' : 'C'); goto err_i2c; } } /* setup the DDC bus. */ if (IS_SDVOB(sdvo_reg)) { intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS"); sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, "SDVOB/VGA DDC BUS"); dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; } else { intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS"); sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, "SDVOC/VGA DDC BUS"); dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; } if (intel_encoder->ddc_bus == NULL) goto err_i2c; /* Wrap with our custom algo which switches to DDC mode */ intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; /* encoder type will be decided later */ drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0); drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); /* In default case sdvo lvds is false */ intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps); if (intel_sdvo_output_setup(intel_encoder, sdvo_priv->caps.output_flags) != true) { DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", IS_SDVOB(sdvo_reg) ? 'B' : 'C'); goto err_i2c; } intel_sdvo_select_ddc_bus(dev_priv, sdvo_priv, sdvo_reg); /* Set the input timing to the screen. Assume always input 0. */ intel_sdvo_set_target_input(intel_encoder, true, false); intel_sdvo_get_input_pixel_clock_range(intel_encoder, &sdvo_priv->pixel_clock_min, &sdvo_priv->pixel_clock_max); DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " "clock range %dMHz - %dMHz, " "input 1: %c, input 2: %c, " "output 1: %c, output 2: %c\n", SDVO_NAME(sdvo_priv), sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id, sdvo_priv->caps.device_rev_id, sdvo_priv->pixel_clock_min / 1000, sdvo_priv->pixel_clock_max / 1000, (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N', (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N', /* check currently supported outputs */ sdvo_priv->caps.output_flags & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N', sdvo_priv->caps.output_flags & (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); return true; err_i2c: if (sdvo_priv->analog_ddc_bus != NULL) intel_i2c_destroy(sdvo_priv->analog_ddc_bus); if (intel_encoder->ddc_bus != NULL) intel_i2c_destroy(intel_encoder->ddc_bus); if (intel_encoder->i2c_bus != NULL) intel_i2c_destroy(intel_encoder->i2c_bus); err_inteloutput: kfree(intel_encoder); return false; }
gpl-2.0
snishanth512/linux
sound/soc/fsl/p1022_ds.c
827
13281
/** * Freescale P1022DS ALSA SoC Machine driver * * Author: Timur Tabi <timur@freescale.com> * * Copyright 2010 Freescale Semiconductor, Inc. * * This file is licensed under the terms of the GNU General Public License * version 2. This program is licensed "as is" without any warranty of any * kind, whether express or implied. */ #include <linux/module.h> #include <linux/interrupt.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/slab.h> #include <sound/soc.h> #include <asm/fsl_guts.h> #include "fsl_dma.h" #include "fsl_ssi.h" #include "fsl_utils.h" /* P1022-specific PMUXCR and DMUXCR bit definitions */ #define CCSR_GUTS_PMUXCR_UART0_I2C1_MASK 0x0001c000 #define CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI 0x00010000 #define CCSR_GUTS_PMUXCR_UART0_I2C1_SSI 0x00018000 #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK 0x00000c00 #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI 0x00000000 #define CCSR_GUTS_DMUXCR_PAD 1 /* DMA controller/channel set to pad */ #define CCSR_GUTS_DMUXCR_SSI 2 /* DMA controller/channel set to SSI */ /* * Set the DMACR register in the GUTS * * The DMACR register determines the source of initiated transfers for each * channel on each DMA controller. Rather than have a bunch of repetitive * macros for the bit patterns, we just have a function that calculates * them. * * guts: Pointer to GUTS structure * co: The DMA controller (0 or 1) * ch: The channel on the DMA controller (0, 1, 2, or 3) * device: The device to set as the target (CCSR_GUTS_DMUXCR_xxx) */ static inline void guts_set_dmuxcr(struct ccsr_guts __iomem *guts, unsigned int co, unsigned int ch, unsigned int device) { unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch)); clrsetbits_be32(&guts->dmuxcr, 3 << shift, device << shift); } /* There's only one global utilities register */ static phys_addr_t guts_phys; /** * machine_data: machine-specific ASoC device data * * This structure contains data for a single sound platform device on an * P1022 DS. Some of the data is taken from the device tree. */ struct machine_data { struct snd_soc_dai_link dai[2]; struct snd_soc_card card; unsigned int dai_format; unsigned int codec_clk_direction; unsigned int cpu_clk_direction; unsigned int clk_frequency; unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */ unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ }; /** * p1022_ds_machine_probe: initialize the board * * This function is used to initialize the board-specific hardware. * * Here we program the DMACR and PMUXCR registers. */ static int p1022_ds_machine_probe(struct snd_soc_card *card) { struct machine_data *mdata = container_of(card, struct machine_data, card); struct ccsr_guts __iomem *guts; guts = ioremap(guts_phys, sizeof(struct ccsr_guts)); if (!guts) { dev_err(card->dev, "could not map global utilities\n"); return -ENOMEM; } /* Enable SSI Tx signal */ clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK, CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI); /* Enable SSI Rx signal */ clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI); /* Enable DMA Channel for SSI */ guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0], CCSR_GUTS_DMUXCR_SSI); guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1], CCSR_GUTS_DMUXCR_SSI); iounmap(guts); return 0; } /** * p1022_ds_startup: program the board with various hardware parameters * * This function takes board-specific information, like clock frequencies * and serial data formats, and passes that information to the codec and * transport drivers. */ static int p1022_ds_startup(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct machine_data *mdata = container_of(rtd->card, struct machine_data, card); struct device *dev = rtd->card->dev; int ret = 0; /* Tell the codec driver what the serial protocol is. */ ret = snd_soc_dai_set_fmt(rtd->codec_dai, mdata->dai_format); if (ret < 0) { dev_err(dev, "could not set codec driver audio format\n"); return ret; } /* * Tell the codec driver what the MCLK frequency is, and whether it's * a slave or master. */ ret = snd_soc_dai_set_sysclk(rtd->codec_dai, 0, mdata->clk_frequency, mdata->codec_clk_direction); if (ret < 0) { dev_err(dev, "could not set codec driver clock params\n"); return ret; } return 0; } /** * p1022_ds_machine_remove: Remove the sound device * * This function is called to remove the sound device for one SSI. We * de-program the DMACR and PMUXCR register. */ static int p1022_ds_machine_remove(struct snd_soc_card *card) { struct machine_data *mdata = container_of(card, struct machine_data, card); struct ccsr_guts __iomem *guts; guts = ioremap(guts_phys, sizeof(struct ccsr_guts)); if (!guts) { dev_err(card->dev, "could not map global utilities\n"); return -ENOMEM; } /* Restore the signal routing */ clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK); clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK); guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0], 0); guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1], 0); iounmap(guts); return 0; } /** * p1022_ds_ops: ASoC machine driver operations */ static struct snd_soc_ops p1022_ds_ops = { .startup = p1022_ds_startup, }; /** * p1022_ds_probe: platform probe function for the machine driver * * Although this is a machine driver, the SSI node is the "master" node with * respect to audio hardware connections. Therefore, we create a new ASoC * device for each new SSI node that has a codec attached. */ static int p1022_ds_probe(struct platform_device *pdev) { struct device *dev = pdev->dev.parent; /* ssi_pdev is the platform device for the SSI node that probed us */ struct platform_device *ssi_pdev = container_of(dev, struct platform_device, dev); struct device_node *np = ssi_pdev->dev.of_node; struct device_node *codec_np = NULL; struct machine_data *mdata; int ret = -ENODEV; const char *sprop; const u32 *iprop; /* Find the codec node for this SSI. */ codec_np = of_parse_phandle(np, "codec-handle", 0); if (!codec_np) { dev_err(dev, "could not find codec node\n"); return -EINVAL; } mdata = kzalloc(sizeof(struct machine_data), GFP_KERNEL); if (!mdata) { ret = -ENOMEM; goto error_put; } mdata->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); mdata->dai[0].ops = &p1022_ds_ops; /* ASoC core can match codec with device node */ mdata->dai[0].codec_of_node = codec_np; /* We register two DAIs per SSI, one for playback and the other for * capture. We support codecs that have separate DAIs for both playback * and capture. */ memcpy(&mdata->dai[1], &mdata->dai[0], sizeof(struct snd_soc_dai_link)); /* The DAI names from the codec (snd_soc_dai_driver.name) */ mdata->dai[0].codec_dai_name = "wm8776-hifi-playback"; mdata->dai[1].codec_dai_name = "wm8776-hifi-capture"; /* Get the device ID */ iprop = of_get_property(np, "cell-index", NULL); if (!iprop) { dev_err(&pdev->dev, "cell-index property not found\n"); ret = -EINVAL; goto error; } mdata->ssi_id = be32_to_cpup(iprop); /* Get the serial format and clock direction. */ sprop = of_get_property(np, "fsl,mode", NULL); if (!sprop) { dev_err(&pdev->dev, "fsl,mode property not found\n"); ret = -EINVAL; goto error; } if (strcasecmp(sprop, "i2s-slave") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM; mdata->codec_clk_direction = SND_SOC_CLOCK_OUT; mdata->cpu_clk_direction = SND_SOC_CLOCK_IN; /* In i2s-slave mode, the codec has its own clock source, so we * need to get the frequency from the device tree and pass it to * the codec driver. */ iprop = of_get_property(codec_np, "clock-frequency", NULL); if (!iprop || !*iprop) { dev_err(&pdev->dev, "codec bus-frequency " "property is missing or invalid\n"); ret = -EINVAL; goto error; } mdata->clk_frequency = be32_to_cpup(iprop); } else if (strcasecmp(sprop, "i2s-master") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS; mdata->codec_clk_direction = SND_SOC_CLOCK_IN; mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT; } else if (strcasecmp(sprop, "lj-slave") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM; mdata->codec_clk_direction = SND_SOC_CLOCK_OUT; mdata->cpu_clk_direction = SND_SOC_CLOCK_IN; } else if (strcasecmp(sprop, "lj-master") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBS_CFS; mdata->codec_clk_direction = SND_SOC_CLOCK_IN; mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT; } else if (strcasecmp(sprop, "rj-slave") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBM_CFM; mdata->codec_clk_direction = SND_SOC_CLOCK_OUT; mdata->cpu_clk_direction = SND_SOC_CLOCK_IN; } else if (strcasecmp(sprop, "rj-master") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBS_CFS; mdata->codec_clk_direction = SND_SOC_CLOCK_IN; mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT; } else if (strcasecmp(sprop, "ac97-slave") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM; mdata->codec_clk_direction = SND_SOC_CLOCK_OUT; mdata->cpu_clk_direction = SND_SOC_CLOCK_IN; } else if (strcasecmp(sprop, "ac97-master") == 0) { mdata->dai_format = SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS; mdata->codec_clk_direction = SND_SOC_CLOCK_IN; mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT; } else { dev_err(&pdev->dev, "unrecognized fsl,mode property '%s'\n", sprop); ret = -EINVAL; goto error; } if (!mdata->clk_frequency) { dev_err(&pdev->dev, "unknown clock frequency\n"); ret = -EINVAL; goto error; } /* Find the playback DMA channel to use. */ mdata->dai[0].platform_name = mdata->platform_name[0]; ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0], &mdata->dma_channel_id[0], &mdata->dma_id[0]); if (ret) { dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); goto error; } /* Find the capture DMA channel to use. */ mdata->dai[1].platform_name = mdata->platform_name[1]; ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1], &mdata->dma_channel_id[1], &mdata->dma_id[1]); if (ret) { dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); goto error; } /* Initialize our DAI data structure. */ mdata->dai[0].stream_name = "playback"; mdata->dai[1].stream_name = "capture"; mdata->dai[0].name = mdata->dai[0].stream_name; mdata->dai[1].name = mdata->dai[1].stream_name; mdata->card.probe = p1022_ds_machine_probe; mdata->card.remove = p1022_ds_machine_remove; mdata->card.name = pdev->name; /* The platform driver name */ mdata->card.owner = THIS_MODULE; mdata->card.dev = &pdev->dev; mdata->card.num_links = 2; mdata->card.dai_link = mdata->dai; /* Register with ASoC */ ret = snd_soc_register_card(&mdata->card); if (ret) { dev_err(&pdev->dev, "could not register card\n"); goto error; } of_node_put(codec_np); return 0; error: kfree(mdata); error_put: of_node_put(codec_np); return ret; } /** * p1022_ds_remove: remove the platform device * * This function is called when the platform device is removed. */ static int p1022_ds_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); struct machine_data *mdata = container_of(card, struct machine_data, card); snd_soc_unregister_card(card); kfree(mdata); return 0; } static struct platform_driver p1022_ds_driver = { .probe = p1022_ds_probe, .remove = p1022_ds_remove, .driver = { /* * The name must match 'compatible' property in the device tree, * in lowercase letters. */ .name = "snd-soc-p1022ds", }, }; /** * p1022_ds_init: machine driver initialization. * * This function is called when this module is loaded. */ static int __init p1022_ds_init(void) { struct device_node *guts_np; struct resource res; /* Get the physical address of the global utilities registers */ guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts"); if (of_address_to_resource(guts_np, 0, &res)) { pr_err("snd-soc-p1022ds: missing/invalid global utils node\n"); of_node_put(guts_np); return -EINVAL; } guts_phys = res.start; of_node_put(guts_np); return platform_driver_register(&p1022_ds_driver); } /** * p1022_ds_exit: machine driver exit * * This function is called when this driver is unloaded. */ static void __exit p1022_ds_exit(void) { platform_driver_unregister(&p1022_ds_driver); } module_init(p1022_ds_init); module_exit(p1022_ds_exit); MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); MODULE_DESCRIPTION("Freescale P1022 DS ALSA SoC machine driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
FrancescoCG/CrazySuperKernel-CM13-KLTE-NEW-REBASE
arch/arm/mach-msm/board-msm7x27.c
2107
55318
/* * Copyright (C) 2007 Google, Inc. * Copyright (c) 2008-2012, The Linux Foundation. All rights reserved. * Author: Brian Swetland <swetland@google.com> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/kernel.h> #include <linux/gpio.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/input.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/bootmem.h> #include <linux/power_supply.h> #include <mach/msm_memtypes.h> #include <mach/hardware.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <asm/mach/map.h> #include <asm/mach/flash.h> #include <asm/setup.h> #ifdef CONFIG_CACHE_L2X0 #include <asm/hardware/cache-l2x0.h> #endif #include <asm/mach/mmc.h> #include <mach/vreg.h> #include <mach/mpp.h> #include <mach/board.h> #include <mach/pmic.h> #include <mach/msm_iomap.h> #include <mach/msm_rpcrouter.h> #include <mach/msm_hsusb.h> #include <mach/rpc_hsusb.h> #include <mach/rpc_pmapp.h> #include <mach/msm_serial_hs.h> #include <mach/memory.h> #include <mach/msm_battery.h> #include <mach/rpc_server_handset.h> #include <mach/msm_tsif.h> #include <mach/socinfo.h> #include <linux/mtd/nand.h> #include <linux/mtd/partitions.h> #include <linux/i2c.h> #include <mach/camera.h> #ifdef CONFIG_USB_G_ANDROID #include <linux/usb/android.h> #include <mach/usbdiag.h> #endif #include "board-msm7627-regulator.h" #include "devices.h" #include "clock.h" #include "msm-keypad-devices.h" #include "pm.h" #include "pm-boot.h" #ifdef CONFIG_ARCH_MSM7X25 #define MSM_PMEM_MDP_SIZE 0xb21000 #define MSM_PMEM_ADSP_SIZE 0x97b000 #define MSM_PMEM_AUDIO_SIZE 0x121000 #define MSM_FB_SIZE 0x200000 #define PMEM_KERNEL_EBI1_SIZE 0x64000 #endif #ifdef CONFIG_ARCH_MSM7X27 #define MSM_PMEM_MDP_SIZE 0x1B76000 #define MSM_PMEM_ADSP_SIZE 0xC8A000 #define MSM_PMEM_AUDIO_SIZE 0x5B000 #ifdef CONFIG_FB_MSM_TRIPLE_BUFFER #define MSM_FB_SIZE 0x233000 #else #define MSM_FB_SIZE 0x177000 #endif #define PMEM_KERNEL_EBI1_SIZE 0x1C000 #endif #define ADSP_RPC_PROG 0x3000000a static struct resource smc91x_resources[] = { [0] = { .start = 0x9C004300, .end = 0x9C0043ff, .flags = IORESOURCE_MEM, }, [1] = { .start = MSM_GPIO_TO_INT(132), .end = MSM_GPIO_TO_INT(132), .flags = IORESOURCE_IRQ, }, }; static struct platform_device smc91x_device = { .name = "smc91x", .id = 0, .num_resources = ARRAY_SIZE(smc91x_resources), .resource = smc91x_resources, }; #ifdef CONFIG_USB_G_ANDROID static struct android_usb_platform_data android_usb_pdata = { .update_pid_and_serial_num = usb_diag_update_pid_and_serial_num, }; static struct platform_device android_usb_device = { .name = "android_usb", .id = -1, .dev = { .platform_data = &android_usb_pdata, }, }; #endif #ifdef CONFIG_USB_EHCI_MSM_72K static void msm_hsusb_vbus_power(unsigned phy_info, int on) { if (on) msm_hsusb_vbus_powerup(); else msm_hsusb_vbus_shutdown(); } static struct msm_usb_host_platform_data msm_usb_host_pdata = { .phy_info = (USB_PHY_INTEGRATED | USB_PHY_MODEL_65NM), }; static void __init msm7x2x_init_host(void) { if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) return; msm_add_host(0, &msm_usb_host_pdata); } #endif #ifdef CONFIG_USB_MSM_OTG_72K static int hsusb_rpc_connect(int connect) { if (connect) return msm_hsusb_rpc_connect(); else return msm_hsusb_rpc_close(); } #endif #ifdef CONFIG_USB_MSM_OTG_72K static int msm_hsusb_ldo_init(int init) { static struct regulator *reg_hsusb; int rc; if (init) { reg_hsusb = regulator_get(NULL, "usb"); if (IS_ERR(reg_hsusb)) { rc = PTR_ERR(reg_hsusb); pr_err("%s: could not get regulator: %d\n", __func__, rc); goto out; } rc = regulator_set_voltage(reg_hsusb, 3300000, 3300000); if (rc < 0) { pr_err("%s: could not set voltage: %d\n", __func__, rc); goto usb_reg_fail; } rc = regulator_enable(reg_hsusb); if (rc < 0) { pr_err("%s: could not enable regulator: %d\n", __func__, rc); goto usb_reg_fail; } /* * PHY 3.3V analog domain(VDDA33) is powered up by * an always enabled power supply (LP5900TL-3.3). * USB VREG default source is VBUS line. Turning * on USB VREG has a side effect on the USB suspend * current. Hence USB VREG is explicitly turned * off here. */ rc = regulator_disable(reg_hsusb); if (rc < 0) { pr_err("%s: could not disable regulator: %d\n", __func__, rc); goto usb_reg_fail; } regulator_put(reg_hsusb); } return 0; usb_reg_fail: regulator_put(reg_hsusb); out: return rc; } static int msm_hsusb_pmic_notif_init(void (*callback)(int online), int init) { int ret; if (init) { ret = msm_pm_app_rpc_init(callback); } else { msm_pm_app_rpc_deinit(callback); ret = 0; } return ret; } static int msm_otg_rpc_phy_reset(void __iomem *regs) { return msm_hsusb_phy_reset(); } static struct msm_otg_platform_data msm_otg_pdata = { .rpc_connect = hsusb_rpc_connect, .pmic_vbus_notif_init = msm_hsusb_pmic_notif_init, .chg_vbus_draw = hsusb_chg_vbus_draw, .chg_connected = hsusb_chg_connected, .chg_init = hsusb_chg_init, #ifdef CONFIG_USB_EHCI_MSM_72K .vbus_power = msm_hsusb_vbus_power, #endif .ldo_init = msm_hsusb_ldo_init, .pclk_required_during_lpm = 1, }; #ifdef CONFIG_USB_GADGET static struct msm_hsusb_gadget_platform_data msm_gadget_pdata; #endif #endif #define SND(desc, num) { .name = #desc, .id = num } static struct snd_endpoint snd_endpoints_list[] = { SND(HANDSET, 0), SND(MONO_HEADSET, 2), SND(HEADSET, 3), SND(SPEAKER, 6), SND(TTY_HEADSET, 8), SND(TTY_VCO, 9), SND(TTY_HCO, 10), SND(BT, 12), SND(IN_S_SADC_OUT_HANDSET, 16), SND(IN_S_SADC_OUT_SPEAKER_PHONE, 25), SND(CURRENT, 27), }; #undef SND static struct msm_snd_endpoints msm_device_snd_endpoints = { .endpoints = snd_endpoints_list, .num = sizeof(snd_endpoints_list) / sizeof(struct snd_endpoint) }; static struct platform_device msm_device_snd = { .name = "msm_snd", .id = -1, .dev = { .platform_data = &msm_device_snd_endpoints }, }; #define DEC0_FORMAT ((1<<MSM_ADSP_CODEC_MP3)| \ (1<<MSM_ADSP_CODEC_AAC)|(1<<MSM_ADSP_CODEC_WMA)| \ (1<<MSM_ADSP_CODEC_WMAPRO)|(1<<MSM_ADSP_CODEC_AMRWB)| \ (1<<MSM_ADSP_CODEC_AMRNB)|(1<<MSM_ADSP_CODEC_WAV)| \ (1<<MSM_ADSP_CODEC_ADPCM)|(1<<MSM_ADSP_CODEC_YADPCM)| \ (1<<MSM_ADSP_CODEC_EVRC)|(1<<MSM_ADSP_CODEC_QCELP)) #ifdef CONFIG_ARCH_MSM7X25 #define DEC1_FORMAT ((1<<MSM_ADSP_CODEC_WAV)|(1<<MSM_ADSP_CODEC_ADPCM)| \ (1<<MSM_ADSP_CODEC_YADPCM)|(1<<MSM_ADSP_CODEC_QCELP)| \ (1<<MSM_ADSP_CODEC_MP3)) #define DEC2_FORMAT ((1<<MSM_ADSP_CODEC_WAV)|(1<<MSM_ADSP_CODEC_ADPCM)| \ (1<<MSM_ADSP_CODEC_YADPCM)|(1<<MSM_ADSP_CODEC_QCELP)| \ (1<<MSM_ADSP_CODEC_MP3)) #define DEC3_FORMAT 0 #define DEC4_FORMAT 0 #else #define DEC1_FORMAT ((1<<MSM_ADSP_CODEC_MP3)| \ (1<<MSM_ADSP_CODEC_AAC)|(1<<MSM_ADSP_CODEC_WMA)| \ (1<<MSM_ADSP_CODEC_WMAPRO)|(1<<MSM_ADSP_CODEC_AMRWB)| \ (1<<MSM_ADSP_CODEC_AMRNB)|(1<<MSM_ADSP_CODEC_WAV)| \ (1<<MSM_ADSP_CODEC_ADPCM)|(1<<MSM_ADSP_CODEC_YADPCM)| \ (1<<MSM_ADSP_CODEC_EVRC)|(1<<MSM_ADSP_CODEC_QCELP)) #define DEC2_FORMAT ((1<<MSM_ADSP_CODEC_MP3)| \ (1<<MSM_ADSP_CODEC_AAC)|(1<<MSM_ADSP_CODEC_WMA)| \ (1<<MSM_ADSP_CODEC_WMAPRO)|(1<<MSM_ADSP_CODEC_AMRWB)| \ (1<<MSM_ADSP_CODEC_AMRNB)|(1<<MSM_ADSP_CODEC_WAV)| \ (1<<MSM_ADSP_CODEC_ADPCM)|(1<<MSM_ADSP_CODEC_YADPCM)| \ (1<<MSM_ADSP_CODEC_EVRC)|(1<<MSM_ADSP_CODEC_QCELP)) #define DEC3_FORMAT ((1<<MSM_ADSP_CODEC_MP3)| \ (1<<MSM_ADSP_CODEC_AAC)|(1<<MSM_ADSP_CODEC_WMA)| \ (1<<MSM_ADSP_CODEC_WMAPRO)|(1<<MSM_ADSP_CODEC_AMRWB)| \ (1<<MSM_ADSP_CODEC_AMRNB)|(1<<MSM_ADSP_CODEC_WAV)| \ (1<<MSM_ADSP_CODEC_ADPCM)|(1<<MSM_ADSP_CODEC_YADPCM)| \ (1<<MSM_ADSP_CODEC_EVRC)|(1<<MSM_ADSP_CODEC_QCELP)) #define DEC4_FORMAT (1<<MSM_ADSP_CODEC_MIDI) #endif static unsigned int dec_concurrency_table[] = { /* Audio LP */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DMA)), 0, 0, 0, 0, /* Concurrency 1 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), /* Concurrency 2 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), /* Concurrency 3 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), /* Concurrency 4 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), /* Concurrency 5 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_TUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), /* Concurrency 6 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), 0, 0, 0, 0, /* Concurrency 7 */ (DEC0_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC1_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC2_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC3_FORMAT|(1<<MSM_ADSP_MODE_NONTUNNEL)|(1<<MSM_ADSP_OP_DM)), (DEC4_FORMAT), }; #define DEC_INFO(name, queueid, decid, nr_codec) { .module_name = name, \ .module_queueid = queueid, .module_decid = decid, \ .nr_codec_support = nr_codec} static struct msm_adspdec_info dec_info_list[] = { DEC_INFO("AUDPLAY0TASK", 13, 0, 11), /* AudPlay0BitStreamCtrlQueue */ #ifdef CONFIG_ARCH_MSM7X25 DEC_INFO("AUDPLAY1TASK", 14, 1, 5), /* AudPlay1BitStreamCtrlQueue */ DEC_INFO("AUDPLAY2TASK", 15, 2, 5), /* AudPlay2BitStreamCtrlQueue */ DEC_INFO("AUDPLAY3TASK", 16, 3, 0), /* AudPlay3BitStreamCtrlQueue */ DEC_INFO("AUDPLAY4TASK", 17, 4, 0), /* AudPlay4BitStreamCtrlQueue */ #else DEC_INFO("AUDPLAY1TASK", 14, 1, 11), /* AudPlay1BitStreamCtrlQueue */ DEC_INFO("AUDPLAY2TASK", 15, 2, 11), /* AudPlay2BitStreamCtrlQueue */ DEC_INFO("AUDPLAY3TASK", 16, 3, 11), /* AudPlay3BitStreamCtrlQueue */ DEC_INFO("AUDPLAY4TASK", 17, 4, 1), /* AudPlay4BitStreamCtrlQueue */ #endif }; static struct msm_adspdec_database msm_device_adspdec_database = { .num_dec = ARRAY_SIZE(dec_info_list), .num_concurrency_support = (ARRAY_SIZE(dec_concurrency_table) / \ ARRAY_SIZE(dec_info_list)), .dec_concurrency_table = dec_concurrency_table, .dec_info_list = dec_info_list, }; static struct platform_device msm_device_adspdec = { .name = "msm_adspdec", .id = -1, .dev = { .platform_data = &msm_device_adspdec_database }, }; static struct android_pmem_platform_data android_pmem_pdata = { .name = "pmem", .allocator_type = PMEM_ALLOCATORTYPE_BITMAP, .cached = 1, .memory_type = MEMTYPE_EBI1, }; static struct android_pmem_platform_data android_pmem_adsp_pdata = { .name = "pmem_adsp", .allocator_type = PMEM_ALLOCATORTYPE_BITMAP, .cached = 0, .memory_type = MEMTYPE_EBI1, }; static struct android_pmem_platform_data android_pmem_audio_pdata = { .name = "pmem_audio", .allocator_type = PMEM_ALLOCATORTYPE_BITMAP, .cached = 0, .memory_type = MEMTYPE_EBI1, }; static struct platform_device android_pmem_device = { .name = "android_pmem", .id = 0, .dev = { .platform_data = &android_pmem_pdata }, }; static struct platform_device android_pmem_adsp_device = { .name = "android_pmem", .id = 1, .dev = { .platform_data = &android_pmem_adsp_pdata }, }; static struct platform_device android_pmem_audio_device = { .name = "android_pmem", .id = 2, .dev = { .platform_data = &android_pmem_audio_pdata }, }; static struct msm_handset_platform_data hs_platform_data = { .hs_name = "7k_handset", .pwr_key_delay_ms = 500, /* 0 will disable end key */ }; static struct platform_device hs_device = { .name = "msm-handset", .id = -1, .dev = { .platform_data = &hs_platform_data, }, }; /* TSIF begin */ #if defined(CONFIG_TSIF) || defined(CONFIG_TSIF_MODULE) #define TSIF_B_SYNC GPIO_CFG(87, 5, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA) #define TSIF_B_DATA GPIO_CFG(86, 3, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA) #define TSIF_B_EN GPIO_CFG(85, 3, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA) #define TSIF_B_CLK GPIO_CFG(84, 4, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA) static const struct msm_gpio tsif_gpios[] = { { .gpio_cfg = TSIF_B_CLK, .label = "tsif_clk", }, { .gpio_cfg = TSIF_B_EN, .label = "tsif_en", }, { .gpio_cfg = TSIF_B_DATA, .label = "tsif_data", }, { .gpio_cfg = TSIF_B_SYNC, .label = "tsif_sync", }, }; static struct msm_tsif_platform_data tsif_platform_data = { .num_gpios = ARRAY_SIZE(tsif_gpios), .gpios = tsif_gpios, .tsif_clk = "core_clk", .tsif_pclk = "iface_clk", .tsif_ref_clk = "ref_clk", }; #endif /* defined(CONFIG_TSIF) || defined(CONFIG_TSIF_MODULE) */ /* TSIF end */ #define LCDC_CONFIG_PROC 21 #define LCDC_UN_CONFIG_PROC 22 #define LCDC_API_PROG 0x30000066 #define LCDC_API_VERS 0x00010001 #define GPIO_OUT_132 132 #define GPIO_OUT_131 131 #define GPIO_OUT_103 103 #define GPIO_OUT_102 102 #define GPIO_OUT_88 88 static struct msm_rpc_endpoint *lcdc_ep; static int msm_fb_lcdc_config(int on) { int rc = 0; struct rpc_request_hdr hdr; if (on) pr_info("lcdc config\n"); else pr_info("lcdc un-config\n"); lcdc_ep = msm_rpc_connect_compatible(LCDC_API_PROG, LCDC_API_VERS, 0); if (IS_ERR(lcdc_ep)) { printk(KERN_ERR "%s: msm_rpc_connect failed! rc = %ld\n", __func__, PTR_ERR(lcdc_ep)); return -EINVAL; } rc = msm_rpc_call(lcdc_ep, (on) ? LCDC_CONFIG_PROC : LCDC_UN_CONFIG_PROC, &hdr, sizeof(hdr), 5 * HZ); if (rc) printk(KERN_ERR "%s: msm_rpc_call failed! rc = %d\n", __func__, rc); msm_rpc_close(lcdc_ep); return rc; } static int gpio_array_num[] = { GPIO_OUT_132, /* spi_clk */ GPIO_OUT_131, /* spi_cs */ GPIO_OUT_103, /* spi_sdi */ GPIO_OUT_102, /* spi_sdoi */ GPIO_OUT_88 }; static void lcdc_gordon_gpio_init(void) { if (gpio_request(GPIO_OUT_132, "spi_clk")) pr_err("failed to request gpio spi_clk\n"); if (gpio_request(GPIO_OUT_131, "spi_cs")) pr_err("failed to request gpio spi_cs\n"); if (gpio_request(GPIO_OUT_103, "spi_sdi")) pr_err("failed to request gpio spi_sdi\n"); if (gpio_request(GPIO_OUT_102, "spi_sdoi")) pr_err("failed to request gpio spi_sdoi\n"); if (gpio_request(GPIO_OUT_88, "gpio_dac")) pr_err("failed to request gpio_dac\n"); } static uint32_t lcdc_gpio_table[] = { GPIO_CFG(GPIO_OUT_132, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG(GPIO_OUT_131, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG(GPIO_OUT_103, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG(GPIO_OUT_102, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG(GPIO_OUT_88, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), }; static void config_lcdc_gpio_table(uint32_t *table, int len, unsigned enable) { int n, rc; for (n = 0; n < len; n++) { rc = gpio_tlmm_config(table[n], enable ? GPIO_CFG_ENABLE : GPIO_CFG_DISABLE); if (rc) { printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, table[n], rc); break; } } } static void lcdc_gordon_config_gpios(int enable) { config_lcdc_gpio_table(lcdc_gpio_table, ARRAY_SIZE(lcdc_gpio_table), enable); } static char *msm_fb_lcdc_vreg[] = { "gp5" }; static int msm_fb_lcdc_power_save(int on) { int i, rc = 0; static struct regulator *vreg[ARRAY_SIZE(msm_fb_lcdc_vreg)]; if (on) { for (i = 0; i < ARRAY_SIZE(msm_fb_lcdc_vreg); i++) { vreg[i] = regulator_get(NULL, msm_fb_lcdc_vreg[i]); if (IS_ERR(vreg[i])) { rc = PTR_ERR(vreg[i]); pr_err("%s: could get not regulator: %d\n", __func__, rc); goto reg_get_fail; } rc = regulator_set_voltage(vreg[i], 2850000, 3000000); if (rc < 0) { pr_err("%s: could not set voltage: %d\n", __func__, rc); goto reg_get_fail; } } } for (i = 0; i < ARRAY_SIZE(msm_fb_lcdc_vreg); i++) { if (on) { rc = regulator_enable(vreg[i]); if (rc) { pr_err("%s: could not enable regulator %s:" "%d\n", __func__, msm_fb_lcdc_vreg[i], rc); goto vreg_lcdc_fail; } } else { rc = regulator_disable(vreg[i]); if (rc) { pr_err("%s: could not disable regulator %s:" "%d\n", __func__, msm_fb_lcdc_vreg[i], rc); regulator_put(vreg[i]); goto vreg_lcdc_fail; } regulator_put(vreg[i]); rc = gpio_tlmm_config(GPIO_CFG(GPIO_OUT_88, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE); if (rc) printk(KERN_ERR "gpio_tlmm_config failed\n"); gpio_set_value(88, 0); mdelay(15); gpio_set_value(88, 1); mdelay(15); } } return rc; reg_get_fail: for (; i > 0; i--) regulator_put(vreg[i - 1]); return rc; vreg_lcdc_fail: if (on) { for (; i > 0; i--) regulator_disable(vreg[i - 1]); } else { for (; i > 0; i--) regulator_enable(vreg[i - 1]); } return rc; } static struct lcdc_platform_data lcdc_pdata = { .lcdc_gpio_config = msm_fb_lcdc_config, .lcdc_power_save = msm_fb_lcdc_power_save, }; static struct msm_panel_common_pdata lcdc_gordon_panel_data = { .panel_config_gpio = lcdc_gordon_config_gpios, .gpio_num = gpio_array_num, }; static struct platform_device lcdc_gordon_panel_device = { .name = "lcdc_gordon_vga", .id = 0, .dev = { .platform_data = &lcdc_gordon_panel_data, } }; static struct resource msm_fb_resources[] = { { .flags = IORESOURCE_DMA, } }; static int msm_fb_detect_panel(const char *name) { int ret = -EPERM; if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) { if (!strcmp(name, "lcdc_gordon_vga")) ret = 0; else ret = -ENODEV; } return ret; } static struct msm_fb_platform_data msm_fb_pdata = { .detect_client = msm_fb_detect_panel, .mddi_prescan = 1, }; static struct platform_device msm_fb_device = { .name = "msm_fb", .id = 0, .num_resources = ARRAY_SIZE(msm_fb_resources), .resource = msm_fb_resources, .dev = { .platform_data = &msm_fb_pdata, } }; #ifdef CONFIG_BT static struct platform_device msm_bt_power_device = { .name = "bt_power", }; enum { BT_WAKE, BT_RFR, BT_CTS, BT_RX, BT_TX, BT_PCM_DOUT, BT_PCM_DIN, BT_PCM_SYNC, BT_PCM_CLK, BT_HOST_WAKE, }; static unsigned bt_config_power_on[] = { GPIO_CFG(42, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* WAKE */ GPIO_CFG(43, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* RFR */ GPIO_CFG(44, 2, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* CTS */ GPIO_CFG(45, 2, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* Rx */ GPIO_CFG(46, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* Tx */ GPIO_CFG(68, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* PCM_DOUT */ GPIO_CFG(69, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* PCM_DIN */ GPIO_CFG(70, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* PCM_SYNC */ GPIO_CFG(71, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* PCM_CLK */ GPIO_CFG(83, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* HOST_WAKE */ }; static unsigned bt_config_power_off[] = { GPIO_CFG(42, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* WAKE */ GPIO_CFG(43, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* RFR */ GPIO_CFG(44, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* CTS */ GPIO_CFG(45, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* Rx */ GPIO_CFG(46, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* Tx */ GPIO_CFG(68, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* PCM_DOUT */ GPIO_CFG(69, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* PCM_DIN */ GPIO_CFG(70, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* PCM_SYNC */ GPIO_CFG(71, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* PCM_CLK */ GPIO_CFG(83, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* HOST_WAKE */ }; static int bluetooth_power(int on) { int pin, rc; static struct regulator *vreg_bt; printk(KERN_DEBUG "%s\n", __func__); /* do not have vreg bt defined, gp6 is the same */ /* vreg_get parameter 1 (struct device *) is ignored */ if (on) { for (pin = 0; pin < ARRAY_SIZE(bt_config_power_on); pin++) { rc = gpio_tlmm_config(bt_config_power_on[pin], GPIO_CFG_ENABLE); if (rc) { printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, bt_config_power_on[pin], rc); return -EIO; } } vreg_bt = regulator_get(NULL, "gp6"); if (IS_ERR(vreg_bt)) { rc = PTR_ERR(vreg_bt); pr_err("%s: could get not regulator: %d\n", __func__, rc); goto out; } /* units of mV, steps of 50 mV */ rc = regulator_set_voltage(vreg_bt, 2600000, 2600000); if (rc < 0) { pr_err("%s: could not set voltage: %d\n", __func__, rc); goto bt_vreg_fail; } rc = regulator_enable(vreg_bt); if (rc < 0) { pr_err("%s: could not enable regulator: %d\n", __func__, rc); goto bt_vreg_fail; } } else { rc = regulator_disable(vreg_bt); if (rc < 0) { pr_err("%s: could not disable regulator: %d\n", __func__, rc); goto bt_vreg_fail; } regulator_put(vreg_bt); for (pin = 0; pin < ARRAY_SIZE(bt_config_power_off); pin++) { rc = gpio_tlmm_config(bt_config_power_off[pin], GPIO_CFG_ENABLE); if (rc) { printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, bt_config_power_off[pin], rc); return -EIO; } } } return 0; bt_vreg_fail: regulator_put(vreg_bt); out: return rc; } static void __init bt_power_init(void) { msm_bt_power_device.dev.platform_data = &bluetooth_power; } #else #define bt_power_init(x) do {} while (0) #endif static struct platform_device msm_device_pmic_leds = { .name = "pmic-leds", .id = -1, }; static struct resource bluesleep_resources[] = { { .name = "gpio_host_wake", .start = 83, .end = 83, .flags = IORESOURCE_IO, }, { .name = "gpio_ext_wake", .start = 42, .end = 42, .flags = IORESOURCE_IO, }, { .name = "host_wake", .start = MSM_GPIO_TO_INT(83), .end = MSM_GPIO_TO_INT(83), .flags = IORESOURCE_IRQ, }, }; static struct platform_device msm_bluesleep_device = { .name = "bluesleep", .id = -1, .num_resources = ARRAY_SIZE(bluesleep_resources), .resource = bluesleep_resources, }; static struct i2c_board_info i2c_devices[] = { #ifdef CONFIG_MT9D112 { I2C_BOARD_INFO("mt9d112", 0x78 >> 1), }, #endif #ifdef CONFIG_S5K3E2FX { I2C_BOARD_INFO("s5k3e2fx", 0x20 >> 1), }, #endif #ifdef CONFIG_MT9P012 { I2C_BOARD_INFO("mt9p012", 0x6C >> 1), }, #endif #ifdef CONFIG_MT9P012_KM { I2C_BOARD_INFO("mt9p012_km", 0x6C >> 2), }, #endif #if defined(CONFIG_MT9T013) || defined(CONFIG_SENSORS_MT9T013) { I2C_BOARD_INFO("mt9t013", 0x6C), }, #endif #ifdef CONFIG_VB6801 { I2C_BOARD_INFO("vb6801", 0x20), }, #endif }; #ifdef CONFIG_MSM_CAMERA static uint32_t camera_off_gpio_table[] = { /* parallel CAMERA interfaces */ GPIO_CFG(0, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT0 */ GPIO_CFG(1, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT1 */ GPIO_CFG(2, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT2 */ GPIO_CFG(3, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT3 */ GPIO_CFG(4, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT4 */ GPIO_CFG(5, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT5 */ GPIO_CFG(6, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT6 */ GPIO_CFG(7, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT7 */ GPIO_CFG(8, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT8 */ GPIO_CFG(9, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT9 */ GPIO_CFG(10, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT10 */ GPIO_CFG(11, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT11 */ GPIO_CFG(12, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* PCLK */ GPIO_CFG(13, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* HSYNC_IN */ GPIO_CFG(14, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* VSYNC_IN */ GPIO_CFG(15, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), /* MCLK */ }; static uint32_t camera_on_gpio_table[] = { /* parallel CAMERA interfaces */ GPIO_CFG(0, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT0 */ GPIO_CFG(1, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT1 */ GPIO_CFG(2, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT2 */ GPIO_CFG(3, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT3 */ GPIO_CFG(4, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT4 */ GPIO_CFG(5, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT5 */ GPIO_CFG(6, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT6 */ GPIO_CFG(7, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT7 */ GPIO_CFG(8, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT8 */ GPIO_CFG(9, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT9 */ GPIO_CFG(10, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT10 */ GPIO_CFG(11, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* DAT11 */ GPIO_CFG(12, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_16MA), /* PCLK */ GPIO_CFG(13, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* HSYNC_IN */ GPIO_CFG(14, 1, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), /* VSYNC_IN */ GPIO_CFG(15, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_16MA), /* MCLK */ }; static void config_gpio_table(uint32_t *table, int len) { int n, rc; for (n = 0; n < len; n++) { rc = gpio_tlmm_config(table[n], GPIO_CFG_ENABLE); if (rc) { printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, table[n], rc); break; } } } static void msm_camera_vreg_config(int vreg_en) { int rc; static struct regulator *vreg_gp2; static struct regulator *vreg_gp3; if (vreg_gp2 == NULL && vreg_gp3 == NULL) { vreg_gp2 = regulator_get(NULL, "gp2"); if (IS_ERR(vreg_gp2)) { rc = PTR_ERR(vreg_gp2); pr_err("%s: could not get regulator: %d\n", __func__, rc); return; } rc = regulator_set_voltage(vreg_gp2, 1800000, 1800000); if (rc < 0) { pr_err("%s: could not set voltage: %d\n", __func__, rc); goto cam_vreg_fail; } vreg_gp3 = regulator_get(NULL, "gp3"); if (IS_ERR(vreg_gp3)) { rc = PTR_ERR(vreg_gp3); pr_err("%s: could not get regulator: %d\n", __func__, rc); goto cam_vreg_fail; } rc = regulator_set_voltage(vreg_gp3, 2850000, 2850000); if (rc < 0) { pr_err("%s: could not set voltage: %d\n", __func__, rc); goto cam_vreg2_fail; } return; } if (vreg_gp2 == NULL || vreg_gp3 == NULL) { pr_err("Camera Regulators are not initialized\n"); return; } if (vreg_en) { rc = regulator_enable(vreg_gp2); if (rc) { pr_err("%s: could not enable regulator: %d\n", __func__, rc); goto cam_vreg2_fail; } rc = regulator_enable(vreg_gp3); if (rc) { pr_err("%s: could not enable regulator: %d\n", __func__, rc); goto vreg_gp3_fail; } } else { rc = regulator_disable(vreg_gp2); if (rc) { pr_err("%s: could not disable regulator: %d\n", __func__, rc); return; } rc = regulator_disable(vreg_gp3); if (rc) { pr_err("%s: could not disable regulator: %d\n", __func__, rc); goto cam_vreg2_fail; } } return; vreg_gp3_fail: if (vreg_en) regulator_disable(vreg_gp2); cam_vreg2_fail: regulator_put(vreg_gp3); cam_vreg_fail: regulator_put(vreg_gp2); vreg_gp3 = NULL; vreg_gp2 = NULL; } static int config_camera_on_gpios(void) { int vreg_en = 1; if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) msm_camera_vreg_config(vreg_en); config_gpio_table(camera_on_gpio_table, ARRAY_SIZE(camera_on_gpio_table)); return 0; } static void config_camera_off_gpios(void) { int vreg_en = 0; if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) msm_camera_vreg_config(vreg_en); config_gpio_table(camera_off_gpio_table, ARRAY_SIZE(camera_off_gpio_table)); } static struct msm_camera_device_platform_data msm_camera_device_data = { .camera_gpio_on = config_camera_on_gpios, .camera_gpio_off = config_camera_off_gpios, .ioext.mdcphy = MSM7XXX_MDC_PHYS, .ioext.mdcsz = MSM7XXX_MDC_SIZE, .ioext.appphy = MSM7XXX_CLK_CTL_PHYS, .ioext.appsz = MSM7XXX_CLK_CTL_SIZE, }; int pmic_set_flash_led_current(enum pmic8058_leds id, unsigned mA) { int rc; rc = pmic_flash_led_set_current(mA); return rc; } static struct msm_camera_sensor_flash_src msm_flash_src = { .flash_sr_type = MSM_CAMERA_FLASH_SRC_PMIC, ._fsrc.pmic_src.num_of_src = 1, ._fsrc.pmic_src.low_current = 30, ._fsrc.pmic_src.high_current = 100, ._fsrc.pmic_src.led_src_1 = 0, ._fsrc.pmic_src.led_src_2 = 0, ._fsrc.pmic_src.pmic_set_current = pmic_set_flash_led_current, }; #ifdef CONFIG_MT9D112 static struct msm_camera_sensor_flash_data flash_mt9d112 = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_mt9d112_data = { .sensor_name = "mt9d112", .sensor_reset = 89, .sensor_pwd = 85, .vcm_pwd = 0, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_mt9d112 }; static struct platform_device msm_camera_sensor_mt9d112 = { .name = "msm_camera_mt9d112", .dev = { .platform_data = &msm_camera_sensor_mt9d112_data, }, }; #endif #ifdef CONFIG_S5K3E2FX static struct msm_camera_sensor_flash_data flash_s5k3e2fx = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_s5k3e2fx_data = { .sensor_name = "s5k3e2fx", .sensor_reset = 89, .sensor_pwd = 85, .vcm_pwd = 0, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_s5k3e2fx }; static struct platform_device msm_camera_sensor_s5k3e2fx = { .name = "msm_camera_s5k3e2fx", .dev = { .platform_data = &msm_camera_sensor_s5k3e2fx_data, }, }; #endif #ifdef CONFIG_MT9P012 static struct msm_camera_sensor_flash_data flash_mt9p012 = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_mt9p012_data = { .sensor_name = "mt9p012", .sensor_reset = 89, .sensor_pwd = 85, .vcm_pwd = 88, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_mt9p012 }; static struct platform_device msm_camera_sensor_mt9p012 = { .name = "msm_camera_mt9p012", .dev = { .platform_data = &msm_camera_sensor_mt9p012_data, }, }; #endif #ifdef CONFIG_MT9P012_KM static struct msm_camera_sensor_flash_data flash_mt9p012_km = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_mt9p012_km_data = { .sensor_name = "mt9p012_km", .sensor_reset = 89, .sensor_pwd = 85, .vcm_pwd = 88, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_mt9p012_km }; static struct platform_device msm_camera_sensor_mt9p012_km = { .name = "msm_camera_mt9p012_km", .dev = { .platform_data = &msm_camera_sensor_mt9p012_km_data, }, }; #endif #ifdef CONFIG_MT9T013 static struct msm_camera_sensor_flash_data flash_mt9t013 = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_mt9t013_data = { .sensor_name = "mt9t013", .sensor_reset = 89, .sensor_pwd = 85, .vcm_pwd = 0, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_mt9t013 }; static struct platform_device msm_camera_sensor_mt9t013 = { .name = "msm_camera_mt9t013", .dev = { .platform_data = &msm_camera_sensor_mt9t013_data, }, }; #endif #ifdef CONFIG_VB6801 static struct msm_camera_sensor_flash_data flash_vb6801 = { .flash_type = MSM_CAMERA_FLASH_LED, .flash_src = &msm_flash_src }; static struct msm_camera_sensor_info msm_camera_sensor_vb6801_data = { .sensor_name = "vb6801", .sensor_reset = 89, .sensor_pwd = 88, .vcm_pwd = 0, .vcm_enable = 0, .pdata = &msm_camera_device_data, .flash_data = &flash_vb6801 }; static struct platform_device msm_camera_sensor_vb6801 = { .name = "msm_camera_vb6801", .dev = { .platform_data = &msm_camera_sensor_vb6801_data, }, }; #endif #endif static u32 msm_calculate_batt_capacity(u32 current_voltage); static struct msm_psy_batt_pdata msm_psy_batt_data = { .voltage_min_design = 2800, .voltage_max_design = 4300, .avail_chg_sources = AC_CHG | USB_CHG , .batt_technology = POWER_SUPPLY_TECHNOLOGY_LION, .calculate_capacity = &msm_calculate_batt_capacity, }; static u32 msm_calculate_batt_capacity(u32 current_voltage) { u32 low_voltage = msm_psy_batt_data.voltage_min_design; u32 high_voltage = msm_psy_batt_data.voltage_max_design; return (current_voltage - low_voltage) * 100 / (high_voltage - low_voltage); } static struct platform_device msm_batt_device = { .name = "msm-battery", .id = -1, .dev.platform_data = &msm_psy_batt_data, }; static struct platform_device *devices[] __initdata = { &asoc_msm_pcm, &asoc_msm_dai0, &asoc_msm_dai1, &msm_device_smd, &msm_device_dmov, &msm_device_nand, #ifdef CONFIG_USB_MSM_OTG_72K &msm_device_otg, #ifdef CONFIG_USB_GADGET &msm_device_gadget_peripheral, #endif #endif #ifdef CONFIG_USB_G_ANDROID &android_usb_device, #endif &msm_device_i2c, &smc91x_device, &msm_device_tssc, &android_pmem_device, &android_pmem_adsp_device, &android_pmem_audio_device, &msm_fb_device, &lcdc_gordon_panel_device, &msm_device_uart_dm1, #ifdef CONFIG_BT &msm_bt_power_device, #endif &msm_device_pmic_leds, &msm_device_snd, &msm_device_adspdec, #ifdef CONFIG_MT9T013 &msm_camera_sensor_mt9t013, #endif #ifdef CONFIG_MT9D112 &msm_camera_sensor_mt9d112, #endif #ifdef CONFIG_S5K3E2FX &msm_camera_sensor_s5k3e2fx, #endif #ifdef CONFIG_MT9P012 &msm_camera_sensor_mt9p012, #endif #ifdef CONFIG_MT9P012_KM &msm_camera_sensor_mt9p012_km, #endif #ifdef CONFIG_VB6801 &msm_camera_sensor_vb6801, #endif &msm_bluesleep_device, #ifdef CONFIG_ARCH_MSM7X27 &msm_kgsl_3d0, #endif #if defined(CONFIG_TSIF) || defined(CONFIG_TSIF_MODULE) &msm_device_tsif, #endif &hs_device, &msm_batt_device, }; static struct msm_panel_common_pdata mdp_pdata = { .gpio = 97, .mdp_rev = MDP_REV_30, }; static void __init msm_fb_add_devices(void) { msm_fb_register_device("mdp", &mdp_pdata); msm_fb_register_device("pmdh", 0); msm_fb_register_device("lcdc", &lcdc_pdata); } extern struct sys_timer msm_timer; static void __init msm7x2x_init_irq(void) { msm_init_irq(); } void msm_serial_debug_init(unsigned int base, int irq, struct device *clk_device, int signal_irq); #if (defined(CONFIG_MMC_MSM_SDC1_SUPPORT)\ || defined(CONFIG_MMC_MSM_SDC2_SUPPORT)\ || defined(CONFIG_MMC_MSM_SDC3_SUPPORT)\ || defined(CONFIG_MMC_MSM_SDC4_SUPPORT)) static unsigned long vreg_sts, gpio_sts; static struct regulator *vreg_mmc; static unsigned mpp_mmc = 2; struct sdcc_gpio { struct msm_gpio *cfg_data; uint32_t size; struct msm_gpio *sleep_cfg_data; }; static struct msm_gpio sdc1_cfg_data[] = { {GPIO_CFG(51, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc1_dat_3"}, {GPIO_CFG(52, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc1_dat_2"}, {GPIO_CFG(53, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc1_dat_1"}, {GPIO_CFG(54, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc1_dat_0"}, {GPIO_CFG(55, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc1_cmd"}, {GPIO_CFG(56, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA), "sdc1_clk"}, }; static struct msm_gpio sdc2_cfg_data[] = { {GPIO_CFG(62, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA), "sdc2_clk"}, {GPIO_CFG(63, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc2_cmd"}, {GPIO_CFG(64, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc2_dat_3"}, {GPIO_CFG(65, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc2_dat_2"}, {GPIO_CFG(66, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc2_dat_1"}, {GPIO_CFG(67, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc2_dat_0"}, }; static struct msm_gpio sdc2_sleep_cfg_data[] = { {GPIO_CFG(62, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_clk"}, {GPIO_CFG(63, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_cmd"}, {GPIO_CFG(64, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_dat_3"}, {GPIO_CFG(65, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_dat_2"}, {GPIO_CFG(66, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_dat_1"}, {GPIO_CFG(67, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), "sdc2_dat_0"}, }; static struct msm_gpio sdc3_cfg_data[] = { {GPIO_CFG(88, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA), "sdc3_clk"}, {GPIO_CFG(89, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc3_cmd"}, {GPIO_CFG(90, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc3_dat_3"}, {GPIO_CFG(91, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc3_dat_2"}, {GPIO_CFG(92, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc3_dat_1"}, {GPIO_CFG(93, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc3_dat_0"}, }; static struct msm_gpio sdc4_cfg_data[] = { {GPIO_CFG(19, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc4_dat_3"}, {GPIO_CFG(20, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc4_dat_2"}, {GPIO_CFG(21, 4, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc4_dat_1"}, {GPIO_CFG(107, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc4_cmd"}, {GPIO_CFG(108, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA), "sdc4_dat_0"}, {GPIO_CFG(109, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA), "sdc4_clk"}, }; static struct sdcc_gpio sdcc_cfg_data[] = { { .cfg_data = sdc1_cfg_data, .size = ARRAY_SIZE(sdc1_cfg_data), .sleep_cfg_data = NULL, }, { .cfg_data = sdc2_cfg_data, .size = ARRAY_SIZE(sdc2_cfg_data), .sleep_cfg_data = sdc2_sleep_cfg_data, }, { .cfg_data = sdc3_cfg_data, .size = ARRAY_SIZE(sdc3_cfg_data), .sleep_cfg_data = NULL, }, { .cfg_data = sdc4_cfg_data, .size = ARRAY_SIZE(sdc4_cfg_data), .sleep_cfg_data = NULL, }, }; static void msm_sdcc_setup_gpio(int dev_id, unsigned int enable) { int rc = 0; struct sdcc_gpio *curr; curr = &sdcc_cfg_data[dev_id - 1]; if (!(test_bit(dev_id, &gpio_sts)^enable)) return; if (enable) { set_bit(dev_id, &gpio_sts); rc = msm_gpios_request_enable(curr->cfg_data, curr->size); if (rc) printk(KERN_ERR "%s: Failed to turn on GPIOs for slot %d\n", __func__, dev_id); } else { clear_bit(dev_id, &gpio_sts); if (curr->sleep_cfg_data) { msm_gpios_enable(curr->sleep_cfg_data, curr->size); msm_gpios_free(curr->sleep_cfg_data, curr->size); return; } msm_gpios_disable_free(curr->cfg_data, curr->size); } } static uint32_t msm_sdcc_setup_power(struct device *dv, unsigned int vdd) { int rc = 0; struct platform_device *pdev; pdev = container_of(dv, struct platform_device, dev); msm_sdcc_setup_gpio(pdev->id, !!vdd); if (vdd == 0) { if (!vreg_sts) return 0; clear_bit(pdev->id, &vreg_sts); if (!vreg_sts) { if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) { rc = mpp_config_digital_out(mpp_mmc, MPP_CFG(MPP_DLOGIC_LVL_MSMP, MPP_DLOGIC_OUT_CTRL_LOW)); } else rc = regulator_disable(vreg_mmc); if (rc) { pr_err("%s: return val: %d\n", __func__, rc); } } return 0; } if (!vreg_sts) { if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) { rc = mpp_config_digital_out(mpp_mmc, MPP_CFG(MPP_DLOGIC_LVL_MSMP, MPP_DLOGIC_OUT_CTRL_HIGH)); } else { rc = regulator_set_voltage(vreg_mmc, 2850000, 2850000); if (!rc) rc = regulator_enable(vreg_mmc); } if (rc) { pr_err("%s: return val: %d\n", __func__, rc); } } set_bit(pdev->id, &vreg_sts); return 0; } #ifdef CONFIG_MMC_MSM_SDC1_SUPPORT static struct mmc_platform_data msm7x2x_sdc1_data = { .ocr_mask = MMC_VDD_28_29, .translate_vdd = msm_sdcc_setup_power, .mmc_bus_width = MMC_CAP_4_BIT_DATA, .msmsdcc_fmin = 144000, .msmsdcc_fmid = 24576000, .msmsdcc_fmax = 49152000, .nonremovable = 0, }; #endif #ifdef CONFIG_MMC_MSM_SDC2_SUPPORT static struct mmc_platform_data msm7x2x_sdc2_data = { .ocr_mask = MMC_VDD_28_29, .translate_vdd = msm_sdcc_setup_power, .mmc_bus_width = MMC_CAP_4_BIT_DATA, .sdiowakeup_irq = MSM_GPIO_TO_INT(66), .msmsdcc_fmin = 144000, .msmsdcc_fmid = 24576000, .msmsdcc_fmax = 49152000, .nonremovable = 0, }; #endif #ifdef CONFIG_MMC_MSM_SDC3_SUPPORT static struct mmc_platform_data msm7x2x_sdc3_data = { .ocr_mask = MMC_VDD_28_29, .translate_vdd = msm_sdcc_setup_power, .mmc_bus_width = MMC_CAP_4_BIT_DATA, .msmsdcc_fmin = 144000, .msmsdcc_fmid = 24576000, .msmsdcc_fmax = 49152000, .nonremovable = 0, }; #endif #ifdef CONFIG_MMC_MSM_SDC4_SUPPORT static struct mmc_platform_data msm7x2x_sdc4_data = { .ocr_mask = MMC_VDD_28_29, .translate_vdd = msm_sdcc_setup_power, .mmc_bus_width = MMC_CAP_4_BIT_DATA, .msmsdcc_fmin = 144000, .msmsdcc_fmid = 24576000, .msmsdcc_fmax = 49152000, .nonremovable = 0, }; #endif static void __init msm7x2x_init_mmc(void) { if (!machine_is_msm7x25_ffa() && !machine_is_msm7x27_ffa()) { vreg_mmc = regulator_get(NULL, "mmc"); if (IS_ERR(vreg_mmc)) { pr_err("%s: could not get regulator: %ld\n", __func__, PTR_ERR(vreg_mmc)); } } #ifdef CONFIG_MMC_MSM_SDC1_SUPPORT msm_add_sdcc(1, &msm7x2x_sdc1_data); #endif if (machine_is_msm7x25_surf() || machine_is_msm7x27_surf() || machine_is_msm7x27_ffa()) { #ifdef CONFIG_MMC_MSM_SDC2_SUPPORT msm_sdcc_setup_gpio(2, 1); msm_add_sdcc(2, &msm7x2x_sdc2_data); #endif } if (machine_is_msm7x25_surf() || machine_is_msm7x27_surf()) { #ifdef CONFIG_MMC_MSM_SDC3_SUPPORT msm_add_sdcc(3, &msm7x2x_sdc3_data); #endif #ifdef CONFIG_MMC_MSM_SDC4_SUPPORT msm_add_sdcc(4, &msm7x2x_sdc4_data); #endif } } #else #define msm7x2x_init_mmc() do {} while (0) #endif static struct msm_pm_platform_data msm7x25_pm_data[MSM_PM_SLEEP_MODE_NR] = { [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_POWER_COLLAPSE)].latency = 16000, [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN)] .latency = 12000, [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT)] .latency = 2000, }; static struct msm_pm_platform_data msm7x27_pm_data[MSM_PM_SLEEP_MODE_NR] = { [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_POWER_COLLAPSE)] = { .idle_supported = 1, .suspend_supported = 1, .idle_enabled = 1, .suspend_enabled = 1, .latency = 16000, .residency = 20000, }, [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN)] = { .idle_supported = 1, .suspend_supported = 1, .idle_enabled = 1, .suspend_enabled = 1, .latency = 12000, .residency = 20000, }, [MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT)] = { .idle_supported = 1, .suspend_supported = 1, .idle_enabled = 1, .suspend_enabled = 1, .latency = 2000, .residency = 0, }, }; static struct msm_pm_boot_platform_data msm_pm_boot_pdata __initdata = { .mode = MSM_PM_BOOT_CONFIG_RESET_VECTOR_PHYS, .p_addr = 0, }; static void msm_i2c_gpio_config(int iface, int config_type) { int gpio_scl; int gpio_sda; if (iface) { gpio_scl = 95; gpio_sda = 96; } else { gpio_scl = 60; gpio_sda = 61; } if (config_type) { gpio_tlmm_config(GPIO_CFG(gpio_scl, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_16MA), GPIO_CFG_ENABLE); gpio_tlmm_config(GPIO_CFG(gpio_sda, 1, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_16MA), GPIO_CFG_ENABLE); } else { gpio_tlmm_config(GPIO_CFG(gpio_scl, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_16MA), GPIO_CFG_ENABLE); gpio_tlmm_config(GPIO_CFG(gpio_sda, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_16MA), GPIO_CFG_ENABLE); } } static struct msm_i2c_platform_data msm_i2c_pdata = { .clk_freq = 100000, .rmutex = 0, .pri_clk = 60, .pri_dat = 61, .aux_clk = 95, .aux_dat = 96, .msm_i2c_config_gpio = msm_i2c_gpio_config, }; static struct platform_device msm_proccomm_regulator_dev = { .name = PROCCOMM_REGULATOR_DEV_NAME, .id = -1, .dev = { .platform_data = &msm7627_proccomm_regulator_data } }; static void __init msm7627_init_regulators(void) { int rc = platform_device_register(&msm_proccomm_regulator_dev); if (rc) pr_err("%s: could not register regulator device: %d\n", __func__, rc); } static void __init msm_device_i2c_init(void) { if (gpio_request(60, "i2c_pri_clk")) pr_err("failed to request gpio i2c_pri_clk\n"); if (gpio_request(61, "i2c_pri_dat")) pr_err("failed to request gpio i2c_pri_dat\n"); if (gpio_request(95, "i2c_sec_clk")) pr_err("failed to request gpio i2c_sec_clk\n"); if (gpio_request(96, "i2c_sec_dat")) pr_err("failed to request gpio i2c_sec_dat\n"); if (cpu_is_msm7x27()) msm_i2c_pdata.pm_lat = msm7x27_pm_data[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] .latency; else msm_i2c_pdata.pm_lat = msm7x25_pm_data[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] .latency; msm_device_i2c.dev.platform_data = &msm_i2c_pdata; } static void usb_mpp_init(void) { unsigned rc; unsigned mpp_usb = 7; if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) { rc = mpp_config_digital_out(mpp_usb, MPP_CFG(MPP_DLOGIC_LVL_VDD, MPP_DLOGIC_OUT_CTRL_HIGH)); if (rc) pr_err("%s: configuring mpp pin" "to enable 3.3V LDO failed\n", __func__); } } static void msm7x27_wlan_init(void) { int rc = 0; /* TBD: if (machine_is_msm7x27_ffa_with_wcn1312()) */ if (machine_is_msm7x27_ffa()) { rc = mpp_config_digital_out(3, MPP_CFG(MPP_DLOGIC_LVL_MSMP, MPP_DLOGIC_OUT_CTRL_LOW)); if (rc) printk(KERN_ERR "%s: return val: %d \n", __func__, rc); } } static void msm_adsp_add_pdev(void) { int rc = 0; struct rpc_board_dev *rpc_adsp_pdev; rpc_adsp_pdev = kzalloc(sizeof(struct rpc_board_dev), GFP_KERNEL); if (rpc_adsp_pdev == NULL) { pr_err("%s: Memory Allocation failure\n", __func__); return; } rpc_adsp_pdev->prog = ADSP_RPC_PROG; rpc_adsp_pdev->pdev = msm_adsp_device; rc = msm_rpc_add_board_dev(rpc_adsp_pdev, 1); if (rc < 0) { pr_err("%s: return val: %d\n", __func__, rc); kfree(rpc_adsp_pdev); } } static void __init msm7x2x_init(void) { msm7627_init_regulators(); #ifdef CONFIG_ARCH_MSM7X25 msm_clock_init(msm_clocks_7x25, msm_num_clocks_7x25); #elif defined(CONFIG_ARCH_MSM7X27) msm_clock_init(&msm7x27_clock_init_data); #endif #if defined(CONFIG_SMC91X) if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) { smc91x_resources[0].start = 0x98000300; smc91x_resources[0].end = 0x980003ff; smc91x_resources[1].start = MSM_GPIO_TO_INT(85); smc91x_resources[1].end = MSM_GPIO_TO_INT(85); if (gpio_tlmm_config(GPIO_CFG(85, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE)) { printk(KERN_ERR "%s: Err: Config GPIO-85 INT\n", __func__); } } #endif platform_device_register(&msm7x27_device_acpuclk); usb_mpp_init(); #ifdef CONFIG_USB_MSM_OTG_72K msm_device_otg.dev.platform_data = &msm_otg_pdata; if (machine_is_msm7x25_surf() || machine_is_msm7x25_ffa()) { msm_otg_pdata.pemp_level = PRE_EMPHASIS_WITH_20_PERCENT; msm_otg_pdata.drv_ampl = HS_DRV_AMPLITUDE_5_PERCENT; msm_otg_pdata.cdr_autoreset = CDR_AUTO_RESET_ENABLE; msm_otg_pdata.phy_reset = msm_otg_rpc_phy_reset; } if (machine_is_msm7x27_surf() || machine_is_msm7x27_ffa()) { msm_otg_pdata.pemp_level = PRE_EMPHASIS_WITH_10_PERCENT; msm_otg_pdata.drv_ampl = HS_DRV_AMPLITUDE_5_PERCENT; msm_otg_pdata.cdr_autoreset = CDR_AUTO_RESET_DISABLE; msm_otg_pdata.phy_reset_sig_inverted = 1; } #ifdef CONFIG_USB_GADGET msm_otg_pdata.swfi_latency = msm7x27_pm_data [MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT].latency; msm_device_gadget_peripheral.dev.platform_data = &msm_gadget_pdata; msm_gadget_pdata.is_phy_status_timer_on = 1; #endif #endif #if defined(CONFIG_TSIF) || defined(CONFIG_TSIF_MODULE) msm_device_tsif.dev.platform_data = &tsif_platform_data; #endif platform_add_devices(msm_footswitch_devices, msm_num_footswitch_devices); platform_add_devices(devices, ARRAY_SIZE(devices)); #ifdef CONFIG_MSM_CAMERA config_camera_off_gpios(); /* might not be necessary */ #endif msm_adsp_add_pdev(); msm_device_i2c_init(); i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices)); #ifdef CONFIG_SURF_FFA_GPIO_KEYPAD if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) platform_device_register(&keypad_device_7k_ffa); else platform_device_register(&keypad_device_surf); #endif lcdc_gordon_gpio_init(); msm_fb_add_devices(); #ifdef CONFIG_USB_EHCI_MSM_72K msm7x2x_init_host(); #endif msm7x2x_init_mmc(); bt_power_init(); if (cpu_is_msm7x27()) msm_pm_set_platform_data(msm7x27_pm_data, ARRAY_SIZE(msm7x27_pm_data)); else msm_pm_set_platform_data(msm7x25_pm_data, ARRAY_SIZE(msm7x25_pm_data)); BUG_ON(msm_pm_boot_init(&msm_pm_boot_pdata)); msm7x27_wlan_init(); } static unsigned pmem_kernel_ebi1_size = PMEM_KERNEL_EBI1_SIZE; static int __init pmem_kernel_ebi1_size_setup(char *p) { pmem_kernel_ebi1_size = memparse(p, NULL); return 0; } early_param("pmem_kernel_ebi1_size", pmem_kernel_ebi1_size_setup); static unsigned pmem_mdp_size = MSM_PMEM_MDP_SIZE; static int __init pmem_mdp_size_setup(char *p) { pmem_mdp_size = memparse(p, NULL); return 0; } early_param("pmem_mdp_size", pmem_mdp_size_setup); static unsigned pmem_adsp_size = MSM_PMEM_ADSP_SIZE; static int __init pmem_adsp_size_setup(char *p) { pmem_adsp_size = memparse(p, NULL); return 0; } early_param("pmem_adsp_size", pmem_adsp_size_setup); static unsigned pmem_audio_size = MSM_PMEM_AUDIO_SIZE; static int __init pmem_audio_size_setup(char *p) { pmem_audio_size = memparse(p, NULL); return 0; } early_param("pmem_audio_size", pmem_audio_size_setup); static unsigned fb_size = MSM_FB_SIZE; static int __init fb_size_setup(char *p) { fb_size = memparse(p, NULL); return 0; } early_param("fb_size", fb_size_setup); static void __init msm_msm7x2x_allocate_memory_regions(void) { void *addr; unsigned long size; size = fb_size ? : MSM_FB_SIZE; addr = alloc_bootmem_align(size, 0x1000); msm_fb_resources[0].start = __pa(addr); msm_fb_resources[0].end = msm_fb_resources[0].start + size - 1; pr_info("allocating %lu bytes at %p (%lx physical) for fb\n", size, addr, __pa(addr)); } static struct memtype_reserve msm7x27_reserve_table[] __initdata = { [MEMTYPE_SMI] = { }, [MEMTYPE_EBI0] = { .flags = MEMTYPE_FLAGS_1M_ALIGN, }, [MEMTYPE_EBI1] = { .flags = MEMTYPE_FLAGS_1M_ALIGN, }, }; static void __init size_pmem_devices(void) { #ifdef CONFIG_ANDROID_PMEM android_pmem_adsp_pdata.size = pmem_adsp_size; android_pmem_pdata.size = pmem_mdp_size; android_pmem_audio_pdata.size = pmem_audio_size; #endif } static void __init reserve_memory_for(struct android_pmem_platform_data *p) { msm7x27_reserve_table[p->memory_type].size += p->size; } static void __init reserve_pmem_memory(void) { #ifdef CONFIG_ANDROID_PMEM reserve_memory_for(&android_pmem_adsp_pdata); reserve_memory_for(&android_pmem_pdata); reserve_memory_for(&android_pmem_audio_pdata); msm7x27_reserve_table[MEMTYPE_EBI1].size += pmem_kernel_ebi1_size; #endif } static void __init msm7x27_calculate_reserve_sizes(void) { size_pmem_devices(); reserve_pmem_memory(); } static int msm7x27_paddr_to_memtype(unsigned int paddr) { return MEMTYPE_EBI1; } static struct reserve_info msm7x27_reserve_info __initdata = { .memtype_reserve_table = msm7x27_reserve_table, .calculate_reserve_sizes = msm7x27_calculate_reserve_sizes, .paddr_to_memtype = msm7x27_paddr_to_memtype, }; static void __init msm7x27_reserve(void) { reserve_info = &msm7x27_reserve_info; msm_reserve(); } static void __init msm7x27_init_early(void) { msm_msm7x2x_allocate_memory_regions(); } static void __init msm7x2x_map_io(void) { msm_map_common_io(); if (socinfo_init() < 0) BUG(); #ifdef CONFIG_CACHE_L2X0 if (machine_is_msm7x27_surf() || machine_is_msm7x27_ffa()) { /* 7x27 has 256KB L2 cache: 64Kb/Way and 4-Way Associativity; evmon/parity/share disabled. */ if ((SOCINFO_VERSION_MAJOR(socinfo_get_version()) > 1) || ((SOCINFO_VERSION_MAJOR(socinfo_get_version()) == 1) && (SOCINFO_VERSION_MINOR(socinfo_get_version()) >= 3))) /* R/W latency: 4 cycles; */ l2x0_init(MSM_L2CC_BASE, 0x0006801B, 0xfe000000); else /* R/W latency: 3 cycles; */ l2x0_init(MSM_L2CC_BASE, 0x00068012, 0xfe000000); } #endif } MACHINE_START(MSM7X27_SURF, "QCT MSM7x27 SURF") .atag_offset = 0x100, .map_io = msm7x2x_map_io, .reserve = msm7x27_reserve, .init_irq = msm7x2x_init_irq, .init_machine = msm7x2x_init, .timer = &msm_timer, .init_early = msm7x27_init_early, .handle_irq = vic_handle_irq, MACHINE_END MACHINE_START(MSM7X27_FFA, "QCT MSM7x27 FFA") .atag_offset = 0x100, .map_io = msm7x2x_map_io, .reserve = msm7x27_reserve, .init_irq = msm7x2x_init_irq, .init_machine = msm7x2x_init, .timer = &msm_timer, .init_early = msm7x27_init_early, .handle_irq = vic_handle_irq, MACHINE_END MACHINE_START(MSM7X25_SURF, "QCT MSM7x25 SURF") .atag_offset = 0x100, .map_io = msm7x2x_map_io, .reserve = msm7x27_reserve, .init_irq = msm7x2x_init_irq, .init_machine = msm7x2x_init, .timer = &msm_timer, .init_early = msm7x27_init_early, .handle_irq = vic_handle_irq, MACHINE_END MACHINE_START(MSM7X25_FFA, "QCT MSM7x25 FFA") .atag_offset = 0x100, .map_io = msm7x2x_map_io, .reserve = msm7x27_reserve, .init_irq = msm7x2x_init_irq, .init_machine = msm7x2x_init, .timer = &msm_timer, .init_early = msm7x27_init_early, .handle_irq = vic_handle_irq, MACHINE_END
gpl-2.0
iperminov/linux-tion270
arch/mips/txx9/rbtx4927/setup.c
4155
10460
/* * Toshiba rbtx4927 specific setup * * Author: MontaVista Software, Inc. * source@mvista.com * * Copyright 2001-2002 MontaVista Software Inc. * * Copyright (C) 1996, 97, 2001, 04 Ralf Baechle (ralf@linux-mips.org) * Copyright (C) 2000 RidgeRun, Inc. * Author: RidgeRun, Inc. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com * * Copyright 2001 MontaVista Software Inc. * Author: jsun@mvista.com or jsun@junsun.net * * Copyright 2002 MontaVista Software Inc. * Author: Michael Pruznick, michael_pruznick@mvista.com * * Copyright (C) 2000-2001 Toshiba Corporation * * Copyright (C) 2004 MontaVista Software Inc. * Author: Manish Lachwani, mlachwani@mvista.com * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/init.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/ioport.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/gpio.h> #include <linux/leds.h> #include <asm/io.h> #include <asm/reboot.h> #include <asm/txx9/generic.h> #include <asm/txx9/pci.h> #include <asm/txx9/rbtx4927.h> #include <asm/txx9/tx4938.h> /* for TX4937 */ #ifdef CONFIG_PCI static void __init tx4927_pci_setup(void) { int extarb = !(__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB); struct pci_controller *c = &txx9_primary_pcic; register_pci_controller(c); if (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66) txx9_pci_option = (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) | TXX9_PCI_OPT_CLK_66; /* already configured */ /* Reset PCI Bus */ writeb(1, rbtx4927_pcireset_addr); /* Reset PCIC */ txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST); if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) == TXX9_PCI_OPT_CLK_66) tx4927_pciclk66_setup(); mdelay(10); /* clear PCIC reset */ txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST); writeb(0, rbtx4927_pcireset_addr); iob(); tx4927_report_pciclk(); tx4927_pcic_setup(tx4927_pcicptr, c, extarb); if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) == TXX9_PCI_OPT_CLK_AUTO && txx9_pci66_check(c, 0, 0)) { /* Reset PCI Bus */ writeb(1, rbtx4927_pcireset_addr); /* Reset PCIC */ txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST); tx4927_pciclk66_setup(); mdelay(10); /* clear PCIC reset */ txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST); writeb(0, rbtx4927_pcireset_addr); iob(); /* Reinitialize PCIC */ tx4927_report_pciclk(); tx4927_pcic_setup(tx4927_pcicptr, c, extarb); } tx4927_setup_pcierr_irq(); } static void __init tx4937_pci_setup(void) { int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB); struct pci_controller *c = &txx9_primary_pcic; register_pci_controller(c); if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66) txx9_pci_option = (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) | TXX9_PCI_OPT_CLK_66; /* already configured */ /* Reset PCI Bus */ writeb(1, rbtx4927_pcireset_addr); /* Reset PCIC */ txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST); if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) == TXX9_PCI_OPT_CLK_66) tx4938_pciclk66_setup(); mdelay(10); /* clear PCIC reset */ txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST); writeb(0, rbtx4927_pcireset_addr); iob(); tx4938_report_pciclk(); tx4927_pcic_setup(tx4938_pcicptr, c, extarb); if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) == TXX9_PCI_OPT_CLK_AUTO && txx9_pci66_check(c, 0, 0)) { /* Reset PCI Bus */ writeb(1, rbtx4927_pcireset_addr); /* Reset PCIC */ txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST); tx4938_pciclk66_setup(); mdelay(10); /* clear PCIC reset */ txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST); writeb(0, rbtx4927_pcireset_addr); iob(); /* Reinitialize PCIC */ tx4938_report_pciclk(); tx4927_pcic_setup(tx4938_pcicptr, c, extarb); } tx4938_setup_pcierr_irq(); } static void __init rbtx4927_arch_init(void) { tx4927_pci_setup(); } static void __init rbtx4937_arch_init(void) { tx4937_pci_setup(); } #else #define rbtx4927_arch_init NULL #define rbtx4937_arch_init NULL #endif /* CONFIG_PCI */ static void toshiba_rbtx4927_restart(char *command) { /* enable the s/w reset register */ writeb(1, rbtx4927_softresetlock_addr); /* wait for enable to be seen */ while (!(readb(rbtx4927_softresetlock_addr) & 1)) ; /* do a s/w reset */ writeb(1, rbtx4927_softreset_addr); /* fallback */ (*_machine_halt)(); } static void __init rbtx4927_clock_init(void); static void __init rbtx4937_clock_init(void); static void __init rbtx4927_mem_setup(void) { if (TX4927_REV_PCODE() == 0x4927) { rbtx4927_clock_init(); tx4927_setup(); } else { rbtx4937_clock_init(); tx4938_setup(); } _machine_restart = toshiba_rbtx4927_restart; #ifdef CONFIG_PCI txx9_alloc_pci_controller(&txx9_primary_pcic, RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE, RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE); txx9_board_pcibios_setup = tx4927_pcibios_setup; #else set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET); #endif /* TX4927-SIO DTR on (PIO[15]) */ gpio_request(15, "sio-dtr"); gpio_direction_output(15, 1); tx4927_sio_init(0, 0); } static void __init rbtx4927_clock_init(void) { /* * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz. * * For TX4927: * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1). * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5) * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3) * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5) * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6) * i.e. S9[3]: ON (83MHz), OFF (100MHz) */ switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIDIVMODE_MASK) { case TX4927_CCFG_PCIDIVMODE_2_5: case TX4927_CCFG_PCIDIVMODE_5: txx9_cpu_clock = 166666666; /* 166MHz */ break; default: txx9_cpu_clock = 200000000; /* 200MHz */ } } static void __init rbtx4937_clock_init(void) { /* * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz. * * For TX4937: * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1) * PCIDIVMODE[10] is 0. * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8) * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4) * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9) * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5) * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10) * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5) */ switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIDIVMODE_MASK) { case TX4938_CCFG_PCIDIVMODE_8: case TX4938_CCFG_PCIDIVMODE_4: txx9_cpu_clock = 266666666; /* 266MHz */ break; case TX4938_CCFG_PCIDIVMODE_9: case TX4938_CCFG_PCIDIVMODE_4_5: txx9_cpu_clock = 300000000; /* 300MHz */ break; default: txx9_cpu_clock = 333333333; /* 333MHz */ } } static void __init rbtx4927_time_init(void) { tx4927_time_init(0); } static void __init toshiba_rbtx4927_rtc_init(void) { struct resource res = { .start = RBTX4927_BRAMRTC_BASE - IO_BASE, .end = RBTX4927_BRAMRTC_BASE - IO_BASE + 0x800 - 1, .flags = IORESOURCE_MEM, }; platform_device_register_simple("rtc-ds1742", -1, &res, 1); } static void __init rbtx4927_ne_init(void) { struct resource res[] = { { .start = RBTX4927_RTL_8019_BASE, .end = RBTX4927_RTL_8019_BASE + 0x20 - 1, .flags = IORESOURCE_IO, }, { .start = RBTX4927_RTL_8019_IRQ, .flags = IORESOURCE_IRQ, } }; platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res)); } static void __init rbtx4927_mtd_init(void) { int i; for (i = 0; i < 2; i++) tx4927_mtd_init(i); } static void __init rbtx4927_gpioled_init(void) { static struct gpio_led leds[] = { { .name = "gpioled:green:0", .gpio = 0, .active_low = 1, }, { .name = "gpioled:green:1", .gpio = 1, .active_low = 1, }, }; static struct gpio_led_platform_data pdata = { .num_leds = ARRAY_SIZE(leds), .leds = leds, }; struct platform_device *pdev = platform_device_alloc("leds-gpio", 0); if (!pdev) return; pdev->dev.platform_data = &pdata; if (platform_device_add(pdev)) platform_device_put(pdev); } static void __init rbtx4927_device_init(void) { toshiba_rbtx4927_rtc_init(); rbtx4927_ne_init(); tx4927_wdt_init(); rbtx4927_mtd_init(); if (TX4927_REV_PCODE() == 0x4927) { tx4927_dmac_init(2); tx4927_aclc_init(0, 1); } else { tx4938_dmac_init(0, 2); tx4938_aclc_init(); } platform_device_register_simple("txx9aclc-generic", -1, NULL, 0); txx9_iocled_init(RBTX4927_LED_ADDR - IO_BASE, -1, 3, 1, "green", NULL); rbtx4927_gpioled_init(); } struct txx9_board_vec rbtx4927_vec __initdata = { .system = "Toshiba RBTX4927", .prom_init = rbtx4927_prom_init, .mem_setup = rbtx4927_mem_setup, .irq_setup = rbtx4927_irq_setup, .time_init = rbtx4927_time_init, .device_init = rbtx4927_device_init, .arch_init = rbtx4927_arch_init, #ifdef CONFIG_PCI .pci_map_irq = rbtx4927_pci_map_irq, #endif }; struct txx9_board_vec rbtx4937_vec __initdata = { .system = "Toshiba RBTX4937", .prom_init = rbtx4927_prom_init, .mem_setup = rbtx4927_mem_setup, .irq_setup = rbtx4927_irq_setup, .time_init = rbtx4927_time_init, .device_init = rbtx4927_device_init, .arch_init = rbtx4937_arch_init, #ifdef CONFIG_PCI .pci_map_irq = rbtx4927_pci_map_irq, #endif };
gpl-2.0
ghbhaha/android_kernel_oneplus_msm8974
arch/powerpc/kvm/44x.c
4667
4207
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright IBM Corp. 2008 * * Authors: Hollis Blanchard <hollisb@us.ibm.com> */ #include <linux/kvm_host.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/export.h> #include <asm/reg.h> #include <asm/cputable.h> #include <asm/tlbflush.h> #include <asm/kvm_44x.h> #include <asm/kvm_ppc.h> #include "44x_tlb.h" void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { kvmppc_44x_tlb_load(vcpu); } void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) { kvmppc_44x_tlb_put(vcpu); } int kvmppc_core_check_processor_compat(void) { int r; if (strncmp(cur_cpu_spec->platform, "ppc440", 6) == 0) r = 0; else r = -ENOTSUPP; return r; } int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu) { struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); struct kvmppc_44x_tlbe *tlbe = &vcpu_44x->guest_tlb[0]; int i; tlbe->tid = 0; tlbe->word0 = PPC44x_TLB_16M | PPC44x_TLB_VALID; tlbe->word1 = 0; tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR; tlbe++; tlbe->tid = 0; tlbe->word0 = 0xef600000 | PPC44x_TLB_4K | PPC44x_TLB_VALID; tlbe->word1 = 0xef600000; tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_I | PPC44x_TLB_G; /* Since the guest can directly access the timebase, it must know the * real timebase frequency. Accordingly, it must see the state of * CCR1[TCS]. */ /* XXX CCR1 doesn't exist on all 440 SoCs. */ vcpu->arch.ccr1 = mfspr(SPRN_CCR1); for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_refs); i++) vcpu_44x->shadow_refs[i].gtlb_index = -1; vcpu->arch.cpu_type = KVM_CPU_440; return 0; } /* 'linear_address' is actually an encoding of AS|PID|EADDR . */ int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, struct kvm_translation *tr) { int index; gva_t eaddr; u8 pid; u8 as; eaddr = tr->linear_address; pid = (tr->linear_address >> 32) & 0xff; as = (tr->linear_address >> 40) & 0x1; index = kvmppc_44x_tlb_index(vcpu, eaddr, pid, as); if (index == -1) { tr->valid = 0; return 0; } tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr); /* XXX what does "writeable" and "usermode" even mean? */ tr->valid = 1; return 0; } void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) { kvmppc_get_sregs_ivor(vcpu, sregs); } int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) { return kvmppc_set_sregs_ivor(vcpu, sregs); } struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) { struct kvmppc_vcpu_44x *vcpu_44x; struct kvm_vcpu *vcpu; int err; vcpu_44x = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); if (!vcpu_44x) { err = -ENOMEM; goto out; } vcpu = &vcpu_44x->vcpu; err = kvm_vcpu_init(vcpu, kvm, id); if (err) goto free_vcpu; vcpu->arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO); if (!vcpu->arch.shared) goto uninit_vcpu; return vcpu; uninit_vcpu: kvm_vcpu_uninit(vcpu); free_vcpu: kmem_cache_free(kvm_vcpu_cache, vcpu_44x); out: return ERR_PTR(err); } void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) { struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); free_page((unsigned long)vcpu->arch.shared); kvm_vcpu_uninit(vcpu); kmem_cache_free(kvm_vcpu_cache, vcpu_44x); } static int __init kvmppc_44x_init(void) { int r; r = kvmppc_booke_init(); if (r) return r; return kvm_init(NULL, sizeof(struct kvmppc_vcpu_44x), 0, THIS_MODULE); } static void __exit kvmppc_44x_exit(void) { kvmppc_booke_exit(); } module_init(kvmppc_44x_init); module_exit(kvmppc_44x_exit);
gpl-2.0
VM12/android_kernel_oneplus_msm8974
drivers/tty/serial/pxa.c
4923
22192
/* * Based on drivers/serial/8250.c by Russell King. * * Author: Nicolas Pitre * Created: Feb 20, 2003 * Copyright: (C) 2003 Monta Vista Software, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Note 1: This driver is made separate from the already too overloaded * 8250.c because it needs some kirks of its own and that'll make it * easier to add DMA support. * * Note 2: I'm too sick of device allocation policies for serial ports. * If someone else wants to request an "official" allocation of major/minor * for this driver please be my guest. And don't forget that new hardware * to come from Intel might have more than 3 or 4 of those UARTs. Let's * hope for a better port registration and dynamic device allocation scheme * with the serial core maintainer satisfaction to appear soon. */ #if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) #define SUPPORT_SYSRQ #endif #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/console.h> #include <linux/sysrq.h> #include <linux/serial_reg.h> #include <linux/circ_buf.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/serial_core.h> #include <linux/clk.h> #include <linux/io.h> #include <linux/slab.h> #define PXA_NAME_LEN 8 struct uart_pxa_port { struct uart_port port; unsigned char ier; unsigned char lcr; unsigned char mcr; unsigned int lsr_break_flag; struct clk *clk; char name[PXA_NAME_LEN]; }; static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) { offset <<= 2; return readl(up->port.membase + offset); } static inline void serial_out(struct uart_pxa_port *up, int offset, int value) { offset <<= 2; writel(value, up->port.membase + offset); } static void serial_pxa_enable_ms(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; up->ier |= UART_IER_MSI; serial_out(up, UART_IER, up->ier); } static void serial_pxa_stop_tx(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; if (up->ier & UART_IER_THRI) { up->ier &= ~UART_IER_THRI; serial_out(up, UART_IER, up->ier); } } static void serial_pxa_stop_rx(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; up->ier &= ~UART_IER_RLSI; up->port.read_status_mask &= ~UART_LSR_DR; serial_out(up, UART_IER, up->ier); } static inline void receive_chars(struct uart_pxa_port *up, int *status) { struct tty_struct *tty = up->port.state->port.tty; unsigned int ch, flag; int max_count = 256; do { /* work around Errata #20 according to * Intel(R) PXA27x Processor Family * Specification Update (May 2005) * * Step 2 * Disable the Reciever Time Out Interrupt via IER[RTOEI] */ up->ier &= ~UART_IER_RTOIE; serial_out(up, UART_IER, up->ier); ch = serial_in(up, UART_RX); flag = TTY_NORMAL; up->port.icount.rx++; if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE | UART_LSR_FE | UART_LSR_OE))) { /* * For statistics only */ if (*status & UART_LSR_BI) { *status &= ~(UART_LSR_FE | UART_LSR_PE); up->port.icount.brk++; /* * We do the SysRQ and SAK checking * here because otherwise the break * may get masked by ignore_status_mask * or read_status_mask. */ if (uart_handle_break(&up->port)) goto ignore_char; } else if (*status & UART_LSR_PE) up->port.icount.parity++; else if (*status & UART_LSR_FE) up->port.icount.frame++; if (*status & UART_LSR_OE) up->port.icount.overrun++; /* * Mask off conditions which should be ignored. */ *status &= up->port.read_status_mask; #ifdef CONFIG_SERIAL_PXA_CONSOLE if (up->port.line == up->port.cons->index) { /* Recover the break flag from console xmit */ *status |= up->lsr_break_flag; up->lsr_break_flag = 0; } #endif if (*status & UART_LSR_BI) { flag = TTY_BREAK; } else if (*status & UART_LSR_PE) flag = TTY_PARITY; else if (*status & UART_LSR_FE) flag = TTY_FRAME; } if (uart_handle_sysrq_char(&up->port, ch)) goto ignore_char; uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); ignore_char: *status = serial_in(up, UART_LSR); } while ((*status & UART_LSR_DR) && (max_count-- > 0)); tty_flip_buffer_push(tty); /* work around Errata #20 according to * Intel(R) PXA27x Processor Family * Specification Update (May 2005) * * Step 6: * No more data in FIFO: Re-enable RTO interrupt via IER[RTOIE] */ up->ier |= UART_IER_RTOIE; serial_out(up, UART_IER, up->ier); } static void transmit_chars(struct uart_pxa_port *up) { struct circ_buf *xmit = &up->port.state->xmit; int count; if (up->port.x_char) { serial_out(up, UART_TX, up->port.x_char); up->port.icount.tx++; up->port.x_char = 0; return; } if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { serial_pxa_stop_tx(&up->port); return; } count = up->port.fifosize / 2; do { serial_out(up, UART_TX, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); up->port.icount.tx++; if (uart_circ_empty(xmit)) break; } while (--count > 0); if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(&up->port); if (uart_circ_empty(xmit)) serial_pxa_stop_tx(&up->port); } static void serial_pxa_start_tx(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; if (!(up->ier & UART_IER_THRI)) { up->ier |= UART_IER_THRI; serial_out(up, UART_IER, up->ier); } } static inline void check_modem_status(struct uart_pxa_port *up) { int status; status = serial_in(up, UART_MSR); if ((status & UART_MSR_ANY_DELTA) == 0) return; if (status & UART_MSR_TERI) up->port.icount.rng++; if (status & UART_MSR_DDSR) up->port.icount.dsr++; if (status & UART_MSR_DDCD) uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); if (status & UART_MSR_DCTS) uart_handle_cts_change(&up->port, status & UART_MSR_CTS); wake_up_interruptible(&up->port.state->port.delta_msr_wait); } /* * This handles the interrupt from one port. */ static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id) { struct uart_pxa_port *up = dev_id; unsigned int iir, lsr; iir = serial_in(up, UART_IIR); if (iir & UART_IIR_NO_INT) return IRQ_NONE; lsr = serial_in(up, UART_LSR); if (lsr & UART_LSR_DR) receive_chars(up, &lsr); check_modem_status(up); if (lsr & UART_LSR_THRE) transmit_chars(up); return IRQ_HANDLED; } static unsigned int serial_pxa_tx_empty(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned long flags; unsigned int ret; spin_lock_irqsave(&up->port.lock, flags); ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; spin_unlock_irqrestore(&up->port.lock, flags); return ret; } static unsigned int serial_pxa_get_mctrl(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned char status; unsigned int ret; status = serial_in(up, UART_MSR); ret = 0; if (status & UART_MSR_DCD) ret |= TIOCM_CAR; if (status & UART_MSR_RI) ret |= TIOCM_RNG; if (status & UART_MSR_DSR) ret |= TIOCM_DSR; if (status & UART_MSR_CTS) ret |= TIOCM_CTS; return ret; } static void serial_pxa_set_mctrl(struct uart_port *port, unsigned int mctrl) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned char mcr = 0; if (mctrl & TIOCM_RTS) mcr |= UART_MCR_RTS; if (mctrl & TIOCM_DTR) mcr |= UART_MCR_DTR; if (mctrl & TIOCM_OUT1) mcr |= UART_MCR_OUT1; if (mctrl & TIOCM_OUT2) mcr |= UART_MCR_OUT2; if (mctrl & TIOCM_LOOP) mcr |= UART_MCR_LOOP; mcr |= up->mcr; serial_out(up, UART_MCR, mcr); } static void serial_pxa_break_ctl(struct uart_port *port, int break_state) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned long flags; spin_lock_irqsave(&up->port.lock, flags); if (break_state == -1) up->lcr |= UART_LCR_SBC; else up->lcr &= ~UART_LCR_SBC; serial_out(up, UART_LCR, up->lcr); spin_unlock_irqrestore(&up->port.lock, flags); } #if 0 static void serial_pxa_dma_init(struct pxa_uart *up) { up->rxdma = pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_receive_dma, up); if (up->rxdma < 0) goto out; up->txdma = pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_transmit_dma, up); if (up->txdma < 0) goto err_txdma; up->dmadesc = kmalloc(4 * sizeof(pxa_dma_desc), GFP_KERNEL); if (!up->dmadesc) goto err_alloc; /* ... */ err_alloc: pxa_free_dma(up->txdma); err_rxdma: pxa_free_dma(up->rxdma); out: return; } #endif static int serial_pxa_startup(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned long flags; int retval; if (port->line == 3) /* HWUART */ up->mcr |= UART_MCR_AFE; else up->mcr = 0; up->port.uartclk = clk_get_rate(up->clk); /* * Allocate the IRQ */ retval = request_irq(up->port.irq, serial_pxa_irq, 0, up->name, up); if (retval) return retval; /* * Clear the FIFO buffers and disable them. * (they will be reenabled in set_termios()) */ serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); serial_out(up, UART_FCR, 0); /* * Clear the interrupt registers. */ (void) serial_in(up, UART_LSR); (void) serial_in(up, UART_RX); (void) serial_in(up, UART_IIR); (void) serial_in(up, UART_MSR); /* * Now, initialize the UART */ serial_out(up, UART_LCR, UART_LCR_WLEN8); spin_lock_irqsave(&up->port.lock, flags); up->port.mctrl |= TIOCM_OUT2; serial_pxa_set_mctrl(&up->port, up->port.mctrl); spin_unlock_irqrestore(&up->port.lock, flags); /* * Finally, enable interrupts. Note: Modem status interrupts * are set via set_termios(), which will be occurring imminently * anyway, so we don't enable them here. */ up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE; serial_out(up, UART_IER, up->ier); /* * And clear the interrupt registers again for luck. */ (void) serial_in(up, UART_LSR); (void) serial_in(up, UART_RX); (void) serial_in(up, UART_IIR); (void) serial_in(up, UART_MSR); return 0; } static void serial_pxa_shutdown(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned long flags; free_irq(up->port.irq, up); /* * Disable interrupts from this port */ up->ier = 0; serial_out(up, UART_IER, 0); spin_lock_irqsave(&up->port.lock, flags); up->port.mctrl &= ~TIOCM_OUT2; serial_pxa_set_mctrl(&up->port, up->port.mctrl); spin_unlock_irqrestore(&up->port.lock, flags); /* * Disable break condition and FIFOs */ serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); serial_out(up, UART_FCR, 0); } static void serial_pxa_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; unsigned char cval, fcr = 0; unsigned long flags; unsigned int baud, quot; unsigned int dll; switch (termios->c_cflag & CSIZE) { case CS5: cval = UART_LCR_WLEN5; break; case CS6: cval = UART_LCR_WLEN6; break; case CS7: cval = UART_LCR_WLEN7; break; default: case CS8: cval = UART_LCR_WLEN8; break; } if (termios->c_cflag & CSTOPB) cval |= UART_LCR_STOP; if (termios->c_cflag & PARENB) cval |= UART_LCR_PARITY; if (!(termios->c_cflag & PARODD)) cval |= UART_LCR_EPAR; /* * Ask the core to calculate the divisor for us. */ baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); quot = uart_get_divisor(port, baud); if ((up->port.uartclk / quot) < (2400 * 16)) fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1; else if ((up->port.uartclk / quot) < (230400 * 16)) fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8; else fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR32; /* * Ok, we're now changing the port state. Do it with * interrupts disabled. */ spin_lock_irqsave(&up->port.lock, flags); /* * Ensure the port will be enabled. * This is required especially for serial console. */ up->ier |= UART_IER_UUE; /* * Update the per-port timeout. */ uart_update_timeout(port, termios->c_cflag, baud); up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; if (termios->c_iflag & INPCK) up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; if (termios->c_iflag & (BRKINT | PARMRK)) up->port.read_status_mask |= UART_LSR_BI; /* * Characters to ignore */ up->port.ignore_status_mask = 0; if (termios->c_iflag & IGNPAR) up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; if (termios->c_iflag & IGNBRK) { up->port.ignore_status_mask |= UART_LSR_BI; /* * If we're ignoring parity and break indicators, * ignore overruns too (for real raw support). */ if (termios->c_iflag & IGNPAR) up->port.ignore_status_mask |= UART_LSR_OE; } /* * ignore all characters if CREAD is not set */ if ((termios->c_cflag & CREAD) == 0) up->port.ignore_status_mask |= UART_LSR_DR; /* * CTS flow control flag and modem status interrupts */ up->ier &= ~UART_IER_MSI; if (UART_ENABLE_MS(&up->port, termios->c_cflag)) up->ier |= UART_IER_MSI; serial_out(up, UART_IER, up->ier); if (termios->c_cflag & CRTSCTS) up->mcr |= UART_MCR_AFE; else up->mcr &= ~UART_MCR_AFE; serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */ serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */ /* * work around Errata #75 according to Intel(R) PXA27x Processor Family * Specification Update (Nov 2005) */ dll = serial_in(up, UART_DLL); WARN_ON(dll != (quot & 0xff)); serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */ serial_out(up, UART_LCR, cval); /* reset DLAB */ up->lcr = cval; /* Save LCR */ serial_pxa_set_mctrl(&up->port, up->port.mctrl); serial_out(up, UART_FCR, fcr); spin_unlock_irqrestore(&up->port.lock, flags); } static void serial_pxa_pm(struct uart_port *port, unsigned int state, unsigned int oldstate) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; if (!state) clk_prepare_enable(up->clk); else clk_disable_unprepare(up->clk); } static void serial_pxa_release_port(struct uart_port *port) { } static int serial_pxa_request_port(struct uart_port *port) { return 0; } static void serial_pxa_config_port(struct uart_port *port, int flags) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; up->port.type = PORT_PXA; } static int serial_pxa_verify_port(struct uart_port *port, struct serial_struct *ser) { /* we don't want the core code to modify any port params */ return -EINVAL; } static const char * serial_pxa_type(struct uart_port *port) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; return up->name; } static struct uart_pxa_port *serial_pxa_ports[4]; static struct uart_driver serial_pxa_reg; #ifdef CONFIG_SERIAL_PXA_CONSOLE #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) /* * Wait for transmitter & holding register to empty */ static inline void wait_for_xmitr(struct uart_pxa_port *up) { unsigned int status, tmout = 10000; /* Wait up to 10ms for the character(s) to be sent. */ do { status = serial_in(up, UART_LSR); if (status & UART_LSR_BI) up->lsr_break_flag = UART_LSR_BI; if (--tmout == 0) break; udelay(1); } while ((status & BOTH_EMPTY) != BOTH_EMPTY); /* Wait up to 1s for flow control if necessary */ if (up->port.flags & UPF_CONS_FLOW) { tmout = 1000000; while (--tmout && ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) udelay(1); } } static void serial_pxa_console_putchar(struct uart_port *port, int ch) { struct uart_pxa_port *up = (struct uart_pxa_port *)port; wait_for_xmitr(up); serial_out(up, UART_TX, ch); } /* * Print a string to the serial port trying not to disturb * any possible real use of the port... * * The console_lock must be held when we get here. */ static void serial_pxa_console_write(struct console *co, const char *s, unsigned int count) { struct uart_pxa_port *up = serial_pxa_ports[co->index]; unsigned int ier; clk_prepare_enable(up->clk); /* * First save the IER then disable the interrupts */ ier = serial_in(up, UART_IER); serial_out(up, UART_IER, UART_IER_UUE); uart_console_write(&up->port, s, count, serial_pxa_console_putchar); /* * Finally, wait for transmitter to become empty * and restore the IER */ wait_for_xmitr(up); serial_out(up, UART_IER, ier); clk_disable_unprepare(up->clk); } static int __init serial_pxa_console_setup(struct console *co, char *options) { struct uart_pxa_port *up; int baud = 9600; int bits = 8; int parity = 'n'; int flow = 'n'; if (co->index == -1 || co->index >= serial_pxa_reg.nr) co->index = 0; up = serial_pxa_ports[co->index]; if (!up) return -ENODEV; if (options) uart_parse_options(options, &baud, &parity, &bits, &flow); return uart_set_options(&up->port, co, baud, parity, bits, flow); } static struct console serial_pxa_console = { .name = "ttyS", .write = serial_pxa_console_write, .device = uart_console_device, .setup = serial_pxa_console_setup, .flags = CON_PRINTBUFFER, .index = -1, .data = &serial_pxa_reg, }; #define PXA_CONSOLE &serial_pxa_console #else #define PXA_CONSOLE NULL #endif struct uart_ops serial_pxa_pops = { .tx_empty = serial_pxa_tx_empty, .set_mctrl = serial_pxa_set_mctrl, .get_mctrl = serial_pxa_get_mctrl, .stop_tx = serial_pxa_stop_tx, .start_tx = serial_pxa_start_tx, .stop_rx = serial_pxa_stop_rx, .enable_ms = serial_pxa_enable_ms, .break_ctl = serial_pxa_break_ctl, .startup = serial_pxa_startup, .shutdown = serial_pxa_shutdown, .set_termios = serial_pxa_set_termios, .pm = serial_pxa_pm, .type = serial_pxa_type, .release_port = serial_pxa_release_port, .request_port = serial_pxa_request_port, .config_port = serial_pxa_config_port, .verify_port = serial_pxa_verify_port, }; static struct uart_driver serial_pxa_reg = { .owner = THIS_MODULE, .driver_name = "PXA serial", .dev_name = "ttyS", .major = TTY_MAJOR, .minor = 64, .nr = 4, .cons = PXA_CONSOLE, }; #ifdef CONFIG_PM static int serial_pxa_suspend(struct device *dev) { struct uart_pxa_port *sport = dev_get_drvdata(dev); if (sport) uart_suspend_port(&serial_pxa_reg, &sport->port); return 0; } static int serial_pxa_resume(struct device *dev) { struct uart_pxa_port *sport = dev_get_drvdata(dev); if (sport) uart_resume_port(&serial_pxa_reg, &sport->port); return 0; } static const struct dev_pm_ops serial_pxa_pm_ops = { .suspend = serial_pxa_suspend, .resume = serial_pxa_resume, }; #endif static struct of_device_id serial_pxa_dt_ids[] = { { .compatible = "mrvl,pxa-uart", }, { .compatible = "mrvl,mmp-uart", }, {} }; MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids); static int serial_pxa_probe_dt(struct platform_device *pdev, struct uart_pxa_port *sport) { struct device_node *np = pdev->dev.of_node; int ret; if (!np) return 1; ret = of_alias_get_id(np, "serial"); if (ret < 0) { dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); return ret; } sport->port.line = ret; return 0; } static int serial_pxa_probe(struct platform_device *dev) { struct uart_pxa_port *sport; struct resource *mmres, *irqres; int ret; mmres = platform_get_resource(dev, IORESOURCE_MEM, 0); irqres = platform_get_resource(dev, IORESOURCE_IRQ, 0); if (!mmres || !irqres) return -ENODEV; sport = kzalloc(sizeof(struct uart_pxa_port), GFP_KERNEL); if (!sport) return -ENOMEM; sport->clk = clk_get(&dev->dev, NULL); if (IS_ERR(sport->clk)) { ret = PTR_ERR(sport->clk); goto err_free; } sport->port.type = PORT_PXA; sport->port.iotype = UPIO_MEM; sport->port.mapbase = mmres->start; sport->port.irq = irqres->start; sport->port.fifosize = 64; sport->port.ops = &serial_pxa_pops; sport->port.dev = &dev->dev; sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; sport->port.uartclk = clk_get_rate(sport->clk); ret = serial_pxa_probe_dt(dev, sport); if (ret > 0) sport->port.line = dev->id; else if (ret < 0) goto err_clk; snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); sport->port.membase = ioremap(mmres->start, resource_size(mmres)); if (!sport->port.membase) { ret = -ENOMEM; goto err_clk; } serial_pxa_ports[sport->port.line] = sport; uart_add_one_port(&serial_pxa_reg, &sport->port); platform_set_drvdata(dev, sport); return 0; err_clk: clk_put(sport->clk); err_free: kfree(sport); return ret; } static int serial_pxa_remove(struct platform_device *dev) { struct uart_pxa_port *sport = platform_get_drvdata(dev); platform_set_drvdata(dev, NULL); uart_remove_one_port(&serial_pxa_reg, &sport->port); clk_put(sport->clk); kfree(sport); return 0; } static struct platform_driver serial_pxa_driver = { .probe = serial_pxa_probe, .remove = serial_pxa_remove, .driver = { .name = "pxa2xx-uart", .owner = THIS_MODULE, #ifdef CONFIG_PM .pm = &serial_pxa_pm_ops, #endif .of_match_table = serial_pxa_dt_ids, }, }; int __init serial_pxa_init(void) { int ret; ret = uart_register_driver(&serial_pxa_reg); if (ret != 0) return ret; ret = platform_driver_register(&serial_pxa_driver); if (ret != 0) uart_unregister_driver(&serial_pxa_reg); return ret; } void __exit serial_pxa_exit(void) { platform_driver_unregister(&serial_pxa_driver); uart_unregister_driver(&serial_pxa_reg); } module_init(serial_pxa_init); module_exit(serial_pxa_exit); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:pxa2xx-uart");
gpl-2.0
vm03/android_kernel_asus_P024
net/dccp/ccids/lib/tfrc_equation.c
4923
19085
/* * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. * Copyright (c) 2005 Ian McDonald <ian.mcdonald@jandi.co.nz> * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include <linux/module.h> #include "../../dccp.h" #include "tfrc.h" #define TFRC_CALC_X_ARRSIZE 500 #define TFRC_CALC_X_SPLIT 50000 /* 0.05 * 1000000, details below */ #define TFRC_SMALLEST_P (TFRC_CALC_X_SPLIT/TFRC_CALC_X_ARRSIZE) /* TFRC TCP Reno Throughput Equation Lookup Table for f(p) The following two-column lookup table implements a part of the TCP throughput equation from [RFC 3448, sec. 3.1]: s X_calc = -------------------------------------------------------------- R * sqrt(2*b*p/3) + (3 * t_RTO * sqrt(3*b*p/8) * (p + 32*p^3)) Where: X is the transmit rate in bytes/second s is the packet size in bytes R is the round trip time in seconds p is the loss event rate, between 0 and 1.0, of the number of loss events as a fraction of the number of packets transmitted t_RTO is the TCP retransmission timeout value in seconds b is the number of packets acknowledged by a single TCP ACK We can assume that b = 1 and t_RTO is 4 * R. The equation now becomes: s X_calc = ------------------------------------------------------- R * sqrt(p*2/3) + (12 * R * sqrt(p*3/8) * (p + 32*p^3)) which we can break down into: s X_calc = --------- R * f(p) where f(p) is given for 0 < p <= 1 by: f(p) = sqrt(2*p/3) + 12 * sqrt(3*p/8) * (p + 32*p^3) Since this is kernel code, floating-point arithmetic is avoided in favour of integer arithmetic. This means that nearly all fractional parameters are scaled by 1000000: * the parameters p and R * the return result f(p) The lookup table therefore actually tabulates the following function g(q): g(q) = 1000000 * f(q/1000000) Hence, when p <= 1, q must be less than or equal to 1000000. To achieve finer granularity for the practically more relevant case of small values of p (up to 5%), the second column is used; the first one ranges up to 100%. This split corresponds to the value of q = TFRC_CALC_X_SPLIT. At the same time this also determines the smallest resolution possible with this lookup table: TFRC_SMALLEST_P = TFRC_CALC_X_SPLIT / TFRC_CALC_X_ARRSIZE The entire table is generated by: for(i=0; i < TFRC_CALC_X_ARRSIZE; i++) { lookup[i][0] = g((i+1) * 1000000/TFRC_CALC_X_ARRSIZE); lookup[i][1] = g((i+1) * TFRC_CALC_X_SPLIT/TFRC_CALC_X_ARRSIZE); } With the given configuration, we have, with M = TFRC_CALC_X_ARRSIZE-1, lookup[0][0] = g(1000000/(M+1)) = 1000000 * f(0.2%) lookup[M][0] = g(1000000) = 1000000 * f(100%) lookup[0][1] = g(TFRC_SMALLEST_P) = 1000000 * f(0.01%) lookup[M][1] = g(TFRC_CALC_X_SPLIT) = 1000000 * f(5%) In summary, the two columns represent f(p) for the following ranges: * The first column is for 0.002 <= p <= 1.0 * The second column is for 0.0001 <= p <= 0.05 Where the columns overlap, the second (finer-grained) is given preference, i.e. the first column is used only for p >= 0.05. */ static const u32 tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE][2] = { { 37172, 8172 }, { 53499, 11567 }, { 66664, 14180 }, { 78298, 16388 }, { 89021, 18339 }, { 99147, 20108 }, { 108858, 21738 }, { 118273, 23260 }, { 127474, 24693 }, { 136520, 26052 }, { 145456, 27348 }, { 154316, 28589 }, { 163130, 29783 }, { 171919, 30935 }, { 180704, 32049 }, { 189502, 33130 }, { 198328, 34180 }, { 207194, 35202 }, { 216114, 36198 }, { 225097, 37172 }, { 234153, 38123 }, { 243294, 39055 }, { 252527, 39968 }, { 261861, 40864 }, { 271305, 41743 }, { 280866, 42607 }, { 290553, 43457 }, { 300372, 44293 }, { 310333, 45117 }, { 320441, 45929 }, { 330705, 46729 }, { 341131, 47518 }, { 351728, 48297 }, { 362501, 49066 }, { 373460, 49826 }, { 384609, 50577 }, { 395958, 51320 }, { 407513, 52054 }, { 419281, 52780 }, { 431270, 53499 }, { 443487, 54211 }, { 455940, 54916 }, { 468635, 55614 }, { 481581, 56306 }, { 494785, 56991 }, { 508254, 57671 }, { 521996, 58345 }, { 536019, 59014 }, { 550331, 59677 }, { 564939, 60335 }, { 579851, 60988 }, { 595075, 61636 }, { 610619, 62279 }, { 626491, 62918 }, { 642700, 63553 }, { 659253, 64183 }, { 676158, 64809 }, { 693424, 65431 }, { 711060, 66050 }, { 729073, 66664 }, { 747472, 67275 }, { 766266, 67882 }, { 785464, 68486 }, { 805073, 69087 }, { 825103, 69684 }, { 845562, 70278 }, { 866460, 70868 }, { 887805, 71456 }, { 909606, 72041 }, { 931873, 72623 }, { 954614, 73202 }, { 977839, 73778 }, { 1001557, 74352 }, { 1025777, 74923 }, { 1050508, 75492 }, { 1075761, 76058 }, { 1101544, 76621 }, { 1127867, 77183 }, { 1154739, 77741 }, { 1182172, 78298 }, { 1210173, 78852 }, { 1238753, 79405 }, { 1267922, 79955 }, { 1297689, 80503 }, { 1328066, 81049 }, { 1359060, 81593 }, { 1390684, 82135 }, { 1422947, 82675 }, { 1455859, 83213 }, { 1489430, 83750 }, { 1523671, 84284 }, { 1558593, 84817 }, { 1594205, 85348 }, { 1630518, 85878 }, { 1667543, 86406 }, { 1705290, 86932 }, { 1743770, 87457 }, { 1782994, 87980 }, { 1822973, 88501 }, { 1863717, 89021 }, { 1905237, 89540 }, { 1947545, 90057 }, { 1990650, 90573 }, { 2034566, 91087 }, { 2079301, 91600 }, { 2124869, 92111 }, { 2171279, 92622 }, { 2218543, 93131 }, { 2266673, 93639 }, { 2315680, 94145 }, { 2365575, 94650 }, { 2416371, 95154 }, { 2468077, 95657 }, { 2520707, 96159 }, { 2574271, 96660 }, { 2628782, 97159 }, { 2684250, 97658 }, { 2740689, 98155 }, { 2798110, 98651 }, { 2856524, 99147 }, { 2915944, 99641 }, { 2976382, 100134 }, { 3037850, 100626 }, { 3100360, 101117 }, { 3163924, 101608 }, { 3228554, 102097 }, { 3294263, 102586 }, { 3361063, 103073 }, { 3428966, 103560 }, { 3497984, 104045 }, { 3568131, 104530 }, { 3639419, 105014 }, { 3711860, 105498 }, { 3785467, 105980 }, { 3860253, 106462 }, { 3936229, 106942 }, { 4013410, 107422 }, { 4091808, 107902 }, { 4171435, 108380 }, { 4252306, 108858 }, { 4334431, 109335 }, { 4417825, 109811 }, { 4502501, 110287 }, { 4588472, 110762 }, { 4675750, 111236 }, { 4764349, 111709 }, { 4854283, 112182 }, { 4945564, 112654 }, { 5038206, 113126 }, { 5132223, 113597 }, { 5227627, 114067 }, { 5324432, 114537 }, { 5422652, 115006 }, { 5522299, 115474 }, { 5623389, 115942 }, { 5725934, 116409 }, { 5829948, 116876 }, { 5935446, 117342 }, { 6042439, 117808 }, { 6150943, 118273 }, { 6260972, 118738 }, { 6372538, 119202 }, { 6485657, 119665 }, { 6600342, 120128 }, { 6716607, 120591 }, { 6834467, 121053 }, { 6953935, 121514 }, { 7075025, 121976 }, { 7197752, 122436 }, { 7322131, 122896 }, { 7448175, 123356 }, { 7575898, 123815 }, { 7705316, 124274 }, { 7836442, 124733 }, { 7969291, 125191 }, { 8103877, 125648 }, { 8240216, 126105 }, { 8378321, 126562 }, { 8518208, 127018 }, { 8659890, 127474 }, { 8803384, 127930 }, { 8948702, 128385 }, { 9095861, 128840 }, { 9244875, 129294 }, { 9395760, 129748 }, { 9548529, 130202 }, { 9703198, 130655 }, { 9859782, 131108 }, { 10018296, 131561 }, { 10178755, 132014 }, { 10341174, 132466 }, { 10505569, 132917 }, { 10671954, 133369 }, { 10840345, 133820 }, { 11010757, 134271 }, { 11183206, 134721 }, { 11357706, 135171 }, { 11534274, 135621 }, { 11712924, 136071 }, { 11893673, 136520 }, { 12076536, 136969 }, { 12261527, 137418 }, { 12448664, 137867 }, { 12637961, 138315 }, { 12829435, 138763 }, { 13023101, 139211 }, { 13218974, 139658 }, { 13417071, 140106 }, { 13617407, 140553 }, { 13819999, 140999 }, { 14024862, 141446 }, { 14232012, 141892 }, { 14441465, 142339 }, { 14653238, 142785 }, { 14867346, 143230 }, { 15083805, 143676 }, { 15302632, 144121 }, { 15523842, 144566 }, { 15747453, 145011 }, { 15973479, 145456 }, { 16201939, 145900 }, { 16432847, 146345 }, { 16666221, 146789 }, { 16902076, 147233 }, { 17140429, 147677 }, { 17381297, 148121 }, { 17624696, 148564 }, { 17870643, 149007 }, { 18119154, 149451 }, { 18370247, 149894 }, { 18623936, 150336 }, { 18880241, 150779 }, { 19139176, 151222 }, { 19400759, 151664 }, { 19665007, 152107 }, { 19931936, 152549 }, { 20201564, 152991 }, { 20473907, 153433 }, { 20748982, 153875 }, { 21026807, 154316 }, { 21307399, 154758 }, { 21590773, 155199 }, { 21876949, 155641 }, { 22165941, 156082 }, { 22457769, 156523 }, { 22752449, 156964 }, { 23049999, 157405 }, { 23350435, 157846 }, { 23653774, 158287 }, { 23960036, 158727 }, { 24269236, 159168 }, { 24581392, 159608 }, { 24896521, 160049 }, { 25214642, 160489 }, { 25535772, 160929 }, { 25859927, 161370 }, { 26187127, 161810 }, { 26517388, 162250 }, { 26850728, 162690 }, { 27187165, 163130 }, { 27526716, 163569 }, { 27869400, 164009 }, { 28215234, 164449 }, { 28564236, 164889 }, { 28916423, 165328 }, { 29271815, 165768 }, { 29630428, 166208 }, { 29992281, 166647 }, { 30357392, 167087 }, { 30725779, 167526 }, { 31097459, 167965 }, { 31472452, 168405 }, { 31850774, 168844 }, { 32232445, 169283 }, { 32617482, 169723 }, { 33005904, 170162 }, { 33397730, 170601 }, { 33792976, 171041 }, { 34191663, 171480 }, { 34593807, 171919 }, { 34999428, 172358 }, { 35408544, 172797 }, { 35821174, 173237 }, { 36237335, 173676 }, { 36657047, 174115 }, { 37080329, 174554 }, { 37507197, 174993 }, { 37937673, 175433 }, { 38371773, 175872 }, { 38809517, 176311 }, { 39250924, 176750 }, { 39696012, 177190 }, { 40144800, 177629 }, { 40597308, 178068 }, { 41053553, 178507 }, { 41513554, 178947 }, { 41977332, 179386 }, { 42444904, 179825 }, { 42916290, 180265 }, { 43391509, 180704 }, { 43870579, 181144 }, { 44353520, 181583 }, { 44840352, 182023 }, { 45331092, 182462 }, { 45825761, 182902 }, { 46324378, 183342 }, { 46826961, 183781 }, { 47333531, 184221 }, { 47844106, 184661 }, { 48358706, 185101 }, { 48877350, 185541 }, { 49400058, 185981 }, { 49926849, 186421 }, { 50457743, 186861 }, { 50992759, 187301 }, { 51531916, 187741 }, { 52075235, 188181 }, { 52622735, 188622 }, { 53174435, 189062 }, { 53730355, 189502 }, { 54290515, 189943 }, { 54854935, 190383 }, { 55423634, 190824 }, { 55996633, 191265 }, { 56573950, 191706 }, { 57155606, 192146 }, { 57741621, 192587 }, { 58332014, 193028 }, { 58926806, 193470 }, { 59526017, 193911 }, { 60129666, 194352 }, { 60737774, 194793 }, { 61350361, 195235 }, { 61967446, 195677 }, { 62589050, 196118 }, { 63215194, 196560 }, { 63845897, 197002 }, { 64481179, 197444 }, { 65121061, 197886 }, { 65765563, 198328 }, { 66414705, 198770 }, { 67068508, 199213 }, { 67726992, 199655 }, { 68390177, 200098 }, { 69058085, 200540 }, { 69730735, 200983 }, { 70408147, 201426 }, { 71090343, 201869 }, { 71777343, 202312 }, { 72469168, 202755 }, { 73165837, 203199 }, { 73867373, 203642 }, { 74573795, 204086 }, { 75285124, 204529 }, { 76001380, 204973 }, { 76722586, 205417 }, { 77448761, 205861 }, { 78179926, 206306 }, { 78916102, 206750 }, { 79657310, 207194 }, { 80403571, 207639 }, { 81154906, 208084 }, { 81911335, 208529 }, { 82672880, 208974 }, { 83439562, 209419 }, { 84211402, 209864 }, { 84988421, 210309 }, { 85770640, 210755 }, { 86558080, 211201 }, { 87350762, 211647 }, { 88148708, 212093 }, { 88951938, 212539 }, { 89760475, 212985 }, { 90574339, 213432 }, { 91393551, 213878 }, { 92218133, 214325 }, { 93048107, 214772 }, { 93883493, 215219 }, { 94724314, 215666 }, { 95570590, 216114 }, { 96422343, 216561 }, { 97279594, 217009 }, { 98142366, 217457 }, { 99010679, 217905 }, { 99884556, 218353 }, { 100764018, 218801 }, { 101649086, 219250 }, { 102539782, 219698 }, { 103436128, 220147 }, { 104338146, 220596 }, { 105245857, 221046 }, { 106159284, 221495 }, { 107078448, 221945 }, { 108003370, 222394 }, { 108934074, 222844 }, { 109870580, 223294 }, { 110812910, 223745 }, { 111761087, 224195 }, { 112715133, 224646 }, { 113675069, 225097 }, { 114640918, 225548 }, { 115612702, 225999 }, { 116590442, 226450 }, { 117574162, 226902 }, { 118563882, 227353 }, { 119559626, 227805 }, { 120561415, 228258 }, { 121569272, 228710 }, { 122583219, 229162 }, { 123603278, 229615 }, { 124629471, 230068 }, { 125661822, 230521 }, { 126700352, 230974 }, { 127745083, 231428 }, { 128796039, 231882 }, { 129853241, 232336 }, { 130916713, 232790 }, { 131986475, 233244 }, { 133062553, 233699 }, { 134144966, 234153 }, { 135233739, 234608 }, { 136328894, 235064 }, { 137430453, 235519 }, { 138538440, 235975 }, { 139652876, 236430 }, { 140773786, 236886 }, { 141901190, 237343 }, { 143035113, 237799 }, { 144175576, 238256 }, { 145322604, 238713 }, { 146476218, 239170 }, { 147636442, 239627 }, { 148803298, 240085 }, { 149976809, 240542 }, { 151156999, 241000 }, { 152343890, 241459 }, { 153537506, 241917 }, { 154737869, 242376 }, { 155945002, 242835 }, { 157158929, 243294 }, { 158379673, 243753 }, { 159607257, 244213 }, { 160841704, 244673 }, { 162083037, 245133 }, { 163331279, 245593 }, { 164586455, 246054 }, { 165848586, 246514 }, { 167117696, 246975 }, { 168393810, 247437 }, { 169676949, 247898 }, { 170967138, 248360 }, { 172264399, 248822 }, { 173568757, 249284 }, { 174880235, 249747 }, { 176198856, 250209 }, { 177524643, 250672 }, { 178857621, 251136 }, { 180197813, 251599 }, { 181545242, 252063 }, { 182899933, 252527 }, { 184261908, 252991 }, { 185631191, 253456 }, { 187007807, 253920 }, { 188391778, 254385 }, { 189783129, 254851 }, { 191181884, 255316 }, { 192588065, 255782 }, { 194001698, 256248 }, { 195422805, 256714 }, { 196851411, 257181 }, { 198287540, 257648 }, { 199731215, 258115 }, { 201182461, 258582 }, { 202641302, 259050 }, { 204107760, 259518 }, { 205581862, 259986 }, { 207063630, 260454 }, { 208553088, 260923 }, { 210050262, 261392 }, { 211555174, 261861 }, { 213067849, 262331 }, { 214588312, 262800 }, { 216116586, 263270 }, { 217652696, 263741 }, { 219196666, 264211 }, { 220748520, 264682 }, { 222308282, 265153 }, { 223875978, 265625 }, { 225451630, 266097 }, { 227035265, 266569 }, { 228626905, 267041 }, { 230226576, 267514 }, { 231834302, 267986 }, { 233450107, 268460 }, { 235074016, 268933 }, { 236706054, 269407 }, { 238346244, 269881 }, { 239994613, 270355 }, { 241651183, 270830 }, { 243315981, 271305 } }; /* return largest index i such that fval <= lookup[i][small] */ static inline u32 tfrc_binsearch(u32 fval, u8 small) { u32 try, low = 0, high = TFRC_CALC_X_ARRSIZE - 1; while (low < high) { try = (low + high) / 2; if (fval <= tfrc_calc_x_lookup[try][small]) high = try; else low = try + 1; } return high; } /** * tfrc_calc_x - Calculate the send rate as per section 3.1 of RFC3448 * @s: packet size in bytes * @R: RTT scaled by 1000000 (i.e., microseconds) * @p: loss ratio estimate scaled by 1000000 * * Returns X_calc in bytes per second (not scaled). */ u32 tfrc_calc_x(u16 s, u32 R, u32 p) { u16 index; u32 f; u64 result; /* check against invalid parameters and divide-by-zero */ BUG_ON(p > 1000000); /* p must not exceed 100% */ BUG_ON(p == 0); /* f(0) = 0, divide by zero */ if (R == 0) { /* possible divide by zero */ DCCP_CRIT("WARNING: RTT is 0, returning maximum X_calc."); return ~0U; } if (p <= TFRC_CALC_X_SPLIT) { /* 0.0000 < p <= 0.05 */ if (p < TFRC_SMALLEST_P) { /* 0.0000 < p < 0.0001 */ DCCP_WARN("Value of p (%d) below resolution. " "Substituting %d\n", p, TFRC_SMALLEST_P); index = 0; } else /* 0.0001 <= p <= 0.05 */ index = p/TFRC_SMALLEST_P - 1; f = tfrc_calc_x_lookup[index][1]; } else { /* 0.05 < p <= 1.00 */ index = p/(1000000/TFRC_CALC_X_ARRSIZE) - 1; f = tfrc_calc_x_lookup[index][0]; } /* * Compute X = s/(R*f(p)) in bytes per second. * Since f(p) and R are both scaled by 1000000, we need to multiply by * 1000000^2. To avoid overflow, the result is computed in two stages. * This works under almost all reasonable operational conditions, for a * wide range of parameters. Yet, should some strange combination of * parameters result in overflow, the use of scaled_div32 will catch * this and return UINT_MAX - which is a logically adequate consequence. */ result = scaled_div(s, R); return scaled_div32(result, f); } /** * tfrc_calc_x_reverse_lookup - try to find p given f(p) * @fvalue: function value to match, scaled by 1000000 * * Returns closest match for p, also scaled by 1000000 */ u32 tfrc_calc_x_reverse_lookup(u32 fvalue) { int index; if (fvalue == 0) /* f(p) = 0 whenever p = 0 */ return 0; /* Error cases. */ if (fvalue < tfrc_calc_x_lookup[0][1]) { DCCP_WARN("fvalue %u smaller than resolution\n", fvalue); return TFRC_SMALLEST_P; } if (fvalue > tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE - 1][0]) { DCCP_WARN("fvalue %u exceeds bounds!\n", fvalue); return 1000000; } if (fvalue <= tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE - 1][1]) { index = tfrc_binsearch(fvalue, 1); return (index + 1) * TFRC_CALC_X_SPLIT / TFRC_CALC_X_ARRSIZE; } /* else ... it must be in the coarse-grained column */ index = tfrc_binsearch(fvalue, 0); return (index + 1) * 1000000 / TFRC_CALC_X_ARRSIZE; } /** * tfrc_invert_loss_event_rate - Compute p so that 10^6 corresponds to 100% * When @loss_event_rate is large, there is a chance that p is truncated to 0. * To avoid re-entering slow-start in that case, we set p = TFRC_SMALLEST_P > 0. */ u32 tfrc_invert_loss_event_rate(u32 loss_event_rate) { if (loss_event_rate == UINT_MAX) /* see RFC 4342, 8.5 */ return 0; if (unlikely(loss_event_rate == 0)) /* map 1/0 into 100% */ return 1000000; return max_t(u32, scaled_div(1, loss_event_rate), TFRC_SMALLEST_P); }
gpl-2.0
mifl/android_kernel_pantech_msm8974
drivers/media/video/tlg2300/pd-main.c
4923
12333
/* * device driver for Telegent tlg2300 based TV cards * * Author : * Kang Yong <kangyong@telegent.com> * Zhang Xiaobing <xbzhang@telegent.com> * Huang Shijie <zyziii@telegent.com> or <shijie8@gmail.com> * * (c) 2009 Telegent Systems * (c) 2010 Telegent Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/kref.h> #include <linux/suspend.h> #include <linux/usb/quirks.h> #include <linux/ctype.h> #include <linux/string.h> #include <linux/types.h> #include <linux/firmware.h> #include "vendorcmds.h" #include "pd-common.h" #define VENDOR_ID 0x1B24 #define PRODUCT_ID 0x4001 static struct usb_device_id id_table[] = { { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 0) }, { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 1) }, { }, }; MODULE_DEVICE_TABLE(usb, id_table); int debug_mode; module_param(debug_mode, int, 0644); MODULE_PARM_DESC(debug_mode, "0 = disable, 1 = enable, 2 = verbose"); static const char *firmware_name = "tlg2300_firmware.bin"; static struct usb_driver poseidon_driver; static LIST_HEAD(pd_device_list); /* * send set request to USB firmware. */ s32 send_set_req(struct poseidon *pd, u8 cmdid, s32 param, s32 *cmd_status) { s32 ret; s8 data[32] = {}; u16 lower_16, upper_16; if (pd->state & POSEIDON_STATE_DISCONNECT) return -ENODEV; mdelay(30); if (param == 0) { upper_16 = lower_16 = 0; } else { /* send 32 bit param as two 16 bit param,little endian */ lower_16 = (unsigned short)(param & 0xffff); upper_16 = (unsigned short)((param >> 16) & 0xffff); } ret = usb_control_msg(pd->udev, usb_rcvctrlpipe(pd->udev, 0), REQ_SET_CMD | cmdid, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, lower_16, upper_16, &data, sizeof(*cmd_status), USB_CTRL_GET_TIMEOUT); if (!ret) { return -ENXIO; } else { /* 1st 4 bytes into cmd_status */ memcpy((char *)cmd_status, &(data[0]), sizeof(*cmd_status)); } return 0; } /* * send get request to Poseidon firmware. */ s32 send_get_req(struct poseidon *pd, u8 cmdid, s32 param, void *buf, s32 *cmd_status, s32 datalen) { s32 ret; s8 data[128] = {}; u16 lower_16, upper_16; if (pd->state & POSEIDON_STATE_DISCONNECT) return -ENODEV; mdelay(30); if (param == 0) { upper_16 = lower_16 = 0; } else { /*send 32 bit param as two 16 bit param, little endian */ lower_16 = (unsigned short)(param & 0xffff); upper_16 = (unsigned short)((param >> 16) & 0xffff); } ret = usb_control_msg(pd->udev, usb_rcvctrlpipe(pd->udev, 0), REQ_GET_CMD | cmdid, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, lower_16, upper_16, &data, (datalen + sizeof(*cmd_status)), USB_CTRL_GET_TIMEOUT); if (ret < 0) { return -ENXIO; } else { /* 1st 4 bytes into cmd_status, remaining data into cmd_data */ memcpy((char *)cmd_status, &data[0], sizeof(*cmd_status)); memcpy((char *)buf, &data[sizeof(*cmd_status)], datalen); } return 0; } static int pm_notifier_block(struct notifier_block *nb, unsigned long event, void *dummy) { struct poseidon *pd = NULL; struct list_head *node, *next; switch (event) { case PM_POST_HIBERNATION: list_for_each_safe(node, next, &pd_device_list) { struct usb_device *udev; struct usb_interface *iface; int rc = 0; pd = container_of(node, struct poseidon, device_list); udev = pd->udev; iface = pd->interface; /* It will cause the system to reload the firmware */ rc = usb_lock_device_for_reset(udev, iface); if (rc >= 0) { usb_reset_device(udev); usb_unlock_device(udev); } } break; default: break; } log("event :%ld\n", event); return 0; } static struct notifier_block pm_notifer = { .notifier_call = pm_notifier_block, }; int set_tuner_mode(struct poseidon *pd, unsigned char mode) { s32 ret, cmd_status; if (pd->state & POSEIDON_STATE_DISCONNECT) return -ENODEV; ret = send_set_req(pd, TUNE_MODE_SELECT, mode, &cmd_status); if (ret || cmd_status) return -ENXIO; return 0; } void poseidon_delete(struct kref *kref) { struct poseidon *pd = container_of(kref, struct poseidon, kref); if (!pd) return; list_del_init(&pd->device_list); pd_dvb_usb_device_cleanup(pd); /* clean_audio_data(&pd->audio_data);*/ if (pd->udev) { usb_put_dev(pd->udev); pd->udev = NULL; } if (pd->interface) { usb_put_intf(pd->interface); pd->interface = NULL; } kfree(pd); log(); } static int firmware_download(struct usb_device *udev) { int ret = 0, actual_length; const struct firmware *fw = NULL; void *fwbuf = NULL; size_t fwlength = 0, offset; size_t max_packet_size; ret = request_firmware(&fw, firmware_name, &udev->dev); if (ret) { log("download err : %d", ret); return ret; } fwlength = fw->size; fwbuf = kmemdup(fw->data, fwlength, GFP_KERNEL); if (!fwbuf) { ret = -ENOMEM; goto out; } max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize; log("\t\t download size : %d", (int)max_packet_size); for (offset = 0; offset < fwlength; offset += max_packet_size) { actual_length = 0; ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01), /* ep 1 */ fwbuf + offset, min(max_packet_size, fwlength - offset), &actual_length, HZ * 10); if (ret) break; } kfree(fwbuf); out: release_firmware(fw); return ret; } static inline struct poseidon *get_pd(struct usb_interface *intf) { return usb_get_intfdata(intf); } #ifdef CONFIG_PM /* one-to-one map : poseidon{} <----> usb_device{}'s port */ static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev) { pd->portnum = udev->portnum; } static inline int get_autopm_ref(struct poseidon *pd) { return pd->video_data.users + pd->vbi_data.users + pd->audio.users + atomic_read(&pd->dvb_data.users) + pd->radio_data.users; } /* fixup something for poseidon */ static inline struct poseidon *fixup(struct poseidon *pd) { int count; /* old udev and interface have gone, so put back reference . */ count = get_autopm_ref(pd); log("count : %d, ref count : %d", count, get_pm_count(pd)); while (count--) usb_autopm_put_interface(pd->interface); /*usb_autopm_set_interface(pd->interface); */ usb_put_dev(pd->udev); usb_put_intf(pd->interface); log("event : %d\n", pd->msg.event); return pd; } static struct poseidon *find_old_poseidon(struct usb_device *udev) { struct poseidon *pd; list_for_each_entry(pd, &pd_device_list, device_list) { if (pd->portnum == udev->portnum && in_hibernation(pd)) return fixup(pd); } return NULL; } /* Is the card working now ? */ static inline int is_working(struct poseidon *pd) { return get_pm_count(pd) > 0; } static int poseidon_suspend(struct usb_interface *intf, pm_message_t msg) { struct poseidon *pd = get_pd(intf); if (!pd) return 0; if (!is_working(pd)) { if (get_pm_count(pd) <= 0 && !in_hibernation(pd)) { pd->msg.event = PM_EVENT_AUTO_SUSPEND; pd->pm_resume = NULL; /* a good guard */ printk(KERN_DEBUG "\n\t+ TLG2300 auto suspend +\n\n"); } return 0; } pd->msg = msg; /* save it here */ logpm(pd); return pd->pm_suspend ? pd->pm_suspend(pd) : 0; } static int poseidon_resume(struct usb_interface *intf) { struct poseidon *pd = get_pd(intf); if (!pd) return 0; printk(KERN_DEBUG "\n\t ++ TLG2300 resume ++\n\n"); if (!is_working(pd)) { if (PM_EVENT_AUTO_SUSPEND == pd->msg.event) pd->msg = PMSG_ON; return 0; } if (in_hibernation(pd)) { logpm(pd); return 0; } logpm(pd); return pd->pm_resume ? pd->pm_resume(pd) : 0; } static void hibernation_resume(struct work_struct *w) { struct poseidon *pd = container_of(w, struct poseidon, pm_work); int count; pd->msg.event = 0; /* clear it here */ pd->state &= ~POSEIDON_STATE_DISCONNECT; /* set the new interface's reference */ count = get_autopm_ref(pd); while (count--) usb_autopm_get_interface(pd->interface); /* resume the context */ logpm(pd); if (pd->pm_resume) pd->pm_resume(pd); } #else /* CONFIG_PM is not enabled: */ static inline struct poseidon *find_old_poseidon(struct usb_device *udev) { return NULL; } static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev) { } #endif static int check_firmware(struct usb_device *udev, int *down_firmware) { void *buf; int ret; struct cmd_firmware_vers_s *cmd_firm; buf = kzalloc(sizeof(*cmd_firm) + sizeof(u32), GFP_KERNEL); if (!buf) return -ENOMEM; ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), REQ_GET_CMD | GET_FW_ID, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, buf, sizeof(*cmd_firm) + sizeof(u32), USB_CTRL_GET_TIMEOUT); kfree(buf); if (ret < 0) { *down_firmware = 1; return firmware_download(udev); } return 0; } static int poseidon_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct poseidon *pd = NULL; int ret = 0; int new_one = 0; /* download firmware */ check_firmware(udev, &ret); if (ret) return 0; /* Do I recovery from the hibernate ? */ pd = find_old_poseidon(udev); if (!pd) { pd = kzalloc(sizeof(*pd), GFP_KERNEL); if (!pd) return -ENOMEM; kref_init(&pd->kref); set_map_flags(pd, udev); new_one = 1; } pd->udev = usb_get_dev(udev); pd->interface = usb_get_intf(interface); usb_set_intfdata(interface, pd); if (new_one) { struct device *dev = &interface->dev; logpm(pd); mutex_init(&pd->lock); /* register v4l2 device */ snprintf(pd->v4l2_dev.name, sizeof(pd->v4l2_dev.name), "%s %s", dev->driver->name, dev_name(dev)); ret = v4l2_device_register(NULL, &pd->v4l2_dev); /* register devices in directory /dev */ ret = pd_video_init(pd); poseidon_audio_init(pd); poseidon_fm_init(pd); pd_dvb_usb_device_init(pd); INIT_LIST_HEAD(&pd->device_list); list_add_tail(&pd->device_list, &pd_device_list); } device_init_wakeup(&udev->dev, 1); #ifdef CONFIG_PM pm_runtime_set_autosuspend_delay(&pd->udev->dev, 1000 * PM_SUSPEND_DELAY); usb_enable_autosuspend(pd->udev); if (in_hibernation(pd)) { INIT_WORK(&pd->pm_work, hibernation_resume); schedule_work(&pd->pm_work); } #endif return 0; } static void poseidon_disconnect(struct usb_interface *interface) { struct poseidon *pd = get_pd(interface); if (!pd) return; logpm(pd); if (in_hibernation(pd)) return; mutex_lock(&pd->lock); pd->state |= POSEIDON_STATE_DISCONNECT; mutex_unlock(&pd->lock); /* stop urb transferring */ stop_all_video_stream(pd); dvb_stop_streaming(&pd->dvb_data); /*unregister v4l2 device */ v4l2_device_unregister(&pd->v4l2_dev); pd_dvb_usb_device_exit(pd); poseidon_fm_exit(pd); poseidon_audio_free(pd); pd_video_exit(pd); usb_set_intfdata(interface, NULL); kref_put(&pd->kref, poseidon_delete); } static struct usb_driver poseidon_driver = { .name = "poseidon", .probe = poseidon_probe, .disconnect = poseidon_disconnect, .id_table = id_table, #ifdef CONFIG_PM .suspend = poseidon_suspend, .resume = poseidon_resume, #endif .supports_autosuspend = 1, }; static int __init poseidon_init(void) { int ret; ret = usb_register(&poseidon_driver); if (ret) return ret; register_pm_notifier(&pm_notifer); return ret; } static void __exit poseidon_exit(void) { log(); unregister_pm_notifier(&pm_notifer); usb_deregister(&poseidon_driver); } module_init(poseidon_init); module_exit(poseidon_exit); MODULE_AUTHOR("Telegent Systems"); MODULE_DESCRIPTION("For tlg2300-based USB device "); MODULE_LICENSE("GPL"); MODULE_VERSION("0.0.2");
gpl-2.0
mpokwsths/Z3_kernel
drivers/media/video/cx88/cx88-i2c.c
5179
5046
/* cx88-i2c.c -- all the i2c code is here Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de) & Marcus Metzler (mocm@thp.uni-koeln.de) (c) 2002 Yurij Sysoev <yurij@naturesoft.net> (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org> (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org> - Multituner support and i2c address binding This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/module.h> #include <linux/init.h> #include <asm/io.h> #include "cx88.h" #include <media/v4l2-common.h> static unsigned int i2c_debug; module_param(i2c_debug, int, 0644); MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]"); static unsigned int i2c_scan; module_param(i2c_scan, int, 0444); MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); static unsigned int i2c_udelay = 5; module_param(i2c_udelay, int, 0644); MODULE_PARM_DESC(i2c_udelay,"i2c delay at insmod time, in usecs " "(should be 5 or higher). Lower value means higher bus speed."); #define dprintk(level,fmt, arg...) if (i2c_debug >= level) \ printk(KERN_DEBUG "%s: " fmt, core->name , ## arg) /* ----------------------------------------------------------------------- */ static void cx8800_bit_setscl(void *data, int state) { struct cx88_core *core = data; if (state) core->i2c_state |= 0x02; else core->i2c_state &= ~0x02; cx_write(MO_I2C, core->i2c_state); cx_read(MO_I2C); } static void cx8800_bit_setsda(void *data, int state) { struct cx88_core *core = data; if (state) core->i2c_state |= 0x01; else core->i2c_state &= ~0x01; cx_write(MO_I2C, core->i2c_state); cx_read(MO_I2C); } static int cx8800_bit_getscl(void *data) { struct cx88_core *core = data; u32 state; state = cx_read(MO_I2C); return state & 0x02 ? 1 : 0; } static int cx8800_bit_getsda(void *data) { struct cx88_core *core = data; u32 state; state = cx_read(MO_I2C); return state & 0x01; } /* ----------------------------------------------------------------------- */ static const struct i2c_algo_bit_data cx8800_i2c_algo_template = { .setsda = cx8800_bit_setsda, .setscl = cx8800_bit_setscl, .getsda = cx8800_bit_getsda, .getscl = cx8800_bit_getscl, .udelay = 16, .timeout = 200, }; /* ----------------------------------------------------------------------- */ static const char * const i2c_devs[128] = { [ 0x1c >> 1 ] = "lgdt330x", [ 0x86 >> 1 ] = "tda9887/cx22702", [ 0xa0 >> 1 ] = "eeprom", [ 0xc0 >> 1 ] = "tuner (analog)", [ 0xc2 >> 1 ] = "tuner (analog/dvb)", [ 0xc8 >> 1 ] = "xc5000", }; static void do_i2c_scan(const char *name, struct i2c_client *c) { unsigned char buf; int i,rc; for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) { c->addr = i; rc = i2c_master_recv(c,&buf,0); if (rc < 0) continue; printk("%s: i2c scan: found device @ 0x%x [%s]\n", name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); } } /* init + register i2c adapter */ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci) { /* Prevents usage of invalid delay values */ if (i2c_udelay<5) i2c_udelay=5; memcpy(&core->i2c_algo, &cx8800_i2c_algo_template, sizeof(core->i2c_algo)); core->i2c_adap.dev.parent = &pci->dev; strlcpy(core->i2c_adap.name,core->name,sizeof(core->i2c_adap.name)); core->i2c_adap.owner = THIS_MODULE; core->i2c_algo.udelay = i2c_udelay; core->i2c_algo.data = core; i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev); core->i2c_adap.algo_data = &core->i2c_algo; core->i2c_client.adapter = &core->i2c_adap; strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE); cx8800_bit_setscl(core,1); cx8800_bit_setsda(core,1); core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap); if (0 == core->i2c_rc) { static u8 tuner_data[] = { 0x0b, 0xdc, 0x86, 0x52 }; static struct i2c_msg tuner_msg = { .flags = 0, .addr = 0xc2 >> 1, .buf = tuner_data, .len = 4 }; dprintk(1, "i2c register ok\n"); switch( core->boardnr ) { case CX88_BOARD_HAUPPAUGE_HVR1300: case CX88_BOARD_HAUPPAUGE_HVR3000: case CX88_BOARD_HAUPPAUGE_HVR4000: printk("%s: i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n", core->name); i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1); break; default: break; } if (i2c_scan) do_i2c_scan(core->name,&core->i2c_client); } else printk("%s: i2c register FAILED\n", core->name); return core->i2c_rc; }
gpl-2.0
NoelMacwan/kernel_sony_msm8x27
drivers/xen/xen-balloon.c
7227
6872
/****************************************************************************** * Xen balloon driver - enables returning/claiming memory to/from Xen. * * Copyright (c) 2003, B Dragovic * Copyright (c) 2003-2004, M Williamson, K Fraser * Copyright (c) 2005 Dan M. Smith, IBM Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation; or, when distributed * separately from the Linux kernel or incorporated into other * software packages, subject to the following license: * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this source file (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/capability.h> #include <xen/xen.h> #include <xen/interface/xen.h> #include <xen/balloon.h> #include <xen/xenbus.h> #include <xen/features.h> #include <xen/page.h> #define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10)) #define BALLOON_CLASS_NAME "xen_memory" static struct device balloon_dev; static int register_balloon(struct device *dev); /* React to a change in the target key */ static void watch_target(struct xenbus_watch *watch, const char **vec, unsigned int len) { unsigned long long new_target; int err; err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target); if (err != 1) { /* This is ok (for domain0 at least) - so just return */ return; } /* The given memory/target value is in KiB, so it needs converting to * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10. */ balloon_set_new_target(new_target >> (PAGE_SHIFT - 10)); } static struct xenbus_watch target_watch = { .node = "memory/target", .callback = watch_target, }; static int balloon_init_watcher(struct notifier_block *notifier, unsigned long event, void *data) { int err; err = register_xenbus_watch(&target_watch); if (err) printk(KERN_ERR "Failed to set balloon watcher\n"); return NOTIFY_DONE; } static struct notifier_block xenstore_notifier = { .notifier_call = balloon_init_watcher, }; static int __init balloon_init(void) { if (!xen_domain()) return -ENODEV; pr_info("xen-balloon: Initialising balloon driver.\n"); register_balloon(&balloon_dev); register_xen_selfballooning(&balloon_dev); register_xenstore_notifier(&xenstore_notifier); return 0; } subsys_initcall(balloon_init); static void balloon_exit(void) { /* XXX - release balloon here */ return; } module_exit(balloon_exit); #define BALLOON_SHOW(name, format, args...) \ static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ return sprintf(buf, format, ##args); \ } \ static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(balloon_stats.current_pages)); BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_low)); BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_high)); static DEVICE_ULONG_ATTR(schedule_delay, 0444, balloon_stats.schedule_delay); static DEVICE_ULONG_ATTR(max_schedule_delay, 0644, balloon_stats.max_schedule_delay); static DEVICE_ULONG_ATTR(retry_count, 0444, balloon_stats.retry_count); static DEVICE_ULONG_ATTR(max_retry_count, 0644, balloon_stats.max_retry_count); static ssize_t show_target_kb(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%lu\n", PAGES2KB(balloon_stats.target_pages)); } static ssize_t store_target_kb(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { char *endchar; unsigned long long target_bytes; if (!capable(CAP_SYS_ADMIN)) return -EPERM; target_bytes = simple_strtoull(buf, &endchar, 0) * 1024; balloon_set_new_target(target_bytes >> PAGE_SHIFT); return count; } static DEVICE_ATTR(target_kb, S_IRUGO | S_IWUSR, show_target_kb, store_target_kb); static ssize_t show_target(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%llu\n", (unsigned long long)balloon_stats.target_pages << PAGE_SHIFT); } static ssize_t store_target(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { char *endchar; unsigned long long target_bytes; if (!capable(CAP_SYS_ADMIN)) return -EPERM; target_bytes = memparse(buf, &endchar); balloon_set_new_target(target_bytes >> PAGE_SHIFT); return count; } static DEVICE_ATTR(target, S_IRUGO | S_IWUSR, show_target, store_target); static struct device_attribute *balloon_attrs[] = { &dev_attr_target_kb, &dev_attr_target, &dev_attr_schedule_delay.attr, &dev_attr_max_schedule_delay.attr, &dev_attr_retry_count.attr, &dev_attr_max_retry_count.attr }; static struct attribute *balloon_info_attrs[] = { &dev_attr_current_kb.attr, &dev_attr_low_kb.attr, &dev_attr_high_kb.attr, NULL }; static const struct attribute_group balloon_info_group = { .name = "info", .attrs = balloon_info_attrs }; static struct bus_type balloon_subsys = { .name = BALLOON_CLASS_NAME, .dev_name = BALLOON_CLASS_NAME, }; static int register_balloon(struct device *dev) { int i, error; error = subsys_system_register(&balloon_subsys, NULL); if (error) return error; dev->id = 0; dev->bus = &balloon_subsys; error = device_register(dev); if (error) { bus_unregister(&balloon_subsys); return error; } for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) { error = device_create_file(dev, balloon_attrs[i]); if (error) goto fail; } error = sysfs_create_group(&dev->kobj, &balloon_info_group); if (error) goto fail; return 0; fail: while (--i >= 0) device_remove_file(dev, balloon_attrs[i]); device_unregister(dev); bus_unregister(&balloon_subsys); return error; } MODULE_LICENSE("GPL");
gpl-2.0
mlachwani/Android-4.4.2-Hammerhead-Kernel
net/appletalk/aarp.c
7483
25491
/* * AARP: An implementation of the AppleTalk AARP protocol for * Ethernet 'ELAP'. * * Alan Cox <Alan.Cox@linux.org> * * This doesn't fit cleanly with the IP arp. Potentially we can use * the generic neighbour discovery code to clean this up. * * FIXME: * We ought to handle the retransmits with a single list and a * separate fast timer for when it is needed. * Use neighbour discovery code. * Token Ring Support. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * * References: * Inside AppleTalk (2nd Ed). * Fixes: * Jaume Grau - flush caches on AARP_PROBE * Rob Newberry - Added proxy AARP and AARP proc fs, * moved probing from DDP module. * Arnaldo C. Melo - don't mangle rx packets * */ #include <linux/if_arp.h> #include <linux/slab.h> #include <net/sock.h> #include <net/datalink.h> #include <net/psnap.h> #include <linux/atalk.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/export.h> int sysctl_aarp_expiry_time = AARP_EXPIRY_TIME; int sysctl_aarp_tick_time = AARP_TICK_TIME; int sysctl_aarp_retransmit_limit = AARP_RETRANSMIT_LIMIT; int sysctl_aarp_resolve_time = AARP_RESOLVE_TIME; /* Lists of aarp entries */ /** * struct aarp_entry - AARP entry * @last_sent - Last time we xmitted the aarp request * @packet_queue - Queue of frames wait for resolution * @status - Used for proxy AARP * expires_at - Entry expiry time * target_addr - DDP Address * dev - Device to use * hwaddr - Physical i/f address of target/router * xmit_count - When this hits 10 we give up * next - Next entry in chain */ struct aarp_entry { /* These first two are only used for unresolved entries */ unsigned long last_sent; struct sk_buff_head packet_queue; int status; unsigned long expires_at; struct atalk_addr target_addr; struct net_device *dev; char hwaddr[6]; unsigned short xmit_count; struct aarp_entry *next; }; /* Hashed list of resolved, unresolved and proxy entries */ static struct aarp_entry *resolved[AARP_HASH_SIZE]; static struct aarp_entry *unresolved[AARP_HASH_SIZE]; static struct aarp_entry *proxies[AARP_HASH_SIZE]; static int unresolved_count; /* One lock protects it all. */ static DEFINE_RWLOCK(aarp_lock); /* Used to walk the list and purge/kick entries. */ static struct timer_list aarp_timer; /* * Delete an aarp queue * * Must run under aarp_lock. */ static void __aarp_expire(struct aarp_entry *a) { skb_queue_purge(&a->packet_queue); kfree(a); } /* * Send an aarp queue entry request * * Must run under aarp_lock. */ static void __aarp_send_query(struct aarp_entry *a) { static unsigned char aarp_eth_multicast[ETH_ALEN] = { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF }; struct net_device *dev = a->dev; struct elapaarp *eah; int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length; struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC); struct atalk_addr *sat = atalk_find_dev_addr(dev); if (!skb) return; if (!sat) { kfree_skb(skb); return; } /* Set up the buffer */ skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length); skb_reset_network_header(skb); skb_reset_transport_header(skb); skb_put(skb, sizeof(*eah)); skb->protocol = htons(ETH_P_ATALK); skb->dev = dev; eah = aarp_hdr(skb); /* Set up the ARP */ eah->hw_type = htons(AARP_HW_TYPE_ETHERNET); eah->pa_type = htons(ETH_P_ATALK); eah->hw_len = ETH_ALEN; eah->pa_len = AARP_PA_ALEN; eah->function = htons(AARP_REQUEST); memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN); eah->pa_src_zero = 0; eah->pa_src_net = sat->s_net; eah->pa_src_node = sat->s_node; memset(eah->hw_dst, '\0', ETH_ALEN); eah->pa_dst_zero = 0; eah->pa_dst_net = a->target_addr.s_net; eah->pa_dst_node = a->target_addr.s_node; /* Send it */ aarp_dl->request(aarp_dl, skb, aarp_eth_multicast); /* Update the sending count */ a->xmit_count++; a->last_sent = jiffies; } /* This runs under aarp_lock and in softint context, so only atomic memory * allocations can be used. */ static void aarp_send_reply(struct net_device *dev, struct atalk_addr *us, struct atalk_addr *them, unsigned char *sha) { struct elapaarp *eah; int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length; struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC); if (!skb) return; /* Set up the buffer */ skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length); skb_reset_network_header(skb); skb_reset_transport_header(skb); skb_put(skb, sizeof(*eah)); skb->protocol = htons(ETH_P_ATALK); skb->dev = dev; eah = aarp_hdr(skb); /* Set up the ARP */ eah->hw_type = htons(AARP_HW_TYPE_ETHERNET); eah->pa_type = htons(ETH_P_ATALK); eah->hw_len = ETH_ALEN; eah->pa_len = AARP_PA_ALEN; eah->function = htons(AARP_REPLY); memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN); eah->pa_src_zero = 0; eah->pa_src_net = us->s_net; eah->pa_src_node = us->s_node; if (!sha) memset(eah->hw_dst, '\0', ETH_ALEN); else memcpy(eah->hw_dst, sha, ETH_ALEN); eah->pa_dst_zero = 0; eah->pa_dst_net = them->s_net; eah->pa_dst_node = them->s_node; /* Send it */ aarp_dl->request(aarp_dl, skb, sha); } /* * Send probe frames. Called from aarp_probe_network and * aarp_proxy_probe_network. */ static void aarp_send_probe(struct net_device *dev, struct atalk_addr *us) { struct elapaarp *eah; int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length; struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC); static unsigned char aarp_eth_multicast[ETH_ALEN] = { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF }; if (!skb) return; /* Set up the buffer */ skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length); skb_reset_network_header(skb); skb_reset_transport_header(skb); skb_put(skb, sizeof(*eah)); skb->protocol = htons(ETH_P_ATALK); skb->dev = dev; eah = aarp_hdr(skb); /* Set up the ARP */ eah->hw_type = htons(AARP_HW_TYPE_ETHERNET); eah->pa_type = htons(ETH_P_ATALK); eah->hw_len = ETH_ALEN; eah->pa_len = AARP_PA_ALEN; eah->function = htons(AARP_PROBE); memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN); eah->pa_src_zero = 0; eah->pa_src_net = us->s_net; eah->pa_src_node = us->s_node; memset(eah->hw_dst, '\0', ETH_ALEN); eah->pa_dst_zero = 0; eah->pa_dst_net = us->s_net; eah->pa_dst_node = us->s_node; /* Send it */ aarp_dl->request(aarp_dl, skb, aarp_eth_multicast); } /* * Handle an aarp timer expire * * Must run under the aarp_lock. */ static void __aarp_expire_timer(struct aarp_entry **n) { struct aarp_entry *t; while (*n) /* Expired ? */ if (time_after(jiffies, (*n)->expires_at)) { t = *n; *n = (*n)->next; __aarp_expire(t); } else n = &((*n)->next); } /* * Kick all pending requests 5 times a second. * * Must run under the aarp_lock. */ static void __aarp_kick(struct aarp_entry **n) { struct aarp_entry *t; while (*n) /* Expired: if this will be the 11th tx, we delete instead. */ if ((*n)->xmit_count >= sysctl_aarp_retransmit_limit) { t = *n; *n = (*n)->next; __aarp_expire(t); } else { __aarp_send_query(*n); n = &((*n)->next); } } /* * A device has gone down. Take all entries referring to the device * and remove them. * * Must run under the aarp_lock. */ static void __aarp_expire_device(struct aarp_entry **n, struct net_device *dev) { struct aarp_entry *t; while (*n) if ((*n)->dev == dev) { t = *n; *n = (*n)->next; __aarp_expire(t); } else n = &((*n)->next); } /* Handle the timer event */ static void aarp_expire_timeout(unsigned long unused) { int ct; write_lock_bh(&aarp_lock); for (ct = 0; ct < AARP_HASH_SIZE; ct++) { __aarp_expire_timer(&resolved[ct]); __aarp_kick(&unresolved[ct]); __aarp_expire_timer(&unresolved[ct]); __aarp_expire_timer(&proxies[ct]); } write_unlock_bh(&aarp_lock); mod_timer(&aarp_timer, jiffies + (unresolved_count ? sysctl_aarp_tick_time : sysctl_aarp_expiry_time)); } /* Network device notifier chain handler. */ static int aarp_device_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = ptr; int ct; if (!net_eq(dev_net(dev), &init_net)) return NOTIFY_DONE; if (event == NETDEV_DOWN) { write_lock_bh(&aarp_lock); for (ct = 0; ct < AARP_HASH_SIZE; ct++) { __aarp_expire_device(&resolved[ct], dev); __aarp_expire_device(&unresolved[ct], dev); __aarp_expire_device(&proxies[ct], dev); } write_unlock_bh(&aarp_lock); } return NOTIFY_DONE; } /* Expire all entries in a hash chain */ static void __aarp_expire_all(struct aarp_entry **n) { struct aarp_entry *t; while (*n) { t = *n; *n = (*n)->next; __aarp_expire(t); } } /* Cleanup all hash chains -- module unloading */ static void aarp_purge(void) { int ct; write_lock_bh(&aarp_lock); for (ct = 0; ct < AARP_HASH_SIZE; ct++) { __aarp_expire_all(&resolved[ct]); __aarp_expire_all(&unresolved[ct]); __aarp_expire_all(&proxies[ct]); } write_unlock_bh(&aarp_lock); } /* * Create a new aarp entry. This must use GFP_ATOMIC because it * runs while holding spinlocks. */ static struct aarp_entry *aarp_alloc(void) { struct aarp_entry *a = kmalloc(sizeof(*a), GFP_ATOMIC); if (a) skb_queue_head_init(&a->packet_queue); return a; } /* * Find an entry. We might return an expired but not yet purged entry. We * don't care as it will do no harm. * * This must run under the aarp_lock. */ static struct aarp_entry *__aarp_find_entry(struct aarp_entry *list, struct net_device *dev, struct atalk_addr *sat) { while (list) { if (list->target_addr.s_net == sat->s_net && list->target_addr.s_node == sat->s_node && list->dev == dev) break; list = list->next; } return list; } /* Called from the DDP code, and thus must be exported. */ void aarp_proxy_remove(struct net_device *dev, struct atalk_addr *sa) { int hash = sa->s_node % (AARP_HASH_SIZE - 1); struct aarp_entry *a; write_lock_bh(&aarp_lock); a = __aarp_find_entry(proxies[hash], dev, sa); if (a) a->expires_at = jiffies - 1; write_unlock_bh(&aarp_lock); } /* This must run under aarp_lock. */ static struct atalk_addr *__aarp_proxy_find(struct net_device *dev, struct atalk_addr *sa) { int hash = sa->s_node % (AARP_HASH_SIZE - 1); struct aarp_entry *a = __aarp_find_entry(proxies[hash], dev, sa); return a ? sa : NULL; } /* * Probe a Phase 1 device or a device that requires its Net:Node to * be set via an ioctl. */ static void aarp_send_probe_phase1(struct atalk_iface *iface) { struct ifreq atreq; struct sockaddr_at *sa = (struct sockaddr_at *)&atreq.ifr_addr; const struct net_device_ops *ops = iface->dev->netdev_ops; sa->sat_addr.s_node = iface->address.s_node; sa->sat_addr.s_net = ntohs(iface->address.s_net); /* We pass the Net:Node to the drivers/cards by a Device ioctl. */ if (!(ops->ndo_do_ioctl(iface->dev, &atreq, SIOCSIFADDR))) { ops->ndo_do_ioctl(iface->dev, &atreq, SIOCGIFADDR); if (iface->address.s_net != htons(sa->sat_addr.s_net) || iface->address.s_node != sa->sat_addr.s_node) iface->status |= ATIF_PROBE_FAIL; iface->address.s_net = htons(sa->sat_addr.s_net); iface->address.s_node = sa->sat_addr.s_node; } } void aarp_probe_network(struct atalk_iface *atif) { if (atif->dev->type == ARPHRD_LOCALTLK || atif->dev->type == ARPHRD_PPP) aarp_send_probe_phase1(atif); else { unsigned int count; for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) { aarp_send_probe(atif->dev, &atif->address); /* Defer 1/10th */ msleep(100); if (atif->status & ATIF_PROBE_FAIL) break; } } } int aarp_proxy_probe_network(struct atalk_iface *atif, struct atalk_addr *sa) { int hash, retval = -EPROTONOSUPPORT; struct aarp_entry *entry; unsigned int count; /* * we don't currently support LocalTalk or PPP for proxy AARP; * if someone wants to try and add it, have fun */ if (atif->dev->type == ARPHRD_LOCALTLK || atif->dev->type == ARPHRD_PPP) goto out; /* * create a new AARP entry with the flags set to be published -- * we need this one to hang around even if it's in use */ entry = aarp_alloc(); retval = -ENOMEM; if (!entry) goto out; entry->expires_at = -1; entry->status = ATIF_PROBE; entry->target_addr.s_node = sa->s_node; entry->target_addr.s_net = sa->s_net; entry->dev = atif->dev; write_lock_bh(&aarp_lock); hash = sa->s_node % (AARP_HASH_SIZE - 1); entry->next = proxies[hash]; proxies[hash] = entry; for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) { aarp_send_probe(atif->dev, sa); /* Defer 1/10th */ write_unlock_bh(&aarp_lock); msleep(100); write_lock_bh(&aarp_lock); if (entry->status & ATIF_PROBE_FAIL) break; } if (entry->status & ATIF_PROBE_FAIL) { entry->expires_at = jiffies - 1; /* free the entry */ retval = -EADDRINUSE; /* return network full */ } else { /* clear the probing flag */ entry->status &= ~ATIF_PROBE; retval = 1; } write_unlock_bh(&aarp_lock); out: return retval; } /* Send a DDP frame */ int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb, struct atalk_addr *sa, void *hwaddr) { static char ddp_eth_multicast[ETH_ALEN] = { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF }; int hash; struct aarp_entry *a; skb_reset_network_header(skb); /* Check for LocalTalk first */ if (dev->type == ARPHRD_LOCALTLK) { struct atalk_addr *at = atalk_find_dev_addr(dev); struct ddpehdr *ddp = (struct ddpehdr *)skb->data; int ft = 2; /* * Compressible ? * * IFF: src_net == dest_net == device_net * (zero matches anything) */ if ((!ddp->deh_snet || at->s_net == ddp->deh_snet) && (!ddp->deh_dnet || at->s_net == ddp->deh_dnet)) { skb_pull(skb, sizeof(*ddp) - 4); /* * The upper two remaining bytes are the port * numbers we just happen to need. Now put the * length in the lower two. */ *((__be16 *)skb->data) = htons(skb->len); ft = 1; } /* * Nice and easy. No AARP type protocols occur here so we can * just shovel it out with a 3 byte LLAP header */ skb_push(skb, 3); skb->data[0] = sa->s_node; skb->data[1] = at->s_node; skb->data[2] = ft; skb->dev = dev; goto sendit; } /* On a PPP link we neither compress nor aarp. */ if (dev->type == ARPHRD_PPP) { skb->protocol = htons(ETH_P_PPPTALK); skb->dev = dev; goto sendit; } /* Non ELAP we cannot do. */ if (dev->type != ARPHRD_ETHER) goto free_it; skb->dev = dev; skb->protocol = htons(ETH_P_ATALK); hash = sa->s_node % (AARP_HASH_SIZE - 1); /* Do we have a resolved entry? */ if (sa->s_node == ATADDR_BCAST) { /* Send it */ ddp_dl->request(ddp_dl, skb, ddp_eth_multicast); goto sent; } write_lock_bh(&aarp_lock); a = __aarp_find_entry(resolved[hash], dev, sa); if (a) { /* Return 1 and fill in the address */ a->expires_at = jiffies + (sysctl_aarp_expiry_time * 10); ddp_dl->request(ddp_dl, skb, a->hwaddr); write_unlock_bh(&aarp_lock); goto sent; } /* Do we have an unresolved entry: This is the less common path */ a = __aarp_find_entry(unresolved[hash], dev, sa); if (a) { /* Queue onto the unresolved queue */ skb_queue_tail(&a->packet_queue, skb); goto out_unlock; } /* Allocate a new entry */ a = aarp_alloc(); if (!a) { /* Whoops slipped... good job it's an unreliable protocol 8) */ write_unlock_bh(&aarp_lock); goto free_it; } /* Set up the queue */ skb_queue_tail(&a->packet_queue, skb); a->expires_at = jiffies + sysctl_aarp_resolve_time; a->dev = dev; a->next = unresolved[hash]; a->target_addr = *sa; a->xmit_count = 0; unresolved[hash] = a; unresolved_count++; /* Send an initial request for the address */ __aarp_send_query(a); /* * Switch to fast timer if needed (That is if this is the first * unresolved entry to get added) */ if (unresolved_count == 1) mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time); /* Now finally, it is safe to drop the lock. */ out_unlock: write_unlock_bh(&aarp_lock); /* Tell the ddp layer we have taken over for this frame. */ goto sent; sendit: if (skb->sk) skb->priority = skb->sk->sk_priority; if (dev_queue_xmit(skb)) goto drop; sent: return NET_XMIT_SUCCESS; free_it: kfree_skb(skb); drop: return NET_XMIT_DROP; } EXPORT_SYMBOL(aarp_send_ddp); /* * An entry in the aarp unresolved queue has become resolved. Send * all the frames queued under it. * * Must run under aarp_lock. */ static void __aarp_resolved(struct aarp_entry **list, struct aarp_entry *a, int hash) { struct sk_buff *skb; while (*list) if (*list == a) { unresolved_count--; *list = a->next; /* Move into the resolved list */ a->next = resolved[hash]; resolved[hash] = a; /* Kick frames off */ while ((skb = skb_dequeue(&a->packet_queue)) != NULL) { a->expires_at = jiffies + sysctl_aarp_expiry_time * 10; ddp_dl->request(ddp_dl, skb, a->hwaddr); } } else list = &((*list)->next); } /* * This is called by the SNAP driver whenever we see an AARP SNAP * frame. We currently only support Ethernet. */ static int aarp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { struct elapaarp *ea = aarp_hdr(skb); int hash, ret = 0; __u16 function; struct aarp_entry *a; struct atalk_addr sa, *ma, da; struct atalk_iface *ifa; if (!net_eq(dev_net(dev), &init_net)) goto out0; /* We only do Ethernet SNAP AARP. */ if (dev->type != ARPHRD_ETHER) goto out0; /* Frame size ok? */ if (!skb_pull(skb, sizeof(*ea))) goto out0; function = ntohs(ea->function); /* Sanity check fields. */ if (function < AARP_REQUEST || function > AARP_PROBE || ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN || ea->pa_src_zero || ea->pa_dst_zero) goto out0; /* Looks good. */ hash = ea->pa_src_node % (AARP_HASH_SIZE - 1); /* Build an address. */ sa.s_node = ea->pa_src_node; sa.s_net = ea->pa_src_net; /* Process the packet. Check for replies of me. */ ifa = atalk_find_dev(dev); if (!ifa) goto out1; if (ifa->status & ATIF_PROBE && ifa->address.s_node == ea->pa_dst_node && ifa->address.s_net == ea->pa_dst_net) { ifa->status |= ATIF_PROBE_FAIL; /* Fail the probe (in use) */ goto out1; } /* Check for replies of proxy AARP entries */ da.s_node = ea->pa_dst_node; da.s_net = ea->pa_dst_net; write_lock_bh(&aarp_lock); a = __aarp_find_entry(proxies[hash], dev, &da); if (a && a->status & ATIF_PROBE) { a->status |= ATIF_PROBE_FAIL; /* * we do not respond to probe or request packets for * this address while we are probing this address */ goto unlock; } switch (function) { case AARP_REPLY: if (!unresolved_count) /* Speed up */ break; /* Find the entry. */ a = __aarp_find_entry(unresolved[hash], dev, &sa); if (!a || dev != a->dev) break; /* We can fill one in - this is good. */ memcpy(a->hwaddr, ea->hw_src, ETH_ALEN); __aarp_resolved(&unresolved[hash], a, hash); if (!unresolved_count) mod_timer(&aarp_timer, jiffies + sysctl_aarp_expiry_time); break; case AARP_REQUEST: case AARP_PROBE: /* * If it is my address set ma to my address and reply. * We can treat probe and request the same. Probe * simply means we shouldn't cache the querying host, * as in a probe they are proposing an address not * using one. * * Support for proxy-AARP added. We check if the * address is one of our proxies before we toss the * packet out. */ sa.s_node = ea->pa_dst_node; sa.s_net = ea->pa_dst_net; /* See if we have a matching proxy. */ ma = __aarp_proxy_find(dev, &sa); if (!ma) ma = &ifa->address; else { /* We need to make a copy of the entry. */ da.s_node = sa.s_node; da.s_net = sa.s_net; ma = &da; } if (function == AARP_PROBE) { /* * A probe implies someone trying to get an * address. So as a precaution flush any * entries we have for this address. */ a = __aarp_find_entry(resolved[sa.s_node % (AARP_HASH_SIZE - 1)], skb->dev, &sa); /* * Make it expire next tick - that avoids us * getting into a probe/flush/learn/probe/ * flush/learn cycle during probing of a slow * to respond host addr. */ if (a) { a->expires_at = jiffies - 1; mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time); } } if (sa.s_node != ma->s_node) break; if (sa.s_net && ma->s_net && sa.s_net != ma->s_net) break; sa.s_node = ea->pa_src_node; sa.s_net = ea->pa_src_net; /* aarp_my_address has found the address to use for us. */ aarp_send_reply(dev, ma, &sa, ea->hw_src); break; } unlock: write_unlock_bh(&aarp_lock); out1: ret = 1; out0: kfree_skb(skb); return ret; } static struct notifier_block aarp_notifier = { .notifier_call = aarp_device_event, }; static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 }; void __init aarp_proto_init(void) { aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv); if (!aarp_dl) printk(KERN_CRIT "Unable to register AARP with SNAP.\n"); setup_timer(&aarp_timer, aarp_expire_timeout, 0); aarp_timer.expires = jiffies + sysctl_aarp_expiry_time; add_timer(&aarp_timer); register_netdevice_notifier(&aarp_notifier); } /* Remove the AARP entries associated with a device. */ void aarp_device_down(struct net_device *dev) { int ct; write_lock_bh(&aarp_lock); for (ct = 0; ct < AARP_HASH_SIZE; ct++) { __aarp_expire_device(&resolved[ct], dev); __aarp_expire_device(&unresolved[ct], dev); __aarp_expire_device(&proxies[ct], dev); } write_unlock_bh(&aarp_lock); } #ifdef CONFIG_PROC_FS struct aarp_iter_state { int bucket; struct aarp_entry **table; }; /* * Get the aarp entry that is in the chain described * by the iterator. * If pos is set then skip till that index. * pos = 1 is the first entry */ static struct aarp_entry *iter_next(struct aarp_iter_state *iter, loff_t *pos) { int ct = iter->bucket; struct aarp_entry **table = iter->table; loff_t off = 0; struct aarp_entry *entry; rescan: while(ct < AARP_HASH_SIZE) { for (entry = table[ct]; entry; entry = entry->next) { if (!pos || ++off == *pos) { iter->table = table; iter->bucket = ct; return entry; } } ++ct; } if (table == resolved) { ct = 0; table = unresolved; goto rescan; } if (table == unresolved) { ct = 0; table = proxies; goto rescan; } return NULL; } static void *aarp_seq_start(struct seq_file *seq, loff_t *pos) __acquires(aarp_lock) { struct aarp_iter_state *iter = seq->private; read_lock_bh(&aarp_lock); iter->table = resolved; iter->bucket = 0; return *pos ? iter_next(iter, pos) : SEQ_START_TOKEN; } static void *aarp_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct aarp_entry *entry = v; struct aarp_iter_state *iter = seq->private; ++*pos; /* first line after header */ if (v == SEQ_START_TOKEN) entry = iter_next(iter, NULL); /* next entry in current bucket */ else if (entry->next) entry = entry->next; /* next bucket or table */ else { ++iter->bucket; entry = iter_next(iter, NULL); } return entry; } static void aarp_seq_stop(struct seq_file *seq, void *v) __releases(aarp_lock) { read_unlock_bh(&aarp_lock); } static const char *dt2str(unsigned long ticks) { static char buf[32]; sprintf(buf, "%ld.%02ld", ticks / HZ, ((ticks % HZ) * 100 ) / HZ); return buf; } static int aarp_seq_show(struct seq_file *seq, void *v) { struct aarp_iter_state *iter = seq->private; struct aarp_entry *entry = v; unsigned long now = jiffies; if (v == SEQ_START_TOKEN) seq_puts(seq, "Address Interface Hardware Address" " Expires LastSend Retry Status\n"); else { seq_printf(seq, "%04X:%02X %-12s", ntohs(entry->target_addr.s_net), (unsigned int) entry->target_addr.s_node, entry->dev ? entry->dev->name : "????"); seq_printf(seq, "%pM", entry->hwaddr); seq_printf(seq, " %8s", dt2str((long)entry->expires_at - (long)now)); if (iter->table == unresolved) seq_printf(seq, " %8s %6hu", dt2str(now - entry->last_sent), entry->xmit_count); else seq_puts(seq, " "); seq_printf(seq, " %s\n", (iter->table == resolved) ? "resolved" : (iter->table == unresolved) ? "unresolved" : (iter->table == proxies) ? "proxies" : "unknown"); } return 0; } static const struct seq_operations aarp_seq_ops = { .start = aarp_seq_start, .next = aarp_seq_next, .stop = aarp_seq_stop, .show = aarp_seq_show, }; static int aarp_seq_open(struct inode *inode, struct file *file) { return seq_open_private(file, &aarp_seq_ops, sizeof(struct aarp_iter_state)); } const struct file_operations atalk_seq_arp_fops = { .owner = THIS_MODULE, .open = aarp_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_private, }; #endif /* General module cleanup. Called from cleanup_module() in ddp.c. */ void aarp_cleanup_module(void) { del_timer_sync(&aarp_timer); unregister_netdevice_notifier(&aarp_notifier); unregister_snap_client(aarp_dl); aarp_purge(); }
gpl-2.0
bfg-repo-cleaner-demos/linux-original
drivers/net/wireless/rtlwifi/rtl8192cu/led.c
9531
4157
/****************************************************************************** * * Copyright(c) 2009-2012 Realtek Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * wlanfae <wlanfae@realtek.com> * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, * Hsinchu 300, Taiwan. * *****************************************************************************/ #include "../wifi.h" #include "../usb.h" #include "reg.h" #include "led.h" static void _rtl92cu_init_led(struct ieee80211_hw *hw, struct rtl_led *pled, enum rtl_led_pin ledpin) { pled->hw = hw; pled->ledpin = ledpin; pled->ledon = false; } static void _rtl92cu_deInit_led(struct rtl_led *pled) { } void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled) { u8 ledcfg; struct rtl_priv *rtlpriv = rtl_priv(hw); RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin); ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); switch (pled->ledpin) { case LED_PIN_GPIO0: break; case LED_PIN_LED0: rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6)); break; case LED_PIN_LED1: rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5)); break; default: RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "switch case not processed\n"); break; } pled->ledon = true; } void rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); u8 ledcfg; RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin); ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); switch (pled->ledpin) { case LED_PIN_GPIO0: break; case LED_PIN_LED0: ledcfg &= 0xf0; if (usbpriv->ledctl.led_opendrain) rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(1) | BIT(5) | BIT(6))); else rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3) | BIT(5) | BIT(6))); break; case LED_PIN_LED1: ledcfg &= 0x0f; rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3))); break; default: RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "switch case not processed\n"); break; } pled->ledon = false; } void rtl92cu_init_sw_leds(struct ieee80211_hw *hw) { struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led0), LED_PIN_LED0); _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led1), LED_PIN_LED1); } void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw) { struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led0)); _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led1)); } static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction) { } void rtl92cu_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && (ledaction == LED_CTL_TX || ledaction == LED_CTL_RX || ledaction == LED_CTL_SITE_SURVEY || ledaction == LED_CTL_LINK || ledaction == LED_CTL_NO_LINK || ledaction == LED_CTL_START_TO_LINK || ledaction == LED_CTL_POWER_ON)) { return; } RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction); _rtl92cu_sw_led_control(hw, ledaction); }
gpl-2.0
samsung-msm/android_kernel_samsung_msm8960
drivers/infiniband/hw/cxgb3/iwch_ev.c
9787
7025
/* * Copyright (c) 2006 Chelsio, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <linux/gfp.h> #include <linux/mman.h> #include <net/sock.h> #include "iwch_provider.h" #include "iwch.h" #include "iwch_cm.h" #include "cxio_hal.h" #include "cxio_wr.h" static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp, struct respQ_msg_t *rsp_msg, enum ib_event_type ib_event, int send_term) { struct ib_event event; struct iwch_qp_attributes attrs; struct iwch_qp *qhp; unsigned long flag; spin_lock(&rnicp->lock); qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe)); if (!qhp) { printk(KERN_ERR "%s unaffiliated error 0x%x qpid 0x%x\n", __func__, CQE_STATUS(rsp_msg->cqe), CQE_QPID(rsp_msg->cqe)); spin_unlock(&rnicp->lock); return; } if ((qhp->attr.state == IWCH_QP_STATE_ERROR) || (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) { PDBG("%s AE received after RTS - " "qp state %d qpid 0x%x status 0x%x\n", __func__, qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe)); spin_unlock(&rnicp->lock); return; } printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x " "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __func__, CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe)); atomic_inc(&qhp->refcnt); spin_unlock(&rnicp->lock); if (qhp->attr.state == IWCH_QP_STATE_RTS) { attrs.next_state = IWCH_QP_STATE_TERMINATE; iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 1); if (send_term) iwch_post_terminate(qhp, rsp_msg); } event.event = ib_event; event.device = chp->ibcq.device; if (ib_event == IB_EVENT_CQ_ERR) event.element.cq = &chp->ibcq; else event.element.qp = &qhp->ibqp; if (qhp->ibqp.event_handler) (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context); spin_lock_irqsave(&chp->comp_handler_lock, flag); (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context); spin_unlock_irqrestore(&chp->comp_handler_lock, flag); if (atomic_dec_and_test(&qhp->refcnt)) wake_up(&qhp->wait); } void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb) { struct iwch_dev *rnicp; struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data; struct iwch_cq *chp; struct iwch_qp *qhp; u32 cqid = RSPQ_CQID(rsp_msg); unsigned long flag; rnicp = (struct iwch_dev *) rdev_p->ulp; spin_lock(&rnicp->lock); chp = get_chp(rnicp, cqid); qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe)); if (!chp || !qhp) { printk(KERN_ERR MOD "BAD AE cqid 0x%x qpid 0x%x opcode %d " "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x \n", cqid, CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe)); spin_unlock(&rnicp->lock); goto out; } iwch_qp_add_ref(&qhp->ibqp); atomic_inc(&chp->refcnt); spin_unlock(&rnicp->lock); /* * 1) completion of our sending a TERMINATE. * 2) incoming TERMINATE message. */ if ((CQE_OPCODE(rsp_msg->cqe) == T3_TERMINATE) && (CQE_STATUS(rsp_msg->cqe) == 0)) { if (SQ_TYPE(rsp_msg->cqe)) { PDBG("%s QPID 0x%x ep %p disconnecting\n", __func__, qhp->wq.qpid, qhp->ep); iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC); } else { PDBG("%s post REQ_ERR AE QPID 0x%x\n", __func__, qhp->wq.qpid); post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 0); iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC); } goto done; } /* Bad incoming Read request */ if (SQ_TYPE(rsp_msg->cqe) && (CQE_OPCODE(rsp_msg->cqe) == T3_READ_RESP)) { post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1); goto done; } /* Bad incoming write */ if (RQ_TYPE(rsp_msg->cqe) && (CQE_OPCODE(rsp_msg->cqe) == T3_RDMA_WRITE)) { post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1); goto done; } switch (CQE_STATUS(rsp_msg->cqe)) { /* Completion Events */ case TPT_ERR_SUCCESS: /* * Confirm the destination entry if this is a RECV completion. */ if (qhp->ep && SQ_TYPE(rsp_msg->cqe)) dst_confirm(qhp->ep->dst); spin_lock_irqsave(&chp->comp_handler_lock, flag); (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context); spin_unlock_irqrestore(&chp->comp_handler_lock, flag); break; case TPT_ERR_STAG: case TPT_ERR_PDID: case TPT_ERR_QPID: case TPT_ERR_ACCESS: case TPT_ERR_WRAP: case TPT_ERR_BOUND: case TPT_ERR_INVALIDATE_SHARED_MR: case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND: post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1); break; /* Device Fatal Errors */ case TPT_ERR_ECC: case TPT_ERR_ECC_PSTAG: case TPT_ERR_INTERNAL_ERR: post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_DEVICE_FATAL, 1); break; /* QP Fatal Errors */ case TPT_ERR_OUT_OF_RQE: case TPT_ERR_PBL_ADDR_BOUND: case TPT_ERR_CRC: case TPT_ERR_MARKER: case TPT_ERR_PDU_LEN_ERR: case TPT_ERR_DDP_VERSION: case TPT_ERR_RDMA_VERSION: case TPT_ERR_OPCODE: case TPT_ERR_DDP_QUEUE_NUM: case TPT_ERR_MSN: case TPT_ERR_TBIT: case TPT_ERR_MO: case TPT_ERR_MSN_GAP: case TPT_ERR_MSN_RANGE: case TPT_ERR_RQE_ADDR_BOUND: case TPT_ERR_IRD_OVERFLOW: post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1); break; default: printk(KERN_ERR MOD "Unknown T3 status 0x%x QPID 0x%x\n", CQE_STATUS(rsp_msg->cqe), qhp->wq.qpid); post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1); break; } done: if (atomic_dec_and_test(&chp->refcnt)) wake_up(&chp->wait); iwch_qp_rem_ref(&qhp->ibqp); out: dev_kfree_skb_irq(skb); }
gpl-2.0
RealDigitalMediaAndroid/linux-imx6
arch/arm/mach-w90x900/clksel.c
9787
1958
/* * linux/arch/arm/mach-w90x900/clksel.c * * Copyright (c) 2008 Nuvoton technology corporation * * Wan ZongShun <mcuos.com@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation;version 2 of the License. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/device.h> #include <linux/list.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/string.h> #include <linux/clk.h> #include <linux/mutex.h> #include <linux/io.h> #include <mach/hardware.h> #include <mach/regs-clock.h> #define PLL0 0x00 #define PLL1 0x01 #define OTHER 0x02 #define EXT 0x03 #define MSOFFSET 0x0C #define ATAOFFSET 0x0a #define LCDOFFSET 0x06 #define AUDOFFSET 0x04 #define CPUOFFSET 0x00 static DEFINE_MUTEX(clksel_sem); static void clock_source_select(const char *dev_id, unsigned int clkval) { unsigned int clksel, offset; clksel = __raw_readl(REG_CLKSEL); if (strcmp(dev_id, "nuc900-ms") == 0) offset = MSOFFSET; else if (strcmp(dev_id, "nuc900-atapi") == 0) offset = ATAOFFSET; else if (strcmp(dev_id, "nuc900-lcd") == 0) offset = LCDOFFSET; else if (strcmp(dev_id, "nuc900-ac97") == 0) offset = AUDOFFSET; else offset = CPUOFFSET; clksel &= ~(0x03 << offset); clksel |= (clkval << offset); __raw_writel(clksel, REG_CLKSEL); } void nuc900_clock_source(struct device *dev, unsigned char *src) { unsigned int clkval; const char *dev_id; BUG_ON(!src); clkval = 0; mutex_lock(&clksel_sem); if (dev) dev_id = dev_name(dev); else dev_id = "cpufreq"; if (strcmp(src, "pll0") == 0) clkval = PLL0; else if (strcmp(src, "pll1") == 0) clkval = PLL1; else if (strcmp(src, "ext") == 0) clkval = EXT; else if (strcmp(src, "oth") == 0) clkval = OTHER; clock_source_select(dev_id, clkval); mutex_unlock(&clksel_sem); } EXPORT_SYMBOL(nuc900_clock_source);
gpl-2.0
jmztaylor/android_kernel_htc_a3ul
drivers/infiniband/hw/qib/qib_cq.c
10555
12207
/* * Copyright (c) 2006, 2007, 2008, 2010 QLogic Corporation. All rights reserved. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <linux/err.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include "qib_verbs.h" /** * qib_cq_enter - add a new entry to the completion queue * @cq: completion queue * @entry: work completion entry to add * @sig: true if @entry is a solicitated entry * * This may be called with qp->s_lock held. */ void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int solicited) { struct qib_cq_wc *wc; unsigned long flags; u32 head; u32 next; spin_lock_irqsave(&cq->lock, flags); /* * Note that the head pointer might be writable by user processes. * Take care to verify it is a sane value. */ wc = cq->queue; head = wc->head; if (head >= (unsigned) cq->ibcq.cqe) { head = cq->ibcq.cqe; next = 0; } else next = head + 1; if (unlikely(next == wc->tail)) { spin_unlock_irqrestore(&cq->lock, flags); if (cq->ibcq.event_handler) { struct ib_event ev; ev.device = cq->ibcq.device; ev.element.cq = &cq->ibcq; ev.event = IB_EVENT_CQ_ERR; cq->ibcq.event_handler(&ev, cq->ibcq.cq_context); } return; } if (cq->ip) { wc->uqueue[head].wr_id = entry->wr_id; wc->uqueue[head].status = entry->status; wc->uqueue[head].opcode = entry->opcode; wc->uqueue[head].vendor_err = entry->vendor_err; wc->uqueue[head].byte_len = entry->byte_len; wc->uqueue[head].ex.imm_data = (__u32 __force)entry->ex.imm_data; wc->uqueue[head].qp_num = entry->qp->qp_num; wc->uqueue[head].src_qp = entry->src_qp; wc->uqueue[head].wc_flags = entry->wc_flags; wc->uqueue[head].pkey_index = entry->pkey_index; wc->uqueue[head].slid = entry->slid; wc->uqueue[head].sl = entry->sl; wc->uqueue[head].dlid_path_bits = entry->dlid_path_bits; wc->uqueue[head].port_num = entry->port_num; /* Make sure entry is written before the head index. */ smp_wmb(); } else wc->kqueue[head] = *entry; wc->head = next; if (cq->notify == IB_CQ_NEXT_COMP || (cq->notify == IB_CQ_SOLICITED && (solicited || entry->status != IB_WC_SUCCESS))) { cq->notify = IB_CQ_NONE; cq->triggered++; /* * This will cause send_complete() to be called in * another thread. */ queue_work(qib_cq_wq, &cq->comptask); } spin_unlock_irqrestore(&cq->lock, flags); } /** * qib_poll_cq - poll for work completion entries * @ibcq: the completion queue to poll * @num_entries: the maximum number of entries to return * @entry: pointer to array where work completions are placed * * Returns the number of completion entries polled. * * This may be called from interrupt context. Also called by ib_poll_cq() * in the generic verbs code. */ int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry) { struct qib_cq *cq = to_icq(ibcq); struct qib_cq_wc *wc; unsigned long flags; int npolled; u32 tail; /* The kernel can only poll a kernel completion queue */ if (cq->ip) { npolled = -EINVAL; goto bail; } spin_lock_irqsave(&cq->lock, flags); wc = cq->queue; tail = wc->tail; if (tail > (u32) cq->ibcq.cqe) tail = (u32) cq->ibcq.cqe; for (npolled = 0; npolled < num_entries; ++npolled, ++entry) { if (tail == wc->head) break; /* The kernel doesn't need a RMB since it has the lock. */ *entry = wc->kqueue[tail]; if (tail >= cq->ibcq.cqe) tail = 0; else tail++; } wc->tail = tail; spin_unlock_irqrestore(&cq->lock, flags); bail: return npolled; } static void send_complete(struct work_struct *work) { struct qib_cq *cq = container_of(work, struct qib_cq, comptask); /* * The completion handler will most likely rearm the notification * and poll for all pending entries. If a new completion entry * is added while we are in this routine, queue_work() * won't call us again until we return so we check triggered to * see if we need to call the handler again. */ for (;;) { u8 triggered = cq->triggered; /* * IPoIB connected mode assumes the callback is from a * soft IRQ. We simulate this by blocking "bottom halves". * See the implementation for ipoib_cm_handle_tx_wc(), * netif_tx_lock_bh() and netif_tx_lock(). */ local_bh_disable(); cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context); local_bh_enable(); if (cq->triggered == triggered) return; } } /** * qib_create_cq - create a completion queue * @ibdev: the device this completion queue is attached to * @entries: the minimum size of the completion queue * @context: unused by the QLogic_IB driver * @udata: user data for libibverbs.so * * Returns a pointer to the completion queue or negative errno values * for failure. * * Called by ib_create_cq() in the generic verbs code. */ struct ib_cq *qib_create_cq(struct ib_device *ibdev, int entries, int comp_vector, struct ib_ucontext *context, struct ib_udata *udata) { struct qib_ibdev *dev = to_idev(ibdev); struct qib_cq *cq; struct qib_cq_wc *wc; struct ib_cq *ret; u32 sz; if (entries < 1 || entries > ib_qib_max_cqes) { ret = ERR_PTR(-EINVAL); goto done; } /* Allocate the completion queue structure. */ cq = kmalloc(sizeof(*cq), GFP_KERNEL); if (!cq) { ret = ERR_PTR(-ENOMEM); goto done; } /* * Allocate the completion queue entries and head/tail pointers. * This is allocated separately so that it can be resized and * also mapped into user space. * We need to use vmalloc() in order to support mmap and large * numbers of entries. */ sz = sizeof(*wc); if (udata && udata->outlen >= sizeof(__u64)) sz += sizeof(struct ib_uverbs_wc) * (entries + 1); else sz += sizeof(struct ib_wc) * (entries + 1); wc = vmalloc_user(sz); if (!wc) { ret = ERR_PTR(-ENOMEM); goto bail_cq; } /* * Return the address of the WC as the offset to mmap. * See qib_mmap() for details. */ if (udata && udata->outlen >= sizeof(__u64)) { int err; cq->ip = qib_create_mmap_info(dev, sz, context, wc); if (!cq->ip) { ret = ERR_PTR(-ENOMEM); goto bail_wc; } err = ib_copy_to_udata(udata, &cq->ip->offset, sizeof(cq->ip->offset)); if (err) { ret = ERR_PTR(err); goto bail_ip; } } else cq->ip = NULL; spin_lock(&dev->n_cqs_lock); if (dev->n_cqs_allocated == ib_qib_max_cqs) { spin_unlock(&dev->n_cqs_lock); ret = ERR_PTR(-ENOMEM); goto bail_ip; } dev->n_cqs_allocated++; spin_unlock(&dev->n_cqs_lock); if (cq->ip) { spin_lock_irq(&dev->pending_lock); list_add(&cq->ip->pending_mmaps, &dev->pending_mmaps); spin_unlock_irq(&dev->pending_lock); } /* * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe. * The number of entries should be >= the number requested or return * an error. */ cq->ibcq.cqe = entries; cq->notify = IB_CQ_NONE; cq->triggered = 0; spin_lock_init(&cq->lock); INIT_WORK(&cq->comptask, send_complete); wc->head = 0; wc->tail = 0; cq->queue = wc; ret = &cq->ibcq; goto done; bail_ip: kfree(cq->ip); bail_wc: vfree(wc); bail_cq: kfree(cq); done: return ret; } /** * qib_destroy_cq - destroy a completion queue * @ibcq: the completion queue to destroy. * * Returns 0 for success. * * Called by ib_destroy_cq() in the generic verbs code. */ int qib_destroy_cq(struct ib_cq *ibcq) { struct qib_ibdev *dev = to_idev(ibcq->device); struct qib_cq *cq = to_icq(ibcq); flush_work(&cq->comptask); spin_lock(&dev->n_cqs_lock); dev->n_cqs_allocated--; spin_unlock(&dev->n_cqs_lock); if (cq->ip) kref_put(&cq->ip->ref, qib_release_mmap_info); else vfree(cq->queue); kfree(cq); return 0; } /** * qib_req_notify_cq - change the notification type for a completion queue * @ibcq: the completion queue * @notify_flags: the type of notification to request * * Returns 0 for success. * * This may be called from interrupt context. Also called by * ib_req_notify_cq() in the generic verbs code. */ int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags) { struct qib_cq *cq = to_icq(ibcq); unsigned long flags; int ret = 0; spin_lock_irqsave(&cq->lock, flags); /* * Don't change IB_CQ_NEXT_COMP to IB_CQ_SOLICITED but allow * any other transitions (see C11-31 and C11-32 in ch. 11.4.2.2). */ if (cq->notify != IB_CQ_NEXT_COMP) cq->notify = notify_flags & IB_CQ_SOLICITED_MASK; if ((notify_flags & IB_CQ_REPORT_MISSED_EVENTS) && cq->queue->head != cq->queue->tail) ret = 1; spin_unlock_irqrestore(&cq->lock, flags); return ret; } /** * qib_resize_cq - change the size of the CQ * @ibcq: the completion queue * * Returns 0 for success. */ int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) { struct qib_cq *cq = to_icq(ibcq); struct qib_cq_wc *old_wc; struct qib_cq_wc *wc; u32 head, tail, n; int ret; u32 sz; if (cqe < 1 || cqe > ib_qib_max_cqes) { ret = -EINVAL; goto bail; } /* * Need to use vmalloc() if we want to support large #s of entries. */ sz = sizeof(*wc); if (udata && udata->outlen >= sizeof(__u64)) sz += sizeof(struct ib_uverbs_wc) * (cqe + 1); else sz += sizeof(struct ib_wc) * (cqe + 1); wc = vmalloc_user(sz); if (!wc) { ret = -ENOMEM; goto bail; } /* Check that we can write the offset to mmap. */ if (udata && udata->outlen >= sizeof(__u64)) { __u64 offset = 0; ret = ib_copy_to_udata(udata, &offset, sizeof(offset)); if (ret) goto bail_free; } spin_lock_irq(&cq->lock); /* * Make sure head and tail are sane since they * might be user writable. */ old_wc = cq->queue; head = old_wc->head; if (head > (u32) cq->ibcq.cqe) head = (u32) cq->ibcq.cqe; tail = old_wc->tail; if (tail > (u32) cq->ibcq.cqe) tail = (u32) cq->ibcq.cqe; if (head < tail) n = cq->ibcq.cqe + 1 + head - tail; else n = head - tail; if (unlikely((u32)cqe < n)) { ret = -EINVAL; goto bail_unlock; } for (n = 0; tail != head; n++) { if (cq->ip) wc->uqueue[n] = old_wc->uqueue[tail]; else wc->kqueue[n] = old_wc->kqueue[tail]; if (tail == (u32) cq->ibcq.cqe) tail = 0; else tail++; } cq->ibcq.cqe = cqe; wc->head = n; wc->tail = 0; cq->queue = wc; spin_unlock_irq(&cq->lock); vfree(old_wc); if (cq->ip) { struct qib_ibdev *dev = to_idev(ibcq->device); struct qib_mmap_info *ip = cq->ip; qib_update_mmap_info(dev, ip, sz, wc); /* * Return the offset to mmap. * See qib_mmap() for details. */ if (udata && udata->outlen >= sizeof(__u64)) { ret = ib_copy_to_udata(udata, &ip->offset, sizeof(ip->offset)); if (ret) goto bail; } spin_lock_irq(&dev->pending_lock); if (list_empty(&ip->pending_mmaps)) list_add(&ip->pending_mmaps, &dev->pending_mmaps); spin_unlock_irq(&dev->pending_lock); } ret = 0; goto bail; bail_unlock: spin_unlock_irq(&cq->lock); bail_free: vfree(wc); bail: return ret; }
gpl-2.0
morogoku/MoRoKernel-S7-v2
sound/isa/msnd/msnd_pinnacle.c
572
31111
/********************************************************************* * * Linux multisound pinnacle/fiji driver for ALSA. * * 2002/06/30 Karsten Wiese: * for now this is only used to build a pinnacle / fiji driver. * the OSS parent of this code is designed to also support * the multisound classic via the file msnd_classic.c. * to make it easier for some brave heart to implemt classic * support in alsa, i left all the MSND_CLASSIC tokens in this file. * but for now this untested & undone. * * * ripped from linux kernel 2.4.18 by Karsten Wiese. * * the following is a copy of the 2.4.18 OSS FREE file-heading comment: * * Turtle Beach MultiSound Sound Card Driver for Linux * msnd_pinnacle.c / msnd_classic.c * * -- If MSND_CLASSIC is defined: * * -> driver for Turtle Beach Classic/Monterey/Tahiti * * -- Else * * -> driver for Turtle Beach Pinnacle/Fiji * * 12-3-2000 Modified IO port validation Steve Sycamore * * Copyright (C) 1998 Andrew Veliath * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * ********************************************************************/ #include <linux/kernel.h> #include <linux/module.h> #include <linux/interrupt.h> #include <linux/types.h> #include <linux/delay.h> #include <linux/ioport.h> #include <linux/firmware.h> #include <linux/isa.h> #include <linux/isapnp.h> #include <linux/irq.h> #include <linux/io.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/asound.h> #include <sound/pcm.h> #include <sound/mpu401.h> #ifdef MSND_CLASSIC # ifndef __alpha__ # define SLOWIO # endif #endif #include "msnd.h" #ifdef MSND_CLASSIC # include "msnd_classic.h" # define LOGNAME "msnd_classic" # define DEV_NAME "msnd-classic" #else # include "msnd_pinnacle.h" # define LOGNAME "snd_msnd_pinnacle" # define DEV_NAME "msnd-pinnacle" #endif static void set_default_audio_parameters(struct snd_msnd *chip) { chip->play_sample_size = DEFSAMPLESIZE; chip->play_sample_rate = DEFSAMPLERATE; chip->play_channels = DEFCHANNELS; chip->capture_sample_size = DEFSAMPLESIZE; chip->capture_sample_rate = DEFSAMPLERATE; chip->capture_channels = DEFCHANNELS; } static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage) { switch (HIBYTE(wMessage)) { case HIMT_PLAY_DONE: { if (chip->banksPlayed < 3) snd_printdd("%08X: HIMT_PLAY_DONE: %i\n", (unsigned)jiffies, LOBYTE(wMessage)); if (chip->last_playbank == LOBYTE(wMessage)) { snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n"); break; } chip->banksPlayed++; if (test_bit(F_WRITING, &chip->flags)) snd_msnd_DAPQ(chip, 0); chip->last_playbank = LOBYTE(wMessage); chip->playDMAPos += chip->play_period_bytes; if (chip->playDMAPos > chip->playLimit) chip->playDMAPos = 0; snd_pcm_period_elapsed(chip->playback_substream); break; } case HIMT_RECORD_DONE: if (chip->last_recbank == LOBYTE(wMessage)) break; chip->last_recbank = LOBYTE(wMessage); chip->captureDMAPos += chip->capturePeriodBytes; if (chip->captureDMAPos > (chip->captureLimit)) chip->captureDMAPos = 0; if (test_bit(F_READING, &chip->flags)) snd_msnd_DARQ(chip, chip->last_recbank); snd_pcm_period_elapsed(chip->capture_substream); break; case HIMT_DSP: switch (LOBYTE(wMessage)) { #ifndef MSND_CLASSIC case HIDSP_PLAY_UNDER: #endif case HIDSP_INT_PLAY_UNDER: snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n", chip->banksPlayed); if (chip->banksPlayed > 2) clear_bit(F_WRITING, &chip->flags); break; case HIDSP_INT_RECORD_OVER: snd_printd(KERN_WARNING LOGNAME ": Record overflow\n"); clear_bit(F_READING, &chip->flags); break; default: snd_printd(KERN_WARNING LOGNAME ": DSP message %d 0x%02x\n", LOBYTE(wMessage), LOBYTE(wMessage)); break; } break; case HIMT_MIDI_IN_UCHAR: if (chip->msndmidi_mpu) snd_msndmidi_input_read(chip->msndmidi_mpu); break; default: snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); break; } } static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id) { struct snd_msnd *chip = dev_id; void *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF; /* Send ack to DSP */ /* inb(chip->io + HP_RXL); */ /* Evaluate queued DSP messages */ while (readw(chip->DSPQ + JQS_wTail) != readw(chip->DSPQ + JQS_wHead)) { u16 wTmp; snd_msnd_eval_dsp_msg(chip, readw(pwDSPQData + 2 * readw(chip->DSPQ + JQS_wHead))); wTmp = readw(chip->DSPQ + JQS_wHead) + 1; if (wTmp > readw(chip->DSPQ + JQS_wSize)) writew(0, chip->DSPQ + JQS_wHead); else writew(wTmp, chip->DSPQ + JQS_wHead); } /* Send ack to DSP */ inb(chip->io + HP_RXL); return IRQ_HANDLED; } static int snd_msnd_reset_dsp(long io, unsigned char *info) { int timeout = 100; outb(HPDSPRESET_ON, io + HP_DSPR); msleep(1); #ifndef MSND_CLASSIC if (info) *info = inb(io + HP_INFO); #endif outb(HPDSPRESET_OFF, io + HP_DSPR); msleep(1); while (timeout-- > 0) { if (inb(io + HP_CVR) == HP_CVR_DEF) return 0; msleep(1); } snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n"); return -EIO; } static int snd_msnd_probe(struct snd_card *card) { struct snd_msnd *chip = card->private_data; unsigned char info; #ifndef MSND_CLASSIC char *xv, *rev = NULL; char *pin = "TB Pinnacle", *fiji = "TB Fiji"; char *pinfiji = "TB Pinnacle/Fiji"; #endif if (!request_region(chip->io, DSP_NUMIO, "probing")) { snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n"); return -ENODEV; } if (snd_msnd_reset_dsp(chip->io, &info) < 0) { release_region(chip->io, DSP_NUMIO); return -ENODEV; } #ifdef MSND_CLASSIC strcpy(card->shortname, "Classic/Tahiti/Monterey"); strcpy(card->longname, "Turtle Beach Multisound"); printk(KERN_INFO LOGNAME ": %s, " "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n", card->shortname, chip->io, chip->io + DSP_NUMIO - 1, chip->irq, chip->base, chip->base + 0x7fff); #else switch (info >> 4) { case 0xf: xv = "<= 1.15"; break; case 0x1: xv = "1.18/1.2"; break; case 0x2: xv = "1.3"; break; case 0x3: xv = "1.4"; break; default: xv = "unknown"; break; } switch (info & 0x7) { case 0x0: rev = "I"; strcpy(card->shortname, pin); break; case 0x1: rev = "F"; strcpy(card->shortname, pin); break; case 0x2: rev = "G"; strcpy(card->shortname, pin); break; case 0x3: rev = "H"; strcpy(card->shortname, pin); break; case 0x4: rev = "E"; strcpy(card->shortname, fiji); break; case 0x5: rev = "C"; strcpy(card->shortname, fiji); break; case 0x6: rev = "D"; strcpy(card->shortname, fiji); break; case 0x7: rev = "A-B (Fiji) or A-E (Pinnacle)"; strcpy(card->shortname, pinfiji); break; } strcpy(card->longname, "Turtle Beach Multisound Pinnacle"); printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, " "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n", card->shortname, rev, xv, chip->io, chip->io + DSP_NUMIO - 1, chip->irq, chip->base, chip->base + 0x7fff); #endif release_region(chip->io, DSP_NUMIO); return 0; } static int snd_msnd_init_sma(struct snd_msnd *chip) { static int initted; u16 mastVolLeft, mastVolRight; unsigned long flags; #ifdef MSND_CLASSIC outb(chip->memid, chip->io + HP_MEMM); #endif outb(HPBLKSEL_0, chip->io + HP_BLKS); /* Motorola 56k shared memory base */ chip->SMA = chip->mappedbase + SMA_STRUCT_START; if (initted) { mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft); mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight); } else mastVolLeft = mastVolRight = 0; memset_io(chip->mappedbase, 0, 0x8000); /* Critical section: bank 1 access */ spin_lock_irqsave(&chip->lock, flags); outb(HPBLKSEL_1, chip->io + HP_BLKS); memset_io(chip->mappedbase, 0, 0x8000); outb(HPBLKSEL_0, chip->io + HP_BLKS); spin_unlock_irqrestore(&chip->lock, flags); /* Digital audio play queue */ chip->DAPQ = chip->mappedbase + DAPQ_OFFSET; snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE); /* Digital audio record queue */ chip->DARQ = chip->mappedbase + DARQ_OFFSET; snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE); /* MIDI out queue */ chip->MODQ = chip->mappedbase + MODQ_OFFSET; snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE); /* MIDI in queue */ chip->MIDQ = chip->mappedbase + MIDQ_OFFSET; snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE); /* DSP -> host message queue */ chip->DSPQ = chip->mappedbase + DSPQ_OFFSET; snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE); /* Setup some DSP values */ #ifndef MSND_CLASSIC writew(1, chip->SMA + SMA_wCurrPlayFormat); writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize); writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels); writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate); #endif writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD); writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft); writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight); #ifndef MSND_CLASSIC writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch); writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate); #endif writew(0x303, chip->SMA + SMA_wCurrInputTagBits); initted = 1; return 0; } static int upload_dsp_code(struct snd_card *card) { struct snd_msnd *chip = card->private_data; const struct firmware *init_fw = NULL, *perm_fw = NULL; int err; outb(HPBLKSEL_0, chip->io + HP_BLKS); err = request_firmware(&init_fw, INITCODEFILE, card->dev); if (err < 0) { printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE); goto cleanup1; } err = request_firmware(&perm_fw, PERMCODEFILE, card->dev); if (err < 0) { printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE); goto cleanup; } memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size); if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) { printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n"); err = -ENODEV; goto cleanup; } printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n"); err = 0; cleanup: release_firmware(perm_fw); cleanup1: release_firmware(init_fw); return err; } #ifdef MSND_CLASSIC static void reset_proteus(struct snd_msnd *chip) { outb(HPPRORESET_ON, chip->io + HP_PROR); msleep(TIME_PRO_RESET); outb(HPPRORESET_OFF, chip->io + HP_PROR); msleep(TIME_PRO_RESET_DONE); } #endif static int snd_msnd_initialize(struct snd_card *card) { struct snd_msnd *chip = card->private_data; int err, timeout; #ifdef MSND_CLASSIC outb(HPWAITSTATE_0, chip->io + HP_WAIT); outb(HPBITMODE_16, chip->io + HP_BITM); reset_proteus(chip); #endif err = snd_msnd_init_sma(chip); if (err < 0) { printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n"); return err; } err = snd_msnd_reset_dsp(chip->io, NULL); if (err < 0) return err; err = upload_dsp_code(card); if (err < 0) { printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n"); return err; } timeout = 200; while (readw(chip->mappedbase)) { msleep(1); if (!timeout--) { snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n"); return -EIO; } } snd_msndmix_setup(chip); return 0; } static int snd_msnd_dsp_full_reset(struct snd_card *card) { struct snd_msnd *chip = card->private_data; int rv; if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10) return 0; set_bit(F_RESETTING, &chip->flags); snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */ rv = snd_msnd_initialize(card); if (rv) printk(KERN_WARNING LOGNAME ": DSP reset failed\n"); snd_msndmix_force_recsrc(chip, 0); clear_bit(F_RESETTING, &chip->flags); return rv; } static int snd_msnd_dev_free(struct snd_device *device) { snd_printdd("snd_msnd_chip_free()\n"); return 0; } static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd) { if (snd_msnd_send_dsp_cmd(chip, cmd) == 0) return 0; snd_msnd_dsp_full_reset(chip->card); return snd_msnd_send_dsp_cmd(chip, cmd); } static int snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate) { snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate); writew(srate, chip->SMA + SMA_wCalFreqAtoD); if (chip->calibrate_signal == 0) writew(readw(chip->SMA + SMA_wCurrHostStatusFlags) | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags); else writew(readw(chip->SMA + SMA_wCurrHostStatusFlags) & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags); if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 && snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) { schedule_timeout_interruptible(msecs_to_jiffies(333)); return 0; } printk(KERN_WARNING LOGNAME ": ADC calibration failed\n"); return -EIO; } /* * ALSA callback function, called when attempting to open the MIDI device. */ static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu) { snd_msnd_enable_irq(mpu->private_data); snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START); return 0; } static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu) { snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP); snd_msnd_disable_irq(mpu->private_data); } static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; static int snd_msnd_attach(struct snd_card *card) { struct snd_msnd *chip = card->private_data; int err; static struct snd_device_ops ops = { .dev_free = snd_msnd_dev_free, }; err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname, chip); if (err < 0) { printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq); return err; } if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) { free_irq(chip->irq, chip); return -EBUSY; } if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) { printk(KERN_ERR LOGNAME ": unable to grab memory region 0x%lx-0x%lx\n", chip->base, chip->base + BUFFSIZE - 1); release_region(chip->io, DSP_NUMIO); free_irq(chip->irq, chip); return -EBUSY; } chip->mappedbase = ioremap_nocache(chip->base, 0x8000); if (!chip->mappedbase) { printk(KERN_ERR LOGNAME ": unable to map memory region 0x%lx-0x%lx\n", chip->base, chip->base + BUFFSIZE - 1); err = -EIO; goto err_release_region; } err = snd_msnd_dsp_full_reset(card); if (err < 0) goto err_release_region; /* Register device */ err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); if (err < 0) goto err_release_region; err = snd_msnd_pcm(card, 0, NULL); if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new PCM device\n"); goto err_release_region; } err = snd_msndmix_new(card); if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new Mixer device\n"); goto err_release_region; } if (mpu_io[0] != SNDRV_AUTO_PORT) { struct snd_mpu401 *mpu; err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, mpu_io[0], MPU401_MODE_INPUT | MPU401_MODE_OUTPUT, mpu_irq[0], &chip->rmidi); if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new Midi device\n"); goto err_release_region; } mpu = chip->rmidi->private_data; mpu->open_input = snd_msnd_mpu401_open; mpu->close_input = snd_msnd_mpu401_close; mpu->private_data = chip; } disable_irq(chip->irq); snd_msnd_calibrate_adc(chip, chip->play_sample_rate); snd_msndmix_force_recsrc(chip, 0); err = snd_card_register(card); if (err < 0) goto err_release_region; return 0; err_release_region: if (chip->mappedbase) iounmap(chip->mappedbase); release_mem_region(chip->base, BUFFSIZE); release_region(chip->io, DSP_NUMIO); free_irq(chip->irq, chip); return err; } static void snd_msnd_unload(struct snd_card *card) { struct snd_msnd *chip = card->private_data; iounmap(chip->mappedbase); release_mem_region(chip->base, BUFFSIZE); release_region(chip->io, DSP_NUMIO); free_irq(chip->irq, chip); snd_card_free(card); } #ifndef MSND_CLASSIC /* Pinnacle/Fiji Logical Device Configuration */ static int snd_msnd_write_cfg(int cfg, int reg, int value) { outb(reg, cfg); outb(value, cfg + 1); if (value != inb(cfg + 1)) { printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n"); return -EIO; } return 0; } static int snd_msnd_write_cfg_io0(int cfg, int num, u16 io) { if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io))) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io))) return -EIO; return 0; } static int snd_msnd_write_cfg_io1(int cfg, int num, u16 io) { if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io))) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io))) return -EIO; return 0; } static int snd_msnd_write_cfg_irq(int cfg, int num, u16 irq) { if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq))) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE)) return -EIO; return 0; } static int snd_msnd_write_cfg_mem(int cfg, int num, int mem) { u16 wmem; mem >>= 8; wmem = (u16)(mem & 0xfff); if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem))) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem))) return -EIO; if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL, MEMTYPE_HIADDR | MEMTYPE_16BIT)) return -EIO; return 0; } static int snd_msnd_activate_logical(int cfg, int num) { if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE)) return -EIO; return 0; } static int snd_msnd_write_cfg_logical(int cfg, int num, u16 io0, u16 io1, u16 irq, int mem) { if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) return -EIO; if (snd_msnd_write_cfg_io0(cfg, num, io0)) return -EIO; if (snd_msnd_write_cfg_io1(cfg, num, io1)) return -EIO; if (snd_msnd_write_cfg_irq(cfg, num, irq)) return -EIO; if (snd_msnd_write_cfg_mem(cfg, num, mem)) return -EIO; if (snd_msnd_activate_logical(cfg, num)) return -EIO; return 0; } static int snd_msnd_pinnacle_cfg_reset(int cfg) { int i; /* Reset devices if told to */ printk(KERN_INFO LOGNAME ": Resetting all devices\n"); for (i = 0; i < 4; ++i) if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0)) return -EIO; return 0; } #endif static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ module_param_array(index, int, NULL, S_IRUGO); MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard."); module_param_array(id, charp, NULL, S_IRUGO); MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard."); static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; #ifndef MSND_CLASSIC static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Extra Peripheral Configuration (Default: Disable) */ static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* If we have the digital daugherboard... */ static int digital[SNDRV_CARDS]; /* Extra Peripheral Configuration */ static int reset[SNDRV_CARDS]; #endif static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 }; static int calibrate_signal; #ifdef CONFIG_PNP static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; module_param_array(isapnp, bool, NULL, 0444); MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); #define has_isapnp(x) isapnp[x] #else #define has_isapnp(x) 0 #endif MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>"); MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver"); MODULE_LICENSE("GPL"); MODULE_FIRMWARE(INITCODEFILE); MODULE_FIRMWARE(PERMCODEFILE); module_param_array(io, long, NULL, S_IRUGO); MODULE_PARM_DESC(io, "IO port #"); module_param_array(irq, int, NULL, S_IRUGO); module_param_array(mem, long, NULL, S_IRUGO); module_param_array(write_ndelay, int, NULL, S_IRUGO); module_param(calibrate_signal, int, S_IRUGO); #ifndef MSND_CLASSIC module_param_array(digital, int, NULL, S_IRUGO); module_param_array(cfg, long, NULL, S_IRUGO); module_param_array(reset, int, 0, S_IRUGO); module_param_array(mpu_io, long, NULL, S_IRUGO); module_param_array(mpu_irq, int, NULL, S_IRUGO); module_param_array(ide_io0, long, NULL, S_IRUGO); module_param_array(ide_io1, long, NULL, S_IRUGO); module_param_array(ide_irq, int, NULL, S_IRUGO); module_param_array(joystick_io, long, NULL, S_IRUGO); #endif static int snd_msnd_isa_match(struct device *pdev, unsigned int i) { if (io[i] == SNDRV_AUTO_PORT) return 0; if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) { printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n"); return 0; } #ifdef MSND_CLASSIC if (!(io[i] == 0x290 || io[i] == 0x260 || io[i] == 0x250 || io[i] == 0x240 || io[i] == 0x230 || io[i] == 0x220 || io[i] == 0x210 || io[i] == 0x3e0)) { printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set " " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, " "or 0x3E0\n"); return 0; } #else if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) { printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 " "to 0x3E0 and must be evenly divisible by 0x10\n"); return 0; } #endif /* MSND_CLASSIC */ if (!(irq[i] == 5 || irq[i] == 7 || irq[i] == 9 || irq[i] == 10 || irq[i] == 11 || irq[i] == 12)) { printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n"); return 0; } if (!(mem[i] == 0xb0000 || mem[i] == 0xc8000 || mem[i] == 0xd0000 || mem[i] == 0xd8000 || mem[i] == 0xe0000 || mem[i] == 0xe8000)) { printk(KERN_ERR LOGNAME ": \"mem\" - must be set to " "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or " "0xe8000\n"); return 0; } #ifndef MSND_CLASSIC if (cfg[i] == SNDRV_AUTO_PORT) { printk(KERN_INFO LOGNAME ": Assuming PnP mode\n"); } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) { printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 " "(or unspecified for PnP mode)\n"); return 0; } #endif /* MSND_CLASSIC */ return 1; } static int snd_msnd_isa_probe(struct device *pdev, unsigned int idx) { int err; struct snd_card *card; struct snd_msnd *chip; if (has_isapnp(idx) #ifndef MSND_CLASSIC || cfg[idx] == SNDRV_AUTO_PORT #endif ) { printk(KERN_INFO LOGNAME ": Assuming PnP mode\n"); return -ENODEV; } err = snd_card_new(pdev, index[idx], id[idx], THIS_MODULE, sizeof(struct snd_msnd), &card); if (err < 0) return err; chip = card->private_data; chip->card = card; #ifdef MSND_CLASSIC switch (irq[idx]) { case 5: chip->irqid = HPIRQ_5; break; case 7: chip->irqid = HPIRQ_7; break; case 9: chip->irqid = HPIRQ_9; break; case 10: chip->irqid = HPIRQ_10; break; case 11: chip->irqid = HPIRQ_11; break; case 12: chip->irqid = HPIRQ_12; break; } switch (mem[idx]) { case 0xb0000: chip->memid = HPMEM_B000; break; case 0xc8000: chip->memid = HPMEM_C800; break; case 0xd0000: chip->memid = HPMEM_D000; break; case 0xd8000: chip->memid = HPMEM_D800; break; case 0xe0000: chip->memid = HPMEM_E000; break; case 0xe8000: chip->memid = HPMEM_E800; break; } #else printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n", cfg[idx]); if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) { printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n", cfg[idx]); snd_card_free(card); return -EIO; } if (reset[idx]) if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) { err = -EIO; goto cfg_error; } /* DSP */ err = snd_msnd_write_cfg_logical(cfg[idx], 0, io[idx], 0, irq[idx], mem[idx]); if (err) goto cfg_error; /* The following are Pinnacle specific */ /* MPU */ if (mpu_io[idx] != SNDRV_AUTO_PORT && mpu_irq[idx] != SNDRV_AUTO_IRQ) { printk(KERN_INFO LOGNAME ": Configuring MPU to I/O 0x%lx IRQ %d\n", mpu_io[idx], mpu_irq[idx]); err = snd_msnd_write_cfg_logical(cfg[idx], 1, mpu_io[idx], 0, mpu_irq[idx], 0); if (err) goto cfg_error; } /* IDE */ if (ide_io0[idx] != SNDRV_AUTO_PORT && ide_io1[idx] != SNDRV_AUTO_PORT && ide_irq[idx] != SNDRV_AUTO_IRQ) { printk(KERN_INFO LOGNAME ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n", ide_io0[idx], ide_io1[idx], ide_irq[idx]); err = snd_msnd_write_cfg_logical(cfg[idx], 2, ide_io0[idx], ide_io1[idx], ide_irq[idx], 0); if (err) goto cfg_error; } /* Joystick */ if (joystick_io[idx] != SNDRV_AUTO_PORT) { printk(KERN_INFO LOGNAME ": Configuring joystick to I/O 0x%lx\n", joystick_io[idx]); err = snd_msnd_write_cfg_logical(cfg[idx], 3, joystick_io[idx], 0, 0, 0); if (err) goto cfg_error; } release_region(cfg[idx], 2); #endif /* MSND_CLASSIC */ set_default_audio_parameters(chip); #ifdef MSND_CLASSIC chip->type = msndClassic; #else chip->type = msndPinnacle; #endif chip->io = io[idx]; chip->irq = irq[idx]; chip->base = mem[idx]; chip->calibrate_signal = calibrate_signal ? 1 : 0; chip->recsrc = 0; chip->dspq_data_buff = DSPQ_DATA_BUFF; chip->dspq_buff_size = DSPQ_BUFF_SIZE; if (write_ndelay[idx]) clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); else set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); #ifndef MSND_CLASSIC if (digital[idx]) set_bit(F_HAVEDIGITAL, &chip->flags); #endif spin_lock_init(&chip->lock); err = snd_msnd_probe(card); if (err < 0) { printk(KERN_ERR LOGNAME ": Probe failed\n"); snd_card_free(card); return err; } err = snd_msnd_attach(card); if (err < 0) { printk(KERN_ERR LOGNAME ": Attach failed\n"); snd_card_free(card); return err; } dev_set_drvdata(pdev, card); return 0; #ifndef MSND_CLASSIC cfg_error: release_region(cfg[idx], 2); snd_card_free(card); return err; #endif } static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev) { snd_msnd_unload(dev_get_drvdata(pdev)); return 0; } static struct isa_driver snd_msnd_driver = { .match = snd_msnd_isa_match, .probe = snd_msnd_isa_probe, .remove = snd_msnd_isa_remove, /* FIXME: suspend, resume */ .driver = { .name = DEV_NAME }, }; #ifdef CONFIG_PNP static int snd_msnd_pnp_detect(struct pnp_card_link *pcard, const struct pnp_card_device_id *pid) { static int idx; struct pnp_dev *pnp_dev; struct pnp_dev *mpu_dev; struct snd_card *card; struct snd_msnd *chip; int ret; for ( ; idx < SNDRV_CARDS; idx++) { if (has_isapnp(idx)) break; } if (idx >= SNDRV_CARDS) return -ENODEV; /* * Check that we still have room for another sound card ... */ pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); if (!pnp_dev) return -ENODEV; mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL); if (!mpu_dev) return -ENODEV; if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) { printk(KERN_INFO "msnd_pinnacle: device is inactive\n"); return -EBUSY; } if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) { printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n"); return -EBUSY; } /* * Create a new ALSA sound card entry, in anticipation * of detecting our hardware ... */ ret = snd_card_new(&pcard->card->dev, index[idx], id[idx], THIS_MODULE, sizeof(struct snd_msnd), &card); if (ret < 0) return ret; chip = card->private_data; chip->card = card; /* * Read the correct parameters off the ISA PnP bus ... */ io[idx] = pnp_port_start(pnp_dev, 0); irq[idx] = pnp_irq(pnp_dev, 0); mem[idx] = pnp_mem_start(pnp_dev, 0); mpu_io[idx] = pnp_port_start(mpu_dev, 0); mpu_irq[idx] = pnp_irq(mpu_dev, 0); set_default_audio_parameters(chip); #ifdef MSND_CLASSIC chip->type = msndClassic; #else chip->type = msndPinnacle; #endif chip->io = io[idx]; chip->irq = irq[idx]; chip->base = mem[idx]; chip->calibrate_signal = calibrate_signal ? 1 : 0; chip->recsrc = 0; chip->dspq_data_buff = DSPQ_DATA_BUFF; chip->dspq_buff_size = DSPQ_BUFF_SIZE; if (write_ndelay[idx]) clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); else set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); #ifndef MSND_CLASSIC if (digital[idx]) set_bit(F_HAVEDIGITAL, &chip->flags); #endif spin_lock_init(&chip->lock); ret = snd_msnd_probe(card); if (ret < 0) { printk(KERN_ERR LOGNAME ": Probe failed\n"); goto _release_card; } ret = snd_msnd_attach(card); if (ret < 0) { printk(KERN_ERR LOGNAME ": Attach failed\n"); goto _release_card; } pnp_set_card_drvdata(pcard, card); ++idx; return 0; _release_card: snd_card_free(card); return ret; } static void snd_msnd_pnp_remove(struct pnp_card_link *pcard) { snd_msnd_unload(pnp_get_card_drvdata(pcard)); pnp_set_card_drvdata(pcard, NULL); } static int isa_registered; static int pnp_registered; static struct pnp_card_device_id msnd_pnpids[] = { /* Pinnacle PnP */ { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } }, { .id = "" } /* end */ }; MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids); static struct pnp_card_driver msnd_pnpc_driver = { .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, .name = "msnd_pinnacle", .id_table = msnd_pnpids, .probe = snd_msnd_pnp_detect, .remove = snd_msnd_pnp_remove, }; #endif /* CONFIG_PNP */ static int __init snd_msnd_init(void) { int err; err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS); #ifdef CONFIG_PNP if (!err) isa_registered = 1; err = pnp_register_card_driver(&msnd_pnpc_driver); if (!err) pnp_registered = 1; if (isa_registered) err = 0; #endif return err; } static void __exit snd_msnd_exit(void) { #ifdef CONFIG_PNP if (pnp_registered) pnp_unregister_card_driver(&msnd_pnpc_driver); if (isa_registered) #endif isa_unregister_driver(&snd_msnd_driver); } module_init(snd_msnd_init); module_exit(snd_msnd_exit);
gpl-2.0
sim0629/linux-openwrt
drivers/video/fbmem.c
572
46605
/* * linux/drivers/video/fbmem.c * * Copyright (C) 1994 Martin Schaller * * 2001 - Documented with DocBook * - Brad Douglas <brad@neruo.com> * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. */ #include <linux/module.h> #include <linux/compat.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/slab.h> #include <linux/mm.h> #include <linux/mman.h> #include <linux/vt.h> #include <linux/init.h> #include <linux/linux_logo.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/console.h> #include <linux/kmod.h> #include <linux/err.h> #include <linux/device.h> #include <linux/efi.h> #include <linux/fb.h> #include <asm/fb.h> /* * Frame buffer device initialization and setup routines */ #define FBPIXMAPSIZE (1024 * 8) static DEFINE_MUTEX(registration_lock); struct fb_info *registered_fb[FB_MAX] __read_mostly; int num_registered_fb __read_mostly; static struct fb_info *get_fb_info(unsigned int idx) { struct fb_info *fb_info; if (idx >= FB_MAX) return ERR_PTR(-ENODEV); mutex_lock(&registration_lock); fb_info = registered_fb[idx]; if (fb_info) atomic_inc(&fb_info->count); mutex_unlock(&registration_lock); return fb_info; } static void put_fb_info(struct fb_info *fb_info) { if (!atomic_dec_and_test(&fb_info->count)) return; if (fb_info->fbops->fb_destroy) fb_info->fbops->fb_destroy(fb_info); } int lock_fb_info(struct fb_info *info) { mutex_lock(&info->lock); if (!info->fbops) { mutex_unlock(&info->lock); return 0; } return 1; } EXPORT_SYMBOL(lock_fb_info); /* * Helpers */ int fb_get_color_depth(struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix) { int depth = 0; if (fix->visual == FB_VISUAL_MONO01 || fix->visual == FB_VISUAL_MONO10) depth = 1; else { if (var->green.length == var->blue.length && var->green.length == var->red.length && var->green.offset == var->blue.offset && var->green.offset == var->red.offset) depth = var->green.length; else depth = var->green.length + var->red.length + var->blue.length; } return depth; } EXPORT_SYMBOL(fb_get_color_depth); /* * Data padding functions. */ void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height) { __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height); } EXPORT_SYMBOL(fb_pad_aligned_buffer); void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx, u32 height, u32 shift_high, u32 shift_low, u32 mod) { u8 mask = (u8) (0xfff << shift_high), tmp; int i, j; for (i = height; i--; ) { for (j = 0; j < idx; j++) { tmp = dst[j]; tmp &= mask; tmp |= *src >> shift_low; dst[j] = tmp; tmp = *src << shift_high; dst[j+1] = tmp; src++; } tmp = dst[idx]; tmp &= mask; tmp |= *src >> shift_low; dst[idx] = tmp; if (shift_high < mod) { tmp = *src << shift_high; dst[idx+1] = tmp; } src++; dst += d_pitch; } } EXPORT_SYMBOL(fb_pad_unaligned_buffer); /* * we need to lock this section since fb_cursor * may use fb_imageblit() */ char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size) { u32 align = buf->buf_align - 1, offset; char *addr = buf->addr; /* If IO mapped, we need to sync before access, no sharing of * the pixmap is done */ if (buf->flags & FB_PIXMAP_IO) { if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC)) info->fbops->fb_sync(info); return addr; } /* See if we fit in the remaining pixmap space */ offset = buf->offset + align; offset &= ~align; if (offset + size > buf->size) { /* We do not fit. In order to be able to re-use the buffer, * we must ensure no asynchronous DMA'ing or whatever operation * is in progress, we sync for that. */ if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC)) info->fbops->fb_sync(info); offset = 0; } buf->offset = offset + size; addr += offset; return addr; } #ifdef CONFIG_LOGO static inline unsigned safe_shift(unsigned d, int n) { return n < 0 ? d >> -n : d << n; } static void fb_set_logocmap(struct fb_info *info, const struct linux_logo *logo) { struct fb_cmap palette_cmap; u16 palette_green[16]; u16 palette_blue[16]; u16 palette_red[16]; int i, j, n; const unsigned char *clut = logo->clut; palette_cmap.start = 0; palette_cmap.len = 16; palette_cmap.red = palette_red; palette_cmap.green = palette_green; palette_cmap.blue = palette_blue; palette_cmap.transp = NULL; for (i = 0; i < logo->clutsize; i += n) { n = logo->clutsize - i; /* palette_cmap provides space for only 16 colors at once */ if (n > 16) n = 16; palette_cmap.start = 32 + i; palette_cmap.len = n; for (j = 0; j < n; ++j) { palette_cmap.red[j] = clut[0] << 8 | clut[0]; palette_cmap.green[j] = clut[1] << 8 | clut[1]; palette_cmap.blue[j] = clut[2] << 8 | clut[2]; clut += 3; } fb_set_cmap(&palette_cmap, info); } } static void fb_set_logo_truepalette(struct fb_info *info, const struct linux_logo *logo, u32 *palette) { static const unsigned char mask[] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff }; unsigned char redmask, greenmask, bluemask; int redshift, greenshift, blueshift; int i; const unsigned char *clut = logo->clut; /* * We have to create a temporary palette since console palette is only * 16 colors long. */ /* Bug: Doesn't obey msb_right ... (who needs that?) */ redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8]; greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8]; bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8]; redshift = info->var.red.offset - (8 - info->var.red.length); greenshift = info->var.green.offset - (8 - info->var.green.length); blueshift = info->var.blue.offset - (8 - info->var.blue.length); for ( i = 0; i < logo->clutsize; i++) { palette[i+32] = (safe_shift((clut[0] & redmask), redshift) | safe_shift((clut[1] & greenmask), greenshift) | safe_shift((clut[2] & bluemask), blueshift)); clut += 3; } } static void fb_set_logo_directpalette(struct fb_info *info, const struct linux_logo *logo, u32 *palette) { int redshift, greenshift, blueshift; int i; redshift = info->var.red.offset; greenshift = info->var.green.offset; blueshift = info->var.blue.offset; for (i = 32; i < 32 + logo->clutsize; i++) palette[i] = i << redshift | i << greenshift | i << blueshift; } static void fb_set_logo(struct fb_info *info, const struct linux_logo *logo, u8 *dst, int depth) { int i, j, k; const u8 *src = logo->data; u8 xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0; u8 fg = 1, d; switch (fb_get_color_depth(&info->var, &info->fix)) { case 1: fg = 1; break; case 2: fg = 3; break; default: fg = 7; break; } if (info->fix.visual == FB_VISUAL_MONO01 || info->fix.visual == FB_VISUAL_MONO10) fg = ~((u8) (0xfff << info->var.green.length)); switch (depth) { case 4: for (i = 0; i < logo->height; i++) for (j = 0; j < logo->width; src++) { *dst++ = *src >> 4; j++; if (j < logo->width) { *dst++ = *src & 0x0f; j++; } } break; case 1: for (i = 0; i < logo->height; i++) { for (j = 0; j < logo->width; src++) { d = *src ^ xor; for (k = 7; k >= 0; k--) { *dst++ = ((d >> k) & 1) ? fg : 0; j++; } } } break; } } /* * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors), * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on * the visual format and color depth of the framebuffer, the DAC, the * pseudo_palette, and the logo data will be adjusted accordingly. * * Case 1 - linux_logo_clut224: * Color exceeds the number of console colors (16), thus we set the hardware DAC * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set. * * For visuals that require color info from the pseudo_palette, we also construct * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags * will be set. * * Case 2 - linux_logo_vga16: * The number of colors just matches the console colors, thus there is no need * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie, * each byte contains color information for two pixels (upper and lower nibble). * To be consistent with fb_imageblit() usage, we therefore separate the two * nibbles into separate bytes. The "depth" flag will be set to 4. * * Case 3 - linux_logo_mono: * This is similar with Case 2. Each byte contains information for 8 pixels. * We isolate each bit and expand each into a byte. The "depth" flag will * be set to 1. */ static struct logo_data { int depth; int needs_directpalette; int needs_truepalette; int needs_cmapreset; const struct linux_logo *logo; } fb_logo __read_mostly; static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height) { u32 size = width * height, i; out += size - 1; for (i = size; i--; ) *out-- = *in++; } static void fb_rotate_logo_cw(const u8 *in, u8 *out, u32 width, u32 height) { int i, j, h = height - 1; for (i = 0; i < height; i++) for (j = 0; j < width; j++) out[height * j + h - i] = *in++; } static void fb_rotate_logo_ccw(const u8 *in, u8 *out, u32 width, u32 height) { int i, j, w = width - 1; for (i = 0; i < height; i++) for (j = 0; j < width; j++) out[height * (w - j) + i] = *in++; } static void fb_rotate_logo(struct fb_info *info, u8 *dst, struct fb_image *image, int rotate) { u32 tmp; if (rotate == FB_ROTATE_UD) { fb_rotate_logo_ud(image->data, dst, image->width, image->height); image->dx = info->var.xres - image->width - image->dx; image->dy = info->var.yres - image->height - image->dy; } else if (rotate == FB_ROTATE_CW) { fb_rotate_logo_cw(image->data, dst, image->width, image->height); tmp = image->width; image->width = image->height; image->height = tmp; tmp = image->dy; image->dy = image->dx; image->dx = info->var.xres - image->width - tmp; } else if (rotate == FB_ROTATE_CCW) { fb_rotate_logo_ccw(image->data, dst, image->width, image->height); tmp = image->width; image->width = image->height; image->height = tmp; tmp = image->dx; image->dx = image->dy; image->dy = info->var.yres - image->height - tmp; } image->data = dst; } static void fb_do_show_logo(struct fb_info *info, struct fb_image *image, int rotate, unsigned int num) { unsigned int x; if (rotate == FB_ROTATE_UR) { for (x = 0; x < num && image->dx + image->width <= info->var.xres; x++) { info->fbops->fb_imageblit(info, image); image->dx += image->width + 8; } } else if (rotate == FB_ROTATE_UD) { for (x = 0; x < num && image->dx >= 0; x++) { info->fbops->fb_imageblit(info, image); image->dx -= image->width + 8; } } else if (rotate == FB_ROTATE_CW) { for (x = 0; x < num && image->dy + image->height <= info->var.yres; x++) { info->fbops->fb_imageblit(info, image); image->dy += image->height + 8; } } else if (rotate == FB_ROTATE_CCW) { for (x = 0; x < num && image->dy >= 0; x++) { info->fbops->fb_imageblit(info, image); image->dy -= image->height + 8; } } } static int fb_show_logo_line(struct fb_info *info, int rotate, const struct linux_logo *logo, int y, unsigned int n) { u32 *palette = NULL, *saved_pseudo_palette = NULL; unsigned char *logo_new = NULL, *logo_rotate = NULL; struct fb_image image; /* Return if the frame buffer is not mapped or suspended */ if (logo == NULL || info->state != FBINFO_STATE_RUNNING || info->flags & FBINFO_MODULE) return 0; image.depth = 8; image.data = logo->data; if (fb_logo.needs_cmapreset) fb_set_logocmap(info, logo); if (fb_logo.needs_truepalette || fb_logo.needs_directpalette) { palette = kmalloc(256 * 4, GFP_KERNEL); if (palette == NULL) return 0; if (fb_logo.needs_truepalette) fb_set_logo_truepalette(info, logo, palette); else fb_set_logo_directpalette(info, logo, palette); saved_pseudo_palette = info->pseudo_palette; info->pseudo_palette = palette; } if (fb_logo.depth <= 4) { logo_new = kmalloc(logo->width * logo->height, GFP_KERNEL); if (logo_new == NULL) { kfree(palette); if (saved_pseudo_palette) info->pseudo_palette = saved_pseudo_palette; return 0; } image.data = logo_new; fb_set_logo(info, logo, logo_new, fb_logo.depth); } image.dx = 0; image.dy = y; image.width = logo->width; image.height = logo->height; if (rotate) { logo_rotate = kmalloc(logo->width * logo->height, GFP_KERNEL); if (logo_rotate) fb_rotate_logo(info, logo_rotate, &image, rotate); } fb_do_show_logo(info, &image, rotate, n); kfree(palette); if (saved_pseudo_palette != NULL) info->pseudo_palette = saved_pseudo_palette; kfree(logo_new); kfree(logo_rotate); return logo->height; } #ifdef CONFIG_FB_LOGO_EXTRA #define FB_LOGO_EX_NUM_MAX 10 static struct logo_data_extra { const struct linux_logo *logo; unsigned int n; } fb_logo_ex[FB_LOGO_EX_NUM_MAX]; static unsigned int fb_logo_ex_num; void fb_append_extra_logo(const struct linux_logo *logo, unsigned int n) { if (!n || fb_logo_ex_num == FB_LOGO_EX_NUM_MAX) return; fb_logo_ex[fb_logo_ex_num].logo = logo; fb_logo_ex[fb_logo_ex_num].n = n; fb_logo_ex_num++; } static int fb_prepare_extra_logos(struct fb_info *info, unsigned int height, unsigned int yres) { unsigned int i; /* FIXME: logo_ex supports only truecolor fb. */ if (info->fix.visual != FB_VISUAL_TRUECOLOR) fb_logo_ex_num = 0; for (i = 0; i < fb_logo_ex_num; i++) { if (fb_logo_ex[i].logo->type != fb_logo.logo->type) { fb_logo_ex[i].logo = NULL; continue; } height += fb_logo_ex[i].logo->height; if (height > yres) { height -= fb_logo_ex[i].logo->height; fb_logo_ex_num = i; break; } } return height; } static int fb_show_extra_logos(struct fb_info *info, int y, int rotate) { unsigned int i; for (i = 0; i < fb_logo_ex_num; i++) y += fb_show_logo_line(info, rotate, fb_logo_ex[i].logo, y, fb_logo_ex[i].n); return y; } #else /* !CONFIG_FB_LOGO_EXTRA */ static inline int fb_prepare_extra_logos(struct fb_info *info, unsigned int height, unsigned int yres) { return height; } static inline int fb_show_extra_logos(struct fb_info *info, int y, int rotate) { return y; } #endif /* CONFIG_FB_LOGO_EXTRA */ int fb_prepare_logo(struct fb_info *info, int rotate) { int depth = fb_get_color_depth(&info->var, &info->fix); unsigned int yres; memset(&fb_logo, 0, sizeof(struct logo_data)); if (info->flags & FBINFO_MISC_TILEBLITTING || info->flags & FBINFO_MODULE) return 0; if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { depth = info->var.blue.length; if (info->var.red.length < depth) depth = info->var.red.length; if (info->var.green.length < depth) depth = info->var.green.length; } if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR && depth > 4) { /* assume console colormap */ depth = 4; } /* Return if no suitable logo was found */ fb_logo.logo = fb_find_logo(depth); if (!fb_logo.logo) { return 0; } if (rotate == FB_ROTATE_UR || rotate == FB_ROTATE_UD) yres = info->var.yres; else yres = info->var.xres; if (fb_logo.logo->height > yres) { fb_logo.logo = NULL; return 0; } /* What depth we asked for might be different from what we get */ if (fb_logo.logo->type == LINUX_LOGO_CLUT224) fb_logo.depth = 8; else if (fb_logo.logo->type == LINUX_LOGO_VGA16) fb_logo.depth = 4; else fb_logo.depth = 1; if (fb_logo.depth > 4 && depth > 4) { switch (info->fix.visual) { case FB_VISUAL_TRUECOLOR: fb_logo.needs_truepalette = 1; break; case FB_VISUAL_DIRECTCOLOR: fb_logo.needs_directpalette = 1; fb_logo.needs_cmapreset = 1; break; case FB_VISUAL_PSEUDOCOLOR: fb_logo.needs_cmapreset = 1; break; } } return fb_prepare_extra_logos(info, fb_logo.logo->height, yres); } int fb_show_logo(struct fb_info *info, int rotate) { int y; y = fb_show_logo_line(info, rotate, fb_logo.logo, 0, num_online_cpus()); y = fb_show_extra_logos(info, y, rotate); return y; } #else int fb_prepare_logo(struct fb_info *info, int rotate) { return 0; } int fb_show_logo(struct fb_info *info, int rotate) { return 0; } #endif /* CONFIG_LOGO */ static void *fb_seq_start(struct seq_file *m, loff_t *pos) { mutex_lock(&registration_lock); return (*pos < FB_MAX) ? pos : NULL; } static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos) { (*pos)++; return (*pos < FB_MAX) ? pos : NULL; } static void fb_seq_stop(struct seq_file *m, void *v) { mutex_unlock(&registration_lock); } static int fb_seq_show(struct seq_file *m, void *v) { int i = *(loff_t *)v; struct fb_info *fi = registered_fb[i]; if (fi) seq_printf(m, "%d %s\n", fi->node, fi->fix.id); return 0; } static const struct seq_operations proc_fb_seq_ops = { .start = fb_seq_start, .next = fb_seq_next, .stop = fb_seq_stop, .show = fb_seq_show, }; static int proc_fb_open(struct inode *inode, struct file *file) { return seq_open(file, &proc_fb_seq_ops); } static const struct file_operations fb_proc_fops = { .owner = THIS_MODULE, .open = proc_fb_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; /* * We hold a reference to the fb_info in file->private_data, * but if the current registered fb has changed, we don't * actually want to use it. * * So look up the fb_info using the inode minor number, * and just verify it against the reference we have. */ static struct fb_info *file_fb_info(struct file *file) { struct inode *inode = file_inode(file); int fbidx = iminor(inode); struct fb_info *info = registered_fb[fbidx]; if (info != file->private_data) info = NULL; return info; } static ssize_t fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; struct fb_info *info = file_fb_info(file); u8 *buffer, *dst; u8 __iomem *src; int c, cnt = 0, err = 0; unsigned long total_size; if (!info || ! info->screen_base) return -ENODEV; if (info->state != FBINFO_STATE_RUNNING) return -EPERM; if (info->fbops->fb_read) return info->fbops->fb_read(info, buf, count, ppos); total_size = info->screen_size; if (total_size == 0) total_size = info->fix.smem_len; if (p >= total_size) return 0; if (count >= total_size) count = total_size; if (count + p > total_size) count = total_size - p; buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL); if (!buffer) return -ENOMEM; src = (u8 __iomem *) (info->screen_base + p); if (info->fbops->fb_sync) info->fbops->fb_sync(info); while (count) { c = (count > PAGE_SIZE) ? PAGE_SIZE : count; dst = buffer; fb_memcpy_fromfb(dst, src, c); dst += c; src += c; if (copy_to_user(buf, buffer, c)) { err = -EFAULT; break; } *ppos += c; buf += c; cnt += c; count -= c; } kfree(buffer); return (err) ? err : cnt; } static ssize_t fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; struct fb_info *info = file_fb_info(file); u8 *buffer, *src; u8 __iomem *dst; int c, cnt = 0, err = 0; unsigned long total_size; if (!info || !info->screen_base) return -ENODEV; if (info->state != FBINFO_STATE_RUNNING) return -EPERM; if (info->fbops->fb_write) return info->fbops->fb_write(info, buf, count, ppos); total_size = info->screen_size; if (total_size == 0) total_size = info->fix.smem_len; if (p > total_size) return -EFBIG; if (count > total_size) { err = -EFBIG; count = total_size; } if (count + p > total_size) { if (!err) err = -ENOSPC; count = total_size - p; } buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL); if (!buffer) return -ENOMEM; dst = (u8 __iomem *) (info->screen_base + p); if (info->fbops->fb_sync) info->fbops->fb_sync(info); while (count) { c = (count > PAGE_SIZE) ? PAGE_SIZE : count; src = buffer; if (copy_from_user(src, buf, c)) { err = -EFAULT; break; } fb_memcpy_tofb(dst, src, c); dst += c; src += c; *ppos += c; buf += c; cnt += c; count -= c; } kfree(buffer); return (cnt) ? cnt : err; } int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) { struct fb_fix_screeninfo *fix = &info->fix; unsigned int yres = info->var.yres; int err = 0; if (var->yoffset > 0) { if (var->vmode & FB_VMODE_YWRAP) { if (!fix->ywrapstep || (var->yoffset % fix->ywrapstep)) err = -EINVAL; else yres = 0; } else if (!fix->ypanstep || (var->yoffset % fix->ypanstep)) err = -EINVAL; } if (var->xoffset > 0 && (!fix->xpanstep || (var->xoffset % fix->xpanstep))) err = -EINVAL; if (err || !info->fbops->fb_pan_display || var->yoffset > info->var.yres_virtual - yres || var->xoffset > info->var.xres_virtual - info->var.xres) return -EINVAL; if ((err = info->fbops->fb_pan_display(var, info))) return err; info->var.xoffset = var->xoffset; info->var.yoffset = var->yoffset; if (var->vmode & FB_VMODE_YWRAP) info->var.vmode |= FB_VMODE_YWRAP; else info->var.vmode &= ~FB_VMODE_YWRAP; return 0; } static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var, u32 activate) { struct fb_event event; struct fb_blit_caps caps, fbcaps; int err = 0; memset(&caps, 0, sizeof(caps)); memset(&fbcaps, 0, sizeof(fbcaps)); caps.flags = (activate & FB_ACTIVATE_ALL) ? 1 : 0; event.info = info; event.data = &caps; fb_notifier_call_chain(FB_EVENT_GET_REQ, &event); info->fbops->fb_get_caps(info, &fbcaps, var); if (((fbcaps.x ^ caps.x) & caps.x) || ((fbcaps.y ^ caps.y) & caps.y) || (fbcaps.len < caps.len)) err = -EINVAL; return err; } int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) { int flags = info->flags; int ret = 0; if (var->activate & FB_ACTIVATE_INV_MODE) { struct fb_videomode mode1, mode2; fb_var_to_videomode(&mode1, var); fb_var_to_videomode(&mode2, &info->var); /* make sure we don't delete the videomode of current var */ ret = fb_mode_is_equal(&mode1, &mode2); if (!ret) { struct fb_event event; event.info = info; event.data = &mode1; ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event); } if (!ret) fb_delete_videomode(&mode1, &info->modelist); ret = (ret) ? -EINVAL : 0; goto done; } if ((var->activate & FB_ACTIVATE_FORCE) || memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) { u32 activate = var->activate; /* When using FOURCC mode, make sure the red, green, blue and * transp fields are set to 0. */ if ((info->fix.capabilities & FB_CAP_FOURCC) && var->grayscale > 1) { if (var->red.offset || var->green.offset || var->blue.offset || var->transp.offset || var->red.length || var->green.length || var->blue.length || var->transp.length || var->red.msb_right || var->green.msb_right || var->blue.msb_right || var->transp.msb_right) return -EINVAL; } if (!info->fbops->fb_check_var) { *var = info->var; goto done; } ret = info->fbops->fb_check_var(var, info); if (ret) goto done; if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { struct fb_var_screeninfo old_var; struct fb_videomode mode; if (info->fbops->fb_get_caps) { ret = fb_check_caps(info, var, activate); if (ret) goto done; } old_var = info->var; info->var = *var; if (info->fbops->fb_set_par) { ret = info->fbops->fb_set_par(info); if (ret) { info->var = old_var; printk(KERN_WARNING "detected " "fb_set_par error, " "error code: %d\n", ret); goto done; } } fb_pan_display(info, &info->var); fb_set_cmap(&info->cmap, info); fb_var_to_videomode(&mode, &info->var); if (info->modelist.prev && info->modelist.next && !list_empty(&info->modelist)) ret = fb_add_videomode(&mode, &info->modelist); if (!ret && (flags & FBINFO_MISC_USEREVENT)) { struct fb_event event; int evnt = (activate & FB_ACTIVATE_ALL) ? FB_EVENT_MODE_CHANGE_ALL : FB_EVENT_MODE_CHANGE; info->flags &= ~FBINFO_MISC_USEREVENT; event.info = info; event.data = &mode; fb_notifier_call_chain(evnt, &event); } } } done: return ret; } int fb_blank(struct fb_info *info, int blank) { struct fb_event event; int ret = -EINVAL, early_ret; if (blank > FB_BLANK_POWERDOWN) blank = FB_BLANK_POWERDOWN; event.info = info; event.data = &blank; early_ret = fb_notifier_call_chain(FB_EARLY_EVENT_BLANK, &event); if (info->fbops->fb_blank) ret = info->fbops->fb_blank(blank, info); if (!ret) fb_notifier_call_chain(FB_EVENT_BLANK, &event); else { /* * if fb_blank is failed then revert effects of * the early blank event. */ if (!early_ret) fb_notifier_call_chain(FB_R_EARLY_EVENT_BLANK, &event); } return ret; } static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { struct fb_ops *fb; struct fb_var_screeninfo var; struct fb_fix_screeninfo fix; struct fb_con2fbmap con2fb; struct fb_cmap cmap_from; struct fb_cmap_user cmap; struct fb_event event; void __user *argp = (void __user *)arg; long ret = 0; switch (cmd) { case FBIOGET_VSCREENINFO: if (!lock_fb_info(info)) return -ENODEV; var = info->var; unlock_fb_info(info); ret = copy_to_user(argp, &var, sizeof(var)) ? -EFAULT : 0; break; case FBIOPUT_VSCREENINFO: if (copy_from_user(&var, argp, sizeof(var))) return -EFAULT; if (!lock_fb_info(info)) return -ENODEV; console_lock(); info->flags |= FBINFO_MISC_USEREVENT; ret = fb_set_var(info, &var); info->flags &= ~FBINFO_MISC_USEREVENT; console_unlock(); unlock_fb_info(info); if (!ret && copy_to_user(argp, &var, sizeof(var))) ret = -EFAULT; break; case FBIOGET_FSCREENINFO: if (!lock_fb_info(info)) return -ENODEV; fix = info->fix; unlock_fb_info(info); ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0; break; case FBIOPUTCMAP: if (copy_from_user(&cmap, argp, sizeof(cmap))) return -EFAULT; ret = fb_set_user_cmap(&cmap, info); break; case FBIOGETCMAP: if (copy_from_user(&cmap, argp, sizeof(cmap))) return -EFAULT; if (!lock_fb_info(info)) return -ENODEV; cmap_from = info->cmap; unlock_fb_info(info); ret = fb_cmap_to_user(&cmap_from, &cmap); break; case FBIOPAN_DISPLAY: if (copy_from_user(&var, argp, sizeof(var))) return -EFAULT; if (!lock_fb_info(info)) return -ENODEV; console_lock(); ret = fb_pan_display(info, &var); console_unlock(); unlock_fb_info(info); if (ret == 0 && copy_to_user(argp, &var, sizeof(var))) return -EFAULT; break; case FBIO_CURSOR: ret = -EINVAL; break; case FBIOGET_CON2FBMAP: if (copy_from_user(&con2fb, argp, sizeof(con2fb))) return -EFAULT; if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) return -EINVAL; con2fb.framebuffer = -1; event.data = &con2fb; if (!lock_fb_info(info)) return -ENODEV; event.info = info; fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event); unlock_fb_info(info); ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0; break; case FBIOPUT_CON2FBMAP: if (copy_from_user(&con2fb, argp, sizeof(con2fb))) return -EFAULT; if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) return -EINVAL; if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) return -EINVAL; if (!registered_fb[con2fb.framebuffer]) request_module("fb%d", con2fb.framebuffer); if (!registered_fb[con2fb.framebuffer]) { ret = -EINVAL; break; } event.data = &con2fb; if (!lock_fb_info(info)) return -ENODEV; console_lock(); event.info = info; ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event); console_unlock(); unlock_fb_info(info); break; case FBIOBLANK: if (!lock_fb_info(info)) return -ENODEV; console_lock(); info->flags |= FBINFO_MISC_USEREVENT; ret = fb_blank(info, arg); info->flags &= ~FBINFO_MISC_USEREVENT; console_unlock(); unlock_fb_info(info); break; default: if (!lock_fb_info(info)) return -ENODEV; fb = info->fbops; if (fb->fb_ioctl) ret = fb->fb_ioctl(info, cmd, arg); else ret = -ENOTTY; unlock_fb_info(info); } return ret; } static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct fb_info *info = file_fb_info(file); if (!info) return -ENODEV; return do_fb_ioctl(info, cmd, arg); } #ifdef CONFIG_COMPAT struct fb_fix_screeninfo32 { char id[16]; compat_caddr_t smem_start; u32 smem_len; u32 type; u32 type_aux; u32 visual; u16 xpanstep; u16 ypanstep; u16 ywrapstep; u32 line_length; compat_caddr_t mmio_start; u32 mmio_len; u32 accel; u16 reserved[3]; }; struct fb_cmap32 { u32 start; u32 len; compat_caddr_t red; compat_caddr_t green; compat_caddr_t blue; compat_caddr_t transp; }; static int fb_getput_cmap(struct fb_info *info, unsigned int cmd, unsigned long arg) { struct fb_cmap_user __user *cmap; struct fb_cmap32 __user *cmap32; __u32 data; int err; cmap = compat_alloc_user_space(sizeof(*cmap)); cmap32 = compat_ptr(arg); if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32))) return -EFAULT; if (get_user(data, &cmap32->red) || put_user(compat_ptr(data), &cmap->red) || get_user(data, &cmap32->green) || put_user(compat_ptr(data), &cmap->green) || get_user(data, &cmap32->blue) || put_user(compat_ptr(data), &cmap->blue) || get_user(data, &cmap32->transp) || put_user(compat_ptr(data), &cmap->transp)) return -EFAULT; err = do_fb_ioctl(info, cmd, (unsigned long) cmap); if (!err) { if (copy_in_user(&cmap32->start, &cmap->start, 2 * sizeof(__u32))) err = -EFAULT; } return err; } static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix, struct fb_fix_screeninfo32 __user *fix32) { __u32 data; int err; err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id)); data = (__u32) (unsigned long) fix->smem_start; err |= put_user(data, &fix32->smem_start); err |= put_user(fix->smem_len, &fix32->smem_len); err |= put_user(fix->type, &fix32->type); err |= put_user(fix->type_aux, &fix32->type_aux); err |= put_user(fix->visual, &fix32->visual); err |= put_user(fix->xpanstep, &fix32->xpanstep); err |= put_user(fix->ypanstep, &fix32->ypanstep); err |= put_user(fix->ywrapstep, &fix32->ywrapstep); err |= put_user(fix->line_length, &fix32->line_length); data = (__u32) (unsigned long) fix->mmio_start; err |= put_user(data, &fix32->mmio_start); err |= put_user(fix->mmio_len, &fix32->mmio_len); err |= put_user(fix->accel, &fix32->accel); err |= copy_to_user(fix32->reserved, fix->reserved, sizeof(fix->reserved)); return err; } static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs; struct fb_fix_screeninfo fix; struct fb_fix_screeninfo32 __user *fix32; int err; fix32 = compat_ptr(arg); old_fs = get_fs(); set_fs(KERNEL_DS); err = do_fb_ioctl(info, cmd, (unsigned long) &fix); set_fs(old_fs); if (!err) err = do_fscreeninfo_to_user(&fix, fix32); return err; } static long fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct fb_info *info = file_fb_info(file); struct fb_ops *fb; long ret = -ENOIOCTLCMD; if (!info) return -ENODEV; fb = info->fbops; switch(cmd) { case FBIOGET_VSCREENINFO: case FBIOPUT_VSCREENINFO: case FBIOPAN_DISPLAY: case FBIOGET_CON2FBMAP: case FBIOPUT_CON2FBMAP: arg = (unsigned long) compat_ptr(arg); case FBIOBLANK: ret = do_fb_ioctl(info, cmd, arg); break; case FBIOGET_FSCREENINFO: ret = fb_get_fscreeninfo(info, cmd, arg); break; case FBIOGETCMAP: case FBIOPUTCMAP: ret = fb_getput_cmap(info, cmd, arg); break; default: if (fb->fb_compat_ioctl) ret = fb->fb_compat_ioctl(info, cmd, arg); break; } return ret; } #endif static int fb_mmap(struct file *file, struct vm_area_struct * vma) { struct fb_info *info = file_fb_info(file); struct fb_ops *fb; unsigned long mmio_pgoff; unsigned long start; u32 len; if (!info) return -ENODEV; fb = info->fbops; if (!fb) return -ENODEV; mutex_lock(&info->mm_lock); if (fb->fb_mmap) { int res; res = fb->fb_mmap(info, vma); mutex_unlock(&info->mm_lock); return res; } /* * Ugh. This can be either the frame buffer mapping, or * if pgoff points past it, the mmio mapping. */ start = info->fix.smem_start; len = info->fix.smem_len; mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT; if (vma->vm_pgoff >= mmio_pgoff) { if (info->var.accel_flags) { mutex_unlock(&info->mm_lock); return -EINVAL; } vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; } mutex_unlock(&info->mm_lock); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); fb_pgprotect(file, vma, start); return vm_iomap_memory(vma, start, len); } static int fb_open(struct inode *inode, struct file *file) __acquires(&info->lock) __releases(&info->lock) { int fbidx = iminor(inode); struct fb_info *info; int res = 0; info = get_fb_info(fbidx); if (!info) { request_module("fb%d", fbidx); info = get_fb_info(fbidx); if (!info) return -ENODEV; } if (IS_ERR(info)) return PTR_ERR(info); mutex_lock(&info->lock); if (!try_module_get(info->fbops->owner)) { res = -ENODEV; goto out; } file->private_data = info; if (info->fbops->fb_open) { res = info->fbops->fb_open(info,1); if (res) module_put(info->fbops->owner); } #ifdef CONFIG_FB_DEFERRED_IO if (info->fbdefio) fb_deferred_io_open(info, inode, file); #endif out: mutex_unlock(&info->lock); if (res) put_fb_info(info); return res; } static int fb_release(struct inode *inode, struct file *file) __acquires(&info->lock) __releases(&info->lock) { struct fb_info * const info = file->private_data; mutex_lock(&info->lock); if (info->fbops->fb_release) info->fbops->fb_release(info,1); module_put(info->fbops->owner); mutex_unlock(&info->lock); put_fb_info(info); return 0; } static const struct file_operations fb_fops = { .owner = THIS_MODULE, .read = fb_read, .write = fb_write, .unlocked_ioctl = fb_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = fb_compat_ioctl, #endif .mmap = fb_mmap, .open = fb_open, .release = fb_release, #ifdef HAVE_ARCH_FB_UNMAPPED_AREA .get_unmapped_area = get_fb_unmapped_area, #endif #ifdef CONFIG_FB_DEFERRED_IO .fsync = fb_deferred_io_fsync, #endif .llseek = default_llseek, }; struct class *fb_class; EXPORT_SYMBOL(fb_class); static int fb_check_foreignness(struct fb_info *fi) { const bool foreign_endian = fi->flags & FBINFO_FOREIGN_ENDIAN; fi->flags &= ~FBINFO_FOREIGN_ENDIAN; #ifdef __BIG_ENDIAN fi->flags |= foreign_endian ? 0 : FBINFO_BE_MATH; #else fi->flags |= foreign_endian ? FBINFO_BE_MATH : 0; #endif /* __BIG_ENDIAN */ if (fi->flags & FBINFO_BE_MATH && !fb_be_math(fi)) { pr_err("%s: enable CONFIG_FB_BIG_ENDIAN to " "support this framebuffer\n", fi->fix.id); return -ENOSYS; } else if (!(fi->flags & FBINFO_BE_MATH) && fb_be_math(fi)) { pr_err("%s: enable CONFIG_FB_LITTLE_ENDIAN to " "support this framebuffer\n", fi->fix.id); return -ENOSYS; } return 0; } static bool apertures_overlap(struct aperture *gen, struct aperture *hw) { /* is the generic aperture base the same as the HW one */ if (gen->base == hw->base) return true; /* is the generic aperture base inside the hw base->hw base+size */ if (gen->base > hw->base && gen->base < hw->base + hw->size) return true; return false; } static bool fb_do_apertures_overlap(struct apertures_struct *gena, struct apertures_struct *hwa) { int i, j; if (!hwa || !gena) return false; for (i = 0; i < hwa->count; ++i) { struct aperture *h = &hwa->ranges[i]; for (j = 0; j < gena->count; ++j) { struct aperture *g = &gena->ranges[j]; printk(KERN_DEBUG "checking generic (%llx %llx) vs hw (%llx %llx)\n", (unsigned long long)g->base, (unsigned long long)g->size, (unsigned long long)h->base, (unsigned long long)h->size); if (apertures_overlap(g, h)) return true; } } return false; } static int do_unregister_framebuffer(struct fb_info *fb_info); #define VGA_FB_PHYS 0xA0000 static void do_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { int i; /* check all firmware fbs and kick off if the base addr overlaps */ for (i = 0 ; i < FB_MAX; i++) { struct apertures_struct *gen_aper; if (!registered_fb[i]) continue; if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE)) continue; gen_aper = registered_fb[i]->apertures; if (fb_do_apertures_overlap(gen_aper, a) || (primary && gen_aper && gen_aper->count && gen_aper->ranges[0].base == VGA_FB_PHYS)) { printk(KERN_INFO "fb: conflicting fb hw usage " "%s vs %s - removing generic driver\n", name, registered_fb[i]->fix.id); do_unregister_framebuffer(registered_fb[i]); } } } static int do_register_framebuffer(struct fb_info *fb_info) { int i; struct fb_event event; struct fb_videomode mode; if (fb_check_foreignness(fb_info)) return -ENOSYS; do_remove_conflicting_framebuffers(fb_info->apertures, fb_info->fix.id, fb_is_primary_device(fb_info)); if (num_registered_fb == FB_MAX) return -ENXIO; num_registered_fb++; for (i = 0 ; i < FB_MAX; i++) if (!registered_fb[i]) break; fb_info->node = i; atomic_set(&fb_info->count, 1); mutex_init(&fb_info->lock); mutex_init(&fb_info->mm_lock); fb_info->dev = device_create(fb_class, fb_info->device, MKDEV(FB_MAJOR, i), NULL, "fb%d", i); if (IS_ERR(fb_info->dev)) { /* Not fatal */ printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev)); fb_info->dev = NULL; } else fb_init_device(fb_info); if (fb_info->pixmap.addr == NULL) { fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL); if (fb_info->pixmap.addr) { fb_info->pixmap.size = FBPIXMAPSIZE; fb_info->pixmap.buf_align = 1; fb_info->pixmap.scan_align = 1; fb_info->pixmap.access_align = 32; fb_info->pixmap.flags = FB_PIXMAP_DEFAULT; } } fb_info->pixmap.offset = 0; if (!fb_info->pixmap.blit_x) fb_info->pixmap.blit_x = ~(u32)0; if (!fb_info->pixmap.blit_y) fb_info->pixmap.blit_y = ~(u32)0; if (!fb_info->modelist.prev || !fb_info->modelist.next) INIT_LIST_HEAD(&fb_info->modelist); if (fb_info->skip_vt_switch) pm_vt_switch_required(fb_info->dev, false); else pm_vt_switch_required(fb_info->dev, true); fb_var_to_videomode(&mode, &fb_info->var); fb_add_videomode(&mode, &fb_info->modelist); registered_fb[i] = fb_info; event.info = fb_info; if (!lock_fb_info(fb_info)) return -ENODEV; console_lock(); fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event); console_unlock(); unlock_fb_info(fb_info); return 0; } static int do_unregister_framebuffer(struct fb_info *fb_info) { struct fb_event event; int i, ret = 0; i = fb_info->node; if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info) return -EINVAL; if (!lock_fb_info(fb_info)) return -ENODEV; console_lock(); event.info = fb_info; ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event); console_unlock(); unlock_fb_info(fb_info); if (ret) return -EINVAL; pm_vt_switch_unregister(fb_info->dev); unlink_framebuffer(fb_info); if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT)) kfree(fb_info->pixmap.addr); fb_destroy_modelist(&fb_info->modelist); registered_fb[i] = NULL; num_registered_fb--; fb_cleanup_device(fb_info); event.info = fb_info; console_lock(); fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event); console_unlock(); /* this may free fb info */ put_fb_info(fb_info); return 0; } int unlink_framebuffer(struct fb_info *fb_info) { int i; i = fb_info->node; if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info) return -EINVAL; if (fb_info->dev) { device_destroy(fb_class, MKDEV(FB_MAJOR, i)); fb_info->dev = NULL; } return 0; } EXPORT_SYMBOL(unlink_framebuffer); void remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { mutex_lock(&registration_lock); do_remove_conflicting_framebuffers(a, name, primary); mutex_unlock(&registration_lock); } EXPORT_SYMBOL(remove_conflicting_framebuffers); /** * register_framebuffer - registers a frame buffer device * @fb_info: frame buffer info structure * * Registers a frame buffer device @fb_info. * * Returns negative errno on error, or zero for success. * */ int register_framebuffer(struct fb_info *fb_info) { int ret; mutex_lock(&registration_lock); ret = do_register_framebuffer(fb_info); mutex_unlock(&registration_lock); return ret; } /** * unregister_framebuffer - releases a frame buffer device * @fb_info: frame buffer info structure * * Unregisters a frame buffer device @fb_info. * * Returns negative errno on error, or zero for success. * * This function will also notify the framebuffer console * to release the driver. * * This is meant to be called within a driver's module_exit() * function. If this is called outside module_exit(), ensure * that the driver implements fb_open() and fb_release() to * check that no processes are using the device. */ int unregister_framebuffer(struct fb_info *fb_info) { int ret; mutex_lock(&registration_lock); ret = do_unregister_framebuffer(fb_info); mutex_unlock(&registration_lock); return ret; } /** * fb_set_suspend - low level driver signals suspend * @info: framebuffer affected * @state: 0 = resuming, !=0 = suspending * * This is meant to be used by low level drivers to * signal suspend/resume to the core & clients. * It must be called with the console semaphore held */ void fb_set_suspend(struct fb_info *info, int state) { struct fb_event event; event.info = info; if (state) { fb_notifier_call_chain(FB_EVENT_SUSPEND, &event); info->state = FBINFO_STATE_SUSPENDED; } else { info->state = FBINFO_STATE_RUNNING; fb_notifier_call_chain(FB_EVENT_RESUME, &event); } } /** * fbmem_init - init frame buffer subsystem * * Initialize the frame buffer subsystem. * * NOTE: This function is _only_ to be called by drivers/char/mem.c. * */ static int __init fbmem_init(void) { proc_create("fb", 0, NULL, &fb_proc_fops); if (register_chrdev(FB_MAJOR,"fb",&fb_fops)) printk("unable to get major %d for fb devs\n", FB_MAJOR); fb_class = class_create(THIS_MODULE, "graphics"); if (IS_ERR(fb_class)) { printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class)); fb_class = NULL; } return 0; } #ifdef MODULE module_init(fbmem_init); static void __exit fbmem_exit(void) { remove_proc_entry("fb", NULL); class_destroy(fb_class); unregister_chrdev(FB_MAJOR, "fb"); } module_exit(fbmem_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Framebuffer base"); #else subsys_initcall(fbmem_init); #endif int fb_new_modelist(struct fb_info *info) { struct fb_event event; struct fb_var_screeninfo var = info->var; struct list_head *pos, *n; struct fb_modelist *modelist; struct fb_videomode *m, mode; int err = 1; list_for_each_safe(pos, n, &info->modelist) { modelist = list_entry(pos, struct fb_modelist, list); m = &modelist->mode; fb_videomode_to_var(&var, m); var.activate = FB_ACTIVATE_TEST; err = fb_set_var(info, &var); fb_var_to_videomode(&mode, &var); if (err || !fb_mode_is_equal(m, &mode)) { list_del(pos); kfree(pos); } } err = 1; if (!list_empty(&info->modelist)) { event.info = info; err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event); } return err; } static char *video_options[FB_MAX] __read_mostly; static int ofonly __read_mostly; /** * fb_get_options - get kernel boot parameters * @name: framebuffer name as it would appear in * the boot parameter line * (video=<name>:<options>) * @option: the option will be stored here * * NOTE: Needed to maintain backwards compatibility */ int fb_get_options(char *name, char **option) { char *opt, *options = NULL; int retval = 0; int name_len = strlen(name), i; if (name_len && ofonly && strncmp(name, "offb", 4)) retval = 1; if (name_len && !retval) { for (i = 0; i < FB_MAX; i++) { if (video_options[i] == NULL) continue; if (!video_options[i][0]) continue; opt = video_options[i]; if (!strncmp(name, opt, name_len) && opt[name_len] == ':') options = opt + name_len + 1; } } if (options && !strncmp(options, "off", 3)) retval = 1; if (option) *option = options; return retval; } #ifndef MODULE /** * video_setup - process command line options * @options: string of options * * Process command line options for frame buffer subsystem. * * NOTE: This function is a __setup and __init function. * It only stores the options. Drivers have to call * fb_get_options() as necessary. * * Returns zero. * */ static int __init video_setup(char *options) { int i, global = 0; if (!options || !*options) global = 1; if (!global && !strncmp(options, "ofonly", 6)) { ofonly = 1; global = 1; } if (!global && !strchr(options, ':')) { fb_mode_option = options; global = 1; } if (!global) { for (i = 0; i < FB_MAX; i++) { if (video_options[i] == NULL) { video_options[i] = options; break; } } } return 1; } __setup("video=", video_setup); #endif /* * Visible symbols for modules */ EXPORT_SYMBOL(register_framebuffer); EXPORT_SYMBOL(unregister_framebuffer); EXPORT_SYMBOL(num_registered_fb); EXPORT_SYMBOL(registered_fb); EXPORT_SYMBOL(fb_show_logo); EXPORT_SYMBOL(fb_set_var); EXPORT_SYMBOL(fb_blank); EXPORT_SYMBOL(fb_pan_display); EXPORT_SYMBOL(fb_get_buffer_offset); EXPORT_SYMBOL(fb_set_suspend); EXPORT_SYMBOL(fb_get_options); MODULE_LICENSE("GPL");
gpl-2.0
stratosk/semaphore
arch/arm/mach-pxa/e400.c
828
3829
/* * Hardware definitions for the Toshiba eseries PDAs * * Copyright (c) 2003 Ian Molton <spyro@f2s.com> * * This file is licensed under * the terms of the GNU General Public License version 2. This program * is licensed "as is" without any warranty of any kind, whether express * or implied. * */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/clk.h> #include <linux/platform_device.h> #include <linux/mfd/t7l66xb.h> #include <linux/mtd/nand.h> #include <linux/mtd/partitions.h> #include <asm/setup.h> #include <asm/mach/arch.h> #include <asm/mach-types.h> #include <mach/pxa25x.h> #include <mach/eseries-gpio.h> #include <mach/pxafb.h> #include <mach/udc.h> #include <mach/irqs.h> #include "generic.h" #include "eseries.h" #include "clock.h" /* ------------------------ E400 LCD definitions ------------------------ */ static struct pxafb_mode_info e400_pxafb_mode_info = { .pixclock = 140703, .xres = 240, .yres = 320, .bpp = 16, .hsync_len = 4, .left_margin = 28, .right_margin = 8, .vsync_len = 3, .upper_margin = 5, .lower_margin = 6, .sync = 0, }; static struct pxafb_mach_info e400_pxafb_mach_info = { .modes = &e400_pxafb_mode_info, .num_modes = 1, .lcd_conn = LCD_COLOR_TFT_16BPP, .lccr3 = 0, .pxafb_backlight_power = NULL, }; /* ------------------------ E400 MFP config ----------------------------- */ static unsigned long e400_pin_config[] __initdata = { /* Chip selects */ GPIO15_nCS_1, /* CS1 - Flash */ GPIO80_nCS_4, /* CS4 - TMIO */ /* Clocks */ GPIO12_32KHz, /* BTUART */ GPIO42_BTUART_RXD, GPIO43_BTUART_TXD, GPIO44_BTUART_CTS, /* TMIO controller */ GPIO19_GPIO, /* t7l66xb #PCLR */ GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */ /* wakeup */ GPIO0_GPIO | WAKEUP_ON_EDGE_RISE, }; /* ---------------------------------------------------------------------- */ static struct mtd_partition partition_a = { .name = "Internal NAND flash", .offset = 0, .size = MTDPART_SIZ_FULL, }; static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; static struct nand_bbt_descr e400_t7l66xb_nand_bbt = { .options = 0, .offs = 4, .len = 2, .pattern = scan_ff_pattern }; static struct tmio_nand_data e400_t7l66xb_nand_config = { .num_partitions = 1, .partition = &partition_a, .badblock_pattern = &e400_t7l66xb_nand_bbt, }; static struct t7l66xb_platform_data e400_t7l66xb_info = { .irq_base = IRQ_BOARD_START, .enable = &eseries_tmio_enable, .suspend = &eseries_tmio_suspend, .resume = &eseries_tmio_resume, .nand_data = &e400_t7l66xb_nand_config, }; static struct platform_device e400_t7l66xb_device = { .name = "t7l66xb", .id = -1, .dev = { .platform_data = &e400_t7l66xb_info, }, .num_resources = 2, .resource = eseries_tmio_resources, }; /* ---------------------------------------------------------- */ static struct platform_device *devices[] __initdata = { &e400_t7l66xb_device, }; static void __init e400_init(void) { pxa2xx_mfp_config(ARRAY_AND_SIZE(e400_pin_config)); pxa_set_ffuart_info(NULL); pxa_set_btuart_info(NULL); pxa_set_stuart_info(NULL); /* Fixme - e400 may have a switched clock */ eseries_register_clks(); eseries_get_tmio_gpios(); set_pxa_fb_info(&e400_pxafb_mach_info); platform_add_devices(devices, ARRAY_SIZE(devices)); pxa_set_udc_info(&e7xx_udc_mach_info); } MACHINE_START(E400, "Toshiba e400") /* Maintainer: Ian Molton (spyro@f2s.com) */ .phys_io = 0x40000000, .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, .boot_params = 0xa0000100, .map_io = pxa_map_io, .init_irq = pxa25x_init_irq, .fixup = eseries_fixup, .init_machine = e400_init, .timer = &pxa_timer, MACHINE_END
gpl-2.0
ehigh2014/linux
lib/decompress_unxz.c
1084
10899
/* * Wrapper for decompressing XZ-compressed kernel, initramfs, and initrd * * Author: Lasse Collin <lasse.collin@tukaani.org> * * This file has been put into the public domain. * You can do whatever you want with this file. */ /* * Important notes about in-place decompression * * At least on x86, the kernel is decompressed in place: the compressed data * is placed to the end of the output buffer, and the decompressor overwrites * most of the compressed data. There must be enough safety margin to * guarantee that the write position is always behind the read position. * * The safety margin for XZ with LZMA2 or BCJ+LZMA2 is calculated below. * Note that the margin with XZ is bigger than with Deflate (gzip)! * * The worst case for in-place decompression is that the beginning of * the file is compressed extremely well, and the rest of the file is * uncompressible. Thus, we must look for worst-case expansion when the * compressor is encoding uncompressible data. * * The structure of the .xz file in case of a compresed kernel is as follows. * Sizes (as bytes) of the fields are in parenthesis. * * Stream Header (12) * Block Header: * Block Header (8-12) * Compressed Data (N) * Block Padding (0-3) * CRC32 (4) * Index (8-20) * Stream Footer (12) * * Normally there is exactly one Block, but let's assume that there are * 2-4 Blocks just in case. Because Stream Header and also Block Header * of the first Block don't make the decompressor produce any uncompressed * data, we can ignore them from our calculations. Block Headers of possible * additional Blocks have to be taken into account still. With these * assumptions, it is safe to assume that the total header overhead is * less than 128 bytes. * * Compressed Data contains LZMA2 or BCJ+LZMA2 encoded data. Since BCJ * doesn't change the size of the data, it is enough to calculate the * safety margin for LZMA2. * * LZMA2 stores the data in chunks. Each chunk has a header whose size is * a maximum of 6 bytes, but to get round 2^n numbers, let's assume that * the maximum chunk header size is 8 bytes. After the chunk header, there * may be up to 64 KiB of actual payload in the chunk. Often the payload is * quite a bit smaller though; to be safe, let's assume that an average * chunk has only 32 KiB of payload. * * The maximum uncompressed size of the payload is 2 MiB. The minimum * uncompressed size of the payload is in practice never less than the * payload size itself. The LZMA2 format would allow uncompressed size * to be less than the payload size, but no sane compressor creates such * files. LZMA2 supports storing uncompressible data in uncompressed form, * so there's never a need to create payloads whose uncompressed size is * smaller than the compressed size. * * The assumption, that the uncompressed size of the payload is never * smaller than the payload itself, is valid only when talking about * the payload as a whole. It is possible that the payload has parts where * the decompressor consumes more input than it produces output. Calculating * the worst case for this would be tricky. Instead of trying to do that, * let's simply make sure that the decompressor never overwrites any bytes * of the payload which it is currently reading. * * Now we have enough information to calculate the safety margin. We need * - 128 bytes for the .xz file format headers; * - 8 bytes per every 32 KiB of uncompressed size (one LZMA2 chunk header * per chunk, each chunk having average payload size of 32 KiB); and * - 64 KiB (biggest possible LZMA2 chunk payload size) to make sure that * the decompressor never overwrites anything from the LZMA2 chunk * payload it is currently reading. * * We get the following formula: * * safety_margin = 128 + uncompressed_size * 8 / 32768 + 65536 * = 128 + (uncompressed_size >> 12) + 65536 * * For comparison, according to arch/x86/boot/compressed/misc.c, the * equivalent formula for Deflate is this: * * safety_margin = 18 + (uncompressed_size >> 12) + 32768 * * Thus, when updating Deflate-only in-place kernel decompressor to * support XZ, the fixed overhead has to be increased from 18+32768 bytes * to 128+65536 bytes. */ /* * STATIC is defined to "static" if we are being built for kernel * decompression (pre-boot code). <linux/decompress/mm.h> will define * STATIC to empty if it wasn't already defined. Since we will need to * know later if we are being used for kernel decompression, we define * XZ_PREBOOT here. */ #ifdef STATIC # define XZ_PREBOOT #endif #ifdef __KERNEL__ # include <linux/decompress/mm.h> #endif #define XZ_EXTERN STATIC #ifndef XZ_PREBOOT # include <linux/slab.h> # include <linux/xz.h> #else /* * Use the internal CRC32 code instead of kernel's CRC32 module, which * is not available in early phase of booting. */ #define XZ_INTERNAL_CRC32 1 /* * For boot time use, we enable only the BCJ filter of the current * architecture or none if no BCJ filter is available for the architecture. */ #ifdef CONFIG_X86 # define XZ_DEC_X86 #endif #ifdef CONFIG_PPC # define XZ_DEC_POWERPC #endif #ifdef CONFIG_ARM # define XZ_DEC_ARM #endif #ifdef CONFIG_IA64 # define XZ_DEC_IA64 #endif #ifdef CONFIG_SPARC # define XZ_DEC_SPARC #endif /* * This will get the basic headers so that memeq() and others * can be defined. */ #include "xz/xz_private.h" /* * Replace the normal allocation functions with the versions from * <linux/decompress/mm.h>. vfree() needs to support vfree(NULL) * when XZ_DYNALLOC is used, but the pre-boot free() doesn't support it. * Workaround it here because the other decompressors don't need it. */ #undef kmalloc #undef kfree #undef vmalloc #undef vfree #define kmalloc(size, flags) malloc(size) #define kfree(ptr) free(ptr) #define vmalloc(size) malloc(size) #define vfree(ptr) do { if (ptr != NULL) free(ptr); } while (0) /* * FIXME: Not all basic memory functions are provided in architecture-specific * files (yet). We define our own versions here for now, but this should be * only a temporary solution. * * memeq and memzero are not used much and any remotely sane implementation * is fast enough. memcpy/memmove speed matters in multi-call mode, but * the kernel image is decompressed in single-call mode, in which only * memcpy speed can matter and only if there is a lot of uncompressible data * (LZMA2 stores uncompressible chunks in uncompressed form). Thus, the * functions below should just be kept small; it's probably not worth * optimizing for speed. */ #ifndef memeq static bool memeq(const void *a, const void *b, size_t size) { const uint8_t *x = a; const uint8_t *y = b; size_t i; for (i = 0; i < size; ++i) if (x[i] != y[i]) return false; return true; } #endif #ifndef memzero static void memzero(void *buf, size_t size) { uint8_t *b = buf; uint8_t *e = b + size; while (b != e) *b++ = '\0'; } #endif #ifndef memmove /* Not static to avoid a conflict with the prototype in the Linux headers. */ void *memmove(void *dest, const void *src, size_t size) { uint8_t *d = dest; const uint8_t *s = src; size_t i; if (d < s) { for (i = 0; i < size; ++i) d[i] = s[i]; } else if (d > s) { i = size; while (i-- > 0) d[i] = s[i]; } return dest; } #endif /* * Since we need memmove anyway, would use it as memcpy too. * Commented out for now to avoid breaking things. */ /* #ifndef memcpy # define memcpy memmove #endif */ #include "xz/xz_crc32.c" #include "xz/xz_dec_stream.c" #include "xz/xz_dec_lzma2.c" #include "xz/xz_dec_bcj.c" #endif /* XZ_PREBOOT */ /* Size of the input and output buffers in multi-call mode */ #define XZ_IOBUF_SIZE 4096 /* * This function implements the API defined in <linux/decompress/generic.h>. * * This wrapper will automatically choose single-call or multi-call mode * of the native XZ decoder API. The single-call mode can be used only when * both input and output buffers are available as a single chunk, i.e. when * fill() and flush() won't be used. */ STATIC int INIT unxz(unsigned char *in, long in_size, long (*fill)(void *dest, unsigned long size), long (*flush)(void *src, unsigned long size), unsigned char *out, long *in_used, void (*error)(char *x)) { struct xz_buf b; struct xz_dec *s; enum xz_ret ret; bool must_free_in = false; #if XZ_INTERNAL_CRC32 xz_crc32_init(); #endif if (in_used != NULL) *in_used = 0; if (fill == NULL && flush == NULL) s = xz_dec_init(XZ_SINGLE, 0); else s = xz_dec_init(XZ_DYNALLOC, (uint32_t)-1); if (s == NULL) goto error_alloc_state; if (flush == NULL) { b.out = out; b.out_size = (size_t)-1; } else { b.out_size = XZ_IOBUF_SIZE; b.out = malloc(XZ_IOBUF_SIZE); if (b.out == NULL) goto error_alloc_out; } if (in == NULL) { must_free_in = true; in = malloc(XZ_IOBUF_SIZE); if (in == NULL) goto error_alloc_in; } b.in = in; b.in_pos = 0; b.in_size = in_size; b.out_pos = 0; if (fill == NULL && flush == NULL) { ret = xz_dec_run(s, &b); } else { do { if (b.in_pos == b.in_size && fill != NULL) { if (in_used != NULL) *in_used += b.in_pos; b.in_pos = 0; in_size = fill(in, XZ_IOBUF_SIZE); if (in_size < 0) { /* * This isn't an optimal error code * but it probably isn't worth making * a new one either. */ ret = XZ_BUF_ERROR; break; } b.in_size = in_size; } ret = xz_dec_run(s, &b); if (flush != NULL && (b.out_pos == b.out_size || (ret != XZ_OK && b.out_pos > 0))) { /* * Setting ret here may hide an error * returned by xz_dec_run(), but probably * it's not too bad. */ if (flush(b.out, b.out_pos) != (long)b.out_pos) ret = XZ_BUF_ERROR; b.out_pos = 0; } } while (ret == XZ_OK); if (must_free_in) free(in); if (flush != NULL) free(b.out); } if (in_used != NULL) *in_used += b.in_pos; xz_dec_end(s); switch (ret) { case XZ_STREAM_END: return 0; case XZ_MEM_ERROR: /* This can occur only in multi-call mode. */ error("XZ decompressor ran out of memory"); break; case XZ_FORMAT_ERROR: error("Input is not in the XZ format (wrong magic bytes)"); break; case XZ_OPTIONS_ERROR: error("Input was encoded with settings that are not " "supported by this XZ decoder"); break; case XZ_DATA_ERROR: case XZ_BUF_ERROR: error("XZ-compressed data is corrupt"); break; default: error("Bug in the XZ decompressor"); break; } return -1; error_alloc_in: if (flush != NULL) free(b.out); error_alloc_out: xz_dec_end(s); error_alloc_state: error("XZ decompressor ran out of memory"); return -1; } /* * This macro is used by architecture-specific files to decompress * the kernel image. */ #define decompress unxz
gpl-2.0
fortunave3gxx/android_kernel_samsung_fortuna-common
drivers/staging/serqt_usb2/serqt_usb2.c
1596
39102
/* * This code was developed for the Quatech USB line for linux, it used * much of the code developed by Greg Kroah-Hartman for USB serial devices * */ #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/tty.h> #include <linux/tty_driver.h> #include <linux/tty_flip.h> #include <linux/module.h> #include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <linux/uaccess.h> /* Version Information */ #define DRIVER_VERSION "v2.14" #define DRIVER_AUTHOR "Tim Gobeli, Quatech, Inc" #define DRIVER_DESC "Quatech USB to Serial Driver" #define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */ #define QUATECH_SSU200 0xC030 /* SSU200 */ #define QUATECH_DSU100 0xC040 /* DSU100 */ #define QUATECH_DSU200 0xC050 /* DSU200 */ #define QUATECH_QSU100 0xC060 /* QSU100 */ #define QUATECH_QSU200 0xC070 /* QSU200 */ #define QUATECH_ESU100A 0xC080 /* ESU100A */ #define QUATECH_ESU100B 0xC081 /* ESU100B */ #define QUATECH_ESU200A 0xC0A0 /* ESU200A */ #define QUATECH_ESU200B 0xC0A1 /* ESU200B */ #define QUATECH_HSU100A 0xC090 /* HSU100A */ #define QUATECH_HSU100B 0xC091 /* HSU100B */ #define QUATECH_HSU100C 0xC092 /* HSU100C */ #define QUATECH_HSU100D 0xC093 /* HSU100D */ #define QUATECH_HSU200A 0xC0B0 /* HSU200A */ #define QUATECH_HSU200B 0xC0B1 /* HSU200B */ #define QUATECH_HSU200C 0xC0B2 /* HSU200C */ #define QUATECH_HSU200D 0xC0B3 /* HSU200D */ #define QT_SET_GET_DEVICE 0xc2 #define QT_OPEN_CLOSE_CHANNEL 0xca #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc #define QT_SET_ATF 0xcd #define QT_GET_SET_REGISTER 0xc0 #define QT_GET_SET_UART 0xc1 #define QT_HW_FLOW_CONTROL_MASK 0xc5 #define QT_SW_FLOW_CONTROL_MASK 0xc6 #define QT_SW_FLOW_CONTROL_DISABLE 0xc7 #define QT_BREAK_CONTROL 0xc8 #define USBD_TRANSFER_DIRECTION_IN 0xc0 #define USBD_TRANSFER_DIRECTION_OUT 0x40 #define MAX_BAUD_RATE 460800 #define MAX_BAUD_REMAINDER 4608 #define DIV_LATCH_LS 0x00 #define XMT_HOLD_REGISTER 0x00 #define XVR_BUFFER_REGISTER 0x00 #define DIV_LATCH_MS 0x01 #define FIFO_CONTROL_REGISTER 0x02 #define LINE_CONTROL_REGISTER 0x03 #define MODEM_CONTROL_REGISTER 0x04 #define LINE_STATUS_REGISTER 0x05 #define MODEM_STATUS_REGISTER 0x06 #define SERIAL_MCR_DTR 0x01 #define SERIAL_MCR_RTS 0x02 #define SERIAL_MCR_LOOP 0x10 #define SERIAL_MSR_CTS 0x10 #define SERIAL_MSR_CD 0x80 #define SERIAL_MSR_RI 0x40 #define SERIAL_MSR_DSR 0x20 #define SERIAL_MSR_MASK 0xf0 #define SERIAL_8_DATA 0x03 #define SERIAL_7_DATA 0x02 #define SERIAL_6_DATA 0x01 #define SERIAL_5_DATA 0x00 #define SERIAL_ODD_PARITY 0X08 #define SERIAL_EVEN_PARITY 0X18 #define SERIAL_TWO_STOPB 0x04 #define SERIAL_ONE_STOPB 0x00 #define DEFAULT_DIVISOR 0x30 /* gives 9600 baud rate */ #define DEFAULT_LCR SERIAL_8_DATA /* 8, none , 1 */ #define FULLPWRBIT 0x00000080 #define NEXT_BOARD_POWER_BIT 0x00000004 #define SERIAL_LSR_OE 0x02 #define SERIAL_LSR_PE 0x04 #define SERIAL_LSR_FE 0x08 #define SERIAL_LSR_BI 0x10 #define SERIAL_MSR_CTS 0x10 #define SERIAL_MSR_CD 0x80 #define SERIAL_MSR_RI 0x40 #define SERIAL_MSR_DSR 0x20 #define SERIAL_MSR_MASK 0xf0 #define PREFUFF_LEVEL_CONSERVATIVE 128 #define ATC_DISABLED 0x0 #define RR_BITS 0x03 /* for clearing clock bits */ #define DUPMODE_BITS 0xc0 #define CLKS_X4 0x02 #define LOOPMODE_BITS 0x41 /* LOOP1 = b6, LOOP0 = b0 (PORT B) */ #define ALL_LOOPBACK 0x01 #define MODEM_CTRL 0x40 #define RS232_MODE 0x00 static const struct usb_device_id id_table[] = { {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU200)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU100)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU200)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU100)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU200)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU100A)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU100B)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU200A)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU200B)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU100A)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU100B)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU100C)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU100D)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200A)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200B)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200C)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200D)}, {} /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, id_table); struct qt_get_device_data { __u8 porta; __u8 portb; __u8 portc; }; struct qt_open_channel_data { __u8 line_status; __u8 modem_status; }; struct quatech_port { int port_num; /* number of the port */ struct urb *write_urb; /* write URB for this port */ struct urb *read_urb; /* read URB for this port */ struct urb *int_urb; __u8 shadowLCR; /* last LCR value received */ __u8 shadowMCR; /* last MCR value received */ __u8 shadowMSR; /* last MSR value received */ __u8 shadowLSR; /* last LSR value received */ char open_ports; /* Used for TIOCMIWAIT */ wait_queue_head_t msr_wait; char prev_status, diff_status; wait_queue_head_t wait; struct async_icount icount; struct usb_serial_port *port; /* owner of this object */ struct qt_get_device_data DeviceData; struct mutex lock; bool read_urb_busy; int RxHolding; int ReadBulkStopped; char closePending; }; static int port_paranoia_check(struct usb_serial_port *port, const char *function) { if (!port) { pr_debug("%s - port == NULL", function); return -1; } if (!port->serial) { pr_debug("%s - port->serial == NULL\n", function); return -1; } return 0; } static int serial_paranoia_check(struct usb_serial *serial, const char *function) { if (!serial) { pr_debug("%s - serial == NULL\n", function); return -1; } if (!serial->type) { pr_debug("%s - serial->type == NULL!", function); return -1; } return 0; } static inline struct quatech_port *qt_get_port_private(struct usb_serial_port *port) { return (struct quatech_port *)usb_get_serial_port_data(port); } static inline void qt_set_port_private(struct usb_serial_port *port, struct quatech_port *data) { usb_set_serial_port_data(port, (void *)data); } static struct usb_serial *get_usb_serial(struct usb_serial_port *port, const char *function) { /* if no port was specified, or it fails a paranoia check */ if (!port || port_paranoia_check(port, function) || serial_paranoia_check(port->serial, function)) { /* * then say that we dont have a valid usb_serial thing, * which will end up genrating -ENODEV return values */ return NULL; } return port->serial; } static void ProcessLineStatus(struct quatech_port *qt_port, unsigned char line_status) { qt_port->shadowLSR = line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); } static void ProcessModemStatus(struct quatech_port *qt_port, unsigned char modem_status) { qt_port->shadowMSR = modem_status; wake_up_interruptible(&qt_port->wait); } static void ProcessRxChar(struct usb_serial_port *port, unsigned char data) { struct urb *urb = port->read_urb; if (urb->actual_length) tty_insert_flip_char(&port->port, data, TTY_NORMAL); } static void qt_write_bulk_callback(struct urb *urb) { int status; struct quatech_port *quatech_port; status = urb->status; if (status) { dev_dbg(&urb->dev->dev, "nonzero write bulk status received:%d\n", status); return; } quatech_port = urb->context; tty_port_tty_wakeup(&quatech_port->port->port); } static void qt_interrupt_callback(struct urb *urb) { /* FIXME */ } static void qt_status_change_check(struct urb *urb, struct quatech_port *qt_port, struct usb_serial_port *port) { int flag, i; unsigned char *data = urb->transfer_buffer; unsigned int RxCount = urb->actual_length; for (i = 0; i < RxCount; ++i) { /* Look ahead code here */ if ((i <= (RxCount - 3)) && (data[i] == 0x1b) && (data[i + 1] == 0x1b)) { flag = 0; switch (data[i + 2]) { case 0x00: if (i > (RxCount - 4)) { dev_dbg(&port->dev, "Illegal escape seuences in received data\n"); break; } ProcessLineStatus(qt_port, data[i + 3]); i += 3; flag = 1; break; case 0x01: if (i > (RxCount - 4)) { dev_dbg(&port->dev, "Illegal escape seuences in received data\n"); break; } ProcessModemStatus(qt_port, data[i + 3]); i += 3; flag = 1; break; case 0xff: dev_dbg(&port->dev, "No status sequence.\n"); ProcessRxChar(port, data[i]); ProcessRxChar(port, data[i + 1]); i += 2; break; } if (flag == 1) continue; } if (urb->actual_length) tty_insert_flip_char(&port->port, data[i], TTY_NORMAL); } tty_flip_buffer_push(&port->port); } static void qt_read_bulk_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port = qt_get_port_private(port); int result; if (urb->status) { qt_port->ReadBulkStopped = 1; dev_dbg(&urb->dev->dev, "%s - nonzero write bulk status received: %d\n", __func__, urb->status); return; } dev_dbg(&port->dev, "%s - port->RxHolding = %d\n", __func__, qt_port->RxHolding); if (port_paranoia_check(port, __func__) != 0) { qt_port->ReadBulkStopped = 1; return; } if (!serial) return; if (qt_port->closePending == 1) { /* Were closing , stop reading */ dev_dbg(&port->dev, "%s - (qt_port->closepending == 1\n", __func__); qt_port->ReadBulkStopped = 1; return; } /* * RxHolding is asserted by throttle, if we assert it, we're not * receiving any more characters and let the box handle the flow * control */ if (qt_port->RxHolding == 1) { qt_port->ReadBulkStopped = 1; return; } if (urb->status) { qt_port->ReadBulkStopped = 1; dev_dbg(&port->dev, "%s - nonzero read bulk status received: %d\n", __func__, urb->status); return; } if (urb->actual_length) qt_status_change_check(urb, qt_port, port); /* Continue trying to always read */ usb_fill_bulk_urb(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, qt_read_bulk_callback, port); result = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (result) dev_dbg(&port->dev, "%s - failed resubmitting read urb, error %d", __func__, result); else { if (urb->actual_length) { tty_flip_buffer_push(&port->port); tty_schedule_flip(&port->port); } } schedule_work(&port->work); } /* * qt_get_device * Issue a GET_DEVICE vendor-specific request on the default control pipe If * successful, fills in the qt_get_device_data structure pointed to by * device_data, otherwise return a negative error number of the problem. */ static int qt_get_device(struct usb_serial *serial, struct qt_get_device_data *device_data) { int result; unsigned char *transfer_buffer; transfer_buffer = kmalloc(sizeof(struct qt_get_device_data), GFP_KERNEL); if (!transfer_buffer) return -ENOMEM; result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_SET_GET_DEVICE, 0xc0, 0, 0, transfer_buffer, sizeof(struct qt_get_device_data), 300); if (result > 0) memcpy(device_data, transfer_buffer, sizeof(struct qt_get_device_data)); kfree(transfer_buffer); return result; } /**************************************************************************** * BoxSetPrebufferLevel TELLS BOX WHEN TO ASSERT FLOW CONTROL ****************************************************************************/ static int BoxSetPrebufferLevel(struct usb_serial *serial) { int result; __u16 buffer_length; buffer_length = PREFUFF_LEVEL_CONSERVATIVE; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_PREBUF_TRIG_LVL, 0x40, buffer_length, 0, NULL, 0, 300); return result; } /**************************************************************************** * BoxSetATC TELLS BOX WHEN TO ASSERT automatic transmitter control ****************************************************************************/ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) { int result; __u16 buffer_length; buffer_length = PREFUFF_LEVEL_CONSERVATIVE; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SET_ATF, 0x40, n_Mode, 0, NULL, 0, 300); return result; } /** * qt_set_device * Issue a SET_DEVICE vendor-specific request on the default control pipe If * successful returns the number of bytes written, otherwise it returns a * negative error number of the problem. */ static int qt_set_device(struct usb_serial *serial, struct qt_get_device_data *device_data) { int result; __u16 length; __u16 PortSettings; PortSettings = ((__u16) (device_data->portb)); PortSettings = (PortSettings << 8); PortSettings += ((__u16) (device_data->porta)); length = sizeof(struct qt_get_device_data); result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SET_GET_DEVICE, 0x40, PortSettings, 0, NULL, 0, 300); return result; } static int qt_open_channel(struct usb_serial *serial, __u16 Uart_Number, struct qt_open_channel_data *pDeviceData) { int result; result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_OPEN_CLOSE_CHANNEL, USBD_TRANSFER_DIRECTION_IN, 1, Uart_Number, pDeviceData, sizeof(struct qt_open_channel_data), 300); return result; } static int qt_close_channel(struct usb_serial *serial, __u16 Uart_Number) { int result; result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_OPEN_CLOSE_CHANNEL, USBD_TRANSFER_DIRECTION_OUT, 0, Uart_Number, NULL, 0, 300); return result; } /**************************************************************************** * BoxGetRegister * issuse a GET_REGISTER vendor-spcific request on the default control pipe * If successful, fills in the pValue with the register value asked for ****************************************************************************/ static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, unsigned short Register_Num, __u8 *pValue) { int result; __u16 current_length; current_length = sizeof(struct qt_get_device_data); result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, 0xC0, Register_Num, Uart_Number, (void *)pValue, sizeof(*pValue), 300); return result; } /**************************************************************************** * BoxSetRegister * issuse a GET_REGISTER vendor-spcific request on the default control pipe * If successful, fills in the pValue with the register value asked for ****************************************************************************/ static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, unsigned short Register_Num, unsigned short Value) { int result; unsigned short RegAndByte; RegAndByte = Value; RegAndByte = RegAndByte << 8; RegAndByte = RegAndByte + Register_Num; /* result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, 0xC0, Register_Num, Uart_Number, NULL, 0, 300); */ result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, 0x40, RegAndByte, Uart_Number, NULL, 0, 300); return result; } /* * qt_setuart * issues a SET_UART vendor-specific request on the default control pipe * If successful sets baud rate divisor and LCR value */ static int qt_setuart(struct usb_serial *serial, unsigned short Uart_Number, unsigned short default_divisor, unsigned char default_LCR) { int result; unsigned short UartNumandLCR; UartNumandLCR = (default_LCR << 8) + Uart_Number; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_UART, 0x40, default_divisor, UartNumandLCR, NULL, 0, 300); return result; } static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int index, int bSet) { __u8 mcr = 0; __u8 msr = 0, MOUT_Value = 0; unsigned int status; if (bSet == 1) { /* flow control, box will clear RTS line to prevent remote */ mcr = SERIAL_MCR_RTS; } /* device from xmitting more chars */ else { /* no flow control to remote device */ mcr = 0; } MOUT_Value = mcr << 8; if (bSet == 1) { /* flow control, box will inhibit xmit data if CTS line is * asserted */ msr = SERIAL_MSR_CTS; } else { /* Box will not inhimbe xmit data due to CTS line */ msr = 0; } MOUT_Value |= msr; status = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_HW_FLOW_CONTROL_MASK, 0x40, MOUT_Value, index, NULL, 0, 300); return status; } static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 index, unsigned char stop_char, unsigned char start_char) { __u16 nSWflowout; int result; nSWflowout = start_char << 8; nSWflowout = (unsigned short)stop_char; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_MASK, 0x40, nSWflowout, index, NULL, 0, 300); return result; } static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 index) { int result; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_DISABLE, 0x40, 0, index, NULL, 0, 300); return result; } static int qt_startup(struct usb_serial *serial) { struct device *dev = &serial->dev->dev; struct usb_serial_port *port; struct quatech_port *qt_port; struct qt_get_device_data DeviceData; int i; int status; /* Now setup per port private data */ for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; qt_port = kzalloc(sizeof(*qt_port), GFP_KERNEL); if (!qt_port) { for (--i; i >= 0; i--) { port = serial->port[i]; kfree(usb_get_serial_port_data(port)); usb_set_serial_port_data(port, NULL); } return -ENOMEM; } mutex_init(&qt_port->lock); usb_set_serial_port_data(port, qt_port); } status = qt_get_device(serial, &DeviceData); if (status < 0) goto startup_error; dev_dbg(dev, "DeviceData.portb = 0x%x\n", DeviceData.portb); DeviceData.portb &= ~FULLPWRBIT; dev_dbg(dev, "Changing DeviceData.portb to 0x%x\n", DeviceData.portb); status = qt_set_device(serial, &DeviceData); if (status < 0) { dev_dbg(dev, "qt_set_device failed\n"); goto startup_error; } status = qt_get_device(serial, &DeviceData); if (status < 0) { dev_dbg(dev, "qt_get_device failed\n"); goto startup_error; } switch (le16_to_cpu(serial->dev->descriptor.idProduct)) { case QUATECH_DSU100: case QUATECH_QSU100: case QUATECH_ESU100A: case QUATECH_ESU100B: case QUATECH_HSU100A: case QUATECH_HSU100B: case QUATECH_HSU100C: case QUATECH_HSU100D: DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); DeviceData.porta |= CLKS_X4; DeviceData.portb &= ~(LOOPMODE_BITS); DeviceData.portb |= RS232_MODE; break; case QUATECH_SSU200: case QUATECH_DSU200: case QUATECH_QSU200: case QUATECH_ESU200A: case QUATECH_ESU200B: case QUATECH_HSU200A: case QUATECH_HSU200B: case QUATECH_HSU200C: case QUATECH_HSU200D: DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); DeviceData.porta |= CLKS_X4; DeviceData.portb &= ~(LOOPMODE_BITS); DeviceData.portb |= ALL_LOOPBACK; break; default: DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); DeviceData.porta |= CLKS_X4; DeviceData.portb &= ~(LOOPMODE_BITS); DeviceData.portb |= RS232_MODE; break; } status = BoxSetPrebufferLevel(serial); /* sets to default value */ if (status < 0) { dev_dbg(dev, "BoxSetPrebufferLevel failed\n"); goto startup_error; } status = BoxSetATC(serial, ATC_DISABLED); if (status < 0) { dev_dbg(dev, "BoxSetATC failed\n"); goto startup_error; } dev_dbg(dev, "DeviceData.portb = 0x%x\n", DeviceData.portb); DeviceData.portb |= NEXT_BOARD_POWER_BIT; dev_dbg(dev, "Changing DeviceData.portb to 0x%x\n", DeviceData.portb); status = qt_set_device(serial, &DeviceData); if (status < 0) { dev_dbg(dev, "qt_set_device failed\n"); goto startup_error; } return 0; startup_error: for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; qt_port = qt_get_port_private(port); kfree(qt_port); usb_set_serial_port_data(port, NULL); } return -EIO; } static void qt_release(struct usb_serial *serial) { struct usb_serial_port *port; struct quatech_port *qt_port; int i; for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; if (!port) continue; qt_port = usb_get_serial_port_data(port); kfree(qt_port); usb_set_serial_port_data(port, NULL); } } static void qt_submit_urb_from_open(struct usb_serial *serial, struct usb_serial_port *port) { int result; struct usb_serial_port *port0 = serial->port[0]; /* set up interrupt urb */ usb_fill_int_urb(port0->interrupt_in_urb, serial->dev, usb_rcvintpipe(serial->dev, port0->interrupt_in_endpointAddress), port0->interrupt_in_buffer, port0->interrupt_in_urb->transfer_buffer_length, qt_interrupt_callback, serial, port0->interrupt_in_urb->interval); result = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL); if (result) { dev_err(&port->dev, "%s - Error %d submitting interrupt urb\n", __func__, result); } } static int qt_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial; struct quatech_port *quatech_port; struct quatech_port *port0; struct qt_open_channel_data ChannelData; int result; if (port_paranoia_check(port, __func__)) return -ENODEV; serial = port->serial; if (serial_paranoia_check(serial, __func__)) return -ENODEV; quatech_port = qt_get_port_private(port); port0 = qt_get_port_private(serial->port[0]); if (quatech_port == NULL || port0 == NULL) return -ENODEV; usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); port0->open_ports++; result = qt_get_device(serial, &port0->DeviceData); /* Port specific setups */ result = qt_open_channel(serial, port->number, &ChannelData); if (result < 0) { dev_dbg(&port->dev, "qt_open_channel failed\n"); return result; } dev_dbg(&port->dev, "qt_open_channel completed.\n"); /* FIXME: are these needed? Does it even do anything useful? */ quatech_port->shadowLSR = ChannelData.line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); quatech_port->shadowMSR = ChannelData.modem_status & (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); /* Set Baud rate to default and turn off (default)flow control here */ result = qt_setuart(serial, port->number, DEFAULT_DIVISOR, DEFAULT_LCR); if (result < 0) { dev_dbg(&port->dev, "qt_setuart failed\n"); return result; } dev_dbg(&port->dev, "qt_setuart completed.\n"); /* * Put this here to make it responsive to stty and defaults set by * the tty layer */ /* Check to see if we've set up our endpoint info yet */ if (port0->open_ports == 1) { if (serial->port[0]->interrupt_in_buffer == NULL) qt_submit_urb_from_open(serial, port); } dev_dbg(&port->dev, "port number is %d\n", port->number); dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor); dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress); dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress); dev_dbg(&port->dev, "port's number in the device is %d\n", quatech_port->port_num); quatech_port->read_urb = port->read_urb; /* set up our bulk in urb */ usb_fill_bulk_urb(quatech_port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->bulk_in_buffer, quatech_port->read_urb->transfer_buffer_length, qt_read_bulk_callback, quatech_port); dev_dbg(&port->dev, "qt_open: bulkin endpoint is %d\n", port->bulk_in_endpointAddress); quatech_port->read_urb_busy = true; result = usb_submit_urb(quatech_port->read_urb, GFP_KERNEL); if (result) { dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, result); quatech_port->read_urb_busy = false; } /* initialize our wait queues */ init_waitqueue_head(&quatech_port->wait); init_waitqueue_head(&quatech_port->msr_wait); /* initialize our icount structure */ memset(&(quatech_port->icount), 0x00, sizeof(quatech_port->icount)); return 0; } static int qt_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial; int chars = 0; serial = get_usb_serial(port, __func__); if (serial->num_bulk_out) { if (port->write_urb->status == -EINPROGRESS) chars = port->write_urb->transfer_buffer_length; } return chars; } static void qt_block_until_empty(struct tty_struct *tty, struct quatech_port *qt_port) { int timeout = HZ / 10; int wait = 30; int count; while (1) { count = qt_chars_in_buffer(tty); if (count <= 0) return; interruptible_sleep_on_timeout(&qt_port->wait, timeout); wait--; if (wait == 0) { dev_dbg(&qt_port->port->dev, "%s - TIMEOUT", __func__); return; } else { wait = 30; } } } static void qt_close(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; struct quatech_port *qt_port; struct quatech_port *port0; struct tty_struct *tty; int status; unsigned int index; status = 0; tty = tty_port_tty_get(&port->port); index = tty->index - serial->minor; qt_port = qt_get_port_private(port); port0 = qt_get_port_private(serial->port[0]); /* shutdown any bulk reads that might be going on */ if (serial->num_bulk_out) usb_unlink_urb(port->write_urb); if (serial->num_bulk_in) usb_unlink_urb(port->read_urb); /* wait up to for transmitter to empty */ if (serial->dev) qt_block_until_empty(tty, qt_port); tty_kref_put(tty); /* Close uart channel */ status = qt_close_channel(serial, index); if (status < 0) dev_dbg(&port->dev, "%s - port %d qt_close_channel failed.\n", __func__, port->number); port0->open_ports--; dev_dbg(&port->dev, "qt_num_open_ports in close%d:in port%d\n", port0->open_ports, port->number); if (port0->open_ports == 0) { if (serial->port[0]->interrupt_in_urb) { dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); usb_kill_urb(serial->port[0]->interrupt_in_urb); } } if (qt_port->write_urb) { /* if this urb had a transfer buffer already (old tx) free it */ kfree(qt_port->write_urb->transfer_buffer); usb_free_urb(qt_port->write_urb); } } static int qt_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { int result; struct usb_serial *serial = get_usb_serial(port, __func__); if (serial == NULL) return -ENODEV; if (count == 0) { dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); return 0; } /* only do something if we have a bulk out endpoint */ if (serial->num_bulk_out) { if (port->write_urb->status == -EINPROGRESS) { dev_dbg(&port->dev, "%s - already writing\n", __func__); return 0; } count = (count > port->bulk_out_size) ? port->bulk_out_size : count; memcpy(port->write_urb->transfer_buffer, buf, count); /* set up our urb */ usb_fill_bulk_urb(port->write_urb, serial->dev, usb_sndbulkpipe(serial->dev, port-> bulk_out_endpointAddress), port->write_urb->transfer_buffer, count, qt_write_bulk_callback, port); /* send the data out the bulk port */ result = usb_submit_urb(port->write_urb, GFP_ATOMIC); if (result) dev_dbg(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); else result = count; return result; } /* no bulk out, so return 0 bytes written */ return 0; } static int qt_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial; struct quatech_port *qt_port; int retval = -EINVAL; if (port_paranoia_check(port, __func__)) return -1; serial = get_usb_serial(port, __func__); if (!serial) return -ENODEV; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); if (serial->num_bulk_out) { if (port->write_urb->status != -EINPROGRESS) retval = port->bulk_out_size; } mutex_unlock(&qt_port->lock); return retval; } static int qt_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = tty->driver_data; struct quatech_port *qt_port = qt_get_port_private(port); struct usb_serial *serial = get_usb_serial(port, __func__); unsigned int index; dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); index = tty->index - serial->minor; if (cmd == TIOCMIWAIT) { while (qt_port != NULL) { interruptible_sleep_on(&qt_port->msr_wait); if (signal_pending(current)) return -ERESTARTSYS; else { char diff = qt_port->diff_status; if (diff == 0) return -EIO; /* no change => error */ /* Consume all events */ qt_port->diff_status = 0; if (((arg & TIOCM_RNG) && (diff & SERIAL_MSR_RI)) || ((arg & TIOCM_DSR) && (diff & SERIAL_MSR_DSR)) || ((arg & TIOCM_CD) && (diff & SERIAL_MSR_CD)) || ((arg & TIOCM_CTS) && (diff & SERIAL_MSR_CTS))) { return 0; } } } return 0; } dev_dbg(&port->dev, "%s -No ioctl for that one. port = %d\n", __func__, port->number); return -ENOIOCTLCMD; } static void qt_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { struct ktermios *termios = &tty->termios; unsigned char new_LCR = 0; unsigned int cflag = termios->c_cflag; unsigned int index; int baud, divisor, remainder; int status; index = tty->index - port->serial->minor; switch (cflag & CSIZE) { case CS5: new_LCR |= SERIAL_5_DATA; break; case CS6: new_LCR |= SERIAL_6_DATA; break; case CS7: new_LCR |= SERIAL_7_DATA; break; default: termios->c_cflag &= ~CSIZE; termios->c_cflag |= CS8; case CS8: new_LCR |= SERIAL_8_DATA; break; } /* Parity stuff */ if (cflag & PARENB) { if (cflag & PARODD) new_LCR |= SERIAL_ODD_PARITY; else new_LCR |= SERIAL_EVEN_PARITY; } if (cflag & CSTOPB) new_LCR |= SERIAL_TWO_STOPB; else new_LCR |= SERIAL_ONE_STOPB; dev_dbg(&port->dev, "%s - 4\n", __func__); /* Thats the LCR stuff, go ahead and set it */ baud = tty_get_baud_rate(tty); if (!baud) /* pick a default, any default... */ baud = 9600; dev_dbg(&port->dev, "%s - got baud = %d\n", __func__, baud); divisor = MAX_BAUD_RATE / baud; remainder = MAX_BAUD_RATE % baud; /* Round to nearest divisor */ if (((remainder * 2) >= baud) && (baud != 110)) divisor++; /* * Set Baud rate to default and turn off (default)flow control here */ status = qt_setuart(port->serial, index, (unsigned short)divisor, new_LCR); if (status < 0) { dev_dbg(&port->dev, "qt_setuart failed\n"); return; } /* Now determine flow control */ if (cflag & CRTSCTS) { dev_dbg(&port->dev, "%s - Enabling HW flow control port %d\n", __func__, port->number); /* Enable RTS/CTS flow control */ status = BoxSetHW_FlowCtrl(port->serial, index, 1); if (status < 0) { dev_dbg(&port->dev, "BoxSetHW_FlowCtrl failed\n"); return; } } else { /* Disable RTS/CTS flow control */ dev_dbg(&port->dev, "%s - disabling HW flow control port %d\n", __func__, port->number); status = BoxSetHW_FlowCtrl(port->serial, index, 0); if (status < 0) { dev_dbg(&port->dev, "BoxSetHW_FlowCtrl failed\n"); return; } } /* if we are implementing XON/XOFF, set the start and stop character in * the device */ if (I_IXOFF(tty) || I_IXON(tty)) { unsigned char stop_char = STOP_CHAR(tty); unsigned char start_char = START_CHAR(tty); status = BoxSetSW_FlowCtrl(port->serial, index, stop_char, start_char); if (status < 0) dev_dbg(&port->dev, "BoxSetSW_FlowCtrl (enabled) failed\n"); } else { /* disable SW flow control */ status = BoxDisable_SW_FlowCtrl(port->serial, index); if (status < 0) dev_dbg(&port->dev, "BoxSetSW_FlowCtrl (diabling) failed\n"); } termios->c_cflag &= ~CMSPAR; /* FIXME: Error cases should be returning the actual bits changed only */ } static void qt_break(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; u16 index, onoff; unsigned int result; index = tty->index - serial->minor; qt_port = qt_get_port_private(port); if (break_state == -1) onoff = 1; else onoff = 0; mutex_lock(&qt_port->lock); result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_BREAK_CONTROL, 0x40, onoff, index, NULL, 0, 300); mutex_unlock(&qt_port->lock); } static inline int qt_real_tiocmget(struct tty_struct *tty, struct usb_serial_port *port, struct usb_serial *serial) { u8 mcr; u8 msr; unsigned int result = 0; int status; unsigned int index; index = tty->index - serial->minor; status = BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr); if (status >= 0) { status = BoxGetRegister(port->serial, index, MODEM_STATUS_REGISTER, &msr); } if (status >= 0) { result = ((mcr & SERIAL_MCR_DTR) ? TIOCM_DTR : 0) /* DTR IS SET */ | ((mcr & SERIAL_MCR_RTS) ? TIOCM_RTS : 0) /* RTS IS SET */ | ((msr & SERIAL_MSR_CTS) ? TIOCM_CTS : 0) /* CTS is set */ | ((msr & SERIAL_MSR_CD) ? TIOCM_CAR : 0) /* Carrier detect is set */ | ((msr & SERIAL_MSR_RI) ? TIOCM_RI : 0) /* Ring indicator set */ | ((msr & SERIAL_MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ return result; } else return -ESPIPE; } static inline int qt_real_tiocmset(struct tty_struct *tty, struct usb_serial_port *port, struct usb_serial *serial, unsigned int value) { u8 mcr; int status; unsigned int index; index = tty->index - serial->minor; status = BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr); if (status < 0) return -ESPIPE; /* * Turn off the RTS and DTR and loopback and then only turn on what was * asked for */ mcr &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); if (value & TIOCM_RTS) mcr |= SERIAL_MCR_RTS; if (value & TIOCM_DTR) mcr |= SERIAL_MCR_DTR; if (value & TIOCM_LOOP) mcr |= SERIAL_MCR_LOOP; status = BoxSetRegister(port->serial, index, MODEM_CONTROL_REGISTER, mcr); if (status < 0) return -ESPIPE; else return 0; } static int qt_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port = qt_get_port_private(port); int retval; if (!serial) return -ENODEV; mutex_lock(&qt_port->lock); retval = qt_real_tiocmget(tty, port, serial); mutex_unlock(&qt_port->lock); return retval; } static int qt_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port = qt_get_port_private(port); int retval; if (!serial) return -ENODEV; mutex_lock(&qt_port->lock); retval = qt_real_tiocmset(tty, port, serial, set); mutex_unlock(&qt_port->lock); return retval; } static void qt_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; if (!serial) return; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); /* pass on to the driver specific version of this function */ qt_port->RxHolding = 1; mutex_unlock(&qt_port->lock); } static void qt_submit_urb_from_unthrottle(struct usb_serial_port *port, struct usb_serial *serial) { int result; /* Start reading from the device */ usb_fill_bulk_urb(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, qt_read_bulk_callback, port); result = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (result) dev_err(&port->dev, "%s - failed restarting read urb, error %d\n", __func__, result); } static void qt_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; if (!serial) return; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); if (qt_port->RxHolding == 1) { dev_dbg(&port->dev, "%s -qt_port->RxHolding == 1\n", __func__); qt_port->RxHolding = 0; dev_dbg(&port->dev, "%s - qt_port->RxHolding = 0\n", __func__); /* if we have a bulk endpoint, start it up */ if ((serial->num_bulk_in) && (qt_port->ReadBulkStopped == 1)) qt_submit_urb_from_unthrottle(port, serial); } mutex_unlock(&qt_port->lock); } static int qt_calc_num_ports(struct usb_serial *serial) { int num_ports; num_ports = (serial->interface->cur_altsetting->desc.bNumEndpoints - 1) / 2; return num_ports; } static struct usb_serial_driver quatech_device = { .driver = { .owner = THIS_MODULE, .name = "serqt", }, .description = DRIVER_DESC, .id_table = id_table, .num_ports = 8, .open = qt_open, .close = qt_close, .write = qt_write, .write_room = qt_write_room, .chars_in_buffer = qt_chars_in_buffer, .throttle = qt_throttle, .unthrottle = qt_unthrottle, .calc_num_ports = qt_calc_num_ports, .ioctl = qt_ioctl, .set_termios = qt_set_termios, .break_ctl = qt_break, .tiocmget = qt_tiocmget, .tiocmset = qt_tiocmset, .attach = qt_startup, .release = qt_release, }; static struct usb_serial_driver * const serial_drivers[] = { &quatech_device, NULL }; module_usb_serial_driver(serial_drivers, id_table); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL");
gpl-2.0
M1cha/lge-kernel-lproj
arch/mips/mm/tlb-r4k.c
4412
10048
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1996 David S. Miller (davem@davemloft.net) * Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle ralf@gnu.org * Carsten Langgaard, carstenl@mips.com * Copyright (C) 2002 MIPS Technologies, Inc. All rights reserved. */ #include <linux/init.h> #include <linux/sched.h> #include <linux/smp.h> #include <linux/mm.h> #include <linux/hugetlb.h> #include <asm/cpu.h> #include <asm/bootinfo.h> #include <asm/mmu_context.h> #include <asm/pgtable.h> #include <asm/tlbmisc.h> extern void build_tlb_refill_handler(void); /* * Make sure all entries differ. If they're not different * MIPS32 will take revenge ... */ #define UNIQUE_ENTRYHI(idx) (CKSEG0 + ((idx) << (PAGE_SHIFT + 1))) /* Atomicity and interruptability */ #ifdef CONFIG_MIPS_MT_SMTC #include <asm/smtc.h> #include <asm/mipsmtregs.h> #define ENTER_CRITICAL(flags) \ { \ unsigned int mvpflags; \ local_irq_save(flags);\ mvpflags = dvpe() #define EXIT_CRITICAL(flags) \ evpe(mvpflags); \ local_irq_restore(flags); \ } #else #define ENTER_CRITICAL(flags) local_irq_save(flags) #define EXIT_CRITICAL(flags) local_irq_restore(flags) #endif /* CONFIG_MIPS_MT_SMTC */ #if defined(CONFIG_CPU_LOONGSON2) /* * LOONGSON2 has a 4 entry itlb which is a subset of dtlb, * unfortrunately, itlb is not totally transparent to software. */ #define FLUSH_ITLB write_c0_diag(4); #define FLUSH_ITLB_VM(vma) { if ((vma)->vm_flags & VM_EXEC) write_c0_diag(4); } #else #define FLUSH_ITLB #define FLUSH_ITLB_VM(vma) #endif void local_flush_tlb_all(void) { unsigned long flags; unsigned long old_ctx; int entry; ENTER_CRITICAL(flags); /* Save old context and create impossible VPN2 value */ old_ctx = read_c0_entryhi(); write_c0_entrylo0(0); write_c0_entrylo1(0); entry = read_c0_wired(); /* Blast 'em all away. */ while (entry < current_cpu_data.tlbsize) { /* Make sure all entries differ. */ write_c0_entryhi(UNIQUE_ENTRYHI(entry)); write_c0_index(entry); mtc0_tlbw_hazard(); tlb_write_indexed(); entry++; } tlbw_use_hazard(); write_c0_entryhi(old_ctx); FLUSH_ITLB; EXIT_CRITICAL(flags); } /* All entries common to a mm share an asid. To effectively flush these entries, we just bump the asid. */ void local_flush_tlb_mm(struct mm_struct *mm) { int cpu; preempt_disable(); cpu = smp_processor_id(); if (cpu_context(cpu, mm) != 0) { drop_mmu_context(mm, cpu); } preempt_enable(); } void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) { struct mm_struct *mm = vma->vm_mm; int cpu = smp_processor_id(); if (cpu_context(cpu, mm) != 0) { unsigned long size, flags; int huge = is_vm_hugetlb_page(vma); ENTER_CRITICAL(flags); if (huge) { start = round_down(start, HPAGE_SIZE); end = round_up(end, HPAGE_SIZE); size = (end - start) >> HPAGE_SHIFT; } else { start = round_down(start, PAGE_SIZE << 1); end = round_up(end, PAGE_SIZE << 1); size = (end - start) >> (PAGE_SHIFT + 1); } if (size <= current_cpu_data.tlbsize/2) { int oldpid = read_c0_entryhi(); int newpid = cpu_asid(cpu, mm); while (start < end) { int idx; write_c0_entryhi(start | newpid); if (huge) start += HPAGE_SIZE; else start += (PAGE_SIZE << 1); mtc0_tlbw_hazard(); tlb_probe(); tlb_probe_hazard(); idx = read_c0_index(); write_c0_entrylo0(0); write_c0_entrylo1(0); if (idx < 0) continue; /* Make sure all entries differ. */ write_c0_entryhi(UNIQUE_ENTRYHI(idx)); mtc0_tlbw_hazard(); tlb_write_indexed(); } tlbw_use_hazard(); write_c0_entryhi(oldpid); } else { drop_mmu_context(mm, cpu); } FLUSH_ITLB; EXIT_CRITICAL(flags); } } void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) { unsigned long size, flags; ENTER_CRITICAL(flags); size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT; size = (size + 1) >> 1; if (size <= current_cpu_data.tlbsize / 2) { int pid = read_c0_entryhi(); start &= (PAGE_MASK << 1); end += ((PAGE_SIZE << 1) - 1); end &= (PAGE_MASK << 1); while (start < end) { int idx; write_c0_entryhi(start); start += (PAGE_SIZE << 1); mtc0_tlbw_hazard(); tlb_probe(); tlb_probe_hazard(); idx = read_c0_index(); write_c0_entrylo0(0); write_c0_entrylo1(0); if (idx < 0) continue; /* Make sure all entries differ. */ write_c0_entryhi(UNIQUE_ENTRYHI(idx)); mtc0_tlbw_hazard(); tlb_write_indexed(); } tlbw_use_hazard(); write_c0_entryhi(pid); } else { local_flush_tlb_all(); } FLUSH_ITLB; EXIT_CRITICAL(flags); } void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page) { int cpu = smp_processor_id(); if (cpu_context(cpu, vma->vm_mm) != 0) { unsigned long flags; int oldpid, newpid, idx; newpid = cpu_asid(cpu, vma->vm_mm); page &= (PAGE_MASK << 1); ENTER_CRITICAL(flags); oldpid = read_c0_entryhi(); write_c0_entryhi(page | newpid); mtc0_tlbw_hazard(); tlb_probe(); tlb_probe_hazard(); idx = read_c0_index(); write_c0_entrylo0(0); write_c0_entrylo1(0); if (idx < 0) goto finish; /* Make sure all entries differ. */ write_c0_entryhi(UNIQUE_ENTRYHI(idx)); mtc0_tlbw_hazard(); tlb_write_indexed(); tlbw_use_hazard(); finish: write_c0_entryhi(oldpid); FLUSH_ITLB_VM(vma); EXIT_CRITICAL(flags); } } /* * This one is only used for pages with the global bit set so we don't care * much about the ASID. */ void local_flush_tlb_one(unsigned long page) { unsigned long flags; int oldpid, idx; ENTER_CRITICAL(flags); oldpid = read_c0_entryhi(); page &= (PAGE_MASK << 1); write_c0_entryhi(page); mtc0_tlbw_hazard(); tlb_probe(); tlb_probe_hazard(); idx = read_c0_index(); write_c0_entrylo0(0); write_c0_entrylo1(0); if (idx >= 0) { /* Make sure all entries differ. */ write_c0_entryhi(UNIQUE_ENTRYHI(idx)); mtc0_tlbw_hazard(); tlb_write_indexed(); tlbw_use_hazard(); } write_c0_entryhi(oldpid); FLUSH_ITLB; EXIT_CRITICAL(flags); } /* * We will need multiple versions of update_mmu_cache(), one that just * updates the TLB with the new pte(s), and another which also checks * for the R4k "end of page" hardware bug and does the needy. */ void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte) { unsigned long flags; pgd_t *pgdp; pud_t *pudp; pmd_t *pmdp; pte_t *ptep; int idx, pid; /* * Handle debugger faulting in for debugee. */ if (current->active_mm != vma->vm_mm) return; ENTER_CRITICAL(flags); pid = read_c0_entryhi() & ASID_MASK; address &= (PAGE_MASK << 1); write_c0_entryhi(address | pid); pgdp = pgd_offset(vma->vm_mm, address); mtc0_tlbw_hazard(); tlb_probe(); tlb_probe_hazard(); pudp = pud_offset(pgdp, address); pmdp = pmd_offset(pudp, address); idx = read_c0_index(); #ifdef CONFIG_HUGETLB_PAGE /* this could be a huge page */ if (pmd_huge(*pmdp)) { unsigned long lo; write_c0_pagemask(PM_HUGE_MASK); ptep = (pte_t *)pmdp; lo = pte_to_entrylo(pte_val(*ptep)); write_c0_entrylo0(lo); write_c0_entrylo1(lo + (HPAGE_SIZE >> 7)); mtc0_tlbw_hazard(); if (idx < 0) tlb_write_random(); else tlb_write_indexed(); write_c0_pagemask(PM_DEFAULT_MASK); } else #endif { ptep = pte_offset_map(pmdp, address); #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32) write_c0_entrylo0(ptep->pte_high); ptep++; write_c0_entrylo1(ptep->pte_high); #else write_c0_entrylo0(pte_to_entrylo(pte_val(*ptep++))); write_c0_entrylo1(pte_to_entrylo(pte_val(*ptep))); #endif mtc0_tlbw_hazard(); if (idx < 0) tlb_write_random(); else tlb_write_indexed(); } tlbw_use_hazard(); FLUSH_ITLB_VM(vma); EXIT_CRITICAL(flags); } void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1, unsigned long entryhi, unsigned long pagemask) { unsigned long flags; unsigned long wired; unsigned long old_pagemask; unsigned long old_ctx; ENTER_CRITICAL(flags); /* Save old context and create impossible VPN2 value */ old_ctx = read_c0_entryhi(); old_pagemask = read_c0_pagemask(); wired = read_c0_wired(); write_c0_wired(wired + 1); write_c0_index(wired); tlbw_use_hazard(); /* What is the hazard here? */ write_c0_pagemask(pagemask); write_c0_entryhi(entryhi); write_c0_entrylo0(entrylo0); write_c0_entrylo1(entrylo1); mtc0_tlbw_hazard(); tlb_write_indexed(); tlbw_use_hazard(); write_c0_entryhi(old_ctx); tlbw_use_hazard(); /* What is the hazard here? */ write_c0_pagemask(old_pagemask); local_flush_tlb_all(); EXIT_CRITICAL(flags); } static int __cpuinitdata ntlb; static int __init set_ntlb(char *str) { get_option(&str, &ntlb); return 1; } __setup("ntlb=", set_ntlb); void __cpuinit tlb_init(void) { /* * You should never change this register: * - On R4600 1.7 the tlbp never hits for pages smaller than * the value in the c0_pagemask register. * - The entire mm handling assumes the c0_pagemask register to * be set to fixed-size pages. */ write_c0_pagemask(PM_DEFAULT_MASK); write_c0_wired(0); if (current_cpu_type() == CPU_R10000 || current_cpu_type() == CPU_R12000 || current_cpu_type() == CPU_R14000) write_c0_framemask(0); if (kernel_uses_smartmips_rixi) { /* * Enable the no read, no exec bits, and enable large virtual * address. */ u32 pg = PG_RIE | PG_XIE; #ifdef CONFIG_64BIT pg |= PG_ELPA; #endif write_c0_pagegrain(pg); } /* From this point on the ARC firmware is dead. */ local_flush_tlb_all(); /* Did I tell you that ARC SUCKS? */ if (ntlb) { if (ntlb > 1 && ntlb <= current_cpu_data.tlbsize) { int wired = current_cpu_data.tlbsize - ntlb; write_c0_wired(wired); write_c0_index(wired-1); printk("Restricting TLB to %d entries\n", ntlb); } else printk("Ignoring invalid argument ntlb=%d\n", ntlb); } build_tlb_refill_handler(); }
gpl-2.0
ashyx/Samsung_Galaxy_Tab_A_kernel
drivers/mtd/mtdoops.c
4668
12101
/* * MTD Oops/Panic logger * * Copyright © 2007 Nokia Corporation. All rights reserved. * * Author: Richard Purdie <rpurdie@openedhand.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/console.h> #include <linux/vmalloc.h> #include <linux/workqueue.h> #include <linux/sched.h> #include <linux/wait.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/mtd/mtd.h> #include <linux/kmsg_dump.h> /* Maximum MTD partition size */ #define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024) #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 #define MTDOOPS_HEADER_SIZE 8 static unsigned long record_size = 4096; module_param(record_size, ulong, 0400); MODULE_PARM_DESC(record_size, "record size for MTD OOPS pages in bytes (default 4096)"); static char mtddev[80]; module_param_string(mtddev, mtddev, 80, 0400); MODULE_PARM_DESC(mtddev, "name or index number of the MTD device to use"); static int dump_oops = 1; module_param(dump_oops, int, 0600); MODULE_PARM_DESC(dump_oops, "set to 1 to dump oopses, 0 to only dump panics (default 1)"); static struct mtdoops_context { struct kmsg_dumper dump; int mtd_index; struct work_struct work_erase; struct work_struct work_write; struct mtd_info *mtd; int oops_pages; int nextpage; int nextcount; unsigned long *oops_page_used; void *oops_buf; } oops_cxt; static void mark_page_used(struct mtdoops_context *cxt, int page) { set_bit(page, cxt->oops_page_used); } static void mark_page_unused(struct mtdoops_context *cxt, int page) { clear_bit(page, cxt->oops_page_used); } static int page_is_used(struct mtdoops_context *cxt, int page) { return test_bit(page, cxt->oops_page_used); } static void mtdoops_erase_callback(struct erase_info *done) { wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv; wake_up(wait_q); } static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) { struct mtd_info *mtd = cxt->mtd; u32 start_page_offset = mtd_div_by_eb(offset, mtd) * mtd->erasesize; u32 start_page = start_page_offset / record_size; u32 erase_pages = mtd->erasesize / record_size; struct erase_info erase; DECLARE_WAITQUEUE(wait, current); wait_queue_head_t wait_q; int ret; int page; init_waitqueue_head(&wait_q); erase.mtd = mtd; erase.callback = mtdoops_erase_callback; erase.addr = offset; erase.len = mtd->erasesize; erase.priv = (u_long)&wait_q; set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&wait_q, &wait); ret = mtd_erase(mtd, &erase); if (ret) { set_current_state(TASK_RUNNING); remove_wait_queue(&wait_q, &wait); printk(KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n", (unsigned long long)erase.addr, (unsigned long long)erase.len, mtddev); return ret; } schedule(); /* Wait for erase to finish. */ remove_wait_queue(&wait_q, &wait); /* Mark pages as unused */ for (page = start_page; page < start_page + erase_pages; page++) mark_page_unused(cxt, page); return 0; } static void mtdoops_inc_counter(struct mtdoops_context *cxt) { cxt->nextpage++; if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage = 0; cxt->nextcount++; if (cxt->nextcount == 0xffffffff) cxt->nextcount = 0; if (page_is_used(cxt, cxt->nextpage)) { schedule_work(&cxt->work_erase); return; } printk(KERN_DEBUG "mtdoops: ready %d, %d (no erase)\n", cxt->nextpage, cxt->nextcount); } /* Scheduled work - when we can't proceed without erasing a block */ static void mtdoops_workfunc_erase(struct work_struct *work) { struct mtdoops_context *cxt = container_of(work, struct mtdoops_context, work_erase); struct mtd_info *mtd = cxt->mtd; int i = 0, j, ret, mod; /* We were unregistered */ if (!mtd) return; mod = (cxt->nextpage * record_size) % mtd->erasesize; if (mod != 0) { cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage = 0; } while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { badblock: printk(KERN_WARNING "mtdoops: bad block at %08lx\n", cxt->nextpage * record_size); i++; cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage = 0; if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { printk(KERN_ERR "mtdoops: all blocks bad!\n"); return; } } if (ret < 0) { printk(KERN_ERR "mtdoops: mtd_block_isbad failed, aborting\n"); return; } for (j = 0, ret = -1; (j < 3) && (ret < 0); j++) ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); if (ret >= 0) { printk(KERN_DEBUG "mtdoops: ready %d, %d\n", cxt->nextpage, cxt->nextcount); return; } if (ret == -EIO) { ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); if (ret < 0 && ret != -EOPNOTSUPP) { printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n"); return; } } goto badblock; } static void mtdoops_write(struct mtdoops_context *cxt, int panic) { struct mtd_info *mtd = cxt->mtd; size_t retlen; u32 *hdr; int ret; /* Add mtdoops header to the buffer */ hdr = cxt->oops_buf; hdr[0] = cxt->nextcount; hdr[1] = MTDOOPS_KERNMSG_MAGIC; if (panic) { ret = mtd_panic_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); if (ret == -EOPNOTSUPP) { printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); return; } } else ret = mtd_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); if (retlen != record_size || ret < 0) printk(KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n", cxt->nextpage * record_size, retlen, record_size, ret); mark_page_used(cxt, cxt->nextpage); memset(cxt->oops_buf, 0xff, record_size); mtdoops_inc_counter(cxt); } static void mtdoops_workfunc_write(struct work_struct *work) { struct mtdoops_context *cxt = container_of(work, struct mtdoops_context, work_write); mtdoops_write(cxt, 0); } static void find_next_position(struct mtdoops_context *cxt) { struct mtd_info *mtd = cxt->mtd; int ret, page, maxpos = 0; u32 count[2], maxcount = 0xffffffff; size_t retlen; for (page = 0; page < cxt->oops_pages; page++) { if (mtd_block_isbad(mtd, page * record_size)) continue; /* Assume the page is used */ mark_page_used(cxt, page); ret = mtd_read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, &retlen, (u_char *)&count[0]); if (retlen != MTDOOPS_HEADER_SIZE || (ret < 0 && !mtd_is_bitflip(ret))) { printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n", page * record_size, retlen, MTDOOPS_HEADER_SIZE, ret); continue; } if (count[0] == 0xffffffff && count[1] == 0xffffffff) mark_page_unused(cxt, page); if (count[0] == 0xffffffff || count[1] != MTDOOPS_KERNMSG_MAGIC) continue; if (maxcount == 0xffffffff) { maxcount = count[0]; maxpos = page; } else if (count[0] < 0x40000000 && maxcount > 0xc0000000) { maxcount = count[0]; maxpos = page; } else if (count[0] > maxcount && count[0] < 0xc0000000) { maxcount = count[0]; maxpos = page; } else if (count[0] > maxcount && count[0] > 0xc0000000 && maxcount > 0x80000000) { maxcount = count[0]; maxpos = page; } } if (maxcount == 0xffffffff) { cxt->nextpage = cxt->oops_pages - 1; cxt->nextcount = 0; } else { cxt->nextpage = maxpos; cxt->nextcount = maxcount; } mtdoops_inc_counter(cxt); } static void mtdoops_do_dump(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason) { struct mtdoops_context *cxt = container_of(dumper, struct mtdoops_context, dump); /* Only dump oopses if dump_oops is set */ if (reason == KMSG_DUMP_OOPS && !dump_oops) return; kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, record_size - MTDOOPS_HEADER_SIZE, NULL); /* Panics must be written immediately */ if (reason != KMSG_DUMP_OOPS) mtdoops_write(cxt, 1); /* For other cases, schedule work to write it "nicely" */ schedule_work(&cxt->work_write); } static void mtdoops_notify_add(struct mtd_info *mtd) { struct mtdoops_context *cxt = &oops_cxt; u64 mtdoops_pages = div_u64(mtd->size, record_size); int err; if (!strcmp(mtd->name, mtddev)) cxt->mtd_index = mtd->index; if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) return; if (mtd->size < mtd->erasesize * 2) { printk(KERN_ERR "mtdoops: MTD partition %d not big enough for mtdoops\n", mtd->index); return; } if (mtd->erasesize < record_size) { printk(KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n", mtd->index); return; } if (mtd->size > MTDOOPS_MAX_MTD_SIZE) { printk(KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n", mtd->index, MTDOOPS_MAX_MTD_SIZE / 1024 / 1024); return; } /* oops_page_used is a bit field */ cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages, BITS_PER_LONG) * sizeof(unsigned long)); if (!cxt->oops_page_used) { printk(KERN_ERR "mtdoops: could not allocate page array\n"); return; } cxt->dump.max_reason = KMSG_DUMP_OOPS; cxt->dump.dump = mtdoops_do_dump; err = kmsg_dump_register(&cxt->dump); if (err) { printk(KERN_ERR "mtdoops: registering kmsg dumper failed, error %d\n", err); vfree(cxt->oops_page_used); cxt->oops_page_used = NULL; return; } cxt->mtd = mtd; cxt->oops_pages = (int)mtd->size / record_size; find_next_position(cxt); printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index); } static void mtdoops_notify_remove(struct mtd_info *mtd) { struct mtdoops_context *cxt = &oops_cxt; if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) return; if (kmsg_dump_unregister(&cxt->dump) < 0) printk(KERN_WARNING "mtdoops: could not unregister kmsg_dumper\n"); cxt->mtd = NULL; flush_work(&cxt->work_erase); flush_work(&cxt->work_write); } static struct mtd_notifier mtdoops_notifier = { .add = mtdoops_notify_add, .remove = mtdoops_notify_remove, }; static int __init mtdoops_init(void) { struct mtdoops_context *cxt = &oops_cxt; int mtd_index; char *endp; if (strlen(mtddev) == 0) { printk(KERN_ERR "mtdoops: mtd device (mtddev=name/number) must be supplied\n"); return -EINVAL; } if ((record_size & 4095) != 0) { printk(KERN_ERR "mtdoops: record_size must be a multiple of 4096\n"); return -EINVAL; } if (record_size < 4096) { printk(KERN_ERR "mtdoops: record_size must be over 4096 bytes\n"); return -EINVAL; } /* Setup the MTD device to use */ cxt->mtd_index = -1; mtd_index = simple_strtoul(mtddev, &endp, 0); if (*endp == '\0') cxt->mtd_index = mtd_index; cxt->oops_buf = vmalloc(record_size); if (!cxt->oops_buf) { printk(KERN_ERR "mtdoops: failed to allocate buffer workspace\n"); return -ENOMEM; } memset(cxt->oops_buf, 0xff, record_size); INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); register_mtd_user(&mtdoops_notifier); return 0; } static void __exit mtdoops_exit(void) { struct mtdoops_context *cxt = &oops_cxt; unregister_mtd_user(&mtdoops_notifier); vfree(cxt->oops_buf); vfree(cxt->oops_page_used); } module_init(mtdoops_init); module_exit(mtdoops_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); MODULE_DESCRIPTION("MTD Oops/Panic console logger/driver");
gpl-2.0
AlbertXingZhang/android_kernel_sony_msm8x60
arch/arm/plat-mxc/devices/platform-spi_imx.c
5436
4130
/* * Copyright (C) 2009-2010 Pengutronix * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 2 as published by the * Free Software Foundation. */ #include <mach/hardware.h> #include <mach/devices-common.h> #define imx_spi_imx_data_entry_single(soc, type, _devid, _id, hwid, _size) \ { \ .devid = _devid, \ .id = _id, \ .iobase = soc ## _ ## type ## hwid ## _BASE_ADDR, \ .iosize = _size, \ .irq = soc ## _INT_ ## type ## hwid, \ } #define imx_spi_imx_data_entry(soc, type, devid, id, hwid, size) \ [id] = imx_spi_imx_data_entry_single(soc, type, devid, id, hwid, size) #ifdef CONFIG_SOC_IMX1 const struct imx_spi_imx_data imx1_cspi_data[] __initconst = { #define imx1_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX1, CSPI, "imx1-cspi", _id, _hwid, SZ_4K) imx1_cspi_data_entry(0, 1), imx1_cspi_data_entry(1, 2), }; #endif #ifdef CONFIG_SOC_IMX21 const struct imx_spi_imx_data imx21_cspi_data[] __initconst = { #define imx21_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX21, CSPI, "imx21-cspi", _id, _hwid, SZ_4K) imx21_cspi_data_entry(0, 1), imx21_cspi_data_entry(1, 2), }; #endif #ifdef CONFIG_SOC_IMX25 /* i.mx25 has the i.mx35 type cspi */ const struct imx_spi_imx_data imx25_cspi_data[] __initconst = { #define imx25_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX25, CSPI, "imx35-cspi", _id, _hwid, SZ_16K) imx25_cspi_data_entry(0, 1), imx25_cspi_data_entry(1, 2), imx25_cspi_data_entry(2, 3), }; #endif /* ifdef CONFIG_SOC_IMX25 */ #ifdef CONFIG_SOC_IMX27 const struct imx_spi_imx_data imx27_cspi_data[] __initconst = { #define imx27_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX27, CSPI, "imx27-cspi", _id, _hwid, SZ_4K) imx27_cspi_data_entry(0, 1), imx27_cspi_data_entry(1, 2), imx27_cspi_data_entry(2, 3), }; #endif /* ifdef CONFIG_SOC_IMX27 */ #ifdef CONFIG_SOC_IMX31 const struct imx_spi_imx_data imx31_cspi_data[] __initconst = { #define imx31_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX31, CSPI, "imx31-cspi", _id, _hwid, SZ_4K) imx31_cspi_data_entry(0, 1), imx31_cspi_data_entry(1, 2), imx31_cspi_data_entry(2, 3), }; #endif /* ifdef CONFIG_SOC_IMX31 */ #ifdef CONFIG_SOC_IMX35 const struct imx_spi_imx_data imx35_cspi_data[] __initconst = { #define imx35_cspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX35, CSPI, "imx35-cspi", _id, _hwid, SZ_4K) imx35_cspi_data_entry(0, 1), imx35_cspi_data_entry(1, 2), }; #endif /* ifdef CONFIG_SOC_IMX35 */ #ifdef CONFIG_SOC_IMX51 /* i.mx51 has the i.mx35 type cspi */ const struct imx_spi_imx_data imx51_cspi_data __initconst = imx_spi_imx_data_entry_single(MX51, CSPI, "imx35-cspi", 2, , SZ_4K); const struct imx_spi_imx_data imx51_ecspi_data[] __initconst = { #define imx51_ecspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX51, ECSPI, "imx51-ecspi", _id, _hwid, SZ_4K) imx51_ecspi_data_entry(0, 1), imx51_ecspi_data_entry(1, 2), }; #endif /* ifdef CONFIG_SOC_IMX51 */ #ifdef CONFIG_SOC_IMX53 /* i.mx53 has the i.mx35 type cspi */ const struct imx_spi_imx_data imx53_cspi_data __initconst = imx_spi_imx_data_entry_single(MX53, CSPI, "imx35-cspi", 0, , SZ_4K); /* i.mx53 has the i.mx51 type ecspi */ const struct imx_spi_imx_data imx53_ecspi_data[] __initconst = { #define imx53_ecspi_data_entry(_id, _hwid) \ imx_spi_imx_data_entry(MX53, ECSPI, "imx51-ecspi", _id, _hwid, SZ_4K) imx53_ecspi_data_entry(0, 1), imx53_ecspi_data_entry(1, 2), }; #endif /* ifdef CONFIG_SOC_IMX53 */ struct platform_device *__init imx_add_spi_imx( const struct imx_spi_imx_data *data, const struct spi_imx_master *pdata) { struct resource res[] = { { .start = data->iobase, .end = data->iobase + data->iosize - 1, .flags = IORESOURCE_MEM, }, { .start = data->irq, .end = data->irq, .flags = IORESOURCE_IRQ, }, }; return imx_add_platform_device(data->devid, data->id, res, ARRAY_SIZE(res), pdata, sizeof(*pdata)); }
gpl-2.0
mukulsoni/android_kernel_samsung_ms013g-G4SWA
drivers/net/wireless/brcm80211/brcmsmac/phy/phytbl_lcn.c
7740
44665
/* * Copyright (c) 2010 Broadcom Corporation * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <types.h> #include "phytbl_lcn.h" static const u32 dot11lcn_gain_tbl_rev0[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000d, 0x0000004d, 0x0000008d, 0x0000000d, 0x0000004d, 0x0000008d, 0x000000cd, 0x0000004f, 0x0000008f, 0x000000cf, 0x000000d3, 0x00000113, 0x00000513, 0x00000913, 0x00000953, 0x00000d53, 0x00001153, 0x00001193, 0x00005193, 0x00009193, 0x0000d193, 0x00011193, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000d, 0x0000004d, 0x0000008d, 0x0000000d, 0x0000004d, 0x0000008d, 0x000000cd, 0x0000004f, 0x0000008f, 0x000000cf, 0x000000d3, 0x00000113, 0x00000513, 0x00000913, 0x00000953, 0x00000d53, 0x00001153, 0x00005153, 0x00009153, 0x0000d153, 0x00011153, 0x00015153, 0x00019153, 0x0001d153, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; static const u32 dot11lcn_gain_tbl_rev1[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000008, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000D, 0x00000011, 0x00000051, 0x00000091, 0x00000011, 0x00000051, 0x00000091, 0x000000d1, 0x00000053, 0x00000093, 0x000000d3, 0x000000d7, 0x00000117, 0x00000517, 0x00000917, 0x00000957, 0x00000d57, 0x00001157, 0x00001197, 0x00005197, 0x00009197, 0x0000d197, 0x00011197, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000008, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000D, 0x00000011, 0x00000051, 0x00000091, 0x00000011, 0x00000051, 0x00000091, 0x000000d1, 0x00000053, 0x00000093, 0x000000d3, 0x000000d7, 0x00000117, 0x00000517, 0x00000917, 0x00000957, 0x00000d57, 0x00001157, 0x00005157, 0x00009157, 0x0000d157, 0x00011157, 0x00015157, 0x00019157, 0x0001d157, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; static const u16 dot11lcn_aux_gain_idx_tbl_rev0[] = { 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x058b, 0x058c, 0x058d, 0x058e, 0x058f, 0x0090, 0x0091, 0x0092, 0x0193, 0x0194, 0x0195, 0x0196, 0x0197, 0x0198, 0x0199, 0x019a, 0x019b, 0x019c, 0x019d, 0x019e, 0x019f, 0x01a0, 0x01a1, 0x01a2, 0x01a3, 0x01a4, 0x01a5, 0x0000, }; static const u32 dot11lcn_gain_idx_tbl_rev0[] = { 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x20000000, 0x00000000, 0x30000000, 0x00000000, 0x40000000, 0x00000000, 0x50000000, 0x00000000, 0x60000000, 0x00000000, 0x70000000, 0x00000000, 0x80000000, 0x00000000, 0x90000000, 0x00000008, 0xa0000000, 0x00000008, 0xb0000000, 0x00000008, 0xc0000000, 0x00000008, 0xd0000000, 0x00000008, 0xe0000000, 0x00000008, 0xf0000000, 0x00000008, 0x00000000, 0x00000009, 0x10000000, 0x00000009, 0x20000000, 0x00000019, 0x30000000, 0x00000019, 0x40000000, 0x00000019, 0x50000000, 0x00000019, 0x60000000, 0x00000019, 0x70000000, 0x00000019, 0x80000000, 0x00000019, 0x90000000, 0x00000019, 0xa0000000, 0x00000019, 0xb0000000, 0x00000019, 0xc0000000, 0x00000019, 0xd0000000, 0x00000019, 0xe0000000, 0x00000019, 0xf0000000, 0x00000019, 0x00000000, 0x0000001a, 0x10000000, 0x0000001a, 0x20000000, 0x0000001a, 0x30000000, 0x0000001a, 0x40000000, 0x0000001a, 0x50000000, 0x00000002, 0x60000000, 0x00000002, 0x70000000, 0x00000002, 0x80000000, 0x00000002, 0x90000000, 0x00000002, 0xa0000000, 0x00000002, 0xb0000000, 0x00000002, 0xc0000000, 0x0000000a, 0xd0000000, 0x0000000a, 0xe0000000, 0x0000000a, 0xf0000000, 0x0000000a, 0x00000000, 0x0000000b, 0x10000000, 0x0000000b, 0x20000000, 0x0000000b, 0x30000000, 0x0000000b, 0x40000000, 0x0000000b, 0x50000000, 0x0000001b, 0x60000000, 0x0000001b, 0x70000000, 0x0000001b, 0x80000000, 0x0000001b, 0x90000000, 0x0000001b, 0xa0000000, 0x0000001b, 0xb0000000, 0x0000001b, 0xc0000000, 0x0000001b, 0xd0000000, 0x0000001b, 0xe0000000, 0x0000001b, 0xf0000000, 0x0000001b, 0x00000000, 0x0000001c, 0x10000000, 0x0000001c, 0x20000000, 0x0000001c, 0x30000000, 0x0000001c, 0x40000000, 0x0000001c, 0x50000000, 0x0000001c, 0x60000000, 0x0000001c, 0x70000000, 0x0000001c, 0x80000000, 0x0000001c, 0x90000000, 0x0000001c, }; static const u16 dot11lcn_aux_gain_idx_tbl_2G[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0080, 0x0081, 0x0100, 0x0101, 0x0180, 0x0181, 0x0182, 0x0183, 0x0184, 0x0185, 0x0186, 0x0187, 0x0188, 0x0285, 0x0289, 0x028a, 0x028b, 0x028c, 0x028d, 0x028e, 0x028f, 0x0290, 0x0291, 0x0292, 0x0293, 0x0294, 0x0295, 0x0296, 0x0297, 0x0298, 0x0299, 0x029a, 0x0000 }; static const u8 dot11lcn_gain_val_tbl_2G[] = { 0xfc, 0x02, 0x08, 0x0e, 0x13, 0x1b, 0xfc, 0x02, 0x08, 0x0e, 0x13, 0x1b, 0xfc, 0x00, 0x0c, 0x03, 0xeb, 0xfe, 0x07, 0x0b, 0x0f, 0xfb, 0xfe, 0x01, 0x05, 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15, 0x18, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u32 dot11lcn_gain_idx_tbl_2G[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000008, 0x10000000, 0x00000008, 0x00000000, 0x00000010, 0x10000000, 0x00000010, 0x00000000, 0x00000018, 0x10000000, 0x00000018, 0x20000000, 0x00000018, 0x30000000, 0x00000018, 0x40000000, 0x00000018, 0x50000000, 0x00000018, 0x60000000, 0x00000018, 0x70000000, 0x00000018, 0x80000000, 0x00000018, 0x50000000, 0x00000028, 0x90000000, 0x00000028, 0xa0000000, 0x00000028, 0xb0000000, 0x00000028, 0xc0000000, 0x00000028, 0xd0000000, 0x00000028, 0xe0000000, 0x00000028, 0xf0000000, 0x00000028, 0x00000000, 0x00000029, 0x10000000, 0x00000029, 0x20000000, 0x00000029, 0x30000000, 0x00000029, 0x40000000, 0x00000029, 0x50000000, 0x00000029, 0x60000000, 0x00000029, 0x70000000, 0x00000029, 0x80000000, 0x00000029, 0x90000000, 0x00000029, 0xa0000000, 0x00000029, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000008, 0x10000000, 0x00000008, 0x00000000, 0x00000010, 0x10000000, 0x00000010, 0x00000000, 0x00000018, 0x10000000, 0x00000018, 0x20000000, 0x00000018, 0x30000000, 0x00000018, 0x40000000, 0x00000018, 0x50000000, 0x00000018, 0x60000000, 0x00000018, 0x70000000, 0x00000018, 0x80000000, 0x00000018, 0x50000000, 0x00000028, 0x90000000, 0x00000028, 0xa0000000, 0x00000028, 0xb0000000, 0x00000028, 0xc0000000, 0x00000028, 0xd0000000, 0x00000028, 0xe0000000, 0x00000028, 0xf0000000, 0x00000028, 0x00000000, 0x00000029, 0x10000000, 0x00000029, 0x20000000, 0x00000029, 0x30000000, 0x00000029, 0x40000000, 0x00000029, 0x50000000, 0x00000029, 0x60000000, 0x00000029, 0x70000000, 0x00000029, 0x80000000, 0x00000029, 0x90000000, 0x00000029, 0xa0000000, 0x00000029, 0xb0000000, 0x00000029, 0xc0000000, 0x00000029, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; static const u32 dot11lcn_gain_tbl_2G[] = { 0x00000000, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000d, 0x0000004d, 0x0000008d, 0x00000049, 0x00000089, 0x000000c9, 0x0000004b, 0x0000008b, 0x000000cb, 0x000000cf, 0x0000010f, 0x0000050f, 0x0000090f, 0x0000094f, 0x00000d4f, 0x0000114f, 0x0000118f, 0x0000518f, 0x0000918f, 0x0000d18f, 0x0001118f, 0x0001518f, 0x0001918f, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; static const u32 dot11lcn_gain_tbl_extlna_2G[] = { 0x00000000, 0x00000004, 0x00000008, 0x00000001, 0x00000005, 0x00000009, 0x0000000d, 0x00000003, 0x00000007, 0x0000000b, 0x0000000f, 0x0000004f, 0x0000008f, 0x000000cf, 0x0000010f, 0x0000014f, 0x0000018f, 0x0000058f, 0x0000098f, 0x00000d8f, 0x00008000, 0x00008004, 0x00008008, 0x00008001, 0x00008005, 0x00008009, 0x0000800d, 0x00008003, 0x00008007, 0x0000800b, 0x0000800f, 0x0000804f, 0x0000808f, 0x000080cf, 0x0000810f, 0x0000814f, 0x0000818f, 0x0000858f, 0x0000898f, 0x00008d8f, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; static const u16 dot11lcn_aux_gain_idx_tbl_extlna_2G[] = { 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0483, 0x0484, 0x0485, 0x0486, 0x0583, 0x0584, 0x0585, 0x0587, 0x0588, 0x0589, 0x058a, 0x0687, 0x0688, 0x0689, 0x068a, 0x068b, 0x068c, 0x068d, 0x068e, 0x068f, 0x0690, 0x0691, 0x0692, 0x0693, 0x0000 }; static const u8 dot11lcn_gain_val_tbl_extlna_2G[] = { 0xfc, 0x02, 0x08, 0x0e, 0x13, 0x1b, 0xfc, 0x02, 0x08, 0x0e, 0x13, 0x1b, 0xfc, 0x00, 0x0f, 0x03, 0xeb, 0xfe, 0x07, 0x0b, 0x0f, 0xfb, 0xfe, 0x01, 0x05, 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15, 0x18, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u32 dot11lcn_gain_idx_tbl_extlna_2G[] = { 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x10000000, 0x00000040, 0x20000000, 0x00000040, 0x30000000, 0x00000040, 0x40000000, 0x00000040, 0x30000000, 0x00000048, 0x40000000, 0x00000048, 0x50000000, 0x00000048, 0x60000000, 0x00000048, 0x30000000, 0x00000058, 0x40000000, 0x00000058, 0x50000000, 0x00000058, 0x70000000, 0x00000058, 0x80000000, 0x00000058, 0x90000000, 0x00000058, 0xa0000000, 0x00000058, 0x70000000, 0x00000068, 0x80000000, 0x00000068, 0x90000000, 0x00000068, 0xa0000000, 0x00000068, 0xb0000000, 0x00000068, 0xc0000000, 0x00000068, 0xd0000000, 0x00000068, 0xe0000000, 0x00000068, 0xf0000000, 0x00000068, 0x00000000, 0x00000069, 0x10000000, 0x00000069, 0x20000000, 0x00000069, 0x30000000, 0x00000069, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x40000000, 0x00000041, 0x50000000, 0x00000041, 0x60000000, 0x00000041, 0x70000000, 0x00000041, 0x80000000, 0x00000041, 0x70000000, 0x00000049, 0x80000000, 0x00000049, 0x90000000, 0x00000049, 0xa0000000, 0x00000049, 0x70000000, 0x00000059, 0x80000000, 0x00000059, 0x90000000, 0x00000059, 0xb0000000, 0x00000059, 0xc0000000, 0x00000059, 0xd0000000, 0x00000059, 0xe0000000, 0x00000059, 0xb0000000, 0x00000069, 0xc0000000, 0x00000069, 0xd0000000, 0x00000069, 0xe0000000, 0x00000069, 0xf0000000, 0x00000069, 0x00000000, 0x0000006a, 0x10000000, 0x0000006a, 0x20000000, 0x0000006a, 0x30000000, 0x0000006a, 0x40000000, 0x0000006a, 0x50000000, 0x0000006a, 0x60000000, 0x0000006a, 0x70000000, 0x0000006a, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; static const u32 dot11lcn_aux_gain_idx_tbl_5G[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0186, 0x0187, 0x0188, 0x0189, 0x018a, 0x018b, 0x018c, 0x018d, 0x018e, 0x018f, 0x0190, 0x0191, 0x0192, 0x0193, 0x0194, 0x0195, 0x0196, 0x0197, 0x0198, 0x0199, 0x019a, 0x019b, 0x019c, 0x019d, 0x0000 }; static const u32 dot11lcn_gain_val_tbl_5G[] = { 0xf7, 0xfd, 0x00, 0x04, 0x04, 0x04, 0xf7, 0xfd, 0x00, 0x04, 0x04, 0x04, 0xf6, 0x00, 0x0c, 0x03, 0xeb, 0xfe, 0x06, 0x0a, 0x10, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15, 0x18, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15, 0x18, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u32 dot11lcn_gain_idx_tbl_5G[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x20000000, 0x00000000, 0x30000000, 0x00000000, 0x40000000, 0x00000000, 0x30000000, 0x00000008, 0x40000000, 0x00000008, 0x50000000, 0x00000008, 0x60000000, 0x00000008, 0x70000000, 0x00000008, 0x60000000, 0x00000018, 0x70000000, 0x00000018, 0x80000000, 0x00000018, 0x90000000, 0x00000018, 0xa0000000, 0x00000018, 0xb0000000, 0x00000018, 0xc0000000, 0x00000018, 0xd0000000, 0x00000018, 0xe0000000, 0x00000018, 0xf0000000, 0x00000018, 0x00000000, 0x00000019, 0x10000000, 0x00000019, 0x20000000, 0x00000019, 0x30000000, 0x00000019, 0x40000000, 0x00000019, 0x50000000, 0x00000019, 0x60000000, 0x00000019, 0x70000000, 0x00000019, 0x80000000, 0x00000019, 0x90000000, 0x00000019, 0xa0000000, 0x00000019, 0xb0000000, 0x00000019, 0xc0000000, 0x00000019, 0xd0000000, 0x00000019, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; static const u32 dot11lcn_gain_tbl_5G[] = { 0x00000000, 0x00000040, 0x00000080, 0x00000001, 0x00000005, 0x00000009, 0x0000000d, 0x00000011, 0x00000015, 0x00000055, 0x00000095, 0x00000017, 0x0000001b, 0x0000005b, 0x0000009b, 0x000000db, 0x0000011b, 0x0000015b, 0x0000019b, 0x0000059b, 0x0000099b, 0x00000d9b, 0x0000119b, 0x0000519b, 0x0000919b, 0x0000d19b, 0x0001119b, 0x0001519b, 0x0001919b, 0x0001d19b, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; const struct phytbl_info dot11lcnphytbl_rx_gain_info_rev0[] = { {&dot11lcn_gain_tbl_rev0, sizeof(dot11lcn_gain_tbl_rev0) / sizeof(dot11lcn_gain_tbl_rev0[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_rev0, sizeof(dot11lcn_aux_gain_idx_tbl_rev0) / sizeof(dot11lcn_aux_gain_idx_tbl_rev0[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_rev0, sizeof(dot11lcn_gain_idx_tbl_rev0) / sizeof(dot11lcn_gain_idx_tbl_rev0[0]), 13, 0, 32} , }; static const struct phytbl_info dot11lcnphytbl_rx_gain_info_rev1[] = { {&dot11lcn_gain_tbl_rev1, sizeof(dot11lcn_gain_tbl_rev1) / sizeof(dot11lcn_gain_tbl_rev1[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_rev0, sizeof(dot11lcn_aux_gain_idx_tbl_rev0) / sizeof(dot11lcn_aux_gain_idx_tbl_rev0[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_rev0, sizeof(dot11lcn_gain_idx_tbl_rev0) / sizeof(dot11lcn_gain_idx_tbl_rev0[0]), 13, 0, 32} , }; const struct phytbl_info dot11lcnphytbl_rx_gain_info_2G_rev2[] = { {&dot11lcn_gain_tbl_2G, sizeof(dot11lcn_gain_tbl_2G) / sizeof(dot11lcn_gain_tbl_2G[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_2G, sizeof(dot11lcn_aux_gain_idx_tbl_2G) / sizeof(dot11lcn_aux_gain_idx_tbl_2G[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_2G, sizeof(dot11lcn_gain_idx_tbl_2G) / sizeof(dot11lcn_gain_idx_tbl_2G[0]), 13, 0, 32} , {&dot11lcn_gain_val_tbl_2G, sizeof(dot11lcn_gain_val_tbl_2G) / sizeof(dot11lcn_gain_val_tbl_2G[0]), 17, 0, 8} }; const struct phytbl_info dot11lcnphytbl_rx_gain_info_5G_rev2[] = { {&dot11lcn_gain_tbl_5G, sizeof(dot11lcn_gain_tbl_5G) / sizeof(dot11lcn_gain_tbl_5G[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_5G, sizeof(dot11lcn_aux_gain_idx_tbl_5G) / sizeof(dot11lcn_aux_gain_idx_tbl_5G[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_5G, sizeof(dot11lcn_gain_idx_tbl_5G) / sizeof(dot11lcn_gain_idx_tbl_5G[0]), 13, 0, 32} , {&dot11lcn_gain_val_tbl_5G, sizeof(dot11lcn_gain_val_tbl_5G) / sizeof(dot11lcn_gain_val_tbl_5G[0]), 17, 0, 8} }; const struct phytbl_info dot11lcnphytbl_rx_gain_info_extlna_2G_rev2[] = { {&dot11lcn_gain_tbl_extlna_2G, sizeof(dot11lcn_gain_tbl_extlna_2G) / sizeof(dot11lcn_gain_tbl_extlna_2G[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_extlna_2G, sizeof(dot11lcn_aux_gain_idx_tbl_extlna_2G) / sizeof(dot11lcn_aux_gain_idx_tbl_extlna_2G[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_extlna_2G, sizeof(dot11lcn_gain_idx_tbl_extlna_2G) / sizeof(dot11lcn_gain_idx_tbl_extlna_2G[0]), 13, 0, 32} , {&dot11lcn_gain_val_tbl_extlna_2G, sizeof(dot11lcn_gain_val_tbl_extlna_2G) / sizeof(dot11lcn_gain_val_tbl_extlna_2G[0]), 17, 0, 8} }; const struct phytbl_info dot11lcnphytbl_rx_gain_info_extlna_5G_rev2[] = { {&dot11lcn_gain_tbl_5G, sizeof(dot11lcn_gain_tbl_5G) / sizeof(dot11lcn_gain_tbl_5G[0]), 18, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_5G, sizeof(dot11lcn_aux_gain_idx_tbl_5G) / sizeof(dot11lcn_aux_gain_idx_tbl_5G[0]), 14, 0, 16} , {&dot11lcn_gain_idx_tbl_5G, sizeof(dot11lcn_gain_idx_tbl_5G) / sizeof(dot11lcn_gain_idx_tbl_5G[0]), 13, 0, 32} , {&dot11lcn_gain_val_tbl_5G, sizeof(dot11lcn_gain_val_tbl_5G) / sizeof(dot11lcn_gain_val_tbl_5G[0]), 17, 0, 8} }; const u32 dot11lcnphytbl_rx_gain_info_sz_rev0 = sizeof(dot11lcnphytbl_rx_gain_info_rev0) / sizeof(dot11lcnphytbl_rx_gain_info_rev0[0]); const u32 dot11lcnphytbl_rx_gain_info_2G_rev2_sz = sizeof(dot11lcnphytbl_rx_gain_info_2G_rev2) / sizeof(dot11lcnphytbl_rx_gain_info_2G_rev2[0]); const u32 dot11lcnphytbl_rx_gain_info_5G_rev2_sz = sizeof(dot11lcnphytbl_rx_gain_info_5G_rev2) / sizeof(dot11lcnphytbl_rx_gain_info_5G_rev2[0]); static const u16 dot11lcn_min_sig_sq_tbl_rev0[] = { 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, }; static const u16 dot11lcn_noise_scale_tbl_rev0[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, }; static const u32 dot11lcn_fltr_ctrl_tbl_rev0[] = { 0x000141f8, 0x000021f8, 0x000021fb, 0x000041fb, 0x0001fe4b, 0x0000217b, 0x00002133, 0x000040eb, 0x0001fea3, 0x0000024b, }; static const u32 dot11lcn_ps_ctrl_tbl_rev0[] = { 0x00100001, 0x00200010, 0x00300001, 0x00400010, 0x00500022, 0x00600122, 0x00700222, 0x00800322, 0x00900422, 0x00a00522, 0x00b00622, 0x00c00722, 0x00d00822, 0x00f00922, 0x00100a22, 0x00200b22, 0x00300c22, 0x00400d22, 0x00500e22, 0x00600f22, }; static const u16 dot11lcn_sw_ctrl_tbl_4313_epa_rev0_combo[] = { 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x0007, 0x0005, 0x0006, 0x0004, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, 0x000b, 0x000b, 0x000a, 0x000a, }; static const u16 dot11lcn_sw_ctrl_tbl_4313_bt_epa_p250_rev0[] = { 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0005, 0x0002, 0x0000, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, 0x0007, 0x0007, 0x0002, 0x0002, }; static const u16 dot11lcn_sw_ctrl_tbl_4313_epa_rev0[] = { 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, 0x0002, 0x0008, 0x0004, 0x0001, }; static const u16 dot11lcn_sw_ctrl_tbl_4313_rev0[] = { 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, 0x000a, 0x0009, 0x0006, 0x0005, }; static const u16 dot11lcn_sw_ctrl_tbl_rev0[] = { 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, 0x0004, 0x0004, 0x0002, 0x0002, }; static const u8 dot11lcn_nf_table_rev0[] = { 0x5f, 0x36, 0x29, 0x1f, 0x5f, 0x36, 0x29, 0x1f, 0x5f, 0x36, 0x29, 0x1f, 0x5f, 0x36, 0x29, 0x1f, }; static const u8 dot11lcn_gain_val_tbl_rev0[] = { 0x09, 0x0f, 0x14, 0x18, 0xfe, 0x07, 0x0b, 0x0f, 0xfb, 0xfe, 0x01, 0x05, 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15, 0x18, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xeb, 0x00, 0x00, }; static const u8 dot11lcn_spur_tbl_rev0[] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x01, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x01, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }; static const u16 dot11lcn_unsup_mcs_tbl_rev0[] = { 0x001a, 0x0034, 0x004e, 0x0068, 0x009c, 0x00d0, 0x00ea, 0x0104, 0x0034, 0x0068, 0x009c, 0x00d0, 0x0138, 0x01a0, 0x01d4, 0x0208, 0x004e, 0x009c, 0x00ea, 0x0138, 0x01d4, 0x0270, 0x02be, 0x030c, 0x0068, 0x00d0, 0x0138, 0x01a0, 0x0270, 0x0340, 0x03a8, 0x0410, 0x0018, 0x009c, 0x00d0, 0x0104, 0x00ea, 0x0138, 0x0186, 0x00d0, 0x0104, 0x0104, 0x0138, 0x016c, 0x016c, 0x01a0, 0x0138, 0x0186, 0x0186, 0x01d4, 0x0222, 0x0222, 0x0270, 0x0104, 0x0138, 0x016c, 0x0138, 0x016c, 0x01a0, 0x01d4, 0x01a0, 0x01d4, 0x0208, 0x0208, 0x023c, 0x0186, 0x01d4, 0x0222, 0x01d4, 0x0222, 0x0270, 0x02be, 0x0270, 0x02be, 0x030c, 0x030c, 0x035a, 0x0036, 0x006c, 0x00a2, 0x00d8, 0x0144, 0x01b0, 0x01e6, 0x021c, 0x006c, 0x00d8, 0x0144, 0x01b0, 0x0288, 0x0360, 0x03cc, 0x0438, 0x00a2, 0x0144, 0x01e6, 0x0288, 0x03cc, 0x0510, 0x05b2, 0x0654, 0x00d8, 0x01b0, 0x0288, 0x0360, 0x0510, 0x06c0, 0x0798, 0x0870, 0x0018, 0x0144, 0x01b0, 0x021c, 0x01e6, 0x0288, 0x032a, 0x01b0, 0x021c, 0x021c, 0x0288, 0x02f4, 0x02f4, 0x0360, 0x0288, 0x032a, 0x032a, 0x03cc, 0x046e, 0x046e, 0x0510, 0x021c, 0x0288, 0x02f4, 0x0288, 0x02f4, 0x0360, 0x03cc, 0x0360, 0x03cc, 0x0438, 0x0438, 0x04a4, 0x032a, 0x03cc, 0x046e, 0x03cc, 0x046e, 0x0510, 0x05b2, 0x0510, 0x05b2, 0x0654, 0x0654, 0x06f6, }; static const u16 dot11lcn_iq_local_tbl_rev0[] = { 0x0200, 0x0300, 0x0400, 0x0600, 0x0800, 0x0b00, 0x1000, 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007, 0x1707, 0x2007, 0x2d07, 0x4007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x0300, 0x0400, 0x0600, 0x0800, 0x0b00, 0x1000, 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007, 0x1707, 0x2007, 0x2d07, 0x4007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, }; static const u32 dot11lcn_papd_compdelta_tbl_rev0[] = { 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, 0x00080000, }; const struct phytbl_info dot11lcnphytbl_info_rev0[] = { {&dot11lcn_min_sig_sq_tbl_rev0, sizeof(dot11lcn_min_sig_sq_tbl_rev0) / sizeof(dot11lcn_min_sig_sq_tbl_rev0[0]), 2, 0, 16} , {&dot11lcn_noise_scale_tbl_rev0, sizeof(dot11lcn_noise_scale_tbl_rev0) / sizeof(dot11lcn_noise_scale_tbl_rev0[0]), 1, 0, 16} , {&dot11lcn_fltr_ctrl_tbl_rev0, sizeof(dot11lcn_fltr_ctrl_tbl_rev0) / sizeof(dot11lcn_fltr_ctrl_tbl_rev0[0]), 11, 0, 32} , {&dot11lcn_ps_ctrl_tbl_rev0, sizeof(dot11lcn_ps_ctrl_tbl_rev0) / sizeof(dot11lcn_ps_ctrl_tbl_rev0[0]), 12, 0, 32} , {&dot11lcn_gain_idx_tbl_rev0, sizeof(dot11lcn_gain_idx_tbl_rev0) / sizeof(dot11lcn_gain_idx_tbl_rev0[0]), 13, 0, 32} , {&dot11lcn_aux_gain_idx_tbl_rev0, sizeof(dot11lcn_aux_gain_idx_tbl_rev0) / sizeof(dot11lcn_aux_gain_idx_tbl_rev0[0]), 14, 0, 16} , {&dot11lcn_sw_ctrl_tbl_rev0, sizeof(dot11lcn_sw_ctrl_tbl_rev0) / sizeof(dot11lcn_sw_ctrl_tbl_rev0[0]), 15, 0, 16} , {&dot11lcn_nf_table_rev0, sizeof(dot11lcn_nf_table_rev0) / sizeof(dot11lcn_nf_table_rev0[0]), 16, 0, 8} , {&dot11lcn_gain_val_tbl_rev0, sizeof(dot11lcn_gain_val_tbl_rev0) / sizeof(dot11lcn_gain_val_tbl_rev0[0]), 17, 0, 8} , {&dot11lcn_gain_tbl_rev0, sizeof(dot11lcn_gain_tbl_rev0) / sizeof(dot11lcn_gain_tbl_rev0[0]), 18, 0, 32} , {&dot11lcn_spur_tbl_rev0, sizeof(dot11lcn_spur_tbl_rev0) / sizeof(dot11lcn_spur_tbl_rev0[0]), 20, 0, 8} , {&dot11lcn_unsup_mcs_tbl_rev0, sizeof(dot11lcn_unsup_mcs_tbl_rev0) / sizeof(dot11lcn_unsup_mcs_tbl_rev0[0]), 23, 0, 16} , {&dot11lcn_iq_local_tbl_rev0, sizeof(dot11lcn_iq_local_tbl_rev0) / sizeof(dot11lcn_iq_local_tbl_rev0[0]), 0, 0, 16} , {&dot11lcn_papd_compdelta_tbl_rev0, sizeof(dot11lcn_papd_compdelta_tbl_rev0) / sizeof(dot11lcn_papd_compdelta_tbl_rev0[0]), 24, 0, 32} , }; const struct phytbl_info dot11lcn_sw_ctrl_tbl_info_4313 = { &dot11lcn_sw_ctrl_tbl_4313_rev0, sizeof(dot11lcn_sw_ctrl_tbl_4313_rev0) / sizeof(dot11lcn_sw_ctrl_tbl_4313_rev0[0]), 15, 0, 16 }; const struct phytbl_info dot11lcn_sw_ctrl_tbl_info_4313_epa = { &dot11lcn_sw_ctrl_tbl_4313_epa_rev0, sizeof(dot11lcn_sw_ctrl_tbl_4313_epa_rev0) / sizeof(dot11lcn_sw_ctrl_tbl_4313_epa_rev0[0]), 15, 0, 16 }; const struct phytbl_info dot11lcn_sw_ctrl_tbl_info_4313_bt_epa = { &dot11lcn_sw_ctrl_tbl_4313_epa_rev0_combo, sizeof(dot11lcn_sw_ctrl_tbl_4313_epa_rev0_combo) / sizeof(dot11lcn_sw_ctrl_tbl_4313_epa_rev0_combo[0]), 15, 0, 16 }; const struct phytbl_info dot11lcn_sw_ctrl_tbl_info_4313_bt_epa_p250 = { &dot11lcn_sw_ctrl_tbl_4313_bt_epa_p250_rev0, sizeof(dot11lcn_sw_ctrl_tbl_4313_bt_epa_p250_rev0) / sizeof(dot11lcn_sw_ctrl_tbl_4313_bt_epa_p250_rev0[0]), 15, 0, 16 }; const u32 dot11lcnphytbl_info_sz_rev0 = sizeof(dot11lcnphytbl_info_rev0) / sizeof(dot11lcnphytbl_info_rev0[0]); const struct lcnphy_tx_gain_tbl_entry dot11lcnphy_2GHz_extPA_gaintable_rev0[128] = { {3, 0, 31, 0, 72}, {3, 0, 31, 0, 70}, {3, 0, 31, 0, 68}, {3, 0, 30, 0, 67}, {3, 0, 29, 0, 68}, {3, 0, 28, 0, 68}, {3, 0, 27, 0, 69}, {3, 0, 26, 0, 70}, {3, 0, 25, 0, 70}, {3, 0, 24, 0, 71}, {3, 0, 23, 0, 72}, {3, 0, 23, 0, 70}, {3, 0, 22, 0, 71}, {3, 0, 21, 0, 72}, {3, 0, 21, 0, 70}, {3, 0, 21, 0, 68}, {3, 0, 21, 0, 66}, {3, 0, 21, 0, 64}, {3, 0, 21, 0, 63}, {3, 0, 20, 0, 64}, {3, 0, 19, 0, 65}, {3, 0, 19, 0, 64}, {3, 0, 18, 0, 65}, {3, 0, 18, 0, 64}, {3, 0, 17, 0, 65}, {3, 0, 17, 0, 64}, {3, 0, 16, 0, 65}, {3, 0, 16, 0, 64}, {3, 0, 16, 0, 62}, {3, 0, 16, 0, 60}, {3, 0, 16, 0, 58}, {3, 0, 15, 0, 61}, {3, 0, 15, 0, 59}, {3, 0, 14, 0, 61}, {3, 0, 14, 0, 60}, {3, 0, 14, 0, 58}, {3, 0, 13, 0, 60}, {3, 0, 13, 0, 59}, {3, 0, 12, 0, 62}, {3, 0, 12, 0, 60}, {3, 0, 12, 0, 58}, {3, 0, 11, 0, 62}, {3, 0, 11, 0, 60}, {3, 0, 11, 0, 59}, {3, 0, 11, 0, 57}, {3, 0, 10, 0, 61}, {3, 0, 10, 0, 59}, {3, 0, 10, 0, 57}, {3, 0, 9, 0, 62}, {3, 0, 9, 0, 60}, {3, 0, 9, 0, 58}, {3, 0, 9, 0, 57}, {3, 0, 8, 0, 62}, {3, 0, 8, 0, 60}, {3, 0, 8, 0, 58}, {3, 0, 8, 0, 57}, {3, 0, 8, 0, 55}, {3, 0, 7, 0, 61}, {3, 0, 7, 0, 60}, {3, 0, 7, 0, 58}, {3, 0, 7, 0, 56}, {3, 0, 7, 0, 55}, {3, 0, 6, 0, 62}, {3, 0, 6, 0, 60}, {3, 0, 6, 0, 58}, {3, 0, 6, 0, 57}, {3, 0, 6, 0, 55}, {3, 0, 6, 0, 54}, {3, 0, 6, 0, 52}, {3, 0, 5, 0, 61}, {3, 0, 5, 0, 59}, {3, 0, 5, 0, 57}, {3, 0, 5, 0, 56}, {3, 0, 5, 0, 54}, {3, 0, 5, 0, 53}, {3, 0, 5, 0, 51}, {3, 0, 4, 0, 62}, {3, 0, 4, 0, 60}, {3, 0, 4, 0, 58}, {3, 0, 4, 0, 57}, {3, 0, 4, 0, 55}, {3, 0, 4, 0, 54}, {3, 0, 4, 0, 52}, {3, 0, 4, 0, 51}, {3, 0, 4, 0, 49}, {3, 0, 4, 0, 48}, {3, 0, 4, 0, 46}, {3, 0, 3, 0, 60}, {3, 0, 3, 0, 58}, {3, 0, 3, 0, 57}, {3, 0, 3, 0, 55}, {3, 0, 3, 0, 54}, {3, 0, 3, 0, 52}, {3, 0, 3, 0, 51}, {3, 0, 3, 0, 49}, {3, 0, 3, 0, 48}, {3, 0, 3, 0, 46}, {3, 0, 3, 0, 45}, {3, 0, 3, 0, 44}, {3, 0, 3, 0, 43}, {3, 0, 3, 0, 41}, {3, 0, 2, 0, 61}, {3, 0, 2, 0, 59}, {3, 0, 2, 0, 57}, {3, 0, 2, 0, 56}, {3, 0, 2, 0, 54}, {3, 0, 2, 0, 53}, {3, 0, 2, 0, 51}, {3, 0, 2, 0, 50}, {3, 0, 2, 0, 48}, {3, 0, 2, 0, 47}, {3, 0, 2, 0, 46}, {3, 0, 2, 0, 44}, {3, 0, 2, 0, 43}, {3, 0, 2, 0, 42}, {3, 0, 2, 0, 41}, {3, 0, 2, 0, 39}, {3, 0, 2, 0, 38}, {3, 0, 2, 0, 37}, {3, 0, 2, 0, 36}, {3, 0, 2, 0, 35}, {3, 0, 2, 0, 34}, {3, 0, 2, 0, 33}, {3, 0, 2, 0, 32}, {3, 0, 1, 0, 63}, {3, 0, 1, 0, 61}, {3, 0, 1, 0, 59}, {3, 0, 1, 0, 57}, }; const struct lcnphy_tx_gain_tbl_entry dot11lcnphy_2GHz_gaintable_rev0[128] = { {7, 0, 31, 0, 72}, {7, 0, 31, 0, 70}, {7, 0, 31, 0, 68}, {7, 0, 30, 0, 67}, {7, 0, 29, 0, 68}, {7, 0, 28, 0, 68}, {7, 0, 27, 0, 69}, {7, 0, 26, 0, 70}, {7, 0, 25, 0, 70}, {7, 0, 24, 0, 71}, {7, 0, 23, 0, 72}, {7, 0, 23, 0, 70}, {7, 0, 22, 0, 71}, {7, 0, 21, 0, 72}, {7, 0, 21, 0, 70}, {7, 0, 21, 0, 68}, {7, 0, 21, 0, 66}, {7, 0, 21, 0, 64}, {7, 0, 21, 0, 63}, {7, 0, 20, 0, 64}, {7, 0, 19, 0, 65}, {7, 0, 19, 0, 64}, {7, 0, 18, 0, 65}, {7, 0, 18, 0, 64}, {7, 0, 17, 0, 65}, {7, 0, 17, 0, 64}, {7, 0, 16, 0, 65}, {7, 0, 16, 0, 64}, {7, 0, 16, 0, 62}, {7, 0, 16, 0, 60}, {7, 0, 16, 0, 58}, {7, 0, 15, 0, 61}, {7, 0, 15, 0, 59}, {7, 0, 14, 0, 61}, {7, 0, 14, 0, 60}, {7, 0, 14, 0, 58}, {7, 0, 13, 0, 60}, {7, 0, 13, 0, 59}, {7, 0, 12, 0, 62}, {7, 0, 12, 0, 60}, {7, 0, 12, 0, 58}, {7, 0, 11, 0, 62}, {7, 0, 11, 0, 60}, {7, 0, 11, 0, 59}, {7, 0, 11, 0, 57}, {7, 0, 10, 0, 61}, {7, 0, 10, 0, 59}, {7, 0, 10, 0, 57}, {7, 0, 9, 0, 62}, {7, 0, 9, 0, 60}, {7, 0, 9, 0, 58}, {7, 0, 9, 0, 57}, {7, 0, 8, 0, 62}, {7, 0, 8, 0, 60}, {7, 0, 8, 0, 58}, {7, 0, 8, 0, 57}, {7, 0, 8, 0, 55}, {7, 0, 7, 0, 61}, {7, 0, 7, 0, 60}, {7, 0, 7, 0, 58}, {7, 0, 7, 0, 56}, {7, 0, 7, 0, 55}, {7, 0, 6, 0, 62}, {7, 0, 6, 0, 60}, {7, 0, 6, 0, 58}, {7, 0, 6, 0, 57}, {7, 0, 6, 0, 55}, {7, 0, 6, 0, 54}, {7, 0, 6, 0, 52}, {7, 0, 5, 0, 61}, {7, 0, 5, 0, 59}, {7, 0, 5, 0, 57}, {7, 0, 5, 0, 56}, {7, 0, 5, 0, 54}, {7, 0, 5, 0, 53}, {7, 0, 5, 0, 51}, {7, 0, 4, 0, 62}, {7, 0, 4, 0, 60}, {7, 0, 4, 0, 58}, {7, 0, 4, 0, 57}, {7, 0, 4, 0, 55}, {7, 0, 4, 0, 54}, {7, 0, 4, 0, 52}, {7, 0, 4, 0, 51}, {7, 0, 4, 0, 49}, {7, 0, 4, 0, 48}, {7, 0, 4, 0, 46}, {7, 0, 3, 0, 60}, {7, 0, 3, 0, 58}, {7, 0, 3, 0, 57}, {7, 0, 3, 0, 55}, {7, 0, 3, 0, 54}, {7, 0, 3, 0, 52}, {7, 0, 3, 0, 51}, {7, 0, 3, 0, 49}, {7, 0, 3, 0, 48}, {7, 0, 3, 0, 46}, {7, 0, 3, 0, 45}, {7, 0, 3, 0, 44}, {7, 0, 3, 0, 43}, {7, 0, 3, 0, 41}, {7, 0, 2, 0, 61}, {7, 0, 2, 0, 59}, {7, 0, 2, 0, 57}, {7, 0, 2, 0, 56}, {7, 0, 2, 0, 54}, {7, 0, 2, 0, 53}, {7, 0, 2, 0, 51}, {7, 0, 2, 0, 50}, {7, 0, 2, 0, 48}, {7, 0, 2, 0, 47}, {7, 0, 2, 0, 46}, {7, 0, 2, 0, 44}, {7, 0, 2, 0, 43}, {7, 0, 2, 0, 42}, {7, 0, 2, 0, 41}, {7, 0, 2, 0, 39}, {7, 0, 2, 0, 38}, {7, 0, 2, 0, 37}, {7, 0, 2, 0, 36}, {7, 0, 2, 0, 35}, {7, 0, 2, 0, 34}, {7, 0, 2, 0, 33}, {7, 0, 2, 0, 32}, {7, 0, 1, 0, 63}, {7, 0, 1, 0, 61}, {7, 0, 1, 0, 59}, {7, 0, 1, 0, 57}, }; const struct lcnphy_tx_gain_tbl_entry dot11lcnphy_5GHz_gaintable_rev0[128] = { {255, 255, 0xf0, 0, 152}, {255, 255, 0xf0, 0, 147}, {255, 255, 0xf0, 0, 143}, {255, 255, 0xf0, 0, 139}, {255, 255, 0xf0, 0, 135}, {255, 255, 0xf0, 0, 131}, {255, 255, 0xf0, 0, 128}, {255, 255, 0xf0, 0, 124}, {255, 255, 0xf0, 0, 121}, {255, 255, 0xf0, 0, 117}, {255, 255, 0xf0, 0, 114}, {255, 255, 0xf0, 0, 111}, {255, 255, 0xf0, 0, 107}, {255, 255, 0xf0, 0, 104}, {255, 255, 0xf0, 0, 101}, {255, 255, 0xf0, 0, 99}, {255, 255, 0xf0, 0, 96}, {255, 255, 0xf0, 0, 93}, {255, 255, 0xf0, 0, 90}, {255, 255, 0xf0, 0, 88}, {255, 255, 0xf0, 0, 85}, {255, 255, 0xf0, 0, 83}, {255, 255, 0xf0, 0, 81}, {255, 255, 0xf0, 0, 78}, {255, 255, 0xf0, 0, 76}, {255, 255, 0xf0, 0, 74}, {255, 255, 0xf0, 0, 72}, {255, 255, 0xf0, 0, 70}, {255, 255, 0xf0, 0, 68}, {255, 255, 0xf0, 0, 66}, {255, 255, 0xf0, 0, 64}, {255, 248, 0xf0, 0, 64}, {255, 241, 0xf0, 0, 64}, {255, 251, 0xe0, 0, 64}, {255, 244, 0xe0, 0, 64}, {255, 254, 0xd0, 0, 64}, {255, 246, 0xd0, 0, 64}, {255, 239, 0xd0, 0, 64}, {255, 249, 0xc0, 0, 64}, {255, 242, 0xc0, 0, 64}, {255, 255, 0xb0, 0, 64}, {255, 248, 0xb0, 0, 64}, {255, 241, 0xb0, 0, 64}, {255, 254, 0xa0, 0, 64}, {255, 246, 0xa0, 0, 64}, {255, 239, 0xa0, 0, 64}, {255, 255, 0x90, 0, 64}, {255, 248, 0x90, 0, 64}, {255, 241, 0x90, 0, 64}, {255, 234, 0x90, 0, 64}, {255, 255, 0x80, 0, 64}, {255, 248, 0x80, 0, 64}, {255, 241, 0x80, 0, 64}, {255, 234, 0x80, 0, 64}, {255, 255, 0x70, 0, 64}, {255, 248, 0x70, 0, 64}, {255, 241, 0x70, 0, 64}, {255, 234, 0x70, 0, 64}, {255, 227, 0x70, 0, 64}, {255, 221, 0x70, 0, 64}, {255, 215, 0x70, 0, 64}, {255, 208, 0x70, 0, 64}, {255, 203, 0x70, 0, 64}, {255, 197, 0x70, 0, 64}, {255, 255, 0x60, 0, 64}, {255, 248, 0x60, 0, 64}, {255, 241, 0x60, 0, 64}, {255, 234, 0x60, 0, 64}, {255, 227, 0x60, 0, 64}, {255, 221, 0x60, 0, 64}, {255, 255, 0x50, 0, 64}, {255, 248, 0x50, 0, 64}, {255, 241, 0x50, 0, 64}, {255, 234, 0x50, 0, 64}, {255, 227, 0x50, 0, 64}, {255, 221, 0x50, 0, 64}, {255, 215, 0x50, 0, 64}, {255, 208, 0x50, 0, 64}, {255, 255, 0x40, 0, 64}, {255, 248, 0x40, 0, 64}, {255, 241, 0x40, 0, 64}, {255, 234, 0x40, 0, 64}, {255, 227, 0x40, 0, 64}, {255, 221, 0x40, 0, 64}, {255, 215, 0x40, 0, 64}, {255, 208, 0x40, 0, 64}, {255, 203, 0x40, 0, 64}, {255, 197, 0x40, 0, 64}, {255, 255, 0x30, 0, 64}, {255, 248, 0x30, 0, 64}, {255, 241, 0x30, 0, 64}, {255, 234, 0x30, 0, 64}, {255, 227, 0x30, 0, 64}, {255, 221, 0x30, 0, 64}, {255, 215, 0x30, 0, 64}, {255, 208, 0x30, 0, 64}, {255, 203, 0x30, 0, 64}, {255, 197, 0x30, 0, 64}, {255, 191, 0x30, 0, 64}, {255, 186, 0x30, 0, 64}, {255, 181, 0x30, 0, 64}, {255, 175, 0x30, 0, 64}, {255, 255, 0x20, 0, 64}, {255, 248, 0x20, 0, 64}, {255, 241, 0x20, 0, 64}, {255, 234, 0x20, 0, 64}, {255, 227, 0x20, 0, 64}, {255, 221, 0x20, 0, 64}, {255, 215, 0x20, 0, 64}, {255, 208, 0x20, 0, 64}, {255, 203, 0x20, 0, 64}, {255, 197, 0x20, 0, 64}, {255, 191, 0x20, 0, 64}, {255, 186, 0x20, 0, 64}, {255, 181, 0x20, 0, 64}, {255, 175, 0x20, 0, 64}, {255, 170, 0x20, 0, 64}, {255, 166, 0x20, 0, 64}, {255, 161, 0x20, 0, 64}, {255, 156, 0x20, 0, 64}, {255, 152, 0x20, 0, 64}, {255, 148, 0x20, 0, 64}, {255, 143, 0x20, 0, 64}, {255, 139, 0x20, 0, 64}, {255, 135, 0x20, 0, 64}, {255, 132, 0x20, 0, 64}, {255, 255, 0x10, 0, 64}, {255, 248, 0x10, 0, 64}, };
gpl-2.0
CoRfr/linux
arch/arm/kernel/pj4-cp0.c
7996
1967
/* * linux/arch/arm/kernel/pj4-cp0.c * * PJ4 iWMMXt coprocessor context switching and handling * * Copyright (c) 2010 Marvell International Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/init.h> #include <linux/io.h> #include <asm/thread_notify.h> static int iwmmxt_do(struct notifier_block *self, unsigned long cmd, void *t) { struct thread_info *thread = t; switch (cmd) { case THREAD_NOTIFY_FLUSH: /* * flush_thread() zeroes thread->fpstate, so no need * to do anything here. * * FALLTHROUGH: Ensure we don't try to overwrite our newly * initialised state information on the first fault. */ case THREAD_NOTIFY_EXIT: iwmmxt_task_release(thread); break; case THREAD_NOTIFY_SWITCH: iwmmxt_task_switch(thread); break; } return NOTIFY_DONE; } static struct notifier_block iwmmxt_notifier_block = { .notifier_call = iwmmxt_do, }; static u32 __init pj4_cp_access_read(void) { u32 value; __asm__ __volatile__ ( "mrc p15, 0, %0, c1, c0, 2\n\t" : "=r" (value)); return value; } static void __init pj4_cp_access_write(u32 value) { u32 temp; __asm__ __volatile__ ( "mcr p15, 0, %1, c1, c0, 2\n\t" "mrc p15, 0, %0, c1, c0, 2\n\t" "mov %0, %0\n\t" "sub pc, pc, #4\n\t" : "=r" (temp) : "r" (value)); } /* * Disable CP0/CP1 on boot, and let call_fpe() and the iWMMXt lazy * switch code handle iWMMXt context switching. */ static int __init pj4_cp0_init(void) { u32 cp_access; cp_access = pj4_cp_access_read() & ~0xf; pj4_cp_access_write(cp_access); printk(KERN_INFO "PJ4 iWMMXt coprocessor enabled.\n"); elf_hwcap |= HWCAP_IWMMXT; thread_register_notifier(&iwmmxt_notifier_block); return 0; } late_initcall(pj4_cp0_init);
gpl-2.0
onejay09/OLD----kernel_HTC_msm7x30_KK
arch/mips/pci/ops-bcm63xx.c
9020
11120
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr> */ #include <linux/types.h> #include <linux/pci.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/io.h> #include "pci-bcm63xx.h" /* * swizzle 32bits data to return only the needed part */ static int postprocess_read(u32 data, int where, unsigned int size) { u32 ret; ret = 0; switch (size) { case 1: ret = (data >> ((where & 3) << 3)) & 0xff; break; case 2: ret = (data >> ((where & 3) << 3)) & 0xffff; break; case 4: ret = data; break; } return ret; } static int preprocess_write(u32 orig_data, u32 val, int where, unsigned int size) { u32 ret; ret = 0; switch (size) { case 1: ret = (orig_data & ~(0xff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); break; case 2: ret = (orig_data & ~(0xffff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); break; case 4: ret = val; break; } return ret; } /* * setup hardware for a configuration cycle with given parameters */ static int bcm63xx_setup_cfg_access(int type, unsigned int busn, unsigned int devfn, int where) { unsigned int slot, func, reg; u32 val; slot = PCI_SLOT(devfn); func = PCI_FUNC(devfn); reg = where >> 2; /* sanity check */ if (slot > (MPI_L2PCFG_DEVNUM_MASK >> MPI_L2PCFG_DEVNUM_SHIFT)) return 1; if (func > (MPI_L2PCFG_FUNC_MASK >> MPI_L2PCFG_FUNC_SHIFT)) return 1; if (reg > (MPI_L2PCFG_REG_MASK >> MPI_L2PCFG_REG_SHIFT)) return 1; /* ok, setup config access */ val = (reg << MPI_L2PCFG_REG_SHIFT); val |= (func << MPI_L2PCFG_FUNC_SHIFT); val |= (slot << MPI_L2PCFG_DEVNUM_SHIFT); val |= MPI_L2PCFG_CFG_USEREG_MASK; val |= MPI_L2PCFG_CFG_SEL_MASK; /* type 0 cycle for local bus, type 1 cycle for anything else */ if (type != 0) { /* FIXME: how to specify bus ??? */ val |= (1 << MPI_L2PCFG_CFG_TYPE_SHIFT); } bcm_mpi_writel(val, MPI_L2PCFG_REG); return 0; } static int bcm63xx_do_cfg_read(int type, unsigned int busn, unsigned int devfn, int where, int size, u32 *val) { u32 data; /* two phase cycle, first we write address, then read data at * another location, caller already has a spinlock so no need * to add one here */ if (bcm63xx_setup_cfg_access(type, busn, devfn, where)) return PCIBIOS_DEVICE_NOT_FOUND; iob(); data = le32_to_cpu(__raw_readl(pci_iospace_start)); /* restore IO space normal behaviour */ bcm_mpi_writel(0, MPI_L2PCFG_REG); *val = postprocess_read(data, where, size); return PCIBIOS_SUCCESSFUL; } static int bcm63xx_do_cfg_write(int type, unsigned int busn, unsigned int devfn, int where, int size, u32 val) { u32 data; /* two phase cycle, first we write address, then write data to * another location, caller already has a spinlock so no need * to add one here */ if (bcm63xx_setup_cfg_access(type, busn, devfn, where)) return PCIBIOS_DEVICE_NOT_FOUND; iob(); data = le32_to_cpu(__raw_readl(pci_iospace_start)); data = preprocess_write(data, val, where, size); __raw_writel(cpu_to_le32(data), pci_iospace_start); wmb(); /* no way to know the access is done, we have to wait */ udelay(500); /* restore IO space normal behaviour */ bcm_mpi_writel(0, MPI_L2PCFG_REG); return PCIBIOS_SUCCESSFUL; } static int bcm63xx_pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val) { int type; type = bus->parent ? 1 : 0; if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL) return PCIBIOS_DEVICE_NOT_FOUND; return bcm63xx_do_cfg_read(type, bus->number, devfn, where, size, val); } static int bcm63xx_pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val) { int type; type = bus->parent ? 1 : 0; if (type == 0 && PCI_SLOT(devfn) == CARDBUS_PCI_IDSEL) return PCIBIOS_DEVICE_NOT_FOUND; return bcm63xx_do_cfg_write(type, bus->number, devfn, where, size, val); } struct pci_ops bcm63xx_pci_ops = { .read = bcm63xx_pci_read, .write = bcm63xx_pci_write }; #ifdef CONFIG_CARDBUS /* * emulate configuration read access on a cardbus bridge */ #define FAKE_CB_BRIDGE_SLOT 0x1e static int fake_cb_bridge_bus_number = -1; static struct { u16 pci_command; u8 cb_latency; u8 subordinate_busn; u8 cardbus_busn; u8 pci_busn; int bus_assigned; u16 bridge_control; u32 mem_base0; u32 mem_limit0; u32 mem_base1; u32 mem_limit1; u32 io_base0; u32 io_limit0; u32 io_base1; u32 io_limit1; } fake_cb_bridge_regs; static int fake_cb_bridge_read(int where, int size, u32 *val) { unsigned int reg; u32 data; data = 0; reg = where >> 2; switch (reg) { case (PCI_VENDOR_ID >> 2): case (PCI_CB_SUBSYSTEM_VENDOR_ID >> 2): /* create dummy vendor/device id from our cpu id */ data = (bcm63xx_get_cpu_id() << 16) | PCI_VENDOR_ID_BROADCOM; break; case (PCI_COMMAND >> 2): data = (PCI_STATUS_DEVSEL_SLOW << 16); data |= fake_cb_bridge_regs.pci_command; break; case (PCI_CLASS_REVISION >> 2): data = (PCI_CLASS_BRIDGE_CARDBUS << 16); break; case (PCI_CACHE_LINE_SIZE >> 2): data = (PCI_HEADER_TYPE_CARDBUS << 16); break; case (PCI_INTERRUPT_LINE >> 2): /* bridge control */ data = (fake_cb_bridge_regs.bridge_control << 16); /* pin:intA line:0xff */ data |= (0x1 << 8) | 0xff; break; case (PCI_CB_PRIMARY_BUS >> 2): data = (fake_cb_bridge_regs.cb_latency << 24); data |= (fake_cb_bridge_regs.subordinate_busn << 16); data |= (fake_cb_bridge_regs.cardbus_busn << 8); data |= fake_cb_bridge_regs.pci_busn; break; case (PCI_CB_MEMORY_BASE_0 >> 2): data = fake_cb_bridge_regs.mem_base0; break; case (PCI_CB_MEMORY_LIMIT_0 >> 2): data = fake_cb_bridge_regs.mem_limit0; break; case (PCI_CB_MEMORY_BASE_1 >> 2): data = fake_cb_bridge_regs.mem_base1; break; case (PCI_CB_MEMORY_LIMIT_1 >> 2): data = fake_cb_bridge_regs.mem_limit1; break; case (PCI_CB_IO_BASE_0 >> 2): /* | 1 for 32bits io support */ data = fake_cb_bridge_regs.io_base0 | 0x1; break; case (PCI_CB_IO_LIMIT_0 >> 2): data = fake_cb_bridge_regs.io_limit0; break; case (PCI_CB_IO_BASE_1 >> 2): /* | 1 for 32bits io support */ data = fake_cb_bridge_regs.io_base1 | 0x1; break; case (PCI_CB_IO_LIMIT_1 >> 2): data = fake_cb_bridge_regs.io_limit1; break; } *val = postprocess_read(data, where, size); return PCIBIOS_SUCCESSFUL; } /* * emulate configuration write access on a cardbus bridge */ static int fake_cb_bridge_write(int where, int size, u32 val) { unsigned int reg; u32 data, tmp; int ret; ret = fake_cb_bridge_read((where & ~0x3), 4, &data); if (ret != PCIBIOS_SUCCESSFUL) return ret; data = preprocess_write(data, val, where, size); reg = where >> 2; switch (reg) { case (PCI_COMMAND >> 2): fake_cb_bridge_regs.pci_command = (data & 0xffff); break; case (PCI_CB_PRIMARY_BUS >> 2): fake_cb_bridge_regs.cb_latency = (data >> 24) & 0xff; fake_cb_bridge_regs.subordinate_busn = (data >> 16) & 0xff; fake_cb_bridge_regs.cardbus_busn = (data >> 8) & 0xff; fake_cb_bridge_regs.pci_busn = data & 0xff; if (fake_cb_bridge_regs.cardbus_busn) fake_cb_bridge_regs.bus_assigned = 1; break; case (PCI_INTERRUPT_LINE >> 2): tmp = (data >> 16) & 0xffff; /* disable memory prefetch support */ tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0; tmp &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1; fake_cb_bridge_regs.bridge_control = tmp; break; case (PCI_CB_MEMORY_BASE_0 >> 2): fake_cb_bridge_regs.mem_base0 = data; break; case (PCI_CB_MEMORY_LIMIT_0 >> 2): fake_cb_bridge_regs.mem_limit0 = data; break; case (PCI_CB_MEMORY_BASE_1 >> 2): fake_cb_bridge_regs.mem_base1 = data; break; case (PCI_CB_MEMORY_LIMIT_1 >> 2): fake_cb_bridge_regs.mem_limit1 = data; break; case (PCI_CB_IO_BASE_0 >> 2): fake_cb_bridge_regs.io_base0 = data; break; case (PCI_CB_IO_LIMIT_0 >> 2): fake_cb_bridge_regs.io_limit0 = data; break; case (PCI_CB_IO_BASE_1 >> 2): fake_cb_bridge_regs.io_base1 = data; break; case (PCI_CB_IO_LIMIT_1 >> 2): fake_cb_bridge_regs.io_limit1 = data; break; } return PCIBIOS_SUCCESSFUL; } static int bcm63xx_cb_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val) { /* snoop access to slot 0x1e on root bus, we fake a cardbus * bridge at this location */ if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) { fake_cb_bridge_bus_number = bus->number; return fake_cb_bridge_read(where, size, val); } /* a configuration cycle for the device behind the cardbus * bridge is actually done as a type 0 cycle on the primary * bus. This means that only one device can be on the cardbus * bus */ if (fake_cb_bridge_regs.bus_assigned && bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(devfn) == 0) return bcm63xx_do_cfg_read(0, 0, PCI_DEVFN(CARDBUS_PCI_IDSEL, 0), where, size, val); return PCIBIOS_DEVICE_NOT_FOUND; } static int bcm63xx_cb_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val) { if (!bus->parent && PCI_SLOT(devfn) == FAKE_CB_BRIDGE_SLOT) { fake_cb_bridge_bus_number = bus->number; return fake_cb_bridge_write(where, size, val); } if (fake_cb_bridge_regs.bus_assigned && bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(devfn) == 0) return bcm63xx_do_cfg_write(0, 0, PCI_DEVFN(CARDBUS_PCI_IDSEL, 0), where, size, val); return PCIBIOS_DEVICE_NOT_FOUND; } struct pci_ops bcm63xx_cb_ops = { .read = bcm63xx_cb_read, .write = bcm63xx_cb_write, }; /* * only one IO window, so it cannot be shared by PCI and cardbus, use * fixup to choose and detect unhandled configuration */ static void bcm63xx_fixup(struct pci_dev *dev) { static int io_window = -1; int i, found, new_io_window; u32 val; /* look for any io resource */ found = 0; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { if (pci_resource_flags(dev, i) & IORESOURCE_IO) { found = 1; break; } } if (!found) return; /* skip our fake bus with only cardbus bridge on it */ if (dev->bus->number == fake_cb_bridge_bus_number) return; /* find on which bus the device is */ if (fake_cb_bridge_regs.bus_assigned && dev->bus->number == fake_cb_bridge_regs.cardbus_busn && PCI_SLOT(dev->devfn) == 0) new_io_window = 1; else new_io_window = 0; if (new_io_window == io_window) return; if (io_window != -1) { printk(KERN_ERR "bcm63xx: both PCI and cardbus devices " "need IO, which hardware cannot do\n"); return; } printk(KERN_INFO "bcm63xx: PCI IO window assigned to %s\n", (new_io_window == 0) ? "PCI" : "cardbus"); val = bcm_mpi_readl(MPI_L2PIOREMAP_REG); if (io_window) val |= MPI_L2PREMAP_IS_CARDBUS_MASK; else val &= ~MPI_L2PREMAP_IS_CARDBUS_MASK; bcm_mpi_writel(val, MPI_L2PIOREMAP_REG); io_window = new_io_window; } DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, bcm63xx_fixup); #endif
gpl-2.0
ecostaalfaia/linux-sunxi-3.4_aufs_support
drivers/mmc/mmc-pm/mmc_pm_usi_bm01a.c
61
6342
/* * drivers/mmc/mmc-pm/mmc_pm_usi_bm01a.c * * (C) Copyright 2007-2012 * Allwinner Technology Co., Ltd. <www.allwinnertech.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ /* * USI wm-bn-bm-01-5(bcm4329) sdio wifi power management API * evb gpio define * A10 gpio define: * usi_bm01a_wl_pwr = port:PH12<1><default><default><0> * usi_bm01a_wlbt_regon = port:PI11<1><default><default><0> * usi_bm01a_wl_rst = port:PI10<1><default><default><0> * usi_bm01a_wl_wake = port:PI12<1><default><default><0> * usi_bm01a_bt_rst = port:PB05<1><default><default><0> * usi_bm01a_bt_wake = port:PI20<1><default><default><0> * usi_bm01a_bt_hostwake = port:PI21<0><default><default><0> * ----------------------------------------------------------- * A12 gpio define: * usi_bm01a_wl_pwr = LDO3 * usi_bm01a_wl_wake = port:PA01<1><default><default><0> * usi_bm01a_wlbt_regon = port:PA02<1><default><default><0> * usi_bm01a_wl_rst = port:PA03<1><default><default><0> * usi_bm01a_bt_rst = port:PA04<1><default><default><0> * usi_bm01a_bt_wake = port:PA05<1><default><default><0> * usi_bm01a_bt_hostwake = */ #include <linux/kernel.h> #include <linux/module.h> #include <plat/sys_config.h> #include "mmc_pm.h" #define usi_msg(...) do {printk("[usi_bm01a]: "__VA_ARGS__);} while(0) static int usi_bm01a_wl_on = 0; static int usi_bm01a_bt_on = 0; #ifdef CONFIG_ARCH_SUN5I #include <linux/regulator/consumer.h> static int usi_bm01a_power_onoff(int onoff) { struct regulator* wifi_ldo = NULL; static int first = 1; #ifndef CONFIG_AW_AXP usi_msg("AXP driver is disabled, pls check !!\n"); return 0; #endif usi_msg("usi_bm01a_power_onoff\n"); wifi_ldo = regulator_get(NULL, "axp20_pll"); if (!wifi_ldo) usi_msg("Get power regulator failed\n"); if (first) { usi_msg("first time\n"); regulator_force_disable(wifi_ldo); first = 0; } if (onoff) { usi_msg("regulator on\n"); regulator_set_voltage(wifi_ldo, 3300000, 3300000); regulator_enable(wifi_ldo); } else { usi_msg("regulator off\n"); regulator_disable(wifi_ldo); } return 0; } #endif static int usi_bm01a_gpio_ctrl(char* name, int level) { struct mmc_pm_ops *ops = &mmc_card_pm_ops; char* gpio_cmd[6] = {"usi_bm01a_wl_regon", "usi_bm01a_bt_regon", "usi_bm01a_wl_rst", "usi_bm01a_wl_wake", "usi_bm01a_bt_rst", "usi_bm01a_bt_wake"}; int i = 0; int ret = 0; for (i=0; i<6; i++) { if (strcmp(name, gpio_cmd[i])==0) break; } if (i==6) { usi_msg("No gpio %s for USI-BM01A module\n", name); return -1; } // usi_msg("Set GPIO %s to %d !\n", name, level); if (strcmp(name, "usi_bm01a_wl_regon") == 0) { if (level) { if (usi_bm01a_bt_on) { usi_msg("USI-BM01A is already powered up by bluetooth\n"); goto change_state; } else { usi_msg("USI-BM01A is powered up by wifi\n"); goto power_change; } } else { if (usi_bm01a_bt_on) { usi_msg("USI-BM01A should stay on because of bluetooth\n"); goto change_state; } else { usi_msg("USI-BM01A is powered off by wifi\n"); goto power_change; } } } if (strcmp(name, "usi_bm01a_bt_regon") == 0) { if (level) { if (usi_bm01a_wl_on) { usi_msg("USI-BM01A is already powered up by wifi\n"); goto change_state; } else { usi_msg("USI-BM01A is powered up by bt\n"); goto power_change; } } else { if (usi_bm01a_wl_on) { usi_msg("USI-BM01A should stay on because of wifi\n"); goto change_state; } else { usi_msg("USI-BM01A is powered off by bt\n"); goto power_change; } } } ret = gpio_write_one_pin_value(ops->pio_hdle, level, name); if (ret) { usi_msg("Failed to set gpio %s to %d !\n", name, level); return -1; } return 0; power_change: #if defined(CONFIG_ARCH_SUN4I) || defined(CONFIG_ARCH_SUN7I) ret = gpio_write_one_pin_value(ops->pio_hdle, level, "usi_bm01a_wl_pwr"); #elif defined(CONFIG_ARCH_SUN5I) ret = usi_bm01a_power_onoff(level); #else #error "Found wrong chip id in wifi onoff\n" #endif if (ret) { usi_msg("Failed to power off USI-BM01A module!\n"); return -1; } ret = gpio_write_one_pin_value(ops->pio_hdle, level, "usi_bm01a_wlbt_regon"); if (ret) { usi_msg("Failed to regon off for USI-BM01A module!\n"); return -1; } change_state: if (strcmp(name, "usi_bm01a_wl_regon")==0) usi_bm01a_wl_on = level; if (strcmp(name, "usi_bm01a_bt_regon")==0) usi_bm01a_bt_on = level; usi_msg("USI-BM01A power state change: wifi %d, bt %d !!\n", usi_bm01a_wl_on, usi_bm01a_bt_on); return 0; } static int usi_bm01a_get_gpio_value(char* name) { struct mmc_pm_ops *ops = &mmc_card_pm_ops; char* bt_hostwake = "usi_bm01a_bt_hostwake"; if (strcmp(name, bt_hostwake)) { usi_msg("No gpio %s for USI-BM01A\n", name); return -1; } return gpio_read_one_pin_value(ops->pio_hdle, name); } void usi_bm01a_gpio_init(void) { struct mmc_pm_ops *ops = &mmc_card_pm_ops; usi_bm01a_wl_on = 0; usi_bm01a_bt_on = 0; ops->gpio_ctrl = usi_bm01a_gpio_ctrl; ops->get_io_val = usi_bm01a_get_gpio_value; }
gpl-2.0
gototem/kernel
arch/powerpc/mm/fault.c
573
14865
/* * PowerPC version * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) * * Derived from "arch/i386/mm/fault.c" * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds * * Modified by Cort Dougan and Paul Mackerras. * * Modified for PPC64 by Dave Engebretsen (engebret@ibm.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/signal.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/types.h> #include <linux/ptrace.h> #include <linux/mman.h> #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/highmem.h> #include <linux/module.h> #include <linux/kprobes.h> #include <linux/kdebug.h> #include <linux/perf_event.h> #include <linux/magic.h> #include <linux/ratelimit.h> #include <linux/context_tracking.h> #include <asm/firmware.h> #include <asm/page.h> #include <asm/pgtable.h> #include <asm/mmu.h> #include <asm/mmu_context.h> #include <asm/uaccess.h> #include <asm/tlbflush.h> #include <asm/siginfo.h> #include <asm/debug.h> #include <mm/mmu_decl.h> #include "icswx.h" #ifdef CONFIG_KPROBES static inline int notify_page_fault(struct pt_regs *regs) { int ret = 0; /* kprobe_running() needs smp_processor_id() */ if (!user_mode(regs)) { preempt_disable(); if (kprobe_running() && kprobe_fault_handler(regs, 11)) ret = 1; preempt_enable(); } return ret; } #else static inline int notify_page_fault(struct pt_regs *regs) { return 0; } #endif /* * Check whether the instruction at regs->nip is a store using * an update addressing form which will update r1. */ static int store_updates_sp(struct pt_regs *regs) { unsigned int inst; if (get_user(inst, (unsigned int __user *)regs->nip)) return 0; /* check for 1 in the rA field */ if (((inst >> 16) & 0x1f) != 1) return 0; /* check major opcode */ switch (inst >> 26) { case 37: /* stwu */ case 39: /* stbu */ case 45: /* sthu */ case 53: /* stfsu */ case 55: /* stfdu */ return 1; case 62: /* std or stdu */ return (inst & 3) == 1; case 31: /* check minor opcode */ switch ((inst >> 1) & 0x3ff) { case 181: /* stdux */ case 183: /* stwux */ case 247: /* stbux */ case 439: /* sthux */ case 695: /* stfsux */ case 759: /* stfdux */ return 1; } } return 0; } /* * do_page_fault error handling helpers */ #define MM_FAULT_RETURN 0 #define MM_FAULT_CONTINUE -1 #define MM_FAULT_ERR(sig) (sig) static int do_sigbus(struct pt_regs *regs, unsigned long address) { siginfo_t info; up_read(&current->mm->mmap_sem); if (user_mode(regs)) { current->thread.trap_nr = BUS_ADRERR; info.si_signo = SIGBUS; info.si_errno = 0; info.si_code = BUS_ADRERR; info.si_addr = (void __user *)address; force_sig_info(SIGBUS, &info, current); return MM_FAULT_RETURN; } return MM_FAULT_ERR(SIGBUS); } static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault) { /* * Pagefault was interrupted by SIGKILL. We have no reason to * continue the pagefault. */ if (fatal_signal_pending(current)) { /* * If we have retry set, the mmap semaphore will have * alrady been released in __lock_page_or_retry(). Else * we release it now. */ if (!(fault & VM_FAULT_RETRY)) up_read(&current->mm->mmap_sem); /* Coming from kernel, we need to deal with uaccess fixups */ if (user_mode(regs)) return MM_FAULT_RETURN; return MM_FAULT_ERR(SIGKILL); } /* No fault: be happy */ if (!(fault & VM_FAULT_ERROR)) return MM_FAULT_CONTINUE; /* Out of memory */ if (fault & VM_FAULT_OOM) { up_read(&current->mm->mmap_sem); /* * We ran out of memory, or some other thing happened to us that * made us unable to handle the page fault gracefully. */ if (!user_mode(regs)) return MM_FAULT_ERR(SIGKILL); pagefault_out_of_memory(); return MM_FAULT_RETURN; } /* Bus error. x86 handles HWPOISON here, we'll add this if/when * we support the feature in HW */ if (fault & VM_FAULT_SIGBUS) return do_sigbus(regs, addr); /* We don't understand the fault code, this is fatal */ BUG(); return MM_FAULT_CONTINUE; } /* * For 600- and 800-family processors, the error_code parameter is DSISR * for a data fault, SRR1 for an instruction fault. For 400-family processors * the error_code parameter is ESR for a data fault, 0 for an instruction * fault. * For 64-bit processors, the error_code parameter is * - DSISR for a non-SLB data access fault, * - SRR1 & 0x08000000 for a non-SLB instruction access fault * - 0 any SLB fault. * * The return value is 0 if the fault was handled, or the signal * number if this is a kernel fault that can't be handled here. */ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address, unsigned long error_code) { enum ctx_state prev_state = exception_enter(); struct vm_area_struct * vma; struct mm_struct *mm = current->mm; unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; int code = SEGV_MAPERR; int is_write = 0; int trap = TRAP(regs); int is_exec = trap == 0x400; int fault; int rc = 0; #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE)) /* * Fortunately the bit assignments in SRR1 for an instruction * fault and DSISR for a data fault are mostly the same for the * bits we are interested in. But there are some bits which * indicate errors in DSISR but can validly be set in SRR1. */ if (trap == 0x400) error_code &= 0x48200000; else is_write = error_code & DSISR_ISSTORE; #else is_write = error_code & ESR_DST; #endif /* CONFIG_4xx || CONFIG_BOOKE */ if (is_write) flags |= FAULT_FLAG_WRITE; #ifdef CONFIG_PPC_ICSWX /* * we need to do this early because this "data storage * interrupt" does not update the DAR/DEAR so we don't want to * look at it */ if (error_code & ICSWX_DSI_UCT) { rc = acop_handle_fault(regs, address, error_code); if (rc) goto bail; } #endif /* CONFIG_PPC_ICSWX */ if (notify_page_fault(regs)) goto bail; if (unlikely(debugger_fault_handler(regs))) goto bail; /* On a kernel SLB miss we can only check for a valid exception entry */ if (!user_mode(regs) && (address >= TASK_SIZE)) { rc = SIGSEGV; goto bail; } #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE) || \ defined(CONFIG_PPC_BOOK3S_64)) if (error_code & DSISR_DABRMATCH) { /* breakpoint match */ do_break(regs, address, error_code); goto bail; } #endif /* We restore the interrupt state now */ if (!arch_irq_disabled_regs(regs)) local_irq_enable(); if (in_atomic() || mm == NULL) { if (!user_mode(regs)) { rc = SIGSEGV; goto bail; } /* in_atomic() in user mode is really bad, as is current->mm == NULL. */ printk(KERN_EMERG "Page fault in user mode with " "in_atomic() = %d mm = %p\n", in_atomic(), mm); printk(KERN_EMERG "NIP = %lx MSR = %lx\n", regs->nip, regs->msr); die("Weird page fault", regs, SIGSEGV); } perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); /* When running in the kernel we expect faults to occur only to * addresses in user space. All other faults represent errors in the * kernel and should generate an OOPS. Unfortunately, in the case of an * erroneous fault occurring in a code path which already holds mmap_sem * we will deadlock attempting to validate the fault against the * address space. Luckily the kernel only validly references user * space from well defined areas of code, which are listed in the * exceptions table. * * As the vast majority of faults will be valid we will only perform * the source reference check when there is a possibility of a deadlock. * Attempt to lock the address space, if we cannot we then validate the * source. If this is invalid we can skip the address space check, * thus avoiding the deadlock. */ if (!down_read_trylock(&mm->mmap_sem)) { if (!user_mode(regs) && !search_exception_tables(regs->nip)) goto bad_area_nosemaphore; retry: down_read(&mm->mmap_sem); } else { /* * The above down_read_trylock() might have succeeded in * which case we'll have missed the might_sleep() from * down_read(): */ might_sleep(); } vma = find_vma(mm, address); if (!vma) goto bad_area; if (vma->vm_start <= address) goto good_area; if (!(vma->vm_flags & VM_GROWSDOWN)) goto bad_area; /* * N.B. The POWER/Open ABI allows programs to access up to * 288 bytes below the stack pointer. * The kernel signal delivery code writes up to about 1.5kB * below the stack pointer (r1) before decrementing it. * The exec code can write slightly over 640kB to the stack * before setting the user r1. Thus we allow the stack to * expand to 1MB without further checks. */ if (address + 0x100000 < vma->vm_end) { /* get user regs even if this fault is in kernel mode */ struct pt_regs *uregs = current->thread.regs; if (uregs == NULL) goto bad_area; /* * A user-mode access to an address a long way below * the stack pointer is only valid if the instruction * is one which would update the stack pointer to the * address accessed if the instruction completed, * i.e. either stwu rs,n(r1) or stwux rs,r1,rb * (or the byte, halfword, float or double forms). * * If we don't check this then any write to the area * between the last mapped region and the stack will * expand the stack rather than segfaulting. */ if (address + 2048 < uregs->gpr[1] && (!user_mode(regs) || !store_updates_sp(regs))) goto bad_area; } if (expand_stack(vma, address)) goto bad_area; good_area: code = SEGV_ACCERR; #if defined(CONFIG_6xx) if (error_code & 0x95700000) /* an error such as lwarx to I/O controller space, address matching DABR, eciwx, etc. */ goto bad_area; #endif /* CONFIG_6xx */ #if defined(CONFIG_8xx) /* 8xx sometimes need to load a invalid/non-present TLBs. * These must be invalidated separately as linux mm don't. */ if (error_code & 0x40000000) /* no translation? */ _tlbil_va(address, 0, 0, 0); /* The MPC8xx seems to always set 0x80000000, which is * "undefined". Of those that can be set, this is the only * one which seems bad. */ if (error_code & 0x10000000) /* Guarded storage error. */ goto bad_area; #endif /* CONFIG_8xx */ if (is_exec) { #ifdef CONFIG_PPC_STD_MMU /* Protection fault on exec go straight to failure on * Hash based MMUs as they either don't support per-page * execute permission, or if they do, it's handled already * at the hash level. This test would probably have to * be removed if we change the way this works to make hash * processors use the same I/D cache coherency mechanism * as embedded. */ if (error_code & DSISR_PROTFAULT) goto bad_area; #endif /* CONFIG_PPC_STD_MMU */ /* * Allow execution from readable areas if the MMU does not * provide separate controls over reading and executing. * * Note: That code used to not be enabled for 4xx/BookE. * It is now as I/D cache coherency for these is done at * set_pte_at() time and I see no reason why the test * below wouldn't be valid on those processors. This -may- * break programs compiled with a really old ABI though. */ if (!(vma->vm_flags & VM_EXEC) && (cpu_has_feature(CPU_FTR_NOEXECUTE) || !(vma->vm_flags & (VM_READ | VM_WRITE)))) goto bad_area; /* a write */ } else if (is_write) { if (!(vma->vm_flags & VM_WRITE)) goto bad_area; /* a read */ } else { /* protection fault */ if (error_code & 0x08000000) goto bad_area; if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) goto bad_area; } /* * If for any reason at all we couldn't handle the fault, * make sure we exit gracefully rather than endlessly redo * the fault. */ fault = handle_mm_fault(mm, vma, address, flags); if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) { rc = mm_fault_error(regs, address, fault); if (rc >= MM_FAULT_RETURN) goto bail; else rc = 0; } /* * Major/minor page fault accounting is only done on the * initial attempt. If we go through a retry, it is extremely * likely that the page will be found in page cache at that point. */ if (flags & FAULT_FLAG_ALLOW_RETRY) { if (fault & VM_FAULT_MAJOR) { current->maj_flt++; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address); #ifdef CONFIG_PPC_SMLPAR if (firmware_has_feature(FW_FEATURE_CMO)) { preempt_disable(); get_lppaca()->page_ins += (1 << PAGE_FACTOR); preempt_enable(); } #endif /* CONFIG_PPC_SMLPAR */ } else { current->min_flt++; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); } if (fault & VM_FAULT_RETRY) { /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk * of starvation. */ flags &= ~FAULT_FLAG_ALLOW_RETRY; flags |= FAULT_FLAG_TRIED; goto retry; } } up_read(&mm->mmap_sem); goto bail; bad_area: up_read(&mm->mmap_sem); bad_area_nosemaphore: /* User mode accesses cause a SIGSEGV */ if (user_mode(regs)) { _exception(SIGSEGV, regs, code, address); goto bail; } if (is_exec && (error_code & DSISR_PROTFAULT)) printk_ratelimited(KERN_CRIT "kernel tried to execute NX-protected" " page (%lx) - exploit attempt? (uid: %d)\n", address, from_kuid(&init_user_ns, current_uid())); rc = SIGSEGV; bail: exception_exit(prev_state); return rc; } /* * bad_page_fault is called when we have a bad access from the kernel. * It is called from the DSI and ISI handlers in head.S and from some * of the procedures in traps.c. */ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig) { const struct exception_table_entry *entry; unsigned long *stackend; /* Are we prepared to handle this fault? */ if ((entry = search_exception_tables(regs->nip)) != NULL) { regs->nip = entry->fixup; return; } /* kernel has accessed a bad area */ switch (regs->trap) { case 0x300: case 0x380: printk(KERN_ALERT "Unable to handle kernel paging request for " "data at address 0x%08lx\n", regs->dar); break; case 0x400: case 0x480: printk(KERN_ALERT "Unable to handle kernel paging request for " "instruction fetch\n"); break; default: printk(KERN_ALERT "Unable to handle kernel paging request for " "unknown fault\n"); break; } printk(KERN_ALERT "Faulting instruction address: 0x%08lx\n", regs->nip); stackend = end_of_stack(current); if (current != &init_task && *stackend != STACK_END_MAGIC) printk(KERN_ALERT "Thread overran stack, or stack corrupted\n"); die("Kernel access of bad area", regs, sig); }
gpl-2.0
shankarathi07/linux_samsung_ics
drivers/net/wireless/rt2x00/rt2800usb.c
573
32302
/* Copyright (C) 2010 Willow Garage <http://www.willowgarage.com> Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com> Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> Copyright (C) 2009 Axel Kollhofer <rain_maker@root-forum.org> <http://rt2x00.serialmonkey.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Module: rt2800usb Abstract: rt2800usb device specific routines. Supported chipsets: RT2800U. */ #include <linux/delay.h> #include <linux/etherdevice.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> #include "rt2x00.h" #include "rt2x00usb.h" #include "rt2800lib.h" #include "rt2800.h" #include "rt2800usb.h" /* * Allow hardware encryption to be disabled. */ static int modparam_nohwcrypt; module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); /* * Queue handlers. */ static void rt2800usb_start_queue(struct data_queue *queue) { struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; u32 reg; switch (queue->qid) { case QID_RX: rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1); rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); break; case QID_BEACON: rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg); rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1); rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1); rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1); rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg); break; default: break; } } static void rt2800usb_stop_queue(struct data_queue *queue) { struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; u32 reg; switch (queue->qid) { case QID_RX: rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0); rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); break; case QID_BEACON: rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg); rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0); rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0); rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0); rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg); break; default: break; } } /* * test if there is an entry in any TX queue for which DMA is done * but the TX status has not been returned yet */ static bool rt2800usb_txstatus_pending(struct rt2x00_dev *rt2x00dev) { struct data_queue *queue; tx_queue_for_each(rt2x00dev, queue) { if (rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE) != rt2x00queue_get_entry(queue, Q_INDEX_DONE)) return true; } return false; } static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev, int urb_status, u32 tx_status) { if (urb_status) { WARNING(rt2x00dev, "rt2x00usb_register_read_async failed: %d\n", urb_status); return false; } /* try to read all TX_STA_FIFO entries before scheduling txdone_work */ if (rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID)) { if (!kfifo_put(&rt2x00dev->txstatus_fifo, &tx_status)) { WARNING(rt2x00dev, "TX status FIFO overrun, " "drop tx status report.\n"); queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work); } else return true; } else if (!kfifo_is_empty(&rt2x00dev->txstatus_fifo)) { queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work); } else if (rt2800usb_txstatus_pending(rt2x00dev)) { mod_timer(&rt2x00dev->txstatus_timer, jiffies + msecs_to_jiffies(2)); } return false; } static void rt2800usb_tx_dma_done(struct queue_entry *entry) { struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO, rt2800usb_tx_sta_fifo_read_completed); } static void rt2800usb_tx_sta_fifo_timeout(unsigned long data) { struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data; rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO, rt2800usb_tx_sta_fifo_read_completed); } /* * Firmware functions */ static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev) { return FIRMWARE_RT2870; } static int rt2800usb_write_firmware(struct rt2x00_dev *rt2x00dev, const u8 *data, const size_t len) { int status; u32 offset; u32 length; /* * Check which section of the firmware we need. */ if (rt2x00_rt(rt2x00dev, RT2860) || rt2x00_rt(rt2x00dev, RT2872) || rt2x00_rt(rt2x00dev, RT3070)) { offset = 0; length = 4096; } else { offset = 4096; length = 4096; } /* * Write firmware to device. */ rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, data + offset, length); rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0); rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0); /* * Send firmware request to device to load firmware, * we need to specify a long timeout time. */ status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0, USB_MODE_FIRMWARE, REGISTER_TIMEOUT_FIRMWARE); if (status < 0) { ERROR(rt2x00dev, "Failed to write Firmware to device.\n"); return status; } msleep(10); rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); return 0; } /* * Device state switch handlers. */ static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev) { u32 reg; /* * Wait until BBP and RF are ready. */ if (rt2800_wait_csr_ready(rt2x00dev)) return -EBUSY; rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg); rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000); rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003); rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1); rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1); rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000); rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0, USB_MODE_RESET, REGISTER_TIMEOUT); rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000); return 0; } static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev) { u32 reg; if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev))) return -EIO; rt2x00usb_register_read(rt2x00dev, USB_DMA_CFG, &reg); rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0); rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN, 0); rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128); /* * Total room for RX frames in kilobytes, PBF might still exceed * this limit so reduce the number to prevent errors. */ rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT, ((rt2x00dev->ops->rx->entry_num * DATA_FRAME_SIZE) / 1024) - 3); rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1); rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1); rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg); return rt2800_enable_radio(rt2x00dev); } static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev) { rt2800_disable_radio(rt2x00dev); rt2x00usb_disable_radio(rt2x00dev); } static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) { if (state == STATE_AWAKE) rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 2); else rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0xff, 2); return 0; } static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) { int retval = 0; switch (state) { case STATE_RADIO_ON: /* * Before the radio can be enabled, the device first has * to be woken up. After that it needs a bit of time * to be fully awake and then the radio can be enabled. */ rt2800usb_set_state(rt2x00dev, STATE_AWAKE); msleep(1); retval = rt2800usb_enable_radio(rt2x00dev); break; case STATE_RADIO_OFF: /* * After the radio has been disabled, the device should * be put to sleep for powersaving. */ rt2800usb_disable_radio(rt2x00dev); rt2800usb_set_state(rt2x00dev, STATE_SLEEP); break; case STATE_RADIO_IRQ_ON: case STATE_RADIO_IRQ_OFF: /* No support, but no error either */ break; case STATE_DEEP_SLEEP: case STATE_SLEEP: case STATE_STANDBY: case STATE_AWAKE: retval = rt2800usb_set_state(rt2x00dev, state); break; default: retval = -ENOTSUPP; break; } if (unlikely(retval)) ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n", state, retval); return retval; } /* * Watchdog handlers */ static void rt2800usb_watchdog(struct rt2x00_dev *rt2x00dev) { unsigned int i; u32 reg; rt2x00usb_register_read(rt2x00dev, TXRXQ_PCNT, &reg); if (rt2x00_get_field32(reg, TXRXQ_PCNT_TX0Q)) { WARNING(rt2x00dev, "TX HW queue 0 timed out," " invoke forced kick\n"); rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40012); for (i = 0; i < 10; i++) { udelay(10); if (!rt2x00_get_field32(reg, TXRXQ_PCNT_TX0Q)) break; } rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006); } rt2x00usb_register_read(rt2x00dev, TXRXQ_PCNT, &reg); if (rt2x00_get_field32(reg, TXRXQ_PCNT_TX1Q)) { WARNING(rt2x00dev, "TX HW queue 1 timed out," " invoke forced kick\n"); rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf4000a); for (i = 0; i < 10; i++) { udelay(10); if (!rt2x00_get_field32(reg, TXRXQ_PCNT_TX1Q)) break; } rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006); } rt2x00usb_watchdog(rt2x00dev); } /* * TX descriptor initialization */ static __le32 *rt2800usb_get_txwi(struct queue_entry *entry) { if (entry->queue->qid == QID_BEACON) return (__le32 *) (entry->skb->data); else return (__le32 *) (entry->skb->data + TXINFO_DESC_SIZE); } static void rt2800usb_write_tx_desc(struct queue_entry *entry, struct txentry_desc *txdesc) { struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); __le32 *txi = (__le32 *) entry->skb->data; u32 word; /* * Initialize TXINFO descriptor */ rt2x00_desc_read(txi, 0, &word); /* * The size of TXINFO_W0_USB_DMA_TX_PKT_LEN is * TXWI + 802.11 header + L2 pad + payload + pad, * so need to decrease size of TXINFO and USB end pad. */ rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN, entry->skb->len - TXINFO_DESC_SIZE - 4); rt2x00_set_field32(&word, TXINFO_W0_WIV, !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags)); rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2); rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0); rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0); rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST, test_bit(ENTRY_TXD_BURST, &txdesc->flags)); rt2x00_desc_write(txi, 0, word); /* * Register descriptor details in skb frame descriptor. */ skbdesc->flags |= SKBDESC_DESC_IN_SKB; skbdesc->desc = txi; skbdesc->desc_len = TXINFO_DESC_SIZE + TXWI_DESC_SIZE; } static void rt2800usb_write_tx_data(struct queue_entry *entry, struct txentry_desc *txdesc) { unsigned int len; int err; rt2800_write_tx_data(entry, txdesc); /* * pad(1~3 bytes) is added after each 802.11 payload. * USB end pad(4 bytes) is added at each USB bulk out packet end. * TX frame format is : * | TXINFO | TXWI | 802.11 header | L2 pad | payload | pad | USB end pad | * |<------------- tx_pkt_len ------------->| */ len = roundup(entry->skb->len, 4) + 4; err = skb_padto(entry->skb, len); if (unlikely(err)) { WARNING(entry->queue->rt2x00dev, "TX SKB padding error, out of memory\n"); return; } entry->skb->len = len; } /* * TX data initialization */ static int rt2800usb_get_tx_data_len(struct queue_entry *entry) { return entry->skb->len; } /* * TX control handlers */ static void rt2800usb_work_txdone(struct work_struct *work) { struct rt2x00_dev *rt2x00dev = container_of(work, struct rt2x00_dev, txdone_work); struct data_queue *queue; struct queue_entry *entry; rt2800_txdone(rt2x00dev); /* * Process any trailing TX status reports for IO failures, * we loop until we find the first non-IO error entry. This * can either be a frame which is free, is being uploaded, * or has completed the upload but didn't have an entry * in the TX_STAT_FIFO register yet. */ tx_queue_for_each(rt2x00dev, queue) { while (!rt2x00queue_empty(queue)) { entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE); if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) || !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags)) break; if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags)) rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE); else if (rt2x00queue_status_timeout(entry)) rt2x00lib_txdone_noinfo(entry, TXDONE_UNKNOWN); else break; } } /* * The hw may delay sending the packet after DMA complete * if the medium is busy, thus the TX_STA_FIFO entry is * also delayed -> use a timer to retrieve it. */ if (rt2800usb_txstatus_pending(rt2x00dev)) mod_timer(&rt2x00dev->txstatus_timer, jiffies + msecs_to_jiffies(2)); } /* * RX control handlers */ static void rt2800usb_fill_rxdone(struct queue_entry *entry, struct rxdone_entry_desc *rxdesc) { struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); __le32 *rxi = (__le32 *)entry->skb->data; __le32 *rxd; u32 word; int rx_pkt_len; /* * Copy descriptor to the skbdesc->desc buffer, making it safe from * moving of frame data in rt2x00usb. */ memcpy(skbdesc->desc, rxi, skbdesc->desc_len); /* * RX frame format is : * | RXINFO | RXWI | header | L2 pad | payload | pad | RXD | USB pad | * |<------------ rx_pkt_len -------------->| */ rt2x00_desc_read(rxi, 0, &word); rx_pkt_len = rt2x00_get_field32(word, RXINFO_W0_USB_DMA_RX_PKT_LEN); /* * Remove the RXINFO structure from the sbk. */ skb_pull(entry->skb, RXINFO_DESC_SIZE); /* * FIXME: we need to check for rx_pkt_len validity */ rxd = (__le32 *)(entry->skb->data + rx_pkt_len); /* * It is now safe to read the descriptor on all architectures. */ rt2x00_desc_read(rxd, 0, &word); if (rt2x00_get_field32(word, RXD_W0_CRC_ERROR)) rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W0_CIPHER_ERROR); if (rt2x00_get_field32(word, RXD_W0_DECRYPTED)) { /* * Hardware has stripped IV/EIV data from 802.11 frame during * decryption. Unfortunately the descriptor doesn't contain * any fields with the EIV/IV data either, so they can't * be restored by rt2x00lib. */ rxdesc->flags |= RX_FLAG_IV_STRIPPED; /* * The hardware has already checked the Michael Mic and has * stripped it from the frame. Signal this to mac80211. */ rxdesc->flags |= RX_FLAG_MMIC_STRIPPED; if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) rxdesc->flags |= RX_FLAG_DECRYPTED; else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) rxdesc->flags |= RX_FLAG_MMIC_ERROR; } if (rt2x00_get_field32(word, RXD_W0_MY_BSS)) rxdesc->dev_flags |= RXDONE_MY_BSS; if (rt2x00_get_field32(word, RXD_W0_L2PAD)) rxdesc->dev_flags |= RXDONE_L2PAD; /* * Remove RXD descriptor from end of buffer. */ skb_trim(entry->skb, rx_pkt_len); /* * Process the RXWI structure. */ rt2800_process_rxwi(entry, rxdesc); } /* * Device probe functions. */ static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev) { if (rt2800_efuse_detect(rt2x00dev)) rt2800_read_eeprom_efuse(rt2x00dev); else rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE); return rt2800_validate_eeprom(rt2x00dev); } static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev) { int retval; /* * Allocate eeprom data. */ retval = rt2800usb_validate_eeprom(rt2x00dev); if (retval) return retval; retval = rt2800_init_eeprom(rt2x00dev); if (retval) return retval; /* * Initialize hw specifications. */ retval = rt2800_probe_hw_mode(rt2x00dev); if (retval) return retval; /* * This device has multiple filters for control frames * and has a separate filter for PS Poll frames. */ __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags); __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags); /* * This device requires firmware. */ __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags); __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags); if (!modparam_nohwcrypt) __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags); __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags); __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags); __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags); setup_timer(&rt2x00dev->txstatus_timer, rt2800usb_tx_sta_fifo_timeout, (unsigned long) rt2x00dev); /* * Set the rssi offset. */ rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; /* * Overwrite TX done handler */ PREPARE_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone); return 0; } static const struct ieee80211_ops rt2800usb_mac80211_ops = { .tx = rt2x00mac_tx, .start = rt2x00mac_start, .stop = rt2x00mac_stop, .add_interface = rt2x00mac_add_interface, .remove_interface = rt2x00mac_remove_interface, .config = rt2x00mac_config, .configure_filter = rt2x00mac_configure_filter, .set_tim = rt2x00mac_set_tim, .set_key = rt2x00mac_set_key, .sw_scan_start = rt2x00mac_sw_scan_start, .sw_scan_complete = rt2x00mac_sw_scan_complete, .get_stats = rt2x00mac_get_stats, .get_tkip_seq = rt2800_get_tkip_seq, .set_rts_threshold = rt2800_set_rts_threshold, .bss_info_changed = rt2x00mac_bss_info_changed, .conf_tx = rt2800_conf_tx, .get_tsf = rt2800_get_tsf, .rfkill_poll = rt2x00mac_rfkill_poll, .ampdu_action = rt2800_ampdu_action, .flush = rt2x00mac_flush, .get_survey = rt2800_get_survey, .get_ringparam = rt2x00mac_get_ringparam, }; static const struct rt2800_ops rt2800usb_rt2800_ops = { .register_read = rt2x00usb_register_read, .register_read_lock = rt2x00usb_register_read_lock, .register_write = rt2x00usb_register_write, .register_write_lock = rt2x00usb_register_write_lock, .register_multiread = rt2x00usb_register_multiread, .register_multiwrite = rt2x00usb_register_multiwrite, .regbusy_read = rt2x00usb_regbusy_read, .drv_write_firmware = rt2800usb_write_firmware, .drv_init_registers = rt2800usb_init_registers, .drv_get_txwi = rt2800usb_get_txwi, }; static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = { .probe_hw = rt2800usb_probe_hw, .get_firmware_name = rt2800usb_get_firmware_name, .check_firmware = rt2800_check_firmware, .load_firmware = rt2800_load_firmware, .initialize = rt2x00usb_initialize, .uninitialize = rt2x00usb_uninitialize, .clear_entry = rt2x00usb_clear_entry, .set_device_state = rt2800usb_set_device_state, .rfkill_poll = rt2800_rfkill_poll, .link_stats = rt2800_link_stats, .reset_tuner = rt2800_reset_tuner, .link_tuner = rt2800_link_tuner, .gain_calibration = rt2800_gain_calibration, .watchdog = rt2800usb_watchdog, .start_queue = rt2800usb_start_queue, .kick_queue = rt2x00usb_kick_queue, .stop_queue = rt2800usb_stop_queue, .flush_queue = rt2x00usb_flush_queue, .tx_dma_done = rt2800usb_tx_dma_done, .write_tx_desc = rt2800usb_write_tx_desc, .write_tx_data = rt2800usb_write_tx_data, .write_beacon = rt2800_write_beacon, .clear_beacon = rt2800_clear_beacon, .get_tx_data_len = rt2800usb_get_tx_data_len, .fill_rxdone = rt2800usb_fill_rxdone, .config_shared_key = rt2800_config_shared_key, .config_pairwise_key = rt2800_config_pairwise_key, .config_filter = rt2800_config_filter, .config_intf = rt2800_config_intf, .config_erp = rt2800_config_erp, .config_ant = rt2800_config_ant, .config = rt2800_config, }; static const struct data_queue_desc rt2800usb_queue_rx = { .entry_num = 128, .data_size = AGGREGATION_SIZE, .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE, .priv_size = sizeof(struct queue_entry_priv_usb), }; static const struct data_queue_desc rt2800usb_queue_tx = { .entry_num = 64, .data_size = AGGREGATION_SIZE, .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE, .priv_size = sizeof(struct queue_entry_priv_usb), }; static const struct data_queue_desc rt2800usb_queue_bcn = { .entry_num = 8, .data_size = MGMT_FRAME_SIZE, .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE, .priv_size = sizeof(struct queue_entry_priv_usb), }; static const struct rt2x00_ops rt2800usb_ops = { .name = KBUILD_MODNAME, .max_sta_intf = 1, .max_ap_intf = 8, .eeprom_size = EEPROM_SIZE, .rf_size = RF_SIZE, .tx_queues = NUM_TX_QUEUES, .extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE, .rx = &rt2800usb_queue_rx, .tx = &rt2800usb_queue_tx, .bcn = &rt2800usb_queue_bcn, .lib = &rt2800usb_rt2x00_ops, .drv = &rt2800usb_rt2800_ops, .hw = &rt2800usb_mac80211_ops, #ifdef CONFIG_RT2X00_LIB_DEBUGFS .debugfs = &rt2800_rt2x00debug, #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ }; /* * rt2800usb module information. */ static struct usb_device_id rt2800usb_device_table[] = { /* Abocom */ { USB_DEVICE(0x07b8, 0x2870) }, { USB_DEVICE(0x07b8, 0x2770) }, { USB_DEVICE(0x07b8, 0x3070) }, { USB_DEVICE(0x07b8, 0x3071) }, { USB_DEVICE(0x07b8, 0x3072) }, { USB_DEVICE(0x1482, 0x3c09) }, /* AirTies */ { USB_DEVICE(0x1eda, 0x2012) }, { USB_DEVICE(0x1eda, 0x2310) }, /* Allwin */ { USB_DEVICE(0x8516, 0x2070) }, { USB_DEVICE(0x8516, 0x2770) }, { USB_DEVICE(0x8516, 0x2870) }, { USB_DEVICE(0x8516, 0x3070) }, { USB_DEVICE(0x8516, 0x3071) }, { USB_DEVICE(0x8516, 0x3072) }, /* Alpha Networks */ { USB_DEVICE(0x14b2, 0x3c06) }, { USB_DEVICE(0x14b2, 0x3c07) }, { USB_DEVICE(0x14b2, 0x3c09) }, { USB_DEVICE(0x14b2, 0x3c12) }, { USB_DEVICE(0x14b2, 0x3c23) }, { USB_DEVICE(0x14b2, 0x3c25) }, { USB_DEVICE(0x14b2, 0x3c27) }, { USB_DEVICE(0x14b2, 0x3c28) }, { USB_DEVICE(0x14b2, 0x3c2c) }, /* Amit */ { USB_DEVICE(0x15c5, 0x0008) }, /* Askey */ { USB_DEVICE(0x1690, 0x0740) }, /* ASUS */ { USB_DEVICE(0x0b05, 0x1731) }, { USB_DEVICE(0x0b05, 0x1732) }, { USB_DEVICE(0x0b05, 0x1742) }, { USB_DEVICE(0x0b05, 0x1784) }, { USB_DEVICE(0x1761, 0x0b05) }, /* AzureWave */ { USB_DEVICE(0x13d3, 0x3247) }, { USB_DEVICE(0x13d3, 0x3273) }, { USB_DEVICE(0x13d3, 0x3305) }, { USB_DEVICE(0x13d3, 0x3307) }, { USB_DEVICE(0x13d3, 0x3321) }, /* Belkin */ { USB_DEVICE(0x050d, 0x8053) }, { USB_DEVICE(0x050d, 0x805c) }, { USB_DEVICE(0x050d, 0x815c) }, { USB_DEVICE(0x050d, 0x825a) }, { USB_DEVICE(0x050d, 0x825b) }, { USB_DEVICE(0x050d, 0x935a) }, { USB_DEVICE(0x050d, 0x935b) }, /* Buffalo */ { USB_DEVICE(0x0411, 0x00e8) }, { USB_DEVICE(0x0411, 0x0158) }, { USB_DEVICE(0x0411, 0x015d) }, { USB_DEVICE(0x0411, 0x016f) }, { USB_DEVICE(0x0411, 0x01a2) }, /* Corega */ { USB_DEVICE(0x07aa, 0x002f) }, { USB_DEVICE(0x07aa, 0x003c) }, { USB_DEVICE(0x07aa, 0x003f) }, { USB_DEVICE(0x18c5, 0x0012) }, /* D-Link */ { USB_DEVICE(0x07d1, 0x3c09) }, { USB_DEVICE(0x07d1, 0x3c0a) }, { USB_DEVICE(0x07d1, 0x3c0d) }, { USB_DEVICE(0x07d1, 0x3c0e) }, { USB_DEVICE(0x07d1, 0x3c0f) }, { USB_DEVICE(0x07d1, 0x3c11) }, { USB_DEVICE(0x07d1, 0x3c13) }, { USB_DEVICE(0x07d1, 0x3c15) }, { USB_DEVICE(0x07d1, 0x3c16) }, { USB_DEVICE(0x2001, 0x3c1b) }, /* Draytek */ { USB_DEVICE(0x07fa, 0x7712) }, /* Edimax */ { USB_DEVICE(0x7392, 0x7711) }, { USB_DEVICE(0x7392, 0x7717) }, { USB_DEVICE(0x7392, 0x7718) }, { USB_DEVICE(0x7392, 0x7722) }, /* Encore */ { USB_DEVICE(0x203d, 0x1480) }, { USB_DEVICE(0x203d, 0x14a9) }, /* EnGenius */ { USB_DEVICE(0x1740, 0x9701) }, { USB_DEVICE(0x1740, 0x9702) }, { USB_DEVICE(0x1740, 0x9703) }, { USB_DEVICE(0x1740, 0x9705) }, { USB_DEVICE(0x1740, 0x9706) }, { USB_DEVICE(0x1740, 0x9707) }, { USB_DEVICE(0x1740, 0x9708) }, { USB_DEVICE(0x1740, 0x9709) }, /* Gemtek */ { USB_DEVICE(0x15a9, 0x0012) }, /* Gigabyte */ { USB_DEVICE(0x1044, 0x800b) }, { USB_DEVICE(0x1044, 0x800d) }, /* Hawking */ { USB_DEVICE(0x0e66, 0x0001) }, { USB_DEVICE(0x0e66, 0x0003) }, { USB_DEVICE(0x0e66, 0x0009) }, { USB_DEVICE(0x0e66, 0x000b) }, { USB_DEVICE(0x0e66, 0x0013) }, { USB_DEVICE(0x0e66, 0x0017) }, { USB_DEVICE(0x0e66, 0x0018) }, /* I-O DATA */ { USB_DEVICE(0x04bb, 0x0945) }, { USB_DEVICE(0x04bb, 0x0947) }, { USB_DEVICE(0x04bb, 0x0948) }, /* Linksys */ { USB_DEVICE(0x13b1, 0x0031) }, { USB_DEVICE(0x1737, 0x0070) }, { USB_DEVICE(0x1737, 0x0071) }, { USB_DEVICE(0x1737, 0x0077) }, { USB_DEVICE(0x1737, 0x0078) }, /* Logitec */ { USB_DEVICE(0x0789, 0x0162) }, { USB_DEVICE(0x0789, 0x0163) }, { USB_DEVICE(0x0789, 0x0164) }, { USB_DEVICE(0x0789, 0x0166) }, /* Motorola */ { USB_DEVICE(0x100d, 0x9031) }, /* MSI */ { USB_DEVICE(0x0db0, 0x3820) }, { USB_DEVICE(0x0db0, 0x3821) }, { USB_DEVICE(0x0db0, 0x3822) }, { USB_DEVICE(0x0db0, 0x3870) }, { USB_DEVICE(0x0db0, 0x3871) }, { USB_DEVICE(0x0db0, 0x6899) }, { USB_DEVICE(0x0db0, 0x821a) }, { USB_DEVICE(0x0db0, 0x822a) }, { USB_DEVICE(0x0db0, 0x822b) }, { USB_DEVICE(0x0db0, 0x822c) }, { USB_DEVICE(0x0db0, 0x870a) }, { USB_DEVICE(0x0db0, 0x871a) }, { USB_DEVICE(0x0db0, 0x871b) }, { USB_DEVICE(0x0db0, 0x871c) }, { USB_DEVICE(0x0db0, 0x899a) }, /* Ovislink */ { USB_DEVICE(0x1b75, 0x3071) }, { USB_DEVICE(0x1b75, 0x3072) }, /* Para */ { USB_DEVICE(0x20b8, 0x8888) }, /* Pegatron */ { USB_DEVICE(0x1d4d, 0x0002) }, { USB_DEVICE(0x1d4d, 0x000c) }, { USB_DEVICE(0x1d4d, 0x000e) }, { USB_DEVICE(0x1d4d, 0x0011) }, /* Philips */ { USB_DEVICE(0x0471, 0x200f) }, /* Planex */ { USB_DEVICE(0x2019, 0xab25) }, { USB_DEVICE(0x2019, 0xed06) }, /* Quanta */ { USB_DEVICE(0x1a32, 0x0304) }, /* Ralink */ { USB_DEVICE(0x148f, 0x2070) }, { USB_DEVICE(0x148f, 0x2770) }, { USB_DEVICE(0x148f, 0x2870) }, { USB_DEVICE(0x148f, 0x3070) }, { USB_DEVICE(0x148f, 0x3071) }, { USB_DEVICE(0x148f, 0x3072) }, /* Samsung */ { USB_DEVICE(0x04e8, 0x2018) }, /* Siemens */ { USB_DEVICE(0x129b, 0x1828) }, /* Sitecom */ { USB_DEVICE(0x0df6, 0x0017) }, { USB_DEVICE(0x0df6, 0x002b) }, { USB_DEVICE(0x0df6, 0x002c) }, { USB_DEVICE(0x0df6, 0x002d) }, { USB_DEVICE(0x0df6, 0x0039) }, { USB_DEVICE(0x0df6, 0x003b) }, { USB_DEVICE(0x0df6, 0x003d) }, { USB_DEVICE(0x0df6, 0x003e) }, { USB_DEVICE(0x0df6, 0x003f) }, { USB_DEVICE(0x0df6, 0x0040) }, { USB_DEVICE(0x0df6, 0x0042) }, { USB_DEVICE(0x0df6, 0x0047) }, { USB_DEVICE(0x0df6, 0x0048) }, { USB_DEVICE(0x0df6, 0x0051) }, { USB_DEVICE(0x0df6, 0x005f) }, { USB_DEVICE(0x0df6, 0x0060) }, /* SMC */ { USB_DEVICE(0x083a, 0x6618) }, { USB_DEVICE(0x083a, 0x7511) }, { USB_DEVICE(0x083a, 0x7512) }, { USB_DEVICE(0x083a, 0x7522) }, { USB_DEVICE(0x083a, 0x8522) }, { USB_DEVICE(0x083a, 0xa618) }, { USB_DEVICE(0x083a, 0xa701) }, { USB_DEVICE(0x083a, 0xa702) }, { USB_DEVICE(0x083a, 0xa703) }, { USB_DEVICE(0x083a, 0xb522) }, /* Sparklan */ { USB_DEVICE(0x15a9, 0x0006) }, /* Sweex */ { USB_DEVICE(0x177f, 0x0153) }, { USB_DEVICE(0x177f, 0x0302) }, { USB_DEVICE(0x177f, 0x0313) }, /* U-Media */ { USB_DEVICE(0x157e, 0x300e) }, { USB_DEVICE(0x157e, 0x3013) }, /* ZCOM */ { USB_DEVICE(0x0cde, 0x0022) }, { USB_DEVICE(0x0cde, 0x0025) }, /* Zinwell */ { USB_DEVICE(0x5a57, 0x0280) }, { USB_DEVICE(0x5a57, 0x0282) }, { USB_DEVICE(0x5a57, 0x0283) }, { USB_DEVICE(0x5a57, 0x5257) }, /* Zyxel */ { USB_DEVICE(0x0586, 0x3416) }, { USB_DEVICE(0x0586, 0x3418) }, { USB_DEVICE(0x0586, 0x341e) }, { USB_DEVICE(0x0586, 0x343e) }, #ifdef CONFIG_RT2800USB_RT33XX /* Belkin */ { USB_DEVICE(0x050d, 0x945b) }, /* Ralink */ { USB_DEVICE(0x148f, 0x3370) }, { USB_DEVICE(0x148f, 0x8070) }, /* Sitecom */ { USB_DEVICE(0x0df6, 0x0050) }, #endif #ifdef CONFIG_RT2800USB_RT35XX /* Allwin */ { USB_DEVICE(0x8516, 0x3572) }, /* Askey */ { USB_DEVICE(0x1690, 0x0744) }, /* Cisco */ { USB_DEVICE(0x167b, 0x4001) }, /* EnGenius */ { USB_DEVICE(0x1740, 0x9801) }, /* I-O DATA */ { USB_DEVICE(0x04bb, 0x0944) }, /* Linksys */ { USB_DEVICE(0x13b1, 0x002f) }, { USB_DEVICE(0x1737, 0x0079) }, /* Ralink */ { USB_DEVICE(0x148f, 0x3572) }, /* Sitecom */ { USB_DEVICE(0x0df6, 0x0041) }, { USB_DEVICE(0x0df6, 0x0062) }, /* Toshiba */ { USB_DEVICE(0x0930, 0x0a07) }, /* Zinwell */ { USB_DEVICE(0x5a57, 0x0284) }, #endif #ifdef CONFIG_RT2800USB_RT53XX /* Azurewave */ { USB_DEVICE(0x13d3, 0x3329) }, { USB_DEVICE(0x13d3, 0x3365) }, /* Ralink */ { USB_DEVICE(0x148f, 0x5370) }, { USB_DEVICE(0x148f, 0x5372) }, #endif #ifdef CONFIG_RT2800USB_UNKNOWN /* * Unclear what kind of devices these are (they aren't supported by the * vendor linux driver). */ /* Abocom */ { USB_DEVICE(0x07b8, 0x3073) }, { USB_DEVICE(0x07b8, 0x3074) }, /* Alpha Networks */ { USB_DEVICE(0x14b2, 0x3c08) }, { USB_DEVICE(0x14b2, 0x3c11) }, /* Amigo */ { USB_DEVICE(0x0e0b, 0x9031) }, { USB_DEVICE(0x0e0b, 0x9041) }, /* ASUS */ { USB_DEVICE(0x0b05, 0x166a) }, { USB_DEVICE(0x0b05, 0x1760) }, { USB_DEVICE(0x0b05, 0x1761) }, { USB_DEVICE(0x0b05, 0x1790) }, { USB_DEVICE(0x0b05, 0x179d) }, /* AzureWave */ { USB_DEVICE(0x13d3, 0x3262) }, { USB_DEVICE(0x13d3, 0x3284) }, { USB_DEVICE(0x13d3, 0x3322) }, /* Belkin */ { USB_DEVICE(0x050d, 0x1003) }, /* Buffalo */ { USB_DEVICE(0x0411, 0x012e) }, { USB_DEVICE(0x0411, 0x0148) }, { USB_DEVICE(0x0411, 0x0150) }, /* Corega */ { USB_DEVICE(0x07aa, 0x0041) }, { USB_DEVICE(0x07aa, 0x0042) }, { USB_DEVICE(0x18c5, 0x0008) }, /* D-Link */ { USB_DEVICE(0x07d1, 0x3c0b) }, { USB_DEVICE(0x07d1, 0x3c17) }, { USB_DEVICE(0x2001, 0x3c17) }, /* Edimax */ { USB_DEVICE(0x7392, 0x4085) }, /* Encore */ { USB_DEVICE(0x203d, 0x14a1) }, /* Fujitsu Stylistic 550 */ { USB_DEVICE(0x1690, 0x0761) }, /* Gemtek */ { USB_DEVICE(0x15a9, 0x0010) }, /* Gigabyte */ { USB_DEVICE(0x1044, 0x800c) }, /* Huawei */ { USB_DEVICE(0x148f, 0xf101) }, /* I-O DATA */ { USB_DEVICE(0x04bb, 0x094b) }, /* LevelOne */ { USB_DEVICE(0x1740, 0x0605) }, { USB_DEVICE(0x1740, 0x0615) }, /* Logitec */ { USB_DEVICE(0x0789, 0x0168) }, { USB_DEVICE(0x0789, 0x0169) }, /* Motorola */ { USB_DEVICE(0x100d, 0x9032) }, /* Pegatron */ { USB_DEVICE(0x05a6, 0x0101) }, { USB_DEVICE(0x1d4d, 0x0010) }, /* Planex */ { USB_DEVICE(0x2019, 0x5201) }, { USB_DEVICE(0x2019, 0xab24) }, /* Qcom */ { USB_DEVICE(0x18e8, 0x6259) }, /* RadioShack */ { USB_DEVICE(0x08b9, 0x1197) }, /* Sitecom */ { USB_DEVICE(0x0df6, 0x003c) }, { USB_DEVICE(0x0df6, 0x004a) }, { USB_DEVICE(0x0df6, 0x004d) }, { USB_DEVICE(0x0df6, 0x0053) }, /* SMC */ { USB_DEVICE(0x083a, 0xa512) }, { USB_DEVICE(0x083a, 0xc522) }, { USB_DEVICE(0x083a, 0xd522) }, { USB_DEVICE(0x083a, 0xf511) }, /* Zyxel */ { USB_DEVICE(0x0586, 0x341a) }, #endif { 0, } }; MODULE_AUTHOR(DRV_PROJECT); MODULE_VERSION(DRV_VERSION); MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver."); MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards"); MODULE_DEVICE_TABLE(usb, rt2800usb_device_table); MODULE_FIRMWARE(FIRMWARE_RT2870); MODULE_LICENSE("GPL"); static int rt2800usb_probe(struct usb_interface *usb_intf, const struct usb_device_id *id) { return rt2x00usb_probe(usb_intf, &rt2800usb_ops); } static struct usb_driver rt2800usb_driver = { .name = KBUILD_MODNAME, .id_table = rt2800usb_device_table, .probe = rt2800usb_probe, .disconnect = rt2x00usb_disconnect, .suspend = rt2x00usb_suspend, .resume = rt2x00usb_resume, }; static int __init rt2800usb_init(void) { return usb_register(&rt2800usb_driver); } static void __exit rt2800usb_exit(void) { usb_deregister(&rt2800usb_driver); } module_init(rt2800usb_init); module_exit(rt2800usb_exit);
gpl-2.0
rajat1994/linux
drivers/infiniband/hw/mlx4/mr.c
573
12530
/* * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <linux/slab.h> #include "mlx4_ib.h" static u32 convert_access(int acc) { return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX4_PERM_ATOMIC : 0) | (acc & IB_ACCESS_REMOTE_WRITE ? MLX4_PERM_REMOTE_WRITE : 0) | (acc & IB_ACCESS_REMOTE_READ ? MLX4_PERM_REMOTE_READ : 0) | (acc & IB_ACCESS_LOCAL_WRITE ? MLX4_PERM_LOCAL_WRITE : 0) | (acc & IB_ACCESS_MW_BIND ? MLX4_PERM_BIND_MW : 0) | MLX4_PERM_LOCAL_READ; } static enum mlx4_mw_type to_mlx4_type(enum ib_mw_type type) { switch (type) { case IB_MW_TYPE_1: return MLX4_MW_TYPE_1; case IB_MW_TYPE_2: return MLX4_MW_TYPE_2; default: return -1; } } struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc) { struct mlx4_ib_mr *mr; int err; mr = kmalloc(sizeof *mr, GFP_KERNEL); if (!mr) return ERR_PTR(-ENOMEM); err = mlx4_mr_alloc(to_mdev(pd->device)->dev, to_mpd(pd)->pdn, 0, ~0ull, convert_access(acc), 0, 0, &mr->mmr); if (err) goto err_free; err = mlx4_mr_enable(to_mdev(pd->device)->dev, &mr->mmr); if (err) goto err_mr; mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key; mr->umem = NULL; return &mr->ibmr; err_mr: (void) mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr); err_free: kfree(mr); return ERR_PTR(err); } int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt, struct ib_umem *umem) { u64 *pages; int i, k, entry; int n; int len; int err = 0; struct scatterlist *sg; pages = (u64 *) __get_free_page(GFP_KERNEL); if (!pages) return -ENOMEM; i = n = 0; for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) { len = sg_dma_len(sg) >> mtt->page_shift; for (k = 0; k < len; ++k) { pages[i++] = sg_dma_address(sg) + umem->page_size * k; /* * Be friendly to mlx4_write_mtt() and * pass it chunks of appropriate size. */ if (i == PAGE_SIZE / sizeof (u64)) { err = mlx4_write_mtt(dev->dev, mtt, n, i, pages); if (err) goto out; n += i; i = 0; } } } if (i) err = mlx4_write_mtt(dev->dev, mtt, n, i, pages); out: free_page((unsigned long) pages); return err; } struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt_addr, int access_flags, struct ib_udata *udata) { struct mlx4_ib_dev *dev = to_mdev(pd->device); struct mlx4_ib_mr *mr; int shift; int err; int n; mr = kmalloc(sizeof *mr, GFP_KERNEL); if (!mr) return ERR_PTR(-ENOMEM); /* Force registering the memory as writable. */ /* Used for memory re-registeration. HCA protects the access */ mr->umem = ib_umem_get(pd->uobject->context, start, length, access_flags | IB_ACCESS_LOCAL_WRITE, 0); if (IS_ERR(mr->umem)) { err = PTR_ERR(mr->umem); goto err_free; } n = ib_umem_page_count(mr->umem); shift = ilog2(mr->umem->page_size); err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, virt_addr, length, convert_access(access_flags), n, shift, &mr->mmr); if (err) goto err_umem; err = mlx4_ib_umem_write_mtt(dev, &mr->mmr.mtt, mr->umem); if (err) goto err_mr; err = mlx4_mr_enable(dev->dev, &mr->mmr); if (err) goto err_mr; mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key; return &mr->ibmr; err_mr: (void) mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr); err_umem: ib_umem_release(mr->umem); err_free: kfree(mr); return ERR_PTR(err); } int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start, u64 length, u64 virt_addr, int mr_access_flags, struct ib_pd *pd, struct ib_udata *udata) { struct mlx4_ib_dev *dev = to_mdev(mr->device); struct mlx4_ib_mr *mmr = to_mmr(mr); struct mlx4_mpt_entry *mpt_entry; struct mlx4_mpt_entry **pmpt_entry = &mpt_entry; int err; /* Since we synchronize this call and mlx4_ib_dereg_mr via uverbs, * we assume that the calls can't run concurrently. Otherwise, a * race exists. */ err = mlx4_mr_hw_get_mpt(dev->dev, &mmr->mmr, &pmpt_entry); if (err) return err; if (flags & IB_MR_REREG_PD) { err = mlx4_mr_hw_change_pd(dev->dev, *pmpt_entry, to_mpd(pd)->pdn); if (err) goto release_mpt_entry; } if (flags & IB_MR_REREG_ACCESS) { err = mlx4_mr_hw_change_access(dev->dev, *pmpt_entry, convert_access(mr_access_flags)); if (err) goto release_mpt_entry; } if (flags & IB_MR_REREG_TRANS) { int shift; int n; mlx4_mr_rereg_mem_cleanup(dev->dev, &mmr->mmr); ib_umem_release(mmr->umem); mmr->umem = ib_umem_get(mr->uobject->context, start, length, mr_access_flags | IB_ACCESS_LOCAL_WRITE, 0); if (IS_ERR(mmr->umem)) { err = PTR_ERR(mmr->umem); /* Prevent mlx4_ib_dereg_mr from free'ing invalid pointer */ mmr->umem = NULL; goto release_mpt_entry; } n = ib_umem_page_count(mmr->umem); shift = ilog2(mmr->umem->page_size); err = mlx4_mr_rereg_mem_write(dev->dev, &mmr->mmr, virt_addr, length, n, shift, *pmpt_entry); if (err) { ib_umem_release(mmr->umem); goto release_mpt_entry; } mmr->mmr.iova = virt_addr; mmr->mmr.size = length; err = mlx4_ib_umem_write_mtt(dev, &mmr->mmr.mtt, mmr->umem); if (err) { mlx4_mr_rereg_mem_cleanup(dev->dev, &mmr->mmr); ib_umem_release(mmr->umem); goto release_mpt_entry; } } /* If we couldn't transfer the MR to the HCA, just remember to * return a failure. But dereg_mr will free the resources. */ err = mlx4_mr_hw_write_mpt(dev->dev, &mmr->mmr, pmpt_entry); if (!err && flags & IB_MR_REREG_ACCESS) mmr->mmr.access = mr_access_flags; release_mpt_entry: mlx4_mr_hw_put_mpt(dev->dev, pmpt_entry); return err; } int mlx4_ib_dereg_mr(struct ib_mr *ibmr) { struct mlx4_ib_mr *mr = to_mmr(ibmr); int ret; ret = mlx4_mr_free(to_mdev(ibmr->device)->dev, &mr->mmr); if (ret) return ret; if (mr->umem) ib_umem_release(mr->umem); kfree(mr); return 0; } struct ib_mw *mlx4_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type) { struct mlx4_ib_dev *dev = to_mdev(pd->device); struct mlx4_ib_mw *mw; int err; mw = kmalloc(sizeof(*mw), GFP_KERNEL); if (!mw) return ERR_PTR(-ENOMEM); err = mlx4_mw_alloc(dev->dev, to_mpd(pd)->pdn, to_mlx4_type(type), &mw->mmw); if (err) goto err_free; err = mlx4_mw_enable(dev->dev, &mw->mmw); if (err) goto err_mw; mw->ibmw.rkey = mw->mmw.key; return &mw->ibmw; err_mw: mlx4_mw_free(dev->dev, &mw->mmw); err_free: kfree(mw); return ERR_PTR(err); } int mlx4_ib_bind_mw(struct ib_qp *qp, struct ib_mw *mw, struct ib_mw_bind *mw_bind) { struct ib_send_wr wr; struct ib_send_wr *bad_wr; int ret; memset(&wr, 0, sizeof(wr)); wr.opcode = IB_WR_BIND_MW; wr.wr_id = mw_bind->wr_id; wr.send_flags = mw_bind->send_flags; wr.wr.bind_mw.mw = mw; wr.wr.bind_mw.bind_info = mw_bind->bind_info; wr.wr.bind_mw.rkey = ib_inc_rkey(mw->rkey); ret = mlx4_ib_post_send(qp, &wr, &bad_wr); if (!ret) mw->rkey = wr.wr.bind_mw.rkey; return ret; } int mlx4_ib_dealloc_mw(struct ib_mw *ibmw) { struct mlx4_ib_mw *mw = to_mmw(ibmw); mlx4_mw_free(to_mdev(ibmw->device)->dev, &mw->mmw); kfree(mw); return 0; } struct ib_mr *mlx4_ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len) { struct mlx4_ib_dev *dev = to_mdev(pd->device); struct mlx4_ib_mr *mr; int err; mr = kmalloc(sizeof *mr, GFP_KERNEL); if (!mr) return ERR_PTR(-ENOMEM); err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, 0, 0, 0, max_page_list_len, 0, &mr->mmr); if (err) goto err_free; err = mlx4_mr_enable(dev->dev, &mr->mmr); if (err) goto err_mr; mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key; mr->umem = NULL; return &mr->ibmr; err_mr: (void) mlx4_mr_free(dev->dev, &mr->mmr); err_free: kfree(mr); return ERR_PTR(err); } struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device *ibdev, int page_list_len) { struct mlx4_ib_dev *dev = to_mdev(ibdev); struct mlx4_ib_fast_reg_page_list *mfrpl; int size = page_list_len * sizeof (u64); if (page_list_len > MLX4_MAX_FAST_REG_PAGES) return ERR_PTR(-EINVAL); mfrpl = kmalloc(sizeof *mfrpl, GFP_KERNEL); if (!mfrpl) return ERR_PTR(-ENOMEM); mfrpl->ibfrpl.page_list = kmalloc(size, GFP_KERNEL); if (!mfrpl->ibfrpl.page_list) goto err_free; mfrpl->mapped_page_list = dma_alloc_coherent(&dev->dev->persist-> pdev->dev, size, &mfrpl->map, GFP_KERNEL); if (!mfrpl->mapped_page_list) goto err_free; WARN_ON(mfrpl->map & 0x3f); return &mfrpl->ibfrpl; err_free: kfree(mfrpl->ibfrpl.page_list); kfree(mfrpl); return ERR_PTR(-ENOMEM); } void mlx4_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list) { struct mlx4_ib_dev *dev = to_mdev(page_list->device); struct mlx4_ib_fast_reg_page_list *mfrpl = to_mfrpl(page_list); int size = page_list->max_page_list_len * sizeof (u64); dma_free_coherent(&dev->dev->persist->pdev->dev, size, mfrpl->mapped_page_list, mfrpl->map); kfree(mfrpl->ibfrpl.page_list); kfree(mfrpl); } struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int acc, struct ib_fmr_attr *fmr_attr) { struct mlx4_ib_dev *dev = to_mdev(pd->device); struct mlx4_ib_fmr *fmr; int err = -ENOMEM; fmr = kmalloc(sizeof *fmr, GFP_KERNEL); if (!fmr) return ERR_PTR(-ENOMEM); err = mlx4_fmr_alloc(dev->dev, to_mpd(pd)->pdn, convert_access(acc), fmr_attr->max_pages, fmr_attr->max_maps, fmr_attr->page_shift, &fmr->mfmr); if (err) goto err_free; err = mlx4_fmr_enable(to_mdev(pd->device)->dev, &fmr->mfmr); if (err) goto err_mr; fmr->ibfmr.rkey = fmr->ibfmr.lkey = fmr->mfmr.mr.key; return &fmr->ibfmr; err_mr: (void) mlx4_mr_free(to_mdev(pd->device)->dev, &fmr->mfmr.mr); err_free: kfree(fmr); return ERR_PTR(err); } int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages, u64 iova) { struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); struct mlx4_ib_dev *dev = to_mdev(ifmr->ibfmr.device); return mlx4_map_phys_fmr(dev->dev, &ifmr->mfmr, page_list, npages, iova, &ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey); } int mlx4_ib_unmap_fmr(struct list_head *fmr_list) { struct ib_fmr *ibfmr; int err; struct mlx4_dev *mdev = NULL; list_for_each_entry(ibfmr, fmr_list, list) { if (mdev && to_mdev(ibfmr->device)->dev != mdev) return -EINVAL; mdev = to_mdev(ibfmr->device)->dev; } if (!mdev) return 0; list_for_each_entry(ibfmr, fmr_list, list) { struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); mlx4_fmr_unmap(mdev, &ifmr->mfmr, &ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey); } /* * Make sure all MPT status updates are visible before issuing * SYNC_TPT firmware command. */ wmb(); err = mlx4_SYNC_TPT(mdev); if (err) pr_warn("SYNC_TPT error %d when " "unmapping FMRs\n", err); return 0; } int mlx4_ib_fmr_dealloc(struct ib_fmr *ibfmr) { struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); struct mlx4_ib_dev *dev = to_mdev(ibfmr->device); int err; err = mlx4_fmr_free(dev->dev, &ifmr->mfmr); if (!err) kfree(ifmr); return err; }
gpl-2.0
fenggangwu/sffs
fs/xfs/xfs_trans_inode.c
829
4017
/* * Copyright (c) 2000,2005 Silicon Graphics, Inc. * All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "xfs.h" #include "xfs_fs.h" #include "xfs_shared.h" #include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_trans_priv.h" #include "xfs_inode_item.h" #include "xfs_trace.h" /* * Add a locked inode to the transaction. * * The inode must be locked, and it cannot be associated with any transaction. * If lock_flags is non-zero the inode will be unlocked on transaction commit. */ void xfs_trans_ijoin( struct xfs_trans *tp, struct xfs_inode *ip, uint lock_flags) { xfs_inode_log_item_t *iip; ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); if (ip->i_itemp == NULL) xfs_inode_item_init(ip, ip->i_mount); iip = ip->i_itemp; ASSERT(iip->ili_lock_flags == 0); iip->ili_lock_flags = lock_flags; /* * Get a log_item_desc to point at the new item. */ xfs_trans_add_item(tp, &iip->ili_item); } /* * Transactional inode timestamp update. Requires the inode to be locked and * joined to the transaction supplied. Relies on the transaction subsystem to * track dirty state and update/writeback the inode accordingly. */ void xfs_trans_ichgtime( struct xfs_trans *tp, struct xfs_inode *ip, int flags) { struct inode *inode = VFS_I(ip); struct timespec tv; ASSERT(tp); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); tv = current_fs_time(inode->i_sb); if ((flags & XFS_ICHGTIME_MOD) && !timespec_equal(&inode->i_mtime, &tv)) { inode->i_mtime = tv; ip->i_d.di_mtime.t_sec = tv.tv_sec; ip->i_d.di_mtime.t_nsec = tv.tv_nsec; } if ((flags & XFS_ICHGTIME_CHG) && !timespec_equal(&inode->i_ctime, &tv)) { inode->i_ctime = tv; ip->i_d.di_ctime.t_sec = tv.tv_sec; ip->i_d.di_ctime.t_nsec = tv.tv_nsec; } } /* * This is called to mark the fields indicated in fieldmask as needing * to be logged when the transaction is committed. The inode must * already be associated with the given transaction. * * The values for fieldmask are defined in xfs_inode_item.h. We always * log all of the core inode if any of it has changed, and we always log * all of the inline data/extents/b-tree root if any of them has changed. */ void xfs_trans_log_inode( xfs_trans_t *tp, xfs_inode_t *ip, uint flags) { ASSERT(ip->i_itemp != NULL); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); /* * First time we log the inode in a transaction, bump the inode change * counter if it is configured for this to occur. We don't use * inode_inc_version() because there is no need for extra locking around * i_version as we already hold the inode locked exclusively for * metadata modification. */ if (!(ip->i_itemp->ili_item.li_desc->lid_flags & XFS_LID_DIRTY) && IS_I_VERSION(VFS_I(ip))) { ip->i_d.di_changecount = ++VFS_I(ip)->i_version; flags |= XFS_ILOG_CORE; } tp->t_flags |= XFS_TRANS_DIRTY; ip->i_itemp->ili_item.li_desc->lid_flags |= XFS_LID_DIRTY; /* * Always OR in the bits from the ili_last_fields field. * This is to coordinate with the xfs_iflush() and xfs_iflush_done() * routines in the eventual clearing of the ili_fields bits. * See the big comment in xfs_iflush() for an explanation of * this coordination mechanism. */ flags |= ip->i_itemp->ili_last_fields; ip->i_itemp->ili_fields |= flags; }
gpl-2.0
schqiushui/kernel_lollipop_sense_m8ace
drivers/gpu/msm/adreno_a3xx_snapshot.c
1341
15747
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/io.h> #include "kgsl.h" #include "adreno.h" #include "kgsl_snapshot.h" #include "a3xx_reg.h" #define DEBUG_SECTION_SZ(_dwords) (((_dwords) * sizeof(unsigned int)) \ + sizeof(struct kgsl_snapshot_debug)) /* Shader memory size in words */ #define SHADER_MEMORY_SIZE 0x4000 /** * _rbbm_debug_bus_read - Helper function to read data from the RBBM * debug bus. * @device - GPU device to read/write registers * @block_id - Debug bus block to read from * @index - Index in the debug bus block to read * @ret - Value of the register read */ static void _rbbm_debug_bus_read(struct kgsl_device *device, unsigned int block_id, unsigned int index, unsigned int *val) { unsigned int block = (block_id << 8) | 1 << 16; kgsl_regwrite(device, A3XX_RBBM_DEBUG_BUS_CTL, block | index); kgsl_regread(device, A3XX_RBBM_DEBUG_BUS_DATA_STATUS, val); } /** * a3xx_snapshot_shader_memory - Helper function to dump the GPU shader * memory to the snapshot buffer. * @device - GPU device whose shader memory is to be dumped * @snapshot - Pointer to binary snapshot data blob being made * @remain - Number of remaining bytes in the snapshot blob * @priv - Unused parameter */ static int a3xx_snapshot_shader_memory(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct kgsl_snapshot_debug *header = snapshot; unsigned int i; unsigned int *data = snapshot + sizeof(*header); unsigned int shader_read_len = SHADER_MEMORY_SIZE; if (SHADER_MEMORY_SIZE > (device->shader_mem_len >> 2)) shader_read_len = (device->shader_mem_len >> 2); if (remain < DEBUG_SECTION_SZ(SHADER_MEMORY_SIZE)) { SNAPSHOT_ERR_NOMEM(device, "SHADER MEMORY"); return 0; } header->type = SNAPSHOT_DEBUG_SHADER_MEMORY; header->size = SHADER_MEMORY_SIZE; /* Map shader memory to kernel, for dumping */ if (device->shader_mem_virt == NULL) device->shader_mem_virt = devm_ioremap(device->dev, device->shader_mem_phys, device->shader_mem_len); if (device->shader_mem_virt == NULL) { KGSL_DRV_ERR(device, "Unable to map shader memory region\n"); return 0; } /* Now, dump shader memory to snapshot */ for (i = 0; i < shader_read_len; i++) adreno_shadermem_regread(device, i, &data[i]); return DEBUG_SECTION_SZ(SHADER_MEMORY_SIZE); } #define VPC_MEMORY_BANKS 4 #define VPC_MEMORY_SIZE 512 static int a3xx_snapshot_vpc_memory(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int size = VPC_MEMORY_BANKS * VPC_MEMORY_SIZE; int bank, addr, i = 0; if (remain < DEBUG_SECTION_SZ(size)) { SNAPSHOT_ERR_NOMEM(device, "VPC MEMORY"); return 0; } header->type = SNAPSHOT_DEBUG_VPC_MEMORY; header->size = size; for (bank = 0; bank < VPC_MEMORY_BANKS; bank++) { for (addr = 0; addr < VPC_MEMORY_SIZE; addr++) { unsigned int val = bank | (addr << 4); kgsl_regwrite(device, A3XX_VPC_VPC_DEBUG_RAM_SEL, val); kgsl_regread(device, A3XX_VPC_VPC_DEBUG_RAM_READ, &data[i++]); } } return DEBUG_SECTION_SZ(size); } #define CP_MEQ_SIZE 16 static int a3xx_snapshot_cp_meq(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int i; if (remain < DEBUG_SECTION_SZ(CP_MEQ_SIZE)) { SNAPSHOT_ERR_NOMEM(device, "CP MEQ DEBUG"); return 0; } header->type = SNAPSHOT_DEBUG_CP_MEQ; header->size = CP_MEQ_SIZE; kgsl_regwrite(device, A3XX_CP_MEQ_ADDR, 0x0); for (i = 0; i < CP_MEQ_SIZE; i++) kgsl_regread(device, A3XX_CP_MEQ_DATA, &data[i]); return DEBUG_SECTION_SZ(CP_MEQ_SIZE); } static int a3xx_snapshot_cp_pm4_ram(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct adreno_device *adreno_dev = ADRENO_DEVICE(device); struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int i, size = adreno_dev->pm4_fw_size - 1; if (remain < DEBUG_SECTION_SZ(size)) { SNAPSHOT_ERR_NOMEM(device, "CP PM4 RAM DEBUG"); return 0; } header->type = SNAPSHOT_DEBUG_CP_PM4_RAM; header->size = size; /* * Read the firmware from the GPU rather than use our cache in order to * try to catch mis-programming or corruption in the hardware. We do * use the cached version of the size, however, instead of trying to * maintain always changing hardcoded constants */ kgsl_regwrite(device, REG_CP_ME_RAM_RADDR, 0x0); for (i = 0; i < size; i++) kgsl_regread(device, REG_CP_ME_RAM_DATA, &data[i]); return DEBUG_SECTION_SZ(size); } static int a3xx_snapshot_cp_pfp_ram(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct adreno_device *adreno_dev = ADRENO_DEVICE(device); struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int i, size = adreno_dev->pfp_fw_size - 1; if (remain < DEBUG_SECTION_SZ(size)) { SNAPSHOT_ERR_NOMEM(device, "CP PFP RAM DEBUG"); return 0; } header->type = SNAPSHOT_DEBUG_CP_PFP_RAM; header->size = size; /* * Read the firmware from the GPU rather than use our cache in order to * try to catch mis-programming or corruption in the hardware. We do * use the cached version of the size, however, instead of trying to * maintain always changing hardcoded constants */ kgsl_regwrite(device, A3XX_CP_PFP_UCODE_ADDR, 0x0); for (i = 0; i < size; i++) kgsl_regread(device, A3XX_CP_PFP_UCODE_DATA, &data[i]); return DEBUG_SECTION_SZ(size); } /* This is the ROQ buffer size on both the A305 and A320 */ #define A320_CP_ROQ_SIZE 128 /* This is the ROQ buffer size on the A330 */ #define A330_CP_ROQ_SIZE 512 static int a3xx_snapshot_cp_roq(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct adreno_device *adreno_dev = ADRENO_DEVICE(device); struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int i, size; /* The size of the ROQ buffer is core dependent */ size = (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) ? A330_CP_ROQ_SIZE : A320_CP_ROQ_SIZE; if (remain < DEBUG_SECTION_SZ(size)) { SNAPSHOT_ERR_NOMEM(device, "CP ROQ DEBUG"); return 0; } header->type = SNAPSHOT_DEBUG_CP_ROQ; header->size = size; kgsl_regwrite(device, A3XX_CP_ROQ_ADDR, 0x0); for (i = 0; i < size; i++) kgsl_regread(device, A3XX_CP_ROQ_DATA, &data[i]); return DEBUG_SECTION_SZ(size); } #define A330_CP_MERCIU_QUEUE_SIZE 32 static int a330_snapshot_cp_merciu(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct kgsl_snapshot_debug *header = snapshot; unsigned int *data = snapshot + sizeof(*header); int i, size; /* The MERCIU data is two dwords per entry */ size = A330_CP_MERCIU_QUEUE_SIZE << 1; if (remain < DEBUG_SECTION_SZ(size)) { SNAPSHOT_ERR_NOMEM(device, "CP MERCIU DEBUG"); return 0; } header->type = SNAPSHOT_DEBUG_CP_MERCIU; header->size = size; kgsl_regwrite(device, A3XX_CP_MERCIU_ADDR, 0x0); for (i = 0; i < A330_CP_MERCIU_QUEUE_SIZE; i++) { kgsl_regread(device, A3XX_CP_MERCIU_DATA, &data[(i * 2)]); kgsl_regread(device, A3XX_CP_MERCIU_DATA2, &data[(i * 2) + 1]); } return DEBUG_SECTION_SZ(size); } struct debugbus_block { unsigned int block_id; unsigned int dwords; }; static int a3xx_snapshot_debugbus_block(struct kgsl_device *device, void *snapshot, int remain, void *priv) { struct adreno_device *adreno_dev = ADRENO_DEVICE(device); struct kgsl_snapshot_debugbus *header = snapshot; struct debugbus_block *block = priv; int i; unsigned int *data = snapshot + sizeof(*header); unsigned int dwords; int size; /* * For A305 and A320 all debug bus regions are the same size (0x40). For * A330, they can be different sizes - most are still 0x40, but some * like CP are larger */ dwords = (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) ? block->dwords : 0x40; size = (dwords * sizeof(unsigned int)) + sizeof(*header); if (remain < size) { SNAPSHOT_ERR_NOMEM(device, "DEBUGBUS"); return 0; } header->id = block->block_id; header->count = dwords; for (i = 0; i < dwords; i++) _rbbm_debug_bus_read(device, block->block_id, i, &data[i]); return size; } static struct debugbus_block debugbus_blocks[] = { { RBBM_BLOCK_ID_CP, 0x52, }, { RBBM_BLOCK_ID_RBBM, 0x40, }, { RBBM_BLOCK_ID_VBIF, 0x40, }, { RBBM_BLOCK_ID_HLSQ, 0x40, }, { RBBM_BLOCK_ID_UCHE, 0x40, }, { RBBM_BLOCK_ID_PC, 0x40, }, { RBBM_BLOCK_ID_VFD, 0x40, }, { RBBM_BLOCK_ID_VPC, 0x40, }, { RBBM_BLOCK_ID_TSE, 0x40, }, { RBBM_BLOCK_ID_RAS, 0x40, }, { RBBM_BLOCK_ID_VSC, 0x40, }, { RBBM_BLOCK_ID_SP_0, 0x40, }, { RBBM_BLOCK_ID_SP_1, 0x40, }, { RBBM_BLOCK_ID_SP_2, 0x40, }, { RBBM_BLOCK_ID_SP_3, 0x40, }, { RBBM_BLOCK_ID_TPL1_0, 0x40, }, { RBBM_BLOCK_ID_TPL1_1, 0x40, }, { RBBM_BLOCK_ID_TPL1_2, 0x40, }, { RBBM_BLOCK_ID_TPL1_3, 0x40, }, { RBBM_BLOCK_ID_RB_0, 0x40, }, { RBBM_BLOCK_ID_RB_1, 0x40, }, { RBBM_BLOCK_ID_RB_2, 0x40, }, { RBBM_BLOCK_ID_RB_3, 0x40, }, { RBBM_BLOCK_ID_MARB_0, 0x40, }, { RBBM_BLOCK_ID_MARB_1, 0x40, }, { RBBM_BLOCK_ID_MARB_2, 0x40, }, { RBBM_BLOCK_ID_MARB_3, 0x40, }, }; static void *a3xx_snapshot_debugbus(struct kgsl_device *device, void *snapshot, int *remain) { int i; for (i = 0; i < ARRAY_SIZE(debugbus_blocks); i++) { snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUGBUS, snapshot, remain, a3xx_snapshot_debugbus_block, (void *) &debugbus_blocks[i]); } return snapshot; } static void _snapshot_a3xx_regs(struct kgsl_snapshot_registers *regs, struct kgsl_snapshot_registers_list *list) { regs[list->count].regs = (unsigned int *) a3xx_registers; regs[list->count].count = a3xx_registers_count; list->count++; } static void _snapshot_hlsq_regs(struct kgsl_snapshot_registers *regs, struct kgsl_snapshot_registers_list *list, struct adreno_device *adreno_dev) { struct kgsl_device *device = &adreno_dev->dev; /* * Trying to read HLSQ registers when the HLSQ block is busy * will cause the device to hang. The RBBM_DEBUG_BUS has information * that will tell us if the HLSQ block is busy or not. Read values * from the debug bus to ensure the HLSQ block is not busy (this * is hardware dependent). If the HLSQ block is busy do not * dump the registers, otherwise dump the HLSQ registers. */ if (adreno_is_a330(adreno_dev)) { /* * stall_ctxt_full status bit: RBBM_BLOCK_ID_HLSQ index 49 [27] * * if (!stall_context_full) * then dump HLSQ registers */ unsigned int stall_context_full = 0; _rbbm_debug_bus_read(device, RBBM_BLOCK_ID_HLSQ, 49, &stall_context_full); stall_context_full &= 0x08000000; if (stall_context_full) return; } else { /* * tpif status bits: RBBM_BLOCK_ID_HLSQ index 4 [4:0] * spif status bits: RBBM_BLOCK_ID_HLSQ index 7 [5:0] * * if ((tpif == 0, 1, 28) && (spif == 0, 1, 10)) * then dump HLSQ registers */ unsigned int next_pif = 0; /* check tpif */ _rbbm_debug_bus_read(device, RBBM_BLOCK_ID_HLSQ, 4, &next_pif); next_pif &= 0x1f; if (next_pif != 0 && next_pif != 1 && next_pif != 28) return; /* check spif */ _rbbm_debug_bus_read(device, RBBM_BLOCK_ID_HLSQ, 7, &next_pif); next_pif &= 0x3f; if (next_pif != 0 && next_pif != 1 && next_pif != 10) return; } regs[list->count].regs = (unsigned int *) a3xx_hlsq_registers; regs[list->count].count = a3xx_hlsq_registers_count; list->count++; } static void _snapshot_a330_regs(struct kgsl_snapshot_registers *regs, struct kgsl_snapshot_registers_list *list) { /* For A330, append the additional list of new registers to grab */ regs[list->count].regs = (unsigned int *) a330_registers; regs[list->count].count = a330_registers_count; list->count++; } /* A3XX GPU snapshot function - this is where all of the A3XX specific * bits and pieces are grabbed into the snapshot memory */ void *a3xx_snapshot(struct adreno_device *adreno_dev, void *snapshot, int *remain, int hang) { struct kgsl_device *device = &adreno_dev->dev; struct kgsl_snapshot_registers_list list; struct kgsl_snapshot_registers regs[5]; int size; list.registers = regs; list.count = 0; /* Disable Clock gating temporarily for the debug bus to work */ kgsl_regwrite(device, A3XX_RBBM_CLOCK_CTL, 0x00); /* Store relevant registers in list to snapshot */ _snapshot_a3xx_regs(regs, &list); _snapshot_hlsq_regs(regs, &list, adreno_dev); if (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) _snapshot_a330_regs(regs, &list); /* Master set of (non debug) registers */ snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS, snapshot, remain, kgsl_snapshot_dump_regs, &list); /* * CP_STATE_DEBUG indexed registers - 20 on 305 and 320 and 46 on A330 */ size = (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) ? 0x2E : 0x14; snapshot = kgsl_snapshot_indexed_registers(device, snapshot, remain, REG_CP_STATE_DEBUG_INDEX, REG_CP_STATE_DEBUG_DATA, 0x0, size); /* CP_ME indexed registers */ snapshot = kgsl_snapshot_indexed_registers(device, snapshot, remain, REG_CP_ME_CNTL, REG_CP_ME_STATUS, 64, 44); /* VPC memory */ snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_vpc_memory, NULL); /* CP MEQ */ snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_cp_meq, NULL); /* Shader working/shadow memory */ snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_shader_memory, NULL); /* CP PFP and PM4 */ /* Reading these will hang the GPU if it isn't already hung */ if (hang) { unsigned int reg; /* * Reading the microcode while the CP will is running will * basically basically move the CP instruction pointer to * whatever address we read. Big badaboom ensues. Stop the CP * (if it isn't already stopped) to ensure that we are safe. * We do this here and not earlier to avoid corrupting the RBBM * status and CP registers - by the time we get here we don't * care about the contents of the CP anymore. */ adreno_readreg(adreno_dev, ADRENO_REG_CP_ME_CNTL, &reg); reg |= (1 << 27) | (1 << 28); adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, reg); snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_cp_pfp_ram, NULL); snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_cp_pm4_ram, NULL); } /* CP ROQ */ snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a3xx_snapshot_cp_roq, NULL); if (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) { snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain, a330_snapshot_cp_merciu, NULL); } snapshot = a3xx_snapshot_debugbus(device, snapshot, remain); /* Enable Clock gating */ kgsl_regwrite(device, A3XX_RBBM_CLOCK_CTL, adreno_a3xx_rbbm_clock_ctl_default(adreno_dev)); return snapshot; }
gpl-2.0
cfpeng/linux
drivers/char/agp/intel-agp.c
1341
28658
/* * Intel AGPGART routines. */ #include <linux/module.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/pagemap.h> #include <linux/agp_backend.h> #include <asm/smp.h> #include "agp.h" #include "intel-agp.h" #include <drm/intel-gtt.h> static int intel_fetch_size(void) { int i; u16 temp; struct aper_size_info_16 *values; pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp); values = A_SIZE_16(agp_bridge->driver->aperture_sizes); for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { if (temp == values[i].size_value) { agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i); agp_bridge->aperture_size_idx = i; return values[i].size; } } return 0; } static int __intel_8xx_fetch_size(u8 temp) { int i; struct aper_size_info_8 *values; values = A_SIZE_8(agp_bridge->driver->aperture_sizes); for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { if (temp == values[i].size_value) { agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i); agp_bridge->aperture_size_idx = i; return values[i].size; } } return 0; } static int intel_8xx_fetch_size(void) { u8 temp; pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp); return __intel_8xx_fetch_size(temp); } static int intel_815_fetch_size(void) { u8 temp; /* Intel 815 chipsets have a _weird_ APSIZE register with only * one non-reserved bit, so mask the others out ... */ pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp); temp &= (1 << 3); return __intel_8xx_fetch_size(temp); } static void intel_tlbflush(struct agp_memory *mem) { pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280); } static void intel_8xx_tlbflush(struct agp_memory *mem) { u32 temp; pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7)); pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7)); } static void intel_cleanup(void) { u16 temp; struct aper_size_info_16 *previous_size; previous_size = A_SIZE_16(agp_bridge->previous_size); pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9)); pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static void intel_8xx_cleanup(void) { u16 temp; struct aper_size_info_8 *previous_size; previous_size = A_SIZE_8(agp_bridge->previous_size); pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9)); pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static int intel_configure(void) { u16 temp2; struct aper_size_info_16 *current_size; current_size = A_SIZE_16(agp_bridge->current_size); /* aperture size */ pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280); /* paccfg/nbxcfg */ pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, (temp2 & ~(1 << 10)) | (1 << 9)); /* clear any possible error conditions */ pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7); return 0; } static int intel_815_configure(void) { u32 addr; u8 temp2; struct aper_size_info_8 *current_size; /* attbase - aperture base */ /* the Intel 815 chipset spec. says that bits 29-31 in the * ATTBASE register are reserved -> try not to write them */ if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) { dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high"); return -EINVAL; } current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr); addr &= INTEL_815_ATTBASE_MASK; addr |= agp_bridge->gatt_bus_addr; pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* apcont */ pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1)); /* clear any possible error conditions */ /* Oddness : this chipset seems to have no ERRSTS register ! */ return 0; } static void intel_820_tlbflush(struct agp_memory *mem) { return; } static void intel_820_cleanup(void) { u8 temp; struct aper_size_info_8 *previous_size; previous_size = A_SIZE_8(agp_bridge->previous_size); pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp); pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp & ~(1 << 1)); pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static int intel_820_configure(void) { u8 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* global enable aperture access */ /* This flag is not accessed through MCHCFG register as in */ /* i850 chipset. */ pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c); return 0; } static int intel_840_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9)); /* clear any possible error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000); return 0; } static int intel_845_configure(void) { u8 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); if (agp_bridge->apbase_config != 0) { pci_write_config_dword(agp_bridge->dev, AGP_APBASE, agp_bridge->apbase_config); } else { /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); agp_bridge->apbase_config = agp_bridge->gart_bus_addr; } /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* agpm */ pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1)); /* clear any possible error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c); return 0; } static int intel_850_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c); return 0; } static int intel_860_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700); return 0; } static int intel_830mp_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* gmch */ pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c); return 0; } static int intel_7505_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mchcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9)); return 0; } /* Setup function */ static const struct gatt_mask intel_generic_masks[] = { {.mask = 0x00000017, .type = 0} }; static const struct aper_size_info_8 intel_815_sizes[2] = { {64, 16384, 4, 0}, {32, 8192, 3, 8}, }; static const struct aper_size_info_8 intel_8xx_sizes[7] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56}, {16, 4096, 2, 60}, {8, 2048, 1, 62}, {4, 1024, 0, 63} }; static const struct aper_size_info_16 intel_generic_sizes[7] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56}, {16, 4096, 2, 60}, {8, 2048, 1, 62}, {4, 1024, 0, 63} }; static const struct aper_size_info_8 intel_830mp_sizes[4] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56} }; static const struct agp_bridge_driver intel_generic_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_generic_sizes, .size_type = U16_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_configure, .fetch_size = intel_fetch_size, .cleanup = intel_cleanup, .tlb_flush = intel_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_815_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_815_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 2, .needs_scratch_page = true, .configure = intel_815_configure, .fetch_size = intel_815_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_820_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_820_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_820_cleanup, .tlb_flush = intel_820_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_830mp_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_830mp_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 4, .needs_scratch_page = true, .configure = intel_830mp_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_840_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_840_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_845_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_845_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_850_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_850_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_860_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_860_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_7505_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_7505_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of * driver and gmch_driver must be non-null, and find_gmch will determine * which one should be used if a gmch_chip_id is present. */ static const struct intel_agp_driver_description { unsigned int chip_id; char *name; const struct agp_bridge_driver *driver; } intel_agp_chipsets[] = { { PCI_DEVICE_ID_INTEL_82443LX_0, "440LX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82443BX_0, "440BX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82443GX_0, "440GX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82815_MC, "i815", &intel_815_driver }, { PCI_DEVICE_ID_INTEL_82820_HB, "i820", &intel_820_driver }, { PCI_DEVICE_ID_INTEL_82820_UP_HB, "i820", &intel_820_driver }, { PCI_DEVICE_ID_INTEL_82830_HB, "830M", &intel_830mp_driver }, { PCI_DEVICE_ID_INTEL_82840_HB, "i840", &intel_840_driver }, { PCI_DEVICE_ID_INTEL_82845_HB, "i845", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82845G_HB, "845G", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82850_HB, "i850", &intel_850_driver }, { PCI_DEVICE_ID_INTEL_82854_HB, "854", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82855PM_HB, "855PM", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82855GM_HB, "855GM", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82860_HB, "i860", &intel_860_driver }, { PCI_DEVICE_ID_INTEL_82865_HB, "865", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82875_HB, "i875", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_7505_0, "E7505", &intel_7505_driver }, { PCI_DEVICE_ID_INTEL_7205_0, "E7205", &intel_7505_driver }, { 0, NULL, NULL } }; static int agp_intel_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct agp_bridge_data *bridge; u8 cap_ptr = 0; struct resource *r; int i, err; cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); bridge = agp_alloc_bridge(); if (!bridge) return -ENOMEM; bridge->capndx = cap_ptr; if (intel_gmch_probe(pdev, NULL, bridge)) goto found_gmch; for (i = 0; intel_agp_chipsets[i].name != NULL; i++) { /* In case that multiple models of gfx chip may stand on same host bridge type, this can be sure we detect the right IGD. */ if (pdev->device == intel_agp_chipsets[i].chip_id) { bridge->driver = intel_agp_chipsets[i].driver; break; } } if (!bridge->driver) { if (cap_ptr) dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n", pdev->vendor, pdev->device); agp_put_bridge(bridge); return -ENODEV; } bridge->dev = pdev; bridge->dev_private_data = NULL; dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name); /* * The following fixes the case where the BIOS has "forgotten" to * provide an address range for the GART. * 20030610 - hamish@zot.org * This happens before pci_enable_device() intentionally; * calling pci_enable_device() before assigning the resource * will result in the GART being disabled on machines with such * BIOSs (the GART ends up with a BAR starting at 0, which * conflicts a lot of other devices). */ r = &pdev->resource[0]; if (!r->start && r->end) { if (pci_assign_resource(pdev, 0)) { dev_err(&pdev->dev, "can't assign resource 0\n"); agp_put_bridge(bridge); return -ENODEV; } } /* * If the device has not been properly setup, the following will catch * the problem and should stop the system from crashing. * 20030610 - hamish@zot.org */ if (pci_enable_device(pdev)) { dev_err(&pdev->dev, "can't enable PCI device\n"); agp_put_bridge(bridge); return -ENODEV; } /* Fill in the mode register */ if (cap_ptr) { pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode); } found_gmch: pci_set_drvdata(pdev, bridge); err = agp_add_bridge(bridge); return err; } static void agp_intel_remove(struct pci_dev *pdev) { struct agp_bridge_data *bridge = pci_get_drvdata(pdev); agp_remove_bridge(bridge); intel_gmch_remove(); agp_put_bridge(bridge); } #ifdef CONFIG_PM static int agp_intel_resume(struct pci_dev *pdev) { struct agp_bridge_data *bridge = pci_get_drvdata(pdev); bridge->driver->configure(); return 0; } #endif static struct pci_device_id agp_intel_pci_table[] = { #define ID(x) \ { \ .class = (PCI_CLASS_BRIDGE_HOST << 8), \ .class_mask = ~0, \ .vendor = PCI_VENDOR_ID_INTEL, \ .device = x, \ .subvendor = PCI_ANY_ID, \ .subdevice = PCI_ANY_ID, \ } ID(PCI_DEVICE_ID_INTEL_82441), /* for HAS2 support */ ID(PCI_DEVICE_ID_INTEL_82443LX_0), ID(PCI_DEVICE_ID_INTEL_82443BX_0), ID(PCI_DEVICE_ID_INTEL_82443GX_0), ID(PCI_DEVICE_ID_INTEL_82810_MC1), ID(PCI_DEVICE_ID_INTEL_82810_MC3), ID(PCI_DEVICE_ID_INTEL_82810E_MC), ID(PCI_DEVICE_ID_INTEL_82815_MC), ID(PCI_DEVICE_ID_INTEL_82820_HB), ID(PCI_DEVICE_ID_INTEL_82820_UP_HB), ID(PCI_DEVICE_ID_INTEL_82830_HB), ID(PCI_DEVICE_ID_INTEL_82840_HB), ID(PCI_DEVICE_ID_INTEL_82845_HB), ID(PCI_DEVICE_ID_INTEL_82845G_HB), ID(PCI_DEVICE_ID_INTEL_82850_HB), ID(PCI_DEVICE_ID_INTEL_82854_HB), ID(PCI_DEVICE_ID_INTEL_82855PM_HB), ID(PCI_DEVICE_ID_INTEL_82855GM_HB), ID(PCI_DEVICE_ID_INTEL_82860_HB), ID(PCI_DEVICE_ID_INTEL_82865_HB), ID(PCI_DEVICE_ID_INTEL_82875_HB), ID(PCI_DEVICE_ID_INTEL_7505_0), ID(PCI_DEVICE_ID_INTEL_7205_0), ID(PCI_DEVICE_ID_INTEL_E7221_HB), ID(PCI_DEVICE_ID_INTEL_82915G_HB), ID(PCI_DEVICE_ID_INTEL_82915GM_HB), ID(PCI_DEVICE_ID_INTEL_82945G_HB), ID(PCI_DEVICE_ID_INTEL_82945GM_HB), ID(PCI_DEVICE_ID_INTEL_82945GME_HB), ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB), ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB), ID(PCI_DEVICE_ID_INTEL_82946GZ_HB), ID(PCI_DEVICE_ID_INTEL_82G35_HB), ID(PCI_DEVICE_ID_INTEL_82965Q_HB), ID(PCI_DEVICE_ID_INTEL_82965G_HB), ID(PCI_DEVICE_ID_INTEL_82965GM_HB), ID(PCI_DEVICE_ID_INTEL_82965GME_HB), ID(PCI_DEVICE_ID_INTEL_G33_HB), ID(PCI_DEVICE_ID_INTEL_Q35_HB), ID(PCI_DEVICE_ID_INTEL_Q33_HB), ID(PCI_DEVICE_ID_INTEL_GM45_HB), ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB), ID(PCI_DEVICE_ID_INTEL_Q45_HB), ID(PCI_DEVICE_ID_INTEL_G45_HB), ID(PCI_DEVICE_ID_INTEL_G41_HB), ID(PCI_DEVICE_ID_INTEL_B43_HB), ID(PCI_DEVICE_ID_INTEL_B43_1_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D2_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB), { } }; MODULE_DEVICE_TABLE(pci, agp_intel_pci_table); static struct pci_driver agp_intel_pci_driver = { .name = "agpgart-intel", .id_table = agp_intel_pci_table, .probe = agp_intel_probe, .remove = agp_intel_remove, #ifdef CONFIG_PM .resume = agp_intel_resume, #endif }; static int __init agp_intel_init(void) { if (agp_off) return -EINVAL; return pci_register_driver(&agp_intel_pci_driver); } static void __exit agp_intel_cleanup(void) { pci_unregister_driver(&agp_intel_pci_driver); } module_init(agp_intel_init); module_exit(agp_intel_cleanup); MODULE_AUTHOR("Dave Jones, Various @Intel"); MODULE_LICENSE("GPL and additional rights");
gpl-2.0
liusen09003110-163-com/linux
drivers/char/agp/intel-agp.c
1341
28658
/* * Intel AGPGART routines. */ #include <linux/module.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/pagemap.h> #include <linux/agp_backend.h> #include <asm/smp.h> #include "agp.h" #include "intel-agp.h" #include <drm/intel-gtt.h> static int intel_fetch_size(void) { int i; u16 temp; struct aper_size_info_16 *values; pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp); values = A_SIZE_16(agp_bridge->driver->aperture_sizes); for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { if (temp == values[i].size_value) { agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i); agp_bridge->aperture_size_idx = i; return values[i].size; } } return 0; } static int __intel_8xx_fetch_size(u8 temp) { int i; struct aper_size_info_8 *values; values = A_SIZE_8(agp_bridge->driver->aperture_sizes); for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { if (temp == values[i].size_value) { agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i); agp_bridge->aperture_size_idx = i; return values[i].size; } } return 0; } static int intel_8xx_fetch_size(void) { u8 temp; pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp); return __intel_8xx_fetch_size(temp); } static int intel_815_fetch_size(void) { u8 temp; /* Intel 815 chipsets have a _weird_ APSIZE register with only * one non-reserved bit, so mask the others out ... */ pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp); temp &= (1 << 3); return __intel_8xx_fetch_size(temp); } static void intel_tlbflush(struct agp_memory *mem) { pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280); } static void intel_8xx_tlbflush(struct agp_memory *mem) { u32 temp; pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7)); pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp); pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7)); } static void intel_cleanup(void) { u16 temp; struct aper_size_info_16 *previous_size; previous_size = A_SIZE_16(agp_bridge->previous_size); pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9)); pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static void intel_8xx_cleanup(void) { u16 temp; struct aper_size_info_8 *previous_size; previous_size = A_SIZE_8(agp_bridge->previous_size); pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9)); pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static int intel_configure(void) { u16 temp2; struct aper_size_info_16 *current_size; current_size = A_SIZE_16(agp_bridge->current_size); /* aperture size */ pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280); /* paccfg/nbxcfg */ pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, (temp2 & ~(1 << 10)) | (1 << 9)); /* clear any possible error conditions */ pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7); return 0; } static int intel_815_configure(void) { u32 addr; u8 temp2; struct aper_size_info_8 *current_size; /* attbase - aperture base */ /* the Intel 815 chipset spec. says that bits 29-31 in the * ATTBASE register are reserved -> try not to write them */ if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) { dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high"); return -EINVAL; } current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr); addr &= INTEL_815_ATTBASE_MASK; addr |= agp_bridge->gatt_bus_addr; pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* apcont */ pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1)); /* clear any possible error conditions */ /* Oddness : this chipset seems to have no ERRSTS register ! */ return 0; } static void intel_820_tlbflush(struct agp_memory *mem) { return; } static void intel_820_cleanup(void) { u8 temp; struct aper_size_info_8 *previous_size; previous_size = A_SIZE_8(agp_bridge->previous_size); pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp); pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp & ~(1 << 1)); pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value); } static int intel_820_configure(void) { u8 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* global enable aperture access */ /* This flag is not accessed through MCHCFG register as in */ /* i850 chipset. */ pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c); return 0; } static int intel_840_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9)); /* clear any possible error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000); return 0; } static int intel_845_configure(void) { u8 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); if (agp_bridge->apbase_config != 0) { pci_write_config_dword(agp_bridge->dev, AGP_APBASE, agp_bridge->apbase_config); } else { /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); agp_bridge->apbase_config = agp_bridge->gart_bus_addr; } /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* agpm */ pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2); pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1)); /* clear any possible error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c); return 0; } static int intel_850_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c); return 0; } static int intel_860_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mcgcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700); return 0; } static int intel_830mp_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* gmch */ pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9)); /* clear any possible AGP-related error conditions */ pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c); return 0; } static int intel_7505_configure(void) { u16 temp2; struct aper_size_info_8 *current_size; current_size = A_SIZE_8(agp_bridge->current_size); /* aperture size */ pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); /* address to map to */ agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR); /* attbase - aperture base */ pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); /* agpctrl */ pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000); /* mchcfg */ pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2); pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9)); return 0; } /* Setup function */ static const struct gatt_mask intel_generic_masks[] = { {.mask = 0x00000017, .type = 0} }; static const struct aper_size_info_8 intel_815_sizes[2] = { {64, 16384, 4, 0}, {32, 8192, 3, 8}, }; static const struct aper_size_info_8 intel_8xx_sizes[7] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56}, {16, 4096, 2, 60}, {8, 2048, 1, 62}, {4, 1024, 0, 63} }; static const struct aper_size_info_16 intel_generic_sizes[7] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56}, {16, 4096, 2, 60}, {8, 2048, 1, 62}, {4, 1024, 0, 63} }; static const struct aper_size_info_8 intel_830mp_sizes[4] = { {256, 65536, 6, 0}, {128, 32768, 5, 32}, {64, 16384, 4, 48}, {32, 8192, 3, 56} }; static const struct agp_bridge_driver intel_generic_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_generic_sizes, .size_type = U16_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_configure, .fetch_size = intel_fetch_size, .cleanup = intel_cleanup, .tlb_flush = intel_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_815_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_815_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 2, .needs_scratch_page = true, .configure = intel_815_configure, .fetch_size = intel_815_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_820_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_820_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_820_cleanup, .tlb_flush = intel_820_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_830mp_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_830mp_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 4, .needs_scratch_page = true, .configure = intel_830mp_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_840_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_840_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_845_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_845_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_850_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_850_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_860_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_860_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; static const struct agp_bridge_driver intel_7505_driver = { .owner = THIS_MODULE, .aperture_sizes = intel_8xx_sizes, .size_type = U8_APER_SIZE, .num_aperture_sizes = 7, .needs_scratch_page = true, .configure = intel_7505_configure, .fetch_size = intel_8xx_fetch_size, .cleanup = intel_8xx_cleanup, .tlb_flush = intel_8xx_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = intel_generic_masks, .agp_enable = agp_generic_enable, .cache_flush = global_cache_flush, .create_gatt_table = agp_generic_create_gatt_table, .free_gatt_table = agp_generic_free_gatt_table, .insert_memory = agp_generic_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_alloc_pages = agp_generic_alloc_pages, .agp_destroy_page = agp_generic_destroy_page, .agp_destroy_pages = agp_generic_destroy_pages, .agp_type_to_mask_type = agp_generic_type_to_mask_type, }; /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of * driver and gmch_driver must be non-null, and find_gmch will determine * which one should be used if a gmch_chip_id is present. */ static const struct intel_agp_driver_description { unsigned int chip_id; char *name; const struct agp_bridge_driver *driver; } intel_agp_chipsets[] = { { PCI_DEVICE_ID_INTEL_82443LX_0, "440LX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82443BX_0, "440BX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82443GX_0, "440GX", &intel_generic_driver }, { PCI_DEVICE_ID_INTEL_82815_MC, "i815", &intel_815_driver }, { PCI_DEVICE_ID_INTEL_82820_HB, "i820", &intel_820_driver }, { PCI_DEVICE_ID_INTEL_82820_UP_HB, "i820", &intel_820_driver }, { PCI_DEVICE_ID_INTEL_82830_HB, "830M", &intel_830mp_driver }, { PCI_DEVICE_ID_INTEL_82840_HB, "i840", &intel_840_driver }, { PCI_DEVICE_ID_INTEL_82845_HB, "i845", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82845G_HB, "845G", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82850_HB, "i850", &intel_850_driver }, { PCI_DEVICE_ID_INTEL_82854_HB, "854", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82855PM_HB, "855PM", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82855GM_HB, "855GM", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82860_HB, "i860", &intel_860_driver }, { PCI_DEVICE_ID_INTEL_82865_HB, "865", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_82875_HB, "i875", &intel_845_driver }, { PCI_DEVICE_ID_INTEL_7505_0, "E7505", &intel_7505_driver }, { PCI_DEVICE_ID_INTEL_7205_0, "E7205", &intel_7505_driver }, { 0, NULL, NULL } }; static int agp_intel_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct agp_bridge_data *bridge; u8 cap_ptr = 0; struct resource *r; int i, err; cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); bridge = agp_alloc_bridge(); if (!bridge) return -ENOMEM; bridge->capndx = cap_ptr; if (intel_gmch_probe(pdev, NULL, bridge)) goto found_gmch; for (i = 0; intel_agp_chipsets[i].name != NULL; i++) { /* In case that multiple models of gfx chip may stand on same host bridge type, this can be sure we detect the right IGD. */ if (pdev->device == intel_agp_chipsets[i].chip_id) { bridge->driver = intel_agp_chipsets[i].driver; break; } } if (!bridge->driver) { if (cap_ptr) dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n", pdev->vendor, pdev->device); agp_put_bridge(bridge); return -ENODEV; } bridge->dev = pdev; bridge->dev_private_data = NULL; dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name); /* * The following fixes the case where the BIOS has "forgotten" to * provide an address range for the GART. * 20030610 - hamish@zot.org * This happens before pci_enable_device() intentionally; * calling pci_enable_device() before assigning the resource * will result in the GART being disabled on machines with such * BIOSs (the GART ends up with a BAR starting at 0, which * conflicts a lot of other devices). */ r = &pdev->resource[0]; if (!r->start && r->end) { if (pci_assign_resource(pdev, 0)) { dev_err(&pdev->dev, "can't assign resource 0\n"); agp_put_bridge(bridge); return -ENODEV; } } /* * If the device has not been properly setup, the following will catch * the problem and should stop the system from crashing. * 20030610 - hamish@zot.org */ if (pci_enable_device(pdev)) { dev_err(&pdev->dev, "can't enable PCI device\n"); agp_put_bridge(bridge); return -ENODEV; } /* Fill in the mode register */ if (cap_ptr) { pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode); } found_gmch: pci_set_drvdata(pdev, bridge); err = agp_add_bridge(bridge); return err; } static void agp_intel_remove(struct pci_dev *pdev) { struct agp_bridge_data *bridge = pci_get_drvdata(pdev); agp_remove_bridge(bridge); intel_gmch_remove(); agp_put_bridge(bridge); } #ifdef CONFIG_PM static int agp_intel_resume(struct pci_dev *pdev) { struct agp_bridge_data *bridge = pci_get_drvdata(pdev); bridge->driver->configure(); return 0; } #endif static struct pci_device_id agp_intel_pci_table[] = { #define ID(x) \ { \ .class = (PCI_CLASS_BRIDGE_HOST << 8), \ .class_mask = ~0, \ .vendor = PCI_VENDOR_ID_INTEL, \ .device = x, \ .subvendor = PCI_ANY_ID, \ .subdevice = PCI_ANY_ID, \ } ID(PCI_DEVICE_ID_INTEL_82441), /* for HAS2 support */ ID(PCI_DEVICE_ID_INTEL_82443LX_0), ID(PCI_DEVICE_ID_INTEL_82443BX_0), ID(PCI_DEVICE_ID_INTEL_82443GX_0), ID(PCI_DEVICE_ID_INTEL_82810_MC1), ID(PCI_DEVICE_ID_INTEL_82810_MC3), ID(PCI_DEVICE_ID_INTEL_82810E_MC), ID(PCI_DEVICE_ID_INTEL_82815_MC), ID(PCI_DEVICE_ID_INTEL_82820_HB), ID(PCI_DEVICE_ID_INTEL_82820_UP_HB), ID(PCI_DEVICE_ID_INTEL_82830_HB), ID(PCI_DEVICE_ID_INTEL_82840_HB), ID(PCI_DEVICE_ID_INTEL_82845_HB), ID(PCI_DEVICE_ID_INTEL_82845G_HB), ID(PCI_DEVICE_ID_INTEL_82850_HB), ID(PCI_DEVICE_ID_INTEL_82854_HB), ID(PCI_DEVICE_ID_INTEL_82855PM_HB), ID(PCI_DEVICE_ID_INTEL_82855GM_HB), ID(PCI_DEVICE_ID_INTEL_82860_HB), ID(PCI_DEVICE_ID_INTEL_82865_HB), ID(PCI_DEVICE_ID_INTEL_82875_HB), ID(PCI_DEVICE_ID_INTEL_7505_0), ID(PCI_DEVICE_ID_INTEL_7205_0), ID(PCI_DEVICE_ID_INTEL_E7221_HB), ID(PCI_DEVICE_ID_INTEL_82915G_HB), ID(PCI_DEVICE_ID_INTEL_82915GM_HB), ID(PCI_DEVICE_ID_INTEL_82945G_HB), ID(PCI_DEVICE_ID_INTEL_82945GM_HB), ID(PCI_DEVICE_ID_INTEL_82945GME_HB), ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB), ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB), ID(PCI_DEVICE_ID_INTEL_82946GZ_HB), ID(PCI_DEVICE_ID_INTEL_82G35_HB), ID(PCI_DEVICE_ID_INTEL_82965Q_HB), ID(PCI_DEVICE_ID_INTEL_82965G_HB), ID(PCI_DEVICE_ID_INTEL_82965GM_HB), ID(PCI_DEVICE_ID_INTEL_82965GME_HB), ID(PCI_DEVICE_ID_INTEL_G33_HB), ID(PCI_DEVICE_ID_INTEL_Q35_HB), ID(PCI_DEVICE_ID_INTEL_Q33_HB), ID(PCI_DEVICE_ID_INTEL_GM45_HB), ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB), ID(PCI_DEVICE_ID_INTEL_Q45_HB), ID(PCI_DEVICE_ID_INTEL_G45_HB), ID(PCI_DEVICE_ID_INTEL_G41_HB), ID(PCI_DEVICE_ID_INTEL_B43_HB), ID(PCI_DEVICE_ID_INTEL_B43_1_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D2_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB), ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB), { } }; MODULE_DEVICE_TABLE(pci, agp_intel_pci_table); static struct pci_driver agp_intel_pci_driver = { .name = "agpgart-intel", .id_table = agp_intel_pci_table, .probe = agp_intel_probe, .remove = agp_intel_remove, #ifdef CONFIG_PM .resume = agp_intel_resume, #endif }; static int __init agp_intel_init(void) { if (agp_off) return -EINVAL; return pci_register_driver(&agp_intel_pci_driver); } static void __exit agp_intel_cleanup(void) { pci_unregister_driver(&agp_intel_pci_driver); } module_init(agp_intel_init); module_exit(agp_intel_cleanup); MODULE_AUTHOR("Dave Jones, Various @Intel"); MODULE_LICENSE("GPL and additional rights");
gpl-2.0
NeoPhyTe-x360/i9300-S3-JB-kernel
drivers/staging/rtl8192e/r8192E_core.c
2365
147404
/****************************************************************************** * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. * Linux device driver for RTL8192E * * Based on the r8180 driver, which is: * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al. * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * Jerry chuang <wlanfae@realtek.com> */ #include <linux/vmalloc.h> #include <linux/slab.h> #include <asm/uaccess.h> #include "r8192E_hw.h" #include "r8192E.h" #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */ #include "r8180_93cx6.h" /* Card EEPROM */ #include "r8192E_wx.h" #include "r819xE_phy.h" //added by WB 4.30.2008 #include "r819xE_phyreg.h" #include "r819xE_cmdpkt.h" #include "r8192E_dm.h" #ifdef CONFIG_PM #include "r8192_pm.h" #endif #ifdef ENABLE_DOT11D #include "ieee80211/dot11d.h" #endif //set here to open your trace code. //WB u32 rt_global_debug_component = COMP_ERR ; //always open err flags on static DEFINE_PCI_DEVICE_TABLE(rtl8192_pci_id_tbl) = { /* Realtek */ { PCI_DEVICE(0x10ec, 0x8192) }, /* Corega */ { PCI_DEVICE(0x07aa, 0x0044) }, { PCI_DEVICE(0x07aa, 0x0047) }, {} }; static char ifname[IFNAMSIZ] = "wlan%d"; static int hwwep = 1; //default use hw. set 0 to use software security static int channels = 0x3fff; MODULE_LICENSE("GPL"); MODULE_VERSION("V 1.1"); MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl); //MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>"); MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); module_param(hwwep,int, S_IRUGO|S_IWUSR); module_param(channels,int, S_IRUGO|S_IWUSR); MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default"); MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards"); MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI"); static int __devinit rtl8192_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id); static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev); static struct pci_driver rtl8192_pci_driver = { .name = RTL819xE_MODULE_NAME, /* Driver name */ .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */ .probe = rtl8192_pci_probe, /* probe fn */ .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */ #ifdef CONFIG_PM .suspend = rtl8192E_suspend, /* PM suspend fn */ .resume = rtl8192E_resume, /* PM resume fn */ #else .suspend = NULL, /* PM suspend fn */ .resume = NULL, /* PM resume fn */ #endif }; static void rtl8192_start_beacon(struct ieee80211_device *ieee80211); static void rtl8192_stop_beacon(struct ieee80211_device *ieee80211); static void rtl819x_watchdog_wqcallback(struct work_struct *work); static void rtl8192_irq_rx_tasklet(unsigned long arg); static void rtl8192_irq_tx_tasklet(unsigned long arg); static void rtl8192_prepare_beacon(unsigned long arg); static irqreturn_t rtl8192_interrupt(int irq, void *param); static void rtl819xE_tx_cmd(struct r8192_priv *priv, struct sk_buff *skb); static void rtl8192_update_ratr_table(struct r8192_priv *priv); static void rtl8192_restart(struct work_struct *work); static void watch_dog_timer_callback(unsigned long data); static int _rtl8192_up(struct r8192_priv *priv); static void rtl8192_cancel_deferred_work(struct r8192_priv* priv); static short rtl8192_tx(struct r8192_priv *priv, struct sk_buff* skb); #ifdef ENABLE_DOT11D typedef struct _CHANNEL_LIST { u8 Channel[32]; u8 Len; }CHANNEL_LIST, *PCHANNEL_LIST; static const CHANNEL_LIST ChannelPlan[] = { {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI. {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI. {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel. {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, // For 11a , TELEC {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14} //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626 }; static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv) { int i, max_chan=-1, min_chan=-1; struct ieee80211_device* ieee = priv->ieee80211; switch (channel_plan) { case COUNTRY_CODE_FCC: case COUNTRY_CODE_IC: case COUNTRY_CODE_ETSI: case COUNTRY_CODE_SPAIN: case COUNTRY_CODE_FRANCE: case COUNTRY_CODE_MKK: case COUNTRY_CODE_MKK1: case COUNTRY_CODE_ISRAEL: case COUNTRY_CODE_TELEC: case COUNTRY_CODE_MIC: { Dot11d_Init(ieee); ieee->bGlobalDomain = false; //acturally 8225 & 8256 rf chip only support B,G,24N mode min_chan = 1; max_chan = 14; if (ChannelPlan[channel_plan].Len != 0){ // Clear old channel map memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); // Set new channel map for (i=0;i<ChannelPlan[channel_plan].Len;i++) { if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan) break; GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1; } } break; } case COUNTRY_CODE_GLOBAL_DOMAIN: { GET_DOT11D_INFO(ieee)->bEnabled = 0; //this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain setting Dot11d_Reset(ieee); ieee->bGlobalDomain = true; break; } default: break; } } #endif static inline bool rx_hal_is_cck_rate(prx_fwinfo_819x_pci pdrvinfo) { return (pdrvinfo->RxRate == DESC90_RATE1M || pdrvinfo->RxRate == DESC90_RATE2M || pdrvinfo->RxRate == DESC90_RATE5_5M || pdrvinfo->RxRate == DESC90_RATE11M) && !pdrvinfo->RxHT; } void CamResetAllEntry(struct r8192_priv* priv) { write_nic_dword(priv, RWCAM, BIT31|BIT30); } void write_cam(struct r8192_priv *priv, u8 addr, u32 data) { write_nic_dword(priv, WCAMI, data); write_nic_dword(priv, RWCAM, BIT31|BIT16|(addr&0xff) ); } u32 read_cam(struct r8192_priv *priv, u8 addr) { write_nic_dword(priv, RWCAM, 0x80000000|(addr&0xff) ); return read_nic_dword(priv, 0xa8); } u8 read_nic_byte(struct r8192_priv *priv, int x) { return 0xff & readb(priv->mem_start + x); } u32 read_nic_dword(struct r8192_priv *priv, int x) { return readl(priv->mem_start + x); } u16 read_nic_word(struct r8192_priv *priv, int x) { return readw(priv->mem_start + x); } void write_nic_byte(struct r8192_priv *priv, int x,u8 y) { writeb(y, priv->mem_start + x); udelay(20); } void write_nic_dword(struct r8192_priv *priv, int x,u32 y) { writel(y, priv->mem_start + x); udelay(20); } void write_nic_word(struct r8192_priv *priv, int x,u16 y) { writew(y, priv->mem_start + x); udelay(20); } u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee) { static const u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04}; static const u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04}; int wpa_ie_len= ieee->wpa_ie_len; struct ieee80211_crypt_data* crypt; int encrypt; crypt = ieee->crypt[ieee->tx_keyidx]; encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP"))); /* simply judge */ if(encrypt && (wpa_ie_len == 0)) { // wep encryption, no N mode setting */ return SEC_ALG_WEP; } else if((wpa_ie_len != 0)) { // parse pairwise key type */ if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4)))) return SEC_ALG_CCMP; else return SEC_ALG_TKIP; } else { return SEC_ALG_NONE; } } void rtl8192e_SetHwReg(struct ieee80211_device *ieee80211, u8 variable, u8 *val) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); switch(variable) { case HW_VAR_BSSID: write_nic_dword(priv, BSSIDR, ((u32*)(val))[0]); write_nic_word(priv, BSSIDR+2, ((u16*)(val+2))[0]); break; case HW_VAR_MEDIA_STATUS: { RT_OP_MODE OpMode = *((RT_OP_MODE *)(val)); u8 btMsr = read_nic_byte(priv, MSR); btMsr &= 0xfc; switch(OpMode) { case RT_OP_MODE_INFRASTRUCTURE: btMsr |= MSR_INFRA; break; case RT_OP_MODE_IBSS: btMsr |= MSR_ADHOC; break; case RT_OP_MODE_AP: btMsr |= MSR_AP; break; default: btMsr |= MSR_NOLINK; break; } write_nic_byte(priv, MSR, btMsr); } break; case HW_VAR_CHECK_BSSID: { u32 RegRCR, Type; Type = ((u8*)(val))[0]; RegRCR = read_nic_dword(priv, RCR); priv->ReceiveConfig = RegRCR; if (Type == true) RegRCR |= (RCR_CBSSID); else if (Type == false) RegRCR &= (~RCR_CBSSID); write_nic_dword(priv, RCR,RegRCR); priv->ReceiveConfig = RegRCR; } break; case HW_VAR_SLOT_TIME: { priv->slot_time = val[0]; write_nic_byte(priv, SLOT_TIME, val[0]); } break; case HW_VAR_ACK_PREAMBLE: { u32 regTmp = 0; priv->short_preamble = (bool)(*(u8*)val ); regTmp = priv->basic_rate; if (priv->short_preamble) regTmp |= BRSR_AckShortPmb; write_nic_dword(priv, RRSR, regTmp); } break; case HW_VAR_CPU_RST: write_nic_dword(priv, CPU_GEN, ((u32*)(val))[0]); break; default: break; } } static struct proc_dir_entry *rtl8192_proc = NULL; static int proc_get_stats_ap(char *page, char **start, off_t offset, int count, int *eof, void *data) { struct r8192_priv *priv = data; struct ieee80211_device *ieee = priv->ieee80211; struct ieee80211_network *target; int len = 0; list_for_each_entry(target, &ieee->network_list, list) { len += snprintf(page + len, count - len, "%s ", target->ssid); if(target->wpa_ie_len>0 || target->rsn_ie_len>0){ len += snprintf(page + len, count - len, "WPA\n"); } else{ len += snprintf(page + len, count - len, "non_WPA\n"); } } *eof = 1; return len; } static int proc_get_registers(char *page, char **start, off_t offset, int count, int *eof, void *data) { struct r8192_priv *priv = data; int len = 0; int i,n; int max=0xff; /* This dump the current register page */ len += snprintf(page + len, count - len, "\n####################page 0##################\n "); for(n=0;n<=max;) { len += snprintf(page + len, count - len, "\nD: %2x > ",n); for(i=0;i<16 && n<=max;i++,n++) len += snprintf(page + len, count - len, "%2x ",read_nic_byte(priv,n)); } len += snprintf(page + len, count - len,"\n"); len += snprintf(page + len, count - len, "\n####################page 1##################\n "); for(n=0;n<=max;) { len += snprintf(page + len, count - len, "\nD: %2x > ",n); for(i=0;i<16 && n<=max;i++,n++) len += snprintf(page + len, count - len, "%2x ",read_nic_byte(priv,0x100|n)); } len += snprintf(page + len, count - len, "\n####################page 3##################\n "); for(n=0;n<=max;) { len += snprintf(page + len, count - len, "\nD: %2x > ",n); for(i=0;i<16 && n<=max;i++,n++) len += snprintf(page + len, count - len, "%2x ",read_nic_byte(priv,0x300|n)); } *eof = 1; return len; } static int proc_get_stats_tx(char *page, char **start, off_t offset, int count, int *eof, void *data) { struct r8192_priv *priv = data; int len = 0; len += snprintf(page + len, count - len, "TX VI priority ok int: %lu\n" "TX VO priority ok int: %lu\n" "TX BE priority ok int: %lu\n" "TX BK priority ok int: %lu\n" "TX MANAGE priority ok int: %lu\n" "TX BEACON priority ok int: %lu\n" "TX BEACON priority error int: %lu\n" "TX CMDPKT priority ok int: %lu\n" "TX queue stopped?: %d\n" "TX fifo overflow: %lu\n" "TX total data packets %lu\n" "TX total data bytes :%lu\n", priv->stats.txviokint, priv->stats.txvookint, priv->stats.txbeokint, priv->stats.txbkokint, priv->stats.txmanageokint, priv->stats.txbeaconokint, priv->stats.txbeaconerr, priv->stats.txcmdpktokint, netif_queue_stopped(priv->ieee80211->dev), priv->stats.txoverflow, priv->ieee80211->stats.tx_packets, priv->ieee80211->stats.tx_bytes); *eof = 1; return len; } static int proc_get_stats_rx(char *page, char **start, off_t offset, int count, int *eof, void *data) { struct r8192_priv *priv = data; int len = 0; len += snprintf(page + len, count - len, "RX packets: %lu\n" "RX desc err: %lu\n" "RX rx overflow error: %lu\n", priv->stats.rxint, priv->stats.rxrdu, priv->stats.rxoverflow); *eof = 1; return len; } static void rtl8192_proc_module_init(void) { RT_TRACE(COMP_INIT, "Initializing proc filesystem\n"); rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net); } static void rtl8192_proc_module_remove(void) { remove_proc_entry(RTL819xE_MODULE_NAME, init_net.proc_net); } static void rtl8192_proc_remove_one(struct r8192_priv *priv) { struct net_device *dev = priv->ieee80211->dev; printk("dev name=======> %s\n",dev->name); if (priv->dir_dev) { remove_proc_entry("stats-tx", priv->dir_dev); remove_proc_entry("stats-rx", priv->dir_dev); remove_proc_entry("stats-ap", priv->dir_dev); remove_proc_entry("registers", priv->dir_dev); remove_proc_entry("wlan0", rtl8192_proc); priv->dir_dev = NULL; } } static void rtl8192_proc_init_one(struct r8192_priv *priv) { struct net_device *dev = priv->ieee80211->dev; struct proc_dir_entry *e; priv->dir_dev = create_proc_entry(dev->name, S_IFDIR | S_IRUGO | S_IXUGO, rtl8192_proc); if (!priv->dir_dev) { RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n", dev->name); return; } e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO, priv->dir_dev, proc_get_stats_rx, priv); if (!e) { RT_TRACE(COMP_ERR,"Unable to initialize " "/proc/net/rtl8192/%s/stats-rx\n", dev->name); } e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO, priv->dir_dev, proc_get_stats_tx, priv); if (!e) { RT_TRACE(COMP_ERR, "Unable to initialize " "/proc/net/rtl8192/%s/stats-tx\n", dev->name); } e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO, priv->dir_dev, proc_get_stats_ap, priv); if (!e) { RT_TRACE(COMP_ERR, "Unable to initialize " "/proc/net/rtl8192/%s/stats-ap\n", dev->name); } e = create_proc_read_entry("registers", S_IFREG | S_IRUGO, priv->dir_dev, proc_get_registers, priv); if (!e) { RT_TRACE(COMP_ERR, "Unable to initialize " "/proc/net/rtl8192/%s/registers\n", dev->name); } } static short check_nic_enough_desc(struct ieee80211_device *ieee, int prio) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; /* for now we reserve two free descriptor as a safety boundary * between the tail and the head */ return (ring->entries - skb_queue_len(&ring->queue) >= 2); } static void tx_timeout(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); schedule_work(&priv->reset_wq); printk("TXTIMEOUT"); } static void rtl8192_irq_enable(struct r8192_priv *priv) { u32 mask; mask = IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK | IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK | IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW | IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER; write_nic_dword(priv, INTA_MASK, mask); } static void rtl8192_irq_disable(struct r8192_priv *priv) { write_nic_dword(priv, INTA_MASK, 0); synchronize_irq(priv->irq); } static void rtl8192_update_msr(struct r8192_priv *priv) { u8 msr; msr = read_nic_byte(priv, MSR); msr &= ~ MSR_LINK_MASK; /* do not change in link_state != WLAN_LINK_ASSOCIATED. * msr must be updated if the state is ASSOCIATING. * this is intentional and make sense for ad-hoc and * master (see the create BSS/IBSS func) */ if (priv->ieee80211->state == IEEE80211_LINKED){ if (priv->ieee80211->iw_mode == IW_MODE_INFRA) msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT); else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT); else if (priv->ieee80211->iw_mode == IW_MODE_MASTER) msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT); }else msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT); write_nic_byte(priv, MSR, msr); } static void rtl8192_set_chan(struct ieee80211_device *ieee80211, short ch) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); priv->chan = ch; /* need to implement rf set channel here WB */ if (priv->rf_set_chan) priv->rf_set_chan(ieee80211, priv->chan); } static void rtl8192_rx_enable(struct r8192_priv *priv) { write_nic_dword(priv, RDQDA, priv->rx_ring_dma); } /* the TX_DESC_BASE setting is according to the following queue index * BK_QUEUE ===> 0 * BE_QUEUE ===> 1 * VI_QUEUE ===> 2 * VO_QUEUE ===> 3 * HCCA_QUEUE ===> 4 * TXCMD_QUEUE ===> 5 * MGNT_QUEUE ===> 6 * HIGH_QUEUE ===> 7 * BEACON_QUEUE ===> 8 * */ static const u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA}; static void rtl8192_tx_enable(struct r8192_priv *priv) { u32 i; for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) write_nic_dword(priv, TX_DESC_BASE[i], priv->tx_ring[i].dma); ieee80211_reset_queue(priv->ieee80211); } static void rtl8192_free_rx_ring(struct r8192_priv *priv) { int i; for (i = 0; i < priv->rxringcount; i++) { struct sk_buff *skb = priv->rx_buf[i]; if (!skb) continue; pci_unmap_single(priv->pdev, *((dma_addr_t *)skb->cb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); kfree_skb(skb); } pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount, priv->rx_ring, priv->rx_ring_dma); priv->rx_ring = NULL; } static void rtl8192_free_tx_ring(struct r8192_priv *priv, unsigned int prio) { struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; while (skb_queue_len(&ring->queue)) { tx_desc_819x_pci *entry = &ring->desc[ring->idx]; struct sk_buff *skb = __skb_dequeue(&ring->queue); pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), skb->len, PCI_DMA_TODEVICE); kfree_skb(skb); ring->idx = (ring->idx + 1) % ring->entries; } pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries, ring->desc, ring->dma); ring->desc = NULL; } void PHY_SetRtl8192eRfOff(struct r8192_priv *priv) { //disable RF-Chip A/B rtl8192_setBBreg(priv, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0); //analog to digital off, for power save rtl8192_setBBreg(priv, rFPGA0_AnalogParameter4, 0x300, 0x0); //digital to analog off, for power save rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x18, 0x0); //rx antenna off rtl8192_setBBreg(priv, rOFDM0_TRxPathEnable, 0xf, 0x0); //rx antenna off rtl8192_setBBreg(priv, rOFDM1_TRxPathEnable, 0xf, 0x0); //analog to digital part2 off, for power save rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x60, 0x0); rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x4, 0x0); // Analog parameter!!Change bias and Lbus control. write_nic_byte(priv, ANAPAR_FOR_8192PciE, 0x07); } static void rtl8192_halt_adapter(struct r8192_priv *priv, bool reset) { int i; u8 OpMode; u32 ulRegRead; OpMode = RT_OP_MODE_NO_LINK; priv->ieee80211->SetHwRegHandler(priv->ieee80211, HW_VAR_MEDIA_STATUS, &OpMode); if (!priv->ieee80211->bSupportRemoteWakeUp) { /* * disable tx/rx. In 8185 we write 0x10 (Reset bit), * but here we make reference to WMAC and wirte 0x0 */ write_nic_byte(priv, CMDR, 0); } mdelay(20); if (!reset) { mdelay(150); priv->bHwRfOffAction = 2; /* * Call MgntActSet_RF_State instead to * prevent RF config race condition. */ if (!priv->ieee80211->bSupportRemoteWakeUp) { PHY_SetRtl8192eRfOff(priv); ulRegRead = read_nic_dword(priv, CPU_GEN); ulRegRead |= CPU_GEN_SYSTEM_RESET; write_nic_dword(priv,CPU_GEN, ulRegRead); } else { /* for WOL */ write_nic_dword(priv, WFCRC0, 0xffffffff); write_nic_dword(priv, WFCRC1, 0xffffffff); write_nic_dword(priv, WFCRC2, 0xffffffff); /* Write PMR register */ write_nic_byte(priv, PMR, 0x5); /* Disable tx, enanble rx */ write_nic_byte(priv, MacBlkCtrl, 0xa); } } for(i = 0; i < MAX_QUEUE_SIZE; i++) { skb_queue_purge(&priv->ieee80211->skb_waitQ [i]); } for(i = 0; i < MAX_QUEUE_SIZE; i++) { skb_queue_purge(&priv->ieee80211->skb_aggQ [i]); } skb_queue_purge(&priv->skb_queue); } static void rtl8192_data_hard_stop(struct ieee80211_device *ieee80211) { } static void rtl8192_data_hard_resume(struct ieee80211_device *ieee80211) { } /* * this function TX data frames when the ieee80211 stack requires this. * It checks also if we need to stop the ieee tx queue, eventually do it */ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct ieee80211_device *ieee80211, int rate) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); int ret; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); u8 queue_index = tcb_desc->queue_index; /* shall not be referred by command packet */ BUG_ON(queue_index == TXCMD_QUEUE); if (priv->bHwRadioOff || (!priv->up)) { kfree_skb(skb); return; } skb_push(skb, priv->ieee80211->tx_headroom); ret = rtl8192_tx(priv, skb); if (ret != 0) { kfree_skb(skb); } if (queue_index != MGNT_QUEUE) { priv->ieee80211->stats.tx_bytes += (skb->len - priv->ieee80211->tx_headroom); priv->ieee80211->stats.tx_packets++; } } /* * This is a rough attempt to TX a frame * This is called by the ieee 80211 stack to TX management frames. * If the ring is full packet are dropped (for data frame the queue * is stopped before this can happen). */ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); int ret; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); u8 queue_index = tcb_desc->queue_index; if (queue_index != TXCMD_QUEUE) { if (priv->bHwRadioOff || (!priv->up)) { kfree_skb(skb); return 0; } } if (queue_index == TXCMD_QUEUE) { rtl819xE_tx_cmd(priv, skb); ret = 0; return ret; } else { tcb_desc->RATRIndex = 7; tcb_desc->bTxDisableRateFallBack = 1; tcb_desc->bTxUseDriverAssingedRate = 1; tcb_desc->bTxEnableFwCalcDur = 1; skb_push(skb, ieee80211->tx_headroom); ret = rtl8192_tx(priv, skb); if (ret != 0) { kfree_skb(skb); } } return ret; } static void rtl8192_tx_isr(struct r8192_priv *priv, int prio) { struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; while (skb_queue_len(&ring->queue)) { tx_desc_819x_pci *entry = &ring->desc[ring->idx]; struct sk_buff *skb; /* * beacon packet will only use the first descriptor defaultly, * and the OWN may not be cleared by the hardware */ if (prio != BEACON_QUEUE) { if (entry->OWN) return; ring->idx = (ring->idx + 1) % ring->entries; } skb = __skb_dequeue(&ring->queue); pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), skb->len, PCI_DMA_TODEVICE); kfree_skb(skb); } if (prio != BEACON_QUEUE) { /* try to deal with the pending packets */ tasklet_schedule(&priv->irq_tx_tasklet); } } static void rtl8192_stop_beacon(struct ieee80211_device *ieee80211) { } static void rtl8192_config_rate(struct r8192_priv *priv, u16* rate_config) { struct ieee80211_network *net; u8 i=0, basic_rate = 0; net = & priv->ieee80211->current_network; for (i=0; i<net->rates_len; i++) { basic_rate = net->rates[i]&0x7f; switch(basic_rate) { case MGN_1M: *rate_config |= RRSR_1M; break; case MGN_2M: *rate_config |= RRSR_2M; break; case MGN_5_5M: *rate_config |= RRSR_5_5M; break; case MGN_11M: *rate_config |= RRSR_11M; break; case MGN_6M: *rate_config |= RRSR_6M; break; case MGN_9M: *rate_config |= RRSR_9M; break; case MGN_12M: *rate_config |= RRSR_12M; break; case MGN_18M: *rate_config |= RRSR_18M; break; case MGN_24M: *rate_config |= RRSR_24M; break; case MGN_36M: *rate_config |= RRSR_36M; break; case MGN_48M: *rate_config |= RRSR_48M; break; case MGN_54M: *rate_config |= RRSR_54M; break; } } for (i=0; i<net->rates_ex_len; i++) { basic_rate = net->rates_ex[i]&0x7f; switch(basic_rate) { case MGN_1M: *rate_config |= RRSR_1M; break; case MGN_2M: *rate_config |= RRSR_2M; break; case MGN_5_5M: *rate_config |= RRSR_5_5M; break; case MGN_11M: *rate_config |= RRSR_11M; break; case MGN_6M: *rate_config |= RRSR_6M; break; case MGN_9M: *rate_config |= RRSR_9M; break; case MGN_12M: *rate_config |= RRSR_12M; break; case MGN_18M: *rate_config |= RRSR_18M; break; case MGN_24M: *rate_config |= RRSR_24M; break; case MGN_36M: *rate_config |= RRSR_36M; break; case MGN_48M: *rate_config |= RRSR_48M; break; case MGN_54M: *rate_config |= RRSR_54M; break; } } } #define SHORT_SLOT_TIME 9 #define NON_SHORT_SLOT_TIME 20 static void rtl8192_update_cap(struct r8192_priv *priv, u16 cap) { u32 tmp = 0; struct ieee80211_network *net = &priv->ieee80211->current_network; priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE; tmp = priv->basic_rate; if (priv->short_preamble) tmp |= BRSR_AckShortPmb; write_nic_dword(priv, RRSR, tmp); if (net->mode & (IEEE_G|IEEE_N_24G)) { u8 slot_time = 0; if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) {//short slot time slot_time = SHORT_SLOT_TIME; } else //long slot time slot_time = NON_SHORT_SLOT_TIME; priv->slot_time = slot_time; write_nic_byte(priv, SLOT_TIME, slot_time); } } static void rtl8192_net_update(struct r8192_priv *priv) { struct ieee80211_network *net; u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf; u16 rate_config = 0; net = &priv->ieee80211->current_network; /* update Basic rate: RR, BRSR */ rtl8192_config_rate(priv, &rate_config); /* * Select RRSR (in Legacy-OFDM and CCK) * For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, * 2M, and 1M from the Basic rate. * We do not use other rates. */ priv->basic_rate = rate_config &= 0x15f; /* BSSID */ write_nic_dword(priv, BSSIDR, ((u32 *)net->bssid)[0]); write_nic_word(priv, BSSIDR+4, ((u16 *)net->bssid)[2]); if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) { write_nic_word(priv, ATIMWND, 2); write_nic_word(priv, BCN_DMATIME, 256); write_nic_word(priv, BCN_INTERVAL, net->beacon_interval); /* * BIT15 of BCN_DRV_EARLY_INT will indicate * whether software beacon or hw beacon is applied. */ write_nic_word(priv, BCN_DRV_EARLY_INT, 10); write_nic_byte(priv, BCN_ERR_THRESH, 100); BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT); /* TODO: BcnIFS may required to be changed on ASIC */ BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; write_nic_word(priv, BCN_TCFG, BcnTimeCfg); } } static void rtl819xE_tx_cmd(struct r8192_priv *priv, struct sk_buff *skb) { struct rtl8192_tx_ring *ring; tx_desc_819x_pci *entry; unsigned int idx; dma_addr_t mapping; cb_desc *tcb_desc; unsigned long flags; ring = &priv->tx_ring[TXCMD_QUEUE]; mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); spin_lock_irqsave(&priv->irq_th_lock,flags); idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; entry = &ring->desc[idx]; tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); memset(entry,0,12); entry->LINIP = tcb_desc->bLastIniPkt; entry->FirstSeg = 1;//first segment entry->LastSeg = 1; //last segment if(tcb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) { entry->CmdInit = DESC_PACKET_TYPE_INIT; } else { entry->CmdInit = DESC_PACKET_TYPE_NORMAL; entry->Offset = sizeof(TX_FWINFO_8190PCI) + 8; entry->PktSize = (u16)(tcb_desc->pkt_size + entry->Offset); entry->QueueSelect = QSLT_CMD; entry->TxFWInfoSize = 0x08; entry->RATid = (u8)DESC_PACKET_TYPE_INIT; } entry->TxBufferSize = skb->len; entry->TxBuffAddr = cpu_to_le32(mapping); entry->OWN = 1; __skb_queue_tail(&ring->queue, skb); spin_unlock_irqrestore(&priv->irq_th_lock,flags); write_nic_byte(priv, TPPoll, TPPoll_CQ); return; } /* * Mapping Software/Hardware descriptor queue id to "Queue Select Field" * in TxFwInfo data structure */ static u8 MapHwQueueToFirmwareQueue(u8 QueueID) { u8 QueueSelect = 0; switch (QueueID) { case BE_QUEUE: QueueSelect = QSLT_BE; break; case BK_QUEUE: QueueSelect = QSLT_BK; break; case VO_QUEUE: QueueSelect = QSLT_VO; break; case VI_QUEUE: QueueSelect = QSLT_VI; break; case MGNT_QUEUE: QueueSelect = QSLT_MGNT; break; case BEACON_QUEUE: QueueSelect = QSLT_BEACON; break; case TXCMD_QUEUE: QueueSelect = QSLT_CMD; break; case HIGH_QUEUE: default: RT_TRACE(COMP_ERR, "Impossible Queue Selection: %d\n", QueueID); break; } return QueueSelect; } static u8 MRateToHwRate8190Pci(u8 rate) { u8 ret = DESC90_RATE1M; switch(rate) { case MGN_1M: ret = DESC90_RATE1M; break; case MGN_2M: ret = DESC90_RATE2M; break; case MGN_5_5M: ret = DESC90_RATE5_5M; break; case MGN_11M: ret = DESC90_RATE11M; break; case MGN_6M: ret = DESC90_RATE6M; break; case MGN_9M: ret = DESC90_RATE9M; break; case MGN_12M: ret = DESC90_RATE12M; break; case MGN_18M: ret = DESC90_RATE18M; break; case MGN_24M: ret = DESC90_RATE24M; break; case MGN_36M: ret = DESC90_RATE36M; break; case MGN_48M: ret = DESC90_RATE48M; break; case MGN_54M: ret = DESC90_RATE54M; break; // HT rate since here case MGN_MCS0: ret = DESC90_RATEMCS0; break; case MGN_MCS1: ret = DESC90_RATEMCS1; break; case MGN_MCS2: ret = DESC90_RATEMCS2; break; case MGN_MCS3: ret = DESC90_RATEMCS3; break; case MGN_MCS4: ret = DESC90_RATEMCS4; break; case MGN_MCS5: ret = DESC90_RATEMCS5; break; case MGN_MCS6: ret = DESC90_RATEMCS6; break; case MGN_MCS7: ret = DESC90_RATEMCS7; break; case MGN_MCS8: ret = DESC90_RATEMCS8; break; case MGN_MCS9: ret = DESC90_RATEMCS9; break; case MGN_MCS10: ret = DESC90_RATEMCS10; break; case MGN_MCS11: ret = DESC90_RATEMCS11; break; case MGN_MCS12: ret = DESC90_RATEMCS12; break; case MGN_MCS13: ret = DESC90_RATEMCS13; break; case MGN_MCS14: ret = DESC90_RATEMCS14; break; case MGN_MCS15: ret = DESC90_RATEMCS15; break; case (0x80|0x20): ret = DESC90_RATEMCS32; break; default: break; } return ret; } static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc) { u8 tmp_Short; tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0); if(TxHT==1 && TxRate != DESC90_RATEMCS15) tmp_Short = 0; return tmp_Short; } /* * The tx procedure is just as following, * skb->cb will contain all the following information, * priority, morefrag, rate, &dev. */ static short rtl8192_tx(struct r8192_priv *priv, struct sk_buff* skb) { struct rtl8192_tx_ring *ring; unsigned long flags; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); tx_desc_819x_pci *pdesc = NULL; TX_FWINFO_8190PCI *pTxFwInfo = NULL; dma_addr_t mapping; bool multi_addr = false, broad_addr = false, uni_addr = false; u8 *pda_addr = NULL; int idx; if (priv->bdisable_nic) { RT_TRACE(COMP_ERR, "Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n", skb->len, tcb_desc->queue_index); return skb->len; } #ifdef ENABLE_LPS priv->ieee80211->bAwakePktSent = true; #endif mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); /* collect the tx packets statitcs */ pda_addr = ((u8 *)skb->data) + sizeof(TX_FWINFO_8190PCI); if (is_multicast_ether_addr(pda_addr)) multi_addr = true; else if (is_broadcast_ether_addr(pda_addr)) broad_addr = true; else uni_addr = true; if (uni_addr) priv->stats.txbytesunicast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI); /* fill tx firmware */ pTxFwInfo = (PTX_FWINFO_8190PCI)skb->data; memset(pTxFwInfo, 0, sizeof(TX_FWINFO_8190PCI)); pTxFwInfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0; pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)tcb_desc->data_rate); pTxFwInfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur; pTxFwInfo->Short = QueryIsShort(pTxFwInfo->TxHT, pTxFwInfo->TxRate, tcb_desc); /* Aggregation related */ if (tcb_desc->bAMPDUEnable) { pTxFwInfo->AllowAggregation = 1; pTxFwInfo->RxMF = tcb_desc->ampdu_factor; pTxFwInfo->RxAMD = tcb_desc->ampdu_density; } else { pTxFwInfo->AllowAggregation = 0; pTxFwInfo->RxMF = 0; pTxFwInfo->RxAMD = 0; } /* Protection mode related */ pTxFwInfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0; pTxFwInfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0; pTxFwInfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0; pTxFwInfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0; pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate); pTxFwInfo->RtsBandwidth = 0; pTxFwInfo->RtsSubcarrier = tcb_desc->RTSSC; pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) : (tcb_desc->bRTSUseShortGI? 1 : 0); /* Set Bandwidth and sub-channel settings. */ if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) { if (tcb_desc->bPacketBW) { pTxFwInfo->TxBandwidth = 1; /* use duplicated mode */ pTxFwInfo->TxSubCarrier = 0; } else { pTxFwInfo->TxBandwidth = 0; pTxFwInfo->TxSubCarrier = priv->nCur40MhzPrimeSC; } } else { pTxFwInfo->TxBandwidth = 0; pTxFwInfo->TxSubCarrier = 0; } spin_lock_irqsave(&priv->irq_th_lock, flags); ring = &priv->tx_ring[tcb_desc->queue_index]; if (tcb_desc->queue_index != BEACON_QUEUE) idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; else idx = 0; pdesc = &ring->desc[idx]; if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) { RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d,idx = %d,%x\n", tcb_desc->queue_index, ring->idx, idx, skb->len); spin_unlock_irqrestore(&priv->irq_th_lock, flags); return skb->len; } /* fill tx descriptor */ memset(pdesc, 0, 12); /*DWORD 0*/ pdesc->LINIP = 0; pdesc->CmdInit = 1; pdesc->Offset = sizeof(TX_FWINFO_8190PCI) + 8; /* We must add 8!! */ pdesc->PktSize = (u16)skb->len-sizeof(TX_FWINFO_8190PCI); /*DWORD 1*/ pdesc->SecCAMID = 0; pdesc->RATid = tcb_desc->RATRIndex; pdesc->NoEnc = 1; pdesc->SecType = 0x0; if (tcb_desc->bHwSec) { switch (priv->ieee80211->pairwise_key_type) { case KEY_TYPE_WEP40: case KEY_TYPE_WEP104: pdesc->SecType = 0x1; pdesc->NoEnc = 0; break; case KEY_TYPE_TKIP: pdesc->SecType = 0x2; pdesc->NoEnc = 0; break; case KEY_TYPE_CCMP: pdesc->SecType = 0x3; pdesc->NoEnc = 0; break; case KEY_TYPE_NA: pdesc->SecType = 0x0; pdesc->NoEnc = 1; break; } } /* Set Packet ID */ pdesc->PktId = 0x0; pdesc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index); pdesc->TxFWInfoSize = sizeof(TX_FWINFO_8190PCI); pdesc->DISFB = tcb_desc->bTxDisableRateFallBack; pdesc->USERATE = tcb_desc->bTxUseDriverAssingedRate; pdesc->FirstSeg = 1; pdesc->LastSeg = 1; pdesc->TxBufferSize = skb->len; pdesc->TxBuffAddr = cpu_to_le32(mapping); __skb_queue_tail(&ring->queue, skb); pdesc->OWN = 1; spin_unlock_irqrestore(&priv->irq_th_lock, flags); priv->ieee80211->dev->trans_start = jiffies; write_nic_word(priv, TPPoll, 0x01<<tcb_desc->queue_index); return 0; } static short rtl8192_alloc_rx_desc_ring(struct r8192_priv *priv) { rx_desc_819x_pci *entry = NULL; int i; priv->rx_ring = pci_alloc_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount, &priv->rx_ring_dma); if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) { RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n"); return -ENOMEM; } memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * priv->rxringcount); priv->rx_idx = 0; for (i = 0; i < priv->rxringcount; i++) { struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize); dma_addr_t *mapping; entry = &priv->rx_ring[i]; if (!skb) return 0; priv->rx_buf[i] = skb; mapping = (dma_addr_t *)skb->cb; *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); entry->BufferAddress = cpu_to_le32(*mapping); entry->Length = priv->rxbuffersize; entry->OWN = 1; } entry->EOR = 1; return 0; } static int rtl8192_alloc_tx_desc_ring(struct r8192_priv *priv, unsigned int prio, unsigned int entries) { tx_desc_819x_pci *ring; dma_addr_t dma; int i; ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma); if (!ring || (unsigned long)ring & 0xFF) { RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio); return -ENOMEM; } memset(ring, 0, sizeof(*ring)*entries); priv->tx_ring[prio].desc = ring; priv->tx_ring[prio].dma = dma; priv->tx_ring[prio].idx = 0; priv->tx_ring[prio].entries = entries; skb_queue_head_init(&priv->tx_ring[prio].queue); for (i = 0; i < entries; i++) ring[i].NextDescAddress = cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring)); return 0; } static short rtl8192_pci_initdescring(struct r8192_priv *priv) { u32 ret; int i; ret = rtl8192_alloc_rx_desc_ring(priv); if (ret) return ret; /* general process for other queue */ for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { ret = rtl8192_alloc_tx_desc_ring(priv, i, priv->txringcount); if (ret) goto err_free_rings; } return 0; err_free_rings: rtl8192_free_rx_ring(priv); for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) if (priv->tx_ring[i].desc) rtl8192_free_tx_ring(priv, i); return 1; } static void rtl8192_pci_resetdescring(struct r8192_priv *priv) { int i; /* force the rx_idx to the first one */ if(priv->rx_ring) { rx_desc_819x_pci *entry = NULL; for (i = 0; i < priv->rxringcount; i++) { entry = &priv->rx_ring[i]; entry->OWN = 1; } priv->rx_idx = 0; } /* after reset, release previous pending packet, and force the * tx idx to the first one */ for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { if (priv->tx_ring[i].desc) { struct rtl8192_tx_ring *ring = &priv->tx_ring[i]; while (skb_queue_len(&ring->queue)) { tx_desc_819x_pci *entry = &ring->desc[ring->idx]; struct sk_buff *skb = __skb_dequeue(&ring->queue); pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), skb->len, PCI_DMA_TODEVICE); kfree_skb(skb); ring->idx = (ring->idx + 1) % ring->entries; } ring->idx = 0; } } } static void rtl8192_link_change(struct ieee80211_device *ieee) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); if (ieee->state == IEEE80211_LINKED) { rtl8192_net_update(priv); rtl8192_update_ratr_table(priv); //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) EnableHWSecurityConfig8192(priv); } else { write_nic_byte(priv, 0x173, 0); } rtl8192_update_msr(priv); // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have // // To set CBSSID bit when link with any AP or STA. if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) { u32 reg = 0; reg = read_nic_dword(priv, RCR); if (priv->ieee80211->state == IEEE80211_LINKED) priv->ReceiveConfig = reg |= RCR_CBSSID; else priv->ReceiveConfig = reg &= ~RCR_CBSSID; write_nic_dword(priv, RCR, reg); } } static const struct ieee80211_qos_parameters def_qos_parameters = { {3,3,3,3},/* cw_min */ {7,7,7,7},/* cw_max */ {2,2,2,2},/* aifs */ {0,0,0,0},/* flags */ {0,0,0,0} /* tx_op_limit */ }; static void rtl8192_update_beacon(struct work_struct * work) { struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); struct ieee80211_device* ieee = priv->ieee80211; struct ieee80211_network* net = &ieee->current_network; if (ieee->pHTInfo->bCurrentHTSupport) HTUpdateSelfAndPeerSetting(ieee, net); ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime; rtl8192_update_cap(priv, net->capability); } /* * background support to run QoS activate functionality */ static const int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO}; static void rtl8192_qos_activate(struct work_struct * work) { struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate); struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters; u8 mode = priv->ieee80211->current_network.mode; u8 u1bAIFS; u32 u4bAcParam; int i; mutex_lock(&priv->mutex); if(priv->ieee80211->state != IEEE80211_LINKED) goto success; RT_TRACE(COMP_QOS,"qos active process with associate response received\n"); /* It better set slot time at first */ /* For we just support b/g mode at present, let the slot time at 9/20 selection */ /* update the ac parameter to related registers */ for(i = 0; i < QOS_QUEUE_NUM; i++) { //Mode G/A: slotTimeTimer = 9; Mode B: 20 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime; u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)| (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)| (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)| ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET)); write_nic_dword(priv, WDCAPARA_ADD[i], u4bAcParam); } success: mutex_unlock(&priv->mutex); } static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv, int active_network, struct ieee80211_network *network) { int ret = 0; u32 size = sizeof(struct ieee80211_qos_parameters); if(priv->ieee80211->state !=IEEE80211_LINKED) return ret; if ((priv->ieee80211->iw_mode != IW_MODE_INFRA)) return ret; if (network->flags & NETWORK_HAS_QOS_MASK) { if (active_network && (network->flags & NETWORK_HAS_QOS_PARAMETERS)) network->qos_data.active = network->qos_data.supported; if ((network->qos_data.active == 1) && (active_network == 1) && (network->flags & NETWORK_HAS_QOS_PARAMETERS) && (network->qos_data.old_param_count != network->qos_data.param_count)) { network->qos_data.old_param_count = network->qos_data.param_count; queue_work(priv->priv_wq, &priv->qos_activate); RT_TRACE (COMP_QOS, "QoS parameters change call " "qos_activate\n"); } } else { memcpy(&priv->ieee80211->current_network.qos_data.parameters, &def_qos_parameters, size); if ((network->qos_data.active == 1) && (active_network == 1)) { queue_work(priv->priv_wq, &priv->qos_activate); RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate\n"); } network->qos_data.active = 0; network->qos_data.supported = 0; } return 0; } /* handle manage frame frame beacon and probe response */ static int rtl8192_handle_beacon(struct ieee80211_device *ieee, struct ieee80211_beacon * beacon, struct ieee80211_network * network) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); rtl8192_qos_handle_probe_response(priv,1,network); queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0); return 0; } /* * handling the beaconing responses. if we get different QoS setting * off the network from the associated setting, adjust the QoS setting */ static int rtl8192_qos_association_resp(struct r8192_priv *priv, struct ieee80211_network *network) { int ret = 0; unsigned long flags; u32 size = sizeof(struct ieee80211_qos_parameters); int set_qos_param = 0; if ((priv == NULL) || (network == NULL)) return ret; if (priv->ieee80211->state != IEEE80211_LINKED) return ret; if ((priv->ieee80211->iw_mode != IW_MODE_INFRA)) return ret; spin_lock_irqsave(&priv->ieee80211->lock, flags); if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { memcpy(&priv->ieee80211->current_network.qos_data.parameters, &network->qos_data.parameters, sizeof(struct ieee80211_qos_parameters)); priv->ieee80211->current_network.qos_data.active = 1; set_qos_param = 1; /* update qos parameter for current network */ priv->ieee80211->current_network.qos_data.old_param_count = priv->ieee80211->current_network.qos_data.param_count; priv->ieee80211->current_network.qos_data.param_count = network->qos_data.param_count; } else { memcpy(&priv->ieee80211->current_network.qos_data.parameters, &def_qos_parameters, size); priv->ieee80211->current_network.qos_data.active = 0; priv->ieee80211->current_network.qos_data.supported = 0; set_qos_param = 1; } spin_unlock_irqrestore(&priv->ieee80211->lock, flags); RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __FUNCTION__, network->flags, priv->ieee80211->current_network.qos_data.active); if (set_qos_param == 1) queue_work(priv->priv_wq, &priv->qos_activate); return ret; } static int rtl8192_handle_assoc_response(struct ieee80211_device *ieee, struct ieee80211_assoc_response_frame *resp, struct ieee80211_network *network) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); rtl8192_qos_association_resp(priv, network); return 0; } /* updateRATRTabel for MCS only. Basic rate is not implemented. */ static void rtl8192_update_ratr_table(struct r8192_priv* priv) { struct ieee80211_device* ieee = priv->ieee80211; u8* pMcsRate = ieee->dot11HTOperationalRateSet; u32 ratr_value = 0; u8 rate_index = 0; rtl8192_config_rate(priv, (u16*)(&ratr_value)); ratr_value |= (*(u16*)(pMcsRate)) << 12; switch (ieee->mode) { case IEEE_A: ratr_value &= 0x00000FF0; break; case IEEE_B: ratr_value &= 0x0000000F; break; case IEEE_G: ratr_value &= 0x00000FF7; break; case IEEE_N_24G: case IEEE_N_5G: if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC ratr_value &= 0x0007F007; else{ if (priv->rf_type == RF_1T2R) ratr_value &= 0x000FF007; else ratr_value &= 0x0F81F007; } break; default: break; } ratr_value &= 0x0FFFFFFF; if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){ ratr_value |= 0x80000000; }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){ ratr_value |= 0x80000000; } write_nic_dword(priv, RATR0+rate_index*4, ratr_value); write_nic_byte(priv, UFWP, 1); } static bool GetNmodeSupportBySecCfg8190Pci(struct ieee80211_device *ieee) { return !(ieee->rtllib_ap_sec_type && (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP))); } static void rtl8192_refresh_supportrate(struct r8192_priv* priv) { struct ieee80211_device* ieee = priv->ieee80211; //we donot consider set support rate for ABG mode, only HT MCS rate is set here. if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G) { memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16); } else memset(ieee->Regdot11HTOperationalRateSet, 0, 16); } static u8 rtl8192_getSupportedWireleeMode(void) { return (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B); } static void rtl8192_SetWirelessMode(struct ieee80211_device *ieee, u8 wireless_mode) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); u8 bSupportMode = rtl8192_getSupportedWireleeMode(); if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0)) { if(bSupportMode & WIRELESS_MODE_N_24G) { wireless_mode = WIRELESS_MODE_N_24G; } else if(bSupportMode & WIRELESS_MODE_N_5G) { wireless_mode = WIRELESS_MODE_N_5G; } else if((bSupportMode & WIRELESS_MODE_A)) { wireless_mode = WIRELESS_MODE_A; } else if((bSupportMode & WIRELESS_MODE_G)) { wireless_mode = WIRELESS_MODE_G; } else if((bSupportMode & WIRELESS_MODE_B)) { wireless_mode = WIRELESS_MODE_B; } else{ RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode); wireless_mode = WIRELESS_MODE_B; } } priv->ieee80211->mode = wireless_mode; if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G)) priv->ieee80211->pHTInfo->bEnableHT = 1; else priv->ieee80211->pHTInfo->bEnableHT = 0; RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode); rtl8192_refresh_supportrate(priv); } static bool GetHalfNmodeSupportByAPs819xPci(struct ieee80211_device* ieee) { return ieee->bHalfWirelessN24GMode; } static short rtl8192_is_tx_queue_empty(struct ieee80211_device *ieee) { int i=0; struct r8192_priv *priv = ieee80211_priv(ieee->dev); for (i=0; i<=MGNT_QUEUE; i++) { if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) ) continue; if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){ printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue)); return 0; } } return 1; } static void rtl8192_hw_sleep_down(struct r8192_priv *priv) { MgntActSet_RF_State(priv, eRfSleep, RF_CHANGE_BY_PS); } static void rtl8192_hw_wakeup(struct ieee80211_device *ieee) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); MgntActSet_RF_State(priv, eRfOn, RF_CHANGE_BY_PS); } static void rtl8192_hw_wakeup_wq (struct work_struct *work) { struct delayed_work *dwork = container_of(work,struct delayed_work,work); struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq); rtl8192_hw_wakeup(ieee); } #define MIN_SLEEP_TIME 50 #define MAX_SLEEP_TIME 10000 static void rtl8192_hw_to_sleep(struct ieee80211_device *ieee, u32 th, u32 tl) { struct r8192_priv *priv = ieee80211_priv(ieee->dev); u32 tmp; u32 rb = jiffies; // Writing HW register with 0 equals to disable // the timer, that is not really what we want // tl -= MSECS(8+16+7); // If the interval in witch we are requested to sleep is too // short then give up and remain awake // when we sleep after send null frame, the timer will be too short to sleep. // if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME)) ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) { printk("too short to sleep::%x, %x, %lx\n",tl, rb, MSECS(MIN_SLEEP_TIME)); return; } if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))|| ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))|| ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) { printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME)); return; } tmp = (tl>rb)?(tl-rb):(rb-tl); queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq,tmp); rtl8192_hw_sleep_down(priv); } static void rtl8192_init_priv_variable(struct r8192_priv *priv) { u8 i; PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; // Default Halt the NIC if RF is OFF. pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC; pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_CLK_REQ; pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM; pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM; pPSC->bLeisurePs = true; priv->ieee80211->RegMaxLPSAwakeIntvl = 5; priv->bHwRadioOff = false; priv->being_init_adapter = false; priv->txringcount = 64;//32; priv->rxbuffersize = 9100;//2048;//1024; priv->rxringcount = MAX_RX_COUNT;//64; priv->chan = 1; //set to channel 1 priv->RegWirelessMode = WIRELESS_MODE_AUTO; priv->RegChannelPlan = 0xf; priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO priv->ieee80211->iw_mode = IW_MODE_INFRA; priv->ieee80211->ieee_up=0; priv->retry_rts = DEFAULT_RETRY_RTS; priv->retry_data = DEFAULT_RETRY_DATA; priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD; priv->ieee80211->rate = 110; //11 mbps priv->ieee80211->short_slot = 1; priv->promisc = (priv->ieee80211->dev->flags & IFF_PROMISC) ? 1:0; priv->bcck_in_ch14 = false; priv->CCKPresentAttentuation = 0; priv->rfa_txpowertrackingindex = 0; priv->rfc_txpowertrackingindex = 0; priv->CckPwEnl = 6; //added by amy for silent reset priv->ResetProgress = RESET_TYPE_NORESET; priv->bForcedSilentReset = 0; priv->bDisableNormalResetCheck = false; priv->force_reset = false; //added by amy for power save priv->RfOffReason = 0; priv->bHwRfOffAction = 0; priv->PowerSaveControl.bInactivePs = true; priv->PowerSaveControl.bIPSModeBackup = false; priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL; priv->ieee80211->iw_mode = IW_MODE_INFRA; priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN | IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ | IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;/* | IEEE_SOFTMAC_BEACONS;*///added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE; priv->ieee80211->active_scan = 1; priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION; priv->ieee80211->host_encrypt = 1; priv->ieee80211->host_decrypt = 1; priv->ieee80211->start_send_beacons = rtl8192_start_beacon; priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon; priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit; priv->ieee80211->set_chan = rtl8192_set_chan; priv->ieee80211->link_change = rtl8192_link_change; priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit; priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop; priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume; priv->ieee80211->init_wmmparam_flag = 0; priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD; priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc; priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI); priv->ieee80211->qos_support = 1; priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode; priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response; priv->ieee80211->handle_beacon = rtl8192_handle_beacon; priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup; priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep; priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty; priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci; priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode; priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci; priv->ieee80211->InitialGainHandler = InitialGain819xPci; #ifdef ENABLE_IPS priv->ieee80211->ieee80211_ips_leave_wq = ieee80211_ips_leave_wq; priv->ieee80211->ieee80211_ips_leave = ieee80211_ips_leave; #endif #ifdef ENABLE_LPS priv->ieee80211->LeisurePSLeave = LeisurePSLeave; #endif priv->ieee80211->SetHwRegHandler = rtl8192e_SetHwReg; priv->ieee80211->rtllib_ap_sec_type = rtl8192e_ap_sec_type; priv->ShortRetryLimit = 0x30; priv->LongRetryLimit = 0x30; priv->ReceiveConfig = RCR_ADD3 | RCR_AMF | RCR_ADF | //accept management/data RCR_AICV | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) | ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT; priv->pFirmware = vzalloc(sizeof(rt_firmware)); /* rx related queue */ skb_queue_head_init(&priv->skb_queue); /* Tx related queue */ for(i = 0; i < MAX_QUEUE_SIZE; i++) { skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]); } for(i = 0; i < MAX_QUEUE_SIZE; i++) { skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]); } priv->rf_set_chan = rtl8192_phy_SwChnl; } static void rtl8192_init_priv_lock(struct r8192_priv* priv) { spin_lock_init(&priv->irq_th_lock); spin_lock_init(&priv->rf_ps_lock); sema_init(&priv->wx_sem,1); sema_init(&priv->rf_sem,1); mutex_init(&priv->mutex); } /* init tasklet and wait_queue here */ #define DRV_NAME "wlan0" static void rtl8192_init_priv_task(struct r8192_priv *priv) { priv->priv_wq = create_workqueue(DRV_NAME); #ifdef ENABLE_IPS INIT_WORK(&priv->ieee80211->ips_leave_wq, IPSLeave_wq); #endif INIT_WORK(&priv->reset_wq, rtl8192_restart); INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback); INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback); INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback); INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon); INIT_WORK(&priv->qos_activate, rtl8192_qos_activate); INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq, rtl8192_hw_wakeup_wq); tasklet_init(&priv->irq_rx_tasklet, rtl8192_irq_rx_tasklet, (unsigned long) priv); tasklet_init(&priv->irq_tx_tasklet, rtl8192_irq_tx_tasklet, (unsigned long) priv); tasklet_init(&priv->irq_prepare_beacon_tasklet, rtl8192_prepare_beacon, (unsigned long) priv); } static void rtl8192_get_eeprom_size(struct r8192_priv *priv) { u16 curCR = 0; RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__); curCR = read_nic_dword(priv, EPROM_CMD); RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR); //whether need I consider BIT5? priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EPROM_93c56 : EPROM_93c46; RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype); } /* * Adapter->EEPROMAddressSize should be set before this function call. * EEPROM address size can be got through GetEEPROMSize8185() */ static void rtl8192_read_eeprom_info(struct r8192_priv *priv) { struct net_device *dev = priv->ieee80211->dev; u8 tempval; u8 ICVer8192, ICVer8256; u16 i,usValue, IC_Version; u16 EEPROMId; u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01}; RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n"); // TODO: I don't know if we need to apply EF function to EEPROM read function //2 Read EEPROM ID to make sure autoload is success EEPROMId = eprom_read(priv, 0); if( EEPROMId != RTL8190_EEPROM_ID ) { RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID); priv->AutoloadFailFlag=true; } else { priv->AutoloadFailFlag=false; } // // Assign Chip Version ID // // Read IC Version && Channel Plan if(!priv->AutoloadFailFlag) { // VID, PID priv->eeprom_vid = eprom_read(priv, (EEPROM_VID >> 1)); priv->eeprom_did = eprom_read(priv, (EEPROM_DID >> 1)); usValue = eprom_read(priv, (u16)(EEPROM_Customer_ID>>1)) >> 8 ; priv->eeprom_CustomerID = (u8)( usValue & 0xff); usValue = eprom_read(priv, (EEPROM_ICVersion_ChannelPlan>>1)); priv->eeprom_ChannelPlan = usValue&0xff; IC_Version = ((usValue&0xff00)>>8); ICVer8192 = (IC_Version&0xf); //bit0~3; 1:A cut, 2:B cut, 3:C cut... ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut... RT_TRACE(COMP_INIT, "ICVer8192 = 0x%x\n", ICVer8192); RT_TRACE(COMP_INIT, "ICVer8256 = 0x%x\n", ICVer8256); if(ICVer8192 == 0x2) //B-cut { if(ICVer8256 == 0x5) //E-cut priv->card_8192_version= VERSION_8190_BE; } switch(priv->card_8192_version) { case VERSION_8190_BD: case VERSION_8190_BE: break; default: priv->card_8192_version = VERSION_8190_BD; break; } RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", priv->card_8192_version); } else { priv->card_8192_version = VERSION_8190_BD; priv->eeprom_vid = 0; priv->eeprom_did = 0; priv->eeprom_CustomerID = 0; priv->eeprom_ChannelPlan = 0; RT_TRACE(COMP_INIT, "IC Version = 0x%x\n", 0xff); } RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid); RT_TRACE(COMP_INIT, "EEPROM DID = 0x%4x\n", priv->eeprom_did); RT_TRACE(COMP_INIT,"EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID); //2 Read Permanent MAC address if(!priv->AutoloadFailFlag) { for(i = 0; i < 6; i += 2) { usValue = eprom_read(priv, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1)); *(u16*)(&dev->dev_addr[i]) = usValue; } } else { // when auto load failed, the last address byte set to be a random one. // added by david woo.2007/11/7 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6); } RT_TRACE(COMP_INIT, "Permanent Address = %pM\n", dev->dev_addr); //2 TX Power Check EEPROM Fail or not if(priv->card_8192_version > VERSION_8190_BD) { priv->bTXPowerDataReadFromEEPORM = true; } else { priv->bTXPowerDataReadFromEEPORM = false; } // 2007/11/15 MH 8190PCI Default=2T4R, 8192PCIE default=1T2R priv->rf_type = RTL819X_DEFAULT_RF_TYPE; if(priv->card_8192_version > VERSION_8190_BD) { // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate. if(!priv->AutoloadFailFlag) { tempval = (eprom_read(priv, (EEPROM_RFInd_PowerDiff>>1))) & 0xff; priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; // bit[3:0] if (tempval&0x80) //RF-indication, bit[7] priv->rf_type = RF_1T2R; else priv->rf_type = RF_2T4R; } else { priv->EEPROMLegacyHTTxPowerDiff = EEPROM_Default_LegacyHTTxPowerDiff; } RT_TRACE(COMP_INIT, "EEPROMLegacyHTTxPowerDiff = %d\n", priv->EEPROMLegacyHTTxPowerDiff); // Read ThermalMeter from EEPROM if(!priv->AutoloadFailFlag) { priv->EEPROMThermalMeter = (u8)(((eprom_read(priv, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8); } else { priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; } RT_TRACE(COMP_INIT, "ThermalMeter = %d\n", priv->EEPROMThermalMeter); //vivi, for tx power track priv->TSSI_13dBm = priv->EEPROMThermalMeter *100; if(priv->epromtype == EPROM_93c46) { // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM if(!priv->AutoloadFailFlag) { usValue = eprom_read(priv, (EEPROM_TxPwDiff_CrystalCap>>1)); priv->EEPROMAntPwDiff = (usValue&0x0fff); priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12); } else { priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff; priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap; } RT_TRACE(COMP_INIT, "EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff); RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap); // // Get per-channel Tx Power Level // for(i=0; i<14; i+=2) { if(!priv->AutoloadFailFlag) { usValue = eprom_read(priv, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) ); } else { usValue = EEPROM_Default_TxPower; } *((u16*)(&priv->EEPROMTxPowerLevelCCK[i])) = usValue; RT_TRACE(COMP_INIT,"CCK Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK[i]); RT_TRACE(COMP_INIT, "CCK Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelCCK[i+1]); } for(i=0; i<14; i+=2) { if(!priv->AutoloadFailFlag) { usValue = eprom_read(priv, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) ); } else { usValue = EEPROM_Default_TxPower; } *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[i])) = usValue; RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelOFDM24G[i]); RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelOFDM24G[i+1]); } } // // Update HAL variables. // if(priv->epromtype == EPROM_93c46) { for(i=0; i<14; i++) { priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK[i]; priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[i]; } priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff; // Antenna B gain offset to antenna A, bit0~3 priv->AntennaTxPwDiff[0] = (priv->EEPROMAntPwDiff & 0xf); // Antenna C gain offset to antenna A, bit4~7 priv->AntennaTxPwDiff[1] = ((priv->EEPROMAntPwDiff & 0xf0)>>4); // Antenna D gain offset to antenna A, bit8~11 priv->AntennaTxPwDiff[2] = ((priv->EEPROMAntPwDiff & 0xf00)>>8); // CrystalCap, bit12~15 priv->CrystalCap = priv->EEPROMCrystalCap; // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf); priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4); } else if(priv->epromtype == EPROM_93c56) { for(i=0; i<3; i++) // channel 1~3 use the same Tx Power Level. { priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[0]; priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[0]; priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[0]; priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[0]; } for(i=3; i<9; i++) // channel 4~9 use the same Tx Power Level { priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[1]; priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[1]; priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[1]; priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[1]; } for(i=9; i<14; i++) // channel 10~14 use the same Tx Power Level { priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[2]; priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[2]; priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[2]; priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[2]; } for(i=0; i<14; i++) RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_A[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_A[i]); for(i=0; i<14; i++) RT_TRACE(COMP_INIT,"priv->TxPowerLevelOFDM24G_A[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_A[i]); for(i=0; i<14; i++) RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_C[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_C[i]); for(i=0; i<14; i++) RT_TRACE(COMP_INIT, "priv->TxPowerLevelOFDM24G_C[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_C[i]); priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff; priv->AntennaTxPwDiff[0] = 0; priv->AntennaTxPwDiff[1] = 0; priv->AntennaTxPwDiff[2] = 0; priv->CrystalCap = priv->EEPROMCrystalCap; // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf); priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4); } } if(priv->rf_type == RF_1T2R) { RT_TRACE(COMP_INIT, "1T2R config\n"); } else if (priv->rf_type == RF_2T4R) { RT_TRACE(COMP_INIT, "2T4R config\n"); } // 2008/01/16 MH We can only know RF type in the function. So we have to init // DIG RATR table again. init_rate_adaptive(priv); //1 Make a copy for following variables and we can change them if we want if(priv->RegChannelPlan == 0xf) { priv->ChannelPlan = priv->eeprom_ChannelPlan; } else { priv->ChannelPlan = priv->RegChannelPlan; } // // Used PID and DID to Set CustomerID // if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304 ) { priv->CustomerID = RT_CID_DLINK; } switch(priv->eeprom_CustomerID) { case EEPROM_CID_DEFAULT: priv->CustomerID = RT_CID_DEFAULT; break; case EEPROM_CID_CAMEO: priv->CustomerID = RT_CID_819x_CAMEO; break; case EEPROM_CID_RUNTOP: priv->CustomerID = RT_CID_819x_RUNTOP; break; case EEPROM_CID_NetCore: priv->CustomerID = RT_CID_819x_Netcore; break; case EEPROM_CID_TOSHIBA: // Merge by Jacken, 2008/01/31 priv->CustomerID = RT_CID_TOSHIBA; if(priv->eeprom_ChannelPlan&0x80) priv->ChannelPlan = priv->eeprom_ChannelPlan&0x7f; else priv->ChannelPlan = 0x0; RT_TRACE(COMP_INIT, "Toshiba ChannelPlan = 0x%x\n", priv->ChannelPlan); break; case EEPROM_CID_Nettronix: priv->CustomerID = RT_CID_Nettronix; break; case EEPROM_CID_Pronet: priv->CustomerID = RT_CID_PRONET; break; case EEPROM_CID_DLINK: priv->CustomerID = RT_CID_DLINK; break; case EEPROM_CID_WHQL: break; default: // value from RegCustomerID break; } //Avoid the channel plan array overflow, by Bruce, 2007-08-27. if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1) priv->ChannelPlan = 0; //FCC if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304) priv->ieee80211->bSupportRemoteWakeUp = true; else priv->ieee80211->bSupportRemoteWakeUp = false; RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan); RT_TRACE(COMP_INIT, "ChannelPlan = %d\n", priv->ChannelPlan); RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n"); } static short rtl8192_get_channel_map(struct r8192_priv *priv) { #ifdef ENABLE_DOT11D if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){ printk("rtl8180_init:Error channel plan! Set to default.\n"); priv->ChannelPlan= 0; } RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan); rtl819x_set_channel_map(priv->ChannelPlan, priv); #else int ch,i; //Set Default Channel Plan if(!channels){ DMESG("No channels, aborting"); return -1; } ch=channels; priv->ChannelPlan= 0;//hikaru // set channels 1..14 allowed in given locale for (i=1; i<=14; i++) { (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01); ch >>= 1; } #endif return 0; } static short rtl8192_init(struct r8192_priv *priv) { struct net_device *dev = priv->ieee80211->dev; memset(&(priv->stats),0,sizeof(struct Stats)); rtl8192_init_priv_variable(priv); rtl8192_init_priv_lock(priv); rtl8192_init_priv_task(priv); rtl8192_get_eeprom_size(priv); rtl8192_read_eeprom_info(priv); rtl8192_get_channel_map(priv); init_hal_dm(priv); init_timer(&priv->watch_dog_timer); priv->watch_dog_timer.data = (unsigned long)priv; priv->watch_dog_timer.function = watch_dog_timer_callback; if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED, dev->name, priv)) { printk("Error allocating IRQ %d",dev->irq); return -1; }else{ priv->irq=dev->irq; printk("IRQ %d",dev->irq); } if (rtl8192_pci_initdescring(priv) != 0){ printk("Endopoints initialization failed"); return -1; } return 0; } /* * Actually only set RRSR, RATR and BW_OPMODE registers * not to do all the hw config as its name says * This part need to modified according to the rate set we filtered */ static void rtl8192_hwconfig(struct r8192_priv *priv) { u32 regRATR = 0, regRRSR = 0; u8 regBwOpMode = 0, regTmp = 0; // Set RRSR, RATR, and BW_OPMODE registers // switch (priv->ieee80211->mode) { case WIRELESS_MODE_B: regBwOpMode = BW_OPMODE_20MHZ; regRATR = RATE_ALL_CCK; regRRSR = RATE_ALL_CCK; break; case WIRELESS_MODE_A: regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ; regRATR = RATE_ALL_OFDM_AG; regRRSR = RATE_ALL_OFDM_AG; break; case WIRELESS_MODE_G: regBwOpMode = BW_OPMODE_20MHZ; regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; break; case WIRELESS_MODE_AUTO: case WIRELESS_MODE_N_24G: // It support CCK rate by default. // CCK rate will be filtered out only when associated AP does not support it. regBwOpMode = BW_OPMODE_20MHZ; regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS; regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; break; case WIRELESS_MODE_N_5G: regBwOpMode = BW_OPMODE_5G; regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS; regRRSR = RATE_ALL_OFDM_AG; break; } write_nic_byte(priv, BW_OPMODE, regBwOpMode); { u32 ratr_value = 0; ratr_value = regRATR; if (priv->rf_type == RF_1T2R) { ratr_value &= ~(RATE_ALL_OFDM_2SS); } write_nic_dword(priv, RATR0, ratr_value); write_nic_byte(priv, UFWP, 1); } regTmp = read_nic_byte(priv, 0x313); regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff); write_nic_dword(priv, RRSR, regRRSR); // // Set Retry Limit here // write_nic_word(priv, RETRY_LIMIT, priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT); // Set Contention Window here // Set Tx AGC // Set Tx Antenna including Feedback control // Set Auto Rate fallback control } static RT_STATUS rtl8192_adapter_start(struct r8192_priv *priv) { struct net_device *dev = priv->ieee80211->dev; u32 ulRegRead; RT_STATUS rtStatus = RT_STATUS_SUCCESS; u8 tmpvalue; u8 ICVersion,SwitchingRegulatorOutput; bool bfirmwareok = true; u32 tmpRegA, tmpRegC, TempCCk; int i =0; RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__); priv->being_init_adapter = true; rtl8192_pci_resetdescring(priv); // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W. priv->Rf_Mode = RF_OP_By_SW_3wire; //dPLL on if(priv->ResetProgress == RESET_TYPE_NORESET) { write_nic_byte(priv, ANAPAR, 0x37); // Accordign to designer's explain, LBUS active will never > 10ms. We delay 10ms // Joseph increae the time to prevent firmware download fail mdelay(500); } //PlatformSleepUs(10000); // For any kind of InitializeAdapter process, we shall use system now!! priv->pFirmware->firmware_status = FW_STATUS_0_INIT; // //3 //Config CPUReset Register //3// //3 Firmware Reset Or Not ulRegRead = read_nic_dword(priv, CPU_GEN); if(priv->pFirmware->firmware_status == FW_STATUS_0_INIT) { //called from MPInitialized. do nothing ulRegRead |= CPU_GEN_SYSTEM_RESET; }else if(priv->pFirmware->firmware_status == FW_STATUS_5_READY) ulRegRead |= CPU_GEN_FIRMWARE_RESET; // Called from MPReset else RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status); write_nic_dword(priv, CPU_GEN, ulRegRead); //3// //3 //Fix the issue of E-cut high temperature issue //3// // TODO: E cut only ICVersion = read_nic_byte(priv, IC_VERRSION); if(ICVersion >= 0x4) //E-cut only { // HW SD suggest that we should not wirte this register too often, so driver // should readback this register. This register will be modified only when // power on reset SwitchingRegulatorOutput = read_nic_byte(priv, SWREGULATOR); if(SwitchingRegulatorOutput != 0xb8) { write_nic_byte(priv, SWREGULATOR, 0xa8); mdelay(1); write_nic_byte(priv, SWREGULATOR, 0xb8); } } //3// //3// Initialize BB before MAC //3// RT_TRACE(COMP_INIT, "BB Config Start!\n"); rtStatus = rtl8192_BBConfig(priv); if(rtStatus != RT_STATUS_SUCCESS) { RT_TRACE(COMP_ERR, "BB Config failed\n"); return rtStatus; } RT_TRACE(COMP_INIT,"BB Config Finished!\n"); //3//Set Loopback mode or Normal mode //3// //2006.12.13 by emily. Note!We should not merge these two CPU_GEN register writings // because setting of System_Reset bit reset MAC to default transmission mode. //Loopback mode or not priv->LoopbackMode = RTL819X_NO_LOOPBACK; if(priv->ResetProgress == RESET_TYPE_NORESET) { ulRegRead = read_nic_dword(priv, CPU_GEN); if(priv->LoopbackMode == RTL819X_NO_LOOPBACK) { ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET); } else if (priv->LoopbackMode == RTL819X_MAC_LOOPBACK ) { ulRegRead |= CPU_CCK_LOOPBACK; } else { RT_TRACE(COMP_ERR,"Serious error: wrong loopback mode setting\n"); } //2008.06.03, for WOL //ulRegRead &= (~(CPU_GEN_GPIO_UART)); write_nic_dword(priv, CPU_GEN, ulRegRead); // 2006.11.29. After reset cpu, we sholud wait for a second, otherwise, it may fail to write registers. Emily udelay(500); } //3Set Hardware(Do nothing now) rtl8192_hwconfig(priv); //2======================================================= // Common Setting for all of the FPGA platform. (part 1) //2======================================================= // If there is changes, please make sure it applies to all of the FPGA version //3 Turn on Tx/Rx write_nic_byte(priv, CMDR, CR_RE|CR_TE); //2Set Tx dma burst write_nic_byte(priv, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) | (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) )); //set IDR0 here write_nic_dword(priv, MAC0, ((u32*)dev->dev_addr)[0]); write_nic_word(priv, MAC4, ((u16*)(dev->dev_addr + 4))[0]); //set RCR write_nic_dword(priv, RCR, priv->ReceiveConfig); //3 Initialize Number of Reserved Pages in Firmware Queue write_nic_dword(priv, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT | NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT | NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT | NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT); write_nic_dword(priv, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT); write_nic_dword(priv, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT| NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT); rtl8192_tx_enable(priv); rtl8192_rx_enable(priv); //3Set Response Rate Setting Register // CCK rate is supported by default. // CCK rate will be filtered out only when associated AP does not support it. ulRegRead = (0xFFF00000 & read_nic_dword(priv, RRSR)) | RATE_ALL_OFDM_AG | RATE_ALL_CCK; write_nic_dword(priv, RRSR, ulRegRead); write_nic_dword(priv, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK)); //2Set AckTimeout // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily write_nic_byte(priv, ACK_TIMEOUT, 0x30); if(priv->ResetProgress == RESET_TYPE_NORESET) rtl8192_SetWirelessMode(priv->ieee80211, priv->ieee80211->mode); //----------------------------------------------------------------------------- // Set up security related. 070106, by rcnjko: // 1. Clear all H/W keys. // 2. Enable H/W encryption/decryption. //----------------------------------------------------------------------------- CamResetAllEntry(priv); { u8 SECR_value = 0x0; SECR_value |= SCR_TxEncEnable; SECR_value |= SCR_RxDecEnable; SECR_value |= SCR_NoSKMC; write_nic_byte(priv, SECR, SECR_value); } //3Beacon related write_nic_word(priv, ATIMWND, 2); write_nic_word(priv, BCN_INTERVAL, 100); for (i=0; i<QOS_QUEUE_NUM; i++) write_nic_dword(priv, WDCAPARA_ADD[i], 0x005e4332); // // Switching regulator controller: This is set temporarily. // It's not sure if this can be removed in the future. // PJ advised to leave it by default. // write_nic_byte(priv, 0xbe, 0xc0); //2======================================================= // Set PHY related configuration defined in MAC register bank //2======================================================= rtl8192_phy_configmac(priv); if (priv->card_8192_version > (u8) VERSION_8190_BD) { rtl8192_phy_getTxPower(priv); rtl8192_phy_setTxPower(priv, priv->chan); } //if D or C cut tmpvalue = read_nic_byte(priv, IC_VERRSION); priv->IC_Cut = tmpvalue; RT_TRACE(COMP_INIT, "priv->IC_Cut = 0x%x\n", priv->IC_Cut); if(priv->IC_Cut >= IC_VersionCut_D) { //pHalData->bDcut = TRUE; if(priv->IC_Cut == IC_VersionCut_D) RT_TRACE(COMP_INIT, "D-cut\n"); if(priv->IC_Cut == IC_VersionCut_E) { RT_TRACE(COMP_INIT, "E-cut\n"); // HW SD suggest that we should not wirte this register too often, so driver // should readback this register. This register will be modified only when // power on reset } } else { //pHalData->bDcut = FALSE; RT_TRACE(COMP_INIT, "Before C-cut\n"); } //Firmware download RT_TRACE(COMP_INIT, "Load Firmware!\n"); bfirmwareok = init_firmware(priv); if(bfirmwareok != true) { rtStatus = RT_STATUS_FAILURE; return rtStatus; } RT_TRACE(COMP_INIT, "Load Firmware finished!\n"); //RF config if(priv->ResetProgress == RESET_TYPE_NORESET) { RT_TRACE(COMP_INIT, "RF Config Started!\n"); rtStatus = rtl8192_phy_RFConfig(priv); if(rtStatus != RT_STATUS_SUCCESS) { RT_TRACE(COMP_ERR, "RF Config failed\n"); return rtStatus; } RT_TRACE(COMP_INIT, "RF Config Finished!\n"); } rtl8192_phy_updateInitGain(priv); /*---- Set CCK and OFDM Block "ON"----*/ rtl8192_setBBreg(priv, rFPGA0_RFMOD, bCCKEn, 0x1); rtl8192_setBBreg(priv, rFPGA0_RFMOD, bOFDMEn, 0x1); //Enable Led write_nic_byte(priv, 0x87, 0x0); //2======================================================= // RF Power Save //2======================================================= #ifdef ENABLE_IPS { if(priv->RfOffReason > RF_CHANGE_BY_PS) { // H/W or S/W RF OFF before sleep. RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d)\n", __FUNCTION__,priv->RfOffReason); MgntActSet_RF_State(priv, eRfOff, priv->RfOffReason); } else if(priv->RfOffReason >= RF_CHANGE_BY_IPS) { // H/W or S/W RF OFF before sleep. RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d)\n", __FUNCTION__, priv->RfOffReason); MgntActSet_RF_State(priv, eRfOff, priv->RfOffReason); } else { RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__); priv->eRFPowerState = eRfOn; priv->RfOffReason = 0; } } #endif // We can force firmware to do RF-R/W if(priv->ieee80211->FwRWRF) priv->Rf_Mode = RF_OP_By_FW; else priv->Rf_Mode = RF_OP_By_SW_3wire; if(priv->ResetProgress == RESET_TYPE_NORESET) { dm_initialize_txpower_tracking(priv); if(priv->IC_Cut >= IC_VersionCut_D) { tmpRegA = rtl8192_QueryBBReg(priv, rOFDM0_XATxIQImbalance, bMaskDWord); tmpRegC = rtl8192_QueryBBReg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord); for(i = 0; i<TxBBGainTableLength; i++) { if(tmpRegA == priv->txbbgain_table[i].txbbgain_value) { priv->rfa_txpowertrackingindex= (u8)i; priv->rfa_txpowertrackingindex_real= (u8)i; priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex; break; } } TempCCk = rtl8192_QueryBBReg(priv, rCCK0_TxFilter1, bMaskByte2); for(i=0 ; i<CCKTxBBGainTableLength ; i++) { if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) { priv->CCKPresentAttentuation_20Mdefault =(u8) i; break; } } priv->CCKPresentAttentuation_40Mdefault = 0; priv->CCKPresentAttentuation_difference = 0; priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault; RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex); RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real); RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference); RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation); priv->btxpower_tracking = FALSE;//TEMPLY DISABLE } } rtl8192_irq_enable(priv); priv->being_init_adapter = false; return rtStatus; } static void rtl8192_prepare_beacon(unsigned long arg) { struct r8192_priv *priv = (struct r8192_priv*) arg; struct sk_buff *skb; cb_desc *tcb_desc; skb = ieee80211_get_beacon(priv->ieee80211); tcb_desc = (cb_desc *)(skb->cb + 8); /* prepare misc info for the beacon xmit */ tcb_desc->queue_index = BEACON_QUEUE; /* IBSS does not support HT yet, use 1M defaultly */ tcb_desc->data_rate = 2; tcb_desc->RATRIndex = 7; tcb_desc->bTxDisableRateFallBack = 1; tcb_desc->bTxUseDriverAssingedRate = 1; skb_push(skb, priv->ieee80211->tx_headroom); if(skb){ rtl8192_tx(priv, skb); } } /* * configure registers for beacon tx and enables it via * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might * be used to stop beacon transmission */ static void rtl8192_start_beacon(struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); struct ieee80211_network *net = &priv->ieee80211->current_network; u16 BcnTimeCfg = 0; u16 BcnCW = 6; u16 BcnIFS = 0xf; DMESG("Enabling beacon TX"); rtl8192_irq_disable(priv); //rtl8192_beacon_tx_enable(dev); /* ATIM window */ write_nic_word(priv, ATIMWND, 2); /* Beacon interval (in unit of TU) */ write_nic_word(priv, BCN_INTERVAL, net->beacon_interval); /* * DrvErlyInt (in unit of TU). * (Time to send interrupt to notify driver to c * hange beacon content) * */ write_nic_word(priv, BCN_DRV_EARLY_INT, 10); /* * BcnDMATIM(in unit of us). * Indicates the time before TBTT to perform beacon queue DMA * */ write_nic_word(priv, BCN_DMATIME, 256); /* * Force beacon frame transmission even after receiving * beacon frame from other ad hoc STA * */ write_nic_byte(priv, BCN_ERR_THRESH, 100); /* Set CW and IFS */ BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT; BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; write_nic_word(priv, BCN_TCFG, BcnTimeCfg); /* enable the interrupt for ad-hoc process */ rtl8192_irq_enable(priv); } static bool HalRxCheckStuck8190Pci(struct r8192_priv *priv) { u16 RegRxCounter = read_nic_word(priv, 0x130); bool bStuck = FALSE; RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter); // If rssi is small, we should check rx for long time because of bad rx. // or maybe it will continuous silent reset every 2 seconds. priv->rx_chk_cnt++; if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) { priv->rx_chk_cnt = 0; /* high rssi, check rx stuck right now. */ } else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) && ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) || (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) ) { if(priv->rx_chk_cnt < 2) { return bStuck; } else { priv->rx_chk_cnt = 0; } } else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) || (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) && priv->undecorated_smoothed_pwdb >= VeryLowRSSI) { if(priv->rx_chk_cnt < 4) { return bStuck; } else { priv->rx_chk_cnt = 0; } } else { if(priv->rx_chk_cnt < 8) { return bStuck; } else { priv->rx_chk_cnt = 0; } } if(priv->RxCounter==RegRxCounter) bStuck = TRUE; priv->RxCounter = RegRxCounter; return bStuck; } static RESET_TYPE RxCheckStuck(struct r8192_priv *priv) { if(HalRxCheckStuck8190Pci(priv)) { RT_TRACE(COMP_RESET, "RxStuck Condition\n"); return RESET_TYPE_SILENT; } return RESET_TYPE_NORESET; } static RESET_TYPE rtl819x_check_reset(struct r8192_priv *priv) { RESET_TYPE RxResetType = RESET_TYPE_NORESET; RT_RF_POWER_STATE rfState; rfState = priv->eRFPowerState; if (rfState != eRfOff && (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) { /* * If driver is in the status of firmware download failure, * driver skips RF initialization and RF is in turned off state. * Driver should check whether Rx stuck and do silent reset. And * if driver is in firmware download failure status, driver * should initialize RF in the following silent reset procedure * * Driver should not check RX stuck in IBSS mode because it is * required to set Check BSSID in order to send beacon, however, * if check BSSID is set, STA cannot hear any packet a all. */ RxResetType = RxCheckStuck(priv); } RT_TRACE(COMP_RESET, "%s(): RxResetType is %d\n", __FUNCTION__, RxResetType); return RxResetType; } #ifdef ENABLE_IPS static void InactivePsWorkItemCallback(struct r8192_priv *priv) { PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() --------->\n"); // // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem // is really scheduled. // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing // blocks the IPS procedure of switching RF. // By Bruce, 2007-12-25. // pPSC->bSwRfProcessing = TRUE; RT_TRACE(COMP_RF, "InactivePsWorkItemCallback(): Set RF to %s.\n", pPSC->eInactivePowerState == eRfOff?"OFF":"ON"); MgntActSet_RF_State(priv, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS); // // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20. // pPSC->bSwRfProcessing = FALSE; RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <---------\n"); } #ifdef ENABLE_LPS /* Change current and default preamble mode. */ bool MgntActSet_802_11_PowerSaveMode(struct r8192_priv *priv, u8 rtPsMode) { // Currently, we do not change power save mode on IBSS mode. if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) { return false; } // // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us, // some AP will not response to our mgnt frames with PwrMgt bit set, // e.g. cannot associate the AP. // So I commented out it. 2005.02.16, by rcnjko. // // // Change device's power save mode. // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode ); // Update power save mode configured. //RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode); if(!priv->ps_force) { priv->ieee80211->ps = rtPsMode; } // Awake immediately if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED) { // Notify the AP we awke. rtl8192_hw_wakeup(priv->ieee80211); priv->ieee80211->sta_sleep = 0; spin_lock(&priv->ieee80211->mgmt_tx_lock); printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n"); ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0); spin_unlock(&priv->ieee80211->mgmt_tx_lock); } return true; } /* Enter the leisure power save mode. */ void LeisurePSEnter(struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) && (priv->ieee80211->state == IEEE80211_LINKED)) || (priv->ieee80211->iw_mode == IW_MODE_ADHOC) || (priv->ieee80211->iw_mode == IW_MODE_MASTER)) return; if (pPSC->bLeisurePs) { // Idle for a while if we connect to AP a while ago. if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) // 4 Sec { if(priv->ieee80211->ps == IEEE80211_PS_DISABLED) { MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST); } } else pPSC->LpsIdleCount++; } } /* Leave leisure power save mode. */ void LeisurePSLeave(struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; if (pPSC->bLeisurePs) { if(priv->ieee80211->ps != IEEE80211_PS_DISABLED) { // move to lps_wakecomplete() MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED); } } } #endif /* Enter the inactive power save mode. RF will be off */ void IPSEnter(struct r8192_priv *priv) { PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; RT_RF_POWER_STATE rtState; if (pPSC->bInactivePs) { rtState = priv->eRFPowerState; // // Added by Bruce, 2007-12-25. // Do not enter IPS in the following conditions: // (1) RF is already OFF or Sleep // (2) bSwRfProcessing (indicates the IPS is still under going) // (3) Connectted (only disconnected can trigger IPS) // (4) IBSS (send Beacon) // (5) AP mode (send Beacon) // if (rtState == eRfOn && !pPSC->bSwRfProcessing && (priv->ieee80211->state != IEEE80211_LINKED) ) { RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n"); pPSC->eInactivePowerState = eRfOff; // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem)); InactivePsWorkItemCallback(priv); } } } // // Description: // Leave the inactive power save mode, RF will be on. // 2007.08.17, by shien chang. // void IPSLeave(struct r8192_priv *priv) { PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; RT_RF_POWER_STATE rtState; if (pPSC->bInactivePs) { rtState = priv->eRFPowerState; if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->RfOffReason <= RF_CHANGE_BY_IPS) { RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n"); pPSC->eInactivePowerState = eRfOn; InactivePsWorkItemCallback(priv); } } } void IPSLeave_wq(struct work_struct *work) { struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, ips_leave_wq); struct net_device *dev = ieee->dev; struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); down(&priv->ieee80211->ips_sem); IPSLeave(priv); up(&priv->ieee80211->ips_sem); } void ieee80211_ips_leave_wq(struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); RT_RF_POWER_STATE rtState; rtState = priv->eRFPowerState; if (priv->PowerSaveControl.bInactivePs){ if(rtState == eRfOff){ if(priv->RfOffReason > RF_CHANGE_BY_IPS) { RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__); return; } else{ printk("=========>%s(): IPSLeave\n",__FUNCTION__); queue_work(priv->ieee80211->wq,&priv->ieee80211->ips_leave_wq); } } } } //added by amy 090331 end void ieee80211_ips_leave(struct ieee80211_device *ieee80211) { struct r8192_priv *priv = ieee80211_priv(ieee80211->dev); down(&ieee80211->ips_sem); IPSLeave(priv); up(&ieee80211->ips_sem); } #endif static void rtl819x_update_rxcounts( struct r8192_priv *priv, u32* TotalRxBcnNum, u32* TotalRxDataNum ) { u16 SlotIndex; u8 i; *TotalRxBcnNum = 0; *TotalRxDataNum = 0; SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum); priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod; priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod; for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){ *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i]; *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i]; } } static void rtl819x_watchdog_wqcallback(struct work_struct *work) { struct delayed_work *dwork = container_of(work,struct delayed_work,work); struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq); struct ieee80211_device* ieee = priv->ieee80211; RESET_TYPE ResetType = RESET_TYPE_NORESET; bool bBusyTraffic = false; bool bEnterPS = false; if ((!priv->up) || priv->bHwRadioOff) return; if(!priv->up) return; hal_dm_watchdog(priv); #ifdef ENABLE_IPS if(ieee->actscanning == false){ if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) && (priv->eRFPowerState == eRfOn) && !ieee->is_set_key && (!ieee->proto_stoppping) && !ieee->wx_set_enc){ if (priv->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){ IPSEnter(priv); } } } #endif {//to get busy traffic condition if(ieee->state == IEEE80211_LINKED) { if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 || ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) { bBusyTraffic = true; } #ifdef ENABLE_LPS //added by amy for Leisure PS if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) || (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) ) { bEnterPS= false; } else { bEnterPS= true; } // LeisurePS only work in infra mode. if(bEnterPS) { LeisurePSEnter(priv->ieee80211); } else { LeisurePSLeave(priv->ieee80211); } #endif } else { #ifdef ENABLE_LPS LeisurePSLeave(priv->ieee80211); #endif } ieee->LinkDetectInfo.NumRxOkInPeriod = 0; ieee->LinkDetectInfo.NumTxOkInPeriod = 0; ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic; } //added by amy for AP roaming if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) { u32 TotalRxBcnNum = 0; u32 TotalRxDataNum = 0; rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum); if((TotalRxBcnNum+TotalRxDataNum) == 0) { if (priv->eRFPowerState == eRfOff) RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__); printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__); // Dot11d_Reset(dev); ieee->state = IEEE80211_ASSOCIATING; notify_wx_assoc_event(priv->ieee80211); RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid); ieee->is_roaming = true; ieee->is_set_key = false; ieee->link_change(ieee); queue_work(ieee->wq, &ieee->associate_procedure_wq); } } ieee->LinkDetectInfo.NumRecvBcnInPeriod=0; ieee->LinkDetectInfo.NumRecvDataInPeriod=0; //check if reset the driver if (priv->watchdog_check_reset_cnt++ >= 3 && !ieee->is_roaming && priv->watchdog_last_time != 1) { ResetType = rtl819x_check_reset(priv); priv->watchdog_check_reset_cnt = 3; } if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) { priv->ResetProgress = RESET_TYPE_NORMAL; RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__FUNCTION__); return; } /* disable silent reset temply 2008.9.11*/ if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo { priv->watchdog_last_time = 1; } else priv->watchdog_last_time = 0; priv->force_reset = false; priv->bForcedSilentReset = false; priv->bResetInProgress = false; RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n"); } void watch_dog_timer_callback(unsigned long data) { struct r8192_priv *priv = (struct r8192_priv *) data; queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0); mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME)); } static int _rtl8192_up(struct r8192_priv *priv) { RT_STATUS init_status = RT_STATUS_SUCCESS; struct net_device *dev = priv->ieee80211->dev; priv->up=1; priv->ieee80211->ieee_up=1; priv->bdisable_nic = false; //YJ,add,091111 RT_TRACE(COMP_INIT, "Bringing up iface\n"); init_status = rtl8192_adapter_start(priv); if(init_status != RT_STATUS_SUCCESS) { RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__); return -1; } RT_TRACE(COMP_INIT, "start adapter finished\n"); if (priv->eRFPowerState != eRfOn) MgntActSet_RF_State(priv, eRfOn, priv->RfOffReason); if(priv->ieee80211->state != IEEE80211_LINKED) ieee80211_softmac_start_protocol(priv->ieee80211); ieee80211_reset_queue(priv->ieee80211); watch_dog_timer_callback((unsigned long) priv); if(!netif_queue_stopped(dev)) netif_start_queue(dev); else netif_wake_queue(dev); return 0; } static int rtl8192_open(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); int ret; down(&priv->wx_sem); ret = rtl8192_up(dev); up(&priv->wx_sem); return ret; } int rtl8192_up(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); if (priv->up == 1) return -1; return _rtl8192_up(priv); } static int rtl8192_close(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); int ret; down(&priv->wx_sem); ret = rtl8192_down(dev); up(&priv->wx_sem); return ret; } int rtl8192_down(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); if (priv->up == 0) return -1; #ifdef ENABLE_LPS //LZM for PS-Poll AID issue. 090429 if(priv->ieee80211->state == IEEE80211_LINKED) LeisurePSLeave(priv->ieee80211); #endif priv->up=0; priv->ieee80211->ieee_up = 0; RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__); /* FIXME */ if (!netif_queue_stopped(dev)) netif_stop_queue(dev); rtl8192_irq_disable(priv); rtl8192_cancel_deferred_work(priv); deinit_hal_dm(priv); del_timer_sync(&priv->watch_dog_timer); ieee80211_softmac_stop_protocol(priv->ieee80211,true); rtl8192_halt_adapter(priv, false); memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list)); RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__); return 0; } void rtl8192_commit(struct r8192_priv *priv) { if (priv->up == 0) return ; ieee80211_softmac_stop_protocol(priv->ieee80211,true); rtl8192_irq_disable(priv); rtl8192_halt_adapter(priv, true); _rtl8192_up(priv); } static void rtl8192_restart(struct work_struct *work) { struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq); down(&priv->wx_sem); rtl8192_commit(priv); up(&priv->wx_sem); } static void r8192_set_multicast(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0; } static int r8192_set_mac_adr(struct net_device *dev, void *mac) { struct r8192_priv *priv = ieee80211_priv(dev); struct sockaddr *addr = mac; down(&priv->wx_sem); memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); schedule_work(&priv->reset_wq); up(&priv->wx_sem); return 0; } static void r8192e_set_hw_key(struct r8192_priv *priv, struct ieee_param *ipw) { struct ieee80211_device *ieee = priv->ieee80211; u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; u32 key[4]; if (ipw->u.crypt.set_tx) { if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) ieee->pairwise_key_type = KEY_TYPE_CCMP; else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) ieee->pairwise_key_type = KEY_TYPE_TKIP; else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) { if (ipw->u.crypt.key_len == 13) ieee->pairwise_key_type = KEY_TYPE_WEP104; else if (ipw->u.crypt.key_len == 5) ieee->pairwise_key_type = KEY_TYPE_WEP40; } else ieee->pairwise_key_type = KEY_TYPE_NA; if (ieee->pairwise_key_type) { memcpy(key, ipw->u.crypt.key, 16); EnableHWSecurityConfig8192(priv); /* * We fill both index entry and 4th entry for pairwise * key as in IPW interface, adhoc will only get here, * so we need index entry for its default key serching! */ setKey(priv, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); /* LEAP WEP will never set this. */ if (ieee->auth_mode != 2) setKey(priv, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); } if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport) { write_nic_byte(priv, 0x173, 1); /* fix aes bug */ } } else { memcpy(key, ipw->u.crypt.key, 16); if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) ieee->group_key_type= KEY_TYPE_CCMP; else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) ieee->group_key_type = KEY_TYPE_TKIP; else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) { if (ipw->u.crypt.key_len == 13) ieee->group_key_type = KEY_TYPE_WEP104; else if (ipw->u.crypt.key_len == 5) ieee->group_key_type = KEY_TYPE_WEP40; } else ieee->group_key_type = KEY_TYPE_NA; if (ieee->group_key_type) { setKey(priv, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->group_key_type, broadcast_addr, 0, key); } } } /* based on ipw2200 driver */ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); struct iwreq *wrq = (struct iwreq *)rq; int ret=-1; struct iw_point *p = &wrq->u.data; struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer; down(&priv->wx_sem); if (p->length < sizeof(struct ieee_param) || !p->pointer){ ret = -EINVAL; goto out; } ipw = kmalloc(p->length, GFP_KERNEL); if (ipw == NULL){ ret = -ENOMEM; goto out; } if (copy_from_user(ipw, p->pointer, p->length)) { kfree(ipw); ret = -EFAULT; goto out; } switch (cmd) { case RTL_IOCTL_WPA_SUPPLICANT: /* parse here for HW security */ if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) r8192e_set_hw_key(priv, ipw); ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data); break; default: ret = -EOPNOTSUPP; break; } kfree(ipw); out: up(&priv->wx_sem); return ret; } static u8 HwRateToMRate90(bool bIsHT, u8 rate) { u8 ret_rate = 0x02; if(!bIsHT) { switch(rate) { case DESC90_RATE1M: ret_rate = MGN_1M; break; case DESC90_RATE2M: ret_rate = MGN_2M; break; case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break; case DESC90_RATE11M: ret_rate = MGN_11M; break; case DESC90_RATE6M: ret_rate = MGN_6M; break; case DESC90_RATE9M: ret_rate = MGN_9M; break; case DESC90_RATE12M: ret_rate = MGN_12M; break; case DESC90_RATE18M: ret_rate = MGN_18M; break; case DESC90_RATE24M: ret_rate = MGN_24M; break; case DESC90_RATE36M: ret_rate = MGN_36M; break; case DESC90_RATE48M: ret_rate = MGN_48M; break; case DESC90_RATE54M: ret_rate = MGN_54M; break; default: RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT); break; } } else { switch(rate) { case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break; case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break; case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break; case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break; case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break; case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break; case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break; case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break; case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break; case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break; case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break; case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break; case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break; case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break; case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break; case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break; case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break; default: RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT); break; } } return ret_rate; } /* Record the TSF time stamp when receiving a packet */ static void UpdateRxPktTimeStamp8190(struct r8192_priv *priv, struct ieee80211_rx_stats *stats) { if(stats->bIsAMPDU && !stats->bFirstMPDU) { stats->mac_time[0] = priv->LastRxDescTSFLow; stats->mac_time[1] = priv->LastRxDescTSFHigh; } else { priv->LastRxDescTSFLow = stats->mac_time[0]; priv->LastRxDescTSFHigh = stats->mac_time[1]; } } static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index. { long signal_power; // in dBm. // Translate to dBm (x=0.5y-95). signal_power = (long)((signal_strength_index + 1) >> 1); signal_power -= 95; return signal_power; } /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to be a local static. Otherwise, it may increase when we return from S3/S4. The value will be kept in memory or disk. We must delcare the value in adapter and it will be reinitialized when return from S3/S4. */ static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats) { bool bcheck = false; u8 rfpath; u32 nspatial_stream, tmp_val; static u32 slide_rssi_index=0, slide_rssi_statistics=0; static u32 slide_evm_index=0, slide_evm_statistics=0; static u32 last_rssi=0, last_evm=0; //cosa add for beacon rssi smoothing static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0; static u32 last_beacon_adc_pwdb=0; struct ieee80211_hdr_3addr *hdr; u16 sc ; unsigned int frag,seq; hdr = (struct ieee80211_hdr_3addr *)buffer; sc = le16_to_cpu(hdr->seq_ctl); frag = WLAN_GET_SEQ_FRAG(sc); seq = WLAN_GET_SEQ_SEQ(sc); // // Check whether we should take the previous packet into accounting // if(!pprevious_stats->bIsAMPDU) { // if previous packet is not aggregated packet bcheck = true; } if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) { slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX; last_rssi = priv->stats.slide_signal_strength[slide_rssi_index]; priv->stats.slide_rssi_total -= last_rssi; } priv->stats.slide_rssi_total += pprevious_stats->SignalStrength; priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength; if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX) slide_rssi_index = 0; // <1> Showed on UI for user, in dbm tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics; priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val); pcurrent_stats->rssi = priv->stats.signal_strength; // // If the previous packet does not match the criteria, neglect it // if(!pprevious_stats->bPacketMatchBSSID) { if(!pprevious_stats->bToSelfBA) return; } if(!bcheck) return; // <2> Showed on UI for engineering // hardware does not provide rssi information for each rf path in CCK if(!pprevious_stats->bIsCCK && pprevious_stats->bPacketToSelf) { for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++) { if (!rtl8192_phy_CheckIsLegalRFPath(priv, rfpath)) continue; RT_TRACE(COMP_DBG, "pPreviousstats->RxMIMOSignalStrength[rfpath] = %d\n", pprevious_stats->RxMIMOSignalStrength[rfpath]); //Fixed by Jacken 2008-03-20 if(priv->stats.rx_rssi_percentage[rfpath] == 0) { priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath]; } if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) { priv->stats.rx_rssi_percentage[rfpath] = ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) + (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor); priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1; } else { priv->stats.rx_rssi_percentage[rfpath] = ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) + (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor); } RT_TRACE(COMP_DBG, "priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" , priv->stats.rx_rssi_percentage[rfpath]); } } // // Check PWDB. // //cosa add for beacon rssi smoothing by average. if(pprevious_stats->bPacketBeacon) { /* record the beacon pwdb to the sliding window. */ if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) { slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX; last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index]; priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb; // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total); } priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll; priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll; slide_beacon_adc_pwdb_index++; if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX) slide_beacon_adc_pwdb_index = 0; pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics; if(pprevious_stats->RxPWDBAll >= 3) pprevious_stats->RxPWDBAll -= 3; } RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n", pprevious_stats->bIsCCK? "CCK": "OFDM", pprevious_stats->RxPWDBAll); if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) { if(priv->undecorated_smoothed_pwdb < 0) // initialize { priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll; } if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) { priv->undecorated_smoothed_pwdb = ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) + (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor); priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1; } else { priv->undecorated_smoothed_pwdb = ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) + (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor); } } // // Check EVM // /* record the general EVM to the sliding window. */ if(pprevious_stats->SignalQuality == 0) { } else { if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){ if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){ slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX; last_evm = priv->stats.slide_evm[slide_evm_index]; priv->stats.slide_evm_total -= last_evm; } priv->stats.slide_evm_total += pprevious_stats->SignalQuality; priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality; if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX) slide_evm_index = 0; // <1> Showed on UI for user, in percentage. tmp_val = priv->stats.slide_evm_total/slide_evm_statistics; //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality. } // <2> Showed on UI for engineering if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) { for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream { if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) { if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize { priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream]; } priv->stats.rx_evm_percentage[nspatial_stream] = ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) + (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor); } } } } } static u8 rtl819x_query_rxpwrpercentage( char antpower ) { if ((antpower <= -100) || (antpower >= 20)) { return 0; } else if (antpower >= 0) { return 100; } else { return (100+antpower); } } static u8 rtl819x_evm_dbtopercentage( char value ) { char ret_val; ret_val = value; if(ret_val >= 0) ret_val = 0; if(ret_val <= -33) ret_val = -33; ret_val = 0 - ret_val; ret_val*=3; if(ret_val == 99) ret_val = 100; return ret_val; } /* We want good-looking for signal strength/quality */ static long rtl819x_signal_scale_mapping(long currsig) { long retsig; // Step 1. Scale mapping. if(currsig >= 61 && currsig <= 100) { retsig = 90 + ((currsig - 60) / 4); } else if(currsig >= 41 && currsig <= 60) { retsig = 78 + ((currsig - 40) / 2); } else if(currsig >= 31 && currsig <= 40) { retsig = 66 + (currsig - 30); } else if(currsig >= 21 && currsig <= 30) { retsig = 54 + (currsig - 20); } else if(currsig >= 5 && currsig <= 20) { retsig = 42 + (((currsig - 5) * 2) / 3); } else if(currsig == 4) { retsig = 36; } else if(currsig == 3) { retsig = 27; } else if(currsig == 2) { retsig = 18; } else if(currsig == 1) { retsig = 9; } else { retsig = currsig; } return retsig; } static void rtl8192_query_rxphystatus( struct r8192_priv * priv, struct ieee80211_rx_stats * pstats, prx_desc_819x_pci pdesc, prx_fwinfo_819x_pci pdrvinfo, struct ieee80211_rx_stats * precord_stats, bool bpacket_match_bssid, bool bpacket_toself, bool bPacketBeacon, bool bToSelfBA ) { //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status); phy_sts_ofdm_819xpci_t* pofdm_buf; phy_sts_cck_819xpci_t * pcck_buf; phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc; u8 *prxpkt; u8 i,max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg; char rx_pwr[4], rx_pwr_all=0; //long rx_avg_pwr = 0; char rx_snrX, rx_evmX; u8 evm, pwdb_all; u32 RSSI, total_rssi=0;//, total_evm=0; // long signal_strength_index = 0; u8 is_cck_rate=0; u8 rf_rx_num = 0; is_cck_rate = rx_hal_is_cck_rate(pdrvinfo); // Record it for next packet processing memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats)); pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid; pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself; pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo); pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon; pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA; /*2007.08.30 requested by SD3 Jerry */ if (priv->phy_check_reg824 == 0) { priv->phy_reg824_bit9 = rtl8192_QueryBBReg(priv, rFPGA0_XA_HSSIParameter2, 0x200); priv->phy_check_reg824 = 1; } prxpkt = (u8*)pdrvinfo; /* Move pointer to the 16th bytes. Phy status start address. */ prxpkt += sizeof(rx_fwinfo_819x_pci); /* Initial the cck and ofdm buffer pointer */ pcck_buf = (phy_sts_cck_819xpci_t *)prxpkt; pofdm_buf = (phy_sts_ofdm_819xpci_t *)prxpkt; pstats->RxMIMOSignalQuality[0] = -1; pstats->RxMIMOSignalQuality[1] = -1; precord_stats->RxMIMOSignalQuality[0] = -1; precord_stats->RxMIMOSignalQuality[1] = -1; if(is_cck_rate) { // // (1)Hardware does not provide RSSI for CCK // // // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) // u8 report;//, cck_agc_rpt; if (!priv->phy_reg824_bit9) { report = pcck_buf->cck_agc_rpt & 0xc0; report = report>>6; switch(report) { //Fixed by Jacken from Bryant 2008-03-20 //Original value is -38 , -26 , -14 , -2 //Fixed value is -35 , -23 , -11 , 6 case 0x3: rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e); break; case 0x2: rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e); break; case 0x1: rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e); break; case 0x0: rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e); break; } } else { report = pcck_buf->cck_agc_rpt & 0x60; report = report>>5; switch(report) { case 0x3: rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; break; case 0x2: rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1); break; case 0x1: rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; break; case 0x0: rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; break; } } pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; pstats->RecvSignalPower = rx_pwr_all; // // (3) Get Signal Quality (EVM) // if(bpacket_match_bssid) { u8 sq; if(pstats->RxPWDBAll > 40) { sq = 100; }else { sq = pcck_buf->sq_rpt; if(pcck_buf->sq_rpt > 64) sq = 0; else if (pcck_buf->sq_rpt < 20) sq = 100; else sq = ((64-sq) * 100) / 44; } pstats->SignalQuality = precord_stats->SignalQuality = sq; pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq; pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1; } } else { // // (1)Get RSSI for HT rate // for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) { // 2008/01/30 MH we will judge RF RX path now. if (priv->brfpath_rxenable[i]) rf_rx_num++; //else //continue; //Fixed by Jacken from Bryant 2008-03-20 //Original value is 106 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 110; //Get Rx snr value in DB tmp_rxsnr = pofdm_buf->rxsnr_X[i]; rx_snrX = (char)(tmp_rxsnr); rx_snrX /= 2; /* Translate DBM to percentage. */ RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]); if (priv->brfpath_rxenable[i]) total_rssi += RSSI; /* Record Signal Strength for next packet */ if(bpacket_match_bssid) { pstats->RxMIMOSignalStrength[i] =(u8) RSSI; precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI; } } // // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) // //Fixed by Jacken from Bryant 2008-03-20 //Original value is 106 rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106; pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; pstats->RxPower = precord_stats->RxPower = rx_pwr_all; pstats->RecvSignalPower = rx_pwr_all; // // (3)EVM of HT rate // if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 && pdrvinfo->RxRate<=DESC90_RATEMCS15) max_spatial_stream = 2; //both spatial stream make sense else max_spatial_stream = 1; //only spatial stream 1 makes sense for(i=0; i<max_spatial_stream; i++) { tmp_rxevm = pofdm_buf->rxevm_X[i]; rx_evmX = (char)(tmp_rxevm); // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment // fill most significant bit to "zero" when doing shifting operation which may change a negative // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore. rx_evmX /= 2; //dbm evm = rtl819x_evm_dbtopercentage(rx_evmX); if(bpacket_match_bssid) { if(i==0) // Fill value in RFD, Get the first spatial stream only pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff); pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff); } } /* record rx statistics for debug */ rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg; prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg; } //UI BSS List signal strength(in percentage), make it good looking, from 0~100. //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). if(is_cck_rate) { pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL; } else { //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u1Byte)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u1Byte)(total_rssi/=RF90_PATH_MAX); // We can judge RX path number now. if (rf_rx_num != 0) pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num))); } } static void rtl8192_record_rxdesc_forlateruse( struct ieee80211_rx_stats * psrc_stats, struct ieee80211_rx_stats * ptarget_stats ) { ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU; ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU; } static void TranslateRxSignalStuff819xpci(struct r8192_priv *priv, struct sk_buff *skb, struct ieee80211_rx_stats * pstats, prx_desc_819x_pci pdesc, prx_fwinfo_819x_pci pdrvinfo) { // TODO: We must only check packet for current MAC address. Not finish bool bpacket_match_bssid, bpacket_toself; bool bPacketBeacon=false, bToSelfBA=false; struct ieee80211_hdr_3addr *hdr; u16 fc,type; // Get Signal Quality for only RX data queue (but not command queue) u8* tmp_buf; u8 *praddr; /* Get MAC frame start address. */ tmp_buf = skb->data; hdr = (struct ieee80211_hdr_3addr *)tmp_buf; fc = le16_to_cpu(hdr->frame_ctl); type = WLAN_FC_GET_TYPE(fc); praddr = hdr->addr1; /* Check if the received packet is acceptabe. */ bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) && (!compare_ether_addr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3)) && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV)); bpacket_toself = bpacket_match_bssid & (!compare_ether_addr(praddr, priv->ieee80211->dev->dev_addr)); if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON) { bPacketBeacon = true; } if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) { if (!compare_ether_addr(praddr, priv->ieee80211->dev->dev_addr)) bToSelfBA = true; } // // Process PHY information for previous packet (RSSI/PWDB/EVM) // // Because phy information is contained in the last packet of AMPDU only, so driver // should process phy information of previous packet rtl8192_process_phyinfo(priv, tmp_buf, &priv->previous_stats, pstats); rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, &priv->previous_stats, bpacket_match_bssid, bpacket_toself ,bPacketBeacon, bToSelfBA); rtl8192_record_rxdesc_forlateruse(pstats, &priv->previous_stats); } static void rtl8192_tx_resume(struct r8192_priv *priv) { struct ieee80211_device *ieee = priv->ieee80211; struct sk_buff *skb; int i; for (i = BK_QUEUE; i < TXCMD_QUEUE; i++) { while ((!skb_queue_empty(&ieee->skb_waitQ[i])) && (priv->ieee80211->check_nic_enough_desc(ieee, i) > 0)) { /* 1. dequeue the packet from the wait queue */ skb = skb_dequeue(&ieee->skb_waitQ[i]); /* 2. tx the packet directly */ ieee->softmac_data_hard_start_xmit(skb, ieee, 0); } } } static void rtl8192_irq_tx_tasklet(unsigned long arg) { struct r8192_priv *priv = (struct r8192_priv*) arg; struct rtl8192_tx_ring *mgnt_ring = &priv->tx_ring[MGNT_QUEUE]; unsigned long flags; /* check if we need to report that the management queue is drained */ spin_lock_irqsave(&priv->irq_th_lock, flags); if (!skb_queue_len(&mgnt_ring->queue) && priv->ieee80211->ack_tx_to_ieee && rtl8192_is_tx_queue_empty(priv->ieee80211)) { priv->ieee80211->ack_tx_to_ieee = 0; ieee80211_ps_tx_ack(priv->ieee80211, 1); } spin_unlock_irqrestore(&priv->irq_th_lock, flags); rtl8192_tx_resume(priv); } /* Record the received data rate */ static void UpdateReceivedRateHistogramStatistics8190( struct r8192_priv *priv, struct ieee80211_rx_stats* pstats ) { u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV u32 rateIndex; u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI if(pstats->bCRC) rcvType = 2; else if(pstats->bICV) rcvType = 3; if(pstats->bShortPreamble) preamble_guardinterval = 1;// short else preamble_guardinterval = 0;// long switch(pstats->rate) { // // CCK rate // case MGN_1M: rateIndex = 0; break; case MGN_2M: rateIndex = 1; break; case MGN_5_5M: rateIndex = 2; break; case MGN_11M: rateIndex = 3; break; // // Legacy OFDM rate // case MGN_6M: rateIndex = 4; break; case MGN_9M: rateIndex = 5; break; case MGN_12M: rateIndex = 6; break; case MGN_18M: rateIndex = 7; break; case MGN_24M: rateIndex = 8; break; case MGN_36M: rateIndex = 9; break; case MGN_48M: rateIndex = 10; break; case MGN_54M: rateIndex = 11; break; // // 11n High throughput rate // case MGN_MCS0: rateIndex = 12; break; case MGN_MCS1: rateIndex = 13; break; case MGN_MCS2: rateIndex = 14; break; case MGN_MCS3: rateIndex = 15; break; case MGN_MCS4: rateIndex = 16; break; case MGN_MCS5: rateIndex = 17; break; case MGN_MCS6: rateIndex = 18; break; case MGN_MCS7: rateIndex = 19; break; case MGN_MCS8: rateIndex = 20; break; case MGN_MCS9: rateIndex = 21; break; case MGN_MCS10: rateIndex = 22; break; case MGN_MCS11: rateIndex = 23; break; case MGN_MCS12: rateIndex = 24; break; case MGN_MCS13: rateIndex = 25; break; case MGN_MCS14: rateIndex = 26; break; case MGN_MCS15: rateIndex = 27; break; default: rateIndex = 28; break; } priv->stats.received_rate_histogram[0][rateIndex]++; //total priv->stats.received_rate_histogram[rcvType][rateIndex]++; } static void rtl8192_rx(struct r8192_priv *priv) { struct ieee80211_hdr_1addr *ieee80211_hdr = NULL; bool unicast_packet = false; struct ieee80211_rx_stats stats = { .signal = 0, .noise = -98, .rate = 0, .freq = IEEE80211_24GHZ_BAND, }; unsigned int count = priv->rxringcount; prx_fwinfo_819x_pci pDrvInfo = NULL; struct sk_buff *new_skb; while (count--) { rx_desc_819x_pci *pdesc = &priv->rx_ring[priv->rx_idx];//rx descriptor struct sk_buff *skb = priv->rx_buf[priv->rx_idx];//rx pkt if (pdesc->OWN) /* wait data to be filled by hardware */ return; stats.bICV = pdesc->ICV; stats.bCRC = pdesc->CRC32; stats.bHwError = pdesc->CRC32 | pdesc->ICV; stats.Length = pdesc->Length; if(stats.Length < 24) stats.bHwError |= 1; if(stats.bHwError) { stats.bShift = false; goto done; } pDrvInfo = NULL; new_skb = dev_alloc_skb(priv->rxbuffersize); if (unlikely(!new_skb)) goto done; stats.RxDrvInfoSize = pdesc->RxDrvInfoSize; stats.RxBufShift = ((pdesc->Shift)&0x03); stats.Decrypted = !pdesc->SWDec; pci_dma_sync_single_for_cpu(priv->pdev, *((dma_addr_t *)skb->cb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); skb_put(skb, pdesc->Length); pDrvInfo = (rx_fwinfo_819x_pci *)(skb->data + stats.RxBufShift); skb_reserve(skb, stats.RxDrvInfoSize + stats.RxBufShift); stats.rate = HwRateToMRate90((bool)pDrvInfo->RxHT, (u8)pDrvInfo->RxRate); stats.bShortPreamble = pDrvInfo->SPLCP; /* it is debug only. It should be disabled in released driver. * 2007.1.11 by Emily * */ UpdateReceivedRateHistogramStatistics8190(priv, &stats); stats.bIsAMPDU = (pDrvInfo->PartAggr==1); stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1); stats.TimeStampLow = pDrvInfo->TSFL; stats.TimeStampHigh = read_nic_dword(priv, TSFR+4); UpdateRxPktTimeStamp8190(priv, &stats); // // Get Total offset of MPDU Frame Body // if((stats.RxBufShift + stats.RxDrvInfoSize) > 0) stats.bShift = 1; /* ???? */ TranslateRxSignalStuff819xpci(priv, skb, &stats, pdesc, pDrvInfo); /* Rx A-MPDU */ if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1) RT_TRACE(COMP_RXDESC, "pDrvInfo->FirstAGGR = %d, pDrvInfo->PartAggr = %d\n", pDrvInfo->FirstAGGR, pDrvInfo->PartAggr); skb_trim(skb, skb->len - 4/*sCrcLng*/); /* rx packets statistics */ ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data; unicast_packet = false; if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) { //TODO }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){ //TODO }else { /* unicast packet */ unicast_packet = true; } if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){ dev_kfree_skb_any(skb); } else { priv->stats.rxok++; if(unicast_packet) { priv->stats.rxbytesunicast += skb->len; } } pci_unmap_single(priv->pdev, *((dma_addr_t *) skb->cb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); skb = new_skb; priv->rx_buf[priv->rx_idx] = skb; *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); done: pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb)); pdesc->OWN = 1; pdesc->Length = priv->rxbuffersize; if (priv->rx_idx == priv->rxringcount-1) pdesc->EOR = 1; priv->rx_idx = (priv->rx_idx + 1) % priv->rxringcount; } } static void rtl8192_irq_rx_tasklet(unsigned long arg) { struct r8192_priv *priv = (struct r8192_priv*) arg; rtl8192_rx(priv); /* unmask RDU */ write_nic_dword(priv, INTA_MASK, read_nic_dword(priv, INTA_MASK) | IMR_RDU); } static const struct net_device_ops rtl8192_netdev_ops = { .ndo_open = rtl8192_open, .ndo_stop = rtl8192_close, .ndo_tx_timeout = tx_timeout, .ndo_do_ioctl = rtl8192_ioctl, .ndo_set_multicast_list = r8192_set_multicast, .ndo_set_mac_address = r8192_set_mac_adr, .ndo_start_xmit = ieee80211_rtl_xmit, }; static int __devinit rtl8192_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct net_device *dev = NULL; struct r8192_priv *priv= NULL; u8 unit = 0; int ret = -ENODEV; unsigned long pmem_start, pmem_len, pmem_flags; u8 revisionid; RT_TRACE(COMP_INIT,"Configuring chip resources\n"); if( pci_enable_device (pdev) ){ RT_TRACE(COMP_ERR,"Failed to enable PCI device"); return -EIO; } pci_set_master(pdev); //pci_set_wmi(pdev); pci_set_dma_mask(pdev, 0xffffff00ULL); pci_set_consistent_dma_mask(pdev,0xffffff00ULL); dev = alloc_ieee80211(sizeof(struct r8192_priv)); if (!dev) { ret = -ENOMEM; goto fail_free; } pci_set_drvdata(pdev, dev); SET_NETDEV_DEV(dev, &pdev->dev); priv = ieee80211_priv(dev); priv->ieee80211 = netdev_priv(dev); priv->pdev=pdev; if((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304)){ priv->ieee80211->bSupportRemoteWakeUp = 1; } else { priv->ieee80211->bSupportRemoteWakeUp = 0; } pmem_start = pci_resource_start(pdev, 1); pmem_len = pci_resource_len(pdev, 1); pmem_flags = pci_resource_flags (pdev, 1); if (!(pmem_flags & IORESOURCE_MEM)) { RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting\n"); goto fail; } //DMESG("Memory mapped space @ 0x%08lx ", pmem_start); if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) { RT_TRACE(COMP_ERR,"request_mem_region failed!\n"); goto fail; } priv->mem_start = ioremap_nocache(pmem_start, pmem_len); if (!priv->mem_start) { RT_TRACE(COMP_ERR,"ioremap failed!\n"); goto fail1; } dev->mem_start = (unsigned long) priv->mem_start; dev->mem_end = (unsigned long) (priv->mem_start + pci_resource_len(pdev, 0)); /* We disable the RETRY_TIMEOUT register (0x41) to keep * PCI Tx retries from interfering with C3 CPU state */ pci_write_config_byte(pdev, 0x41, 0x00); pci_read_config_byte(pdev, 0x08, &revisionid); /* If the revisionid is 0x10, the device uses rtl8192se. */ if (pdev->device == 0x8192 && revisionid == 0x10) goto fail1; pci_read_config_byte(pdev, 0x05, &unit); pci_write_config_byte(pdev, 0x05, unit & (~0x04)); dev->irq = pdev->irq; priv->irq = 0; dev->netdev_ops = &rtl8192_netdev_ops; dev->wireless_handlers = &r8192_wx_handlers_def; dev->type=ARPHRD_ETHER; dev->watchdog_timeo = HZ*3; if (dev_alloc_name(dev, ifname) < 0){ RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); strcpy(ifname, "wlan%d"); dev_alloc_name(dev, ifname); } RT_TRACE(COMP_INIT, "Driver probe completed1\n"); if (rtl8192_init(priv)!=0) { RT_TRACE(COMP_ERR, "Initialization failed\n"); goto fail; } register_netdev(dev); RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name); rtl8192_proc_init_one(priv); RT_TRACE(COMP_INIT, "Driver probe completed\n"); return 0; fail1: if (priv->mem_start) { iounmap(priv->mem_start); release_mem_region( pci_resource_start(pdev, 1), pci_resource_len(pdev, 1) ); } fail: if(dev){ if (priv->irq) { free_irq(priv->irq, priv); priv->irq = 0; } free_ieee80211(dev); } fail_free: pci_disable_device(pdev); DMESG("wlan driver load failed\n"); pci_set_drvdata(pdev, NULL); return ret; } /* detach all the work and timer structure declared or inititialized * in r8192_init function. * */ static void rtl8192_cancel_deferred_work(struct r8192_priv* priv) { /* call cancel_work_sync instead of cancel_delayed_work if and only if Linux_version_code * is or is newer than 2.6.20 and work structure is defined to be struct work_struct. * Otherwise call cancel_delayed_work is enough. * FIXME (2.6.20 should 2.6.22, work_struct should not cancel) * */ cancel_delayed_work(&priv->watch_dog_wq); cancel_delayed_work(&priv->update_beacon_wq); cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq); cancel_delayed_work(&priv->gpio_change_rf_wq); cancel_work_sync(&priv->reset_wq); cancel_work_sync(&priv->qos_activate); } static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); struct r8192_priv *priv ; u32 i; if (dev) { unregister_netdev(dev); priv = ieee80211_priv(dev); rtl8192_proc_remove_one(priv); rtl8192_down(dev); if (priv->pFirmware) { vfree(priv->pFirmware); priv->pFirmware = NULL; } destroy_workqueue(priv->priv_wq); /* free tx/rx rings */ rtl8192_free_rx_ring(priv); for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) rtl8192_free_tx_ring(priv, i); if (priv->irq) { printk("Freeing irq %d\n", priv->irq); free_irq(priv->irq, priv); priv->irq = 0; } if (priv->mem_start) { iounmap(priv->mem_start); release_mem_region( pci_resource_start(pdev, 1), pci_resource_len(pdev, 1) ); } free_ieee80211(dev); } pci_disable_device(pdev); RT_TRACE(COMP_DOWN, "wlan driver removed\n"); } extern int ieee80211_rtl_init(void); extern void ieee80211_rtl_exit(void); static int __init rtl8192_pci_module_init(void) { int retval; retval = ieee80211_rtl_init(); if (retval) return retval; printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n"); printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n"); RT_TRACE(COMP_INIT, "Initializing module\n"); rtl8192_proc_module_init(); if(0!=pci_register_driver(&rtl8192_pci_driver)) { DMESG("No device found"); /*pci_unregister_driver (&rtl8192_pci_driver);*/ return -ENODEV; } return 0; } static void __exit rtl8192_pci_module_exit(void) { pci_unregister_driver(&rtl8192_pci_driver); RT_TRACE(COMP_DOWN, "Exiting\n"); rtl8192_proc_module_remove(); ieee80211_rtl_exit(); } static irqreturn_t rtl8192_interrupt(int irq, void *param) { struct r8192_priv *priv = param; struct net_device *dev = priv->ieee80211->dev; unsigned long flags; u32 inta; irqreturn_t ret = IRQ_HANDLED; spin_lock_irqsave(&priv->irq_th_lock, flags); /* ISR: 4bytes */ inta = read_nic_dword(priv, ISR); /* & priv->IntrMask; */ write_nic_dword(priv, ISR, inta); /* reset int situation */ if (!inta) { /* * most probably we can safely return IRQ_NONE, * but for now is better to avoid problems */ goto out_unlock; } if (inta == 0xffff) { /* HW disappared */ goto out_unlock; } if (!netif_running(dev)) goto out_unlock; if (inta & IMR_TBDOK) { RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); rtl8192_tx_isr(priv, BEACON_QUEUE); priv->stats.txbeaconokint++; } if (inta & IMR_TBDER) { RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); rtl8192_tx_isr(priv, BEACON_QUEUE); priv->stats.txbeaconerr++; } if (inta & IMR_MGNTDOK ) { RT_TRACE(COMP_INTR, "Manage ok interrupt!\n"); priv->stats.txmanageokint++; rtl8192_tx_isr(priv, MGNT_QUEUE); } if (inta & IMR_COMDOK) { priv->stats.txcmdpktokint++; rtl8192_tx_isr(priv, TXCMD_QUEUE); } if (inta & IMR_ROK) { priv->stats.rxint++; tasklet_schedule(&priv->irq_rx_tasklet); } if (inta & IMR_BcnInt) { RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n"); tasklet_schedule(&priv->irq_prepare_beacon_tasklet); } if (inta & IMR_RDU) { RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n"); priv->stats.rxrdu++; /* reset int situation */ write_nic_dword(priv, INTA_MASK, read_nic_dword(priv, INTA_MASK) & ~IMR_RDU); tasklet_schedule(&priv->irq_rx_tasklet); } if (inta & IMR_RXFOVW) { RT_TRACE(COMP_INTR, "rx overflow !\n"); priv->stats.rxoverflow++; tasklet_schedule(&priv->irq_rx_tasklet); } if (inta & IMR_TXFOVW) priv->stats.txoverflow++; if (inta & IMR_BKDOK) { RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n"); priv->stats.txbkokint++; priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; rtl8192_tx_isr(priv, BK_QUEUE); } if (inta & IMR_BEDOK) { RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n"); priv->stats.txbeokint++; priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; rtl8192_tx_isr(priv, BE_QUEUE); } if (inta & IMR_VIDOK) { RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n"); priv->stats.txviokint++; priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; rtl8192_tx_isr(priv, VI_QUEUE); } if (inta & IMR_VODOK) { priv->stats.txvookint++; priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; rtl8192_tx_isr(priv, VO_QUEUE); } out_unlock: spin_unlock_irqrestore(&priv->irq_th_lock, flags); return ret; } void EnableHWSecurityConfig8192(struct r8192_priv *priv) { u8 SECR_value = 0x0; struct ieee80211_device* ieee = priv->ieee80211; SECR_value = SCR_TxEncEnable | SCR_RxDecEnable; if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) { SECR_value |= SCR_RxUseDK; SECR_value |= SCR_TxUseDK; } else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) { SECR_value |= SCR_RxUseDK; SECR_value |= SCR_TxUseDK; } //add HWSec active enable here. //default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4 ieee->hwsec_active = 1; if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep)//!ieee->hwsec_support) //add hwsec_support flag to totol control hw_sec on/off { ieee->hwsec_active = 0; SECR_value &= ~SCR_RxDecEnable; } RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, ieee->hwsec_active, ieee->pairwise_key_type, SECR_value); { write_nic_byte(priv, SECR, SECR_value);//SECR_value | SCR_UseDK ); } } #define TOTAL_CAM_ENTRY 32 //#define CAM_CONTENT_COUNT 8 void setKey(struct r8192_priv *priv, u8 EntryNo, u8 KeyIndex, u16 KeyType, const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent) { u32 TargetCommand = 0; u32 TargetContent = 0; u16 usConfig = 0; u8 i; #ifdef ENABLE_IPS RT_RF_POWER_STATE rtState; rtState = priv->eRFPowerState; if (priv->PowerSaveControl.bInactivePs){ if(rtState == eRfOff){ if(priv->RfOffReason > RF_CHANGE_BY_IPS) { RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__); //up(&priv->wx_sem); return ; } else{ down(&priv->ieee80211->ips_sem); IPSLeave(priv); up(&priv->ieee80211->ips_sem); } } } priv->ieee80211->is_set_key = true; #endif if (EntryNo >= TOTAL_CAM_ENTRY) RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n"); RT_TRACE(COMP_SEC, "====>to setKey(), priv:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", priv, EntryNo, KeyIndex, KeyType, MacAddr); if (DefaultKey) usConfig |= BIT15 | (KeyType<<2); else usConfig |= BIT15 | (KeyType<<2) | KeyIndex; // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex; for(i=0 ; i<CAM_CONTENT_COUNT; i++){ TargetCommand = i+CAM_CONTENT_COUNT*EntryNo; TargetCommand |= BIT31|BIT16; if(i==0){//MAC|Config TargetContent = (u32)(*(MacAddr+0)) << 16| (u32)(*(MacAddr+1)) << 24| (u32)usConfig; write_nic_dword(priv, WCAMI, TargetContent); write_nic_dword(priv, RWCAM, TargetCommand); } else if(i==1){//MAC TargetContent = (u32)(*(MacAddr+2)) | (u32)(*(MacAddr+3)) << 8| (u32)(*(MacAddr+4)) << 16| (u32)(*(MacAddr+5)) << 24; write_nic_dword(priv, WCAMI, TargetContent); write_nic_dword(priv, RWCAM, TargetCommand); } else { //Key Material if(KeyContent != NULL) { write_nic_dword(priv, WCAMI, (u32)(*(KeyContent+i-2)) ); write_nic_dword(priv, RWCAM, TargetCommand); } } } RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig); } bool NicIFEnableNIC(struct r8192_priv *priv) { RT_STATUS init_status = RT_STATUS_SUCCESS; PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl; //YJ,add,091109 if (priv->up == 0){ RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__FUNCTION__); priv->bdisable_nic = false; //YJ,add,091111 return false; } // <1> Reset memory: descriptor, buffer,.. //NicIFResetMemory(Adapter); // <2> Enable Adapter //priv->bfirst_init = true; init_status = rtl8192_adapter_start(priv); if (init_status != RT_STATUS_SUCCESS) { RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__); priv->bdisable_nic = false; //YJ,add,091111 return -1; } RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); //priv->bfirst_init = false; // <3> Enable Interrupt rtl8192_irq_enable(priv); priv->bdisable_nic = false; return (init_status == RT_STATUS_SUCCESS); } bool NicIFDisableNIC(struct r8192_priv *priv) { bool status = true; u8 tmp_state = 0; // <1> Disable Interrupt priv->bdisable_nic = true; //YJ,move,091109 tmp_state = priv->ieee80211->state; ieee80211_softmac_stop_protocol(priv->ieee80211, false); priv->ieee80211->state = tmp_state; rtl8192_cancel_deferred_work(priv); rtl8192_irq_disable(priv); // <2> Stop all timer // <3> Disable Adapter rtl8192_halt_adapter(priv, false); // priv->bdisable_nic = true; return status; } module_init(rtl8192_pci_module_init); module_exit(rtl8192_pci_module_exit);
gpl-2.0
yevgeniy-logachev/CATB15Kernel
kernel/net/ipv4/netfilter/nf_nat_proto_udplite.c
4669
2731
/* (C) 1999-2001 Paul `Rusty' Russell * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org> * (C) 2008 Patrick McHardy <kaber@trash.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/types.h> #include <linux/init.h> #include <linux/ip.h> #include <linux/udp.h> #include <linux/netfilter.h> #include <linux/module.h> #include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_protocol.h> static u_int16_t udplite_port_rover; static void udplite_unique_tuple(struct nf_conntrack_tuple *tuple, const struct nf_nat_ipv4_range *range, enum nf_nat_manip_type maniptype, const struct nf_conn *ct) { nf_nat_proto_unique_tuple(tuple, range, maniptype, ct, &udplite_port_rover); } static bool udplite_manip_pkt(struct sk_buff *skb, unsigned int iphdroff, const struct nf_conntrack_tuple *tuple, enum nf_nat_manip_type maniptype) { const struct iphdr *iph = (struct iphdr *)(skb->data + iphdroff); struct udphdr *hdr; unsigned int hdroff = iphdroff + iph->ihl*4; __be32 oldip, newip; __be16 *portptr, newport; if (!skb_make_writable(skb, hdroff + sizeof(*hdr))) return false; iph = (struct iphdr *)(skb->data + iphdroff); hdr = (struct udphdr *)(skb->data + hdroff); if (maniptype == NF_NAT_MANIP_SRC) { /* Get rid of src ip and src pt */ oldip = iph->saddr; newip = tuple->src.u3.ip; newport = tuple->src.u.udp.port; portptr = &hdr->source; } else { /* Get rid of dst ip and dst pt */ oldip = iph->daddr; newip = tuple->dst.u3.ip; newport = tuple->dst.u.udp.port; portptr = &hdr->dest; } inet_proto_csum_replace4(&hdr->check, skb, oldip, newip, 1); inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, 0); if (!hdr->check) hdr->check = CSUM_MANGLED_0; *portptr = newport; return true; } static const struct nf_nat_protocol nf_nat_protocol_udplite = { .protonum = IPPROTO_UDPLITE, .manip_pkt = udplite_manip_pkt, .in_range = nf_nat_proto_in_range, .unique_tuple = udplite_unique_tuple, #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) .nlattr_to_range = nf_nat_proto_nlattr_to_range, #endif }; static int __init nf_nat_proto_udplite_init(void) { return nf_nat_protocol_register(&nf_nat_protocol_udplite); } static void __exit nf_nat_proto_udplite_fini(void) { nf_nat_protocol_unregister(&nf_nat_protocol_udplite); } module_init(nf_nat_proto_udplite_init); module_exit(nf_nat_proto_udplite_fini); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("UDP-Lite NAT protocol helper"); MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
gpl-2.0
cannondalev2000/kernel_lge_msm8974
arch/sparc/kernel/btext.c
7485
31895
/* * Procedures for drawing on the screen early on in the boot process. * * Benjamin Herrenschmidt <benh@kernel.crashing.org> */ #include <linux/kernel.h> #include <linux/string.h> #include <linux/init.h> #include <linux/console.h> #include <asm/btext.h> #include <asm/oplib.h> #include <asm/io.h> #define NO_SCROLL #ifndef NO_SCROLL static void scrollscreen(void); #endif static void draw_byte(unsigned char c, long locX, long locY); static void draw_byte_32(unsigned char *bits, unsigned int *base, int rb); static void draw_byte_16(unsigned char *bits, unsigned int *base, int rb); static void draw_byte_8(unsigned char *bits, unsigned int *base, int rb); #define __force_data __attribute__((__section__(".data"))) static int g_loc_X __force_data; static int g_loc_Y __force_data; static int g_max_loc_X __force_data; static int g_max_loc_Y __force_data; static int dispDeviceRowBytes __force_data; static int dispDeviceDepth __force_data; static int dispDeviceRect[4] __force_data; static unsigned char *dispDeviceBase __force_data; #define cmapsz (16*256) static unsigned char vga_font[cmapsz]; static int __init btext_initialize(phandle node) { unsigned int width, height, depth, pitch; unsigned long address = 0; u32 prop; if (prom_getproperty(node, "width", (char *)&width, 4) < 0) return -EINVAL; if (prom_getproperty(node, "height", (char *)&height, 4) < 0) return -EINVAL; if (prom_getproperty(node, "depth", (char *)&depth, 4) < 0) return -EINVAL; pitch = width * ((depth + 7) / 8); if (prom_getproperty(node, "linebytes", (char *)&prop, 4) >= 0 && prop != 0xffffffffu) pitch = prop; if (pitch == 1) pitch = 0x1000; if (prom_getproperty(node, "address", (char *)&prop, 4) >= 0) address = prop; /* FIXME: Add support for PCI reg properties. Right now, only * reliable on macs */ if (address == 0) return -EINVAL; g_loc_X = 0; g_loc_Y = 0; g_max_loc_X = width / 8; g_max_loc_Y = height / 16; dispDeviceBase = (unsigned char *)address; dispDeviceRowBytes = pitch; dispDeviceDepth = depth == 15 ? 16 : depth; dispDeviceRect[0] = dispDeviceRect[1] = 0; dispDeviceRect[2] = width; dispDeviceRect[3] = height; return 0; } /* Calc the base address of a given point (x,y) */ static unsigned char * calc_base(int x, int y) { unsigned char *base = dispDeviceBase; base += (x + dispDeviceRect[0]) * (dispDeviceDepth >> 3); base += (y + dispDeviceRect[1]) * dispDeviceRowBytes; return base; } static void btext_clearscreen(void) { unsigned int *base = (unsigned int *)calc_base(0, 0); unsigned long width = ((dispDeviceRect[2] - dispDeviceRect[0]) * (dispDeviceDepth >> 3)) >> 2; int i,j; for (i=0; i<(dispDeviceRect[3] - dispDeviceRect[1]); i++) { unsigned int *ptr = base; for(j=width; j; --j) *(ptr++) = 0; base += (dispDeviceRowBytes >> 2); } } #ifndef NO_SCROLL static void scrollscreen(void) { unsigned int *src = (unsigned int *)calc_base(0,16); unsigned int *dst = (unsigned int *)calc_base(0,0); unsigned long width = ((dispDeviceRect[2] - dispDeviceRect[0]) * (dispDeviceDepth >> 3)) >> 2; int i,j; for (i=0; i<(dispDeviceRect[3] - dispDeviceRect[1] - 16); i++) { unsigned int *src_ptr = src; unsigned int *dst_ptr = dst; for(j=width; j; --j) *(dst_ptr++) = *(src_ptr++); src += (dispDeviceRowBytes >> 2); dst += (dispDeviceRowBytes >> 2); } for (i=0; i<16; i++) { unsigned int *dst_ptr = dst; for(j=width; j; --j) *(dst_ptr++) = 0; dst += (dispDeviceRowBytes >> 2); } } #endif /* ndef NO_SCROLL */ void btext_drawchar(char c) { int cline = 0; #ifdef NO_SCROLL int x; #endif switch (c) { case '\b': if (g_loc_X > 0) --g_loc_X; break; case '\t': g_loc_X = (g_loc_X & -8) + 8; break; case '\r': g_loc_X = 0; break; case '\n': g_loc_X = 0; g_loc_Y++; cline = 1; break; default: draw_byte(c, g_loc_X++, g_loc_Y); } if (g_loc_X >= g_max_loc_X) { g_loc_X = 0; g_loc_Y++; cline = 1; } #ifndef NO_SCROLL while (g_loc_Y >= g_max_loc_Y) { scrollscreen(); g_loc_Y--; } #else /* wrap around from bottom to top of screen so we don't waste time scrolling each line. -- paulus. */ if (g_loc_Y >= g_max_loc_Y) g_loc_Y = 0; if (cline) { for (x = 0; x < g_max_loc_X; ++x) draw_byte(' ', x, g_loc_Y); } #endif } static void btext_drawtext(const char *c, unsigned int len) { while (len--) btext_drawchar(*c++); } static void draw_byte(unsigned char c, long locX, long locY) { unsigned char *base = calc_base(locX << 3, locY << 4); unsigned char *font = &vga_font[((unsigned int)c) * 16]; int rb = dispDeviceRowBytes; switch(dispDeviceDepth) { case 24: case 32: draw_byte_32(font, (unsigned int *)base, rb); break; case 15: case 16: draw_byte_16(font, (unsigned int *)base, rb); break; case 8: draw_byte_8(font, (unsigned int *)base, rb); break; } } static unsigned int expand_bits_8[16] = { 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff }; static unsigned int expand_bits_16[4] = { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff }; static void draw_byte_32(unsigned char *font, unsigned int *base, int rb) { int l, bits; int fg = 0xFFFFFFFFUL; int bg = 0x00000000UL; for (l = 0; l < 16; ++l) { bits = *font++; base[0] = (-(bits >> 7) & fg) ^ bg; base[1] = (-((bits >> 6) & 1) & fg) ^ bg; base[2] = (-((bits >> 5) & 1) & fg) ^ bg; base[3] = (-((bits >> 4) & 1) & fg) ^ bg; base[4] = (-((bits >> 3) & 1) & fg) ^ bg; base[5] = (-((bits >> 2) & 1) & fg) ^ bg; base[6] = (-((bits >> 1) & 1) & fg) ^ bg; base[7] = (-(bits & 1) & fg) ^ bg; base = (unsigned int *) ((char *)base + rb); } } static void draw_byte_16(unsigned char *font, unsigned int *base, int rb) { int l, bits; int fg = 0xFFFFFFFFUL; int bg = 0x00000000UL; unsigned int *eb = (int *)expand_bits_16; for (l = 0; l < 16; ++l) { bits = *font++; base[0] = (eb[bits >> 6] & fg) ^ bg; base[1] = (eb[(bits >> 4) & 3] & fg) ^ bg; base[2] = (eb[(bits >> 2) & 3] & fg) ^ bg; base[3] = (eb[bits & 3] & fg) ^ bg; base = (unsigned int *) ((char *)base + rb); } } static void draw_byte_8(unsigned char *font, unsigned int *base, int rb) { int l, bits; int fg = 0x0F0F0F0FUL; int bg = 0x00000000UL; unsigned int *eb = (int *)expand_bits_8; for (l = 0; l < 16; ++l) { bits = *font++; base[0] = (eb[bits >> 4] & fg) ^ bg; base[1] = (eb[bits & 0xf] & fg) ^ bg; base = (unsigned int *) ((char *)base + rb); } } static void btext_console_write(struct console *con, const char *s, unsigned int n) { btext_drawtext(s, n); } static struct console btext_console = { .name = "btext", .write = btext_console_write, .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME, .index = 0, }; int __init btext_find_display(void) { phandle node; char type[32]; int ret; node = prom_inst2pkg(prom_stdout); if (prom_getproperty(node, "device_type", type, 32) < 0) return -ENODEV; if (strcmp(type, "display")) return -ENODEV; ret = btext_initialize(node); if (!ret) { btext_clearscreen(); register_console(&btext_console); } return ret; } static unsigned char vga_font[cmapsz] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1e, 0x0e, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xde, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x0c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xdb, 0x99, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x3c, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc3, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc1, 0xc3, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x0c, 0x06, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x60, 0x60, 0x66, 0x3c, 0x0c, 0x06, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0xfe, 0x66, 0x60, 0x7c, 0x60, 0x60, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x1b, 0x7e, 0xd8, 0xdc, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0x78, 0x00, 0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xe6, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x7c, 0x62, 0x66, 0x6f, 0x66, 0x66, 0x66, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xc0, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x60, 0xce, 0x9b, 0x06, 0x0c, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xce, 0x96, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36, 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xd8, 0xd8, 0xd8, 0xdc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x6c, 0x3c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xd8, 0x30, 0x60, 0xc8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
gpl-2.0
W4TCH0UT/zz_quark
drivers/infiniband/hw/amso1100/c2_intr.c
7741
5759
/* * Copyright (c) 2005 Ammasso, Inc. All rights reserved. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "c2.h" #include <rdma/iw_cm.h> #include "c2_vq.h" static void handle_mq(struct c2_dev *c2dev, u32 index); static void handle_vq(struct c2_dev *c2dev, u32 mq_index); /* * Handle RNIC interrupts */ void c2_rnic_interrupt(struct c2_dev *c2dev) { unsigned int mq_index; while (c2dev->hints_read != be16_to_cpu(*c2dev->hint_count)) { mq_index = readl(c2dev->regs + PCI_BAR0_HOST_HINT); if (mq_index & 0x80000000) { break; } c2dev->hints_read++; handle_mq(c2dev, mq_index); } } /* * Top level MQ handler */ static void handle_mq(struct c2_dev *c2dev, u32 mq_index) { if (c2dev->qptr_array[mq_index] == NULL) { pr_debug("handle_mq: stray activity for mq_index=%d\n", mq_index); return; } switch (mq_index) { case (0): /* * An index of 0 in the activity queue * indicates the req vq now has messages * available... * * Wake up any waiters waiting on req VQ * message availability. */ wake_up(&c2dev->req_vq_wo); break; case (1): handle_vq(c2dev, mq_index); break; case (2): /* We have to purge the VQ in case there are pending * accept reply requests that would result in the * generation of an ESTABLISHED event. If we don't * generate these first, a CLOSE event could end up * being delivered before the ESTABLISHED event. */ handle_vq(c2dev, 1); c2_ae_event(c2dev, mq_index); break; default: /* There is no event synchronization between CQ events * and AE or CM events. In fact, CQE could be * delivered for all of the I/O up to and including the * FLUSH for a peer disconenct prior to the ESTABLISHED * event being delivered to the app. The reason for this * is that CM events are delivered on a thread, while AE * and CM events are delivered on interrupt context. */ c2_cq_event(c2dev, mq_index); break; } return; } /* * Handles verbs WR replies. */ static void handle_vq(struct c2_dev *c2dev, u32 mq_index) { void *adapter_msg, *reply_msg; struct c2wr_hdr *host_msg; struct c2wr_hdr tmp; struct c2_mq *reply_vq; struct c2_vq_req *req; struct iw_cm_event cm_event; int err; reply_vq = (struct c2_mq *) c2dev->qptr_array[mq_index]; /* * get next msg from mq_index into adapter_msg. * don't free it yet. */ adapter_msg = c2_mq_consume(reply_vq); if (adapter_msg == NULL) { return; } host_msg = vq_repbuf_alloc(c2dev); /* * If we can't get a host buffer, then we'll still * wakeup the waiter, we just won't give him the msg. * It is assumed the waiter will deal with this... */ if (!host_msg) { pr_debug("handle_vq: no repbufs!\n"); /* * just copy the WR header into a local variable. * this allows us to still demux on the context */ host_msg = &tmp; memcpy(host_msg, adapter_msg, sizeof(tmp)); reply_msg = NULL; } else { memcpy(host_msg, adapter_msg, reply_vq->msg_size); reply_msg = host_msg; } /* * consume the msg from the MQ */ c2_mq_free(reply_vq); /* * wakeup the waiter. */ req = (struct c2_vq_req *) (unsigned long) host_msg->context; if (req == NULL) { /* * We should never get here, as the adapter should * never send us a reply that we're not expecting. */ vq_repbuf_free(c2dev, host_msg); pr_debug("handle_vq: UNEXPECTEDLY got NULL req\n"); return; } if (reply_msg) err = c2_errno(reply_msg); else err = -ENOMEM; if (!err) switch (req->event) { case IW_CM_EVENT_ESTABLISHED: c2_set_qp_state(req->qp, C2_QP_STATE_RTS); /* * Until ird/ord negotiation via MPAv2 support is added, send * max supported values */ cm_event.ird = cm_event.ord = 128; case IW_CM_EVENT_CLOSE: /* * Move the QP to RTS if this is * the established event */ cm_event.event = req->event; cm_event.status = 0; cm_event.local_addr = req->cm_id->local_addr; cm_event.remote_addr = req->cm_id->remote_addr; cm_event.private_data = NULL; cm_event.private_data_len = 0; req->cm_id->event_handler(req->cm_id, &cm_event); break; default: break; } req->reply_msg = (u64) (unsigned long) (reply_msg); atomic_set(&req->reply_ready, 1); wake_up(&req->wait_object); /* * If the request was cancelled, then this put will * free the vq_req memory...and reply_msg!!! */ vq_req_put(c2dev, req); }
gpl-2.0
GuneetAtwal/kernel_a210
drivers/staging/rtl8192e/rtl819x_HTProc.c
7997
31703
/****************************************************************************** * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * wlanfae <wlanfae@realtek.com> ******************************************************************************/ #include "rtllib.h" #include "rtl819x_HT.h" u8 MCS_FILTER_ALL[16] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; u8 MCS_FILTER_1SS[16] = { 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} ; u16 MCS_DATA_RATE[2][2][77] = { {{13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, 39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416, 468, 520, 0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182, 182, 208, 156, 195, 195, 234, 273, 273, 312, 130, 156, 181, 156, 181, 208, 234, 208, 234, 260, 260, 286, 195, 234, 273, 234, 273, 312, 351, 312, 351, 390, 390, 429} , {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289, 43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520, 578, 0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231, 173, 217, 217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260, 231, 260, 289, 289, 318, 217, 260, 303, 260, 303, 347, 390, 347, 390, 433, 433, 477} } , {{27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080, 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405, 405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540, 594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891}, {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200, 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450, 450, 540, 630, 630, 720, 300, 360, 420, 360, 420, 480, 540, 480, 540, 600, 600, 660, 450, 540, 630, 540, 630, 720, 810, 720, 810, 900, 900, 990} } }; static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf}; static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70}; static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e}; static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f}; static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf}; static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc}; static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e}; static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02}; static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0}; static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91}; static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94}; static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4}; void HTUpdateDefaultSetting(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; pHTInfo->bAcceptAddbaReq = 1; pHTInfo->bRegShortGI20MHz = 1; pHTInfo->bRegShortGI40MHz = 1; pHTInfo->bRegBW40MHz = 1; if (pHTInfo->bRegBW40MHz) pHTInfo->bRegSuppCCK = 1; else pHTInfo->bRegSuppCCK = true; pHTInfo->nAMSDU_MaxSize = 7935UL; pHTInfo->bAMSDU_Support = 0; pHTInfo->bAMPDUEnable = 1; pHTInfo->AMPDU_Factor = 2; pHTInfo->MPDU_Density = 0; pHTInfo->SelfMimoPs = 3; if (pHTInfo->SelfMimoPs == 2) pHTInfo->SelfMimoPs = 3; ieee->bTxDisableRateFallBack = 0; ieee->bTxUseDriverAssingedRate = 0; ieee->bTxEnableFwCalcDur = 1; pHTInfo->bRegRT2RTAggregation = 1; pHTInfo->bRegRxReorderEnable = 1; pHTInfo->RxReorderWinSize = 64; pHTInfo->RxReorderPendingTime = 30; } void HTDebugHTCapability(u8 *CapIE, u8 *TitleString) { static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; struct ht_capab_ele *pCapELE; if (!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) { RTLLIB_DEBUG(RTLLIB_DL_HT, "EWC IE in %s()\n", __func__); pCapELE = (struct ht_capab_ele *)(&CapIE[4]); } else pCapELE = (struct ht_capab_ele *)(&CapIE[0]); RTLLIB_DEBUG(RTLLIB_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSupported Channel Width = %s\n", (pCapELE->ChlWidth) ? "20MHz" : "20/40MHz"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSupport Short GI for 20M = %s\n", (pCapELE->ShortGI20Mhz) ? "YES" : "NO"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSupport Short GI for 40M = %s\n", (pCapELE->ShortGI40Mhz) ? "YES" : "NO"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSupport TX STBC = %s\n", (pCapELE->TxSTBC) ? "YES" : "NO"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tMax AMSDU Size = %s\n", (pCapELE->MaxAMSDUSize) ? "3839" : "7935"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSupport CCK in 20/40 mode = %s\n", (pCapELE->DssCCk) ? "YES" : "NO"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tMax AMPDU Factor = %d\n", pCapELE->MaxRxAMPDUFactor); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tMPDU Density = %d\n", pCapELE->MPDUDensity); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tMCS Rate Set = [%x][%x][%x][%x][%x]\n", pCapELE->MCS[0], pCapELE->MCS[1], pCapELE->MCS[2], pCapELE->MCS[3], pCapELE->MCS[4]); return; } void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString) { static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; struct ht_info_ele *pHTInfoEle; if (!memcmp(InfoIE, EWC11NHTInfo, sizeof(EWC11NHTInfo))) { RTLLIB_DEBUG(RTLLIB_DL_HT, "EWC IE in %s()\n", __func__); pHTInfoEle = (struct ht_info_ele *)(&InfoIE[4]); } else pHTInfoEle = (struct ht_info_ele *)(&InfoIE[0]); RTLLIB_DEBUG(RTLLIB_DL_HT, "<Log HT Information Element>. " "Called by %s\n", TitleString); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tPrimary channel = %d\n", pHTInfoEle->ControlChl); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSenondary channel ="); switch (pHTInfoEle->ExtChlOffset) { case 0: RTLLIB_DEBUG(RTLLIB_DL_HT, "Not Present\n"); break; case 1: RTLLIB_DEBUG(RTLLIB_DL_HT, "Upper channel\n"); break; case 2: RTLLIB_DEBUG(RTLLIB_DL_HT, "Reserved. Eooro!!!\n"); break; case 3: RTLLIB_DEBUG(RTLLIB_DL_HT, "Lower Channel\n"); break; } RTLLIB_DEBUG(RTLLIB_DL_HT, "\tRecommended channel width = %s\n", (pHTInfoEle->RecommemdedTxWidth) ? "20Mhz" : "40Mhz"); RTLLIB_DEBUG(RTLLIB_DL_HT, "\tOperation mode for protection = "); switch (pHTInfoEle->OptMode) { case 0: RTLLIB_DEBUG(RTLLIB_DL_HT, "No Protection\n"); break; case 1: RTLLIB_DEBUG(RTLLIB_DL_HT, "HT non-member protection mode\n"); break; case 2: RTLLIB_DEBUG(RTLLIB_DL_HT, "Suggest to open protection\n"); break; case 3: RTLLIB_DEBUG(RTLLIB_DL_HT, "HT mixed mode\n"); break; } RTLLIB_DEBUG(RTLLIB_DL_HT, "\tBasic MCS Rate Set = [%x][%x][%x][%x]" "[%x]\n", pHTInfoEle->BasicMSC[0], pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]); return; } static bool IsHTHalfNmode40Bandwidth(struct rtllib_device *ieee) { bool retValue = false; struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; if (pHTInfo->bCurrentHTSupport == false) retValue = false; else if (pHTInfo->bRegBW40MHz == false) retValue = false; else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) retValue = false; else if (((struct ht_capab_ele *)(pHTInfo->PeerHTCapBuf))->ChlWidth) retValue = true; else retValue = false; return retValue; } static bool IsHTHalfNmodeSGI(struct rtllib_device *ieee, bool is40MHz) { bool retValue = false; struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; if (pHTInfo->bCurrentHTSupport == false) retValue = false; else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) retValue = false; else if (is40MHz) { if (((struct ht_capab_ele *) (pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) retValue = true; else retValue = false; } else { if (((struct ht_capab_ele *) (pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) retValue = true; else retValue = false; } return retValue; } u16 HTHalfMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate) { u8 is40MHz; u8 isShortGI; is40MHz = (IsHTHalfNmode40Bandwidth(ieee)) ? 1 : 0; isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz)) ? 1 : 0; return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)]; } u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; u8 is40MHz = (pHTInfo->bCurBW40MHz) ? 1 : 0; u8 isShortGI = (pHTInfo->bCurBW40MHz) ? ((pHTInfo->bCurShortGI40MHz) ? 1 : 0) : ((pHTInfo->bCurShortGI20MHz) ? 1 : 0); return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)]; } u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate) { u16 CCKOFDMRate[12] = {0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c}; u8 is40MHz = 0; u8 isShortGI = 0; if (nDataRate < 12) { return CCKOFDMRate[nDataRate]; } else { if (nDataRate >= 0x10 && nDataRate <= 0x1f) { is40MHz = 0; isShortGI = 0; } else if (nDataRate >= 0x20 && nDataRate <= 0x2f) { is40MHz = 1; isShortGI = 0; } else if (nDataRate >= 0x30 && nDataRate <= 0x3f) { is40MHz = 0; isShortGI = 1; } else if (nDataRate >= 0x40 && nDataRate <= 0x4f) { is40MHz = 1; isShortGI = 1; } return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate&0xf]; } } bool IsHTHalfNmodeAPs(struct rtllib_device *ieee) { bool retValue = false; struct rtllib_network *net = &ieee->current_network; if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || (memcmp(net->bssid, PCI_RALINK, 3) == 0) || (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || (net->ralink_cap_exist)) retValue = true; else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) || (net->broadcom_cap_exist)) retValue = true; else if (net->bssht.bdRT2RTAggregation) retValue = true; else retValue = false; return retValue; } static void HTIOTPeerDetermine(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; struct rtllib_network *net = &ieee->current_network; if (net->bssht.bdRT2RTAggregation) { pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK; if (net->bssht.RT2RT_HT_Mode & RT_HT_CAP_USE_92SE) pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK_92SE; if (net->bssht.RT2RT_HT_Mode & RT_HT_CAP_USE_SOFTAP) pHTInfo->IOTPeer = HT_IOT_PEER_92U_SOFTAP; } else if (net->broadcom_cap_exist) pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM; else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)) pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM; else if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || (memcmp(net->bssid, PCI_RALINK, 3) == 0) || (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || net->ralink_cap_exist) pHTInfo->IOTPeer = HT_IOT_PEER_RALINK; else if ((net->atheros_cap_exist) || (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0) || (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0)) pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS; else if ((memcmp(net->bssid, CISCO_BROADCOM, 3) == 0) || net->cisco_cap_exist) pHTInfo->IOTPeer = HT_IOT_PEER_CISCO; else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) || net->marvell_cap_exist) pHTInfo->IOTPeer = HT_IOT_PEER_MARVELL; else if (net->airgo_cap_exist) pHTInfo->IOTPeer = HT_IOT_PEER_AIRGO; else pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN; RTLLIB_DEBUG(RTLLIB_DL_IOT, "Joseph debug!! IOTPEER: %x\n", pHTInfo->IOTPeer); } static u8 HTIOTActIsDisableMCS14(struct rtllib_device *ieee, u8 *PeerMacAddr) { return 0; } static bool HTIOTActIsDisableMCS15(struct rtllib_device *ieee) { bool retValue = false; return retValue; } static bool HTIOTActIsDisableMCSTwoSpatialStream(struct rtllib_device *ieee) { return false; } static u8 HTIOTActIsDisableEDCATurbo(struct rtllib_device *ieee, u8 *PeerMacAddr) { return false; } static u8 HTIOTActIsMgntUseCCK6M(struct rtllib_device *ieee, struct rtllib_network *network) { u8 retValue = 0; if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) retValue = 1; return retValue; } static u8 HTIOTActIsCCDFsync(struct rtllib_device *ieee) { u8 retValue = 0; if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) retValue = 1; return retValue; } static void HTIOTActDetermineRaFunc(struct rtllib_device *ieee, bool bPeerRx2ss) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; pHTInfo->IOTRaFunc &= HT_IOT_RAFUNC_DISABLE_ALL; if (pHTInfo->IOTPeer == HT_IOT_PEER_RALINK && !bPeerRx2ss) pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_PEER_1R; if (pHTInfo->IOTAction & HT_IOT_ACT_AMSDU_ENABLE) pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_TX_AMSDU; } void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo) { pHTInfo->IOTAction = 0; pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN; pHTInfo->IOTRaFunc = 0; } void HTConstructCapabilityElement(struct rtllib_device *ieee, u8 *posHTCap, u8 *len, u8 IsEncrypt, bool bAssoc) { struct rt_hi_throughput *pHT = ieee->pHTInfo; struct ht_capab_ele *pCapELE = NULL; if ((posHTCap == NULL) || (pHT == NULL)) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "posHTCap or pHTInfo can't be " "null in HTConstructCapabilityElement()\n"); return; } memset(posHTCap, 0, *len); if ((bAssoc) && (pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)) { u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap)); pCapELE = (struct ht_capab_ele *)&(posHTCap[4]); *len = 30 + 2; } else { pCapELE = (struct ht_capab_ele *)posHTCap; *len = 26 + 2; } pCapELE->AdvCoding = 0; if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) pCapELE->ChlWidth = 0; else pCapELE->ChlWidth = (pHT->bRegBW40MHz ? 1 : 0); pCapELE->MimoPwrSave = pHT->SelfMimoPs; pCapELE->GreenField = 0; pCapELE->ShortGI20Mhz = 1; pCapELE->ShortGI40Mhz = 1; pCapELE->TxSTBC = 1; pCapELE->RxSTBC = 0; pCapELE->DelayBA = 0; pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0; pCapELE->DssCCk = ((pHT->bRegBW40MHz) ? (pHT->bRegSuppCCK ? 1 : 0) : 0); pCapELE->PSMP = 0; pCapELE->LSigTxopProtect = 0; RTLLIB_DEBUG(RTLLIB_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d " "DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk); if (IsEncrypt) { pCapELE->MPDUDensity = 7; pCapELE->MaxRxAMPDUFactor = 2; } else { pCapELE->MaxRxAMPDUFactor = 3; pCapELE->MPDUDensity = 0; } memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16); memset(&pCapELE->ExtHTCapInfo, 0, 2); memset(pCapELE->TxBFCap, 0, 4); pCapELE->ASCap = 0; if (bAssoc) { if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15) pCapELE->MCS[1] &= 0x7f; if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14) pCapELE->MCS[1] &= 0xbf; if (pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS) pCapELE->MCS[1] &= 0x00; if (pHT->IOTAction & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI) pCapELE->ShortGI40Mhz = 0; if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) { pCapELE->ChlWidth = 0; pCapELE->MCS[1] = 0; } } return; } void HTConstructInfoElement(struct rtllib_device *ieee, u8 *posHTInfo, u8 *len, u8 IsEncrypt) { struct rt_hi_throughput *pHT = ieee->pHTInfo; struct ht_info_ele *pHTInfoEle = (struct ht_info_ele *)posHTInfo; if ((posHTInfo == NULL) || (pHTInfoEle == NULL)) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "posHTInfo or pHTInfoEle can't be " "null in HTConstructInfoElement()\n"); return; } memset(posHTInfo, 0, *len); if ((ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) { pHTInfoEle->ControlChl = ieee->current_network.channel; pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false) ? HT_EXTCHNL_OFFSET_NO_EXT : (ieee->current_network.channel <= 6) ? HT_EXTCHNL_OFFSET_UPPER : HT_EXTCHNL_OFFSET_LOWER); pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz; pHTInfoEle->RIFS = 0; pHTInfoEle->PSMPAccessOnly = 0; pHTInfoEle->SrvIntGranularity = 0; pHTInfoEle->OptMode = pHT->CurrentOpMode; pHTInfoEle->NonGFDevPresent = 0; pHTInfoEle->DualBeacon = 0; pHTInfoEle->SecondaryBeacon = 0; pHTInfoEle->LSigTxopProtectFull = 0; pHTInfoEle->PcoActive = 0; pHTInfoEle->PcoPhase = 0; memset(pHTInfoEle->BasicMSC, 0, 16); *len = 22 + 2; } else { *len = 0; } return; } void HTConstructRT2RTAggElement(struct rtllib_device *ieee, u8 *posRT2RTAgg, u8 *len) { if (posRT2RTAgg == NULL) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "posRT2RTAgg can't be null in " "HTConstructRT2RTAggElement()\n"); return; } memset(posRT2RTAgg, 0, *len); *posRT2RTAgg++ = 0x00; *posRT2RTAgg++ = 0xe0; *posRT2RTAgg++ = 0x4c; *posRT2RTAgg++ = 0x02; *posRT2RTAgg++ = 0x01; *posRT2RTAgg = 0x30; if (ieee->bSupportRemoteWakeUp) *posRT2RTAgg |= RT_HT_CAP_USE_WOW; *len = 6 + 2; return; } static u8 HT_PickMCSRate(struct rtllib_device *ieee, u8 *pOperateMCS) { u8 i; if (pOperateMCS == NULL) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "pOperateMCS can't be null" " in HT_PickMCSRate()\n"); return false; } switch (ieee->mode) { case IEEE_A: case IEEE_B: case IEEE_G: for (i = 0; i <= 15; i++) pOperateMCS[i] = 0; break; case IEEE_N_24G: case IEEE_N_5G: pOperateMCS[0] &= RATE_ADPT_1SS_MASK; pOperateMCS[1] &= RATE_ADPT_2SS_MASK; pOperateMCS[3] &= RATE_ADPT_MCS32_MASK; break; default: break; } return true; } u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet, u8 *pMCSFilter) { u8 i, j; u8 bitMap; u8 mcsRate = 0; u8 availableMcsRate[16]; if (pMCSRateSet == NULL || pMCSFilter == NULL) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "pMCSRateSet or pMCSFilter can't " "be null in HTGetHighestMCSRate()\n"); return false; } for (i = 0; i < 16; i++) availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i]; for (i = 0; i < 16; i++) { if (availableMcsRate[i] != 0) break; } if (i == 16) return false; for (i = 0; i < 16; i++) { if (availableMcsRate[i] != 0) { bitMap = availableMcsRate[i]; for (j = 0; j < 8; j++) { if ((bitMap%2) != 0) { if (HTMcsToDataRate(ieee, (8*i+j)) > HTMcsToDataRate(ieee, mcsRate)) mcsRate = (8*i+j); } bitMap = bitMap>>1; } } } return mcsRate | 0x80; } u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS, u8 *pOperateMCS) { u8 i; for (i = 0; i <= 15; i++) pOperateMCS[i] = ieee->Regdot11TxHTOperationalRateSet[i] & pSupportMCS[i]; HT_PickMCSRate(ieee, pOperateMCS); if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) pOperateMCS[1] = 0; for (i = 2; i <= 15; i++) pOperateMCS[i] = 0; return true; } void HTSetConnectBwMode(struct rtllib_device *ieee, enum ht_channel_width Bandwidth, enum ht_extchnl_offset Offset); void HTOnAssocRsp(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; struct ht_capab_ele *pPeerHTCap = NULL; struct ht_info_ele *pPeerHTInfo = NULL; u16 nMaxAMSDUSize = 0; u8 *pMcsFilter = NULL; static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; if (pHTInfo->bCurrentHTSupport == false) { RTLLIB_DEBUG(RTLLIB_DL_ERR, "<=== HTOnAssocRsp(): " "HT_DISABLE\n"); return; } RTLLIB_DEBUG(RTLLIB_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n"); if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap))) pPeerHTCap = (struct ht_capab_ele *)(&pHTInfo->PeerHTCapBuf[4]); else pPeerHTCap = (struct ht_capab_ele *)(pHTInfo->PeerHTCapBuf); if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo))) pPeerHTInfo = (struct ht_info_ele *) (&pHTInfo->PeerHTInfoBuf[4]); else pPeerHTInfo = (struct ht_info_ele *)(pHTInfo->PeerHTInfoBuf); RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA | RTLLIB_DL_HT, pPeerHTCap, sizeof(struct ht_capab_ele)); HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth), (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset)); pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ? true : false); pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ? ((pPeerHTCap->ShortGI20Mhz == 1) ? true : false) : false); pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ? ((pPeerHTCap->ShortGI40Mhz == 1) ? true : false) : false); pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ? ((pPeerHTCap->DssCCk == 1) ? true : false) : false); pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support; nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize == 0) ? 3839 : 7935; if (pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize) pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize; else pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable; if (ieee->rtllib_ap_sec_type && (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP))) { if ((pHTInfo->IOTPeer == HT_IOT_PEER_ATHEROS) || (pHTInfo->IOTPeer == HT_IOT_PEER_UNKNOWN)) pHTInfo->bCurrentAMPDUEnable = false; } if (!pHTInfo->bRegRT2RTAggregation) { if (pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor) pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor; else pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; } else { if (ieee->current_network.bssht.bdRT2RTAggregation) { if (ieee->pairwise_key_type != KEY_TYPE_NA) pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor; else pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K; } else { if (pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K) pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor; else pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K; } } if (pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity) pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density; else pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity; if (pHTInfo->IOTAction & HT_IOT_ACT_TX_USE_AMSDU_8K) { pHTInfo->bCurrentAMPDUEnable = false; pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE; pHTInfo->ForcedAMSDUMaxSize = 7935; } pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable; if (pPeerHTCap->MCS[0] == 0) pPeerHTCap->MCS[0] = 0xff; HTIOTActDetermineRaFunc(ieee, ((pPeerHTCap->MCS[1]) != 0)); HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet); pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave; if (pHTInfo->PeerMimoPs == MIMO_PS_STATIC) pMcsFilter = MCS_FILTER_1SS; else pMcsFilter = MCS_FILTER_ALL; ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, pMcsFilter); ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode; } void HTInitializeHTInfo(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; RTLLIB_DEBUG(RTLLIB_DL_HT, "===========>%s()\n", __func__); pHTInfo->bCurrentHTSupport = false; pHTInfo->bCurBW40MHz = false; pHTInfo->bCurTxBW40MHz = false; pHTInfo->bCurShortGI20MHz = false; pHTInfo->bCurShortGI40MHz = false; pHTInfo->bForcedShortGI = false; pHTInfo->bCurSuppCCK = true; pHTInfo->bCurrent_AMSDU_Support = false; pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density; pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; memset((void *)(&(pHTInfo->SelfHTCap)), 0, sizeof(pHTInfo->SelfHTCap)); memset((void *)(&(pHTInfo->SelfHTInfo)), 0, sizeof(pHTInfo->SelfHTInfo)); memset((void *)(&(pHTInfo->PeerHTCapBuf)), 0, sizeof(pHTInfo->PeerHTCapBuf)); memset((void *)(&(pHTInfo->PeerHTInfoBuf)), 0, sizeof(pHTInfo->PeerHTInfoBuf)); pHTInfo->bSwBwInProgress = false; pHTInfo->ChnlOp = CHNLOP_NONE; pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE; pHTInfo->bCurrentRT2RTAggregation = false; pHTInfo->bCurrentRT2RTLongSlotTime = false; pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; pHTInfo->IOTPeer = 0; pHTInfo->IOTAction = 0; pHTInfo->IOTRaFunc = 0; { u8 *RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]); RegHTSuppRateSets[0] = 0xFF; RegHTSuppRateSets[1] = 0xFF; RegHTSuppRateSets[4] = 0x01; } } void HTInitializeBssDesc(struct bss_ht *pBssHT) { pBssHT->bdSupportHT = false; memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf)); pBssHT->bdHTCapLen = 0; memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf)); pBssHT->bdHTInfoLen = 0; pBssHT->bdHTSpecVer = HT_SPEC_VER_IEEE; pBssHT->bdRT2RTAggregation = false; pBssHT->bdRT2RTLongSlotTime = false; pBssHT->RT2RT_HT_Mode = (enum rt_ht_capability)0; } void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee, struct rtllib_network *pNetwork) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; u8 bIOTAction = 0; RTLLIB_DEBUG(RTLLIB_DL_HT, "==============>%s()\n", __func__); /* unmark bEnableHT flag here is the same reason why unmarked in * function rtllib_softmac_new_net. WB 2008.09.10*/ if (pNetwork->bssht.bdSupportHT) { pHTInfo->bCurrentHTSupport = true; pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer; if (pNetwork->bssht.bdHTCapLen > 0 && pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf)) memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen); if (pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf)) memcpy(pHTInfo->PeerHTInfoBuf, pNetwork->bssht.bdHTInfoBuf, pNetwork->bssht.bdHTInfoLen); if (pHTInfo->bRegRT2RTAggregation) { pHTInfo->bCurrentRT2RTAggregation = pNetwork->bssht.bdRT2RTAggregation; pHTInfo->bCurrentRT2RTLongSlotTime = pNetwork->bssht.bdRT2RTLongSlotTime; pHTInfo->RT2RT_HT_Mode = pNetwork->bssht.RT2RT_HT_Mode; } else { pHTInfo->bCurrentRT2RTAggregation = false; pHTInfo->bCurrentRT2RTLongSlotTime = false; pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; } HTIOTPeerDetermine(ieee); pHTInfo->IOTAction = 0; bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14; bIOTAction = HTIOTActIsDisableMCS15(ieee); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15; bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS; bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO; bIOTAction = HTIOTActIsMgntUseCCK6M(ieee, pNetwork); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M; bIOTAction = HTIOTActIsCCDFsync(ieee); if (bIOTAction) pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC; } else { pHTInfo->bCurrentHTSupport = false; pHTInfo->bCurrentRT2RTAggregation = false; pHTInfo->bCurrentRT2RTLongSlotTime = false; pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; pHTInfo->IOTAction = 0; pHTInfo->IOTRaFunc = 0; } } void HT_update_self_and_peer_setting(struct rtllib_device *ieee, struct rtllib_network *pNetwork) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; struct ht_info_ele *pPeerHTInfo = (struct ht_info_ele *)pNetwork->bssht.bdHTInfoBuf; if (pHTInfo->bCurrentHTSupport) { if (pNetwork->bssht.bdHTInfoLen != 0) pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode; } } EXPORT_SYMBOL(HT_update_self_and_peer_setting); void HTUseDefaultSetting(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; if (pHTInfo->bEnableHT) { pHTInfo->bCurrentHTSupport = true; pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK; pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz; pHTInfo->bCurShortGI20MHz = pHTInfo->bRegShortGI20MHz; pHTInfo->bCurShortGI40MHz = pHTInfo->bRegShortGI40MHz; if (ieee->iw_mode == IW_MODE_ADHOC) ieee->current_network.qos_data.active = ieee->current_network.qos_data.supported; pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support; pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable; pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; pHTInfo->CurrentMPDUDensity = pHTInfo->CurrentMPDUDensity; HTFilterMCSRate(ieee, ieee->Regdot11TxHTOperationalRateSet, ieee->dot11HTOperationalRateSet); ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, MCS_FILTER_ALL); ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; } else { pHTInfo->bCurrentHTSupport = false; } return; } u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame) { if (ieee->pHTInfo->bCurrentHTSupport) { if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) { RTLLIB_DEBUG(RTLLIB_DL_HT, "HT CONTROL FILED " "EXIST!!\n"); return true; } } return false; } static void HTSetConnectBwModeCallback(struct rtllib_device *ieee) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; RTLLIB_DEBUG(RTLLIB_DL_HT, "======>%s()\n", __func__); if (pHTInfo->bCurBW40MHz) { if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER) ieee->set_chan(ieee->dev, ieee->current_network.channel + 2); else if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_LOWER) ieee->set_chan(ieee->dev, ieee->current_network.channel - 2); else ieee->set_chan(ieee->dev, ieee->current_network.channel); ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset); } else { ieee->set_chan(ieee->dev, ieee->current_network.channel); ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); } pHTInfo->bSwBwInProgress = false; } void HTSetConnectBwMode(struct rtllib_device *ieee, enum ht_channel_width Bandwidth, enum ht_extchnl_offset Offset) { struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; if (pHTInfo->bRegBW40MHz == false) return; if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) Bandwidth = HT_CHANNEL_WIDTH_20; if (pHTInfo->bSwBwInProgress) { printk(KERN_INFO "%s: bSwBwInProgress!!\n", __func__); return; } if (Bandwidth == HT_CHANNEL_WIDTH_20_40) { if (ieee->current_network.channel < 2 && Offset == HT_EXTCHNL_OFFSET_LOWER) Offset = HT_EXTCHNL_OFFSET_NO_EXT; if (Offset == HT_EXTCHNL_OFFSET_UPPER || Offset == HT_EXTCHNL_OFFSET_LOWER) { pHTInfo->bCurBW40MHz = true; pHTInfo->CurSTAExtChnlOffset = Offset; } else { pHTInfo->bCurBW40MHz = false; pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; } } else { pHTInfo->bCurBW40MHz = false; pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; } printk(KERN_INFO "%s():pHTInfo->bCurBW40MHz:%x\n", __func__, pHTInfo->bCurBW40MHz); pHTInfo->bSwBwInProgress = true; HTSetConnectBwModeCallback(ieee); }
gpl-2.0
RoGod/Kernel_SleeDry_HTC
drivers/net/wireless/compat-wireless_R5.SP2.03/drivers/net/wireless/b43legacy/rfkill.c
9277
2661
/* Broadcom B43 wireless driver RFKILL support Copyright (c) 2007 Michael Buesch <m@bues.ch> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "radio.h" #include "b43legacy.h" /* Returns TRUE, if the radio is enabled in hardware. */ bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev) { if (dev->dev->id.revision >= 3) { if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI) & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK)) return 1; } else { /* To prevent CPU fault on PPC, do not read a register * unless the interface is started; however, on resume * for hibernation, this routine is entered early. When * that happens, unconditionally return TRUE. */ if (b43legacy_status(dev) < B43legacy_STAT_STARTED) return 1; if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO) & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK) return 1; } return 0; } /* The poll callback for the hardware button. */ void b43legacy_rfkill_poll(struct ieee80211_hw *hw) { struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw); struct b43legacy_wldev *dev = wl->current_dev; struct ssb_bus *bus = dev->dev->bus; bool enabled; bool brought_up = false; mutex_lock(&wl->mutex); if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) { if (ssb_bus_powerup(bus, 0)) { mutex_unlock(&wl->mutex); return; } ssb_device_enable(dev->dev, 0); brought_up = true; } enabled = b43legacy_is_hw_radio_enabled(dev); if (unlikely(enabled != dev->radio_hw_enable)) { dev->radio_hw_enable = enabled; b43legacyinfo(wl, "Radio hardware status changed to %s\n", enabled ? "ENABLED" : "DISABLED"); wiphy_rfkill_set_hw_state(hw->wiphy, !enabled); if (enabled != dev->phy.radio_on) { if (enabled) b43legacy_radio_turn_on(dev); else b43legacy_radio_turn_off(dev, 0); } } if (brought_up) { ssb_device_disable(dev->dev, 0); ssb_bus_may_powerdown(bus); } mutex_unlock(&wl->mutex); }
gpl-2.0
mkasick/android_kernel_samsung_d2vzw
arch/x86/kernel/doublefault_32.c
9789
1695
#include <linux/mm.h> #include <linux/sched.h> #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/processor.h> #include <asm/desc.h> #define DOUBLEFAULT_STACKSIZE (1024) static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE]; #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE) #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM) static void doublefault_fn(void) { struct desc_ptr gdt_desc = {0, 0}; unsigned long gdt, tss; store_gdt(&gdt_desc); gdt = gdt_desc.address; printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size); if (ptr_ok(gdt)) { gdt += GDT_ENTRY_TSS << 3; tss = get_desc_base((struct desc_struct *)gdt); printk(KERN_EMERG "double fault, tss at %08lx\n", tss); if (ptr_ok(tss)) { struct x86_hw_tss *t = (struct x86_hw_tss *)tss; printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", t->ip, t->sp); printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n", t->ax, t->bx, t->cx, t->dx); printk(KERN_EMERG "esi = %08lx, edi = %08lx\n", t->si, t->di); } } for (;;) cpu_relax(); } struct tss_struct doublefault_tss __cacheline_aligned = { .x86_tss = { .sp0 = STACK_START, .ss0 = __KERNEL_DS, .ldt = 0, .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, .ip = (unsigned long) doublefault_fn, /* 0x2 bit is always set */ .flags = X86_EFLAGS_SF | 0x2, .sp = STACK_START, .es = __USER_DS, .cs = __KERNEL_CS, .ss = __KERNEL_DS, .ds = __USER_DS, .fs = __KERNEL_PERCPU, .__cr3 = __pa_nodebug(swapper_pg_dir), } };
gpl-2.0
zhenyw/linux
drivers/pcmcia/pxa2xx_palmld.c
9789
2802
/* * linux/drivers/pcmcia/pxa2xx_palmld.c * * Driver for Palm LifeDrive PCMCIA * * Copyright (C) 2006 Alex Osborne <ato@meshy.org> * Copyright (C) 2007-2011 Marek Vasut <marek.vasut@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include <linux/module.h> #include <linux/platform_device.h> #include <linux/gpio.h> #include <asm/mach-types.h> #include <mach/palmld.h> #include "soc_common.h" static struct gpio palmld_pcmcia_gpios[] = { { GPIO_NR_PALMLD_PCMCIA_POWER, GPIOF_INIT_LOW, "PCMCIA Power" }, { GPIO_NR_PALMLD_PCMCIA_RESET, GPIOF_INIT_HIGH,"PCMCIA Reset" }, }; static int palmld_pcmcia_hw_init(struct soc_pcmcia_socket *skt) { int ret; ret = gpio_request_array(palmld_pcmcia_gpios, ARRAY_SIZE(palmld_pcmcia_gpios)); skt->stat[SOC_STAT_RDY].gpio = GPIO_NR_PALMLD_PCMCIA_READY; skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready"; return ret; } static void palmld_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) { gpio_free_array(palmld_pcmcia_gpios, ARRAY_SIZE(palmld_pcmcia_gpios)); } static void palmld_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) { state->detect = 1; /* always inserted */ state->vs_3v = 1; state->vs_Xv = 0; } static int palmld_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) { gpio_set_value(GPIO_NR_PALMLD_PCMCIA_POWER, 1); gpio_set_value(GPIO_NR_PALMLD_PCMCIA_RESET, !!(state->flags & SS_RESET)); return 0; } static struct pcmcia_low_level palmld_pcmcia_ops = { .owner = THIS_MODULE, .first = 1, .nr = 1, .hw_init = palmld_pcmcia_hw_init, .hw_shutdown = palmld_pcmcia_hw_shutdown, .socket_state = palmld_pcmcia_socket_state, .configure_socket = palmld_pcmcia_configure_socket, }; static struct platform_device *palmld_pcmcia_device; static int __init palmld_pcmcia_init(void) { int ret; if (!machine_is_palmld()) return -ENODEV; palmld_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); if (!palmld_pcmcia_device) return -ENOMEM; ret = platform_device_add_data(palmld_pcmcia_device, &palmld_pcmcia_ops, sizeof(palmld_pcmcia_ops)); if (!ret) ret = platform_device_add(palmld_pcmcia_device); if (ret) platform_device_put(palmld_pcmcia_device); return ret; } static void __exit palmld_pcmcia_exit(void) { platform_device_unregister(palmld_pcmcia_device); } module_init(palmld_pcmcia_init); module_exit(palmld_pcmcia_exit); MODULE_AUTHOR("Alex Osborne <ato@meshy.org>," " Marek Vasut <marek.vasut@gmail.com>"); MODULE_DESCRIPTION("PCMCIA support for Palm LifeDrive"); MODULE_ALIAS("platform:pxa2xx-pcmcia"); MODULE_LICENSE("GPL");
gpl-2.0
existz/htc-kernel-msm7x30
arch/h8300/platform/h8300h/ptrace_h8300h.c
10813
8568
/* * linux/arch/h8300/platform/h8300h/ptrace_h8300h.c * ptrace cpu depend helper functions * * Yoshinori Sato <ysato@users.sourceforge.jp> * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of * this archive for more details. */ #include <linux/linkage.h> #include <linux/sched.h> #include <asm/ptrace.h> #define CCR_MASK 0x6f /* mode/imask not set */ #define BREAKINST 0x5730 /* trapa #3 */ /* Mapping from PT_xxx to the stack offset at which the register is saved. Notice that usp has no stack-slot and needs to be treated specially (see get_reg/put_reg below). */ static const int h8300_register_offset[] = { PT_REG(er1), PT_REG(er2), PT_REG(er3), PT_REG(er4), PT_REG(er5), PT_REG(er6), PT_REG(er0), PT_REG(orig_er0), PT_REG(ccr), PT_REG(pc) }; /* read register */ long h8300_get_reg(struct task_struct *task, int regno) { switch (regno) { case PT_USP: return task->thread.usp + sizeof(long)*2; case PT_CCR: return *(unsigned short *)(task->thread.esp0 + h8300_register_offset[regno]); default: return *(unsigned long *)(task->thread.esp0 + h8300_register_offset[regno]); } } /* write register */ int h8300_put_reg(struct task_struct *task, int regno, unsigned long data) { unsigned short oldccr; switch (regno) { case PT_USP: task->thread.usp = data - sizeof(long)*2; case PT_CCR: oldccr = *(unsigned short *)(task->thread.esp0 + h8300_register_offset[regno]); oldccr &= ~CCR_MASK; data &= CCR_MASK; data |= oldccr; *(unsigned short *)(task->thread.esp0 + h8300_register_offset[regno]) = data; break; default: *(unsigned long *)(task->thread.esp0 + h8300_register_offset[regno]) = data; break; } return 0; } /* disable singlestep */ void user_disable_single_step(struct task_struct *child) { if((long)child->thread.breakinfo.addr != -1L) { *child->thread.breakinfo.addr = child->thread.breakinfo.inst; child->thread.breakinfo.addr = (unsigned short *)-1L; } } /* calculate next pc */ enum jump_type {none, /* normal instruction */ jabs, /* absolute address jump */ ind, /* indirect address jump */ ret, /* return to subrutine */ reg, /* register indexed jump */ relb, /* pc relative jump (byte offset) */ relw, /* pc relative jump (word offset) */ }; /* opcode decode table define ptn: opcode pattern msk: opcode bitmask len: instruction length (<0 next table index) jmp: jump operation mode */ struct optable { unsigned char bitpattern; unsigned char bitmask; signed char length; signed char type; } __attribute__((aligned(1),packed)); #define OPTABLE(ptn,msk,len,jmp) \ { \ .bitpattern = ptn, \ .bitmask = msk, \ .length = len, \ .type = jmp, \ } static const struct optable optable_0[] = { OPTABLE(0x00,0xff, 1,none), /* 0x00 */ OPTABLE(0x01,0xff,-1,none), /* 0x01 */ OPTABLE(0x02,0xfe, 1,none), /* 0x02-0x03 */ OPTABLE(0x04,0xee, 1,none), /* 0x04-0x05/0x14-0x15 */ OPTABLE(0x06,0xfe, 1,none), /* 0x06-0x07 */ OPTABLE(0x08,0xea, 1,none), /* 0x08-0x09/0x0c-0x0d/0x18-0x19/0x1c-0x1d */ OPTABLE(0x0a,0xee, 1,none), /* 0x0a-0x0b/0x1a-0x1b */ OPTABLE(0x0e,0xee, 1,none), /* 0x0e-0x0f/0x1e-0x1f */ OPTABLE(0x10,0xfc, 1,none), /* 0x10-0x13 */ OPTABLE(0x16,0xfe, 1,none), /* 0x16-0x17 */ OPTABLE(0x20,0xe0, 1,none), /* 0x20-0x3f */ OPTABLE(0x40,0xf0, 1,relb), /* 0x40-0x4f */ OPTABLE(0x50,0xfc, 1,none), /* 0x50-0x53 */ OPTABLE(0x54,0xfd, 1,ret ), /* 0x54/0x56 */ OPTABLE(0x55,0xff, 1,relb), /* 0x55 */ OPTABLE(0x57,0xff, 1,none), /* 0x57 */ OPTABLE(0x58,0xfb, 2,relw), /* 0x58/0x5c */ OPTABLE(0x59,0xfb, 1,reg ), /* 0x59/0x5b */ OPTABLE(0x5a,0xfb, 2,jabs), /* 0x5a/0x5e */ OPTABLE(0x5b,0xfb, 2,ind ), /* 0x5b/0x5f */ OPTABLE(0x60,0xe8, 1,none), /* 0x60-0x67/0x70-0x77 */ OPTABLE(0x68,0xfa, 1,none), /* 0x68-0x69/0x6c-0x6d */ OPTABLE(0x6a,0xfe,-2,none), /* 0x6a-0x6b */ OPTABLE(0x6e,0xfe, 2,none), /* 0x6e-0x6f */ OPTABLE(0x78,0xff, 4,none), /* 0x78 */ OPTABLE(0x79,0xff, 2,none), /* 0x79 */ OPTABLE(0x7a,0xff, 3,none), /* 0x7a */ OPTABLE(0x7b,0xff, 2,none), /* 0x7b */ OPTABLE(0x7c,0xfc, 2,none), /* 0x7c-0x7f */ OPTABLE(0x80,0x80, 1,none), /* 0x80-0xff */ }; static const struct optable optable_1[] = { OPTABLE(0x00,0xff,-3,none), /* 0x0100 */ OPTABLE(0x40,0xf0,-3,none), /* 0x0140-0x14f */ OPTABLE(0x80,0xf0, 1,none), /* 0x0180-0x018f */ OPTABLE(0xc0,0xc0, 2,none), /* 0x01c0-0x01ff */ }; static const struct optable optable_2[] = { OPTABLE(0x00,0x20, 2,none), /* 0x6a0?/0x6a8?/0x6b0?/0x6b8? */ OPTABLE(0x20,0x20, 3,none), /* 0x6a2?/0x6aa?/0x6b2?/0x6ba? */ }; static const struct optable optable_3[] = { OPTABLE(0x69,0xfb, 2,none), /* 0x010069/0x01006d/014069/0x01406d */ OPTABLE(0x6b,0xff,-4,none), /* 0x01006b/0x01406b */ OPTABLE(0x6f,0xff, 3,none), /* 0x01006f/0x01406f */ OPTABLE(0x78,0xff, 5,none), /* 0x010078/0x014078 */ }; static const struct optable optable_4[] = { OPTABLE(0x00,0x78, 3,none), /* 0x0100690?/0x01006d0?/0140690/0x01406d0?/0x0100698?/0x01006d8?/0140698?/0x01406d8? */ OPTABLE(0x20,0x78, 4,none), /* 0x0100692?/0x01006d2?/0140692/0x01406d2?/0x010069a?/0x01006da?/014069a?/0x01406da? */ }; static const struct optables_list { const struct optable *ptr; int size; } optables[] = { #define OPTABLES(no) \ { \ .ptr = optable_##no, \ .size = sizeof(optable_##no) / sizeof(struct optable), \ } OPTABLES(0), OPTABLES(1), OPTABLES(2), OPTABLES(3), OPTABLES(4), }; const unsigned char condmask[] = { 0x00,0x40,0x01,0x04,0x02,0x08,0x10,0x20 }; static int isbranch(struct task_struct *task,int reson) { unsigned char cond = h8300_get_reg(task, PT_CCR); /* encode complex conditions */ /* B4: N^V B5: Z|(N^V) B6: C|Z */ __asm__("bld #3,%w0\n\t" "bxor #1,%w0\n\t" "bst #4,%w0\n\t" "bor #2,%w0\n\t" "bst #5,%w0\n\t" "bld #2,%w0\n\t" "bor #0,%w0\n\t" "bst #6,%w0\n\t" :"=&r"(cond)::"cc"); cond &= condmask[reson >> 1]; if (!(reson & 1)) return cond == 0; else return cond != 0; } static unsigned short *getnextpc(struct task_struct *child, unsigned short *pc) { const struct optable *op; unsigned char *fetch_p; unsigned char inst; unsigned long addr; unsigned long *sp; int op_len,regno; op = optables[0].ptr; op_len = optables[0].size; fetch_p = (unsigned char *)pc; inst = *fetch_p++; do { if ((inst & op->bitmask) == op->bitpattern) { if (op->length < 0) { op = optables[-op->length].ptr; op_len = optables[-op->length].size + 1; inst = *fetch_p++; } else { switch (op->type) { case none: return pc + op->length; case jabs: addr = *(unsigned long *)pc; return (unsigned short *)(addr & 0x00ffffff); case ind: addr = *pc & 0xff; return (unsigned short *)(*(unsigned long *)addr); case ret: sp = (unsigned long *)h8300_get_reg(child, PT_USP); /* user stack frames | er0 | temporary saved +--------+ | exp | exception stack frames +--------+ | ret pc | userspace return address */ return (unsigned short *)(*(sp+2) & 0x00ffffff); case reg: regno = (*pc >> 4) & 0x07; if (regno == 0) addr = h8300_get_reg(child, PT_ER0); else addr = h8300_get_reg(child, regno-1+PT_ER1); return (unsigned short *)addr; case relb: if (inst == 0x55 || isbranch(child,inst & 0x0f)) pc = (unsigned short *)((unsigned long)pc + ((signed char)(*fetch_p))); return pc+1; /* skip myself */ case relw: if (inst == 0x5c || isbranch(child,(*fetch_p & 0xf0) >> 4)) pc = (unsigned short *)((unsigned long)pc + ((signed short)(*(pc+1)))); return pc+2; /* skip myself */ } } } else op++; } while(--op_len > 0); return NULL; } /* Set breakpoint(s) to simulate a single step from the current PC. */ void user_enable_single_step(struct task_struct *child) { unsigned short *nextpc; nextpc = getnextpc(child,(unsigned short *)h8300_get_reg(child, PT_PC)); child->thread.breakinfo.addr = nextpc; child->thread.breakinfo.inst = *nextpc; *nextpc = BREAKINST; } asmlinkage void trace_trap(unsigned long bp) { if ((unsigned long)current->thread.breakinfo.addr == bp) { user_disable_single_step(current); force_sig(SIGTRAP,current); } else force_sig(SIGILL,current); }
gpl-2.0
jcbless/linux-xlnx
drivers/media/usb/dvb-usb-v2/rtl28xxu.c
62
46386
/* * Realtek RTL28xxU DVB USB driver * * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> * Copyright (C) 2011 Antti Palosaari <crope@iki.fi> * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "rtl28xxu.h" static int rtl28xxu_disable_rc; module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644); MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller"); DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req) { struct rtl28xxu_dev *dev = d->priv; int ret; unsigned int pipe; u8 requesttype; if (req->index & CMD_WR_FLAG) { /* write */ memcpy(dev->buf, req->data, req->size); requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT); pipe = usb_sndctrlpipe(d->udev, 0); } else { /* read */ requesttype = (USB_TYPE_VENDOR | USB_DIR_IN); pipe = usb_rcvctrlpipe(d->udev, 0); } ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value, req->index, dev->buf, req->size, 1000); dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value, req->index, dev->buf, req->size); if (ret < 0) goto err; /* read request, copy returned data to return buf */ if (requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) memcpy(req->data, dev->buf, req->size); return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl28xxu_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) { struct rtl28xxu_req req; if (reg < 0x3000) req.index = CMD_USB_WR; else if (reg < 0x4000) req.index = CMD_SYS_WR; else req.index = CMD_IR_WR; req.value = reg; req.size = len; req.data = val; return rtl28xxu_ctrl_msg(d, &req); } static int rtl28xxu_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) { struct rtl28xxu_req req; if (reg < 0x3000) req.index = CMD_USB_RD; else if (reg < 0x4000) req.index = CMD_SYS_RD; else req.index = CMD_IR_RD; req.value = reg; req.size = len; req.data = val; return rtl28xxu_ctrl_msg(d, &req); } static int rtl28xxu_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val) { return rtl28xxu_wr_regs(d, reg, &val, 1); } static int rtl28xxu_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val) { return rtl28xxu_rd_regs(d, reg, val, 1); } static int rtl28xxu_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val, u8 mask) { int ret; u8 tmp; /* no need for read if whole reg is written */ if (mask != 0xff) { ret = rtl28xxu_rd_reg(d, reg, &tmp); if (ret) return ret; val &= mask; tmp &= ~mask; val |= tmp; } return rtl28xxu_wr_reg(d, reg, val); } /* I2C */ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) { int ret; struct dvb_usb_device *d = i2c_get_adapdata(adap); struct rtl28xxu_dev *dev = d->priv; struct rtl28xxu_req req; /* * It is not known which are real I2C bus xfer limits, but testing * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes. * TODO: find out RTL2832U lens */ /* * I2C adapter logic looks rather complicated due to fact it handles * three different access methods. Those methods are; * 1) integrated demod access * 2) old I2C access * 3) new I2C access * * Used method is selected in order 1, 2, 3. Method 3 can handle all * requests but there is two reasons why not use it always; * 1) It is most expensive, usually two USB messages are needed * 2) At least RTL2831U does not support it * * Method 3 is needed in case of I2C write+read (typical register read) * where write is more than one byte. */ if (mutex_lock_interruptible(&d->i2c_mutex) < 0) return -EAGAIN; if (num == 2 && !(msg[0].flags & I2C_M_RD) && (msg[1].flags & I2C_M_RD)) { if (msg[0].len > 24 || msg[1].len > 24) { /* TODO: check msg[0].len max */ ret = -EOPNOTSUPP; goto err_mutex_unlock; } else if (msg[0].addr == 0x10) { /* method 1 - integrated demod */ req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_DEMOD_RD | dev->page; req.size = msg[1].len; req.data = &msg[1].buf[0]; ret = rtl28xxu_ctrl_msg(d, &req); } else if (msg[0].len < 2) { /* method 2 - old I2C */ req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_I2C_RD; req.size = msg[1].len; req.data = &msg[1].buf[0]; ret = rtl28xxu_ctrl_msg(d, &req); } else { /* method 3 - new I2C */ req.value = (msg[0].addr << 1); req.index = CMD_I2C_DA_WR; req.size = msg[0].len; req.data = msg[0].buf; ret = rtl28xxu_ctrl_msg(d, &req); if (ret) goto err_mutex_unlock; req.value = (msg[0].addr << 1); req.index = CMD_I2C_DA_RD; req.size = msg[1].len; req.data = msg[1].buf; ret = rtl28xxu_ctrl_msg(d, &req); } } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) { if (msg[0].len > 22) { /* TODO: check msg[0].len max */ ret = -EOPNOTSUPP; goto err_mutex_unlock; } else if (msg[0].addr == 0x10) { /* method 1 - integrated demod */ if (msg[0].buf[0] == 0x00) { /* save demod page for later demod access */ dev->page = msg[0].buf[1]; ret = 0; } else { req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_DEMOD_WR | dev->page; req.size = msg[0].len-1; req.data = &msg[0].buf[1]; ret = rtl28xxu_ctrl_msg(d, &req); } } else if (msg[0].len < 23) { /* method 2 - old I2C */ req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_I2C_WR; req.size = msg[0].len-1; req.data = &msg[0].buf[1]; ret = rtl28xxu_ctrl_msg(d, &req); } else { /* method 3 - new I2C */ req.value = (msg[0].addr << 1); req.index = CMD_I2C_DA_WR; req.size = msg[0].len; req.data = msg[0].buf; ret = rtl28xxu_ctrl_msg(d, &req); } } else { ret = -EINVAL; } err_mutex_unlock: mutex_unlock(&d->i2c_mutex); return ret ? ret : num; } static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter) { return I2C_FUNC_I2C; } static struct i2c_algorithm rtl28xxu_i2c_algo = { .master_xfer = rtl28xxu_i2c_xfer, .functionality = rtl28xxu_i2c_func, }; static int rtl2831u_read_config(struct dvb_usb_device *d) { struct rtl28xxu_dev *dev = d_to_priv(d); int ret; u8 buf[1]; /* open RTL2831U/RTL2830 I2C gate */ struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"}; /* tuner probes */ struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf}; dev_dbg(&d->intf->dev, "\n"); /* * RTL2831U GPIOs * ========================================================= * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?) * GPIO2 | LED | 0 off | 1 on | * GPIO4 | tuner#1 | 0 on | 1 off | MT2060 */ /* GPIO direction */ ret = rtl28xxu_wr_reg(d, SYS_GPIO_DIR, 0x0a); if (ret) goto err; /* enable as output GPIO0, GPIO2, GPIO4 */ ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_EN, 0x15); if (ret) goto err; /* * Probe used tuner. We need to know used tuner before demod attach * since there is some demod params needed to set according to tuner. */ /* demod needs some time to wake up */ msleep(20); dev->tuner_name = "NONE"; /* open demod I2C gate */ ret = rtl28xxu_ctrl_msg(d, &req_gate_open); if (ret) goto err; /* check QT1010 ID(?) register; reg=0f val=2c */ ret = rtl28xxu_ctrl_msg(d, &req_qt1010); if (ret == 0 && buf[0] == 0x2c) { dev->tuner = TUNER_RTL2830_QT1010; dev->tuner_name = "QT1010"; goto found; } /* open demod I2C gate */ ret = rtl28xxu_ctrl_msg(d, &req_gate_open); if (ret) goto err; /* check MT2060 ID register; reg=00 val=63 */ ret = rtl28xxu_ctrl_msg(d, &req_mt2060); if (ret == 0 && buf[0] == 0x63) { dev->tuner = TUNER_RTL2830_MT2060; dev->tuner_name = "MT2060"; goto found; } /* assume MXL5005S */ dev->tuner = TUNER_RTL2830_MXL5005S; dev->tuner_name = "MXL5005S"; goto found; found: dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name); return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2832u_read_config(struct dvb_usb_device *d) { struct rtl28xxu_dev *dev = d_to_priv(d); int ret; u8 buf[2]; /* open RTL2832U/RTL2832 I2C gate */ struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"}; /* close RTL2832U/RTL2832 I2C gate */ struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"}; /* tuner probes */ struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf}; struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; dev_dbg(&d->intf->dev, "\n"); /* enable GPIO3 and GPIO6 as output */ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40); if (ret) goto err; ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48); if (ret) goto err; /* * Probe used tuner. We need to know used tuner before demod attach * since there is some demod params needed to set according to tuner. */ /* open demod I2C gate */ ret = rtl28xxu_ctrl_msg(d, &req_gate_open); if (ret) goto err; dev->tuner_name = "NONE"; /* check FC0012 ID register; reg=00 val=a1 */ ret = rtl28xxu_ctrl_msg(d, &req_fc0012); if (ret == 0 && buf[0] == 0xa1) { dev->tuner = TUNER_RTL2832_FC0012; dev->tuner_name = "FC0012"; goto tuner_found; } /* check FC0013 ID register; reg=00 val=a3 */ ret = rtl28xxu_ctrl_msg(d, &req_fc0013); if (ret == 0 && buf[0] == 0xa3) { dev->tuner = TUNER_RTL2832_FC0013; dev->tuner_name = "FC0013"; goto tuner_found; } /* check MT2266 ID register; reg=00 val=85 */ ret = rtl28xxu_ctrl_msg(d, &req_mt2266); if (ret == 0 && buf[0] == 0x85) { dev->tuner = TUNER_RTL2832_MT2266; dev->tuner_name = "MT2266"; goto tuner_found; } /* check FC2580 ID register; reg=01 val=56 */ ret = rtl28xxu_ctrl_msg(d, &req_fc2580); if (ret == 0 && buf[0] == 0x56) { dev->tuner = TUNER_RTL2832_FC2580; dev->tuner_name = "FC2580"; goto tuner_found; } /* check MT2063 ID register; reg=00 val=9e || 9c */ ret = rtl28xxu_ctrl_msg(d, &req_mt2063); if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) { dev->tuner = TUNER_RTL2832_MT2063; dev->tuner_name = "MT2063"; goto tuner_found; } /* check MAX3543 ID register; reg=00 val=38 */ ret = rtl28xxu_ctrl_msg(d, &req_max3543); if (ret == 0 && buf[0] == 0x38) { dev->tuner = TUNER_RTL2832_MAX3543; dev->tuner_name = "MAX3543"; goto tuner_found; } /* check TUA9001 ID register; reg=7e val=2328 */ ret = rtl28xxu_ctrl_msg(d, &req_tua9001); if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) { dev->tuner = TUNER_RTL2832_TUA9001; dev->tuner_name = "TUA9001"; goto tuner_found; } /* check MXL5007R ID register; reg=d9 val=14 */ ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t); if (ret == 0 && buf[0] == 0x14) { dev->tuner = TUNER_RTL2832_MXL5007T; dev->tuner_name = "MXL5007T"; goto tuner_found; } /* check E4000 ID register; reg=02 val=40 */ ret = rtl28xxu_ctrl_msg(d, &req_e4000); if (ret == 0 && buf[0] == 0x40) { dev->tuner = TUNER_RTL2832_E4000; dev->tuner_name = "E4000"; goto tuner_found; } /* check TDA18272 ID register; reg=00 val=c760 */ ret = rtl28xxu_ctrl_msg(d, &req_tda18272); if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) { dev->tuner = TUNER_RTL2832_TDA18272; dev->tuner_name = "TDA18272"; goto tuner_found; } /* check R820T ID register; reg=00 val=69 */ ret = rtl28xxu_ctrl_msg(d, &req_r820t); if (ret == 0 && buf[0] == 0x69) { dev->tuner = TUNER_RTL2832_R820T; dev->tuner_name = "R820T"; goto tuner_found; } /* check R828D ID register; reg=00 val=69 */ ret = rtl28xxu_ctrl_msg(d, &req_r828d); if (ret == 0 && buf[0] == 0x69) { dev->tuner = TUNER_RTL2832_R828D; dev->tuner_name = "R828D"; goto tuner_found; } tuner_found: dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name); /* probe slave demod */ if (dev->tuner == TUNER_RTL2832_R828D) { /* power on MN88472 demod on GPIO0 */ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01); if (ret) goto err; ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01); if (ret) goto err; ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01); if (ret) goto err; /* check MN88472 answers */ ret = rtl28xxu_ctrl_msg(d, &req_mn88472); if (ret == 0 && buf[0] == 0x02) { dev_dbg(&d->intf->dev, "MN88472 found\n"); dev->slave_demod = SLAVE_DEMOD_MN88472; goto demod_found; } ret = rtl28xxu_ctrl_msg(d, &req_mn88473); if (ret == 0 && buf[0] == 0x03) { dev_dbg(&d->intf->dev, "MN88473 found\n"); dev->slave_demod = SLAVE_DEMOD_MN88473; goto demod_found; } } demod_found: /* close demod I2C gate */ ret = rtl28xxu_ctrl_msg(d, &req_gate_close); if (ret < 0) goto err; return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl28xxu_read_config(struct dvb_usb_device *d) { struct rtl28xxu_dev *dev = d_to_priv(d); if (dev->chip_id == CHIP_ID_RTL2831U) return rtl2831u_read_config(d); else return rtl2832u_read_config(d); } static int rtl28xxu_identify_state(struct dvb_usb_device *d, const char **name) { struct rtl28xxu_dev *dev = d_to_priv(d); int ret; struct rtl28xxu_req req_demod_i2c = {0x0020, CMD_I2C_DA_RD, 0, NULL}; dev_dbg(&d->intf->dev, "\n"); /* * Detect chip type using I2C command that is not supported * by old RTL2831U. */ ret = rtl28xxu_ctrl_msg(d, &req_demod_i2c); if (ret == -EPIPE) { dev->chip_id = CHIP_ID_RTL2831U; } else if (ret == 0) { dev->chip_id = CHIP_ID_RTL2832U; } else { dev_err(&d->intf->dev, "chip type detection failed %d\n", ret); goto err; } dev_dbg(&d->intf->dev, "chip_id=%u\n", dev->chip_id); return WARM; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static const struct rtl2830_platform_data rtl2830_mt2060_platform_data = { .clk = 28800000, .spec_inv = 1, .vtop = 0x20, .krf = 0x04, .agc_targ_val = 0x2d, }; static const struct rtl2830_platform_data rtl2830_qt1010_platform_data = { .clk = 28800000, .spec_inv = 1, .vtop = 0x20, .krf = 0x04, .agc_targ_val = 0x2d, }; static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data = { .clk = 28800000, .spec_inv = 0, .vtop = 0x3f, .krf = 0x04, .agc_targ_val = 0x3e, }; static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; struct i2c_board_info board_info; struct i2c_client *client; int ret; dev_dbg(&d->intf->dev, "\n"); switch (dev->tuner) { case TUNER_RTL2830_QT1010: *pdata = rtl2830_qt1010_platform_data; break; case TUNER_RTL2830_MT2060: *pdata = rtl2830_mt2060_platform_data; break; case TUNER_RTL2830_MXL5005S: *pdata = rtl2830_mxl5005s_platform_data; break; default: dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name); ret = -ENODEV; goto err; } /* attach demodulator */ memset(&board_info, 0, sizeof(board_info)); strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE); board_info.addr = 0x10; board_info.platform_data = pdata; request_module("%s", board_info.type); client = i2c_new_device(&d->i2c_adap, &board_info); if (client == NULL || client->dev.driver == NULL) { ret = -ENODEV; goto err; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); ret = -ENODEV; goto err; } adap->fe[0] = pdata->get_dvb_frontend(client); dev->demod_i2c_adapter = pdata->get_i2c_adapter(client); dev->i2c_client_demod = client; return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = { .clk = 28800000, .tuner = TUNER_RTL2832_FC0012 }; static const struct rtl2832_platform_data rtl2832_fc0013_platform_data = { .clk = 28800000, .tuner = TUNER_RTL2832_FC0013 }; static const struct rtl2832_platform_data rtl2832_tua9001_platform_data = { .clk = 28800000, .tuner = TUNER_RTL2832_TUA9001, }; static const struct rtl2832_platform_data rtl2832_e4000_platform_data = { .clk = 28800000, .tuner = TUNER_RTL2832_E4000, }; static const struct rtl2832_platform_data rtl2832_r820t_platform_data = { .clk = 28800000, .tuner = TUNER_RTL2832_R820T, }; static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) { int ret; u8 val; dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg); switch (cmd) { case FC_FE_CALLBACK_VHF_ENABLE: /* set output values */ ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &val); if (ret) goto err; if (arg) val &= 0xbf; /* set GPIO6 low */ else val |= 0x40; /* set GPIO6 high */ ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, val); if (ret) goto err; break; default: ret = -EINVAL; goto err; } return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) { int ret; u8 val; dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg); /* * CEN always enabled by hardware wiring * RESETN GPIO4 * RXEN GPIO1 */ switch (cmd) { case TUA9001_CMD_RESETN: if (arg) val = (1 << 4); else val = (0 << 4); ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10); if (ret) goto err; break; case TUA9001_CMD_RXEN: if (arg) val = (1 << 1); else val = (0 << 1); ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02); if (ret) goto err; break; } return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2832u_frontend_callback(void *adapter_priv, int component, int cmd, int arg) { struct i2c_adapter *adapter = adapter_priv; struct device *parent = adapter->dev.parent; struct i2c_adapter *parent_adapter; struct dvb_usb_device *d; struct rtl28xxu_dev *dev; /* * All tuners are connected to demod muxed I2C adapter. We have to * resolve its parent adapter in order to get handle for this driver * private data. That is a bit hackish solution, GPIO or direct driver * callback would be better... */ if (parent != NULL && parent->type == &i2c_adapter_type) parent_adapter = to_i2c_adapter(parent); else return -EINVAL; d = i2c_get_adapdata(parent_adapter); dev = d->priv; dev_dbg(&d->intf->dev, "component=%d cmd=%d arg=%d\n", component, cmd, arg); switch (component) { case DVB_FRONTEND_COMPONENT_TUNER: switch (dev->tuner) { case TUNER_RTL2832_FC0012: return rtl2832u_fc0012_tuner_callback(d, cmd, arg); case TUNER_RTL2832_TUA9001: return rtl2832u_tua9001_tuner_callback(d, cmd, arg); } } return 0; } static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; struct i2c_board_info board_info; struct i2c_client *client; int ret; dev_dbg(&d->intf->dev, "\n"); switch (dev->tuner) { case TUNER_RTL2832_FC0012: *pdata = rtl2832_fc0012_platform_data; break; case TUNER_RTL2832_FC0013: *pdata = rtl2832_fc0013_platform_data; break; case TUNER_RTL2832_FC2580: /* FIXME: do not abuse fc0012 settings */ *pdata = rtl2832_fc0012_platform_data; break; case TUNER_RTL2832_TUA9001: *pdata = rtl2832_tua9001_platform_data; break; case TUNER_RTL2832_E4000: *pdata = rtl2832_e4000_platform_data; break; case TUNER_RTL2832_R820T: case TUNER_RTL2832_R828D: *pdata = rtl2832_r820t_platform_data; break; default: dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name); ret = -ENODEV; goto err; } /* attach demodulator */ memset(&board_info, 0, sizeof(board_info)); strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE); board_info.addr = 0x10; board_info.platform_data = pdata; request_module("%s", board_info.type); client = i2c_new_device(&d->i2c_adap, &board_info); if (client == NULL || client->dev.driver == NULL) { ret = -ENODEV; goto err; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); ret = -ENODEV; goto err; } adap->fe[0] = pdata->get_dvb_frontend(client); dev->demod_i2c_adapter = pdata->get_i2c_adapter(client); dev->i2c_client_demod = client; /* set fe callback */ adap->fe[0]->callback = rtl2832u_frontend_callback; if (dev->slave_demod) { struct i2c_board_info info = {}; /* * We continue on reduced mode, without DVB-T2/C, using master * demod, when slave demod fails. */ ret = 0; /* attach slave demodulator */ if (dev->slave_demod == SLAVE_DEMOD_MN88472) { struct mn88472_config mn88472_config = {}; mn88472_config.fe = &adap->fe[1]; mn88472_config.i2c_wr_max = 22, strlcpy(info.type, "mn88472", I2C_NAME_SIZE); mn88472_config.xtal = 20500000; info.addr = 0x18; info.platform_data = &mn88472_config; request_module(info.type); client = i2c_new_device(&d->i2c_adap, &info); if (client == NULL || client->dev.driver == NULL) { dev->slave_demod = SLAVE_DEMOD_NONE; goto err_slave_demod_failed; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); dev->slave_demod = SLAVE_DEMOD_NONE; goto err_slave_demod_failed; } dev->i2c_client_slave_demod = client; } else { struct mn88473_config mn88473_config = {}; mn88473_config.fe = &adap->fe[1]; mn88473_config.i2c_wr_max = 22, strlcpy(info.type, "mn88473", I2C_NAME_SIZE); info.addr = 0x18; info.platform_data = &mn88473_config; request_module(info.type); client = i2c_new_device(&d->i2c_adap, &info); if (client == NULL || client->dev.driver == NULL) { dev->slave_demod = SLAVE_DEMOD_NONE; goto err_slave_demod_failed; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); dev->slave_demod = SLAVE_DEMOD_NONE; goto err_slave_demod_failed; } dev->i2c_client_slave_demod = client; } } return 0; err_slave_demod_failed: err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap) { struct rtl28xxu_dev *dev = adap_to_priv(adap); if (dev->chip_id == CHIP_ID_RTL2831U) return rtl2831u_frontend_attach(adap); else return rtl2832u_frontend_attach(adap); } static int rtl28xxu_frontend_detach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct i2c_client *client; dev_dbg(&d->intf->dev, "\n"); /* remove I2C slave demod */ client = dev->i2c_client_slave_demod; if (client) { module_put(client->dev.driver->owner); i2c_unregister_device(client); } /* remove I2C demod */ client = dev->i2c_client_demod; if (client) { module_put(client->dev.driver->owner); i2c_unregister_device(client); } return 0; } static struct qt1010_config rtl28xxu_qt1010_config = { .i2c_address = 0x62, /* 0xc4 */ }; static struct mt2060_config rtl28xxu_mt2060_config = { .i2c_address = 0x60, /* 0xc0 */ .clock_out = 0, }; static struct mxl5005s_config rtl28xxu_mxl5005s_config = { .i2c_address = 0x63, /* 0xc6 */ .if_freq = IF_FREQ_4570000HZ, .xtal_freq = CRYSTAL_FREQ_16000000HZ, .agc_mode = MXL_SINGLE_AGC, .tracking_filter = MXL_TF_C_H, .rssi_enable = MXL_RSSI_ENABLE, .cap_select = MXL_CAP_SEL_ENABLE, .div_out = MXL_DIV_OUT_4, .clock_out = MXL_CLOCK_OUT_DISABLE, .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, .top = MXL5005S_TOP_25P2, .mod_mode = MXL_DIGITAL_MODE, .if_mode = MXL_ZERO_IF, .AgcMasterByte = 0x00, }; static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap) { int ret; struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct dvb_frontend *fe; dev_dbg(&d->intf->dev, "\n"); switch (dev->tuner) { case TUNER_RTL2830_QT1010: fe = dvb_attach(qt1010_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl28xxu_qt1010_config); break; case TUNER_RTL2830_MT2060: fe = dvb_attach(mt2060_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl28xxu_mt2060_config, 1220); break; case TUNER_RTL2830_MXL5005S: fe = dvb_attach(mxl5005s_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl28xxu_mxl5005s_config); break; default: fe = NULL; dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner); } if (fe == NULL) { ret = -ENODEV; goto err; } return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static const struct fc2580_config rtl2832u_fc2580_config = { .i2c_addr = 0x56, .clock = 16384000, }; static struct tua9001_config rtl2832u_tua9001_config = { .i2c_addr = 0x60, }; static const struct fc0012_config rtl2832u_fc0012_config = { .i2c_address = 0x63, /* 0xc6 >> 1 */ .xtal_freq = FC_XTAL_28_8_MHZ, }; static const struct r820t_config rtl2832u_r820t_config = { .i2c_addr = 0x1a, .xtal = 28800000, .max_i2c_msg_len = 2, .rafael_chip = CHIP_R820T, }; static const struct r820t_config rtl2832u_r828d_config = { .i2c_addr = 0x3a, .xtal = 16000000, .max_i2c_msg_len = 2, .rafael_chip = CHIP_R828D, }; static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) { int ret; struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct dvb_frontend *fe = NULL; struct i2c_board_info info; struct i2c_client *client; struct v4l2_subdev *subdev = NULL; struct platform_device *pdev; struct rtl2832_sdr_platform_data pdata; dev_dbg(&d->intf->dev, "\n"); memset(&info, 0, sizeof(struct i2c_board_info)); memset(&pdata, 0, sizeof(pdata)); switch (dev->tuner) { case TUNER_RTL2832_FC0012: fe = dvb_attach(fc0012_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl2832u_fc0012_config); /* since fc0012 includs reading the signal strength delegate * that to the tuner driver */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; break; case TUNER_RTL2832_FC0013: fe = dvb_attach(fc0013_attach, adap->fe[0], dev->demod_i2c_adapter, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); /* fc0013 also supports signal strength reading */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; break; case TUNER_RTL2832_E4000: { struct e4000_config e4000_config = { .fe = adap->fe[0], .clock = 28800000, }; strlcpy(info.type, "e4000", I2C_NAME_SIZE); info.addr = 0x64; info.platform_data = &e4000_config; request_module(info.type); client = i2c_new_device(dev->demod_i2c_adapter, &info); if (client == NULL || client->dev.driver == NULL) break; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); break; } dev->i2c_client_tuner = client; subdev = i2c_get_clientdata(client); } break; case TUNER_RTL2832_FC2580: fe = dvb_attach(fc2580_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl2832u_fc2580_config); break; case TUNER_RTL2832_TUA9001: /* enable GPIO1 and GPIO4 as output */ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); if (ret) goto err; ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); if (ret) goto err; fe = dvb_attach(tua9001_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl2832u_tua9001_config); break; case TUNER_RTL2832_R820T: fe = dvb_attach(r820t_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl2832u_r820t_config); /* Use tuner to get the signal strength */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; break; case TUNER_RTL2832_R828D: fe = dvb_attach(r820t_attach, adap->fe[0], dev->demod_i2c_adapter, &rtl2832u_r828d_config); adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; if (adap->fe[1]) { fe = dvb_attach(r820t_attach, adap->fe[1], dev->demod_i2c_adapter, &rtl2832u_r828d_config); adap->fe[1]->ops.read_signal_strength = adap->fe[1]->ops.tuner_ops.get_rf_strength; } break; default: dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner); } if (fe == NULL && dev->i2c_client_tuner == NULL) { ret = -ENODEV; goto err; } /* register SDR */ switch (dev->tuner) { case TUNER_RTL2832_FC0012: case TUNER_RTL2832_FC0013: case TUNER_RTL2832_E4000: case TUNER_RTL2832_R820T: case TUNER_RTL2832_R828D: pdata.clk = dev->rtl2832_platform_data.clk; pdata.tuner = dev->tuner; pdata.i2c_client = dev->i2c_client_demod; pdata.bulk_read = dev->rtl2832_platform_data.bulk_read; pdata.bulk_write = dev->rtl2832_platform_data.bulk_write; pdata.update_bits = dev->rtl2832_platform_data.update_bits; pdata.dvb_frontend = adap->fe[0]; pdata.dvb_usb_device = d; pdata.v4l2_subdev = subdev; request_module("%s", "rtl2832_sdr"); pdev = platform_device_register_data(&d->intf->dev, "rtl2832_sdr", PLATFORM_DEVID_AUTO, &pdata, sizeof(pdata)); if (pdev == NULL || pdev->dev.driver == NULL) break; dev->platform_device_sdr = pdev; break; default: dev_dbg(&d->intf->dev, "no SDR for tuner=%d\n", dev->tuner); } return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap) { struct rtl28xxu_dev *dev = adap_to_priv(adap); if (dev->chip_id == CHIP_ID_RTL2831U) return rtl2831u_tuner_attach(adap); else return rtl2832u_tuner_attach(adap); } static int rtl28xxu_tuner_detach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_dev *dev = d_to_priv(d); struct i2c_client *client; struct platform_device *pdev; dev_dbg(&d->intf->dev, "\n"); /* remove platform SDR */ pdev = dev->platform_device_sdr; if (pdev) platform_device_unregister(pdev); /* remove I2C tuner */ client = dev->i2c_client_tuner; if (client) { module_put(client->dev.driver->owner); i2c_unregister_device(client); } return 0; } static int rtl28xxu_init(struct dvb_usb_device *d) { int ret; u8 val; dev_dbg(&d->intf->dev, "\n"); /* init USB endpoints */ ret = rtl28xxu_rd_reg(d, USB_SYSCTL_0, &val); if (ret) goto err; /* enable DMA and Full Packet Mode*/ val |= 0x09; ret = rtl28xxu_wr_reg(d, USB_SYSCTL_0, val); if (ret) goto err; /* set EPA maximum packet size to 0x0200 */ ret = rtl28xxu_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); if (ret) goto err; /* change EPA FIFO length */ ret = rtl28xxu_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); if (ret) goto err; return ret; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) { int ret; u8 gpio, sys0, epa_ctl[2]; dev_dbg(&d->intf->dev, "onoff=%d\n", onoff); /* demod adc */ ret = rtl28xxu_rd_reg(d, SYS_SYS0, &sys0); if (ret) goto err; /* tuner power, read GPIOs */ ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); if (ret) goto err; dev_dbg(&d->intf->dev, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio); if (onoff) { gpio |= 0x01; /* GPIO0 = 1 */ gpio &= (~0x10); /* GPIO4 = 0 */ gpio |= 0x04; /* GPIO2 = 1, LED on */ sys0 = sys0 & 0x0f; sys0 |= 0xe0; epa_ctl[0] = 0x00; /* clear stall */ epa_ctl[1] = 0x00; /* clear reset */ } else { gpio &= (~0x01); /* GPIO0 = 0 */ gpio |= 0x10; /* GPIO4 = 1 */ gpio &= (~0x04); /* GPIO2 = 1, LED off */ sys0 = sys0 & (~0xc0); epa_ctl[0] = 0x10; /* set stall */ epa_ctl[1] = 0x02; /* set reset */ } dev_dbg(&d->intf->dev, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio); /* demod adc */ ret = rtl28xxu_wr_reg(d, SYS_SYS0, sys0); if (ret) goto err; /* tuner power, write GPIOs */ ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); if (ret) goto err; /* streaming EP: stall & reset */ ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); if (ret) goto err; if (onoff) usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); return ret; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) { int ret; dev_dbg(&d->intf->dev, "onoff=%d\n", onoff); if (onoff) { /* GPIO3=1, GPIO4=0 */ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18); if (ret) goto err; /* suspend? */ ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10); if (ret) goto err; /* enable PLL */ ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80); if (ret) goto err; /* disable reset */ ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20); if (ret) goto err; /* streaming EP: clear stall & reset */ ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); if (ret) goto err; ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); if (ret) goto err; } else { /* GPIO4=1 */ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10); if (ret) goto err; /* disable PLL */ ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80); if (ret) goto err; /* streaming EP: set stall & reset */ ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); if (ret) goto err; } return ret; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff) { struct rtl28xxu_dev *dev = d_to_priv(d); if (dev->chip_id == CHIP_ID_RTL2831U) return rtl2831u_power_ctrl(d, onoff); else return rtl2832u_power_ctrl(d, onoff); } static int rtl28xxu_frontend_ctrl(struct dvb_frontend *fe, int onoff) { struct dvb_usb_device *d = fe_to_d(fe); struct rtl28xxu_dev *dev = fe_to_priv(fe); struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; int ret; u8 val; dev_dbg(&d->intf->dev, "fe=%d onoff=%d\n", fe->id, onoff); if (dev->chip_id == CHIP_ID_RTL2831U) return 0; /* control internal demod ADC */ if (fe->id == 0 && onoff) val = 0x48; /* enable ADC */ else val = 0x00; /* disable ADC */ ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48); if (ret) goto err; /* bypass slave demod TS through master demod */ if (fe->id == 1 && onoff) { ret = pdata->enable_slave_ts(dev->i2c_client_demod); if (ret) goto err; } return 0; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } #if IS_ENABLED(CONFIG_RC_CORE) static int rtl2831u_rc_query(struct dvb_usb_device *d) { int ret, i; struct rtl28xxu_dev *dev = d->priv; u8 buf[5]; u32 rc_code; struct rtl28xxu_reg_val rc_nec_tab[] = { { 0x3033, 0x80 }, { 0x3020, 0x43 }, { 0x3021, 0x16 }, { 0x3022, 0x16 }, { 0x3023, 0x5a }, { 0x3024, 0x2d }, { 0x3025, 0x16 }, { 0x3026, 0x01 }, { 0x3028, 0xb0 }, { 0x3029, 0x04 }, { 0x302c, 0x88 }, { 0x302e, 0x13 }, { 0x3030, 0xdf }, { 0x3031, 0x05 }, }; /* init remote controller */ if (!dev->rc_active) { for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { ret = rtl28xxu_wr_reg(d, rc_nec_tab[i].reg, rc_nec_tab[i].val); if (ret) goto err; } dev->rc_active = true; } ret = rtl28xxu_rd_regs(d, SYS_IRRC_RP, buf, 5); if (ret) goto err; if (buf[4] & 0x01) { if (buf[2] == (u8) ~buf[3]) { if (buf[0] == (u8) ~buf[1]) { /* NEC standard (16 bit) */ rc_code = RC_SCANCODE_NEC(buf[0], buf[2]); } else { /* NEC extended (24 bit) */ rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1], buf[2]); } } else { /* NEC full (32 bit) */ rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]); } rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0); ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1); if (ret) goto err; /* repeated intentionally to avoid extra keypress */ ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1); if (ret) goto err; } return ret; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2831u_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) { rc->map_name = RC_MAP_EMPTY; rc->allowed_protos = RC_BIT_NEC; rc->query = rtl2831u_rc_query; rc->interval = 400; return 0; } static int rtl2832u_rc_query(struct dvb_usb_device *d) { int ret, i, len; struct rtl28xxu_dev *dev = d->priv; struct ir_raw_event ev; u8 buf[128]; static const struct rtl28xxu_reg_val_mask refresh_tab[] = { {IR_RX_IF, 0x03, 0xff}, {IR_RX_BUF_CTRL, 0x80, 0xff}, {IR_RX_CTRL, 0x80, 0xff}, }; /* init remote controller */ if (!dev->rc_active) { static const struct rtl28xxu_reg_val_mask init_tab[] = { {SYS_DEMOD_CTL1, 0x00, 0x04}, {SYS_DEMOD_CTL1, 0x00, 0x08}, {USB_CTRL, 0x20, 0x20}, {SYS_GPIO_DIR, 0x00, 0x08}, {SYS_GPIO_OUT_EN, 0x08, 0x08}, {SYS_GPIO_OUT_VAL, 0x08, 0x08}, {IR_MAX_DURATION0, 0xd0, 0xff}, {IR_MAX_DURATION1, 0x07, 0xff}, {IR_IDLE_LEN0, 0xc0, 0xff}, {IR_IDLE_LEN1, 0x00, 0xff}, {IR_GLITCH_LEN, 0x03, 0xff}, {IR_RX_CLK, 0x09, 0xff}, {IR_RX_CFG, 0x1c, 0xff}, {IR_MAX_H_TOL_LEN, 0x1e, 0xff}, {IR_MAX_L_TOL_LEN, 0x1e, 0xff}, {IR_RX_CTRL, 0x80, 0xff}, }; for (i = 0; i < ARRAY_SIZE(init_tab); i++) { ret = rtl28xxu_wr_reg_mask(d, init_tab[i].reg, init_tab[i].val, init_tab[i].mask); if (ret) goto err; } dev->rc_active = true; } ret = rtl28xxu_rd_reg(d, IR_RX_IF, &buf[0]); if (ret) goto err; if (buf[0] != 0x83) goto exit; ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]); if (ret) goto err; len = buf[0]; /* read raw code from hw */ ret = rtl28xxu_rd_regs(d, IR_RX_BUF, buf, len); if (ret) goto err; /* let hw receive new code */ for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) { ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg, refresh_tab[i].val, refresh_tab[i].mask); if (ret) goto err; } /* pass data to Kernel IR decoder */ init_ir_raw_event(&ev); for (i = 0; i < len; i++) { ev.pulse = buf[i] >> 7; ev.duration = 50800 * (buf[i] & 0x7f); ir_raw_event_store_with_filter(d->rc_dev, &ev); } /* 'flush' ir_raw_event_store_with_filter() */ ir_raw_event_set_idle(d->rc_dev, true); ir_raw_event_handle(d->rc_dev); exit: return ret; err: dev_dbg(&d->intf->dev, "failed=%d\n", ret); return ret; } static int rtl2832u_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) { /* disable IR interrupts in order to avoid SDR sample loss */ if (rtl28xxu_disable_rc) return rtl28xxu_wr_reg(d, IR_RX_IE, 0x00); /* load empty to enable rc */ if (!rc->map_name) rc->map_name = RC_MAP_EMPTY; rc->allowed_protos = RC_BIT_ALL; rc->driver_type = RC_DRIVER_IR_RAW; rc->query = rtl2832u_rc_query; rc->interval = 400; return 0; } static int rtl28xxu_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) { struct rtl28xxu_dev *dev = d_to_priv(d); if (dev->chip_id == CHIP_ID_RTL2831U) return rtl2831u_get_rc_config(d, rc); else return rtl2832u_get_rc_config(d, rc); } #else #define rtl28xxu_get_rc_config NULL #endif static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) { struct rtl28xxu_dev *dev = adap_to_priv(adap); if (dev->chip_id == CHIP_ID_RTL2831U) { struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; return pdata->pid_filter_ctrl(adap->fe[0], onoff); } else { struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; return pdata->pid_filter_ctrl(adap->fe[0], onoff); } } static int rtl28xxu_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff) { struct rtl28xxu_dev *dev = adap_to_priv(adap); if (dev->chip_id == CHIP_ID_RTL2831U) { struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; return pdata->pid_filter(adap->fe[0], index, pid, onoff); } else { struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; return pdata->pid_filter(adap->fe[0], index, pid, onoff); } } static const struct dvb_usb_device_properties rtl28xxu_props = { .driver_name = KBUILD_MODNAME, .owner = THIS_MODULE, .adapter_nr = adapter_nr, .size_of_priv = sizeof(struct rtl28xxu_dev), .identify_state = rtl28xxu_identify_state, .power_ctrl = rtl28xxu_power_ctrl, .frontend_ctrl = rtl28xxu_frontend_ctrl, .i2c_algo = &rtl28xxu_i2c_algo, .read_config = rtl28xxu_read_config, .frontend_attach = rtl28xxu_frontend_attach, .frontend_detach = rtl28xxu_frontend_detach, .tuner_attach = rtl28xxu_tuner_attach, .tuner_detach = rtl28xxu_tuner_detach, .init = rtl28xxu_init, .get_rc_config = rtl28xxu_get_rc_config, .num_adapters = 1, .adapter = { { .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, .pid_filter_count = 32, .pid_filter_ctrl = rtl28xxu_pid_filter_ctrl, .pid_filter = rtl28xxu_pid_filter, .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), }, }, }; static const struct usb_device_id rtl28xxu_id_table[] = { /* RTL2831U devices: */ { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, &rtl28xxu_props, "Realtek RTL2831U reference design", NULL) }, { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT, &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) }, { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2, &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) }, /* RTL2832U devices: */ { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832, &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) }, { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, &rtl28xxu_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) }, { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, &rtl28xxu_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, &rtl28xxu_props, "TerraTec NOXON DAB Stick", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2, &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3, &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) }, { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, &rtl28xxu_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, &rtl28xxu_props, "Dexatek DK DVB-T Dongle", NULL) }, { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680, &rtl28xxu_props, "DigitalNow Quad DVB-T Receiver", NULL) }, { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID, &rtl28xxu_props, "Leadtek Winfast DTV Dongle Mini D", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3, &rtl28xxu_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) }, { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102, &rtl28xxu_props, "Dexatek DK mini DVB-T Dongle", NULL) }, { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7, &rtl28xxu_props, "TerraTec Cinergy T Stick+", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8, &rtl28xxu_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393, &rtl28xxu_props, "GIGABYTE U7300", NULL) }, { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104, &rtl28xxu_props, "MSI DIGIVOX Micro HD", NULL) }, { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620, &rtl28xxu_props, "Compro VideoMate U620F", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394, &rtl28xxu_props, "MaxMedia HU394-T", NULL) }, { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03, &rtl28xxu_props, "Leadtek WinFast DTV Dongle mini", NULL) }, { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A, &rtl28xxu_props, "Crypto ReDi PC 50 A", NULL) }, { DVB_USB_DEVICE(USB_VID_KYE, 0x707f, &rtl28xxu_props, "Genius TVGo DVB-T03", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395, &rtl28xxu_props, "Peak DVB-T USB", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U, &rtl28xxu_props, "Sveon STV20", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21, &rtl28xxu_props, "Sveon STV21", NULL) }, { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27, &rtl28xxu_props, "Sveon STV27", NULL) }, /* RTL2832P devices: */ { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131, &rtl28xxu_props, "Astrometa DVB-T2", NULL) }, { } }; MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); static struct usb_driver rtl28xxu_usb_driver = { .name = KBUILD_MODNAME, .id_table = rtl28xxu_id_table, .probe = dvb_usbv2_probe, .disconnect = dvb_usbv2_disconnect, .suspend = dvb_usbv2_suspend, .resume = dvb_usbv2_resume, .reset_resume = dvb_usbv2_reset_resume, .no_dynamic_id = 1, .soft_unbind = 1, }; module_usb_driver(rtl28xxu_usb_driver); MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver"); MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>"); MODULE_LICENSE("GPL");
gpl-2.0
c2h2/aria-imx6-uboot
board/sbc8548/tlb.c
62
3965
/* * Copyright 2008 Freescale Semiconductor, Inc. * * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include <common.h> #include <asm/mmu.h> struct fsl_e_tlb_entry tlb_table[] = { /* TLB 0 - for temp stack in cache */ SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR, CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 0, BOOKE_PAGESZ_4K, 0), SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024, CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 0, BOOKE_PAGESZ_4K, 0), SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024, CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 0, BOOKE_PAGESZ_4K, 0), SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024, CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 0, BOOKE_PAGESZ_4K, 0), /* * TLB 0: 64M Non-cacheable, guarded * 0xfc000000 56M 8MB -> 64MB of user flash * 0xff800000 8M boot FLASH * Out of reset this entry is only 4K. */ SET_TLB_ENTRY(1, CONFIG_SYS_ALT_FLASH + 0x800000, CONFIG_SYS_ALT_FLASH + 0x800000, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 0, BOOKE_PAGESZ_64M, 1), /* * TLB 1: 1G Non-cacheable, guarded * 0x80000000 512M PCI1 MEM * 0xa0000000 512M PCIe MEM */ SET_TLB_ENTRY(1, CONFIG_SYS_PCI1_MEM_VIRT, CONFIG_SYS_PCI1_MEM_PHYS, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 1, BOOKE_PAGESZ_1G, 1), /* * TLB 2: 64M Non-cacheable, guarded * 0xe0000000 1M CCSRBAR * 0xe2000000 8M PCI1 IO * 0xe2800000 8M PCIe IO */ SET_TLB_ENTRY(1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 2, BOOKE_PAGESZ_64M, 1), /* * TLB 3: 64M Cacheable, non-guarded * 0xf0000000 64M LBC SDRAM First half */ SET_TLB_ENTRY(1, CONFIG_SYS_LBC_SDRAM_BASE, CONFIG_SYS_LBC_SDRAM_BASE, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 3, BOOKE_PAGESZ_64M, 1), /* * TLB 4: 64M Cacheable, non-guarded * 0xf4000000 64M LBC SDRAM Second half */ SET_TLB_ENTRY(1, CONFIG_SYS_LBC_SDRAM_BASE + 0x4000000, CONFIG_SYS_LBC_SDRAM_BASE + 0x4000000, MAS3_SX|MAS3_SW|MAS3_SR, 0, 0, 4, BOOKE_PAGESZ_64M, 1), /* * TLB 5: 16M Cacheable, non-guarded * 0xf8000000 1M 7-segment LED display * 0xf8100000 1M User switches * 0xf8300000 1M Board revision * 0xf8b00000 1M EEPROM */ SET_TLB_ENTRY(1, CONFIG_SYS_EPLD_BASE, CONFIG_SYS_EPLD_BASE, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 5, BOOKE_PAGESZ_16M, 1), /* * TLB 6: 4M Non-cacheable, guarded * 0xfb800000 4M 1st 4MB block of 64MB user FLASH */ SET_TLB_ENTRY(1, CONFIG_SYS_ALT_FLASH, CONFIG_SYS_ALT_FLASH, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 6, BOOKE_PAGESZ_4M, 1), /* * TLB 7: 4M Non-cacheable, guarded * 0xfbc00000 4M 2nd 4MB block of 64MB user FLASH */ SET_TLB_ENTRY(1, CONFIG_SYS_ALT_FLASH + 0x400000, CONFIG_SYS_ALT_FLASH + 0x400000, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, 7, BOOKE_PAGESZ_4M, 1), }; int num_tlb_entries = ARRAY_SIZE(tlb_table);
gpl-2.0
wetek-enigma/linux-wetek
drivers/amlogic/wifi/rtl8xxx_EU/core/rtw_mp_ioctl.c
62
90425
/****************************************************************************** * * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * ******************************************************************************/ #define _RTW_MP_IOCTL_C_ #include <drv_types.h> #include <rtw_mp_ioctl.h> #include "../hal/OUTSRC/odm_precomp.h" //**************** oid_rtl_seg_81_85 section start **************** NDIS_STATUS oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->information_buf_len < sizeof(u8)) return NDIS_STATUS_INVALID_LENGTH; if (poid_par_priv->type_of_oid == SET_OID) { Adapter->registrypriv.wireless_mode = *(u8*)poid_par_priv->information_buf; } else if (poid_par_priv->type_of_oid == QUERY_OID) { *(u8*)poid_par_priv->information_buf = Adapter->registrypriv.wireless_mode; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_info_, ("-query Wireless Mode=%d\n", Adapter->registrypriv.wireless_mode)); } else { status = NDIS_STATUS_NOT_ACCEPTED; } _func_exit_; return status; } //**************** oid_rtl_seg_81_87_80 section start **************** NDIS_STATUS oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif struct bb_reg_param *pbbreg; u16 offset; u32 value; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_write_bb_reg_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) return NDIS_STATUS_INVALID_LENGTH; pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); offset = (u16)(pbbreg->offset) & 0xFFF; //0ffset :0x800~0xfff if (offset < BB_REG_BASE_ADDR) offset |= BB_REG_BASE_ADDR; value = pbbreg->value; RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_write_bb_reg_hdl: offset=0x%03X value=0x%08X\n", offset, value)); _irqlevel_changed_(&oldirql, LOWER); write_bbreg(Adapter, offset, 0xFFFFFFFF, value); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif struct bb_reg_param *pbbreg; u16 offset; u32 value; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_read_bb_reg_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) return NDIS_STATUS_INVALID_LENGTH; pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); offset = (u16)(pbbreg->offset) & 0xFFF; //0ffset :0x800~0xfff if (offset < BB_REG_BASE_ADDR) offset |= BB_REG_BASE_ADDR; _irqlevel_changed_(&oldirql, LOWER); value = read_bbreg(Adapter, offset, 0xFFFFFFFF); _irqlevel_changed_(&oldirql, RAISE); pbbreg->value = value; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_read_bb_reg_hdl: offset=0x%03X value:0x%08X\n", offset, value)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif struct rf_reg_param *pbbreg; u8 path; u8 offset; u32 value; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_write_rf_reg_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) return NDIS_STATUS_INVALID_LENGTH; pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); if (pbbreg->path >= MAX_RF_PATH_NUMS) return NDIS_STATUS_NOT_ACCEPTED; if (pbbreg->offset > 0xFF) return NDIS_STATUS_NOT_ACCEPTED; if (pbbreg->value > 0xFFFFF) return NDIS_STATUS_NOT_ACCEPTED; path = (u8)pbbreg->path; offset = (u8)pbbreg->offset; value = pbbreg->value; RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_write_rf_reg_hdl: path=%d offset=0x%02X value=0x%05X\n", path, offset, value)); _irqlevel_changed_(&oldirql, LOWER); write_rfreg(Adapter, path, offset, value); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif struct rf_reg_param *pbbreg; u8 path; u8 offset; u32 value; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_read_rf_reg_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) return NDIS_STATUS_INVALID_LENGTH; pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); if (pbbreg->path >= MAX_RF_PATH_NUMS) return NDIS_STATUS_NOT_ACCEPTED; if (pbbreg->offset > 0xFF) return NDIS_STATUS_NOT_ACCEPTED; path = (u8)pbbreg->path; offset = (u8)pbbreg->offset; _irqlevel_changed_(&oldirql, LOWER); value = read_rfreg(Adapter, path, offset); _irqlevel_changed_(&oldirql, RAISE); pbbreg->value = value; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_read_rf_reg_hdl: path=%d offset=0x%02X value=0x%05X\n", path, offset, value)); _func_exit_; return status; } //**************** oid_rtl_seg_81_87_00 section end**************** //------------------------------------------------------------------------------ //**************** oid_rtl_seg_81_80_00 section start **************** //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_data_rate_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 ratevalue;//4 NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_data_rate_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; ratevalue = *((u32*)poid_par_priv->information_buf);//4 RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_set_data_rate_hdl: data rate idx=%d\n", ratevalue)); if (ratevalue >= MPT_RATE_LAST) return NDIS_STATUS_INVALID_DATA; Adapter->mppriv.rateidx = ratevalue; _irqlevel_changed_(&oldirql, LOWER); SetDataRate(Adapter); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 mode; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_start_test_hdl\n")); if (Adapter->registrypriv.mp_mode == 0) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); //IQCalibrateBcut(Adapter); mode = *((u32*)poid_par_priv->information_buf); Adapter->mppriv.mode = mode;// 1 for loopback if (mp_start_test(Adapter) == _FAIL) { status = NDIS_STATUS_NOT_ACCEPTED; goto exit; } exit: _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_start_test_hdl: mp_mode=%d\n", Adapter->mppriv.mode)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+Set OID_RT_PRO_STOP_TEST\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); mp_stop_test(Adapter); _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_notice_, ("-Set OID_RT_PRO_STOP_TEST\n")); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 Channel; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_channel_direct_call_hdl\n")); if (poid_par_priv->information_buf_len != sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; if (poid_par_priv->type_of_oid == QUERY_OID) { *((u32*)poid_par_priv->information_buf) = Adapter->mppriv.channel; return NDIS_STATUS_SUCCESS; } if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; Channel = *((u32*)poid_par_priv->information_buf); RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_set_channel_direct_call_hdl: Channel=%d\n", Channel)); if (Channel > 14) return NDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.channel = Channel; _irqlevel_changed_(&oldirql, LOWER); SetChannel(Adapter); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u16 bandwidth; u16 channel_offset; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_set_bandwidth_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; bandwidth = *((u32*)poid_par_priv->information_buf);//4 channel_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; if (bandwidth != CHANNEL_WIDTH_40) bandwidth = CHANNEL_WIDTH_20; padapter->mppriv.bandwidth = (u8)bandwidth; padapter->mppriv.prime_channel_offset = (u8)channel_offset; _irqlevel_changed_(&oldirql, LOWER); SetBandwidth(padapter); _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_set_bandwidth_hdl: bandwidth=%d channel_offset=%d\n", bandwidth, channel_offset)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 antenna; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_antenna_bb_hdl\n")); if (poid_par_priv->information_buf_len != sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; if (poid_par_priv->type_of_oid == SET_OID) { antenna = *(u32*)poid_par_priv->information_buf; Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16); Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF); RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_set_antenna_bb_hdl: tx_ant=0x%04x rx_ant=0x%04x\n", Adapter->mppriv.antenna_tx, Adapter->mppriv.antenna_rx)); _irqlevel_changed_(&oldirql, LOWER); SetAntenna(Adapter); _irqlevel_changed_(&oldirql, RAISE); } else { antenna = (Adapter->mppriv.antenna_tx << 16)|Adapter->mppriv.antenna_rx; *(u32*)poid_par_priv->information_buf = antenna; } _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_tx_power_control_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 tx_pwr_idx; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_pro_set_tx_power_control_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; tx_pwr_idx = *((u32*)poid_par_priv->information_buf); if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE) return NDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.txpoweridx = (u8)tx_pwr_idx; RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_set_tx_power_control_hdl: idx=0x%2x\n", Adapter->mppriv.txpoweridx)); _irqlevel_changed_(&oldirql, LOWER); SetTxPower(Adapter); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ //**************** oid_rtl_seg_81_80_20 section start **************** //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_query_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid !=QUERY_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len == sizeof(ULONG)) { *(ULONG*)poid_par_priv->information_buf = Adapter->mppriv.tx_pktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else { status = NDIS_STATUS_INVALID_LENGTH; } _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_query_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } RT_TRACE(_module_mp_, _drv_alert_, ("===> oid_rt_pro_query_rx_packet_received_hdl.\n")); if (poid_par_priv->information_buf_len == sizeof(ULONG)) { *(ULONG*)poid_par_priv->information_buf = Adapter->mppriv.rx_pktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_alert_, ("recv_ok:%d \n",Adapter->mppriv.rx_pktcount)); } else { status = NDIS_STATUS_INVALID_LENGTH; } _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_query_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } RT_TRACE(_module_mp_, _drv_alert_, ("===> oid_rt_pro_query_rx_packet_crc32_error_hdl.\n")); if (poid_par_priv->information_buf_len == sizeof(ULONG)) { *(ULONG*)poid_par_priv->information_buf = Adapter->mppriv.rx_crcerrpktcount; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_alert_, ("recv_err:%d \n",Adapter->mppriv.rx_crcerrpktcount)); } else { status = NDIS_STATUS_INVALID_LENGTH; } _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } RT_TRACE(_module_mp_, _drv_alert_, ("===> oid_rt_pro_reset_tx_packet_sent_hdl.\n")); Adapter->mppriv.tx_pktcount = 0; _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len == sizeof(ULONG)) { Adapter->mppriv.rx_pktcount = 0; Adapter->mppriv.rx_crcerrpktcount = 0; } else { status = NDIS_STATUS_INVALID_LENGTH; } _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } _irqlevel_changed_(&oldirql, LOWER); ResetPhyRxPktCount(Adapter); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_get_phy_rx_packet_received_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(ULONG)) return NDIS_STATUS_INVALID_LENGTH; _irqlevel_changed_(&oldirql, LOWER); *(ULONG*)poid_par_priv->information_buf = GetPhyRxPktReceived(Adapter); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_get_phy_rx_packet_received_hdl: recv_ok=%d\n", *(ULONG*)poid_par_priv->information_buf)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_get_phy_rx_packet_crc32_error_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len != sizeof(ULONG)) return NDIS_STATUS_INVALID_LENGTH; _irqlevel_changed_(&oldirql, LOWER); *(ULONG*)poid_par_priv->information_buf = GetPhyRxPktCRC32Error(Adapter); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_get_phy_rx_packet_crc32_error_hdl: recv_err=%d\n", *(ULONG*)poid_par_priv->information_buf)); _func_exit_; return status; } //**************** oid_rtl_seg_81_80_20 section end **************** NDIS_STATUS oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 bStartTest; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_continuous_tx_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32*)poid_par_priv->information_buf); _irqlevel_changed_(&oldirql, LOWER); SetContinuousTx(Adapter,(u8)bStartTest); if (bStartTest) { struct mp_priv *pmp_priv = &Adapter->mppriv; if (pmp_priv->tx.stop == 0) { pmp_priv->tx.stop = 1; DBG_871X("%s: pkt tx is running...\n", __func__); rtw_msleep_os(5); } pmp_priv->tx.stop = 0; pmp_priv->tx.count = 1; SetPacketTx(Adapter); } _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 bStartTest; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_alert_, ("+oid_rt_pro_set_single_carrier_tx_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32*)poid_par_priv->information_buf); _irqlevel_changed_(&oldirql, LOWER); SetSingleCarrierTx(Adapter, (u8)bStartTest); if (bStartTest) { struct mp_priv *pmp_priv = &Adapter->mppriv; if (pmp_priv->tx.stop == 0) { pmp_priv->tx.stop = 1; DBG_871X("%s: pkt tx is running...\n", __func__); rtw_msleep_os(5); } pmp_priv->tx.stop = 0; pmp_priv->tx.count = 1; SetPacketTx(Adapter); } _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 bStartTest; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_carrier_suppression_tx_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32*)poid_par_priv->information_buf); _irqlevel_changed_(&oldirql, LOWER); SetCarrierSuppressionTx(Adapter, (u8)bStartTest); if (bStartTest) { struct mp_priv *pmp_priv = &Adapter->mppriv; if (pmp_priv->tx.stop == 0) { pmp_priv->tx.stop = 1; DBG_871X("%s: pkt tx is running...\n", __func__); rtw_msleep_os(5); } pmp_priv->tx.stop = 0; pmp_priv->tx.count = 1; SetPacketTx(Adapter); } _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 bStartTest; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_alert_, ("+oid_rt_pro_set_single_tone_tx_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; bStartTest = *((u32*)poid_par_priv->information_buf); _irqlevel_changed_(&oldirql, LOWER); SetSingleToneTx(Adapter,(u8)bStartTest); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_modulation_hdl(struct oid_par_priv* poid_par_priv) { return 0; } NDIS_STATUS oid_rt_pro_trigger_gpio_hdl(struct oid_par_priv *poid_par_priv) { PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); rtw_hal_set_hwreg(Adapter, HW_VAR_TRIGGER_GPIO_0, 0); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //**************** oid_rtl_seg_81_80_00 section end **************** //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro8711_join_bss_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PNDIS_802_11_SSID pssid; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = (u32)sizeof(NDIS_802_11_SSID); *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) return NDIS_STATUS_INVALID_LENGTH; pssid = (PNDIS_802_11_SSID)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); if (mp_start_joinbss(Adapter, pssid) == _FAIL) status = NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = sizeof(NDIS_802_11_SSID); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_read_register_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pRW_Reg RegRWStruct; u32 offset, width; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_pro_read_register_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; RegRWStruct = (pRW_Reg)poid_par_priv->information_buf; offset = RegRWStruct->offset; width = RegRWStruct->width; if (offset > 0xFFF) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); switch (width) { case 1: RegRWStruct->value = rtw_read8(Adapter, offset); break; case 2: RegRWStruct->value = rtw_read16(Adapter, offset); break; default: width = 4; RegRWStruct->value = rtw_read32(Adapter, offset); break; } RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_read_register_hdl: offset:0x%04X value:0x%X\n", offset, RegRWStruct->value)); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = width; _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pRW_Reg RegRWStruct; u32 offset, width, value; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_pro_write_register_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; RegRWStruct = (pRW_Reg)poid_par_priv->information_buf; offset = RegRWStruct->offset; width = RegRWStruct->width; value = RegRWStruct->value; if (offset > 0xFFF) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); switch (RegRWStruct->width) { case 1: if (value > 0xFF) { status = NDIS_STATUS_NOT_ACCEPTED; break; } rtw_write8(padapter, offset, (u8)value); break; case 2: if (value > 0xFFFF) { status = NDIS_STATUS_NOT_ACCEPTED; break; } rtw_write16(padapter, offset, (u16)value); break; case 4: rtw_write32(padapter, offset, value); break; default: status = NDIS_STATUS_NOT_ACCEPTED; break; } _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_write_register_hdl: offset=0x%08X width=%d value=0x%X\n", offset, width, value)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_burst_read_register_hdl(struct oid_par_priv *poid_par_priv) { #if 0 #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pBurst_RW_Reg pBstRwReg; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_burst_read_register_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; pBstRwReg = (pBurst_RW_Reg)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); rtw_read_mem(padapter, pBstRwReg->offset, (u32)pBstRwReg->len, pBstRwReg->Data); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_burst_read_register_hdl\n")); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_burst_write_register_hdl(struct oid_par_priv *poid_par_priv) { #if 0 #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pBurst_RW_Reg pBstRwReg; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_burst_write_register_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; pBstRwReg = (pBurst_RW_Reg)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); rtw_write_mem(padapter, pBstRwReg->offset, (u32)pBstRwReg->len, pBstRwReg->Data); _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_burst_write_register_hdl\n")); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_write_txcmd_hdl(struct oid_par_priv *poid_par_priv) { #if 0 NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)( poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif TX_CMD_Desc *TxCmd_Info; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; RT_TRACE(_module_mp_, _drv_info_, ("+Set OID_RT_PRO_WRITE_TXCMD\n")); TxCmd_Info=(TX_CMD_Desc*)poid_par_priv->information_buf; RT_TRACE(_module_mp_, _drv_info_, ("WRITE_TXCMD:Addr=%.8X\n", TxCmd_Info->offset)); RT_TRACE(_module_mp_, _drv_info_, ("WRITE_TXCMD:1.)%.8X\n", (ULONG)TxCmd_Info->TxCMD.value[0])); RT_TRACE(_module_mp_, _drv_info_, ("WRITE_TXCMD:2.)%.8X\n", (ULONG)TxCmd_Info->TxCMD.value[1])); RT_TRACE(_module_mp_, _drv_info_, (("WRITE_TXCMD:3.)%.8X\n", (ULONG)TxCmd_Info->TxCMD.value[2])); RT_TRACE(_module_mp_, _drv_info_, ("WRITE_TXCMD:4.)%.8X\n", (ULONG)TxCmd_Info->TxCMD.value[3])); _irqlevel_changed_(&oldirql, LOWER); rtw_write32(Adapter, TxCmd_Info->offset + 0, (unsigned int)TxCmd_Info->TxCMD.value[0]); rtw_write32(Adapter, TxCmd_Info->offset + 4, (unsigned int)TxCmd_Info->TxCMD.value[1]); _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_notice_, ("-Set OID_RT_PRO_WRITE_TXCMD: status=0x%08X\n", status)); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv) { #if 0 #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pEEPROM_RWParam pEEPROM; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+Query OID_RT_PRO_READ16_EEPROM\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; pEEPROM = (pEEPROM_RWParam)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); pEEPROM->value = eeprom_read16(padapter, (u16)(pEEPROM->offset >> 1)); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-Query OID_RT_PRO_READ16_EEPROM: offset=0x%x value=0x%x\n", pEEPROM->offset, pEEPROM->value)); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_write16_eeprom_hdl (struct oid_par_priv *poid_par_priv) { #if 0 #ifdef PLATFORM_OS_XP _irqL oldirql; #endif pEEPROM_RWParam pEEPROM; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+Set OID_RT_PRO_WRITE16_EEPROM\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; pEEPROM = (pEEPROM_RWParam)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); eeprom_write16(padapter, (u16)(pEEPROM->offset >> 1), pEEPROM->value); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)( poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; struct mp_wiparam *pwi_param; _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(struct mp_wiparam)) return NDIS_STATUS_INVALID_LENGTH; if (Adapter->mppriv.workparam.bcompleted == _FALSE) return NDIS_STATUS_NOT_ACCEPTED; pwi_param = (struct mp_wiparam *)poid_par_priv->information_buf; _rtw_memcpy(pwi_param, &Adapter->mppriv.workparam, sizeof(struct mp_wiparam)); Adapter->mppriv.act_in_progress = _FALSE; // RT_TRACE(_module_mp_, _drv_info_, ("rf:%x\n", pwiparam->IoValue)); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)( poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro8711_pkt_loss_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(uint)*2) { RT_TRACE(_module_mp_, _drv_err_, ("-oid_rt_pro8711_pkt_loss_hdl: buf_len=%d\n", (int)poid_par_priv->information_buf_len)); return NDIS_STATUS_INVALID_LENGTH; } if (*(uint*)poid_par_priv->information_buf == 1)//init==1 Adapter->mppriv.rx_pktloss = 0; *((uint*)poid_par_priv->information_buf+1) = Adapter->mppriv.rx_pktloss; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_rd_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)( poid_par_priv->adapter_context); struct io_queue *pio_queue = (struct io_queue *)Adapter->pio_queue; struct intf_hdl *pintfhdl = &pio_queue->intf; #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; #ifdef CONFIG_SDIO_HCI void (*_attrib_read)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); #endif _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+Query OID_RT_RD_ATTRIB_MEM\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; #ifdef CONFIG_SDIO_HCI _irqlevel_changed_(&oldirql, LOWER); { u32 *plmem = (u32*)poid_par_priv->information_buf+2; _attrib_read = pintfhdl->io_ops._attrib_read; _attrib_read(pintfhdl, *((u32*)poid_par_priv->information_buf), *((u32*)poid_par_priv->information_buf+1), (u8*)plmem); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } _irqlevel_changed_(&oldirql, RAISE); #endif _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_wr_attrib_mem_hdl (struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); struct io_queue *pio_queue = (struct io_queue *)Adapter->pio_queue; struct intf_hdl *pintfhdl = &pio_queue->intf; #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; #ifdef CONFIG_SDIO_HCI void (*_attrib_write)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); #endif _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; #ifdef CONFIG_SDIO_HCI _irqlevel_changed_(&oldirql, LOWER); { u32 *plmem = (u32*)poid_par_priv->information_buf + 2; _attrib_write = pintfhdl->io_ops._attrib_write; _attrib_write(pintfhdl, *(u32*)poid_par_priv->information_buf, *((u32*)poid_par_priv->information_buf+1), (u8*)plmem); } _irqlevel_changed_(&oldirql, RAISE); #endif _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_rf_intfs_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+OID_RT_PRO_SET_RF_INTFS\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); if (rtw_setrfintfs_cmd(Adapter, *(unsigned char*)poid_par_priv->information_buf) == _FAIL) status = NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; _rtw_memcpy(poid_par_priv->information_buf, (unsigned char*)&Adapter->mppriv.rxstat, sizeof(struct recv_stat)); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_cfg_debug_message_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; PCFG_DBG_MSG_STRUCT pdbg_msg; _func_enter_; // RT_TRACE(0xffffffffff,_drv_alert_,("===> oid_rt_pro_cfg_debug_message_hdl.\n")); #if 0//#ifdef CONFIG_DEBUG_RTL871X pdbg_msg = (PCFG_DBG_MSG_STRUCT)(poid_par_priv->information_buf); if (poid_par_priv->type_of_oid == SET_OID) { RT_TRACE(0xffffffffff, _drv_alert_, ("===>Set level :0x%08x, H32:0x%08x L32:0x%08x\n", pdbg_msg->DebugLevel, pdbg_msg->DebugComponent_H32, pdbg_msg->DebugComponent_L32)); GlobalDebugLevel = pdbg_msg->DebugLevel; GlobalDebugComponents = (pdbg_msg->DebugComponent_H32 << 32) | pdbg_msg->DebugComponent_L32; RT_TRACE(0xffffffffff, _drv_alert_, ("===> Set level :0x%08x, component:0x%016x\n", GlobalDebugLevel, (u32)GlobalDebugComponents)); } else { pdbg_msg->DebugLevel = GlobalDebugLevel; pdbg_msg->DebugComponent_H32 = (u32)(GlobalDebugComponents >> 32); pdbg_msg->DebugComponent_L32 = (u32)GlobalDebugComponents; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(0xffffffffff, _drv_alert_, ("===>Query level:0x%08x H32:0x%08x L32:0x%08x\n", (u32)pdbg_msg->DebugLevel, (u32)pdbg_msg->DebugComponent_H32, (u32)pdbg_msg->DebugComponent_L32)); } #endif _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv *poid_par_priv) { PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+OID_RT_PRO_SET_DATA_RATE_EX\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, LOWER); if (rtw_setdatarate_cmd(Adapter, poid_par_priv->information_buf) !=_SUCCESS) status = NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //----------------------------------------------------------------------------- NDIS_STATUS oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; u8 thermal = 0; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_get_thermal_meter_hdl\n")); if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; _irqlevel_changed_(&oldirql, LOWER); GetThermalMeter(Adapter, &thermal); _irqlevel_changed_(&oldirql, RAISE); *(u32*)poid_par_priv->information_buf = (u32)thermal; *poid_par_priv->bytes_rw = sizeof(u32); _func_exit_; return status; } //----------------------------------------------------------------------------- NDIS_STATUS oid_rt_pro_read_tssi_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_read_tssi_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (Adapter->mppriv.act_in_progress == _TRUE) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) return NDIS_STATUS_INVALID_LENGTH; //init workparam Adapter->mppriv.act_in_progress = _TRUE; Adapter->mppriv.workparam.bcompleted = _FALSE; Adapter->mppriv.workparam.act_type = MPT_READ_TSSI; Adapter->mppriv.workparam.io_offset = 0; Adapter->mppriv.workparam.io_value = 0xFFFFFFFF; _irqlevel_changed_(&oldirql, LOWER); if (!rtw_gettssi_cmd(Adapter,0, (u8*)&Adapter->mppriv.workparam.io_value)) status = NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_power_tracking_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; // if (poid_par_priv->type_of_oid != SET_OID) // return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) return NDIS_STATUS_INVALID_LENGTH; _irqlevel_changed_(&oldirql, LOWER); if (poid_par_priv->type_of_oid == SET_OID) { u8 enable; enable = *(u8*)poid_par_priv->information_buf; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_set_power_tracking_hdl: enable=%d\n", enable)); SetPowerTracking(Adapter, enable); } else { GetPowerTracking(Adapter, (u8*)poid_par_priv->information_buf); } _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //----------------------------------------------------------------------------- NDIS_STATUS oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv) { #if 0 #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 ratevalue; u8 datarates[NumRates]; int i; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+OID_RT_PRO_SET_BASIC_RATE\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; #if 0 ratevalue = *((u32*)poid_par_priv->information_buf); for (i = 0; i < NumRates; i++) { if (ratevalue == mpdatarate[i]) datarates[i] = mpdatarate[i]; else datarates[i] = 0xff; RT_TRACE(_module_rtl871x_ioctl_c_, _drv_info_, ("basicrate_inx=%d\n", datarates[i])); } _irqlevel_changed_(&oldirql, LOWER); if (rtw_setbasicrate_cmd(padapter, datarates) != _SUCCESS) status = NDIS_STATUS_NOT_ACCEPTED; _irqlevel_changed_(&oldirql, RAISE); #endif RT_TRACE(_module_mp_, _drv_notice_, ("-OID_RT_PRO_SET_BASIC_RATE: status=0x%08X\n", status)); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_qry_pwrstate_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < 8) return NDIS_STATUS_INVALID_LENGTH; *poid_par_priv->bytes_rw = 8; _rtw_memcpy(poid_par_priv->information_buf, &(adapter_to_pwrctl(Adapter)->pwr_mode), 8); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_qry_pwrstate_hdl: pwr_mode=%d smart_ps=%d\n", adapter_to_pwrctl(Adapter)->pwr_mode, adapter_to_pwrctl(Adapter)->smart_ps)); _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; uint pwr_mode, smart_ps; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+Set OID_RT_PRO_SET_PWRSTATE\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_rw = 0; *poid_par_priv->bytes_needed = 8; if (poid_par_priv->information_buf_len < 8) return NDIS_STATUS_INVALID_LENGTH; pwr_mode = *(uint *)(poid_par_priv->information_buf); smart_ps = *(uint *)((int)poid_par_priv->information_buf + 4); *poid_par_priv->bytes_rw = 8; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; struct setratable_parm *prate_table; u8 res; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = sizeof(struct setratable_parm); if (poid_par_priv->information_buf_len < sizeof(struct setratable_parm)) return NDIS_STATUS_INVALID_LENGTH; prate_table = (struct setratable_parm*)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); res = rtw_setrttbl_cmd(Adapter, prate_table); _irqlevel_changed_(&oldirql, RAISE); if (res == _FAIL) status = NDIS_STATUS_FAILURE; _func_exit_; return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_h2c_get_rate_table_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; #if 0 struct mp_wi_cntx *pmp_wi_cntx=&(Adapter->mppriv.wi_cntx); u8 res=_SUCCESS; DEBUG_INFO(("===> Set OID_RT_PRO_H2C_GET_RATE_TABLE.\n")); if(pmp_wi_cntx->bmp_wi_progress ==_TRUE){ DEBUG_ERR(("\n mp workitem is progressing, not allow to set another workitem right now!!!\n")); Status = NDIS_STATUS_NOT_ACCEPTED; break; } else{ pmp_wi_cntx->bmp_wi_progress=_TRUE; pmp_wi_cntx->param.bcompleted=_FALSE; pmp_wi_cntx->param.act_type=MPT_GET_RATE_TABLE; pmp_wi_cntx->param.io_offset=0x0; pmp_wi_cntx->param.bytes_cnt=sizeof(struct getratable_rsp); pmp_wi_cntx->param.io_value=0xffffffff; res=rtw_getrttbl_cmd(Adapter,(struct getratable_rsp *)pmp_wi_cntx->param.data); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; if(res != _SUCCESS) { Status = NDIS_STATUS_NOT_ACCEPTED; } } DEBUG_INFO(("\n <=== Set OID_RT_PRO_H2C_GET_RATE_TABLE.\n")); #endif _func_exit_; return status; #else return 0; #endif } //**************** oid_rtl_seg_87_12_00 section start **************** NDIS_STATUS oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); struct security_priv *psecuritypriv = &Adapter->securitypriv; NDIS_STATUS status = NDIS_STATUS_SUCCESS; ENCRY_CTRL_STATE encry_mode; *poid_par_priv->bytes_needed = sizeof(u8); if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) return NDIS_STATUS_INVALID_LENGTH; if (poid_par_priv->type_of_oid == SET_OID) { encry_mode = *((u8*)poid_par_priv->information_buf); switch (encry_mode) { case HW_CONTROL: #if 0 Adapter->registrypriv.software_decrypt=_FALSE; Adapter->registrypriv.software_encrypt=_FALSE; #else psecuritypriv->sw_decrypt = _FALSE; psecuritypriv->sw_encrypt = _FALSE; #endif break; case SW_CONTROL: #if 0 Adapter->registrypriv.software_decrypt=_TRUE; Adapter->registrypriv.software_encrypt=_TRUE; #else psecuritypriv->sw_decrypt = _TRUE; psecuritypriv->sw_encrypt = _TRUE; #endif break; case HW_ENCRY_SW_DECRY: #if 0 Adapter->registrypriv.software_decrypt=_TRUE; Adapter->registrypriv.software_encrypt=_FALSE; #else psecuritypriv->sw_decrypt = _TRUE; psecuritypriv->sw_encrypt = _FALSE; #endif break; case SW_ENCRY_HW_DECRY: #if 0 Adapter->registrypriv.software_decrypt=_FALSE; Adapter->registrypriv.software_encrypt=_TRUE; #else psecuritypriv->sw_decrypt = _FALSE; psecuritypriv->sw_encrypt = _TRUE; #endif break; } RT_TRACE(_module_rtl871x_ioctl_c_, _drv_notice_, ("-oid_rt_pro_encryption_ctrl_hdl: SET encry_mode=0x%x sw_encrypt=0x%x sw_decrypt=0x%x\n", encry_mode, psecuritypriv->sw_encrypt, psecuritypriv->sw_decrypt)); } else { #if 0 if (Adapter->registrypriv.software_encrypt == _FALSE) { if (Adapter->registrypriv.software_decrypt == _FALSE) encry_mode = HW_CONTROL; else encry_mode = HW_ENCRY_SW_DECRY; } else { if (Adapter->registrypriv.software_decrypt == _FALSE) encry_mode = SW_ENCRY_HW_DECRY; else encry_mode = SW_CONTROL; } #else if ((psecuritypriv->sw_encrypt == _FALSE) && (psecuritypriv->sw_decrypt == _FALSE)) encry_mode = HW_CONTROL; else if ((psecuritypriv->sw_encrypt == _FALSE) && (psecuritypriv->sw_decrypt == _TRUE)) encry_mode = HW_ENCRY_SW_DECRY; else if ((psecuritypriv->sw_encrypt == _TRUE) && (psecuritypriv->sw_decrypt == _FALSE)) encry_mode = SW_ENCRY_HW_DECRY; else if ((psecuritypriv->sw_encrypt == _TRUE) && (psecuritypriv->sw_decrypt == _TRUE)) encry_mode = SW_CONTROL; #endif *(u8*)poid_par_priv->information_buf = encry_mode; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_encryption_ctrl_hdl: QUERY encry_mode=0x%x\n", encry_mode)); } return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; struct sta_info *psta = NULL; UCHAR *macaddr; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = ETH_ALEN; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) return NDIS_STATUS_INVALID_LENGTH; macaddr = (UCHAR *) poid_par_priv->information_buf ; RT_TRACE(_module_rtl871x_ioctl_c_,_drv_notice_, ("OID_RT_PRO_ADD_STA_INFO: addr="MAC_FMT"\n", MAC_ARG(macaddr) )); _irqlevel_changed_(&oldirql, LOWER); psta = rtw_get_stainfo(&Adapter->stapriv, macaddr); if (psta == NULL) { // the sta have been in sta_info_queue => do nothing psta = rtw_alloc_stainfo(&Adapter->stapriv, macaddr); if (psta == NULL) { RT_TRACE(_module_rtl871x_ioctl_c_,_drv_err_,("Can't alloc sta_info when OID_RT_PRO_ADD_STA_INFO\n")); status = NDIS_STATUS_FAILURE; } } else { //(between drv has received this event before and fw have not yet to set key to CAM_ENTRY) RT_TRACE(_module_rtl871x_ioctl_c_, _drv_err_, ("Error: OID_RT_PRO_ADD_STA_INFO: sta has been in sta_hash_queue \n")); } _irqlevel_changed_(&oldirql, RAISE); return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_dele_sta_info_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; struct sta_info *psta = NULL; UCHAR *macaddr; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = ETH_ALEN; if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) return NDIS_STATUS_INVALID_LENGTH; macaddr = (UCHAR *) poid_par_priv->information_buf ; RT_TRACE(_module_rtl871x_ioctl_c_,_drv_notice_, ("+OID_RT_PRO_ADD_STA_INFO: addr="MAC_FMT"\n", MAC_ARG(macaddr) )); psta = rtw_get_stainfo(&Adapter->stapriv, macaddr); if (psta != NULL) { _enter_critical(&(Adapter->stapriv.sta_hash_lock), &irqL); rtw_free_stainfo(Adapter, psta); _exit_critical(&(Adapter->stapriv.sta_hash_lock), &irqL); } return status; #else return 0; #endif } //------------------------------------------------------------------------------ #if 0 static u32 mp_query_drv_var(_adapter *padapter, u8 offset, u32 var) { #ifdef CONFIG_SDIO_HCI if (offset == 1) { u16 tmp_blk_num; tmp_blk_num = rtw_read16(padapter, SDIO_RX0_RDYBLK_NUM); RT_TRACE(_module_mp_, _drv_err_, ("Query Information, mp_query_drv_var SDIO_RX0_RDYBLK_NUM=0x%x dvobj.rxblknum=0x%x\n", tmp_blk_num, adapter_to_dvobj(padapter)->rxblknum)); if (adapter_to_dvobj(padapter)->rxblknum != tmp_blk_num) { RT_TRACE(_module_mp_,_drv_err_, ("Query Information, mp_query_drv_var call recv rx\n")); // sd_recv_rxfifo(padapter); } } #if 0 if(offset <=100){ //For setting data rate and query data rate if(offset==100){ //For query data rate RT_TRACE(_module_mp_, _drv_emerg_, ("\n mp_query_drv_var: offset(%d): query rate=0x%.2x \n",offset,padapter->registrypriv.tx_rate)); var=padapter->registrypriv.tx_rate; } else if(offset<0x1d){ //For setting data rate padapter->registrypriv.tx_rate=offset; var=padapter->registrypriv.tx_rate; padapter->registrypriv.use_rate=_TRUE; RT_TRACE(_module_mp_, _drv_emerg_, ("\n mp_query_drv_var: offset(%d): set rate=0x%.2x \n",offset,padapter->registrypriv.tx_rate)); } else{ //not use the data rate padapter->registrypriv.use_rate=_FALSE; RT_TRACE(_module_mp_, _drv_emerg_, ("\n mp_query_drv_var: offset(%d) out of rate range\n",offset)); } } else if (offset<=110){ //for setting debug level RT_TRACE(_module_mp_, _drv_emerg_, (" mp_query_drv_var: offset(%d) for set debug level\n",offset)); if(offset==110){ //For query data rate RT_TRACE(_module_mp_, _drv_emerg_, (" mp_query_drv_var: offset(%d): query dbg level=0x%.2x \n",offset,padapter->registrypriv.dbg_level)); padapter->registrypriv.dbg_level=GlobalDebugLevel; var=padapter->registrypriv.dbg_level; } else if(offset<110 && offset>100){ RT_TRACE(_module_mp_, _drv_emerg_, (" mp_query_drv_var: offset(%d): set dbg level=0x%.2x \n",offset,offset-100)); padapter->registrypriv.dbg_level=GlobalDebugLevel=offset-100; var=padapter->registrypriv.dbg_level; RT_TRACE(_module_mp_, _drv_emerg_, (" mp_query_drv_var(_drv_emerg_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_alert_, (" mp_query_drv_var(_drv_alert_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_crit_, (" mp_query_drv_var(_drv_crit_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_err_, (" mp_query_drv_var(_drv_err_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_warning_, (" mp_query_drv_var(_drv_warning_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_notice_, (" mp_query_drv_var(_drv_notice_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_info_, (" mp_query_drv_var(_drv_info_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); RT_TRACE(_module_mp_, _drv_debug_, (" mp_query_drv_var(_drv_debug_): offset(%d): set dbg level=0x%.2x \n",offset,GlobalDebugLevel)); } } else if(offset >110 &&offset <116){ if(115==offset){ RT_TRACE(_module_mp_, _drv_emerg_, (" mp_query_drv_var(_drv_emerg_): offset(%d): query TRX access type: [tx_block_mode=%x,rx_block_mode=%x]\n",\ offset, adapter_to_dvobj(padapter)->tx_block_mode, adapter_to_dvobj(padapter)->rx_block_mode)); } else { switch(offset){ case 111: adapter_to_dvobj(padapter)->tx_block_mode=1; adapter_to_dvobj(padapter)->rx_block_mode=1; RT_TRACE(_module_mp_, _drv_emerg_, \ (" mp_query_drv_var(_drv_emerg_): offset(%d): SET TRX access type:(TX block/RX block) [tx_block_mode=%x,rx_block_mode=%x]\n",\ offset, adapter_to_dvobj(padapter)->tx_block_mode, adapter_to_dvobj(padapter)->rx_block_mode)); break; case 112: adapter_to_dvobj(padapter)->tx_block_mode=1; adapter_to_dvobj(padapter)->rx_block_mode=0; RT_TRACE(_module_mp_, _drv_emerg_, \ (" mp_query_drv_var(_drv_emerg_): offset(%d): SET TRX access type:(TX block/RX byte) [tx_block_mode=%x,rx_block_mode=%x]\n",\ offset, adapter_to_dvobj(padapter)->tx_block_mode, adapter_to_dvobj(padapter)->rx_block_mode)); break; case 113: adapter_to_dvobj(padapter)->tx_block_mode=0; adapter_to_dvobj(padapter)->rx_block_mode=1; RT_TRACE(_module_mp_, _drv_emerg_, \ (" mp_query_drv_var(_drv_emerg_): offset(%d): SET TRX access type:(TX byte/RX block) [tx_block_mode=%x,rx_block_mode=%x]\n",\ offset, adapter_to_dvobj(padapter)->tx_block_mode, adapter_to_dvobj(padapter)->rx_block_mode)); break; case 114: adapter_to_dvobj(padapter)->tx_block_mode=0; adapter_to_dvobj(padapter)->rx_block_mode=0; RT_TRACE(_module_mp_, _drv_emerg_, \ (" mp_query_drv_var(_drv_emerg_): offset(%d): SET TRX access type:(TX byte/RX byte) [tx_block_mode=%x,rx_block_mode=%x]\n",\ offset, adapter_to_dvobj(padapter)->tx_block_mode, adapter_to_dvobj(padapter)->rx_block_mode)); break; default : break; } } } else if(offset>=127){ u64 prnt_dbg_comp; u8 chg_idx; u64 tmp_dbg_comp; chg_idx=offset-0x80; tmp_dbg_comp=BIT(chg_idx); prnt_dbg_comp=padapter->registrypriv.dbg_component= GlobalDebugComponents; RT_TRACE(_module_mp_, _drv_emerg_, (" 1: mp_query_drv_var: offset(%d;0x%x):for dbg conpoment prnt_dbg_comp=0x%.16x GlobalDebugComponents=0x%.16x padapter->registrypriv.dbg_component=0x%.16x\n",offset,offset,prnt_dbg_comp,GlobalDebugComponents,padapter->registrypriv.dbg_component)); if(offset==127){ // prnt_dbg_comp=padapter->registrypriv.dbg_component= GlobalDebugComponents; var=(u32)(padapter->registrypriv.dbg_component); RT_TRACE(0xffffffff, _drv_emerg_, ("2: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h) \n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp)); prnt_dbg_comp=GlobalDebugComponents; RT_TRACE(0xffffffff, _drv_emerg_, ("2-1: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h)\n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp)); prnt_dbg_comp=GlobalDebugComponents=padapter->registrypriv.dbg_component; RT_TRACE(0xffffffff, _drv_emerg_, ("2-2: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h)\n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp)); } else{ RT_TRACE(0xffffffff, _drv_emerg_, ("3: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h) chg_idx=%d\n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp,chg_idx)); prnt_dbg_comp=GlobalDebugComponents; RT_TRACE(0xffffffff, _drv_emerg_,("3-1: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h) chg_idx=%d\n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp,chg_idx));// ("3-1: mp_query_drv_var: offset(%d;0x%x):before set dbg conpoment=0x%x chg_idx=%d or0x%x BIT(chg_idx[%d]=0x%x)\n",offset,offset,prnt_dbg_comp,chg_idx,chg_idx,(chg_idx),tmp_dbg_comp) prnt_dbg_comp=GlobalDebugComponents=padapter->registrypriv.dbg_component; RT_TRACE(0xffffffff, _drv_emerg_, ("3-2: mp_query_drv_var: offset(%d;0x%x):for query dbg conpoment=0x%x(l) 0x%x(h) GlobalDebugComponents=0x%x(l) 0x%x(h)\n",offset,offset,padapter->registrypriv.dbg_component,prnt_dbg_comp)); if(GlobalDebugComponents&tmp_dbg_comp){ //this bit is already set, now clear it GlobalDebugComponents=GlobalDebugComponents&(~tmp_dbg_comp); } else{ //this bit is not set, now set it. GlobalDebugComponents =GlobalDebugComponents|tmp_dbg_comp; } RT_TRACE(0xffffffff, _drv_emerg_, ("4: mp_query_drv_var: offset(%d;0x%x):before set dbg conpoment tmp_dbg_comp=0x%x GlobalDebugComponents=0x%x(l) 0x%x(h)",offset,offset,tmp_dbg_comp,prnt_dbg_comp)); prnt_dbg_comp=GlobalDebugComponents; RT_TRACE(0xffffffff, _drv_emerg_, ("4-1: mp_query_drv_var: offset(%d;0x%x):before set dbg conpoment tmp_dbg_comp=0x%x GlobalDebugComponents=0x%x(l) 0x%x(h)",offset,offset,tmp_dbg_comp,prnt_dbg_comp)); RT_TRACE(_module_rtl871x_xmit_c_, _drv_emerg_, ("0: mp_query_drv_var(_module_rtl871x_xmit_c_:0): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,prnt_dbg_comp)); RT_TRACE(_module_xmit_osdep_c_, _drv_emerg_, ("1: mp_query_drv_var(_module_xmit_osdep_c_:1): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_recv_c_, _drv_emerg_, ("2: mp_query_drv_var(_module_rtl871x_recv_c_:2): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_recv_osdep_c_, _drv_emerg_, ("3: mp_query_drv_var(_module_recv_osdep_c_:3): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_mlme_c_, _drv_emerg_, ("4: mp_query_drv_var(_module_rtl871x_mlme_c_:4): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_mlme_osdep_c_, _drv_emerg_, (" 5:mp_query_drv_var(_module_mlme_osdep_c_:5): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_emerg_, ("6: mp_query_drv_var(_module_rtl871x_sta_mgt_c_:6): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_cmd_c_, _drv_emerg_, ("7: mp_query_drv_var(_module_rtl871x_cmd_c_:7): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_cmd_osdep_c_, _drv_emerg_, ("8: mp_query_drv_var(_module_cmd_osdep_c_:8): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_io_c_, _drv_emerg_, ("9: mp_query_drv_var(_module_rtl871x_io_c_:9): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_io_osdep_c_, _drv_emerg_, ("10: mp_query_drv_var(_module_io_osdep_c_:10): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_os_intfs_c_, _drv_emerg_, ("11: mp_query_drv_var(_module_os_intfs_c_:11): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_security_c_, _drv_emerg_, ("12: mp_query_drv_var(_module_rtl871x_security_c_:12): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_eeprom_c_, _drv_emerg_, ("13: mp_query_drv_var(_module_rtl871x_eeprom_c_:13): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_hal_init_c_, _drv_emerg_, ("14: mp_query_drv_var(_module_hal_init_c_:14): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_hci_hal_init_c_, _drv_emerg_, ("15: mp_query_drv_var(_module_hci_hal_init_c_:15): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_ioctl_c_, _drv_emerg_, ("16: mp_query_drv_var(_module_rtl871x_ioctl_c_:16): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_emerg_, ("17: mp_query_drv_var(_module_rtl871x_ioctl_set_c_:17): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_ioctl_query_c_, _drv_emerg_, ("18: mp_query_drv_var(_module_rtl871x_ioctl_query_c_:18): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_emerg_, ("19: mp_query_drv_var(_module_rtl871x_pwrctrl_c_:19): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_hci_intfs_c_, _drv_emerg_, ("20: mp_query_drv_var(_module_hci_intfs_c_:20): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_hci_ops_c_, _drv_emerg_, ("21: mp_query_drv_var(_module_hci_ops_c_:21): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_osdep_service_c_, _drv_emerg_, ("22: mp_query_drv_var(_module_osdep_service_c_:22): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_mp_, _drv_emerg_, ("23: mp_query_drv_var(_module_mp_:23): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); RT_TRACE(_module_hci_ops_os_c_, _drv_emerg_, ("24: mp_query_drv_var(_module_hci_ops_os_c_:24): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); var=(u32)(GlobalDebugComponents); //GlobalDebugComponents=padapter->registrypriv.dbg_component; RT_TRACE(0xffffffff, _drv_emerg_, (" ==mp_query_drv_var(_module_mp_): offset(%d;0x%x):before set dbg conpoment=0x%x(l) 0x%x(h)\n",offset,offset,GlobalDebugComponents)); } } else{ RT_TRACE(_module_mp_, _drv_emerg_, ("\n mp_query_drv_var: offset(%d) >110\n",offset)); } #endif #endif return var; } #endif NDIS_STATUS oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; DR_VARIABLE_STRUCT *pdrv_var; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; *poid_par_priv->bytes_needed = sizeof(DR_VARIABLE_STRUCT); if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) return NDIS_STATUS_INVALID_LENGTH; RT_TRACE(_module_mp_, _drv_notice_, ("+Query Information, OID_RT_PRO_QUERY_DR_VARIABLE\n")); pdrv_var = (struct _DR_VARIABLE_STRUCT_ *)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); pdrv_var->variable = mp_query_drv_var(Adapter, pdrv_var->offset, pdrv_var->variable); _irqlevel_changed_(&oldirql, RAISE); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_notice_, ("-oid_rt_pro_query_dr_variable_hdl: offset=0x%x valule=0x%x\n", pdrv_var->offset, pdrv_var->variable)); return status; #else return 0; #endif } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; RT_TRACE(_module_mp_, _drv_err_, ("oid_rt_pro_rx_packet_type_hdl...................\n")); if (poid_par_priv->information_buf_len < sizeof (UCHAR)) { status = NDIS_STATUS_INVALID_LENGTH; *poid_par_priv->bytes_needed = sizeof(UCHAR); return status; } if (poid_par_priv->type_of_oid == SET_OID) { Adapter->mppriv.rx_with_status = *(UCHAR *) poid_par_priv->information_buf; RT_TRACE(_module_rtl871x_ioctl_c_,_drv_err_, ("Query Information, OID_RT_PRO_RX_PACKET_TYPE:%d \n",\ Adapter->mppriv.rx_with_status)); //*(u32 *)&Adapter->eeprompriv.mac_addr[0]=rtw_read32(Adapter, 0x10250050); //*(u16 *)&Adapter->eeprompriv.mac_addr[4]=rtw_read16(Adapter, 0x10250054); RT_TRACE(_module_rtl871x_ioctl_c_,_drv_err_,("MAC addr=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x \n", Adapter->eeprompriv.mac_addr[0],Adapter->eeprompriv.mac_addr[1],Adapter->eeprompriv.mac_addr[2],\ Adapter->eeprompriv.mac_addr[3],Adapter->eeprompriv.mac_addr[4],Adapter->eeprompriv.mac_addr[5])); } else { *(UCHAR *) poid_par_priv->information_buf = Adapter->mppriv.rx_with_status; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_rtl871x_ioctl_c_,_drv_err_, ("Query Information, OID_RT_PRO_RX_PACKET_TYPE:%d \n", \ Adapter->mppriv.rx_with_status)); //*(u32 *)&Adapter->eeprompriv.mac_addr[0]=rtw_read32(Adapter, 0x10250050); //*(u16 *)&Adapter->eeprompriv.mac_addr[4]=rtw_read16(Adapter, 0x10250054); RT_TRACE(_module_rtl871x_ioctl_c_,_drv_err_,("MAC addr=0x%x:0x%x:0x%x:0x%x:0x%x:0x%x \n", Adapter->eeprompriv.mac_addr[0],Adapter->eeprompriv.mac_addr[1],Adapter->eeprompriv.mac_addr[2],\ Adapter->eeprompriv.mac_addr[3],Adapter->eeprompriv.mac_addr[4],Adapter->eeprompriv.mac_addr[5])); } #endif return NDIS_STATUS_SUCCESS; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif PEFUSE_ACCESS_STRUCT pefuse; u8 *data; u16 addr = 0, cnts = 0, max_available_size = 0; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(EFUSE_ACCESS_STRUCT)) return NDIS_STATUS_INVALID_LENGTH; pefuse = (PEFUSE_ACCESS_STRUCT)poid_par_priv->information_buf; addr = pefuse->start_addr; cnts = pefuse->cnts; data = pefuse->data; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_read_efuse_hd: buf_len=%d addr=%d cnts=%d\n", poid_par_priv->information_buf_len, addr, cnts)); EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE); if ((addr + cnts) > max_available_size) { RT_TRACE(_module_mp_, _drv_err_, ("!oid_rt_pro_read_efuse_hdl: parameter error!\n")); return NDIS_STATUS_NOT_ACCEPTED; } _irqlevel_changed_(&oldirql, LOWER); if (rtw_efuse_access(Adapter, _FALSE, addr, cnts, data) == _FAIL) { RT_TRACE(_module_mp_, _drv_err_, ("!oid_rt_pro_read_efuse_hdl: rtw_efuse_access FAIL!\n")); status = NDIS_STATUS_FAILURE; } else *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif PEFUSE_ACCESS_STRUCT pefuse; u8 *data; u16 addr = 0, cnts = 0, max_available_size = 0; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; pefuse = (PEFUSE_ACCESS_STRUCT)poid_par_priv->information_buf; addr = pefuse->start_addr; cnts = pefuse->cnts; data = pefuse->data; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_write_efuse_hdl: buf_len=%d addr=0x%04x cnts=%d\n", poid_par_priv->information_buf_len, addr, cnts)); EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE); if ((addr + cnts) > max_available_size) { RT_TRACE(_module_mp_, _drv_err_, ("!oid_rt_pro_write_efuse_hdl: parameter error")); return NDIS_STATUS_NOT_ACCEPTED; } _irqlevel_changed_(&oldirql, LOWER); if (rtw_efuse_access(Adapter, _TRUE, addr, cnts, data) == _FAIL) status = NDIS_STATUS_FAILURE; _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif PPGPKT_STRUCT ppgpkt; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; // RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_pro_rw_efuse_pgpkt_hdl\n")); *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < sizeof(PGPKT_STRUCT)) return NDIS_STATUS_INVALID_LENGTH; ppgpkt = (PPGPKT_STRUCT)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); if (poid_par_priv->type_of_oid == QUERY_OID) { RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_rw_efuse_pgpkt_hdl: Read offset=0x%x\n",\ ppgpkt->offset)); Efuse_PowerSwitch(Adapter, _FALSE, _TRUE); if (Efuse_PgPacketRead(Adapter, ppgpkt->offset, ppgpkt->data, _FALSE) == _TRUE) *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; else status = NDIS_STATUS_FAILURE; Efuse_PowerSwitch(Adapter, _FALSE, _FALSE); } else { RT_TRACE(_module_mp_, _drv_notice_, ("oid_rt_pro_rw_efuse_pgpkt_hdl: Write offset=0x%x word_en=0x%x\n",\ ppgpkt->offset, ppgpkt->word_en)); Efuse_PowerSwitch(Adapter, _TRUE, _TRUE); if (Efuse_PgPacketWrite(Adapter, ppgpkt->offset, ppgpkt->word_en, ppgpkt->data, _FALSE) == _TRUE) *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; else status = NDIS_STATUS_FAILURE; Efuse_PowerSwitch(Adapter, _TRUE, _FALSE); } _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_rw_efuse_pgpkt_hdl: status=0x%08X\n", status)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_get_efuse_current_size_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u16 size; u8 ret; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len <sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; _irqlevel_changed_(&oldirql, LOWER); ret = efuse_GetCurrentSize(Adapter, &size); _irqlevel_changed_(&oldirql, RAISE); if (ret == _SUCCESS) { *(u32*)poid_par_priv->information_buf = size; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; } else status = NDIS_STATUS_FAILURE; _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; *(u32*)poid_par_priv->information_buf = efuse_GetMaxSize(Adapter); *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_get_efuse_max_size_hdl: size=%d status=0x%08X\n", *(int*)poid_par_priv->information_buf, status)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status; _func_enter_; RT_TRACE(_module_mp_, _drv_info_, ("+oid_rt_pro_efuse_hdl\n")); if (poid_par_priv->type_of_oid == QUERY_OID) status = oid_rt_pro_read_efuse_hdl(poid_par_priv); else status = oid_rt_pro_write_efuse_hdl(poid_par_priv); RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_efuse_hdl: status=0x%08X\n", status)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u8 *data; NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); u16 mapLen=0; _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_pro_efuse_map_hdl\n")); EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE); *poid_par_priv->bytes_rw = 0; if (poid_par_priv->information_buf_len < mapLen) return NDIS_STATUS_INVALID_LENGTH; data = (u8*)poid_par_priv->information_buf; _irqlevel_changed_(&oldirql, LOWER); if (poid_par_priv->type_of_oid == QUERY_OID) { RT_TRACE(_module_mp_, _drv_info_, ("oid_rt_pro_efuse_map_hdl: READ\n")); if (rtw_efuse_map_read(Adapter, 0, mapLen, data) == _SUCCESS) *poid_par_priv->bytes_rw = mapLen; else { RT_TRACE(_module_mp_, _drv_err_, ("oid_rt_pro_efuse_map_hdl: READ fail\n")); status = NDIS_STATUS_FAILURE; } } else { // SET_OID RT_TRACE(_module_mp_, _drv_info_, ("oid_rt_pro_efuse_map_hdl: WRITE\n")); if (rtw_efuse_map_write(Adapter, 0, mapLen, data) == _SUCCESS) *poid_par_priv->bytes_rw = mapLen; else { RT_TRACE(_module_mp_, _drv_err_, ("oid_rt_pro_efuse_map_hdl: WRITE fail\n")); status = NDIS_STATUS_FAILURE; } } _irqlevel_changed_(&oldirql, RAISE); RT_TRACE(_module_mp_, _drv_info_, ("-oid_rt_pro_efuse_map_hdl: status=0x%08X\n", status)); _func_exit_; return status; } NDIS_STATUS oid_rt_set_crystal_cap_hdl(struct oid_par_priv *poid_par_priv) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u32 crystal_cap = 0; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len <sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; crystal_cap = *((u32*)poid_par_priv->information_buf);//4 if (crystal_cap > 0xf) return NDIS_STATUS_NOT_ACCEPTED; Adapter->mppriv.curr_crystalcap = crystal_cap; _irqlevel_changed_(&oldirql,LOWER); SetCrystalCap(Adapter); _irqlevel_changed_(&oldirql,RAISE); _func_exit_; #endif return status; } NDIS_STATUS oid_rt_set_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u8 rx_pkt_type; // u32 rcr_val32; NDIS_STATUS status = NDIS_STATUS_SUCCESS; // PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); _func_enter_; RT_TRACE(_module_mp_, _drv_notice_, ("+oid_rt_set_rx_packet_type_hdl\n")); if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u8)) return NDIS_STATUS_INVALID_LENGTH; rx_pkt_type = *((u8*)poid_par_priv->information_buf);//4 RT_TRACE(_module_mp_, _drv_info_, ("rx_pkt_type: %x\n",rx_pkt_type )); #if 0 _irqlevel_changed_(&oldirql, LOWER); #if 0 rcr_val8 = rtw_read8(Adapter, 0x10250048);//RCR rcr_val8 &= ~(RCR_AB|RCR_AM|RCR_APM|RCR_AAP); if(rx_pkt_type == RX_PKT_BROADCAST){ rcr_val8 |= (RCR_AB | RCR_ACRC32 ); } else if(rx_pkt_type == RX_PKT_DEST_ADDR){ rcr_val8 |= (RCR_AAP| RCR_AM |RCR_ACRC32); } else if(rx_pkt_type == RX_PKT_PHY_MATCH){ rcr_val8 |= (RCR_APM|RCR_ACRC32); } else{ rcr_val8 &= ~(RCR_AAP|RCR_APM|RCR_AM|RCR_AB|RCR_ACRC32); } rtw_write8(padapter, 0x10250048,rcr_val8); #else rcr_val32 = rtw_read32(padapter, RCR);//RCR = 0x10250048 rcr_val32 &= ~(RCR_CBSSID|RCR_AB|RCR_AM|RCR_APM|RCR_AAP); #if 0 if(rx_pkt_type == RX_PKT_BROADCAST){ rcr_val32 |= (RCR_AB|RCR_AM|RCR_APM|RCR_AAP|RCR_ACRC32); } else if(rx_pkt_type == RX_PKT_DEST_ADDR){ //rcr_val32 |= (RCR_CBSSID|RCR_AAP|RCR_AM|RCR_ACRC32); rcr_val32 |= (RCR_CBSSID|RCR_APM|RCR_ACRC32); } else if(rx_pkt_type == RX_PKT_PHY_MATCH){ rcr_val32 |= (RCR_APM|RCR_ACRC32); //rcr_val32 |= (RCR_AAP|RCR_ACRC32); } else{ rcr_val32 &= ~(RCR_AAP|RCR_APM|RCR_AM|RCR_AB|RCR_ACRC32); } #else switch (rx_pkt_type) { case RX_PKT_BROADCAST : rcr_val32 |= (RCR_AB|RCR_AM|RCR_APM|RCR_AAP|RCR_ACRC32); break; case RX_PKT_DEST_ADDR : rcr_val32 |= (RCR_AB|RCR_AM|RCR_APM|RCR_AAP|RCR_ACRC32); break; case RX_PKT_PHY_MATCH: rcr_val32 |= (RCR_APM|RCR_ACRC32); break; default: rcr_val32 &= ~(RCR_AAP|RCR_APM|RCR_AM|RCR_AB|RCR_ACRC32); break; } if (rx_pkt_type == RX_PKT_DEST_ADDR) { padapter->mppriv.check_mp_pkt = 1; } else { padapter->mppriv.check_mp_pkt = 0; } #endif rtw_write32(padapter, RCR, rcr_val32); #endif _irqlevel_changed_(&oldirql, RAISE); #endif _func_exit_; return status; } NDIS_STATUS oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); #ifdef PLATFORM_OS_XP _irqL oldirql; #endif NDIS_STATUS status = NDIS_STATUS_SUCCESS; u32 txagc; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len < sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; txagc = *(u32*)poid_par_priv->information_buf; RT_TRACE(_module_mp_, _drv_info_, ("oid_rt_pro_set_tx_agc_offset_hdl: 0x%08x\n", txagc)); _irqlevel_changed_(&oldirql, LOWER); SetTxAGCOffset(Adapter, txagc); _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; #else return 0; #endif } NDIS_STATUS oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv *poid_par_priv) { #if 0 PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); NDIS_STATUS status = NDIS_STATUS_SUCCESS; struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; struct mp_priv *pmppriv = &Adapter->mppriv; u32 type; _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) return NDIS_STATUS_NOT_ACCEPTED; if (poid_par_priv->information_buf_len <sizeof(u32)) return NDIS_STATUS_INVALID_LENGTH; type = *(u32*)poid_par_priv->information_buf; if (_LOOPBOOK_MODE_ == type) { pmppriv->mode = type; set_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE); //append txdesc RT_TRACE(_module_mp_, _drv_info_, ("test mode change to loopback mode:0x%08x.\n", get_fwstate(pmlmepriv))); } else if (_2MAC_MODE_ == type){ pmppriv->mode = type; _clr_fwstate_(pmlmepriv, WIFI_MP_LPBK_STATE); RT_TRACE(_module_mp_, _drv_info_, ("test mode change to 2mac mode:0x%08x.\n", get_fwstate(pmlmepriv))); } else status = NDIS_STATUS_NOT_ACCEPTED; _func_exit_; return status; #else return 0; #endif } unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv) { PMP_XMIT_PARM pparm; PADAPTER padapter; struct mp_priv *pmp_priv; struct pkt_attrib *pattrib; RT_TRACE(_module_mp_, _drv_notice_, ("+%s\n", __func__)); pparm = (PMP_XMIT_PARM)poid_par_priv->information_buf; padapter = (PADAPTER)poid_par_priv->adapter_context; pmp_priv = &padapter->mppriv; if (poid_par_priv->type_of_oid == QUERY_OID) { pparm->enable = !pmp_priv->tx.stop; pparm->count = pmp_priv->tx.sended; } else { if (pparm->enable == 0) { pmp_priv->tx.stop = 1; } else if (pmp_priv->tx.stop == 1) { pmp_priv->tx.stop = 0; pmp_priv->tx.count = pparm->count; pmp_priv->tx.payload = pparm->payload_type; pattrib = &pmp_priv->tx.attrib; pattrib->pktlen = pparm->length; _rtw_memcpy(pattrib->dst, pparm->da, ETH_ALEN); SetPacketTx(padapter); } else return NDIS_STATUS_FAILURE; } return NDIS_STATUS_SUCCESS; } #if 0 unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv) { unsigned char *pframe, *pmp_pkt; struct ethhdr *pethhdr; struct pkt_attrib *pattrib; struct rtw_ieee80211_hdr *pwlanhdr; unsigned short *fctrl; int llc_sz, payload_len; struct mp_xmit_frame *pxframe= NULL; struct mp_xmit_packet *pmp_xmitpkt = (struct mp_xmit_packet*)param; u8 addr3[] = {0x02, 0xE0, 0x4C, 0x87, 0x66, 0x55}; // DBG_871X("+mp_ioctl_xmit_packet_hdl\n"); pxframe = alloc_mp_xmitframe(&padapter->mppriv); if (pxframe == NULL) { DEBUG_ERR(("Can't alloc pmpframe %d:%s\n", __LINE__, __FILE__)); return -1; } //mp_xmit_pkt payload_len = pmp_xmitpkt->len - 14; pmp_pkt = (unsigned char*)pmp_xmitpkt->mem; pethhdr = (struct ethhdr *)pmp_pkt; //DBG_871X("payload_len=%d, pkt_mem=0x%x\n", pmp_xmitpkt->len, (void*)pmp_xmitpkt->mem); //DBG_871X("pxframe=0x%x\n", (void*)pxframe); //DBG_871X("pxframe->mem=0x%x\n", (void*)pxframe->mem); //update attribute pattrib = &pxframe->attrib; memset((u8 *)(pattrib), 0, sizeof (struct pkt_attrib)); pattrib->pktlen = pmp_xmitpkt->len; pattrib->ether_type = ntohs(pethhdr->h_proto); pattrib->hdrlen = 24; pattrib->nr_frags = 1; pattrib->priority = 0; #ifndef CONFIG_MP_LINUX if(IS_MCAST(pethhdr->h_dest)) pattrib->mac_id = 4; else pattrib->mac_id = 5; #else pattrib->mac_id = 5; #endif // memset(pxframe->mem, 0 , WLANHDR_OFFSET); pframe = (u8 *)(pxframe->mem) + WLANHDR_OFFSET; pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; fctrl = &(pwlanhdr->frame_ctl); *(fctrl) = 0; SetFrameSubType(pframe, WIFI_DATA); _rtw_memcpy(pwlanhdr->addr1, pethhdr->h_dest, ETH_ALEN); _rtw_memcpy(pwlanhdr->addr2, pethhdr->h_source, ETH_ALEN); _rtw_memcpy(pwlanhdr->addr3, addr3, ETH_ALEN); pwlanhdr->seq_ctl = 0; pframe += pattrib->hdrlen; llc_sz= rtw_put_snap(pframe, pattrib->ether_type); pframe += llc_sz; _rtw_memcpy(pframe, (void*)(pmp_pkt+14), payload_len); pattrib->last_txcmdsz = pattrib->hdrlen + llc_sz + payload_len; DEBUG_INFO(("issuing mp_xmit_frame, tx_len=%d, ether_type=0x%x\n", pattrib->last_txcmdsz, pattrib->ether_type)); xmit_mp_frame(padapter, pxframe); return _SUCCESS; } #endif //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv) { #ifdef PLATFORM_OS_XP _irqL oldirql; #endif u8 bpwrup; NDIS_STATUS status = NDIS_STATUS_SUCCESS; #ifdef PLATFORM_LINUX #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); #endif #endif _func_enter_; if (poid_par_priv->type_of_oid != SET_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } RT_TRACE(_module_mp_, _drv_info_, ("\n ===> Setoid_rt_set_power_down_hdl.\n")); _irqlevel_changed_(&oldirql, LOWER); bpwrup = *(u8 *)poid_par_priv->information_buf; //CALL the power_down function #ifdef PLATFORM_LINUX #if defined(CONFIG_RTL8712) //Linux MP insmod unknown symbol dev_power_down(padapter,bpwrup); #endif #endif _irqlevel_changed_(&oldirql, RAISE); //DEBUG_ERR(("\n <=== Query OID_RT_PRO_READ_REGISTER. // Add:0x%08x Width:%d Value:0x%08x\n",RegRWStruct->offset,RegRWStruct->width,RegRWStruct->value)); _func_exit_; return status; } //------------------------------------------------------------------------------ NDIS_STATUS oid_rt_get_power_mode_hdl(struct oid_par_priv *poid_par_priv) { #if 0 NDIS_STATUS status = NDIS_STATUS_SUCCESS; PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); //#ifdef PLATFORM_OS_XP // _irqL oldirql; //#endif _func_enter_; if (poid_par_priv->type_of_oid != QUERY_OID) { status = NDIS_STATUS_NOT_ACCEPTED; return status; } if (poid_par_priv->information_buf_len < sizeof(u32)) { status = NDIS_STATUS_INVALID_LENGTH; return status; } RT_TRACE(_module_mp_, _drv_info_, ("\n ===> oid_rt_get_power_mode_hdl.\n")); // _irqlevel_changed_(&oldirql, LOWER); *(int*)poid_par_priv->information_buf = Adapter->registrypriv.low_power ? POWER_LOW : POWER_NORMAL; *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; // _irqlevel_changed_(&oldirql, RAISE); _func_exit_; return status; #else return 0; #endif }
gpl-2.0
mdr78/Linux-3.8.7-galileo
drivers/cpufreq/speedstep-ich.c
318
9478
/* * (C) 2001 Dave Jones, Arjan van de ven. * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> * * Licensed under the terms of the GNU GPL License version 2. * Based upon reverse engineered information, and on Intel documentation * for chipsets ICH2-M and ICH3-M. * * Many thanks to Ducrot Bruno for finding and fixing the last * "missing link" for ICH2-M/ICH3-M support, and to Thomas Winkler * for extensive testing. * * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* */ /********************************************************************* * SPEEDSTEP - DEFINITIONS * *********************************************************************/ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/cpufreq.h> #include <linux/pci.h> #include <linux/sched.h> #include <asm/cpu_device_id.h> #include "speedstep-lib.h" /* speedstep_chipset: * It is necessary to know which chipset is used. As accesses to * this device occur at various places in this module, we need a * static struct pci_dev * pointing to that device. */ static struct pci_dev *speedstep_chipset_dev; /* speedstep_processor */ static enum speedstep_processor speedstep_processor; static u32 pmbase; /* * There are only two frequency states for each processor. Values * are in kHz for the time being. */ static struct cpufreq_frequency_table speedstep_freqs[] = { {SPEEDSTEP_HIGH, 0}, {SPEEDSTEP_LOW, 0}, {0, CPUFREQ_TABLE_END}, }; /** * speedstep_find_register - read the PMBASE address * * Returns: -ENODEV if no register could be found */ static int speedstep_find_register(void) { if (!speedstep_chipset_dev) return -ENODEV; /* get PMBASE */ pci_read_config_dword(speedstep_chipset_dev, 0x40, &pmbase); if (!(pmbase & 0x01)) { printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); return -ENODEV; } pmbase &= 0xFFFFFFFE; if (!pmbase) { printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); return -ENODEV; } pr_debug("pmbase is 0x%x\n", pmbase); return 0; } /** * speedstep_set_state - set the SpeedStep state * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) * * Tries to change the SpeedStep state. Can be called from * smp_call_function_single. */ static void speedstep_set_state(unsigned int state) { u8 pm2_blk; u8 value; unsigned long flags; if (state > 0x1) return; /* Disable IRQs */ local_irq_save(flags); /* read state */ value = inb(pmbase + 0x50); pr_debug("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); /* write new state */ value &= 0xFE; value |= state; pr_debug("writing 0x%x to pmbase 0x%x + 0x50\n", value, pmbase); /* Disable bus master arbitration */ pm2_blk = inb(pmbase + 0x20); pm2_blk |= 0x01; outb(pm2_blk, (pmbase + 0x20)); /* Actual transition */ outb(value, (pmbase + 0x50)); /* Restore bus master arbitration */ pm2_blk &= 0xfe; outb(pm2_blk, (pmbase + 0x20)); /* check if transition was successful */ value = inb(pmbase + 0x50); /* Enable IRQs */ local_irq_restore(flags); pr_debug("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); if (state == (value & 0x1)) pr_debug("change to %u MHz succeeded\n", speedstep_get_frequency(speedstep_processor) / 1000); else printk(KERN_ERR "cpufreq: change failed - I/O error\n"); return; } /* Wrapper for smp_call_function_single. */ static void _speedstep_set_state(void *_state) { speedstep_set_state(*(unsigned int *)_state); } /** * speedstep_activate - activate SpeedStep control in the chipset * * Tries to activate the SpeedStep status and control registers. * Returns -EINVAL on an unsupported chipset, and zero on success. */ static int speedstep_activate(void) { u16 value = 0; if (!speedstep_chipset_dev) return -EINVAL; pci_read_config_word(speedstep_chipset_dev, 0x00A0, &value); if (!(value & 0x08)) { value |= 0x08; pr_debug("activating SpeedStep (TM) registers\n"); pci_write_config_word(speedstep_chipset_dev, 0x00A0, value); } return 0; } /** * speedstep_detect_chipset - detect the Southbridge which contains SpeedStep logic * * Detects ICH2-M, ICH3-M and ICH4-M so far. The pci_dev points to * the LPC bridge / PM module which contains all power-management * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected * chipset, or zero on failure. */ static unsigned int speedstep_detect_chipset(void) { speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID, PCI_ANY_ID, NULL); if (speedstep_chipset_dev) return 4; /* 4-M */ speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID, PCI_ANY_ID, NULL); if (speedstep_chipset_dev) return 3; /* 3-M */ speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID, PCI_ANY_ID, NULL); if (speedstep_chipset_dev) { /* speedstep.c causes lockups on Dell Inspirons 8000 and * 8100 which use a pretty old revision of the 82815 * host bridge. Abort on these systems. */ static struct pci_dev *hostbridge; hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_MC, PCI_ANY_ID, PCI_ANY_ID, NULL); if (!hostbridge) return 2; /* 2-M */ if (hostbridge->revision < 5) { pr_debug("hostbridge does not support speedstep\n"); speedstep_chipset_dev = NULL; pci_dev_put(hostbridge); return 0; } pci_dev_put(hostbridge); return 2; /* 2-M */ } return 0; } static void get_freq_data(void *_speed) { unsigned int *speed = _speed; *speed = speedstep_get_frequency(speedstep_processor); } static unsigned int speedstep_get(unsigned int cpu) { unsigned int speed; /* You're supposed to ensure CPU is online. */ if (smp_call_function_single(cpu, get_freq_data, &speed, 1) != 0) BUG(); pr_debug("detected %u kHz as current frequency\n", speed); return speed; } /** * speedstep_target - set a new CPUFreq policy * @policy: new policy * @index: index of target frequency * * Sets a new CPUFreq policy. */ static int speedstep_target(struct cpufreq_policy *policy, unsigned int index) { unsigned int policy_cpu; policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); smp_call_function_single(policy_cpu, _speedstep_set_state, &index, true); return 0; } struct get_freqs { struct cpufreq_policy *policy; int ret; }; static void get_freqs_on_cpu(void *_get_freqs) { struct get_freqs *get_freqs = _get_freqs; get_freqs->ret = speedstep_get_freqs(speedstep_processor, &speedstep_freqs[SPEEDSTEP_LOW].frequency, &speedstep_freqs[SPEEDSTEP_HIGH].frequency, &get_freqs->policy->cpuinfo.transition_latency, &speedstep_set_state); } static int speedstep_cpu_init(struct cpufreq_policy *policy) { unsigned int policy_cpu; struct get_freqs gf; /* only run on CPU to be set, or on its sibling */ #ifdef CONFIG_SMP cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); #endif policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); /* detect low and high frequency and transition latency */ gf.policy = policy; smp_call_function_single(policy_cpu, get_freqs_on_cpu, &gf, 1); if (gf.ret) return gf.ret; return cpufreq_table_validate_and_show(policy, speedstep_freqs); } static struct cpufreq_driver speedstep_driver = { .name = "speedstep-ich", .verify = cpufreq_generic_frequency_table_verify, .target_index = speedstep_target, .init = speedstep_cpu_init, .exit = cpufreq_generic_exit, .get = speedstep_get, .attr = cpufreq_generic_attr, }; static const struct x86_cpu_id ss_smi_ids[] = { { X86_VENDOR_INTEL, 6, 0xb, }, { X86_VENDOR_INTEL, 6, 0x8, }, { X86_VENDOR_INTEL, 15, 2 }, {} }; #if 0 /* Autoload or not? Do not for now. */ MODULE_DEVICE_TABLE(x86cpu, ss_smi_ids); #endif /** * speedstep_init - initializes the SpeedStep CPUFreq driver * * Initializes the SpeedStep support. Returns -ENODEV on unsupported * devices, -EINVAL on problems during initiatization, and zero on * success. */ static int __init speedstep_init(void) { if (!x86_match_cpu(ss_smi_ids)) return -ENODEV; /* detect processor */ speedstep_processor = speedstep_detect_processor(); if (!speedstep_processor) { pr_debug("Intel(R) SpeedStep(TM) capable processor " "not found\n"); return -ENODEV; } /* detect chipset */ if (!speedstep_detect_chipset()) { pr_debug("Intel(R) SpeedStep(TM) for this chipset not " "(yet) available.\n"); return -ENODEV; } /* activate speedstep support */ if (speedstep_activate()) { pci_dev_put(speedstep_chipset_dev); return -EINVAL; } if (speedstep_find_register()) return -ENODEV; return cpufreq_register_driver(&speedstep_driver); } /** * speedstep_exit - unregisters SpeedStep support * * Unregisters SpeedStep support. */ static void __exit speedstep_exit(void) { pci_dev_put(speedstep_chipset_dev); cpufreq_unregister_driver(&speedstep_driver); } MODULE_AUTHOR("Dave Jones <davej@redhat.com>, " "Dominik Brodowski <linux@brodo.de>"); MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets " "with ICH-M southbridges."); MODULE_LICENSE("GPL"); module_init(speedstep_init); module_exit(speedstep_exit);
gpl-2.0
maikelwever/android_kernel_htc_msm8660-caf
drivers/usb/serial/cypress_m8.c
574
43217
/* * USB Cypress M8 driver * * Copyright (C) 2004 * Lonnie Mendez (dignome@gmail.com) * Copyright (C) 2003,2004 * Neil Whelchel (koyama@firstlight.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * See Documentation/usb/usb-serial.txt for more information on using this * driver * * See http://geocities.com/i0xox0i for information on this driver and the * earthmate usb device. * * Lonnie Mendez <dignome@gmail.com> * 4-29-2005 * Fixed problem where setting or retreiving the serial config would fail * with EPIPE. Removed CRTS toggling so the driver behaves more like * other usbserial adapters. Issued new interval of 1ms instead of the * default 10ms. As a result, transfer speed has been substantially * increased from avg. 850bps to avg. 3300bps. initial termios has also * been modified. Cleaned up code and formatting issues so it is more * readable. Replaced the C++ style comments. * * Lonnie Mendez <dignome@gmail.com> * 12-15-2004 * Incorporated write buffering from pl2303 driver. Fixed bug with line * handling so both lines are raised in cypress_open. (was dropping rts) * Various code cleanups made as well along with other misc bug fixes. * * Lonnie Mendez <dignome@gmail.com> * 04-10-2004 * Driver modified to support dynamic line settings. Various improvements * and features. * * Neil Whelchel * 10-2003 * Driver first released. * */ /* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */ /* Thanks to cypress for providing references for the hid reports. */ /* Thanks to Jiang Zhang for providing links and for general help. */ /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/tty.h> #include <linux/tty_driver.h> #include <linux/tty_flip.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/spinlock.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <linux/serial.h> #include <linux/kfifo.h> #include <linux/delay.h> #include <linux/uaccess.h> #include <asm/unaligned.h> #include "cypress_m8.h" static int debug; static int stats; static int interval; static int unstable_bauds; /* * Version Information */ #define DRIVER_VERSION "v1.10" #define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>" #define DRIVER_DESC "Cypress USB to Serial Driver" /* write buffer size defines */ #define CYPRESS_BUF_SIZE 1024 static const struct usb_device_id id_table_earthmate[] = { { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, { } /* Terminating entry */ }; static const struct usb_device_id id_table_cyphidcomrs232[] = { { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) }, { USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) }, { } /* Terminating entry */ }; static const struct usb_device_id id_table_nokiaca42v2[] = { { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) }, { } /* Terminating entry */ }; static const struct usb_device_id id_table_combined[] = { { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) }, { USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) }, { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) }, { } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, id_table_combined); static struct usb_driver cypress_driver = { .name = "cypress", .probe = usb_serial_probe, .disconnect = usb_serial_disconnect, .id_table = id_table_combined, .no_dynamic_id = 1, }; enum packet_format { packet_format_1, /* b0:status, b1:payload count */ packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */ }; struct cypress_private { spinlock_t lock; /* private lock */ int chiptype; /* identifier of device, for quirks/etc */ int bytes_in; /* used for statistics */ int bytes_out; /* used for statistics */ int cmd_count; /* used for statistics */ int cmd_ctrl; /* always set this to 1 before issuing a command */ struct kfifo write_fifo; /* write fifo */ int write_urb_in_use; /* write urb in use indicator */ int write_urb_interval; /* interval to use for write urb */ int read_urb_interval; /* interval to use for read urb */ int comm_is_ok; /* true if communication is (still) ok */ int termios_initialized; __u8 line_control; /* holds dtr / rts value */ __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ __u8 current_config; /* stores the current configuration byte */ __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ enum packet_format pkt_fmt; /* format to use for packet send / receive */ int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */ int baud_rate; /* stores current baud rate in integer form */ int isthrottled; /* if throttled, discard reads */ wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ char prev_status, diff_status; /* used for TIOCMIWAIT */ /* we pass a pointer to this as the argument sent to cypress_set_termios old_termios */ struct ktermios tmp_termios; /* stores the old termios settings */ }; /* function prototypes for the Cypress USB to serial device */ static int cypress_earthmate_startup(struct usb_serial *serial); static int cypress_hidcom_startup(struct usb_serial *serial); static int cypress_ca42v2_startup(struct usb_serial *serial); static void cypress_release(struct usb_serial *serial); static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port); static void cypress_close(struct usb_serial_port *port); static void cypress_dtr_rts(struct usb_serial_port *port, int on); static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); static void cypress_send(struct usb_serial_port *port); static int cypress_write_room(struct tty_struct *tty); static int cypress_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg); static void cypress_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old); static int cypress_tiocmget(struct tty_struct *tty); static int cypress_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); static int cypress_chars_in_buffer(struct tty_struct *tty); static void cypress_throttle(struct tty_struct *tty); static void cypress_unthrottle(struct tty_struct *tty); static void cypress_set_dead(struct usb_serial_port *port); static void cypress_read_int_callback(struct urb *urb); static void cypress_write_int_callback(struct urb *urb); static struct usb_serial_driver cypress_earthmate_device = { .driver = { .owner = THIS_MODULE, .name = "earthmate", }, .description = "DeLorme Earthmate USB", .usb_driver = &cypress_driver, .id_table = id_table_earthmate, .num_ports = 1, .attach = cypress_earthmate_startup, .release = cypress_release, .open = cypress_open, .close = cypress_close, .dtr_rts = cypress_dtr_rts, .write = cypress_write, .write_room = cypress_write_room, .ioctl = cypress_ioctl, .set_termios = cypress_set_termios, .tiocmget = cypress_tiocmget, .tiocmset = cypress_tiocmset, .chars_in_buffer = cypress_chars_in_buffer, .throttle = cypress_throttle, .unthrottle = cypress_unthrottle, .read_int_callback = cypress_read_int_callback, .write_int_callback = cypress_write_int_callback, }; static struct usb_serial_driver cypress_hidcom_device = { .driver = { .owner = THIS_MODULE, .name = "cyphidcom", }, .description = "HID->COM RS232 Adapter", .usb_driver = &cypress_driver, .id_table = id_table_cyphidcomrs232, .num_ports = 1, .attach = cypress_hidcom_startup, .release = cypress_release, .open = cypress_open, .close = cypress_close, .dtr_rts = cypress_dtr_rts, .write = cypress_write, .write_room = cypress_write_room, .ioctl = cypress_ioctl, .set_termios = cypress_set_termios, .tiocmget = cypress_tiocmget, .tiocmset = cypress_tiocmset, .chars_in_buffer = cypress_chars_in_buffer, .throttle = cypress_throttle, .unthrottle = cypress_unthrottle, .read_int_callback = cypress_read_int_callback, .write_int_callback = cypress_write_int_callback, }; static struct usb_serial_driver cypress_ca42v2_device = { .driver = { .owner = THIS_MODULE, .name = "nokiaca42v2", }, .description = "Nokia CA-42 V2 Adapter", .usb_driver = &cypress_driver, .id_table = id_table_nokiaca42v2, .num_ports = 1, .attach = cypress_ca42v2_startup, .release = cypress_release, .open = cypress_open, .close = cypress_close, .dtr_rts = cypress_dtr_rts, .write = cypress_write, .write_room = cypress_write_room, .ioctl = cypress_ioctl, .set_termios = cypress_set_termios, .tiocmget = cypress_tiocmget, .tiocmset = cypress_tiocmset, .chars_in_buffer = cypress_chars_in_buffer, .throttle = cypress_throttle, .unthrottle = cypress_unthrottle, .read_int_callback = cypress_read_int_callback, .write_int_callback = cypress_write_int_callback, }; /***************************************************************************** * Cypress serial helper functions *****************************************************************************/ /* FRWD Dongle hidcom needs to skip reset and speed checks */ static inline bool is_frwd(struct usb_device *dev) { return ((le16_to_cpu(dev->descriptor.idVendor) == VENDOR_ID_FRWD) && (le16_to_cpu(dev->descriptor.idProduct) == PRODUCT_ID_CYPHIDCOM_FRWD)); } static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate) { struct cypress_private *priv; priv = usb_get_serial_port_data(port); if (unstable_bauds) return new_rate; /* FRWD Dongle uses 115200 bps */ if (is_frwd(port->serial->dev)) return new_rate; /* * The general purpose firmware for the Cypress M8 allows for * a maximum speed of 57600bps (I have no idea whether DeLorme * chose to use the general purpose firmware or not), if you * need to modify this speed setting for your own project * please add your own chiptype and modify the code likewise. * The Cypress HID->COM device will work successfully up to * 115200bps (but the actual throughput is around 3kBps). */ if (port->serial->dev->speed == USB_SPEED_LOW) { /* * Mike Isely <isely@pobox.com> 2-Feb-2008: The * Cypress app note that describes this mechanism * states the the low-speed part can't handle more * than 800 bytes/sec, in which case 4800 baud is the * safest speed for a part like that. */ if (new_rate > 4800) { dbg("%s - failed setting baud rate, device incapable " "speed %d", __func__, new_rate); return -1; } } switch (priv->chiptype) { case CT_EARTHMATE: if (new_rate <= 600) { /* 300 and 600 baud rates are supported under * the generic firmware, but are not used with * NMEA and SiRF protocols */ dbg("%s - failed setting baud rate, unsupported speed " "of %d on Earthmate GPS", __func__, new_rate); return -1; } break; default: break; } return new_rate; } /* This function can either set or retrieve the current serial line settings */ static int cypress_serial_control(struct tty_struct *tty, struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits, int parity_enable, int parity_type, int reset, int cypress_request_type) { int new_baudrate = 0, retval = 0, tries = 0; struct cypress_private *priv; u8 *feature_buffer; const unsigned int feature_len = 5; unsigned long flags; dbg("%s", __func__); priv = usb_get_serial_port_data(port); if (!priv->comm_is_ok) return -ENODEV; feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL); if (!feature_buffer) return -ENOMEM; switch (cypress_request_type) { case CYPRESS_SET_CONFIG: /* 0 means 'Hang up' so doesn't change the true bit rate */ new_baudrate = priv->baud_rate; if (baud_rate && baud_rate != priv->baud_rate) { dbg("%s - baud rate is changing", __func__); retval = analyze_baud_rate(port, baud_rate); if (retval >= 0) { new_baudrate = retval; dbg("%s - New baud rate set to %d", __func__, new_baudrate); } } dbg("%s - baud rate is being sent as %d", __func__, new_baudrate); /* fill the feature_buffer with new configuration */ put_unaligned_le32(new_baudrate, feature_buffer); feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */ /* 1 bit gap */ feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */ feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */ feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */ /* 1 bit gap */ feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */ dbg("%s - device is being sent this feature report:", __func__); dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1], feature_buffer[2], feature_buffer[3], feature_buffer[4]); do { retval = usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), HID_REQ_SET_REPORT, USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 0x0300, 0, feature_buffer, feature_len, 500); if (tries++ >= 3) break; } while (retval != feature_len && retval != -ENODEV); if (retval != feature_len) { dev_err(&port->dev, "%s - failed sending serial " "line settings - %d\n", __func__, retval); cypress_set_dead(port); } else { spin_lock_irqsave(&priv->lock, flags); priv->baud_rate = new_baudrate; priv->current_config = feature_buffer[4]; spin_unlock_irqrestore(&priv->lock, flags); /* If we asked for a speed change encode it */ if (baud_rate) tty_encode_baud_rate(tty, new_baudrate, new_baudrate); } break; case CYPRESS_GET_CONFIG: if (priv->get_cfg_unsafe) { /* Not implemented for this device, and if we try to do it we're likely to crash the hardware. */ retval = -ENOTTY; goto out; } dbg("%s - retreiving serial line settings", __func__); do { retval = usb_control_msg(port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0), HID_REQ_GET_REPORT, USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 0x0300, 0, feature_buffer, feature_len, 500); if (tries++ >= 3) break; } while (retval != feature_len && retval != -ENODEV); if (retval != feature_len) { dev_err(&port->dev, "%s - failed to retrieve serial " "line settings - %d\n", __func__, retval); cypress_set_dead(port); goto out; } else { spin_lock_irqsave(&priv->lock, flags); /* store the config in one byte, and later use bit masks to check values */ priv->current_config = feature_buffer[4]; priv->baud_rate = get_unaligned_le32(feature_buffer); spin_unlock_irqrestore(&priv->lock, flags); } } spin_lock_irqsave(&priv->lock, flags); ++priv->cmd_count; spin_unlock_irqrestore(&priv->lock, flags); out: kfree(feature_buffer); return retval; } /* cypress_serial_control */ static void cypress_set_dead(struct usb_serial_port *port) { struct cypress_private *priv = usb_get_serial_port_data(port); unsigned long flags; spin_lock_irqsave(&priv->lock, flags); if (!priv->comm_is_ok) { spin_unlock_irqrestore(&priv->lock, flags); return; } priv->comm_is_ok = 0; spin_unlock_irqrestore(&priv->lock, flags); dev_err(&port->dev, "cypress_m8 suspending failing port %d - " "interval might be too short\n", port->number); } /***************************************************************************** * Cypress serial driver functions *****************************************************************************/ static int generic_startup(struct usb_serial *serial) { struct cypress_private *priv; struct usb_serial_port *port = serial->port[0]; dbg("%s - port %d", __func__, port->number); priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL); if (!priv) return -ENOMEM; priv->comm_is_ok = !0; spin_lock_init(&priv->lock); if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) { kfree(priv); return -ENOMEM; } init_waitqueue_head(&priv->delta_msr_wait); /* Skip reset for FRWD device. It is a workaound: device hangs if it receives SET_CONFIGURE in Configured state. */ if (!is_frwd(serial->dev)) usb_reset_configuration(serial->dev); priv->cmd_ctrl = 0; priv->line_control = 0; priv->termios_initialized = 0; priv->rx_flags = 0; /* Default packet format setting is determined by packet size. Anything with a size larger then 9 must have a separate count field since the 3 bit count field is otherwise too small. Otherwise we can use the slightly more compact format. This is in accordance with the cypress_m8 serial converter app note. */ if (port->interrupt_out_size > 9) priv->pkt_fmt = packet_format_1; else priv->pkt_fmt = packet_format_2; if (interval > 0) { priv->write_urb_interval = interval; priv->read_urb_interval = interval; dbg("%s - port %d read & write intervals forced to %d", __func__, port->number, interval); } else { priv->write_urb_interval = port->interrupt_out_urb->interval; priv->read_urb_interval = port->interrupt_in_urb->interval; dbg("%s - port %d intervals: read=%d write=%d", __func__, port->number, priv->read_urb_interval, priv->write_urb_interval); } usb_set_serial_port_data(port, priv); return 0; } static int cypress_earthmate_startup(struct usb_serial *serial) { struct cypress_private *priv; struct usb_serial_port *port = serial->port[0]; dbg("%s", __func__); if (generic_startup(serial)) { dbg("%s - Failed setting up port %d", __func__, port->number); return 1; } priv = usb_get_serial_port_data(port); priv->chiptype = CT_EARTHMATE; /* All Earthmate devices use the separated-count packet format! Idiotic. */ priv->pkt_fmt = packet_format_1; if (serial->dev->descriptor.idProduct != cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { /* The old original USB Earthmate seemed able to handle GET_CONFIG requests; everything they've produced since that time crashes if this command is attempted :-( */ dbg("%s - Marking this device as unsafe for GET_CONFIG " "commands", __func__); priv->get_cfg_unsafe = !0; } return 0; } /* cypress_earthmate_startup */ static int cypress_hidcom_startup(struct usb_serial *serial) { struct cypress_private *priv; dbg("%s", __func__); if (generic_startup(serial)) { dbg("%s - Failed setting up port %d", __func__, serial->port[0]->number); return 1; } priv = usb_get_serial_port_data(serial->port[0]); priv->chiptype = CT_CYPHIDCOM; return 0; } /* cypress_hidcom_startup */ static int cypress_ca42v2_startup(struct usb_serial *serial) { struct cypress_private *priv; dbg("%s", __func__); if (generic_startup(serial)) { dbg("%s - Failed setting up port %d", __func__, serial->port[0]->number); return 1; } priv = usb_get_serial_port_data(serial->port[0]); priv->chiptype = CT_CA42V2; return 0; } /* cypress_ca42v2_startup */ static void cypress_release(struct usb_serial *serial) { struct cypress_private *priv; dbg("%s - port %d", __func__, serial->port[0]->number); /* all open ports are closed at this point */ priv = usb_get_serial_port_data(serial->port[0]); if (priv) { kfifo_free(&priv->write_fifo); kfree(priv); } } static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port) { struct cypress_private *priv = usb_get_serial_port_data(port); struct usb_serial *serial = port->serial; unsigned long flags; int result = 0; dbg("%s - port %d", __func__, port->number); if (!priv->comm_is_ok) return -EIO; /* clear halts before open */ usb_clear_halt(serial->dev, 0x81); usb_clear_halt(serial->dev, 0x02); spin_lock_irqsave(&priv->lock, flags); /* reset read/write statistics */ priv->bytes_in = 0; priv->bytes_out = 0; priv->cmd_count = 0; priv->rx_flags = 0; spin_unlock_irqrestore(&priv->lock, flags); /* Set termios */ cypress_send(port); if (tty) cypress_set_termios(tty, port, &priv->tmp_termios); /* setup the port and start reading from the device */ if (!port->interrupt_in_urb) { dev_err(&port->dev, "%s - interrupt_in_urb is empty!\n", __func__); return -1; } usb_fill_int_urb(port->interrupt_in_urb, serial->dev, usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, cypress_read_int_callback, port, priv->read_urb_interval); result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (result) { dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); cypress_set_dead(port); } port->port.drain_delay = 256; return result; } /* cypress_open */ static void cypress_dtr_rts(struct usb_serial_port *port, int on) { struct cypress_private *priv = usb_get_serial_port_data(port); /* drop dtr and rts */ spin_lock_irq(&priv->lock); if (on == 0) priv->line_control = 0; else priv->line_control = CONTROL_DTR | CONTROL_RTS; priv->cmd_ctrl = 1; spin_unlock_irq(&priv->lock); cypress_write(NULL, port, NULL, 0); } static void cypress_close(struct usb_serial_port *port) { struct cypress_private *priv = usb_get_serial_port_data(port); unsigned long flags; dbg("%s - port %d", __func__, port->number); /* writing is potentially harmful, lock must be taken */ mutex_lock(&port->serial->disc_mutex); if (port->serial->disconnected) { mutex_unlock(&port->serial->disc_mutex); return; } spin_lock_irqsave(&priv->lock, flags); kfifo_reset_out(&priv->write_fifo); spin_unlock_irqrestore(&priv->lock, flags); dbg("%s - stopping urbs", __func__); usb_kill_urb(port->interrupt_in_urb); usb_kill_urb(port->interrupt_out_urb); if (stats) dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", priv->bytes_in, priv->bytes_out, priv->cmd_count); mutex_unlock(&port->serial->disc_mutex); } /* cypress_close */ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { struct cypress_private *priv = usb_get_serial_port_data(port); dbg("%s - port %d, %d bytes", __func__, port->number, count); /* line control commands, which need to be executed immediately, are not put into the buffer for obvious reasons. */ if (priv->cmd_ctrl) { count = 0; goto finish; } if (!count) return count; count = kfifo_in_locked(&priv->write_fifo, buf, count, &priv->lock); finish: cypress_send(port); return count; } /* cypress_write */ static void cypress_send(struct usb_serial_port *port) { int count = 0, result, offset, actual_size; struct cypress_private *priv = usb_get_serial_port_data(port); unsigned long flags; if (!priv->comm_is_ok) return; dbg("%s - port %d", __func__, port->number); dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size); spin_lock_irqsave(&priv->lock, flags); if (priv->write_urb_in_use) { dbg("%s - can't write, urb in use", __func__); spin_unlock_irqrestore(&priv->lock, flags); return; } spin_unlock_irqrestore(&priv->lock, flags); /* clear buffer */ memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); spin_lock_irqsave(&priv->lock, flags); switch (priv->pkt_fmt) { default: case packet_format_1: /* this is for the CY7C64013... */ offset = 2; port->interrupt_out_buffer[0] = priv->line_control; break; case packet_format_2: /* this is for the CY7C63743... */ offset = 1; port->interrupt_out_buffer[0] = priv->line_control; break; } if (priv->line_control & CONTROL_RESET) priv->line_control &= ~CONTROL_RESET; if (priv->cmd_ctrl) { priv->cmd_count++; dbg("%s - line control command being issued", __func__); spin_unlock_irqrestore(&priv->lock, flags); goto send; } else spin_unlock_irqrestore(&priv->lock, flags); count = kfifo_out_locked(&priv->write_fifo, &port->interrupt_out_buffer[offset], port->interrupt_out_size - offset, &priv->lock); if (count == 0) return; switch (priv->pkt_fmt) { default: case packet_format_1: port->interrupt_out_buffer[1] = count; break; case packet_format_2: port->interrupt_out_buffer[0] |= count; } dbg("%s - count is %d", __func__, count); send: spin_lock_irqsave(&priv->lock, flags); priv->write_urb_in_use = 1; spin_unlock_irqrestore(&priv->lock, flags); if (priv->cmd_ctrl) actual_size = 1; else actual_size = count + (priv->pkt_fmt == packet_format_1 ? 2 : 1); usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size, port->interrupt_out_urb->transfer_buffer); usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), port->interrupt_out_buffer, port->interrupt_out_size, cypress_write_int_callback, port, priv->write_urb_interval); result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); if (result) { dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); priv->write_urb_in_use = 0; cypress_set_dead(port); } spin_lock_irqsave(&priv->lock, flags); if (priv->cmd_ctrl) priv->cmd_ctrl = 0; /* do not count the line control and size bytes */ priv->bytes_out += count; spin_unlock_irqrestore(&priv->lock, flags); usb_serial_port_softint(port); } /* cypress_send */ /* returns how much space is available in the soft buffer */ static int cypress_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); int room = 0; unsigned long flags; dbg("%s - port %d", __func__, port->number); spin_lock_irqsave(&priv->lock, flags); room = kfifo_avail(&priv->write_fifo); spin_unlock_irqrestore(&priv->lock, flags); dbg("%s - returns %d", __func__, room); return room; } static int cypress_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); __u8 status, control; unsigned int result = 0; unsigned long flags; dbg("%s - port %d", __func__, port->number); spin_lock_irqsave(&priv->lock, flags); control = priv->line_control; status = priv->current_status; spin_unlock_irqrestore(&priv->lock, flags); result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) | ((control & CONTROL_RTS) ? TIOCM_RTS : 0) | ((status & UART_CTS) ? TIOCM_CTS : 0) | ((status & UART_DSR) ? TIOCM_DSR : 0) | ((status & UART_RI) ? TIOCM_RI : 0) | ((status & UART_CD) ? TIOCM_CD : 0); dbg("%s - result = %x", __func__, result); return result; } static int cypress_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); unsigned long flags; dbg("%s - port %d", __func__, port->number); spin_lock_irqsave(&priv->lock, flags); if (set & TIOCM_RTS) priv->line_control |= CONTROL_RTS; if (set & TIOCM_DTR) priv->line_control |= CONTROL_DTR; if (clear & TIOCM_RTS) priv->line_control &= ~CONTROL_RTS; if (clear & TIOCM_DTR) priv->line_control &= ~CONTROL_DTR; priv->cmd_ctrl = 1; spin_unlock_irqrestore(&priv->lock, flags); return cypress_write(tty, port, NULL, 0); } static int cypress_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); switch (cmd) { /* This code comes from drivers/char/serial.c and ftdi_sio.c */ case TIOCMIWAIT: while (priv != NULL) { interruptible_sleep_on(&priv->delta_msr_wait); /* see if a signal did it */ if (signal_pending(current)) return -ERESTARTSYS; else { char diff = priv->diff_status; if (diff == 0) return -EIO; /* no change => error */ /* consume all events */ priv->diff_status = 0; /* return 0 if caller wanted to know about these bits */ if (((arg & TIOCM_RNG) && (diff & UART_RI)) || ((arg & TIOCM_DSR) && (diff & UART_DSR)) || ((arg & TIOCM_CD) && (diff & UART_CD)) || ((arg & TIOCM_CTS) && (diff & UART_CTS))) return 0; /* otherwise caller can't care less about what * happened, and so we continue to wait for * more events. */ } } return 0; default: break; } dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); return -ENOIOCTLCMD; } /* cypress_ioctl */ static void cypress_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { struct cypress_private *priv = usb_get_serial_port_data(port); int data_bits, stop_bits, parity_type, parity_enable; unsigned cflag, iflag; unsigned long flags; __u8 oldlines; int linechange = 0; dbg("%s - port %d", __func__, port->number); spin_lock_irqsave(&priv->lock, flags); /* We can't clean this one up as we don't know the device type early enough */ if (!priv->termios_initialized) { if (priv->chiptype == CT_EARTHMATE) { *(tty->termios) = tty_std_termios; tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL; tty->termios->c_ispeed = 4800; tty->termios->c_ospeed = 4800; } else if (priv->chiptype == CT_CYPHIDCOM) { *(tty->termios) = tty_std_termios; tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty->termios->c_ispeed = 9600; tty->termios->c_ospeed = 9600; } else if (priv->chiptype == CT_CA42V2) { *(tty->termios) = tty_std_termios; tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty->termios->c_ispeed = 9600; tty->termios->c_ospeed = 9600; } priv->termios_initialized = 1; } spin_unlock_irqrestore(&priv->lock, flags); /* Unsupported features need clearing */ tty->termios->c_cflag &= ~(CMSPAR|CRTSCTS); cflag = tty->termios->c_cflag; iflag = tty->termios->c_iflag; /* check if there are new settings */ if (old_termios) { spin_lock_irqsave(&priv->lock, flags); priv->tmp_termios = *(tty->termios); spin_unlock_irqrestore(&priv->lock, flags); } /* set number of data bits, parity, stop bits */ /* when parity is disabled the parity type bit is ignored */ /* 1 means 2 stop bits, 0 means 1 stop bit */ stop_bits = cflag & CSTOPB ? 1 : 0; if (cflag & PARENB) { parity_enable = 1; /* 1 means odd parity, 0 means even parity */ parity_type = cflag & PARODD ? 1 : 0; } else parity_enable = parity_type = 0; switch (cflag & CSIZE) { case CS5: data_bits = 0; break; case CS6: data_bits = 1; break; case CS7: data_bits = 2; break; case CS8: data_bits = 3; break; default: dev_err(&port->dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__); data_bits = 3; } spin_lock_irqsave(&priv->lock, flags); oldlines = priv->line_control; if ((cflag & CBAUD) == B0) { /* drop dtr and rts */ dbg("%s - dropping the lines, baud rate 0bps", __func__); priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); } else priv->line_control = (CONTROL_DTR | CONTROL_RTS); spin_unlock_irqrestore(&priv->lock, flags); dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, " "%d data_bits (+5)", __func__, stop_bits, parity_enable, parity_type, data_bits); cypress_serial_control(tty, port, tty_get_baud_rate(tty), data_bits, stop_bits, parity_enable, parity_type, 0, CYPRESS_SET_CONFIG); /* we perform a CYPRESS_GET_CONFIG so that the current settings are * filled into the private structure this should confirm that all is * working if it returns what we just set */ cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); /* Here we can define custom tty settings for devices; the main tty * termios flag base comes from empeg.c */ spin_lock_irqsave(&priv->lock, flags); if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) { dbg("Using custom termios settings for a baud rate of " "4800bps."); /* define custom termios settings for NMEA protocol */ tty->termios->c_iflag /* input modes - */ &= ~(IGNBRK /* disable ignore break */ | BRKINT /* disable break causes interrupt */ | PARMRK /* disable mark parity errors */ | ISTRIP /* disable clear high bit of input char */ | INLCR /* disable translate NL to CR */ | IGNCR /* disable ignore CR */ | ICRNL /* disable translate CR to NL */ | IXON); /* disable enable XON/XOFF flow control */ tty->termios->c_oflag /* output modes */ &= ~OPOST; /* disable postprocess output char */ tty->termios->c_lflag /* line discipline modes */ &= ~(ECHO /* disable echo input characters */ | ECHONL /* disable echo new line */ | ICANON /* disable erase, kill, werase, and rprnt special characters */ | ISIG /* disable interrupt, quit, and suspend special characters */ | IEXTEN); /* disable non-POSIX special characters */ } /* CT_CYPHIDCOM: Application should handle this for device */ linechange = (priv->line_control != oldlines); spin_unlock_irqrestore(&priv->lock, flags); /* if necessary, set lines */ if (linechange) { priv->cmd_ctrl = 1; cypress_write(tty, port, NULL, 0); } } /* cypress_set_termios */ /* returns amount of data still left in soft buffer */ static int cypress_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); int chars = 0; unsigned long flags; dbg("%s - port %d", __func__, port->number); spin_lock_irqsave(&priv->lock, flags); chars = kfifo_len(&priv->write_fifo); spin_unlock_irqrestore(&priv->lock, flags); dbg("%s - returns %d", __func__, chars); return chars; } static void cypress_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); dbg("%s - port %d", __func__, port->number); spin_lock_irq(&priv->lock); priv->rx_flags = THROTTLED; spin_unlock_irq(&priv->lock); } static void cypress_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); int actually_throttled, result; dbg("%s - port %d", __func__, port->number); spin_lock_irq(&priv->lock); actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; priv->rx_flags = 0; spin_unlock_irq(&priv->lock); if (!priv->comm_is_ok) return; if (actually_throttled) { port->interrupt_in_urb->dev = port->serial->dev; result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (result) { dev_err(&port->dev, "%s - failed submitting read urb, " "error %d\n", __func__, result); cypress_set_dead(port); } } } static void cypress_read_int_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; struct cypress_private *priv = usb_get_serial_port_data(port); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; unsigned long flags; char tty_flag = TTY_NORMAL; int havedata = 0; int bytes = 0; int result; int i = 0; int status = urb->status; dbg("%s - port %d", __func__, port->number); switch (status) { case 0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* precursor to disconnect so just go away */ return; case -EPIPE: /* Can't call usb_clear_halt while in_interrupt */ /* FALLS THROUGH */ default: /* something ugly is going on... */ dev_err(&urb->dev->dev, "%s - unexpected nonzero read status received: %d\n", __func__, status); cypress_set_dead(port); return; } spin_lock_irqsave(&priv->lock, flags); if (priv->rx_flags & THROTTLED) { dbg("%s - now throttling", __func__); priv->rx_flags |= ACTUALLY_THROTTLED; spin_unlock_irqrestore(&priv->lock, flags); return; } spin_unlock_irqrestore(&priv->lock, flags); tty = tty_port_tty_get(&port->port); if (!tty) { dbg("%s - bad tty pointer - exiting", __func__); return; } spin_lock_irqsave(&priv->lock, flags); result = urb->actual_length; switch (priv->pkt_fmt) { default: case packet_format_1: /* This is for the CY7C64013... */ priv->current_status = data[0] & 0xF8; bytes = data[1] + 2; i = 2; if (bytes > 2) havedata = 1; break; case packet_format_2: /* This is for the CY7C63743... */ priv->current_status = data[0] & 0xF8; bytes = (data[0] & 0x07) + 1; i = 1; if (bytes > 1) havedata = 1; break; } spin_unlock_irqrestore(&priv->lock, flags); if (result < bytes) { dbg("%s - wrong packet size - received %d bytes but packet " "said %d bytes", __func__, result, bytes); goto continue_read; } usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); spin_lock_irqsave(&priv->lock, flags); /* check to see if status has changed */ if (priv->current_status != priv->prev_status) { priv->diff_status |= priv->current_status ^ priv->prev_status; wake_up_interruptible(&priv->delta_msr_wait); priv->prev_status = priv->current_status; } spin_unlock_irqrestore(&priv->lock, flags); /* hangup, as defined in acm.c... this might be a bad place for it * though */ if (tty && !(tty->termios->c_cflag & CLOCAL) && !(priv->current_status & UART_CD)) { dbg("%s - calling hangup", __func__); tty_hangup(tty); goto continue_read; } /* There is one error bit... I'm assuming it is a parity error * indicator as the generic firmware will set this bit to 1 if a * parity error occurs. * I can not find reference to any other error events. */ spin_lock_irqsave(&priv->lock, flags); if (priv->current_status & CYP_ERROR) { spin_unlock_irqrestore(&priv->lock, flags); tty_flag = TTY_PARITY; dbg("%s - Parity Error detected", __func__); } else spin_unlock_irqrestore(&priv->lock, flags); /* process read if there is data other than line status */ if (tty && bytes > i) { tty_insert_flip_string_fixed_flag(tty, data + i, tty_flag, bytes - i); tty_flip_buffer_push(tty); } spin_lock_irqsave(&priv->lock, flags); /* control and status byte(s) are also counted */ priv->bytes_in += bytes; spin_unlock_irqrestore(&priv->lock, flags); continue_read: tty_kref_put(tty); /* Continue trying to always read */ if (priv->comm_is_ok) { usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, cypress_read_int_callback, port, priv->read_urb_interval); result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); if (result && result != -EPERM) { dev_err(&urb->dev->dev, "%s - failed resubmitting " "read urb, error %d\n", __func__, result); cypress_set_dead(port); } } } /* cypress_read_int_callback */ static void cypress_write_int_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; struct cypress_private *priv = usb_get_serial_port_data(port); int result; int status = urb->status; dbg("%s - port %d", __func__, port->number); switch (status) { case 0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */ dbg("%s - urb shutting down with status: %d", __func__, status); priv->write_urb_in_use = 0; return; case -EPIPE: /* no break needed; clear halt and resubmit */ if (!priv->comm_is_ok) break; usb_clear_halt(port->serial->dev, 0x02); /* error in the urb, so we have to resubmit it */ dbg("%s - nonzero write bulk status received: %d", __func__, status); port->interrupt_out_urb->transfer_buffer_length = 1; port->interrupt_out_urb->dev = port->serial->dev; result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); if (!result) return; dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __func__, result); cypress_set_dead(port); break; default: dev_err(&urb->dev->dev, "%s - unexpected nonzero write status received: %d\n", __func__, status); cypress_set_dead(port); break; } priv->write_urb_in_use = 0; /* send any buffered data */ cypress_send(port); } /***************************************************************************** * Module functions *****************************************************************************/ static int __init cypress_init(void) { int retval; dbg("%s", __func__); retval = usb_serial_register(&cypress_earthmate_device); if (retval) goto failed_em_register; retval = usb_serial_register(&cypress_hidcom_device); if (retval) goto failed_hidcom_register; retval = usb_serial_register(&cypress_ca42v2_device); if (retval) goto failed_ca42v2_register; retval = usb_register(&cypress_driver); if (retval) goto failed_usb_register; printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" DRIVER_DESC "\n"); return 0; failed_usb_register: usb_serial_deregister(&cypress_ca42v2_device); failed_ca42v2_register: usb_serial_deregister(&cypress_hidcom_device); failed_hidcom_register: usb_serial_deregister(&cypress_earthmate_device); failed_em_register: return retval; } static void __exit cypress_exit(void) { dbg("%s", __func__); usb_deregister(&cypress_driver); usb_serial_deregister(&cypress_earthmate_device); usb_serial_deregister(&cypress_hidcom_device); usb_serial_deregister(&cypress_ca42v2_device); } module_init(cypress_init); module_exit(cypress_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL"); module_param(debug, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug enabled or not"); module_param(stats, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(stats, "Enable statistics or not"); module_param(interval, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(interval, "Overrides interrupt interval"); module_param(unstable_bauds, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates");
gpl-2.0
CyanogenMod/htc-kernel-liberty
sound/core/seq/oss/seq_oss_writeq.c
830
4172
/* * OSS compatible sequencer driver * * seq_oss_writeq.c - write queue and sync * * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "seq_oss_writeq.h" #include "seq_oss_event.h" #include "seq_oss_timer.h" #include <sound/seq_oss_legacy.h> #include "../seq_lock.h" #include "../seq_clientmgr.h" #include <linux/wait.h> /* * create a write queue record */ struct seq_oss_writeq * snd_seq_oss_writeq_new(struct seq_oss_devinfo *dp, int maxlen) { struct seq_oss_writeq *q; struct snd_seq_client_pool pool; if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) return NULL; q->dp = dp; q->maxlen = maxlen; spin_lock_init(&q->sync_lock); q->sync_event_put = 0; q->sync_time = 0; init_waitqueue_head(&q->sync_sleep); memset(&pool, 0, sizeof(pool)); pool.client = dp->cseq; pool.output_pool = maxlen; pool.output_room = maxlen / 2; snd_seq_oss_control(dp, SNDRV_SEQ_IOCTL_SET_CLIENT_POOL, &pool); return q; } /* * delete the write queue */ void snd_seq_oss_writeq_delete(struct seq_oss_writeq *q) { if (q) { snd_seq_oss_writeq_clear(q); /* to be sure */ kfree(q); } } /* * reset the write queue */ void snd_seq_oss_writeq_clear(struct seq_oss_writeq *q) { struct snd_seq_remove_events reset; memset(&reset, 0, sizeof(reset)); reset.remove_mode = SNDRV_SEQ_REMOVE_OUTPUT; /* remove all */ snd_seq_oss_control(q->dp, SNDRV_SEQ_IOCTL_REMOVE_EVENTS, &reset); /* wake up sleepers if any */ snd_seq_oss_writeq_wakeup(q, 0); } /* * wait until the write buffer has enough room */ int snd_seq_oss_writeq_sync(struct seq_oss_writeq *q) { struct seq_oss_devinfo *dp = q->dp; abstime_t time; time = snd_seq_oss_timer_cur_tick(dp->timer); if (q->sync_time >= time) return 0; /* already finished */ if (! q->sync_event_put) { struct snd_seq_event ev; union evrec *rec; /* put echoback event */ memset(&ev, 0, sizeof(ev)); ev.flags = 0; ev.type = SNDRV_SEQ_EVENT_ECHO; ev.time.tick = time; /* echo back to itself */ snd_seq_oss_fill_addr(dp, &ev, dp->addr.client, dp->addr.port); rec = (union evrec *)&ev.data; rec->t.code = SEQ_SYNCTIMER; rec->t.time = time; q->sync_event_put = 1; snd_seq_kernel_client_enqueue_blocking(dp->cseq, &ev, NULL, 0, 0); } wait_event_interruptible_timeout(q->sync_sleep, ! q->sync_event_put, HZ); if (signal_pending(current)) /* interrupted - return 0 to finish sync */ q->sync_event_put = 0; if (! q->sync_event_put || q->sync_time >= time) return 0; return 1; } /* * wake up sync - echo event was catched */ void snd_seq_oss_writeq_wakeup(struct seq_oss_writeq *q, abstime_t time) { unsigned long flags; spin_lock_irqsave(&q->sync_lock, flags); q->sync_time = time; q->sync_event_put = 0; if (waitqueue_active(&q->sync_sleep)) { wake_up(&q->sync_sleep); } spin_unlock_irqrestore(&q->sync_lock, flags); } /* * return the unused pool size */ int snd_seq_oss_writeq_get_free_size(struct seq_oss_writeq *q) { struct snd_seq_client_pool pool; pool.client = q->dp->cseq; snd_seq_oss_control(q->dp, SNDRV_SEQ_IOCTL_GET_CLIENT_POOL, &pool); return pool.output_free; } /* * set output threshold size from ioctl */ void snd_seq_oss_writeq_set_output(struct seq_oss_writeq *q, int val) { struct snd_seq_client_pool pool; pool.client = q->dp->cseq; snd_seq_oss_control(q->dp, SNDRV_SEQ_IOCTL_GET_CLIENT_POOL, &pool); pool.output_room = val; snd_seq_oss_control(q->dp, SNDRV_SEQ_IOCTL_SET_CLIENT_POOL, &pool); }
gpl-2.0
thederekjay/kernel_lge_mako
drivers/mfd/pm8821-core.c
1086
9561
/* * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #define pr_fmt(fmt) "%s: " fmt, __func__ #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/msm_ssbi.h> #include <linux/mfd/core.h> #include <linux/mfd/pm8xxx/pm8821.h> #include <linux/mfd/pm8xxx/core.h> #define REG_HWREV 0x002 /* PMIC4 revision */ #define REG_HWREV_2 0x0E8 /* PMIC4 revision 2 */ #define REG_MPP_BASE 0x050 #define REG_IRQ_BASE 0x100 #define REG_TEMP_ALARM_CTRL 0x01B #define REG_TEMP_ALARM_PWM 0x09B #define PM8821_VERSION_MASK 0xFFF0 #define PM8821_VERSION_VALUE 0x0BF0 #define PM8821_REVISION_MASK 0x000F #define SINGLE_IRQ_RESOURCE(_name, _irq) \ { \ .name = _name, \ .start = _irq, \ .end = _irq, \ .flags = IORESOURCE_IRQ, \ } struct pm8821 { struct device *dev; struct pm_irq_chip *irq_chip; u32 rev_registers; }; static int pm8821_readb(const struct device *dev, u16 addr, u8 *val) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return msm_ssbi_read(pmic->dev->parent, addr, val, 1); } static int pm8821_writeb(const struct device *dev, u16 addr, u8 val) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return msm_ssbi_write(pmic->dev->parent, addr, &val, 1); } static int pm8821_read_buf(const struct device *dev, u16 addr, u8 *buf, int cnt) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt); } static int pm8821_write_buf(const struct device *dev, u16 addr, u8 *buf, int cnt) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt); } static int pm8821_read_irq_stat(const struct device *dev, int irq) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return pm8821_get_irq_stat(pmic->irq_chip, irq); } static enum pm8xxx_version pm8821_get_version(const struct device *dev) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; enum pm8xxx_version version = -ENODEV; if ((pmic->rev_registers & PM8821_VERSION_MASK) == PM8821_VERSION_VALUE) version = PM8XXX_VERSION_8821; return version; } static int pm8821_get_revision(const struct device *dev) { const struct pm8xxx_drvdata *pm8821_drvdata = dev_get_drvdata(dev); const struct pm8821 *pmic = pm8821_drvdata->pm_chip_data; return pmic->rev_registers & PM8821_REVISION_MASK; } static struct pm8xxx_drvdata pm8821_drvdata = { .pmic_readb = pm8821_readb, .pmic_writeb = pm8821_writeb, .pmic_read_buf = pm8821_read_buf, .pmic_write_buf = pm8821_write_buf, .pmic_read_irq_stat = pm8821_read_irq_stat, .pmic_get_version = pm8821_get_version, .pmic_get_revision = pm8821_get_revision, }; static const struct resource mpp_cell_resources[] __devinitconst = { { .start = PM8821_IRQ_BLOCK_BIT(PM8821_MPP_BLOCK_START, 0), .end = PM8821_IRQ_BLOCK_BIT(PM8821_MPP_BLOCK_START, 0) + PM8821_NR_MPPS - 1, .flags = IORESOURCE_IRQ, }, }; static struct mfd_cell mpp_cell __devinitdata = { .name = PM8XXX_MPP_DEV_NAME, .id = 1, .resources = mpp_cell_resources, .num_resources = ARRAY_SIZE(mpp_cell_resources), }; static struct mfd_cell debugfs_cell __devinitdata = { .name = "pm8xxx-debug", .id = 1, .platform_data = "pm8821-dbg", .pdata_size = sizeof("pm8821-dbg"), }; static const struct resource thermal_alarm_cell_resources[] __devinitconst = { SINGLE_IRQ_RESOURCE("pm8821_tempstat_irq", PM8821_TEMPSTAT_IRQ), SINGLE_IRQ_RESOURCE("pm8821_overtemp_irq", PM8821_OVERTEMP_IRQ), }; static struct pm8xxx_tm_core_data thermal_alarm_cdata = { .adc_type = PM8XXX_TM_ADC_NONE, .reg_addr_temp_alarm_ctrl = REG_TEMP_ALARM_CTRL, .reg_addr_temp_alarm_pwm = REG_TEMP_ALARM_PWM, .tm_name = "pm8821_tz", .irq_name_temp_stat = "pm8821_tempstat_irq", .irq_name_over_temp = "pm8821_overtemp_irq", .default_no_adc_temp = 37000, }; static struct mfd_cell thermal_alarm_cell __devinitdata = { .name = PM8XXX_TM_DEV_NAME, .id = 1, .resources = thermal_alarm_cell_resources, .num_resources = ARRAY_SIZE(thermal_alarm_cell_resources), .platform_data = &thermal_alarm_cdata, .pdata_size = sizeof(struct pm8xxx_tm_core_data), }; static int __devinit pm8821_add_subdevices(const struct pm8821_platform_data *pdata, struct pm8821 *pmic) { int ret = 0, irq_base = 0; struct pm_irq_chip *irq_chip; if (pdata->irq_pdata) { pdata->irq_pdata->irq_cdata.nirqs = PM8821_NR_IRQS; pdata->irq_pdata->irq_cdata.base_addr = REG_IRQ_BASE; irq_base = pdata->irq_pdata->irq_base; irq_chip = pm8821_irq_init(pmic->dev, pdata->irq_pdata); if (IS_ERR(irq_chip)) { pr_err("Failed to init interrupts ret=%ld\n", PTR_ERR(irq_chip)); return PTR_ERR(irq_chip); } pmic->irq_chip = irq_chip; } if (pdata->mpp_pdata) { pdata->mpp_pdata->core_data.nmpps = PM8821_NR_MPPS; pdata->mpp_pdata->core_data.base_addr = REG_MPP_BASE; mpp_cell.platform_data = pdata->mpp_pdata; mpp_cell.pdata_size = sizeof(struct pm8xxx_mpp_platform_data); ret = mfd_add_devices(pmic->dev, 0, &mpp_cell, 1, NULL, irq_base); if (ret) { pr_err("Failed to add mpp subdevice ret=%d\n", ret); goto bail; } } ret = mfd_add_devices(pmic->dev, 0, &debugfs_cell, 1, NULL, irq_base); if (ret) { pr_err("Failed to add debugfs subdevice ret=%d\n", ret); goto bail; } ret = mfd_add_devices(pmic->dev, 0, &thermal_alarm_cell, 1, NULL, irq_base); if (ret) { pr_err("Failed to add thermal alarm subdevice ret=%d\n", ret); goto bail; } return 0; bail: if (pmic->irq_chip) { pm8821_irq_exit(pmic->irq_chip); pmic->irq_chip = NULL; } return ret; } static const char * const pm8821_rev_names[] = { [PM8XXX_REVISION_8821_TEST] = "test", [PM8XXX_REVISION_8821_1p0] = "1.0", [PM8XXX_REVISION_8821_2p0] = "2.0", [PM8XXX_REVISION_8821_2p1] = "2.1", }; static int __devinit pm8821_probe(struct platform_device *pdev) { const struct pm8821_platform_data *pdata = pdev->dev.platform_data; const char *revision_name = "unknown"; struct pm8821 *pmic; enum pm8xxx_version version; int revision; int rc; u8 val; if (!pdata) { pr_err("missing platform data\n"); return -EINVAL; } pmic = kzalloc(sizeof(struct pm8821), GFP_KERNEL); if (!pmic) { pr_err("Cannot alloc pm8821 struct\n"); return -ENOMEM; } /* Read PMIC chip revision */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); goto err_read_rev; } pr_info("PMIC revision 1: PM8821 rev %02X\n", val); pmic->rev_registers = val; /* Read PMIC chip revision 2 */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", REG_HWREV_2, rc); goto err_read_rev; } pr_info("PMIC revision 2: PM8821 rev %02X\n", val); pmic->rev_registers |= val << BITS_PER_BYTE; pmic->dev = &pdev->dev; pm8821_drvdata.pm_chip_data = pmic; platform_set_drvdata(pdev, &pm8821_drvdata); /* Print out human readable version and revision names. */ version = pm8xxx_get_version(pmic->dev); if (version == PM8XXX_VERSION_8821) { revision = pm8xxx_get_revision(pmic->dev); if (revision >= 0 && revision < ARRAY_SIZE(pm8821_rev_names)) revision_name = pm8821_rev_names[revision]; pr_info("PMIC version: PM8821 ver %s\n", revision_name); } else { WARN_ON(version != PM8XXX_VERSION_8821); } rc = pm8821_add_subdevices(pdata, pmic); if (rc) { pr_err("Cannot add subdevices rc=%d\n", rc); goto err; } return 0; err: mfd_remove_devices(pmic->dev); platform_set_drvdata(pdev, NULL); err_read_rev: kfree(pmic); return rc; } static int __devexit pm8821_remove(struct platform_device *pdev) { struct pm8xxx_drvdata *drvdata; struct pm8821 *pmic = NULL; drvdata = platform_get_drvdata(pdev); if (drvdata) pmic = drvdata->pm_chip_data; if (pmic) mfd_remove_devices(pmic->dev); if (pmic->irq_chip) { pm8821_irq_exit(pmic->irq_chip); pmic->irq_chip = NULL; } platform_set_drvdata(pdev, NULL); kfree(pmic); return 0; } static struct platform_driver pm8821_driver = { .probe = pm8821_probe, .remove = __devexit_p(pm8821_remove), .driver = { .name = "pm8821-core", .owner = THIS_MODULE, }, }; static int __init pm8821_init(void) { return platform_driver_register(&pm8821_driver); } postcore_initcall(pm8821_init); static void __exit pm8821_exit(void) { platform_driver_unregister(&pm8821_driver); } module_exit(pm8821_exit); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("PMIC 8821 core driver"); MODULE_VERSION("1.0"); MODULE_ALIAS("platform:pm8821-core");
gpl-2.0
TREX-ROM/kernel_n5_racer
fs/ext4/mmp.c
3390
9066
#include <linux/fs.h> #include <linux/random.h> #include <linux/buffer_head.h> #include <linux/utsname.h> #include <linux/kthread.h> #include "ext4.h" /* * Write the MMP block using WRITE_SYNC to try to get the block on-disk * faster. */ static int write_mmp_block(struct buffer_head *bh) { mark_buffer_dirty(bh); lock_buffer(bh); bh->b_end_io = end_buffer_write_sync; get_bh(bh); submit_bh(WRITE_SYNC, bh); wait_on_buffer(bh); if (unlikely(!buffer_uptodate(bh))) return 1; return 0; } /* * Read the MMP block. It _must_ be read from disk and hence we clear the * uptodate flag on the buffer. */ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, ext4_fsblk_t mmp_block) { struct mmp_struct *mmp; if (*bh) clear_buffer_uptodate(*bh); /* This would be sb_bread(sb, mmp_block), except we need to be sure * that the MD RAID device cache has been bypassed, and that the read * is not blocked in the elevator. */ if (!*bh) *bh = sb_getblk(sb, mmp_block); if (*bh) { get_bh(*bh); lock_buffer(*bh); (*bh)->b_end_io = end_buffer_read_sync; submit_bh(READ_SYNC, *bh); wait_on_buffer(*bh); if (!buffer_uptodate(*bh)) { brelse(*bh); *bh = NULL; } } if (!*bh) { ext4_warning(sb, "Error while reading MMP block %llu", mmp_block); return -EIO; } mmp = (struct mmp_struct *)((*bh)->b_data); if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC) return -EINVAL; return 0; } /* * Dump as much information as possible to help the admin. */ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp, const char *function, unsigned int line, const char *msg) { __ext4_warning(sb, function, line, msg); __ext4_warning(sb, function, line, "MMP failure info: last update time: %llu, last update " "node: %s, last update device: %s\n", (long long unsigned int) le64_to_cpu(mmp->mmp_time), mmp->mmp_nodename, mmp->mmp_bdevname); } /* * kmmpd will update the MMP sequence every s_mmp_update_interval seconds */ static int kmmpd(void *data) { struct super_block *sb = ((struct mmpd_data *) data)->sb; struct buffer_head *bh = ((struct mmpd_data *) data)->bh; struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct mmp_struct *mmp; ext4_fsblk_t mmp_block; u32 seq = 0; unsigned long failed_writes = 0; int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned mmp_check_interval; unsigned long last_update_time; unsigned long diff; int retval; mmp_block = le64_to_cpu(es->s_mmp_block); mmp = (struct mmp_struct *)(bh->b_data); mmp->mmp_time = cpu_to_le64(get_seconds()); /* * Start with the higher mmp_check_interval and reduce it if * the MMP block is being updated on time. */ mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval, EXT4_MMP_MIN_CHECK_INTERVAL); mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval); bdevname(bh->b_bdev, mmp->mmp_bdevname); memcpy(mmp->mmp_nodename, init_utsname()->nodename, sizeof(mmp->mmp_nodename)); while (!kthread_should_stop()) { if (++seq > EXT4_MMP_SEQ_MAX) seq = 1; mmp->mmp_seq = cpu_to_le32(seq); mmp->mmp_time = cpu_to_le64(get_seconds()); last_update_time = jiffies; retval = write_mmp_block(bh); /* * Don't spew too many error messages. Print one every * (s_mmp_update_interval * 60) seconds. */ if (retval) { if ((failed_writes % 60) == 0) ext4_error(sb, "Error writing to MMP block"); failed_writes++; } if (!(le32_to_cpu(es->s_feature_incompat) & EXT4_FEATURE_INCOMPAT_MMP)) { ext4_warning(sb, "kmmpd being stopped since MMP feature" " has been disabled."); EXT4_SB(sb)->s_mmp_tsk = NULL; goto failed; } if (sb->s_flags & MS_RDONLY) { ext4_warning(sb, "kmmpd being stopped since filesystem " "has been remounted as readonly."); EXT4_SB(sb)->s_mmp_tsk = NULL; goto failed; } diff = jiffies - last_update_time; if (diff < mmp_update_interval * HZ) schedule_timeout_interruptible(mmp_update_interval * HZ - diff); /* * We need to make sure that more than mmp_check_interval * seconds have not passed since writing. If that has happened * we need to check if the MMP block is as we left it. */ diff = jiffies - last_update_time; if (diff > mmp_check_interval * HZ) { struct buffer_head *bh_check = NULL; struct mmp_struct *mmp_check; retval = read_mmp_block(sb, &bh_check, mmp_block); if (retval) { ext4_error(sb, "error reading MMP data: %d", retval); EXT4_SB(sb)->s_mmp_tsk = NULL; goto failed; } mmp_check = (struct mmp_struct *)(bh_check->b_data); if (mmp->mmp_seq != mmp_check->mmp_seq || memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename, sizeof(mmp->mmp_nodename))) { dump_mmp_msg(sb, mmp_check, "Error while updating MMP info. " "The filesystem seems to have been" " multiply mounted."); ext4_error(sb, "abort"); goto failed; } put_bh(bh_check); } /* * Adjust the mmp_check_interval depending on how much time * it took for the MMP block to be written. */ mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ, EXT4_MMP_MAX_CHECK_INTERVAL), EXT4_MMP_MIN_CHECK_INTERVAL); mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval); } /* * Unmount seems to be clean. */ mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN); mmp->mmp_time = cpu_to_le64(get_seconds()); retval = write_mmp_block(bh); failed: kfree(data); brelse(bh); return retval; } /* * Get a random new sequence number but make sure it is not greater than * EXT4_MMP_SEQ_MAX. */ static unsigned int mmp_new_seq(void) { u32 new_seq; do { get_random_bytes(&new_seq, sizeof(u32)); } while (new_seq > EXT4_MMP_SEQ_MAX); return new_seq; } /* * Protect the filesystem from being mounted more than once. */ int ext4_multi_mount_protect(struct super_block *sb, ext4_fsblk_t mmp_block) { struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct buffer_head *bh = NULL; struct mmp_struct *mmp = NULL; struct mmpd_data *mmpd_data; u32 seq; unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned int wait_time = 0; int retval; if (mmp_block < le32_to_cpu(es->s_first_data_block) || mmp_block >= ext4_blocks_count(es)) { ext4_warning(sb, "Invalid MMP block in superblock"); goto failed; } retval = read_mmp_block(sb, &bh, mmp_block); if (retval) goto failed; mmp = (struct mmp_struct *)(bh->b_data); if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL) mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL; /* * If check_interval in MMP block is larger, use that instead of * update_interval from the superblock. */ if (le16_to_cpu(mmp->mmp_check_interval) > mmp_check_interval) mmp_check_interval = le16_to_cpu(mmp->mmp_check_interval); seq = le32_to_cpu(mmp->mmp_seq); if (seq == EXT4_MMP_SEQ_CLEAN) goto skip; if (seq == EXT4_MMP_SEQ_FSCK) { dump_mmp_msg(sb, mmp, "fsck is running on the filesystem"); goto failed; } wait_time = min(mmp_check_interval * 2 + 1, mmp_check_interval + 60); /* Print MMP interval if more than 20 secs. */ if (wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4) ext4_warning(sb, "MMP interval %u higher than expected, please" " wait.\n", wait_time * 2); if (schedule_timeout_interruptible(HZ * wait_time) != 0) { ext4_warning(sb, "MMP startup interrupted, failing mount\n"); goto failed; } retval = read_mmp_block(sb, &bh, mmp_block); if (retval) goto failed; mmp = (struct mmp_struct *)(bh->b_data); if (seq != le32_to_cpu(mmp->mmp_seq)) { dump_mmp_msg(sb, mmp, "Device is already active on another node."); goto failed; } skip: /* * write a new random sequence number. */ seq = mmp_new_seq(); mmp->mmp_seq = cpu_to_le32(seq); retval = write_mmp_block(bh); if (retval) goto failed; /* * wait for MMP interval and check mmp_seq. */ if (schedule_timeout_interruptible(HZ * wait_time) != 0) { ext4_warning(sb, "MMP startup interrupted, failing mount\n"); goto failed; } retval = read_mmp_block(sb, &bh, mmp_block); if (retval) goto failed; mmp = (struct mmp_struct *)(bh->b_data); if (seq != le32_to_cpu(mmp->mmp_seq)) { dump_mmp_msg(sb, mmp, "Device is already active on another node."); goto failed; } mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL); if (!mmpd_data) { ext4_warning(sb, "not enough memory for mmpd_data"); goto failed; } mmpd_data->sb = sb; mmpd_data->bh = bh; /* * Start a kernel thread to update the MMP block periodically. */ EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s", bdevname(bh->b_bdev, mmp->mmp_bdevname)); if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) { EXT4_SB(sb)->s_mmp_tsk = NULL; kfree(mmpd_data); ext4_warning(sb, "Unable to create kmmpd thread for %s.", sb->s_id); goto failed; } return 0; failed: brelse(bh); return 1; }
gpl-2.0
CyanogenMod/android_kernel_moto_shamu
drivers/media/usb/gspca/m5602/m5602_s5k83a.c
3646
10853
/* * Driver for the s5k83a sensor * * Copyright (C) 2008 Erik Andrén * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project. * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br> * * Portions of code to USB interface and ALi driver software, * Copyright (c) 2006 Willem Duinker * v4l2 interface modeled after the V4L2 driver * for SN9C10x PC Camera Controllers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kthread.h> #include "m5602_s5k83a.h" static int s5k83a_s_ctrl(struct v4l2_ctrl *ctrl); static const struct v4l2_ctrl_ops s5k83a_ctrl_ops = { .s_ctrl = s5k83a_s_ctrl, }; static struct v4l2_pix_format s5k83a_modes[] = { { 640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, .sizeimage = 640 * 480, .bytesperline = 640, .colorspace = V4L2_COLORSPACE_SRGB, .priv = 0 } }; static void s5k83a_dump_registers(struct sd *sd); static int s5k83a_get_rotation(struct sd *sd, u8 *reg_data); static int s5k83a_set_led_indication(struct sd *sd, u8 val); static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev, __s32 vflip, __s32 hflip); int s5k83a_probe(struct sd *sd) { u8 prod_id = 0, ver_id = 0; int i, err = 0; struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; if (force_sensor) { if (force_sensor == S5K83A_SENSOR) { pr_info("Forcing a %s sensor\n", s5k83a.name); goto sensor_found; } /* If we want to force another sensor, don't try to probe this * one */ return -ENODEV; } PDEBUG(D_PROBE, "Probing for a s5k83a sensor"); /* Preinit the sensor */ for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) { u8 data[2] = {preinit_s5k83a[i][2], preinit_s5k83a[i][3]}; if (preinit_s5k83a[i][0] == SENSOR) err = m5602_write_sensor(sd, preinit_s5k83a[i][1], data, 2); else err = m5602_write_bridge(sd, preinit_s5k83a[i][1], data[0]); } /* We don't know what register (if any) that contain the product id * Just pick the first addresses that seem to produce the same results * on multiple machines */ if (m5602_read_sensor(sd, 0x00, &prod_id, 1)) return -ENODEV; if (m5602_read_sensor(sd, 0x01, &ver_id, 1)) return -ENODEV; if ((prod_id == 0xff) || (ver_id == 0xff)) return -ENODEV; else pr_info("Detected a s5k83a sensor\n"); sensor_found: sd->gspca_dev.cam.cam_mode = s5k83a_modes; sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k83a_modes); /* null the pointer! thread is't running now */ sd->rotation_thread = NULL; return 0; } int s5k83a_init(struct sd *sd) { int i, err = 0; for (i = 0; i < ARRAY_SIZE(init_s5k83a) && !err; i++) { u8 data[2] = {0x00, 0x00}; switch (init_s5k83a[i][0]) { case BRIDGE: err = m5602_write_bridge(sd, init_s5k83a[i][1], init_s5k83a[i][2]); break; case SENSOR: data[0] = init_s5k83a[i][2]; err = m5602_write_sensor(sd, init_s5k83a[i][1], data, 1); break; case SENSOR_LONG: data[0] = init_s5k83a[i][2]; data[1] = init_s5k83a[i][3]; err = m5602_write_sensor(sd, init_s5k83a[i][1], data, 2); break; default: pr_info("Invalid stream command, exiting init\n"); return -EINVAL; } } if (dump_sensor) s5k83a_dump_registers(sd); return err; } int s5k83a_init_controls(struct sd *sd) { struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler; sd->gspca_dev.vdev.ctrl_handler = hdl; v4l2_ctrl_handler_init(hdl, 6); v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_BRIGHTNESS, 0, 255, 1, S5K83A_DEFAULT_BRIGHTNESS); v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_EXPOSURE, 0, S5K83A_MAXIMUM_EXPOSURE, 1, S5K83A_DEFAULT_EXPOSURE); v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_GAIN, 0, 255, 1, S5K83A_DEFAULT_GAIN); sd->hflip = v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); sd->vflip = v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); if (hdl->error) { pr_err("Could not initialize controls\n"); return hdl->error; } v4l2_ctrl_cluster(2, &sd->hflip); return 0; } static int rotation_thread_function(void *data) { struct sd *sd = (struct sd *) data; u8 reg, previous_rotation = 0; __s32 vflip, hflip; set_current_state(TASK_INTERRUPTIBLE); while (!schedule_timeout(100)) { if (mutex_lock_interruptible(&sd->gspca_dev.usb_lock)) break; s5k83a_get_rotation(sd, &reg); if (previous_rotation != reg) { previous_rotation = reg; pr_info("Camera was flipped\n"); hflip = sd->hflip->val; vflip = sd->vflip->val; if (reg) { vflip = !vflip; hflip = !hflip; } s5k83a_set_flip_real((struct gspca_dev *) sd, vflip, hflip); } mutex_unlock(&sd->gspca_dev.usb_lock); set_current_state(TASK_INTERRUPTIBLE); } /* return to "front" flip */ if (previous_rotation) { hflip = sd->hflip->val; vflip = sd->vflip->val; s5k83a_set_flip_real((struct gspca_dev *) sd, vflip, hflip); } sd->rotation_thread = NULL; return 0; } int s5k83a_start(struct sd *sd) { int i, err = 0; /* Create another thread, polling the GPIO ports of the camera to check if it got rotated. This is how the windows driver does it so we have to assume that there is no better way of accomplishing this */ sd->rotation_thread = kthread_create(rotation_thread_function, sd, "rotation thread"); wake_up_process(sd->rotation_thread); /* Preinit the sensor */ for (i = 0; i < ARRAY_SIZE(start_s5k83a) && !err; i++) { u8 data[2] = {start_s5k83a[i][2], start_s5k83a[i][3]}; if (start_s5k83a[i][0] == SENSOR) err = m5602_write_sensor(sd, start_s5k83a[i][1], data, 2); else err = m5602_write_bridge(sd, start_s5k83a[i][1], data[0]); } if (err < 0) return err; return s5k83a_set_led_indication(sd, 1); } int s5k83a_stop(struct sd *sd) { if (sd->rotation_thread) kthread_stop(sd->rotation_thread); return s5k83a_set_led_indication(sd, 0); } void s5k83a_disconnect(struct sd *sd) { s5k83a_stop(sd); sd->sensor = NULL; } static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[2]; struct sd *sd = (struct sd *) gspca_dev; data[0] = 0x00; data[1] = 0x20; err = m5602_write_sensor(sd, 0x14, data, 2); if (err < 0) return err; data[0] = 0x01; data[1] = 0x00; err = m5602_write_sensor(sd, 0x0d, data, 2); if (err < 0) return err; /* FIXME: This is not sane, we need to figure out the composition of these registers */ data[0] = val >> 3; /* gain, high 5 bits */ data[1] = val >> 1; /* gain, high 7 bits */ err = m5602_write_sensor(sd, S5K83A_GAIN, data, 2); return err; } static int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[1]; struct sd *sd = (struct sd *) gspca_dev; data[0] = val; err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 1); return err; } static int s5k83a_set_exposure(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[2]; struct sd *sd = (struct sd *) gspca_dev; data[0] = 0; data[1] = val; err = m5602_write_sensor(sd, S5K83A_EXPOSURE, data, 2); return err; } static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev, __s32 vflip, __s32 hflip) { int err; u8 data[1]; struct sd *sd = (struct sd *) gspca_dev; data[0] = 0x05; err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); if (err < 0) return err; /* six bit is vflip, seven is hflip */ data[0] = S5K83A_FLIP_MASK; data[0] = (vflip) ? data[0] | 0x40 : data[0]; data[0] = (hflip) ? data[0] | 0x80 : data[0]; err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1); if (err < 0) return err; data[0] = (vflip) ? 0x0b : 0x0a; err = m5602_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1); if (err < 0) return err; data[0] = (hflip) ? 0x0a : 0x0b; err = m5602_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1); return err; } static int s5k83a_set_hvflip(struct gspca_dev *gspca_dev) { int err; u8 reg; struct sd *sd = (struct sd *) gspca_dev; int hflip = sd->hflip->val; int vflip = sd->vflip->val; err = s5k83a_get_rotation(sd, &reg); if (err < 0) return err; if (reg) { hflip = !hflip; vflip = !vflip; } err = s5k83a_set_flip_real(gspca_dev, vflip, hflip); return err; } static int s5k83a_s_ctrl(struct v4l2_ctrl *ctrl) { struct gspca_dev *gspca_dev = container_of(ctrl->handler, struct gspca_dev, ctrl_handler); int err; if (!gspca_dev->streaming) return 0; switch (ctrl->id) { case V4L2_CID_BRIGHTNESS: err = s5k83a_set_brightness(gspca_dev, ctrl->val); break; case V4L2_CID_EXPOSURE: err = s5k83a_set_exposure(gspca_dev, ctrl->val); break; case V4L2_CID_GAIN: err = s5k83a_set_gain(gspca_dev, ctrl->val); break; case V4L2_CID_HFLIP: err = s5k83a_set_hvflip(gspca_dev); break; default: return -EINVAL; } return err; } static int s5k83a_set_led_indication(struct sd *sd, u8 val) { int err = 0; u8 data[1]; err = m5602_read_bridge(sd, M5602_XB_GPIO_DAT, data); if (err < 0) return err; if (val) data[0] = data[0] | S5K83A_GPIO_LED_MASK; else data[0] = data[0] & ~S5K83A_GPIO_LED_MASK; err = m5602_write_bridge(sd, M5602_XB_GPIO_DAT, data[0]); return err; } /* Get camera rotation on Acer notebooks */ static int s5k83a_get_rotation(struct sd *sd, u8 *reg_data) { int err = m5602_read_bridge(sd, M5602_XB_GPIO_DAT, reg_data); *reg_data = (*reg_data & S5K83A_GPIO_ROTATION_MASK) ? 0 : 1; return err; } static void s5k83a_dump_registers(struct sd *sd) { int address; u8 page, old_page; m5602_read_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1); for (page = 0; page < 16; page++) { m5602_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1); pr_info("Dumping the s5k83a register state for page 0x%x\n", page); for (address = 0; address <= 0xff; address++) { u8 val = 0; m5602_read_sensor(sd, address, &val, 1); pr_info("register 0x%x contains 0x%x\n", address, val); } } pr_info("s5k83a register state dump complete\n"); for (page = 0; page < 16; page++) { m5602_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1); pr_info("Probing for which registers that are read/write for page 0x%x\n", page); for (address = 0; address <= 0xff; address++) { u8 old_val, ctrl_val, test_val = 0xff; m5602_read_sensor(sd, address, &old_val, 1); m5602_write_sensor(sd, address, &test_val, 1); m5602_read_sensor(sd, address, &ctrl_val, 1); if (ctrl_val == test_val) pr_info("register 0x%x is writeable\n", address); else pr_info("register 0x%x is read only\n", address); /* Restore original val */ m5602_write_sensor(sd, address, &old_val, 1); } } pr_info("Read/write register probing complete\n"); m5602_write_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1); }
gpl-2.0
LuweiLight/linux-3.14.35-vbal
drivers/isdn/hardware/eicon/diddfunc.c
4926
2644
/* $Id: diddfunc.c,v 1.14.6.2 2004/08/28 20:03:53 armin Exp $ * * DIDD Interface module for Eicon active cards. * * Functions are in dadapter.c * * Copyright 2002-2003 by Armin Schindler (mac@melware.de) * Copyright 2002-2003 Cytronics & Melware (info@melware.de) * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. */ #include "platform.h" #include "di_defs.h" #include "dadapter.h" #include "divasync.h" #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR) #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG) extern void DIVA_DIDD_Read(void *, int); extern char *DRIVERRELEASE_DIDD; static dword notify_handle; static DESCRIPTOR _DAdapter; /* * didd callback function */ static void *didd_callback(void *context, DESCRIPTOR *adapter, int removal) { if (adapter->type == IDI_DADAPTER) { DBG_ERR(("Notification about IDI_DADAPTER change ! Oops.")) return (NULL); } else if (adapter->type == IDI_DIMAINT) { if (removal) { DbgDeregister(); } else { DbgRegister("DIDD", DRIVERRELEASE_DIDD, DBG_DEFAULT); } } return (NULL); } /* * connect to didd */ static int __init connect_didd(void) { int x = 0; int dadapter = 0; IDI_SYNC_REQ req; DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS]; DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table)); for (x = 0; x < MAX_DESCRIPTORS; x++) { if (DIDD_Table[x].type == IDI_DADAPTER) { /* DADAPTER found */ dadapter = 1; memcpy(&_DAdapter, &DIDD_Table[x], sizeof(_DAdapter)); req.didd_notify.e.Req = 0; req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REGISTER_ADAPTER_NOTIFY; req.didd_notify.info.callback = (void *)didd_callback; req.didd_notify.info.context = NULL; _DAdapter.request((ENTITY *)&req); if (req.didd_notify.e.Rc != 0xff) return (0); notify_handle = req.didd_notify.info.handle; } else if (DIDD_Table[x].type == IDI_DIMAINT) { /* MAINT found */ DbgRegister("DIDD", DRIVERRELEASE_DIDD, DBG_DEFAULT); } } return (dadapter); } /* * disconnect from didd */ static void __exit disconnect_didd(void) { IDI_SYNC_REQ req; req.didd_notify.e.Req = 0; req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY; req.didd_notify.info.handle = notify_handle; _DAdapter.request((ENTITY *)&req); } /* * init */ int __init diddfunc_init(void) { diva_didd_load_time_init(); if (!connect_didd()) { DBG_ERR(("init: failed to connect to DIDD.")) diva_didd_load_time_finit(); return (0); } return (1); } /* * finit */ void __exit diddfunc_finit(void) { DbgDeregister(); disconnect_didd(); diva_didd_load_time_finit(); }
gpl-2.0
KylinUI/android_kernel_lge_msm8974
drivers/isdn/gigaset/interface.c
4926
14969
/* * interface to user space for the gigaset driver * * Copyright (c) 2004 by Hansjoerg Lipp <hjlipp@web.de> * * ===================================================================== * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * ===================================================================== */ #include "gigaset.h" #include <linux/gigaset_dev.h> #include <linux/tty_flip.h> #include <linux/module.h> /*** our ioctls ***/ static int if_lock(struct cardstate *cs, int *arg) { int cmd = *arg; gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd); if (cmd > 1) return -EINVAL; if (cmd < 0) { *arg = cs->mstate == MS_LOCKED; return 0; } if (!cmd && cs->mstate == MS_LOCKED && cs->connected) { cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR | TIOCM_RTS); cs->ops->baud_rate(cs, B115200); cs->ops->set_line_ctrl(cs, CS8); cs->control_state = TIOCM_DTR | TIOCM_RTS; } cs->waiting = 1; if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK, NULL, cmd, NULL)) { cs->waiting = 0; return -ENOMEM; } gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); if (cs->cmd_result >= 0) { *arg = cs->cmd_result; return 0; } return cs->cmd_result; } static int if_version(struct cardstate *cs, unsigned arg[4]) { static const unsigned version[4] = GIG_VERSION; static const unsigned compat[4] = GIG_COMPAT; unsigned cmd = arg[0]; gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd); switch (cmd) { case GIGVER_DRIVER: memcpy(arg, version, sizeof version); return 0; case GIGVER_COMPAT: memcpy(arg, compat, sizeof compat); return 0; case GIGVER_FWBASE: cs->waiting = 1; if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER, NULL, 0, arg)) { cs->waiting = 0; return -ENOMEM; } gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); if (cs->cmd_result >= 0) return 0; return cs->cmd_result; default: return -EINVAL; } } static int if_config(struct cardstate *cs, int *arg) { gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg); if (*arg != 1) return -EINVAL; if (cs->mstate != MS_LOCKED) return -EBUSY; if (!cs->connected) { pr_err("%s: not connected\n", __func__); return -ENODEV; } *arg = 0; return gigaset_enterconfigmode(cs); } /*** the terminal driver ***/ /* stolen from usbserial and some other tty drivers */ static int if_open(struct tty_struct *tty, struct file *filp); static void if_close(struct tty_struct *tty, struct file *filp); static int if_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg); static int if_write_room(struct tty_struct *tty); static int if_chars_in_buffer(struct tty_struct *tty); static void if_throttle(struct tty_struct *tty); static void if_unthrottle(struct tty_struct *tty); static void if_set_termios(struct tty_struct *tty, struct ktermios *old); static int if_tiocmget(struct tty_struct *tty); static int if_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); static int if_write(struct tty_struct *tty, const unsigned char *buf, int count); static const struct tty_operations if_ops = { .open = if_open, .close = if_close, .ioctl = if_ioctl, .write = if_write, .write_room = if_write_room, .chars_in_buffer = if_chars_in_buffer, .set_termios = if_set_termios, .throttle = if_throttle, .unthrottle = if_unthrottle, .tiocmget = if_tiocmget, .tiocmset = if_tiocmset, }; static int if_open(struct tty_struct *tty, struct file *filp) { struct cardstate *cs; gig_dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index, __func__); cs = gigaset_get_cs_by_tty(tty); if (!cs || !try_module_get(cs->driver->owner)) return -ENODEV; if (mutex_lock_interruptible(&cs->mutex)) { module_put(cs->driver->owner); return -ERESTARTSYS; } tty->driver_data = cs; ++cs->port.count; if (cs->port.count == 1) { tty_port_tty_set(&cs->port, tty); tty->low_latency = 1; } mutex_unlock(&cs->mutex); return 0; } static void if_close(struct tty_struct *tty, struct file *filp) { struct cardstate *cs = tty->driver_data; if (!cs) { /* happens if we didn't find cs in open */ gig_dbg(DEBUG_IF, "%s: no cardstate", __func__); return; } gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); mutex_lock(&cs->mutex); if (!cs->connected) gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ else if (!cs->port.count) dev_warn(cs->dev, "%s: device not opened\n", __func__); else if (!--cs->port.count) tty_port_tty_set(&cs->port, NULL); mutex_unlock(&cs->mutex); module_put(cs->driver->owner); } static int if_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct cardstate *cs = tty->driver_data; int retval = -ENODEV; int int_arg; unsigned char buf[6]; unsigned version[4]; gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); if (mutex_lock_interruptible(&cs->mutex)) return -ERESTARTSYS; if (!cs->connected) { gig_dbg(DEBUG_IF, "not connected"); retval = -ENODEV; } else { retval = 0; switch (cmd) { case GIGASET_REDIR: retval = get_user(int_arg, (int __user *) arg); if (retval >= 0) retval = if_lock(cs, &int_arg); if (retval >= 0) retval = put_user(int_arg, (int __user *) arg); break; case GIGASET_CONFIG: retval = get_user(int_arg, (int __user *) arg); if (retval >= 0) retval = if_config(cs, &int_arg); if (retval >= 0) retval = put_user(int_arg, (int __user *) arg); break; case GIGASET_BRKCHARS: retval = copy_from_user(&buf, (const unsigned char __user *) arg, 6) ? -EFAULT : 0; if (retval >= 0) { gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS", 6, (const unsigned char *) arg); retval = cs->ops->brkchars(cs, buf); } break; case GIGASET_VERSION: retval = copy_from_user(version, (unsigned __user *) arg, sizeof version) ? -EFAULT : 0; if (retval >= 0) retval = if_version(cs, version); if (retval >= 0) retval = copy_to_user((unsigned __user *) arg, version, sizeof version) ? -EFAULT : 0; break; default: gig_dbg(DEBUG_IF, "%s: arg not supported - 0x%04x", __func__, cmd); retval = -ENOIOCTLCMD; } } mutex_unlock(&cs->mutex); return retval; } static int if_tiocmget(struct tty_struct *tty) { struct cardstate *cs = tty->driver_data; int retval; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); if (mutex_lock_interruptible(&cs->mutex)) return -ERESTARTSYS; retval = cs->control_state & (TIOCM_RTS | TIOCM_DTR); mutex_unlock(&cs->mutex); return retval; } static int if_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { struct cardstate *cs = tty->driver_data; int retval; unsigned mc; gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", cs->minor_index, __func__, set, clear); if (mutex_lock_interruptible(&cs->mutex)) return -ERESTARTSYS; if (!cs->connected) { gig_dbg(DEBUG_IF, "not connected"); retval = -ENODEV; } else { mc = (cs->control_state | set) & ~clear & (TIOCM_RTS | TIOCM_DTR); retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc); cs->control_state = mc; } mutex_unlock(&cs->mutex); return retval; } static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct cardstate *cs = tty->driver_data; struct cmdbuf_t *cb; int retval; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); if (mutex_lock_interruptible(&cs->mutex)) return -ERESTARTSYS; if (!cs->connected) { gig_dbg(DEBUG_IF, "not connected"); retval = -ENODEV; goto done; } if (cs->mstate != MS_LOCKED) { dev_warn(cs->dev, "can't write to unlocked device\n"); retval = -EBUSY; goto done; } if (count <= 0) { /* nothing to do */ retval = 0; goto done; } cb = kmalloc(sizeof(struct cmdbuf_t) + count, GFP_KERNEL); if (!cb) { dev_err(cs->dev, "%s: out of memory\n", __func__); retval = -ENOMEM; goto done; } memcpy(cb->buf, buf, count); cb->len = count; cb->offset = 0; cb->next = NULL; cb->wake_tasklet = &cs->if_wake_tasklet; retval = cs->ops->write_cmd(cs, cb); done: mutex_unlock(&cs->mutex); return retval; } static int if_write_room(struct tty_struct *tty) { struct cardstate *cs = tty->driver_data; int retval = -ENODEV; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); if (mutex_lock_interruptible(&cs->mutex)) return -ERESTARTSYS; if (!cs->connected) { gig_dbg(DEBUG_IF, "not connected"); retval = -ENODEV; } else if (cs->mstate != MS_LOCKED) { dev_warn(cs->dev, "can't write to unlocked device\n"); retval = -EBUSY; } else retval = cs->ops->write_room(cs); mutex_unlock(&cs->mutex); return retval; } static int if_chars_in_buffer(struct tty_struct *tty) { struct cardstate *cs = tty->driver_data; int retval = 0; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); mutex_lock(&cs->mutex); if (!cs->connected) gig_dbg(DEBUG_IF, "not connected"); else if (cs->mstate != MS_LOCKED) dev_warn(cs->dev, "can't write to unlocked device\n"); else retval = cs->ops->chars_in_buffer(cs); mutex_unlock(&cs->mutex); return retval; } static void if_throttle(struct tty_struct *tty) { struct cardstate *cs = tty->driver_data; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); mutex_lock(&cs->mutex); if (!cs->connected) gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ else gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); mutex_unlock(&cs->mutex); } static void if_unthrottle(struct tty_struct *tty) { struct cardstate *cs = tty->driver_data; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); mutex_lock(&cs->mutex); if (!cs->connected) gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ else gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); mutex_unlock(&cs->mutex); } static void if_set_termios(struct tty_struct *tty, struct ktermios *old) { struct cardstate *cs = tty->driver_data; unsigned int iflag; unsigned int cflag; unsigned int old_cflag; unsigned int control_state, new_state; gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); mutex_lock(&cs->mutex); if (!cs->connected) { gig_dbg(DEBUG_IF, "not connected"); goto out; } iflag = tty->termios->c_iflag; cflag = tty->termios->c_cflag; old_cflag = old ? old->c_cflag : cflag; gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index, iflag, cflag, old_cflag); /* get a local copy of the current port settings */ control_state = cs->control_state; /* * Update baud rate. * Do not attempt to cache old rates and skip settings, * disconnects screw such tricks up completely. * Premature optimization is the root of all evil. */ /* reassert DTR and (maybe) RTS on transition from B0 */ if ((old_cflag & CBAUD) == B0) { new_state = control_state | TIOCM_DTR; /* don't set RTS if using hardware flow control */ if (!(old_cflag & CRTSCTS)) new_state |= TIOCM_RTS; gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index, (new_state & TIOCM_RTS) ? " only" : "/RTS"); cs->ops->set_modem_ctrl(cs, control_state, new_state); control_state = new_state; } cs->ops->baud_rate(cs, cflag & CBAUD); if ((cflag & CBAUD) == B0) { /* Drop RTS and DTR */ gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index); new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS); cs->ops->set_modem_ctrl(cs, control_state, new_state); control_state = new_state; } /* * Update line control register (LCR) */ cs->ops->set_line_ctrl(cs, cflag); /* save off the modified port settings */ cs->control_state = control_state; out: mutex_unlock(&cs->mutex); } /* wakeup tasklet for the write operation */ static void if_wake(unsigned long data) { struct cardstate *cs = (struct cardstate *)data; struct tty_struct *tty = tty_port_tty_get(&cs->port); if (tty) { tty_wakeup(tty); tty_kref_put(tty); } } /*** interface to common ***/ void gigaset_if_init(struct cardstate *cs) { struct gigaset_driver *drv; drv = cs->driver; if (!drv->have_tty) return; tasklet_init(&cs->if_wake_tasklet, if_wake, (unsigned long) cs); mutex_lock(&cs->mutex); cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL); if (!IS_ERR(cs->tty_dev)) dev_set_drvdata(cs->tty_dev, cs); else { pr_warning("could not register device to the tty subsystem\n"); cs->tty_dev = NULL; } mutex_unlock(&cs->mutex); } void gigaset_if_free(struct cardstate *cs) { struct gigaset_driver *drv; drv = cs->driver; if (!drv->have_tty) return; tasklet_disable(&cs->if_wake_tasklet); tasklet_kill(&cs->if_wake_tasklet); cs->tty_dev = NULL; tty_unregister_device(drv->tty, cs->minor_index); } /** * gigaset_if_receive() - pass a received block of data to the tty device * @cs: device descriptor structure. * @buffer: received data. * @len: number of bytes received. * * Called by asyncdata/isocdata if a block of data received from the * device must be sent to userspace through the ttyG* device. */ void gigaset_if_receive(struct cardstate *cs, unsigned char *buffer, size_t len) { struct tty_struct *tty = tty_port_tty_get(&cs->port); if (tty == NULL) { gig_dbg(DEBUG_IF, "receive on closed device"); return; } tty_insert_flip_string(tty, buffer, len); tty_flip_buffer_push(tty); tty_kref_put(tty); } EXPORT_SYMBOL_GPL(gigaset_if_receive); /* gigaset_if_initdriver * Initialize tty interface. * parameters: * drv Driver * procname Name of the driver (e.g. for /proc/tty/drivers) * devname Name of the device files (prefix without minor number) */ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, const char *devname) { int ret; struct tty_driver *tty; drv->have_tty = 0; drv->tty = tty = alloc_tty_driver(drv->minors); if (tty == NULL) goto enomem; tty->type = TTY_DRIVER_TYPE_SERIAL; tty->subtype = SERIAL_TYPE_NORMAL; tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; tty->driver_name = procname; tty->name = devname; tty->minor_start = drv->minor; tty->init_termios = tty_std_termios; tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty_set_operations(tty, &if_ops); ret = tty_register_driver(tty); if (ret < 0) { pr_err("error %d registering tty driver\n", ret); goto error; } gig_dbg(DEBUG_IF, "tty driver initialized"); drv->have_tty = 1; return; enomem: pr_err("out of memory\n"); error: if (drv->tty) put_tty_driver(drv->tty); } void gigaset_if_freedriver(struct gigaset_driver *drv) { if (!drv->have_tty) return; drv->have_tty = 0; tty_unregister_driver(drv->tty); put_tty_driver(drv->tty); }
gpl-2.0
nyterage/Galaxy_Tab_3_217s
arch/mips/pci/ops-sni.c
9534
3734
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * SNI specific PCI support for RM200/RM300. * * Copyright (C) 1997 - 2000, 2003 Ralf Baechle <ralf@linux-mips.org> */ #include <linux/kernel.h> #include <linux/pci.h> #include <linux/types.h> #include <asm/sni.h> /* * It seems that on the RM200 only lower 3 bits of the 5 bit PCI device * address are decoded. We therefore manually have to reject attempts at * reading outside this range. Being on the paranoid side we only do this * test for bus 0 and hope forwarding and decoding work properly for any * subordinated busses. * * ASIC PCI only supports type 1 config cycles. */ static int set_config_address(unsigned int busno, unsigned int devfn, int reg) { if ((devfn > 255) || (reg > 255)) return PCIBIOS_BAD_REGISTER_NUMBER; if (busno == 0 && devfn >= PCI_DEVFN(8, 0)) return PCIBIOS_DEVICE_NOT_FOUND; *(volatile u32 *)PCIMT_CONFIG_ADDRESS = ((busno & 0xff) << 16) | ((devfn & 0xff) << 8) | (reg & 0xfc); return PCIBIOS_SUCCESSFUL; } static int pcimt_read(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 * val) { int res; if ((res = set_config_address(bus->number, devfn, reg))) return res; switch (size) { case 1: *val = inb(PCIMT_CONFIG_DATA + (reg & 3)); break; case 2: *val = inw(PCIMT_CONFIG_DATA + (reg & 2)); break; case 4: *val = inl(PCIMT_CONFIG_DATA); break; } return 0; } static int pcimt_write(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 val) { int res; if ((res = set_config_address(bus->number, devfn, reg))) return res; switch (size) { case 1: outb(val, PCIMT_CONFIG_DATA + (reg & 3)); break; case 2: outw(val, PCIMT_CONFIG_DATA + (reg & 2)); break; case 4: outl(val, PCIMT_CONFIG_DATA); break; } return 0; } struct pci_ops sni_pcimt_ops = { .read = pcimt_read, .write = pcimt_write, }; static int pcit_set_config_address(unsigned int busno, unsigned int devfn, int reg) { if ((devfn > 255) || (reg > 255) || (busno > 255)) return PCIBIOS_BAD_REGISTER_NUMBER; outl((1 << 31) | ((busno & 0xff) << 16) | ((devfn & 0xff) << 8) | (reg & 0xfc), 0xcf8); return PCIBIOS_SUCCESSFUL; } static int pcit_read(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 * val) { int res; /* * on bus 0 we need to check, whether there is a device answering * for the devfn by doing a config write and checking the result. If * we don't do it, we will get a data bus error */ if (bus->number == 0) { pcit_set_config_address(0, 0, 0x68); outl(inl(0xcfc) | 0xc0000000, 0xcfc); if ((res = pcit_set_config_address(0, devfn, 0))) return res; outl(0xffffffff, 0xcfc); pcit_set_config_address(0, 0, 0x68); if (inl(0xcfc) & 0x100000) return PCIBIOS_DEVICE_NOT_FOUND; } if ((res = pcit_set_config_address(bus->number, devfn, reg))) return res; switch (size) { case 1: *val = inb(PCIMT_CONFIG_DATA + (reg & 3)); break; case 2: *val = inw(PCIMT_CONFIG_DATA + (reg & 2)); break; case 4: *val = inl(PCIMT_CONFIG_DATA); break; } return 0; } static int pcit_write(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 val) { int res; if ((res = pcit_set_config_address(bus->number, devfn, reg))) return res; switch (size) { case 1: outb(val, PCIMT_CONFIG_DATA + (reg & 3)); break; case 2: outw(val, PCIMT_CONFIG_DATA + (reg & 2)); break; case 4: outl(val, PCIMT_CONFIG_DATA); break; } return 0; } struct pci_ops sni_pcit_ops = { .read = pcit_read, .write = pcit_write, };
gpl-2.0
fledermaus/steamos_kernel
drivers/pcmcia/pxa2xx_stargate2.c
9790
3468
/* * linux/drivers/pcmcia/pxa2xx_stargate2.c * * Stargate 2 PCMCIA specific routines. * * Created: December 6, 2005 * Author: Ed C. Epp * Copyright: Intel Corp 2005 * Jonathan Cameron <jic23@cam.ac.uk> 2009 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/platform_device.h> #include <linux/gpio.h> #include <pcmcia/ss.h> #include <asm/irq.h> #include <asm/mach-types.h> #include "soc_common.h" #define SG2_S0_POWER_CTL 108 #define SG2_S0_GPIO_RESET 82 #define SG2_S0_GPIO_DETECT 53 #define SG2_S0_GPIO_READY 81 static struct gpio sg2_pcmcia_gpios[] = { { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" }, { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" }, }; static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt) { skt->stat[SOC_STAT_CD].gpio = SG2_S0_GPIO_DETECT; skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; skt->stat[SOC_STAT_RDY].gpio = SG2_S0_GPIO_READY; skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY"; return 0; } static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) { state->bvd1 = 0; /* not available - battery detect on card */ state->bvd2 = 0; /* not available */ state->vs_3v = 1; /* not available - voltage detect for card */ state->vs_Xv = 0; /* not available */ } static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) { /* Enable card power */ switch (state->Vcc) { case 0: /* sets power ctl register high */ gpio_set_value(SG2_S0_POWER_CTL, 1); break; case 33: case 50: /* sets power control register low (clear) */ gpio_set_value(SG2_S0_POWER_CTL, 0); msleep(100); break; default: pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc); return -1; } /* reset */ gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET)); return 0; } static struct pcmcia_low_level sg2_pcmcia_ops __initdata = { .owner = THIS_MODULE, .hw_init = sg2_pcmcia_hw_init, .socket_state = sg2_pcmcia_socket_state, .configure_socket = sg2_pcmcia_configure_socket, .nr = 1, }; static struct platform_device *sg2_pcmcia_device; static int __init sg2_pcmcia_init(void) { int ret; if (!machine_is_stargate2()) return -ENODEV; sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); if (!sg2_pcmcia_device) return -ENOMEM; ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios)); if (ret) goto error_put_platform_device; ret = platform_device_add_data(sg2_pcmcia_device, &sg2_pcmcia_ops, sizeof(sg2_pcmcia_ops)); if (ret) goto error_free_gpios; ret = platform_device_add(sg2_pcmcia_device); if (ret) goto error_free_gpios; return 0; error_free_gpios: gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios)); error_put_platform_device: platform_device_put(sg2_pcmcia_device); return ret; } static void __exit sg2_pcmcia_exit(void) { platform_device_unregister(sg2_pcmcia_device); gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios)); } fs_initcall(sg2_pcmcia_init); module_exit(sg2_pcmcia_exit); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:pxa2xx-pcmcia");
gpl-2.0
rex-xxx/mt6572_x201
kernel/sound/pci/ice1712/ews.c
10046
31821
/* * ALSA driver for ICEnsemble ICE1712 (Envy24) * * Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire * * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> * 2002 Takashi Iwai <tiwai@suse.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <asm/io.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/slab.h> #include <sound/core.h> #include <sound/cs8427.h> #include <sound/asoundef.h> #include "ice1712.h" #include "ews.h" #define SND_CS8404 #include <sound/cs8403.h> enum { EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2, EWS_I2C_88D = 0, EWS_I2C_6FIRE = 0 }; /* additional i2c devices for EWS boards */ struct ews_spec { struct snd_i2c_device *i2cdevs[3]; }; /* * access via i2c mode (for EWX 24/96, EWS 88MT&D) */ /* send SDA and SCL */ static void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data) { struct snd_ice1712 *ice = bus->private_data; unsigned char tmp = 0; if (clk) tmp |= ICE1712_EWX2496_SERIAL_CLOCK; if (data) tmp |= ICE1712_EWX2496_SERIAL_DATA; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp); udelay(5); } static int ewx_i2c_getclock(struct snd_i2c_bus *bus) { struct snd_ice1712 *ice = bus->private_data; return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0; } static int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack) { struct snd_ice1712 *ice = bus->private_data; int bit; /* set RW pin to low */ snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW); snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0); if (ack) udelay(5); bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0; /* set RW pin to high */ snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW); /* reset write mask */ snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK); return bit; } static void ewx_i2c_start(struct snd_i2c_bus *bus) { struct snd_ice1712 *ice = bus->private_data; unsigned char mask; snd_ice1712_save_gpio_status(ice); /* set RW high */ mask = ICE1712_EWX2496_RW; switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWX2496: mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */ break; case ICE1712_SUBDEVICE_DMX6FIRE: mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */ break; } snd_ice1712_gpio_write_bits(ice, mask, mask); } static void ewx_i2c_stop(struct snd_i2c_bus *bus) { struct snd_ice1712 *ice = bus->private_data; snd_ice1712_restore_gpio_status(ice); } static void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data) { struct snd_ice1712 *ice = bus->private_data; unsigned char mask = 0; if (clock) mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */ if (data) mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */ ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA); ice->gpio.direction |= mask; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction); snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask); } static struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = { .start = ewx_i2c_start, .stop = ewx_i2c_stop, .direction = ewx_i2c_direction, .setlines = ewx_i2c_setlines, .getclock = ewx_i2c_getclock, .getdata = ewx_i2c_getdata, }; /* * AK4524 access */ /* AK4524 chip select; address 0x48 bit 0-3 */ static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask) { struct ews_spec *spec = ice->spec; unsigned char data, ndata; if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f)) return -EINVAL; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) goto __error; ndata = (data & 0xf0) | chip_mask; if (ndata != data) if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1) != 1) goto __error; snd_i2c_unlock(ice->i2c); return 0; __error: snd_i2c_unlock(ice->i2c); snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n"); return -EIO; } /* start callback for EWS88MT, needs to select a certain chip mask */ static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip) { struct snd_ice1712 *ice = ak->private_data[0]; unsigned char tmp; /* assert AK4524 CS */ if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0) snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n"); snd_ice1712_save_gpio_status(ice); tmp = ICE1712_EWS88_SERIAL_DATA | ICE1712_EWS88_SERIAL_CLOCK | ICE1712_EWS88_RW; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction | tmp); snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp); } /* stop callback for EWS88MT, needs to deselect chip mask */ static void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip) { struct snd_ice1712 *ice = ak->private_data[0]; snd_ice1712_restore_gpio_status(ice); udelay(1); snd_ice1712_ews88mt_chip_select(ice, 0x0f); } /* start callback for EWX24/96 */ static void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip) { struct snd_ice1712 *ice = ak->private_data[0]; unsigned char tmp; snd_ice1712_save_gpio_status(ice); tmp = ICE1712_EWX2496_SERIAL_DATA | ICE1712_EWX2496_SERIAL_CLOCK | ICE1712_EWX2496_AK4524_CS | ICE1712_EWX2496_RW; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction | tmp); snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp); } /* start callback for DMX 6fire */ static void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip) { struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; struct snd_ice1712 *ice = ak->private_data[0]; unsigned char tmp; snd_ice1712_save_gpio_status(ice); tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK; tmp |= ICE1712_6FIRE_SERIAL_DATA | ICE1712_6FIRE_SERIAL_CLOCK | ICE1712_6FIRE_RW; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction | tmp); snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp); } /* * CS8404 interface on EWS88MT/D */ static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits) { struct ews_spec *spec = ice->spec; unsigned char bytes[2]; snd_i2c_lock(ice->i2c); switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1) != 1) goto _error; break; case ICE1712_SUBDEVICE_EWS88D: if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2) != 2) goto _error; if (bits != bytes[1]) { bytes[1] = bits; if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2) != 2) goto _error; } break; } _error: snd_i2c_unlock(ice->i2c); } /* */ static void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) { snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits); } static int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) { unsigned int val; int change; val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958); spin_lock_irq(&ice->reg_lock); change = ice->spdif.cs8403_bits != val; ice->spdif.cs8403_bits = val; if (change && ice->playback_pro_substream == NULL) { spin_unlock_irq(&ice->reg_lock); snd_ice1712_ews_cs8404_spdif_write(ice, val); } else { spin_unlock_irq(&ice->reg_lock); } return change; } static void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) { snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits); } static int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol) { unsigned int val; int change; val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958); spin_lock_irq(&ice->reg_lock); change = ice->spdif.cs8403_stream_bits != val; ice->spdif.cs8403_stream_bits = val; if (change && ice->playback_pro_substream != NULL) { spin_unlock_irq(&ice->reg_lock); snd_ice1712_ews_cs8404_spdif_write(ice, val); } else { spin_unlock_irq(&ice->reg_lock); } return change; } /* open callback */ static void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream) { ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits; } /* set up SPDIF for EWS88MT / EWS88D */ static void ews88_setup_spdif(struct snd_ice1712 *ice, int rate) { unsigned long flags; unsigned char tmp; int change; spin_lock_irqsave(&ice->reg_lock, flags); tmp = ice->spdif.cs8403_stream_bits; if (tmp & 0x10) /* consumer */ tmp &= (tmp & 0x01) ? ~0x06 : ~0x60; switch (rate) { case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break; case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break; case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break; default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break; } change = ice->spdif.cs8403_stream_bits != tmp; ice->spdif.cs8403_stream_bits = tmp; spin_unlock_irqrestore(&ice->reg_lock, flags); if (change) snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id); snd_ice1712_ews_cs8404_spdif_write(ice, tmp); } /* */ static struct snd_akm4xxx akm_ews88mt __devinitdata = { .num_adcs = 8, .num_dacs = 8, .type = SND_AK4524, .ops = { .lock = ews88mt_ak4524_lock, .unlock = ews88mt_ak4524_unlock } }; static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = { .caddr = 2, .cif = 1, /* CIF high */ .data_mask = ICE1712_EWS88_SERIAL_DATA, .clk_mask = ICE1712_EWS88_SERIAL_CLOCK, .cs_mask = 0, .cs_addr = 0, .cs_none = 0, /* no chip select on gpio */ .add_flags = ICE1712_EWS88_RW, /* set rw bit high */ .mask_flags = 0, }; static struct snd_akm4xxx akm_ewx2496 __devinitdata = { .num_adcs = 2, .num_dacs = 2, .type = SND_AK4524, .ops = { .lock = ewx2496_ak4524_lock } }; static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = { .caddr = 2, .cif = 1, /* CIF high */ .data_mask = ICE1712_EWS88_SERIAL_DATA, .clk_mask = ICE1712_EWS88_SERIAL_CLOCK, .cs_mask = ICE1712_EWX2496_AK4524_CS, .cs_addr = ICE1712_EWX2496_AK4524_CS, .cs_none = 0, .add_flags = ICE1712_EWS88_RW, /* set rw bit high */ .mask_flags = 0, }; static struct snd_akm4xxx akm_6fire __devinitdata = { .num_adcs = 6, .num_dacs = 6, .type = SND_AK4524, .ops = { .lock = dmx6fire_ak4524_lock } }; static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = { .caddr = 2, .cif = 1, /* CIF high */ .data_mask = ICE1712_6FIRE_SERIAL_DATA, .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK, .cs_mask = 0, .cs_addr = 0, /* set later */ .cs_none = 0, .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */ .mask_flags = 0, }; /* * initialize the chip */ /* 6fire specific */ #define PCF9554_REG_INPUT 0 #define PCF9554_REG_OUTPUT 1 #define PCF9554_REG_POLARITY 2 #define PCF9554_REG_CONFIG 3 static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data); static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice) { int err; struct snd_akm4xxx *ak; struct ews_spec *spec; /* set the analog DACs */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWX2496: ice->num_total_dacs = 2; ice->num_total_adcs = 2; break; case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: ice->num_total_dacs = 8; ice->num_total_adcs = 8; break; case ICE1712_SUBDEVICE_EWS88D: /* Note: not analog but ADAT I/O */ ice->num_total_dacs = 8; ice->num_total_adcs = 8; break; case ICE1712_SUBDEVICE_DMX6FIRE: ice->num_total_dacs = 6; ice->num_total_adcs = 6; break; } spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; ice->spec = spec; /* create i2c */ if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { snd_printk(KERN_ERR "unable to create I2C bus\n"); return err; } ice->i2c->private_data = ice; ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops; /* create i2c devices */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_DMX6FIRE: err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &spec->i2cdevs[EWS_I2C_6FIRE]); if (err < 0) { snd_printk(KERN_ERR "PCF9554 initialization failed\n"); return err; } snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80); break; case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &spec->i2cdevs[EWS_I2C_CS8404]); if (err < 0) return err; err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &spec->i2cdevs[EWS_I2C_PCF1]); if (err < 0) return err; err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &spec->i2cdevs[EWS_I2C_PCF2]); if (err < 0) return err; /* Check if the front module is connected */ if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0) return err; break; case ICE1712_SUBDEVICE_EWS88D: err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &spec->i2cdevs[EWS_I2C_88D]); if (err < 0) return err; break; } /* set up SPDIF interface */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWX2496: if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0) return err; snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR); break; case ICE1712_SUBDEVICE_DMX6FIRE: if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0) return err; snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR); break; case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: case ICE1712_SUBDEVICE_EWS88D: /* set up CS8404 */ ice->spdif.ops.open = ews88_open_spdif; ice->spdif.ops.setup_rate = ews88_setup_spdif; ice->spdif.ops.default_get = ews88_spdif_default_get; ice->spdif.ops.default_put = ews88_spdif_default_put; ice->spdif.ops.stream_get = ews88_spdif_stream_get; ice->spdif.ops.stream_put = ews88_spdif_stream_put; /* Set spdif defaults */ snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits); break; } /* no analog? */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWS88D: return 0; } /* analog section */ ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); if (! ak) return -ENOMEM; ice->akm_codecs = 1; switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice); break; case ICE1712_SUBDEVICE_EWX2496: err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice); break; case ICE1712_SUBDEVICE_DMX6FIRE: err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice); break; default: err = 0; } return err; } /* * EWX 24/96 specific controls */ /* i/o sensitivity - this callback is shared among other devices, too */ static int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static char *texts[2] = { "+4dBu", "-10dBV", }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 2; if (uinfo->value.enumerated.item >= 2) uinfo->value.enumerated.item = 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned char mask = kcontrol->private_value & 0xff; snd_ice1712_save_gpio_status(ice); ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0; snd_ice1712_restore_gpio_status(ice); return 0; } static int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned char mask = kcontrol->private_value & 0xff; int val, nval; if (kcontrol->private_value & (1 << 31)) return -EPERM; nval = ucontrol->value.enumerated.item[0] ? mask : 0; snd_ice1712_save_gpio_status(ice); val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); nval |= val & ~mask; snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval); snd_ice1712_restore_gpio_status(ice); return val != nval; } static struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] __devinitdata = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input Sensitivity Switch", .info = snd_ice1712_ewx_io_sense_info, .get = snd_ice1712_ewx_io_sense_get, .put = snd_ice1712_ewx_io_sense_put, .private_value = ICE1712_EWX2496_AIN_SEL, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Output Sensitivity Switch", .info = snd_ice1712_ewx_io_sense_info, .get = snd_ice1712_ewx_io_sense_get, .put = snd_ice1712_ewx_io_sense_put, .private_value = ICE1712_EWX2496_AOUT_SEL, }, }; /* * EWS88MT specific controls */ /* analog output sensitivity;; address 0x48 bit 6 */ static int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; unsigned char data; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */ return 0; } /* analog output sensitivity;; address 0x48 bit 6 */ static int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; unsigned char data, ndata; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0); if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); return ndata != data; } /* analog input sensitivity; address 0x46 */ static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); unsigned char data; if (snd_BUG_ON(channel < 0 || channel > 7)) return 0; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } /* reversed; high = +4dBu, low = -10dBV */ ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1; snd_i2c_unlock(ice->i2c); return 0; } /* analog output sensitivity; address 0x46 */ static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); unsigned char data, ndata; if (snd_BUG_ON(channel < 0 || channel > 7)) return 0; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel)); if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1], &ndata, 1) != 1) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); return ndata != data; } static struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input Sensitivity Switch", .info = snd_ice1712_ewx_io_sense_info, .get = snd_ice1712_ews88mt_input_sense_get, .put = snd_ice1712_ews88mt_input_sense_put, .count = 8, }; static struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Output Sensitivity Switch", .info = snd_ice1712_ewx_io_sense_info, .get = snd_ice1712_ews88mt_output_sense_get, .put = snd_ice1712_ews88mt_output_sense_put, }; /* * EWS88D specific controls */ #define snd_ice1712_ews88d_control_info snd_ctl_boolean_mono_info static int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; int shift = kcontrol->private_value & 0xff; int invert = (kcontrol->private_value >> 8) & 1; unsigned char data[2]; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01; if (invert) data[0] ^= 0x01; ucontrol->value.integer.value[0] = data[0]; return 0; } static int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct ews_spec *spec = ice->spec; int shift = kcontrol->private_value & 0xff; int invert = (kcontrol->private_value >> 8) & 1; unsigned char data[2], ndata[2]; int change; snd_i2c_lock(ice->i2c); if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { snd_i2c_unlock(ice->i2c); return -EIO; } ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7)); if (invert) { if (! ucontrol->value.integer.value[0]) ndata[shift >> 3] |= (1 << (shift & 7)); } else { if (ucontrol->value.integer.value[0]) ndata[shift >> 3] |= (1 << (shift & 7)); } change = (data[shift >> 3] != ndata[shift >> 3]); if (change && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); return change; } #define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \ { .iface = xiface,\ .name = xname,\ .access = xaccess,\ .info = snd_ice1712_ews88d_control_info,\ .get = snd_ice1712_ews88d_control_get,\ .put = snd_ice1712_ews88d_control_put,\ .private_value = xshift | (xinvert << 8),\ } static struct snd_kcontrol_new snd_ice1712_ews88d_controls[] __devinitdata = { EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */ EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0), EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0), EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0), EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0), }; /* * DMX 6Fire specific controls */ static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg) { unsigned char byte; struct ews_spec *spec = ice->spec; snd_i2c_lock(ice->i2c); byte = reg; snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1); byte = 0; if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) { snd_i2c_unlock(ice->i2c); printk(KERN_ERR "cannot read pca\n"); return -EIO; } snd_i2c_unlock(ice->i2c); return byte; } static int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data) { unsigned char bytes[2]; struct ews_spec *spec = ice->spec; snd_i2c_lock(ice->i2c); bytes[0] = reg; bytes[1] = data; if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) { snd_i2c_unlock(ice->i2c); return -EIO; } snd_i2c_unlock(ice->i2c); return 0; } #define snd_ice1712_6fire_control_info snd_ctl_boolean_mono_info static int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int shift = kcontrol->private_value & 0xff; int invert = (kcontrol->private_value >> 8) & 1; int data; if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) return data; data = (data >> shift) & 1; if (invert) data ^= 1; ucontrol->value.integer.value[0] = data; return 0; } static int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int shift = kcontrol->private_value & 0xff; int invert = (kcontrol->private_value >> 8) & 1; int data, ndata; if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) return data; ndata = data & ~(1 << shift); if (ucontrol->value.integer.value[0]) ndata |= (1 << shift); if (invert) ndata ^= (1 << shift); if (data != ndata) { snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata); return 1; } return 0; } static int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static char *texts[4] = { "Internal", "Front Input", "Rear Input", "Wave Table" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 4; if (uinfo->value.enumerated.item >= 4) uinfo->value.enumerated.item = 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int data; if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) return data; ucontrol->value.integer.value[0] = data & 3; return 0; } static int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int data, ndata; if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0) return data; ndata = data & ~3; ndata |= (ucontrol->value.integer.value[0] & 3); if (data != ndata) { snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata); return 1; } return 0; } #define DMX6FIRE_CONTROL(xname, xshift, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\ .name = xname,\ .info = snd_ice1712_6fire_control_info,\ .get = snd_ice1712_6fire_control_get,\ .put = snd_ice1712_6fire_control_put,\ .private_value = xshift | (xinvert << 8),\ } static struct snd_kcontrol_new snd_ice1712_6fire_controls[] __devinitdata = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Analog Input Select", .info = snd_ice1712_6fire_select_input_info, .get = snd_ice1712_6fire_select_input_get, .put = snd_ice1712_6fire_select_input_put, }, DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1), // DMX6FIRE_CONTROL("Master Clock Select", 3, 0), DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0), DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0), DMX6FIRE_CONTROL("Breakbox LED", 6, 0), }; static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice) { unsigned int idx; int err; /* all terratec cards have spdif, but cs8427 module builds it's own controls */ if (ice->cs8427 == NULL) { err = snd_ice1712_spdif_build_controls(ice); if (err < 0) return err; } /* ak4524 controls */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWX2496: case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: case ICE1712_SUBDEVICE_DMX6FIRE: err = snd_ice1712_akm4xxx_build_controls(ice); if (err < 0) return err; break; } /* card specific controls */ switch (ice->eeprom.subvendor) { case ICE1712_SUBDEVICE_EWX2496: for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) { err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice)); if (err < 0) return err; } break; case ICE1712_SUBDEVICE_EWS88MT: case ICE1712_SUBDEVICE_EWS88MT_NEW: case ICE1712_SUBDEVICE_PHASE88: case ICE1712_SUBDEVICE_TS88: err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice)); if (err < 0) return err; err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice)); if (err < 0) return err; break; case ICE1712_SUBDEVICE_EWS88D: for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) { err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice)); if (err < 0) return err; } break; case ICE1712_SUBDEVICE_DMX6FIRE: for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) { err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice)); if (err < 0) return err; } break; } return 0; } /* entry point */ struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = { { .subvendor = ICE1712_SUBDEVICE_EWX2496, .name = "TerraTec EWX24/96", .model = "ewx2496", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_EWS88MT, .name = "TerraTec EWS88MT", .model = "ews88mt", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW, .name = "TerraTec EWS88MT", .model = "ews88mt_new", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_PHASE88, .name = "TerraTec Phase88", .model = "phase88", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_TS88, .name = "terrasoniq TS88", .model = "phase88", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_EWS88D, .name = "TerraTec EWS88D", .model = "ews88d", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, }, { .subvendor = ICE1712_SUBDEVICE_DMX6FIRE, .name = "TerraTec DMX6Fire", .model = "dmx6fire", .chip_init = snd_ice1712_ews_init, .build_controls = snd_ice1712_ews_add_controls, .mpu401_1_name = "MIDI-Front DMX6fire", .mpu401_2_name = "Wavetable DMX6fire", .mpu401_2_info_flags = MPU401_INFO_OUTPUT, }, { } /* terminator */ };
gpl-2.0
eugene373/Nexus_S_ICS
drivers/scsi/ses.c
10302
17917
/* * SCSI Enclosure Services * * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com> * **----------------------------------------------------------------------------- ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** version 2 as published by the Free Software Foundation. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ** **----------------------------------------------------------------------------- */ #include <linux/slab.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/enclosure.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_dbg.h> #include <scsi/scsi_device.h> #include <scsi/scsi_driver.h> #include <scsi/scsi_host.h> struct ses_device { unsigned char *page1; unsigned char *page1_types; unsigned char *page2; unsigned char *page10; short page1_len; short page1_num_types; short page2_len; short page10_len; }; struct ses_component { u64 addr; unsigned char *desc; }; static int ses_probe(struct device *dev) { struct scsi_device *sdev = to_scsi_device(dev); int err = -ENODEV; if (sdev->type != TYPE_ENCLOSURE) goto out; err = 0; sdev_printk(KERN_NOTICE, sdev, "Attached Enclosure device\n"); out: return err; } #define SES_TIMEOUT (30 * HZ) #define SES_RETRIES 3 static int ses_recv_diag(struct scsi_device *sdev, int page_code, void *buf, int bufflen) { unsigned char cmd[] = { RECEIVE_DIAGNOSTIC, 1, /* Set PCV bit */ page_code, bufflen >> 8, bufflen & 0xff, 0 }; return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen, NULL, SES_TIMEOUT, SES_RETRIES, NULL); } static int ses_send_diag(struct scsi_device *sdev, int page_code, void *buf, int bufflen) { u32 result; unsigned char cmd[] = { SEND_DIAGNOSTIC, 0x10, /* Set PF bit */ 0, bufflen >> 8, bufflen & 0xff, 0 }; result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, buf, bufflen, NULL, SES_TIMEOUT, SES_RETRIES, NULL); if (result) sdev_printk(KERN_ERR, sdev, "SEND DIAGNOSTIC result: %8x\n", result); return result; } static int ses_set_page2_descriptor(struct enclosure_device *edev, struct enclosure_component *ecomp, unsigned char *desc) { int i, j, count = 0, descriptor = ecomp->number; struct scsi_device *sdev = to_scsi_device(edev->edev.parent); struct ses_device *ses_dev = edev->scratch; unsigned char *type_ptr = ses_dev->page1_types; unsigned char *desc_ptr = ses_dev->page2 + 8; /* Clear everything */ memset(desc_ptr, 0, ses_dev->page2_len - 8); for (i = 0; i < ses_dev->page1_num_types; i++, type_ptr += 4) { for (j = 0; j < type_ptr[1]; j++) { desc_ptr += 4; if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE && type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE) continue; if (count++ == descriptor) { memcpy(desc_ptr, desc, 4); /* set select */ desc_ptr[0] |= 0x80; /* clear reserved, just in case */ desc_ptr[0] &= 0xf0; } } } return ses_send_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len); } static unsigned char *ses_get_page2_descriptor(struct enclosure_device *edev, struct enclosure_component *ecomp) { int i, j, count = 0, descriptor = ecomp->number; struct scsi_device *sdev = to_scsi_device(edev->edev.parent); struct ses_device *ses_dev = edev->scratch; unsigned char *type_ptr = ses_dev->page1_types; unsigned char *desc_ptr = ses_dev->page2 + 8; ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len); for (i = 0; i < ses_dev->page1_num_types; i++, type_ptr += 4) { for (j = 0; j < type_ptr[1]; j++) { desc_ptr += 4; if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE && type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE) continue; if (count++ == descriptor) return desc_ptr; } } return NULL; } /* For device slot and array device slot elements, byte 3 bit 6 * is "fault sensed" while byte 3 bit 5 is "fault reqstd". As this * code stands these bits are shifted 4 positions right so in * sysfs they will appear as bits 2 and 1 respectively. Strange. */ static void ses_get_fault(struct enclosure_device *edev, struct enclosure_component *ecomp) { unsigned char *desc; desc = ses_get_page2_descriptor(edev, ecomp); if (desc) ecomp->fault = (desc[3] & 0x60) >> 4; } static int ses_set_fault(struct enclosure_device *edev, struct enclosure_component *ecomp, enum enclosure_component_setting val) { unsigned char desc[4] = {0 }; switch (val) { case ENCLOSURE_SETTING_DISABLED: /* zero is disabled */ break; case ENCLOSURE_SETTING_ENABLED: desc[3] = 0x20; break; default: /* SES doesn't do the SGPIO blink settings */ return -EINVAL; } return ses_set_page2_descriptor(edev, ecomp, desc); } static void ses_get_status(struct enclosure_device *edev, struct enclosure_component *ecomp) { unsigned char *desc; desc = ses_get_page2_descriptor(edev, ecomp); if (desc) ecomp->status = (desc[0] & 0x0f); } static void ses_get_locate(struct enclosure_device *edev, struct enclosure_component *ecomp) { unsigned char *desc; desc = ses_get_page2_descriptor(edev, ecomp); if (desc) ecomp->locate = (desc[2] & 0x02) ? 1 : 0; } static int ses_set_locate(struct enclosure_device *edev, struct enclosure_component *ecomp, enum enclosure_component_setting val) { unsigned char desc[4] = {0 }; switch (val) { case ENCLOSURE_SETTING_DISABLED: /* zero is disabled */ break; case ENCLOSURE_SETTING_ENABLED: desc[2] = 0x02; break; default: /* SES doesn't do the SGPIO blink settings */ return -EINVAL; } return ses_set_page2_descriptor(edev, ecomp, desc); } static int ses_set_active(struct enclosure_device *edev, struct enclosure_component *ecomp, enum enclosure_component_setting val) { unsigned char desc[4] = {0 }; switch (val) { case ENCLOSURE_SETTING_DISABLED: /* zero is disabled */ ecomp->active = 0; break; case ENCLOSURE_SETTING_ENABLED: desc[2] = 0x80; ecomp->active = 1; break; default: /* SES doesn't do the SGPIO blink settings */ return -EINVAL; } return ses_set_page2_descriptor(edev, ecomp, desc); } static struct enclosure_component_callbacks ses_enclosure_callbacks = { .get_fault = ses_get_fault, .set_fault = ses_set_fault, .get_status = ses_get_status, .get_locate = ses_get_locate, .set_locate = ses_set_locate, .set_active = ses_set_active, }; struct ses_host_edev { struct Scsi_Host *shost; struct enclosure_device *edev; }; #if 0 int ses_match_host(struct enclosure_device *edev, void *data) { struct ses_host_edev *sed = data; struct scsi_device *sdev; if (!scsi_is_sdev_device(edev->edev.parent)) return 0; sdev = to_scsi_device(edev->edev.parent); if (sdev->host != sed->shost) return 0; sed->edev = edev; return 1; } #endif /* 0 */ static void ses_process_descriptor(struct enclosure_component *ecomp, unsigned char *desc) { int eip = desc[0] & 0x10; int invalid = desc[0] & 0x80; enum scsi_protocol proto = desc[0] & 0x0f; u64 addr = 0; struct ses_component *scomp = ecomp->scratch; unsigned char *d; scomp->desc = desc; if (invalid) return; switch (proto) { case SCSI_PROTOCOL_SAS: if (eip) d = desc + 8; else d = desc + 4; /* only take the phy0 addr */ addr = (u64)d[12] << 56 | (u64)d[13] << 48 | (u64)d[14] << 40 | (u64)d[15] << 32 | (u64)d[16] << 24 | (u64)d[17] << 16 | (u64)d[18] << 8 | (u64)d[19]; break; default: /* FIXME: Need to add more protocols than just SAS */ break; } scomp->addr = addr; } struct efd { u64 addr; struct device *dev; }; static int ses_enclosure_find_by_addr(struct enclosure_device *edev, void *data) { struct efd *efd = data; int i; struct ses_component *scomp; if (!edev->component[0].scratch) return 0; for (i = 0; i < edev->components; i++) { scomp = edev->component[i].scratch; if (scomp->addr != efd->addr) continue; enclosure_add_device(edev, i, efd->dev); return 1; } return 0; } #define INIT_ALLOC_SIZE 32 static void ses_enclosure_data_process(struct enclosure_device *edev, struct scsi_device *sdev, int create) { u32 result; unsigned char *buf = NULL, *type_ptr, *desc_ptr, *addl_desc_ptr = NULL; int i, j, page7_len, len, components; struct ses_device *ses_dev = edev->scratch; int types = ses_dev->page1_num_types; unsigned char *hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL); if (!hdr_buf) goto simple_populate; /* re-read page 10 */ if (ses_dev->page10) ses_recv_diag(sdev, 10, ses_dev->page10, ses_dev->page10_len); /* Page 7 for the descriptors is optional */ result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE); if (result) goto simple_populate; page7_len = len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; /* add 1 for trailing '\0' we'll use */ buf = kzalloc(len + 1, GFP_KERNEL); if (!buf) goto simple_populate; result = ses_recv_diag(sdev, 7, buf, len); if (result) { simple_populate: kfree(buf); buf = NULL; desc_ptr = NULL; len = 0; page7_len = 0; } else { desc_ptr = buf + 8; len = (desc_ptr[2] << 8) + desc_ptr[3]; /* skip past overall descriptor */ desc_ptr += len + 4; } if (ses_dev->page10) addl_desc_ptr = ses_dev->page10 + 8; type_ptr = ses_dev->page1_types; components = 0; for (i = 0; i < types; i++, type_ptr += 4) { for (j = 0; j < type_ptr[1]; j++) { char *name = NULL; struct enclosure_component *ecomp; if (desc_ptr) { if (desc_ptr >= buf + page7_len) { desc_ptr = NULL; } else { len = (desc_ptr[2] << 8) + desc_ptr[3]; desc_ptr += 4; /* Add trailing zero - pushes into * reserved space */ desc_ptr[len] = '\0'; name = desc_ptr; } } if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE || type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) { if (create) ecomp = enclosure_component_register(edev, components++, type_ptr[0], name); else ecomp = &edev->component[components++]; if (!IS_ERR(ecomp) && addl_desc_ptr) ses_process_descriptor(ecomp, addl_desc_ptr); } if (desc_ptr) desc_ptr += len; if (addl_desc_ptr) addl_desc_ptr += addl_desc_ptr[1] + 2; } } kfree(buf); kfree(hdr_buf); } static void ses_match_to_enclosure(struct enclosure_device *edev, struct scsi_device *sdev) { unsigned char *buf; unsigned char *desc; unsigned int vpd_len; struct efd efd = { .addr = 0, }; buf = kmalloc(INIT_ALLOC_SIZE, GFP_KERNEL); if (!buf || scsi_get_vpd_page(sdev, 0x83, buf, INIT_ALLOC_SIZE)) goto free; ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0); vpd_len = ((buf[2] << 8) | buf[3]) + 4; kfree(buf); buf = kmalloc(vpd_len, GFP_KERNEL); if (!buf ||scsi_get_vpd_page(sdev, 0x83, buf, vpd_len)) goto free; desc = buf + 4; while (desc < buf + vpd_len) { enum scsi_protocol proto = desc[0] >> 4; u8 code_set = desc[0] & 0x0f; u8 piv = desc[1] & 0x80; u8 assoc = (desc[1] & 0x30) >> 4; u8 type = desc[1] & 0x0f; u8 len = desc[3]; if (piv && code_set == 1 && assoc == 1 && proto == SCSI_PROTOCOL_SAS && type == 3 && len == 8) efd.addr = (u64)desc[4] << 56 | (u64)desc[5] << 48 | (u64)desc[6] << 40 | (u64)desc[7] << 32 | (u64)desc[8] << 24 | (u64)desc[9] << 16 | (u64)desc[10] << 8 | (u64)desc[11]; desc += len + 4; } if (!efd.addr) goto free; efd.dev = &sdev->sdev_gendev; enclosure_for_each_device(ses_enclosure_find_by_addr, &efd); free: kfree(buf); } static int ses_intf_add(struct device *cdev, struct class_interface *intf) { struct scsi_device *sdev = to_scsi_device(cdev->parent); struct scsi_device *tmp_sdev; unsigned char *buf = NULL, *hdr_buf, *type_ptr; struct ses_device *ses_dev; u32 result; int i, types, len, components = 0; int err = -ENOMEM; int num_enclosures; struct enclosure_device *edev; struct ses_component *scomp = NULL; if (!scsi_device_enclosure(sdev)) { /* not an enclosure, but might be in one */ struct enclosure_device *prev = NULL; while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) { ses_match_to_enclosure(edev, sdev); prev = edev; } return -ENODEV; } /* TYPE_ENCLOSURE prints a message in probe */ if (sdev->type != TYPE_ENCLOSURE) sdev_printk(KERN_NOTICE, sdev, "Embedded Enclosure Device\n"); ses_dev = kzalloc(sizeof(*ses_dev), GFP_KERNEL); hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL); if (!hdr_buf || !ses_dev) goto err_init_free; result = ses_recv_diag(sdev, 1, hdr_buf, INIT_ALLOC_SIZE); if (result) goto recv_failed; len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; buf = kzalloc(len, GFP_KERNEL); if (!buf) goto err_free; result = ses_recv_diag(sdev, 1, buf, len); if (result) goto recv_failed; types = 0; /* we always have one main enclosure and the rest are referred * to as secondary subenclosures */ num_enclosures = buf[1] + 1; /* begin at the enclosure descriptor */ type_ptr = buf + 8; /* skip all the enclosure descriptors */ for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) { types += type_ptr[2]; type_ptr += type_ptr[3] + 4; } ses_dev->page1_types = type_ptr; ses_dev->page1_num_types = types; for (i = 0; i < types && type_ptr < buf + len; i++, type_ptr += 4) { if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE || type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) components += type_ptr[1]; } ses_dev->page1 = buf; ses_dev->page1_len = len; buf = NULL; result = ses_recv_diag(sdev, 2, hdr_buf, INIT_ALLOC_SIZE); if (result) goto recv_failed; len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; buf = kzalloc(len, GFP_KERNEL); if (!buf) goto err_free; /* make sure getting page 2 actually works */ result = ses_recv_diag(sdev, 2, buf, len); if (result) goto recv_failed; ses_dev->page2 = buf; ses_dev->page2_len = len; buf = NULL; /* The additional information page --- allows us * to match up the devices */ result = ses_recv_diag(sdev, 10, hdr_buf, INIT_ALLOC_SIZE); if (!result) { len = (hdr_buf[2] << 8) + hdr_buf[3] + 4; buf = kzalloc(len, GFP_KERNEL); if (!buf) goto err_free; result = ses_recv_diag(sdev, 10, buf, len); if (result) goto recv_failed; ses_dev->page10 = buf; ses_dev->page10_len = len; buf = NULL; } scomp = kzalloc(sizeof(struct ses_component) * components, GFP_KERNEL); if (!scomp) goto err_free; edev = enclosure_register(cdev->parent, dev_name(&sdev->sdev_gendev), components, &ses_enclosure_callbacks); if (IS_ERR(edev)) { err = PTR_ERR(edev); goto err_free; } kfree(hdr_buf); edev->scratch = ses_dev; for (i = 0; i < components; i++) edev->component[i].scratch = scomp + i; ses_enclosure_data_process(edev, sdev, 1); /* see if there are any devices matching before * we found the enclosure */ shost_for_each_device(tmp_sdev, sdev->host) { if (tmp_sdev->lun != 0 || scsi_device_enclosure(tmp_sdev)) continue; ses_match_to_enclosure(edev, tmp_sdev); } return 0; recv_failed: sdev_printk(KERN_ERR, sdev, "Failed to get diagnostic page 0x%x\n", result); err = -ENODEV; err_free: kfree(buf); kfree(scomp); kfree(ses_dev->page10); kfree(ses_dev->page2); kfree(ses_dev->page1); err_init_free: kfree(ses_dev); kfree(hdr_buf); sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n", err); return err; } static int ses_remove(struct device *dev) { return 0; } static void ses_intf_remove_component(struct scsi_device *sdev) { struct enclosure_device *edev, *prev = NULL; while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) { prev = edev; if (!enclosure_remove_device(edev, &sdev->sdev_gendev)) break; } if (edev) put_device(&edev->edev); } static void ses_intf_remove_enclosure(struct scsi_device *sdev) { struct enclosure_device *edev; struct ses_device *ses_dev; /* exact match to this enclosure */ edev = enclosure_find(&sdev->sdev_gendev, NULL); if (!edev) return; ses_dev = edev->scratch; edev->scratch = NULL; kfree(ses_dev->page10); kfree(ses_dev->page1); kfree(ses_dev->page2); kfree(ses_dev); kfree(edev->component[0].scratch); put_device(&edev->edev); enclosure_unregister(edev); } static void ses_intf_remove(struct device *cdev, struct class_interface *intf) { struct scsi_device *sdev = to_scsi_device(cdev->parent); if (!scsi_device_enclosure(sdev)) ses_intf_remove_component(sdev); else ses_intf_remove_enclosure(sdev); } static struct class_interface ses_interface = { .add_dev = ses_intf_add, .remove_dev = ses_intf_remove, }; static struct scsi_driver ses_template = { .owner = THIS_MODULE, .gendrv = { .name = "ses", .probe = ses_probe, .remove = ses_remove, }, }; static int __init ses_init(void) { int err; err = scsi_register_interface(&ses_interface); if (err) return err; err = scsi_register_driver(&ses_template.gendrv); if (err) goto out_unreg; return 0; out_unreg: scsi_unregister_interface(&ses_interface); return err; } static void __exit ses_exit(void) { scsi_unregister_driver(&ses_template.gendrv); scsi_unregister_interface(&ses_interface); } module_init(ses_init); module_exit(ses_exit); MODULE_ALIAS_SCSI_DEVICE(TYPE_ENCLOSURE); MODULE_AUTHOR("James Bottomley"); MODULE_DESCRIPTION("SCSI Enclosure Services (ses) driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
gomi1992/tiny210v2-uboot
board/palmtc/palmtc.c
63
1724
/* * Palm Tungsten|C Support * * Copyright (C) 2009-2010 Marek Vasut <marek.vasut@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include <common.h> #include <command.h> #include <serial.h> #include <asm/io.h> #include <asm/arch/pxa.h> #include <asm/arch/regs-mmc.h> DECLARE_GLOBAL_DATA_PTR; /* * Miscelaneous platform dependent initialisations */ int board_init(void) { /* We have RAM, disable cache */ dcache_disable(); icache_disable(); /* Arch number of Palm Tungsten|C */ gd->bd->bi_arch_number = MACH_TYPE_PALMTC; /* Adress of boot parameters */ gd->bd->bi_boot_params = 0xa0000100; /* Set PWM for LCD */ writel(0x5f, PWM_CTRL1); writel(0x3ff, PWM_PERVAL1); writel(892, PWM_PWDUTY1); return 0; } #ifdef CONFIG_CMD_MMC int board_mmc_init(bd_t *bis) { pxa_mmc_register(0); return 0; } #endif int dram_init(void) { pxa2xx_dram_init(); gd->ram_size = PHYS_SDRAM_1_SIZE; return 0; } void dram_init_banksize(void) { gd->bd->bi_dram[0].start = PHYS_SDRAM_1; gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; }
gpl-2.0
percy-g2/Novathor_xperia_u8500
6.2.A.1.100/external/netlink/src/nl-addr-delete.c
63
4025
/* * src/nl-addr-delete.c Delete addresses * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation version 2 of the License. * * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ #include <netlink/cli/utils.h> #include <netlink/cli/addr.h> #include <netlink/cli/link.h> static struct nl_sock *sock; static int interactive = 0, default_yes = 0, quiet = 0; static int deleted = 0; static void print_usage(void) { printf( "Usage: nl-addr-delete [OPTION]... [ADDRESS]\n" "\n" "Options\n" " -i, --interactive Run interactively.\n" " --yes Set default answer to yes.\n" " -q, --quiet Do not print informal notifications.\n" " -h, --help Show this help.\n" " -v, --version Show versioning information.\n" "\n" "Address Options\n" " -a, --local=ADDR Local address.\n" " -d, --dev=DEV Associated network device.\n" " --family=FAMILY Family of local address.\n" " --label=STRING Address label (IPv4).\n" " --peer=ADDR Peer address (IPv4).\n" " --scope=SCOPE Address scope (IPv4).\n" " --broadcast=ADDR Broadcast address of network (IPv4).\n" " --valid-lifetime=TS Valid lifetime before route expires (IPv6).\n" " --preferred=TIME Preferred lifetime (IPv6).\n" " --valid=TIME Valid lifetime (IPv6).\n" ); exit(0); } static void delete_cb(struct nl_object *obj, void *arg) { struct rtnl_addr *addr = nl_object_priv(obj); struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; int err; if (interactive && !nl_cli_confirm(obj, &params, default_yes)) return; if ((err = rtnl_addr_delete(sock, addr, 0)) < 0) nl_cli_fatal(err, "Unable to delete address: %s\n", nl_geterror(err)); if (!quiet) { printf("Deleted "); nl_object_dump(obj, &params); } deleted++; } int main(int argc, char *argv[]) { struct rtnl_addr *addr; struct nl_cache *link_cache, *addr_cache; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); addr_cache = nl_cli_addr_alloc_cache(sock); addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_LABEL = 258, ARG_YES, ARG_PEER, ARG_SCOPE, ARG_BROADCAST, ARG_PREFERRED, ARG_VALID, }; static struct option long_opts[] = { { "interactive", 0, 0, 'i' }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "local", 1, 0, 'a' }, { "dev", 1, 0, 'd' }, { "family", 1, 0, ARG_FAMILY }, { "label", 1, 0, ARG_LABEL }, { "peer", 1, 0, ARG_PEER }, { "scope", 1, 0, ARG_SCOPE }, { "broadcast", 1, 0, ARG_BROADCAST }, { "preferred", 1, 0, ARG_PREFERRED }, { "valid", 1, 0, ARG_VALID }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "iqhva:d:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'i': interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), delete_cb, NULL); if (!quiet) printf("Deleted %d addresses\n", deleted); return 0; }
gpl-2.0
gpkulkarni/linux-arm64
drivers/scsi/mpt3sas/mpt3sas_config.c
319
55064
/* * This module provides common API for accessing firmware configuration pages * * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c * Copyright (C) 2012-2014 LSI Corporation * Copyright (C) 2013-2014 Avago Technologies * (mailto: MPT-FusionLinux.pdl@avagotech.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * NO WARRANTY * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is * solely responsible for determining the appropriateness of using and * distributing the Program and assumes all risks associated with its * exercise of rights under this Agreement, including but not limited to * the risks and costs of program errors, damage to or loss of data, * programs or equipment, and unavailability or interruption of operations. * DISCLAIMER OF LIABILITY * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/blkdev.h> #include <linux/sched.h> #include <linux/workqueue.h> #include <linux/delay.h> #include <linux/pci.h> #include "mpt3sas_base.h" /* local definitions */ /* Timeout for config page request (in seconds) */ #define MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT 15 /* Common sgl flags for READING a config page. */ #define MPT3_CONFIG_COMMON_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \ MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \ | MPI2_SGE_FLAGS_END_OF_LIST) << MPI2_SGE_FLAGS_SHIFT) /* Common sgl flags for WRITING a config page. */ #define MPT3_CONFIG_COMMON_WRITE_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \ MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \ | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC) \ << MPI2_SGE_FLAGS_SHIFT) /** * struct config_request - obtain dma memory via routine * @sz: size * @page: virt pointer * @page_dma: phys pointer * */ struct config_request { u16 sz; void *page; dma_addr_t page_dma; }; /** * _config_display_some_debug - debug routine * @ioc: per adapter object * @smid: system request message index * @calling_function_name: string pass from calling function * @mpi_reply: reply message frame * Context: none. * * Function for displaying debug info helpful when debugging issues * in this module. */ static void _config_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid, char *calling_function_name, MPI2DefaultReply_t *mpi_reply) { Mpi2ConfigRequest_t *mpi_request; char *desc = NULL; if (!(ioc->logging_level & MPT_DEBUG_CONFIG)) return; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); switch (mpi_request->Header.PageType & MPI2_CONFIG_PAGETYPE_MASK) { case MPI2_CONFIG_PAGETYPE_IO_UNIT: desc = "io_unit"; break; case MPI2_CONFIG_PAGETYPE_IOC: desc = "ioc"; break; case MPI2_CONFIG_PAGETYPE_BIOS: desc = "bios"; break; case MPI2_CONFIG_PAGETYPE_RAID_VOLUME: desc = "raid_volume"; break; case MPI2_CONFIG_PAGETYPE_MANUFACTURING: desc = "manufaucturing"; break; case MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK: desc = "physdisk"; break; case MPI2_CONFIG_PAGETYPE_EXTENDED: switch (mpi_request->ExtPageType) { case MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT: desc = "sas_io_unit"; break; case MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER: desc = "sas_expander"; break; case MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE: desc = "sas_device"; break; case MPI2_CONFIG_EXTPAGETYPE_SAS_PHY: desc = "sas_phy"; break; case MPI2_CONFIG_EXTPAGETYPE_LOG: desc = "log"; break; case MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE: desc = "enclosure"; break; case MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG: desc = "raid_config"; break; case MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING: desc = "driver_mapping"; break; } break; } if (!desc) return; pr_info(MPT3SAS_FMT "%s: %s(%d), action(%d), form(0x%08x), smid(%d)\n", ioc->name, calling_function_name, desc, mpi_request->Header.PageNumber, mpi_request->Action, le32_to_cpu(mpi_request->PageAddress), smid); if (!mpi_reply) return; if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo) pr_info(MPT3SAS_FMT "\tiocstatus(0x%04x), loginfo(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->IOCStatus), le32_to_cpu(mpi_reply->IOCLogInfo)); } /** * _config_alloc_config_dma_memory - obtain physical memory * @ioc: per adapter object * @mem: struct config_request * * A wrapper for obtaining dma-able memory for config page request. * * Returns 0 for success, non-zero for failure. */ static int _config_alloc_config_dma_memory(struct MPT3SAS_ADAPTER *ioc, struct config_request *mem) { int r = 0; if (mem->sz > ioc->config_page_sz) { mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz, &mem->page_dma, GFP_KERNEL); if (!mem->page) { pr_err(MPT3SAS_FMT "%s: dma_alloc_coherent failed asking for (%d) bytes!!\n", ioc->name, __func__, mem->sz); r = -ENOMEM; } } else { /* use tmp buffer if less than 512 bytes */ mem->page = ioc->config_page; mem->page_dma = ioc->config_page_dma; } return r; } /** * _config_free_config_dma_memory - wrapper to free the memory * @ioc: per adapter object * @mem: struct config_request * * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory. * * Returns 0 for success, non-zero for failure. */ static void _config_free_config_dma_memory(struct MPT3SAS_ADAPTER *ioc, struct config_request *mem) { if (mem->sz > ioc->config_page_sz) dma_free_coherent(&ioc->pdev->dev, mem->sz, mem->page, mem->page_dma); } /** * mpt3sas_config_done - config page completion routine * @ioc: per adapter object * @smid: system request message index * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * Context: none. * * The callback handler when using _config_request. * * Return 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function. */ u8 mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) { MPI2DefaultReply_t *mpi_reply; if (ioc->config_cmds.status == MPT3_CMD_NOT_USED) return 1; if (ioc->config_cmds.smid != smid) return 1; ioc->config_cmds.status |= MPT3_CMD_COMPLETE; mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (mpi_reply) { ioc->config_cmds.status |= MPT3_CMD_REPLY_VALID; memcpy(ioc->config_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); } ioc->config_cmds.status &= ~MPT3_CMD_PENDING; _config_display_some_debug(ioc, smid, "config_done", mpi_reply); ioc->config_cmds.smid = USHRT_MAX; complete(&ioc->config_cmds.done); return 1; } /** * _config_request - main routine for sending config page requests * @ioc: per adapter object * @mpi_request: request message frame * @mpi_reply: reply mf payload returned from firmware * @timeout: timeout in seconds * @config_page: contents of the config page * @config_page_sz: size of config page * Context: sleep * * A generic API for config page requests to firmware. * * The ioc->config_cmds.status flag should be MPT3_CMD_NOT_USED before calling * this API. * * The callback index is set inside `ioc->config_cb_idx. * * Returns 0 for success, non-zero for failure. */ static int _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout, void *config_page, u16 config_page_sz) { u16 smid; u32 ioc_state; unsigned long timeleft; Mpi2ConfigRequest_t *config_request; int r; u8 retry_count, issue_host_reset = 0; u16 wait_state_count; struct config_request mem; u32 ioc_status = UINT_MAX; mutex_lock(&ioc->config_cmds.mutex); if (ioc->config_cmds.status != MPT3_CMD_NOT_USED) { pr_err(MPT3SAS_FMT "%s: config_cmd in use\n", ioc->name, __func__); mutex_unlock(&ioc->config_cmds.mutex); return -EAGAIN; } retry_count = 0; memset(&mem, 0, sizeof(struct config_request)); mpi_request->VF_ID = 0; /* TODO */ mpi_request->VP_ID = 0; if (config_page) { mpi_request->Header.PageVersion = mpi_reply->Header.PageVersion; mpi_request->Header.PageNumber = mpi_reply->Header.PageNumber; mpi_request->Header.PageType = mpi_reply->Header.PageType; mpi_request->Header.PageLength = mpi_reply->Header.PageLength; mpi_request->ExtPageLength = mpi_reply->ExtPageLength; mpi_request->ExtPageType = mpi_reply->ExtPageType; if (mpi_request->Header.PageLength) mem.sz = mpi_request->Header.PageLength * 4; else mem.sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4; r = _config_alloc_config_dma_memory(ioc, &mem); if (r != 0) goto out; if (mpi_request->Action == MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT || mpi_request->Action == MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM) { ioc->base_add_sg_single(&mpi_request->PageBufferSGE, MPT3_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz, mem.page_dma); memcpy(mem.page, config_page, min_t(u16, mem.sz, config_page_sz)); } else { memset(config_page, 0, config_page_sz); ioc->base_add_sg_single(&mpi_request->PageBufferSGE, MPT3_CONFIG_COMMON_SGLFLAGS | mem.sz, mem.page_dma); memset(mem.page, 0, min_t(u16, mem.sz, config_page_sz)); } } retry_config: if (retry_count) { if (retry_count > 2) { /* attempt only 2 retries */ r = -EFAULT; goto free_mem; } pr_info(MPT3SAS_FMT "%s: attempting retry (%d)\n", ioc->name, __func__, retry_count); } wait_state_count = 0; ioc_state = mpt3sas_base_get_iocstate(ioc, 1); while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { if (wait_state_count++ == MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT) { pr_err(MPT3SAS_FMT "%s: failed due to ioc not operational\n", ioc->name, __func__); ioc->config_cmds.status = MPT3_CMD_NOT_USED; r = -EFAULT; goto free_mem; } ssleep(1); ioc_state = mpt3sas_base_get_iocstate(ioc, 1); pr_info(MPT3SAS_FMT "%s: waiting for operational state(count=%d)\n", ioc->name, __func__, wait_state_count); } if (wait_state_count) pr_info(MPT3SAS_FMT "%s: ioc is operational\n", ioc->name, __func__); smid = mpt3sas_base_get_smid(ioc, ioc->config_cb_idx); if (!smid) { pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", ioc->name, __func__); ioc->config_cmds.status = MPT3_CMD_NOT_USED; r = -EAGAIN; goto free_mem; } r = 0; memset(mpi_reply, 0, sizeof(Mpi2ConfigReply_t)); ioc->config_cmds.status = MPT3_CMD_PENDING; config_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->config_cmds.smid = smid; memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t)); _config_display_some_debug(ioc, smid, "config_request", NULL); init_completion(&ioc->config_cmds.done); mpt3sas_base_put_smid_default(ioc, smid); timeleft = wait_for_completion_timeout(&ioc->config_cmds.done, timeout*HZ); if (!(ioc->config_cmds.status & MPT3_CMD_COMPLETE)) { pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name, __func__); _debug_dump_mf(mpi_request, sizeof(Mpi2ConfigRequest_t)/4); retry_count++; if (ioc->config_cmds.smid == smid) mpt3sas_base_free_smid(ioc, smid); if ((ioc->shost_recovery) || (ioc->config_cmds.status & MPT3_CMD_RESET) || ioc->pci_error_recovery) goto retry_config; issue_host_reset = 1; r = -EFAULT; goto free_mem; } if (ioc->config_cmds.status & MPT3_CMD_REPLY_VALID) { memcpy(mpi_reply, ioc->config_cmds.reply, sizeof(Mpi2ConfigReply_t)); /* Reply Frame Sanity Checks to workaround FW issues */ if ((mpi_request->Header.PageType & 0xF) != (mpi_reply->Header.PageType & 0xF)) { _debug_dump_mf(mpi_request, ioc->request_sz/4); _debug_dump_reply(mpi_reply, ioc->request_sz/4); panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \ " mpi_reply mismatch: Requested PageType(0x%02x)" \ " Reply PageType(0x%02x)\n", \ ioc->name, __func__, (mpi_request->Header.PageType & 0xF), (mpi_reply->Header.PageType & 0xF)); } if (((mpi_request->Header.PageType & 0xF) == MPI2_CONFIG_PAGETYPE_EXTENDED) && mpi_request->ExtPageType != mpi_reply->ExtPageType) { _debug_dump_mf(mpi_request, ioc->request_sz/4); _debug_dump_reply(mpi_reply, ioc->request_sz/4); panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \ " mpi_reply mismatch: Requested ExtPageType(0x%02x)" " Reply ExtPageType(0x%02x)\n", ioc->name, __func__, mpi_request->ExtPageType, mpi_reply->ExtPageType); } ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; } if (retry_count) pr_info(MPT3SAS_FMT "%s: retry (%d) completed!!\n", \ ioc->name, __func__, retry_count); if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) && config_page && mpi_request->Action == MPI2_CONFIG_ACTION_PAGE_READ_CURRENT) { u8 *p = (u8 *)mem.page; /* Config Page Sanity Checks to workaround FW issues */ if (p) { if ((mpi_request->Header.PageType & 0xF) != (p[3] & 0xF)) { _debug_dump_mf(mpi_request, ioc->request_sz/4); _debug_dump_reply(mpi_reply, ioc->request_sz/4); _debug_dump_config(p, min_t(u16, mem.sz, config_page_sz)/4); panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \ " config page mismatch:" " Requested PageType(0x%02x)" " Reply PageType(0x%02x)\n", ioc->name, __func__, (mpi_request->Header.PageType & 0xF), (p[3] & 0xF)); } if (((mpi_request->Header.PageType & 0xF) == MPI2_CONFIG_PAGETYPE_EXTENDED) && (mpi_request->ExtPageType != p[6])) { _debug_dump_mf(mpi_request, ioc->request_sz/4); _debug_dump_reply(mpi_reply, ioc->request_sz/4); _debug_dump_config(p, min_t(u16, mem.sz, config_page_sz)/4); panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \ " config page mismatch:" " Requested ExtPageType(0x%02x)" " Reply ExtPageType(0x%02x)\n", ioc->name, __func__, mpi_request->ExtPageType, p[6]); } } memcpy(config_page, mem.page, min_t(u16, mem.sz, config_page_sz)); } free_mem: if (config_page) _config_free_config_dma_memory(ioc, &mem); out: ioc->config_cmds.status = MPT3_CMD_NOT_USED; mutex_unlock(&ioc->config_cmds.mutex); if (issue_host_reset) mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER); return r; } /** * mpt3sas_config_get_manufacturing_pg0 - obtain manufacturing page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_manufacturing_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_manufacturing_pg7 - obtain manufacturing page 7 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @sz: size of buffer passed in config_page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_manufacturing_pg7(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage7_t *config_page, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; mpi_request.Header.PageNumber = 7; mpi_request.Header.PageVersion = MPI2_MANUFACTURING7_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_get_manufacturing_pg10 - obtain manufacturing page 10 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_manufacturing_pg10(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, struct Mpi2ManufacturingPage10_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; mpi_request.Header.PageNumber = 10; mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_manufacturing_pg11 - obtain manufacturing page 11 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, struct Mpi2ManufacturingPage11_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; mpi_request.Header.PageNumber = 11; mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_set_manufacturing_pg11 - set manufacturing page 11 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_set_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, struct Mpi2ManufacturingPage11_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; mpi_request.Header.PageNumber = 11; mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_bios_pg2 - obtain bios page 2 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_bios_pg2(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2BiosPage2_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS; mpi_request.Header.PageNumber = 2; mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_bios_pg3 - obtain bios page 3 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_bios_pg3(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2BiosPage3_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS; mpi_request.Header.PageNumber = 3; mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_iounit_pg0 - obtain iounit page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_iounit_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage0_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_iounit_pg1 - obtain iounit page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_set_iounit_pg1 - set iounit page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_set_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_iounit_pg3 - obtain iounit page 3 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @sz: size of buffer passed in config_page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; mpi_request.Header.PageNumber = 3; mpi_request.Header.PageVersion = MPI2_IOUNITPAGE3_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_get_iounit_pg8 - obtain iounit page 8 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_iounit_pg8(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage8_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; mpi_request.Header.PageNumber = 8; mpi_request.Header.PageVersion = MPI2_IOUNITPAGE8_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_ioc_pg8 - obtain ioc page 8 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_ioc_pg8(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage8_t *config_page) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC; mpi_request.Header.PageNumber = 8; mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_sas_device_pg0 - obtain sas device page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: device handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_sas_device_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE; mpi_request.Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION; mpi_request.Header.PageNumber = 0; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_sas_device_pg1 - obtain sas device page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: device handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_sas_device_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE; mpi_request.Header.PageVersion = MPI2_SASDEVICE1_PAGEVERSION; mpi_request.Header.PageNumber = 1; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_number_hba_phys - obtain number of phys on the host * @ioc: per adapter object * @num_phys: pointer returned with the number of phys * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_number_hba_phys(struct MPT3SAS_ADAPTER *ioc, u8 *num_phys) { Mpi2ConfigRequest_t mpi_request; int r; u16 ioc_status; Mpi2ConfigReply_t mpi_reply; Mpi2SasIOUnitPage0_t config_page; *num_phys = 0; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page, sizeof(Mpi2SasIOUnitPage0_t)); if (!r) { ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status == MPI2_IOCSTATUS_SUCCESS) *num_phys = config_page.NumPhys; } out: return r; } /** * mpt3sas_config_get_sas_iounit_pg0 - obtain sas iounit page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @sz: size of buffer passed in config_page * Context: sleep. * * Calling function should call config_get_number_hba_phys prior to * this function, so enough memory is allocated for config_page. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_sas_iounit_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_get_sas_iounit_pg1 - obtain sas iounit page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @sz: size of buffer passed in config_page * Context: sleep. * * Calling function should call config_get_number_hba_phys prior to * this function, so enough memory is allocated for config_page. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_set_sas_iounit_pg1 - send sas iounit page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @sz: size of buffer passed in config_page * Context: sleep. * * Calling function should call config_get_number_hba_phys prior to * this function, so enough memory is allocated for config_page. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_set_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_get_expander_pg0 - obtain expander page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: expander handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_expander_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_expander_pg1 - obtain expander page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @phy_number: phy number * @handle: expander handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_expander_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM | (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_enclosure_pg0 - obtain enclosure page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: expander handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_enclosure_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_phy_pg0 - obtain phy page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @phy_number: phy number * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_phy_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_phy_pg1 - obtain phy page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @phy_number: phy number * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_phy_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_raid_volume_pg1 - obtain raid volume page 1 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: volume handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_raid_volume_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; mpi_request.Header.PageNumber = 1; mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_number_pds - obtain number of phys disk assigned to volume * @ioc: per adapter object * @handle: volume handle * @num_pds: returns pds count * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_number_pds(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 *num_pds) { Mpi2ConfigRequest_t mpi_request; Mpi2RaidVolPage0_t config_page; Mpi2ConfigReply_t mpi_reply; int r; u16 ioc_status; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); *num_pds = 0; mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page, sizeof(Mpi2RaidVolPage0_t)); if (!r) { ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status == MPI2_IOCSTATUS_SUCCESS) *num_pds = config_page.NumPhysDisks; } out: return r; } /** * mpt3sas_config_get_raid_volume_pg0 - obtain raid volume page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_HANDLE or HANDLE * @handle: volume handle * @sz: size of buffer passed in config_page * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_raid_volume_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | handle); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); out: return r; } /** * mpt3sas_config_get_phys_disk_pg0 - obtain phys disk page 0 * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @config_page: contents of the config page * @form: GET_NEXT_PHYSDISKNUM, PHYSDISKNUM, DEVHANDLE * @form_specific: specific to the form * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_phys_disk_pg0(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form, u32 form_specific) { Mpi2ConfigRequest_t mpi_request; int r; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK; mpi_request.Header.PageNumber = 0; mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.PageAddress = cpu_to_le32(form | form_specific); mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); out: return r; } /** * mpt3sas_config_get_volume_handle - returns volume handle for give hidden * raid components * @ioc: per adapter object * @pd_handle: phys disk handle * @volume_handle: volume handle * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_volume_handle(struct MPT3SAS_ADAPTER *ioc, u16 pd_handle, u16 *volume_handle) { Mpi2RaidConfigurationPage0_t *config_page = NULL; Mpi2ConfigRequest_t mpi_request; Mpi2ConfigReply_t mpi_reply; int r, i, config_page_sz; u16 ioc_status; int config_num; u16 element_type; u16 phys_disk_dev_handle; *volume_handle = 0; memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); mpi_request.Function = MPI2_FUNCTION_CONFIG; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG; mpi_request.Header.PageVersion = MPI2_RAIDCONFIG0_PAGEVERSION; mpi_request.Header.PageNumber = 0; ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE); r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); if (r) goto out; mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4); config_page = kmalloc(config_page_sz, GFP_KERNEL); if (!config_page) { r = -1; goto out; } config_num = 0xff; while (1) { mpi_request.PageAddress = cpu_to_le32(config_num + MPI2_RAID_PGAD_FORM_GET_NEXT_CONFIGNUM); r = _config_request(ioc, &mpi_request, &mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, config_page_sz); if (r) goto out; r = -1; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) goto out; for (i = 0; i < config_page->NumElements; i++) { element_type = le16_to_cpu(config_page-> ConfigElement[i].ElementFlags) & MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE; if (element_type == MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT || element_type == MPI2_RAIDCONFIG0_EFLAGS_OCE_ELEMENT) { phys_disk_dev_handle = le16_to_cpu(config_page->ConfigElement[i]. PhysDiskDevHandle); if (phys_disk_dev_handle == pd_handle) { *volume_handle = le16_to_cpu(config_page-> ConfigElement[i].VolDevHandle); r = 0; goto out; } } else if (element_type == MPI2_RAIDCONFIG0_EFLAGS_HOT_SPARE_ELEMENT) { *volume_handle = 0; r = 0; goto out; } } config_num = config_page->ConfigNum; } out: kfree(config_page); return r; } /** * mpt3sas_config_get_volume_wwid - returns wwid given the volume handle * @ioc: per adapter object * @volume_handle: volume handle * @wwid: volume wwid * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpt3sas_config_get_volume_wwid(struct MPT3SAS_ADAPTER *ioc, u16 volume_handle, u64 *wwid) { Mpi2ConfigReply_t mpi_reply; Mpi2RaidVolPage1_t raid_vol_pg1; *wwid = 0; if (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, &raid_vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, volume_handle))) { *wwid = le64_to_cpu(raid_vol_pg1.WWID); return 0; } else return -1; }
gpl-2.0
getitnowmarketing/LG-2.6.32
drivers/mtd/onenand/generic.c
575
3756
/* * linux/drivers/mtd/onenand/generic.c * * Copyright (c) 2005 Samsung Electronics * Kyungmin Park <kyungmin.park@samsung.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Overview: * This is a device driver for the OneNAND flash for generic boards. */ #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/platform_device.h> #include <linux/mtd/mtd.h> #include <linux/mtd/onenand.h> #include <linux/mtd/partitions.h> #include <asm/io.h> /* * Note: Driver name and platform data format have been updated! * * This version of the driver is named "onenand-flash" and takes struct * onenand_platform_data as platform data. The old ARM-specific version * with the name "onenand" used to take struct flash_platform_data. */ #define DRIVER_NAME "onenand-flash" #ifdef CONFIG_MTD_PARTITIONS static const char *part_probes[] = { "cmdlinepart", NULL, }; #endif struct onenand_info { struct mtd_info mtd; struct mtd_partition *parts; struct onenand_chip onenand; }; static int __devinit generic_onenand_probe(struct platform_device *pdev) { struct onenand_info *info; struct onenand_platform_data *pdata = pdev->dev.platform_data; struct resource *res = pdev->resource; unsigned long size = resource_size(res); int err; info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL); if (!info) return -ENOMEM; if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) { err = -EBUSY; goto out_free_info; } info->onenand.base = ioremap(res->start, size); if (!info->onenand.base) { err = -ENOMEM; goto out_release_mem_region; } info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0; info->onenand.irq = platform_get_irq(pdev, 0); info->mtd.name = dev_name(&pdev->dev); info->mtd.priv = &info->onenand; info->mtd.owner = THIS_MODULE; if (onenand_scan(&info->mtd, 1)) { err = -ENXIO; goto out_iounmap; } #ifdef CONFIG_MTD_PARTITIONS err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); if (err > 0) add_mtd_partitions(&info->mtd, info->parts, err); else if (err <= 0 && pdata && pdata->parts) add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts); else #endif err = add_mtd_device(&info->mtd); platform_set_drvdata(pdev, info); return 0; out_iounmap: iounmap(info->onenand.base); out_release_mem_region: release_mem_region(res->start, size); out_free_info: kfree(info); return err; } static int __devexit generic_onenand_remove(struct platform_device *pdev) { struct onenand_info *info = platform_get_drvdata(pdev); struct resource *res = pdev->resource; unsigned long size = resource_size(res); platform_set_drvdata(pdev, NULL); if (info) { if (info->parts) del_mtd_partitions(&info->mtd); else del_mtd_device(&info->mtd); onenand_release(&info->mtd); release_mem_region(res->start, size); iounmap(info->onenand.base); kfree(info); } return 0; } static struct platform_driver generic_onenand_driver = { .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, }, .probe = generic_onenand_probe, .remove = __devexit_p(generic_onenand_remove), }; MODULE_ALIAS("platform:" DRIVER_NAME); static int __init generic_onenand_init(void) { return platform_driver_register(&generic_onenand_driver); } static void __exit generic_onenand_exit(void) { platform_driver_unregister(&generic_onenand_driver); } module_init(generic_onenand_init); module_exit(generic_onenand_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>"); MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
gpl-2.0
eckucukoglu/sober-kernel
fs/coda/cache.c
575
3028
/* * Cache operations for Coda. * For Linux 2.1: (C) 1997 Carnegie Mellon University * For Linux 2.3: (C) 2000 Carnegie Mellon University * * Carnegie Mellon encourages users of this code to contribute improvements * to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>. */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/time.h> #include <linux/fs.h> #include <linux/stat.h> #include <linux/errno.h> #include <asm/uaccess.h> #include <linux/string.h> #include <linux/list.h> #include <linux/sched.h> #include <linux/spinlock.h> #include <linux/coda.h> #include <linux/coda_psdev.h> #include "coda_linux.h" #include "coda_cache.h" static atomic_t permission_epoch = ATOMIC_INIT(0); /* replace or extend an acl cache hit */ void coda_cache_enter(struct inode *inode, int mask) { struct coda_inode_info *cii = ITOC(inode); spin_lock(&cii->c_lock); cii->c_cached_epoch = atomic_read(&permission_epoch); if (!uid_eq(cii->c_uid, current_fsuid())) { cii->c_uid = current_fsuid(); cii->c_cached_perm = mask; } else cii->c_cached_perm |= mask; spin_unlock(&cii->c_lock); } /* remove cached acl from an inode */ void coda_cache_clear_inode(struct inode *inode) { struct coda_inode_info *cii = ITOC(inode); spin_lock(&cii->c_lock); cii->c_cached_epoch = atomic_read(&permission_epoch) - 1; spin_unlock(&cii->c_lock); } /* remove all acl caches */ void coda_cache_clear_all(struct super_block *sb) { atomic_inc(&permission_epoch); } /* check if the mask has been matched against the acl already */ int coda_cache_check(struct inode *inode, int mask) { struct coda_inode_info *cii = ITOC(inode); int hit; spin_lock(&cii->c_lock); hit = (mask & cii->c_cached_perm) == mask && uid_eq(cii->c_uid, current_fsuid()) && cii->c_cached_epoch == atomic_read(&permission_epoch); spin_unlock(&cii->c_lock); return hit; } /* Purging dentries and children */ /* The following routines drop dentries which are not in use and flag dentries which are in use to be zapped later. The flags are detected by: - coda_dentry_revalidate (for lookups) if the flag is C_PURGE - coda_dentry_delete: to remove dentry from the cache when d_count falls to zero - an inode method coda_revalidate (for attributes) if the flag is C_VATTR */ /* this won't do any harm: just flag all children */ static void coda_flag_children(struct dentry *parent, int flag) { struct dentry *de; spin_lock(&parent->d_lock); list_for_each_entry(de, &parent->d_subdirs, d_child) { /* don't know what to do with negative dentries */ if (de->d_inode ) coda_flag_inode(de->d_inode, flag); } spin_unlock(&parent->d_lock); return; } void coda_flag_inode_children(struct inode *inode, int flag) { struct dentry *alias_de; if ( !inode || !S_ISDIR(inode->i_mode)) return; alias_de = d_find_alias(inode); if (!alias_de) return; coda_flag_children(alias_de, flag); shrink_dcache_parent(alias_de); dput(alias_de); }
gpl-2.0
kaldaris/WIDzard-A850K
arch/arm/mach-msm/qdsp5/adsp_debug.c
831
2600
/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/errno.h> #include <linux/fs.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/sched.h> #include <linux/spinlock.h> #include <linux/string.h> #include <linux/types.h> #include <linux/uaccess.h> #include <linux/wait.h> #include <mach/debug_mm.h> #include <mach/msm_smd.h> #include "adsp.h" #define MAX_LEN 64 #ifdef CONFIG_DEBUG_FS static struct dentry *adsp_dentry; #endif static char l_buf[MAX_LEN]; static unsigned int crash_enable; static ssize_t q5_debug_open(struct inode *inode, struct file *file) { file->private_data = inode->i_private; MM_DBG("q5 debugfs opened\n"); return 0; } static ssize_t q5_debug_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { int len; if (count < 0) return 0; len = count > (MAX_LEN - 1) ? (MAX_LEN - 1) : count; if (copy_from_user(l_buf, buf, len)) { MM_INFO("Unable to copy data from user space\n"); return -EFAULT; } l_buf[len] = 0; if (l_buf[len - 1] == '\n') { l_buf[len - 1] = 0; len--; } if (!strncmp(l_buf, "boom", MAX_LEN)) { q5audio_dsp_not_responding(); } else if (!strncmp(l_buf, "enable", MAX_LEN)) { crash_enable = 1; MM_INFO("Crash enabled : %d\n", crash_enable); } else if (!strncmp(l_buf, "disable", MAX_LEN)) { crash_enable = 0; MM_INFO("Crash disabled : %d\n", crash_enable); } else MM_INFO("Unknown Command\n"); return count; } static const struct file_operations q5_debug_fops = { .write = q5_debug_write, .open = q5_debug_open, }; static int __init q5_debug_init(void) { #ifdef CONFIG_DEBUG_FS adsp_dentry = debugfs_create_file("q5_debug", S_IFREG | S_IRUGO, NULL, (void *) NULL, &q5_debug_fops); #endif /* CONFIG_DEBUG_FS */ return 0; } device_initcall(q5_debug_init);
gpl-2.0
HB72K/android_kernel_lgk10_mt6582
drivers/net/wireless/ath/ath9k/ar5008_phy.c
2111
39059
/* * Copyright (c) 2008-2011 Atheros Communications Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "hw.h" #include "hw-ops.h" #include "../regd.h" #include "ar9002_phy.h" #include "ar5008_initvals.h" /* All code below is for AR5008, AR9001, AR9002 */ static const int firstep_table[] = /* level: 0 1 2 3 4 5 6 7 8 */ { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */ static const int cycpwrThr1_table[] = /* level: 0 1 2 3 4 5 6 7 8 */ { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */ /* * register values to turn OFDM weak signal detection OFF */ static const int m1ThreshLow_off = 127; static const int m2ThreshLow_off = 127; static const int m1Thresh_off = 127; static const int m2Thresh_off = 127; static const int m2CountThr_off = 31; static const int m2CountThrLow_off = 63; static const int m1ThreshLowExt_off = 127; static const int m2ThreshLowExt_off = 127; static const int m1ThreshExt_off = 127; static const int m2ThreshExt_off = 127; static const struct ar5416IniArray bank0 = STATIC_INI_ARRAY(ar5416Bank0); static const struct ar5416IniArray bank1 = STATIC_INI_ARRAY(ar5416Bank1); static const struct ar5416IniArray bank2 = STATIC_INI_ARRAY(ar5416Bank2); static const struct ar5416IniArray bank3 = STATIC_INI_ARRAY(ar5416Bank3); static const struct ar5416IniArray bank7 = STATIC_INI_ARRAY(ar5416Bank7); static void ar5008_write_bank6(struct ath_hw *ah, unsigned int *writecnt) { struct ar5416IniArray *array = &ah->iniBank6; u32 *data = ah->analogBank6Data; int r; ENABLE_REGWRITE_BUFFER(ah); for (r = 0; r < array->ia_rows; r++) { REG_WRITE(ah, INI_RA(array, r, 0), data[r]); DO_DELAY(*writecnt); } REGWRITE_BUFFER_FLUSH(ah); } /** * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters * @rfbuf: * @reg32: * @numBits: * @firstBit: * @column: * * Performs analog "swizzling" of parameters into their location. * Used on external AR2133/AR5133 radios. */ static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32, u32 numBits, u32 firstBit, u32 column) { u32 tmp32, mask, arrayEntry, lastBit; int32_t bitPosition, bitsLeft; tmp32 = ath9k_hw_reverse_bits(reg32, numBits); arrayEntry = (firstBit - 1) / 8; bitPosition = (firstBit - 1) % 8; bitsLeft = numBits; while (bitsLeft > 0) { lastBit = (bitPosition + bitsLeft > 8) ? 8 : bitPosition + bitsLeft; mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) << (column * 8); rfBuf[arrayEntry] &= ~mask; rfBuf[arrayEntry] |= ((tmp32 << bitPosition) << (column * 8)) & mask; bitsLeft -= 8 - bitPosition; tmp32 = tmp32 >> (8 - bitPosition); bitPosition = 0; arrayEntry++; } } /* * Fix on 2.4 GHz band for orientation sensitivity issue by increasing * rf_pwd_icsyndiv. * * Theoretical Rules: * if 2 GHz band * if forceBiasAuto * if synth_freq < 2412 * bias = 0 * else if 2412 <= synth_freq <= 2422 * bias = 1 * else // synth_freq > 2422 * bias = 2 * else if forceBias > 0 * bias = forceBias & 7 * else * no change, use value from ini file * else * no change, invalid band * * 1st Mod: * 2422 also uses value of 2 * <approved> * * 2nd Mod: * Less than 2412 uses value of 0, 2412 and above uses value of 2 */ static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq) { struct ath_common *common = ath9k_hw_common(ah); u32 tmp_reg; int reg_writes = 0; u32 new_bias = 0; if (!AR_SREV_5416(ah) || synth_freq >= 3000) return; BUG_ON(AR_SREV_9280_20_OR_LATER(ah)); if (synth_freq < 2412) new_bias = 0; else if (synth_freq < 2422) new_bias = 1; else new_bias = 2; /* pre-reverse this field */ tmp_reg = ath9k_hw_reverse_bits(new_bias, 3); ath_dbg(common, CONFIG, "Force rf_pwd_icsyndiv to %1d on %4d\n", new_bias, synth_freq); /* swizzle rf_pwd_icsyndiv */ ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3); /* write Bank 6 with new params */ ar5008_write_bank6(ah, &reg_writes); } /** * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios * @ah: atheros hardware structure * @chan: * * For the external AR2133/AR5133 radios, takes the MHz channel value and set * the channel value. Assumes writes enabled to analog bus and bank6 register * cache in ah->analogBank6Data. */ static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan) { struct ath_common *common = ath9k_hw_common(ah); u32 channelSel = 0; u32 bModeSynth = 0; u32 aModeRefSel = 0; u32 reg32 = 0; u16 freq; struct chan_centers centers; ath9k_hw_get_channel_centers(ah, chan, &centers); freq = centers.synth_center; if (freq < 4800) { u32 txctl; if (((freq - 2192) % 5) == 0) { channelSel = ((freq - 672) * 2 - 3040) / 10; bModeSynth = 0; } else if (((freq - 2224) % 5) == 0) { channelSel = ((freq - 704) * 2 - 3040) / 10; bModeSynth = 1; } else { ath_err(common, "Invalid channel %u MHz\n", freq); return -EINVAL; } channelSel = (channelSel << 2) & 0xff; channelSel = ath9k_hw_reverse_bits(channelSel, 8); txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL); if (freq == 2484) { REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, txctl | AR_PHY_CCK_TX_CTRL_JAPAN); } else { REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN); } } else if ((freq % 20) == 0 && freq >= 5120) { channelSel = ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8); aModeRefSel = ath9k_hw_reverse_bits(1, 2); } else if ((freq % 10) == 0) { channelSel = ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8); if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) aModeRefSel = ath9k_hw_reverse_bits(2, 2); else aModeRefSel = ath9k_hw_reverse_bits(1, 2); } else if ((freq % 5) == 0) { channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8); aModeRefSel = ath9k_hw_reverse_bits(1, 2); } else { ath_err(common, "Invalid channel %u MHz\n", freq); return -EINVAL; } ar5008_hw_force_bias(ah, freq); reg32 = (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) | (1 << 5) | 0x1; REG_WRITE(ah, AR_PHY(0x37), reg32); ah->curchan = chan; return 0; } /** * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios * @ah: atheros hardware structure * @chan: * * For non single-chip solutions. Converts to baseband spur frequency given the * input channel frequency and compute register settings below. */ static void ar5008_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan) { int bb_spur = AR_NO_SPUR; int bin, cur_bin; int spur_freq_sd; int spur_delta_phase; int denominator; int upper, lower, cur_vit_mask; int tmp, new; int i; static int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8, AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 }; static int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10, AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 }; static int inc[4] = { 0, 100, 0, 0 }; int8_t mask_m[123]; int8_t mask_p[123]; int8_t mask_amt; int tmp_mask; int cur_bb_spur; bool is2GHz = IS_CHAN_2GHZ(chan); memset(&mask_m, 0, sizeof(int8_t) * 123); memset(&mask_p, 0, sizeof(int8_t) * 123); for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); if (AR_NO_SPUR == cur_bb_spur) break; cur_bb_spur = cur_bb_spur - (chan->channel * 10); if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) { bb_spur = cur_bb_spur; break; } } if (AR_NO_SPUR == bb_spur) return; bin = bb_spur * 32; tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new); new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | AR_PHY_SPUR_REG_ENABLE_MASK_PPM | AR_PHY_SPUR_REG_MASK_RATE_SELECT | AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); REG_WRITE(ah, AR_PHY_SPUR_REG, new); spur_delta_phase = ((bb_spur * 524288) / 100) & AR_PHY_TIMING11_SPUR_DELTA_PHASE; denominator = IS_CHAN_2GHZ(chan) ? 440 : 400; spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff; new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); REG_WRITE(ah, AR_PHY_TIMING11, new); cur_bin = -6000; upper = bin + 100; lower = bin - 100; for (i = 0; i < 4; i++) { int pilot_mask = 0; int chan_mask = 0; int bp = 0; for (bp = 0; bp < 30; bp++) { if ((cur_bin > lower) && (cur_bin < upper)) { pilot_mask = pilot_mask | 0x1 << bp; chan_mask = chan_mask | 0x1 << bp; } cur_bin += 100; } cur_bin += inc[i]; REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); REG_WRITE(ah, chan_mask_reg[i], chan_mask); } cur_vit_mask = 6100; upper = bin + 120; lower = bin - 120; for (i = 0; i < 123; i++) { if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { /* workaround for gcc bug #37014 */ volatile int tmp_v = abs(cur_vit_mask - bin); if (tmp_v < 75) mask_amt = 1; else mask_amt = 0; if (cur_vit_mask < 0) mask_m[abs(cur_vit_mask / 100)] = mask_amt; else mask_p[cur_vit_mask / 100] = mask_amt; } cur_vit_mask -= 100; } tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) | (mask_m[48] << 26) | (mask_m[49] << 24) | (mask_m[50] << 22) | (mask_m[51] << 20) | (mask_m[52] << 18) | (mask_m[53] << 16) | (mask_m[54] << 14) | (mask_m[55] << 12) | (mask_m[56] << 10) | (mask_m[57] << 8) | (mask_m[58] << 6) | (mask_m[59] << 4) | (mask_m[60] << 2) | (mask_m[61] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); tmp_mask = (mask_m[31] << 28) | (mask_m[32] << 26) | (mask_m[33] << 24) | (mask_m[34] << 22) | (mask_m[35] << 20) | (mask_m[36] << 18) | (mask_m[37] << 16) | (mask_m[48] << 14) | (mask_m[39] << 12) | (mask_m[40] << 10) | (mask_m[41] << 8) | (mask_m[42] << 6) | (mask_m[43] << 4) | (mask_m[44] << 2) | (mask_m[45] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) | (mask_m[18] << 26) | (mask_m[18] << 24) | (mask_m[20] << 22) | (mask_m[20] << 20) | (mask_m[22] << 18) | (mask_m[22] << 16) | (mask_m[24] << 14) | (mask_m[24] << 12) | (mask_m[25] << 10) | (mask_m[26] << 8) | (mask_m[27] << 6) | (mask_m[28] << 4) | (mask_m[29] << 2) | (mask_m[30] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) | (mask_m[2] << 26) | (mask_m[3] << 24) | (mask_m[4] << 22) | (mask_m[5] << 20) | (mask_m[6] << 18) | (mask_m[7] << 16) | (mask_m[8] << 14) | (mask_m[9] << 12) | (mask_m[10] << 10) | (mask_m[11] << 8) | (mask_m[12] << 6) | (mask_m[13] << 4) | (mask_m[14] << 2) | (mask_m[15] << 0); REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); tmp_mask = (mask_p[15] << 28) | (mask_p[14] << 26) | (mask_p[13] << 24) | (mask_p[12] << 22) | (mask_p[11] << 20) | (mask_p[10] << 18) | (mask_p[9] << 16) | (mask_p[8] << 14) | (mask_p[7] << 12) | (mask_p[6] << 10) | (mask_p[5] << 8) | (mask_p[4] << 6) | (mask_p[3] << 4) | (mask_p[2] << 2) | (mask_p[1] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); tmp_mask = (mask_p[30] << 28) | (mask_p[29] << 26) | (mask_p[28] << 24) | (mask_p[27] << 22) | (mask_p[26] << 20) | (mask_p[25] << 18) | (mask_p[24] << 16) | (mask_p[23] << 14) | (mask_p[22] << 12) | (mask_p[21] << 10) | (mask_p[20] << 8) | (mask_p[19] << 6) | (mask_p[18] << 4) | (mask_p[17] << 2) | (mask_p[16] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); tmp_mask = (mask_p[45] << 28) | (mask_p[44] << 26) | (mask_p[43] << 24) | (mask_p[42] << 22) | (mask_p[41] << 20) | (mask_p[40] << 18) | (mask_p[39] << 16) | (mask_p[38] << 14) | (mask_p[37] << 12) | (mask_p[36] << 10) | (mask_p[35] << 8) | (mask_p[34] << 6) | (mask_p[33] << 4) | (mask_p[32] << 2) | (mask_p[31] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) | (mask_p[59] << 26) | (mask_p[58] << 24) | (mask_p[57] << 22) | (mask_p[56] << 20) | (mask_p[55] << 18) | (mask_p[54] << 16) | (mask_p[53] << 14) | (mask_p[52] << 12) | (mask_p[51] << 10) | (mask_p[50] << 8) | (mask_p[49] << 6) | (mask_p[48] << 4) | (mask_p[47] << 2) | (mask_p[46] << 0); REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); } /** * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming * @ah: atheros hardware structure * * Only required for older devices with external AR2133/AR5133 radios. */ static int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah) { int size = ah->iniBank6.ia_rows * sizeof(u32); if (AR_SREV_9280_20_OR_LATER(ah)) return 0; ah->analogBank6Data = devm_kzalloc(ah->dev, size, GFP_KERNEL); if (!ah->analogBank6Data) return -ENOMEM; return 0; } /* * * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM * @ah: atheros hardware structure * @chan: * @modesIndex: * * Used for the external AR2133/AR5133 radios. * * Reads the EEPROM header info from the device structure and programs * all rf registers. This routine requires access to the analog * rf device. This is not required for single-chip devices. */ static bool ar5008_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan, u16 modesIndex) { u32 eepMinorRev; u32 ob5GHz = 0, db5GHz = 0; u32 ob2GHz = 0, db2GHz = 0; int regWrites = 0; int i; /* * Software does not need to program bank data * for single chip devices, that is AR9280 or anything * after that. */ if (AR_SREV_9280_20_OR_LATER(ah)) return true; /* Setup rf parameters */ eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV); for (i = 0; i < ah->iniBank6.ia_rows; i++) ah->analogBank6Data[i] = INI_RA(&ah->iniBank6, i, modesIndex); /* Only the 5 or 2 GHz OB/DB need to be set for a mode */ if (eepMinorRev >= 2) { if (IS_CHAN_2GHZ(chan)) { ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2); db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2); ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, ob2GHz, 3, 197, 0); ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, db2GHz, 3, 194, 0); } else { ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5); db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5); ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, ob5GHz, 3, 203, 0); ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, db5GHz, 3, 200, 0); } } /* Write Analog registers */ REG_WRITE_ARRAY(&bank0, 1, regWrites); REG_WRITE_ARRAY(&bank1, 1, regWrites); REG_WRITE_ARRAY(&bank2, 1, regWrites); REG_WRITE_ARRAY(&bank3, modesIndex, regWrites); ar5008_write_bank6(ah, &regWrites); REG_WRITE_ARRAY(&bank7, 1, regWrites); return true; } static void ar5008_hw_init_bb(struct ath_hw *ah, struct ath9k_channel *chan) { u32 synthDelay; synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); ath9k_hw_synth_delay(ah, chan, synthDelay); } static void ar5008_hw_init_chain_masks(struct ath_hw *ah) { int rx_chainmask, tx_chainmask; rx_chainmask = ah->rxchainmask; tx_chainmask = ah->txchainmask; switch (rx_chainmask) { case 0x5: REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, AR_PHY_SWAP_ALT_CHAIN); case 0x3: if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) { REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7); REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7); break; } case 0x1: case 0x2: case 0x7: ENABLE_REGWRITE_BUFFER(ah); REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); break; default: ENABLE_REGWRITE_BUFFER(ah); break; } REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask); REGWRITE_BUFFER_FLUSH(ah); if (tx_chainmask == 0x5) { REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, AR_PHY_SWAP_ALT_CHAIN); } if (AR_SREV_9100(ah)) REG_WRITE(ah, AR_PHY_ANALOG_SWAP, REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001); } static void ar5008_hw_override_ini(struct ath_hw *ah, struct ath9k_channel *chan) { u32 val; /* * Set the RX_ABORT and RX_DIS and clear if off only after * RXE is set for MAC. This prevents frames with corrupted * descriptor status. */ REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); if (AR_SREV_9280_20_OR_LATER(ah)) { val = REG_READ(ah, AR_PCU_MISC_MODE2); if (!AR_SREV_9271(ah)) val &= ~AR_PCU_MISC_MODE2_HWWAR1; if (AR_SREV_9287_11_OR_LATER(ah)) val = val & (~AR_PCU_MISC_MODE2_HWWAR2); REG_WRITE(ah, AR_PCU_MISC_MODE2, val); } REG_SET_BIT(ah, AR_PHY_CCK_DETECT, AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV); if (AR_SREV_9280_20_OR_LATER(ah)) return; /* * Disable BB clock gating * Necessary to avoid issues on AR5416 2.0 */ REG_WRITE(ah, 0x9800 + (651 << 2), 0x11); /* * Disable RIFS search on some chips to avoid baseband * hang issues. */ if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) { val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS); val &= ~AR_PHY_RIFS_INIT_DELAY; REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val); } } static void ar5008_hw_set_channel_regs(struct ath_hw *ah, struct ath9k_channel *chan) { u32 phymode; u32 enableDacFifo = 0; if (AR_SREV_9285_12_OR_LATER(ah)) enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) & AR_PHY_FC_ENABLE_DAC_FIFO); phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo; if (IS_CHAN_HT40(chan)) { phymode |= AR_PHY_FC_DYN2040_EN; if ((chan->chanmode == CHANNEL_A_HT40PLUS) || (chan->chanmode == CHANNEL_G_HT40PLUS)) phymode |= AR_PHY_FC_DYN2040_PRI_CH; } REG_WRITE(ah, AR_PHY_TURBO, phymode); ath9k_hw_set11nmac2040(ah); ENABLE_REGWRITE_BUFFER(ah); REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S); REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S); REGWRITE_BUFFER_FLUSH(ah); } static int ar5008_hw_process_ini(struct ath_hw *ah, struct ath9k_channel *chan) { struct ath_common *common = ath9k_hw_common(ah); int i, regWrites = 0; u32 modesIndex, freqIndex; switch (chan->chanmode) { case CHANNEL_A: case CHANNEL_A_HT20: modesIndex = 1; freqIndex = 1; break; case CHANNEL_A_HT40PLUS: case CHANNEL_A_HT40MINUS: modesIndex = 2; freqIndex = 1; break; case CHANNEL_G: case CHANNEL_G_HT20: case CHANNEL_B: modesIndex = 4; freqIndex = 2; break; case CHANNEL_G_HT40PLUS: case CHANNEL_G_HT40MINUS: modesIndex = 3; freqIndex = 2; break; default: return -EINVAL; } /* * Set correct baseband to analog shift setting to * access analog chips. */ REG_WRITE(ah, AR_PHY(0), 0x00000007); /* Write ADDAC shifts */ REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO); if (ah->eep_ops->set_addac) ah->eep_ops->set_addac(ah, chan); REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites); REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC); ENABLE_REGWRITE_BUFFER(ah); for (i = 0; i < ah->iniModes.ia_rows; i++) { u32 reg = INI_RA(&ah->iniModes, i, 0); u32 val = INI_RA(&ah->iniModes, i, modesIndex); if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup) val &= ~AR_AN_TOP2_PWDCLKIND; REG_WRITE(ah, reg, val); if (reg >= 0x7800 && reg < 0x78a0 && ah->config.analog_shiftreg && (common->bus_ops->ath_bus_type != ATH_USB)) { udelay(100); } DO_DELAY(regWrites); } REGWRITE_BUFFER_FLUSH(ah); if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah)) REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites); if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) || AR_SREV_9287_11_OR_LATER(ah)) REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); if (AR_SREV_9271_10(ah)) { REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA); REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa); } ENABLE_REGWRITE_BUFFER(ah); /* Write common array parameters */ for (i = 0; i < ah->iniCommon.ia_rows; i++) { u32 reg = INI_RA(&ah->iniCommon, i, 0); u32 val = INI_RA(&ah->iniCommon, i, 1); REG_WRITE(ah, reg, val); if (reg >= 0x7800 && reg < 0x78a0 && ah->config.analog_shiftreg && (common->bus_ops->ath_bus_type != ATH_USB)) { udelay(100); } DO_DELAY(regWrites); } REGWRITE_BUFFER_FLUSH(ah); REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites); if (IS_CHAN_A_FAST_CLOCK(ah, chan)) REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites); ar5008_hw_override_ini(ah, chan); ar5008_hw_set_channel_regs(ah, chan); ar5008_hw_init_chain_masks(ah); ath9k_olc_init(ah); ath9k_hw_apply_txpower(ah, chan, false); /* Write analog registers */ if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n"); return -EIO; } return 0; } static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan) { u32 rfMode = 0; if (chan == NULL) return; rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan)) ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM; if (!AR_SREV_9280_20_OR_LATER(ah)) rfMode |= (IS_CHAN_5GHZ(chan)) ? AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ; if (IS_CHAN_A_FAST_CLOCK(ah, chan)) rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE); REG_WRITE(ah, AR_PHY_MODE, rfMode); } static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah) { REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS); } static void ar5008_hw_set_delta_slope(struct ath_hw *ah, struct ath9k_channel *chan) { u32 coef_scaled, ds_coef_exp, ds_coef_man; u32 clockMhzScaled = 0x64000000; struct chan_centers centers; if (IS_CHAN_HALF_RATE(chan)) clockMhzScaled = clockMhzScaled >> 1; else if (IS_CHAN_QUARTER_RATE(chan)) clockMhzScaled = clockMhzScaled >> 2; ath9k_hw_get_channel_centers(ah, chan, &centers); coef_scaled = clockMhzScaled / centers.synth_center; ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, &ds_coef_exp); REG_RMW_FIELD(ah, AR_PHY_TIMING3, AR_PHY_TIMING3_DSC_MAN, ds_coef_man); REG_RMW_FIELD(ah, AR_PHY_TIMING3, AR_PHY_TIMING3_DSC_EXP, ds_coef_exp); coef_scaled = (9 * coef_scaled) / 10; ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, &ds_coef_exp); REG_RMW_FIELD(ah, AR_PHY_HALFGI, AR_PHY_HALFGI_DSC_MAN, ds_coef_man); REG_RMW_FIELD(ah, AR_PHY_HALFGI, AR_PHY_HALFGI_DSC_EXP, ds_coef_exp); } static bool ar5008_hw_rfbus_req(struct ath_hw *ah) { REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT); } static void ar5008_hw_rfbus_done(struct ath_hw *ah) { u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; ath9k_hw_synth_delay(ah, ah->curchan, synthDelay); REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0); } static void ar5008_restore_chainmask(struct ath_hw *ah) { int rx_chainmask = ah->rxchainmask; if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) { REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); } } static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah, struct ath9k_channel *chan) { u32 pll; pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); if (chan && IS_CHAN_HALF_RATE(chan)) pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); else if (chan && IS_CHAN_QUARTER_RATE(chan)) pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); if (chan && IS_CHAN_5GHZ(chan)) pll |= SM(0x50, AR_RTC_9160_PLL_DIV); else pll |= SM(0x58, AR_RTC_9160_PLL_DIV); return pll; } static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah, struct ath9k_channel *chan) { u32 pll; pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2; if (chan && IS_CHAN_HALF_RATE(chan)) pll |= SM(0x1, AR_RTC_PLL_CLKSEL); else if (chan && IS_CHAN_QUARTER_RATE(chan)) pll |= SM(0x2, AR_RTC_PLL_CLKSEL); if (chan && IS_CHAN_5GHZ(chan)) pll |= SM(0xa, AR_RTC_PLL_DIV); else pll |= SM(0xb, AR_RTC_PLL_DIV); return pll; } static bool ar5008_hw_ani_control_new(struct ath_hw *ah, enum ath9k_ani_cmd cmd, int param) { struct ath_common *common = ath9k_hw_common(ah); struct ath9k_channel *chan = ah->curchan; struct ar5416AniState *aniState = &chan->ani; s32 value, value2; switch (cmd & ah->ani_function) { case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{ /* * on == 1 means ofdm weak signal detection is ON * on == 1 is the default, for less noise immunity * * on == 0 means ofdm weak signal detection is OFF * on == 0 means more noise imm */ u32 on = param ? 1 : 0; /* * make register setting for default * (weak sig detect ON) come from INI file */ int m1ThreshLow = on ? aniState->iniDef.m1ThreshLow : m1ThreshLow_off; int m2ThreshLow = on ? aniState->iniDef.m2ThreshLow : m2ThreshLow_off; int m1Thresh = on ? aniState->iniDef.m1Thresh : m1Thresh_off; int m2Thresh = on ? aniState->iniDef.m2Thresh : m2Thresh_off; int m2CountThr = on ? aniState->iniDef.m2CountThr : m2CountThr_off; int m2CountThrLow = on ? aniState->iniDef.m2CountThrLow : m2CountThrLow_off; int m1ThreshLowExt = on ? aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off; int m2ThreshLowExt = on ? aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off; int m1ThreshExt = on ? aniState->iniDef.m1ThreshExt : m1ThreshExt_off; int m2ThreshExt = on ? aniState->iniDef.m2ThreshExt : m2ThreshExt_off; REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, AR_PHY_SFCORR_LOW_M1_THRESH_LOW, m1ThreshLow); REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, AR_PHY_SFCORR_LOW_M2_THRESH_LOW, m2ThreshLow); REG_RMW_FIELD(ah, AR_PHY_SFCORR, AR_PHY_SFCORR_M1_THRESH, m1Thresh); REG_RMW_FIELD(ah, AR_PHY_SFCORR, AR_PHY_SFCORR_M2_THRESH, m2Thresh); REG_RMW_FIELD(ah, AR_PHY_SFCORR, AR_PHY_SFCORR_M2COUNT_THR, m2CountThr); REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, m2CountThrLow); REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt); REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt); REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt); REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT, AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt); if (on) REG_SET_BIT(ah, AR_PHY_SFCORR_LOW, AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); else REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW, AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW); if (on != aniState->ofdmWeakSigDetect) { ath_dbg(common, ANI, "** ch %d: ofdm weak signal: %s=>%s\n", chan->channel, aniState->ofdmWeakSigDetect ? "on" : "off", on ? "on" : "off"); if (on) ah->stats.ast_ani_ofdmon++; else ah->stats.ast_ani_ofdmoff++; aniState->ofdmWeakSigDetect = on; } break; } case ATH9K_ANI_FIRSTEP_LEVEL:{ u32 level = param; if (level >= ARRAY_SIZE(firstep_table)) { ath_dbg(common, ANI, "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n", level, ARRAY_SIZE(firstep_table)); return false; } /* * make register setting relative to default * from INI file & cap value */ value = firstep_table[level] - firstep_table[ATH9K_ANI_FIRSTEP_LVL] + aniState->iniDef.firstep; if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN) value = ATH9K_SIG_FIRSTEP_SETTING_MIN; if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX) value = ATH9K_SIG_FIRSTEP_SETTING_MAX; REG_RMW_FIELD(ah, AR_PHY_FIND_SIG, AR_PHY_FIND_SIG_FIRSTEP, value); /* * we need to set first step low register too * make register setting relative to default * from INI file & cap value */ value2 = firstep_table[level] - firstep_table[ATH9K_ANI_FIRSTEP_LVL] + aniState->iniDef.firstepLow; if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN) value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN; if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX) value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX; REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW, AR_PHY_FIND_SIG_FIRSTEP_LOW, value2); if (level != aniState->firstepLevel) { ath_dbg(common, ANI, "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n", chan->channel, aniState->firstepLevel, level, ATH9K_ANI_FIRSTEP_LVL, value, aniState->iniDef.firstep); ath_dbg(common, ANI, "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n", chan->channel, aniState->firstepLevel, level, ATH9K_ANI_FIRSTEP_LVL, value2, aniState->iniDef.firstepLow); if (level > aniState->firstepLevel) ah->stats.ast_ani_stepup++; else if (level < aniState->firstepLevel) ah->stats.ast_ani_stepdown++; aniState->firstepLevel = level; } break; } case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{ u32 level = param; if (level >= ARRAY_SIZE(cycpwrThr1_table)) { ath_dbg(common, ANI, "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n", level, ARRAY_SIZE(cycpwrThr1_table)); return false; } /* * make register setting relative to default * from INI file & cap value */ value = cycpwrThr1_table[level] - cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] + aniState->iniDef.cycpwrThr1; if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN) value = ATH9K_SIG_SPUR_IMM_SETTING_MIN; if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX) value = ATH9K_SIG_SPUR_IMM_SETTING_MAX; REG_RMW_FIELD(ah, AR_PHY_TIMING5, AR_PHY_TIMING5_CYCPWR_THR1, value); /* * set AR_PHY_EXT_CCA for extension channel * make register setting relative to default * from INI file & cap value */ value2 = cycpwrThr1_table[level] - cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] + aniState->iniDef.cycpwrThr1Ext; if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN) value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN; if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX) value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX; REG_RMW_FIELD(ah, AR_PHY_EXT_CCA, AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2); if (level != aniState->spurImmunityLevel) { ath_dbg(common, ANI, "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n", chan->channel, aniState->spurImmunityLevel, level, ATH9K_ANI_SPUR_IMMUNE_LVL, value, aniState->iniDef.cycpwrThr1); ath_dbg(common, ANI, "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n", chan->channel, aniState->spurImmunityLevel, level, ATH9K_ANI_SPUR_IMMUNE_LVL, value2, aniState->iniDef.cycpwrThr1Ext); if (level > aniState->spurImmunityLevel) ah->stats.ast_ani_spurup++; else if (level < aniState->spurImmunityLevel) ah->stats.ast_ani_spurdown++; aniState->spurImmunityLevel = level; } break; } case ATH9K_ANI_MRC_CCK: /* * You should not see this as AR5008, AR9001, AR9002 * does not have hardware support for MRC CCK. */ WARN_ON(1); break; case ATH9K_ANI_PRESENT: break; default: ath_dbg(common, ANI, "invalid cmd %u\n", cmd); return false; } ath_dbg(common, ANI, "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n", aniState->spurImmunityLevel, aniState->ofdmWeakSigDetect ? "on" : "off", aniState->firstepLevel, aniState->mrcCCK ? "on" : "off", aniState->listenTime, aniState->ofdmPhyErrCount, aniState->cckPhyErrCount); return true; } static void ar5008_hw_do_getnf(struct ath_hw *ah, int16_t nfarray[NUM_NF_READINGS]) { int16_t nf; nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR); nfarray[0] = sign_extend32(nf, 8); nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR); nfarray[1] = sign_extend32(nf, 8); nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR); nfarray[2] = sign_extend32(nf, 8); if (!IS_CHAN_HT40(ah->curchan)) return; nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); nfarray[3] = sign_extend32(nf, 8); nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR); nfarray[4] = sign_extend32(nf, 8); nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR); nfarray[5] = sign_extend32(nf, 8); } /* * Initialize the ANI register values with default (ini) values. * This routine is called during a (full) hardware reset after * all the registers are initialised from the INI. */ static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah) { struct ath_common *common = ath9k_hw_common(ah); struct ath9k_channel *chan = ah->curchan; struct ar5416AniState *aniState = &chan->ani; struct ath9k_ani_default *iniDef; u32 val; iniDef = &aniState->iniDef; ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n", ah->hw_version.macVersion, ah->hw_version.macRev, ah->opmode, chan->channel, chan->channelFlags); val = REG_READ(ah, AR_PHY_SFCORR); iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH); iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH); iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR); val = REG_READ(ah, AR_PHY_SFCORR_LOW); iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW); iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW); iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW); val = REG_READ(ah, AR_PHY_SFCORR_EXT); iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH); iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH); iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW); iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW); iniDef->firstep = REG_READ_FIELD(ah, AR_PHY_FIND_SIG, AR_PHY_FIND_SIG_FIRSTEP); iniDef->firstepLow = REG_READ_FIELD(ah, AR_PHY_FIND_SIG_LOW, AR_PHY_FIND_SIG_FIRSTEP_LOW); iniDef->cycpwrThr1 = REG_READ_FIELD(ah, AR_PHY_TIMING5, AR_PHY_TIMING5_CYCPWR_THR1); iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah, AR_PHY_EXT_CCA, AR_PHY_EXT_TIMING5_CYCPWR_THR1); /* these levels just got reset to defaults by the INI */ aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL; aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL; aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG; aniState->mrcCCK = false; /* not available on pre AR9003 */ } static void ar5008_hw_set_nf_limits(struct ath_hw *ah) { ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ; ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ; ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ; ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ; ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ; ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ; } static void ar5008_hw_set_radar_params(struct ath_hw *ah, struct ath_hw_radar_conf *conf) { u32 radar_0 = 0, radar_1 = 0; if (!conf) { REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA); return; } radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA; radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR); radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI); radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT); radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI); radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND); radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI; radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK; radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN); radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH); radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH); REG_WRITE(ah, AR_PHY_RADAR_0, radar_0); REG_WRITE(ah, AR_PHY_RADAR_1, radar_1); if (conf->ext_channel) REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); else REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA); } static void ar5008_hw_set_radar_conf(struct ath_hw *ah) { struct ath_hw_radar_conf *conf = &ah->radar_conf; conf->fir_power = -33; conf->radar_rssi = 20; conf->pulse_height = 10; conf->pulse_rssi = 24; conf->pulse_inband = 15; conf->pulse_maxlen = 255; conf->pulse_inband_step = 12; conf->radar_inband = 8; } int ar5008_hw_attach_phy_ops(struct ath_hw *ah) { struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); static const u32 ar5416_cca_regs[6] = { AR_PHY_CCA, AR_PHY_CH1_CCA, AR_PHY_CH2_CCA, AR_PHY_EXT_CCA, AR_PHY_CH1_EXT_CCA, AR_PHY_CH2_EXT_CCA }; int ret; ret = ar5008_hw_rf_alloc_ext_banks(ah); if (ret) return ret; priv_ops->rf_set_freq = ar5008_hw_set_channel; priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate; priv_ops->set_rf_regs = ar5008_hw_set_rf_regs; priv_ops->set_channel_regs = ar5008_hw_set_channel_regs; priv_ops->init_bb = ar5008_hw_init_bb; priv_ops->process_ini = ar5008_hw_process_ini; priv_ops->set_rfmode = ar5008_hw_set_rfmode; priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive; priv_ops->set_delta_slope = ar5008_hw_set_delta_slope; priv_ops->rfbus_req = ar5008_hw_rfbus_req; priv_ops->rfbus_done = ar5008_hw_rfbus_done; priv_ops->restore_chainmask = ar5008_restore_chainmask; priv_ops->do_getnf = ar5008_hw_do_getnf; priv_ops->set_radar_params = ar5008_hw_set_radar_params; priv_ops->ani_control = ar5008_hw_ani_control_new; priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs; if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) priv_ops->compute_pll_control = ar9160_hw_compute_pll_control; else priv_ops->compute_pll_control = ar5008_hw_compute_pll_control; ar5008_hw_set_nf_limits(ah); ar5008_hw_set_radar_conf(ah); memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs)); return 0; }
gpl-2.0
dirty-hank/frankenlenok
drivers/acpi/acpica/nsobject.c
2623
12950
/******************************************************************************* * * Module Name: nsobject - Utilities for objects attached to namespace * table entries * ******************************************************************************/ /* * Copyright (C) 2000 - 2013, Intel Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsobject") /******************************************************************************* * * FUNCTION: acpi_ns_attach_object * * PARAMETERS: node - Parent Node * object - Object to be attached * type - Type of object, or ACPI_TYPE_ANY if not * known * * RETURN: Status * * DESCRIPTION: Record the given object as the value associated with the * name whose acpi_handle is passed. If Object is NULL * and Type is ACPI_TYPE_ANY, set the name as having no value. * Note: Future may require that the Node->Flags field be passed * as a parameter. * * MUTEX: Assumes namespace is locked * ******************************************************************************/ acpi_status acpi_ns_attach_object(struct acpi_namespace_node *node, union acpi_operand_object *object, acpi_object_type type) { union acpi_operand_object *obj_desc; union acpi_operand_object *last_obj_desc; acpi_object_type object_type = ACPI_TYPE_ANY; ACPI_FUNCTION_TRACE(ns_attach_object); /* * Parameter validation */ if (!node) { /* Invalid handle */ ACPI_ERROR((AE_INFO, "Null NamedObj handle")); return_ACPI_STATUS(AE_BAD_PARAMETER); } if (!object && (ACPI_TYPE_ANY != type)) { /* Null object */ ACPI_ERROR((AE_INFO, "Null object, but type not ACPI_TYPE_ANY")); return_ACPI_STATUS(AE_BAD_PARAMETER); } if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { /* Not a name handle */ ACPI_ERROR((AE_INFO, "Invalid handle %p [%s]", node, acpi_ut_get_descriptor_name(node))); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Check if this object is already attached */ if (node->object == object) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj %p already installed in NameObj %p\n", object, node)); return_ACPI_STATUS(AE_OK); } /* If null object, we will just install it */ if (!object) { obj_desc = NULL; object_type = ACPI_TYPE_ANY; } /* * If the source object is a namespace Node with an attached object, * we will use that (attached) object */ else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) && ((struct acpi_namespace_node *)object)->object) { /* * Value passed is a name handle and that name has a * non-null value. Use that name's value and type. */ obj_desc = ((struct acpi_namespace_node *)object)->object; object_type = ((struct acpi_namespace_node *)object)->type; } /* * Otherwise, we will use the parameter object, but we must type * it first */ else { obj_desc = (union acpi_operand_object *)object; /* Use the given type */ object_type = type; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n", obj_desc, node, acpi_ut_get_node_name(node))); /* Detach an existing attached object if present */ if (node->object) { acpi_ns_detach_object(node); } if (obj_desc) { /* * Must increment the new value's reference count * (if it is an internal object) */ acpi_ut_add_reference(obj_desc); /* * Handle objects with multiple descriptors - walk * to the end of the descriptor list */ last_obj_desc = obj_desc; while (last_obj_desc->common.next_object) { last_obj_desc = last_obj_desc->common.next_object; } /* Install the object at the front of the object list */ last_obj_desc->common.next_object = node->object; } node->type = (u8) object_type; node->object = obj_desc; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_detach_object * * PARAMETERS: node - A Namespace node whose object will be detached * * RETURN: None. * * DESCRIPTION: Detach/delete an object associated with a namespace node. * if the object is an allocated object, it is freed. * Otherwise, the field is simply cleared. * ******************************************************************************/ void acpi_ns_detach_object(struct acpi_namespace_node *node) { union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE(ns_detach_object); obj_desc = node->object; if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) { return_VOID; } if (node->flags & ANOBJ_ALLOCATED_BUFFER) { /* Free the dynamic aml buffer */ if (obj_desc->common.type == ACPI_TYPE_METHOD) { ACPI_FREE(obj_desc->method.aml_start); } } /* Clear the entry in all cases */ node->object = NULL; if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) { node->object = obj_desc->common.next_object; if (node->object && ((node->object)->common.type != ACPI_TYPE_LOCAL_DATA)) { node->object = node->object->common.next_object; } } /* Reset the node type to untyped */ node->type = ACPI_TYPE_ANY; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n", node, acpi_ut_get_node_name(node), obj_desc)); /* Remove one reference on the object (and all subobjects) */ acpi_ut_remove_reference(obj_desc); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ns_get_attached_object * * PARAMETERS: node - Namespace node * * RETURN: Current value of the object field from the Node whose * handle is passed * * DESCRIPTION: Obtain the object attached to a namespace node. * ******************************************************************************/ union acpi_operand_object *acpi_ns_get_attached_object(struct acpi_namespace_node *node) { ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node); if (!node) { ACPI_WARNING((AE_INFO, "Null Node ptr")); return_PTR(NULL); } if (!node->object || ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND) && (ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_NAMED)) || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) { return_PTR(NULL); } return_PTR(node->object); } /******************************************************************************* * * FUNCTION: acpi_ns_get_secondary_object * * PARAMETERS: node - Namespace node * * RETURN: Current value of the object field from the Node whose * handle is passed. * * DESCRIPTION: Obtain a secondary object associated with a namespace node. * ******************************************************************************/ union acpi_operand_object *acpi_ns_get_secondary_object(union acpi_operand_object *obj_desc) { ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc); if ((!obj_desc) || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) || (!obj_desc->common.next_object) || ((obj_desc->common.next_object)->common.type == ACPI_TYPE_LOCAL_DATA)) { return_PTR(NULL); } return_PTR(obj_desc->common.next_object); } /******************************************************************************* * * FUNCTION: acpi_ns_attach_data * * PARAMETERS: node - Namespace node * handler - Handler to be associated with the data * data - Data to be attached * * RETURN: Status * * DESCRIPTION: Low-level attach data. Create and attach a Data object. * ******************************************************************************/ acpi_status acpi_ns_attach_data(struct acpi_namespace_node *node, acpi_object_handler handler, void *data) { union acpi_operand_object *prev_obj_desc; union acpi_operand_object *obj_desc; union acpi_operand_object *data_desc; /* We only allow one attachment per handler */ prev_obj_desc = NULL; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { return (AE_ALREADY_EXISTS); } prev_obj_desc = obj_desc; obj_desc = obj_desc->common.next_object; } /* Create an internal object for the data */ data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA); if (!data_desc) { return (AE_NO_MEMORY); } data_desc->data.handler = handler; data_desc->data.pointer = data; /* Install the data object */ if (prev_obj_desc) { prev_obj_desc->common.next_object = data_desc; } else { node->object = data_desc; } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_detach_data * * PARAMETERS: node - Namespace node * handler - Handler associated with the data * * RETURN: Status * * DESCRIPTION: Low-level detach data. Delete the data node, but the caller * is responsible for the actual data. * ******************************************************************************/ acpi_status acpi_ns_detach_data(struct acpi_namespace_node * node, acpi_object_handler handler) { union acpi_operand_object *obj_desc; union acpi_operand_object *prev_obj_desc; prev_obj_desc = NULL; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { if (prev_obj_desc) { prev_obj_desc->common.next_object = obj_desc->common.next_object; } else { node->object = obj_desc->common.next_object; } acpi_ut_remove_reference(obj_desc); return (AE_OK); } prev_obj_desc = obj_desc; obj_desc = obj_desc->common.next_object; } return (AE_NOT_FOUND); } /******************************************************************************* * * FUNCTION: acpi_ns_get_attached_data * * PARAMETERS: node - Namespace node * handler - Handler associated with the data * data - Where the data is returned * * RETURN: Status * * DESCRIPTION: Low level interface to obtain data previously associated with * a namespace node. * ******************************************************************************/ acpi_status acpi_ns_get_attached_data(struct acpi_namespace_node * node, acpi_object_handler handler, void **data) { union acpi_operand_object *obj_desc; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { *data = obj_desc->data.pointer; return (AE_OK); } obj_desc = obj_desc->common.next_object; } return (AE_NOT_FOUND); }
gpl-2.0
ckw1375/mptcp
drivers/acpi/acpica/rsmemory.c
2623
7391
/******************************************************************************* * * Module Name: rsmem24 - Memory resource descriptors * ******************************************************************************/ /* * Copyright (C) 2000 - 2013, Intel Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsmemory") /******************************************************************************* * * acpi_rs_convert_memory24 * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_memory24[4] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_MEMORY24, ACPI_RS_SIZE(struct acpi_resource_memory24), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_memory24)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_MEMORY24, sizeof(struct aml_resource_memory24), 0}, /* Read/Write bit */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.memory24.write_protect), AML_OFFSET(memory24.flags), 0}, /* * These fields are contiguous in both the source and destination: * Minimum Base Address * Maximum Base Address * Address Base Alignment * Range Length */ {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.memory24.minimum), AML_OFFSET(memory24.minimum), 4} }; /******************************************************************************* * * acpi_rs_convert_memory32 * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_memory32[4] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_MEMORY32, ACPI_RS_SIZE(struct acpi_resource_memory32), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_memory32)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_MEMORY32, sizeof(struct aml_resource_memory32), 0}, /* Read/Write bit */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.memory32.write_protect), AML_OFFSET(memory32.flags), 0}, /* * These fields are contiguous in both the source and destination: * Minimum Base Address * Maximum Base Address * Address Base Alignment * Range Length */ {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.memory32.minimum), AML_OFFSET(memory32.minimum), 4} }; /******************************************************************************* * * acpi_rs_convert_fixed_memory32 * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_fixed_memory32[4] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_FIXED_MEMORY32, ACPI_RS_SIZE(struct acpi_resource_fixed_memory32), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_fixed_memory32)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_FIXED_MEMORY32, sizeof(struct aml_resource_fixed_memory32), 0}, /* Read/Write bit */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.fixed_memory32.write_protect), AML_OFFSET(fixed_memory32.flags), 0}, /* * These fields are contiguous in both the source and destination: * Base Address * Range Length */ {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.fixed_memory32.address), AML_OFFSET(fixed_memory32.address), 2} }; /******************************************************************************* * * acpi_rs_get_vendor_small * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_get_vendor_small[3] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_VENDOR, ACPI_RS_SIZE(struct acpi_resource_vendor), ACPI_RSC_TABLE_SIZE(acpi_rs_get_vendor_small)}, /* Length of the vendor data (byte count) */ {ACPI_RSC_COUNT16, ACPI_RS_OFFSET(data.vendor.byte_length), 0, sizeof(u8)}, /* Vendor data */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.vendor.byte_data[0]), sizeof(struct aml_resource_small_header), 0} }; /******************************************************************************* * * acpi_rs_get_vendor_large * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_get_vendor_large[3] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_VENDOR, ACPI_RS_SIZE(struct acpi_resource_vendor), ACPI_RSC_TABLE_SIZE(acpi_rs_get_vendor_large)}, /* Length of the vendor data (byte count) */ {ACPI_RSC_COUNT16, ACPI_RS_OFFSET(data.vendor.byte_length), 0, sizeof(u8)}, /* Vendor data */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.vendor.byte_data[0]), sizeof(struct aml_resource_large_header), 0} }; /******************************************************************************* * * acpi_rs_set_vendor * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_set_vendor[7] = { /* Default is a small vendor descriptor */ {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_VENDOR_SMALL, sizeof(struct aml_resource_small_header), ACPI_RSC_TABLE_SIZE(acpi_rs_set_vendor)}, /* Get the length and copy the data */ {ACPI_RSC_COUNT16, ACPI_RS_OFFSET(data.vendor.byte_length), 0, 0}, {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.vendor.byte_data[0]), sizeof(struct aml_resource_small_header), 0}, /* * All done if the Vendor byte length is 7 or less, meaning that it will * fit within a small descriptor */ {ACPI_RSC_EXIT_LE, 0, 0, 7}, /* Must create a large vendor descriptor */ {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_VENDOR_LARGE, sizeof(struct aml_resource_large_header), 0}, {ACPI_RSC_COUNT16, ACPI_RS_OFFSET(data.vendor.byte_length), 0, 0}, {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.vendor.byte_data[0]), sizeof(struct aml_resource_large_header), 0} };
gpl-2.0
LEPT-Development/android_kernel_lge_msm8916-old
drivers/power/reset/qnap-poweroff.c
2623
3007
/* * QNAP Turbo NAS Board power off * * Copyright (C) 2012 Andrew Lunn <andrew@lunn.ch> * * Based on the code from: * * Copyright (C) 2009 Martin Michlmayr <tbm@cyrius.com> * Copyright (C) 2008 Byron Bradley <byron.bbradley@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/serial_reg.h> #include <linux/kallsyms.h> #include <linux/of.h> #include <linux/io.h> #include <linux/clk.h> #define UART1_REG(x) (base + ((UART_##x) << 2)) static void __iomem *base; static unsigned long tclk; static void qnap_power_off(void) { /* 19200 baud divisor */ const unsigned divisor = ((tclk + (8 * 19200)) / (16 * 19200)); pr_err("%s: triggering power-off...\n", __func__); /* hijack UART1 and reset into sane state (19200,8n1) */ writel(0x83, UART1_REG(LCR)); writel(divisor & 0xff, UART1_REG(DLL)); writel((divisor >> 8) & 0xff, UART1_REG(DLM)); writel(0x03, UART1_REG(LCR)); writel(0x00, UART1_REG(IER)); writel(0x00, UART1_REG(FCR)); writel(0x00, UART1_REG(MCR)); /* send the power-off command 'A' to PIC */ writel('A', UART1_REG(TX)); } static int qnap_power_off_probe(struct platform_device *pdev) { struct resource *res; struct clk *clk; char symname[KSYM_NAME_LEN]; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "Missing resource"); return -EINVAL; } base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!base) { dev_err(&pdev->dev, "Unable to map resource"); return -EINVAL; } /* We need to know tclk in order to calculate the UART divisor */ clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "Clk missing"); return PTR_ERR(clk); } tclk = clk_get_rate(clk); /* Check that nothing else has already setup a handler */ if (pm_power_off) { lookup_symbol_name((ulong)pm_power_off, symname); dev_err(&pdev->dev, "pm_power_off already claimed %p %s", pm_power_off, symname); return -EBUSY; } pm_power_off = qnap_power_off; return 0; } static int qnap_power_off_remove(struct platform_device *pdev) { pm_power_off = NULL; return 0; } static const struct of_device_id qnap_power_off_of_match_table[] = { { .compatible = "qnap,power-off", }, {} }; MODULE_DEVICE_TABLE(of, qnap_power_off_of_match_table); static struct platform_driver qnap_power_off_driver = { .probe = qnap_power_off_probe, .remove = qnap_power_off_remove, .driver = { .owner = THIS_MODULE, .name = "qnap_power_off", .of_match_table = of_match_ptr(qnap_power_off_of_match_table), }, }; module_platform_driver(qnap_power_off_driver); MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); MODULE_DESCRIPTION("QNAP Power off driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
mitwo-dev/android_kernel_xiaomi_msm8960
arch/arm/crypto/aesbs-glue.c
2623
12024
/* * linux/arch/arm/crypto/aesbs-glue.c - glue code for NEON bit sliced AES * * Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <asm/neon.h> #include <crypto/aes.h> #include <crypto/ablk_helper.h> #include <crypto/algapi.h> #include <linux/module.h> #include "aes_glue.h" #define BIT_SLICED_KEY_MAXSIZE (128 * (AES_MAXNR - 1) + 2 * AES_BLOCK_SIZE) struct BS_KEY { struct AES_KEY rk; int converted; u8 __aligned(8) bs[BIT_SLICED_KEY_MAXSIZE]; } __aligned(8); asmlinkage void bsaes_enc_key_convert(u8 out[], struct AES_KEY const *in); asmlinkage void bsaes_dec_key_convert(u8 out[], struct AES_KEY const *in); asmlinkage void bsaes_cbc_encrypt(u8 const in[], u8 out[], u32 bytes, struct BS_KEY *key, u8 iv[]); asmlinkage void bsaes_ctr32_encrypt_blocks(u8 const in[], u8 out[], u32 blocks, struct BS_KEY *key, u8 const iv[]); asmlinkage void bsaes_xts_encrypt(u8 const in[], u8 out[], u32 bytes, struct BS_KEY *key, u8 tweak[]); asmlinkage void bsaes_xts_decrypt(u8 const in[], u8 out[], u32 bytes, struct BS_KEY *key, u8 tweak[]); struct aesbs_cbc_ctx { struct AES_KEY enc; struct BS_KEY dec; }; struct aesbs_ctr_ctx { struct BS_KEY enc; }; struct aesbs_xts_ctx { struct BS_KEY enc; struct BS_KEY dec; struct AES_KEY twkey; }; static int aesbs_cbc_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) { struct aesbs_cbc_ctx *ctx = crypto_tfm_ctx(tfm); int bits = key_len * 8; if (private_AES_set_encrypt_key(in_key, bits, &ctx->enc)) { tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; return -EINVAL; } ctx->dec.rk = ctx->enc; private_AES_set_decrypt_key(in_key, bits, &ctx->dec.rk); ctx->dec.converted = 0; return 0; } static int aesbs_ctr_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) { struct aesbs_ctr_ctx *ctx = crypto_tfm_ctx(tfm); int bits = key_len * 8; if (private_AES_set_encrypt_key(in_key, bits, &ctx->enc.rk)) { tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; return -EINVAL; } ctx->enc.converted = 0; return 0; } static int aesbs_xts_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) { struct aesbs_xts_ctx *ctx = crypto_tfm_ctx(tfm); int bits = key_len * 4; if (private_AES_set_encrypt_key(in_key, bits, &ctx->enc.rk)) { tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; return -EINVAL; } ctx->dec.rk = ctx->enc.rk; private_AES_set_decrypt_key(in_key, bits, &ctx->dec.rk); private_AES_set_encrypt_key(in_key + key_len / 2, bits, &ctx->twkey); ctx->enc.converted = ctx->dec.converted = 0; return 0; } static int aesbs_cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct aesbs_cbc_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); struct blkcipher_walk walk; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt(desc, &walk); while (walk.nbytes) { u32 blocks = walk.nbytes / AES_BLOCK_SIZE; u8 *src = walk.src.virt.addr; if (walk.dst.virt.addr == walk.src.virt.addr) { u8 *iv = walk.iv; do { crypto_xor(src, iv, AES_BLOCK_SIZE); AES_encrypt(src, src, &ctx->enc); iv = src; src += AES_BLOCK_SIZE; } while (--blocks); memcpy(walk.iv, iv, AES_BLOCK_SIZE); } else { u8 *dst = walk.dst.virt.addr; do { crypto_xor(walk.iv, src, AES_BLOCK_SIZE); AES_encrypt(walk.iv, dst, &ctx->enc); memcpy(walk.iv, dst, AES_BLOCK_SIZE); src += AES_BLOCK_SIZE; dst += AES_BLOCK_SIZE; } while (--blocks); } err = blkcipher_walk_done(desc, &walk, walk.nbytes % AES_BLOCK_SIZE); } return err; } static int aesbs_cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct aesbs_cbc_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); struct blkcipher_walk walk; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt_block(desc, &walk, 8 * AES_BLOCK_SIZE); while ((walk.nbytes / AES_BLOCK_SIZE) >= 8) { kernel_neon_begin(); bsaes_cbc_encrypt(walk.src.virt.addr, walk.dst.virt.addr, walk.nbytes, &ctx->dec, walk.iv); kernel_neon_end(); err = blkcipher_walk_done(desc, &walk, walk.nbytes % AES_BLOCK_SIZE); } while (walk.nbytes) { u32 blocks = walk.nbytes / AES_BLOCK_SIZE; u8 *dst = walk.dst.virt.addr; u8 *src = walk.src.virt.addr; u8 bk[2][AES_BLOCK_SIZE]; u8 *iv = walk.iv; do { if (walk.dst.virt.addr == walk.src.virt.addr) memcpy(bk[blocks & 1], src, AES_BLOCK_SIZE); AES_decrypt(src, dst, &ctx->dec.rk); crypto_xor(dst, iv, AES_BLOCK_SIZE); if (walk.dst.virt.addr == walk.src.virt.addr) iv = bk[blocks & 1]; else iv = src; dst += AES_BLOCK_SIZE; src += AES_BLOCK_SIZE; } while (--blocks); err = blkcipher_walk_done(desc, &walk, walk.nbytes % AES_BLOCK_SIZE); } return err; } static void inc_be128_ctr(__be32 ctr[], u32 addend) { int i; for (i = 3; i >= 0; i--, addend = 1) { u32 n = be32_to_cpu(ctr[i]) + addend; ctr[i] = cpu_to_be32(n); if (n >= addend) break; } } static int aesbs_ctr_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct aesbs_ctr_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); struct blkcipher_walk walk; u32 blocks; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt_block(desc, &walk, 8 * AES_BLOCK_SIZE); while ((blocks = walk.nbytes / AES_BLOCK_SIZE)) { u32 tail = walk.nbytes % AES_BLOCK_SIZE; __be32 *ctr = (__be32 *)walk.iv; u32 headroom = UINT_MAX - be32_to_cpu(ctr[3]); /* avoid 32 bit counter overflow in the NEON code */ if (unlikely(headroom < blocks)) { blocks = headroom + 1; tail = walk.nbytes - blocks * AES_BLOCK_SIZE; } kernel_neon_begin(); bsaes_ctr32_encrypt_blocks(walk.src.virt.addr, walk.dst.virt.addr, blocks, &ctx->enc, walk.iv); kernel_neon_end(); inc_be128_ctr(ctr, blocks); nbytes -= blocks * AES_BLOCK_SIZE; if (nbytes && nbytes == tail && nbytes <= AES_BLOCK_SIZE) break; err = blkcipher_walk_done(desc, &walk, tail); } if (walk.nbytes) { u8 *tdst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE; u8 *tsrc = walk.src.virt.addr + blocks * AES_BLOCK_SIZE; u8 ks[AES_BLOCK_SIZE]; AES_encrypt(walk.iv, ks, &ctx->enc.rk); if (tdst != tsrc) memcpy(tdst, tsrc, nbytes); crypto_xor(tdst, ks, nbytes); err = blkcipher_walk_done(desc, &walk, 0); } return err; } static int aesbs_xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct aesbs_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); struct blkcipher_walk walk; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt_block(desc, &walk, 8 * AES_BLOCK_SIZE); /* generate the initial tweak */ AES_encrypt(walk.iv, walk.iv, &ctx->twkey); while (walk.nbytes) { kernel_neon_begin(); bsaes_xts_encrypt(walk.src.virt.addr, walk.dst.virt.addr, walk.nbytes, &ctx->enc, walk.iv); kernel_neon_end(); err = blkcipher_walk_done(desc, &walk, walk.nbytes % AES_BLOCK_SIZE); } return err; } static int aesbs_xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { struct aesbs_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); struct blkcipher_walk walk; int err; blkcipher_walk_init(&walk, dst, src, nbytes); err = blkcipher_walk_virt_block(desc, &walk, 8 * AES_BLOCK_SIZE); /* generate the initial tweak */ AES_encrypt(walk.iv, walk.iv, &ctx->twkey); while (walk.nbytes) { kernel_neon_begin(); bsaes_xts_decrypt(walk.src.virt.addr, walk.dst.virt.addr, walk.nbytes, &ctx->dec, walk.iv); kernel_neon_end(); err = blkcipher_walk_done(desc, &walk, walk.nbytes % AES_BLOCK_SIZE); } return err; } static struct crypto_alg aesbs_algs[] = { { .cra_name = "__cbc-aes-neonbs", .cra_driver_name = "__driver-cbc-aes-neonbs", .cra_priority = 0, .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct aesbs_cbc_ctx), .cra_alignmask = 7, .cra_type = &crypto_blkcipher_type, .cra_module = THIS_MODULE, .cra_blkcipher = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = aesbs_cbc_set_key, .encrypt = aesbs_cbc_encrypt, .decrypt = aesbs_cbc_decrypt, }, }, { .cra_name = "__ctr-aes-neonbs", .cra_driver_name = "__driver-ctr-aes-neonbs", .cra_priority = 0, .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, .cra_blocksize = 1, .cra_ctxsize = sizeof(struct aesbs_ctr_ctx), .cra_alignmask = 7, .cra_type = &crypto_blkcipher_type, .cra_module = THIS_MODULE, .cra_blkcipher = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = aesbs_ctr_set_key, .encrypt = aesbs_ctr_encrypt, .decrypt = aesbs_ctr_encrypt, }, }, { .cra_name = "__xts-aes-neonbs", .cra_driver_name = "__driver-xts-aes-neonbs", .cra_priority = 0, .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct aesbs_xts_ctx), .cra_alignmask = 7, .cra_type = &crypto_blkcipher_type, .cra_module = THIS_MODULE, .cra_blkcipher = { .min_keysize = 2 * AES_MIN_KEY_SIZE, .max_keysize = 2 * AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = aesbs_xts_set_key, .encrypt = aesbs_xts_encrypt, .decrypt = aesbs_xts_decrypt, }, }, { .cra_name = "cbc(aes)", .cra_driver_name = "cbc-aes-neonbs", .cra_priority = 300, .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct async_helper_ctx), .cra_alignmask = 7, .cra_type = &crypto_ablkcipher_type, .cra_module = THIS_MODULE, .cra_init = ablk_init, .cra_exit = ablk_exit, .cra_ablkcipher = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = ablk_set_key, .encrypt = __ablk_encrypt, .decrypt = ablk_decrypt, } }, { .cra_name = "ctr(aes)", .cra_driver_name = "ctr-aes-neonbs", .cra_priority = 300, .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC, .cra_blocksize = 1, .cra_ctxsize = sizeof(struct async_helper_ctx), .cra_alignmask = 7, .cra_type = &crypto_ablkcipher_type, .cra_module = THIS_MODULE, .cra_init = ablk_init, .cra_exit = ablk_exit, .cra_ablkcipher = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = ablk_set_key, .encrypt = ablk_encrypt, .decrypt = ablk_decrypt, } }, { .cra_name = "xts(aes)", .cra_driver_name = "xts-aes-neonbs", .cra_priority = 300, .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct async_helper_ctx), .cra_alignmask = 7, .cra_type = &crypto_ablkcipher_type, .cra_module = THIS_MODULE, .cra_init = ablk_init, .cra_exit = ablk_exit, .cra_ablkcipher = { .min_keysize = 2 * AES_MIN_KEY_SIZE, .max_keysize = 2 * AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = ablk_set_key, .encrypt = ablk_encrypt, .decrypt = ablk_decrypt, } } }; static int __init aesbs_mod_init(void) { if (!cpu_has_neon()) return -ENODEV; return crypto_register_algs(aesbs_algs, ARRAY_SIZE(aesbs_algs)); } static void __exit aesbs_mod_exit(void) { crypto_unregister_algs(aesbs_algs, ARRAY_SIZE(aesbs_algs)); } module_init(aesbs_mod_init); module_exit(aesbs_mod_exit); MODULE_DESCRIPTION("Bit sliced AES in CBC/CTR/XTS modes using NEON"); MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); MODULE_LICENSE("GPL");
gpl-2.0
bootc/linux
drivers/char/mspec.c
2879
10949
/* * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights * reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. */ /* * SN Platform Special Memory (mspec) Support * * This driver exports the SN special memory (mspec) facility to user * processes. * There are three types of memory made available thru this driver: * fetchops, uncached and cached. * * Fetchops are atomic memory operations that are implemented in the * memory controller on SGI SN hardware. * * Uncached are used for memory write combining feature of the ia64 * cpu. * * Cached are used for areas of memory that are used as cached addresses * on our partition and used as uncached addresses from other partitions. * Due to a design constraint of the SN2 Shub, you can not have processors * on the same FSB perform both a cached and uncached reference to the * same cache line. These special memory cached regions prevent the * kernel from ever dropping in a TLB entry and therefore prevent the * processor from ever speculating a cache line from this page. */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/spinlock.h> #include <linux/mm.h> #include <linux/fs.h> #include <linux/vmalloc.h> #include <linux/string.h> #include <linux/slab.h> #include <linux/numa.h> #include <asm/page.h> #include <asm/pgtable.h> #include <linux/atomic.h> #include <asm/tlbflush.h> #include <asm/uncached.h> #include <asm/sn/addrs.h> #include <asm/sn/arch.h> #include <asm/sn/mspec.h> #include <asm/sn/sn_cpuid.h> #include <asm/sn/io.h> #include <asm/sn/bte.h> #include <asm/sn/shubio.h> #define FETCHOP_ID "SGI Fetchop," #define CACHED_ID "Cached," #define UNCACHED_ID "Uncached" #define REVISION "4.0" #define MSPEC_BASENAME "mspec" /* * Page types allocated by the device. */ enum mspec_page_type { MSPEC_FETCHOP = 1, MSPEC_CACHED, MSPEC_UNCACHED }; #ifdef CONFIG_SGI_SN static int is_sn2; #else #define is_sn2 0 #endif /* * One of these structures is allocated when an mspec region is mmaped. The * structure is pointed to by the vma->vm_private_data field in the vma struct. * This structure is used to record the addresses of the mspec pages. * This structure is shared by all vma's that are split off from the * original vma when split_vma()'s are done. * * The refcnt is incremented atomically because mm->mmap_sem does not * protect in fork case where multiple tasks share the vma_data. */ struct vma_data { atomic_t refcnt; /* Number of vmas sharing the data. */ spinlock_t lock; /* Serialize access to this structure. */ int count; /* Number of pages allocated. */ enum mspec_page_type type; /* Type of pages allocated. */ int flags; /* See VMD_xxx below. */ unsigned long vm_start; /* Original (unsplit) base. */ unsigned long vm_end; /* Original (unsplit) end. */ unsigned long maddr[0]; /* Array of MSPEC addresses. */ }; #define VMD_VMALLOCED 0x1 /* vmalloc'd rather than kmalloc'd */ /* used on shub2 to clear FOP cache in the HUB */ static unsigned long scratch_page[MAX_NUMNODES]; #define SH2_AMO_CACHE_ENTRIES 4 static inline int mspec_zero_block(unsigned long addr, int len) { int status; if (is_sn2) { if (is_shub2()) { int nid; void *p; int i; nid = nasid_to_cnodeid(get_node_number(__pa(addr))); p = (void *)TO_AMO(scratch_page[nid]); for (i=0; i < SH2_AMO_CACHE_ENTRIES; i++) { FETCHOP_LOAD_OP(p, FETCHOP_LOAD); p += FETCHOP_VAR_SIZE; } } status = bte_copy(0, addr & ~__IA64_UNCACHED_OFFSET, len, BTE_WACQUIRE | BTE_ZERO_FILL, NULL); } else { memset((char *) addr, 0, len); status = 0; } return status; } /* * mspec_open * * Called when a device mapping is created by a means other than mmap * (via fork, munmap, etc.). Increments the reference count on the * underlying mspec data so it is not freed prematurely. */ static void mspec_open(struct vm_area_struct *vma) { struct vma_data *vdata; vdata = vma->vm_private_data; atomic_inc(&vdata->refcnt); } /* * mspec_close * * Called when unmapping a device mapping. Frees all mspec pages * belonging to all the vma's sharing this vma_data structure. */ static void mspec_close(struct vm_area_struct *vma) { struct vma_data *vdata; int index, last_index; unsigned long my_page; vdata = vma->vm_private_data; if (!atomic_dec_and_test(&vdata->refcnt)) return; last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT; for (index = 0; index < last_index; index++) { if (vdata->maddr[index] == 0) continue; /* * Clear the page before sticking it back * into the pool. */ my_page = vdata->maddr[index]; vdata->maddr[index] = 0; if (!mspec_zero_block(my_page, PAGE_SIZE)) uncached_free_page(my_page, 1); else printk(KERN_WARNING "mspec_close(): " "failed to zero page %ld\n", my_page); } if (vdata->flags & VMD_VMALLOCED) vfree(vdata); else kfree(vdata); } /* * mspec_fault * * Creates a mspec page and maps it to user space. */ static int mspec_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { unsigned long paddr, maddr; unsigned long pfn; pgoff_t index = vmf->pgoff; struct vma_data *vdata = vma->vm_private_data; maddr = (volatile unsigned long) vdata->maddr[index]; if (maddr == 0) { maddr = uncached_alloc_page(numa_node_id(), 1); if (maddr == 0) return VM_FAULT_OOM; spin_lock(&vdata->lock); if (vdata->maddr[index] == 0) { vdata->count++; vdata->maddr[index] = maddr; } else { uncached_free_page(maddr, 1); maddr = vdata->maddr[index]; } spin_unlock(&vdata->lock); } if (vdata->type == MSPEC_FETCHOP) paddr = TO_AMO(maddr); else paddr = maddr & ~__IA64_UNCACHED_OFFSET; pfn = paddr >> PAGE_SHIFT; /* * vm_insert_pfn can fail with -EBUSY, but in that case it will * be because another thread has installed the pte first, so it * is no problem. */ vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn); return VM_FAULT_NOPAGE; } static const struct vm_operations_struct mspec_vm_ops = { .open = mspec_open, .close = mspec_close, .fault = mspec_fault, }; /* * mspec_mmap * * Called when mmapping the device. Initializes the vma with a fault handler * and private data structure necessary to allocate, track, and free the * underlying pages. */ static int mspec_mmap(struct file *file, struct vm_area_struct *vma, enum mspec_page_type type) { struct vma_data *vdata; int pages, vdata_size, flags = 0; if (vma->vm_pgoff != 0) return -EINVAL; if ((vma->vm_flags & VM_SHARED) == 0) return -EINVAL; if ((vma->vm_flags & VM_WRITE) == 0) return -EPERM; pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; vdata_size = sizeof(struct vma_data) + pages * sizeof(long); if (vdata_size <= PAGE_SIZE) vdata = kzalloc(vdata_size, GFP_KERNEL); else { vdata = vzalloc(vdata_size); flags = VMD_VMALLOCED; } if (!vdata) return -ENOMEM; vdata->vm_start = vma->vm_start; vdata->vm_end = vma->vm_end; vdata->flags = flags; vdata->type = type; spin_lock_init(&vdata->lock); vdata->refcnt = ATOMIC_INIT(1); vma->vm_private_data = vdata; vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP | VM_DONTEXPAND); if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED) vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_ops = &mspec_vm_ops; return 0; } static int fetchop_mmap(struct file *file, struct vm_area_struct *vma) { return mspec_mmap(file, vma, MSPEC_FETCHOP); } static int cached_mmap(struct file *file, struct vm_area_struct *vma) { return mspec_mmap(file, vma, MSPEC_CACHED); } static int uncached_mmap(struct file *file, struct vm_area_struct *vma) { return mspec_mmap(file, vma, MSPEC_UNCACHED); } static const struct file_operations fetchop_fops = { .owner = THIS_MODULE, .mmap = fetchop_mmap, .llseek = noop_llseek, }; static struct miscdevice fetchop_miscdev = { .minor = MISC_DYNAMIC_MINOR, .name = "sgi_fetchop", .fops = &fetchop_fops }; static const struct file_operations cached_fops = { .owner = THIS_MODULE, .mmap = cached_mmap, .llseek = noop_llseek, }; static struct miscdevice cached_miscdev = { .minor = MISC_DYNAMIC_MINOR, .name = "mspec_cached", .fops = &cached_fops }; static const struct file_operations uncached_fops = { .owner = THIS_MODULE, .mmap = uncached_mmap, .llseek = noop_llseek, }; static struct miscdevice uncached_miscdev = { .minor = MISC_DYNAMIC_MINOR, .name = "mspec_uncached", .fops = &uncached_fops }; /* * mspec_init * * Called at boot time to initialize the mspec facility. */ static int __init mspec_init(void) { int ret; int nid; /* * The fetchop device only works on SN2 hardware, uncached and cached * memory drivers should both be valid on all ia64 hardware */ #ifdef CONFIG_SGI_SN if (ia64_platform_is("sn2")) { is_sn2 = 1; if (is_shub2()) { ret = -ENOMEM; for_each_node_state(nid, N_ONLINE) { int actual_nid; int nasid; unsigned long phys; scratch_page[nid] = uncached_alloc_page(nid, 1); if (scratch_page[nid] == 0) goto free_scratch_pages; phys = __pa(scratch_page[nid]); nasid = get_node_number(phys); actual_nid = nasid_to_cnodeid(nasid); if (actual_nid != nid) goto free_scratch_pages; } } ret = misc_register(&fetchop_miscdev); if (ret) { printk(KERN_ERR "%s: failed to register device %i\n", FETCHOP_ID, ret); goto free_scratch_pages; } } #endif ret = misc_register(&cached_miscdev); if (ret) { printk(KERN_ERR "%s: failed to register device %i\n", CACHED_ID, ret); if (is_sn2) misc_deregister(&fetchop_miscdev); goto free_scratch_pages; } ret = misc_register(&uncached_miscdev); if (ret) { printk(KERN_ERR "%s: failed to register device %i\n", UNCACHED_ID, ret); misc_deregister(&cached_miscdev); if (is_sn2) misc_deregister(&fetchop_miscdev); goto free_scratch_pages; } printk(KERN_INFO "%s %s initialized devices: %s %s %s\n", MSPEC_BASENAME, REVISION, is_sn2 ? FETCHOP_ID : "", CACHED_ID, UNCACHED_ID); return 0; free_scratch_pages: for_each_node(nid) { if (scratch_page[nid] != 0) uncached_free_page(scratch_page[nid], 1); } return ret; } static void __exit mspec_exit(void) { int nid; misc_deregister(&uncached_miscdev); misc_deregister(&cached_miscdev); if (is_sn2) { misc_deregister(&fetchop_miscdev); for_each_node(nid) { if (scratch_page[nid] != 0) uncached_free_page(scratch_page[nid], 1); } } } module_init(mspec_init); module_exit(mspec_exit); MODULE_AUTHOR("Silicon Graphics, Inc. <linux-altix@sgi.com>"); MODULE_DESCRIPTION("Driver for SGI SN special memory operations"); MODULE_LICENSE("GPL");
gpl-2.0
MyAOSP/kernel_asus_tf201
drivers/media/video/gspca/m5602/m5602_ov7660.c
3135
11578
/* * Driver for the ov7660 sensor * * Copyright (C) 2009 Erik Andrén * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project. * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br> * * Portions of code to USB interface and ALi driver software, * Copyright (c) 2006 Willem Duinker * v4l2 interface modeled after the V4L2 driver * for SN9C10x PC Camera Controllers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. * */ #include "m5602_ov7660.h" static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val); static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val); static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val); static int ov7660_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_auto_exposure(struct gspca_dev *gspca_dev, __s32 val); static int ov7660_get_hflip(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val); static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val); static const struct ctrl ov7660_ctrls[] = { #define GAIN_IDX 1 { { .id = V4L2_CID_GAIN, .type = V4L2_CTRL_TYPE_INTEGER, .name = "gain", .minimum = 0x00, .maximum = 0xff, .step = 0x1, .default_value = OV7660_DEFAULT_GAIN, .flags = V4L2_CTRL_FLAG_SLIDER }, .set = ov7660_set_gain, .get = ov7660_get_gain }, #define BLUE_BALANCE_IDX 2 #define RED_BALANCE_IDX 3 #define AUTO_WHITE_BALANCE_IDX 4 { { .id = V4L2_CID_AUTO_WHITE_BALANCE, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "auto white balance", .minimum = 0, .maximum = 1, .step = 1, .default_value = 1 }, .set = ov7660_set_auto_white_balance, .get = ov7660_get_auto_white_balance }, #define AUTO_GAIN_CTRL_IDX 5 { { .id = V4L2_CID_AUTOGAIN, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "auto gain control", .minimum = 0, .maximum = 1, .step = 1, .default_value = 1 }, .set = ov7660_set_auto_gain, .get = ov7660_get_auto_gain }, #define AUTO_EXPOSURE_IDX 6 { { .id = V4L2_CID_EXPOSURE_AUTO, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "auto exposure", .minimum = 0, .maximum = 1, .step = 1, .default_value = 1 }, .set = ov7660_set_auto_exposure, .get = ov7660_get_auto_exposure }, #define HFLIP_IDX 7 { { .id = V4L2_CID_HFLIP, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "horizontal flip", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0 }, .set = ov7660_set_hflip, .get = ov7660_get_hflip }, #define VFLIP_IDX 8 { { .id = V4L2_CID_VFLIP, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "vertical flip", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0 }, .set = ov7660_set_vflip, .get = ov7660_get_vflip }, }; static struct v4l2_pix_format ov7660_modes[] = { { 640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, .sizeimage = 640 * 480, .bytesperline = 640, .colorspace = V4L2_COLORSPACE_SRGB, .priv = 0 } }; static void ov7660_dump_registers(struct sd *sd); int ov7660_probe(struct sd *sd) { int err = 0, i; u8 prod_id = 0, ver_id = 0; s32 *sensor_settings; if (force_sensor) { if (force_sensor == OV7660_SENSOR) { info("Forcing an %s sensor", ov7660.name); goto sensor_found; } /* If we want to force another sensor, don't try to probe this one */ return -ENODEV; } /* Do the preinit */ for (i = 0; i < ARRAY_SIZE(preinit_ov7660) && !err; i++) { u8 data[2]; if (preinit_ov7660[i][0] == BRIDGE) { err = m5602_write_bridge(sd, preinit_ov7660[i][1], preinit_ov7660[i][2]); } else { data[0] = preinit_ov7660[i][2]; err = m5602_write_sensor(sd, preinit_ov7660[i][1], data, 1); } } if (err < 0) return err; if (m5602_read_sensor(sd, OV7660_PID, &prod_id, 1)) return -ENODEV; if (m5602_read_sensor(sd, OV7660_VER, &ver_id, 1)) return -ENODEV; info("Sensor reported 0x%x%x", prod_id, ver_id); if ((prod_id == 0x76) && (ver_id == 0x60)) { info("Detected a ov7660 sensor"); goto sensor_found; } return -ENODEV; sensor_found: sensor_settings = kmalloc( ARRAY_SIZE(ov7660_ctrls) * sizeof(s32), GFP_KERNEL); if (!sensor_settings) return -ENOMEM; sd->gspca_dev.cam.cam_mode = ov7660_modes; sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov7660_modes); sd->desc->ctrls = ov7660_ctrls; sd->desc->nctrls = ARRAY_SIZE(ov7660_ctrls); for (i = 0; i < ARRAY_SIZE(ov7660_ctrls); i++) sensor_settings[i] = ov7660_ctrls[i].qctrl.default_value; sd->sensor_priv = sensor_settings; return 0; } int ov7660_init(struct sd *sd) { int i, err = 0; s32 *sensor_settings = sd->sensor_priv; /* Init the sensor */ for (i = 0; i < ARRAY_SIZE(init_ov7660); i++) { u8 data[2]; if (init_ov7660[i][0] == BRIDGE) { err = m5602_write_bridge(sd, init_ov7660[i][1], init_ov7660[i][2]); } else { data[0] = init_ov7660[i][2]; err = m5602_write_sensor(sd, init_ov7660[i][1], data, 1); } } if (dump_sensor) ov7660_dump_registers(sd); err = ov7660_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); if (err < 0) return err; err = ov7660_set_auto_white_balance(&sd->gspca_dev, sensor_settings[AUTO_WHITE_BALANCE_IDX]); if (err < 0) return err; err = ov7660_set_auto_gain(&sd->gspca_dev, sensor_settings[AUTO_GAIN_CTRL_IDX]); if (err < 0) return err; err = ov7660_set_auto_exposure(&sd->gspca_dev, sensor_settings[AUTO_EXPOSURE_IDX]); if (err < 0) return err; err = ov7660_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]); if (err < 0) return err; err = ov7660_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); return err; } int ov7660_start(struct sd *sd) { return 0; } int ov7660_stop(struct sd *sd) { return 0; } void ov7660_disconnect(struct sd *sd) { ov7660_stop(sd); sd->sensor = NULL; kfree(sd->sensor_priv); } static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[GAIN_IDX]; PDEBUG(D_V4L2, "Read gain %d", *val); return 0; } static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Setting gain to %d", val); sensor_settings[GAIN_IDX] = val; err = m5602_write_sensor(sd, OV7660_GAIN, &i2c_data, 1); return err; } static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[AUTO_WHITE_BALANCE_IDX]; return 0; } static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set auto white balance to %d", val); sensor_settings[AUTO_WHITE_BALANCE_IDX] = val; err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); if (err < 0) return err; i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1)); err = m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); return err; } static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[AUTO_GAIN_CTRL_IDX]; PDEBUG(D_V4L2, "Read auto gain control %d", *val); return 0; } static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set auto gain control to %d", val); sensor_settings[AUTO_GAIN_CTRL_IDX] = val; err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); if (err < 0) return err; i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2)); return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); } static int ov7660_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[AUTO_EXPOSURE_IDX]; PDEBUG(D_V4L2, "Read auto exposure control %d", *val); return 0; } static int ov7660_set_auto_exposure(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set auto exposure control to %d", val); sensor_settings[AUTO_EXPOSURE_IDX] = val; err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); if (err < 0) return err; i2c_data = ((i2c_data & 0xfe) | ((val & 0x01) << 0)); return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); } static int ov7660_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[HFLIP_IDX]; PDEBUG(D_V4L2, "Read horizontal flip %d", *val); return 0; } static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set horizontal flip to %d", val); sensor_settings[HFLIP_IDX] = val; i2c_data = ((val & 0x01) << 5) | (sensor_settings[VFLIP_IDX] << 4); err = m5602_write_sensor(sd, OV7660_MVFP, &i2c_data, 1); return err; } static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[VFLIP_IDX]; PDEBUG(D_V4L2, "Read vertical flip %d", *val); return 0; } static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 i2c_data; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set vertical flip to %d", val); sensor_settings[VFLIP_IDX] = val; i2c_data = ((val & 0x01) << 4) | (sensor_settings[VFLIP_IDX] << 5); err = m5602_write_sensor(sd, OV7660_MVFP, &i2c_data, 1); if (err < 0) return err; /* When vflip is toggled we need to readjust the bridge hsync/vsync */ if (gspca_dev->streaming) err = ov7660_start(sd); return err; } static void ov7660_dump_registers(struct sd *sd) { int address; info("Dumping the ov7660 register state"); for (address = 0; address < 0xa9; address++) { u8 value; m5602_read_sensor(sd, address, &value, 1); info("register 0x%x contains 0x%x", address, value); } info("ov7660 register state dump complete"); info("Probing for which registers that are read/write"); for (address = 0; address < 0xff; address++) { u8 old_value, ctrl_value; u8 test_value[2] = {0xff, 0xff}; m5602_read_sensor(sd, address, &old_value, 1); m5602_write_sensor(sd, address, test_value, 1); m5602_read_sensor(sd, address, &ctrl_value, 1); if (ctrl_value == test_value[0]) info("register 0x%x is writeable", address); else info("register 0x%x is read only", address); /* Restore original value */ m5602_write_sensor(sd, address, &old_value, 1); } }
gpl-2.0
lll-project/kernel
drivers/media/video/gspca/m5602/m5602_mt9m111.c
3135
16512
/* * Driver for the mt9m111 sensor * * Copyright (C) 2008 Erik Andrén * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project. * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br> * * Portions of code to USB interface and ALi driver software, * Copyright (c) 2006 Willem Duinker * v4l2 interface modeled after the V4L2 driver * for SN9C10x PC Camera Controllers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. * */ #include "m5602_mt9m111.h" static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val); static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val); static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val); static struct v4l2_pix_format mt9m111_modes[] = { { 640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, .sizeimage = 640 * 480, .bytesperline = 640, .colorspace = V4L2_COLORSPACE_SRGB, .priv = 0 } }; static const struct ctrl mt9m111_ctrls[] = { #define VFLIP_IDX 0 { { .id = V4L2_CID_VFLIP, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "vertical flip", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0 }, .set = mt9m111_set_vflip, .get = mt9m111_get_vflip }, #define HFLIP_IDX 1 { { .id = V4L2_CID_HFLIP, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "horizontal flip", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0 }, .set = mt9m111_set_hflip, .get = mt9m111_get_hflip }, #define GAIN_IDX 2 { { .id = V4L2_CID_GAIN, .type = V4L2_CTRL_TYPE_INTEGER, .name = "gain", .minimum = 0, .maximum = (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2, .step = 1, .default_value = MT9M111_DEFAULT_GAIN, .flags = V4L2_CTRL_FLAG_SLIDER }, .set = mt9m111_set_gain, .get = mt9m111_get_gain }, #define AUTO_WHITE_BALANCE_IDX 3 { { .id = V4L2_CID_AUTO_WHITE_BALANCE, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "auto white balance", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0, }, .set = mt9m111_set_auto_white_balance, .get = mt9m111_get_auto_white_balance }, #define GREEN_BALANCE_IDX 4 { { .id = M5602_V4L2_CID_GREEN_BALANCE, .type = V4L2_CTRL_TYPE_INTEGER, .name = "green balance", .minimum = 0x00, .maximum = 0x7ff, .step = 0x1, .default_value = MT9M111_GREEN_GAIN_DEFAULT, .flags = V4L2_CTRL_FLAG_SLIDER }, .set = mt9m111_set_green_balance, .get = mt9m111_get_green_balance }, #define BLUE_BALANCE_IDX 5 { { .id = V4L2_CID_BLUE_BALANCE, .type = V4L2_CTRL_TYPE_INTEGER, .name = "blue balance", .minimum = 0x00, .maximum = 0x7ff, .step = 0x1, .default_value = MT9M111_BLUE_GAIN_DEFAULT, .flags = V4L2_CTRL_FLAG_SLIDER }, .set = mt9m111_set_blue_balance, .get = mt9m111_get_blue_balance }, #define RED_BALANCE_IDX 5 { { .id = V4L2_CID_RED_BALANCE, .type = V4L2_CTRL_TYPE_INTEGER, .name = "red balance", .minimum = 0x00, .maximum = 0x7ff, .step = 0x1, .default_value = MT9M111_RED_GAIN_DEFAULT, .flags = V4L2_CTRL_FLAG_SLIDER }, .set = mt9m111_set_red_balance, .get = mt9m111_get_red_balance }, }; static void mt9m111_dump_registers(struct sd *sd); int mt9m111_probe(struct sd *sd) { u8 data[2] = {0x00, 0x00}; int i; s32 *sensor_settings; if (force_sensor) { if (force_sensor == MT9M111_SENSOR) { info("Forcing a %s sensor", mt9m111.name); goto sensor_found; } /* If we want to force another sensor, don't try to probe this * one */ return -ENODEV; } PDEBUG(D_PROBE, "Probing for a mt9m111 sensor"); /* Do the preinit */ for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) { if (preinit_mt9m111[i][0] == BRIDGE) { m5602_write_bridge(sd, preinit_mt9m111[i][1], preinit_mt9m111[i][2]); } else { data[0] = preinit_mt9m111[i][2]; data[1] = preinit_mt9m111[i][3]; m5602_write_sensor(sd, preinit_mt9m111[i][1], data, 2); } } if (m5602_read_sensor(sd, MT9M111_SC_CHIPVER, data, 2)) return -ENODEV; if ((data[0] == 0x14) && (data[1] == 0x3a)) { info("Detected a mt9m111 sensor"); goto sensor_found; } return -ENODEV; sensor_found: sensor_settings = kmalloc(ARRAY_SIZE(mt9m111_ctrls) * sizeof(s32), GFP_KERNEL); if (!sensor_settings) return -ENOMEM; sd->gspca_dev.cam.cam_mode = mt9m111_modes; sd->gspca_dev.cam.nmodes = ARRAY_SIZE(mt9m111_modes); sd->desc->ctrls = mt9m111_ctrls; sd->desc->nctrls = ARRAY_SIZE(mt9m111_ctrls); for (i = 0; i < ARRAY_SIZE(mt9m111_ctrls); i++) sensor_settings[i] = mt9m111_ctrls[i].qctrl.default_value; sd->sensor_priv = sensor_settings; return 0; } int mt9m111_init(struct sd *sd) { int i, err = 0; s32 *sensor_settings = sd->sensor_priv; /* Init the sensor */ for (i = 0; i < ARRAY_SIZE(init_mt9m111) && !err; i++) { u8 data[2]; if (init_mt9m111[i][0] == BRIDGE) { err = m5602_write_bridge(sd, init_mt9m111[i][1], init_mt9m111[i][2]); } else { data[0] = init_mt9m111[i][2]; data[1] = init_mt9m111[i][3]; err = m5602_write_sensor(sd, init_mt9m111[i][1], data, 2); } } if (dump_sensor) mt9m111_dump_registers(sd); err = mt9m111_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); if (err < 0) return err; err = mt9m111_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]); if (err < 0) return err; err = mt9m111_set_green_balance(&sd->gspca_dev, sensor_settings[GREEN_BALANCE_IDX]); if (err < 0) return err; err = mt9m111_set_blue_balance(&sd->gspca_dev, sensor_settings[BLUE_BALANCE_IDX]); if (err < 0) return err; err = mt9m111_set_red_balance(&sd->gspca_dev, sensor_settings[RED_BALANCE_IDX]); if (err < 0) return err; return mt9m111_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); } int mt9m111_start(struct sd *sd) { int i, err = 0; u8 data[2]; struct cam *cam = &sd->gspca_dev.cam; s32 *sensor_settings = sd->sensor_priv; int width = cam->cam_mode[sd->gspca_dev.curr_mode].width - 1; int height = cam->cam_mode[sd->gspca_dev.curr_mode].height; for (i = 0; i < ARRAY_SIZE(start_mt9m111) && !err; i++) { if (start_mt9m111[i][0] == BRIDGE) { err = m5602_write_bridge(sd, start_mt9m111[i][1], start_mt9m111[i][2]); } else { data[0] = start_mt9m111[i][2]; data[1] = start_mt9m111[i][3]; err = m5602_write_sensor(sd, start_mt9m111[i][1], data, 2); } } if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, (height >> 8) & 0xff); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, (height & 0xff)); if (err < 0) return err; for (i = 0; i < 2 && !err; i++) err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, 0); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 0); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 2); if (err < 0) return err; for (i = 0; i < 2 && !err; i++) err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA, 0); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA, (width >> 8) & 0xff); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA, width & 0xff); if (err < 0) return err; err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 0); if (err < 0) return err; switch (width) { case 640: PDEBUG(D_V4L2, "Configuring camera for VGA mode"); data[0] = MT9M111_RMB_OVER_SIZED; data[1] = MT9M111_RMB_ROW_SKIP_2X | MT9M111_RMB_COLUMN_SKIP_2X | (sensor_settings[VFLIP_IDX] << 0) | (sensor_settings[HFLIP_IDX] << 1); err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); break; case 320: PDEBUG(D_V4L2, "Configuring camera for QVGA mode"); data[0] = MT9M111_RMB_OVER_SIZED; data[1] = MT9M111_RMB_ROW_SKIP_4X | MT9M111_RMB_COLUMN_SKIP_4X | (sensor_settings[VFLIP_IDX] << 0) | (sensor_settings[HFLIP_IDX] << 1); err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); break; } return err; } void mt9m111_disconnect(struct sd *sd) { sd->sensor = NULL; kfree(sd->sensor_priv); } static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[VFLIP_IDX]; PDEBUG(D_V4L2, "Read vertical flip %d", *val); return 0; } static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[2] = {0x00, 0x00}; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set vertical flip to %d", val); sensor_settings[VFLIP_IDX] = val; /* The mt9m111 is flipped by default */ val = !val; /* Set the correct page map */ err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); if (err < 0) return err; err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); if (err < 0) return err; data[1] = (data[1] & 0xfe) | val; err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); return err; } static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[HFLIP_IDX]; PDEBUG(D_V4L2, "Read horizontal flip %d", *val); return 0; } static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[2] = {0x00, 0x00}; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; PDEBUG(D_V4L2, "Set horizontal flip to %d", val); sensor_settings[HFLIP_IDX] = val; /* The mt9m111 is flipped by default */ val = !val; /* Set the correct page map */ err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); if (err < 0) return err; err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); if (err < 0) return err; data[1] = (data[1] & 0xfd) | ((val << 1) & 0x02); err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); return err; } static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[GAIN_IDX]; PDEBUG(D_V4L2, "Read gain %d", *val); return 0; } static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; int err; u8 data[2]; err = m5602_read_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2); if (err < 0) return err; sensor_settings[AUTO_WHITE_BALANCE_IDX] = val & 0x01; data[1] = ((data[1] & 0xfd) | ((val & 0x01) << 1)); err = m5602_write_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2); PDEBUG(D_V4L2, "Set auto white balance %d", val); return err; } static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[AUTO_WHITE_BALANCE_IDX]; PDEBUG(D_V4L2, "Read auto white balance %d", *val); return 0; } static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val) { int err, tmp; u8 data[2] = {0x00, 0x00}; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; sensor_settings[GAIN_IDX] = val; /* Set the correct page map */ err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); if (err < 0) return err; if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2) return -EINVAL; if ((val >= INITIAL_MAX_GAIN * 2 * 2) && (val < (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2)) tmp = (1 << 10) | (val << 9) | (val << 8) | (val / 8); else if ((val >= INITIAL_MAX_GAIN * 2) && (val < INITIAL_MAX_GAIN * 2 * 2)) tmp = (1 << 9) | (1 << 8) | (val / 4); else if ((val >= INITIAL_MAX_GAIN) && (val < INITIAL_MAX_GAIN * 2)) tmp = (1 << 8) | (val / 2); else tmp = val; data[1] = (tmp & 0xff); data[0] = (tmp & 0xff00) >> 8; PDEBUG(D_V4L2, "tmp=%d, data[1]=%d, data[0]=%d", tmp, data[1], data[0]); err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN, data, 2); return err; } static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val) { int err; u8 data[2]; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; sensor_settings[GREEN_BALANCE_IDX] = val; data[1] = (val & 0xff); data[0] = (val & 0xff00) >> 8; PDEBUG(D_V4L2, "Set green balance %d", val); err = m5602_write_sensor(sd, MT9M111_SC_GREEN_1_GAIN, data, 2); if (err < 0) return err; return m5602_write_sensor(sd, MT9M111_SC_GREEN_2_GAIN, data, 2); } static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[GREEN_BALANCE_IDX]; PDEBUG(D_V4L2, "Read green balance %d", *val); return 0; } static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) { u8 data[2]; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; sensor_settings[BLUE_BALANCE_IDX] = val; data[1] = (val & 0xff); data[0] = (val & 0xff00) >> 8; PDEBUG(D_V4L2, "Set blue balance %d", val); return m5602_write_sensor(sd, MT9M111_SC_BLUE_GAIN, data, 2); } static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[BLUE_BALANCE_IDX]; PDEBUG(D_V4L2, "Read blue balance %d", *val); return 0; } static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) { u8 data[2]; struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; sensor_settings[RED_BALANCE_IDX] = val; data[1] = (val & 0xff); data[0] = (val & 0xff00) >> 8; PDEBUG(D_V4L2, "Set red balance %d", val); return m5602_write_sensor(sd, MT9M111_SC_RED_GAIN, data, 2); } static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val) { struct sd *sd = (struct sd *) gspca_dev; s32 *sensor_settings = sd->sensor_priv; *val = sensor_settings[RED_BALANCE_IDX]; PDEBUG(D_V4L2, "Read red balance %d", *val); return 0; } static void mt9m111_dump_registers(struct sd *sd) { u8 address, value[2] = {0x00, 0x00}; info("Dumping the mt9m111 register state"); info("Dumping the mt9m111 sensor core registers"); value[1] = MT9M111_SENSOR_CORE; m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2); for (address = 0; address < 0xff; address++) { m5602_read_sensor(sd, address, value, 2); info("register 0x%x contains 0x%x%x", address, value[0], value[1]); } info("Dumping the mt9m111 color pipeline registers"); value[1] = MT9M111_COLORPIPE; m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2); for (address = 0; address < 0xff; address++) { m5602_read_sensor(sd, address, value, 2); info("register 0x%x contains 0x%x%x", address, value[0], value[1]); } info("Dumping the mt9m111 camera control registers"); value[1] = MT9M111_CAMERA_CONTROL; m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2); for (address = 0; address < 0xff; address++) { m5602_read_sensor(sd, address, value, 2); info("register 0x%x contains 0x%x%x", address, value[0], value[1]); } info("mt9m111 register state dump complete"); }
gpl-2.0
civato/V30B-SithLord
drivers/s390/crypto/zcrypt_mono.c
4415
2270
/* * linux/drivers/s390/crypto/zcrypt_mono.c * * zcrypt 2.1.0 * * Copyright (C) 2001, 2006 IBM Corporation * Author(s): Robert Burroughs * Eric Rossman (edrossma@us.ibm.com) * * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/miscdevice.h> #include <linux/fs.h> #include <linux/proc_fs.h> #include <linux/compat.h> #include <asm/atomic.h> #include <asm/uaccess.h> #include "ap_bus.h" #include "zcrypt_api.h" #include "zcrypt_pcica.h" #include "zcrypt_pcicc.h" #include "zcrypt_pcixcc.h" #include "zcrypt_cex2a.h" /** * The module initialization code. */ static int __init zcrypt_init(void) { int rc; rc = ap_module_init(); if (rc) goto out; rc = zcrypt_api_init(); if (rc) goto out_ap; rc = zcrypt_pcica_init(); if (rc) goto out_api; rc = zcrypt_pcicc_init(); if (rc) goto out_pcica; rc = zcrypt_pcixcc_init(); if (rc) goto out_pcicc; rc = zcrypt_cex2a_init(); if (rc) goto out_pcixcc; return 0; out_pcixcc: zcrypt_pcixcc_exit(); out_pcicc: zcrypt_pcicc_exit(); out_pcica: zcrypt_pcica_exit(); out_api: zcrypt_api_exit(); out_ap: ap_module_exit(); out: return rc; } /** * The module termination code. */ static void __exit zcrypt_exit(void) { zcrypt_cex2a_exit(); zcrypt_pcixcc_exit(); zcrypt_pcicc_exit(); zcrypt_pcica_exit(); zcrypt_api_exit(); ap_module_exit(); } module_init(zcrypt_init); module_exit(zcrypt_exit);
gpl-2.0
RyanAM/gs5-kernel
drivers/net/hamradio/6pack.c
4927
25182
/* * 6pack.c This module implements the 6pack protocol for kernel-based * devices like TTY. It interfaces between a raw TTY and the * kernel's AX.25 protocol layers. * * Authors: Andreas Könsgen <ajk@comnets.uni-bremen.de> * Ralf Baechle DL5RB <ralf@linux-mips.org> * * Quite a lot of stuff "stolen" by Joerg Reuter from slip.c, written by * * Laurence Culhane, <loz@holmes.demon.co.uk> * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> */ #include <linux/module.h> #include <asm/uaccess.h> #include <linux/bitops.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/in.h> #include <linux/tty.h> #include <linux/errno.h> #include <linux/netdevice.h> #include <linux/timer.h> #include <linux/slab.h> #include <net/ax25.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/rtnetlink.h> #include <linux/spinlock.h> #include <linux/if_arp.h> #include <linux/init.h> #include <linux/ip.h> #include <linux/tcp.h> #include <linux/semaphore.h> #include <linux/compat.h> #include <linux/atomic.h> #define SIXPACK_VERSION "Revision: 0.3.0" /* sixpack priority commands */ #define SIXP_SEOF 0x40 /* start and end of a 6pack frame */ #define SIXP_TX_URUN 0x48 /* transmit overrun */ #define SIXP_RX_ORUN 0x50 /* receive overrun */ #define SIXP_RX_BUF_OVL 0x58 /* receive buffer overflow */ #define SIXP_CHKSUM 0xFF /* valid checksum of a 6pack frame */ /* masks to get certain bits out of the status bytes sent by the TNC */ #define SIXP_CMD_MASK 0xC0 #define SIXP_CHN_MASK 0x07 #define SIXP_PRIO_CMD_MASK 0x80 #define SIXP_STD_CMD_MASK 0x40 #define SIXP_PRIO_DATA_MASK 0x38 #define SIXP_TX_MASK 0x20 #define SIXP_RX_MASK 0x10 #define SIXP_RX_DCD_MASK 0x18 #define SIXP_LEDS_ON 0x78 #define SIXP_LEDS_OFF 0x60 #define SIXP_CON 0x08 #define SIXP_STA 0x10 #define SIXP_FOUND_TNC 0xe9 #define SIXP_CON_ON 0x68 #define SIXP_DCD_MASK 0x08 #define SIXP_DAMA_OFF 0 /* default level 2 parameters */ #define SIXP_TXDELAY (HZ/4) /* in 1 s */ #define SIXP_PERSIST 50 /* in 256ths */ #define SIXP_SLOTTIME (HZ/10) /* in 1 s */ #define SIXP_INIT_RESYNC_TIMEOUT (3*HZ/2) /* in 1 s */ #define SIXP_RESYNC_TIMEOUT 5*HZ /* in 1 s */ /* 6pack configuration. */ #define SIXP_NRUNIT 31 /* MAX number of 6pack channels */ #define SIXP_MTU 256 /* Default MTU */ enum sixpack_flags { SIXPF_ERROR, /* Parity, etc. error */ }; struct sixpack { /* Various fields. */ struct tty_struct *tty; /* ptr to TTY structure */ struct net_device *dev; /* easy for intr handling */ /* These are pointers to the malloc()ed frame buffers. */ unsigned char *rbuff; /* receiver buffer */ int rcount; /* received chars counter */ unsigned char *xbuff; /* transmitter buffer */ unsigned char *xhead; /* next byte to XMIT */ int xleft; /* bytes left in XMIT queue */ unsigned char raw_buf[4]; unsigned char cooked_buf[400]; unsigned int rx_count; unsigned int rx_count_cooked; int mtu; /* Our mtu (to spot changes!) */ int buffsize; /* Max buffers sizes */ unsigned long flags; /* Flag values/ mode etc */ unsigned char mode; /* 6pack mode */ /* 6pack stuff */ unsigned char tx_delay; unsigned char persistence; unsigned char slottime; unsigned char duplex; unsigned char led_state; unsigned char status; unsigned char status1; unsigned char status2; unsigned char tx_enable; unsigned char tnc_state; struct timer_list tx_t; struct timer_list resync_t; atomic_t refcnt; struct semaphore dead_sem; spinlock_t lock; }; #define AX25_6PACK_HEADER_LEN 0 static void sixpack_decode(struct sixpack *, unsigned char[], int); static int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char); /* * Perform the persistence/slottime algorithm for CSMA access. If the * persistence check was successful, write the data to the serial driver. * Note that in case of DAMA operation, the data is not sent here. */ static void sp_xmit_on_air(unsigned long channel) { struct sixpack *sp = (struct sixpack *) channel; int actual, when = sp->slottime; static unsigned char random; random = random * 17 + 41; if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) { sp->led_state = 0x70; sp->tty->ops->write(sp->tty, &sp->led_state, 1); sp->tx_enable = 1; actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); sp->xleft -= actual; sp->xhead += actual; sp->led_state = 0x60; sp->tty->ops->write(sp->tty, &sp->led_state, 1); sp->status2 = 0; } else mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100); } /* ----> 6pack timer interrupt handler and friends. <---- */ /* Encapsulate one AX.25 frame and stuff into a TTY queue. */ static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len) { unsigned char *msg, *p = icp; int actual, count; if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */ msg = "oversized transmit packet!"; goto out_drop; } if (len > sp->mtu) { /* sp->mtu = AX25_MTU = max. PACLEN = 256 */ msg = "oversized transmit packet!"; goto out_drop; } if (p[0] > 5) { msg = "invalid KISS command"; goto out_drop; } if ((p[0] != 0) && (len > 2)) { msg = "KISS control packet too long"; goto out_drop; } if ((p[0] == 0) && (len < 15)) { msg = "bad AX.25 packet to transmit"; goto out_drop; } count = encode_sixpack(p, sp->xbuff, len, sp->tx_delay); set_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags); switch (p[0]) { case 1: sp->tx_delay = p[1]; return; case 2: sp->persistence = p[1]; return; case 3: sp->slottime = p[1]; return; case 4: /* ignored */ return; case 5: sp->duplex = p[1]; return; } if (p[0] != 0) return; /* * In case of fullduplex or DAMA operation, we don't take care about the * state of the DCD or of any timers, as the determination of the * correct time to send is the job of the AX.25 layer. We send * immediately after data has arrived. */ if (sp->duplex == 1) { sp->led_state = 0x70; sp->tty->ops->write(sp->tty, &sp->led_state, 1); sp->tx_enable = 1; actual = sp->tty->ops->write(sp->tty, sp->xbuff, count); sp->xleft = count - actual; sp->xhead = sp->xbuff + actual; sp->led_state = 0x60; sp->tty->ops->write(sp->tty, &sp->led_state, 1); } else { sp->xleft = count; sp->xhead = sp->xbuff; sp->status2 = count; sp_xmit_on_air((unsigned long)sp); } return; out_drop: sp->dev->stats.tx_dropped++; netif_start_queue(sp->dev); if (net_ratelimit()) printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg); } /* Encapsulate an IP datagram and kick it into a TTY queue. */ static netdev_tx_t sp_xmit(struct sk_buff *skb, struct net_device *dev) { struct sixpack *sp = netdev_priv(dev); spin_lock_bh(&sp->lock); /* We were not busy, so we are now... :-) */ netif_stop_queue(dev); dev->stats.tx_bytes += skb->len; sp_encaps(sp, skb->data, skb->len); spin_unlock_bh(&sp->lock); dev_kfree_skb(skb); return NETDEV_TX_OK; } static int sp_open_dev(struct net_device *dev) { struct sixpack *sp = netdev_priv(dev); if (sp->tty == NULL) return -ENODEV; return 0; } /* Close the low-level part of the 6pack channel. */ static int sp_close(struct net_device *dev) { struct sixpack *sp = netdev_priv(dev); spin_lock_bh(&sp->lock); if (sp->tty) { /* TTY discipline is running. */ clear_bit(TTY_DO_WRITE_WAKEUP, &sp->tty->flags); } netif_stop_queue(dev); spin_unlock_bh(&sp->lock); return 0; } /* Return the frame type ID */ static int sp_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, const void *daddr, const void *saddr, unsigned len) { #ifdef CONFIG_INET if (type != ETH_P_AX25) return ax25_hard_header(skb, dev, type, daddr, saddr, len); #endif return 0; } static int sp_set_mac_address(struct net_device *dev, void *addr) { struct sockaddr_ax25 *sa = addr; netif_tx_lock_bh(dev); netif_addr_lock(dev); memcpy(dev->dev_addr, &sa->sax25_call, AX25_ADDR_LEN); netif_addr_unlock(dev); netif_tx_unlock_bh(dev); return 0; } static int sp_rebuild_header(struct sk_buff *skb) { #ifdef CONFIG_INET return ax25_rebuild_header(skb); #else return 0; #endif } static const struct header_ops sp_header_ops = { .create = sp_header, .rebuild = sp_rebuild_header, }; static const struct net_device_ops sp_netdev_ops = { .ndo_open = sp_open_dev, .ndo_stop = sp_close, .ndo_start_xmit = sp_xmit, .ndo_set_mac_address = sp_set_mac_address, }; static void sp_setup(struct net_device *dev) { /* Finish setting up the DEVICE info. */ dev->netdev_ops = &sp_netdev_ops; dev->destructor = free_netdev; dev->mtu = SIXP_MTU; dev->hard_header_len = AX25_MAX_HEADER_LEN; dev->header_ops = &sp_header_ops; dev->addr_len = AX25_ADDR_LEN; dev->type = ARPHRD_AX25; dev->tx_queue_len = 10; /* Only activated in AX.25 mode */ memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN); memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN); dev->flags = 0; } /* Send one completely decapsulated IP datagram to the IP layer. */ /* * This is the routine that sends the received data to the kernel AX.25. * 'cmd' is the KISS command. For AX.25 data, it is zero. */ static void sp_bump(struct sixpack *sp, char cmd) { struct sk_buff *skb; int count; unsigned char *ptr; count = sp->rcount + 1; sp->dev->stats.rx_bytes += count; if ((skb = dev_alloc_skb(count)) == NULL) goto out_mem; ptr = skb_put(skb, count); *ptr++ = cmd; /* KISS command */ memcpy(ptr, sp->cooked_buf + 1, count); skb->protocol = ax25_type_trans(skb, sp->dev); netif_rx(skb); sp->dev->stats.rx_packets++; return; out_mem: sp->dev->stats.rx_dropped++; } /* ----------------------------------------------------------------------- */ /* * We have a potential race on dereferencing tty->disc_data, because the tty * layer provides no locking at all - thus one cpu could be running * sixpack_receive_buf while another calls sixpack_close, which zeroes * tty->disc_data and frees the memory that sixpack_receive_buf is using. The * best way to fix this is to use a rwlock in the tty struct, but for now we * use a single global rwlock for all ttys in ppp line discipline. */ static DEFINE_RWLOCK(disc_data_lock); static struct sixpack *sp_get(struct tty_struct *tty) { struct sixpack *sp; read_lock(&disc_data_lock); sp = tty->disc_data; if (sp) atomic_inc(&sp->refcnt); read_unlock(&disc_data_lock); return sp; } static void sp_put(struct sixpack *sp) { if (atomic_dec_and_test(&sp->refcnt)) up(&sp->dead_sem); } /* * Called by the TTY driver when there's room for more data. If we have * more packets to send, we send them here. */ static void sixpack_write_wakeup(struct tty_struct *tty) { struct sixpack *sp = sp_get(tty); int actual; if (!sp) return; if (sp->xleft <= 0) { /* Now serial buffer is almost free & we can start * transmission of another packet */ sp->dev->stats.tx_packets++; clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); sp->tx_enable = 0; netif_wake_queue(sp->dev); goto out; } if (sp->tx_enable) { actual = tty->ops->write(tty, sp->xhead, sp->xleft); sp->xleft -= actual; sp->xhead += actual; } out: sp_put(sp); } /* ----------------------------------------------------------------------- */ /* * Handle the 'receiver data ready' interrupt. * This function is called by the 'tty_io' module in the kernel when * a block of 6pack data has been received, which can now be decapsulated * and sent on to some IP layer for further processing. */ static void sixpack_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) { struct sixpack *sp; unsigned char buf[512]; int count1; if (!count) return; sp = sp_get(tty); if (!sp) return; memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf)); /* Read the characters out of the buffer */ count1 = count; while (count) { count--; if (fp && *fp++) { if (!test_and_set_bit(SIXPF_ERROR, &sp->flags)) sp->dev->stats.rx_errors++; continue; } } sixpack_decode(sp, buf, count1); sp_put(sp); tty_unthrottle(tty); } /* * Try to resync the TNC. Called by the resync timer defined in * decode_prio_command */ #define TNC_UNINITIALIZED 0 #define TNC_UNSYNC_STARTUP 1 #define TNC_UNSYNCED 2 #define TNC_IN_SYNC 3 static void __tnc_set_sync_state(struct sixpack *sp, int new_tnc_state) { char *msg; switch (new_tnc_state) { default: /* gcc oh piece-o-crap ... */ case TNC_UNSYNC_STARTUP: msg = "Synchronizing with TNC"; break; case TNC_UNSYNCED: msg = "Lost synchronization with TNC\n"; break; case TNC_IN_SYNC: msg = "Found TNC"; break; } sp->tnc_state = new_tnc_state; printk(KERN_INFO "%s: %s\n", sp->dev->name, msg); } static inline void tnc_set_sync_state(struct sixpack *sp, int new_tnc_state) { int old_tnc_state = sp->tnc_state; if (old_tnc_state != new_tnc_state) __tnc_set_sync_state(sp, new_tnc_state); } static void resync_tnc(unsigned long channel) { struct sixpack *sp = (struct sixpack *) channel; static char resync_cmd = 0xe8; /* clear any data that might have been received */ sp->rx_count = 0; sp->rx_count_cooked = 0; /* reset state machine */ sp->status = 1; sp->status1 = 1; sp->status2 = 0; /* resync the TNC */ sp->led_state = 0x60; sp->tty->ops->write(sp->tty, &sp->led_state, 1); sp->tty->ops->write(sp->tty, &resync_cmd, 1); /* Start resync timer again -- the TNC might be still absent */ del_timer(&sp->resync_t); sp->resync_t.data = (unsigned long) sp; sp->resync_t.function = resync_tnc; sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT; add_timer(&sp->resync_t); } static inline int tnc_init(struct sixpack *sp) { unsigned char inbyte = 0xe8; tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP); sp->tty->ops->write(sp->tty, &inbyte, 1); del_timer(&sp->resync_t); sp->resync_t.data = (unsigned long) sp; sp->resync_t.function = resync_tnc; sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT; add_timer(&sp->resync_t); return 0; } /* * Open the high-level part of the 6pack channel. * This function is called by the TTY module when the * 6pack line discipline is called for. Because we are * sure the tty line exists, we only have to link it to * a free 6pcack channel... */ static int sixpack_open(struct tty_struct *tty) { char *rbuff = NULL, *xbuff = NULL; struct net_device *dev; struct sixpack *sp; unsigned long len; int err = 0; if (!capable(CAP_NET_ADMIN)) return -EPERM; if (tty->ops->write == NULL) return -EOPNOTSUPP; dev = alloc_netdev(sizeof(struct sixpack), "sp%d", sp_setup); if (!dev) { err = -ENOMEM; goto out; } sp = netdev_priv(dev); sp->dev = dev; spin_lock_init(&sp->lock); atomic_set(&sp->refcnt, 1); sema_init(&sp->dead_sem, 0); /* !!! length of the buffers. MTU is IP MTU, not PACLEN! */ len = dev->mtu * 2; rbuff = kmalloc(len + 4, GFP_KERNEL); xbuff = kmalloc(len + 4, GFP_KERNEL); if (rbuff == NULL || xbuff == NULL) { err = -ENOBUFS; goto out_free; } spin_lock_bh(&sp->lock); sp->tty = tty; sp->rbuff = rbuff; sp->xbuff = xbuff; sp->mtu = AX25_MTU + 73; sp->buffsize = len; sp->rcount = 0; sp->rx_count = 0; sp->rx_count_cooked = 0; sp->xleft = 0; sp->flags = 0; /* Clear ESCAPE & ERROR flags */ sp->duplex = 0; sp->tx_delay = SIXP_TXDELAY; sp->persistence = SIXP_PERSIST; sp->slottime = SIXP_SLOTTIME; sp->led_state = 0x60; sp->status = 1; sp->status1 = 1; sp->status2 = 0; sp->tx_enable = 0; netif_start_queue(dev); init_timer(&sp->tx_t); sp->tx_t.function = sp_xmit_on_air; sp->tx_t.data = (unsigned long) sp; init_timer(&sp->resync_t); spin_unlock_bh(&sp->lock); /* Done. We have linked the TTY line to a channel. */ tty->disc_data = sp; tty->receive_room = 65536; /* Now we're ready to register. */ if (register_netdev(dev)) goto out_free; tnc_init(sp); return 0; out_free: kfree(xbuff); kfree(rbuff); if (dev) free_netdev(dev); out: return err; } /* * Close down a 6pack channel. * This means flushing out any pending queues, and then restoring the * TTY line discipline to what it was before it got hooked to 6pack * (which usually is TTY again). */ static void sixpack_close(struct tty_struct *tty) { struct sixpack *sp; write_lock_bh(&disc_data_lock); sp = tty->disc_data; tty->disc_data = NULL; write_unlock_bh(&disc_data_lock); if (!sp) return; /* * We have now ensured that nobody can start using ap from now on, but * we have to wait for all existing users to finish. */ if (!atomic_dec_and_test(&sp->refcnt)) down(&sp->dead_sem); unregister_netdev(sp->dev); del_timer(&sp->tx_t); del_timer(&sp->resync_t); /* Free all 6pack frame buffers. */ kfree(sp->rbuff); kfree(sp->xbuff); } /* Perform I/O control on an active 6pack channel. */ static int sixpack_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct sixpack *sp = sp_get(tty); struct net_device *dev; unsigned int tmp, err; if (!sp) return -ENXIO; dev = sp->dev; switch(cmd) { case SIOCGIFNAME: err = copy_to_user((void __user *) arg, dev->name, strlen(dev->name) + 1) ? -EFAULT : 0; break; case SIOCGIFENCAP: err = put_user(0, (int __user *) arg); break; case SIOCSIFENCAP: if (get_user(tmp, (int __user *) arg)) { err = -EFAULT; break; } sp->mode = tmp; dev->addr_len = AX25_ADDR_LEN; dev->hard_header_len = AX25_KISS_HEADER_LEN + AX25_MAX_HEADER_LEN + 3; dev->type = ARPHRD_AX25; err = 0; break; case SIOCSIFHWADDR: { char addr[AX25_ADDR_LEN]; if (copy_from_user(&addr, (void __user *) arg, AX25_ADDR_LEN)) { err = -EFAULT; break; } netif_tx_lock_bh(dev); memcpy(dev->dev_addr, &addr, AX25_ADDR_LEN); netif_tx_unlock_bh(dev); err = 0; break; } default: err = tty_mode_ioctl(tty, file, cmd, arg); } sp_put(sp); return err; } #ifdef CONFIG_COMPAT static long sixpack_compat_ioctl(struct tty_struct * tty, struct file * file, unsigned int cmd, unsigned long arg) { switch (cmd) { case SIOCGIFNAME: case SIOCGIFENCAP: case SIOCSIFENCAP: case SIOCSIFHWADDR: return sixpack_ioctl(tty, file, cmd, (unsigned long)compat_ptr(arg)); } return -ENOIOCTLCMD; } #endif static struct tty_ldisc_ops sp_ldisc = { .owner = THIS_MODULE, .magic = TTY_LDISC_MAGIC, .name = "6pack", .open = sixpack_open, .close = sixpack_close, .ioctl = sixpack_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = sixpack_compat_ioctl, #endif .receive_buf = sixpack_receive_buf, .write_wakeup = sixpack_write_wakeup, }; /* Initialize 6pack control device -- register 6pack line discipline */ static const char msg_banner[] __initdata = KERN_INFO \ "AX.25: 6pack driver, " SIXPACK_VERSION "\n"; static const char msg_regfail[] __initdata = KERN_ERR \ "6pack: can't register line discipline (err = %d)\n"; static int __init sixpack_init_driver(void) { int status; printk(msg_banner); /* Register the provided line protocol discipline */ if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0) printk(msg_regfail, status); return status; } static const char msg_unregfail[] __exitdata = KERN_ERR \ "6pack: can't unregister line discipline (err = %d)\n"; static void __exit sixpack_exit_driver(void) { int ret; if ((ret = tty_unregister_ldisc(N_6PACK))) printk(msg_unregfail, ret); } /* encode an AX.25 packet into 6pack */ static int encode_sixpack(unsigned char *tx_buf, unsigned char *tx_buf_raw, int length, unsigned char tx_delay) { int count = 0; unsigned char checksum = 0, buf[400]; int raw_count = 0; tx_buf_raw[raw_count++] = SIXP_PRIO_CMD_MASK | SIXP_TX_MASK; tx_buf_raw[raw_count++] = SIXP_SEOF; buf[0] = tx_delay; for (count = 1; count < length; count++) buf[count] = tx_buf[count]; for (count = 0; count < length; count++) checksum += buf[count]; buf[length] = (unsigned char) 0xff - checksum; for (count = 0; count <= length; count++) { if ((count % 3) == 0) { tx_buf_raw[raw_count++] = (buf[count] & 0x3f); tx_buf_raw[raw_count] = ((buf[count] >> 2) & 0x30); } else if ((count % 3) == 1) { tx_buf_raw[raw_count++] |= (buf[count] & 0x0f); tx_buf_raw[raw_count] = ((buf[count] >> 2) & 0x3c); } else { tx_buf_raw[raw_count++] |= (buf[count] & 0x03); tx_buf_raw[raw_count++] = (buf[count] >> 2); } } if ((length % 3) != 2) raw_count++; tx_buf_raw[raw_count++] = SIXP_SEOF; return raw_count; } /* decode 4 sixpack-encoded bytes into 3 data bytes */ static void decode_data(struct sixpack *sp, unsigned char inbyte) { unsigned char *buf; if (sp->rx_count != 3) { sp->raw_buf[sp->rx_count++] = inbyte; return; } buf = sp->raw_buf; sp->cooked_buf[sp->rx_count_cooked++] = buf[0] | ((buf[1] << 2) & 0xc0); sp->cooked_buf[sp->rx_count_cooked++] = (buf[1] & 0x0f) | ((buf[2] << 2) & 0xf0); sp->cooked_buf[sp->rx_count_cooked++] = (buf[2] & 0x03) | (inbyte << 2); sp->rx_count = 0; } /* identify and execute a 6pack priority command byte */ static void decode_prio_command(struct sixpack *sp, unsigned char cmd) { unsigned char channel; int actual; channel = cmd & SIXP_CHN_MASK; if ((cmd & SIXP_PRIO_DATA_MASK) != 0) { /* idle ? */ /* RX and DCD flags can only be set in the same prio command, if the DCD flag has been set without the RX flag in the previous prio command. If DCD has not been set before, something in the transmission has gone wrong. In this case, RX and DCD are cleared in order to prevent the decode_data routine from reading further data that might be corrupt. */ if (((sp->status & SIXP_DCD_MASK) == 0) && ((cmd & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK)) { if (sp->status != 1) printk(KERN_DEBUG "6pack: protocol violation\n"); else sp->status = 0; cmd &= ~SIXP_RX_DCD_MASK; } sp->status = cmd & SIXP_PRIO_DATA_MASK; } else { /* output watchdog char if idle */ if ((sp->status2 != 0) && (sp->duplex == 1)) { sp->led_state = 0x70; sp->tty->ops->write(sp->tty, &sp->led_state, 1); sp->tx_enable = 1; actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); sp->xleft -= actual; sp->xhead += actual; sp->led_state = 0x60; sp->status2 = 0; } } /* needed to trigger the TNC watchdog */ sp->tty->ops->write(sp->tty, &sp->led_state, 1); /* if the state byte has been received, the TNC is present, so the resync timer can be reset. */ if (sp->tnc_state == TNC_IN_SYNC) { del_timer(&sp->resync_t); sp->resync_t.data = (unsigned long) sp; sp->resync_t.function = resync_tnc; sp->resync_t.expires = jiffies + SIXP_INIT_RESYNC_TIMEOUT; add_timer(&sp->resync_t); } sp->status1 = cmd & SIXP_PRIO_DATA_MASK; } /* identify and execute a standard 6pack command byte */ static void decode_std_command(struct sixpack *sp, unsigned char cmd) { unsigned char checksum = 0, rest = 0, channel; short i; channel = cmd & SIXP_CHN_MASK; switch (cmd & SIXP_CMD_MASK) { /* normal command */ case SIXP_SEOF: if ((sp->rx_count == 0) && (sp->rx_count_cooked == 0)) { if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK) { sp->led_state = 0x68; sp->tty->ops->write(sp->tty, &sp->led_state, 1); } } else { sp->led_state = 0x60; /* fill trailing bytes with zeroes */ sp->tty->ops->write(sp->tty, &sp->led_state, 1); rest = sp->rx_count; if (rest != 0) for (i = rest; i <= 3; i++) decode_data(sp, 0); if (rest == 2) sp->rx_count_cooked -= 2; else if (rest == 3) sp->rx_count_cooked -= 1; for (i = 0; i < sp->rx_count_cooked; i++) checksum += sp->cooked_buf[i]; if (checksum != SIXP_CHKSUM) { printk(KERN_DEBUG "6pack: bad checksum %2.2x\n", checksum); } else { sp->rcount = sp->rx_count_cooked-2; sp_bump(sp, 0); } sp->rx_count_cooked = 0; } break; case SIXP_TX_URUN: printk(KERN_DEBUG "6pack: TX underrun\n"); break; case SIXP_RX_ORUN: printk(KERN_DEBUG "6pack: RX overrun\n"); break; case SIXP_RX_BUF_OVL: printk(KERN_DEBUG "6pack: RX buffer overflow\n"); } } /* decode a 6pack packet */ static void sixpack_decode(struct sixpack *sp, unsigned char *pre_rbuff, int count) { unsigned char inbyte; int count1; for (count1 = 0; count1 < count; count1++) { inbyte = pre_rbuff[count1]; if (inbyte == SIXP_FOUND_TNC) { tnc_set_sync_state(sp, TNC_IN_SYNC); del_timer(&sp->resync_t); } if ((inbyte & SIXP_PRIO_CMD_MASK) != 0) decode_prio_command(sp, inbyte); else if ((inbyte & SIXP_STD_CMD_MASK) != 0) decode_std_command(sp, inbyte); else if ((sp->status & SIXP_RX_DCD_MASK) == SIXP_RX_DCD_MASK) decode_data(sp, inbyte); } } MODULE_AUTHOR("Ralf Baechle DO1GRB <ralf@linux-mips.org>"); MODULE_DESCRIPTION("6pack driver for AX.25"); MODULE_LICENSE("GPL"); MODULE_ALIAS_LDISC(N_6PACK); module_init(sixpack_init_driver); module_exit(sixpack_exit_driver);
gpl-2.0